| OLD | NEW |
| 1 /* $Id: nasm-parser.h 2167 2009-01-02 08:36:09Z peter $ | 1 /* $Id: nasm-parser.h 2277 2010-01-19 07:03:15Z peter $ |
| 2 * NASM-compatible parser header file | 2 * NASM-compatible parser header file |
| 3 * | 3 * |
| 4 * Copyright (C) 2002-2007 Peter Johnson | 4 * Copyright (C) 2002-2007 Peter Johnson |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| 11 * 2. Redistributions in binary form must reproduce the above copyright | 11 * 2. Redistributions in binary form must reproduce the above copyright |
| 12 * notice, this list of conditions and the following disclaimer in the | 12 * notice, this list of conditions and the following disclaimer in the |
| 13 * documentation and/or other materials provided with the distribution. | 13 * documentation and/or other materials provided with the distribution. |
| 14 * | 14 * |
| 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' | 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' |
| 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE | 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE |
| 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 25 * POSSIBILITY OF SUCH DAMAGE. | 25 * POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 #ifndef YASM_NASM_PARSER_H | 27 #ifndef YASM_NASM_PARSER_H |
| 28 #define YASM_NASM_PARSER_H | 28 #define YASM_NASM_PARSER_H |
| 29 | 29 |
| 30 #include "nasm-parser-struct.h" |
| 31 |
| 30 #define YYCTYPE unsigned char | 32 #define YYCTYPE unsigned char |
| 31 | 33 |
| 32 #define MAX_SAVED_LINE_LEN 80 | 34 #define MAX_SAVED_LINE_LEN 80 |
| 33 | 35 |
| 34 enum tokentype { | 36 enum tokentype { |
| 35 INTNUM = 258, | 37 INTNUM = 258, |
| 36 FLTNUM, | 38 FLTNUM, |
| 37 DIRECTIVE_NAME, | 39 DIRECTIVE_NAME, |
| 38 FILENAME, | 40 FILENAME, |
| 39 STRING, | 41 STRING, |
| 40 SIZE_OVERRIDE, | 42 SIZE_OVERRIDE, |
| 41 OFFSET, | 43 OFFSET, |
| 42 DECLARE_DATA, | 44 DECLARE_DATA, |
| 43 RESERVE_SPACE, | 45 RESERVE_SPACE, |
| 44 LABEL, | 46 LABEL, |
| 45 INCBIN, | 47 INCBIN, |
| 46 EQU, | 48 EQU, |
| 47 TIMES, | 49 TIMES, |
| 48 DUP, | 50 DUP, |
| 49 SEG, | 51 SEG, |
| 50 WRT, | 52 WRT, |
| 51 ABS, | 53 ABS, |
| 52 REL, | 54 REL, |
| 53 NOSPLIT, | 55 NOSPLIT, |
| 54 STRICT, | 56 STRICT, |
| 55 INSN, | 57 INSN, |
| 56 PREFIX, | 58 PREFIX, |
| 57 REG, | 59 REG, |
| 60 REGGROUP, |
| 58 SEGREG, | 61 SEGREG, |
| 59 TARGETMOD, | 62 TARGETMOD, |
| 60 LEFT_OP, | 63 LEFT_OP, |
| 61 RIGHT_OP, | 64 RIGHT_OP, |
| 62 LOW, | 65 LOW, |
| 63 HIGH, | 66 HIGH, |
| 64 SIGNDIV, | 67 SIGNDIV, |
| 65 SIGNMOD, | 68 SIGNMOD, |
| 66 START_SECTION_ID, | 69 START_SECTION_ID, |
| 67 ID, | 70 ID, |
| 68 LOCAL_ID, | 71 LOCAL_ID, |
| 69 SPECIAL_ID, | 72 SPECIAL_ID, |
| 70 NONLOCAL_ID, | 73 NONLOCAL_ID, |
| 71 LINE, | 74 LINE, |
| 72 NONE /* special token for lookahead */ | 75 NONE /* special token for lookahead */ |
| 73 }; | 76 }; |
| 74 | 77 |
| 75 typedef union { | 78 enum nasm_parser_state { |
| 76 unsigned int int_info; | 79 INITIAL, |
| 77 char *str_val; | 80 DIRECTIVE, |
| 78 yasm_intnum *intn; | 81 SECTION_DIRECTIVE, |
| 79 yasm_floatnum *flt; | 82 DIRECTIVE2, |
| 80 yasm_bytecode *bc; | 83 LINECHG, |
| 81 uintptr_t arch_data; | 84 LINECHG2, |
| 82 struct { | 85 INSTRUCTION |
| 83 char *contents; | 86 }; |
| 84 size_t len; | |
| 85 } str; | |
| 86 } yystype; | |
| 87 #define YYSTYPE yystype | |
| 88 | 87 |
| 89 typedef struct yasm_parser_nasm { | 88 #define YYSTYPE nasm_yystype |
| 90 int tasm; | |
| 91 | |
| 92 /*@only@*/ yasm_object *object; | |
| 93 | |
| 94 /* last "base" label for local (.) labels */ | |
| 95 /*@null@*/ char *locallabel_base; | |
| 96 size_t locallabel_base_len; | |
| 97 | |
| 98 /*@dependent@*/ yasm_preproc *preproc; | |
| 99 /*@dependent@*/ yasm_errwarns *errwarns; | |
| 100 | |
| 101 /*@dependent@*/ yasm_linemap *linemap; | |
| 102 | |
| 103 /*@null@*/ yasm_bytecode *prev_bc; | |
| 104 | |
| 105 int save_input; | |
| 106 | |
| 107 yasm_scanner s; | |
| 108 enum { | |
| 109 INITIAL, | |
| 110 DIRECTIVE, | |
| 111 SECTION_DIRECTIVE, | |
| 112 DIRECTIVE2, | |
| 113 LINECHG, | |
| 114 LINECHG2, | |
| 115 INSTRUCTION | |
| 116 } state; | |
| 117 | |
| 118 int token; /* enum tokentype or any character */ | |
| 119 yystype tokval; | |
| 120 char tokch; /* first character of token */ | |
| 121 | |
| 122 /* one token of lookahead; used sparingly */ | |
| 123 int peek_token; /* NONE if none */ | |
| 124 yystype peek_tokval; | |
| 125 char peek_tokch; | |
| 126 | |
| 127 /* Starting point of the absolute section. NULL if not in an absolute | |
| 128 * section. | |
| 129 */ | |
| 130 /*@null@*/ yasm_expr *absstart; | |
| 131 | |
| 132 /* Current location inside an absolute section (including the start). | |
| 133 * NULL if not in an absolute section. | |
| 134 */ | |
| 135 /*@null@*/ yasm_expr *abspos; | |
| 136 } yasm_parser_nasm; | |
| 137 | 89 |
| 138 /* shorter access names to commonly used parser_nasm fields */ | 90 /* shorter access names to commonly used parser_nasm fields */ |
| 139 #define p_object (parser_nasm->object) | 91 #define p_object (parser_nasm->object) |
| 140 #define p_symtab (parser_nasm->object->symtab) | 92 #define p_symtab (parser_nasm->object->symtab) |
| 141 #define cursect (parser_nasm->object->cur_section) | 93 #define cursect (parser_nasm->object->cur_section) |
| 142 #define curtok (parser_nasm->token) | 94 #define curtok (parser_nasm->token) |
| 143 #define curval (parser_nasm->tokval) | 95 #define curval (parser_nasm->tokval) |
| 144 | 96 |
| 145 #define INTNUM_val (curval.intn) | 97 #define INTNUM_val (curval.intn) |
| 146 #define FLTNUM_val (curval.flt) | 98 #define FLTNUM_val (curval.flt) |
| 147 #define DIRECTIVE_NAME_val (curval.str_val) | 99 #define DIRECTIVE_NAME_val (curval.str_val) |
| 148 #define FILENAME_val (curval.str_val) | 100 #define FILENAME_val (curval.str_val) |
| 149 #define STRING_val (curval.str) | 101 #define STRING_val (curval.str) |
| 150 #define SIZE_OVERRIDE_val (curval.int_info) | 102 #define SIZE_OVERRIDE_val (curval.int_info) |
| 151 #define DECLARE_DATA_val (curval.int_info) | 103 #define DECLARE_DATA_val (curval.int_info) |
| 152 #define RESERVE_SPACE_val (curval.int_info) | 104 #define RESERVE_SPACE_val (curval.int_info) |
| 153 #define INSN_val (curval.bc) | 105 #define INSN_val (curval.bc) |
| 154 #define PREFIX_val (curval.arch_data) | 106 #define PREFIX_val (curval.arch_data) |
| 155 #define REG_val (curval.arch_data) | 107 #define REG_val (curval.arch_data) |
| 108 #define REGGROUP_val (curval.arch_data) |
| 156 #define SEGREG_val (curval.arch_data) | 109 #define SEGREG_val (curval.arch_data) |
| 157 #define TARGETMOD_val (curval.arch_data) | 110 #define TARGETMOD_val (curval.arch_data) |
| 158 #define ID_val (curval.str_val) | 111 #define ID_val (curval.str_val) |
| 159 | 112 |
| 160 #define cur_line (yasm_linemap_get_current(parser_nasm->linemap)) | 113 #define cur_line (yasm_linemap_get_current(parser_nasm->linemap)) |
| 161 | 114 |
| 162 #define p_expr_new_tree(l,o,r) yasm_expr_create_tree(l,o,r,cur_line) | 115 #define p_expr_new_tree(l,o,r) yasm_expr_create_tree(l,o,r,cur_line) |
| 163 #define p_expr_new_branch(o,r) yasm_expr_create_branch(o,r,cur_line) | 116 #define p_expr_new_branch(o,r) yasm_expr_create_branch(o,r,cur_line) |
| 164 #define p_expr_new_ident(r) yasm_expr_create_ident(r,cur_line) | 117 #define p_expr_new_ident(r) yasm_expr_create_ident(r,cur_line) |
| 165 | 118 |
| 166 void nasm_parser_parse(yasm_parser_nasm *parser_nasm); | 119 void nasm_parser_parse(yasm_parser_nasm *parser_nasm); |
| 167 void nasm_parser_cleanup(yasm_parser_nasm *parser_nasm); | 120 void nasm_parser_cleanup(yasm_parser_nasm *parser_nasm); |
| 168 int nasm_parser_lex(YYSTYPE *lvalp, yasm_parser_nasm *parser_nasm); | 121 int nasm_parser_lex(YYSTYPE *lvalp, yasm_parser_nasm *parser_nasm); |
| 169 | 122 |
| 170 #endif | 123 #endif |
| OLD | NEW |