Documentation ¶
Index ¶
- Constants
- Variables
- func IsLeaf(e Expr) bool
- type Arch
- type ArchId
- type Arg
- type Asm
- type AsmCode
- type Code
- func (c *Code) Init() *Code
- func (c *Code) Inst1(inst Inst1, dst Expr) *Code
- func (c *Code) Inst2(inst Inst2, dst Expr, src Expr) *Code
- func (c *Code) Inst3(inst Inst3, dst Expr, darg Expr, src Expr) *Code
- func (c *Code) Op1(op Op1, src Expr, dst Expr) *Code
- func (c *Code) Op2(op Op2, a Expr, b Expr, dst Expr) *Code
- func (c *Code) SoftReg(op asm.Op1Misc, s SoftReg) *Code
- type Comp
- func (c *Comp) Arch() Arch
- func (c *Comp) ArchId() ArchId
- func (c *Comp) Asm() *Asm
- func (c *Comp) Assemble() MachineCode
- func (c *Comp) ClearCode()
- func (c *Comp) ClearRegs()
- func (c *Comp) Code() Code
- func (c *Comp) Compile(s Source)
- func (c *Comp) Epilogue()
- func (c *Comp) Expr(e Expr) (Expr, SoftReg)
- func (c *Comp) FreeSoftReg(s SoftReg)
- func (c *Comp) Func(funcaddr interface{})
- func (c *Comp) Init() *Comp
- func (c *Comp) InitArch(arch Arch) *Comp
- func (c *Comp) InitArchId(archId ArchId) *Comp
- func (c *Comp) MakeParam(off int32, kind Kind) Mem
- func (c *Comp) MakeVar(idx int, kind Kind) Mem
- func (c *Comp) NewSoftReg(kind Kind) SoftReg
- func (c *Comp) SoftReg(inst Inst1Misc, s SoftReg)
- func (c *Comp) Stmt(t Stmt)
- func (c *Comp) Stmt1(inst Inst1, tdst Expr)
- func (c *Comp) Stmt2(inst Inst2, tdst Expr, tsrc Expr)
- func (c *Comp) Stmt3(inst Inst3, tdst Expr, tdarg Expr, tsrc Expr)
- func (c *Comp) StmtN(tdst []Expr, tsrc []Expr)
- type Const
- func ConstInt(val int) Const
- func ConstInt16(val int16) Const
- func ConstInt32(val int32) Const
- func ConstInt64(val int64) Const
- func ConstInt8(val int8) Const
- func ConstInterface(ival interface{}, t reflect.Type) (Const, error)
- func ConstPointer(val *uint8) Const
- func ConstUint(val uint) Const
- func ConstUint16(val uint16) Const
- func ConstUint32(val uint32) Const
- func ConstUint64(val uint64) Const
- func ConstUint8(val uint8) Const
- func ConstUintptr(val uintptr) Const
- func MakeConst(val int64, kind Kind) Const
- type Expr
- type Expr1
- type Expr2
- type Inst1
- type Inst1Misc
- type Inst2
- type Inst3
- type Kind
- type MachineCode
- type Mem
- type Op1
- type Op2
- type Reg
- type RegId
- type RegIdConfig
- type Save
- type Size
- type SoftReg
- type SoftRegId
- type SoftRegs
- type Source
- type Stmt
- type Stmt1
- type Stmt2
- type Stmt3
- type StmtN
Constants ¶
const ( ASM_SUPPORTED = asm.ARCH_SUPPORTED MMAP_SUPPORTED = asm.MMAP_SUPPORTED SUPPORTED = asm.SUPPORTED NAME = asm.NAME // ArchId NOARCH = common.NOARCH AMD64 = common.AMD64 ARM64 = common.ARM64 ARCH_ID = asm.ARCH_ID // build arch // Kind Invalid = common.Invalid Bool = common.Bool Int = common.Int Int8 = common.Int8 Int16 = common.Int16 Int32 = common.Int32 Int64 = common.Int64 Uint = common.Uint Uint8 = common.Uint8 Uint16 = common.Uint16 Uint32 = common.Uint32 Uint64 = common.Uint64 Uintptr = common.Uintptr Float32 = common.Float32 Float64 = common.Float64 Ptr = common.Ptr KLo = common.KLo KHi = common.KHi // RegId NoRegId = common.NoRegId // SoftRegId FirstSoftRegId = common.FirstSoftRegId LastSoftRegId = common.LastSoftRegId FirstTempRegId = common.FirstTempRegId LastTempRegId = common.LastTempRegId )
const ( INC = Inst1(asm.INC) // ++ DEC = Inst1(asm.DEC) // -- ZERO = Inst1(asm.ZERO) // = 0 NOP = Inst1(asm.NOP) // used to wrap an expression into a statement ASSIGN = Inst2(asm.MOV) ADD_ASSIGN = Inst2(asm.ADD2) SUB_ASSIGN = Inst2(asm.SUB2) MUL_ASSIGN = Inst2(asm.MUL2) QUO_ASSIGN = Inst2(asm.DIV2) REM_ASSIGN = Inst2(asm.REM2) AND_ASSIGN = Inst2(asm.AND2) OR_ASSIGN = Inst2(asm.OR2) XOR_ASSIGN = Inst2(asm.XOR2) SHL_ASSIGN = Inst2(asm.SHL2) SHR_ASSIGN = Inst2(asm.SHR2) AND_NOT_ASSIGN = Inst2(asm.AND_NOT2) LAND_ASSIGN = Inst2(asm.LAND2) LOR_ASSIGN = Inst2(asm.LOR2) IDX_ASSIGN = Inst3(asm.SETIDX) // a[b] = val // allocate / free soft register ALLOC = Inst1Misc(asm.ALLOC) FREE = Inst1Misc(asm.FREE) )
const ( // instead of a single CAST, we must implement // one Op1 per destination type: // INT8 ... INT64, UINT8 ... UINT64, etc. INT = Op1(common.Int) INT8 = Op1(common.Int8) INT16 = Op1(common.Int16) INT32 = Op1(common.Int32) INT64 = Op1(common.Int64) UINT = Op1(common.Uint) UINT8 = Op1(common.Uint8) UINT16 = Op1(common.Uint16) UINT32 = Op1(common.Uint32) UINT64 = Op1(common.Uint64) UINTPTR = Op1(common.Uintptr) FLOAT32 = Op1(common.Float32) FLOAT64 = Op1(common.Float64) PTR = Op1(common.Ptr) NEG = Op1(common.NEG2) NOT = Op1(common.NOT2) )
const ( ADD = Op2(common.ADD3) SUB = Op2(common.SUB3) MUL = Op2(common.MUL3) DIV = Op2(common.DIV3) QUO = DIV REM = Op2(common.REM3) AND = Op2(common.AND3) OR = Op2(common.OR3) XOR = Op2(common.XOR3) SHL = Op2(common.SHL3) SHR = Op2(common.SHR3) AND_NOT = Op2(common.AND_NOT3) // &^ LAND = Op2(common.LAND3) // && LOR = Op2(common.LOR3) // || /* EQL = Op2(common.EQL3) LSS = Op2(common.LSS3) GTR = Op2(common.GTR3) NEQ = Op2(common.NEQ3) LEQ = Op2(common.LEQ3) GEQ = Op2(common.GEQ3) */ IDX = Op2(common.GETIDX) // a[b] )
Variables ¶
var Archs = common.Archs
map[ArchId]Arch is a handle, changes effect common.Archs
Functions ¶
Types ¶
type Code ¶
type Code []AsmCode
will be passed as argument to asm.Asm()
type Comp ¶
type Comp struct { asm.RegIdConfig // contains filtered or unexported fields }
func (*Comp) Assemble ¶
func (c *Comp) Assemble() MachineCode
assemble the code compiled since previous call to Assemble(), and return machine code
func (*Comp) Epilogue ¶
func (c *Comp) Epilogue()
call Comp.Assemble() followed by Comp.Asm().Epilogue()
func (*Comp) FreeSoftReg ¶
func (*Comp) Func ¶
func (c *Comp) Func(funcaddr interface{})
* call Assemble(), then set *funcaddr to assembled machine code. * * funcaddr must be a non-nil pointer to function. * * function type MUST match the code created by the programmer, * or BAD things will happen: crash, memory corruption, undefined behaviour... * * Obviously, code created by the programmer must be for the same architecture * the program is currently running on... * * Caller likely needs to call ClearCode() after this function returns
func (*Comp) InitArchId ¶
func (*Comp) NewSoftReg ¶
type Const ¶
func ConstInt16 ¶
func ConstInt32 ¶
func ConstInt64 ¶
func ConstPointer ¶
guaranteed to work only if val points to non-Go memory, as for example C/C++ memory
func ConstUint16 ¶
func ConstUint32 ¶
func ConstUint64 ¶
func ConstUint8 ¶
func ConstUintptr ¶
type MachineCode ¶
type MachineCode = common.MachineCode
type Mem ¶
type Op1 ¶
type Op1 uint8 // unary expression operator
type RegIdConfig ¶
type RegIdConfig = common.RegIdConfig