diff --git a/flap/questions/retrolixToX86_64/01.retrolix b/flap/questions/retrolixToX86_64/01.retrolix new file mode 100644 index 0000000..33b5fee --- /dev/null +++ b/flap/questions/retrolixToX86_64/01.retrolix @@ -0,0 +1,3 @@ +globals () + exit; +end diff --git a/flap/questions/retrolixToX86_64/02.retrolix b/flap/questions/retrolixToX86_64/02.retrolix new file mode 100644 index 0000000..5157e5d --- /dev/null +++ b/flap/questions/retrolixToX86_64/02.retrolix @@ -0,0 +1,24 @@ +globals (x, y, z, k) + x <- copy 6; + %rdi <- copy x; + print_int(); + %rdi <- copy " "; + print_string(); + + y <- copy 7; + %rdi <- copy y; + print_int(); + %rdi <- copy " "; + print_string(); + + z <- mul y, x; + %rdi <- copy z; + print_int(); + %rdi <- copy " "; + print_string(); + + k <- sub z, x; + %rdi <- copy k; + print_int(); + +end diff --git a/flap/questions/retrolixToX86_64/03.retrolix b/flap/questions/retrolixToX86_64/03.retrolix new file mode 100644 index 0000000..9052a68 --- /dev/null +++ b/flap/questions/retrolixToX86_64/03.retrolix @@ -0,0 +1,17 @@ +globals (res) + local compteur: + compteur <- copy 5; + res <- copy 1; + + condition: + jumpif lte compteur, 1 -> fin, boucle; + + boucle: + res <- mul res, compteur; + compteur <- sub compteur, 1; + jump condition; + + fin: + %rdi <- copy res; + print_int(); +end diff --git a/flap/questions/retrolixToX86_64/04.retrolix b/flap/questions/retrolixToX86_64/04.retrolix new file mode 100644 index 0000000..de73b80 --- /dev/null +++ b/flap/questions/retrolixToX86_64/04.retrolix @@ -0,0 +1,4 @@ +globals () + %rdi <- copy 42; + observe_int(); +end diff --git a/flap/questions/retrolixToX86_64/05.retrolix b/flap/questions/retrolixToX86_64/05.retrolix new file mode 100644 index 0000000..3fa8f67 --- /dev/null +++ b/flap/questions/retrolixToX86_64/05.retrolix @@ -0,0 +1,12 @@ +globals () + %rdi <- copy 1; + %rsi <- copy 2; + %rdx <- copy 3; + %rcx <- copy 4; + %r8 <- copy 5; + %r9 <- copy 6; + add_eight_int(7, 8); + + %rdi <- copy %rax; + observe_int(); +end diff --git a/flap/questions/retrolixToX86_64/06.retrolix b/flap/questions/retrolixToX86_64/06.retrolix new file mode 100644 index 0000000..71a1611 --- /dev/null +++ b/flap/questions/retrolixToX86_64/06.retrolix @@ -0,0 +1,25 @@ +def fact () + %rax <- copy 1; + + condition: + jumpif lte %rdi, 1 -> fin, boucle; + + boucle: + %rax <- mul %rax, %rdi; + %rdi <- sub %rdi, 1; + jump condition; + + fin: + ret; +end + +globals (x) + x <- copy 5; + + %rdi <- copy x; + fact(); + x <- copy %rax; + + %rdi <- copy x; + observe_int(); +end diff --git a/flap/questions/retrolixToX86_64/07.retrolix b/flap/questions/retrolixToX86_64/07.retrolix new file mode 100644 index 0000000..0e0516e --- /dev/null +++ b/flap/questions/retrolixToX86_64/07.retrolix @@ -0,0 +1,26 @@ +def fact () + local x: + jumpif lte %rdi, 1 -> fini, rec; + + fini: + %rax <- copy 1; + ret; + + rec: + x <- copy %rdi; + %rdi <- sub %rdi, 1; + fact(); + %rax <- mul %rax, x; + ret; +end + +globals (x) + x <- copy 5; + + %rdi <- copy x; + fact(); + x <- copy %rax; + + %rdi <- copy x; + observe_int(); +end diff --git a/flap/questions/retrolixToX86_64/08.retrolix b/flap/questions/retrolixToX86_64/08.retrolix new file mode 100644 index 0000000..ea0c8d3 --- /dev/null +++ b/flap/questions/retrolixToX86_64/08.retrolix @@ -0,0 +1,23 @@ +def my_add_eight_int (i7, i8) + %rax <- add %rdi, %rsi; + %rax <- add %rax, %rdx; + %rax <- add %rax, %rcx; + %rax <- add %rax, %r8; + %rax <- add %rax, %r9; + %rax <- add %rax, i7; + %rax <- add %rax, i8; + ret; +end + +globals () + %rdi <- copy 1; + %rsi <- copy 2; + %rdx <- copy 3; + %rcx <- copy 4; + %r8 <- copy 5; + %r9 <- copy 6; + my_add_eight_int(7, 8); + + %rdi <- copy %rax; + observe_int(); +end diff --git a/flap/questions/retrolixToX86_64/Makefile b/flap/questions/retrolixToX86_64/Makefile new file mode 100644 index 0000000..9e23610 --- /dev/null +++ b/flap/questions/retrolixToX86_64/Makefile @@ -0,0 +1,9 @@ +FLAP = ../../_build/default/src/flap.exe +TARGET = retrolix + +main: + @for f in $(wildcard *.$(TARGET)); do \ + printf "%s: " $$f; \ + ./$(FLAP) -s $(TARGET) -d true -r true $$f; \ + printf "\n"; \ + done diff --git a/flap/src/x86-64/retrolixToX86_64.ml b/flap/src/x86-64/retrolixToX86_64.ml index f3be4f3..99abfef 100644 --- a/flap/src/x86-64/retrolixToX86_64.ml +++ b/flap/src/x86-64/retrolixToX86_64.ml @@ -428,6 +428,7 @@ module InstructionSelector : InstructionSelector = struct open T let R15 = `Reg X86_64_Architecture.R15 (* Registre R15 que nous utilisons pour le compilateur *) +<<<<<<< HEAD let mov ~(dst : dst) ~(src : src) = (* SI les sources sont égaux (même adresse ou même registre), on ne bouge rien*) match src, dst with @@ -473,6 +474,57 @@ open T let move_execute f ~dst ~srcl ~srcr = mov ~src:srcr ~dst:r15 @ (execute ~dst (f ~src:srcl)) +======= + let mov ~(dst : dst) ~(src : src) = + (* TODO *) + failwith "Students! This is your job! (mov)" + ;; + + let bin ins ~dst ~srcl ~srcr = + (* TODO *) + failwith "Students! This is your job! (bin)" + ;; + + let add ~dst ~srcl ~srcr = + (* TODO *) + failwith "Students! This is your job! (add)" + ;; + + let sub ~dst ~srcl ~srcr = + (* TODO *) + failwith "Students! This is your job! (sub)" + ;; + + let mul ~dst ~srcl ~srcr = + (* TODO *) + failwith "Students! This is your job! (mul)" + ;; + + let div ~dst ~srcl ~srcr = + (* TODO *) + failwith "Students! This is your job! (div)" + ;; + + let andl ~dst ~srcl ~srcr = + (* TODO *) + failwith "Students! This is your job! (andl)" + ;; + + let orl ~dst ~srcl ~srcr = + (* TODO *) + failwith "Students! This is your job! (orl)" + ;; + + let conditional_jump ~cc ~srcl ~srcr ~ll ~lr = + (* TODO *) + failwith "Students! This is your job! (conditional_jump)" + ;; + + let switch ?default ~discriminant ~cases () = + (* TODO *) + failwith "Students! This is your job! (switch)" + ;; +>>>>>>> ac93861c63fb639c260e046373135aea113d7a9c end module FrameManager (IS : InstructionSelector) : FrameManager = struct @@ -498,23 +550,29 @@ module FrameManager (IS : InstructionSelector) : FrameManager = struct ;; let frame_descriptor ~params ~locals = - (* Student! Implement me! *) + (* TODO: Student! Implement me! *) { param_count = 0; locals_space = 0; stack_map = S.IdMap.empty } ;; - let location_of fd id = failwith "Students! This is your job!" + let location_of fd id = + (* TODO *) + failwith "Students! This is your job! (location_of)" + ;; let function_prologue fd = - (* Student! Implement me! *) + (* TODO: Student! Implement me! *) [] ;; let function_epilogue fd = - (* Student! Implement me! *) + (* TODO: Student! Implement me! *) [] ;; - let call fd ~kind ~f ~args = failwith "Students! This is your job!" + let call fd ~kind ~f ~args = + (* TODO *) + failwith "Students! This is your job! (call)" + ;; end module CG = Codegen (InstructionSelector) (FrameManager (InstructionSelector))