annotate lwasm/list.c @ 388:8991eb507d2d

Added missing arg-nonnull.h ??? file to repo
author lost@l-w.ca
date Wed, 14 Jul 2010 20:17:57 -0600
parents a741d2e4869f
children fbb7bfed8076
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
384
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
1 /*
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
2 list.c
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
3
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
4 Copyright © 2010 William Astle
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
5
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
6 This file is part of LWTOOLS.
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
7
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
11 version.
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
12
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
16 more details.
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
17
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
20 */
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
21
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
22 #include <config.h>
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
23
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
24 #include <stdio.h>
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
25 #include <string.h>
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
26
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
27 #include <lw_alloc.h>
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
28 #include <lw_string.h>
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
29
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
30 #include "lwasm.h"
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
31 #include "instab.h"
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
32
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
33 /*
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
34 Do listing
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
35 */
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
36 void do_list(asmstate_t *as)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
37 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
38 line_t *cl;
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
39 FILE *of;
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
40 int i;
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
41
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
42 if (!(as -> flags & FLAG_LIST))
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
43 return;
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
44
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
45 if (as -> list_file)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
46 of = fopen(as -> list_file, "w");
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
47 else
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
48 of = stdout;
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
49 if (!of)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
50 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
51 fprintf(stderr, "Cannot open list file; list not generated\n");
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
52 return;
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
53 }
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
54 for (cl = as -> line_head; cl; cl = cl -> next)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
55 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
56 if (cl -> len < 1)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
57 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
58 fprintf(of, " ");
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
59 }
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
60 else
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
61 {
387
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
62 lw_expr_t te;
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
63 te = lw_expr_copy(cl -> addr);
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
64 as -> exportcheck = 1;
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
65 lwasm_reduce_expr(as, te);
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
66 as -> exportcheck = 0;
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
67 fprintf(of, "%04X ", lw_expr_intval(te) & 0xffff);
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
68 lw_expr_destroy(te);
384
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
69 for (i = 0; i < cl -> outputl && i < 8; i++)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
70 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
71 fprintf(of, "%02X", cl -> output[i]);
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
72 }
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
73 for (; i < 8; i++)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
74 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
75 fprintf(of, " ");
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
76 }
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
77 fprintf(of, " ");
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
78 }
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
79 fprintf(of, "%15s:%05d %s\n", cl -> linespec, cl -> lineno, cl -> ltext);
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
80 if (cl -> outputl > 8)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
81 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
82 for (i = 8; i < cl -> outputl; i++)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
83 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
84 if (i % 8 == 0)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
85 {
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
86 if (i != 8)
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
87 fprintf(of, "\n ");
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
88 else
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
89 fprintf(of, " ");
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
90 }
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
91 fprintf(of, "%02X", cl -> output[i]);
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
92 }
387
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
93 if (i % 8)
a741d2e4869f Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents: 384
diff changeset
94 fprintf(of, "\n");
384
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
95 }
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
96 }
38b50ce6967a Made --list and --depend work
lost@starbug
parents:
diff changeset
97 }