| OLD | NEW |
| 1 /* | 1 /* |
| 2 * NASM-compatible re2c lexer | 2 * NASM-compatible re2c lexer |
| 3 * | 3 * |
| 4 * Copyright (C) 2001-2007 Peter Johnson | 4 * Copyright (C) 2001-2007 Peter Johnson |
| 5 * | 5 * |
| 6 * Portions based on re2c's example code. | 6 * Portions based on re2c's example code. |
| 7 * | 7 * |
| 8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
| 10 * are met: | 10 * are met: |
| 11 * 1. Redistributions of source code must retain the above copyright | 11 * 1. Redistributions of source code must retain the above copyright |
| 12 * notice, this list of conditions and the following disclaimer. | 12 * notice, this list of conditions and the following disclaimer. |
| 13 * 2. Redistributions in binary form must reproduce the above copyright | 13 * 2. Redistributions in binary form must reproduce the above copyright |
| 14 * notice, this list of conditions and the following disclaimer in the | 14 * notice, this list of conditions and the following disclaimer in the |
| 15 * documentation and/or other materials provided with the distribution. | 15 * documentation and/or other materials provided with the distribution. |
| 16 * | 16 * |
| 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' | 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' |
| 18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE | 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE |
| 21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 27 * POSSIBILITY OF SUCH DAMAGE. | 27 * POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 #include <util.h> | 29 #include <util.h> |
| 30 RCSID("$Id: nasm-token.re 2139 2008-10-08 05:19:47Z peter $"); | 30 RCSID("$Id: nasm-token.re 2277 2010-01-19 07:03:15Z peter $"); |
| 31 | 31 |
| 32 #include <libyasm.h> | 32 #include <libyasm.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 | 37 |
| 38 #define YYCURSOR cursor | 38 #define YYCURSOR cursor |
| 39 #define YYLIMIT (s->lim) | 39 #define YYLIMIT (s->lim) |
| 40 #define YYMARKER (s->ptr) | 40 #define YYMARKER (s->ptr) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 { | 77 { |
| 78 /* check for special non-local labels like ..start */ | 78 /* check for special non-local labels like ..start */ |
| 79 if (tok[zeropos+1] == '.') { | 79 if (tok[zeropos+1] == '.') { |
| 80 lvalp->str_val = yasm__xstrndup(tok+zeropos+(parser_nasm->tasm?2:0), | 80 lvalp->str_val = yasm__xstrndup(tok+zeropos+(parser_nasm->tasm?2:0), |
| 81 toklen-zeropos-(parser_nasm->tasm?2:0)); | 81 toklen-zeropos-(parser_nasm->tasm?2:0)); |
| 82 /* check for special non-local ..@label */ | 82 /* check for special non-local ..@label */ |
| 83 if (lvalp->str_val[zeropos+2] == '@') | 83 if (lvalp->str_val[zeropos+2] == '@') |
| 84 return NONLOCAL_ID; | 84 return NONLOCAL_ID; |
| 85 return SPECIAL_ID; | 85 return SPECIAL_ID; |
| 86 } | 86 } |
| 87 if (parser_nasm->masm && tok[zeropos] == '.') { |
| 88 lvalp->str_val = yasm__xstrndup(tok + zeropos, toklen - zeropos); |
| 89 return SPECIAL_ID; |
| 90 } |
| 87 if (parser_nasm->tasm && (!tasm_locals || | 91 if (parser_nasm->tasm && (!tasm_locals || |
| 88 (tok[zeropos] == '.' && | 92 (tok[zeropos] == '.' && |
| 89 tok[zeropos+1] != '@' && tok[zeropos+2] != '@'))) { | 93 tok[zeropos+1] != '@' && tok[zeropos+2] != '@'))) { |
| 90 /* no locals on Tasm without the 'locals' directive */ | 94 /* no locals on Tasm without the 'locals' directive */ |
| 91 /* .foo is never local either, but .@@foo may be (local structure | 95 /* .foo is never local either, but .@@foo may be (local structure |
| 92 * members) */ | 96 * members) */ |
| 93 lvalp->str_val = yasm__xstrndup(tok + zeropos, toklen - zeropos); | 97 lvalp->str_val = yasm__xstrndup(tok + zeropos, toklen - zeropos); |
| 94 return SPECIAL_ID; | 98 return SPECIAL_ID; |
| 95 } | 99 } |
| 96 if (!parser_nasm->locallabel_base) { | 100 if (!parser_nasm->locallabel_base) { |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 (p_object->arch, TOK, TOKLEN, &lvalp->arch_data)) { | 413 (p_object->arch, TOK, TOKLEN, &lvalp->arch_data)) { |
| 410 case YASM_ARCH_REG: | 414 case YASM_ARCH_REG: |
| 411 s->tok[TOKLEN] = savech; | 415 s->tok[TOKLEN] = savech; |
| 412 RETURN(REG); | 416 RETURN(REG); |
| 413 case YASM_ARCH_SEGREG: | 417 case YASM_ARCH_SEGREG: |
| 414 s->tok[TOKLEN] = savech; | 418 s->tok[TOKLEN] = savech; |
| 415 RETURN(SEGREG); | 419 RETURN(SEGREG); |
| 416 case YASM_ARCH_TARGETMOD: | 420 case YASM_ARCH_TARGETMOD: |
| 417 s->tok[TOKLEN] = savech; | 421 s->tok[TOKLEN] = savech; |
| 418 RETURN(TARGETMOD); | 422 RETURN(TARGETMOD); |
| 423 case YASM_ARCH_REGGROUP: |
| 424 if (parser_nasm->masm) { |
| 425 s->tok[TOKLEN] = savech; |
| 426 RETURN(REGGROUP); |
| 427 } |
| 419 default: | 428 default: |
| 420 break; | 429 break; |
| 421 } | 430 } |
| 422 if (parser_nasm->tasm) { | 431 if (parser_nasm->masm) { |
| 432 if (!yasm__strcasecmp(TOK, "offset")) { |
| 433 s->tok[TOKLEN] = savech; |
| 434 RETURN(OFFSET); |
| 435 } |
| 436 } else if (parser_nasm->tasm) { |
| 423 if (!yasm__strcasecmp(TOK, "shl")) { | 437 if (!yasm__strcasecmp(TOK, "shl")) { |
| 424 s->tok[TOKLEN] = savech; | 438 s->tok[TOKLEN] = savech; |
| 425 RETURN(LEFT_OP); | 439 RETURN(LEFT_OP); |
| 426 } | 440 } |
| 427 if (!yasm__strcasecmp(TOK, "shr")) { | 441 if (!yasm__strcasecmp(TOK, "shr")) { |
| 428 s->tok[TOKLEN] = savech; | 442 s->tok[TOKLEN] = savech; |
| 429 RETURN(RIGHT_OP); | 443 RETURN(RIGHT_OP); |
| 430 } | 444 } |
| 431 if (!yasm__strcasecmp(TOK, "and")) { | 445 if (!yasm__strcasecmp(TOK, "and")) { |
| 432 s->tok[TOKLEN] = savech; | 446 s->tok[TOKLEN] = savech; |
| 433 RETURN('&'); | 447 RETURN('&'); |
| 434 } | 448 } |
| 435 if (!yasm__strcasecmp(TOK, "or")) { | 449 if (!yasm__strcasecmp(TOK, "or")) { |
| 436 s->tok[TOKLEN] = savech; | 450 s->tok[TOKLEN] = savech; |
| 437 RETURN('|'); | 451 RETURN('|'); |
| 438 } | 452 } |
| 453 if (!yasm__strcasecmp(TOK, "not")) { |
| 454 s->tok[TOKLEN] = savech; |
| 455 RETURN('~'); |
| 456 } |
| 439 if (!yasm__strcasecmp(TOK, "low")) { | 457 if (!yasm__strcasecmp(TOK, "low")) { |
| 440 s->tok[TOKLEN] = savech; | 458 s->tok[TOKLEN] = savech; |
| 441 RETURN(LOW); | 459 RETURN(LOW); |
| 442 } | 460 } |
| 443 if (!yasm__strcasecmp(TOK, "high")) { | 461 if (!yasm__strcasecmp(TOK, "high")) { |
| 444 s->tok[TOKLEN] = savech; | 462 s->tok[TOKLEN] = savech; |
| 445 RETURN(HIGH); | 463 RETURN(HIGH); |
| 446 } | 464 } |
| 447 if (!yasm__strcasecmp(TOK, "offset")) { | 465 if (!yasm__strcasecmp(TOK, "offset")) { |
| 448 s->tok[TOKLEN] = savech; | 466 s->tok[TOKLEN] = savech; |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 stringconst_end: | 787 stringconst_end: |
| 770 strbuf[count] = '\0'; | 788 strbuf[count] = '\0'; |
| 771 lvalp->str.contents = (char *)strbuf; | 789 lvalp->str.contents = (char *)strbuf; |
| 772 lvalp->str.len = count; | 790 lvalp->str.len = count; |
| 773 RETURN(STRING); | 791 RETURN(STRING); |
| 774 | 792 |
| 775 endofinput: | 793 endofinput: |
| 776 parser_nasm->state = INITIAL; | 794 parser_nasm->state = INITIAL; |
| 777 RETURN(s->tok[0]); | 795 RETURN(s->tok[0]); |
| 778 } | 796 } |
| OLD | NEW |