hir

package
v0.0.0-...-5ea726b Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ArgMask    = 0x7f
	ArgGeneric = 0x00
	ArgPointer = 0x80
)

Variables

View Source
var GenericRegisters = map[GenericRegister]string{
	R0: "r0",
	R1: "r1",
	R2: "r2",
	R3: "r3",
	R4: "r4",
	Rz: "z",
}
View Source
var PointerRegisters = map[PointerRegister]string{
	P0: "p0",
	P1: "p1",
	P2: "p2",
	P3: "p3",
	P4: "p4",
	P5: "p5",
	Pn: "nil",
}

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func CreateBuilder

func CreateBuilder() *Builder

func (*Builder) ADD

func (self *Builder) ADD(rx GenericRegister, ry GenericRegister, rz GenericRegister) *Ir

func (*Builder) ADDI

func (self *Builder) ADDI(rx GenericRegister, im int64, ry GenericRegister) *Ir

func (*Builder) ADDP

func (self *Builder) ADDP(ps PointerRegister, rx GenericRegister, pd PointerRegister) *Ir

func (*Builder) ADDPI

func (self *Builder) ADDPI(ps PointerRegister, im int64, pd PointerRegister) *Ir

func (*Builder) ANDI

func (self *Builder) ANDI(rx GenericRegister, im int64, ry GenericRegister) *Ir

func (*Builder) Append

func (self *Builder) Append(p *Ir) (r *Ir)

func (*Builder) At

func (self *Builder) At(pc int) string

func (*Builder) BCOPY

func (self *Builder) BCOPY(ps PointerRegister, rx GenericRegister, pd PointerRegister) *Ir

func (*Builder) BEQ

func (self *Builder) BEQ(rx GenericRegister, ry GenericRegister, to string) *Ir

func (*Builder) BEQP

func (self *Builder) BEQP(ps PointerRegister, pd PointerRegister, to string) *Ir

func (*Builder) BGEU

func (self *Builder) BGEU(rx GenericRegister, ry GenericRegister, to string) *Ir

func (*Builder) BLT

func (self *Builder) BLT(rx GenericRegister, ry GenericRegister, to string) *Ir

func (*Builder) BLTU

func (self *Builder) BLTU(rx GenericRegister, ry GenericRegister, to string) *Ir

func (*Builder) BNE

func (self *Builder) BNE(rx GenericRegister, ry GenericRegister, to string) *Ir

func (*Builder) BNEP

func (self *Builder) BNEP(ps PointerRegister, pd PointerRegister, to string) *Ir

func (*Builder) BREAK

func (self *Builder) BREAK() *Ir

func (*Builder) BSI

func (self *Builder) BSI(rx GenericRegister, im int64, ry GenericRegister) *Ir

func (*Builder) BSW

func (self *Builder) BSW(rx GenericRegister, sw []string) *Ir

func (*Builder) BTS

func (self *Builder) BTS(rx GenericRegister, ry GenericRegister, rz GenericRegister) *Ir

func (*Builder) BZERO

func (self *Builder) BZERO(nb int64, pd PointerRegister) *Ir

func (*Builder) Build

func (self *Builder) Build() (r Program)

func (*Builder) CCALL

func (self *Builder) CCALL(fn *CallHandle) *Ir

func (*Builder) GCALL

func (self *Builder) GCALL(fn *CallHandle) *Ir

func (*Builder) IB

func (self *Builder) IB(v int8, rx GenericRegister) *Ir

func (*Builder) ICALL

func (self *Builder) ICALL(vt PointerRegister, vp PointerRegister, mt *CallHandle) *Ir

func (*Builder) IL

func (self *Builder) IL(v int32, rx GenericRegister) *Ir

func (*Builder) IP

func (self *Builder) IP(v interface{}, pd PointerRegister) *Ir

func (*Builder) IQ

func (self *Builder) IQ(v int64, rx GenericRegister) *Ir

func (*Builder) IW

func (self *Builder) IW(v int16, rx GenericRegister) *Ir

