annotate lwasm/symbol.c @ 206:080bb67d84f2

Add export pragma Added a pragma "export" which causes all exportable symbols to be exported automatically.
author William Astle <lost@l-w.ca>
date Thu, 24 May 2012 17:28:15 -0600
parents 17bd59f045af
children 07e1fac76321
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);
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
133 ndir = strcmp(sym, se->symbol);
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
134 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
135 {
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
136 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
137 }
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
138 if (!ndir)
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
139 {
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
140 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
141 {
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
142 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
143 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
144 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
145 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
146 cdir = ndir;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
147 sprev = se;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
148 if (cdir < 0)
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
149 se = se -> left;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
150 else
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
151 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
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
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
154 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
155 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
156 // 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
157 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
158 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
159 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
160
2c24602be78f 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 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
162 {
2c24602be78f 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 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
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
2c24602be78f 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 // 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
167 // 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
168 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
169
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
170 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
171 nse -> context = context;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
172 nse -> version = version;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
173 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
174 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
175 {
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
176 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
177 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
178 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
179 nse -> symbol = lw_strdup(sym);
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
180 nse -> right = NULL;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
181 nse -> left = NULL;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
182 nse -> nextver = NULL;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
183 if (se)
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
184 {
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
185 nse -> nextver = se;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
186 nse -> left = se -> left;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
187 nse -> right = se -> right;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
188 se -> left = NULL;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
189 se -> right = NULL;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
190 }
101
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 82
diff changeset
191 if (cl)
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
192 nse -> section = cl -> csect;
101
ed7f970f3688 Added --define= option to predfine a symbol for assembly
lost@l-w.ca
parents: 82
diff changeset
193 else
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
194 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
195 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
196 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
197 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
198 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
199 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
200 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
201 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
202 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
203 if (cdir < 0)
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
204 sprev -> left = nse;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
205 else
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
206 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
207 }
206
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
208 if (CURPRAGMA(cl, PRAGMA_EXPORT) && cl -> csect && !islocal)
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
209 {
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
210 exportlist_t *e;
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
211
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
212 /* export symbol if not already exported */
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
213 e = lw_alloc(sizeof(exportlist_t));
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
214 e -> next = as -> exportlist;
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
215 e -> symbol = lw_strdup(sym);
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
216 e -> line = cl;
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
217 e -> se = nse;
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
218 as -> exportlist = e;
080bb67d84f2 Add export pragma
William Astle <lost@l-w.ca>
parents: 195
diff changeset
219 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
220 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
221 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
222
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
223 // 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
224 // 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
225 // 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
226 // 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
227 // 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
228 // 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
229 // 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
230 // 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
231 // 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
232 // 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
233 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
234 {
2c24602be78f 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 int local = 0;
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
236 struct symtabe *s;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
237 int cdir;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
238
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
239 // 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
240 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
241 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
242
2c24602be78f 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 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
244 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
245 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
246 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
247
2c24602be78f 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 // 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
249 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
250 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
251
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
252 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
253 {
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
254 cdir = strcmp(sym, s->symbol);
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
255 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
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 (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
258 {
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
259 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
260 }
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
261 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
262
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
263 if (!cdir)
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
264 return s;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
265
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
266 if (cdir < 0)
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
267 s = s -> left;
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
268 else
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
269 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
270 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
271 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
272 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
273
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
274 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
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 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
277 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
278 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
279 };
2c24602be78f 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 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
282 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
283 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
284
2c24602be78f 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 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
286 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
287
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
288 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
289 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
290 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
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 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
293 {
2c24602be78f 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 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
295 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
296 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
297 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
298 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
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 }
2c24602be78f 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 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
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
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
305 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
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 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
308 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
309 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
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 li.as = as;
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
312
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
313 if (!se)
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
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
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
316 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
317
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
318 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
319 {
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
320 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
321 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
322 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
323 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
324 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
325 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
326 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
327 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
328 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
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 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
331 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
332 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
333 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
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 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
336 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
337 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
338 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
339
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
340 fputc(']', of);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
341 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
342 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
343
2c24602be78f 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 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
345 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
346 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
347 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
348 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
349 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
350 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
351 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
352 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
353 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
354 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
355
2c24602be78f 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 (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
357 {
2c24602be78f 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 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
359 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
360 {
2c24602be78f 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, " (%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
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 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
364 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
365 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
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 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
368 // 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
369 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
370 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
371 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
372
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
373 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
374 }
195
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
375
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
376 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
377 {
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
378 fprintf(of, "\nSymbol Table:\n");
17bd59f045af Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents: 101
diff changeset
379 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
380 }