annotate lwasm/insn_gen.c @ 508:10f62dc61a75

Fix bad usage of sprintf() Usage of sprintf() to append to a string in the form of sprintf(buf, "%s...", buf...) is undefined, regardless whether it worked on a lot of older systems. It was always a bad idea and it now breaks on current glibc and gcc development environments. The moral: if any of your code uses sprintf() in a way similar to the above, fix it. It may not fail in a benign way.
author William Astle <lost@l-w.ca>
date Sun, 10 May 2020 22:38:24 -0600
parents 62720ac9e28d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
1 /*
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
2 insn_gen.c, Copyright © 2009 William Astle
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
3
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
4 This file is part of LWASM.
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
5
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
6 LWASM is free software: you can redistribute it and/or modify it under the
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
7 terms of the GNU General Public License as published by the Free Software
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
8 Foundation, either version 3 of the License, or (at your option) any later
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
9 version.
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
10
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
11 This program is distributed in the hope that it will be useful, but WITHOUT
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
14 more details.
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
15
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
16 You should have received a copy of the GNU General Public License along with
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
17 this program. If not, see <http://www.gnu.org/licenses/>.
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
18
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
19 Contains code for parsing general addressing modes (IMM+DIR+EXT+IND)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
20 */
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
21
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
22 #include <ctype.h>
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
23 #include <stdlib.h>
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
24
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
25 #include <lw_expr.h>
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
26
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
27 #include "lwasm.h"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
28 #include "instab.h"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
29
374
8e25147c2aa8 Clean up various "externs"
William Astle <lost@l-w.ca>
parents: 370
diff changeset
30 void insn_indexed_parse_aux(asmstate_t *as, line_t *l, char **p);
8e25147c2aa8 Clean up various "externs"
William Astle <lost@l-w.ca>
parents: 370
diff changeset
31 void insn_indexed_resolve_aux(asmstate_t *as, line_t *l, int force, int elen);
8e25147c2aa8 Clean up various "externs"
William Astle <lost@l-w.ca>
parents: 370
diff changeset
32 void insn_indexed_emit_aux(asmstate_t *as, line_t *l);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
33
374
8e25147c2aa8 Clean up various "externs"
William Astle <lost@l-w.ca>
parents: 370
diff changeset
34 void insn_parse_indexed_aux(asmstate_t *as, line_t *l, char **p);
8e25147c2aa8 Clean up various "externs"
William Astle <lost@l-w.ca>
parents: 370
diff changeset
35 void insn_resolve_indexed_aux(asmstate_t *as, line_t *l, int force, int elen);
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
36
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
37 // "extra" is required due to the way OIM, EIM, TIM, and AIM work
136
b78b2f1e011e Fixed additional instruction length problems with logic/memory operations
lost@l-w.ca
parents: 2
diff changeset
38 void insn_parse_gen_aux(asmstate_t *as, line_t *l, char **p, int elen)
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
39 {
402
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
40 char *optr2;
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
41 int v1, tv;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
42 lw_expr_t s;
402
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
43
255
67acad9db5b3 Fix crash when no operand is present
William Astle <lost@l-w.ca>
parents: 242
diff changeset
44 if (!**p)
67acad9db5b3 Fix crash when no operand is present
William Astle <lost@l-w.ca>
parents: 242
diff changeset
45 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
46 lwasm_register_error(as, l, E_OPERAND_BAD);
255
67acad9db5b3 Fix crash when no operand is present
William Astle <lost@l-w.ca>
parents: 242
diff changeset
47 return;
67acad9db5b3 Fix crash when no operand is present
William Astle <lost@l-w.ca>
parents: 242
diff changeset
48 }
67acad9db5b3 Fix crash when no operand is present
William Astle <lost@l-w.ca>
parents: 242
diff changeset
49
402
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
50 /* this is the easy case - start it [ or , means indexed */
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
51 if (**p == ',' || **p == '[')
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
52 {
402
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
53 indexed:
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
54 l -> lint = -1;
402
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
55 l -> lint2 = 1;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
56 insn_parse_indexed_aux(as, l, p);
241
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
57 l -> minlen = OPLEN(instab[l -> insn].ops[1]) + 1 + elen;
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
58 l -> maxlen = OPLEN(instab[l -> insn].ops[1]) + 3 + elen;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
59 goto out;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
60 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
61
402
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
62 /* we have to parse the first expression to find if we have a comma after it */
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
63 optr2 = *p;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
64 if (**p == '<')
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
65 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
66 (*p)++;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
67 l -> lint2 = 0;
470
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
68 if (**p == '<')
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
69 {
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
70 *p = optr2;
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
71 goto indexed;
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
72 }
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
73 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
74 // for compatibility with asxxxx
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
75 // * followed by a digit, alpha, or _, or ., or ?, or another * is "f8"
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
76 else if (**p == '*')
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
77 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
78 tv = *(*p + 1);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
79 if (isdigit(tv) || isalpha(tv) || tv == '_' || tv == '.' || tv == '?' || tv == '@' || tv == '*' || tv == '+' || tv == '-')
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
80 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
81 l -> lint2 = 0;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
82 (*p)++;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
83 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
84 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
85 else if (**p == '>')
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
86 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
87 (*p)++;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
88 l -> lint2 = 2;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
89 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
90 else
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
91 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
92 l -> lint2 = -1;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
93 }
402
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
94 lwasm_skip_to_next_token(l, p);
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
95
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
96 s = lwasm_parse_expr(as, p);
402
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
97
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
98 if (**p == ',')
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
99 {
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
100 /* we have an indexed mode here - reset and transfer control to indexing mode */
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
101 lw_expr_destroy(s);
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
102 *p = optr2;
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
103 goto indexed;
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
104 }
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
105 if (!s)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
106 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
107 lwasm_register_error(as, l, E_OPERAND_BAD);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
108 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
109 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
110
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
111 lwasm_save_expr(l, 0, s);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
112
402
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
113 l -> minlen = OPLEN(instab[l -> insn].ops[0]) + 1 + elen;
b20f14edda5a Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents: 389
diff changeset
114 l -> maxlen = OPLEN(instab[l -> insn].ops[2]) + 2 + elen;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
115 if (as -> output_format == OUTPUT_OBJ && l -> lint2 == -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
116 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
117 l -> lint2 = 2;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
118 goto out;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
119 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
120
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
121 if (l -> lint2 != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
122 goto out;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
123
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
124 // if we have a constant now, figure out dp vs nondp
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
125 if (lw_expr_istype(s, lw_expr_type_int))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
126 {
389
2d9b7ae6c329 Throw error if address overflows in extended mode
William Astle <lost@l-w.ca>
parents: 380
diff changeset
127 if (s -> value > 0xffff) lwasm_register_error(as, l, E_BYTE_OVERFLOW);
2d9b7ae6c329 Throw error if address overflows in extended mode
William Astle <lost@l-w.ca>
parents: 380
diff changeset
128
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
129 v1 = lw_expr_intval(s);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
130 if (((v1 >> 8) & 0xff) == (l -> dpval & 0xff))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
131 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
132 l -> lint2 = 0;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
133 goto out;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
134 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
135 l -> lint2 = 2;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
136 }
241
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
137 else
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
138 {
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
139 int min;
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
140 int max;
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
141
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
142 if (lwasm_calculate_range(as, s, &min, &max) == 0)
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
143 {
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
144 // fprintf(stderr, "range (P) %d...%d for %s\n", min, max, lw_expr_print(s));
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
145 if (min > max)
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
146 {
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
147 // we don't know what to do in this case so don't do anything
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
148 goto out;
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
149 }
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
150 min = (min >> 8) & 0xff;
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
151 max = (max >> 8) & 0xff;
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
152 if ((l -> dpval & 0xff) < min || (l -> dpval & 0xff) > max)
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
153 {
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
154 l -> lint2 = 2;
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
155 goto out;
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
156 }
242
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
157 if (min == max && (l -> dpval & 0xff) == min)
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
158 {
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
159 l -> lint2 = 0;
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
160 goto out;
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
161 }
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
162 // if here, we don't know if the value is in the DP or not
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
163 {
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
164 l -> lint2 = -1;
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
165 goto out;
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
166 }
241
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
167 }
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
168 }
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
169
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
170 out:
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
171 if (l -> lint2 != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
172 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
173 if (l -> lint2 == 0)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
174 {
136
b78b2f1e011e Fixed additional instruction length problems with logic/memory operations
lost@l-w.ca
parents: 2
diff changeset
175 l -> len = OPLEN(instab[l -> insn].ops[0]) + 1 + elen;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
176 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
177 else if (l -> lint2 == 2)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
178 {
136
b78b2f1e011e Fixed additional instruction length problems with logic/memory operations
lost@l-w.ca
parents: 2
diff changeset
179 l -> len = OPLEN(instab[l -> insn].ops[2]) + 2 + elen;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
180 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
181 else if (l -> lint2 == 1 && l -> lint != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
182 {
470
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
183 if (l -> lint == 3)
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
184 l -> len = OPLEN(instab[l -> insn].ops[1]) + 1 + elen;
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
185 else
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
186 l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1 + elen;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
187 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
188 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
189 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
190
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
191 void insn_resolve_gen_aux(asmstate_t *as, line_t *l, int force, int elen)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
192 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
193 lw_expr_t e;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
194
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
195 if (l -> lint2 == 1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
196 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
197 // indexed
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
198 insn_resolve_indexed_aux(as, l, force, elen);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
199 goto out;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
200 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
201
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
202 if (l -> lint2 != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
203 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
204
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
205 e = lwasm_fetch_expr(l, 0);
241
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
206 lwasm_reduce_expr(as, e);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
207 if (lw_expr_istype(e, lw_expr_type_int))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
208 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
209 int v;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
210
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
211 v = lw_expr_intval(e);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
212
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
213 if (((v >> 8) & 0xff) == (l -> dpval & 0xff))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
214 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
215 l -> lint2 = 0;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
216 goto out;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
217 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
218 l -> lint2 = 2;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
219 goto out;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
220 }
241
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
221 else
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
222 {
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
223 int min;
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
224 int max;
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
225
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
226 if (lwasm_calculate_range(as, e, &min, &max) == 0)
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
227 {
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
228 // fprintf(stderr, "range (R) %d...%d for %s\n", min, max, lw_expr_print(e));
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
229 if (min > max)
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
230 {
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
231 // we don't know what to do in this case so don't do anything
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
232 goto out;
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
233 }
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
234 min = (min >> 8) & 0xff;
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
235 max = (max >> 8) & 0xff;
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
236 if ((l -> dpval & 0xff) < min || (l -> dpval & 0xff) > max)
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
237 {
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
238 l -> lint2 = 2;
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
239 goto out;
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
240 }
242
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
241 if (min == max && (l -> dpval & 0xff) == min)
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
242 {
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
243 l -> lint2 = 0;
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
244 goto out;
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
245 }
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
246 // if here, we don't know if the value is in the DP or not
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
247 {
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
248 l -> lint2 = -1;
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
249 goto out;
ea092ebc5323 Fix thinko with algorithm improvement.
William Astle <lost@l-w.ca>
parents: 241
diff changeset
250 }
241
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
251 }
d0e9dbe9afbe Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents: 177
diff changeset
252 }
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
253
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
254 if (force)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
255 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
256 l -> lint2 = 2;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
257 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
258
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
259 out:
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
260 if (l -> lint2 != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
261 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
262 if (l -> lint2 == 0)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
263 {
136
b78b2f1e011e Fixed additional instruction length problems with logic/memory operations
lost@l-w.ca
parents: 2
diff changeset
264 l -> len = OPLEN(instab[l -> insn].ops[0]) + 1 + elen;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
265 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
266 else if (l -> lint2 == 2)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
267 {
136
b78b2f1e011e Fixed additional instruction length problems with logic/memory operations
lost@l-w.ca
parents: 2
diff changeset
268 l -> len = OPLEN(instab[l -> insn].ops[2]) + 2 + elen;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
269 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
270 else if (l -> lint2 == 1 && l -> lint != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
271 {
470
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
272 if (l -> lint == 3)
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
273 l -> len = OPLEN(instab[l -> insn].ops[1]) + 1 + elen;
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
274 else
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
275 l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1 + elen;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
276 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
277 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
278 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
279
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
280 void insn_emit_gen_aux(asmstate_t *as, line_t *l, int extra)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
281 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
282 lw_expr_t e;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
283
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
284 e = lwasm_fetch_expr(l, 0);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
285 lwasm_emitop(l, instab[l -> insn].ops[l -> lint2]);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
286
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
287 if (extra != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
288 lwasm_emit(l, extra);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
289
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
290 if (l -> lint2 == 1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
291 {
470
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
292 if (l -> lint == 3)
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
293 {
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
294 int offs;
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
295 if (lw_expr_istype(e, lw_expr_type_int))
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
296 {
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
297 offs = lw_expr_intval(e);
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
298 if ((offs >= -16 && offs <= 15) || offs >= 0xFFF0)
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
299 {
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
300 l -> pb |= offs & 0x1f;
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
301 l -> lint = 0;
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
302 }
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
303 else
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
304 {
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
305 lwasm_register_error(as, l, E_BYTE_OVERFLOW);
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
306 }
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
307 }
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
308 else
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
309 {
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
310 lwasm_register_error(as, l, E_EXPRESSION_NOT_RESOLVED);
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
311 }
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
312 }
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
313 lwasm_emit(l, l -> pb);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
314 if (l -> lint > 0)
283
210d261a614d Make byte overflow detection for indexing work better
William Astle <lost@l-w.ca>
parents: 255
diff changeset
315 {
210d261a614d Make byte overflow detection for indexing work better
William Astle <lost@l-w.ca>
parents: 255
diff changeset
316 int i;
210d261a614d Make byte overflow detection for indexing work better
William Astle <lost@l-w.ca>
parents: 255
diff changeset
317 i = lw_expr_intval(e);
210d261a614d Make byte overflow detection for indexing work better
William Astle <lost@l-w.ca>
parents: 255
diff changeset
318 if (l -> lint == 1)
210d261a614d Make byte overflow detection for indexing work better
William Astle <lost@l-w.ca>
parents: 255
diff changeset
319 {
210d261a614d Make byte overflow detection for indexing work better
William Astle <lost@l-w.ca>
parents: 255
diff changeset
320 if (i < -128 || i > 127)
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
321 lwasm_register_error(as, l, E_BYTE_OVERFLOW);
283
210d261a614d Make byte overflow detection for indexing work better
William Astle <lost@l-w.ca>
parents: 255
diff changeset
322 }
458
3948c874901b Make offset,R operand size warning work properly
William Astle <lost@l-w.ca>
parents: 402
diff changeset
323 else if (l -> lint == 2 && lw_expr_istype(e, lw_expr_type_int) && CURPRAGMA(l, PRAGMA_OPERANDSIZE))
3948c874901b Make offset,R operand size warning work properly
William Astle <lost@l-w.ca>
parents: 402
diff changeset
324 {
481
62720ac9e28d Exclude extended indirect from operandsizewarning pragma
William Astle <lost@l-w.ca>
parents: 476
diff changeset
325 // note that W relative and extended indirect must be 16 bits
62720ac9e28d Exclude extended indirect from operandsizewarning pragma
William Astle <lost@l-w.ca>
parents: 476
diff changeset
326 if (l -> pb != 0xAF && l -> pb != 0xB0 && l -> pb != 0x9f)
458
3948c874901b Make offset,R operand size warning work properly
William Astle <lost@l-w.ca>
parents: 402
diff changeset
327 {
3948c874901b Make offset,R operand size warning work properly
William Astle <lost@l-w.ca>
parents: 402
diff changeset
328 if ((i >= -128 && i <= 127) || i >= 0xFF80)
3948c874901b Make offset,R operand size warning work properly
William Astle <lost@l-w.ca>
parents: 402
diff changeset
329 {
3948c874901b Make offset,R operand size warning work properly
William Astle <lost@l-w.ca>
parents: 402
diff changeset
330 lwasm_register_error(as, l, W_OPERAND_SIZE);
3948c874901b Make offset,R operand size warning work properly
William Astle <lost@l-w.ca>
parents: 402
diff changeset
331
3948c874901b Make offset,R operand size warning work properly
William Astle <lost@l-w.ca>
parents: 402
diff changeset
332 }
3948c874901b Make offset,R operand size warning work properly
William Astle <lost@l-w.ca>
parents: 402
diff changeset
333 }
3948c874901b Make offset,R operand size warning work properly
William Astle <lost@l-w.ca>
parents: 402
diff changeset
334 }
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
335 lwasm_emitexpr(l, e, l -> lint);
283
210d261a614d Make byte overflow detection for indexing work better
William Astle <lost@l-w.ca>
parents: 255
diff changeset
336 }
376
35d4213e6657 Add cycle counting to listing
William Astle <lost@l-w.ca>
parents: 374
diff changeset
337
35d4213e6657 Add cycle counting to listing
William Astle <lost@l-w.ca>
parents: 374
diff changeset
338 l -> cycle_adj = lwasm_cycle_calc_ind(l);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
339 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
340 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
341
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
342 if (l -> lint2 == 2)
476
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
343 {
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
344 lwasm_emitexpr(l, e, 2);
476
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
345
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
346 if (CURPRAGMA(l, PRAGMA_OPERANDSIZE))
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
347 {
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
348 if (instab[l -> insn].ops[2] == 0xbd || instab[l -> insn].ops[2] == 0x7e)
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
349 {
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
350 // check if bsr or bra could be used instead
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
351 lw_expr_t e1, e2;
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
352 int offs;
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
353 e2 = lw_expr_build(lw_expr_type_special, lwasm_expr_linelen, l);
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
354 e1 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_minus, e, e2);
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
355 lw_expr_destroy(e2);
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
356 e2 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_minus, e1, l -> addr);
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
357 lw_expr_destroy(e1);
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
358 lwasm_reduce_expr(as, e2);
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
359 if (lw_expr_istype(e2, lw_expr_type_int))
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
360 {
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
361 offs = lw_expr_intval(e2);
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
362 if (offs >= -128 && offs <= 127)
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
363 {
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
364 lwasm_register_error(as, l, W_OPERAND_SIZE);
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
365 }
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
366 }
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
367 lw_expr_destroy(e2);
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
368 }
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
369 }
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
370 }
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
371 else
476
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
372 {
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
373 lwasm_emitexpr(l, e, 1);
476
eac8f5f0867d Update operandsizewarning to detect JMP and JSR that could use BRA or BSR
William Astle <lost@l-w.ca>
parents: 470
diff changeset
374 }
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
375 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
376
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
377 // the various insn_gen? functions have an immediate mode of ? bits
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
378 PARSEFUNC(insn_parse_gen0)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
379 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
380 if (**p == '#')
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
381 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
382 lwasm_register_error(as, l, E_IMMEDIATE_INVALID);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
383 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
384 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
385
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
386 // handle non-immediate
136
b78b2f1e011e Fixed additional instruction length problems with logic/memory operations
lost@l-w.ca
parents: 2
diff changeset
387 insn_parse_gen_aux(as, l, p, 0);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
388 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
389
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
390 RESOLVEFUNC(insn_resolve_gen0)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
391 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
392 if (l -> len != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
393 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
394
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
395 // handle non-immediate
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
396 insn_resolve_gen_aux(as, l, force, 0);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
397 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
398
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
399 EMITFUNC(insn_emit_gen0)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
400 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
401 insn_emit_gen_aux(as, l, -1);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
402 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
403
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
404 PARSEFUNC(insn_parse_gen8)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
405 {
380
17fcd0c3ee45 Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents: 376
diff changeset
406 l -> genmode = 8;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
407 if (**p == '#')
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
408 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
409 lw_expr_t e;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
410
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
411 (*p)++;
366
433dbc18fb41 Make byte overflow detection for 8 bit immediate not fail with COM operator
William Astle <lost@l-w.ca>
parents: 355
diff changeset
412 as -> exprwidth = 8;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
413 e = lwasm_parse_expr(as, p);
366
433dbc18fb41 Make byte overflow detection for 8 bit immediate not fail with COM operator
William Astle <lost@l-w.ca>
parents: 355
diff changeset
414 as -> exprwidth = 16;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
415 if (!e)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
416 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
417 lwasm_register_error(as, l, E_OPERAND_BAD);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
418 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
419 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
420 l -> len = OPLEN(instab[l -> insn].ops[3]) + 1;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
421 l -> lint2 = 3;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
422 lwasm_save_expr(l, 0, e);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
423 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
424 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
425
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
426 // handle non-immediate
136
b78b2f1e011e Fixed additional instruction length problems with logic/memory operations
lost@l-w.ca
parents: 2
diff changeset
427 insn_parse_gen_aux(as, l, p, 0);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
428 if (l -> lint2 != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
429 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
430 if (l -> lint2 == 0)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
431 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
432 l -> len = OPLEN(instab[l -> insn].ops[0]) + 1;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
433 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
434 else if (l -> lint2 == 2)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
435 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
436 l -> len = OPLEN(instab[l -> insn].ops[2]) + 2;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
437 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
438 else if (l -> lint2 == 1 && l -> lint != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
439 {
470
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
440 if (l -> lint == 3)
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
441 l -> len = OPLEN(instab[l -> insn].ops[1]) + 1;
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
442 else
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
443 l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
444 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
445 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
446 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
447
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
448 RESOLVEFUNC(insn_resolve_gen8)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
449 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
450 if (l -> len != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
451 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
452
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
453 // handle non-immediate
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
454 insn_resolve_gen_aux(as, l, force, 0);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
455 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
456
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
457 EMITFUNC(insn_emit_gen8)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
458 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
459 if (l -> lint2 == 3)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
460 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
461 lw_expr_t e;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
462 e = lwasm_fetch_expr(l, 0);
355
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
463 if (lw_expr_istype(e, lw_expr_type_int))
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
464 {
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
465 int i;
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
466 i = lw_expr_intval(e);
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
467 if (i < -128 || i > 255)
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
468 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
469 lwasm_register_error(as, l, E_BYTE_OVERFLOW);
355
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
470 }
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
471 }
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
472
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
473 lwasm_emitop(l, instab[l -> insn].ops[3]);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
474 lwasm_emitexpr(l, e, 1);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
475 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
476 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
477
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
478 insn_emit_gen_aux(as, l, -1);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
479 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
480
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
481 PARSEFUNC(insn_parse_gen16)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
482 {
380
17fcd0c3ee45 Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents: 376
diff changeset
483 l -> genmode = 16;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
484 if (**p == '#')
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
485 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
486 lw_expr_t e;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
487
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
488 (*p)++;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
489 e = lwasm_parse_expr(as, p);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
490 if (!e)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
491 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
492 lwasm_register_error(as, l, E_OPERAND_BAD);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
493 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
494 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
495 l -> len = OPLEN(instab[l -> insn].ops[3]) + 2;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
496 l -> lint2 = 3;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
497 lwasm_save_expr(l, 0, e);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
498 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
499 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
500
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
501 // handle non-immediate
136
b78b2f1e011e Fixed additional instruction length problems with logic/memory operations
lost@l-w.ca
parents: 2
diff changeset
502 insn_parse_gen_aux(as, l, p, 0);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
503 if (l -> lint2 != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
504 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
505 if (l -> lint2 == 0)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
506 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
507 l -> len = OPLEN(instab[l -> insn].ops[0]) + 1;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
508 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
509 else if (l -> lint2 == 2)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
510 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
511 l -> len = OPLEN(instab[l -> insn].ops[2]) + 2;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
512 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
513 else if (l -> lint2 == 1 && l -> lint != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
514 {
470
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
515 if (l -> lint == 3)
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
516 l -> len = OPLEN(instab[l -> insn].ops[1]) + 1;
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
517 else
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
518 l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
519 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
520 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
521 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
522
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
523 RESOLVEFUNC(insn_resolve_gen16)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
524 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
525 if (l -> len != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
526 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
527
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
528 // handle non-immediate
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
529 insn_resolve_gen_aux(as, l, force, 0);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
530 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
531
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
532 EMITFUNC(insn_emit_gen16)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
533 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
534 if (l -> lint2 == 3)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
535 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
536 lw_expr_t e;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
537 e = lwasm_fetch_expr(l, 0);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
538 lwasm_emitop(l, instab[l -> insn].ops[3]);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
539 lwasm_emitexpr(l, e, 2);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
540 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
541 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
542
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
543 insn_emit_gen_aux(as, l, -1);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
544 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
545
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
546 PARSEFUNC(insn_parse_gen32)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
547 {
380
17fcd0c3ee45 Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents: 376
diff changeset
548 l -> genmode = 32;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
549 if (**p == '#')
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
550 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
551 lw_expr_t e;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
552
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
553 (*p)++;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
554 e = lwasm_parse_expr(as, p);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
555 if (!e)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
556 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
557 lwasm_register_error(as, l, E_OPERAND_BAD);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
558 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
559 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
560 l -> len = OPLEN(instab[l -> insn].ops[3]) + 4;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
561 l -> lint2 = 3;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
562 lwasm_save_expr(l, 0, e);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
563 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
564 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
565
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
566 // handle non-immediate
136
b78b2f1e011e Fixed additional instruction length problems with logic/memory operations
lost@l-w.ca
parents: 2
diff changeset
567 insn_parse_gen_aux(as, l, p, 0);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
568 if (l -> lint2 != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
569 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
570 if (l -> lint2 == 0)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
571 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
572 l -> len = OPLEN(instab[l -> insn].ops[0]) + 1;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
573 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
574 else if (l -> lint2 == 2)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
575 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
576 l -> len = OPLEN(instab[l -> insn].ops[2]) + 2;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
577 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
578 else if (l -> lint2 == 1 && l -> lint != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
579 {
470
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
580 if (l -> lint == 3)
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
581 l -> len = OPLEN(instab[l -> insn].ops[1]) + 1;
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
582 else
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
583 l -> len = OPLEN(instab[l -> insn].ops[1]) + l -> lint + 1;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
584 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
585 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
586 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
587
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
588 RESOLVEFUNC(insn_resolve_gen32)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
589 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
590 if (l -> len != -1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
591 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
592
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
593 // handle non-immediate
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
594 insn_resolve_gen_aux(as, l, force, 0);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
595 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
596
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
597 EMITFUNC(insn_emit_gen32)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
598 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
599 if (l -> lint2 == 3)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
600 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
601 lw_expr_t e;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
602 e = lwasm_fetch_expr(l, 0);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
603 lwasm_emitop(l, instab[l -> insn].ops[3]);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
604 lwasm_emitexpr(l, e, 4);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
605 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
606 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
607
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
608 insn_emit_gen_aux(as, l, -1);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
609 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
610
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
611 PARSEFUNC(insn_parse_imm8)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
612 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
613 lw_expr_t e;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
614
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
615 if (**p == '#')
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
616 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
617 (*p)++;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
618
366
433dbc18fb41 Make byte overflow detection for 8 bit immediate not fail with COM operator
William Astle <lost@l-w.ca>
parents: 355
diff changeset
619 as -> exprwidth = 8;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
620 e = lwasm_parse_expr(as, p);
366
433dbc18fb41 Make byte overflow detection for 8 bit immediate not fail with COM operator
William Astle <lost@l-w.ca>
parents: 355
diff changeset
621 as -> exprwidth = 16;
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
622 if (!e)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
623 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
624 lwasm_register_error(as, l, E_OPERAND_BAD);
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
625 return;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
626 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
627 l -> len = OPLEN(instab[l -> insn].ops[0]) + 1;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
628 lwasm_save_expr(l, 0, e);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
629 }
177
f8b07153abc4 Make 'imm8' instructions actually complain about a bad operand if no # is present
lost@l-w.ca
parents: 136
diff changeset
630 else
f8b07153abc4 Make 'imm8' instructions actually complain about a bad operand if no # is present
lost@l-w.ca
parents: 136
diff changeset
631 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
632 lwasm_register_error(as, l, E_OPERAND_BAD);
177
f8b07153abc4 Make 'imm8' instructions actually complain about a bad operand if no # is present
lost@l-w.ca
parents: 136
diff changeset
633 }
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
634 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
635
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
636 EMITFUNC(insn_emit_imm8)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
637 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
638 lw_expr_t e;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
639
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
640 lwasm_emitop(l, instab[l -> insn].ops[0]);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
641 e = lwasm_fetch_expr(l, 0);
355
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
642 if (lw_expr_istype(e, lw_expr_type_int))
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
643 {
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
644 int i;
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
645 i = lw_expr_intval(e);
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
646 if (i < -128 || i > 255)
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
647 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
648 lwasm_register_error(as, l, E_BYTE_OVERFLOW);
355
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
649 }
3afb809c7add Make 8 bit immediate operands flag a byte overflow if not in 8 bit range.
William Astle <lost@l-w.ca>
parents: 283
diff changeset
650 }
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
651 lwasm_emitexpr(l, e, 1);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
652 }