annotate lwasm/pass1.c @ 530:65c2085e0398

Don't rely on undefined memory before start of instab When encountering a symbol on a line by itself, cl->insn was used to index into the instab array. Unfortunately, in that case, cl->insn will be -1 which will refer to memory before the start of instab. Depending on the compiler and linker, that could be anything. This would only have a visible effect on the OS9 target which has separate data and code address counters. On other targets, the two counters are kept in sync. This patch should short circuit that unfortunate code issue.
author William Astle <lost@l-w.ca>
date Wed, 09 Mar 2022 15:56:03 -0700
parents 428039e88a0b
children 3f81d8b11e5b
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 pass1.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 <string.h>
2
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
24 #include <ctype.h>
7317fbe024af Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents: 0
diff changeset
25 #include <stdlib.h>
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
26
2c24602be78f 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_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
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 #include "instab.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
32 #include "input.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
33
374
8e25147c2aa8 Clean up various "externs"
William Astle <lost@l-w.ca>
parents: 371
diff changeset
34 int expand_macro(asmstate_t *as, line_t *l, char **p, char *opc);
8e25147c2aa8 Clean up various "externs"
William Astle <lost@l-w.ca>
parents: 371
diff changeset
35 int expand_struct(asmstate_t *as, line_t *l, char **p, char *opc);
8e25147c2aa8 Clean up various "externs"
William Astle <lost@l-w.ca>
parents: 371
diff changeset
36 int add_macro_line(asmstate_t *as, char *optr);
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
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 /*
2c24602be78f 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 pass 1: parse the lines
2c24602be78f 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
399
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
41 line format if PRAGMA_NEWSOURCE is not in force:
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
42
2c24602be78f 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 [<symbol>] <opcode> <operand>[ <comment>]
2c24602be78f 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
2c24602be78f 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 <symbol> is followed by a :, whitespace may precede 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
46
2c24602be78f 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 A line may optionally start with a number which must not be preceded by
2c24602be78f 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 white space and must be followed by a single whitespace character. After
2c24602be78f 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 that whitespace character, the line is parsed as if it had no line number.
2c24602be78f 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
399
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
51 Also, no spaces are permitted within <operand>.
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
52
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
53 With PRAGMA_NEWSOURCE in effect, line numbers are not allowed and there
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
54 is no automatic comment at the end of each line. All comments must be
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
55 introduced with the comment character. This allows the parser to handle
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
56 spaces in operands unambiguously so in this mode, spaces are permitted
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
57 within operands.
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
58
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
59 */
2c24602be78f 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 void do_pass1(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
61 {
2c24602be78f 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 char *line;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
63 line_t *cl;
2c24602be78f 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 char *p1;
2c24602be78f 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 int stspace;
93
5bf9edabd661 Squashed the remaining memory leaks revealed by valgrind
lost@l-w.ca
parents: 85
diff changeset
66 char *tok, *sym = 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
67 int opnum;
2c24602be78f 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 int lc = 1;
59
1830faeef332 Added ?? prefix for opcode to inhibit macro expansion
lost@l-w.ca
parents: 53
diff changeset
69 int nomacro;
529
428039e88a0b Fix macro definition to include all lines
William Astle <lost@l-w.ca>
parents: 512
diff changeset
70 int wasmacro;
59
1830faeef332 Added ?? prefix for opcode to inhibit macro expansion
lost@l-w.ca
parents: 53
diff changeset
71
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
72 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
73 {
59
1830faeef332 Added ?? prefix for opcode to inhibit macro expansion
lost@l-w.ca
parents: 53
diff changeset
74 nomacro = 0;
93
5bf9edabd661 Squashed the remaining memory leaks revealed by valgrind
lost@l-w.ca
parents: 85
diff changeset
75 if (sym)
5bf9edabd661 Squashed the remaining memory leaks revealed by valgrind
lost@l-w.ca
parents: 85
diff changeset
76 lw_free(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
77 sym = 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
78 line = input_readline(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
79 if (!line)
2c24602be78f 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 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
81 if (line[0] == 1 && line[1] == 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
82 {
2c24602be78f 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 // special internal directive
2c24602be78f 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 // these DO NOT appear in the output anywhere
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
85 // they are generated by the parser to pass information
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
86 // forward
2c24602be78f 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 for (p1 = line + 2; *p1 && !isspace(*p1); p1++)
2c24602be78f 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 /* do nothing */ ;
2c24602be78f 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 *p1++ = '\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
90 if (!strcmp(line + 2, "SETCONTEXT"))
2c24602be78f 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 {
2c24602be78f 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 as -> context = strtol(p1, NULL, 10);
2c24602be78f 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 }
40
d96037ea0b80 Fixed line number counting being broken by macros
lost@l-w.ca
parents: 2
diff changeset
94 else if (!strcmp(line + 2, "SETLINENO"))
d96037ea0b80 Fixed line number counting being broken by macros
lost@l-w.ca
parents: 2
diff changeset
95 {
d96037ea0b80 Fixed line number counting being broken by macros
lost@l-w.ca
parents: 2
diff changeset
96 lc = strtol(p1, NULL, 10);
d96037ea0b80 Fixed line number counting being broken by macros
lost@l-w.ca
parents: 2
diff changeset
97 }
49
bd8b3fbd1e28 Added ability to flag macros as "noexpand" so they are not expanded in the listing
lost@l-w.ca
parents: 43
diff changeset
98 else if (!strcmp(line + 2, "SETNOEXPANDSTART"))
bd8b3fbd1e28 Added ability to flag macros as "noexpand" so they are not expanded in the listing
lost@l-w.ca
parents: 43
diff changeset
99 {
273
1409debcb1a0 Fix crash on listing when nested noexpand macros are used
William Astle <lost@l-w.ca>
parents: 220
diff changeset
100 as -> line_tail -> noexpand_start += 1;
49
bd8b3fbd1e28 Added ability to flag macros as "noexpand" so they are not expanded in the listing
lost@l-w.ca
parents: 43
diff changeset
101 }
bd8b3fbd1e28 Added ability to flag macros as "noexpand" so they are not expanded in the listing
lost@l-w.ca
parents: 43
diff changeset
102 else if (!strcmp(line + 2, "SETNOEXPANDEND"))
bd8b3fbd1e28 Added ability to flag macros as "noexpand" so they are not expanded in the listing
lost@l-w.ca
parents: 43
diff changeset
103 {
273
1409debcb1a0 Fix crash on listing when nested noexpand macros are used
William Astle <lost@l-w.ca>
parents: 220
diff changeset
104 as -> line_tail -> noexpand_end += 1;
49
bd8b3fbd1e28 Added ability to flag macros as "noexpand" so they are not expanded in the listing
lost@l-w.ca
parents: 43
diff changeset
105 }
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
106 lw_free(line);
40
d96037ea0b80 Fixed line number counting being broken by macros
lost@l-w.ca
parents: 2
diff changeset
107 if (lc == 0)
d96037ea0b80 Fixed line number counting being broken by macros
lost@l-w.ca
parents: 2
diff changeset
108 lc = 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
109 continue;
2c24602be78f 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 debug_message(as, 75, "Read line: %s", line);
2c24602be78f 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
529
428039e88a0b Fix macro definition to include all lines
William Astle <lost@l-w.ca>
parents: 512
diff changeset
113 wasmacro = as -> inmacro;
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
114 cl = lw_alloc(sizeof(line_t));
2c24602be78f 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 memset(cl, 0, sizeof(line_t));
2c24602be78f 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 cl -> outputl = -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
117 cl -> linespec = lw_strdup(input_curspec(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
118 cl -> prev = as -> line_tail;
2c24602be78f 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 cl -> insn = -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
120 cl -> as = 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
121 cl -> inmod = as -> inmod;
2c24602be78f 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 cl -> csect = as -> csect;
2c24602be78f 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 cl -> pragmas = as -> pragmas;
2c24602be78f 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 cl -> context = as -> 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
125 cl -> ltext = lw_strdup(line);
2c24602be78f 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 cl -> soff = -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
127 cl -> dshow = -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
128 cl -> dsize = 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
129 cl -> dptr = 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
130 cl -> isbrpt = 0;
142
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
131 cl -> dlen = 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
132 as -> cl = cl;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
133 if (!as -> line_tail)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
134 {
2c24602be78f 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 as -> line_head = cl;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
136 cl -> addr = lw_expr_build(lw_expr_type_int, 0);
142
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
137 cl -> daddr = lw_expr_build(lw_expr_type_int, 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
138 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
139 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
140 {
2c24602be78f 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 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
142
2c24602be78f 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 cl -> lineno = as -> line_tail -> lineno + 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
144 as -> line_tail -> next = cl;
2c24602be78f 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
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
146 // set the line address
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
147 te = lw_expr_build(lw_expr_type_special, lwasm_expr_linelen, cl -> prev);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
148 cl -> addr = lw_expr_build(lw_expr_type_oper, lw_expr_oper_plus, cl -> prev -> addr, 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
149 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
150 lwasm_reduce_expr(as, cl -> addr);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
151 // lw_expr_simplify(cl -> addr, 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
152
142
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
153 // set the data address if relevant
166
324f28905144 Fixed problem with rmb, etc., not working right wrt line address when not in os9 mode
lost@l-w.ca
parents: 147
diff changeset
154 if (as -> output_format == OUTPUT_OS9)
324f28905144 Fixed problem with rmb, etc., not working right wrt line address when not in os9 mode
lost@l-w.ca
parents: 147
diff changeset
155 {
324f28905144 Fixed problem with rmb, etc., not working right wrt line address when not in os9 mode
lost@l-w.ca
parents: 147
diff changeset
156 te = lw_expr_build(lw_expr_type_special, lwasm_expr_linedlen, cl -> prev);
324f28905144 Fixed problem with rmb, etc., not working right wrt line address when not in os9 mode
lost@l-w.ca
parents: 147
diff changeset
157 cl -> daddr = lw_expr_build(lw_expr_type_oper, lw_expr_oper_plus, cl -> prev -> daddr, te);
324f28905144 Fixed problem with rmb, etc., not working right wrt line address when not in os9 mode
lost@l-w.ca
parents: 147
diff changeset
158 lw_expr_destroy(te);
324f28905144 Fixed problem with rmb, etc., not working right wrt line address when not in os9 mode
lost@l-w.ca
parents: 147
diff changeset
159 lwasm_reduce_expr(as, cl -> daddr);
324f28905144 Fixed problem with rmb, etc., not working right wrt line address when not in os9 mode
lost@l-w.ca
parents: 147
diff changeset
160 }
324f28905144 Fixed problem with rmb, etc., not working right wrt line address when not in os9 mode
lost@l-w.ca
parents: 147
diff changeset
161 else
324f28905144 Fixed problem with rmb, etc., not working right wrt line address when not in os9 mode
lost@l-w.ca
parents: 147
diff changeset
162 {
324f28905144 Fixed problem with rmb, etc., not working right wrt line address when not in os9 mode
lost@l-w.ca
parents: 147
diff changeset
163 cl -> daddr = lw_expr_copy(cl -> addr);
324f28905144 Fixed problem with rmb, etc., not working right wrt line address when not in os9 mode
lost@l-w.ca
parents: 147
diff changeset
164 }
142
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
165
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
166 // carry DP value forward
2c24602be78f 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 cl -> dpval = cl -> prev -> dpval;
2c24602be78f 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 }
433
b1adf549d181 Add some debugging instrumentation for tracking an expression bug
William Astle <lost@l-w.ca>
parents: 399
diff changeset
170 debug_message(as, 100, "Line pointer: %p", cl);
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
171 if (!lc && strcmp(cl -> linespec, cl -> prev -> linespec))
2c24602be78f 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 lc = 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
173 if (lc)
2c24602be78f 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 {
40
d96037ea0b80 Fixed line number counting being broken by macros
lost@l-w.ca
parents: 2
diff changeset
175 cl -> lineno = lc;
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
176 lc = 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
177 }
2c24602be78f 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 as -> line_tail = cl;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
179 // blank lines don't count for anything
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
180 // except a local symbol context 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
181 if (!*line)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
182 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
183 as -> context = lwasm_next_context(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
184 goto nextline;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
185 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
186
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
187 // skip comments
399
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
188 // comments do not create a context break
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
189 if (*line == '*' || *line == ';' || *line == '#')
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
190 goto nextline;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
191
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
192 p1 = line;
399
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
193 if (isdigit(*p1) && !CURPRAGMA(cl, PRAGMA_NEWSOURCE))
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
194 {
2c24602be78f 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 // skip line number
2c24602be78f 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 while (*p1 && isdigit(*p1))
2c24602be78f 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 p1++;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
198 if (!*p1 && !isspace(*p1))
2c24602be78f 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 p1 = line;
2c24602be78f 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 if (*p1 && !isspace(*p1))
2c24602be78f 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 p1 = line;
2c24602be78f 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 else if (*p1 && isspace(*p1))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
203 p1++;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
204 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
205
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
206 // blank line - context 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
207 if (!*p1)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
208 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
209 as -> context = lwasm_next_context(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
210 goto nextline;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
211 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
212
2c24602be78f 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 // comment - no context 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
214 if (*p1 == '*' || *p1 == ';' || *p1 == '#')
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
215 goto nextline;
2c24602be78f 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 if (isspace(*p1))
2c24602be78f 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 for (; *p1 && isspace(*p1); p1++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
220 /* do nothing */ ;
2c24602be78f 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 stspace = 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
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 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
224 stspace = 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
225
2c24602be78f 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 if (!*p1)
2c24602be78f 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 {
2c24602be78f 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 // nothing but whitespace - context 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
229 as -> context = lwasm_next_context(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
230 goto nextline;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
231 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
232
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
233 // find the end of the first token
2c24602be78f 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 for (tok = p1; *p1 && !isspace(*p1) && *p1 != ':' && *p1 != '='; p1++)
2c24602be78f 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 /* do nothing */ ;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
236
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
237 if (*p1 == ':' || *p1 == '=' || stspace == 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 {
85
8fa52c3f2970 Make *pragma work correctly
lost@l-w.ca
parents: 59
diff changeset
239 if (*tok == '*' || *tok == ';' || *tok == '#')
8fa52c3f2970 Make *pragma work correctly
lost@l-w.ca
parents: 59
diff changeset
240 goto nextline;
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
241 // have a symbol here
2c24602be78f 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 sym = lw_strndup(tok, p1 - tok);
2c24602be78f 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 (*p1 == ':')
2c24602be78f 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 p1++;
2c24602be78f 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 for (; *p1 && isspace(*p1); p1++)
2c24602be78f 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 /* do nothing */ ;
399
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
247
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
248 if (*p1 == '=')
2c24602be78f 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 {
2c24602be78f 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 tok = p1++;
2c24602be78f 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 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
253 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
254 for (tok = p1; *p1 && !isspace(*p1); p1++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
255 /* do nothing */ ;
2c24602be78f 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 }
2c24602be78f 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 if (sym && strcmp(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
259 cl -> isbrpt = 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
260 else if (sym)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
261 cl -> sym = lw_strdup(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
262 cl -> symset = 0;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
263
2c24602be78f 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 // tok points to the opcode for the line or NUL if none
59
1830faeef332 Added ?? prefix for opcode to inhibit macro expansion
lost@l-w.ca
parents: 53
diff changeset
265
1830faeef332 Added ?? prefix for opcode to inhibit macro expansion
lost@l-w.ca
parents: 53
diff changeset
266 // if the first two chars of the opcode are "??", that's
1830faeef332 Added ?? prefix for opcode to inhibit macro expansion
lost@l-w.ca
parents: 53
diff changeset
267 // a flag to inhibit macro expansion
1830faeef332 Added ?? prefix for opcode to inhibit macro expansion
lost@l-w.ca
parents: 53
diff changeset
268 if (*tok && tok[0] == '?' && tok[1] == '?')
1830faeef332 Added ?? prefix for opcode to inhibit macro expansion
lost@l-w.ca
parents: 53
diff changeset
269 {
1830faeef332 Added ?? prefix for opcode to inhibit macro expansion
lost@l-w.ca
parents: 53
diff changeset
270 nomacro = 1;
1830faeef332 Added ?? prefix for opcode to inhibit macro expansion
lost@l-w.ca
parents: 53
diff changeset
271 tok += 2;
1830faeef332 Added ?? prefix for opcode to inhibit macro expansion
lost@l-w.ca
parents: 53
diff changeset
272 }
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
273 if (*tok)
2c24602be78f 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 {
399
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
275 if (CURPRAGMA(cl, PRAGMA_TESTMODE))
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
276 {
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
277 /* in test mode, terminate the line here so we don't affect the parsers */
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
278 /* (cl -> ltext retains the full, unmodified string) */
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
279 char *t = strstr(p1, ";.");
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
280 if (t) *t = 0;
375
71f507f404f1 Add "testmode" pragma
William Astle <lost@l-w.ca>
parents: 374
diff changeset
281 }
71f507f404f1 Add "testmode" pragma
William Astle <lost@l-w.ca>
parents: 374
diff changeset
282
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
283 // look up operation code
93
5bf9edabd661 Squashed the remaining memory leaks revealed by valgrind
lost@l-w.ca
parents: 85
diff changeset
284 lw_free(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
285 sym = lw_strndup(tok, p1 - tok);
2c24602be78f 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 for (; *p1 && isspace(*p1); p1++)
2c24602be78f 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 /* do nothing */ ;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
288
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
289 for (opnum = 0; instab[opnum].opcode; opnum++)
2c24602be78f 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 {
385
4fd16faa4d93 Add various "convenience" ops
William Astle <lost@l-w.ca>
parents: 382
diff changeset
291 // ignore 6800 compatibility opcodes unless asked for
4fd16faa4d93 Add various "convenience" ops
William Astle <lost@l-w.ca>
parents: 382
diff changeset
292 if ((instab[opnum].flags & lwasm_insn_is6800) && !CURPRAGMA(cl, PRAGMA_6800COMPAT)) continue;
4fd16faa4d93 Add various "convenience" ops
William Astle <lost@l-w.ca>
parents: 382
diff changeset
293 // ignore 6809 convenience opcodes unless asked for
4fd16faa4d93 Add various "convenience" ops
William Astle <lost@l-w.ca>
parents: 382
diff changeset
294 if ((instab[opnum].flags & lwasm_insn_is6809conv) && !CURPRAGMA(cl, PRAGMA_6809CONV)) continue;
4fd16faa4d93 Add various "convenience" ops
William Astle <lost@l-w.ca>
parents: 382
diff changeset
295 // ignore 6809 convenience opcodes in 6309 mode
4fd16faa4d93 Add various "convenience" ops
William Astle <lost@l-w.ca>
parents: 382
diff changeset
296 if ((instab[opnum].flags & lwasm_insn_is6809conv) && !CURPRAGMA(cl, PRAGMA_6809)) continue;
4fd16faa4d93 Add various "convenience" ops
William Astle <lost@l-w.ca>
parents: 382
diff changeset
297 // ignore 6309 convenience opcodes unless asked for
4fd16faa4d93 Add various "convenience" ops
William Astle <lost@l-w.ca>
parents: 382
diff changeset
298 if ((instab[opnum].flags & lwasm_insn_is6309conv) && !CURPRAGMA(cl, PRAGMA_6309CONV)) continue;
472
e97f9a302c6a Add emuext pragma and associated instructions.
William Astle <lost@l-w.ca>
parents: 461
diff changeset
299 // ignore emulator extension opcodes unless asked for
e97f9a302c6a Add emuext pragma and associated instructions.
William Astle <lost@l-w.ca>
parents: 461
diff changeset
300 if ((instab[opnum].flags & lwasm_insn_isemuext) && !CURPRAGMA(cl, PRAGMA_EMUEXT)) continue;
385
4fd16faa4d93 Add various "convenience" ops
William Astle <lost@l-w.ca>
parents: 382
diff changeset
301
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
302 if (!strcasecmp(instab[opnum].opcode, 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
303 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
304 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
305
107
b3557f8325f7 Fixed bug with symbol on a line with a comment not getting registered
lost@l-w.ca
parents: 93
diff changeset
306 // have to go to linedone here in case there was a symbol
b3557f8325f7 Fixed bug with symbol on a line with a comment not getting registered
lost@l-w.ca
parents: 93
diff changeset
307 // to register on this line
85
8fa52c3f2970 Make *pragma work correctly
lost@l-w.ca
parents: 59
diff changeset
308 if (instab[opnum].opcode == NULL && (*tok == '*' || *tok == ';' || *tok == '#'))
107
b3557f8325f7 Fixed bug with symbol on a line with a comment not getting registered
lost@l-w.ca
parents: 93
diff changeset
309 goto linedone;
85
8fa52c3f2970 Make *pragma work correctly
lost@l-w.ca
parents: 59
diff changeset
310
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
311 // p1 points to the start of the operand
2c24602be78f 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 we're inside a macro definition and not at ENDM,
2c24602be78f 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 // add the line to the macro definition and continue
2c24602be78f 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 if (as -> inmacro && !(instab[opnum].flags & lwasm_insn_endm))
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
316 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
317 goto linedone;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
318 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
319
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
320 // if skipping a condition and the operation code doesn't
2c24602be78f 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 // operate within a condition (not a conditional)
2c24602be78f 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 // do nothing
2c24602be78f 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 if (as -> skipcond && !(instab[opnum].flags & lwasm_insn_cond))
2c24602be78f 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 goto linedone;
2c24602be78f 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
371
2593fd529be5 Change PRAGMA_SHADOW to behave more as expected
William Astle <lost@l-w.ca>
parents: 370
diff changeset
326 if (!nomacro && (as->pragmas & PRAGMA_SHADOW))
53
cb4efc47ce9d Allow macros to shadow/override builtin operations when the "shadow" pragma is active, which is NOT the default
lost@l-w.ca
parents: 49
diff changeset
327 {
cb4efc47ce9d Allow macros to shadow/override builtin operations when the "shadow" pragma is active, which is NOT the default
lost@l-w.ca
parents: 49
diff changeset
328 // check for macros even if they shadow real operations
cb4efc47ce9d Allow macros to shadow/override builtin operations when the "shadow" pragma is active, which is NOT the default
lost@l-w.ca
parents: 49
diff changeset
329 // NOTE: "ENDM" cannot be shadowed
cb4efc47ce9d Allow macros to shadow/override builtin operations when the "shadow" pragma is active, which is NOT the default
lost@l-w.ca
parents: 49
diff changeset
330 if (expand_macro(as, cl, &p1, sym) == 0)
cb4efc47ce9d Allow macros to shadow/override builtin operations when the "shadow" pragma is active, which is NOT the default
lost@l-w.ca
parents: 49
diff changeset
331 {
cb4efc47ce9d Allow macros to shadow/override builtin operations when the "shadow" pragma is active, which is NOT the default
lost@l-w.ca
parents: 49
diff changeset
332 // a macro was expanded here
cb4efc47ce9d Allow macros to shadow/override builtin operations when the "shadow" pragma is active, which is NOT the default
lost@l-w.ca
parents: 49
diff changeset
333 goto linedone;
cb4efc47ce9d Allow macros to shadow/override builtin operations when the "shadow" pragma is active, which is NOT the default
lost@l-w.ca
parents: 49
diff changeset
334 }
cb4efc47ce9d Allow macros to shadow/override builtin operations when the "shadow" pragma is active, which is NOT the default
lost@l-w.ca
parents: 49
diff changeset
335 }
460
3d53f2e8d0e0 Allow macros to shadow instructions that are not supported by current CPU.
William Astle <lost@l-w.ca>
parents: 433
diff changeset
336
3d53f2e8d0e0 Allow macros to shadow instructions that are not supported by current CPU.
William Astle <lost@l-w.ca>
parents: 433
diff changeset
337 if (instab[opnum].opcode == NULL ||
3d53f2e8d0e0 Allow macros to shadow instructions that are not supported by current CPU.
William Astle <lost@l-w.ca>
parents: 433
diff changeset
338 (CURPRAGMA(cl, PRAGMA_6809) && (instab[opnum].flags & lwasm_insn_is6309)) ||
3d53f2e8d0e0 Allow macros to shadow instructions that are not supported by current CPU.
William Astle <lost@l-w.ca>
parents: 433
diff changeset
339 (!CURPRAGMA(cl, PRAGMA_6809) && (instab[opnum].flags & lwasm_insn_is6809))
461
c8d4f3486ad7 Make 6309/6809 warnings work again.
William Astle <lost@l-w.ca>
parents: 460
diff changeset
340 )
0
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
341 {
2c24602be78f 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 cl -> insn = -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
343 if (*tok != ';' && *tok != '*')
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
344 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
345 // bad opcode; check for macro here
59
1830faeef332 Added ?? prefix for opcode to inhibit macro expansion
lost@l-w.ca
parents: 53
diff changeset
346 // but don't expand it if "nomacro" is in effect
1830faeef332 Added ?? prefix for opcode to inhibit macro expansion
lost@l-w.ca
parents: 53
diff changeset
347 if (nomacro || expand_macro(as, cl, &p1, sym) != 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
348 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
349 // macro expansion failed
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
350 if (expand_struct(as, cl, &p1, 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
351 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
352 // structure expansion failed
461
c8d4f3486ad7 Make 6309/6809 warnings work again.
William Astle <lost@l-w.ca>
parents: 460
diff changeset
353 if (CURPRAGMA(cl, PRAGMA_6809) && (instab[opnum].flags & lwasm_insn_is6309))
c8d4f3486ad7 Make 6309/6809 warnings work again.
William Astle <lost@l-w.ca>
parents: 460
diff changeset
354 lwasm_register_error2(as, cl, E_6309_INVALID, "(%s)", sym);
c8d4f3486ad7 Make 6309/6809 warnings work again.
William Astle <lost@l-w.ca>
parents: 460
diff changeset
355 else if (!CURPRAGMA(cl, PRAGMA_6809) && (instab[opnum].flags & lwasm_insn_is6809))
c8d4f3486ad7 Make 6309/6809 warnings work again.
William Astle <lost@l-w.ca>
parents: 460
diff changeset
356 lwasm_register_error2(as, cl, E_6809_INVALID, "(%s)", sym);
c8d4f3486ad7 Make 6309/6809 warnings work again.
William Astle <lost@l-w.ca>
parents: 460
diff changeset
357 else
c8d4f3486ad7 Make 6309/6809 warnings work again.
William Astle <lost@l-w.ca>
parents: 460
diff changeset
358 lwasm_register_error(as, cl, E_OPCODE_BAD);
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
359 }
2c24602be78f 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 }
2c24602be78f 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 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
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 cl -> insn = opnum;
2c24602be78f 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 // no parse func means operand doesn't matter
2c24602be78f 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 (instab[opnum].parse)
2c24602be78f 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 {
367
c6d2a1f54e0c Change processor target variations to pragmas.
William Astle <lost@l-w.ca>
parents: 343
diff changeset
369 if (CURPRAGMA(cl, PRAGMA_6809) && (instab[opnum].flags & lwasm_insn_is6309))
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 367
diff changeset
370 lwasm_register_error2(as, cl, E_6309_INVALID, "(%s)", sym);
367
c6d2a1f54e0c Change processor target variations to pragmas.
William Astle <lost@l-w.ca>
parents: 343
diff changeset
371 if (!CURPRAGMA(cl, PRAGMA_6809) && (instab[opnum].flags & lwasm_insn_is6809))
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 367
diff changeset
372 lwasm_register_error2(as, cl, E_6809_INVALID, "(%s)", sym);
367
c6d2a1f54e0c Change processor target variations to pragmas.
William Astle <lost@l-w.ca>
parents: 343
diff changeset
373
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 if (as -> instruct == 0 || instab[opnum].flags & lwasm_insn_struct)
2c24602be78f 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 cl -> len = -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
377 // call parse function
329
9f7889139b06 Fix 6809 mode to count 6309 instructions as non-existent
William Astle <lost@l-w.ca>
parents: 273
diff changeset
378 debug_message(as, 100, "len = %d, dlen = %d", cl -> len, cl -> dlen);
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
379 (instab[opnum].parse)(as, cl, &p1);
382
80d615a6642c Add REORG pseudo op
William Astle <lost@l-w.ca>
parents: 375
diff changeset
380
343
98f3e016cfd8 Add pragma to turn off forward reference optimization
William Astle <lost@l-w.ca>
parents: 336
diff changeset
381 // if we're forcing address modes on pass 1, force a resolution
98f3e016cfd8 Add pragma to turn off forward reference optimization
William Astle <lost@l-w.ca>
parents: 336
diff changeset
382 if (CURPRAGMA(cl, PRAGMA_FORWARDREFMAX) && instab[opnum].resolve)
98f3e016cfd8 Add pragma to turn off forward reference optimization
William Astle <lost@l-w.ca>
parents: 336
diff changeset
383 {
98f3e016cfd8 Add pragma to turn off forward reference optimization
William Astle <lost@l-w.ca>
parents: 336
diff changeset
384 (instab[opnum].resolve)(as, cl, 1);
98f3e016cfd8 Add pragma to turn off forward reference optimization
William Astle <lost@l-w.ca>
parents: 336
diff changeset
385 }
142
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
386 if ((cl -> inmod == 0) && cl -> len >= 0 && cl -> dlen >= 0)
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
387 {
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
388 if (cl -> len == 0)
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
389 cl -> len = cl -> dlen;
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
390 else
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
391 cl -> dlen = cl -> len;
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
392 }
399
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
393 if (!CURPRAGMA(cl, PRAGMA_NEWSOURCE))
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
394 {
399
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
395 if (*p1 && !isspace(*p1) && !(cl -> err))
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
396 {
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
397 // flag bad operand error
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
398 lwasm_register_error2(as, cl, E_OPERAND_BAD, "(%s)", p1);
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
399 }
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
400 }
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
401 else
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
402 {
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
403 lwasm_skip_to_next_token(cl, &p1);
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
404 /* if we did not hit the end of the line and we aren't at a comment character, error out */
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
405 if (*p1 && *p1 != ';' && *p1 != '#' && *p1 != ';')
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
406 {
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
407 // flag bad operand error
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
408 lwasm_register_error2(as, cl, E_OPERAND_BAD, "%s", p1);
6153cb49403c Initial commit of pragma newsource
William Astle <lost@l-w.ca>
parents: 385
diff changeset
409 }
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
410 }
43
18b49cf10ae9 Added an instruction reduction immediately after instruction parsing to minimize memory footprint and expression complexity
lost@l-w.ca
parents: 40
diff changeset
411
18b49cf10ae9 Added an instruction reduction immediately after instruction parsing to minimize memory footprint and expression complexity
lost@l-w.ca
parents: 40
diff changeset
412 /* do a reduction on the line expressions to avoid carrying excessive expression baggage if not needed */
336
30b2bad9b5eb Factor some code for simplifying lines so it can be reused
William Astle <lost@l-w.ca>
parents: 333
diff changeset
413 lwasm_reduce_line_exprs(cl);
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
414 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
415 else if (as -> instruct == 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
416 {
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 367
diff changeset
417 lwasm_register_error2(as, cl, E_OPERAND_BAD, "(%s)", p1);
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
418 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
419 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
420 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
421 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
422
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
423 linedone:
529
428039e88a0b Fix macro definition to include all lines
William Astle <lost@l-w.ca>
parents: 512
diff changeset
424 if (as -> inmacro && wasmacro)
428039e88a0b Fix macro definition to include all lines
William Astle <lost@l-w.ca>
parents: 512
diff changeset
425 add_macro_line(as, line);
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
426 if (!as -> skipcond && !as -> inmacro)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
427 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
428 if (cl -> sym && cl -> symset == 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
429 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
430 debug_message(as, 50, "Register symbol %s: %s", cl -> sym, lw_expr_print(cl -> addr));
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
431
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
432 // register symbol at line address
530
65c2085e0398 Don't rely on undefined memory before start of instab
William Astle <lost@l-w.ca>
parents: 529
diff changeset
433 if ((cl -> insn >= 0) && (instab[cl -> insn].flags & lwasm_insn_setdata))
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
434 {
142
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
435 if (!register_symbol(as, cl, cl -> sym, cl -> daddr, symbol_flag_none))
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
436 {
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
437 // symbol error
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 367
diff changeset
438 // lwasm_register_error2(as, cl, E_SYMBOL_BAD, "(%s)", cl -> sym);
142
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
439 }
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
440 }
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
441 else
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
442 {
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
443 if (!register_symbol(as, cl, cl -> sym, cl -> addr, symbol_flag_none))
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
444 {
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
445 // symbol error
370
8764142b3192 Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents: 367
diff changeset
446 // lwasm_register_error2(as, cl, E_SYMBOL_BAD, "(%s)", cl -> sym);
142
697bc543368c Implement distinction between . and * for OS9 modules
lost@l-w.ca
parents: 107
diff changeset
447 }
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
448 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
449 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
450 debug_message(as, 40, "Line address: %s", lw_expr_print(cl -> addr));
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
451 }
512
7e41d6123175 Make conditional suppression actually hide comments and blank lines
William Astle <lost@l-w.ca>
parents: 474
diff changeset
452
7e41d6123175 Make conditional suppression actually hide comments and blank lines
William Astle <lost@l-w.ca>
parents: 474
diff changeset
453 nextline:
219
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
454 if (as -> skipcond || as -> inmacro || cl -> ltext[0] == 1)
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
455 cl -> hideline = 1;
474
74d0c394666e Add "noexpandcond" pragma (cleans up listings)
William Astle <lost@l-w.ca>
parents: 472
diff changeset
456 if (as -> skipcond)
74d0c394666e Add "noexpandcond" pragma (cleans up listings)
William Astle <lost@l-w.ca>
parents: 472
diff changeset
457 cl -> hidecond = 1;
74d0c394666e Add "noexpandcond" pragma (cleans up listings)
William Astle <lost@l-w.ca>
parents: 472
diff changeset
458
512
7e41d6123175 Make conditional suppression actually hide comments and blank lines
William Astle <lost@l-w.ca>
parents: 474
diff changeset
459 // nextline:
93
5bf9edabd661 Squashed the remaining memory leaks revealed by valgrind
lost@l-w.ca
parents: 85
diff changeset
460 if (sym)
5bf9edabd661 Squashed the remaining memory leaks revealed by valgrind
lost@l-w.ca
parents: 85
diff changeset
461 lw_free(sym);
5bf9edabd661 Squashed the remaining memory leaks revealed by valgrind
lost@l-w.ca
parents: 85
diff changeset
462 sym = NULL;
5bf9edabd661 Squashed the remaining memory leaks revealed by valgrind
lost@l-w.ca
parents: 85
diff changeset
463
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
464 lw_free(line);
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
465
220
3604d0ef06c6 Fix thinko in previous commit
William Astle <lost@l-w.ca>
parents: 219
diff changeset
466 if (as -> preprocess && cl -> hideline == 0)
219
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
467 {
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
468 printf("%s\n", cl -> ltext);
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
469 }
afd50d6b4113 Add --preprocess option
William Astle <lost@l-w.ca>
parents: 212
diff changeset
470
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
471 // if we've hit the "end" bit, finish out
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
472 if (as -> endseen)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
473 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
474 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
475 }