Mercurial > hg-old > index.cgi
comparison lwasm/lwasm.c @ 363:d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
author | lost@starbug |
---|---|
date | Tue, 06 Apr 2010 21:03:19 -0600 |
parents | f50a54d0293a |
children | 9c24d9d485b9 |
comparison
equal
deleted
inserted
replaced
362:4867f18c872f | 363:d96c30e60ddf |
---|---|
31 #include <lw_alloc.h> | 31 #include <lw_alloc.h> |
32 #include <lw_string.h> | 32 #include <lw_string.h> |
33 | 33 |
34 #include "lwasm.h" | 34 #include "lwasm.h" |
35 | 35 |
36 void lwasm_register_error(asmstate_t *as, line_t *l, const char *msg, ...); | |
37 | |
36 lw_expr_t lwasm_evaluate_var(char *var, void *priv) | 38 lw_expr_t lwasm_evaluate_var(char *var, void *priv) |
37 { | 39 { |
40 asmstate_t *as = (asmstate_t *)priv; | |
41 lw_expr_t e; | |
42 importlist_t *im; | |
43 struct symtabe *s; | |
44 | |
45 s = lookup_symbol(as, as -> cl, var); | |
46 if (s) | |
47 { | |
48 e = lw_expr_build(lw_expr_type_special, lwasm_expr_syment, s); | |
49 return e; | |
50 } | |
51 | |
52 // undefined here is undefied unless output is object | |
53 if (as -> output_format != OUTPUT_OBJ) | |
54 goto nomatch; | |
55 | |
56 // check for import | |
57 for (im = as -> importlist; im; im = im -> next) | |
58 { | |
59 if (!strcmp(im -> symbol, var)) | |
60 break; | |
61 } | |
62 | |
63 // check for "undefined" to import automatically | |
64 if (!im && CURPRAGMA(as -> cl, PRAGMA_UNDEFEXTERN)) | |
65 { | |
66 im = lw_alloc(sizeof(importlist_t)); | |
67 im -> symbol = lw_strdup(var); | |
68 im -> next = as -> importlist; | |
69 as -> importlist = im; | |
70 } | |
71 | |
72 if (!im) | |
73 goto nomatch; | |
74 | |
75 e = lw_expr_build(lw_expr_type_special, lwasm_expr_import, im); | |
76 return e; | |
77 | |
78 nomatch: | |
79 if (as -> badsymerr) | |
80 { | |
81 lwasm_register_error(as, as -> cl, "Undefined symbol %s", var); | |
82 } | |
38 return NULL; | 83 return NULL; |
39 } | 84 } |
40 | 85 |
41 lw_expr_t lwasm_evaluate_special(int t, void *ptr, void *priv) | 86 lw_expr_t lwasm_evaluate_special(int t, void *ptr, void *priv) |
42 { | 87 { |
56 line_t *cl = ptr; | 101 line_t *cl = ptr; |
57 if (cl -> addr) | 102 if (cl -> addr) |
58 return lw_expr_copy(cl -> addr); | 103 return lw_expr_copy(cl -> addr); |
59 else | 104 else |
60 return NULL; | 105 return NULL; |
106 } | |
107 | |
108 case lwasm_expr_syment: | |
109 { | |
110 return NULL; | |
111 } | |
112 | |
113 case lwasm_expr_import: | |
114 { | |
115 return NULL; | |
116 } | |
117 | |
118 case lwasm_expr_nextbp: | |
119 { | |
120 return NULL; | |
121 } | |
122 | |
123 case lwasm_expr_prevbp: | |
124 { | |
125 return NULL; | |
61 } | 126 } |
62 } | 127 } |
63 return NULL; | 128 return NULL; |
64 } | 129 } |
65 | 130 |
480 e = lw_expr_parse(p, as); | 545 e = lw_expr_parse(p, as); |
481 | 546 |
482 return e; | 547 return e; |
483 } | 548 } |
484 | 549 |
550 int lwasm_reduce_expr(asmstate_t *as, lw_expr_t expr) | |
551 { | |
552 lw_expr_simplify(expr, as); | |
553 } | |
554 | |
485 void lwasm_save_expr(line_t *cl, int id, lw_expr_t expr) | 555 void lwasm_save_expr(line_t *cl, int id, lw_expr_t expr) |
486 { | 556 { |
487 struct line_expr_s *e; | 557 struct line_expr_s *e; |
488 | 558 |
489 for (e = cl -> exprs; e; e = e -> next) | 559 for (e = cl -> exprs; e; e = e -> next) |
610 (*p) += 2; | 680 (*p) += 2; |
611 else | 681 else |
612 (*p) += 3; | 682 (*p) += 3; |
613 return rval; | 683 return rval; |
614 } | 684 } |
685 | |
686 void lwasm_show_errors(asmstate_t *as) | |
687 { | |
688 fprintf(stderr, "Errors encountered. FIXME - print out errors.\n"); | |
689 } |