a6cdfd8d by Ulrich Schoepp

Backend-Interfaces SML

1 parent 08f47e28
signature MACHINE_INSTR = sig
type t
val use : t -> Temp.t list
val def : t -> Temp.t list
val jumps : t -> Label.t list
val isFallThrough : t -> bool
val isMoveBetweenTemps : t -> (Temp.t * Temp.t) option
val isAssignmentToTemp : t -> Temp.t option
val isLabel : t -> Label.t option
val renameInstr : t -> (Temp.t -> Temp.t) -> t
end
signature MACHINE_FUN = sig
type t
structure I : MACHINE_INSTR
val machineFunctionName : t -> string
val machineFunctionBody : t -> I.t list
val machineFunctionRename : t -> (Temp.t -> Temp.t) -> t
val machineFunctionSpill : t -> Temp.t list -> t
end
signature MACHINE_PRG = sig
type t
structure F : MACHINE_FUN
val machinePrgFunctions : t -> F.t list
val replaceFunctions: t -> F.t list -> t
end
signature CODEGEN = sig
structure P : MACHINE_PRG
val codeGen : Tree.prg -> P.t
val allRegisters : Temp.t list
val generalPurposeRegisters : Temp.t list
end
structure X86CodeGen : CODEGEN = struct
structure P = X86Prg
fun codeGen (p: Tree.prg) =
raise (Fail "instruction selection goes here")
val allRegisters =
raise (Fail "list of all machine registers")
val generalPurposeRegisters =
raise (Fail "list of registers that can be used freely by register allocator")
end
structure X86Fun : MACHINE_FUN = struct
structure I = X86Instr
type t = { name : string,
body : I.t list }
fun machineFunctionName (f: t) = #name f
fun machineFunctionBody (f: t) = #body f
fun machineFunctionRename f =
raise (Fail "needed later for register allocation")
fun machineFunctionSpill f =
raise (Fail "needed later for register allocation")
end
structure X86Instr : MACHINE_INSTR = struct
datatype UnaryInstr = PUSH
| POP
| NEG
| NOT
| INC
| DEC
| IDIV
datatype BinayInstr = MOV
| ADD
| SUB
| SHL
| SHR
| SAL
| SAR
| AND
| OR
| XOR
| TEST
| CMP
| LEA
| IMUL
datatype Cond = E | NE | L | LE | G | GE | Z
(* possible scaling values for effective addressing *)
datatype Scale = S1 | S2 | S4 | S8
type EffectiveAddress = { base : Temp.t option,
indexScale : (Temp.t * Scale) option,
displacement : int }
datatype Operand = Imm of int
| Reg of Temp.t
| Mem of EffectiveAddress
datatype t = Unary of UnaryInstr * Operand
| Binary of BinayInstr * Operand * Operand
| LABEL of Label.t
| CDQ
| JMP of Label.t
| J of Cond * Label.t
| CALL of Label.t
| RET of unit
| NOP of unit
fun use i = raise (Fail "needed later for register allocation")
fun def i = raise (Fail "needed later for register allocation")
fun jumps i = raise (Fail "needed later for register allocation")
fun isFallThrough i = raise (Fail "needed later for register allocation")
fun isMoveBetweenTemps i = raise (Fail "needed later for register allocation")
fun isAssignmentToTemp i = raise (Fail "needed later for register allocation")
fun isLabel i = raise (Fail "needed later for register allocation")
fun renameInstr i = raise (Fail "needed later for register allocation")
end
structure X86Prg : MACHINE_PRG = struct
structure F = X86Fun
type t = {funcs : F.t list}
fun machinePrgFunctions (p: t) = #funcs p
fun replaceFunctions (p: t) (fs: F.t list) = { funcs = fs }
end
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!