ajout mov mul et sub

This commit is contained in:
Nicolas PENELOUX 2023-12-31 17:00:00 +01:00
parent 07a65e7bcb
commit d59d579df9

View file

@ -425,17 +425,54 @@ end
module InstructionSelector : InstructionSelector = struct
open T
open T
let R15 = `Reg X86_64_Architecture.R15 (* Registre R15 que nous utilisons pour le compilateur *)
let mov ~(dst : dst) ~(src : src) = failwith "Students! This is your job!"
let bin ins ~dst ~srcl ~srcr = failwith "Students! This is your job!"
let add ~dst ~srcl ~srcr = failwith "Students! This is your job!"
let sub ~dst ~srcl ~srcr = failwith "Students! This is your job!"
let mul ~dst ~srcl ~srcr = failwith "Students! This is your job!"
let div ~dst ~srcl ~srcr = failwith "Students! This is your job!"
let andl ~dst ~srcl ~srcr = failwith "Students! This is your job!"
let orl ~dst ~srcl ~srcr = failwith "Students! This is your job!"
let conditional_jump ~cc ~srcl ~srcr ~ll ~lr = failwith "Students! This is your job!"
let switch ?default ~discriminant ~cases () = failwith "Students! This is your job!"
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
| `Reg x, `Reg y when x = y -> []
| `Addr x, `Addr y when x = y -> []
(*Si au moins un des deux est un accès mémoire, on créé une instruction movq*)
| (`Imm _ | `Reg _), _ | _, `Reg _-> [Instruction (movq ~src ~dst)]
(*Si la destination est pas un registre, on effectue une copie vers r15 puis on effectue l'instruction movq*)
| _ -> execute ~dst (movq ~src)
let bin ins ~dst ~srcl ~srcr =
failwith "Students! This is your job!"
let add ~dst ~srcl ~srcr =
failwith "Students! This is your job!"
let sub ~dst ~srcl ~srcr =
move_execute imulq ~dst:dst ~srcl:srcl ~srcr:srcr
let mul ~dst ~srcl ~srcr =
move_execute imulq ~dst:dst ~srcl:srcl ~srcr:srcr
let div ~dst ~srcl ~srcr =
failwith "Students! This is your job!"
let andl ~dst ~srcl ~srcr =
failwith "Students! This is your job!"
let orl ~dst ~srcl ~srcr =
failwith "Students! This is your job!"
let conditional_jump ~cc ~srcl ~srcr ~ll ~lr =
failwith "Students! This is your job!"
let switch ?default ~discriminant ~cases () =
failwith "Students! This is your job!"
let execute ~(dst : dst) f = (* On créer une instruction f puis on créer un movq *)
Instruction (f ~dst:r15) :: (if dst = r15 [] else [Instruction (movq ~src:r15 ~dst)])
let move_execute f ~dst ~srcl ~srcr =
mov ~src:srcr ~dst:r15
@ (execute ~dst (f ~src:srcl))
end
module FrameManager (IS : InstructionSelector) : FrameManager = struct