Documentation
¶
Overview ¶
Package ssa/interp defines an interpreter for the SSA representation of Go programs.
This interpreter is provided as an adjunct for testing the SSA construction algorithm. Its purpose is to provide a minimal metacircular implementation of the dynamic semantics of each SSA instruction. It is not, and will never be, a production-quality Go interpreter.
The following is a partial list of Go features that are currently unsupported or incomplete in the interpreter.
* Unsafe operations, including all uses of unsafe.Pointer, are impossible to support given the "boxed" value representation we have chosen.
* The reflect package is only partially implemented.
* The "testing" package is no longer supported because it depends on low-level details that change too often.
* "sync/atomic" operations are not atomic due to the "boxed" value representation: it is not possible to read, modify and write an interface value atomically. As a consequence, Mutexes are currently broken.
* recover is only partially implemented. Also, the interpreter makes no attempt to distinguish target panics from interpreter crashes.
* the sizes of the int, uint and uintptr types in the target program are assumed to be the same as those of the interpreter itself.
* all values occupy space, even those of types defined by the spec to have zero size, e.g. struct{}. This can cause asymptotic performance degradation.
* os.Exit is implemented using panic, causing deferred functions to run.
Index ¶
- Variables
- func AllMethod(typ reflect.Type, enableUnexport bool) []reflect.Method
- func CreateTestMainPackage(pkg *ssa.Package) (*ssa.Package, error)deprecated
- func Field(v interface{}, index int) (interface{}, error)
- func FieldAddr(v interface{}, index int) (interface{}, error)
- func FindTests(pkg *ssa.Package) (tests, benchmarks, examples []*ssa.Function, main *ssa.Function)deprecated
- func IntuitiveMethodSet(T types.Type) []*types.Selection
- func IsConstNil(v ssa.Value) bool
- func IsNil(v reflect.Value) bool
- func RegisterExternal(key string, i interface{})
- func RegisterFileProcess(ext string, fn SourceProcessFunc)
- func RegisterPackage(pkg *Package)
- func Run(path string, args []string, mode Mode) (exitCode int, err error)
- func RunFile(filename string, src interface{}, args []string, mode Mode) (exitCode int, err error)
- func RunTest(path string, args []string, mode Mode) error
- func SetValue(v reflect.Value, x reflect.Value)
- type Context
- func (ctx *Context) BuildPackage(fset *token.FileSet, pkg *types.Package, files []*ast.File) (*ssa.Package, *types.Info, error)
- func (c *Context) LoadAstFile(fset *token.FileSet, file *ast.File) (*ssa.Package, error)
- func (c *Context) LoadAstPackage(fset *token.FileSet, apkg *ast.Package) (*ssa.Package, error)
- func (c *Context) LoadDir(fset *token.FileSet, path string) (pkgs []*ssa.Package, first error)
- func (c *Context) LoadFile(fset *token.FileSet, filename string, src interface{}) (*ssa.Package, error)
- func (c *Context) NewInterp(mainPkg *ssa.Package) (*Interp, error)
- func (c *Context) Run(path string, args []string) (exitCode int, err error)
- func (c *Context) RunFile(filename string, src interface{}, args []string) (exitCode int, err error)
- func (c *Context) RunFunc(mainPkg *ssa.Package, fnname string, args ...Value) (ret Value, err error)
- func (c *Context) RunPkg(mainPkg *ssa.Package, input string, args []string) (exitCode int, err error)
- func (c *Context) RunTest(path string, args []string) error
- func (c *Context) SetDebug(fn func(*DebugInfo))
- func (c *Context) TestPkg(pkgs []*ssa.Package, input string, args []string) error
- type DebugInfo
- type FindMethod
- type Importer
- type Interp
- func (i *Interp) FindMethod(mtyp reflect.Type, fn *types.Func) func([]reflect.Value) []reflect.Value
- func (i *Interp) GetConst(key string) (constant.Value, bool)
- func (i *Interp) GetFunc(key string) (interface{}, bool)
- func (i *Interp) GetType(key string) (reflect.Type, bool)
- func (i *Interp) GetVarAddr(key string) (interface{}, bool)
- func (i *Interp) Run(entry string) (exitCode int, err error)
- func (i *Interp) RunFunc(name string, args ...Value) (r Value, err error)
- type Loader
- type Mode
- type NamedType
- type Package
- type SourceProcessFunc
- type Tuple
- type TypedConst
- type TypesLoader
- func (r *TypesLoader) GetPackage(pkg string) *types.Package
- func (r *TypesLoader) Import(path string) (*types.Package, error)
- func (r *TypesLoader) Insert(v reflect.Value)
- func (r *TypesLoader) InsertAlias(p *types.Package, name string, rt reflect.Type)
- func (r *TypesLoader) InsertConst(p *types.Package, name string, typ types.Type, c constant.Value)
- func (r *TypesLoader) InsertFunc(p *types.Package, name string, v reflect.Value)
- func (r *TypesLoader) InsertInterface(p *types.Package, name string, rt reflect.Type)
- func (r *TypesLoader) InsertNamedType(p *types.Package, name string, t NamedType)
- func (r *TypesLoader) InsertTypedConst(p *types.Package, name string, v TypedConst)
- func (r *TypesLoader) InsertUntypedConst(p *types.Package, name string, v UntypedConst)
- func (r *TypesLoader) InsertVar(p *types.Package, name string, v reflect.Value)
- func (r *TypesLoader) Installed(path string) (pkg *Package, ok bool)
- func (r *TypesLoader) LookupPackage(pkgpath string) (*types.Package, bool)
- func (r *TypesLoader) LookupReflect(typ types.Type) (reflect.Type, bool)
- func (r *TypesLoader) LookupType(typ string) types.Type
- func (r *TypesLoader) LookupTypes(typ reflect.Type) (types.Type, bool)
- func (r *TypesLoader) Packages() (pkgs []*types.Package)
- func (r *TypesLoader) ToType(rt reflect.Type) types.Type
- type TypesRecord
- func (r *TypesRecord) Load(pkg *ssa.Package)
- func (r *TypesRecord) LoadType(typ types.Type) reflect.Type
- func (r *TypesRecord) LookupLocalTypes(rt reflect.Type) (typ types.Type, ok bool)
- func (r *TypesRecord) LookupReflect(typ types.Type) (rt reflect.Type, ok bool)
- func (r *TypesRecord) LookupTypes(rt reflect.Type) (typ types.Type, ok bool)
- func (r *TypesRecord) ToType(typ types.Type) reflect.Type
- func (r *TypesRecord) ToTypeList(tuple *types.Tuple) []reflect.Type
- type UntypedConst
- type Value
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoPackage = errors.New("no package") ErrPackage = errors.New("package contain errors") ErrNotFoundMain = errors.New("not found main package") ErrTestFailed = errors.New("test failed") ErrNotFoundPackage = errors.New("not found package") ErrNotFoundImporter = errors.New("not found provider for types.Importer") )
var CapturedOutput *bytes.Buffer
If CapturedOutput is non-nil, all writes by the interpreted program to file descriptors 1 and 2 will also be written to CapturedOutput.
(The $GOROOT/test system requires that the test be considered a failure if "BUG" appears in the combined stdout/stderr output, even if it exits zero. This is a global variable shared by all interpreters in the same process.)
Functions ¶
func CreateTestMainPackage
deprecated
CreateTestMainPackage creates and returns a synthetic "testmain" package for the specified package if it defines tests, benchmarks or executable examples, or nil otherwise. The new package is named "main" and provides a function named "main" that runs the tests, similar to the one that would be created by the 'go test' tool.
Subsequent calls to prog.AllPackages include the new package. The package pkg must belong to the program prog.
Deprecated: Use golang.org/x/tools/go/packages to access synthetic testmain packages.
func FindTests
deprecated
added in
v0.2.6
FindTests returns the Test, Benchmark, and Example functions (as defined by "go test") defined in the specified package, and its TestMain function, if any.
Deprecated: Use golang.org/x/tools/go/packages to access synthetic testmain packages.
func IntuitiveMethodSet ¶ added in v0.2.0
golang.org/x/tools/go/types/typeutil.IntuitiveMethodSet
func IsConstNil ¶
func RegisterExternal ¶
func RegisterExternal(key string, i interface{})
register external interface
func RegisterFileProcess ¶ added in v0.2.10
func RegisterFileProcess(ext string, fn SourceProcessFunc)
Types ¶
type Context ¶ added in v0.2.0
type Context struct { Loader Loader // types loader Mode Mode // mode ParserMode parser.Mode // parser mode BuilderMode ssa.BuilderMode // ssa builder mode External types.Importer // external import Sizes types.Sizes DebugFunc func(*DebugInfo) }
func NewContext ¶ added in v0.2.0
func (*Context) BuildPackage ¶ added in v0.2.0
func (*Context) LoadAstFile ¶ added in v0.2.0
func (*Context) LoadAstPackage ¶ added in v0.2.0
type FindMethod ¶ added in v0.2.0
type Importer ¶ added in v0.2.0
type Importer struct {
// contains filtered or unexported fields
}
func NewImporter ¶ added in v0.2.0
type Interp ¶ added in v0.2.0
type Interp struct {
// contains filtered or unexported fields
}
State shared between all interpreted goroutines.
func (*Interp) FindMethod ¶ added in v0.2.0
func (*Interp) GetVarAddr ¶ added in v0.2.11
type Loader ¶ added in v0.2.0
type Loader interface { Import(path string) (*types.Package, error) Installed(path string) (*Package, bool) Packages() []*types.Package LookupReflect(typ types.Type) (reflect.Type, bool) LookupTypes(typ reflect.Type) (types.Type, bool) }
types loader interface
func NewTypesLoader ¶ added in v0.2.0
install package and readonly
type Mode ¶
type Mode uint
Mode is a bitmask of options affecting the interpreter.
const ( DisableRecover Mode = 1 << iota // Disable recover() in target programs; show interpreter crash instead. DisableUnexportMethods // Disable unexport methods EnableTracing // Print a trace of all instructions as they are interpreted. EnableDumpPackage // Print package EnableDumpInstr // Print instr type & value )
type Package ¶ added in v0.2.0
type Package struct { Name string Path string Interfaces map[string]reflect.Type NamedTypes map[string]NamedType AliasTypes map[string]reflect.Type Vars map[string]reflect.Value Funcs map[string]reflect.Value TypedConsts map[string]TypedConst UntypedConsts map[string]UntypedConst Deps map[string]string // contains filtered or unexported fields }
func LookupPackage ¶ added in v0.2.0
lookup register pkgs
type SourceProcessFunc ¶ added in v0.2.10
type TypesLoader ¶ added in v0.2.0
type TypesLoader struct {
// contains filtered or unexported fields
}
func (*TypesLoader) GetPackage ¶ added in v0.2.0
func (r *TypesLoader) GetPackage(pkg string) *types.Package
func (*TypesLoader) Import ¶ added in v0.2.0
func (r *TypesLoader) Import(path string) (*types.Package, error)
func (*TypesLoader) Insert ¶ added in v0.2.0
func (r *TypesLoader) Insert(v reflect.Value)
func (*TypesLoader) InsertAlias ¶ added in v0.2.0
func (*TypesLoader) InsertConst ¶ added in v0.2.0
func (*TypesLoader) InsertFunc ¶ added in v0.2.0
func (*TypesLoader) InsertInterface ¶ added in v0.2.0
func (*TypesLoader) InsertNamedType ¶ added in v0.2.0
func (r *TypesLoader) InsertNamedType(p *types.Package, name string, t NamedType)
func (*TypesLoader) InsertTypedConst ¶ added in v0.2.0
func (r *TypesLoader) InsertTypedConst(p *types.Package, name string, v TypedConst)
func (*TypesLoader) InsertUntypedConst ¶ added in v0.2.0
func (r *TypesLoader) InsertUntypedConst(p *types.Package, name string, v UntypedConst)
func (*TypesLoader) Installed ¶ added in v0.2.0
func (r *TypesLoader) Installed(path string) (pkg *Package, ok bool)
func (*TypesLoader) LookupPackage ¶ added in v0.2.0
func (r *TypesLoader) LookupPackage(pkgpath string) (*types.Package, bool)
func (*TypesLoader) LookupReflect ¶ added in v0.2.0
func (*TypesLoader) LookupType ¶ added in v0.2.0
func (r *TypesLoader) LookupType(typ string) types.Type
func (*TypesLoader) LookupTypes ¶ added in v0.2.0
func (*TypesLoader) Packages ¶ added in v0.2.0
func (r *TypesLoader) Packages() (pkgs []*types.Package)
type TypesRecord ¶ added in v0.2.0
type TypesRecord struct {
// contains filtered or unexported fields
}
func NewTypesRecord ¶ added in v0.2.0
func NewTypesRecord(loader Loader, finder FindMethod) *TypesRecord
func (*TypesRecord) Load ¶ added in v0.2.0
func (r *TypesRecord) Load(pkg *ssa.Package)
func (*TypesRecord) LoadType ¶ added in v0.2.0
func (r *TypesRecord) LoadType(typ types.Type) reflect.Type
func (*TypesRecord) LookupLocalTypes ¶ added in v0.2.0
func (*TypesRecord) LookupReflect ¶ added in v0.2.0
func (*TypesRecord) LookupTypes ¶ added in v0.2.0
func (*TypesRecord) ToType ¶ added in v0.2.0
func (r *TypesRecord) ToType(typ types.Type) reflect.Type
func (*TypesRecord) ToTypeList ¶ added in v0.2.0
func (r *TypesRecord) ToTypeList(tuple *types.Tuple) []reflect.Type
type UntypedConst ¶ added in v0.2.0
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
internal/base
Package base defines shared basic pieces of the gop command, in particular logging and the Command structure.
|
Package base defines shared basic pieces of the gop command, in particular logging and the Command structure. |
internal/help
Package help implements the “gossa help” command.
|
Package help implements the “gossa help” command. |
internal/run
Package run implements the “gop run” command.
|
Package run implements the “gop run” command. |
internal/test
Package test implements the “gossa test” command.
|
Package test implements the “gossa test” command. |