Mercurial > hg > index.cgi
annotate lwasm/lwasm.c @ 432:58cafa61ab40
Add support for undocumented custom module format (for LW)
Nothing to see here. Move along. These are not the droids you are looking
for.
author | William Astle <lost@l-w.ca> |
---|---|
date | Fri, 18 Nov 2016 21:25:43 -0700 |
parents | 5dc9f9d47064 |
children | b1adf549d181 |
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 lwasm.c |
2c24602be78f
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 Copyright © 2010 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
|
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 This file is part of LWTOOLS. |
2c24602be78f
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 |
2c24602be78f
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 LWTOOLS 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
|
9 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
|
10 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
|
11 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
|
12 |
2c24602be78f
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 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
|
14 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
|
15 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
|
16 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
|
17 |
2c24602be78f
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 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
|
19 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
|
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 <stdio.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 <stdarg.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 #include <string.h> |
2
7317fbe024af
Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents:
0
diff
changeset
|
25 #include <ctype.h> |
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
|
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 <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
|
28 #include <lw_alloc.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 #include <lw_string.h> |
375 | 30 #include <lw_error.h> |
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
|
31 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
32 #include "lwasm.h" |
336
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
33 #include "instab.h" |
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
|
34 |
399
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
35 void lwasm_skip_to_next_token(line_t *cl, char **p) |
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
36 { |
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
37 if (CURPRAGMA(cl, PRAGMA_NEWSOURCE)) |
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
38 { |
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
39 for (; **p && isspace(**p); (*p)++) |
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
40 /* do nothing */ ; |
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
41 } |
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
42 } |
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
43 |
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
|
44 int lwasm_expr_exportable(asmstate_t *as, lw_expr_t expr) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
45 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
46 return 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
|
47 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
48 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
49 int lwasm_expr_exportval(asmstate_t *as, lw_expr_t expr) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
50 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
51 return 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 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
53 |
249
1f1a28b797e1
Add trap for divide by zero in expression library
William Astle <lost@l-w.ca>
parents:
241
diff
changeset
|
54 void lwasm_dividezero(void *priv) |
1f1a28b797e1
Add trap for divide by zero in expression library
William Astle <lost@l-w.ca>
parents:
241
diff
changeset
|
55 { |
1f1a28b797e1
Add trap for divide by zero in expression library
William Astle <lost@l-w.ca>
parents:
241
diff
changeset
|
56 asmstate_t *as = (asmstate_t *)priv; |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
57 lwasm_register_error(as, as -> cl, E_DIV0); |
249
1f1a28b797e1
Add trap for divide by zero in expression library
William Astle <lost@l-w.ca>
parents:
241
diff
changeset
|
58 } |
1f1a28b797e1
Add trap for divide by zero in expression library
William Astle <lost@l-w.ca>
parents:
241
diff
changeset
|
59 |
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
|
60 lw_expr_t lwasm_evaluate_var(char *var, void *priv) |
2c24602be78f
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 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
62 asmstate_t *as = (asmstate_t *)priv; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
63 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
|
64 importlist_t *im; |
2c24602be78f
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 struct symtabe *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
|
66 |
2c24602be78f
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 s = lookup_symbol(as, as -> cl, var); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
68 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
|
69 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
70 e = lw_expr_build(lw_expr_type_special, lwasm_expr_syment, 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
|
71 return 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
|
72 } |
2c24602be78f
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 |
210 | 74 if (as -> undefzero) |
75 { | |
76 e = lw_expr_build(lw_expr_type_int, 0); | |
77 return e; | |
78 } | |
79 | |
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
|
80 // undefined here is undefied unless output is object |
2c24602be78f
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 if (as -> output_format != OUTPUT_OBJ) |
2c24602be78f
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 goto nomatch; |
2c24602be78f
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 // check for import |
2c24602be78f
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 for (im = as -> importlist; im; im = im -> next) |
2c24602be78f
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 if (!strcmp(im -> symbol, var)) |
2c24602be78f
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 break; |
2c24602be78f
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 |
2c24602be78f
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 // check for "undefined" to import automatically |
70
ceab04fd2969
Fixed premature installation of external reference under UNDEFEXTERN pragma; should not resolve to external references until after the initial parsing pass
lost@l-w.ca
parents:
44
diff
changeset
|
92 if ((as -> passno != 0) && !im && CURPRAGMA(as -> cl, PRAGMA_UNDEFEXTERN)) |
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
|
93 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
94 im = lw_alloc(sizeof(importlist_t)); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
95 im -> symbol = lw_strdup(var); |
2c24602be78f
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 im -> next = as -> importlist; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
97 as -> importlist = im; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
98 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
99 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
100 if (!im) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
101 goto nomatch; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
102 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
103 e = lw_expr_build(lw_expr_type_special, lwasm_expr_import, im); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
104 return 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
|
105 |
2c24602be78f
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 nomatch: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
107 if (as -> badsymerr) |
2c24602be78f
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 { |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
109 lwasm_register_error2(as, as -> cl, E_SYMBOL_UNDEFINED, "%s", var); |
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
|
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 return NULL; |
2c24602be78f
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 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
113 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
114 lw_expr_t lwasm_evaluate_special(int t, void *ptr, void *priv) |
2c24602be78f
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 { |
2c24602be78f
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 switch (t) |
2c24602be78f
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 { |
2c24602be78f
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 case lwasm_expr_secbase: |
2c24602be78f
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 // sectiontab_t *s = priv; |
2c24602be78f
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 asmstate_t *as = priv; |
432
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
122 if (((sectiontab_t *)ptr) -> tbase != -1) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
123 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
124 return lw_expr_build(lw_expr_type_int, ((sectiontab_t *)ptr) -> tbase); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
125 } |
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
|
126 if (as -> exportcheck && ptr == as -> csect) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
127 return lw_expr_build(lw_expr_type_int, 0); |
158
8dead67ba607
Make constant sections always resolve with a constant base offset of zero instead of an undefined reference
lost@l-w.ca
parents:
142
diff
changeset
|
128 if (((sectiontab_t *)ptr) -> flags & section_flag_constant) |
8dead67ba607
Make constant sections always resolve with a constant base offset of zero instead of an undefined reference
lost@l-w.ca
parents:
142
diff
changeset
|
129 return lw_expr_build(lw_expr_type_int, 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
|
130 return NULL; |
2c24602be78f
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 } |
142
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
132 |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
133 case lwasm_expr_linedlen: |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
134 { |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
135 line_t *cl = ptr; |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
136 if (cl -> dlen == -1) |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
137 return NULL; |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
138 return lw_expr_build(lw_expr_type_int, cl -> dlen); |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
139 } |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
140 break; |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
141 |
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
|
142 case lwasm_expr_linelen: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
143 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
144 line_t *cl = ptr; |
211
6f2e18f1fe67
Improve autobranchlength pragma
William Astle <lost@l-w.ca>
parents:
210
diff
changeset
|
145 if (cl -> len != -1) |
6f2e18f1fe67
Improve autobranchlength pragma
William Astle <lost@l-w.ca>
parents:
210
diff
changeset
|
146 return lw_expr_build(lw_expr_type_int, cl -> len); |
6f2e18f1fe67
Improve autobranchlength pragma
William Astle <lost@l-w.ca>
parents:
210
diff
changeset
|
147 |
6f2e18f1fe67
Improve autobranchlength pragma
William Astle <lost@l-w.ca>
parents:
210
diff
changeset
|
148 if (cl -> as -> pretendmax) |
6f2e18f1fe67
Improve autobranchlength pragma
William Astle <lost@l-w.ca>
parents:
210
diff
changeset
|
149 { |
6f2e18f1fe67
Improve autobranchlength pragma
William Astle <lost@l-w.ca>
parents:
210
diff
changeset
|
150 if (cl -> maxlen != 0) |
6f2e18f1fe67
Improve autobranchlength pragma
William Astle <lost@l-w.ca>
parents:
210
diff
changeset
|
151 { |
240 | 152 //fprintf(stderr, "Pretending max, len = %d\n", cl -> maxlen); |
211
6f2e18f1fe67
Improve autobranchlength pragma
William Astle <lost@l-w.ca>
parents:
210
diff
changeset
|
153 return lw_expr_build(lw_expr_type_int, cl -> maxlen); |
6f2e18f1fe67
Improve autobranchlength pragma
William Astle <lost@l-w.ca>
parents:
210
diff
changeset
|
154 } |
6f2e18f1fe67
Improve autobranchlength pragma
William Astle <lost@l-w.ca>
parents:
210
diff
changeset
|
155 } |
6f2e18f1fe67
Improve autobranchlength pragma
William Astle <lost@l-w.ca>
parents:
210
diff
changeset
|
156 return NULL; |
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
|
157 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
158 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
159 |
142
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
160 case lwasm_expr_linedaddr: |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
161 { |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
162 line_t *cl = ptr; |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
163 return lw_expr_copy(cl -> daddr); |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
164 } |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
165 |
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
|
166 case lwasm_expr_lineaddr: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
167 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
168 line_t *cl = ptr; |
2c24602be78f
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 if (cl -> addr) |
2c24602be78f
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 return lw_expr_copy(cl -> addr); |
2c24602be78f
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 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
|
172 return NULL; |
2c24602be78f
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 } |
2c24602be78f
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 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
175 case lwasm_expr_syment: |
2c24602be78f
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 struct symtabe *sym = ptr; |
2c24602be78f
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 return lw_expr_copy(sym -> value); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
179 } |
2c24602be78f
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 case lwasm_expr_import: |
2c24602be78f
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 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
183 return NULL; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
184 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
185 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
186 case lwasm_expr_nextbp: |
2c24602be78f
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 line_t *cl = ptr; |
2c24602be78f
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 for (cl = cl -> next; cl; cl = cl -> next) |
2c24602be78f
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 if (cl -> isbrpt) |
2c24602be78f
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 break; |
2c24602be78f
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 } |
2c24602be78f
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 if (cl) |
2c24602be78f
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 { |
2c24602be78f
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 return lw_expr_copy(cl -> addr); |
2c24602be78f
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 } |
2c24602be78f
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 return NULL; |
2c24602be78f
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 } |
2c24602be78f
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 case lwasm_expr_prevbp: |
2c24602be78f
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 { |
2c24602be78f
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 line_t *cl = ptr; |
2c24602be78f
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 for (cl = cl -> prev; cl; cl = cl -> prev) |
2c24602be78f
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 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
206 if (cl -> isbrpt) |
2c24602be78f
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 break; |
2c24602be78f
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 if (cl) |
2c24602be78f
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 return lw_expr_copy(cl -> addr); |
2c24602be78f
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 return NULL; |
2c24602be78f
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 } |
2c24602be78f
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 return NULL; |
2c24602be78f
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 |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
219 const char* lwasm_lookup_error(lwasm_errorcode_t error_code) |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
220 { |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
221 switch (error_code) |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
222 { |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
223 case E_6309_INVALID: return "Illegal use of 6309 instruction in 6809 mode"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
224 case E_6809_INVALID: return "Illegal use of 6809 instruction in 6309 mode"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
225 case E_ALIGNMENT_INVALID: return "Invalid alignment"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
226 case E_BITNUMBER_INVALID: return "Invalid bit number"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
227 case E_BITNUMBER_UNRESOLVED: return "Bit number must be fully resolved"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
228 case E_BYTE_OVERFLOW: return "Byte overflow"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
229 case E_CONDITION_P1: return "Conditions must be constant on pass 1"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
230 case E_DIRECTIVE_OS9_ONLY: return "Directive only valid for OS9 target"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
231 case E_DIV0: return "Division by zero"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
232 case E_EXEC_ADDRESS: return "Exec address not constant!"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
233 case E_EXPRESSION_BAD: return "Bad expression"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
234 case E_EXPRESSION_NOT_CONST: return "Expression must be constant"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
235 case E_EXPRESSION_NOT_RESOLVED: return "Expression not fully resolved"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
236 case E_FILE_OPEN: return "Cannot open file"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
237 case E_FILENAME_MISSING: return "Missing filename"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
238 case E_FILL_INVALID: return "Invalid fill length"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
239 case E_IMMEDIATE_INVALID: return "Immediate mode not allowed"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
240 case E_IMMEDIATE_UNRESOLVED: return "Immediate byte must be fully resolved"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
241 case E_INSTRUCTION_FAILED: return "Instruction failed to resolve."; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
242 case E_INSTRUCTION_SECTION: return "Instruction generating output outside of a section"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
243 case E_LINE_ADDRESS: return "Cannot resolve line address"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
244 case E_LINED_ADDRESS: return "Cannot resolve line data address"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
245 case E_OBJTARGET_ONLY: return "Only supported for object target"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
246 case E_OPCODE_BAD: return "Bad opcode"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
247 case E_OPERAND_BAD: return "Bad operand"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
248 case E_PADDING_BAD: return "Bad padding"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
249 case E_PRAGMA_UNRECOGNIZED: return "Unrecognized pragma string"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
250 case E_REGISTER_BAD: return "Bad register"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
251 case E_SETDP_INVALID: return "SETDP not permitted for object target"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
252 case E_SETDP_NOT_CONST: return "SETDP must be constant on pass 1"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
253 case E_STRING_BAD: return "Bad string condition"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
254 case E_SYMBOL_BAD: return "Bad symbol"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
255 case E_SYMBOL_MISSING: return "Missing symbol"; |
412
f8e56377a32a
lwasm: Add missing "Undefined symbol" error string
Tormod Volden <debian.tormod@gmail.com>
parents:
399
diff
changeset
|
256 case E_SYMBOL_UNDEFINED: return "Undefined symbol"; |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
257 case E_SYMBOL_UNDEFINED_EXPORT: return "Undefined exported symbol"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
258 case E_MACRO_DUPE: return "Duplicate macro definition"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
259 case E_MACRO_ENDM: return "ENDM without MACRO"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
260 case E_MACRO_NONAME: return "Missing macro name"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
261 case E_MACRO_RECURSE: return "Attempt to define a macro inside a macro"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
262 case E_MODULE_IN: return "Already in a module!"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
263 case E_MODULE_NOTIN: return "Not in a module!"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
264 case E_NEGATIVE_BLOCKSIZE: return "Negative block sizes make no sense!"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
265 case E_NEGATIVE_RESERVATION: return "Negative reservation sizes make no sense!"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
266 case E_NW_8: return "n,W cannot be 8 bit"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
267 case E_SECTION_END: return "ENDSECTION without SECTION"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
268 case E_SECTION_EXTDEP: return "EXTDEP must be within a section"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
269 case E_SECTION_FLAG: return "Unrecognized section flag"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
270 case E_SECTION_NAME: return "Need section name"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
271 case E_SECTION_TARGET: return "Cannot use sections unless using the object target"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
272 case E_STRUCT_DUPE: return "Duplicate structure definition"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
273 case E_STRUCT_NONAME: return "Cannot declare a structure without a symbol name."; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
274 case E_STRUCT_NOSYMBOL: return "Structure definition with no effect - no symbol"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
275 case E_STRUCT_RECURSE: return "Attempt to define a structure inside a structure"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
276 case E_SYMBOL_DUPE: return "Multiply defined symbol"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
277 case E_UNKNOWN_OPERATION: return "Unknown operation"; |
382 | 278 case E_ORG_NOT_FOUND: return "Previous ORG not found"; |
432
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
279 case E_COMPLEX_INCOMPLETE: return "Incomplete expression too complex"; |
413
5dc9f9d47064
Add error string for "user error"
William Astle <lost@l-w.ca>
parents:
412
diff
changeset
|
280 case E_USER_SPECIFIED: return "User Specified:"; |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
281 |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
282 case W_ENDSTRUCT_WITHOUT: return "ENDSTRUCT without STRUCT"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
283 case W_DUPLICATE_SECTION: return "Section flags can only be specified the first time; ignoring duplicate definition"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
284 case W_NOT_SUPPORTED: return "Not supported"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
285 |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
286 default: return "Error"; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
287 } |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
288 } |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
289 |
375 | 290 /* keeping this as a separate error output for stability in unit test scripts */ |
291 void lwasm_error_testmode(line_t *cl, const char* msg, int fatal) | |
292 { | |
293 cl -> as -> testmode_errorcount++; | |
294 fprintf(stderr, "line %d: %s : %s\n", cl->lineno, msg, cl->ltext); | |
295 if (fatal == 1) lw_error("aborting\n"); | |
296 } | |
297 | |
298 /* parse unit test input data from comment field */ | |
299 void lwasm_parse_testmode_comment(line_t *l, lwasm_testflags_t *flags, lwasm_errorcode_t *err, int *len, char **buf) | |
300 { | |
301 *flags = 0; | |
302 | |
303 if (!l) | |
304 return; | |
305 | |
306 char* s = strstr(l -> ltext, ";."); | |
307 if (s == NULL) return; | |
308 | |
309 char* t = strstr(s, ":"); | |
310 if (t == NULL) | |
311 { | |
312 /* parse: ;.8E0FCE (emitted code) */ | |
313 | |
314 if (buf == NULL) return; | |
315 | |
316 int i; | |
317 *flags = TF_EMIT; | |
318 | |
319 s = s + 2; /* skip ;. prefix */ | |
320 t = s; | |
321 while (*t > 32) t++; | |
322 | |
323 if ((t - s) & 1) | |
324 { | |
325 lwasm_error_testmode(l, "bad test data (wrong length of hex chars)", 1); | |
326 return; | |
327 } | |
328 | |
329 *len = (t - s) / 2; | |
330 | |
331 t = lw_alloc(*len); | |
332 *buf = t; | |
333 | |
334 for (i = 0; i < *len; i++) | |
335 { | |
336 int val; | |
337 sscanf(s, "%2x", &val); | |
338 *t++ = (char) val; | |
339 s += 2; | |
340 } | |
341 } | |
342 else | |
343 { | |
344 /* parse: ;.E:1000 or ;.E:7 (warnings or errors) */ | |
345 *flags = TF_ERROR; | |
346 | |
347 char ch = toupper(*(t - 1)); | |
348 if (ch != 'E') lwasm_error_testmode(l, "bad test data (expected E: flag)", 1); | |
349 sscanf(t + 1, "%d", (int*) err); | |
350 } | |
351 } | |
352 | |
353 void lwasm_register_error_real(asmstate_t *as, line_t *l, lwasm_errorcode_t error_code, const char *msg) | |
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
|
354 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
355 lwasm_error_t *e; |
209 | 356 |
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
|
357 if (!l) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
358 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
|
359 |
375 | 360 if (CURPRAGMA(l, PRAGMA_TESTMODE)) |
361 { | |
362 lwasm_testflags_t flags; | |
363 lwasm_errorcode_t testmode_error_code; | |
364 lwasm_parse_testmode_comment(l, &flags, &testmode_error_code, NULL, NULL); | |
365 if (flags == TF_ERROR) | |
366 { | |
367 l -> len = 0; /* null out bogus line */ | |
368 l -> insn = -1; | |
369 l -> err_testmode = error_code; | |
370 if (testmode_error_code == error_code) return; /* expected error: ignore and keep assembling */ | |
371 | |
372 char buf[128]; | |
373 sprintf(buf, "wrong error code (%d)", error_code); | |
374 lwasm_error_testmode(l, buf, 0); | |
375 return; | |
376 } | |
377 } | |
378 | |
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
|
379 e = lw_alloc(sizeof(lwasm_error_t)); |
226
7c2c2239ec9c
Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents:
216
diff
changeset
|
380 |
375 | 381 if (error_code >= 1000) |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
382 { |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
383 e->next = l->warn; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
384 l->warn = e; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
385 as->warningcount++; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
386 } |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
387 else |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
388 { |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
389 e->next = l->err; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
390 l->err = e; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
391 as->errorcount++; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
392 } |
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
|
393 |
375 | 394 e -> code = error_code; |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
395 e -> charpos = -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
|
396 |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
397 e -> mess = lw_strdup(msg); |
226
7c2c2239ec9c
Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents:
216
diff
changeset
|
398 } |
7c2c2239ec9c
Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents:
216
diff
changeset
|
399 |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
400 void lwasm_register_error(asmstate_t *as, line_t *l, lwasm_errorcode_t err) |
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
|
401 { |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
402 lwasm_register_error_real(as, l, err, lwasm_lookup_error(err)); |
226
7c2c2239ec9c
Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents:
216
diff
changeset
|
403 } |
7c2c2239ec9c
Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents:
216
diff
changeset
|
404 |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
405 void lwasm_register_error2(asmstate_t *as, line_t *l, lwasm_errorcode_t err, const char* fmt, ...) |
226
7c2c2239ec9c
Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents:
216
diff
changeset
|
406 { |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
407 char errbuff[1024]; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
408 char f[128]; |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
409 |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
410 sprintf(f, "%s %s", lwasm_lookup_error(err), fmt); |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
411 |
226
7c2c2239ec9c
Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents:
216
diff
changeset
|
412 va_list args; |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
413 |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
414 va_start(args, fmt); |
226
7c2c2239ec9c
Make unicorns grok errors and warnings.
William Astle <lost@l-w.ca>
parents:
216
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 (void) vsnprintf(errbuff, 1024, f, args); |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
417 |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
418 lwasm_register_error_real(as, l, err, errbuff); |
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
419 |
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
|
420 va_end(args); |
2c24602be78f
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 } |
2c24602be78f
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 |
2c24602be78f
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 int lwasm_next_context(asmstate_t *as) |
2c24602be78f
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 int r; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
426 r = as -> nextcontext; |
2c24602be78f
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 as -> nextcontext++; |
2c24602be78f
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 return r; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
429 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
430 |
2c24602be78f
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 void lwasm_emit(line_t *cl, int byte) |
2c24602be78f
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 { |
13
c80e5a063967
Brought forward patch to fix segfault with output outside of a section
lost@l-w.ca
parents:
2
diff
changeset
|
433 if (cl -> as -> output_format == OUTPUT_OBJ && cl -> csect == NULL) |
c80e5a063967
Brought forward patch to fix segfault with output outside of a section
lost@l-w.ca
parents:
2
diff
changeset
|
434 { |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
435 lwasm_register_error(cl -> as, cl, E_INSTRUCTION_SECTION); |
13
c80e5a063967
Brought forward patch to fix segfault with output outside of a section
lost@l-w.ca
parents:
2
diff
changeset
|
436 return; |
c80e5a063967
Brought forward patch to fix segfault with output outside of a section
lost@l-w.ca
parents:
2
diff
changeset
|
437 } |
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
|
438 if (cl -> outputl < 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
|
439 cl -> outputl = 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
|
440 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
441 if (cl -> outputl == cl -> outputbl) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
442 { |
2c24602be78f
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 cl -> output = lw_realloc(cl -> output, cl -> outputbl + 8); |
2c24602be78f
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 cl -> outputbl += 8; |
2c24602be78f
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 cl -> output[cl -> outputl++] = byte & 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
|
447 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
448 if (cl -> inmod) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
449 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
450 asmstate_t *as = cl -> as; |
2c24602be78f
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 // update module CRC |
2c24602be78f
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 // this is a direct transliteration from the nitros9 asm source |
2c24602be78f
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 // to C; it can, no doubt, be optimized for 32 bit processing |
2c24602be78f
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 byte &= 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
|
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 byte ^= (as -> crc)[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
|
457 (as -> crc)[0] = (as -> crc)[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
|
458 (as -> crc)[1] = (as -> crc)[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
|
459 (as -> crc)[1] ^= (byte >> 7); |
2c24602be78f
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 (as -> crc)[2] = (byte << 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
|
461 (as -> crc)[1] ^= (byte >> 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
|
462 (as -> crc)[2] ^= (byte << 6); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
463 byte ^= (byte << 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
|
464 byte ^= (byte << 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
|
465 byte ^= (byte << 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
|
466 if (byte & 0x80) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
467 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
468 (as -> crc)[0] ^= 0x80; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
469 (as -> crc)[2] ^= 0x21; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
470 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
471 } |
2c24602be78f
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 } |
2c24602be78f
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 |
2c24602be78f
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 void lwasm_emitop(line_t *cl, int opc) |
2c24602be78f
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 { |
376 | 476 if (cl->cycle_base == 0) |
477 lwasm_cycle_update_count(cl, opc); /* only call first time, never on postbyte */ | |
478 | |
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
|
479 if (opc > 0x100) |
2c24602be78f
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 lwasm_emit(cl, opc >> 8); |
2c24602be78f
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 lwasm_emit(cl, opc); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
482 } |
2c24602be78f
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 |
2c24602be78f
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 lw_expr_t lwasm_parse_term(char **p, void *priv) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
485 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
486 asmstate_t *as = priv; |
44 | 487 int neg = 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
|
488 int val; |
2c24602be78f
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 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
490 if (!**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
|
491 return NULL; |
2c24602be78f
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 |
142
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
493 if (**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
|
494 && !((*p)[1] >= 'A' && (*p)[1] <= 'Z') |
2c24602be78f
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 && !((*p)[1] >= 'a' && (*p)[1] <= 'z') |
2c24602be78f
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 && !((*p)[1] >= '0' && (*p)[1] <= '9') |
142
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
497 ) |
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
|
498 { |
142
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
499 (*p)++; |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
500 return lw_expr_build(lw_expr_type_special, lwasm_expr_linedaddr, as -> cl); |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
501 } |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
502 |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
503 if (**p == '*') |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
504 { |
697bc543368c
Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents:
113
diff
changeset
|
505 // special "symbol" for current line addr (*) |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
506 (*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
|
507 return lw_expr_build(lw_expr_type_special, lwasm_expr_lineaddr, as -> cl); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
508 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
509 |
2c24602be78f
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 // branch points |
2c24602be78f
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 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
|
512 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
513 (*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
|
514 return lw_expr_build(lw_expr_type_special, lwasm_expr_prevbp, as -> cl); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
515 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
516 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
|
517 { |
2c24602be78f
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 (*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
|
519 return lw_expr_build(lw_expr_type_special, lwasm_expr_nextbp, as -> cl); |
2c24602be78f
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 // double ascii constant |
2c24602be78f
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 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
|
524 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
525 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
|
526 (*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
|
527 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
|
528 return NULL; |
2c24602be78f
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 if (!*((*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
|
530 return NULL; |
2c24602be78f
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 v = (unsigned char)**p << 8 | (unsigned char)*((*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
|
532 (*p) += 2; |
326
d399df78e1ab
Allow trailing ' or " on ascii constants
Tom LeMense <tlemense@yahoo.com>
parents:
256
diff
changeset
|
533 |
d399df78e1ab
Allow trailing ' or " on ascii constants
Tom LeMense <tlemense@yahoo.com>
parents:
256
diff
changeset
|
534 if (**p == '"') |
d399df78e1ab
Allow trailing ' or " on ascii constants
Tom LeMense <tlemense@yahoo.com>
parents:
256
diff
changeset
|
535 (*p)++; |
d399df78e1ab
Allow trailing ' or " on ascii constants
Tom LeMense <tlemense@yahoo.com>
parents:
256
diff
changeset
|
536 |
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 return lw_expr_build(lw_expr_type_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
|
538 } |
2c24602be78f
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 |
380
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
540 /* double ASCII constant, like LDD #'MG */ |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
541 if (CURPRAGMA(as->cl, PRAGMA_M80EXT)) |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
542 { |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
543 if (((**p == '"') || (**p == '\'')) && (as->cl->genmode == 16)) |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
544 { |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
545 int v; |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
546 (*p)++; |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
547 if (!**p) |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
548 return NULL; |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
549 if (!*((*p) + 1)) |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
550 return NULL; |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
551 v = (unsigned char) **p << 8 | (unsigned char) *((*p) + 1); |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
552 (*p) += 2; |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
553 |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
554 if ((**p == '"') || (**p == '\'')) |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
555 (*p)++; |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
556 |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
557 return lw_expr_build(lw_expr_type_int, v); |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
558 } |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
559 } |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
560 |
17fcd0c3ee45
Allow multibyte ascii constants in m80ext mode
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
561 /* single ASCII constant, like LDA #'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
|
562 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
|
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 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
|
565 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
566 (*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
|
567 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
|
568 return NULL; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
569 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
570 v = (unsigned char)**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
|
571 (*p)++; |
326
d399df78e1ab
Allow trailing ' or " on ascii constants
Tom LeMense <tlemense@yahoo.com>
parents:
256
diff
changeset
|
572 |
d399df78e1ab
Allow trailing ' or " on ascii constants
Tom LeMense <tlemense@yahoo.com>
parents:
256
diff
changeset
|
573 if (**p == '\'') |
d399df78e1ab
Allow trailing ' or " on ascii constants
Tom LeMense <tlemense@yahoo.com>
parents:
256
diff
changeset
|
574 (*p)++; |
d399df78e1ab
Allow trailing ' or " on ascii constants
Tom LeMense <tlemense@yahoo.com>
parents:
256
diff
changeset
|
575 |
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
|
576 return lw_expr_build(lw_expr_type_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
|
577 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
578 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
579 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
|
580 { |
113
7e621e00b887
Fixed uninitialized variable in &-prefix and %-prefix constant parsing
lost@l-w.ca
parents:
98
diff
changeset
|
581 val = 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
|
582 // decimal constant |
2c24602be78f
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 (*p)++; |
44 | 584 |
585 if (**p == '-') | |
586 { | |
587 (*p)++; | |
588 neg = -1; | |
589 } | |
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
|
590 |
354
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
591 if (!**p || !strchr("0123456789", **p)) |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
592 { |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
593 (*p)--; |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
594 if (neg < 0) |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
595 (*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
|
596 return NULL; |
354
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
597 } |
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
|
598 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
599 while (**p && strchr("0123456789", **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
|
600 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
601 val = val * 10 + (**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
|
602 (*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
|
603 } |
95 | 604 return lw_expr_build(lw_expr_type_int, val * neg); |
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
|
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 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
|
608 { |
113
7e621e00b887
Fixed uninitialized variable in &-prefix and %-prefix constant parsing
lost@l-w.ca
parents:
98
diff
changeset
|
609 val = 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
|
610 // binary constant |
2c24602be78f
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 (*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
|
612 |
44 | 613 if (**p == '-') |
614 { | |
615 (*p)++; | |
616 neg = -1; | |
617 } | |
618 | |
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 if (**p != '0' && **p != '1') |
354
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
620 { |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
621 (*p)--; |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
622 if (neg < 0) |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
623 (*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
|
624 return NULL; |
354
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
625 } |
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
|
626 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
627 while (**p && (**p == '0' || **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
|
628 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
629 val = val * 2 + (**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
|
630 (*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
|
631 } |
94 | 632 return lw_expr_build(lw_expr_type_int, val * neg); |
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 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
|
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 // hexadecimal constant |
2c24602be78f
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 int v = 0, v2; |
2c24602be78f
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 (*p)++; |
44 | 640 if (**p == '-') |
641 { | |
642 (*p)++; | |
643 neg = -1; | |
644 } | |
645 | |
354
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
646 if (!**p || !strchr("0123456789abcdefABCDEF", **p)) |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
647 { |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
648 (*p)--; |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
649 if (neg < 0) |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
650 (*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
|
651 return NULL; |
354
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
652 } |
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
|
653 while (**p && strchr("0123456789abcdefABCDEF", **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
|
654 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
655 v2 = toupper(**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
|
656 if (v2 > 9) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
657 v2 -= 7; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
658 v = v * 16 + v2; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
659 (*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
|
660 } |
44 | 661 return lw_expr_build(lw_expr_type_int, v * neg); |
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
|
662 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
663 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
664 if (**p == '0' && (*((*p)+1) == 'x' || *((*p)+1) == 'X')) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
665 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
666 // hexadecimal constant, C style |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
667 int v = 0, v2; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
668 (*p)+=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
|
669 |
354
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
670 if (!**p || !strchr("0123456789abcdefABCDEF", **p)) |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
671 { |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
672 (*p) -= 2; |
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
|
673 return NULL; |
354
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
674 } |
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
|
675 while (**p && strchr("0123456789abcdefABCDEF", **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
|
676 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
677 v2 = toupper(**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
|
678 if (v2 > 9) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
679 v2 -= 7; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
680 v = v * 16 + v2; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
681 (*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
|
682 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
683 return lw_expr_build(lw_expr_type_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
|
684 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
685 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
686 if (**p == '@' && (*((*p)+1) >= '0' && *((*p)+1) <= '7')) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
687 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
688 // octal constant |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
689 int v = 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
|
690 (*p)++; |
44 | 691 if (**p == '-') |
692 { | |
693 (*p)++; | |
694 neg = -1; | |
695 } | |
696 | |
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
|
697 |
354
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
698 if (!**p || !strchr("01234567", **p)) |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
699 { |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
700 (*p)--; |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
701 if (neg < 0) |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
702 (*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
|
703 return NULL; |
354
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
704 } |
433851a26794
Make base prefix sigils error out if no number following
William Astle <lost@l-w.ca>
parents:
336
diff
changeset
|
705 |
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
|
706 while (**p && strchr("01234567", **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
|
707 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
708 v = v * 8 + (**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
|
709 (*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
|
710 } |
44 | 711 return lw_expr_build(lw_expr_type_int, v * neg); |
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
|
712 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
713 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
714 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
715 // symbol or bare decimal or suffix constant here |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
716 do |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
717 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
718 int havedol = 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
|
719 int 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
|
720 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
721 while ((*p)[l] && strchr(SYMCHARS, (*p)[l])) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
722 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
723 if ((*p)[l] == '$') |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
724 havedol = 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
|
725 l++; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
726 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
727 if (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
|
728 return NULL; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
729 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
730 if ((*p)[l] == '{') |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
731 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
732 while ((*p)[l] && (*p)[l] != '}') |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
733 l++; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
734 l++; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
735 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
736 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
737 if (havedol || **p < '0' || **p > '9') |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
738 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
739 // have a symbol here |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
740 char *sym; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
741 lw_expr_t term; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
742 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
743 sym = lw_strndup(*p, l); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
744 (*p) += l; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
745 term = lw_expr_build(lw_expr_type_var, sym); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
746 lw_free(sym); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
747 return term; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
748 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
749 } while (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
|
750 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
751 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
|
752 return NULL; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
753 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
754 // we have a numeric constant here, either decimal or postfix base notation |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
755 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
756 int decval = 0, binval = 0, hexval = 0, octval = 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
|
757 int valtype = 15; // 1 = bin, 2 = oct, 4 = dec, 8 = hex |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
758 int bindone = 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
|
759 int val; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
760 int dval; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
761 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
762 while (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
|
763 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
764 if (!**p || !strchr("0123456789ABCDEFabcdefqhoQHO", **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
|
765 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
766 // we can legally be bin or decimal here |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
767 if (bindone) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
768 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
769 // just finished a binary value |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
770 val = binval; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
771 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
772 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
773 else if (valtype & 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
|
774 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
775 val = decval; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
776 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
777 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
778 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
|
779 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
780 // bad value |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
781 return NULL; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
782 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
783 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
784 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
785 dval = toupper(**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
|
786 (*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
|
787 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
788 if (bindone) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
789 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
790 // any characters past "B" means it is not binary |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
791 bindone = 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
|
792 valtype &= 14; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
793 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
794 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
795 switch (dval) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
796 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
797 case 'Q': |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
798 case 'O': |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
799 if (valtype & 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
|
800 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
801 val = octval; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
802 valtype = -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
|
803 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
804 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
805 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
|
806 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
807 return NULL; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
808 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
809 /* can't get here */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
810 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
811 case '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
|
812 if (valtype & 8) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
813 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
814 val = hexval; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
815 valtype = -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
|
816 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
817 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
818 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
|
819 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
820 return NULL; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
821 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
822 /* can't get here */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
823 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
824 case 'B': |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
825 // this is a bit of a sticky one since B may be a |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
826 // hex number instead of the end of a binary number |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
827 // so it falls through to the digit case |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
828 if (valtype & 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
|
829 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
830 // could still be binary of hex |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
831 bindone = 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
|
832 valtype = 9; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
833 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
834 /* fall through intented */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
835 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
836 default: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
837 // digit |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
838 dval -= '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
|
839 if (dval > 9) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
840 dval -= 7; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
841 if (valtype & 8) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
842 hexval = hexval * 16 + dval; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
843 if (valtype & 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
|
844 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
845 if (dval > 9) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
846 valtype &= 11; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
847 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
|
848 decval = decval * 10 + dval; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
849 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
850 if (valtype & 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
|
851 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
852 if (dval > 7) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
853 valtype &= 13; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
854 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
|
855 octval = octval * 8 + dval; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
856 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
857 if (valtype & 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
|
858 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
859 if (dval > 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
|
860 valtype &= 14; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
861 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
|
862 binval = binval * 2 + dval; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
863 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
864 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
865 if (valtype == -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
|
866 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
867 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
868 // return if no more valid types |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
869 if (valtype == 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
|
870 return NULL; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
871 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
872 val = decval; // in case we fall through |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
873 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
874 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
875 // get here if we have a value |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
876 return lw_expr_build(lw_expr_type_int, val); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
877 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
878 // can't get here |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
879 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
880 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
881 lw_expr_t lwasm_parse_expr(asmstate_t *as, char **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
|
882 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
883 lw_expr_t e; |
366
433dbc18fb41
Make byte overflow detection for 8 bit immediate not fail with COM operator
William Astle <lost@l-w.ca>
parents:
354
diff
changeset
|
884 |
433dbc18fb41
Make byte overflow detection for 8 bit immediate not fail with COM operator
William Astle <lost@l-w.ca>
parents:
354
diff
changeset
|
885 if (as->exprwidth != 16) |
433dbc18fb41
Make byte overflow detection for 8 bit immediate not fail with COM operator
William Astle <lost@l-w.ca>
parents:
354
diff
changeset
|
886 { |
433dbc18fb41
Make byte overflow detection for 8 bit immediate not fail with COM operator
William Astle <lost@l-w.ca>
parents:
354
diff
changeset
|
887 lw_expr_setwidth(as->exprwidth); |
399
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
888 if (CURPRAGMA(as -> cl, PRAGMA_NEWSOURCE)) |
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
889 e = lw_expr_parse(p, as); |
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
890 else |
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
891 e = lw_expr_parse_compact(p, as); |
366
433dbc18fb41
Make byte overflow detection for 8 bit immediate not fail with COM operator
William Astle <lost@l-w.ca>
parents:
354
diff
changeset
|
892 lw_expr_setwidth(0); |
433dbc18fb41
Make byte overflow detection for 8 bit immediate not fail with COM operator
William Astle <lost@l-w.ca>
parents:
354
diff
changeset
|
893 } |
433dbc18fb41
Make byte overflow detection for 8 bit immediate not fail with COM operator
William Astle <lost@l-w.ca>
parents:
354
diff
changeset
|
894 else |
433dbc18fb41
Make byte overflow detection for 8 bit immediate not fail with COM operator
William Astle <lost@l-w.ca>
parents:
354
diff
changeset
|
895 { |
399
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
896 if (CURPRAGMA(as -> cl, PRAGMA_NEWSOURCE)) |
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
897 e = lw_expr_parse(p, as); |
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
898 else |
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
899 e = lw_expr_parse_compact(p, as); |
366
433dbc18fb41
Make byte overflow detection for 8 bit immediate not fail with COM operator
William Astle <lost@l-w.ca>
parents:
354
diff
changeset
|
900 } |
399
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
901 lwasm_skip_to_next_token(as -> cl, 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
|
902 return 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
|
903 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
904 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
905 int lwasm_reduce_expr(asmstate_t *as, lw_expr_t expr) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
906 { |
216
398773d7e504
Fix crash bug on indexed expression handling
William Astle <lost@l-w.ca>
parents:
211
diff
changeset
|
907 if (expr) |
398773d7e504
Fix crash bug on indexed expression handling
William Astle <lost@l-w.ca>
parents:
211
diff
changeset
|
908 lw_expr_simplify(expr, as); |
2
7317fbe024af
Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents:
0
diff
changeset
|
909 return 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
|
910 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
911 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
912 void lwasm_save_expr(line_t *cl, int id, lw_expr_t expr) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
913 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
914 struct line_expr_s *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
|
915 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
916 for (e = cl -> exprs; e; e = e -> next) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
917 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
918 if (e -> id == id) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
919 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
920 lw_expr_destroy(e -> expr); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
921 e -> expr = expr; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
922 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
|
923 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
924 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
925 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
926 e = lw_alloc(sizeof(struct line_expr_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
|
927 e -> expr = expr; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
928 e -> id = id; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
929 e -> next = cl -> exprs; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
930 cl -> exprs = 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
|
931 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
932 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
933 lw_expr_t lwasm_fetch_expr(line_t *cl, int id) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
934 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
935 struct line_expr_s *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
|
936 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
937 for (e = cl -> exprs; e; e = e -> next) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
938 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
939 if (e -> id == id) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
940 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
941 return e -> expr; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
942 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
943 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
944 return NULL; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
945 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
946 |
399
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
947 void skip_operand_real(line_t *cl, char **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
|
948 { |
399
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
949 if (CURPRAGMA(cl, PRAGMA_NEWSOURCE)) |
6153cb49403c
Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents:
388
diff
changeset
|
950 return; |
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
|
951 for (; **p && !isspace(**p); (*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
|
952 /* do nothing */ ; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
953 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
954 |
432
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
955 struct auxdata { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
956 int v; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
957 int oc; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
958 int ms; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
959 }; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
960 |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
961 int lwasm_emitexpr_auxlwmod(lw_expr_t expr, void *arg) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
962 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
963 struct auxdata *ad = arg; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
964 if (lw_expr_istype(expr, lw_expr_type_int)) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
965 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
966 ad -> v = lw_expr_intval(expr); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
967 return 0; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
968 } |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
969 if (lw_expr_istype(expr, lw_expr_type_special)) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
970 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
971 if (lw_expr_specint(expr) == lwasm_expr_secbase) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
972 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
973 sectiontab_t *s; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
974 s = lw_expr_specptr(expr); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
975 if (strcmp(s -> name, "main") == 0) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
976 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
977 ad -> ms = 1; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
978 return 0; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
979 } |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
980 if (strcmp(s -> name, "bss")) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
981 return -1; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
982 return 0; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
983 } |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
984 return -1; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
985 } |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
986 if (lw_expr_whichop(expr) == lw_expr_oper_plus) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
987 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
988 if (ad -> oc) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
989 return -1; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
990 ad -> oc = 1; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
991 return 0; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
992 } |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
993 return -1; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
994 } |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
995 |
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
|
996 int lwasm_emitexpr(line_t *l, lw_expr_t expr, int size) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
997 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
998 int v = 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
|
999 int ol; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1000 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1001 ol = l -> outputl; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1002 if (ol == -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
|
1003 ol = 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
|
1004 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1005 if (lw_expr_istype(expr, 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
|
1006 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1007 v = lw_expr_intval(expr); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1008 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1009 // handle external/cross-section/incomplete references here |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1010 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
|
1011 { |
432
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1012 if (l -> as -> output_format == OUTPUT_LWMOD) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1013 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1014 reloctab_t *re; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1015 lw_expr_t te; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1016 struct auxdata ad; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1017 ad.v = 0; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1018 ad.oc = 0; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1019 ad.ms = 0; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1020 |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1021 if (l -> csect == NULL) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1022 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1023 lwasm_register_error(l -> as, l, E_INSTRUCTION_SECTION); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1024 return -1; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1025 } |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1026 if (size != 2) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1027 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1028 lwasm_register_error(l -> as, l, E_OPERAND_BAD); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1029 return -1; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1030 } |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1031 // we have a 16 bit reference here - we need to check to make sure |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1032 // it's at most a + or - with the BSS section base |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1033 v = lw_expr_whichop(expr); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1034 if (v == -1) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1035 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1036 v = 0; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1037 if (lw_expr_testterms(expr, lwasm_emitexpr_auxlwmod, &ad) != 0) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1038 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1039 lwasm_register_error(l -> as, l, E_COMPLEX_INCOMPLETE); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1040 return -1; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1041 } |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1042 v = ad.v; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1043 } |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1044 else if (v == lw_expr_oper_plus) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1045 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1046 v = 0; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1047 if (lw_expr_operandcount(expr) > 2) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1048 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1049 lwasm_register_error(l -> as, l, E_COMPLEX_INCOMPLETE); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1050 return -1; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1051 } |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1052 if (lw_expr_testterms(expr, lwasm_emitexpr_auxlwmod, &ad) != 0) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1053 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1054 lwasm_register_error(l -> as, l, E_COMPLEX_INCOMPLETE); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1055 return -1; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1056 } |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1057 v = ad.v; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1058 } |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1059 else |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1060 { |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1061 lwasm_register_error(l -> as, l, E_COMPLEX_INCOMPLETE); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1062 return -1; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1063 } |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1064 |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1065 // add "expression" record to section table |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1066 re = lw_alloc(sizeof(reloctab_t)); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1067 re -> next = l -> csect -> reloctab; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1068 l -> csect -> reloctab = re; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1069 te = lw_expr_build(lw_expr_type_int, ol); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1070 re -> offset = lw_expr_build(lw_expr_type_oper, lw_expr_oper_plus, l -> addr, te); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1071 lw_expr_destroy(te); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1072 lwasm_reduce_expr(l -> as, re -> offset); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1073 re -> size = size; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1074 if (ad.ms == 1) |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1075 re -> expr = lw_expr_copy(expr); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1076 else |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1077 re -> expr = NULL; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1078 |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1079 lwasm_emit(l, v >> 8); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1080 lwasm_emit(l, v & 0xff); |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1081 return 0; |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1082 } |
58cafa61ab40
Add support for undocumented custom module format (for LW)
William Astle <lost@l-w.ca>
parents:
413
diff
changeset
|
1083 else if (l -> as -> output_format == OUTPUT_OBJ) |
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
|
1084 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1085 reloctab_t *re; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1086 lw_expr_t te; |
13
c80e5a063967
Brought forward patch to fix segfault with output outside of a section
lost@l-w.ca
parents:
2
diff
changeset
|
1087 |
c80e5a063967
Brought forward patch to fix segfault with output outside of a section
lost@l-w.ca
parents:
2
diff
changeset
|
1088 if (l -> csect == NULL) |
c80e5a063967
Brought forward patch to fix segfault with output outside of a section
lost@l-w.ca
parents:
2
diff
changeset
|
1089 { |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
1090 lwasm_register_error(l -> as, l, E_INSTRUCTION_SECTION); |
24 | 1091 return -1; |
13
c80e5a063967
Brought forward patch to fix segfault with output outside of a section
lost@l-w.ca
parents:
2
diff
changeset
|
1092 } |
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
|
1093 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1094 if (size == 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
|
1095 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1096 // create a two part reference because lwlink doesn't |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1097 // support 32 bit references |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1098 lw_expr_t te2; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1099 te = lw_expr_build(lw_expr_type_int, 0x10000); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1100 te2 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_divide, expr, te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1101 lw_expr_destroy(te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1102 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1103 re = lw_alloc(sizeof(reloctab_t)); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1104 re -> next = l -> csect -> reloctab; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1105 l -> csect -> reloctab = re; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1106 te = lw_expr_build(lw_expr_type_int, ol); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1107 re -> offset = lw_expr_build(lw_expr_type_oper, lw_expr_oper_plus, l -> addr, te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1108 lw_expr_destroy(te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1109 lwasm_reduce_expr(l -> as, re -> offset); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1110 re -> expr = te2; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1111 re -> size = 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
|
1112 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1113 te = lw_expr_build(lw_expr_type_int, 0xFFFF); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1114 te2 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_bwand, expr, te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1115 lw_expr_destroy(te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1116 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1117 re = lw_alloc(sizeof(reloctab_t)); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1118 re -> next = l -> csect -> reloctab; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1119 l -> csect -> reloctab = re; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1120 te = lw_expr_build(lw_expr_type_int, ol + 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
|
1121 re -> offset = lw_expr_build(lw_expr_type_oper, lw_expr_oper_plus, l -> addr, te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1122 lw_expr_destroy(te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1123 lwasm_reduce_expr(l -> as, re -> offset); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1124 re -> expr = te2; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1125 re -> size = 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
|
1126 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1127 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
|
1128 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1129 // add "expression" record to section table |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1130 re = lw_alloc(sizeof(reloctab_t)); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1131 re -> next = l -> csect -> reloctab; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1132 l -> csect -> reloctab = re; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1133 te = lw_expr_build(lw_expr_type_int, ol); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1134 re -> offset = lw_expr_build(lw_expr_type_oper, lw_expr_oper_plus, l -> addr, te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1135 lw_expr_destroy(te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1136 lwasm_reduce_expr(l -> as, re -> offset); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1137 re -> size = size; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1138 re -> expr = lw_expr_copy(expr); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1139 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1140 for (v = 0; v < size; 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
|
1141 lwasm_emit(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
|
1142 return 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
|
1143 } |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
1144 lwasm_register_error(l->as, l, E_EXPRESSION_NOT_RESOLVED); |
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
|
1145 return -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
|
1146 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1147 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1148 switch (size) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1149 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1150 case 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
|
1151 lwasm_emit(l, v >> 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
|
1152 lwasm_emit(l, v >> 16); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1153 /* fallthrough intended */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1154 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1155 case 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
|
1156 lwasm_emit(l, v >> 8); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1157 /* fallthrough intended */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1158 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1159 case 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
|
1160 lwasm_emit(l, 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
|
1161 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1162 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1163 return 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
|
1164 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1165 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1166 int lwasm_lookupreg2(const char *regs, char **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
|
1167 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1168 int rval = 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
|
1169 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1170 while (*regs) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1171 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1172 if (toupper(**p) == *regs) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1173 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1174 if (regs[1] == ' ' && !isalpha(*(*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
|
1175 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1176 if (toupper(*(*p + 1)) == regs[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
|
1177 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1178 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1179 regs += 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
|
1180 rval++; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1181 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1182 if (!*regs) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1183 return -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
|
1184 if (regs[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
|
1185 (*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
|
1186 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
|
1187 (*p) += 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
|
1188 return rval; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1189 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1190 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1191 int lwasm_lookupreg3(const char *regs, char **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
|
1192 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1193 int rval = 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
|
1194 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1195 while (*regs) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1196 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1197 if (toupper(**p) == *regs) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1198 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1199 if (regs[1] == ' ' && !isalpha(*(*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
|
1200 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1201 if (toupper(*(*p + 1)) == regs[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
|
1202 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1203 if (regs[2] == ' ' && !isalpha(*(*p + 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
|
1204 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1205 if (toupper(*(*p + 2)) == regs[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
|
1206 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1207 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1208 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1209 regs += 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
|
1210 rval++; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1211 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1212 if (!*regs) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1213 return -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
|
1214 if (regs[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
|
1215 (*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
|
1216 else if (regs[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
|
1217 (*p) += 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
|
1218 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
|
1219 (*p) += 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
|
1220 return rval; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1221 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1222 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1223 void lwasm_show_errors(asmstate_t *as) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1224 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1225 line_t *cl; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1226 lwasm_error_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
|
1227 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1228 for (cl = as -> line_head; cl; cl = cl -> next) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1229 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1230 if (!(cl -> err) && !(cl -> warn)) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1231 continue; |
388
f813a56178c0
Make error output more friendly to IDEs
William Astle <lost@l-w.ca>
parents:
382
diff
changeset
|
1232 |
f813a56178c0
Make error output more friendly to IDEs
William Astle <lost@l-w.ca>
parents:
382
diff
changeset
|
1233 // trim "include:" if it appears |
f813a56178c0
Make error output more friendly to IDEs
William Astle <lost@l-w.ca>
parents:
382
diff
changeset
|
1234 char* s = cl->linespec; |
f813a56178c0
Make error output more friendly to IDEs
William Astle <lost@l-w.ca>
parents:
382
diff
changeset
|
1235 if ((strlen(s) > 8) && (s[7] == ':')) s += 8; |
f813a56178c0
Make error output more friendly to IDEs
William Astle <lost@l-w.ca>
parents:
382
diff
changeset
|
1236 while (*s == ' ') s++; |
f813a56178c0
Make error output more friendly to IDEs
William Astle <lost@l-w.ca>
parents:
382
diff
changeset
|
1237 |
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
|
1238 for (e = cl -> err; e; e = e -> next) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1239 { |
388
f813a56178c0
Make error output more friendly to IDEs
William Astle <lost@l-w.ca>
parents:
382
diff
changeset
|
1240 fprintf(stderr, "%s(%d) : ERROR : %s\n", s, cl->lineno, e->mess); |
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
|
1241 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1242 for (e = cl -> warn; e; e = e -> next) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1243 { |
388
f813a56178c0
Make error output more friendly to IDEs
William Astle <lost@l-w.ca>
parents:
382
diff
changeset
|
1244 fprintf(stderr, "%s(%d) : WARNING : %s\n", s, cl->lineno, e->mess); |
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
|
1245 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1246 fprintf(stderr, "%s:%05d %s\n\n", cl -> linespec, cl -> lineno, cl -> ltext); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1247 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1248 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1249 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1250 /* |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1251 this does any passes and other gymnastics that might be useful |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1252 to see if an expression reduces early |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1253 */ |
374 | 1254 void do_pass3(asmstate_t *as); |
1255 void do_pass4_aux(asmstate_t *as, int 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
|
1256 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1257 void lwasm_interim_reduce(asmstate_t *as) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1258 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1259 do_pass3(as); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1260 // do_pass4_aux(as, 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
|
1261 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1262 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1263 lw_expr_t lwasm_parse_cond(asmstate_t *as, char **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
|
1264 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1265 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
|
1266 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1267 debug_message(as, 250, "Parsing condition"); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1268 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
|
1269 debug_message(as, 250, "COND EXPR: %s", lw_expr_print(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
|
1270 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1271 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
|
1272 { |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
1273 lwasm_register_error(as, as -> cl, E_EXPRESSION_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
|
1274 return NULL; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1275 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1276 |
210 | 1277 /* handle condundefzero */ |
1278 if (CURPRAGMA(as -> cl, PRAGMA_CONDUNDEFZERO)) | |
1279 { | |
1280 as -> undefzero = 1; | |
1281 lwasm_reduce_expr(as, e); | |
1282 as -> undefzero = 0; | |
1283 } | |
1284 | |
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
|
1285 /* we need to simplify the expression here */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1286 debug_message(as, 250, "Doing interim reductions"); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1287 lwasm_interim_reduce(as); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1288 debug_message(as, 250, "COND EXPR: %s", lw_expr_print(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
|
1289 debug_message(as, 250, "Reducing expression"); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1290 lwasm_reduce_expr(as, 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
|
1291 debug_message(as, 250, "COND EXPR: %s", lw_expr_print(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
|
1292 /* lwasm_reduce_expr(as, 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
|
1293 debug_message(as, 250, "COND EXPR: %s", lw_expr_print(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
|
1294 lwasm_reduce_expr(as, 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
|
1295 debug_message(as, 250, "COND EXPR: %s", lw_expr_print(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
|
1296 lwasm_reduce_expr(as, 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
|
1297 debug_message(as, 250, "COND EXPR: %s", lw_expr_print(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
|
1298 */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1299 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1300 lwasm_save_expr(as -> cl, 4242, 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
|
1301 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1302 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
|
1303 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1304 debug_message(as, 250, "Non-constant expression"); |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
366
diff
changeset
|
1305 lwasm_register_error(as, as -> cl, E_CONDITION_P1); |
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
|
1306 return NULL; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1307 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1308 debug_message(as, 250, "Returning expression"); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1309 return 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
|
1310 } |
241
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1311 |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1312 struct range_data |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1313 { |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1314 int min; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1315 int max; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1316 asmstate_t *as; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1317 }; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1318 int lwasm_calculate_range(asmstate_t *as, lw_expr_t expr, int *min, int *max); |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1319 int lwasm_calculate_range_tf(lw_expr_t e, void *info) |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1320 { |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1321 struct range_data *rd = info; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1322 int i; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1323 |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1324 if (lw_expr_istype(e, lw_expr_type_int)) |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1325 { |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1326 i = lw_expr_intval(e); |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1327 rd -> min += i; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1328 rd -> max += i; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1329 return 0; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1330 } |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1331 |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1332 if (lw_expr_istype(e, lw_expr_type_special)) |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1333 { |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1334 line_t *l; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1335 if (lw_expr_specint(e) != lwasm_expr_linelen) |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1336 { |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1337 rd -> min = -1; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1338 return -1; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1339 } |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1340 l = (line_t *)lw_expr_specptr(e); |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1341 if (l -> len == -1) |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1342 { |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1343 rd -> min += l -> minlen; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1344 rd -> max += l -> maxlen; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1345 } |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1346 else |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1347 { |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1348 rd -> min += l -> len; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1349 } |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1350 return 0; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1351 } |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1352 |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1353 if (lw_expr_istype(e, lw_expr_type_var)) |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1354 { |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1355 lw_expr_t te; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1356 te = lw_expr_copy(e); |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1357 lwasm_reduce_expr(rd -> as, te); |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1358 if (lw_expr_istype(te, lw_expr_type_int)) |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1359 { |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1360 i = lw_expr_intval(te); |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1361 rd -> min += i; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1362 rd -> max += i; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1363 } |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1364 else |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1365 { |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1366 rd -> min = -1; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1367 } |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1368 lw_expr_destroy(te); |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1369 if (rd -> min == -1) |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1370 return -1; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1371 return 0; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1372 } |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1373 |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1374 if (lw_expr_istype(e, lw_expr_type_oper)) |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1375 { |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1376 if (lw_expr_whichop(e) == lw_expr_oper_plus) |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1377 return 0; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1378 rd -> min = -1; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1379 return -1; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1380 } |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1381 |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1382 rd -> min = -1; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1383 return -1; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1384 } |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1385 |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1386 int lwasm_calculate_range(asmstate_t *as, lw_expr_t expr, int *min, int *max) |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1387 { |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1388 struct range_data rd; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1389 |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1390 rd.min = 0; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1391 rd.max = 0; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1392 rd.as = as; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1393 |
256
bc25269d96bc
Fix crash on expression range calculation
William Astle <lost@l-w.ca>
parents:
249
diff
changeset
|
1394 if (!expr) |
bc25269d96bc
Fix crash on expression range calculation
William Astle <lost@l-w.ca>
parents:
249
diff
changeset
|
1395 return -1; |
bc25269d96bc
Fix crash on expression range calculation
William Astle <lost@l-w.ca>
parents:
249
diff
changeset
|
1396 |
241
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1397 lw_expr_testterms(expr, lwasm_calculate_range_tf, (void *)&rd); |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1398 *min = rd.min; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1399 *max = rd.max; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1400 if (rd.min == -1) |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1401 return -1; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1402 return 0; |
d0e9dbe9afbe
Add new heuristic for resolving instruction sizes.
William Astle <lost@l-w.ca>
parents:
240
diff
changeset
|
1403 } |
336
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1404 |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1405 void lwasm_reduce_line_exprs(line_t *cl) |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1406 { |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1407 asmstate_t *as; |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1408 struct line_expr_s *le; |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1409 int i; |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1410 |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1411 as = cl -> as; |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1412 as -> cl = cl; |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1413 |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1414 // simplify address |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1415 lwasm_reduce_expr(as, cl -> addr); |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1416 |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1417 // simplify data address |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1418 lwasm_reduce_expr(as, cl -> daddr); |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1419 |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1420 // simplify each expression |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1421 for (i = 0, le = cl -> exprs; le; le = le -> next, i++) |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1422 { |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1423 lwasm_reduce_expr(as, le -> expr); |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1424 debug_message(as, 100, "Reduce expressions: exp[%d] = %s", i, lw_expr_print(le -> expr)); |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1425 } |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1426 |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1427 if (cl -> len == -1 || cl -> dlen == -1) |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1428 { |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1429 // try resolving the instruction length |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1430 // but don't force resolution |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1431 if (cl -> insn >= 0 && instab[cl -> insn].resolve) |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1432 { |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1433 (instab[cl -> insn].resolve)(as, cl, 0); |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1434 if ((cl -> inmod == 0) && cl -> len >= 0 && cl -> dlen >= 0) |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1435 { |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1436 if (cl -> len == 0) |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1437 cl -> len = cl -> dlen; |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1438 else |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1439 cl -> dlen = cl -> len; |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1440 } |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1441 } |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1442 } |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1443 debug_message(as, 100, "Reduce expressions: len = %d", cl -> len); |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1444 debug_message(as, 100, "Reduce expressions: dlen = %d", cl -> dlen); |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1445 debug_message(as, 100, "Reduce expressions: addr = %s", lw_expr_print(cl -> addr)); |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1446 debug_message(as, 100, "Reduce expressions: daddr = %s", lw_expr_print(cl -> daddr)); |
30b2bad9b5eb
Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents:
326
diff
changeset
|
1447 } |