Mercurial > hg-old > index.cgi
comparison lwdisasm/symbol.c @ 409:cba03436c720
Checkpoint disassembler
author | lost@l-w.ca |
---|---|
date | Mon, 02 Aug 2010 18:07:04 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
408:2a94b2e64621 | 409:cba03436c720 |
---|---|
1 /* | |
2 symbol.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 | |
26 #include <lw_alloc.h> | |
27 #include <lw_string.h> | |
28 | |
29 #include "lwdisasm.h" | |
30 | |
31 symbol_t *find_symbol(disasmstate_t *as, int addr, int section) | |
32 { | |
33 symbol_t *s; | |
34 | |
35 for (s = as -> symbols; s; s = s -> next) | |
36 { | |
37 if (s -> address == addr && s -> section == section) | |
38 return s; | |
39 } | |
40 return NULL; | |
41 } | |
42 | |
43 symbol_t *register_symbol(disasmstate_t *as, int addr, int section, char *symbol) | |
44 { | |
45 char symbuf[200]; | |
46 symbol_t *s; | |
47 | |
48 for (s = as -> symbols; s; s = s -> next) | |
49 { | |
50 if (s -> address == addr && s -> section == section) | |
51 return s; | |
52 } | |
53 | |
54 if (!symbol) | |
55 { | |
56 if (section) | |
57 { | |
58 sprintf(symbuf, "L%d_%04X", section, addr); | |
59 } | |
60 else | |
61 { | |
62 sprintf(symbuf, "L%04X", addr); | |
63 } | |
64 symbol = symbuf; | |
65 } | |
66 | |
67 s = lw_alloc(sizeof(symbol_t)); | |
68 s -> symbol = lw_strdup(symbol); | |
69 s -> address = addr; | |
70 s -> section = section; | |
71 s -> next = as -> symbols; | |
72 as -> symbols = s; | |
73 return s; | |
74 } | |
75 | |
76 void attach_symbols(disasmstate_t *as) | |
77 { | |
78 symbol_t *s; | |
79 linedata_t *l; | |
80 | |
81 for (s = as -> symbols; s; s = s -> next) | |
82 { | |
83 for (l = as -> lhead; l; l = l -> next) | |
84 { | |
85 if (l -> isref == 0 && l -> address == s -> address && l -> sectionref == s -> section) | |
86 { | |
87 l -> symbol = s; | |
88 l -> isref = 1; | |
89 break; | |
90 } | |
91 } | |
92 } | |
93 } |