comparison lwasm/pseudo.c @ 219:afd50d6b4113

Add --preprocess option Add --preprocess option which expands macros, resolves conditions, and resolves include files if possible. If an include file is not available, it the include directive is retained.
author William Astle <lost@l-w.ca>
date Sun, 10 Jun 2012 18:24:31 -0600
parents b0c9df865b25
children 3864d96ee8c7
comparison
equal deleted inserted replaced
218:b0c9df865b25 219:afd50d6b4113
1015 } 1015 }
1016 1016
1017 PARSEFUNC(pseudo_parse_ifp1) 1017 PARSEFUNC(pseudo_parse_ifp1)
1018 { 1018 {
1019 l -> len = 0; 1019 l -> len = 0;
1020 l -> hideline = 1;
1020 1021
1021 if (as -> skipcond && !(as -> skipmacro)) 1022 if (as -> skipcond && !(as -> skipmacro))
1022 { 1023 {
1023 as -> skipcount++; 1024 as -> skipcount++;
1024 skip_operand(p); 1025 skip_operand(p);
1030 } 1031 }
1031 1032
1032 PARSEFUNC(pseudo_parse_ifp2) 1033 PARSEFUNC(pseudo_parse_ifp2)
1033 { 1034 {
1034 l -> len = 0; 1035 l -> len = 0;
1036 l -> hideline = 1;
1035 1037
1036 if (as -> skipcond && !(as -> skipmacro)) 1038 if (as -> skipcond && !(as -> skipmacro))
1037 { 1039 {
1038 as -> skipcount++; 1040 as -> skipcount++;
1039 skip_operand(p); 1041 skip_operand(p);
1046 PARSEFUNC(pseudo_parse_ifeq) 1048 PARSEFUNC(pseudo_parse_ifeq)
1047 { 1049 {
1048 lw_expr_t e; 1050 lw_expr_t e;
1049 1051
1050 l -> len = 0; 1052 l -> len = 0;
1053 l -> hideline = 1;
1051 1054
1052 if (as -> skipcond && !(as -> skipmacro)) 1055 if (as -> skipcond && !(as -> skipmacro))
1053 { 1056 {
1054 as -> skipcount++; 1057 as -> skipcount++;
1055 skip_operand(p); 1058 skip_operand(p);
1069 PARSEFUNC(pseudo_parse_ifne) 1072 PARSEFUNC(pseudo_parse_ifne)
1070 { 1073 {
1071 lw_expr_t e; 1074 lw_expr_t e;
1072 1075
1073 l -> len = 0; 1076 l -> len = 0;
1077 l -> hideline = 1;
1074 1078
1075 if (as -> skipcond && !(as -> skipmacro)) 1079 if (as -> skipcond && !(as -> skipmacro))
1076 { 1080 {
1077 as -> skipcount++; 1081 as -> skipcount++;
1078 skip_operand(p); 1082 skip_operand(p);
1093 PARSEFUNC(pseudo_parse_ifgt) 1097 PARSEFUNC(pseudo_parse_ifgt)
1094 { 1098 {
1095 lw_expr_t e; 1099 lw_expr_t e;
1096 1100
1097 l -> len = 0; 1101 l -> len = 0;
1102 l -> hideline = 1;
1098 1103
1099 if (as -> skipcond && !(as -> skipmacro)) 1104 if (as -> skipcond && !(as -> skipmacro))
1100 { 1105 {
1101 as -> skipcount++; 1106 as -> skipcount++;
1102 skip_operand(p); 1107 skip_operand(p);
1116 PARSEFUNC(pseudo_parse_ifge) 1121 PARSEFUNC(pseudo_parse_ifge)
1117 { 1122 {
1118 lw_expr_t e; 1123 lw_expr_t e;
1119 1124
1120 l -> len = 0; 1125 l -> len = 0;
1126 l -> hideline = 1;
1121 1127
1122 if (as -> skipcond && !(as -> skipmacro)) 1128 if (as -> skipcond && !(as -> skipmacro))
1123 { 1129 {
1124 as -> skipcount++; 1130 as -> skipcount++;
1125 skip_operand(p); 1131 skip_operand(p);
1139 PARSEFUNC(pseudo_parse_iflt) 1145 PARSEFUNC(pseudo_parse_iflt)
1140 { 1146 {
1141 lw_expr_t e; 1147 lw_expr_t e;
1142 1148
1143 l -> len = 0; 1149 l -> len = 0;
1150 l -> hideline = 1;
1144 1151
1145 if (as -> skipcond && !(as -> skipmacro)) 1152 if (as -> skipcond && !(as -> skipmacro))
1146 { 1153 {
1147 as -> skipcount++; 1154 as -> skipcount++;
1148 skip_operand(p); 1155 skip_operand(p);
1161 1168
1162 PARSEFUNC(pseudo_parse_ifle) 1169 PARSEFUNC(pseudo_parse_ifle)
1163 { 1170 {
1164 lw_expr_t e; 1171 lw_expr_t e;
1165 1172
1173 l -> hideline = 1;
1166 l -> len = 0; 1174 l -> len = 0;
1167 1175
1168 if (as -> skipcond && !(as -> skipmacro)) 1176 if (as -> skipcond && !(as -> skipmacro))
1169 { 1177 {
1170 as -> skipcount++; 1178 as -> skipcount++;
1182 } 1190 }
1183 } 1191 }
1184 1192
1185 PARSEFUNC(pseudo_parse_endc) 1193 PARSEFUNC(pseudo_parse_endc)
1186 { 1194 {
1195 l -> hideline = 1;
1187 l -> len = 0; 1196 l -> len = 0;
1188 skip_operand(p); 1197 skip_operand(p);
1189 if (as -> skipcond && !(as -> skipmacro)) 1198 if (as -> skipcond && !(as -> skipmacro))
1190 { 1199 {
1191 as -> skipcount--; 1200 as -> skipcount--;
1195 } 1204 }
1196 1205
1197 PARSEFUNC(pseudo_parse_else) 1206 PARSEFUNC(pseudo_parse_else)
1198 { 1207 {
1199 l -> len = 0; 1208 l -> len = 0;
1209 l -> hideline = 1;
1200 skip_operand(p); 1210 skip_operand(p);
1201 1211
1202 if (as -> skipmacro) 1212 if (as -> skipmacro)
1203 return; 1213 return;
1204 1214
1220 char *sym; 1230 char *sym;
1221 int i; 1231 int i;
1222 struct symtabe *s; 1232 struct symtabe *s;
1223 1233
1224 l -> len = 0; 1234 l -> len = 0;
1235 l -> hideline = 1;
1225 1236
1226 if (as -> skipcond && !(as -> skipmacro)) 1237 if (as -> skipcond && !(as -> skipmacro))
1227 { 1238 {
1228 as -> skipcount++; 1239 as -> skipcount++;
1229 skip_operand(p); 1240 skip_operand(p);
1259 char *sym; 1270 char *sym;
1260 int i; 1271 int i;
1261 struct symtabe *s; 1272 struct symtabe *s;
1262 1273
1263 l -> len = 0; 1274 l -> len = 0;
1275 l -> hideline = 1;
1264 1276
1265 if (as -> skipcond && !(as -> skipmacro)) 1277 if (as -> skipcond && !(as -> skipmacro))
1266 { 1278 {
1267 as -> skipcount++; 1279 as -> skipcount++;
1268 skip_operand(p); 1280 skip_operand(p);
1407 input_openstring(as, "INTERNAL", buf); 1419 input_openstring(as, "INTERNAL", buf);
1408 1420
1409 len = strlen(fn) + 8; 1421 len = strlen(fn) + 8;
1410 p3 = lw_alloc(len + 1); 1422 p3 = lw_alloc(len + 1);
1411 sprintf(p3, "include:%s", fn); 1423 sprintf(p3, "include:%s", fn);
1424 as -> fileerr = 0;
1412 input_open(as, p3); 1425 input_open(as, p3);
1413 lw_free(p3); 1426 lw_free(p3);
1414 1427
1428 if (as -> fileerr == 0)
1429 l -> hideline = 1;
1415 l -> len = 0; 1430 l -> len = 0;
1416 lw_free(fn); 1431 lw_free(fn);
1417 } 1432 }
1418 1433
1419 PARSEFUNC(pseudo_parse_align) 1434 PARSEFUNC(pseudo_parse_align)