codegen

package
v0.0.0-...-3042a1c Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2017 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AXXX = 0 + iota
	ACALL
	ACHECKNIL
	ADATA
	ADUFFCOPY
	ADUFFZERO
	AEND
	AFUNCDATA
	AGLOBL
	AJMP
	ANOP
	APCDATA
	ARET
	ATEXT
	ATYPE
	AUNDEF
	AUSEFIELD
	AVARDEF
	AVARKILL
	A_ARCHSPECIFIC
)
View Source
const (
	ABase386 = (1 + iota) << 12
	ABaseARM
	ABaseAMD64
	ABasePPC64
	ABaseARM64
	AMask = 1<<12 - 1 // AND with this to use the opcode as an array index.
)
View Source
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)
)
View Source
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
)
View Source
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
)
View Source
const REG_NONE = 0
View Source
const (
	TYPE_NONE = 0
)

Variables

View Source
var Anames = []string{
	"XXX",
	"CALL",
	"CHECKNIL",
	"DATA",
	"DUFFCOPY",
	"DUFFZERO",
	"END",
	"FUNCDATA",
	"GLOBL",
	"JMP",
	"NOP",
	"PCDATA",
	"RET",
	"TEXT",
	"TYPE",
	"UNDEF",
	"USEFIELD",
	"VARDEF",
	"VARKILL",
}
View Source
var Debug_checknil int
View Source
var Maxarg int64

Functions

func Aconv

func Aconv(a int) string

func Assemble

func Assemble(fn []*Prog) (assembly string)

func Bool2int

func Bool2int(b bool) int

func BuildSSA

func BuildSSA(fnDecl *gst.FuncDecl, pkgName string, log bool) (ssafn *ssa.Func, usessa bool)

BuildSSA parses the function, fn, which must be in ssa form and returns the corresponding ssa.Func

func Dconv

func Dconv(p *Prog, a *Addr) string

func Fatalf

func Fatalf(format string, args ...interface{})

func FuncProto

func FuncProto(name string, frameSize, argsSize int) string

func GenAsm

func GenAsm(f *ssa.Func) (asm string, ok bool)

func GenGoProto

func GenGoProto(f *ssa.Func) (proto string, ok bool)

func GoProto

func GoProto(fn *types.Func) (string, string, string)

func Mconv

func Mconv(a *Addr) string

func Op2

func Op2(op ssa.Op, src OpValue, dst OpValue)

func Preamble

func Preamble() string

func ProgAssembly

func ProgAssembly(p *Prog) string

func Rconv

func Rconv(reg int) string

func RegisterOpcode

func RegisterOpcode(lo int, Anames []string)

RegisterOpcode binds a list of instruction names to a given instruction number range.

func RegisterRegister

func RegisterRegister(lo, hi int, Rconv func(int) string)

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 StdSizes

func StdSizes() types.StdSizes

func TypeCheckFn

func TypeCheckFn(fnDecl *gst.FuncDecl, log bool) (function *types.Func, er error)

func Warn

func Warn(fmt_ string, args ...interface{})

func Warnl

func Warnl(line int, fmt_ string, args ...interface{})

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 Block

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

func (*Block) Name

func (b *Block) Name() string

