Mercurial > hg-old > index.cgi
annotate src/list.c @ 74:c8c772ef5df9
Checkpointing object target implementation
author | lost |
---|---|
date | Thu, 08 Jan 2009 01:18:40 +0000 |
parents | 9fa4f77dd119 |
children | dbf1b926c2f1 |
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 |
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 | 22 |
35
39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents:
4
diff
changeset
|
23 #define __list_c_seen__ |
39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents:
4
diff
changeset
|
24 |
0 | 25 #include <stdio.h> |
35
39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents:
4
diff
changeset
|
26 #include <stdlib.h> |
39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents:
4
diff
changeset
|
27 |
0 | 28 #include "lwasm.h" |
29 | |
35
39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents:
4
diff
changeset
|
30 void lwasm_show_errors(asmstate_t *as) |
0 | 31 { |
35
39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents:
4
diff
changeset
|
32 lwasm_line_t *l; |
39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents:
4
diff
changeset
|
33 lwasm_error_t *e; |
0 | 34 |
35
39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents:
4
diff
changeset
|
35 for (l = as -> lineshead; l; l = l -> next) |
0 | 36 { |
35
39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents:
4
diff
changeset
|
37 if (l -> err) |
0 | 38 { |
35
39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents:
4
diff
changeset
|
39 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
|
40 { |
39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents:
4
diff
changeset
|
41 fprintf(stderr, "ERROR: %s\n", e -> mess); |
39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents:
4
diff
changeset
|
42 } |
44 | 43 fprintf(stderr, "%s:%d: %s\n", l -> filename, l -> lineno, l -> text); |
0 | 44 } |
45 } | |
46 } | |
47 | |
35
39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents:
4
diff
changeset
|
48 void lwasm_list(asmstate_t *as) |
39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents:
4
diff
changeset
|
49 { |
44 | 50 FILE *lf; |
51 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
|
52 int c, c3; |
44 | 53 char *p; |
54 | |
55 if (as -> listfile[0] == '-' && as -> listfile[1] == '\0') | |
56 lf = stdout; | |
57 else | |
58 { | |
45 | 59 lf = fopen(as -> listfile, "w"); |
44 | 60 if (!lf) |
61 { | |
45 | 62 fprintf(stderr, "Unable to open list file '%s'. No listing will be generated: ", as -> listfile); |
63 perror(""); | |
44 | 64 goto showerr; |
65 } | |
66 } | |
67 | |
68 for (l = as -> lineshead; l; l = l -> next) | |
69 { | |
49
21ae0fab469b
Added needed infra for useful listing of EQU and ORG type statements
lost
parents:
47
diff
changeset
|
70 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
|
71 { |
21ae0fab469b
Added needed infra for useful listing of EQU and ORG type statements
lost
parents:
47
diff
changeset
|
72 fprintf(lf, "%04X ", l -> codeaddr); |
21ae0fab469b
Added needed infra for useful listing of EQU and ORG type statements
lost
parents:
47
diff
changeset
|
73 } |
21ae0fab469b
Added needed infra for useful listing of EQU and ORG type statements
lost
parents:
47
diff
changeset
|
74 else |
21ae0fab469b
Added needed infra for useful listing of EQU and ORG type statements
lost
parents:
47
diff
changeset
|
75 { |
21ae0fab469b
Added needed infra for useful listing of EQU and ORG type statements
lost
parents:
47
diff
changeset
|
76 fprintf(lf, " "); |
21ae0fab469b
Added needed infra for useful listing of EQU and ORG type statements
lost
parents:
47
diff
changeset
|
77 } |
44 | 78 |
50 | 79 if (l -> addrset == 2) |
44 | 80 { |
50 | 81 fprintf(lf, "%04X ", l -> symaddr); |
44 | 82 } |
50 | 83 else |
44 | 84 { |
50 | 85 for (c = 0; c < l -> codelen && c < 5; c++) |
86 { | |
87 fprintf(lf, "%02X", l -> bytes[c]); | |
88 } | |
89 while (c < 5) | |
90 { | |
91 fprintf(lf, " "); | |
92 c++; | |
93 } | |
44 | 94 } |
95 fprintf(lf, " %20.20s:%05d ", l -> filename, l -> lineno); | |
96 | |
97 // 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
|
98 for (c3 = 0, c = 0, p = l -> text; *p; c++, p++) |
44 | 99 { |
100 if (*p == '\t') | |
101 { | |
102 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
|
103 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
|
104 c3 += c2; |
44 | 105 while (c2--) fputc(' ', lf); |
106 } | |
107 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
|
108 { |
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
|
109 c3++; |
44 | 110 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
|
111 } |
44 | 112 } |
113 fputc('\n', lf); | |
114 | |
115 if (l -> codelen > 5) | |
116 { | |
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
|
117 fprintf(lf, "%04X ", (l -> codeaddr + 5) & 0xFFFF); |
44 | 118 for (c = 5; c < l -> codelen; c++) |
119 { | |
120 if (!(c % 5) && c != 5) | |
121 { | |
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
|
122 fprintf(lf, "\n%04X ", (l -> codeaddr + c) & 0xFFFF); |
44 | 123 } |
124 fprintf(lf, "%02X", l -> bytes[c]); | |
125 } | |
126 fputc('\n', lf); | |
127 } | |
128 } | |
58 | 129 |
130 lwasm_list_symbols(as, lf); | |
131 | |
44 | 132 if (lf != stdout) |
133 fclose(lf); | |
134 | |
135 showerr: | |
35
39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents:
4
diff
changeset
|
136 lwasm_show_errors(as); |
39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
lost
parents:
4
diff
changeset
|
137 } |