Skip to content

Commit 1f770cc

Browse files
committed
merge main
2 parents 89f7276 + a2e6ee3 commit 1f770cc

22 files changed

Lines changed: 1755 additions & 196 deletions

.gitignore

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

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

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
# binary-room
2+
3+
[![Tests](https://github.com/Samir-Rashid/binary-room/actions/workflows/cargo_test.yml/badge.svg)](https://github.com/Samir-Rashid/binary-room/actions/workflows/cargo_test.yml)
4+
25
Binary translator from RISC-V to ARM written in Rust
6+
7+
8+
## Testing
9+
10+
To get all the cross-compiling dependencies, enter the nix shell using `nix develop`.
11+
12+
`cargo test -- --nocapture`
13+
14+
Then run `./run.sh filename` to assemble and run the file.

flake.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# dual cross compile toolchain
2+
# https://github.com/noteed/riscv-hello-asm/blob/main/shell.nix
13
{
24
description = "binary-room";
35

@@ -35,6 +37,8 @@
3537
];
3638
packages = with pkgs; [
3739
rust-analyzer-nightly
40+
clang-tools
41+
hyperfine # benchmarking tool
3842
];
3943
};
4044
}

run.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
ASM_FILE=$1
4+
PLATFORM=""
5+
LD_FLAGS=""
6+
BENCHMARKING="false" # "true" to enable
7+
8+
if [[ -z "$ASM_FILE" ]]; then
9+
echo "Error: Assembly (.S) file is not passed in."
10+
echo "Usage: ./run.sh test_binary_translate_add.S"
11+
exit 1
12+
fi
13+
14+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
15+
PLATFORM="aarch64-linux-gnu"
16+
fi
17+
18+
if [[ "$OSTYPE" == "darwin"* ]]; then
19+
LD_FLAGS="-lSystem -macosx_version_min 11.3 -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
20+
fi
21+
22+
23+
"$PLATFORM"as "$ASM_FILE" -o "$ASM_FILE".as || { echo "Assembly compilation failed"; exit 1; }
24+
"$PLATFORM"ld "$ASM_FILE".as -o "$ASM_FILE".bin $LD_FLAGS || { echo "Linking failed"; exit 1; }
25+
26+
./"$ASM_FILE".bin
27+
echo "$?"
28+
29+
if [ "$BENCHMARKING" = true ]; then
30+
hyperfine -r 1000 -w 100 -Ni ./"$ASM_FILE".bin
31+
fi

0 commit comments

Comments
 (0)