type Ctx

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

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 struct {
	Goarm    int32
	Headtype int
	//Arch         *LinkArch
	Flag_shared  int32
	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 M128

type M128 [4]float32

type M128d

type M128d [2]float64

type M128i

type M128i [16]byte

SSE2 types

type Node

type Node struct {
	Var ssaVar
	// contains filtered or unexported fields
}

func ExprNode

func ExprNode(n ast.Expr, ctx Ctx) *Node

func NewNode

func NewNode(n ast.Node, ctx Ctx) *Node

func (*Node) Class

func (n *Node) Class() NodeClass

func (*Node) Name

func (n *Node) Name() string

func (*Node) String

func (n *Node) String() string

func (*Node) Typ

func (n *Node) Typ() ssa.Type

func (*Node) Xoffset

func (n *Node) Xoffset() int64

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 OpValue

type OpValue interface {
}

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 CreateProg(as int) *Prog

func GenProg

func GenProg(f *ssa.Func) (fnProg []*Prog, ok bool)

func NewProg

func NewProg() *Prog

func (*Prog) From3Offset

func (p *Prog) From3Offset() int64

From3Offset returns From3.Offset, or 0 when From3 is nil.

func (*Prog) From3Type

func (p *Prog) From3Type() int16

From3Type returns From3.Type, or TYPE_NONE when From3 is nil.

func (*Prog) Line

func (p *Prog) Line() string

func (*Prog) Sprint

func (p *Prog) Sprint(verbose bool) string

func (*Prog) String

func (p *Prog) String() string

type Type

type Type struct {
	types.Type
}

func (*Type) Alignment

func (t *Type) Alignment() int64

func (*Type) Array

func (t *Type) Array() *types.Array

Array returns *types.Array if t.Type is *types.Array else nil is returned.

func (*Type) Basic

func (t *Type) Basic() *types.Basic

Basic returns *types.Basic if t.Type is *types.Basic else nil is returned.

func (*Type) Bound

func (t *Type) Bound() int64

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

func (t *Type) Compare(t2 ssa.Type) ssa.Cmp

compare types, returning one of CMPlt, CMPeq, CMPgt.

func (*Type) Elem

func (t *Type) Elem() ssa.Type

Elem, if t.Type is []T or *T or [n]T, return T, otherwise return nil

func (*Type) ElemType

func (t *Type) ElemType() ssa.Type

given []T or *T or [n]T, return T

func (*Type) Equal

func (t *Type) Equal(v ssa.Type) bool

func (*Type) FieldName

func (t *Type) FieldName(i int) string

name of ith field of the struct

func (*Type) FieldOff

func (t *Type) FieldOff(i int) int64

FieldOff returns the offset of ith field of the struct and panics on error

func (*Type) FieldType

func (t *Type) FieldType(i int) ssa.Type

FieldTypes returns the type of ith field of the struct and panics on error

func (*Type) IsArray

func (t *Type) IsArray() bool

func (*Type) IsBasic

func (t *Type) IsBasic() bool

func (*Type) IsBasicInfoFlag

func (t *Type) IsBasicInfoFlag(flag types.BasicInfo) bool

IsBasicInfoFlag returns true if t.Type is types.Basic and the BasicInfo for t.Type matches flags, otherwise false is returned

func (*Type) IsBoolean

func (t *Type) IsBoolean() bool

func (*Type) IsChan

func (t *Type) IsChan() bool

func (*Type) IsComplex

func (t *Type) IsComplex() bool

func (*Type) IsFlags

func (t *Type) IsFlags() bool

func (*Type) IsFloat

func (t *Type) IsFloat() bool

func (*Type) IsInteger

func (t *Type) IsInteger() bool

func (*Type) IsInterface

func (t *Type) IsInterface() bool

func (*Type) IsMap

func (t *Type) IsMap() bool

func (*Type) IsMemory

func (t *Type) IsMemory() bool

func (*Type) IsPtr

func (t *Type) IsPtr() bool

func (*Type) IsPtrShaped

func (t *Type) IsPtrShaped() bool

func (*Type) IsSigned

func (t *Type) IsSigned() bool

func (*Type) IsSlice

func (t *Type) IsSlice() bool

func (*Type) IsString

func (t *Type) IsString() bool

func (*Type) IsStruct

func (t *Type) IsStruct() bool

func (*Type) IsTuple

func (t *Type) IsTuple() bool

func (*Type) IsVoid

func (t *Type) IsVoid() bool

func (*Type) NumElem

func (t *Type) NumElem() int64

NumElem returns the # of elements of an array and panics on error

func (*Type) NumFields

func (t *Type) NumFields() int

NumFields returns the # of fields of a struct, panics if t is not a types.Struct

func (*Type) PtrTo

func (t *Type) PtrTo() ssa.Type

PtrTo, given T, returns *T

func (*Type) SimpleString

func (t *Type) SimpleString() string

SimpleString is a coarser generic description of T, e.g. T's underlying type

func (*Type) Size

func (t *Type) Size() int64

func (*Type) String

func (t *Type) String() string

func (*Type) Struct

func (t *Type) Struct() *types.Struct

Struct returns *types.Struct if t.Type is *types.Struct else nil is returned.

func (*Type) Width

func (t *Type) Width() int64

Jump to

Keyboard shortcuts

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