145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* 245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * GAS-compatible re2c lexer 345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Copyright (C) 2005-2007 Peter Johnson 545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Redistribution and use in source and binary forms, with or without 745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * modification, are permitted provided that the following conditions 845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * are met: 945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 1. Redistributions of source code must retain the above copyright 1045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer. 1145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 2. Redistributions in binary form must reproduce the above copyright 1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer in the 1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * documentation and/or other materials provided with the distribution. 1445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 3. Neither the name of the author nor the names of other contributors 1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * may be used to endorse or promote products derived from this 1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * software without specific prior written permission. 1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' 1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE 2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * POSSIBILITY OF SUCH DAMAGE. 2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 3045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include <util.h> 3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include <libyasm.h> 3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "modules/parsers/gas/gas-parser.h" 3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define BSIZE 8192 3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YYCURSOR cursor 4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YYLIMIT (s->lim) 4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YYMARKER (s->ptr) 4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YYFILL(n) {cursor = fill(parser_gas, cursor);} 4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define RETURN(i) do {s->cur = cursor; parser_gas->tokch = s->tok[0]; \ 4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return i;} while (0) 4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define SCANINIT() {s->tok = cursor;} 4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define TOK ((char *)s->tok) 5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define TOKLEN (size_t)(cursor-s->tok) 5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* Bridge function to convert byte-oriented parser with line-oriented 5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * preprocessor. 5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic size_t 5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgpreproc_input(yasm_parser_gas *parser_gas, /*@out@*/ YYCTYPE *buf, 5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org size_t max_size) 5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org size_t tot=0; 6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org while (max_size > 0) { 6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org size_t n; 6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (!parser_gas->line) { 6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->line = yasm_preproc_get_line(parser_gas->preproc); 6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (!parser_gas->line) 6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return tot; /* EOF */ 6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->linepos = parser_gas->line; 6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->lineleft = strlen(parser_gas->line) + 1; 6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->line[parser_gas->lineleft-1] = '\n'; 7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 7245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org n = parser_gas->lineleft<max_size ? parser_gas->lineleft : max_size; 7345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strncpy((char *)buf+tot, parser_gas->linepos, n); 7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (n == parser_gas->lineleft) { 7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_xfree(parser_gas->line); 7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->line = NULL; 7845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } else { 7945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->lineleft -= n; 8045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->linepos += n; 8145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 8245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 8345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org tot += n; 8445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org max_size -= n; 8545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 8645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return tot; 8745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 8845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#if 0 8945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic size_t 9045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgfill_input(void *d, unsigned char *buf, size_t max) 9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return yasm_preproc_input((yasm_preproc *)d, (char *)buf, max); 9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 9545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic YYCTYPE * 9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgfill(yasm_parser_gas *parser_gas, YYCTYPE *cursor) 9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_scanner *s = &parser_gas->s; 9945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int first = 0; 10045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if(!s->eof){ 10145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org size_t cnt = s->tok - s->bot; 10245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if(cnt){ 10345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org memmove(s->bot, s->tok, (size_t)(s->lim - s->tok)); 10445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok = s->bot; 10545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->ptr -= cnt; 10645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org cursor -= cnt; 10745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->lim -= cnt; 10845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 10945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (!s->bot) 11045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org first = 1; 11145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if((s->top - s->lim) < BSIZE){ 11245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YYCTYPE *buf = yasm_xmalloc((size_t)(s->lim - s->bot) + BSIZE); 11345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org memcpy(buf, s->tok, (size_t)(s->lim - s->tok)); 11445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok = buf; 11545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->ptr = &buf[s->ptr - s->bot]; 11645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org cursor = &buf[cursor - s->bot]; 11745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->lim = &buf[s->lim - s->bot]; 11845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->top = &s->lim[BSIZE]; 11945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (s->bot) 12045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_xfree(s->bot); 12145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->bot = buf; 12245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 123a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org if((cnt = preproc_input(parser_gas, s->lim, BSIZE)) == 0) { 12445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->eof = &s->lim[cnt]; *s->eof++ = '\n'; 12545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 12645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->lim += cnt; 12745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (first && parser_gas->save_input) { 12845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int i; 12945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YYCTYPE *saveline; 13045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->save_last ^= 1; 13145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org saveline = parser_gas->save_line[parser_gas->save_last]; 13245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* save next line into cur_line */ 13345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org for (i=0; i<79 && &s->tok[i] < s->lim && s->tok[i] != '\n'; i++) 13445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org saveline[i] = s->tok[i]; 13545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org saveline[i] = '\0'; 13645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 13745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 13845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return cursor; 13945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 14045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 14145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic YYCTYPE * 14245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgsave_line(yasm_parser_gas *parser_gas, YYCTYPE *cursor) 14345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 14445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_scanner *s = &parser_gas->s; 14545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int i = 0; 14645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YYCTYPE *saveline; 14745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 14845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->save_last ^= 1; 14945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org saveline = parser_gas->save_line[parser_gas->save_last]; 15045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 15145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* save next line into cur_line */ 15245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if ((YYLIMIT - YYCURSOR) < 80) 15345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YYFILL(80); 15445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org for (i=0; i<79 && &cursor[i] < s->lim && cursor[i] != '\n'; i++) 15545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org saveline[i] = cursor[i]; 15645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org saveline[i] = '\0'; 15745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return cursor; 15845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 15945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 16045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* starting size of string buffer */ 16145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define STRBUF_ALLOC_SIZE 128 16245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 16345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* string buffer used when parsing strings/character constants */ 16445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic YYCTYPE *strbuf = NULL; 16545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 16645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* length of strbuf (including terminating NULL character) */ 16745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic size_t strbuf_size = 0; 16845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 16945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic void 17045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstrbuf_append(size_t count, YYCTYPE *cursor, yasm_scanner *s, int ch) 17145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 17245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (count >= strbuf_size) { 17345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf = yasm_xrealloc(strbuf, strbuf_size + STRBUF_ALLOC_SIZE); 17445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf_size += STRBUF_ALLOC_SIZE; 17545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 17645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf[count] = ch; 17745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 17845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 17945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*!re2c 18045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org any = [\000-\377]; 18145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org digit = [0-9]; 18245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org iletter = [a-zA-Z]; 18345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org bindigit = [01]; 18445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org octdigit = [0-7]; 18545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org hexdigit = [0-9a-fA-F]; 18645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ws = [ \t\r]; 18745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org dquot = ["]; 18845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org*/ 18945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 19045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 19145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint 19245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orggas_parser_lex(YYSTYPE *lvalp, yasm_parser_gas *parser_gas) 19345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 19445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_scanner *s = &parser_gas->s; 19545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YYCTYPE *cursor = s->cur; 19645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org size_t count; 19745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org YYCTYPE savech; 19845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 19945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* Handle one token of lookahead */ 20045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (parser_gas->peek_token != NONE) { 20145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int tok = parser_gas->peek_token; 20245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *lvalp = parser_gas->peek_tokval; /* structure copy */ 20345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->tokch = parser_gas->peek_tokch; 20445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->peek_token = NONE; 20545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return tok; 20645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 20745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 20845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* Catch EOF */ 20945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (s->eof && cursor == s->eof) 21045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return 0; 21145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 21245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* Jump to proper "exclusive" states */ 21345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org switch (parser_gas->state) { 21445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case COMMENT: 21545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto comment; 21645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case SECTION_DIRECTIVE: 21745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto section_directive; 21845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case NASM_FILENAME: 21945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto nasm_filename; 22045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org default: 22145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org break; 22245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 22345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 22445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgscan: 22545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SCANINIT(); 22645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 22745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*!re2c 22845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* standard decimal integer */ 22945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ([1-9] digit*) | "0" { 23045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org savech = s->tok[TOKLEN]; 23145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = '\0'; 23245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_dec(TOK); 23345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 23445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(INTNUM); 23545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 23645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 23745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* 0b10010011 - binary number */ 23845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org '0b' bindigit+ { 23945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org savech = s->tok[TOKLEN]; 24045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = '\0'; 24145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_bin(TOK+2); 24245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 24345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(INTNUM); 24445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 24545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 24645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* 0777 - octal number */ 24745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "0" octdigit+ { 24845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org savech = s->tok[TOKLEN]; 24945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = '\0'; 25045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_oct(TOK); 25145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 25245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(INTNUM); 25345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 25445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 25545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* 0xAA - hexidecimal number */ 25645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org '0x' hexdigit+ { 25745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org savech = s->tok[TOKLEN]; 25845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = '\0'; 25945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* skip 0 and x */ 26045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->intn = yasm_intnum_create_hex(TOK+2); 26145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 26245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(INTNUM); 26345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 26445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 26545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* floating point value */ 26645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [-+]? digit* "." digit+ ('e' [-+]? digit+)? { 26745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org savech = s->tok[TOKLEN]; 26845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = '\0'; 26945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->flt = yasm_floatnum_create(TOK); 27045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 27145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(FLTNUM); 27245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 27345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [-+]? digit+ "." digit* ('e' [-+]? digit+)? { 27445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org savech = s->tok[TOKLEN]; 27545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = '\0'; 27645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->flt = yasm_floatnum_create(TOK); 27745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 27845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(FLTNUM); 27945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 28045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "0" [DdEeFfTt] [-+]? digit* ("." digit*)? ('e' [-+]? digit+)? { 28145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org savech = s->tok[TOKLEN]; 28245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = '\0'; 28345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->flt = yasm_floatnum_create(TOK+2); 28445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 28545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(FLTNUM); 28645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 28745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 28845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* character constant values */ 28945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ['] { 29045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto charconst; 29145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 29245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 29345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* string constant values */ 29445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org dquot { 29545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto stringconst; 29645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 29745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 29845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* operators */ 29945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "<<" { RETURN(LEFT_OP); } 30045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ">>" { RETURN(RIGHT_OP); } 30145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "<" { RETURN(LEFT_OP); } 30245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ">" { RETURN(RIGHT_OP); } 30345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [-+|^!*&/~$():@=,] { RETURN(s->tok[0]); } 30445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ";" { 30545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->state = INITIAL; 30645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(s->tok[0]); 30745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 30845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 30945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* identifier */ 31045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [a-zA-Z_.][a-zA-Z0-9_$.]* { 31145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.contents = yasm__xstrndup(TOK, TOKLEN); 31245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.len = TOKLEN; 31345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(ID); 31445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 31545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 31645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* identifier with @ */ 31745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [a-zA-Z_.]([a-zA-Z0-9_$.]*[@][a-zA-Z0-9_$.]*)+ { 31845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* if @ not part of ID, move the scanner cursor to the first @ */ 31945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (!((yasm_objfmt_base *)p_object->objfmt)->module->id_at_ok) 32045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org cursor = (unsigned char *)strchr(TOK, '@'); 32145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.contents = yasm__xstrndup(TOK, TOKLEN); 32245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.len = TOKLEN; 32345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(ID); 32445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 32545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 32645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* register or segment register */ 32745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [%][a-zA-Z0-9]+ { 32845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org savech = s->tok[TOKLEN]; 32945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = '\0'; 33045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (parser_gas->is_nasm_preproc && strcmp(TOK+1, "line") == 0) { 33145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 33245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(NASM_LINE_MARKER); 33345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 33445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 33545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org switch (yasm_arch_parse_check_regtmod 33645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (p_object->arch, TOK+1, TOKLEN-1, &lvalp->arch_data)) { 33745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case YASM_ARCH_REG: 33845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 33945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(REG); 34045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case YASM_ARCH_REGGROUP: 34145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 34245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(REGGROUP); 34345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org case YASM_ARCH_SEGREG: 34445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 34545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(SEGREG); 34645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org default: 34745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org break; 34845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 34945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_error_set(YASM_ERROR_GENERAL, 35045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org N_("Unrecognized register name `%s'"), s->tok); 35145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org s->tok[TOKLEN] = savech; 35245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->arch_data = 0; 35345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(REG); 35445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 35545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 35645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* local label */ 35745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [0-9] ':' { 35845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* increment label index */ 35945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->local[s->tok[0]-'0']++; 36045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* build local label name */ 36145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.contents = yasm_xmalloc(30); 36245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.len = 36345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org sprintf(lvalp->str.contents, "L%c\001%lu", s->tok[0], 36445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->local[s->tok[0]-'0']); 36545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(LABEL); 36645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 36745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 36845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* local label forward reference */ 36945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [0-9] 'f' { 37045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* build local label name */ 37145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.contents = yasm_xmalloc(30); 37245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.len = 37345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org sprintf(lvalp->str.contents, "L%c\001%lu", s->tok[0], 37445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->local[s->tok[0]-'0']+1); 37545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(ID); 37645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 37745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 37845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* local label backward reference */ 37945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [0-9] 'b' { 38045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* build local label name */ 38145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.contents = yasm_xmalloc(30); 38245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.len = 38345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org sprintf(lvalp->str.contents, "L%c\001%lu", s->tok[0], 38445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->local[s->tok[0]-'0']); 38545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(ID); 38645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 38745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 38845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "/*" { parser_gas->state = COMMENT; goto comment; } 38945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "#" { 39045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (parser_gas->is_cpp_preproc) 39145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org { 39245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(CPP_LINE_MARKER); 39345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } else 39445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto line_comment; 39545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 396a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org "//" { goto line_comment; } 39745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 39845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ws+ { goto scan; } 39945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 40045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "\n" { 40145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (parser_gas->save_input) 40245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org cursor = save_line(parser_gas, cursor); 40345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->state = INITIAL; 40445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(s->tok[0]); 40545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 40645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 40745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org any { 40845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_warn_set(YASM_WARN_UNREC_CHAR, 40945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org N_("ignoring unrecognized character `%s'"), 41045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm__conv_unprint(s->tok[0])); 41145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto scan; 41245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 41345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 41445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 41545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* C-style comment; nesting not supported */ 41645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgcomment: 41745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SCANINIT(); 41845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 41945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*!re2c 42045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* End of comment */ 42145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "*/" { parser_gas->state = INITIAL; goto scan; } 42245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 42345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "\n" { 42445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (parser_gas->save_input) 42545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org cursor = save_line(parser_gas, cursor); 42645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(s->tok[0]); 42745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 42845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 42945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org any { 43045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (cursor == s->eof) 43145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return 0; 43245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto comment; 43345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 43445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 43545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 43645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* Single line comment. */ 43745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgline_comment: 43845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*!re2c 43945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (any \ [\n])* { goto scan; } 44045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 44145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 44245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* .section directive (the section name portion thereof) */ 44345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgsection_directive: 44445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SCANINIT(); 44545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 44645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*!re2c 44745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org [a-zA-Z0-9_$.-]+ { 44845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.contents = yasm__xstrndup(TOK, TOKLEN); 44945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.len = TOKLEN; 45045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->state = INITIAL; 45145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(ID); 45245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 45345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 45445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org dquot { goto stringconst; } 45545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 45645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ws+ { goto section_directive; } 45745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 45845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "," { 45945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->state = INITIAL; 46045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(s->tok[0]); 46145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 46245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 46345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "\n" { 46445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (parser_gas->save_input) 46545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org cursor = save_line(parser_gas, cursor); 46645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->state = INITIAL; 46745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(s->tok[0]); 46845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 46945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 47045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org any { 47145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_warn_set(YASM_WARN_UNREC_CHAR, 47245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org N_("ignoring unrecognized character `%s'"), 47345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm__conv_unprint(s->tok[0])); 47445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto section_directive; 47545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 47645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 47745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 47845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* filename portion of nasm preproc %line */ 47945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgnasm_filename: 48045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf = yasm_xmalloc(STRBUF_ALLOC_SIZE); 48145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf_size = STRBUF_ALLOC_SIZE; 48245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org count = 0; 48345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 48445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgnasm_filename_scan: 48545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SCANINIT(); 48645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 48745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*!re2c 48845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org "\n" { 48945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf_append(count++, cursor, s, '\0'); 49045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.contents = (char *)strbuf; 49145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.len = count; 49245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->state = INITIAL; 49345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(STRING); 49445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 49545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 49645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ws+ { goto nasm_filename_scan; } 49745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 49845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org any { 49945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (cursor == s->eof) { 50045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf_append(count++, cursor, s, '\0'); 50145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.contents = (char *)strbuf; 50245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.len = count; 50345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org parser_gas->state = INITIAL; 50445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(STRING); 50545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 50645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf_append(count++, cursor, s, s->tok[0]); 50745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto nasm_filename_scan; 50845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 50945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 51045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 51145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* character constant values */ 51245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgcharconst: 51345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*TODO*/ 51445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 51545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* string constant values */ 51645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstringconst: 51745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf = yasm_xmalloc(STRBUF_ALLOC_SIZE); 51845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf_size = STRBUF_ALLOC_SIZE; 51945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org count = 0; 52045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 52145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstringconst_scan: 52245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SCANINIT(); 52345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 52445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*!re2c 525d65182f1818d1c19e6f3866ab6e68a262fad5185hbono@chromium.org /* Handle escaped character by copying both and continuing. */ 526d65182f1818d1c19e6f3866ab6e68a262fad5185hbono@chromium.org "\\". { 52745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (cursor == s->eof) { 52845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_error_set(YASM_ERROR_SYNTAX, 52945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org N_("unexpected end of file in string")); 53045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.contents = (char *)strbuf; 53145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.len = count; 53245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(STRING); 53345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 534d65182f1818d1c19e6f3866ab6e68a262fad5185hbono@chromium.org strbuf_append(count++, cursor, s, '\\'); 535d65182f1818d1c19e6f3866ab6e68a262fad5185hbono@chromium.org strbuf_append(count++, cursor, s, s->tok[1]); 53645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto stringconst_scan; 53745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 53845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 53945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org dquot { 54045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf_append(count, cursor, s, '\0'); 54145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_unescape_cstring(strbuf, &count); 54245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.contents = (char *)strbuf; 54345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.len = count; 54445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(STRING); 54545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 54645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 54745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org any { 54845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org if (cursor == s->eof) { 54945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_error_set(YASM_ERROR_SYNTAX, 55045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org N_("unexpected end of file in string")); 55145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.contents = (char *)strbuf; 55245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lvalp->str.len = count; 55345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RETURN(STRING); 55445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 55545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org strbuf_append(count++, cursor, s, s->tok[0]); 55645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org goto stringconst_scan; 55745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } 55845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 55945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 560