func (*Builder) JMP

func (self *Builder) JMP(to string) *Ir

func (*Builder) LB

func (self *Builder) LB(ps PointerRegister, disp int64, rx GenericRegister) *Ir

func (*Builder) LDAP

func (self *Builder) LDAP(id int, pd PointerRegister) *Ir

func (*Builder) LDAQ

func (self *Builder) LDAQ(id int, rx GenericRegister) *Ir

func (*Builder) LL

func (self *Builder) LL(ps PointerRegister, disp int64, rx GenericRegister) *Ir

func (*Builder) LP

func (self *Builder) LP(ps PointerRegister, disp int64, pd PointerRegister) *Ir

func (*Builder) LQ

func (self *Builder) LQ(ps PointerRegister, disp int64, rx GenericRegister) *Ir

func (*Builder) LW

func (self *Builder) LW(ps PointerRegister, disp int64, rx GenericRegister) *Ir

func (*Builder) Label

func (self *Builder) Label(to string)

func (*Builder) MOV

func (self *Builder) MOV(rx GenericRegister, ry GenericRegister) *Ir

func (*Builder) MOVP

func (self *Builder) MOVP(ps PointerRegister, pd PointerRegister) *Ir

func (*Builder) MULI

func (self *Builder) MULI(rx GenericRegister, im int64, ry GenericRegister) *Ir

func (*Builder) Mark

func (self *Builder) Mark(pc int)

func (*Builder) NOP

func (self *Builder) NOP() *Ir

func (*Builder) RET

func (self *Builder) RET() *Ir

func (*Builder) SB

func (self *Builder) SB(rx GenericRegister, pd PointerRegister, disp int64) *Ir

func (*Builder) SHRI

func (self *Builder) SHRI(rx GenericRegister, im int64, ry GenericRegister) *Ir

func (*Builder) SL

func (self *Builder) SL(rx GenericRegister, pd PointerRegister, disp int64) *Ir

func (*Builder) SP

func (self *Builder) SP(ps PointerRegister, pd PointerRegister, disp int64) *Ir

func (*Builder) SQ

func (self *Builder) SQ(rx GenericRegister, pd PointerRegister, disp int64) *Ir

func (*Builder) SUB

func (self *Builder) SUB(rx GenericRegister, ry GenericRegister, rz GenericRegister) *Ir

func (*Builder) SUBI

func (self *Builder) SUBI(rx GenericRegister, im int64, ry GenericRegister) *Ir

func (*Builder) SUBP

func (self *Builder) SUBP(ps PointerRegister, rx GenericRegister, pd PointerRegister) *Ir

func (*Builder) SUBPI

func (self *Builder) SUBPI(ps PointerRegister, im int64, pd PointerRegister) *Ir

func (*Builder) SW

func (self *Builder) SW(rx GenericRegister, pd PointerRegister, disp int64) *Ir

func (*Builder) SWAPL

func (self *Builder) SWAPL(rx GenericRegister, ry GenericRegister) *Ir

func (*Builder) SWAPQ

func (self *Builder) SWAPQ(rx GenericRegister, ry GenericRegister) *Ir

func (*Builder) SWAPW

func (self *Builder) SWAPW(rx GenericRegister, ry GenericRegister) *Ir

func (*Builder) SXLQ

func (self *Builder) SXLQ(rx GenericRegister, ry GenericRegister) *Ir

func (*Builder) XORI

func (self *Builder) XORI(rx GenericRegister, im int64, ry GenericRegister) *Ir

type CallContext

type CallContext struct {
	// contains filtered or unexported fields
}

func (CallContext) Ap

func (self CallContext) Ap(i int) unsafe.Pointer

func (CallContext) Au

func (self CallContext) Au(i int) uint64

func (CallContext) Data

func (self CallContext) Data() unsafe.Pointer

func (CallContext) Itab

func (self CallContext) Itab() *rt.GoItab

func (CallContext) Rp

func (self CallContext) Rp(i int, v unsafe.Pointer)

func (CallContext) Ru

