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