Mercurial > hg > index.cgi
comparison lwasm/list.c @ 0:2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
author | lost@l-w.ca |
---|---|
date | Wed, 19 Jan 2011 22:27:17 -0700 |
parents | |
children | 5ecdc4dae84d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2c24602be78f |
---|---|
1 /* | |
2 list.c | |
3 | |
4 Copyright © 2010 William Astle | |
5 | |
6 This file is part of LWTOOLS. | |
7 | |
8 LWTOOLS is free software: you can redistribute it and/or modify it under the | |
9 terms of the GNU General Public License as published by the Free Software | |
10 Foundation, either version 3 of the License, or (at your option) any later | |
11 version. | |
12 | |
13 This program is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
16 more details. | |
17 | |
18 You should have received a copy of the GNU General Public License along with | |
19 this program. If not, see <http://www.gnu.org/licenses/>. | |
20 */ | |
21 | |
22 #include <stdio.h> | |
23 #include <string.h> | |
24 | |
25 #include <lw_alloc.h> | |
26 #include <lw_string.h> | |
27 | |
28 #include "lwasm.h" | |
29 #include "instab.h" | |
30 | |
31 void list_symbols(asmstate_t *as, FILE *of); | |
32 | |
33 /* | |
34 Do listing | |
35 */ | |
36 void do_list(asmstate_t *as) | |
37 { | |
38 line_t *cl; | |
39 FILE *of; | |
40 int i; | |
41 | |
42 if (!(as -> flags & FLAG_LIST)) | |
43 return; | |
44 | |
45 if (as -> list_file) | |
46 of = fopen(as -> list_file, "w"); | |
47 else | |
48 of = stdout; | |
49 if (!of) | |
50 { | |
51 fprintf(stderr, "Cannot open list file; list not generated\n"); | |
52 return; | |
53 } | |
54 for (cl = as -> line_head; cl; cl = cl -> next) | |
55 { | |
56 if (cl -> len < 1) | |
57 { | |
58 if (cl -> soff >= 0) | |
59 { | |
60 fprintf(of, "%04X ", cl -> soff & 0xffff); | |
61 } | |
62 else if (cl -> dshow >= 0) | |
63 { | |
64 if (cl -> dsize == 1) | |
65 { | |
66 fprintf(of, " %02X ", cl -> dshow & 0xff); | |
67 } | |
68 else | |
69 { | |
70 fprintf(of, " %04X ", cl -> dshow & 0xff); | |
71 } | |
72 } | |
73 else if (cl -> dptr) | |
74 { | |
75 lw_expr_t te; | |
76 te = lw_expr_copy(cl -> dptr -> value); | |
77 as -> exportcheck = 1; | |
78 as -> csect = cl -> csect; | |
79 lwasm_reduce_expr(as, te); | |
80 as -> exportcheck = 0; | |
81 if (lw_expr_istype(te, lw_expr_type_int)) | |
82 { | |
83 fprintf(of, " %04X ", lw_expr_intval(te) & 0xffff); | |
84 } | |
85 else | |
86 { | |
87 fprintf(of, " ???? "); | |
88 } | |
89 lw_expr_destroy(te); | |
90 } | |
91 else | |
92 { | |
93 fprintf(of, " "); | |
94 } | |
95 } | |
96 else | |
97 { | |
98 lw_expr_t te; | |
99 te = lw_expr_copy(cl -> addr); | |
100 as -> exportcheck = 1; | |
101 as -> csect = cl -> csect; | |
102 lwasm_reduce_expr(as, te); | |
103 as -> exportcheck = 0; | |
104 // fprintf(of, "%s\n", lw_expr_print(te)); | |
105 fprintf(of, "%04X ", lw_expr_intval(te) & 0xffff); | |
106 lw_expr_destroy(te); | |
107 for (i = 0; i < cl -> outputl && i < 8; i++) | |
108 { | |
109 fprintf(of, "%02X", cl -> output[i]); | |
110 } | |
111 for (; i < 8; i++) | |
112 { | |
113 fprintf(of, " "); | |
114 } | |
115 fprintf(of, " "); | |
116 } | |
117 /* the 34.34 below is deliberately chosen so that the start of the line text is at | |
118 a multiple of 8 from the start of the list line */ | |
119 fprintf(of, "(%34.34s):%05d %s\n", cl -> linespec, cl -> lineno, cl -> ltext); | |
120 if (cl -> outputl > 8) | |
121 { | |
122 for (i = 8; i < cl -> outputl; i++) | |
123 { | |
124 if (i % 8 == 0) | |
125 { | |
126 if (i != 8) | |
127 fprintf(of, "\n "); | |
128 else | |
129 fprintf(of, " "); | |
130 } | |
131 fprintf(of, "%02X", cl -> output[i]); | |
132 } | |
133 if (i > 8) | |
134 fprintf(of, "\n"); | |
135 } | |
136 } | |
137 | |
138 if (as -> flags & FLAG_SYMBOLS) | |
139 list_symbols(as, of); | |
140 } |