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 CreateTestMainPackage(pkg *ssa.Package) *ssa.Packagedeprecated
- func Interpret(mainpkg *ssa.Package, mode Mode, entry string) (exitCode int)
- func IsConstNil(v ssa.Value) bool
- func IsNil(v reflect.Value) bool
- func LoadTest(input string) (string, []*ssa.Package, error)
- func RegisterExternal(key string, i interface{})
- func RegisterExternals(m map[string]interface{})
- func RegisterFuncs(funcs ...interface{})
- func RegisterPackage(pkg string, ifacemap map[string]interface{}, typelist []interface{})
- func RegisterType(key string, typ reflect.Type)
- func RegisterTypeOf(ptrs ...interface{})
- func Run(mode Mode, input string, args []string) error
- func RunFile(mode Mode, filename string, src interface{}, args []string) error
- func RunPkg(mainPkg *ssa.Package, mode Mode, input string, entry string, args []string) error
- func RunTest(mode Mode, input string, args []string) error
- func RunTestPkg(pkgs []*ssa.Package, mode Mode, input string, args []string)
- func SetValue(v reflect.Value, x reflect.Value)
- type Mode
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") )
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.)
var (
UnsafeSizes types.Sizes
)
Functions ¶
func CreateTestMainPackage
deprecated
added in
v0.1.4
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 Interpret ¶
Interpret interprets the Go program whose main package is mainpkg. mode specifies various interpreter options. filename and args are the initial values of os.Args for the target program. sizes is the effective type-sizing function for this program.
Interpret returns the exit code of the program: 2 for panic (like gc does), or the argument to os.Exit for normal termination.
The SSA program must include the "runtime" package.
func IsConstNil ¶
func RegisterExternal ¶
func RegisterExternal(key string, i interface{})
register external interface
func RegisterExternals ¶
func RegisterExternals(m map[string]interface{})
register external interface map
func RegisterFuncs ¶ added in v0.1.4
func RegisterFuncs(funcs ...interface{})
func RegisterPackage ¶ added in v0.1.4
register extern package
func RunTestPkg ¶ added in v0.1.4
Types ¶
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 “igop help” command.
|
Package help implements the “igop help” command. |
internal/run
Package run implements the “gop run” command.
|
Package run implements the “gop run” command. |
internal/test
Package test implements the “igop test” command.
|
Package test implements the “igop test” command. |
internal
|
|