Documentation ¶
Overview ¶
Package build is a helper package for building SSA IR in the parent directory.
Usage ¶
There are two ways of building SSA IR from source code:
Build from a list of source files ¶
This is the normal usage, where a number of files are supplied (usually as command line arguments), and the builder tool considers all of the files part of the same package (i.e. in the same directory).
Build from a Reader ¶
This is mostly used for testing or demo, where the input source code is read from a given io.Reader and written to a temporary file, which will be removed straight after the build is complete.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CachedSrc ¶
type CachedSrc struct {
// contains filtered or unexported fields
}
CachedSrc is source file from a reader.
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config represents a build configuration.
func (*Config) AddBadPkg ¶
func (c *Config) AddBadPkg(pkg, reason string) Configurer
AddBadPkg marks a package 'bad' to avoid loading.
func (*Config) Default ¶
func (c *Config) Default() Configurer
Default returns a default configuration for static analysis.
func (*Config) WithBuildLog ¶
func (c *Config) WithBuildLog(l io.Writer, flags int) Configurer
WithBuildLog adds build log to config.
func (*Config) WithPtaLog ¶
func (c *Config) WithPtaLog(l io.Writer, flags int) Configurer
WithPtaLog adds pointer analysis log to config.
type Configurer ¶
type Configurer interface { Builder Default() Configurer AddBadPkg(pkg, reason string) Configurer WithBuildLog(l io.Writer, flags int) Configurer WithPtaLog(l io.Writer, flags int) Configurer }
func FromFiles ¶
func FromFiles(files ...string) Configurer
FromFiles returns a non-nil Builder from a slice of filenames.
Example ¶
package main import ( "log" "os" "github.com/nickng/gospal/ssa/build" ) var testdir string func init() { testdir, _ = os.Getwd() } func main() { os.Chdir(testdir) conf := build.FromFiles("testdata/main.go", "testdata/foo.go", "testdata/bar.go") info, err := conf.Build() if err != nil { log.Fatalf("SSA build failed: %v", err) } _ = info // Use info here }
Output:
func FromReader ¶
func FromReader(r io.Reader) Configurer
FromReader returns a non-nil Builder for a reader. This is typically used for testing or building a temporary file.
Example ¶
package main import ( "log" "os" "strings" "github.com/nickng/gospal/ssa/build" ) var testdir string func init() { testdir, _ = os.Getwd() } func main() { conf := build.FromReader(strings.NewReader("package main; func main() {}")) info, err := conf.Build() if err != nil { log.Fatalf("SSA build failed: %v", err) } _ = info // Use info here }
Output: