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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
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
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
22
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
23 //#include <ctype.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
24 #include <errno.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
25 #include <stdio.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
26 //#include <stdlib.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
27 #include <string.h>
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
28 #define __list_c_seen__
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
29 //#include "instab.h"
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
30 #include "lwasm.h"
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
31
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
32 const char *errlist[] =
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
33 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
34 "No error",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
35 "Bad opcode",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
36 "Illegal Symbol",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
37 "Multiply defined symbol",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
38 "Symbol required but not present",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
39 "Forward references not permitted",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
40 "Byte overflow",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
41 "Phase error",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
42 "Bad operand",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
43 "Symbol not permitted here",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
44 "Undefined symbol",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
45 "Bit number out of range",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
46 "Invalid expression",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
47 "Invalid register",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
48 "Bad file name",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
49 "ENDM without MACRO",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
50 "Redefined macro",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
51 "Nested namespace",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
52 "Bad condition",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
53 "User error",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
54 "Bad pragma",
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
55 ""
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
56 };
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
57
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
58 void list_code(asmstate_t *as)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
59 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
60 FILE *lf;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
61 sourceline_t *cl;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
62 int bn;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
63 int c;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
64 char *t;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
65
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
66 if (as -> listfile && strcmp(as -> listfile, "-"))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
67 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
68 lf = fopen(as -> listfile, "w");
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
69 if (!lf)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
70 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
71 perror("Cannot open list file");
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
72 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
73 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
74 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
75 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
76 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
77 lf = stdout;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
78 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
79
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
80 for (cl = as -> source_head; cl; cl = cl -> next)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
81 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
82 bn = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
83 if (cl -> errors)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
84 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
85 errortab_t *e;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
86 for (e = cl -> errors; e; e = e -> next)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
87 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
88 if (e -> errnum < ERR_MAXERR && e -> errnum != ERR_USER)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
89 fprintf(lf, "*****ERROR: %s\n", errlist[e -> errnum]);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
90 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
91 if (cl -> user_error)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
92 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
93 fprintf(lf, "*****ERROR: %s\n", cl -> user_error);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
94 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
95 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
96 if (cl -> skipped)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
97 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
98 fprintf(lf, "%-15.15s", "<skipped>");
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
99 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
100 else if (cl -> macrodef)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
101 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
102 fprintf(lf, "%-15.15s", "<macrodef>");
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
103 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
104 else if (cl -> opcode >= 0 && cl -> numcodebytes > 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
105 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
106 fprintf(lf, "%04X ", cl -> addr);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
107 while (bn < 5 && bn < cl -> numcodebytes)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
108 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
109 fprintf(lf, "%02X", cl -> codebytes[bn]);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
110 bn++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
111 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
112 while (bn < 5)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
113 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
114 fprintf(lf, " ");
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
115 bn++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
116 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
117 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
118 else if (cl -> addrset || (cl -> len && cl -> numcodebytes == 0))
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
119 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
120 fprintf(lf, "%04X %10s", cl -> addr, "");
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
121 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
122 else if (cl -> isequ)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
123 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
124 fprintf(lf, " %04X ", cl -> symaddr);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
125 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
126 else if (cl -> issetdp)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
127 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
128 fprintf(lf, " %02X ", cl -> dpval);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
129 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
130 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
131 fprintf(lf, " ");
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
132 fprintf(lf, " %15.15s:%06d ", cl -> sourcefile, cl -> lineno);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
133 // actually display the line from the file
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
134 for (c = 0, t = cl -> line; *t; t++)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
135 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
136 if (*t == '\n' || *t == '\r')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
137 break;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
138 if (*t == '\t')
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
139 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
140 do
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
141 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
142 fprintf(lf, " ");
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
143 c++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
144 } while (c % 8);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
145 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
146 else
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
147 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
148 c++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
149 fprintf(lf, "%c", *t);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
150 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
151 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
152 // fprintf(lf, "\n");
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
153
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
154 while (bn < cl -> numcodebytes)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
155 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
156 if (bn % 5 == 0)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
157 fprintf(lf, "\n%04X ", (cl -> addr + bn) & 0xFFFF);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
158 fprintf(lf, "%02X", cl -> codebytes[bn]);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
159 bn++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
160 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
161 fprintf(lf, "\n");
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
162 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
163
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
164 fprintf(lf, "\n");
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
165 list_symbols(as, lf);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
166
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
167 if (lf != stdout)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
168 fclose(lf);
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
169 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
170