Skip to content

Commit

Permalink
Update small-main.cpp to make test correct
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoujingya committed Sep 20, 2024
1 parent 3a463d0 commit ba91f81
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
28 changes: 22 additions & 6 deletions src/smallcc/smallcc-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,27 @@ std::string getInputFile(llvm::StringRef filename) {

int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv, "smallcc compiler\n");

outs() << " .globl main\n";
outs() << "main:\n";
printf(" li a0, %d\n", atoi(inputParsedString.c_str()));
printf(" ret\n");

outs() << ".globl main\n";
std::string main= "main:\n"
" addi sp, sp, -16\n "
" sw ra, 12(sp)\n"
" sw s0, 8(sp)\n"
" addi s0, sp, 16\n"
" li a0, 0\n"
" sw a0, -16(s0)\n"
" sw a0, -12(s0)\n"
" lui a0, %hi(.LC0)\n"
" addi a0, a0, %lo(.LC0)\n"
" call printf\n"
" lw a0, -16(s0)\n"
" lw ra, 12(sp)\n"
" lw s0, 8(sp)\n"
" addi sp, sp, 16\n"
" ret\n";
outs() << main;
outs() << ".section .rodata \n";
outs() << ".align 3\n";
printf("%s", ".LC0:\n");
printf(" .string \"%d\"\n", atoi(inputParsedString.c_str()));
// TODO: add
}
14 changes: 8 additions & 6 deletions test/smallcc/input.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// RUN: smallcc -input-string="12" >& /tmp/test.s |
// RUN: /tmp/test.s FileCheck %s
//smallcc -input-string="123" > /tmp/test.s
// riscv64-unknown-linux-gnu-gcc /tmp/test.s -static -o /tmp/a.out
// qemu-riscv64 /tmp/a.out
// echo $? > /tmp/test.log >& /dev/null || true
// RUN: smallcc -input-string="123" > /tmp/test.s
// RUN: riscv64-unknown-linux-gnu-gcc /tmp/test.s -static -o /tmp/a.out
// RUN: qemu-riscv64 /tmp/a.out | FileCheck %s

// CHECK: .globl main
// CHECK-NEXT: main:
// CHECK-NEXT: li a0, 12
// CHECK-NEXT: ret
// CHECK: 123

0 comments on commit ba91f81

Please sign in to comment.