annotate lwasm/symbol.c @ 558:7fb2047ccdee

Flag version number to indicate ongoing development
author William Astle <lost@l-w.ca>
date Fri, 08 Sep 2023 00:35:43 -0600
parents b1adf549d181
children
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 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 365
diff changeset
93 lwasm_register_error2(as, cl, E_SYMBOL_BAD, "(%s)", sym);
0
2c24602be78f 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 }
362
d149e2b56981 Silence tautological comparison warnings
William Astle <lost@l-w.ca>
parents: 261
diff changeset
96 if (*(unsigned char *)sym < 0x80 && (!strchr(SSYMCHARS, *sym) && !strchr(sym + 1, '$') && !strchr(sym + 1, '@') && !strchr(sym + 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
97 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 365
diff changeset
98 lwasm_register_error2(as, cl, E_SYMBOL_BAD, "(%s)", sym);
0
2c24602be78f 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 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 365
diff changeset
104 lwasm_register_error2(as, cl, E_SYMBOL_BAD, "(%s)", sym);
0
2c24602be78f 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
362
d149e2b56981 Silence tautological comparison warnings
William Astle <lost@l-w.ca>
parents: 261
diff changeset
117 if (!(flags & symbol_flag_nocheck) && *(unsigned char *)cp < 0x80 && !strchr(SYMCHARS, *cp))
0
2c24602be78f 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 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 365
diff changeset
119 lwasm_register_error2(as, cl, E_SYMBOL_BAD, "(%s)", sym);
0
2c24602be78f 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
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 365
diff changeset
166 lwasm_register_error2(as, cl, E_SYMBOL_DUPE, "(%s)", sym);
0
2c24602be78f 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
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
225 if (CURPRAGMA(cl, PRAGMA_EXPORT) && cl -> csect && !islocal)
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
226 {
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
227 exportlist_t *e;
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
228
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
229 /* export symbol if not already exported */
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
230 e = lw_alloc(sizeof(exportlist_t));
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
231 e -> next = as -> exportlist;
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
232 e -> symbol = lw_strdup(sym);
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
233 e -> line = cl;
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
234 e -> se = nse;
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
235 as -> exportlist = e;
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
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;
433
b1adf549d181 Add some debugging instrumentation for tracking an expression bug
William Astle <lost@l-w.ca>
parents: 370
diff changeset
255
b1adf549d181 Add some debugging instrumentation for tracking an expression bug
William Astle <lost@l-w.ca>
parents: 370
diff changeset
256 debug_message(as, 100, "Look up symbol %s", sym);
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
257
0
2c24602be78f 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 // 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
259 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
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 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
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 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
265 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
266
2c24602be78f 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 // 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
268 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
269 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
270
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
271 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
272 {
215
5330ba70836a Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents: 207
diff changeset
273 cdir = strcasecmp(sym, s -> symbol);
5330ba70836a Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents: 207
diff changeset
274 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
275 {
5330ba70836a Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents: 207
diff changeset
276 if (strcmp(sym, s -> symbol))
5330ba70836a Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents: 207
diff changeset
277 cdir = 1;
5330ba70836a Fix undefined symbol error with pragma nosymbolcase
William Astle <lost@l-w.ca>
parents: 207
diff changeset
278 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
279 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
280 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
281 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
282 {
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
283 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
284 }
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
285 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
286
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
287 if (!cdir)
433
b1adf549d181 Add some debugging instrumentation for tracking an expression bug
William Astle <lost@l-w.ca>
parents: 370
diff changeset
288 {
b1adf549d181 Add some debugging instrumentation for tracking an expression bug
William Astle <lost@l-w.ca>
parents: 370
diff changeset
289 debug_message(as, 100, "Found symbol %s: %s, %s", sym, s -> symbol, lw_expr_print(s -> value));
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
290 return s;
433
b1adf549d181 Add some debugging instrumentation for tracking an expression bug
William Astle <lost@l-w.ca>
parents: 370
diff changeset
291 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
292
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
293 if (cdir < 0)
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
294 s = s -> left;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
295 else
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
296 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
297 }
433
b1adf549d181 Add some debugging instrumentation for tracking an expression bug
William Astle <lost@l-w.ca>
parents: 370
diff changeset
298 debug_message(as, 100, "Symbol not found %s", sym);
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
299 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
300 }
2c24602be78f 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
2c24602be78f 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 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
305 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
306 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
307 };
2c24602be78f 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 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
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 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
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 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
314 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
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 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
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 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
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 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
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 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
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 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
325 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
326 li -> 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
327 }
2c24602be78f 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 }
2c24602be78f 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 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
331 }
2c24602be78f 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
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
333 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
334 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
335 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
336 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
337 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
338
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
339 li.as = as;
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
340
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
341 if (!se)
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
342 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
343
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
344 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
345
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
346 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
347 {
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
348 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
349 continue;
365
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
350
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
351 if ((as -> flags & FLAG_SYMBOLS_NOLOCALS) && (s -> context >= 0))
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
352 continue;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
353
0
2c24602be78f 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 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
355 fputc('[', of);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
356 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
357 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
358 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
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 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
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 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
363 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
364 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
365 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
366 }
2c24602be78f 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 (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
368 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
369 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
370 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
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 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
373 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
374 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
375
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
376 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
377 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
378 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
379 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
380 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
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 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
383 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
384 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
385 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
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
2c24602be78f 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 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
389 {
2c24602be78f 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, "%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
391 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
392 {
2c24602be78f 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 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
394 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
395 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
396 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
397 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
398 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
399 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
400 // 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
401 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
402 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
403 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
404
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
405 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
406 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
407
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
408 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
409 {
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
410 fprintf(of, "\nSymbol Table:\n");
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
411 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
412 }
365
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
413
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
414 void map_symbols(asmstate_t *as, FILE *of, struct symtabe *se)
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
415 {
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
416 struct symtabe *s;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
417 lw_expr_t te;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
418 struct listinfo li;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
419
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
420 li.as = as;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
421
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
422 if (!se)
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
423 return;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
424
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
425 map_symbols(as, of, se -> left);
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
426
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
427 for (s = se; s; s = s -> nextver)
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
428 {
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
429 if (s -> flags & symbol_flag_nolist)
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
430 continue;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
431 lwasm_reduce_expr(as, s -> value);
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
432
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
433 te = lw_expr_copy(s -> value);
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
434 li.complex = 0;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
435 li.sect = NULL;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
436 lw_expr_testterms(te, list_symbols_test, &li);
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
437 if (li.sect)
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
438 {
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
439 as -> exportcheck = 1;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
440 as -> csect = li.sect;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
441 lwasm_reduce_expr(as, te);
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
442 as -> exportcheck = 0;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
443 }
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
444
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
445 if (lw_expr_istype(te, lw_expr_type_int))
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
446 {
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
447 fprintf(of, "Symbol: %s", s -> symbol);
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
448 if (s -> context != -1)
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
449 fprintf(of, "_%04X", lw_expr_intval(te));
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
450 fprintf(of, " (%s) = %04X\n", as -> output_file, lw_expr_intval(te));
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
451
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
452 }
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
453 lw_expr_destroy(te);
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
454 }
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
455
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
456 map_symbols(as, of, se -> right);
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
457 }
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
458
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
459 void do_map(asmstate_t *as)
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
460 {
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
461 FILE *of = NULL;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
462
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
463 if (!(as -> flags & FLAG_MAP))
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
464 return;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
465
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
466 if (as -> map_file)
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
467 {
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
468 if (strcmp(as -> map_file, "-") == 0)
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
469 {
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
470 of = stdout;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
471 }
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
472 else
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
473 of = fopen(as -> map_file, "w");
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
474 }
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
475 else
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
476 of = stdout;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
477 if (!of)
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
478 {
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
479 fprintf(stderr, "Cannot open map file '%s' for output\n", as -> map_file);
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
480 return;
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
481 }
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
482
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
483 map_symbols(as, of, as -> symtab.head);
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
484
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
485 fclose(of);
3f8abaac214c Add map file output and option to suppress local symbols in listings
William Astle <lost@l-w.ca>
parents: 362
diff changeset
486 }