Documentation ¶
Overview ¶
Package mir provides definition of MIR and converter from AST.
MIR is an abbreviation of GoCaml Intermediate Language. It's an original intermediate language to fill the gap between machine code and syntax tree. MIR is a SSA form and K-normalized, and has high-level type information.
It discards many things from syntax tree because it's no longer needed. For example, position of nodes, display name of symbols and nested tree structure are discarded.
MIR consists of block (basic block), instruction and value. There is a one root block. Block contains sequence of instructions. Instruction contains a bound identifier name and its value. Some value (`if`, `fun`, ...) contains recursive blocks.
Please see spec file in the gocaml repository.
https://github.com/rhysd/gocaml/blob/master/mir/README.md
You can see its string representation by command
gocaml -mir test.ml
e.g.
let x = 1 in let rec f a b = if a < 0 then a + b - x else x in if true then print_int (f 3 4) else () root: x$t1 = int 1 f$t2 = fun a$t3,b$t4 $k1 = int 0 $k2 = less a$t3 $k1 $k3 = if $k2 then: $k4 = add $at3 $bt4 $k5 = sub $k4 x$t1 else: $k6 = ref x$t1 $k7 = bool true $k8 = if $k7 then: $k9 = xref print_int $k10 = ref f$t2 $k11 = int 3 $k12 = int 4 $k13 = app $k10 $k11,$k12 $k14 = app $k9 $k13 else: $k15 = unit
Index ¶
- Variables
- type App
- type AppKind
- type ArrLen
- type ArrLit
- type ArrLoad
- type ArrStore
- type Array
- type Binary
- type Block
- type Bool
- type Closures
- type DerefSome
- type Float
- type Fun
- type FunInsn
- type If
- type Insn
- type Int
- type IsSome
- type MakeCls
- type NOP
- type None
- type OperatorKind
- type Program
- type Ref
- type Some
- type String
- type Toplevel
- type TplLoad
- type Tuple
- type Unary
- type Unit
- type Val
- type XRef
Constants ¶
This section is empty.
Variables ¶
var ( UnitVal = &Unit{} NOPVal = &NOP{} NoneVal = &None{} )
Functions ¶
This section is empty.
Types ¶
type Binary ¶
type Binary struct { Op OperatorKind LHS, RHS string }
type Block ¶
Block struct represents basic block. It has a name and instruction sequence to execute. Note that top and bottom of the sequence are always NOP instruction in order to make modifying instructions easy.
func NewBlockFromArray ¶
func NewEmptyBlock ¶
func (*Block) WholeRange ¶
Returns range [begin, end)
type Insn ¶
Instruction. Its form is always `ident = val`
func (*Insn) RemoveFromList ¶
func (insn *Insn) RemoveFromList()
type OperatorKind ¶
type OperatorKind int
const ( NOT OperatorKind = iota NEG FNEG ADD SUB MUL DIV MOD FADD FSUB FMUL FDIV LT LTE EQ NEQ GT GTE AND OR )
Operators
type Program ¶
type Program struct { Toplevel Toplevel // Mapping from function name to its instruction Closures Closures // Mapping from closure name to it free variables Entry *Block }
Program representation. Program can be obtained after closure transform because all functions must be at the top.
type Toplevel ¶
func NewToplevel ¶
func NewToplevel() Toplevel
type Unary ¶
type Unary struct { Op OperatorKind Child string }