Skip to content

Commit

Permalink
Refactor OpCode
Browse files Browse the repository at this point in the history
  • Loading branch information
AzimMuradov committed Oct 4, 2024
1 parent ed921cc commit 6535501
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 101 deletions.
4 changes: 2 additions & 2 deletions lib/CodeGen/RiscV/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ mainFunction body = do

let ret =
[ instructionCodeLine Li [Register A0, Immediate 0],
instructionCodeLine Jal [Symbol "exit"]
instructionCodeLine Call [Symbol "exit"]
]

let funCode = [globalDir, funLabel, spPush] ++ (concat . reverse $ ([loadRetVal, spPop] ++ ret) : cls)
Expand Down Expand Up @@ -193,7 +193,7 @@ call fun args = do
pushFunctionCodeLines $
loadArguments
++ [ instructionCodeLine Sd [Register Ra, raMem],
instructionCodeLine Jal [fun],
instructionCodeLine Call [fun],
instructionCodeLine Ld [Register Ra, raMem],
instructionCodeLine Sd [retVal, retValMem]
]
Expand Down
17 changes: 8 additions & 9 deletions lib/CodeGen/RiscV/Lib/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,24 @@ instance Pretty Directive where
pretty (DirGlobl name) = pretty ".globl" <+> pretty name

data OpCode
= Add
= And
| Or
| Add
| Sub
| Mul
| And
| Or
| Not
| Neg
| Seqz
| Snez
| Slt
| Ld
| Sd
| Addi
| Ld
| Li
| La
| Neg
| Ret
| Jal
| Addi
| Beqz
| J
| Call
| Ret
deriving (Show)

