This commit is contained in:
Mylloon 2023-12-31 23:16:39 +01:00
parent 57f67d98e6
commit e4b1d10007
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
8 changed files with 27 additions and 36 deletions

View file

@ -1,24 +1,8 @@
globals (x, y, z, k) globals (x, y, z, k)
x <- copy 6; x <- copy 6;
%rdi <- copy x;
print_int();
%rdi <- copy " ";
print_string();
y <- copy 7; y <- copy 7;
%rdi <- copy y;
print_int();
%rdi <- copy " ";
print_string();
z <- mul y, x; z <- mul y, x;
%rdi <- copy z;
print_int();
%rdi <- copy " ";
print_string();
k <- sub z, x; k <- sub z, x;
%rdi <- copy k;
print_int();
exit;
end end

View file

@ -1,11 +1,9 @@
globals (res) globals (res)
res <- copy 1; res <- mul 1, 5;
res <- mul res, 5;
res <- mul res, 4; res <- mul res, 4;
res <- mul res, 3; res <- mul res, 3;
res <- mul res, 2; res <- mul res, 2;
res <- mul res, 1; res <- mul res, 1;
%rdi <- copy res; exit;
print_int();
end end

View file

@ -1,4 +1,6 @@
globals () globals ()
%rdi <- copy 42; %rdi <- copy 42;
observe_int(); observe_int();
exit;
end end

View file

@ -9,4 +9,6 @@ globals ()
%rdi <- copy %rax; %rdi <- copy %rax;
observe_int(); observe_int();
exit;
end end

View file

@ -1,12 +1,15 @@
def fact () def fact ()
local n:
n <- copy %rdi;
%rax <- copy 1; %rax <- copy 1;
condition: condition:
jumpif lte %rdi, 1 -> fin, boucle; jumpif lte n, 1 -> fin, boucle;
boucle: boucle:
%rax <- mul %rax, %rdi; %rax <- mul %rax, n;
%rdi <- sub %rdi, 1; n <- sub n, 1;
jump condition; jump condition;
fin: fin:
@ -14,12 +17,12 @@ def fact ()
end end
globals (x) globals (x)
x <- copy 5; %rdi <- copy 5;
%rdi <- copy x;
fact(); fact();
x <- copy %rax; x <- copy %rax;
%rdi <- copy x; %rdi <- copy x;
observe_int(); observe_int();
exit;
end end

View file

@ -1,26 +1,26 @@
def fact () def fact ()
local x: local n:
jumpif lte %rdi, 1 -> fini, rec; n <- copy %rdi;
jumpif lte n, 1 -> fini, rec;
fini: fini:
%rax <- copy 1; %rax <- copy 1;
ret; ret;
rec: rec:
x <- copy %rdi; %rdi <- sub n, 1;
%rdi <- sub %rdi, 1;
fact(); fact();
%rax <- mul %rax, x; %rax <- mul %rax, n;
ret; ret;
end end
globals (x) globals (x)
x <- copy 5; %rdi <- copy 5;
%rdi <- copy x;
fact(); fact();
x <- copy %rax; x <- copy %rax;
%rdi <- copy x; %rdi <- copy x;
observe_int(); observe_int();
exit;
end end

View file

@ -20,4 +20,6 @@ globals ()
%rdi <- copy %rax; %rdi <- copy %rax;
observe_int(); observe_int();
exit;
end end

View file

@ -549,7 +549,7 @@ module FrameManager (IS : InstructionSelector) : FrameManager = struct
;; ;;
let call fd ~kind ~f ~args = let call fd ~kind ~f ~args =
(* TODO: je segfault.. *) (* TODO *)
(* Appelle la fonction *) (* Appelle la fonction *)
[ T.Instruction (T.calldi ~tgt:f) ] [ T.Instruction (T.calldi ~tgt:f) ]
;; ;;