build

package
Version: 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: 2

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 Builder

type Builder interface {
	Build() (*ssa.Info, error)
}

Builder builds SSA IR and metainfo.

type CachedSrc

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

CachedSrc is source file from a reader.

func (*CachedSrc) NewReader

func (s *CachedSrc) NewReader() io.Reader

NewReader returns a reader for reading the string content.

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

func (c *Config) Build() (*ssa.Info, error)

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:

type FileSrc

type FileSrc struct {
	Files []string
}

FileSrc is a set of filenames.

func (*FileSrc) NewReader

func (s *FileSrc) NewReader() io.Reader

NewReader returns an io.Reader for reading all files.

func (*FileSrc) Reader

func (s *FileSrc) Reader(i int) io.Reader

File returns an io.Reader for file[i].

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto