✨
This commit is contained in:
@ -28,33 +28,46 @@ let rec copyConstPropFoldExp (vtable : VarTable)
|
||||
exists and if so, it should replace the current expression
|
||||
with the variable or constant to be propagated.
|
||||
*)
|
||||
failwith "Unimplemented copyConstPropFold for Var"
|
||||
let name' = SymTab.lookup name vtable
|
||||
match name' with
|
||||
| Some (ConstProp x) -> Constant (x, pos)
|
||||
| Some (VarProp x) -> Var (x, pos)
|
||||
| _ -> Var (name, pos)
|
||||
| Index (name, e, t, pos) ->
|
||||
(* TODO project task 3:
|
||||
Should probably do the same as the `Var` case, for
|
||||
the array name, and optimize the index expression `e` as well.
|
||||
*)
|
||||
failwith "Unimplemented copyConstPropFold for Index"
|
||||
let name' = SymTab.lookup name vtable
|
||||
let e' = copyConstPropFoldExp vtable e
|
||||
match name' with
|
||||
| Some (VarProp x) -> Index (x, e', t, pos)
|
||||
| _ -> Index (name, e', t, pos)
|
||||
|
||||
| Let (Dec (name, e, decpos), body, pos) ->
|
||||
let e' = copyConstPropFoldExp vtable e
|
||||
match e' with
|
||||
| Var (_, _) ->
|
||||
| Var (name', pos') ->
|
||||
(* TODO project task 3:
|
||||
Hint: I have discovered a variable-copy statement `let x = a`.
|
||||
I should probably record it in the `vtable` by
|
||||
associating `x` with a variable-propagatee binding,
|
||||
and optimize the `body` of the let.
|
||||
*)
|
||||
failwith "Unimplemented copyConstPropFold for Let with Var"
|
||||
| Constant (_, _) ->
|
||||
let vtable' = SymTab.bind name (VarProp name') vtable
|
||||
let body' = copyConstPropFoldExp vtable' body
|
||||
Let (Dec (name, e', decpos), body', pos)
|
||||
| Constant (constval, pos') ->
|
||||
(* TODO project task 3:
|
||||
Hint: I have discovered a constant-copy statement `let x = 5`.
|
||||
I should probably record it in the `vtable` by
|
||||
associating `x` with a constant-propagatee binding,
|
||||
and optimize the `body` of the let.
|
||||
*)
|
||||
failwith "Unimplemented copyConstPropFold for Let with Constant"
|
||||
| Let (_, _, _) ->
|
||||
let vtable' = SymTab.bind name (ConstProp constval) vtable
|
||||
let body' = copyConstPropFoldExp vtable' body
|
||||
Let (Dec (name, e', decpos), body', pos)
|
||||
| Let (Dec (name', e'', decpos'), body', pos') ->
|
||||
(* TODO project task 3:
|
||||
Hint: this has the structure
|
||||
`let y = (let x = e1 in e2) in e3`
|
||||
@ -66,23 +79,24 @@ let rec copyConstPropFoldExp (vtable : VarTable)
|
||||
restructured, semantically-equivalent expression:
|
||||
`let x = e1 in let y = e2 in e3`
|
||||
*)
|
||||
failwith "Unimplemented copyConstPropFold for Let with Let"
|
||||
let let' = Let (Dec (name, body', decpos), body, pos)
|
||||
copyConstPropFoldExp vtable (Let (Dec (name', e'', decpos'), let', pos'))
|
||||
| _ -> (* Fallthrough - for everything else, do nothing *)
|
||||
let body' = copyConstPropFoldExp vtable body
|
||||
Let (Dec (name, e', decpos), body', pos)
|
||||
|
||||
| Times (_, _, _) ->
|
||||
| Times (e1, e2, pos) ->
|
||||
(* TODO project task 3: implement as many safe algebraic
|
||||
simplifications as you can think of. You may inspire
|
||||
yourself from the case of `Plus`. For example:
|
||||
1 * x = ?
|
||||
x * 0 = ?
|
||||
*)
|
||||
failwith "Unimplemented copyConstPropFold for multiplication"
|
||||
Times (e1, e2, pos)
|
||||
| And (e1, e2, pos) ->
|
||||
(* TODO project task 3: see above. You may inspire yourself from
|
||||
`Or` below, but that only scratches the surface of what's possible *)
|
||||
failwith "Unimplemented copyConstPropFold for &&"
|
||||
And (e1, e2, pos)
|
||||
| Constant (x,pos) -> Constant (x,pos)
|
||||
| StringLit (x,pos) -> StringLit (x,pos)
|
||||
| ArrayLit (es, t, pos) ->
|
||||
|
20
bin/fasto2.sh
Executable file
20
bin/fasto2.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e # Die on first error.
|
||||
|
||||
base_dir="$(dirname "$0")"
|
||||
|
||||
# Determine location of executable. Does this work on all platforms?
|
||||
if ! [ "$FASTO" ]; then
|
||||
FASTO="$base_dir/../Fasto/bin/Debug/net6.0/Fasto.dll"
|
||||
if [[ $(uname -o 2> /dev/null) = "Cygwin" ]]; then
|
||||
FASTO="$(cygpath -w "FASTO")"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Verify that .NET is installed.
|
||||
dotnet --version &> /dev/null || (echo "Could not find dotnet" && exit 1)
|
||||
|
||||
dotnet $FASTO "$@"
|
||||
|
||||
|
127
bin/runtests2.sh
Executable file
127
bin/runtests2.sh
Executable file
@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Run all tests.
|
||||
#
|
||||
# Use -o to optimise the test programs before compiling them.
|
||||
# Use -i to interpret the test programs instead of compiling them.
|
||||
#
|
||||
# You can just run this script with no arguments. If you want to run
|
||||
# tests from a certain directory, specify that as the last argument.
|
||||
# For example, if you are in the root directory, and want to run the
|
||||
# tests in 'my_tests_dir` with optimisations enabled, you can run:
|
||||
#
|
||||
# $ ./bin/runtests.sh -o my_tests_dir
|
||||
#
|
||||
# Test programs (those ending with '.fo') are given their corresponding
|
||||
# '.in' files as standard in when running, and are expected to produce
|
||||
# the contents of the corresponding '.out' files, or the error of the
|
||||
# corresponding '.err' files. If no corresponding '.in' file exists,
|
||||
# the program is expected to fail at compile time.
|
||||
#
|
||||
# The Mars4_5.jar simulator must be in your Fasto "bin" directory, or
|
||||
# you must export its location into the environment variable named MARS,
|
||||
# unless you're using the '-i' option, in which case MARS is not used.
|
||||
#
|
||||
# If no argument is given, the script will run the tests in the current
|
||||
# directory; otherwise it will use the first argument as a directory,
|
||||
# and run the tests in that directory.
|
||||
#
|
||||
# Authors through the ages:
|
||||
# Troels Henriksen <athas@sigkill.dk>.
|
||||
# Rasmus Wriedt Larsen
|
||||
# Mathias Grymer <mathias1292@gmail.com>
|
||||
# Niels G. W. Serup <ngws@metanohi.name>
|
||||
|
||||
set -e # Die on first error.
|
||||
|
||||
base_dir="$(dirname "$0")"
|
||||
fasto="$base_dir/../bin/fasto.sh"
|
||||
mars="$base_dir/../bin/mars.sh"
|
||||
|
||||
# Find the directory containing the test programs.
|
||||
tests_dir="$1"
|
||||
if ! [ "$tests_dir" ]; then
|
||||
tests_dir="$base_dir/../tests"
|
||||
fi
|
||||
tests_dir="$(echo "$tests_dir" | sed 's/\/*$//')"
|
||||
|
||||
# Remove all whitespace and NUL bytes when comparing results, because
|
||||
# Mars and the interpreter puts different amounts -- and to handle
|
||||
# Windows/OSX/Unix line ending differences.
|
||||
fix_whitespace() {
|
||||
cat "$1" | tr -d '\000' | tr -d ' \t\n\r\f' 1>&1
|
||||
}
|
||||
|
||||
check_equal() {
|
||||
if [ -f $tests_dir/$OUTPUT ]; then
|
||||
|
||||
EXPECTED=$(fix_whitespace "$tests_dir/$OUTPUT")
|
||||
ACTUAL=$(fix_whitespace "$TESTOUT")
|
||||
if [ "$EXPECTED" = "$ACTUAL" ]; then
|
||||
rm -f $TESTOUT
|
||||
else
|
||||
echo "Output for $PROG does not match expected output."
|
||||
echo "Compare $TESTOUT and $tests_dir/$OUTPUT."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# make -C "$base_dir/.."
|
||||
|
||||
file_len=0
|
||||
for FO in $tests_dir/*fo; do
|
||||
L=$(basename "$FO")
|
||||
if ((${#L} > $file_len)); then
|
||||
file_len=${#L}
|
||||
fi
|
||||
done
|
||||
file_len=$(($file_len+4))
|
||||
|
||||
echo
|
||||
echo "=== Running Fasto test programs (compiled, with optimizations) ==="
|
||||
|
||||
echo
|
||||
for FO in $tests_dir/*fo; do
|
||||
FO=$(basename "$FO")
|
||||
PROG=$(echo $FO|sed 's/.fo$//')
|
||||
INPUT=$(echo $FO|sed 's/fo$/in/')
|
||||
OUTPUT=$(echo $FO|sed 's/fo$/out/')
|
||||
ERROUT=$(echo $FO|sed 's/fo$/err/')
|
||||
ASM=$(echo $FO|sed 's/fo$/asm/')
|
||||
TESTOUT=$tests_dir/$OUTPUT-testresult
|
||||
|
||||
if [ -f $tests_dir/$INPUT ]; then
|
||||
# Is positive test.
|
||||
echo -n "Testing"
|
||||
printf "%*s" $file_len " $FO: "
|
||||
flags='-o c'
|
||||
# Compile.
|
||||
if $fasto $flags $tests_dir/$PROG; then
|
||||
$mars $tests_dir/$ASM < $tests_dir/$INPUT > $TESTOUT 2>/dev/null
|
||||
if check_equal; then
|
||||
echo -e "\033[92mSuccess.\033[0m"
|
||||
else
|
||||
echo -e "\033[91mExecution error.\033[0m"
|
||||
fi
|
||||
else
|
||||
echo -e "\033[91mCompilation error.\033[0m"
|
||||
fi
|
||||
else
|
||||
# Is negative test.
|
||||
echo -n "Testing"
|
||||
printf "%*s" $file_len "$FO: "
|
||||
if $fasto -c $tests_dir/$PROG > $TESTOUT 2>&1; then
|
||||
echo -e "\033[91mCompiled but should result in compile error.\033[0m"
|
||||
elif [ -f $tests_dir/$ERROUT ]; then
|
||||
EXPECTED=$(fix_whitespace $tests_dir/$ERROUT)
|
||||
ACTUAL=$(fix_whitespace $TESTOUT)
|
||||
if [ "$EXPECTED" = "$ACTUAL" ]; then
|
||||
rm -f $TESTOUT
|
||||
echo -e "\033[92mSuccess.\033[0m"
|
||||
else
|
||||
echo -e "\033[91mThe error for $PROG does not match the expected error. Compare $TESTOUT and $tests_dir/$ERROUT.\033[0m"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
@ -1 +0,0 @@
|
||||
Parse error: Error at line 8, column 18
|
@ -22,9 +22,10 @@ main:
|
||||
sw $31, -4($29)
|
||||
sw $16, -8($29)
|
||||
addi $29, $29, -12
|
||||
ori $3, $0, 40
|
||||
ori $0, $0, 40
|
||||
# was: ori _letBind_2_, $0, 40
|
||||
# ori _size_reg_4_,_letBind_2_,0
|
||||
ori $3, $0, 40
|
||||
# was: ori _size_reg_4_, $0, 40
|
||||
bgez $3, _safe_lab_5_
|
||||
# was: bgez _size_reg_4_, _safe_lab_5_
|
||||
ori $5, $0, 3
|
||||
@ -43,63 +44,56 @@ _safe_lab_5_:
|
||||
# was: add $28, $28, _tmp_11_
|
||||
sw $3, 0($2)
|
||||
# was: sw _size_reg_4_, 0(_letBind_3_)
|
||||
addi $6, $2, 4
|
||||
addi $5, $2, 4
|
||||
# was: addi _addr_reg_6_, _letBind_3_, 4
|
||||
ori $4, $0, 0
|
||||
# was: ori _i_reg_7_, $0, 0
|
||||
_loop_beg_8_:
|
||||
sub $5, $4, $3
|
||||
sub $6, $4, $3
|
||||
# was: sub _tmp_reg_10_, _i_reg_7_, _size_reg_4_
|
||||
bgez $5, _loop_end_9_
|
||||
bgez $6, _loop_end_9_
|
||||
# was: bgez _tmp_reg_10_, _loop_end_9_
|
||||
sw $4, 0($6)
|
||||
sw $4, 0($5)
|
||||
# was: sw _i_reg_7_, 0(_addr_reg_6_)
|
||||
addi $6, $6, 4
|
||||
addi $5, $5, 4
|
||||
# was: addi _addr_reg_6_, _addr_reg_6_, 4
|
||||
addi $4, $4, 1
|
||||
# was: addi _i_reg_7_, _i_reg_7_, 1
|
||||
j _loop_beg_8_
|
||||
_loop_end_9_:
|
||||
ori $4, $3, 0
|
||||
# was: ori _divide_L_13_, _letBind_2_, 0
|
||||
ori $3, $0, 10
|
||||
# was: ori _divide_R_14_, $0, 10
|
||||
div $4, $4, $3
|
||||
# was: div _letBind_12_, _divide_L_13_, _divide_R_14_
|
||||
# ori _arr_ind_16_,_letBind_12_,0
|
||||
ori $0, $0, 4
|
||||
# was: ori _letBind_12_, $0, 4
|
||||
ori $4, $0, 4
|
||||
# was: ori _arr_ind_14_, $0, 4
|
||||
addi $3, $2, 4
|
||||
# was: addi _arr_reg_17_, _letBind_3_, 4
|
||||
# was: addi _arr_reg_15_, _letBind_3_, 4
|
||||
lw $2, 0($2)
|
||||
# was: lw _size_reg_18_, 0(_letBind_3_)
|
||||
bgez $4, _safe_lab_21_
|
||||
# was: bgez _arr_ind_16_, _safe_lab_21_
|
||||
_error_lab_20_:
|
||||
# was: lw _size_reg_16_, 0(_letBind_3_)
|
||||
bgez $4, _safe_lab_19_
|
||||
# was: bgez _arr_ind_14_, _safe_lab_19_
|
||||
_error_lab_18_:
|
||||
ori $5, $0, 5
|
||||
# was: ori $5, $0, 5
|
||||
la $6, _Msg_IllegalIndex_
|
||||
# was: la $6, _Msg_IllegalIndex_
|
||||
j _RuntimeError_
|
||||
_safe_lab_21_:
|
||||
_safe_lab_19_:
|
||||
sub $2, $4, $2
|
||||
# was: sub _tmp_reg_19_, _arr_ind_16_, _size_reg_18_
|
||||
bgez $2, _error_lab_20_
|
||||
# was: bgez _tmp_reg_19_, _error_lab_20_
|
||||
# was: sub _tmp_reg_17_, _arr_ind_14_, _size_reg_16_
|
||||
bgez $2, _error_lab_18_
|
||||
# was: bgez _tmp_reg_17_, _error_lab_18_
|
||||
sll $4, $4, 2
|
||||
# was: sll _arr_ind_16_, _arr_ind_16_, 2
|
||||
# was: sll _arr_ind_14_, _arr_ind_14_, 2
|
||||
add $3, $3, $4
|
||||
# was: add _arr_reg_17_, _arr_reg_17_, _arr_ind_16_
|
||||
lw $3, 0($3)
|
||||
# was: lw _letBind_15_, 0(_arr_reg_17_)
|
||||
# ori _times_L_25_,_letBind_15_,0
|
||||
ori $2, $0, 1
|
||||
# was: ori _times_R_26_, $0, 1
|
||||
mul $2, $3, $2
|
||||
# was: mul _plus_L_23_, _times_L_25_, _times_R_26_
|
||||
ori $3, $0, 0
|
||||
# was: ori _plus_R_24_, $0, 0
|
||||
add $16, $2, $3
|
||||
# was: add _tmp_22_, _plus_L_23_, _plus_R_24_
|
||||
# ori _mainres_1_,_tmp_22_,0
|
||||
# was: add _arr_reg_15_, _arr_reg_15_, _arr_ind_14_
|
||||
lw $2, 0($3)
|
||||
# was: lw _letBind_13_, 0(_arr_reg_15_)
|
||||
# ori _times_L_21_,_letBind_13_,0
|
||||
ori $3, $0, 1
|
||||
# was: ori _times_R_22_, $0, 1
|
||||
mul $16, $2, $3
|
||||
# was: mul _tmp_20_, _times_L_21_, _times_R_22_
|
||||
# ori _mainres_1_,_tmp_20_,0
|
||||
ori $2, $16, 0
|
||||
# was: ori $2, _mainres_1_, 0
|
||||
jal putint
|
||||
|
@ -153,55 +153,51 @@ boo:
|
||||
sw $16, -8($29)
|
||||
addi $29, $29, -28
|
||||
# ori _param_a_29_,$2,0
|
||||
ori $4, $0, 5
|
||||
# was: ori _plus_L_33_, $0, 5
|
||||
ori $3, $0, 3
|
||||
# was: ori _plus_R_34_, $0, 3
|
||||
add $0, $4, $3
|
||||
# was: add _letBind_32_, _plus_L_33_, _plus_R_34_
|
||||
# ori _arr_reg_36_,_param_a_29_,0
|
||||
ori $0, $0, 8
|
||||
# was: ori _letBind_31_, $0, 8
|
||||
# ori _arr_reg_34_,_param_a_29_,0
|
||||
lw $17, 0($2)
|
||||
# was: lw _size_reg_35_, 0(_arr_reg_36_)
|
||||
# was: lw _size_reg_33_, 0(_arr_reg_34_)
|
||||
ori $16, $28, 0
|
||||
# was: ori _letBind_31_, $28, 0
|
||||
# was: ori _letBind_32_, $28, 0
|
||||
sll $3, $17, 2
|
||||
# was: sll _tmp_45_, _size_reg_35_, 2
|
||||
# was: sll _tmp_43_, _size_reg_33_, 2
|
||||
addi $3, $3, 4
|
||||
# was: addi _tmp_45_, _tmp_45_, 4
|
||||
# was: addi _tmp_43_, _tmp_43_, 4
|
||||
add $28, $28, $3
|
||||
# was: add $28, $28, _tmp_45_
|
||||
# was: add $28, $28, _tmp_43_
|
||||
sw $17, 0($16)
|
||||
# was: sw _size_reg_35_, 0(_letBind_31_)
|
||||
# was: sw _size_reg_33_, 0(_letBind_32_)
|
||||
addi $18, $16, 4
|
||||
# was: addi _addr_reg_39_, _letBind_31_, 4
|
||||
# was: addi _addr_reg_37_, _letBind_32_, 4
|
||||
ori $19, $0, 0
|
||||
# was: ori _i_reg_40_, $0, 0
|
||||
# was: ori _i_reg_38_, $0, 0
|
||||
addi $20, $2, 4
|
||||
# was: addi _elem_reg_37_, _arr_reg_36_, 4
|
||||
_loop_beg_41_:
|
||||
# was: addi _elem_reg_35_, _arr_reg_34_, 4
|
||||
_loop_beg_39_:
|
||||
sub $2, $19, $17
|
||||
# was: sub _tmp_reg_43_, _i_reg_40_, _size_reg_35_
|
||||
bgez $2, _loop_end_42_
|
||||
# was: bgez _tmp_reg_43_, _loop_end_42_
|
||||
# was: sub _tmp_reg_41_, _i_reg_38_, _size_reg_33_
|
||||
bgez $2, _loop_end_40_
|
||||
# was: bgez _tmp_reg_41_, _loop_end_40_
|
||||
lw $2, 0($20)
|
||||
# was: lw _res_reg_38_, 0(_elem_reg_37_)
|
||||
# was: lw _res_reg_36_, 0(_elem_reg_35_)
|
||||
addi $20, $20, 4
|
||||
# was: addi _elem_reg_37_, _elem_reg_37_, 4
|
||||
# ori $2,_res_reg_38_,0
|
||||
# was: addi _elem_reg_35_, _elem_reg_35_, 4
|
||||
# ori $2,_res_reg_36_,0
|
||||
jal plus5
|
||||
# was: jal plus5, $2
|
||||
# ori _tmp_reg_44_,$2,0
|
||||
# ori _res_reg_38_,_tmp_reg_44_,0
|
||||
# ori _tmp_reg_42_,$2,0
|
||||
# ori _res_reg_36_,_tmp_reg_42_,0
|
||||
sw $2, 0($18)
|
||||
# was: sw _res_reg_38_, 0(_addr_reg_39_)
|
||||
# was: sw _res_reg_36_, 0(_addr_reg_37_)
|
||||
addi $18, $18, 4
|
||||
# was: addi _addr_reg_39_, _addr_reg_39_, 4
|
||||
# was: addi _addr_reg_37_, _addr_reg_37_, 4
|
||||
addi $19, $19, 1
|
||||
# was: addi _i_reg_40_, _i_reg_40_, 1
|
||||
j _loop_beg_41_
|
||||
_loop_end_42_:
|
||||
# was: addi _i_reg_38_, _i_reg_38_, 1
|
||||
j _loop_beg_39_
|
||||
_loop_end_40_:
|
||||
ori $2, $16, 0
|
||||
# was: ori _boores_30_, _letBind_31_, 0
|
||||
# was: ori _boores_30_, _letBind_32_, 0
|
||||
# ori $2,_boores_30_,0
|
||||
addi $29, $29, 28
|
||||
lw $20, -24($29)
|
||||
@ -222,110 +218,110 @@ main:
|
||||
addi $29, $29, -28
|
||||
jal getint
|
||||
# was: jal getint, $2
|
||||
ori $3, $2, 0
|
||||
# was: ori _letBind_47_, $2, 0
|
||||
# ori _size_reg_49_,_letBind_47_,0
|
||||
bgez $3, _safe_lab_50_
|
||||
# was: bgez _size_reg_49_, _safe_lab_50_
|
||||
ori $5, $2, 0
|
||||
# was: ori _letBind_45_, $2, 0
|
||||
# ori _size_reg_47_,_letBind_45_,0
|
||||
bgez $5, _safe_lab_48_
|
||||
# was: bgez _size_reg_47_, _safe_lab_48_
|
||||
ori $5, $0, 15
|
||||
# was: ori $5, $0, 15
|
||||
la $6, _Msg_IllegalArraySize_
|
||||
# was: la $6, _Msg_IllegalArraySize_
|
||||
j _RuntimeError_
|
||||
_safe_lab_50_:
|
||||
ori $2, $28, 0
|
||||
# was: ori _letBind_48_, $28, 0
|
||||
sll $4, $3, 2
|
||||
# was: sll _tmp_56_, _size_reg_49_, 2
|
||||
addi $4, $4, 4
|
||||
# was: addi _tmp_56_, _tmp_56_, 4
|
||||
add $28, $28, $4
|
||||
# was: add $28, $28, _tmp_56_
|
||||
sw $3, 0($2)
|
||||
# was: sw _size_reg_49_, 0(_letBind_48_)
|
||||
addi $5, $2, 4
|
||||
# was: addi _addr_reg_51_, _letBind_48_, 4
|
||||
ori $6, $0, 0
|
||||
# was: ori _i_reg_52_, $0, 0
|
||||
_loop_beg_53_:
|
||||
sub $4, $6, $3
|
||||
# was: sub _tmp_reg_55_, _i_reg_52_, _size_reg_49_
|
||||
bgez $4, _loop_end_54_
|
||||
# was: bgez _tmp_reg_55_, _loop_end_54_
|
||||
sw $6, 0($5)
|
||||
# was: sw _i_reg_52_, 0(_addr_reg_51_)
|
||||
addi $5, $5, 4
|
||||
# was: addi _addr_reg_51_, _addr_reg_51_, 4
|
||||
addi $6, $6, 1
|
||||
# was: addi _i_reg_52_, _i_reg_52_, 1
|
||||
j _loop_beg_53_
|
||||
_loop_end_54_:
|
||||
# ori _plus_L_59_,_letBind_47_,0
|
||||
ori $4, $3, 0
|
||||
# was: ori _plus_R_60_, _letBind_47_, 0
|
||||
add $0, $3, $4
|
||||
_safe_lab_48_:
|
||||
ori $3, $28, 0
|
||||
# was: ori _letBind_46_, $28, 0
|
||||
sll $2, $5, 2
|
||||
# was: sll _tmp_54_, _size_reg_47_, 2
|
||||
addi $2, $2, 4
|
||||
# was: addi _tmp_54_, _tmp_54_, 4
|
||||
add $28, $28, $2
|
||||
# was: add $28, $28, _tmp_54_
|
||||
sw $5, 0($3)
|
||||
# was: sw _size_reg_47_, 0(_letBind_46_)
|
||||
addi $3, $3, 4
|
||||
# was: addi _addr_reg_49_, _letBind_46_, 4
|
||||
ori $4, $0, 0
|
||||
# was: ori _i_reg_50_, $0, 0
|
||||
_loop_beg_51_:
|
||||
sub $2, $4, $5
|
||||
# was: sub _tmp_reg_53_, _i_reg_50_, _size_reg_47_
|
||||
bgez $2, _loop_end_52_
|
||||
# was: bgez _tmp_reg_53_, _loop_end_52_
|
||||
sw $4, 0($3)
|
||||
# was: sw _i_reg_50_, 0(_addr_reg_49_)
|
||||
addi $3, $3, 4
|
||||
# was: addi _addr_reg_49_, _addr_reg_49_, 4
|
||||
addi $4, $4, 1
|
||||
# was: addi _i_reg_50_, _i_reg_50_, 1
|
||||
j _loop_beg_51_
|
||||
_loop_end_52_:
|
||||
# ori _plus_L_56_,_letBind_45_,0
|
||||
ori $2, $5, 0
|
||||
# was: ori _plus_R_57_, _letBind_45_, 0
|
||||
add $2, $5, $2
|
||||
# was: add _letBind_55_, _plus_L_56_, _plus_R_57_
|
||||
# ori _plus_L_61_,_letBind_45_,0
|
||||
ori $3, $5, 0
|
||||
# was: ori _plus_R_62_, _letBind_45_, 0
|
||||
add $3, $5, $3
|
||||
# was: add _plus_L_59_, _plus_L_61_, _plus_R_62_
|
||||
# ori _plus_R_60_,_letBind_45_,0
|
||||
add $0, $3, $5
|
||||
# was: add _letBind_58_, _plus_L_59_, _plus_R_60_
|
||||
ori $4, $3, 0
|
||||
# was: ori _plus_L_63_, _letBind_47_, 0
|
||||
# ori _plus_R_64_,_letBind_47_,0
|
||||
add $4, $4, $3
|
||||
# was: add _plus_L_61_, _plus_L_63_, _plus_R_64_
|
||||
# ori _plus_R_62_,_letBind_47_,0
|
||||
add $0, $4, $3
|
||||
# was: add _letBind_57_, _plus_L_61_, _plus_R_62_
|
||||
# ori _arg_66_,_letBind_48_,0
|
||||
# ori $2,_arg_66_,0
|
||||
# ori _arg_64_,_letBind_55_,0
|
||||
# ori $2,_arg_64_,0
|
||||
jal boo
|
||||
# was: jal boo, $2
|
||||
# ori _letBind_65_,$2,0
|
||||
# ori _arr_reg_69_,_letBind_65_,0
|
||||
lw $16, 0($2)
|
||||
# was: lw _size_reg_68_, 0(_arr_reg_69_)
|
||||
ori $17, $28, 0
|
||||
# was: ori _letBind_67_, $28, 0
|
||||
sll $3, $16, 2
|
||||
# was: sll _tmp_78_, _size_reg_68_, 2
|
||||
# ori _letBind_63_,$2,0
|
||||
# ori _arr_reg_67_,_letBind_63_,0
|
||||
lw $17, 0($2)
|
||||
# was: lw _size_reg_66_, 0(_arr_reg_67_)
|
||||
ori $16, $28, 0
|
||||
# was: ori _letBind_65_, $28, 0
|
||||
sll $3, $17, 2
|
||||
# was: sll _tmp_76_, _size_reg_66_, 2
|
||||
addi $3, $3, 4
|
||||
# was: addi _tmp_78_, _tmp_78_, 4
|
||||
# was: addi _tmp_76_, _tmp_76_, 4
|
||||
add $28, $28, $3
|
||||
# was: add $28, $28, _tmp_78_
|
||||
sw $16, 0($17)
|
||||
# was: sw _size_reg_68_, 0(_letBind_67_)
|
||||
addi $18, $17, 4
|
||||
# was: addi _addr_reg_72_, _letBind_67_, 4
|
||||
# was: add $28, $28, _tmp_76_
|
||||
sw $17, 0($16)
|
||||
# was: sw _size_reg_66_, 0(_letBind_65_)
|
||||
addi $18, $16, 4
|
||||
# was: addi _addr_reg_70_, _letBind_65_, 4
|
||||
ori $19, $0, 0
|
||||
# was: ori _i_reg_73_, $0, 0
|
||||
# was: ori _i_reg_71_, $0, 0
|
||||
addi $20, $2, 4
|
||||
# was: addi _elem_reg_70_, _arr_reg_69_, 4
|
||||
_loop_beg_74_:
|
||||
sub $2, $19, $16
|
||||
# was: sub _tmp_reg_76_, _i_reg_73_, _size_reg_68_
|
||||
bgez $2, _loop_end_75_
|
||||
# was: bgez _tmp_reg_76_, _loop_end_75_
|
||||
# was: addi _elem_reg_68_, _arr_reg_67_, 4
|
||||
_loop_beg_72_:
|
||||
sub $2, $19, $17
|
||||
# was: sub _tmp_reg_74_, _i_reg_71_, _size_reg_66_
|
||||
bgez $2, _loop_end_73_
|
||||
# was: bgez _tmp_reg_74_, _loop_end_73_
|
||||
lw $2, 0($20)
|
||||
# was: lw _res_reg_71_, 0(_elem_reg_70_)
|
||||
# was: lw _res_reg_69_, 0(_elem_reg_68_)
|
||||
addi $20, $20, 4
|
||||
# was: addi _elem_reg_70_, _elem_reg_70_, 4
|
||||
# ori $2,_res_reg_71_,0
|
||||
# was: addi _elem_reg_68_, _elem_reg_68_, 4
|
||||
# ori $2,_res_reg_69_,0
|
||||
jal mul2
|
||||
# was: jal mul2, $2
|
||||
# ori _tmp_reg_77_,$2,0
|
||||
# ori _res_reg_71_,_tmp_reg_77_,0
|
||||
# ori _tmp_reg_75_,$2,0
|
||||
# ori _res_reg_69_,_tmp_reg_75_,0
|
||||
sw $2, 0($18)
|
||||
# was: sw _res_reg_71_, 0(_addr_reg_72_)
|
||||
# was: sw _res_reg_69_, 0(_addr_reg_70_)
|
||||
addi $18, $18, 4
|
||||
# was: addi _addr_reg_72_, _addr_reg_72_, 4
|
||||
# was: addi _addr_reg_70_, _addr_reg_70_, 4
|
||||
addi $19, $19, 1
|
||||
# was: addi _i_reg_73_, _i_reg_73_, 1
|
||||
j _loop_beg_74_
|
||||
_loop_end_75_:
|
||||
ori $2, $17, 0
|
||||
# was: ori _arg_79_, _letBind_67_, 0
|
||||
# ori $2,_arg_79_,0
|
||||
# was: addi _i_reg_71_, _i_reg_71_, 1
|
||||
j _loop_beg_72_
|
||||
_loop_end_73_:
|
||||
ori $2, $16, 0
|
||||
# was: ori _arg_77_, _letBind_65_, 0
|
||||
# ori $2,_arg_77_,0
|
||||
jal write_int_arr
|
||||
# was: jal write_int_arr, $2
|
||||
# ori _mainres_46_,$2,0
|
||||
# ori $2,_mainres_46_,0
|
||||
# ori _mainres_44_,$2,0
|
||||
# ori $2,_mainres_44_,0
|
||||
addi $29, $29, 28
|
||||
lw $20, -24($29)
|
||||
lw $19, -20($29)
|
||||
|
142
tests/negate.asm
142
tests/negate.asm
@ -63,119 +63,51 @@ main:
|
||||
sw $17, -12($29)
|
||||
sw $16, -8($29)
|
||||
addi $29, $29, -24
|
||||
ori $3, $0, 3
|
||||
# was: ori _divide_L_14_, $0, 3
|
||||
ori $2, $0, 2
|
||||
# was: ori _divide_R_15_, $0, 2
|
||||
div $3, $3, $2
|
||||
# was: div _eq_L_12_, _divide_L_14_, _divide_R_15_
|
||||
ori $2, $0, 1
|
||||
# was: ori _eq_R_13_, $0, 1
|
||||
ori $4, $0, 0
|
||||
# was: ori _arg_11_, $0, 0
|
||||
bne $3, $2, _false_16_
|
||||
# was: bne _eq_L_12_, _eq_R_13_, _false_16_
|
||||
ori $4, $0, 1
|
||||
# was: ori _arg_11_, $0, 1
|
||||
_false_16_:
|
||||
ori $2, $4, 0
|
||||
# was: ori $2, _arg_11_, 0
|
||||
jal write_nl
|
||||
# was: jal write_nl, $2
|
||||
ori $16, $2, 0
|
||||
# was: ori _letBind_10_, $2, 0
|
||||
ori $2, $0, 3
|
||||
# was: ori _negate_R_23_, $0, 3
|
||||
sub $3, $0, $2
|
||||
# was: sub _divide_L_21_, $0, _negate_R_23_
|
||||
ori $2, $0, 2
|
||||
# was: ori _divide_R_22_, $0, 2
|
||||
div $3, $3, $2
|
||||
# was: div _eq_L_19_, _divide_L_21_, _divide_R_22_
|
||||
ori $2, $0, 2
|
||||
# was: ori _negate_R_24_, $0, 2
|
||||
sub $2, $0, $2
|
||||
# was: sub _eq_R_20_, $0, _negate_R_24_
|
||||
ori $4, $0, 0
|
||||
# was: ori _arg_18_, $0, 0
|
||||
bne $3, $2, _false_25_
|
||||
# was: bne _eq_L_19_, _eq_R_20_, _false_25_
|
||||
ori $4, $0, 1
|
||||
# was: ori _arg_18_, $0, 1
|
||||
_false_25_:
|
||||
ori $2, $4, 0
|
||||
# was: ori $2, _arg_18_, 0
|
||||
jal write_nl
|
||||
# was: jal write_nl, $2
|
||||
ori $17, $2, 0
|
||||
# was: ori _letBind_17_, $2, 0
|
||||
ori $2, $0, 3
|
||||
# was: ori _divide_L_30_, $0, 3
|
||||
ori $3, $0, 2
|
||||
# was: ori _negate_R_32_, $0, 2
|
||||
sub $3, $0, $3
|
||||
# was: sub _divide_R_31_, $0, _negate_R_32_
|
||||
div $3, $2, $3
|
||||
# was: div _eq_L_28_, _divide_L_30_, _divide_R_31_
|
||||
ori $2, $0, 2
|
||||
# was: ori _negate_R_33_, $0, 2
|
||||
sub $2, $0, $2
|
||||
# was: sub _eq_R_29_, $0, _negate_R_33_
|
||||
ori $4, $0, 0
|
||||
# was: ori _arg_27_, $0, 0
|
||||
bne $3, $2, _false_34_
|
||||
# was: bne _eq_L_28_, _eq_R_29_, _false_34_
|
||||
ori $4, $0, 1
|
||||
# was: ori _arg_27_, $0, 1
|
||||
_false_34_:
|
||||
ori $2, $4, 0
|
||||
# was: ori $2, _arg_27_, 0
|
||||
# ori $2,_arg_11_,0
|
||||
jal write_nl
|
||||
# was: jal write_nl, $2
|
||||
ori $18, $2, 0
|
||||
# was: ori _letBind_26_, $2, 0
|
||||
ori $2, $0, 3
|
||||
# was: ori _negate_R_41_, $0, 3
|
||||
sub $2, $0, $2
|
||||
# was: sub _divide_L_39_, $0, _negate_R_41_
|
||||
ori $3, $0, 2
|
||||
# was: ori _negate_R_42_, $0, 2
|
||||
sub $3, $0, $3
|
||||
# was: sub _divide_R_40_, $0, _negate_R_42_
|
||||
div $3, $2, $3
|
||||
# was: div _eq_L_37_, _divide_L_39_, _divide_R_40_
|
||||
ori $2, $0, 1
|
||||
# was: ori _eq_R_38_, $0, 1
|
||||
ori $4, $0, 0
|
||||
# was: ori _arg_36_, $0, 0
|
||||
bne $3, $2, _false_43_
|
||||
# was: bne _eq_L_37_, _eq_R_38_, _false_43_
|
||||
ori $4, $0, 1
|
||||
# was: ori _arg_36_, $0, 1
|
||||
_false_43_:
|
||||
ori $2, $4, 0
|
||||
# was: ori $2, _arg_36_, 0
|
||||
# was: ori _letBind_10_, $2, 0
|
||||
ori $2, $0, 0
|
||||
# was: ori _arg_13_, $0, 0
|
||||
# ori $2,_arg_13_,0
|
||||
jal write_nl
|
||||
# was: jal write_nl, $2
|
||||
# ori _letBind_35_,$2,0
|
||||
# ori _arg_44_,_letBind_10_,0
|
||||
beq $16, $19, _false_47_
|
||||
# was: beq _arg_44_, 0, _false_47_
|
||||
ori $16, $17, 0
|
||||
# was: ori _arg_44_, _letBind_17_, 0
|
||||
_false_47_:
|
||||
beq $16, $19, _false_46_
|
||||
# was: beq _arg_44_, 0, _false_46_
|
||||
ori $16, $18, 0
|
||||
# was: ori _arg_44_, _letBind_26_, 0
|
||||
_false_46_:
|
||||
beq $16, $19, _false_45_
|
||||
# was: beq _arg_44_, 0, _false_45_
|
||||
ori $16, $2, 0
|
||||
# was: ori _arg_44_, _letBind_35_, 0
|
||||
_false_45_:
|
||||
ori $2, $16, 0
|
||||
# was: ori $2, _arg_44_, 0
|
||||
# was: ori _letBind_12_, $2, 0
|
||||
ori $2, $0, 0
|
||||
# was: ori _arg_15_, $0, 0
|
||||
# ori $2,_arg_15_,0
|
||||
jal write_nl
|
||||
# was: jal write_nl, $2
|
||||
ori $17, $2, 0
|
||||
# was: ori _letBind_14_, $2, 0
|
||||
ori $2, $0, 1
|
||||
# was: ori _arg_17_, $0, 1
|
||||
# ori $2,_arg_17_,0
|
||||
jal write_nl
|
||||
# was: jal write_nl, $2
|
||||
# ori _letBind_16_,$2,0
|
||||
# ori _arg_18_,_letBind_10_,0
|
||||
beq $18, $19, _false_21_
|
||||
# was: beq _arg_18_, 0, _false_21_
|
||||
ori $18, $16, 0
|
||||
# was: ori _arg_18_, _letBind_12_, 0
|
||||
_false_21_:
|
||||
beq $18, $19, _false_20_
|
||||
# was: beq _arg_18_, 0, _false_20_
|
||||
ori $18, $17, 0
|
||||
# was: ori _arg_18_, _letBind_14_, 0
|
||||
_false_20_:
|
||||
beq $18, $19, _false_19_
|
||||
# was: beq _arg_18_, 0, _false_19_
|
||||
ori $18, $2, 0
|
||||
# was: ori _arg_18_, _letBind_16_, 0
|
||||
_false_19_:
|
||||
ori $2, $18, 0
|
||||
# was: ori $2, _arg_18_, 0
|
||||
jal write_nl
|
||||
# was: jal write_nl, $2
|
||||
# ori _mainres_9_,$2,0
|
||||
|
Reference in New Issue
Block a user