func (self CallContext) Ru(i int, v uint64)

func (CallContext) Verify

func (self CallContext) Verify(args string, rets string) bool

type CallHandle

type CallHandle struct {
	Id   int
	Slot int
	Type CallType
	Func unsafe.Pointer
	// contains filtered or unexported fields
}

func LookupCall

func LookupCall(id int64) *CallHandle

func RegisterCCall

func RegisterCCall(fn unsafe.Pointer, proxy func(CallContext)) (h *CallHandle)

func RegisterGCall

func RegisterGCall(fn interface{}, proxy func(CallContext)) (h *CallHandle)

func RegisterICall

func RegisterICall(mt rt.Method, proxy func(CallContext)) (h *CallHandle)

func (*CallHandle) Call

func (self *CallHandle) Call(r CallState, p *Ir)

func (*CallHandle) Name

func (self *CallHandle) Name() string

func (*CallHandle) String

func (self *CallHandle) String() string

type CallState

type CallState interface {
	Gr(id GenericRegister) uint64
	Pr(id PointerRegister) unsafe.Pointer
	SetGr(id GenericRegister, val uint64)
	SetPr(id PointerRegister, val unsafe.Pointer)
}

type CallType

type CallType uint8
const (
	CCall CallType = iota
	GCall
	ICall
)

type Constness

type Constness byte
const (
	Const Constness = iota
	Volatile
)

type GenericRegister

type GenericRegister uint8
const (
	R0 GenericRegister = iota
	R1
	R2
	R3
	R4
	Rz
)

func (GenericRegister) A

func (self GenericRegister) A() uint8

func (GenericRegister) String

func (self GenericRegister) String() string

func (GenericRegister) Z

func (self GenericRegister) Z() bool

type Ir

type Ir struct {
	Op OpCode
	Rx GenericRegister
	Ry GenericRegister
	Rz GenericRegister
	Ps PointerRegister
	Pd PointerRegister
	An uint8
	Rn uint8
	Ar [8]uint8
	Rr [8]uint8
	Iv int64
	Pr unsafe.Pointer
	Br *Ir
	Ln *Ir
}

func (*Ir) A0

func (self *Ir) A0(v Register) *Ir

func (*Ir) A1

func (self *Ir) A1(v Register) *Ir

func (*Ir) A2

func (self *Ir) A2(v Register) *Ir

func (*Ir) A3

func (self *Ir) A3(v Register) *Ir

func (*Ir) A4

func (self *Ir) A4(v Register) *Ir

func (*Ir) A5

func (self *Ir) A5(v Register) *Ir

func (*Ir) A6

func (self *Ir) A6(v Register) *Ir

func (*Ir) A7

func (self *Ir) A7(v Register) *Ir

func (*Ir) Const

func (self *Ir) Const() *Ir

func (*Ir) Constness

func (self *Ir) Constness() Constness

func (*Ir) Disassemble

func (self *Ir) Disassemble(refs map[*Ir]string) string

func (*Ir) Free

func (self *Ir) Free()

func (*Ir) IsBranch

func (self *Ir) IsBranch() bool

func (*Ir) Likeliness

func (self *Ir) Likeliness() Likeliness

func (*Ir) Likely

func (self *Ir) Likely() *Ir

func (*Ir) R0

func (self *Ir) R0(v Register) *Ir

func (*Ir) R1

func (self *Ir) R1(v Register) *Ir

func (*Ir) R2

func (self *Ir) R2(v Register) *Ir

func (*Ir) R3

func (self *Ir) R3(v Register) *Ir

func (*Ir) R4

func (self *Ir) R4(v Register) *Ir

func (*Ir) R5

func (self *Ir) R5(v Register) *Ir

func (*Ir) R6

func (self *Ir) R6(v Register) *Ir

func (*Ir) R7

func (self *Ir) R7(v Register) *Ir

func (*Ir) Switch

func (self *Ir) Switch() (p []*Ir)

func (*Ir) Unlikely

func (self *Ir) Unlikely() *Ir

func (*Ir) Volatile

