fix: plus que 3 code tests faux

This commit is contained in:
Guillotin Damien 2021-12-10 11:38:19 +01:00
parent 0c5225da77
commit 8d1cf1a683
4 changed files with 30 additions and 25 deletions

View file

@ -1,4 +1,4 @@
; fichiersRat/src-rat-tam-test/testfun2.rat ; fichiersRat/src-rat-tam-test/testfun5.rat
JUMP main JUMP main
pgcd pgcd
@ -70,16 +70,15 @@ SUBR IMul
CALL (ST) norm CALL (ST) norm
RETURN (2) 4 RETURN (2) 4
f f1
LOAD (1) -1[LB] LOAD (1) -1[LB]
POP (1) 1 POP (1) 1
RETURN (1) 1 RETURN (0) 1
main main
LOADL 3 LOADL 13
LOADL 4 CALL (ST) f1
SUBR IAdd LOAD (1) 0[SB]
CALL (ST) f
SUBR IOut SUBR IOut
HALT HALT

View file

@ -1,3 +1,4 @@
; fichiersRat/test.rat
JUMP main JUMP main
pgcd pgcd
@ -80,7 +81,7 @@ LOAD (1) -1[LB]
LOAD (1) 3[LB] LOAD (1) 3[LB]
SUBR IAdd SUBR IAdd
SUBR IAdd SUBR IAdd
POP (1) 2 POP (1) 1
RETURN (1) 2 RETURN (1) 2
main main
@ -105,7 +106,7 @@ CALL (ST) norm
LOADL 5 LOADL 5
LOAD (2) 2[SB] LOAD (2) 2[SB]
LOAD (1) -2[ST] LOAD (1) -2[ST]
CALL (ST) add CALL (SB) add
LOAD (2) 2[SB] LOAD (2) 2[SB]
CALL (ST) rout CALL (ST) rout
label2 label2

View file

@ -18,7 +18,7 @@ let rec analyse_code_expression e =
begin begin
let InfoFun(nom,_,_) = info_ast_to_info i in let InfoFun(nom,_,_) = info_ast_to_info i in
(List.fold_right (fun e res -> res ^ analyse_code_expression e) le "") ^ (List.fold_right (fun e res -> res ^ analyse_code_expression e) le "") ^
"CALL (ST) " ^nom ^ "\n" "CALL (ST) " ^ nom ^ "\n"
end end
| Ident(i) -> | Ident(i) ->
@ -58,13 +58,13 @@ let rec analyse_code_expression e =
end end
and analyse_code_instruction i = and analyse_code_instruction i taille_return taille_args taille_var =
match i with match i with
| Declaration(i, e) -> | Declaration(i, e) ->
analyse_code_expression e analyse_code_expression e
| Affectation(i, e) -> | Affectation(i, e) ->
let InfoVar(_,t,base,reg) = (info_ast_to_info i) in let InfoVar(_, t, base, reg) = (info_ast_to_info i) in
analyse_code_expression e ^ analyse_code_expression e ^
"STORE (" ^ (string_of_int (getTaille t)) ^ ") " ^ (string_of_int base) ^ "[" ^ reg ^ "]\n" "STORE (" ^ (string_of_int (getTaille t)) ^ ") " ^ (string_of_int base) ^ "[" ^ reg ^ "]\n"
@ -85,10 +85,10 @@ and analyse_code_instruction i =
let etiq2 = getEtiquette () in let etiq2 = getEtiquette () in
(analyse_code_expression e) ^ (analyse_code_expression e) ^
"JUMPIF (0) " ^ etiq1 ^ "\n" ^ "JUMPIF (0) " ^ etiq1 ^ "\n" ^
(analyse_code_bloc b1) ^ (analyse_code_bloc b1 taille_return taille_args taille_var) ^
"JUMP " ^ etiq2 ^ "\n" ^ "JUMP " ^ etiq2 ^ "\n" ^
etiq1 ^ "\n" ^ etiq1 ^ "\n" ^
(analyse_code_bloc b2) ^ (analyse_code_bloc b2 taille_return taille_args taille_var) ^
etiq2 ^ "\n" etiq2 ^ "\n"
| TantQue(e, b) -> | TantQue(e, b) ->
@ -97,34 +97,40 @@ and analyse_code_instruction i =
etiq_while ^ "\n" ^ etiq_while ^ "\n" ^
(analyse_code_expression e) ^ (analyse_code_expression e) ^
"JUMPIF (0) " ^ etiq_fin ^ "\n" ^ "JUMPIF (0) " ^ etiq_fin ^ "\n" ^
(analyse_code_bloc b) ^ (analyse_code_bloc b taille_return taille_args taille_var) ^
"JUMP " ^ etiq_while ^ "\n" ^ "JUMP " ^ etiq_while ^ "\n" ^
etiq_fin ^ "\n" etiq_fin ^ "\n"
| Retour(e) -> | Retour(e) ->
(analyse_code_expression e) (analyse_code_expression e) ^
"POP (" ^ taille_return ^ ") " ^ taille_var ^ "\n" ^
"RETURN (" ^ taille_return ^ ") " ^ taille_args ^ "\n"
| Empty -> "" | Empty -> ""
and analyse_code_bloc bloc = and analyse_code_bloc bloc taille_return taille_args taille_var =
List.fold_right ( List.fold_right (
fun i res -> (analyse_code_instruction i) ^ res fun i res -> (analyse_code_instruction i taille_return taille_args taille_var) ^ res
) bloc "" ) bloc ""
and analyse_code_fonction (AstPlacement.Fonction(info, l_typinfo, bloc)) = and analyse_code_fonction (AstPlacement.Fonction(info, l_typinfo, bloc)) =
match info_ast_to_info info with match info_ast_to_info info with
| InfoFun(name, t, l_t) -> | InfoFun(name, t, l_t) ->
let taille_var = string_of_int (List.fold_right (fun e res -> taille_variables_declarees e + res) bloc 0) in
let taille_return = string_of_int (getTaille t) in let taille_return = string_of_int (getTaille t) in
let taille_args = string_of_int (List.fold_right (fun e res -> getTaille e + res) l_t 0) in let taille_args = string_of_int (List.fold_right (fun e res -> getTaille e + res) l_t 0) in
name ^ "\n" ^ name ^ "\n" ^
(analyse_code_bloc bloc) ^ (analyse_code_bloc bloc taille_return taille_args taille_var) ^
"POP (" ^ taille_return ^ ") " ^ taille_args ^ "\n" ^ "POP (" ^ taille_return ^ ") " ^ taille_var ^ "\n" ^
"RETURN (" ^ taille_return ^ ") " ^ taille_args ^ "\n\n" "RETURN (0) " ^ taille_args ^ "\n\n"
| _ -> failwith "spa normal"
let analyser (AstPlacement.Programme(fonctions, prog)) = let analyser (AstPlacement.Programme(fonctions, prog)) =
let code = getEntete () in let code = getEntete () in
let code = code ^ List.fold_right (fun e res_q -> (analyse_code_fonction e) ^ res_q) fonctions "" in let code = code ^ List.fold_right (fun e res -> (analyse_code_fonction e) ^ res) fonctions "" in
let code = code ^ "main\n" in let code = code ^ "main\n" in
let code = code ^ analyse_code_bloc prog in let code = code ^ (analyse_code_bloc prog "0" "0" "0") in
code ^ "\nHALT" code ^ "\nHALT"
end end

View file

@ -84,7 +84,7 @@ let%expect_test "factfun1" =
let%expect_test "factfun2" = let%expect_test "factfun2" =
runtam "../../fichiersRat/src-rat-tam-test/testfun2.rat"; runtam "../../fichiersRat/src-rat-tam-test/testfun2.rat";
[%expect{| 7 |}] [%expect{| 7 |}]
(*
let%expect_test "factfun3" = let%expect_test "factfun3" =
runtam "../../fichiersRat/src-rat-tam-test/testfun3.rat"; runtam "../../fichiersRat/src-rat-tam-test/testfun3.rat";
[%expect{| 10 |}] [%expect{| 10 |}]
@ -108,4 +108,3 @@ let%expect_test "factfuns" =
let%expect_test "factrec" = let%expect_test "factrec" =
runtam "../../fichiersRat/src-rat-tam-test/factrec.rat"; runtam "../../fichiersRat/src-rat-tam-test/factrec.rat";
[%expect{| 120 |}] [%expect{| 120 |}]
*)