annotate lwasm/symbol.c @ 259:0c4b3e8b4d0b

Fix pragma nosymbolcase interaction with -D Actually make --pragma=nosymbolcase flag symbols defined subsequently on the command line as not being case sensitive. Otherwise, things don't behave quite as expected. There is still a gotcha in that if the -D appears before the --pragma option, the symbol will still be case sensitive.
author William Astle <lost@l-w.ca>
date Fri, 01 Feb 2013 00:04:19 -0700
parents 5330ba70836a
children f45b2a68c3da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
1 /*
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
2 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 }
259
0c4b3e8b4d0b Fix pragma nosymbolcase interaction with -D
William Astle <lost@l-w.ca>
parents: 215
diff changeset
188 if (!cl && (as -> pragmas & PRAGMA_SYMBOLNOCASE))
0c4b3e8b4d0b Fix pragma nosymbolcase interaction with -D
William Astle <lost@l-w.ca>
parents: 215
diff changeset
189 {
0c4b3e8b4d0b Fix pragma nosymbolcase interaction with -D
William Astle <lost@l-w.ca>
parents: 215
diff changeset
190 nse -> flags |= symbol_flag_nocase;
0c4b3e8b4d0b Fix pragma nosymbolcase interaction with -D
William Astle <lost@l-w.ca>
parents: 215
diff changeset
191 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
192 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
193 nse -> symbol = lw_strdup(sym);
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
194 nse -> right = NULL;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
195 nse -> left = NULL;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
196 nse -> nextver = NULL;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
197 if (se)
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
198 {
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
199 nse -> nextver = se;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
200 nse -> left = se -> left;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
201 nse -> right = se -> right;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
202 se -> left = NULL;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
203 se -> right = NULL;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
204 }
101
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 82
diff changeset
205 if (cl)
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
206 nse -> section = cl -> csect;
101
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 82
diff changeset
207 else
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
208 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
209 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
210 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
211 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
212 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
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 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
215 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
216 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
217 if (cdir < 0)
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
218 sprev -> left = nse;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
219 else
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
220 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
221 }
206
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
222 if (CURPRAGMA(cl, PRAGMA_EXPORT) && cl -> csect && !islocal)
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
223 {
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
224 exportlist_t *e;
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
225
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
226 /* export symbol if not already exported */
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
227 e = lw_alloc(sizeof(exportlist_t));
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
228 e -> next = as -> exportlist;
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
229 e -> symbol = lw_strdup(sym);
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
230 e -> line = cl;
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
231 e -> se = nse;
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
232 as -> exportlist = e;
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
233 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
234 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
235 }
2c24602be78f 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
2c24602be78f 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 // 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
238 // 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
239 // 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
240 // 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
241 // 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
242 // 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
243 // 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
244 // 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
245 // 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
246 // 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
247 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
248 {
2c24602be78f 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 int local = 0;
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
250 struct symtabe *s;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
251 int cdir;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
252
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
253 // 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
254 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
255 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
256
2c24602be78f 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 (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
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 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
260 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
261
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
262 // 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
263 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
264 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
265
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
266 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
267 {
215
5330ba70836a Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents: 207
diff changeset
268 cdir = strcasecmp(sym, s -> symbol);
5330ba70836a Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents: 207
diff changeset
269 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
270 {
5330ba70836a Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents: 207
diff changeset
271 if (strcmp(sym, s -> symbol))
5330ba70836a Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents: 207
diff changeset
272 cdir = 1;
5330ba70836a Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents: 207
diff changeset
273 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
274 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
275 {
2c24602be78f 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 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
277 {
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
278 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
279 }
0
2c24602be78f 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
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
282 if (!cdir)
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
283 return s;
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 < 0)
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
286 s = s -> left;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
287 else
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
288 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
289 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
290 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
291 }
2c24602be78f 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
2c24602be78f 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 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
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 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
296 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
297 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
298 };
2c24602be78f 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 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
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 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
303
2c24602be78f 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 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
305 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
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 (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
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 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
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 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
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 -> 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
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 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
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 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
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 }
2c24602be78f 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 }
2c24602be78f 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 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
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
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
324 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
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 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
327 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
328 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
329
2c24602be78f 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 li.as = as;
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
331
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
332 if (!se)
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
333 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
334
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
335 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
336
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
337 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
338 {
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
339 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
340 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
341 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
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 (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
344 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
345 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
346 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
347 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
348 {
2c24602be78f 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 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
350 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
351 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
352 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
353 }
2c24602be78f 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 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
355 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
356 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
357 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
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 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
360 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
361 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
362
2c24602be78f 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 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
364 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
365 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
366 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
367 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
368 {
2c24602be78f 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 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
370 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
371 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
372 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
373 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
374
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
375 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
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 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
378 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
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, " (%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
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, "\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 }
2c24602be78f 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 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
385 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
386 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
387 // 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
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 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
390 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
391
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
392 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
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 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
396 {
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
397 fprintf(of, "\nSymbol Table:\n");
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
398 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
399 }