Mercurial > hg > index.cgi
comparison lwasm/list.c @ 49:bd8b3fbd1e28
Added ability to flag macros as "noexpand" so they are not expanded in the listing
author | lost@l-w.ca |
---|---|
date | Tue, 05 Apr 2011 00:06:28 -0600 |
parents | 31adb7c09b4e |
children | f55650f5e9b8 |
comparison
equal
deleted
inserted
replaced
48:1134255553bc | 49:bd8b3fbd1e28 |
---|---|
33 /* | 33 /* |
34 Do listing | 34 Do listing |
35 */ | 35 */ |
36 void do_list(asmstate_t *as) | 36 void do_list(asmstate_t *as) |
37 { | 37 { |
38 line_t *cl; | 38 line_t *cl, *nl; |
39 FILE *of; | 39 FILE *of; |
40 int i; | 40 int i; |
41 | 41 char *obytes = NULL; |
42 int obytelen = 0; | |
43 | |
42 char *tc; | 44 char *tc; |
43 | 45 |
44 if (!(as -> flags & FLAG_LIST)) | 46 if (!(as -> flags & FLAG_LIST)) |
45 return; | 47 return; |
46 | 48 |
51 if (!of) | 53 if (!of) |
52 { | 54 { |
53 fprintf(stderr, "Cannot open list file; list not generated\n"); | 55 fprintf(stderr, "Cannot open list file; list not generated\n"); |
54 return; | 56 return; |
55 } | 57 } |
56 for (cl = as -> line_head; cl; cl = cl -> next) | 58 for (cl = as -> line_head; cl; cl = nl) |
57 { | 59 { |
58 if (cl -> len < 1) | 60 nl = cl -> next; |
61 if (cl -> noexpand_start) | |
62 { | |
63 obytelen = 0; | |
64 int nc = 0; | |
65 for (nl = cl; ; nl = nl -> next) | |
66 { | |
67 if (nl -> noexpand_start) | |
68 nc++; | |
69 if (nl -> noexpand_end) | |
70 nc--; | |
71 | |
72 if (nl -> outputl > 0) | |
73 obytelen += nl -> outputl; | |
74 if (nc == 0) | |
75 break; | |
76 } | |
77 obytes = lw_alloc(obytelen); | |
78 nc = 0; | |
79 for (nl = cl; ; nl = nl -> next) | |
80 { | |
81 int i; | |
82 for (i = 0; i < nl -> outputl; i++) | |
83 { | |
84 obytes[nc++] = nl -> output[i]; | |
85 } | |
86 if (nc >= obytelen) | |
87 break; | |
88 } | |
89 nl = nl -> next; | |
90 } | |
91 else | |
92 { | |
93 obytelen = cl -> outputl; | |
94 if (obytelen > 0) | |
95 { | |
96 obytes = lw_alloc(obytelen); | |
97 memmove(obytes, cl -> output, cl -> outputl); | |
98 } | |
99 } | |
100 if (cl -> len < 1 && obytelen < 1) | |
59 { | 101 { |
60 if (cl -> soff >= 0) | 102 if (cl -> soff >= 0) |
61 { | 103 { |
62 fprintf(of, "%04X ", cl -> soff & 0xffff); | 104 fprintf(of, "%04X ", cl -> soff & 0xffff); |
63 } | 105 } |
104 lwasm_reduce_expr(as, te); | 146 lwasm_reduce_expr(as, te); |
105 as -> exportcheck = 0; | 147 as -> exportcheck = 0; |
106 // fprintf(of, "%s\n", lw_expr_print(te)); | 148 // fprintf(of, "%s\n", lw_expr_print(te)); |
107 fprintf(of, "%04X ", lw_expr_intval(te) & 0xffff); | 149 fprintf(of, "%04X ", lw_expr_intval(te) & 0xffff); |
108 lw_expr_destroy(te); | 150 lw_expr_destroy(te); |
109 for (i = 0; i < cl -> outputl && i < 8; i++) | 151 for (i = 0; i < obytelen && i < 8; i++) |
110 { | 152 { |
111 fprintf(of, "%02X", cl -> output[i]); | 153 fprintf(of, "%02X", obytes[i]); |
112 } | 154 } |
113 for (; i < 8; i++) | 155 for (; i < 8; i++) |
114 { | 156 { |
115 fprintf(of, " "); | 157 fprintf(of, " "); |
116 } | 158 } |
145 } | 187 } |
146 } | 188 } |
147 fputc('\n', of); | 189 fputc('\n', of); |
148 if (cl -> outputl > 8) | 190 if (cl -> outputl > 8) |
149 { | 191 { |
150 for (i = 8; i < cl -> outputl; i++) | 192 for (i = 8; i < obytelen; i++) |
151 { | 193 { |
152 if (i % 8 == 0) | 194 if (i % 8 == 0) |
153 { | 195 { |
154 if (i != 8) | 196 if (i != 8) |
155 fprintf(of, "\n "); | 197 fprintf(of, "\n "); |
156 else | 198 else |
157 fprintf(of, " "); | 199 fprintf(of, " "); |
158 } | 200 } |
159 fprintf(of, "%02X", cl -> output[i]); | 201 fprintf(of, "%02X", obytes[i]); |
160 } | 202 } |
161 if (i > 8) | 203 if (i > 8) |
162 fprintf(of, "\n"); | 204 fprintf(of, "\n"); |
163 } | 205 } |
206 lw_free(obytes); | |
207 obytes = NULL; | |
164 } | 208 } |
165 | 209 |
166 if (as -> flags & FLAG_SYMBOLS) | 210 if (as -> flags & FLAG_SYMBOLS) |
167 list_symbols(as, of); | 211 list_symbols(as, of); |
168 } | 212 } |