annotate old-trunk/lwasm/old/list.c @ 348:11a95c6414b4

Added third func to instab to split resolve and emit logic
author lost@starbug
date Sat, 27 Mar 2010 22:15:07 -0600
parents eb230fa7d28e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
2 list.c
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
4
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
5 This file is part of LWASM.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
6
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
10 version.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
11
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
15 more details.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
16
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
19
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
20 Contains code for displaying a program listings, etc.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
21 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
22
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
23 #define __list_c_seen__
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
24 #include <config.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
25
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
26 #include <stdio.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
27 #include <stdlib.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
28
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
29 #include "lwasm.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
30
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
31 void lwasm_show_errors(asmstate_t *as)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
32 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
33 lwasm_line_t *l;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
34 lwasm_error_t *e;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
35
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
36 for (l = as -> lineshead; l; l = l -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
37 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
38 if (l -> err)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
39 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
40 for (e = l -> err; e; e = e -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
41 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
42 fprintf(stderr, "ERROR: %s\n", e -> mess);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
43 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
44 fprintf(stderr, "%s:%d: %s\n", l -> filename, l -> lineno, l -> text);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
45 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
46 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
47 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
48
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
49 void lwasm_list(asmstate_t *as)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
50 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
51 FILE *lf;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
52 lwasm_line_t *l;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
53 int c, c3;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
54 char *p;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
55
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
56 if (!as -> listfile)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
57 goto showerr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
58 if (as -> listfile[0] == '-' && as -> listfile[1] == '\0')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
59 lf = stdout;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
60 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
61 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
62 lf = fopen(as -> listfile, "w");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
63 if (!lf)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
64 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
65 fprintf(stderr, "Unable to open list file '%s'. No listing will be generated: ", as -> listfile);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
66 perror("");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
67 goto showerr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
68 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
69 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
70
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
71 for (l = as -> lineshead; l; l = l -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
72 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
73 if (l -> addrset == 1 || l -> codelen > 0 || l -> nocodelen > 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
74 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
75 fprintf(lf, "%04X ", l -> codeaddr);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
76 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
77 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
78 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
79 fprintf(lf, " ");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
80 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
81
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
82 if (l -> addrset == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
83 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
84 fprintf(lf, "%04X ", l -> symaddr);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
85 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
86 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
87 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
88 for (c = 0; c < l -> codelen && c < 5; c++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
89 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
90 fprintf(lf, "%02X", l -> bytes[c]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
91 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
92 while (c < 5)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
93 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
94 fprintf(lf, " ");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
95 c++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
96 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
97 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
98 fprintf(lf, " %20.20s:%05d ", l -> filename, l -> lineno);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
99
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
100 // print line here
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
101 for (c3 = 0, c = 0, p = l -> text; *p; c++, p++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
102 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
103 if (*p == '\t')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
104 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
105 int c2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
106 c2 = 8 - (c3 % 8);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
107 c3 += c2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
108 while (c2--) fputc(' ', lf);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
109 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
110 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
111 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
112 c3++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
113 fputc(*p, lf);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
114 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
115 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
116 fputc('\n', lf);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
117
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
118 if (l -> codelen > 5)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
119 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
120 fprintf(lf, "%04X ", (l -> codeaddr + 5) & 0xFFFF);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
121 for (c = 5; c < l -> codelen; c++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
122 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
123 if (!(c % 5) && c != 5)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
124 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
125 fprintf(lf, "\n%04X ", (l -> codeaddr + c) & 0xFFFF);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
126 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
127 fprintf(lf, "%02X", l -> bytes[c]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
128 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
129 fputc('\n', lf);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
130 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
131 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
132
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
133 lwasm_list_symbols(as, lf);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
134
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
135 if (lf != stdout)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
136 fclose(lf);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
137
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
138 showerr:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
139 lwasm_show_errors(as);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
140 }