1d65182f1818d1c19e6f3866ab6e68a262fad5185hbono@chromium.org/* 245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * NASM-compatible parser header file 345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Copyright (C) 2002-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 * 1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' 1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE 1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * POSSIBILITY OF SUCH DAMAGE. 2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef YASM_NASM_PARSER_H 2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_NASM_PARSER_H 2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 30a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org#include "nasm-parser-struct.h" 31a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org 3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YYCTYPE unsigned char 3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define MAX_SAVED_LINE_LEN 80 3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgenum tokentype { 3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org INTNUM = 258, 3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org FLTNUM, 3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org DIRECTIVE_NAME, 4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org FILENAME, 4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STRING, 4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SIZE_OVERRIDE, 4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org OFFSET, 4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org DECLARE_DATA, 4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RESERVE_SPACE, 4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org LABEL, 4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org INCBIN, 4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EQU, 4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org TIMES, 5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org DUP, 5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SEG, 5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org WRT, 5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ABS, 5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org REL, 5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org NOSPLIT, 5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STRICT, 5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org INSN, 5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org PREFIX, 5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org REG, 60a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org REGGROUP, 6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SEGREG, 6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org TARGETMOD, 6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org LEFT_OP, 6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RIGHT_OP, 6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org LOW, 6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org HIGH, 6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SIGNDIV, 6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SIGNMOD, 6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org START_SECTION_ID, 7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ID, 7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org LOCAL_ID, 7245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SPECIAL_ID, 7345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org NONLOCAL_ID, 7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org LINE, 7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org NONE /* special token for lookahead */ 7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}; 7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 78a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.orgenum nasm_parser_state { 79a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org INITIAL, 80a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org DIRECTIVE, 81a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org SECTION_DIRECTIVE, 82a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org DIRECTIVE2, 83a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org LINECHG, 84a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org LINECHG2, 85a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org INSTRUCTION 86a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org}; 8745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 88a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org#define YYSTYPE nasm_yystype 8945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* shorter access names to commonly used parser_nasm fields */ 9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define p_object (parser_nasm->object) 9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define p_symtab (parser_nasm->object->symtab) 9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define cursect (parser_nasm->object->cur_section) 9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define curtok (parser_nasm->token) 9545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define curval (parser_nasm->tokval) 9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define INTNUM_val (curval.intn) 9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define FLTNUM_val (curval.flt) 9945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define DIRECTIVE_NAME_val (curval.str_val) 10045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define FILENAME_val (curval.str_val) 10145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define STRING_val (curval.str) 10245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define SIZE_OVERRIDE_val (curval.int_info) 10345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define DECLARE_DATA_val (curval.int_info) 10445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define RESERVE_SPACE_val (curval.int_info) 10545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define INSN_val (curval.bc) 10645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define PREFIX_val (curval.arch_data) 10745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define REG_val (curval.arch_data) 108a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org#define REGGROUP_val (curval.arch_data) 10945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define SEGREG_val (curval.arch_data) 11045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define TARGETMOD_val (curval.arch_data) 11145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define ID_val (curval.str_val) 11245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define cur_line (yasm_linemap_get_current(parser_nasm->linemap)) 11445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define p_expr_new_tree(l,o,r) yasm_expr_create_tree(l,o,r,cur_line) 11645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define p_expr_new_branch(o,r) yasm_expr_create_branch(o,r,cur_line) 11745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define p_expr_new_ident(r) yasm_expr_create_ident(r,cur_line) 11845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid nasm_parser_parse(yasm_parser_nasm *parser_nasm); 12045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid nasm_parser_cleanup(yasm_parser_nasm *parser_nasm); 12145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint nasm_parser_lex(YYSTYPE *lvalp, yasm_parser_nasm *parser_nasm); 12245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 12345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 124