func (self *Ir) Volatile() *Ir

type Likeliness

type Likeliness byte
const (
	Likely Likeliness = iota
	Unlikely
)

type OpCode

type OpCode byte
const (
	OP_nop   OpCode = iota // no operation
	OP_ip                  // ptr(Pr) -> Pd
	OP_lb                  // u64(*(* u8)(Ps + Iv)) -> Rx
	OP_lw                  // u64(*(*u16)(Ps + Iv)) -> Rx
	OP_ll                  // u64(*(*u32)(Ps + Iv)) -> Rx
	OP_lq                  //     *(*u64)(Ps + Iv)  -> Rx
	OP_lp                  //     *(*ptr)(Ps + Iv)  -> Pd
	OP_sb                  //  u8(Rx) -> *(*u8)(Pd + Iv)
	OP_sw                  // u16(Rx) -> *(*u16)(Pd + Iv)
	OP_sl                  // u32(Rx) -> *(*u32)(Pd + Iv)
	OP_sq                  //     Rx  -> *(*u64)(Pd + Iv)
	OP_sp                  //     Ps  -> *(*ptr)(Pd + Iv)
	OP_ldaq                // arg[Iv] -> Rx
	OP_ldap                // arg[Iv] -> Pd
	OP_addp                // Ps + Rx -> Pd
	OP_subp                // Ps - Rx -> Pd
	OP_addpi               // Ps + Iv -> Pd
	OP_add                 // Rx + Ry -> Rz
	OP_sub                 // Rx - Ry -> Rz
	OP_bts                 // Ry & (1 << (Rx % PTR_BITS)) != 0 -> Rz, Ry |= 1 << (Rx % PTR_BITS)
	OP_addi                // Rx + Iv -> Ry
	OP_muli                // Rx * Iv -> Ry
	OP_andi                // Rx & Iv -> Ry
	OP_xori                // Rx ^ Iv -> Ry
	OP_shri                // Rx >> Iv -> Ry
	OP_bsi                 // Rx | (1 << Iv) -> Ry
	OP_swapw               // bswap16(Rx) -> Ry
	OP_swapl               // bswap32(Rx) -> Ry
	OP_swapq               // bswap64(Rx) -> Ry
	OP_sxlq                // sign_extend_32_to_64(Rx) -> Ry
	OP_beq                 // if (Rx == Ry) Br.PC -> PC
	OP_bne                 // if (Rx != Ry) Br.PC -> PC
	OP_blt                 // if (Rx <  Ry) Br.PC -> PC
	OP_bltu                // if (u(Rx) <  u(Ry)) Br.PC -> PC
	OP_bgeu                // if (u(Rx) >= u(Ry)) Br.PC -> PC
	OP_beqp                // if (Ps == Pd) Br.PC -> PC
	OP_bnep                // if (Ps == Pd) Br.PC -> PC
	OP_bsw                 // if (u(Rx) <  u(An)) Sw[u(Rx)].PC -> PC
	OP_jmp                 // Br.PC -> PC
	OP_bzero               // memset(Pd, 0, Iv)
	OP_bcopy               // memcpy(Pd, Ps, Rx)
	OP_ccall               // call external C functions
	OP_gcall               // call external Go functions
	OP_icall               // call external Go iface methods
	OP_ret                 // return from function
	OP_break               // trigger a debugger breakpoint
)

type PointerRegister

type PointerRegister uint8
const (
	P0 PointerRegister = iota
	P1
	P2
	P3
	P4
	P5
	Pn
)

func (PointerRegister) A

func (self PointerRegister) A() uint8

func (PointerRegister) String

func (self PointerRegister) String() string

func (PointerRegister) Z

func (self PointerRegister) Z() bool

type Program

type Program struct {
	Head *Ir
}

func (Program) Disassemble

func (self Program) Disassemble() string

func (Program) Free

func (self Program) Free()

type Register

type Register interface {
	fmt.Stringer
	Z() bool
	A() uint8
}

Jump to

Keyboard shortcuts

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