comparison src/lwasm.c @ 98:81fc353d4d69

Cleaned up old lwasm_expr_result() function and unused EXPR_* flags
author lost
date Sat, 17 Jan 2009 07:12:05 +0000
parents 83ba34ed11b3
children f59c0916753d
comparison
equal deleted inserted replaced
97:2e8dda44027c 98:81fc353d4d69
313 313
314 /* 314 /*
315 Evaluate an expression according to the flag value. Return 0 if a constant result was 315 Evaluate an expression according to the flag value. Return 0 if a constant result was
316 obtained, 1 if an incomplete result was obtained, and -1 if an error was flagged. 316 obtained, 1 if an incomplete result was obtained, and -1 if an error was flagged.
317 317
318 Symbol resolution will be modified for the object target as follows:
319 - a symbol which is not defined within a section will evaluate as a constant
320 - a symbol which is defined within the same section will evaluate as a constant
321 - a symbol defined in another section will remain unresolved
322 - external references will also remain unresolved
323
324 EXPR_PASS2PASS will cause the result from pass 1 along with the offset to
325 the end of the expression to be stored in the line data. There can only be
326 one such expression per source line. In this case, the expression is parsed
327 and evaluated on pass 1 but the intermediate representation is re-evaluated
328 on pass 2.
329 */
330 /*
331 int lwasm_expr_result(asmstate_t *as, lwasm_line_t *l, char **inp, int flag, int *val)
332 {
333 lwasm_expr_stack_t *s;
334 const char *ep;
335 int rval;
336
337 s = lwasm_evaluate_expr(as, l, *inp, &ep);
338 if (!s)
339 {
340 register_error(as, l, 1, "Bad expression");
341 *val = 0;
342 return -1;
343 }
344 *inp = (char *)ep;
345
346 if (flag & EXPR_PASS1CONST && as -> passnum == 1 && !lwasm_expr_result_ckconst(as, s))
347 {
348 register_error(as, l, 1, "Undefined reference (pass 1)");
349 *val = 0;
350 lwasm_expr_stack_free(s);
351 return -1;
352 }
353 if (flag & EXPR_PASS2CONST && as -> passnum == 2 && !lwasm_expr_result_ckconst(as, s))
354 {
355 register_error(as, l, 2, "Undefined reference (pass 2)");
356 *val = 0;
357 lwasm_expr_stack_free(s);
358 return -1;
359 }
360 if (flag & EXPR_NOINTERSECT && !lwasm_expr_is_constant(s))
361 {
362 register_error(as, l, 2, "Invalid inter-section reference");
363 }
364 *val = lwasm_expr_get_value(s);
365 if (l -> expr)
366 {
367 lwasm_expr_stack_free(l -> expr);
368 l -> expr = NULL;
369 }
370 if (lwasm_is_constant(s))
371 {
372 // fully resolved value here
373 lwasm_expr_stack_free(s);
374 }
375 else
376 {
377 // incomplete reference here
378 l -> expr = s;
379 }
380
381 if (flag & EXPR_BYTE && as -> passnum == 2 && (*val < -128 || *val > 255))
382 {
383 register_error(as, l, 2, "Byte overflow");
384 *val &= 0xff;
385 return -1;
386 }
387 if (flag & EXPR_BYTE)
388 {
389 *val &= 0xff;
390 }
391
392 return 0;
393 }
394 */ 318 */
395 int lwasm_expr_result2(asmstate_t *as, lwasm_line_t *l, char **inp, int flag, int *val, int slot) 319 int lwasm_expr_result2(asmstate_t *as, lwasm_line_t *l, char **inp, int flag, int *val, int slot)
396 { 320 {
397 lwasm_expr_stack_t *s = NULL; 321 lwasm_expr_stack_t *s = NULL;
398 const char *ep; 322 const char *ep;