Mercurial > hg > index.cgi
annotate lwasm/struct.c @ 452:40516fb9af07 lwtools-4.15
Version 4.15
author | William Astle <lost@l-w.ca> |
---|---|
date | Sun, 07 Jan 2018 12:54:54 -0700 |
parents | 8764142b3192 |
children |
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 struct.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 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
|
4 |
2c24602be78f
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 This file is part of LWASM. |
2c24602be78f
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 |
2c24602be78f
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 LWASM 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
|
8 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
|
9 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
|
10 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
|
11 |
2c24602be78f
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 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
|
13 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
|
14 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
|
15 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
|
16 |
2c24602be78f
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 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
|
18 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
|
19 |
2c24602be78f
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 Contains stuff associated with structure processing |
2c24602be78f
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 |
2c24602be78f
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> |
2c24602be78f
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 |
2c24602be78f
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 #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
|
26 #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
|
27 |
2c24602be78f
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 "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
|
29 #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
|
30 |
2c24602be78f
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 PARSEFUNC(pseudo_parse_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
|
32 { |
2c24602be78f
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 structtab_t *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
|
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 if (as -> instruct) |
2c24602be78f
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 { |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
223
diff
changeset
|
37 lwasm_register_error(as, l, E_STRUCT_RECURSE); |
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
|
38 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
|
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 |
2c24602be78f
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 if (l -> 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
|
42 { |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
223
diff
changeset
|
43 lwasm_register_error(as, l, E_STRUCT_NOSYMBOL); |
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
|
44 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 } |
2c24602be78f
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 for (s = as -> structs; s; s = s -> 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
|
48 { |
2c24602be78f
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 if (!strcmp(s -> name, l -> 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
|
50 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
|
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 |
2c24602be78f
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 (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
|
54 { |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
223
diff
changeset
|
55 lwasm_register_error(as, l, E_STRUCT_DUPE); |
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
|
56 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
|
57 } |
2c24602be78f
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 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
|
60 |
2c24602be78f
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 s = lw_alloc(sizeof(structtab_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
|
62 s -> name = lw_strdup(l -> 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
|
63 s -> next = as -> structs; |
2c24602be78f
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 s -> fields = 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
|
65 s -> size = 0; |
223
211fc8038b8d
More unicorn stuff - structs and macros
William Astle <lost@l-w.ca>
parents:
61
diff
changeset
|
66 s -> definedat = l; |
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 as -> structs = 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
|
68 as -> cstruct = 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
|
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 skip_operand(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
|
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 l -> len = 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
|
73 l -> symset = 1; |
61
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
74 |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
75 // save current assembly address and initialize to 0 |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
76 as -> savedaddr = l -> addr; |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
77 l -> addr = 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
|
78 } |
2c24602be78f
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 |
61
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
80 static void instantiate_struct(asmstate_t *as, line_t *l, structtab_t *s, char *pref, lw_expr_t baseaddr) |
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
|
81 { |
10
127e5b1e01c0
Removed use of asprintf() and added Makefile options for cross compiling; also a bugfix with sizeof{} in lwasm
lost@l-w.ca
parents:
2
diff
changeset
|
82 int len; |
61
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
83 char *t; |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
84 int plen; |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
85 int addr = 0; |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
86 lw_expr_t te, te2; |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
87 structtab_field_t *e; |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
88 |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
89 if (baseaddr == NULL) |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
90 baseaddr = l -> addr; |
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
|
91 |
61
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
92 plen = strlen(pref); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
93 for (e = s -> fields; e; e = e -> next) |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
94 { |
2c24602be78f
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 if (e -> name) |
10
127e5b1e01c0
Removed use of asprintf() and added Makefile options for cross compiling; also a bugfix with sizeof{} in lwasm
lost@l-w.ca
parents:
2
diff
changeset
|
96 { |
61
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
97 len = plen + strlen(e -> name) + 1; |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
98 t = lw_alloc(len + 1); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
99 sprintf(t, "%s.%s", pref, e -> name); |
10
127e5b1e01c0
Removed use of asprintf() and added Makefile options for cross compiling; also a bugfix with sizeof{} in lwasm
lost@l-w.ca
parents:
2
diff
changeset
|
100 } |
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
|
101 else |
10
127e5b1e01c0
Removed use of asprintf() and added Makefile options for cross compiling; also a bugfix with sizeof{} in lwasm
lost@l-w.ca
parents:
2
diff
changeset
|
102 { |
61
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
103 len = plen + 30; |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
104 t = lw_alloc(len + 1); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
105 sprintf(t, "%s.____%d", pref, addr); |
10
127e5b1e01c0
Removed use of asprintf() and added Makefile options for cross compiling; also a bugfix with sizeof{} in lwasm
lost@l-w.ca
parents:
2
diff
changeset
|
106 } |
61
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
107 |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
108 te = lw_expr_build(lw_expr_type_int, addr); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
109 te2 = lw_expr_build(lw_expr_type_oper, lw_expr_oper_plus, te, baseaddr); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
110 register_symbol(as, l, t, te2, symbol_flag_nocheck); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
111 lw_expr_destroy(te); |
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
|
112 |
2c24602be78f
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 (e -> substruct) |
2c24602be78f
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 { |
61
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
115 instantiate_struct(as, l, e -> substruct, t, te2); |
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
|
116 } |
61
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
117 |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
118 lw_expr_destroy(te2); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
119 |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
120 lw_free(t); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
121 addr += e -> size; |
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
|
122 } |
61
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
123 |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
124 /* register the "sizeof" symbol */ |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
125 len = plen + 8; |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
126 t = lw_alloc(len + 1); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
127 sprintf(t, "sizeof{%s}", pref); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
128 te = lw_expr_build(lw_expr_type_int, s -> size); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
129 register_symbol(as, l, t, te, symbol_flag_nocheck); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
130 lw_expr_destroy(te); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
131 lw_free(t); |
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 } |
2c24602be78f
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 |
2c24602be78f
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 PARSEFUNC(pseudo_parse_endstruct) |
2c24602be78f
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 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
137 lw_expr_t te; |
10
127e5b1e01c0
Removed use of asprintf() and added Makefile options for cross compiling; also a bugfix with sizeof{} in lwasm
lost@l-w.ca
parents:
2
diff
changeset
|
138 |
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
|
139 if (as -> instruct == 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 { |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
223
diff
changeset
|
141 lwasm_register_error(as, l, W_ENDSTRUCT_WITHOUT); |
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
|
142 skip_operand(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
|
143 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
|
144 } |
10
127e5b1e01c0
Removed use of asprintf() and added Makefile options for cross compiling; also a bugfix with sizeof{} in lwasm
lost@l-w.ca
parents:
2
diff
changeset
|
145 |
61
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
146 te = lw_expr_build(lw_expr_type_int, 0); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
147 |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
148 // make all the relevant generic struct symbols |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
149 instantiate_struct(as, l, as -> cstruct, as -> cstruct -> name, te); |
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
|
150 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
|
151 |
2c24602be78f
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 l -> soff = as -> cstruct -> size; |
2c24602be78f
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 as -> instruct = 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
|
154 |
2c24602be78f
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 skip_operand(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
|
156 |
61
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
157 lw_expr_destroy(l -> addr); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
158 l -> addr = as -> savedaddr; |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
159 as -> savedaddr = 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
|
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 l -> len = 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
|
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 |
2c24602be78f
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 void register_struct_entry(asmstate_t *as, line_t *l, int size, structtab_t *ss) |
2c24602be78f
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 structtab_field_t *e, *e2; |
2c24602be78f
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 |
2c24602be78f
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 l -> soff = as -> cstruct -> size; |
2c24602be78f
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 e = lw_alloc(sizeof(structtab_field_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
|
170 e -> next = 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
|
171 e -> size = size; |
2c24602be78f
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 if (l -> 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
|
173 e -> name = lw_strdup(l -> 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
|
174 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
|
175 e -> name = 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
|
176 e -> substruct = ss; |
2c24602be78f
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 if (as -> cstruct -> fields) |
2c24602be78f
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 { |
2c24602be78f
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 for (e2 = as -> cstruct -> fields; e2 -> next; e2 = e2 -> 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
|
180 /* 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
|
181 e2 -> next = 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
|
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 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
|
184 { |
2c24602be78f
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 as -> cstruct -> fields = 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
|
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 as -> cstruct -> size += size; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
188 } |
2c24602be78f
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 |
2c24602be78f
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 int expand_struct(asmstate_t *as, line_t *l, char **p, char *opc) |
2c24602be78f
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 structtab_t *s; |
10
127e5b1e01c0
Removed use of asprintf() and added Makefile options for cross compiling; also a bugfix with sizeof{} in lwasm
lost@l-w.ca
parents:
2
diff
changeset
|
193 |
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 debug_message(as, 200, "Checking for structure expansion: %s", opc); |
2c24602be78f
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 |
2c24602be78f
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 for (s = as -> structs; s; s = s -> 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
|
197 { |
2c24602be78f
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 (!strcmp(opc, s -> 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
|
199 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
|
200 } |
2c24602be78f
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 if (!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
|
203 return -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
|
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 debug_message(as, 10, "Expanding structure: %s", opc); |
2c24602be78f
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 |
2c24602be78f
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 (!(l -> 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
|
208 { |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
223
diff
changeset
|
209 lwasm_register_error(as, l, E_STRUCT_NONAME); |
2
7317fbe024af
Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents:
0
diff
changeset
|
210 return -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
|
211 } |
47 | 212 |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
213 l -> len = s -> size; |
2c24602be78f
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 |
2c24602be78f
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 if (as -> instruct) |
10
127e5b1e01c0
Removed use of asprintf() and added Makefile options for cross compiling; also a bugfix with sizeof{} in lwasm
lost@l-w.ca
parents:
2
diff
changeset
|
216 { |
61
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
217 /* register substruct here */ |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
218 register_struct_entry(as, l, s -> size, s); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
219 /* mark the symbol consumed */ |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
220 l -> symset = 1; |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
221 l -> len = 0; |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
222 return 0; |
10
127e5b1e01c0
Removed use of asprintf() and added Makefile options for cross compiling; also a bugfix with sizeof{} in lwasm
lost@l-w.ca
parents:
2
diff
changeset
|
223 } |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
224 else |
10
127e5b1e01c0
Removed use of asprintf() and added Makefile options for cross compiling; also a bugfix with sizeof{} in lwasm
lost@l-w.ca
parents:
2
diff
changeset
|
225 { |
61
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
226 /* instantiate the struct here */ |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
227 instantiate_struct(as, l, s, l -> sym, NULL); |
ccaecdff3fc2
Make structure definitions not affect current assembly address and fix up cosmetic offset display in listings
lost@l-w.ca
parents:
48
diff
changeset
|
228 return 0; |
10
127e5b1e01c0
Removed use of asprintf() and added Makefile options for cross compiling; also a bugfix with sizeof{} in lwasm
lost@l-w.ca
parents:
2
diff
changeset
|
229 } |
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
|
230 |
2c24602be78f
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 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
|
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 |