loader

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: BSD-3-Clause Imports: 28 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCachedGoroot added in v0.14.0

func GetCachedGoroot(config *compileopts.Config) (string, error)

GetCachedGoroot creates a new GOROOT by merging both the standard GOROOT and the GOROOT from TinyGo using lots of symbolic links.

func List added in v0.15.0

func List(config *compileopts.Config, extraArgs, pkgs []string) (*exec.Cmd, error)

List returns a ready-to-run *exec.Cmd for running the `go list` command with the configuration used for TinyGo.

Types

type EmbedFile added in v0.24.0

type EmbedFile struct {
	Name      string
	Size      uint64
	Hash      string // hash of the file (as a hex string)
	NeedsData bool   // true if this file is embedded as a byte slice
	Data      []byte // contents of this file (only if NeedsData is set)
}

type Error added in v0.15.0

type Error struct {
	ImportStack []string
	Err         scanner.Error
}

Error is a regular error but with an added import stack. This is especially useful for debugging import cycle errors.

func (Error) Error added in v0.15.0

func (e Error) Error() string

type Errors

type Errors struct {
	Pkg  *Package
	Errs []error
}

Errors contains a list of parser errors or a list of typechecker errors for the given package.

func (Errors) Error

func (e Errors) Error() string

type NoTestFilesError added in v0.18.0

type NoTestFilesError struct {
	ImportPath string
}

Error returned when loading a *Program for a test binary but no test files are present.

func (NoTestFilesError) Error added in v0.18.0

func (e NoTestFilesError) Error() string

type Package

type Package struct {
	PackageJSON

	Files        []*ast.File
	FileHashes   map[string][]byte
	CFlags       []string // CFlags used during CGo preprocessing (only set if CGo is used)
	CGoHeaders   []string // text above 'import "C"' lines
	EmbedGlobals map[string][]*EmbedFile
	Pkg          *types.Package
	// contains filtered or unexported fields
}

Package holds a loaded package, its imports, and its parsed files.

func (*Package) Check

func (p *Package) Check() error

Check runs the package through the typechecker. The package must already be loaded and all dependencies must have been checked already.

Idempotent.

func (*Package) Import

func (p *Package) Import(to string) (*types.Package, error)

Import implements types.Importer. It loads and parses packages it encounters along the way, if needed.

func (*Package) LoadSSA added in v0.17.0

func (p *Package) LoadSSA() *ssa.Package

LoadSSA constructs the SSA form of this package.

The program must already be parsed and type-checked with the .Parse() method.

func (*Package) OriginalDir added in v0.21.0

func (p *Package) OriginalDir() string

OriginalDir returns the real directory name. It is the same as p.Dir except that if it is part of the cached GOROOT, its real location is returned.

func (*Package) Parse

func (p *Package) Parse() error

Parse parses and typechecks this package.

Idempotent.

type PackageJSON added in v0.15.0

type PackageJSON struct {
	Dir        string
	ImportPath string
	Name       string
	ForTest    string
	Root       string
	Module     struct {
		Path      string
		Main      bool
		Dir       string
		GoMod     string
		GoVersion string
	}

	// Source files
	GoFiles  []string
	CgoFiles []string
	CFiles   []string

	// Embedded files
	EmbedFiles []string

	// Dependency information
	Imports   []string
	ImportMap map[string]string

	// Error information
	Error *struct {
		ImportStack []string
		Pos         string
		Err         string
	}
}

PackageJSON is a subset of the JSON struct returned from `go list`.

type Program

type Program struct {
	Packages map[string]*Package

	// Information obtained during parsing.
	LDFlags []string
	// contains filtered or unexported fields
}

Program holds all packages and some metadata about the program as a whole.

func Load added in v0.15.0

func Load(config *compileopts.Config, inputPkg string, typeChecker types.Config) (*Program, error)

Load loads the given package with all dependencies (including the runtime package). Call .Parse() afterwards to parse all Go files (including CGo processing, if necessary).

func (*Program) LoadSSA

func (p *Program) LoadSSA() *ssa.Program

LoadSSA constructs the SSA form of the loaded packages.

The program must already be parsed and type-checked with the .Parse() method.

func (*Program) MainPkg added in v0.14.0

func (p *Program) MainPkg() *Package

MainPkg returns the last package in the Sorted() slice. This is the main package of the program.

func (*Program) Parse

func (p *Program) Parse() error

Parse parses all packages and typechecks them.

The returned error may be an Errors error, which contains a list of errors.

Idempotent.

func (*Program) Sorted

func (p *Program) Sorted() []*Package

Sorted returns a list of all packages, sorted in a way that no packages come before the packages they depend upon.

Jump to

Keyboard shortcuts

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