-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.rs
More file actions
53 lines (43 loc) · 911 Bytes
/
utils.rs
File metadata and controls
53 lines (43 loc) · 911 Bytes
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
use std::fs;
use crate::{instruction::RiscVInstruction, translate::translate_instrs};
pub const START: &str = r#"
.text
.global _start
.global _main
.balign 4
_start:
bl main
mov x8, #93
svc #0
.balign 4
_main:
main:
"#;
pub const START_NO_MAIN: &str = r#"
.text
.global _start
.global _main
.balign 4
_start:
bl main
mov x8, #93
svc #0
"#;
/// Assembler directives for main only, used when another
/// function defined before main
pub const START_MAIN: &str = r#"
.balign 4
_main:
main:
"#;
pub fn translate_to_file(instrs: Vec<RiscVInstruction>, path: String) {
let arm_instrs = translate_instrs(instrs);
let mut contents = String::new();
for instr in arm_instrs {
let x: String = instr.into();
contents.push_str(&x);
contents.push_str("\n");
}
fs::write(&path, contents).expect("Unable to write file");
println!("Saved ARM assembly to {}", path);
}