H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 1 | /* parser.c source line parser for the Netwide Assembler |
| 2 | * |
| 3 | * The Netwide Assembler is copyright (C) 1996 Simon Tatham and |
| 4 | * Julian Hall. All rights reserved. The software is |
| 5 | * redistributable under the licence given in the file "Licence" |
| 6 | * distributed in the NASM archive. |
| 7 | * |
| 8 | * initial version 27/iii/95 by Simon Tatham |
| 9 | */ |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <stddef.h> |
| 14 | #include <string.h> |
| 15 | #include <ctype.h> |
Keith Kanios | b7a8954 | 2007-04-12 02:40:54 +0000 | [diff] [blame] | 16 | #include <inttypes.h> |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 17 | |
| 18 | #include "nasm.h" |
H. Peter Anvin | 24cfef4 | 2002-09-12 16:34:06 +0000 | [diff] [blame] | 19 | #include "insns.h" |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 20 | #include "nasmlib.h" |
| 21 | #include "parser.h" |
| 22 | #include "float.h" |
| 23 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 24 | extern int in_abs_seg; /* ABSOLUTE segment flag */ |
Keith Kanios | b7a8954 | 2007-04-12 02:40:54 +0000 | [diff] [blame] | 25 | extern int32_t abs_seg; /* ABSOLUTE segment */ |
| 26 | extern int32_t abs_offset; /* ABSOLUTE segment offset */ |
H. Peter Anvin | d0e365d | 2002-05-26 18:19:19 +0000 | [diff] [blame] | 27 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 28 | #include "regflags.c" /* List of register flags */ |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 29 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 30 | static int is_comma_next(void); |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 31 | |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 32 | static int i; |
| 33 | static struct tokenval tokval; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 34 | static efunc error; |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 35 | static struct ofmt *outfmt; /* Structure of addresses of output routines */ |
| 36 | static loc_t *location; /* Pointer to current line's segment,offset */ |
H. Peter Anvin | eba20a7 | 2002-04-30 20:53:55 +0000 | [diff] [blame] | 37 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 38 | void parser_global_info(struct ofmt *output, loc_t * locp) |
H. Peter Anvin | eba20a7 | 2002-04-30 20:53:55 +0000 | [diff] [blame] | 39 | { |
| 40 | outfmt = output; |
| 41 | location = locp; |
| 42 | } |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 43 | |
Keith Kanios | a6dfa78 | 2007-04-13 16:47:53 +0000 | [diff] [blame] | 44 | insn *parse_line(int pass, char *buffer, insn * result, |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 45 | efunc errfunc, evalfunc evaluate, ldfunc ldef) |
H. Peter Anvin | eba20a7 | 2002-04-30 20:53:55 +0000 | [diff] [blame] | 46 | { |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 47 | int operand; |
| 48 | int critical; |
H. Peter Anvin | 76690a1 | 2002-04-30 20:52:49 +0000 | [diff] [blame] | 49 | struct eval_hints hints; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 50 | |
H. Peter Anvin | 76690a1 | 2002-04-30 20:52:49 +0000 | [diff] [blame] | 51 | result->forw_ref = FALSE; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 52 | error = errfunc; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 53 | |
H. Peter Anvin | 76690a1 | 2002-04-30 20:52:49 +0000 | [diff] [blame] | 54 | stdscan_reset(); |
| 55 | stdscan_bufptr = buffer; |
| 56 | i = stdscan(NULL, &tokval); |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 57 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 58 | result->label = NULL; /* Assume no label */ |
| 59 | result->eops = NULL; /* must do this, whatever happens */ |
Keith Kanios | b7a8954 | 2007-04-12 02:40:54 +0000 | [diff] [blame] | 60 | result->operands = 0; /* must initialize this */ |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 61 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 62 | if (i == 0) { /* blank line - ignore */ |
| 63 | result->opcode = -1; /* and no instruction either */ |
| 64 | return result; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 65 | } |
| 66 | if (i != TOKEN_ID && i != TOKEN_INSN && i != TOKEN_PREFIX && |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 67 | (i != TOKEN_REG || (REG_SREG & ~reg_flags[tokval.t_integer]))) { |
| 68 | error(ERR_NONFATAL, "label or instruction expected" |
| 69 | " at start of line"); |
| 70 | result->opcode = -1; |
| 71 | return result; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 72 | } |
| 73 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 74 | if (i == TOKEN_ID) { /* there's a label here */ |
| 75 | result->label = tokval.t_charptr; |
| 76 | i = stdscan(NULL, &tokval); |
| 77 | if (i == ':') { /* skip over the optional colon */ |
| 78 | i = stdscan(NULL, &tokval); |
| 79 | } else if (i == 0) { |
| 80 | error(ERR_WARNING | ERR_WARN_OL | ERR_PASS1, |
| 81 | "label alone on a line without a colon might be in error"); |
| 82 | } |
| 83 | if (i != TOKEN_INSN || tokval.t_integer != I_EQU) { |
| 84 | /* |
| 85 | * FIXME: location->segment could be NO_SEG, in which case |
| 86 | * it is possible we should be passing 'abs_seg'. Look into this. |
| 87 | * Work out whether that is *really* what we should be doing. |
| 88 | * Generally fix things. I think this is right as it is, but |
| 89 | * am still not certain. |
| 90 | */ |
| 91 | ldef(result->label, in_abs_seg ? abs_seg : location->segment, |
| 92 | location->offset, NULL, TRUE, FALSE, outfmt, errfunc); |
| 93 | } |
H. Peter Anvin | eba20a7 | 2002-04-30 20:53:55 +0000 | [diff] [blame] | 94 | } |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 95 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 96 | if (i == 0) { |
| 97 | result->opcode = -1; /* this line contains just a label */ |
| 98 | return result; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | result->nprefix = 0; |
H. Peter Anvin | d7ed89e | 2002-04-30 20:52:08 +0000 | [diff] [blame] | 102 | result->times = 1L; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 103 | |
| 104 | while (i == TOKEN_PREFIX || |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 105 | (i == TOKEN_REG && !(REG_SREG & ~reg_flags[tokval.t_integer]))) |
H. Peter Anvin | eba20a7 | 2002-04-30 20:53:55 +0000 | [diff] [blame] | 106 | { |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 107 | /* |
| 108 | * Handle special case: the TIMES prefix. |
| 109 | */ |
| 110 | if (i == TOKEN_PREFIX && tokval.t_integer == P_TIMES) { |
| 111 | expr *value; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 112 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 113 | i = stdscan(NULL, &tokval); |
| 114 | value = |
| 115 | evaluate(stdscan, NULL, &tokval, NULL, pass0, error, NULL); |
| 116 | i = tokval.t_type; |
| 117 | if (!value) { /* but, error in evaluator */ |
| 118 | result->opcode = -1; /* unrecoverable parse error: */ |
| 119 | return result; /* ignore this instruction */ |
| 120 | } |
| 121 | if (!is_simple(value)) { |
| 122 | error(ERR_NONFATAL, |
| 123 | "non-constant argument supplied to TIMES"); |
| 124 | result->times = 1L; |
| 125 | } else { |
| 126 | result->times = value->value; |
| 127 | if (value->value < 0) { |
| 128 | error(ERR_NONFATAL, "TIMES value %d is negative", |
| 129 | value->value); |
| 130 | result->times = 0; |
| 131 | } |
| 132 | } |
| 133 | } else { |
| 134 | if (result->nprefix == MAXPREFIX) |
| 135 | error(ERR_NONFATAL, |
| 136 | "instruction has more than %d prefixes", MAXPREFIX); |
| 137 | else |
| 138 | result->prefixes[result->nprefix++] = tokval.t_integer; |
| 139 | i = stdscan(NULL, &tokval); |
| 140 | } |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | if (i != TOKEN_INSN) { |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 144 | if (result->nprefix > 0 && i == 0) { |
| 145 | /* |
| 146 | * Instruction prefixes are present, but no actual |
| 147 | * instruction. This is allowed: at this point we |
| 148 | * invent a notional instruction of RESB 0. |
| 149 | */ |
| 150 | result->opcode = I_RESB; |
| 151 | result->operands = 1; |
| 152 | result->oprs[0].type = IMMEDIATE; |
| 153 | result->oprs[0].offset = 0L; |
| 154 | result->oprs[0].segment = result->oprs[0].wrt = NO_SEG; |
| 155 | return result; |
| 156 | } else { |
| 157 | error(ERR_NONFATAL, "parser: instruction expected"); |
| 158 | result->opcode = -1; |
| 159 | return result; |
| 160 | } |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | result->opcode = tokval.t_integer; |
| 164 | result->condition = tokval.t_inttwo; |
| 165 | |
| 166 | /* |
| 167 | * RESB, RESW and RESD cannot be satisfied with incorrectly |
| 168 | * evaluated operands, since the correct values _must_ be known |
| 169 | * on the first pass. Hence, even in pass one, we set the |
| 170 | * `critical' flag on calling evaluate(), so that it will bomb |
| 171 | * out on undefined symbols. Nasty, but there's nothing we can |
| 172 | * do about it. |
| 173 | * |
| 174 | * For the moment, EQU has the same difficulty, so we'll |
| 175 | * include that. |
| 176 | */ |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 177 | if (result->opcode == I_RESB || result->opcode == I_RESW || result->opcode == I_RESD || result->opcode == I_RESQ || result->opcode == I_REST || result->opcode == I_EQU || result->opcode == I_INCBIN) { /* fbk */ |
| 178 | critical = pass0; |
| 179 | } else |
| 180 | critical = (pass == 2 ? 2 : 0); |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 181 | |
| 182 | if (result->opcode == I_DB || |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 183 | result->opcode == I_DW || |
| 184 | result->opcode == I_DD || |
| 185 | result->opcode == I_DQ || |
| 186 | result->opcode == I_DT || result->opcode == I_INCBIN) { |
| 187 | extop *eop, **tail = &result->eops, **fixptr; |
| 188 | int oper_num = 0; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 189 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 190 | result->eops_float = FALSE; |
H. Peter Anvin | eba20a7 | 2002-04-30 20:53:55 +0000 | [diff] [blame] | 191 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 192 | /* |
| 193 | * Begin to read the DB/DW/DD/DQ/DT/INCBIN operands. |
| 194 | */ |
| 195 | while (1) { |
| 196 | i = stdscan(NULL, &tokval); |
| 197 | if (i == 0) |
| 198 | break; |
| 199 | fixptr = tail; |
| 200 | eop = *tail = nasm_malloc(sizeof(extop)); |
| 201 | tail = &eop->next; |
| 202 | eop->next = NULL; |
| 203 | eop->type = EOT_NOTHING; |
| 204 | oper_num++; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 205 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 206 | if (i == TOKEN_NUM && tokval.t_charptr && is_comma_next()) { |
| 207 | eop->type = EOT_DB_STRING; |
| 208 | eop->stringval = tokval.t_charptr; |
| 209 | eop->stringlen = tokval.t_inttwo; |
| 210 | i = stdscan(NULL, &tokval); /* eat the comma */ |
| 211 | continue; |
| 212 | } |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 213 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 214 | if ((i == TOKEN_FLOAT && is_comma_next()) || i == '-') { |
Keith Kanios | b7a8954 | 2007-04-12 02:40:54 +0000 | [diff] [blame] | 215 | int32_t sign = +1L; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 216 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 217 | if (i == '-') { |
Keith Kanios | a6dfa78 | 2007-04-13 16:47:53 +0000 | [diff] [blame] | 218 | char *save = stdscan_bufptr; |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 219 | i = stdscan(NULL, &tokval); |
| 220 | sign = -1L; |
| 221 | if (i != TOKEN_FLOAT || !is_comma_next()) { |
| 222 | stdscan_bufptr = save; |
| 223 | i = tokval.t_type = '-'; |
| 224 | } |
| 225 | } |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 226 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 227 | if (i == TOKEN_FLOAT) { |
| 228 | eop->type = EOT_DB_STRING; |
| 229 | result->eops_float = TRUE; |
| 230 | if (result->opcode == I_DD) |
| 231 | eop->stringlen = 4; |
| 232 | else if (result->opcode == I_DQ) |
| 233 | eop->stringlen = 8; |
| 234 | else if (result->opcode == I_DT) |
| 235 | eop->stringlen = 10; |
| 236 | else { |
| 237 | error(ERR_NONFATAL, "floating-point constant" |
| 238 | " encountered in `D%c' instruction", |
| 239 | result->opcode == I_DW ? 'W' : 'B'); |
| 240 | /* |
| 241 | * fix suggested by Pedro Gimeno... original line |
| 242 | * was: |
| 243 | * eop->type = EOT_NOTHING; |
| 244 | */ |
| 245 | eop->stringlen = 0; |
| 246 | } |
| 247 | eop = |
| 248 | nasm_realloc(eop, sizeof(extop) + eop->stringlen); |
| 249 | tail = &eop->next; |
| 250 | *fixptr = eop; |
Keith Kanios | a6dfa78 | 2007-04-13 16:47:53 +0000 | [diff] [blame] | 251 | eop->stringval = (char *)eop + sizeof(extop); |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 252 | if (eop->stringlen < 4 || |
| 253 | !float_const(tokval.t_charptr, sign, |
Keith Kanios | b7a8954 | 2007-04-12 02:40:54 +0000 | [diff] [blame] | 254 | (uint8_t *)eop->stringval, |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 255 | eop->stringlen, error)) |
| 256 | eop->type = EOT_NOTHING; |
| 257 | i = stdscan(NULL, &tokval); /* eat the comma */ |
| 258 | continue; |
| 259 | } |
| 260 | } |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 261 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 262 | /* anything else */ |
| 263 | { |
| 264 | expr *value; |
| 265 | value = evaluate(stdscan, NULL, &tokval, NULL, |
| 266 | critical, error, NULL); |
| 267 | i = tokval.t_type; |
| 268 | if (!value) { /* error in evaluator */ |
| 269 | result->opcode = -1; /* unrecoverable parse error: */ |
| 270 | return result; /* ignore this instruction */ |
| 271 | } |
| 272 | if (is_unknown(value)) { |
| 273 | eop->type = EOT_DB_NUMBER; |
| 274 | eop->offset = 0; /* doesn't matter what we put */ |
| 275 | eop->segment = eop->wrt = NO_SEG; /* likewise */ |
| 276 | } else if (is_reloc(value)) { |
| 277 | eop->type = EOT_DB_NUMBER; |
| 278 | eop->offset = reloc_value(value); |
| 279 | eop->segment = reloc_seg(value); |
| 280 | eop->wrt = reloc_wrt(value); |
| 281 | } else { |
| 282 | error(ERR_NONFATAL, |
| 283 | "operand %d: expression is not simple" |
| 284 | " or relocatable", oper_num); |
| 285 | } |
| 286 | } |
H. Peter Anvin | 6768eb7 | 2002-04-30 20:52:26 +0000 | [diff] [blame] | 287 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 288 | /* |
| 289 | * We're about to call stdscan(), which will eat the |
| 290 | * comma that we're currently sitting on between |
| 291 | * arguments. However, we'd better check first that it |
| 292 | * _is_ a comma. |
| 293 | */ |
| 294 | if (i == 0) /* also could be EOL */ |
| 295 | break; |
| 296 | if (i != ',') { |
| 297 | error(ERR_NONFATAL, "comma expected after operand %d", |
| 298 | oper_num); |
| 299 | result->opcode = -1; /* unrecoverable parse error: */ |
| 300 | return result; /* ignore this instruction */ |
| 301 | } |
| 302 | } |
H. Peter Anvin | d7ed89e | 2002-04-30 20:52:08 +0000 | [diff] [blame] | 303 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 304 | if (result->opcode == I_INCBIN) { |
| 305 | /* |
| 306 | * Correct syntax for INCBIN is that there should be |
| 307 | * one string operand, followed by one or two numeric |
| 308 | * operands. |
| 309 | */ |
| 310 | if (!result->eops || result->eops->type != EOT_DB_STRING) |
| 311 | error(ERR_NONFATAL, "`incbin' expects a file name"); |
| 312 | else if (result->eops->next && |
| 313 | result->eops->next->type != EOT_DB_NUMBER) |
| 314 | error(ERR_NONFATAL, "`incbin': second parameter is", |
| 315 | " non-numeric"); |
| 316 | else if (result->eops->next && result->eops->next->next && |
| 317 | result->eops->next->next->type != EOT_DB_NUMBER) |
| 318 | error(ERR_NONFATAL, "`incbin': third parameter is", |
| 319 | " non-numeric"); |
| 320 | else if (result->eops->next && result->eops->next->next && |
| 321 | result->eops->next->next->next) |
| 322 | error(ERR_NONFATAL, |
| 323 | "`incbin': more than three parameters"); |
H. Peter Anvin | eba20a7 | 2002-04-30 20:53:55 +0000 | [diff] [blame] | 324 | else |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 325 | return result; |
| 326 | /* |
| 327 | * If we reach here, one of the above errors happened. |
| 328 | * Throw the instruction away. |
| 329 | */ |
| 330 | result->opcode = -1; |
| 331 | return result; |
| 332 | } else /* DB ... */ if (oper_num == 0) |
| 333 | error(ERR_WARNING | ERR_PASS1, |
| 334 | "no operand for data declaration"); |
| 335 | else |
| 336 | result->operands = oper_num; |
H. Peter Anvin | d7ed89e | 2002-04-30 20:52:08 +0000 | [diff] [blame] | 337 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 338 | return result; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | /* right. Now we begin to parse the operands. There may be up to three |
| 342 | * of these, separated by commas, and terminated by a zero token. */ |
| 343 | |
| 344 | for (operand = 0; operand < 3; operand++) { |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 345 | expr *value; /* used most of the time */ |
| 346 | int mref; /* is this going to be a memory ref? */ |
| 347 | int bracket; /* is it a [] mref, or a & mref? */ |
| 348 | int setsize = 0; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 349 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 350 | result->oprs[operand].addr_size = 0; /* have to zero this whatever */ |
| 351 | result->oprs[operand].eaflags = 0; /* and this */ |
| 352 | result->oprs[operand].opflags = 0; |
H. Peter Anvin | eba20a7 | 2002-04-30 20:53:55 +0000 | [diff] [blame] | 353 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 354 | i = stdscan(NULL, &tokval); |
| 355 | if (i == 0) |
| 356 | break; /* end of operands: get out of here */ |
| 357 | result->oprs[operand].type = 0; /* so far, no override */ |
| 358 | while (i == TOKEN_SPECIAL) { /* size specifiers */ |
| 359 | switch ((int)tokval.t_integer) { |
| 360 | case S_BYTE: |
| 361 | if (!setsize) /* we want to use only the first */ |
| 362 | result->oprs[operand].type |= BITS8; |
| 363 | setsize = 1; |
| 364 | break; |
| 365 | case S_WORD: |
| 366 | if (!setsize) |
| 367 | result->oprs[operand].type |= BITS16; |
| 368 | setsize = 1; |
| 369 | break; |
| 370 | case S_DWORD: |
| 371 | case S_LONG: |
| 372 | if (!setsize) |
| 373 | result->oprs[operand].type |= BITS32; |
| 374 | setsize = 1; |
| 375 | break; |
| 376 | case S_QWORD: |
| 377 | if (!setsize) |
| 378 | result->oprs[operand].type |= BITS64; |
| 379 | setsize = 1; |
| 380 | break; |
| 381 | case S_TWORD: |
| 382 | if (!setsize) |
| 383 | result->oprs[operand].type |= BITS80; |
| 384 | setsize = 1; |
| 385 | break; |
| 386 | case S_TO: |
| 387 | result->oprs[operand].type |= TO; |
| 388 | break; |
| 389 | case S_STRICT: |
| 390 | result->oprs[operand].type |= STRICT; |
| 391 | break; |
| 392 | case S_FAR: |
| 393 | result->oprs[operand].type |= FAR; |
| 394 | break; |
| 395 | case S_NEAR: |
| 396 | result->oprs[operand].type |= NEAR; |
| 397 | break; |
| 398 | case S_SHORT: |
| 399 | result->oprs[operand].type |= SHORT; |
| 400 | break; |
| 401 | default: |
| 402 | error(ERR_NONFATAL, "invalid operand size specification"); |
| 403 | } |
| 404 | i = stdscan(NULL, &tokval); |
| 405 | } |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 406 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 407 | if (i == '[' || i == '&') { /* memory reference */ |
| 408 | mref = TRUE; |
| 409 | bracket = (i == '['); |
H. Peter Anvin | 99c4ecd | 2007-08-28 23:06:00 +0000 | [diff] [blame] | 410 | while ((i = stdscan(NULL, &tokval)) == TOKEN_SPECIAL) { |
| 411 | /* check for address directives */ |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 412 | if (tasm_compatible_mode) { |
| 413 | switch ((int)tokval.t_integer) { |
| 414 | /* For TASM compatibility a size override inside the |
| 415 | * brackets changes the size of the operand, not the |
| 416 | * address type of the operand as it does in standard |
| 417 | * NASM syntax. Hence: |
| 418 | * |
| 419 | * mov eax,[DWORD val] |
| 420 | * |
| 421 | * is valid syntax in TASM compatibility mode. Note that |
| 422 | * you lose the ability to override the default address |
| 423 | * type for the instruction, but we never use anything |
| 424 | * but 32-bit flat model addressing in our code. |
| 425 | */ |
| 426 | case S_BYTE: |
| 427 | result->oprs[operand].type |= BITS8; |
| 428 | break; |
| 429 | case S_WORD: |
| 430 | result->oprs[operand].type |= BITS16; |
| 431 | break; |
| 432 | case S_DWORD: |
| 433 | case S_LONG: |
| 434 | result->oprs[operand].type |= BITS32; |
| 435 | break; |
| 436 | case S_QWORD: |
| 437 | result->oprs[operand].type |= BITS64; |
| 438 | break; |
| 439 | case S_TWORD: |
| 440 | result->oprs[operand].type |= BITS80; |
| 441 | break; |
| 442 | default: |
| 443 | error(ERR_NONFATAL, |
| 444 | "invalid operand size specification"); |
| 445 | } |
| 446 | } else { |
| 447 | /* Standard NASM compatible syntax */ |
| 448 | switch ((int)tokval.t_integer) { |
| 449 | case S_NOSPLIT: |
| 450 | result->oprs[operand].eaflags |= EAF_TIMESTWO; |
| 451 | break; |
H. Peter Anvin | 99c4ecd | 2007-08-28 23:06:00 +0000 | [diff] [blame] | 452 | case S_REL: |
| 453 | result->oprs[operand].eaflags |= EAF_REL; |
| 454 | break; |
| 455 | case S_ABS: |
| 456 | result->oprs[operand].eaflags |= EAF_ABS; |
| 457 | break; |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 458 | case S_BYTE: |
| 459 | result->oprs[operand].eaflags |= EAF_BYTEOFFS; |
| 460 | break; |
| 461 | case S_WORD: |
| 462 | result->oprs[operand].addr_size = 16; |
| 463 | result->oprs[operand].eaflags |= EAF_WORDOFFS; |
| 464 | break; |
| 465 | case S_DWORD: |
| 466 | case S_LONG: |
| 467 | result->oprs[operand].addr_size = 32; |
| 468 | result->oprs[operand].eaflags |= EAF_WORDOFFS; |
| 469 | break; |
H. Peter Anvin | 99c4ecd | 2007-08-28 23:06:00 +0000 | [diff] [blame] | 470 | case S_QWORD: |
| 471 | result->oprs[operand].addr_size = 64; |
| 472 | result->oprs[operand].eaflags |= EAF_WORDOFFS; |
| 473 | break; |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 474 | default: |
| 475 | error(ERR_NONFATAL, "invalid size specification in" |
| 476 | " effective address"); |
| 477 | } |
| 478 | } |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 479 | } |
| 480 | } else { /* immediate operand, or register */ |
| 481 | mref = FALSE; |
| 482 | bracket = FALSE; /* placate optimisers */ |
| 483 | } |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 484 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 485 | if ((result->oprs[operand].type & FAR) && !mref && |
| 486 | result->opcode != I_JMP && result->opcode != I_CALL) { |
| 487 | error(ERR_NONFATAL, "invalid use of FAR operand specifier"); |
| 488 | } |
Debbie Wiles | 63b53f7 | 2002-06-04 19:31:24 +0000 | [diff] [blame] | 489 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 490 | value = evaluate(stdscan, NULL, &tokval, |
| 491 | &result->oprs[operand].opflags, |
| 492 | critical, error, &hints); |
| 493 | i = tokval.t_type; |
| 494 | if (result->oprs[operand].opflags & OPFLAG_FORWARD) { |
| 495 | result->forw_ref = TRUE; |
| 496 | } |
| 497 | if (!value) { /* error in evaluator */ |
| 498 | result->opcode = -1; /* unrecoverable parse error: */ |
| 499 | return result; /* ignore this instruction */ |
| 500 | } |
| 501 | if (i == ':' && mref) { /* it was seg:offset */ |
| 502 | /* |
| 503 | * Process the segment override. |
| 504 | */ |
| 505 | if (value[1].type != 0 || value->value != 1 || |
| 506 | REG_SREG & ~reg_flags[value->type]) |
| 507 | error(ERR_NONFATAL, "invalid segment override"); |
| 508 | else if (result->nprefix == MAXPREFIX) |
| 509 | error(ERR_NONFATAL, |
| 510 | "instruction has more than %d prefixes", MAXPREFIX); |
H. Peter Anvin | 99c4ecd | 2007-08-28 23:06:00 +0000 | [diff] [blame] | 511 | else { |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 512 | result->prefixes[result->nprefix++] = value->type; |
H. Peter Anvin | 150e20d | 2007-08-29 15:19:19 +0000 | [diff] [blame] | 513 | if (REG_FSGS & ~reg_flags[value->type]) |
| 514 | result->oprs[operand].eaflags |= EAF_FSGS; |
H. Peter Anvin | 99c4ecd | 2007-08-28 23:06:00 +0000 | [diff] [blame] | 515 | } |
H. Peter Anvin | 76690a1 | 2002-04-30 20:52:49 +0000 | [diff] [blame] | 516 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 517 | i = stdscan(NULL, &tokval); /* then skip the colon */ |
| 518 | if (i == TOKEN_SPECIAL) { /* another check for size override */ |
| 519 | switch ((int)tokval.t_integer) { |
| 520 | case S_WORD: |
| 521 | result->oprs[operand].addr_size = 16; |
| 522 | break; |
| 523 | case S_DWORD: |
| 524 | case S_LONG: |
| 525 | result->oprs[operand].addr_size = 32; |
| 526 | break; |
H. Peter Anvin | 99c4ecd | 2007-08-28 23:06:00 +0000 | [diff] [blame] | 527 | case S_QWORD: |
| 528 | result->oprs[operand].addr_size = 64; |
| 529 | break; |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 530 | default: |
| 531 | error(ERR_NONFATAL, "invalid size specification in" |
| 532 | " effective address"); |
| 533 | } |
| 534 | i = stdscan(NULL, &tokval); |
| 535 | } |
| 536 | value = evaluate(stdscan, NULL, &tokval, |
| 537 | &result->oprs[operand].opflags, |
| 538 | critical, error, &hints); |
| 539 | i = tokval.t_type; |
| 540 | if (result->oprs[operand].opflags & OPFLAG_FORWARD) { |
| 541 | result->forw_ref = TRUE; |
| 542 | } |
| 543 | /* and get the offset */ |
| 544 | if (!value) { /* but, error in evaluator */ |
| 545 | result->opcode = -1; /* unrecoverable parse error: */ |
| 546 | return result; /* ignore this instruction */ |
| 547 | } |
| 548 | } |
| 549 | if (mref && bracket) { /* find ] at the end */ |
| 550 | if (i != ']') { |
| 551 | error(ERR_NONFATAL, "parser: expecting ]"); |
| 552 | do { /* error recovery again */ |
| 553 | i = stdscan(NULL, &tokval); |
| 554 | } while (i != 0 && i != ','); |
| 555 | } else /* we got the required ] */ |
| 556 | i = stdscan(NULL, &tokval); |
| 557 | } else { /* immediate operand */ |
| 558 | if (i != 0 && i != ',' && i != ':') { |
| 559 | error(ERR_NONFATAL, "comma or end of line expected"); |
| 560 | do { /* error recovery */ |
| 561 | i = stdscan(NULL, &tokval); |
| 562 | } while (i != 0 && i != ','); |
| 563 | } else if (i == ':') { |
| 564 | result->oprs[operand].type |= COLON; |
| 565 | } |
| 566 | } |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 567 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 568 | /* now convert the exprs returned from evaluate() into operand |
| 569 | * descriptions... */ |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 570 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 571 | if (mref) { /* it's a memory reference */ |
| 572 | expr *e = value; |
| 573 | int b, i, s; /* basereg, indexreg, scale */ |
Keith Kanios | 7a68f30 | 2007-04-16 04:56:06 +0000 | [diff] [blame] | 574 | int64_t o; /* offset */ |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 575 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 576 | b = i = -1, o = s = 0; |
| 577 | result->oprs[operand].hintbase = hints.base; |
| 578 | result->oprs[operand].hinttype = hints.type; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 579 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 580 | if (e->type && e->type <= EXPR_REG_END) { /* this bit's a register */ |
| 581 | if (e->value == 1) /* in fact it can be basereg */ |
| 582 | b = e->type; |
| 583 | else /* no, it has to be indexreg */ |
| 584 | i = e->type, s = e->value; |
| 585 | e++; |
| 586 | } |
| 587 | if (e->type && e->type <= EXPR_REG_END) { /* it's a 2nd register */ |
| 588 | if (b != -1) /* If the first was the base, ... */ |
| 589 | i = e->type, s = e->value; /* second has to be indexreg */ |
H. Peter Anvin | eba20a7 | 2002-04-30 20:53:55 +0000 | [diff] [blame] | 590 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 591 | else if (e->value != 1) { /* If both want to be index */ |
| 592 | error(ERR_NONFATAL, |
| 593 | "beroset-p-592-invalid effective address"); |
| 594 | result->opcode = -1; |
| 595 | return result; |
| 596 | } else |
| 597 | b = e->type; |
| 598 | e++; |
| 599 | } |
| 600 | if (e->type != 0) { /* is there an offset? */ |
| 601 | if (e->type <= EXPR_REG_END) { /* in fact, is there an error? */ |
| 602 | error(ERR_NONFATAL, |
| 603 | "beroset-p-603-invalid effective address"); |
| 604 | result->opcode = -1; |
| 605 | return result; |
| 606 | } else { |
| 607 | if (e->type == EXPR_UNKNOWN) { |
| 608 | o = 0; /* doesn't matter what */ |
| 609 | result->oprs[operand].wrt = NO_SEG; /* nor this */ |
| 610 | result->oprs[operand].segment = NO_SEG; /* or this */ |
| 611 | while (e->type) |
| 612 | e++; /* go to the end of the line */ |
| 613 | } else { |
| 614 | if (e->type == EXPR_SIMPLE) { |
| 615 | o = e->value; |
| 616 | e++; |
| 617 | } |
| 618 | if (e->type == EXPR_WRT) { |
| 619 | result->oprs[operand].wrt = e->value; |
| 620 | e++; |
| 621 | } else |
| 622 | result->oprs[operand].wrt = NO_SEG; |
| 623 | /* |
| 624 | * Look for a segment base type. |
| 625 | */ |
| 626 | if (e->type && e->type < EXPR_SEGBASE) { |
| 627 | error(ERR_NONFATAL, |
| 628 | "beroset-p-630-invalid effective address"); |
| 629 | result->opcode = -1; |
| 630 | return result; |
| 631 | } |
| 632 | while (e->type && e->value == 0) |
| 633 | e++; |
| 634 | if (e->type && e->value != 1) { |
| 635 | error(ERR_NONFATAL, |
| 636 | "beroset-p-637-invalid effective address"); |
| 637 | result->opcode = -1; |
| 638 | return result; |
| 639 | } |
| 640 | if (e->type) { |
| 641 | result->oprs[operand].segment = |
| 642 | e->type - EXPR_SEGBASE; |
| 643 | e++; |
| 644 | } else |
| 645 | result->oprs[operand].segment = NO_SEG; |
| 646 | while (e->type && e->value == 0) |
| 647 | e++; |
| 648 | if (e->type) { |
| 649 | error(ERR_NONFATAL, |
| 650 | "beroset-p-650-invalid effective address"); |
| 651 | result->opcode = -1; |
| 652 | return result; |
| 653 | } |
| 654 | } |
| 655 | } |
| 656 | } else { |
| 657 | o = 0; |
| 658 | result->oprs[operand].wrt = NO_SEG; |
| 659 | result->oprs[operand].segment = NO_SEG; |
| 660 | } |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 661 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 662 | if (e->type != 0) { /* there'd better be nothing left! */ |
| 663 | error(ERR_NONFATAL, |
| 664 | "beroset-p-663-invalid effective address"); |
| 665 | result->opcode = -1; |
| 666 | return result; |
| 667 | } |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 668 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 669 | result->oprs[operand].type |= MEMORY; |
H. Peter Anvin | 99c4ecd | 2007-08-28 23:06:00 +0000 | [diff] [blame] | 670 | |
| 671 | if (b == -1 && (i == -1 || s == 0)) { |
| 672 | int is_rel = globalbits == 64 && |
| 673 | !(result->oprs[operand].eaflags & EAF_ABS) && |
| 674 | ((globalrel && |
H. Peter Anvin | 150e20d | 2007-08-29 15:19:19 +0000 | [diff] [blame] | 675 | !(result->oprs[operand].eaflags & EAF_FSGS)) || |
H. Peter Anvin | 99c4ecd | 2007-08-28 23:06:00 +0000 | [diff] [blame] | 676 | (result->oprs[operand].eaflags & EAF_REL)); |
| 677 | |
| 678 | result->oprs[operand].type |= is_rel ? IP_REL : MEM_OFFS; |
| 679 | } |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 680 | result->oprs[operand].basereg = b; |
| 681 | result->oprs[operand].indexreg = i; |
| 682 | result->oprs[operand].scale = s; |
| 683 | result->oprs[operand].offset = o; |
| 684 | } else { /* it's not a memory reference */ |
H. Peter Anvin | eba20a7 | 2002-04-30 20:53:55 +0000 | [diff] [blame] | 685 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 686 | if (is_just_unknown(value)) { /* it's immediate but unknown */ |
| 687 | result->oprs[operand].type |= IMMEDIATE; |
| 688 | result->oprs[operand].offset = 0; /* don't care */ |
| 689 | result->oprs[operand].segment = NO_SEG; /* don't care again */ |
| 690 | result->oprs[operand].wrt = NO_SEG; /* still don't care */ |
| 691 | } else if (is_reloc(value)) { /* it's immediate */ |
| 692 | result->oprs[operand].type |= IMMEDIATE; |
| 693 | result->oprs[operand].offset = reloc_value(value); |
| 694 | result->oprs[operand].segment = reloc_seg(value); |
| 695 | result->oprs[operand].wrt = reloc_wrt(value); |
| 696 | if (is_simple(value)) { |
| 697 | if (reloc_value(value) == 1) |
| 698 | result->oprs[operand].type |= UNITY; |
| 699 | if (optimizing >= 0 && |
| 700 | !(result->oprs[operand].type & STRICT)) { |
| 701 | if (reloc_value(value) >= -128 && |
| 702 | reloc_value(value) <= 127) |
| 703 | result->oprs[operand].type |= SBYTE; |
| 704 | } |
| 705 | } |
| 706 | } else { /* it's a register */ |
H. Peter Anvin | eba20a7 | 2002-04-30 20:53:55 +0000 | [diff] [blame] | 707 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 708 | if (value->type >= EXPR_SIMPLE || value->value != 1) { |
| 709 | error(ERR_NONFATAL, "invalid operand type"); |
| 710 | result->opcode = -1; |
| 711 | return result; |
| 712 | } |
H. Peter Anvin | eba20a7 | 2002-04-30 20:53:55 +0000 | [diff] [blame] | 713 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 714 | /* |
| 715 | * check that its only 1 register, not an expression... |
| 716 | */ |
| 717 | for (i = 1; value[i].type; i++) |
| 718 | if (value[i].value) { |
| 719 | error(ERR_NONFATAL, "invalid operand type"); |
| 720 | result->opcode = -1; |
| 721 | return result; |
| 722 | } |
H. Peter Anvin | eba20a7 | 2002-04-30 20:53:55 +0000 | [diff] [blame] | 723 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 724 | /* clear overrides, except TO which applies to FPU regs */ |
| 725 | if (result->oprs[operand].type & ~TO) { |
| 726 | /* |
| 727 | * we want to produce a warning iff the specified size |
| 728 | * is different from the register size |
| 729 | */ |
| 730 | i = result->oprs[operand].type & SIZE_MASK; |
| 731 | } else |
| 732 | i = 0; |
| 733 | |
| 734 | result->oprs[operand].type &= TO; |
| 735 | result->oprs[operand].type |= REGISTER; |
| 736 | result->oprs[operand].type |= reg_flags[value->type]; |
| 737 | result->oprs[operand].basereg = value->type; |
| 738 | |
| 739 | if (i && (result->oprs[operand].type & SIZE_MASK) != i) |
| 740 | error(ERR_WARNING | ERR_PASS1, |
| 741 | "register size specification ignored"); |
| 742 | } |
| 743 | } |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 744 | } |
| 745 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 746 | result->operands = operand; /* set operand count */ |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 747 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 748 | while (operand < 3) /* clear remaining operands */ |
| 749 | result->oprs[operand++].type = 0; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 750 | |
| 751 | /* |
| 752 | * Transform RESW, RESD, RESQ, REST into RESB. |
| 753 | */ |
| 754 | switch (result->opcode) { |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 755 | case I_RESW: |
| 756 | result->opcode = I_RESB; |
| 757 | result->oprs[0].offset *= 2; |
| 758 | break; |
| 759 | case I_RESD: |
| 760 | result->opcode = I_RESB; |
| 761 | result->oprs[0].offset *= 4; |
| 762 | break; |
| 763 | case I_RESQ: |
| 764 | result->opcode = I_RESB; |
| 765 | result->oprs[0].offset *= 8; |
| 766 | break; |
| 767 | case I_REST: |
| 768 | result->opcode = I_RESB; |
| 769 | result->oprs[0].offset *= 10; |
| 770 | break; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | return result; |
| 774 | } |
| 775 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 776 | static int is_comma_next(void) |
H. Peter Anvin | eba20a7 | 2002-04-30 20:53:55 +0000 | [diff] [blame] | 777 | { |
Keith Kanios | a6dfa78 | 2007-04-13 16:47:53 +0000 | [diff] [blame] | 778 | char *p; |
H. Peter Anvin | 76690a1 | 2002-04-30 20:52:49 +0000 | [diff] [blame] | 779 | int i; |
| 780 | struct tokenval tv; |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 781 | |
H. Peter Anvin | 76690a1 | 2002-04-30 20:52:49 +0000 | [diff] [blame] | 782 | p = stdscan_bufptr; |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 783 | i = stdscan(NULL, &tv); |
H. Peter Anvin | 76690a1 | 2002-04-30 20:52:49 +0000 | [diff] [blame] | 784 | stdscan_bufptr = p; |
| 785 | return (i == ',' || i == ';' || !i); |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 786 | } |
| 787 | |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 788 | void cleanup_insn(insn * i) |
H. Peter Anvin | eba20a7 | 2002-04-30 20:53:55 +0000 | [diff] [blame] | 789 | { |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 790 | extop *e; |
| 791 | |
| 792 | while (i->eops) { |
H. Peter Anvin | e2c8018 | 2005-01-15 22:15:51 +0000 | [diff] [blame] | 793 | e = i->eops; |
| 794 | i->eops = i->eops->next; |
| 795 | nasm_free(e); |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 796 | } |
| 797 | } |