ReASM
Wiki
A RISC-V IMFD + Zbb/Zbs compatible assembler/disassembler to Luau.
175+ supported instructions & directives!
[!NOTE]
Some programs, will not work! Create an issue if you find an assembly file which is compiling invalid.
Example:
void printf(const char *, ...); /* manually define printf if we are not using stdlib.h */
int fib(int n) {
if (n <= 1)
return n;
return fib(n-1) + fib(n-2);
}
int main() {
for (int i = 0; i < 10; i++){
printf("%d ", fib(i));
}
return 0;
}
clang -S -target riscv32 -march=rv32im main.c -o main.s
reasm main.s -o main.luau # where the magic happens
luau main.luau
Usage:
reasm main.S -o main.luau --mode {module|main|bench} --trace --comments --accurate
Input file can either be a .S assembly file, or a .elf file which is linked (experimental).
Options
--comments: This will place comments all around the generated code with details such as the instruction's purpose, operands, and any relevant debug information.
--trace: Everytime a jump happens it will log to output, this is a more extreme option and should only be used for debug.
--accurate: Enables more accurate ISA modeling. This turns on 32-bit overflow wrapping and float32 instruction rounding behavior. Much slower, but gives more accurate mathematics.
--memory: Sets generated RAM buffer size in bytes (default: 524288000 / 500MB).
--mode:
module will automatically expose memory, API to inject functions, and registers to whoever imports.
main will generate a simple Luau file which runs on its own.
bench will generate a module prepared for benchmarking with Scriptbench or Benchmarker.
Resources:
Super helpful resources in development below:
TODO:
- Vector extension
- Work on support for ELF files. (or decide to remove it)