Mercurial > hg > index.cgi
comparison lwasm/lwasm.c @ 336:30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
author | William Astle <lost@l-w.ca> |
---|---|
date | Thu, 31 Jul 2014 17:20:11 -0600 |
parents | d399df78e1ab |
children | 433851a26794 |
comparison
equal
deleted
inserted
replaced
335:af78bad4922c | 336:30b2bad9b5eb |
---|---|
29 #include <lw_expr.h> | 29 #include <lw_expr.h> |
30 #include <lw_alloc.h> | 30 #include <lw_alloc.h> |
31 #include <lw_string.h> | 31 #include <lw_string.h> |
32 | 32 |
33 #include "lwasm.h" | 33 #include "lwasm.h" |
34 #include "instab.h" | |
34 | 35 |
35 void lwasm_register_error(asmstate_t *as, line_t *l, const char *msg, ...); | 36 void lwasm_register_error(asmstate_t *as, line_t *l, const char *msg, ...); |
36 | 37 |
37 int lwasm_expr_exportable(asmstate_t *as, lw_expr_t expr) | 38 int lwasm_expr_exportable(asmstate_t *as, lw_expr_t expr) |
38 { | 39 { |
1093 *max = rd.max; | 1094 *max = rd.max; |
1094 if (rd.min == -1) | 1095 if (rd.min == -1) |
1095 return -1; | 1096 return -1; |
1096 return 0; | 1097 return 0; |
1097 } | 1098 } |
1099 | |
1100 void lwasm_reduce_line_exprs(line_t *cl) | |
1101 { | |
1102 asmstate_t *as; | |
1103 struct line_expr_s *le; | |
1104 int i; | |
1105 | |
1106 as = cl -> as; | |
1107 as -> cl = cl; | |
1108 | |
1109 // simplify address | |
1110 lwasm_reduce_expr(as, cl -> addr); | |
1111 | |
1112 // simplify data address | |
1113 lwasm_reduce_expr(as, cl -> daddr); | |
1114 | |
1115 // simplify each expression | |
1116 for (i = 0, le = cl -> exprs; le; le = le -> next, i++) | |
1117 { | |
1118 lwasm_reduce_expr(as, le -> expr); | |
1119 debug_message(as, 100, "Reduce expressions: exp[%d] = %s", i, lw_expr_print(le -> expr)); | |
1120 } | |
1121 | |
1122 if (cl -> len == -1 || cl -> dlen == -1) | |
1123 { | |
1124 // try resolving the instruction length | |
1125 // but don't force resolution | |
1126 if (cl -> insn >= 0 && instab[cl -> insn].resolve) | |
1127 { | |
1128 (instab[cl -> insn].resolve)(as, cl, 0); | |
1129 if ((cl -> inmod == 0) && cl -> len >= 0 && cl -> dlen >= 0) | |
1130 { | |
1131 if (cl -> len == 0) | |
1132 cl -> len = cl -> dlen; | |
1133 else | |
1134 cl -> dlen = cl -> len; | |
1135 } | |
1136 } | |
1137 } | |
1138 debug_message(as, 100, "Reduce expressions: len = %d", cl -> len); | |
1139 debug_message(as, 100, "Reduce expressions: dlen = %d", cl -> dlen); | |
1140 debug_message(as, 100, "Reduce expressions: addr = %s", lw_expr_print(cl -> addr)); | |
1141 debug_message(as, 100, "Reduce expressions: daddr = %s", lw_expr_print(cl -> daddr)); | |
1142 } |