Links und Funktionen
Sprachumschaltung

Navigationspfad
Sie sind hier: Startseite / Lehre / SS 2013 / Compilerbau / Machinespecifics.ml


Inhaltsbereich

Machinespecifics.ml

OCaml source code icon machinespecifics.ml — OCaml source code, 2 KB (2640 bytes)

Dateiinhalt

(* Abstact interface for activation frames *)
module type Frame =
  sig
    (* Abstract representation of frames. 
     * immutable *)
    type t 

    type alloc_location = Anywhere | InMemory

    (* Name of the frame. Typically this will be the name of a function. *)
    val name : t -> string

    (* Number of parameters *)
    val paramCount : t -> int

    (* Returns a tree expression that can be used for reading/writing
     * the n-th parameter in the frame. *)
    val param : t -> int -> Tree.exp list

    (* Returns the frame size, i.e. how much actual memory is being 
     * used for the frame. *)
    val size : t -> int

    (* Allocates a new local and returns a tree expression by which it
     * can be accessed. With the argument of type alloc_location one
     * can enfoce the local to be allocated in memory (as opposed to
     * registers).*)
    val allocLocal : t ->  alloc_location -> t * Tree.exp
    
    (* The frame abstracts how return values are returned to the caller.
     * This function takes a frame, a method body and a return expression 
     * and returns a statement that first executes the body and then 
     * returns the expression to the caller.
     * (Corresponds to procEntryExit1 in the book) *)
    val makeProc : t -> Tree.stm -> Tree.exp -> Tree.stm
  end

(* Abstract interface for assembly instructions *)
module type Assem =
  sig
    (* immutable *)
    type t

    val use : t -> Names.temp list
    val def : t -> Names.temp list
    val jumps : t -> Names.label list
    val isFallThrough : t -> bool
    val isMoveBetweenTemps : t ->  (Names.temp * Names.temp) option
    val isLabel : t -> Names.label option
    val rename : t -> (Names.temp -> Names.temp) -> t
  end

(* Abstraction of all machine dependent parts of the compiler.
 * To implement a new backend one should only need to
 * implement this signature. The rest of the compiler should
 * be machine-independent and be parameterised by this signature. *)
module type S =
  sig
    module Assem : Assem
    module Frame : Frame

    type 'a fragment = FragmentProc of Frame.t * 'a

    val wordSize : int

    (* Construct a frame with given name and number of parameters *)
    val mkFrame : string (* name *) -> int (* # parameters *) -> Frame.t

    val codeGen : Tree.stm list fragment -> (Assem.t list) fragment

    (* Interface to register allocator *)
    val allRegisters : (Names.temp list) option
    val generalPurposeRegisters : (Names.temp list) option
    val spill : Frame.t -> Assem.t list -> Frame.t * (Assem.t list)

    (* Assembler *)
    val formatAssembly : Assem.t fragment -> string
end

Artikelaktionen


Funktionsleiste