Skip to content

Commit 44b6a69

Browse files
committed
have assembly output now
1 parent aaeb3c8 commit 44b6a69

9 files changed

Lines changed: 300 additions & 241 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ Cargo.lock
2626

2727
# temporary files
2828
*.bin
29+
30+
.vscode/

src/instruction.rs

Lines changed: 238 additions & 216 deletions
Large diffs are not rendered by default.

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod instruction;
22
pub mod translate;
3+
pub mod utils;

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::fs;
22
use std::str::FromStr;
33
pub mod instruction;
44
pub mod translate;
5+
pub mod utils;
56
use instruction::RiscVInstruction;
67
use translate::binary_translate;
78

src/utils.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use std::fs;
2+
3+
use crate::{instruction::RiscVInstruction, translate::translate_instrs};
4+
5+
6+
pub fn translate_to_file(instrs: Vec<RiscVInstruction>, path: String) {
7+
let arm_instrs = translate_instrs(instrs);
8+
let mut contents = String::new();
9+
for instr in arm_instrs {
10+
let x: String = instr.into();
11+
contents.push_str(&x);
12+
contents.push_str("\n");
13+
}
14+
fs::write(path, contents).expect("Unable to write file");
15+
}

test_binary_translate_add.S

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
sub sp, sp, -32
2+
str lr, [sp, 24]
3+
str x5, [sp, 16]
4+
add w5, sp, 32
5+
add x12, xzr, 3
6+
str w12, [w5, -20]
7+
add x12, xzr, 4
8+
str w12, [w5, -24]
9+
ldr w12, [w5, -20]
10+
add x11, x12, 0
11+
ldr w12, [w5, -24]
12+
add w12, w11, w12
13+
sxtw x12, w12
14+
add x7, x12, 0
15+
ldr lr, [sp, 24]
16+
ldr x5, [sp, 16]
17+
add sp, sp, 32
18+
blr lr

tests/binaries/flake.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/binaries/flake.nix

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22
description = "A very basic flake";
33

44
inputs = {
5-
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
5+
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
66
};
77

88

9-
outputs = { self, nixpkgs }: let
10-
pkgs = import nixpkgs {
11-
# inherit system;
12-
system = "x86_64-linux";
13-
crossSystem.config = "riscv64-linux-gnu";
14-
};
15-
in {
16-
devShells.x86_64-linux.default = pkgs.mkShell {
17-
# Use the same mkShell as documented above
9+
outputs = { self, nixpkgs }:
10+
let
11+
pkgs = import nixpkgs {
12+
# inherit system;
13+
system = "x86_64-linux";
14+
crossSystem.config = "aarch64-linux-gnu";
15+
};
16+
in
17+
{
18+
devShells.x86_64-linux.default = pkgs.mkShell {
19+
# Use the same mkShell as documented above
1820
packages = with pkgs; [
19-
gcc
20-
# pkgs.clang-tools
21-
];
21+
gcc
22+
# pkgs.clang-tools
23+
];
24+
};
2225
};
23-
};
2426
}

tests/test_translation.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
mod tests {
33
use binary_room::instruction::*;
44
use binary_room::translate::*;
5+
use binary_room::utils;
6+
use binary_room::utils::translate_to_file;
57

68
#[test]
79
fn test_binary_translate() {
@@ -116,12 +118,8 @@ mod tests {
116118
},
117119
];
118120

119-
let arm_instrs = translate_instrs(riscv_asm);
120-
println!("{:?}", arm_instrs);
121-
// assert_eq!(translated_asm, expected_output);
122-
for instr in arm_instrs {
123-
let x: String = instr.into();
124-
println!("{}", x);
125-
}
121+
translate_to_file(riscv_asm, "test_binary_translate_add.S".to_string());
122+
123+
126124
}
127125
}

0 commit comments

Comments
 (0)