llgo

package module
v0.0.0-...-1ff96fa Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2014 License: BSD-3-Clause, MIT Imports: 20 Imported by: 0

README

Build Status

llgo

llgo is a Go frontend for LLVM, written in Go.

llgo is under active development, but is still considered experimental. It is not presently useful for real work. Progress will be reported at http://blog.awilkins.id.au.

Installation

To install llgo, use llgo-dist:

go get github.com/axw/llgo/cmd/llgo-dist
llgo-dist

You should have the latest version of LLVM in your $PATH (3.3 has been confirmed to be compatible). If LLVM is not in $PATH, llgo-dist also has a flag that can specified to point at the LLVM installation: -llvm-config=<path/to/llvm-config>.

llgo requires Go 1.2+.

Running

llgo-dist builds two binaries: there's llgo, the compiler; and there's llgo-build, which is a poor man's go build for llgo.

The compiler is comparable with 6g: it takes a set of Go source files as arguments, and produces an object file. The output is an LLVM bitcode module. There are several flags that alter the behaviour: -triple=<triple> specifies the target LLVM triple to compile for; -dump causes llgo to dump the module in its textual IR form instead of generating bitcode.

The llgo-build tool accepts either Go filenames, or package names, just like go build. If the package is a command, then llgo-build will compile it, link in its dependencies, and translate the LLVM bitcode to a native binary. If you want an untranslated module, specify the -emit-llvm flag.

llgo-build has some additional flags for testing: -run causes llgo-build to execute and dispose of the resultant binary. Passing -test causes llgo-build to generate a test program for the specified package, just like go test -c.

Testing

First install llgo using llgo-dist, as described above. Then you can run the functional tests like so:

go test -v github.com/axw/llgo/llgo

You can also run the compiler tests from gc's source tree ($GOROOT/test) by specifying the build tag go_test:

go test -v -tags go_test github.com/axw/llgo/llgo -run StandardTests

Documentation

Index

Constants

View Source
const (
	LLGOAuthor   = "Andrew Wilkins <axwalk@gmail.com>"
	LLGOProducer = "llgo " + LLGOVersion + " (" + LLGOAuthor + ")"
)

llgo constants.

View Source
const (
	LLGOVersion        = "0.1"
	LLGORuntimeVersion = 0
)
View Source
const AttributeCommentPrefix = "#llgo "
View Source
const PNaClTriple = "armv7-none-linux-gnueabi"

PNaClTriple is the LLVM target triple that should be used to compile modules to be compatible with PNaCl (Portable Native Client).

Variables

This section is empty.

Functions

func NewLLVMTypeMap

func NewLLVMTypeMap(target llvm.TargetData) *llvmTypeMap

Types

type AlgorithmKind

type AlgorithmKind int
const (
	AlgorithmHash AlgorithmKind = iota
	AlgorithmEqual
	AlgorithmPrint
	AlgorithmCopy
)

type Attribute

type Attribute interface {
	Apply(Value)
}

Attribute represents an attribute associated with a global variable or function.

type Compiler

type Compiler interface {
	Compile(filenames []string, importpath string) (*Module, error)
	Dispose()
}

func NewCompiler

func NewCompiler(opts CompilerOptions) (Compiler, error)

type CompilerOptions

type CompilerOptions struct {
	// TargetTriple is the LLVM triple for the target.
	TargetTriple string

	// GenerateDebug decides whether debug data is
	// generated in the output module.
	GenerateDebug bool

	// Logger is a logger used for tracing compilation.
	Logger *log.Logger

	// OrderedCompilation attempts to do some sorting to compile
	// functions in a deterministic order
	OrderedCompilation bool
}

type FuncResolver

type FuncResolver interface {
	ResolveFunc(*types.Func) *LLVMValue
}

type LLVMValue

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

LLVMValue represents a dynamic value produced as the result of an expression.

func (*LLVMValue) BinaryOp

func (lhs *LLVMValue) BinaryOp(op token.Token, rhs_ Value) Value

func (*LLVMValue) Convert

func (v *LLVMValue) Convert(dsttyp types.Type) Value

func (*LLVMValue) LLVMValue

func (v *LLVMValue) LLVMValue() llvm.Value

func (LLVMValue) String

func (v LLVMValue) String() string

func (*LLVMValue) Type

func (v *LLVMValue) Type() types.Type

func (*LLVMValue) UnaryOp

func (v *LLVMValue) UnaryOp(op token.Token) Value

type MethodResolver

type MethodResolver interface {
	ResolveMethod(*types.Selection) *LLVMValue
}

type Module

type Module struct {
	llvm.Module
	Name     string
	Disposed bool
}

func (Module) Dispose

func (m Module) Dispose()

type TypeMap

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

func NewTypeMap

func NewTypeMap(pkgpath string, llvmtm *llvmTypeMap, module llvm.Module, r *runtimeInterface, mr MethodResolver) *TypeMap

func (TypeMap) Alignof

func (tm TypeMap) Alignof(typ types.Type) int64

func (TypeMap) Offsetsof

func (tm TypeMap) Offsetsof(fields []*types.Var) []int64

func (TypeMap) Sizeof

func (tm TypeMap) Sizeof(typ types.Type) int64

func (TypeMap) ToLLVM

func (tm TypeMap) ToLLVM(t types.Type) llvm.Type

func (*TypeMap) ToRuntime

func (tm *TypeMap) ToRuntime(t types.Type) llvm.Value

ToRuntime returns a pointer to the specified type's runtime type descriptor.

type Value

type Value interface {
	// BinaryOp applies the specified binary operator to this value and the
	// specified right-hand operand, and returns a new Value.
	BinaryOp(op token.Token, rhs Value) Value

	// UnaryOp applies the specified unary operator and returns a new Value.
	UnaryOp(op token.Token) Value

	// Convert returns a new Value which has been converted to the specified
	// type.
	Convert(typ types.Type) Value

	// LLVMValue returns an llvm.Value for this value.
	LLVMValue() llvm.Value

	// Type returns the Type of the value.
	Type() types.Type
}

Value is an interface for representing values returned by Go expressions.

Directories

Path Synopsis
cmd
pkg
runtime
Package runtime contains operations that interact with Go's runtime system, such as functions to control goroutines.
Package runtime contains operations that interact with Go's runtime system, such as functions to control goroutines.

Jump to

Keyboard shortcuts

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