annotate lwasm/insn_gen.c @ 476:eac8f5f0867d

Update operandsizewarning to detect JMP and JSR that could use BRA or BSR The operandsizewarning pragma will now raise warnings when it detects that a JMP or JSR instruction is using extended addresing when the target of the branch is within range of a BRA or BSR instruction.
author William Astle <lost@l-w.ca>
date Wed, 12 Dec 2018 19:40:16 -0700
parents 2c1c5dd84024
children 62720ac9e28d
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 {
3948c874901b Make offset,R operand size warning work properly
William Astle <lost@l-w.ca>
parents: 402
diff changeset
325 if (l -> pb != 0xAF && l -> pb != 0xB0)
3948c874901b Make offset,R operand size warning work properly
William Astle <lost@l-w.ca>
parents: 402
diff changeset
326 {
3948c874901b Make offset,R operand size warning work properly
William Astle <lost@l-w.ca>
parents: 402
diff changeset
327 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
328 {
3948c874901b Make offset,R operand size warning work properly
William Astle <lost@l-w.ca>
parents: 402
diff changeset
329 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
330
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 }
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
334 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
335 }
376
35d4213e6657 Add cycle counting to listing
William Astle <lost@l-w.ca>
parents: 374
diff changeset
336
35d4213e6657 Add cycle counting to listing
William Astle <lost@l-w.ca>
parents: 374
diff changeset
337 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
338 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
339 }
2c24602be78f 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 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
342 {
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
343 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
344
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 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
346 {
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 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
348 {
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 // 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
350 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
351 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
352 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
353 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
354 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
355 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
356 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
357 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
358 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
359 {
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 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
361 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
362 {
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 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
364 }
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 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
367 }
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 }
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
370 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
371 {
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
372 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
373 }
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
374 }
2c24602be78f 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 // 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
377 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
378 {
2c24602be78f 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 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
380 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
381 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
382 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
383 }
2c24602be78f 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 // handle non-immediate
136
b78b2f1e011e Fixed additional instruction length problems with logic/memory operations
lost@l-w.ca
parents: 2
diff changeset
386 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
387 }
2c24602be78f 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 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
390 {
2c24602be78f 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 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
392 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
393
2c24602be78f 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 // 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
395 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
396 }
2c24602be78f 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 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
399 {
2c24602be78f 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 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
401 }
2c24602be78f 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 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
404 {
380
17fcd0c3ee45 Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents: 376
diff changeset
405 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
406 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
407 {
2c24602be78f 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 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
409
2c24602be78f 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 (*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
411 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
412 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
413 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
414 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
415 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
416 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
417 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
418 }
2c24602be78f 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 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
420 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
421 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
422 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
423 }
2c24602be78f 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 // handle non-immediate
136
b78b2f1e011e Fixed additional instruction length problems with logic/memory operations
lost@l-w.ca
parents: 2
diff changeset
426 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
427 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
428 {
2c24602be78f 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 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
430 {
2c24602be78f 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 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
432 }
2c24602be78f 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 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
434 {
2c24602be78f 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 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
436 }
2c24602be78f 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 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
438 {
470
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
439 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
440 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
441 else
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
442 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
443 }
2c24602be78f 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 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
448 {
2c24602be78f 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 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
450 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
451
2c24602be78f 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 // 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
453 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
454 }
2c24602be78f 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 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
457 {
2c24602be78f 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 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
459 {
2c24602be78f 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 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
461 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
462 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
463 {
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 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
465 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
466 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
467 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
468 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
469 }
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
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
472 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
473 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
474 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
475 }
2c24602be78f 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 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
478 }
2c24602be78f 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 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
481 {
380
17fcd0c3ee45 Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents: 376
diff changeset
482 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
483 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
484 {
2c24602be78f 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 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
486
2c24602be78f 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 (*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
488 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
489 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
490 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
491 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
492 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
493 }
2c24602be78f 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 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
495 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
496 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
497 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
498 }
2c24602be78f 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 // handle non-immediate
136
b78b2f1e011e Fixed additional instruction length problems with logic/memory operations
lost@l-w.ca
parents: 2
diff changeset
501 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
502 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
503 {
2c24602be78f 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 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
505 {
2c24602be78f 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 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
507 }
2c24602be78f 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 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
509 {
2c24602be78f 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 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
511 }
2c24602be78f 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 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
513 {
470
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
514 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
515 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
516 else
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
517 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
518 }
2c24602be78f 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 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
523 {
2c24602be78f 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 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
525 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
526
2c24602be78f 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 // 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
528 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
529 }
2c24602be78f 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 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
532 {
2c24602be78f 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 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
534 {
2c24602be78f 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 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
536 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
537 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
538 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
539 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
540 }
2c24602be78f 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 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
543 }
2c24602be78f 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 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
546 {
380
17fcd0c3ee45 Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents: 376
diff changeset
547 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
548 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
549 {
2c24602be78f 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 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
551
2c24602be78f 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 (*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
553 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
554 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
555 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
556 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
557 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
558 }
2c24602be78f 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 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
560 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
561 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
562 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
563 }
2c24602be78f 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 // handle non-immediate
136
b78b2f1e011e Fixed additional instruction length problems with logic/memory operations
lost@l-w.ca
parents: 2
diff changeset
566 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
567 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
568 {
2c24602be78f 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 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
570 {
2c24602be78f 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 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
572 }
2c24602be78f 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 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
574 {
2c24602be78f 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 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
576 }
2c24602be78f 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 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
578 {
470
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
579 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
580 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
581 else
2c1c5dd84024 Add << prefix to force 5 bit offsets in indexed modes
William Astle <lost@l-w.ca>
parents: 458
diff changeset
582 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
583 }
2c24602be78f 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 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
588 {
2c24602be78f 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 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
590 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
591
2c24602be78f 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 // 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
593 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
594 }
2c24602be78f 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 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
597 {
2c24602be78f 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 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
599 {
2c24602be78f 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 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
601 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
602 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
603 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
604 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
605 }
2c24602be78f 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 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
608 }
2c24602be78f 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 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
611 {
2c24602be78f 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 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
613
2c24602be78f 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 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
615 {
2c24602be78f 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 (*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
617
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
618 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
619 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
620 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
621 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
622 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
623 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
624 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
625 }
2c24602be78f 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 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
627 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
628 }
177
f8b07153abc4 Make 'imm8' instructions actually complain about a bad operand if no # is present
lost@l-w.ca
parents: 136
diff changeset
629 else
f8b07153abc4 Make 'imm8' instructions actually complain about a bad operand if no # is present
lost@l-w.ca
parents: 136
diff changeset
630 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
631 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
632 }
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
633 }
2c24602be78f 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 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
636 {
2c24602be78f 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 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
638
2c24602be78f 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 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
640 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
641 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
642 {
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 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
644 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
645 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
646 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 366
diff changeset
647 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
648 }
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 }
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
650 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
651 }