Documentation ¶
Index ¶
- Constants
- Variables
- func Aconv(a int) string
- func Assemble(fn []*Prog) (assembly string)
- func Bool2int(b bool) int
- func BuildSSA(file, pkgName, fn string, log bool) (ssafn *ssa.Func, usessa bool)
- func Dconv(p *Prog, a *Addr) string
- func Fatalf(format string, args ...interface{})
- func FuncProto(name string, frameSize, argsSize int) string
- func GoProto(fn *types.Func) (string, string, string)
- func Mconv(a *Addr) string
- func Op2(op ssa.Op, src OpValue, dst OpValue)
- func Preamble() string
- func ProgAssembly(p *Prog) string
- func Rconv(reg int) string
- func RegisterOpcode(lo int, Anames []string)
- func RegisterRegister(lo, hi int, Rconv func(int) string)
- func StdSizes() types.StdSizes
- func TypeCheckFn(file, pkgName, fn string, log bool) (fileTok *token.File, fileAst *ast.File, fnDecl *ast.FuncDecl, ...)
- func Warn(fmt_ string, args ...interface{})
- func Warnl(line int, fmt_ string, args ...interface{})
- type Addr
- type Block
- type Ctx
- type LSym
- type Link
- type M128
- type M128d
- type M128i
- type Node
- type NodeClass
- type NodeOp
- type OpValue
- type Prog
- type Type
- func (t *Type) Alignment() int64
- func (t *Type) Array() *types.Array
- func (t *Type) Basic() *types.Basic
- func (t *Type) Bound() int64
- func (t *Type) Compare(t2 ssa.Type) ssa.Cmp
- func (t *Type) Elem() ssa.Type
- func (t *Type) ElemType() ssa.Type
- func (t *Type) Equal(v ssa.Type) bool
- func (t *Type) FieldName(i int) string
- func (t *Type) FieldOff(i int) int64
- func (t *Type) FieldType(i int) ssa.Type
- func (t *Type) IsArray() bool
- func (t *Type) IsBasic() bool
- func (t *Type) IsBasicInfoFlag(flag types.BasicInfo) bool
- func (t *Type) IsBoolean() bool
- func (t *Type) IsChan() bool
- func (t *Type) IsComplex() bool
- func (t *Type) IsFlags() bool
- func (t *Type) IsFloat() bool
- func (t *Type) IsInteger() bool
- func (t *Type) IsInterface() bool
- func (t *Type) IsMap() bool
- func (t *Type) IsMemory() bool
- func (t *Type) IsPtr() bool
- func (t *Type) IsPtrShaped() bool
- func (t *Type) IsSigned() bool
- func (t *Type) IsSlice() bool
- func (t *Type) IsString() bool
- func (t *Type) IsStruct() bool
- func (t *Type) IsVoid() bool
- func (t *Type) NumElem() int64
- func (t *Type) NumFields() int
- func (t *Type) PtrTo() ssa.Type
- func (t *Type) SimpleString() string
- func (t *Type) Size() int64
- func (t *Type) String() string
- func (t *Type) Struct() *types.Struct
- func (t *Type) Width() int64
Constants ¶
const ( AXXX = 0 + iota ACALL ACHECKNIL ADATA ADUFFCOPY ADUFFZERO AEND AFUNCDATA AGLOBL AJMP ANOP APCDATA ARET ATEXT ATYPE AUNDEF AUSEFIELD AVARDEF AVARKILL A_ARCHSPECIFIC )
const ( ABase386 = (1 + iota) << 12 ABaseARM ABaseAMD64 ABasePPC64 ABaseARM64 AMask = 1<<12 - 1 // AND with this to use the opcode as an array index. )
const ( // Because of masking operations in the encodings, each register // space should start at 0 modulo some power of 2. RBase386 = 1 * 1024 RBaseAMD64 = 2 * 1024 RBaseARM = 3 * 1024 RBasePPC64 = 4 * 1024 // range [4k, 8k) RBaseARM64 = 8 * 1024 // range [8k, 12k) )
const ( NAME_NONE = 0 + iota NAME_EXTERN NAME_STATIC NAME_AUTO NAME_PARAM // A reference to name@GOT(SB) is a reference to the entry in the global offset // table for 'name'. NAME_GOTREF )
const ( TYPE_BRANCH = 5 + iota TYPE_TEXTSIZE TYPE_MEM TYPE_CONST TYPE_FCONST TYPE_SCONST TYPE_REG TYPE_ADDR TYPE_SHIFT TYPE_REGREG TYPE_REGREG2 TYPE_INDIR TYPE_REGLIST )
const REG_NONE = 0
const (
TYPE_NONE = 0
)
Variables ¶
var Anames = []string{
"XXX",
"CALL",
"CHECKNIL",
"DATA",
"DUFFCOPY",
"DUFFZERO",
"END",
"FUNCDATA",
"GLOBL",
"JMP",
"NOP",
"PCDATA",
"RET",
"TEXT",
"TYPE",
"UNDEF",
"USEFIELD",
"VARDEF",
"VARKILL",
}
var Debug_checknil int
var Maxarg int64
var Typ = []*Type{ types.Bool: &Type{types.Typ[types.Bool]}, types.Int: &Type{types.Typ[types.Int]}, types.Int8: &Type{types.Typ[types.Int8]}, types.Int16: &Type{types.Typ[types.Int16]}, types.Int32: &Type{types.Typ[types.Int32]}, types.Int64: &Type{types.Typ[types.Int64]}, types.Uint: &Type{types.Typ[types.Uint]}, types.Uint8: &Type{types.Typ[types.Uint8]}, types.Uint16: &Type{types.Typ[types.Uint16]}, types.Uint32: &Type{types.Typ[types.Uint32]}, types.Uint64: &Type{types.Typ[types.Uint64]}, types.Uintptr: &Type{types.Typ[types.Uintptr]}, types.Float32: &Type{types.Typ[types.Float32]}, types.Float64: &Type{types.Typ[types.Float64]}, types.Complex64: &Type{types.Typ[types.Complex64]}, types.Complex128: &Type{types.Typ[types.Complex128]}, types.String: &Type{types.Typ[types.String]}, types.UnsafePointer: &Type{types.Typ[types.UnsafePointer]}, }
Functions ¶
func BuildSSA ¶
BuildSSA parses the function, fn, which must be in ssa form and returns the corresponding ssa.Func
func ProgAssembly ¶
func RegisterOpcode ¶
RegisterOpcode binds a list of instruction names to a given instruction number range.
func RegisterRegister ¶
RegisterRegister binds a pretty-printer (Rconv) for register numbers to a given register number range. Lo is inclusive, hi exclusive (valid registers are lo through hi-1).
func TypeCheckFn ¶
Types ¶
type Addr ¶
type Addr struct { Type int16 Reg int16 Index int16 Scale int16 // Sometimes holds a register. Name int8 Class int8 Etype uint8 Offset int64 Width int64 Sym *LSym Gotype *LSym // argument value: // for TYPE_SCONST, a string // for TYPE_FCONST, a float64 // for TYPE_BRANCH, a *Prog (optional) // for TYPE_TEXTSIZE, an int32 (optional) Val interface{} Node interface{} // for use by compiler }
type LSym ¶
type LSym struct { Name string Type int16 Version int16 Dupok uint8 Cfunc uint8 Nosplit uint8 Leaf uint8 Seenglobl uint8 Onlist uint8 // Local means make the symbol local even when compiling Go code to reference Go // symbols in other shared libraries, as in this mode symbols are global by // default. "local" here means in the sense of the dynamic linker, i.e. not // visible outside of the module (shared library or executable) that contains its // definition. (When not compiling to support Go shared libraries, all symbols are // local in this sense unless there is a cgo_export_* directive). Local bool Args int32 Locals int32 Value int64 Size int64 }
type Link ¶
type Link struct { Goarm int32 Headtype int //Arch *LinkArch Flag_dynlink bool //Bso *Biobuf Pathname string Windows int32 Goroot string Goroot_final string Enforce_data_order int32 //Hash map[SymVer]*LSym //LineHist LineHist Imports []string //Plist *Plist //Plast *Plist Sym_div *LSym Sym_divu *LSym Sym_mod *LSym Sym_modu *LSym Tlsg *LSym Curp *Prog Printp *Prog Blitrl *Prog Elitrl *Prog Rexflag int Rep int Repn int Lock int Asmode int Andptr []byte And [100]uint8 Instoffset int64 Autosize int32 Armsize int32 Pc int64 Tlsoffset int //Diag func(string, ...interface{}) Mode int Cursym *LSym Version int Textp *LSym Etextp *LSym }
type NodeClass ¶
type NodeClass uint8
const ( Pxxx NodeClass = iota PEXTERN // global variable PAUTO // local variables PPARAM // input arguments PPARAMOUT // output results PPARAMREF // closure variable reference PFUNC // global function PDISCARD // discard during parse of duplicate import PHEAP NodeClass = 1 << 7 // an extra bit to identify an escaped variable )
declaration context
type NodeOp ¶
type NodeOp uint8
Node ops.
const ( OXXX NodeOp = iota // names ONAME // var, const or func name ONONAME // unnamed arg or return value: f(int, string) (int, error) { etc } OTYPE // type name OPACK // import OLITERAL // literal // expressions OADD // Left + Right OSUB // Left - Right OOR // Left | Right OXOR // Left ^ Right OADDSTR // Left + Right (string addition) OADDR // &Left OANDAND // Left && Right OAPPEND // append(List) OARRAYBYTESTR // Type(Left) (Type is string, Left is a []byte) OARRAYBYTESTRTMP // Type(Left) (Type is string, Left is a []byte, ephemeral) OARRAYRUNESTR // Type(Left) (Type is string, Left is a []rune) OSTRARRAYBYTE // Type(Left) (Type is []byte, Left is a string) OSTRARRAYBYTETMP // Type(Left) (Type is []byte, Left is a string, ephemeral) OSTRARRAYRUNE // Type(Left) (Type is []rune, Left is a string) OAS // Left = Right or (if Colas=true) Left := Right OAS2 // List = Rlist (x, y, z = a, b, c) OAS2FUNC // List = Rlist (x, y = f()) OAS2RECV // List = Rlist (x, ok = <-c) OAS2MAPR // List = Rlist (x, ok = m["foo"]) OAS2DOTTYPE // List = Rlist (x, ok = I.(int)) OASOP // Left Etype= Right (x += y) OASWB // Left = Right (with write barrier) OCALL // Left(List) (function call, method call or type conversion) OCALLFUNC // Left(List) (function call f(args)) OCALLMETH // Left(List) (direct method call x.Method(args)) OCALLINTER // Left(List) (interface method call x.Method(args)) OCALLPART // Left.Right (method expression x.Method, not called) OCAP // cap(Left) OCLOSE // close(Left) OCLOSURE // func Type { Body } (func literal) OCMPIFACE // Left Etype Right (interface comparison, x == y or x != y) OCMPSTR // Left Etype Right (string comparison, x == y, x < y, etc) OCOMPLIT // Right{List} (composite literal, not yet lowered to specific form) OMAPLIT // Type{List} (composite literal, Type is map) OSTRUCTLIT // Type{List} (composite literal, Type is struct) OARRAYLIT // Type{List} (composite literal, Type is array or slice) OPTRLIT // &Left (left is composite literal) OCONV // Type(Left) (type conversion) OCONVIFACE // Type(Left) (type conversion, to interface) OCONVNOP // Type(Left) (type conversion, no effect) OCOPY // copy(Left, Right) ODCL // var Left (declares Left of type Left.Type) // Used during parsing but don't last. ODCLFUNC // func f() or func (r) f() ODCLFIELD // struct field, interface field, or func/method argument/return value. ODCLCONST // const pi = 3.14 ODCLTYPE // type Int int ODELETE // delete(Left, Right) ODOT // Left.Right (Left is of struct type) ODOTPTR // Left.Right (Left is of pointer to struct type) ODOTMETH // Left.Right (Left is non-interface, Right is method name) ODOTINTER // Left.Right (Left is interface, Right is method name) OXDOT // Left.Right (before rewrite to one of the preceding) ODOTTYPE // Left.Right or Left.Type (.Right during parsing, .Type once resolved) ODOTTYPE2 // Left.Right or Left.Type (.Right during parsing, .Type once resolved; on rhs of OAS2DOTTYPE) OEQ // Left == Right ONE // Left != Right OLT // Left < Right OLE // Left <= Right OGE // Left >= Right OGT // Left > Right OIND // *Left OINDEX // Left[Right] (index of array or slice) OINDEXMAP // Left[Right] (index of map) OKEY // Left:Right (key:value in struct/array/map literal, or slice index pair) OPARAM // variant of ONAME for on-stack copy of a parameter or return value that escapes. OLEN // len(Left) OMAKE // make(List) (before type checking converts to one of the following) OMAKECHAN // make(Type, Left) (type is chan) OMAKEMAP // make(Type, Left) (type is map) OMAKESLICE // make(Type, Left, Right) (type is slice) OMUL // Left * Right ODIV // Left / Right OMOD // Left % Right OLSH // Left << Right ORSH // Left >> Right OAND // Left & Right OANDNOT // Left &^ Right ONEW // new(Left) ONOT // !Left OCOM // ^Left OPLUS // +Left OMINUS // -Left OOROR // Left || Right OPANIC // panic(Left) OPRINT // print(List) OPRINTN // println(List) OPAREN // (Left) OSEND // Left <- Right OSLICE // Left[Right.Left : Right.Right] (Left is untypechecked or slice; Right.Op==OKEY) OSLICEARR // Left[Right.Left : Right.Right] (Left is array) OSLICESTR // Left[Right.Left : Right.Right] (Left is string) OSLICE3 // Left[R.Left : R.R.Left : R.R.R] (R=Right; Left is untypedchecked or slice; R.Op and R.R.Op==OKEY) OSLICE3ARR // Left[R.Left : R.R.Left : R.R.R] (R=Right; Left is array; R.Op and R.R.Op==OKEY) ORECOVER // recover() ORECV // <-Left ORUNESTR // Type(Left) (Type is string, Left is rune) OSELRECV // Left = <-Right.Left: (appears as .Left of OCASE; Right.Op == ORECV) OSELRECV2 // List = <-Right.Left: (apperas as .Left of OCASE; count(List) == 2, Right.Op == ORECV) OIOTA // iota OREAL // real(Left) OIMAG // imag(Left) OCOMPLEX // complex(Left, Right) // statements OBLOCK // { List } (block of code) OBREAK // break OCASE // case List: Nbody (select case after processing; List==nil means default) OXCASE // case List: Nbody (select case before processing; List==nil means default) OCONTINUE // continue ODEFER // defer Left (Left must be call) OEMPTY // no-op (empty statement) OFALL // fallthrough (after processing) OXFALL // fallthrough (before processing) OFOR // for Ninit; Left; Right { Nbody } OGOTO // goto Left OIF // if Ninit; Left { Nbody } else { Rlist } OLABEL // Left: OPROC // go Left (Left must be call) ORANGE // for List = range Right { Nbody } ORETURN // return List OSELECT // select { List } (List is list of OXCASE or OCASE) OSWITCH // switch Ninit; Left { List } (List is a list of OXCASE or OCASE) OTYPESW // List = Left.(type) (appears as .Left of OSWITCH) // types OTCHAN // chan int OTMAP // map[string]int OTSTRUCT // struct{} OTINTER // interface{} OTFUNC // func() OTARRAY // []int, [8]int, [N]int or [...]int // misc ODDD // func f(args ...int) or f(l...) or var a = [...]int{0, 1, 2}. ODDDARG // func f(args ...int), introduced by escape analysis. OINLCALL // intermediary representation of an inlined call. OEFACE // itable and data words of an empty-interface value. OITAB // itable word of an interface value. OSPTR // base pointer of a slice or string. OCLOSUREVAR // variable reference at beginning of closure function OCFUNC // reference to c function pointer (not go func value) OCHECKNIL // emit code to ensure pointer/interface not nil OVARKILL // variable is dead // thearch-specific registers OREGISTER // a register, such as AX. OINDREG // offset plus indirect of a register, such as 8(SP). // arch-specific opcodes OCMP // compare: ACMP. ODEC // decrement: ADEC. OINC // increment: AINC. OEXTEND // extend: ACWD/ACDQ/ACQO. OHMUL // high mul: AMUL/AIMUL for unsigned/signed (OMUL uses AIMUL for both). OLROT // left rotate: AROL. ORROTC // right rotate-carry: ARCR. ORETJMP // return to other function OPS // compare parity set (for x86 NaN check) OPC // compare parity clear (for x86 NaN check) OSQRT // sqrt(float64), on systems that have hw support OGETG // runtime.getg() (read g pointer) OEND )
type Prog ¶
type Prog struct { Ctxt *Link Link *Prog From Addr From3 *Addr // optional To Addr Opt interface{} Forwd *Prog Pcond *Prog Rel *Prog // Source of forward jumps on x86; pcrel on arm Pc int64 Lineno int32 Spadj int32 As int16 Reg int16 RegTo2 int16 // 2nd register output operand Mark uint16 Optab uint16 Scond uint8 Back uint8 Ft uint8 Tt uint8 Isize uint8 Mode int8 }
func CreateProg ¶
func (*Prog) From3Offset ¶
From3Offset returns From3.Offset, or 0 when From3 is nil.
type Type ¶
func (*Type) Bound ¶
Bound returns the num elements if t is an array, if t is a slice it returns -1, and if t is neither an array or slice it panics
func (*Type) IsBasicInfoFlag ¶
IsBasicInfoFlag returns true if t.Type is types.Basic and the BasicInfo for t.Type matches flags, otherwise false is returned
func (*Type) IsInterface ¶
func (*Type) IsPtrShaped ¶
func (*Type) NumFields ¶
NumFields returns the # of fields of a struct, panics if t is not a types.Struct
func (*Type) SimpleString ¶
SimpleString is a coarser generic description of T, e.g. T's underlying type