Mercurial > hg > index.cgi
annotate lwasm/symbol.c @ 305:54f213c8fb81 ccdev
Various bugfixes and output tuning
Tuned output of preprocessor to include line markers similar to the ones
added by the gcc preprocessor.
Also, many fixes for various bits of dumbosity leading to misbehaviour and
crashing.
author | William Astle <lost@l-w.ca> |
---|---|
date | Wed, 18 Sep 2013 19:17:52 -0600 |
parents | f45b2a68c3da |
children | d149e2b56981 |
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)) |
261
f45b2a68c3da
Make case insensitive symbols error out on duplication
William Astle <lost@l-w.ca>
parents:
259
diff
changeset
|
138 { |
f45b2a68c3da
Make case insensitive symbols error out on duplication
William Astle <lost@l-w.ca>
parents:
259
diff
changeset
|
139 if (!CURPRAGMA(cl, PRAGMA_SYMBOLNOCASE) && !(se -> flags & symbol_flag_nocase)) |
f45b2a68c3da
Make case insensitive symbols error out on duplication
William Astle <lost@l-w.ca>
parents:
259
diff
changeset
|
140 ndir = 1; |
f45b2a68c3da
Make case insensitive symbols error out on duplication
William Astle <lost@l-w.ca>
parents:
259
diff
changeset
|
141 } |
215
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
142 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
143 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
|
144 { |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
145 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
|
146 } |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
147 if (!ndir) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
148 { |
0
2c24602be78f
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 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
|
150 { |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
151 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
|
152 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
153 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
|
154 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
155 cdir = ndir; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
156 sprev = se; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
157 if (cdir < 0) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
158 se = se -> left; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
159 else |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
160 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
|
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 |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
163 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
|
164 { |
2c24602be78f
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 // 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
|
166 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
|
167 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
|
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 |
2c24602be78f
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 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
|
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 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
|
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 // 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
|
176 // 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
|
177 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
|
178 |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
179 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
|
180 nse -> context = context; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
181 nse -> version = version; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
182 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
|
183 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
|
184 { |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
185 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
|
186 } |
207
07e1fac76321
Added pragma to allow non case sensitive symbols
William Astle <lost@l-w.ca>
parents:
206
diff
changeset
|
187 if (CURPRAGMA(cl, PRAGMA_SYMBOLNOCASE)) |
07e1fac76321
Added pragma to allow non case sensitive symbols
William Astle <lost@l-w.ca>
parents:
206
diff
changeset
|
188 { |
07e1fac76321
Added pragma to allow non case sensitive symbols
William Astle <lost@l-w.ca>
parents:
206
diff
changeset
|
189 nse -> flags |= symbol_flag_nocase; |
07e1fac76321
Added pragma to allow non case sensitive symbols
William Astle <lost@l-w.ca>
parents:
206
diff
changeset
|
190 } |
259
0c4b3e8b4d0b
Fix pragma nosymbolcase interaction with -D
William Astle <lost@l-w.ca>
parents:
215
diff
changeset
|
191 if (!cl && (as -> pragmas & PRAGMA_SYMBOLNOCASE)) |
0c4b3e8b4d0b
Fix pragma nosymbolcase interaction with -D
William Astle <lost@l-w.ca>
parents:
215
diff
changeset
|
192 { |
0c4b3e8b4d0b
Fix pragma nosymbolcase interaction with -D
William Astle <lost@l-w.ca>
parents:
215
diff
changeset
|
193 nse -> flags |= symbol_flag_nocase; |
0c4b3e8b4d0b
Fix pragma nosymbolcase interaction with -D
William Astle <lost@l-w.ca>
parents:
215
diff
changeset
|
194 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
195 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
|
196 nse -> symbol = lw_strdup(sym); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
197 nse -> right = NULL; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
198 nse -> left = NULL; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
199 nse -> nextver = NULL; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
200 if (se) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
201 { |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
202 nse -> nextver = se; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
203 nse -> left = se -> left; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
204 nse -> right = se -> right; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
205 se -> left = NULL; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
206 se -> right = NULL; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
207 } |
101
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
82
diff
changeset
|
208 if (cl) |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
209 nse -> section = cl -> csect; |
101
ed7f970f3688
Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents:
82
diff
changeset
|
210 else |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
211 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
|
212 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
|
213 { |
2c24602be78f
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 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
|
215 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
|
216 } |
2c24602be78f
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 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
|
218 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
219 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
|
220 if (cdir < 0) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
221 sprev -> left = nse; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
222 else |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
223 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
|
224 } |
206 | 225 if (CURPRAGMA(cl, PRAGMA_EXPORT) && cl -> csect && !islocal) |
226 { | |
227 exportlist_t *e; | |
228 | |
229 /* export symbol if not already exported */ | |
230 e = lw_alloc(sizeof(exportlist_t)); | |
231 e -> next = as -> exportlist; | |
232 e -> symbol = lw_strdup(sym); | |
233 e -> line = cl; | |
234 e -> se = nse; | |
235 as -> exportlist = e; | |
236 } | |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
237 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
|
238 } |
2c24602be78f
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 |
2c24602be78f
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 // 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
|
241 // 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
|
242 // 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
|
243 // 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
|
244 // 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
|
245 // 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
|
246 // 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
|
247 // 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
|
248 // 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
|
249 // 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
|
250 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
|
251 { |
2c24602be78f
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 int local = 0; |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
253 struct symtabe *s; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
254 int cdir; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
255 |
0
2c24602be78f
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 // 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
|
257 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
|
258 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
|
259 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
260 if (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
|
261 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
|
262 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
|
263 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
|
264 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
265 // 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
|
266 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
|
267 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
|
268 |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
269 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
|
270 { |
215
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
271 cdir = strcasecmp(sym, s -> symbol); |
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
272 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
|
273 { |
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
274 if (strcmp(sym, s -> symbol)) |
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
275 cdir = 1; |
5330ba70836a
Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents:
207
diff
changeset
|
276 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
277 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
|
278 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
279 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
|
280 { |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
281 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
|
282 } |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
283 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
284 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
285 if (!cdir) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
286 return s; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
287 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
288 if (cdir < 0) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
289 s = s -> left; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
290 else |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
291 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
|
292 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
293 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
|
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 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
|
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 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
|
299 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
|
300 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
|
301 }; |
2c24602be78f
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 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
|
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 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
|
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 -> 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
|
308 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
|
309 |
2c24602be78f
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 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
|
311 { |
2c24602be78f
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 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
|
313 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
314 if (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
|
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 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
|
317 } |
2c24602be78f
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 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
|
319 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
320 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
|
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 } |
2c24602be78f
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 } |
2c24602be78f
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 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
|
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 |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
327 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
|
328 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
329 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
|
330 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
|
331 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
|
332 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
333 li.as = as; |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
334 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
335 if (!se) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
336 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
|
337 |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
338 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
|
339 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
340 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
|
341 { |
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
|
342 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 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
|
350 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
|
351 { |
2c24602be78f
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 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
|
353 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
|
354 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
|
355 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
|
356 } |
2c24602be78f
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 (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
|
358 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
|
359 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
|
360 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
|
361 |
2c24602be78f
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 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
|
363 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
|
364 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
|
365 |
2c24602be78f
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 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
|
367 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
|
368 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
|
369 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
|
370 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
|
371 { |
2c24602be78f
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 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
|
373 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
|
374 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
|
375 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
|
376 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
377 |
2c24602be78f
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 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
|
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 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
|
381 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
|
382 { |
2c24602be78f
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)", 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
|
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 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
|
386 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
387 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
|
388 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
389 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
|
390 // 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
|
391 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
392 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
|
393 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
394 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
395 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
|
396 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
397 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
398 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
|
399 { |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
400 fprintf(of, "\nSymbol Table:\n"); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
401 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
|
402 } |