145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* 245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * NASM-compatible re2c lexer 345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Copyright (C) 2001-2007 Peter Johnson 545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Portions based on re2c's example code. 745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Redistribution and use in source and binary forms, with or without 945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * modification, are permitted provided that the following conditions 1045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * are met: 1145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 1. Redistributions of source code must retain the above copyright 1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer. 1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 2. Redistributions in binary form must reproduce the above copyright 1445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer in the 1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * documentation and/or other materials provided with the distribution. 1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' 1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE 2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * POSSIBILITY OF SUCH DAMAGE. 2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include <util.h> 3045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include <libyasm.h> 3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "modules/parsers/nasm/nasm-parser.h" 3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "modules/preprocs/nasm/nasm.h" 3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YYCURSOR cursor 3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YYLIMIT (s->lim) 3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YYMARKER (s->ptr) 4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YYFILL(n) {} 4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define RETURN(i) {s->cur = cursor; parser_nasm->tokch = s->tok[0]; \ 4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return i;} 4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define SCANINIT() {s->tok = cursor;} 4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define TOK ((char *)s->tok) 4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define TOKLEN (size_t)(cursor-s->tok) 4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* starting size of string buffer */ 5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define STRBUF_ALLOC_SIZE 128 5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* string buffer used when parsing strings/character constants */ 5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic YYCTYPE *strbuf = NULL; 5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* length of strbuf (including terminating NULL character) */ 5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic size_t strbuf_size = 0; 5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic int linechg_numcount; 6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*!re2c 6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org any = [\001-\377]; 6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org digit = [0-9]; 6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org iletter = [a-zA-Z]; 6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bindigit = [01_]; 6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org octdigit = [0-7_]; 6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org hexdigit = [0-9a-fA-F_]; 6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ws = [ \t\r]; 7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org quot = ["']; 7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org*/ 7245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 7345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic int 7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orghandle_dot_label(YYSTYPE *lvalp, char *tok, size_t toklen, size_t zeropos, 7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_parser_nasm *parser_nasm) 7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* check for special non-local labels like ..start */ 7845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (tok[zeropos+1] == '.') { 7945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str_val = yasm__xstrndup(tok+zeropos+(parser_nasm->tasm?2:0), 8045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org toklen-zeropos-(parser_nasm->tasm?2:0)); 8145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* check for special non-local ..@label */ 8245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (lvalp->str_val[zeropos+2] == '@') 8345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return NONLOCAL_ID; 8445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return SPECIAL_ID; 8545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 86a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org if (parser_nasm->masm && tok[zeropos] == '.') { 87a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org lvalp->str_val = yasm__xstrndup(tok + zeropos, toklen - zeropos); 88a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org return SPECIAL_ID; 89a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org } 9045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (parser_nasm->tasm && (!tasm_locals || 9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (tok[zeropos] == '.' && 9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org tok[zeropos+1] != '@' && tok[zeropos+2] != '@'))) { 9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* no locals on Tasm without the 'locals' directive */ 9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* .foo is never local either, but .@@foo may be (local structure 9545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * members) */ 9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str_val = yasm__xstrndup(tok + zeropos, toklen - zeropos); 9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return SPECIAL_ID; 9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 9945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (!parser_nasm->locallabel_base) { 10045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str_val = yasm__xstrndup(tok+zeropos, toklen-zeropos); 10145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_warn_set(YASM_WARN_GENERAL, 10245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org N_("no non-local label before `%s'"), 10345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str_val); 10445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } else { 10545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org size_t len = toklen - zeropos + parser_nasm->locallabel_base_len; 10645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str_val = yasm_xmalloc(len + 1); 10745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strcpy(lvalp->str_val, parser_nasm->locallabel_base); 10845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strncat(lvalp->str_val, tok+zeropos, toklen-zeropos); 10945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str_val[len] = '\0'; 11045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 11145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return LOCAL_ID; 11345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 11445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint 11645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgnasm_parser_lex(YYSTYPE *lvalp, yasm_parser_nasm *parser_nasm) 11745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 11845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_scanner *s = &parser_nasm->s; 11945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YYCTYPE *cursor = s->cur; 12045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YYCTYPE endch; 12145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org size_t count; 12245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YYCTYPE savech; 12345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 12445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* Handle one token of lookahead */ 12545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (parser_nasm->peek_token != NONE) { 12645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int tok = parser_nasm->peek_token; 12745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *lvalp = parser_nasm->peek_tokval; /* structure copy */ 12845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->tokch = parser_nasm->peek_tokch; 12945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->peek_token = NONE; 13045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return tok; 13145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 13245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 13345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* Catch EOL (EOF from the scanner perspective) */ 13445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (s->eof && cursor == s->eof) 13545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return 0; 13645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 13745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* Jump to proper "exclusive" states */ 13845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org switch (parser_nasm->state) { 13945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case DIRECTIVE: 14045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto directive; 14145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case SECTION_DIRECTIVE: 14245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto section_directive; 14345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case DIRECTIVE2: 14445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto directive2; 14545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case LINECHG: 14645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto linechg; 14745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case LINECHG2: 14845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto linechg2; 14945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org default: 15045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org break; 15145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 15245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 15345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgscan: 15445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SCANINIT(); 15545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (*cursor == '\0') 15645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto endofinput; 15745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 15845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*!re2c 15945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* standard decimal integer */ 16045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org digit+ { 16145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org savech = s->tok[TOKLEN]; 16245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = '\0'; 16345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_dec(TOK); 16445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 16545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(INTNUM); 16645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 16745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* 10010011b - binary number */ 16845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 16945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [01] bindigit* 'b' { 17045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN-1] = '\0'; /* strip off 'b' */ 17145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_bin(TOK); 17245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(INTNUM); 17345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 17445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 17545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* 777q or 777o - octal number */ 17645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [0-7] octdigit* [qQoO] { 17745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN-1] = '\0'; /* strip off 'q' or 'o' */ 17845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_oct(TOK); 17945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(INTNUM); 18045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 18145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 18245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* 0AAh form of hexidecimal number */ 18345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org digit hexdigit* 'h' { 18445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN-1] = '\0'; /* strip off 'h' */ 18545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_hex(TOK); 18645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(INTNUM); 18745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 18845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 18945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* $0AA and 0xAA forms of hexidecimal number */ 19045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (("$" digit) | '0x') hexdigit+ { 19145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org savech = s->tok[TOKLEN]; 19245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = '\0'; 19345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (s->tok[1] == 'x' || s->tok[1] == 'X') 19445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* skip 0 and x */ 19545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_hex(TOK+2); 19645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org else 19745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* don't skip 0 */ 19845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_hex(TOK+1); 19945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 20045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(INTNUM); 20145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 20245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 20345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* floating point value */ 20445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org digit+ "." digit* ('e' [-+]? digit+)? { 20545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org savech = s->tok[TOKLEN]; 20645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = '\0'; 20745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->flt = yasm_floatnum_create(TOK); 20845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 20945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(FLTNUM); 21045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 21145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 21245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* string/character constant values */ 21345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org quot { 21445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org endch = s->tok[0]; 21545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto stringconst; 21645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 21745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 21845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* %line linenum+lineinc filename */ 21945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "%line" { 22045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = LINECHG; 22145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org linechg_numcount = 0; 22245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(LINE); 22345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 22445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 22545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* size specifiers */ 22645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'byte' { lvalp->int_info = 8; RETURN(SIZE_OVERRIDE); } 22745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'hword' { 22845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)/2; 22945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(SIZE_OVERRIDE); 23045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 23145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'word' { 23245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch); 23345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(SIZE_OVERRIDE); 23445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 23545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'dword' | 'long' { 23645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)*2; 23745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(SIZE_OVERRIDE); 23845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 23945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'qword' { 24045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)*4; 24145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(SIZE_OVERRIDE); 24245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 24345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'tword' { lvalp->int_info = 80; RETURN(SIZE_OVERRIDE); } 24445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'dqword' { 24545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8; 24645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(SIZE_OVERRIDE); 24745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 24845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'oword' { 24945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8; 25045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(SIZE_OVERRIDE); 25145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 25245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'yword' { 25345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = 256; 25445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(SIZE_OVERRIDE); 25545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 25645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 25745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* pseudo-instructions */ 25845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'db' { 25945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = 8; 26045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 26145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(DECLARE_DATA); 26245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 26345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'dhw' { 26445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)/2; 26545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 26645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(DECLARE_DATA); 26745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 26845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'dw' { 26945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch); 27045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 27145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(DECLARE_DATA); 27245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 27345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'dd' { 27445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)*2; 27545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 27645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(DECLARE_DATA); 27745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 27845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'dq' { 27945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)*4; 28045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 28145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(DECLARE_DATA); 28245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 28345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'dt' { 28445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = 80; 28545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 28645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(DECLARE_DATA); 28745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 28845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'ddq' { 28945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8; 29045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 29145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(DECLARE_DATA); 29245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 29345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'do' { 29445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8; 29545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 29645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(DECLARE_DATA); 29745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 29845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'dy' { 29945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = 256; 30045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 30145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(DECLARE_DATA); 30245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 30345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 30445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'resb' { 30545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = 8; 30645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 30745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(RESERVE_SPACE); 30845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 30945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'reshw' { 31045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)/2; 31145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 31245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(RESERVE_SPACE); 31345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 31445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'resw' { 31545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch); 31645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 31745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(RESERVE_SPACE); 31845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 31945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'resd' { 32045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)*2; 32145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 32245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(RESERVE_SPACE); 32345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 32445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'resq' { 32545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)*4; 32645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 32745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(RESERVE_SPACE); 32845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 32945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'rest' { 33045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = 80; 33145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 33245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(RESERVE_SPACE); 33345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 33445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'resdq' { 33545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8; 33645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 33745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(RESERVE_SPACE); 33845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 33945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'reso' { 34045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8; 34145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 34245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(RESERVE_SPACE); 34345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 34445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'resy' { 34545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = 256; 34645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 34745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(RESERVE_SPACE); 34845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 34945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 35045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'incbin' { RETURN(INCBIN); } 35145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 35245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'equ' { RETURN(EQU); } 35345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 35445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'times' { RETURN(TIMES); } 35545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 35645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'seg' { RETURN(SEG); } 35745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'wrt' { RETURN(WRT); } 35845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 35945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'abs' { RETURN(ABS); } 36045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'rel' { RETURN(REL); } 36145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 36245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'nosplit' { RETURN(NOSPLIT); } 36345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 'strict' { RETURN(STRICT); } 36445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 36545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* operators */ 36645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "<<" { RETURN(LEFT_OP); } 36745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ">>" { RETURN(RIGHT_OP); } 36845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "//" { RETURN(SIGNDIV); } 36945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "%%" { RETURN(SIGNMOD); } 37045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "$$" { RETURN(START_SECTION_ID); } 37145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [-+|^*&/%~$():=,\[?] { RETURN(s->tok[0]); } 37245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "]" { RETURN(s->tok[0]); } 37345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 37445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* local label (.label) */ 37545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ("." | "@@") [a-zA-Z0-9_$#@~.?]+ { 37645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(handle_dot_label(lvalp, TOK, TOKLEN, 0, parser_nasm)); 37745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 37845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 37945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* forced identifier */ 38045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "$" [a-zA-Z0-9_$#@~.?]+ { 38145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (TOK[1] == '.' || 38245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (parser_nasm->tasm && TOK[1] == '@' && TOK[2] == '@')) { 38345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* handle like .label */ 38445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(handle_dot_label(lvalp, TOK, TOKLEN, 1, parser_nasm)); 38545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 38645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str_val = yasm__xstrndup(TOK+1, TOKLEN-1); 38745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(ID); 38845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 38945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 39045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* identifier that may be a register, instruction, etc. */ 39145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [a-zA-Z_?@][a-zA-Z0-9_$#@~.?]* { 39245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org savech = s->tok[TOKLEN]; 39345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = '\0'; 39445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (parser_nasm->state != INSTRUCTION) { 39545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org uintptr_t prefix; 39645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org switch (yasm_arch_parse_check_insnprefix 39745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (p_object->arch, TOK, TOKLEN, cur_line, &lvalp->bc, 39845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org &prefix)) { 39945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case YASM_ARCH_INSN: 40045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 40145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 40245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(INSN); 40345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case YASM_ARCH_PREFIX: 40445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->arch_data = prefix; 40545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 40645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(PREFIX); 40745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org default: 40845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org break; 40945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 41045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 41145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org switch (yasm_arch_parse_check_regtmod 41245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (p_object->arch, TOK, TOKLEN, &lvalp->arch_data)) { 41345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case YASM_ARCH_REG: 41445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 41545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(REG); 41645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case YASM_ARCH_SEGREG: 41745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 41845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(SEGREG); 41945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case YASM_ARCH_TARGETMOD: 42045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 42145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(TARGETMOD); 422a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org case YASM_ARCH_REGGROUP: 423a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org if (parser_nasm->masm) { 424a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org s->tok[TOKLEN] = savech; 425a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org RETURN(REGGROUP); 426a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org } 42745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org default: 42845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org break; 42945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 430a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org if (parser_nasm->masm) { 431a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org if (!yasm__strcasecmp(TOK, "offset")) { 432a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org s->tok[TOKLEN] = savech; 433a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org RETURN(OFFSET); 434a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org } 435a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org } else if (parser_nasm->tasm) { 43645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (!yasm__strcasecmp(TOK, "shl")) { 43745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 43845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(LEFT_OP); 43945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 44045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (!yasm__strcasecmp(TOK, "shr")) { 44145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 44245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(RIGHT_OP); 44345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 44445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (!yasm__strcasecmp(TOK, "and")) { 44545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 44645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN('&'); 44745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 44845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (!yasm__strcasecmp(TOK, "or")) { 44945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 45045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN('|'); 45145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 452a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org if (!yasm__strcasecmp(TOK, "not")) { 453a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org s->tok[TOKLEN] = savech; 454a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org RETURN('~'); 455a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org } 45645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (!yasm__strcasecmp(TOK, "low")) { 45745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 45845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(LOW); 45945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 46045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (!yasm__strcasecmp(TOK, "high")) { 46145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 46245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(HIGH); 46345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 46445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (!yasm__strcasecmp(TOK, "offset")) { 46545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 46645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(OFFSET); 46745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 46845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (!yasm__strcasecmp(TOK, "fword")) { 46945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 47045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)*2; 47145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(SIZE_OVERRIDE); 47245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 47345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (!yasm__strcasecmp(TOK, "df")) { 47445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 47545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->int_info = yasm_arch_wordsize(p_object->arch)*3; 47645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INSTRUCTION; 47745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(DECLARE_DATA); 47845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 47945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (!yasm__strcasecmp(TOK, "label")) { 48045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 48145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(LABEL); 48245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 48345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (!yasm__strcasecmp(TOK, "dup")) { 48445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 48545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(DUP); 48645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 48745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 48845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* Propagate errors in case we got a warning from the arch */ 48945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_errwarn_propagate(parser_nasm->errwarns, cur_line); 49045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* Just an identifier, return as such. */ 49145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 49245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str_val = yasm__xstrndup(TOK, TOKLEN); 49345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(ID); 49445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 49545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 49645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ";" (any \ [\000])* { goto scan; } 49745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 49845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ws+ { goto scan; } 49945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 50045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [\000] { goto endofinput; } 50145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 50245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org any { 50345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_warn_set(YASM_WARN_UNREC_CHAR, 50445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org N_("ignoring unrecognized character `%s'"), 50545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm__conv_unprint(s->tok[0])); 50645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto scan; 50745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 50845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 50945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 51045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* %line linenum+lineinc filename */ 51145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orglinechg: 51245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SCANINIT(); 51345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (*cursor == '\0') 51445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto endofinput; 51545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 51645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*!re2c 51745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org digit+ { 51845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org linechg_numcount++; 51945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org savech = s->tok[TOKLEN]; 52045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = '\0'; 52145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_dec(TOK); 52245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 52345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(INTNUM); 52445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 52545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 52645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [\000] { goto endofinput; } 52745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 52845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "+" { 52945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(s->tok[0]); 53045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 53145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 53245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ws+ { 53345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (linechg_numcount == 2) { 53445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = LINECHG2; 53545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto linechg2; 53645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 53745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto linechg; 53845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 53945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 54045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org any { 54145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_warn_set(YASM_WARN_UNREC_CHAR, 54245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org N_("ignoring unrecognized character `%s'"), 54345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm__conv_unprint(s->tok[0])); 54445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto linechg; 54545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 54645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 54745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 54845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orglinechg2: 54945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SCANINIT(); 55045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (*cursor == '\0') 55145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto endofinput; 55245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 55345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*!re2c 55445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [\000] { goto endofinput; } 55545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 55645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "\r" { goto linechg2; } 55745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 55845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (any \ [\000])+ { 55945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = LINECHG; 56045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str_val = yasm__xstrndup(TOK, TOKLEN); 56145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(FILENAME); 56245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 56345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 56445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 56545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* directive: [name value] */ 56645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgdirective: 56745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SCANINIT(); 56845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (*cursor == '\0') 56945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto endofinput; 57045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 57145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*!re2c 57245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [\]\000] { goto endofinput; } 57345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 57445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [a-zA-Z_][a-zA-Z_0-9]* { 57545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str_val = yasm__xstrndup(TOK, TOKLEN); 57645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (yasm__strcasecmp(lvalp->str_val, "section") == 0 || 57745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm__strcasecmp(lvalp->str_val, "segment") == 0) 57845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = SECTION_DIRECTIVE; 57945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org else 58045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = DIRECTIVE2; 58145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(DIRECTIVE_NAME); 58245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 58345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 58445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org any { 58545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_warn_set(YASM_WARN_UNREC_CHAR, 58645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org N_("ignoring unrecognized character `%s'"), 58745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm__conv_unprint(s->tok[0])); 58845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto directive; 58945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 59045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 59145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 59245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* section directive (the section name portion thereof) */ 59345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgsection_directive: 59445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SCANINIT(); 59545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (*cursor == '\0') 59645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto endofinput; 59745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 59845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*!re2c 59945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [a-zA-Z0-9_$#@~.?-]+ { 60045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.contents = yasm__xstrndup(TOK, TOKLEN); 60145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.len = TOKLEN; 60245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = DIRECTIVE2; 60345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(STRING); 60445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 60545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 60645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org quot { 60745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = DIRECTIVE2; 60845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org endch = s->tok[0]; 60945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto stringconst; 61045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 61145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 61245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ws+ { 61345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = DIRECTIVE2; 61445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto section_directive; 61545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 61645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 61745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [\]\000] { goto endofinput; } 61845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 61945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org any { 62045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_warn_set(YASM_WARN_UNREC_CHAR, 62145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org N_("ignoring unrecognized character `%s'"), 62245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm__conv_unprint(s->tok[0])); 62345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto section_directive; 62445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 62545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 62645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 62745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* inner part of directive */ 62845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgdirective2: 62945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SCANINIT(); 63045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (*cursor == '\0') 63145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto endofinput; 63245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 63345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*!re2c 63445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* standard decimal integer */ 63545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org digit+ { 63645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org savech = s->tok[TOKLEN]; 63745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = '\0'; 63845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_dec(TOK); 63945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 64045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(INTNUM); 64145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 64245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* 10010011b - binary number */ 64345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 64445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [01] bindigit* 'b' { 64545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN-1] = '\0'; /* strip off 'b' */ 64645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_bin(TOK); 64745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(INTNUM); 64845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 64945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 65045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* 777q or 777o - octal number */ 65145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [0-7] octdigit* [qQoO] { 65245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN-1] = '\0'; /* strip off 'q' or 'o' */ 65345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_oct(TOK); 65445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(INTNUM); 65545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 65645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 65745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* 0AAh form of hexidecimal number */ 65845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org digit hexdigit* 'h' { 65945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN-1] = '\0'; /* strip off 'h' */ 66045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_hex(TOK); 66145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(INTNUM); 66245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 66345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 66445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* $0AA and 0xAA forms of hexidecimal number */ 66545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (("$" digit) | '0x') hexdigit+ { 66645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org savech = s->tok[TOKLEN]; 66745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = '\0'; 66845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (s->tok[1] == 'x' || s->tok[1] == 'X') 66945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* skip 0 and x */ 67045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_hex(TOK+2); 67145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org else 67245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* don't skip 0 */ 67345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_hex(TOK+1); 67445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 67545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(INTNUM); 67645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 67745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 67845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* string/character constant values */ 67945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org quot { 68045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org endch = s->tok[0]; 68145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto stringconst; 68245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 68345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 68445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* operators */ 68545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "<<" { RETURN(LEFT_OP); } 68645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ">>" { RETURN(RIGHT_OP); } 68745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "//" { RETURN(SIGNDIV); } 68845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "%%" { RETURN(SIGNMOD); } 68945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [-+|^*&/%~$():=,\[] { RETURN(s->tok[0]); } 69045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 69145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* handle ] for directives */ 69245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "]" { goto endofinput; } 69345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 69445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* forced identifier; within directive, don't strip '$', this is 69545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * handled later. 69645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 69745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "$" [a-zA-Z0-9_$#@~.?]+ { 69845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str_val = yasm__xstrndup(TOK, TOKLEN); 69945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(ID); 70045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 70145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 70245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* identifier; within directive, no local label mechanism */ 70345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [a-zA-Z_.?][a-zA-Z0-9_$#@~.?]* { 70445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org savech = s->tok[TOKLEN]; 70545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = '\0'; 70645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org switch (yasm_arch_parse_check_regtmod 70745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (p_object->arch, TOK, TOKLEN, &lvalp->arch_data)) { 70845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case YASM_ARCH_REG: 70945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 71045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(REG); 71145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org default: 71245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 71345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 71445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* Propagate errors in case we got a warning from the arch */ 71545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_errwarn_propagate(parser_nasm->errwarns, cur_line); 71645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* Just an identifier, return as such. */ 71745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str_val = yasm__xstrndup(TOK, TOKLEN); 71845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(ID); 71945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 72045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 72145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ";" (any \ [\000])* { goto directive2; } 72245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 72345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ws+ { goto directive2; } 72445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 72545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [\000] { goto endofinput; } 72645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 72745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org any { 72845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_warn_set(YASM_WARN_UNREC_CHAR, 72945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org N_("ignoring unrecognized character `%s'"), 73045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm__conv_unprint(s->tok[0])); 73145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto scan; 73245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 73345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 73445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 73545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* string/character constant values */ 73645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstringconst: 73745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf = yasm_xmalloc(STRBUF_ALLOC_SIZE); 73845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf_size = STRBUF_ALLOC_SIZE; 73945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org count = 0; 74045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 74145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstringconst_scan: 74245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SCANINIT(); 74345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (*cursor == '\0') 74445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto stringconst_error; 74545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 74645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*!re2c 74745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [\000] { goto stringconst_error; } 74845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 74945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "''" | '""' { 75045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (endch != s->tok[0]) { 75145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf[count++] = s->tok[0]; 75245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (count >= strbuf_size) { 75345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf = yasm_xrealloc(strbuf, 75445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf_size + STRBUF_ALLOC_SIZE); 75545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf_size += STRBUF_ALLOC_SIZE; 75645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 75745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } else if (!parser_nasm->tasm) { 75845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YYCURSOR--; 75945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto stringconst_end; 76045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 76145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf[count++] = s->tok[0]; 76245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (count >= strbuf_size) { 76345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf = yasm_xrealloc(strbuf, strbuf_size + STRBUF_ALLOC_SIZE); 76445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf_size += STRBUF_ALLOC_SIZE; 76545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 76645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto stringconst_scan; 76745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 76845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 76945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org any { 77045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (s->tok[0] == endch) 77145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto stringconst_end; 77245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 77345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf[count++] = s->tok[0]; 77445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (count >= strbuf_size) { 77545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf = yasm_xrealloc(strbuf, strbuf_size + STRBUF_ALLOC_SIZE); 77645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf_size += STRBUF_ALLOC_SIZE; 77745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 77845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 77945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto stringconst_scan; 78045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 78145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 78245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 78345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstringconst_error: 78445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_error_set(YASM_ERROR_SYNTAX, N_("unterminated string")); 78545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 78645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstringconst_end: 78745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf[count] = '\0'; 78845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.contents = (char *)strbuf; 78945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.len = count; 79045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(STRING); 79145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 79245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgendofinput: 79345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_nasm->state = INITIAL; 79445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(s->tok[0]); 79545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 796