Mercurial > hg > index.cgi
annotate lwasm/symbol.c @ 242:ea092ebc5323
Fix thinko with algorithm improvement.
Fix error where DP addressing would be selected by range calculation even
when DP addressing is not known to be valid.
author | William Astle <lost@l-w.ca> |
---|---|
date | Sun, 23 Sep 2012 13:11:34 -0600 |
parents | 5330ba70836a |
children | 0c4b3e8b4d0b |
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 symbol.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 <stdlib.h> |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
24 #include <string.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
|
25 |
2c24602be78f
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 #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
|
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_string.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 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
30 #include "lwasm.h" |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
31 |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
32 #if 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
|
33 struct symtabe *symbol_findprev(asmstate_t *as, struct symtabe *se) |
2c24602be78f
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 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
35 struct symtabe *se1, *se2; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
36 int i; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
37 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
38 for (se2 = NULL, se1 = as -> symtab.head; se1; se1 = se1 -> 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
|
39 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
40 debug_message(as, 200, "Sorting; looking at symbol %s (%p) for %s", se1 -> symbol, se1, se -> symbol); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
41 /* compare se with se1 */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
42 i = strcasecmp(se -> symbol, se1 -> symbol); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
43 |
2c24602be78f
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 /* if the symbol sorts before se1, we just need to 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
|
45 if (i < 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
|
46 return se2; |
2c24602be78f
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 if (i == 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
|
49 { |
2c24602be78f
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 /* symbol name matches; compare other things */ |
2c24602be78f
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 |
2c24602be78f
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 /*if next version is greater than this one, 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
|
53 if (se -> version > se1 -> 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
|
54 return se2; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
55 /* if next context is great than this one, 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
|
56 if (se -> context > se1 -> context) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
57 return se2; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
58 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
59 /* if section name is greater, 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
|
60 /* if se has no section but se1 does, we go first */ |
2c24602be78f
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 if (se -> section == NULL && se1 -> section != 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
|
62 return se2; |
71
6dafb4f0fa56
Fix crash during symbol registration when using object target
lost@l-w.ca
parents:
0
diff
changeset
|
63 if (se -> section != NULL && se1 -> section != 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
|
64 { |
2c24602be78f
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 /* compare section names and if se < se1, 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
|
66 i = strcasecmp(se -> section -> name, se1 -> section -> name); |
2c24602be78f
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 if (i < 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
|
68 return se2; |
2c24602be78f
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 } |
2c24602be78f
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 |
2c24602be78f
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 se2 = se1; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
73 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
74 return se2; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
75 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
76 #endif |
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
|
77 struct symtabe *register_symbol(asmstate_t *as, line_t *cl, char *sym, lw_expr_t val, int flags) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
78 { |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
79 struct symtabe *se, *nse; |
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 struct symtabe *sprev; |
2c24602be78f
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 int islocal = 0; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
82 int context = -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
|
83 int version = -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
|
84 char *cp; |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
85 int cdir; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
86 |
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
|
87 debug_message(as, 200, "Register symbol %s (%02X), %s", sym, flags, lw_expr_print(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
|
88 |
2c24602be78f
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 if (!(flags & symbol_flag_nocheck)) |
2c24602be78f
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 if (!sym || !*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
|
92 { |
2c24602be78f
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 lwasm_register_error(as, cl, "Bad symbol (%s)", 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
|
94 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
|
95 } |
2c24602be78f
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 if (*sym < 0x80 && (!strchr(SSYMCHARS, *sym) && !strchr(sym + 1, '$') && !strchr(sym + 1, '@') && !strchr(sym + 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
|
97 { |
2c24602be78f
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 lwasm_register_error(as, cl, "Bad symbol (%s)", 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
|
99 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
|
100 } |
2c24602be78f
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 |
2c24602be78f
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 if ((*sym == '$' || *sym == '@') && (sym[1] >= '0' && sym[1] <= '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
|
103 { |
2c24602be78f
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 lwasm_register_error(as, cl, "Bad symbol (%s)", 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
|
105 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
|
106 } |
2c24602be78f
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 } |
2c24602be78f
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 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
109 for (cp = sym; *cp; cp++) |
2c24602be78f
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 if (*cp == '@' || *cp == '?') |
2c24602be78f
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 islocal = 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
|
113 if (*cp == '$' && !(CURPRAGMA(cl, PRAGMA_DOLLARNOTLOCAL))) |
2c24602be78f
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 islocal = 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
|
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 // bad symbol |
2c24602be78f
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 if (!(flags & symbol_flag_nocheck) && *cp < 0x80 && !strchr(SYMCHARS, *cp)) |
2c24602be78f
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 { |
2c24602be78f
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 lwasm_register_error(as, cl, "Bad symbol (%s)", 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
|
120 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
|
121 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
122 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
123 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
124 if (islocal) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
125 context = cl -> context; |
2c24602be78f
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 |
2c24602be78f
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 // first, look up symbol to see if it is already defined |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
128 cdir = 0; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
129 for (se = as -> symtab.head, sprev = NULL; se; ) |
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 { |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
131 int ndir; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
132 debug_message(as, 300, "Symbol add lookup: %p", se); |
215
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
133 ndir = strcasecmp(sym, se -> symbol); |
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
134 // if (!ndir && !CURPRAGMA(cl, PRAGMA_SYMBOLNOCASE) && !(se -> flags & symbol_flag_set)) |
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
135 if (!ndir && !(se -> flags & symbol_flag_set)) |
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
136 { |
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
137 if (strcmp(sym, se -> symbol)) |
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
138 ndir = 1; |
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
139 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
140 if (!ndir && se -> context != context) |
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
|
141 { |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
142 ndir = (context < se -> context) ? -1 : 1; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
143 } |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
144 if (!ndir) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
145 { |
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
|
146 if ((flags & symbol_flag_set) && (se -> flags & symbol_flag_set)) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
147 { |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
148 version = se -> version; |
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
|
149 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
150 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
|
151 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
152 cdir = ndir; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
153 sprev = se; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
154 if (cdir < 0) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
155 se = se -> left; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
156 else |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
157 se = se -> right; |
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
|
158 } |
2c24602be78f
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 |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
160 if (se && version == -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
|
161 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
162 // multiply defined symbol |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
163 lwasm_register_error(as, cl, "Multiply defined symbol (%s)", 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
|
164 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
|
165 } |
2c24602be78f
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 |
2c24602be78f
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 if (flags & symbol_flag_set) |
2c24602be78f
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 { |
2c24602be78f
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 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
|
170 } |
2c24602be78f
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 |
2c24602be78f
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 // symplify the symbol expression - replaces "SET" symbols 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
|
173 // symbol table entries |
2c24602be78f
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 lwasm_reduce_expr(as, 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
|
175 |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
176 nse = lw_alloc(sizeof(struct symtabe)); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
177 nse -> context = context; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
178 nse -> version = version; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
179 nse -> flags = flags; |
82
adf4ce03a6a3
Made pragma nolist suppress listing symbols defined under the pragma when listing the symbol table
Lost Wizard (lost@starbug3)
parents:
75
diff
changeset
|
180 if (CURPRAGMA(cl, PRAGMA_NOLIST)) |
adf4ce03a6a3
Made pragma nolist suppress listing symbols defined under the pragma when listing the symbol table
Lost Wizard (lost@starbug3)
parents:
75
diff
changeset
|
181 { |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
182 nse -> flags |= symbol_flag_nolist; |
82
adf4ce03a6a3
Made pragma nolist suppress listing symbols defined under the pragma when listing the symbol table
Lost Wizard (lost@starbug3)
parents:
75
diff
changeset
|
183 } |
207
07e1fac76321
Added pragma to allow non case sensitive symbols
William Astle <lost@l-w.ca>
parents:
206
diff
changeset
|
184 if (CURPRAGMA(cl, PRAGMA_SYMBOLNOCASE)) |
07e1fac76321
Added pragma to allow non case sensitive symbols
William Astle <lost@l-w.ca>
parents:
206
diff
changeset
|
185 { |
07e1fac76321
Added pragma to allow non case sensitive symbols
William Astle <lost@l-w.ca>
parents:
206
diff
changeset
|
186 nse -> flags |= symbol_flag_nocase; |
07e1fac76321
Added pragma to allow non case sensitive symbols
William Astle <lost@l-w.ca>
parents:
206
diff
changeset
|
187 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
188 nse -> value = lw_expr_copy(val); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
189 nse -> symbol = lw_strdup(sym); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
190 nse -> right = NULL; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
191 nse -> left = NULL; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
192 nse -> nextver = NULL; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
193 if (se) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
194 { |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
195 nse -> nextver = se; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
196 nse -> left = se -> left; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
197 nse -> right = se -> right; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
198 se -> left = NULL; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
199 se -> right = NULL; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
200 } |
101
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
82
diff
changeset
|
201 if (cl) |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
202 nse -> section = cl -> csect; |
101
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
82
diff
changeset
|
203 else |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
204 nse -> section = 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
|
205 if (!sprev) |
2c24602be78f
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 { |
2c24602be78f
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 debug_message(as, 200, "Adding symbol at head of symbol table"); |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
208 as -> symtab.head = nse; |
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
|
209 } |
2c24602be78f
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 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
|
211 { |
2c24602be78f
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 debug_message(as, 200, "Adding symbol in middle of symbol table"); |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
213 if (cdir < 0) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
214 sprev -> left = nse; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
215 else |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
216 sprev -> right = nse; |
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
|
217 } |
206 | 218 if (CURPRAGMA(cl, PRAGMA_EXPORT) && cl -> csect && !islocal) |
219 { | |
220 exportlist_t *e; | |
221 | |
222 /* export symbol if not already exported */ | |
223 e = lw_alloc(sizeof(exportlist_t)); | |
224 e -> next = as -> exportlist; | |
225 e -> symbol = lw_strdup(sym); | |
226 e -> line = cl; | |
227 e -> se = nse; | |
228 as -> exportlist = e; | |
229 } | |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
230 return nse; |
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
|
231 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
232 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
233 // for "SET" symbols, always returns the LAST definition of 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
|
234 // symbol. This works because the lwasm_reduce_expr() call in |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
235 // register_symbol will ensure there are no lingering "var" 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
|
236 // to the set symbol anywhere in the symbol table; they will all be |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
237 // converted to direct 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
|
238 // NOTE: this means that for a forward reference to a SET symbol, |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
239 // the LAST definition will be the one used. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
240 // This arrangement also ensures that any reference to the symbol |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
241 // itself inside a "set" definition will refer to the previous 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
|
242 // of the symbol. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
243 struct symtabe * lookup_symbol(asmstate_t *as, line_t *cl, 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
|
244 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
245 int local = 0; |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
246 struct symtabe *s; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
247 int cdir; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
248 |
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
|
249 // check if this is a local symbol |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
250 if (strchr(sym, '@') || strchr(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
|
251 local = 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
|
252 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
253 if (cl && !CURPRAGMA(cl, PRAGMA_DOLLARNOTLOCAL) && strchr(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
|
254 local = 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
|
255 if (!cl && !(as -> pragmas & PRAGMA_DOLLARNOTLOCAL) && strchr(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
|
256 local = 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
|
257 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
258 // cannot look up local symbol in global context!!!!! |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
259 if (!cl && local) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
260 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
|
261 |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
262 for (s = as -> symtab.head; s; ) |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
263 { |
215
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
264 cdir = strcasecmp(sym, s -> symbol); |
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
265 if (!cdir && !(s->flags & symbol_flag_nocase)) |
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
266 { |
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
267 if (strcmp(sym, s -> symbol)) |
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
268 cdir = 1; |
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
269 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
270 if (!cdir) |
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
|
271 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
272 if (local && s -> context != cl -> context) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
273 { |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
274 cdir = (cl -> context < s -> context) ? -1 : 1; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
275 } |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
276 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
277 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
278 if (!cdir) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
279 return s; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
280 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
281 if (cdir < 0) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
282 s = s -> left; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
283 else |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
284 s = s -> right; |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
285 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
286 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
|
287 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
288 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
289 struct listinfo |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
290 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
291 sectiontab_t *sect; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
292 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
|
293 int complex; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
294 }; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
295 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
296 int list_symbols_test(lw_expr_t e, void *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
|
297 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
298 struct listinfo *li = 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
|
299 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
300 if (li -> complex) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
301 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
|
302 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
303 if (lw_expr_istype(e, lw_expr_type_special)) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
304 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
305 if (lw_expr_specint(e) == 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
|
306 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
307 if (li -> sect) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
308 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
309 li -> complex = 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
|
310 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
311 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
|
312 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
313 li -> sect = lw_expr_specptr(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
|
314 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
315 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
316 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
317 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
|
318 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
319 |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
320 void list_symbols_aux(asmstate_t *as, FILE *of, struct symtabe *se) |
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
|
321 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
322 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
|
323 lw_expr_t 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
|
324 struct listinfo li; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
325 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
326 li.as = as; |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
327 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
328 if (!se) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
329 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
|
330 |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
331 list_symbols_aux(as, of, se -> left); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
332 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
333 for (s = se; s; s = s -> nextver) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
334 { |
82
adf4ce03a6a3
Made pragma nolist suppress listing symbols defined under the pragma when listing the symbol table
Lost Wizard (lost@starbug3)
parents:
75
diff
changeset
|
335 if (s -> flags & symbol_flag_nolist) |
adf4ce03a6a3
Made pragma nolist suppress listing symbols defined under the pragma when listing the symbol table
Lost Wizard (lost@starbug3)
parents:
75
diff
changeset
|
336 continue; |
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
|
337 lwasm_reduce_expr(as, s -> 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
|
338 fputc('[', of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
339 if (s -> flags & symbol_flag_set) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
340 fputc('S', of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
341 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
|
342 fputc(' ', of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
343 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
|
344 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
345 if (lw_expr_istype(s -> value, 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
|
346 fputc('c', of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
347 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
|
348 fputc('s', of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
349 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
350 if (s -> context < 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
|
351 fputc('G', of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
352 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
|
353 fputc('L', of); |
2c24602be78f
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 fputc(']', of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
356 fputc(' ', of); |
2c24602be78f
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 fprintf(of, "%-32s ", s -> symbol); |
2c24602be78f
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 |
2c24602be78f
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 te = lw_expr_copy(s -> 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
|
360 li.complex = 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
|
361 li.sect = 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
|
362 lw_expr_testterms(te, list_symbols_test, &li); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
363 if (li.sect) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
364 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
365 as -> exportcheck = 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
|
366 as -> csect = li.sect; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
367 lwasm_reduce_expr(as, 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
|
368 as -> exportcheck = 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
|
369 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
370 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
371 if (lw_expr_istype(te, 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
|
372 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
373 fprintf(of, "%04X", lw_expr_intval(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
|
374 if (li.sect) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
375 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
376 fprintf(of, " (%s)", li.sect -> name); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
377 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
378 fprintf(of, "\n"); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
379 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
380 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
|
381 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
382 fprintf(of, "<<incomplete>>\n"); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
383 // fprintf(of, "%s\n", lw_expr_print(s -> 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
|
384 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
385 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
|
386 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
387 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
388 list_symbols_aux(as, of, se -> right); |
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
|
389 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
390 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
391 void list_symbols(asmstate_t *as, FILE *of) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
392 { |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
393 fprintf(of, "\nSymbol Table:\n"); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
394 list_symbols_aux(as, of, as -> symtab.head); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
395 } |