annotate lwasm/list.c @ 446:194787ce2a77 3.0

Adjusted listings to convert tabs to spaces; assume 8 space tabs
author lost@l-w.ca
date Thu, 04 Nov 2010 22:40:57 -0600
parents 4bcb763bddde
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
384
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
1 /*
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
2 list.c
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
3
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
4 Copyright © 2010 William Astle
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
5
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
6 This file is part of LWTOOLS.
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
7
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
11 version.
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
12
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
16 more details.
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
17
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
20 */
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
21
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
22 #include <config.h>
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
23
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
24 #include <stdio.h>
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
25 #include <string.h>
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
26
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
27 #include <lw_alloc.h>
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
28 #include <lw_string.h>
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
29
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
30 #include "lwasm.h"
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
31 #include "instab.h"
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
32
390
027d7fbcdcfc Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents: 389
diff changeset
33 void list_symbols(asmstate_t *as, FILE *of);
027d7fbcdcfc Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents: 389
diff changeset
34
384
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
35 /*
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
36 Do listing
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
37 */
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
38 void do_list(asmstate_t *as)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
39 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
40 line_t *cl;
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
41 FILE *of;
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
42 int i;
446
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
43 char *tc;
384
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
44 if (!(as -> flags & FLAG_LIST))
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
45 return;
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
46
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
47 if (as -> list_file)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
48 of = fopen(as -> list_file, "w");
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
49 else
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
50 of = stdout;
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
51 if (!of)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
52 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
53 fprintf(stderr, "Cannot open list file; list not generated\n");
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
54 return;
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
55 }
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
56 for (cl = as -> line_head; cl; cl = cl -> next)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
57 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
58 if (cl -> len < 1)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
59 {
389
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
60 if (cl -> soff >= 0)
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
61 {
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
62 fprintf(of, "%04X ", cl -> soff & 0xffff);
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
63 }
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
64 else if (cl -> dshow >= 0)
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
65 {
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
66 if (cl -> dsize == 1)
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
67 {
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
68 fprintf(of, " %02X ", cl -> dshow & 0xff);
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
69 }
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
70 else
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
71 {
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
72 fprintf(of, " %04X ", cl -> dshow & 0xff);
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
73 }
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
74 }
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
75 else if (cl -> dptr)
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
76 {
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
77 lw_expr_t te;
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
78 te = lw_expr_copy(cl -> dptr -> value);
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
79 as -> exportcheck = 1;
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
80 as -> csect = cl -> csect;
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
81 lwasm_reduce_expr(as, te);
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
82 as -> exportcheck = 0;
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
83 if (lw_expr_istype(te, lw_expr_type_int))
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
84 {
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
85 fprintf(of, " %04X ", lw_expr_intval(te) & 0xffff);
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
86 }
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
87 else
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
88 {
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
89 fprintf(of, " ???? ");
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
90 }
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
91 lw_expr_destroy(te);
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
92 }
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
93 else
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
94 {
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
95 fprintf(of, " ");
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
96 }
384
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
97 }
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
98 else
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
99 {
387
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
100 lw_expr_t te;
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
101 te = lw_expr_copy(cl -> addr);
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
102 as -> exportcheck = 1;
389
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
103 as -> csect = cl -> csect;
387
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
104 lwasm_reduce_expr(as, te);
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
105 as -> exportcheck = 0;
389
fbb7bfed8076 Added in structure support and fixed up some warts in the listing code (by adding more warts)
lost@l-w.ca
parents: 387
diff changeset
106 // fprintf(of, "%s\n", lw_expr_print(te));
387
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
107 fprintf(of, "%04X ", lw_expr_intval(te) & 0xffff);
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
108 lw_expr_destroy(te);
384
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
109 for (i = 0; i < cl -> outputl && i < 8; i++)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
110 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
111 fprintf(of, "%02X", cl -> output[i]);
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
112 }
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
113 for (; i < 8; i++)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
114 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
115 fprintf(of, " ");
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
116 }
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
117 fprintf(of, " ");
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
118 }
446
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
119 /* the 32.32 below is deliberately chosen so that the start of the line text is at
430
4bcb763bddde Adjusted output in list so that 8 space tabs line up right in output
lost@l-w.ca
parents: 417
diff changeset
120 a multiple of 8 from the start of the list line */
446
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
121 fprintf(of, "(%32.32s):%05d ", cl -> linespec, cl -> lineno);
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
122 i = 0;
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
123 for (tc = cl -> ltext; *tc; tc++)
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
124 {
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
125 if ((*tc) == '\t')
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
126 {
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
127 if (i % 8 == 0)
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
128 {
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
129 i += 8;
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
130 fprintf(of, " ");
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
131 }
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
132 else
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
133 {
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
134 while (i % 8)
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
135 {
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
136 fprintf(of, " ");
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
137 i++;
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
138 }
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
139 }
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
140 }
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
141 else
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
142 {
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
143 fprintf(of, "%c", *tc);
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
144 i++;
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
145 }
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
146 }
194787ce2a77 Adjusted listings to convert tabs to spaces; assume 8 space tabs
lost@l-w.ca
parents: 430
diff changeset
147 fprintf(of, "\n");
384
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
148 if (cl -> outputl > 8)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
149 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
150 for (i = 8; i < cl -> outputl; i++)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
151 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
152 if (i % 8 == 0)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
153 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
154 if (i != 8)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
155 fprintf(of, "\n ");
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
156 else
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
157 fprintf(of, " ");
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
158 }
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
159 fprintf(of, "%02X", cl -> output[i]);
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
160 }
417
f792faf877bb Fixed minor layout glitch in listing code
lost@l-w.ca
parents: 390
diff changeset
161 if (i > 8)
387
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
162 fprintf(of, "\n");
384
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
163 }
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
164 }
390
027d7fbcdcfc Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents: 389
diff changeset
165
027d7fbcdcfc Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents: 389
diff changeset
166 if (as -> flags & FLAG_SYMBOLS)
027d7fbcdcfc Basic symbol table output; needs work for non-constant symbols
lost@l-w.ca
parents: 389
diff changeset
167 list_symbols(as, of);
384
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
168 }