comparison lwasm/list.c @ 384:38b50ce6967a

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