instance Pretty OpCode where
Expand Down
14 changes: 7 additions & 7 deletions test/Sample/Factorial/FacRec.s
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ else_0:
la a0, factorial_1
ld a1, 64(sp)
sd ra, 80(sp)
jal miniml_fun_to_paf
call miniml_fun_to_paf
ld ra, 80(sp)
sd a0, 72(sp)
ld a0, 72(sp)
ld a1, 56(sp)
sd ra, 96(sp)
jal miniml_apply
call miniml_apply
ld ra, 96(sp)
sd a0, 88(sp)
ld t0, 8(sp)
Expand All @@ -57,29 +57,29 @@ _start:
la a0, factorial_1
ld a1, 8(sp)
sd ra, 24(sp)
jal miniml_fun_to_paf
call miniml_fun_to_paf
ld ra, 24(sp)
sd a0, 16(sp)
li t0, 5
sd t0, 32(sp)
ld a0, 16(sp)
ld a1, 32(sp)
sd ra, 48(sp)
jal miniml_apply
call miniml_apply
ld ra, 48(sp)
sd a0, 40(sp)
li t0, 1
sd t0, 56(sp)
la a0, print_int
ld a1, 56(sp)
sd ra, 72(sp)
jal miniml_fun_to_paf
call miniml_fun_to_paf
ld ra, 72(sp)
sd a0, 64(sp)
ld a0, 64(sp)
ld a1, 40(sp)
sd ra, 88(sp)
jal miniml_apply
call miniml_apply
ld ra, 88(sp)
sd a0, 80(sp)
la t0, simp_3
Expand All @@ -88,4 +88,4 @@ _start:
li a0, 0
addi sp, sp, 88
li a0, 0
jal exit
call exit
34 changes: 17 additions & 17 deletions test/Sample/Factorial/FacRecCps.s
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ll_10:
ld a0, 16(sp)
ld a1, 32(sp)
sd ra, 48(sp)
jal miniml_apply
call miniml_apply
ld ra, 48(sp)
sd a0, 40(sp)
ld a0, 40(sp)
Expand All @@ -43,7 +43,7 @@ cps_factorial_3:
ld a0, 16(sp)
ld a1, 48(sp)
sd ra, 64(sp)
jal miniml_apply
call miniml_apply
ld ra, 64(sp)
sd a0, 56(sp)
ld t0, 56(sp)
Expand All @@ -61,39 +61,39 @@ else_0:
la a0, cps_factorial_3
ld a1, 88(sp)
sd ra, 104(sp)
jal miniml_fun_to_paf
call miniml_fun_to_paf
ld ra, 104(sp)
sd a0, 96(sp)
ld a0, 96(sp)
ld a1, 80(sp)
sd ra, 120(sp)
jal miniml_apply
call miniml_apply
ld ra, 120(sp)
sd a0, 112(sp)
li t0, 3
sd t0, 128(sp)
la a0, ll_10
ld a1, 128(sp)
sd ra, 144(sp)
jal miniml_fun_to_paf
call miniml_fun_to_paf
ld ra, 144(sp)
sd a0, 136(sp)
ld a0, 136(sp)
ld a1, 8(sp)
sd ra, 160(sp)
jal miniml_apply
call miniml_apply
ld ra, 160(sp)
sd a0, 152(sp)
ld a0, 152(sp)
ld a1, 16(sp)
sd ra, 176(sp)
jal miniml_apply
call miniml_apply
ld ra, 176(sp)
sd a0, 168(sp)
ld a0, 112(sp)
ld a1, 168(sp)
sd ra, 192(sp)
jal miniml_apply
call miniml_apply
ld ra, 192(sp)
sd a0, 184(sp)
ld t0, 184(sp)
Expand All @@ -110,27 +110,27 @@ factorial_8:
la a0, cps_factorial_3
ld a1, 16(sp)
sd ra, 32(sp)
jal miniml_fun_to_paf
call miniml_fun_to_paf
ld ra, 32(sp)
sd a0, 24(sp)
ld a0, 24(sp)
ld a1, 8(sp)
sd ra, 48(sp)
jal miniml_apply
call miniml_apply
ld ra, 48(sp)
sd a0, 40(sp)
li t0, 1
sd t0, 56(sp)
la a0, id_2
ld a1, 56(sp)
sd ra, 72(sp)
jal miniml_fun_to_paf
call miniml_fun_to_paf
ld ra, 72(sp)
sd a0, 64(sp)
ld a0, 40(sp)
ld a1, 64(sp)
sd ra, 88(sp)
jal miniml_apply
call miniml_apply
ld ra, 88(sp)
sd a0, 80(sp)
ld a0, 80(sp)
Expand All @@ -144,29 +144,29 @@ _start:
la a0, factorial_8
ld a1, 8(sp)
sd ra, 24(sp)
jal miniml_fun_to_paf
call miniml_fun_to_paf
ld ra, 24(sp)
sd a0, 16(sp)
li t0, 5
sd t0, 32(sp)
ld a0, 16(sp)
ld a1, 32(sp)
sd ra, 48(sp)
jal miniml_apply
call miniml_apply
ld ra, 48(sp)
sd a0, 40(sp)
li t0, 1
sd t0, 56(sp)
la a0, print_int
ld a1, 56(sp)
sd ra, 72(sp)
jal miniml_fun_to_paf
call miniml_fun_to_paf
ld ra, 72(sp)
sd a0, 64(sp)
ld a0, 64(sp)
ld a1, 40(sp)
sd ra, 88(sp)
jal miniml_apply
call miniml_apply
ld ra, 88(sp)
sd a0, 80(sp)
la t0, simp_9
Expand All @@ -175,4 +175,4 @@ _start:
li a0, 0
addi sp, sp, 88
li a0, 0
jal exit
call exit
26 changes: 13 additions & 13 deletions test/Sample/Factorial/FacRecLoop.s
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ else_0:
la a0, loop_2
ld a1, 48(sp)
sd ra, 64(sp)
jal miniml_fun_to_paf
call miniml_fun_to_paf
ld ra, 64(sp)
sd a0, 56(sp)
ld a0, 56(sp)
ld a1, 8(sp)
sd ra, 80(sp)
jal miniml_apply
call miniml_apply
ld ra, 80(sp)
sd a0, 72(sp)
li t0, 1
Expand All @@ -39,7 +39,7 @@ else_0:
ld a0, 72(sp)
ld a1, 96(sp)
sd ra, 112(sp)
jal miniml_apply
call miniml_apply
ld ra, 112(sp)
sd a0, 104(sp)
ld t0, 24(sp)
Expand All @@ -49,7 +49,7 @@ else_0:
ld a0, 104(sp)
ld a1, 120(sp)
sd ra, 136(sp)
jal miniml_apply
call miniml_apply
ld ra, 136(sp)
sd a0, 128(sp)
ld t0, 128(sp)
Expand All @@ -66,29 +66,29 @@ factorial_5:
la a0, loop_2
ld a1, 16(sp)
sd ra, 32(sp)
jal miniml_fun_to_paf
call miniml_fun_to_paf
ld ra, 32(sp)
sd a0, 24(sp)
ld a0, 24(sp)
ld a1, 8(sp)
sd ra, 48(sp)
jal miniml_apply
call miniml_apply
ld ra, 48(sp)
sd a0, 40(sp)
li t0, 1
sd t0, 56(sp)
ld a0, 40(sp)
ld a1, 56(sp)
sd ra, 72(sp)
jal miniml_apply
call miniml_apply
ld ra, 72(sp)
sd a0, 64(sp)
li t0, 1
sd t0, 80(sp)
ld a0, 64(sp)
ld a1, 80(sp)
sd ra, 96(sp)
jal miniml_apply
call miniml_apply
ld ra, 96(sp)
sd a0, 88(sp)
ld a0, 88(sp)
Expand All @@ -102,29 +102,29 @@ _start:
la a0, factorial_5
ld a1, 8(sp)
sd ra, 24(sp)
jal miniml_fun_to_paf
call miniml_fun_to_paf
ld ra, 24(sp)
sd a0, 16(sp)
li t0, 5
sd t0, 32(sp)
ld a0, 16(sp)
ld a1, 32(sp)
sd ra, 48(sp)
jal miniml_apply
call miniml_apply
ld ra, 48(sp)
sd a0, 40(sp)
li t0, 1
sd t0, 56(sp)
la a0, print_int
ld a1, 56(sp)
sd ra, 72(sp)
jal miniml_fun_to_paf
call miniml_fun_to_paf
ld ra, 72(sp)
sd a0, 64(sp)
ld a0, 64(sp)
ld a1, 40(sp)
sd ra, 88(sp)
jal miniml_apply
call miniml_apply
ld ra, 88(sp)
sd a0, 80(sp)
la t0, simp_6
Expand All @@ -133,4 +133,4 @@ _start:
li a0, 0
addi sp, sp, 88
li a0, 0
jal exit
call exit
Loading

0 comments on commit 6535501

Please sign in to comment.