OLD | NEW |
1 /* | 1 /* |
2 * NASM-compatible parser | 2 * NASM-compatible parser |
3 * | 3 * |
4 * Copyright (C) 2001-2007 Peter Johnson, Michael Urman | 4 * Copyright (C) 2001-2007 Peter Johnson, Michael Urman |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
11 * 2. Redistributions in binary form must reproduce the above copyright | 11 * 2. Redistributions in binary form must reproduce the above copyright |
12 * notice, this list of conditions and the following disclaimer in the | 12 * notice, this list of conditions and the following disclaimer in the |
13 * documentation and/or other materials provided with the distribution. | 13 * documentation and/or other materials provided with the distribution. |
14 * | 14 * |
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' | 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' |
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE | 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE |
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 * POSSIBILITY OF SUCH DAMAGE. | 25 * POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 #include <util.h> | 27 #include <util.h> |
28 RCSID("$Id: nasm-parse.c 2191 2009-03-25 03:42:05Z peter $"); | 28 RCSID("$Id: nasm-parse.c 2323 2010-05-16 03:37:00Z peter $"); |
29 | 29 |
30 #include <libyasm.h> | 30 #include <libyasm.h> |
31 | 31 |
32 #include <math.h> | 32 #include <math.h> |
33 | 33 |
34 #include "modules/parsers/nasm/nasm-parser.h" | 34 #include "modules/parsers/nasm/nasm-parser.h" |
35 #include "modules/preprocs/nasm/nasm.h" | 35 #include "modules/preprocs/nasm/nasm.h" |
36 | 36 |
37 typedef enum { | 37 typedef enum { |
38 NORM_EXPR, | 38 NORM_EXPR, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 case INCBIN: str = "INCBIN"; break; | 171 case INCBIN: str = "INCBIN"; break; |
172 case EQU: str = "EQU"; break; | 172 case EQU: str = "EQU"; break; |
173 case TIMES: str = "TIMES"; break; | 173 case TIMES: str = "TIMES"; break; |
174 case SEG: str = "SEG"; break; | 174 case SEG: str = "SEG"; break; |
175 case WRT: str = "WRT"; break; | 175 case WRT: str = "WRT"; break; |
176 case NOSPLIT: str = "NOSPLIT"; break; | 176 case NOSPLIT: str = "NOSPLIT"; break; |
177 case STRICT: str = "STRICT"; break; | 177 case STRICT: str = "STRICT"; break; |
178 case INSN: str = "instruction"; break; | 178 case INSN: str = "instruction"; break; |
179 case PREFIX: str = "instruction prefix"; break; | 179 case PREFIX: str = "instruction prefix"; break; |
180 case REG: str = "register"; break; | 180 case REG: str = "register"; break; |
| 181 case REGGROUP: str = "register group"; break; |
181 case SEGREG: str = "segment register"; break; | 182 case SEGREG: str = "segment register"; break; |
182 case TARGETMOD: str = "target modifier"; break; | 183 case TARGETMOD: str = "target modifier"; break; |
183 case LEFT_OP: str = "<<"; break; | 184 case LEFT_OP: str = "<<"; break; |
184 case RIGHT_OP: str = ">>"; break; | 185 case RIGHT_OP: str = ">>"; break; |
185 case SIGNDIV: str = "//"; break; | 186 case SIGNDIV: str = "//"; break; |
186 case SIGNMOD: str = "%%"; break; | 187 case SIGNMOD: str = "%%"; break; |
187 case START_SECTION_ID: str = "$$"; break; | 188 case START_SECTION_ID: str = "$$"; break; |
188 case ID: str = "identifier"; break; | 189 case ID: str = "identifier"; break; |
189 case LOCAL_ID: str = ".identifier"; break; | 190 case LOCAL_ID: str = ".identifier"; break; |
190 case SPECIAL_ID: str = "..identifier"; break; | 191 case SPECIAL_ID: str = "..identifier"; break; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 incr = INTNUM_val; | 310 incr = INTNUM_val; |
310 get_next_token(); | 311 get_next_token(); |
311 | 312 |
312 if (!expect(FILENAME)) return NULL; | 313 if (!expect(FILENAME)) return NULL; |
313 filename = FILENAME_val; | 314 filename = FILENAME_val; |
314 get_next_token(); | 315 get_next_token(); |
315 | 316 |
316 /* %line indicates the line number of the *next* line, so subtract | 317 /* %line indicates the line number of the *next* line, so subtract |
317 * out the increment when setting the line number. | 318 * out the increment when setting the line number. |
318 */ | 319 */ |
319 yasm_linemap_set(parser_nasm->linemap, filename, | 320 yasm_linemap_set(parser_nasm->linemap, filename, 0, |
320 yasm_intnum_get_uint(line) - yasm_intnum_get_uint(incr), | 321 yasm_intnum_get_uint(line) - yasm_intnum_get_uint(incr), |
321 yasm_intnum_get_uint(incr)); | 322 yasm_intnum_get_uint(incr)); |
322 yasm_intnum_destroy(line); | 323 yasm_intnum_destroy(line); |
323 yasm_intnum_destroy(incr); | 324 yasm_intnum_destroy(incr); |
324 yasm_xfree(filename); | 325 yasm_xfree(filename); |
325 return NULL; | 326 return NULL; |
326 } | 327 } |
327 case '[': /* [ directive ] */ | 328 case '[': /* [ directive ] */ |
328 { | 329 { |
329 char *dirname; | 330 char *dirname; |
330 yasm_valparamhead dir_vps; | 331 yasm_valparamhead dir_vps; |
331 int have_vps = 1; | 332 int have_vps = 1; |
332 | 333 |
333 parser_nasm->state = DIRECTIVE; | 334 parser_nasm->state = DIRECTIVE; |
334 get_next_token(); | 335 get_next_token(); |
335 | 336 |
336 if (!expect(DIRECTIVE_NAME)) | 337 if (!expect(DIRECTIVE_NAME)) |
337 return NULL; | 338 return NULL; |
338 dirname = DIRECTIVE_NAME_val; | 339 dirname = DIRECTIVE_NAME_val; |
339 get_next_token(); | 340 get_next_token(); |
340 | 341 |
| 342 /* ignore [warning]. TODO: actually implement */ |
| 343 if (yasm__strcasecmp(dirname, "warning") == 0) { |
| 344 yasm_warn_set(YASM_WARN_GENERAL, |
| 345 N_("[warning] directive not supported; ignored")); |
| 346 |
| 347 /* throw away the rest of the directive tokens */ |
| 348 while (!is_eol() && curtok != ']') |
| 349 { |
| 350 destroy_curtok(); |
| 351 get_next_token(); |
| 352 } |
| 353 expect(']'); |
| 354 get_next_token(); |
| 355 return NULL; |
| 356 } |
| 357 |
341 if (curtok == ']' || curtok == ':') | 358 if (curtok == ']' || curtok == ':') |
342 have_vps = 0; | 359 have_vps = 0; |
343 else if (!parse_directive_valparams(parser_nasm, &dir_vps)) { | 360 else if (!parse_directive_valparams(parser_nasm, &dir_vps)) { |
344 yasm_error_set(YASM_ERROR_SYNTAX, | 361 yasm_error_set(YASM_ERROR_SYNTAX, |
345 N_("invalid arguments to [%s]"), dirname); | 362 N_("invalid arguments to [%s]"), dirname); |
346 yasm_xfree(dirname); | 363 yasm_xfree(dirname); |
347 return NULL; | 364 return NULL; |
348 } | 365 } |
349 if (curtok == ':') { | 366 if (curtok == ':') { |
350 yasm_valparamhead ext_vps; | 367 yasm_valparamhead ext_vps; |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 ea = yasm_arch_ea_create(p_object->arch, e); | 853 ea = yasm_arch_ea_create(p_object->arch, e); |
837 yasm_ea_set_implicit_size_segment(parser_nasm, ea, e); | 854 yasm_ea_set_implicit_size_segment(parser_nasm, ea, e); |
838 op = yasm_operand_create_mem(ea); | 855 op = yasm_operand_create_mem(ea); |
839 } | 856 } |
840 return op; | 857 return op; |
841 } | 858 } |
842 case OFFSET: | 859 case OFFSET: |
843 { | 860 { |
844 yasm_insn_operand *op2; | 861 yasm_insn_operand *op2; |
845 get_next_token(); | 862 get_next_token(); |
| 863 if (parser_nasm->masm && curtok == ID && !yasm__strcasecmp(ID_val, "
flat")) { |
| 864 get_next_token(); |
| 865 if (curtok == ':') { |
| 866 get_next_token(); |
| 867 } |
| 868 } |
846 op = parse_operand(parser_nasm); | 869 op = parse_operand(parser_nasm); |
847 if (!op) { | 870 if (!op) { |
848 yasm_error_set(YASM_ERROR_SYNTAX, | 871 yasm_error_set(YASM_ERROR_SYNTAX, |
849 N_("memory address expected")); | 872 N_("memory address expected")); |
850 return NULL; | 873 return NULL; |
851 } | 874 } |
852 if (op->type == YASM_INSN__OPERAND_IMM) | 875 if (op->type == YASM_INSN__OPERAND_IMM) |
853 return op; | 876 return op; |
854 if (op->type != YASM_INSN__OPERAND_MEMORY) { | 877 if (op->type != YASM_INSN__OPERAND_MEMORY) { |
855 yasm_error_set(YASM_ERROR_SYNTAX, | 878 yasm_error_set(YASM_ERROR_SYNTAX, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 yasm_ea_set_segreg(op->data.ea, segreg); | 920 yasm_ea_set_segreg(op->data.ea, segreg); |
898 return op; | 921 return op; |
899 } | 922 } |
900 op = yasm_operand_create_segreg(segreg); | 923 op = yasm_operand_create_segreg(segreg); |
901 return op; | 924 return op; |
902 } | 925 } |
903 case REG: | 926 case REG: |
904 op = yasm_operand_create_reg(REG_val); | 927 op = yasm_operand_create_reg(REG_val); |
905 get_next_token(); | 928 get_next_token(); |
906 return op; | 929 return op; |
| 930 case REGGROUP: |
| 931 { |
| 932 unsigned long regindex; |
| 933 uintptr_t reg = REGGROUP_val; |
| 934 get_next_token(); /* REGGROUP */ |
| 935 if (curtok != '(') |
| 936 return yasm_operand_create_reg(reg); |
| 937 get_next_token(); /* '(' */ |
| 938 if (!expect(INTNUM)) { |
| 939 yasm_error_set(YASM_ERROR_SYNTAX, |
| 940 N_("integer register index expected")); |
| 941 return NULL; |
| 942 } |
| 943 regindex = yasm_intnum_get_uint(INTNUM_val); |
| 944 get_next_token(); /* INTNUM */ |
| 945 if (!expect(')')) { |
| 946 yasm_error_set(YASM_ERROR_SYNTAX, |
| 947 N_("missing closing parenthesis for register index")); |
| 948 return NULL; |
| 949 } |
| 950 get_next_token(); /* ')' */ |
| 951 reg = yasm_arch_reggroup_get_reg(p_object->arch, reg, regindex); |
| 952 if (reg == 0) { |
| 953 yasm_error_set(YASM_ERROR_SYNTAX, N_("bad register index `%u'"), |
| 954 regindex); |
| 955 return NULL; |
| 956 } |
| 957 return yasm_operand_create_reg(reg); |
| 958 } |
907 case STRICT: | 959 case STRICT: |
908 get_next_token(); | 960 get_next_token(); |
909 op = parse_operand(parser_nasm); | 961 op = parse_operand(parser_nasm); |
910 if (op) | 962 if (op) |
911 op->strict = 1; | 963 op->strict = 1; |
912 return op; | 964 return op; |
913 case SIZE_OVERRIDE: | 965 case SIZE_OVERRIDE: |
914 { | 966 { |
915 unsigned int size = SIZE_OVERRIDE_val; | 967 unsigned int size = SIZE_OVERRIDE_val; |
916 get_next_token(); | 968 get_next_token(); |
| 969 if (parser_nasm->masm && curtok == ID && !yasm__strcasecmp(ID_val, "
ptr")) { |
| 970 get_next_token(); |
| 971 } |
917 op = parse_operand(parser_nasm); | 972 op = parse_operand(parser_nasm); |
918 if (!op) | 973 if (!op) |
919 return NULL; | 974 return NULL; |
920 if (op->type == YASM_INSN__OPERAND_REG && | 975 if (op->type == YASM_INSN__OPERAND_REG && |
921 yasm_arch_get_reg_size(p_object->arch, op->data.reg) != size) | 976 yasm_arch_get_reg_size(p_object->arch, op->data.reg) != size) |
922 yasm_error_set(YASM_ERROR_TYPE, | 977 yasm_error_set(YASM_ERROR_TYPE, |
923 N_("cannot override register size")); | 978 N_("cannot override register size")); |
924 else { | 979 else { |
925 /* Silently override others unless a warning is turned on. | 980 /* Silently override others unless a warning is turned on. |
926 * This is to allow overrides such as: | 981 * This is to allow overrides such as: |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 op = yasm_operand_create_mem(ea); | 1036 op = yasm_operand_create_mem(ea); |
982 return op; | 1037 return op; |
983 } | 1038 } |
984 } | 1039 } |
985 /* Fallthrough */ | 1040 /* Fallthrough */ |
986 default: | 1041 default: |
987 { | 1042 { |
988 yasm_expr *e = parse_bexpr(parser_nasm, NORM_EXPR); | 1043 yasm_expr *e = parse_bexpr(parser_nasm, NORM_EXPR); |
989 if (!e) | 1044 if (!e) |
990 return NULL; | 1045 return NULL; |
991 if (curtok != ':') | 1046 if (curtok != ':') { |
992 if (parser_nasm->tasm && yasm_expr_size(e)) { | 1047 if (parser_nasm->tasm && yasm_expr_size(e)) { |
993 yasm_effaddr *ea = yasm_arch_ea_create(p_object->arch, e); | 1048 yasm_effaddr *ea = yasm_arch_ea_create(p_object->arch, e); |
994 yasm_ea_set_implicit_size_segment(parser_nasm, ea, e); | 1049 yasm_ea_set_implicit_size_segment(parser_nasm, ea, e); |
995 op = yasm_operand_create_mem(ea); | 1050 op = yasm_operand_create_mem(ea); |
996 return op; | 1051 return op; |
997 } else | 1052 } else if (curtok == '[') { |
| 1053 yasm_expr *f; |
| 1054 yasm_effaddr *ea; |
| 1055 yasm_insn_operand *op2; |
| 1056 |
| 1057 op = parse_operand(parser_nasm); |
| 1058 if (!op) |
| 1059 return NULL; |
| 1060 |
| 1061 f = op->data.ea->disp.abs; |
| 1062 e = p_expr_new_tree(e, YASM_EXPR_ADD, f); |
| 1063 ea = yasm_arch_ea_create(p_object->arch, e); |
| 1064 yasm_ea_set_implicit_size_segment(parser_nasm, ea, e); |
| 1065 op2 = yasm_operand_create_mem(ea); |
| 1066 |
| 1067 yasm_xfree(op); |
| 1068 |
| 1069 return op2; |
| 1070 } else { |
998 return yasm_operand_create_imm(e); | 1071 return yasm_operand_create_imm(e); |
999 else { | 1072 } |
| 1073 } else { |
1000 yasm_expr *off; | 1074 yasm_expr *off; |
1001 get_next_token(); | 1075 get_next_token(); |
1002 off = parse_bexpr(parser_nasm, NORM_EXPR); | 1076 off = parse_bexpr(parser_nasm, NORM_EXPR); |
1003 if (!off) { | 1077 if (!off) { |
1004 yasm_expr_destroy(e); | 1078 yasm_expr_destroy(e); |
1005 return NULL; | 1079 return NULL; |
1006 } | 1080 } |
1007 op = yasm_operand_create_imm(off); | 1081 op = yasm_operand_create_imm(off); |
1008 op->seg = e; | 1082 op->seg = e; |
1009 return op; | 1083 return op; |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1256 } | 1330 } |
1257 return e; | 1331 return e; |
1258 } | 1332 } |
1259 | 1333 |
1260 static yasm_expr * | 1334 static yasm_expr * |
1261 parse_expr6(yasm_parser_nasm *parser_nasm, expr_type type) | 1335 parse_expr6(yasm_parser_nasm *parser_nasm, expr_type type) |
1262 { | 1336 { |
1263 yasm_expr *e; | 1337 yasm_expr *e; |
1264 yasm_symrec *sym; | 1338 yasm_symrec *sym; |
1265 | 1339 |
1266 /* directives allow very little and handle IDs specially */ | 1340 switch (curtok) { |
1267 if (type == DIR_EXPR) { | |
1268 switch (curtok) { | |
1269 case '~': | |
1270 get_next_token(); | |
1271 e = parse_expr6(parser_nasm, type); | |
1272 if (!e) { | |
1273 yasm_error_set(YASM_ERROR_SYNTAX, | |
1274 N_("expected expression after %s"), "`~'"); | |
1275 return NULL; | |
1276 } | |
1277 return p_expr_new_branch(YASM_EXPR_NOT, e); | |
1278 case '(': | |
1279 get_next_token(); | |
1280 e = parse_expr(parser_nasm, type); | |
1281 if (!e) { | |
1282 yasm_error_set(YASM_ERROR_SYNTAX, | |
1283 N_("expected expression after %s"), "`('"); | |
1284 return NULL; | |
1285 } | |
1286 if (!expect(')')) { | |
1287 yasm_error_set(YASM_ERROR_SYNTAX, N_("missing parenthesis")); | |
1288 return NULL; | |
1289 } | |
1290 get_next_token(); | |
1291 return e; | |
1292 case INTNUM: | |
1293 e = p_expr_new_ident(yasm_expr_int(INTNUM_val)); | |
1294 break; | |
1295 case REG: | |
1296 e = p_expr_new_ident(yasm_expr_reg(REG_val)); | |
1297 break; | |
1298 case ID: | |
1299 sym = yasm_symtab_use(p_symtab, ID_val, cur_line); | |
1300 e = p_expr_new_ident(yasm_expr_sym(sym)); | |
1301 yasm_xfree(ID_val); | |
1302 break; | |
1303 default: | |
1304 return NULL; | |
1305 } | |
1306 } else switch (curtok) { | |
1307 case '+': | 1341 case '+': |
1308 get_next_token(); | 1342 get_next_token(); |
1309 e = parse_expr6(parser_nasm, type); | 1343 e = parse_expr6(parser_nasm, type); |
1310 if (!e) { | 1344 if (!e) { |
1311 yasm_error_set(YASM_ERROR_SYNTAX, | 1345 yasm_error_set(YASM_ERROR_SYNTAX, |
1312 N_("expected expression after %s"), "`+'"); | 1346 N_("expected expression after %s"), "`+'"); |
1313 } | 1347 } |
1314 return e; | 1348 return e; |
1315 case '-': | 1349 case '-': |
1316 get_next_token(); | 1350 get_next_token(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1372 return NULL; | 1406 return NULL; |
1373 } | 1407 } |
1374 if (!expect(')')) { | 1408 if (!expect(')')) { |
1375 yasm_error_set(YASM_ERROR_SYNTAX, N_("missing parenthesis")); | 1409 yasm_error_set(YASM_ERROR_SYNTAX, N_("missing parenthesis")); |
1376 return NULL; | 1410 return NULL; |
1377 } | 1411 } |
1378 get_next_token(); | 1412 get_next_token(); |
1379 return e; | 1413 return e; |
1380 case INTNUM: | 1414 case INTNUM: |
1381 e = p_expr_new_ident(yasm_expr_int(INTNUM_val)); | 1415 e = p_expr_new_ident(yasm_expr_int(INTNUM_val)); |
1382 break; | 1416 get_next_token(); |
1383 case FLTNUM: | 1417 return e; |
1384 e = p_expr_new_ident(yasm_expr_float(FLTNUM_val)); | |
1385 break; | |
1386 case REG: | 1418 case REG: |
1387 if (type == DV_EXPR) { | 1419 if (type == DV_EXPR) { |
1388 yasm_error_set(YASM_ERROR_SYNTAX, | 1420 yasm_error_set(YASM_ERROR_SYNTAX, |
1389 N_("data values can't have registers")); | 1421 N_("data values can't have registers")); |
1390 return NULL; | 1422 return NULL; |
1391 } | 1423 } |
1392 e = p_expr_new_ident(yasm_expr_reg(REG_val)); | 1424 e = p_expr_new_ident(yasm_expr_reg(REG_val)); |
| 1425 get_next_token(); |
| 1426 return e; |
| 1427 } |
| 1428 |
| 1429 /* directives allow very little and handle IDs specially */ |
| 1430 if (type == DIR_EXPR) { |
| 1431 switch (curtok) { |
| 1432 case ID: |
| 1433 sym = yasm_symtab_use(p_symtab, ID_val, cur_line); |
| 1434 e = p_expr_new_ident(yasm_expr_sym(sym)); |
| 1435 yasm_xfree(ID_val); |
| 1436 break; |
| 1437 default: |
| 1438 return NULL; |
| 1439 } |
| 1440 } else switch (curtok) { |
| 1441 case FLTNUM: |
| 1442 e = p_expr_new_ident(yasm_expr_float(FLTNUM_val)); |
1393 break; | 1443 break; |
1394 case STRING: | 1444 case STRING: |
1395 { | 1445 { |
1396 yasm_intnum *intn; | 1446 yasm_intnum *intn; |
1397 if (parser_nasm->tasm) | 1447 if (parser_nasm->tasm) |
1398 intn = yasm_intnum_create_charconst_tasm(STRING_val.contents); | 1448 intn = yasm_intnum_create_charconst_tasm(STRING_val.contents); |
1399 else | 1449 else |
1400 intn = yasm_intnum_create_charconst_nasm(STRING_val.contents); | 1450 intn = yasm_intnum_create_charconst_nasm(STRING_val.contents); |
1401 e = p_expr_new_ident(yasm_expr_int(intn)); | 1451 e = p_expr_new_ident(yasm_expr_int(intn)); |
1402 yasm_xfree(STRING_val.contents); | 1452 yasm_xfree(STRING_val.contents); |
(...skipping 30 matching lines...) Expand all Loading... |
1433 e = yasm_expr_copy(parser_nasm->absstart); | 1483 e = yasm_expr_copy(parser_nasm->absstart); |
1434 else { | 1484 else { |
1435 sym = yasm_symtab_define_label(p_symtab, "$$", | 1485 sym = yasm_symtab_define_label(p_symtab, "$$", |
1436 yasm_section_bcs_first(cursect), 0, cur_line); | 1486 yasm_section_bcs_first(cursect), 0, cur_line); |
1437 e = p_expr_new_ident(yasm_expr_sym(sym)); | 1487 e = p_expr_new_ident(yasm_expr_sym(sym)); |
1438 } | 1488 } |
1439 break; | 1489 break; |
1440 default: | 1490 default: |
1441 return NULL; | 1491 return NULL; |
1442 } | 1492 } |
| 1493 |
1443 get_next_token(); | 1494 get_next_token(); |
1444 return e; | 1495 return e; |
1445 } | 1496 } |
1446 | 1497 |
1447 static void | 1498 static void |
1448 set_nonlocal_label(yasm_parser_nasm *parser_nasm, const char *name) | 1499 set_nonlocal_label(yasm_parser_nasm *parser_nasm, const char *name) |
1449 { | 1500 { |
1450 if (!parser_nasm->tasm || tasm_locals) { | 1501 if (!parser_nasm->tasm || tasm_locals) { |
1451 if (parser_nasm->locallabel_base) | 1502 if (parser_nasm->locallabel_base) |
1452 yasm_xfree(parser_nasm->locallabel_base); | 1503 yasm_xfree(parser_nasm->locallabel_base); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1599 if (cursect) { | 1650 if (cursect) { |
1600 /* In case cursect changed or a bytecode was added, update prev_bc. */ | 1651 /* In case cursect changed or a bytecode was added, update prev_bc. */ |
1601 parser_nasm->prev_bc = yasm_section_bcs_last(cursect); | 1652 parser_nasm->prev_bc = yasm_section_bcs_last(cursect); |
1602 } | 1653 } |
1603 | 1654 |
1604 if (valparams) | 1655 if (valparams) |
1605 yasm_vps_delete(valparams); | 1656 yasm_vps_delete(valparams); |
1606 if (objext_valparams) | 1657 if (objext_valparams) |
1607 yasm_vps_delete(objext_valparams); | 1658 yasm_vps_delete(objext_valparams); |
1608 } | 1659 } |
| 1660 |
| 1661 yasm_bytecode * |
| 1662 gas_intel_syntax_parse_instr(yasm_parser_nasm *parser_nasm, unsigned char *instr
) |
| 1663 { |
| 1664 yasm_bytecode *bc = NULL; |
| 1665 char *sinstr = (char *) instr; |
| 1666 |
| 1667 parser_nasm->s.bot = instr; |
| 1668 parser_nasm->s.tok = instr; |
| 1669 parser_nasm->s.ptr = instr; |
| 1670 parser_nasm->s.cur = instr; |
| 1671 parser_nasm->s.lim = instr + strlen(sinstr) + 1; |
| 1672 parser_nasm->s.top = parser_nasm->s.lim; |
| 1673 parser_nasm->peek_token = NONE; |
| 1674 |
| 1675 get_next_token(); |
| 1676 if (!is_eol()) { |
| 1677 bc = parse_instr(parser_nasm); |
| 1678 } |
| 1679 |
| 1680 return bc; |
| 1681 } |
OLD | NEW |