Mercurial > hg-old > index.cgi
annotate src/list.c @ 8:f1df096aa76f 1.1
Tagged 1.1 bugfix release
author | lost |
---|---|
date | Sun, 04 Jan 2009 05:46:07 +0000 |
parents | 34568fab6058 |
children | 39d750ee8d34 |
rev | line source |
---|---|
0 | 1 /* |
4
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
2 list.c |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
3 Copyright © 2008 William Astle |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
4 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
5 This file is part of LWASM. |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
6 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
7 LWASM is free software: you can redistribute it and/or modify it under the |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
8 terms of the GNU General Public License as published by the Free Software |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
9 Foundation, either version 3 of the License, or (at your option) any later |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
10 version. |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
11 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
12 This program is distributed in the hope that it will be useful, but WITHOUT |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
15 more details. |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
16 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
17 You should have received a copy of the GNU General Public License along with |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
18 this program. If not, see <http://www.gnu.org/licenses/>. |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
19 |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
20 Contains code for displaying a program listing in lwasm |
34568fab6058
Fixed package to include all required files; also added copyright preamble to all source files
lost
parents:
0
diff
changeset
|
21 */ |
0 | 22 |
23 //#include <ctype.h> | |
24 #include <errno.h> | |
25 #include <stdio.h> | |
26 //#include <stdlib.h> | |
27 #include <string.h> | |
28 #define __list_c_seen__ | |
29 //#include "instab.h" | |
30 #include "lwasm.h" | |
31 | |
32 const char *errlist[] = | |
33 { | |
34 "No error", | |
35 "Bad opcode", | |
36 "Illegal Symbol", | |
37 "Multiply defined symbol", | |
38 "Symbol required but not present", | |
39 "Forward references not permitted", | |
40 "Byte overflow", | |
41 "Phase error", | |
42 "Bad operand", | |
43 "Symbol not permitted here", | |
44 "Undefined symbol", | |
45 "Bit number out of range", | |
46 "Invalid expression", | |
47 "Invalid register", | |
48 "Bad file name", | |
49 "ENDM without MACRO", | |
50 "Redefined macro", | |
51 "Nested namespace", | |
52 "Bad condition", | |
53 "User error", | |
54 "Bad pragma", | |
55 "" | |
56 }; | |
57 | |
58 void list_code(asmstate_t *as) | |
59 { | |
60 FILE *lf; | |
61 sourceline_t *cl; | |
62 int bn; | |
63 int c; | |
64 char *t; | |
65 | |
66 if (as -> listfile && strcmp(as -> listfile, "-")) | |
67 { | |
68 lf = fopen(as -> listfile, "w"); | |
69 if (!lf) | |
70 { | |
71 perror("Cannot open list file"); | |
72 return; | |
73 } | |
74 } | |
75 else | |
76 { | |
77 lf = stdout; | |
78 } | |
79 | |
80 for (cl = as -> source_head; cl; cl = cl -> next) | |
81 { | |
82 bn = 0; | |
83 if (cl -> errors) | |
84 { | |
85 errortab_t *e; | |
86 for (e = cl -> errors; e; e = e -> next) | |
87 { | |
88 if (e -> errnum < ERR_MAXERR && e -> errnum != ERR_USER) | |
89 fprintf(lf, "*****ERROR: %s\n", errlist[e -> errnum]); | |
90 } | |
91 if (cl -> user_error) | |
92 { | |
93 fprintf(lf, "*****ERROR: %s\n", cl -> user_error); | |
94 } | |
95 } | |
96 if (cl -> skipped) | |
97 { | |
98 fprintf(lf, "%-15.15s", "<skipped>"); | |
99 } | |
100 else if (cl -> macrodef) | |
101 { | |
102 fprintf(lf, "%-15.15s", "<macrodef>"); | |
103 } | |
104 else if (cl -> opcode >= 0 && cl -> numcodebytes > 0) | |
105 { | |
106 fprintf(lf, "%04X ", cl -> addr); | |
107 while (bn < 5 && bn < cl -> numcodebytes) | |
108 { | |
109 fprintf(lf, "%02X", cl -> codebytes[bn]); | |
110 bn++; | |
111 } | |
112 while (bn < 5) | |
113 { | |
114 fprintf(lf, " "); | |
115 bn++; | |
116 } | |
117 } | |
118 else if (cl -> addrset || (cl -> len && cl -> numcodebytes == 0)) | |
119 { | |
120 fprintf(lf, "%04X %10s", cl -> addr, ""); | |
121 } | |
122 else if (cl -> isequ) | |
123 { | |
124 fprintf(lf, " %04X ", cl -> symaddr); | |
125 } | |
126 else if (cl -> issetdp) | |
127 { | |
128 fprintf(lf, " %02X ", cl -> dpval); | |
129 } | |
130 else | |
131 fprintf(lf, " "); | |
132 fprintf(lf, " %15.15s:%06d ", cl -> sourcefile, cl -> lineno); | |
133 // actually display the line from the file | |
134 for (c = 0, t = cl -> line; *t; t++) | |
135 { | |
136 if (*t == '\n' || *t == '\r') | |
137 break; | |
138 if (*t == '\t') | |
139 { | |
140 do | |
141 { | |
142 fprintf(lf, " "); | |
143 c++; | |
144 } while (c % 8); | |
145 } | |
146 else | |
147 { | |
148 c++; | |
149 fprintf(lf, "%c", *t); | |
150 } | |
151 } | |
152 // fprintf(lf, "\n"); | |
153 | |
154 while (bn < cl -> numcodebytes) | |
155 { | |
156 if (bn % 5 == 0) | |
157 fprintf(lf, "\n%04X ", (cl -> addr + bn) & 0xFFFF); | |
158 fprintf(lf, "%02X", cl -> codebytes[bn]); | |
159 bn++; | |
160 } | |
161 fprintf(lf, "\n"); | |
162 } | |
163 | |
164 fprintf(lf, "\n"); | |
165 list_symbols(as, lf); | |
166 | |
167 if (lf != stdout) | |
168 fclose(lf); | |
169 } | |
170 |