1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* libxas: Extendable Assembler Library
* Copyright (C) 2022 Amy Parker <apark0006@student.cerritos.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA or visit
* the GNU Project at <https://gnu.org/licenses>. The GNU General Public
* License version 2 is available at, for your convenience,
* <https://gnu.org/licenses/old-licenses/gpl-2.0.html>.
*/
use cratelpanic;
// TODO: proj global, utilize burns (fn FNNAME(self), which drops the object)
/*
pub fn run_output<T: crate::bbu::SymConv, U: crate::bbu::PtrSize>(
src: Vec<crate::lexer::LexSection<T>>,
// TODO: since dest needs to be empty for symbols to work,
// consider just returning the Vec... or, better yet, manually clearing it!
// to deal with overhead, I think Vec is just a pointer...
dest: &mut Vec<u8>,
plat: &crate::platform::Platform,
) -> () {
let offs: U = get_offset(plat);
// NOTE: vecs only support indices of usize
// this should be fine but is still a potential concern
let mut cp: U = U::from_int::<usize>(0usize);
let mut lt: crate::bbu::outs::LabelTree<T> = crate::bbu::outs::LabelTree::new();
let mut st: crate::bbu::outs::UnresSymTree<T, U> = crate::bbu::outs::UnresSymTree::new();
// NOTE: as a general philosophy, consumption is completely okay
for section in src {
for label in section.labels {
let label_parts: (crate::lexer::LexIdLabel<T>, Option<String>) = label.extract();
if let Some(n) = label_parts.1 {
// TODO: this is inefficient
let mut np: U = cp.clone();
// TODO: support referencing out to data
np.add_ptr(offs);
lt.insert(n.clone(), T::from_ptr(np));
}
for op in label_parts.0 {
let b: Vec<u8> = match op {
// TODO TODO TODO TODO TODO TODO TODO: symbol support in macros
crate::lexer::LexOperation::Macro(m) => m.get_output_bytes(),
crate::lexer::LexOperation::Instruction(n) => {
if n.check_symbols() {
// TODO: remove instantiation
let r = n.get_placeholder();
st.push((n, cp));
r
} else {
n.get_output_bytes()
}
} //_ => panic!("rawbin: unsupported op type"),
};
cp.add_int(b.len());
dest.extend(b);
}
}
}
// now for the linkage magic
for i in &mut st {
// i.1 = the position this needs to be updated at
// see above the issue with vecs with a length of usize
// TODO: only used once, put in directly
let np: usize = i.1.extract_int::<usize>();
// This is code I really really hate... thanks rust data safety
// Like, the reasoning for it completely makes sense. Data invalidation.
// Just still very annoying that this has to be done. I know for certain
// that I'm not risking anything, and that my code is safe. But the compiler
// isn't smart enough to know that. So either I work with unsafe ptrs,
// or I just do this. For now I choose this.
let mut symresv: Vec<(&T, u8)> = Vec::new();
// guaranteed to be Some(V), TODO optimize
for s in i.0.get_symbols().unwrap() {
if lt.contains_key(s.0) {
symresv.push((<[s.0], s.1));
} else {
// Rawbin spec is to panic if a symbol can't be resolved
// to avoid unintentionally unsafe code. (NOTE: error handle instead future)
// This isn't necessarily the case for formats which are outputting
// intermediate object representations. In the future, Rawbin
// (through values on its enum varient) TODO should accept an option to
// create a symbol resolution file, listing symbols and their positions.
// This also leads to the need to TODO override offsets.
lpanic(&format!("rawbin: unresolvable symbol: {}", s.0))
}
}
// now that the previous for is complete, the immutable reference is dropped
// we can now safely, per rust access rules, mutate
for z in symresv {
i.0.fulfill_symbol(z.0, z.1);
}
// all the symbols are now fulfilled, so use the helper to insert the instr in
crate::bbu::outs::vec_update(&i.0.get_output_bytes(), dest, np);
}
}*/
// todo drop
// TODO: featurize
// TODO: no-std
// TODO: make OptionLeaf a globally available concept
type VecOptTree<T> = ;
// TODO: move offsets into another part of BBU maybe? probably arch pages?
// TODO: const fn somehow