annotate lwasm/list.c @ 286:701132971855 2.3

Fixed regression related to force linking a library file
author lost
date Sat, 25 Apr 2009 02:18:06 +0000
parents bae1e3ecdce1
children
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
35
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
3 Copyright © 2009 William Astle
4
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
35
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
20 Contains code for displaying a program listings, etc.
4
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
35
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
23 #define __list_c_seen__
212
bae1e3ecdce1 More preparation for gnulib integration
lost
parents: 164
diff changeset
24 #include <config.h>
35
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
25
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
26 #include <stdio.h>
35
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
27 #include <stdlib.h>
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
28
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
29 #include "lwasm.h"
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
30
35
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
31 void lwasm_show_errors(asmstate_t *as)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
32 {
35
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
33 lwasm_line_t *l;
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
34 lwasm_error_t *e;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
35
35
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
36 for (l = as -> lineshead; l; l = l -> next)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
37 {
35
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
38 if (l -> err)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
39 {
35
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
40 for (e = l -> err; e; e = e -> next)
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
41 {
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
42 fprintf(stderr, "ERROR: %s\n", e -> mess);
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
43 }
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
44 fprintf(stderr, "%s:%d: %s\n", l -> filename, l -> lineno, l -> text);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
45 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
46 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
47 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
48
35
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
49 void lwasm_list(asmstate_t *as)
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
50 {
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
51 FILE *lf;
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
52 lwasm_line_t *l;
72
9fa4f77dd119 Fixed tab handling in list code; also added address to second and later lines in byte listing for a particular line
lost
parents: 58
diff changeset
53 int c, c3;
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
54 char *p;
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
55
102
dbf1b926c2f1 Made listings off be default
lost
parents: 72
diff changeset
56 if (!as -> listfile)
164
586069fb17a1 Actually show errors when no list is requested
lost
parents: 151
diff changeset
57 goto showerr;
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
58 if (as -> listfile[0] == '-' && as -> listfile[1] == '\0')
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
59 lf = stdout;
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
60 else
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
61 {
45
be459d69f481 Fixed stupid error in opening list file
lost
parents: 44
diff changeset
62 lf = fopen(as -> listfile, "w");
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
63 if (!lf)
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
64 {
45
be459d69f481 Fixed stupid error in opening list file
lost
parents: 44
diff changeset
65 fprintf(stderr, "Unable to open list file '%s'. No listing will be generated: ", as -> listfile);
be459d69f481 Fixed stupid error in opening list file
lost
parents: 44
diff changeset
66 perror("");
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
67 goto showerr;
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
68 }
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
69 }
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
70
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
71 for (l = as -> lineshead; l; l = l -> next)
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
72 {
49
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 47
diff changeset
73 if (l -> addrset == 1 || l -> codelen > 0 || l -> nocodelen > 0)
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 47
diff changeset
74 {
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 47
diff changeset
75 fprintf(lf, "%04X ", l -> codeaddr);
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 47
diff changeset
76 }
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 47
diff changeset
77 else
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 47
diff changeset
78 {
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 47
diff changeset
79 fprintf(lf, " ");
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 47
diff changeset
80 }
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
81
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
82 if (l -> addrset == 2)
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
83 {
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
84 fprintf(lf, "%04X ", l -> symaddr);
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
85 }
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
86 else
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
87 {
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
88 for (c = 0; c < l -> codelen && c < 5; c++)
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
89 {
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
90 fprintf(lf, "%02X", l -> bytes[c]);
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
91 }
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
92 while (c < 5)
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
93 {
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
94 fprintf(lf, " ");
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
95 c++;
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
96 }
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
97 }
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
98 fprintf(lf, " %20.20s:%05d ", l -> filename, l -> lineno);
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
99
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
100 // print line here
72
9fa4f77dd119 Fixed tab handling in list code; also added address to second and later lines in byte listing for a particular line
lost
parents: 58
diff changeset
101 for (c3 = 0, c = 0, p = l -> text; *p; c++, p++)
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
102 {
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
103 if (*p == '\t')
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
104 {
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
105 int c2;
72
9fa4f77dd119 Fixed tab handling in list code; also added address to second and later lines in byte listing for a particular line
lost
parents: 58
diff changeset
106 c2 = 8 - (c3 % 8);
9fa4f77dd119 Fixed tab handling in list code; also added address to second and later lines in byte listing for a particular line
lost
parents: 58
diff changeset
107 c3 += c2;
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
108 while (c2--) fputc(' ', lf);
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
109 }
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
110 else
72
9fa4f77dd119 Fixed tab handling in list code; also added address to second and later lines in byte listing for a particular line
lost
parents: 58
diff changeset
111 {
9fa4f77dd119 Fixed tab handling in list code; also added address to second and later lines in byte listing for a particular line
lost
parents: 58
diff changeset
112 c3++;
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
113 fputc(*p, lf);
72
9fa4f77dd119 Fixed tab handling in list code; also added address to second and later lines in byte listing for a particular line
lost
parents: 58
diff changeset
114 }
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
115 }
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
116 fputc('\n', lf);
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
117
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
118 if (l -> codelen > 5)
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
119 {
72
9fa4f77dd119 Fixed tab handling in list code; also added address to second and later lines in byte listing for a particular line
lost
parents: 58
diff changeset
120 fprintf(lf, "%04X ", (l -> codeaddr + 5) & 0xFFFF);
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
121 for (c = 5; c < l -> codelen; c++)
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
122 {
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
123 if (!(c % 5) && c != 5)
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
124 {
72
9fa4f77dd119 Fixed tab handling in list code; also added address to second and later lines in byte listing for a particular line
lost
parents: 58
diff changeset
125 fprintf(lf, "\n%04X ", (l -> codeaddr + c) & 0xFFFF);
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
126 }
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
127 fprintf(lf, "%02X", l -> bytes[c]);
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
128 }
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
129 fputc('\n', lf);
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
130 }
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
131 }
58
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 50
diff changeset
132
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 50
diff changeset
133 lwasm_list_symbols(as, lf);
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 50
diff changeset
134
44
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
135 if (lf != stdout)
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
136 fclose(lf);
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
137
2330b88f9600 Added simple output listing
lost
parents: 35
diff changeset
138 showerr:
35
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
139 lwasm_show_errors(as);
39d750ee8d34 Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents: 4
diff changeset
140 }