ssabuilder

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2019 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Overview

Package ssabuilder provides a wrapper for building SSA IR from Go source code.

Index

Constants

This section is empty.

Variables

View Source
var ErrPtaInternal = errors.New("internal error: pointer analysis failed")

Functions

func MainPkg

func MainPkg(prog *ssa.Program) *ssa.Package

GetMainPkg returns main package of a command.

Types

type ChanOp

type ChanOp struct {
	Value ssa.Value
	Type  ChanOpType
	Pos   token.Pos
}

ChanOp abstracts an ssa.Send, ssa.Unop(ARROW) or a SelectState.

type ChanOpType

type ChanOpType int
const (
	ChanMake ChanOpType = iota
	ChanSend
	ChanRecv
	ChanClose
)

type Config

type Config struct {
	BuildMode Mode
	Files     []string          // (Initial) files to load.
	Source    string            // Source code.
	BuildLog  io.Writer         // Build log.
	PtaLog    io.Writer         // Pointer analysis log.
	LogFlags  int               // Flags for build/pta log.
	BadPkgs   map[string]string // Packages not to load (with reasons).
}

Config holds the configuration for building SSA IR.

func NewConfig

func NewConfig(files []string) (*Config, error)

NewConfig creates a new default build configuration.

func NewConfigFromString

func NewConfigFromString(s string) (*Config, error)

NewConfigFromString creates a new default build configuration.

func (*Config) Build

func (conf *Config) Build() (*SSAInfo, error)

Build constructs the SSA IR using given config, and sets up pointer analysis.

type Members

type Members []ssa.Member

func (Members) Len

func (m Members) Len() int

func (Members) Less

func (m Members) Less(i, j int) bool

func (Members) Swap

func (m Members) Swap(i, j int)

type Mode

type Mode uint

A Mode value is a flag indicating how the source code are supplied.

const (
	// FromFiles is option to use a list of filenames for initial packages.
	FromFiles Mode = 1 << iota

	// FromString is option to use a string as body of initial package.
	FromString
)

type SSAInfo

type SSAInfo struct {
	BuildConf   *Config  // Build configuration (initial files, logs).
	IgnoredPkgs []string // Packages not loaded (respects BuildConf.BadPkgs).

	FSet    *token.FileSet  // FileSet for parsed source files.
	Prog    *ssa.Program    // SSA IR for whole program.
	PtaConf *pointer.Config // Pointer analysis config.

	Logger *log.Logger // Build logger.
}

SSAInfo is the SSA IR + metainfo built from a given Config.

func (*SSAInfo) CallGraph

func (info *SSAInfo) CallGraph() *callgraph.Node

CallGraph builds the call graph from the 'main.main' function.

The call graph is rooted at 'main.main', all nodes appear only once in the graph. A side-effect of building the call graph is obtaining a list of functions used in a program (as functions not called will not appear in the CallGraph). TODO(nickng) cache previously built CallGraph.

func (*SSAInfo) DecodePos

func (info *SSAInfo) DecodePos(pos token.Pos) token.Position

DecodePos converts a token.Pos (offset) to an actual token.Position.

This is just a shortcut to .FSet.Position.

func (*SSAInfo) FindChan

func (info *SSAInfo) FindChan(ch ssa.Value) []ChanOp

FindChan performs a ptr analysis on a given chan ssa.Value, returns a list of related ChanOp on the chan.

func (*SSAInfo) NewPta

func (info *SSAInfo) NewPta(vals ...ssa.Value) *pointer.Result

NewPta performs a custom pointer analysis on given values.

func (*SSAInfo) WriteAll

func (info *SSAInfo) WriteAll(w io.Writer) (int64, error)

WriteAll writes all SSA IR to w.

func (*SSAInfo) WriteTo

func (info *SSAInfo) WriteTo(w io.Writer) (int64, error)

WriteTo writes SSA IR of info.Prog to w.

Directories

Path Synopsis
Package callgraph represents function call graph.
Package callgraph represents function call graph.

Jump to

Keyboard shortcuts

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