jit

package
v0.0.0-...-4cc5765 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2022 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
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)
)
View Source
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)
)
View Source
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

View Source
var Archs = common.Archs

map[ArchId]Arch is a handle, changes effect common.Archs

Functions

func IsLeaf

func IsLeaf(e Expr) bool

Types

type Arch

type Arch = common.Arch

type ArchId

type ArchId = common.ArchId

type Arg

type Arg = common.Arg

type Asm

type Asm = common.Asm

type AsmCode

type AsmCode = common.AsmCode

type Code

type Code []AsmCode

will be passed as argument to asm.Asm()

func (*Code) Init

func (c *Code) Init() *Code

func (*Code) Inst1

func (c *Code) Inst1(inst Inst1, dst Expr) *Code

func (*Code) Inst2

func (c *Code) Inst2(inst Inst2, dst Expr, src Expr) *Code

destination is first argument, as Comp.Stmt2

func (*Code) Inst3

func (c *Code) Inst3(inst Inst3, dst Expr, darg Expr, src Expr) *Code

destination is first argument, as Comp.Stmt3

func (*Code) Op1

func (c *Code) Op1(op Op1, src Expr, dst Expr) *Code

func (*Code) Op2

func (c *Code) Op2(op Op2, a Expr, b Expr, dst Expr) *Code

func (*Code) SoftReg

func (c *Code) SoftReg(op asm.Op1Misc, s SoftReg) *Code

ALLOC/FREE

type Comp

type Comp struct {
	asm.RegIdConfig
	// contains filtered or unexported fields
}

func New

func New() *Comp

func NewArch

func NewArch(arch Arch) *Comp

func NewArchId

func NewArchId(archId ArchId) *Comp

func (*Comp) Arch

func (c *Comp) Arch() Arch

func (*Comp) ArchId

func (c *Comp) ArchId() ArchId

func (*Comp) Asm

func (c *Comp) Asm() *Asm

return assembler

func (*Comp) Assemble

func (c *Comp) Assemble() MachineCode

assemble the code compiled since previous call to Assemble(), and return machine code

func (*Comp) ClearCode

func (c *Comp) ClearCode()

discard assembly code and machine code

func (*Comp) ClearRegs

func (c *Comp) ClearRegs()

forget all allocated registers

func (*Comp) Code

func (c *Comp) Code() Code

return symbolic assembly code

func (*Comp) Compile

func (c *Comp) Compile(s Source)

compile statements and their arguments

func (*Comp) Epilogue

func (c *Comp) Epilogue()

call Comp.Assemble() followed by Comp.Asm().Epilogue()

func (*Comp) Expr

func (c *Comp) Expr(e Expr) (Expr, SoftReg)

compile expression

func (*Comp) FreeSoftReg

func (c *Comp) FreeSoftReg(s SoftReg)

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) Init

func (c *Comp) Init() *Comp

func (*Comp) InitArch

func (c *Comp) InitArch(arch Arch) *Comp

func (*Comp) InitArchId

func (c *Comp) InitArchId(archId ArchId) *Comp

func (*Comp) MakeParam

func (c *Comp) MakeParam(off int32, kind Kind) Mem

func (*Comp) MakeVar

func (c *Comp) MakeVar(idx int, kind Kind) Mem

func (*Comp) NewSoftReg

func (c *Comp) NewSoftReg(kind Kind) SoftReg

func (*Comp) SoftReg

func (c *Comp) SoftReg(inst Inst1Misc, s SoftReg)

alloc or free soft reg

func (*Comp) Stmt

func (c *Comp) Stmt(t Stmt)

compile statement

func (*Comp) Stmt1

func (c *Comp) Stmt1(inst Inst1, tdst Expr)

compile unary statement

func (*Comp) Stmt2

func (c *Comp) Stmt2(inst Inst2, tdst Expr, tsrc Expr)

compile binary statement

func (*Comp) Stmt3

func (c *Comp) Stmt3(inst Inst3, tdst Expr, tdarg Expr, tsrc Expr)

compile ternary statement

func (*Comp) StmtN

func (c *Comp) StmtN(tdst []Expr, tsrc []Expr)

compile n-ary statement

type Const

type Const = common.Const

func ConstInt

func ConstInt(val int) Const

func ConstInt16

func ConstInt16(val int16) Const

func ConstInt32

func ConstInt32(val int32) Const

func ConstInt64

func ConstInt64(val int64) Const

func ConstInt8

func ConstInt8(val int8) Const

func ConstInterface

func ConstInterface(ival interface{}, t reflect.Type) (Const, error)

func ConstPointer

func ConstPointer(val *uint8) Const

guaranteed to work only if val points to non-Go memory, as for example C/C++ memory

func ConstUint

func ConstUint(val uint) Const

func ConstUint16

func ConstUint16(val uint16) Const

func ConstUint32

func ConstUint32(val uint32) Const

func ConstUint64

func ConstUint64(val uint64) Const

func ConstUint8

func ConstUint8(val uint8) Const

func ConstUintptr

func ConstUintptr(val uintptr) Const

func MakeConst

func MakeConst(val int64, kind Kind) Const

type Expr

type Expr = common.Expr

type Expr1

type Expr1 struct {
	X  Expr
	Op Op1
	K  Kind
}

unary expression OP X

func NewExpr1

func NewExpr1(op Op1, x Expr) *Expr1

func (*Expr1) Const

func (e *Expr1) Const() bool

func (*Expr1) Kind

func (e *Expr1) Kind() Kind

implement Expr interface

func (*Expr1) String

func (e *Expr1) String() string

type Expr2

type Expr2 struct {
	X  Expr
	Y  Expr
	Op Op2
	K  Kind
}

binary expression X OP Y

func NewExpr2

func NewExpr2(op Op2, x Expr, y Expr) *Expr2

func NewExprIdx

func NewExprIdx(x Expr, y Expr, kind Kind) *Expr2

func (*Expr2) Const

func (e *Expr2) Const() bool

func (*Expr2) Kind

func (e *Expr2) Kind() Kind

implement Expr interface

func (*Expr2) String

func (e *Expr2) String() string

type Inst1

type Inst1 uint8 // unary statement operator

func (Inst1) Asm

func (inst Inst1) Asm() asm.Op1

convert to asm.Op1

func (Inst1) String

func (inst Inst1) String() string

func (Inst1) Valid

func (inst Inst1) Valid() bool

func (Inst1) Validate

func (inst Inst1) Validate()

type Inst1Misc

type Inst1Misc uint8 // miscellaneous statement operator

func (Inst1Misc) Asm

func (inst Inst1Misc) Asm() asm.Op1Misc

convert to asm.Op1Misc

func (Inst1Misc) String

func (inst Inst1Misc) String() string

func (Inst1Misc) Valid

func (inst Inst1Misc) Valid() bool

func (Inst1Misc) Validate

func (inst Inst1Misc) Validate()

type Inst2

type Inst2 uint8 // binary statement operator

func TokenInst2

func TokenInst2(tok token.Token) (Inst2, error)

convert token.Token to Inst2

func (Inst2) Asm

func (inst Inst2) Asm() asm.Op2

convert to asm.Op2

func (Inst2) String

func (inst Inst2) String() string

func (Inst2) Valid

func (inst Inst2) Valid() bool

func (Inst2) Validate

func (inst Inst2) Validate()

type Inst3

type Inst3 uint8 // ternary statement operator

func (Inst3) Asm

func (inst Inst3) Asm() asm.Op3

convert to asm.Op3

func (Inst3) String

func (inst Inst3) String() string

func (Inst3) Valid

func (inst Inst3) Valid() bool

func (Inst3) Validate

func (inst Inst3) Validate()

type Kind

type Kind = common.Kind

type MachineCode

type MachineCode = common.MachineCode

type Mem

type Mem = common.Mem

func MakeMem

func MakeMem(off int32, id RegId, kind Kind) Mem

func MakeParam

func MakeParam(off int32, kind Kind, config RegIdConfig) Mem

function parameter or return value

func MakeVar

func MakeVar(idx int, kind Kind, config RegIdConfig) (Mem, error)

local variable. only supports upn == 0

type Op1

type Op1 uint8 // unary expression operator

func KindOp1

func KindOp1(kind reflect.Kind) (Op1, error)

convert reflect.Kind to Op1 used to create cast expressions

func TokenOp1

func TokenOp1(tok token.Token) (Op1, error)

convert token.Token to Op1

func (Op1) Asm

func (op Op1) Asm() common.Op2

convert to common.Op2

func (Op1) IsCast

func (op Op1) IsCast() bool

func (Op1) String

func (op Op1) String() string

func (Op1) Valid

func (op Op1) Valid() bool

func (Op1) Validate

func (op Op1) Validate()

type Op2

type Op2 uint8 // binary expression operator

func TokenOp2

func TokenOp2(tok token.Token) (Op2, error)

convert token.Token to Op2

func (Op2) Asm

func (op Op2) Asm() common.Op3

convert to common.Op3

func (Op2) IsCommutative

func (op Op2) IsCommutative() bool

func (Op2) String

func (op Op2) String() string

func (Op2) Valid

func (op Op2) Valid() bool

func (Op2) Validate

func (op Op2) Validate()

type Reg

type Reg = common.Reg

func MakeReg

func MakeReg(id RegId, kind Kind) Reg

type RegId

type RegId = common.RegId

type RegIdConfig

type RegIdConfig = common.RegIdConfig

type Save

type Save = common.Save

type Size

type Size = common.Size

func SizeOf

func SizeOf(e Expr) Size

type SoftReg

type SoftReg = common.SoftReg

func MakeSoftReg

func MakeSoftReg(id SoftRegId, kind Kind) SoftReg

type SoftRegId

type SoftRegId = common.SoftRegId

type SoftRegs

type SoftRegs = common.SoftRegs

type Source

type Source []interface{}

argument of Comp.Compile()

func (Source) String

func (s Source) String() string

pretty-print Source

type Stmt

type Stmt interface {
	// contains filtered or unexported methods
}

type Stmt1

type Stmt1 struct {
	Dst  Expr
	Inst Inst1
}

unary statement X Inst, for example X++

func NewStmt1

func NewStmt1(inst Inst1, dst Expr) *Stmt1

func (*Stmt1) String

func (t *Stmt1) String() string

type Stmt2

type Stmt2 struct {
	Dst  Expr
	Src  Expr
	Inst Inst2
}

binary statement X Inst Y, for example X += Y

func NewStmt2

func NewStmt2(inst Inst2, dst Expr, src Expr) *Stmt2

func (*Stmt2) String

func (t *Stmt2) String() string

type Stmt3

type Stmt3 struct {
	Dst  Expr
	DArg Expr
	Src  Expr
	Inst Inst3
}

ternary statement X Y Inst Z, for example X[Y] = Z

func NewStmt3

func NewStmt3(inst Inst3, dst Expr, darg Expr, src Expr) *Stmt3

func (*Stmt3) String

func (t *Stmt3) String() string

type StmtN

type StmtN struct {
	Dst []Expr
	Src []Expr
}

N-ary assignment a,b,c... = p,q,r...

func NewStmtN

func NewStmtN(dst []Expr, src []Expr) *StmtN

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL