llgo

package module
v0.0.0-...-a80dee0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2013 License: BSD-3-Clause, MIT Imports: 15 Imported by: 0

README

Build Status

llgo

llgo is a compiler for Go, written in Go, and using the LLVM compiler infrastructure.

llgo is a fledgling, and is being developed primarily as an educational exercise. It is not presently useful for real work. Progress will be reported at http://blog.awilkins.id.au.

Installation

The recommended way to install llgo is to use go get. You'll need to set a couple of environment variables first:

export CGO_CFLAGS="`llvm-config --cflags`"
export CGO_LDFLAGS="`llvm-config --ldflags` -Wl,-L`llvm-config --libdir` -lLLVM-`llvm-config --version`"
go get github.com/axw/llgo/llgo

You must have LLVM 3.2 or better in your path. You can also use latest development version of LLVM, and build it from LLVM SVN repository, just be sure to pass --enable-shared to LLVM configure during build.

Note: llgo requires Go 1.0.3 or Go tip before rev 2e2a1d8184e6 (last known good rev is rev 6e9d872ffc66).

Running

First compile the runtime support packages using cmd/llgo-dist command, just run llgo-dist.

Currently there is just a compiler which produces LLVM bitcode, and there is no integration with the go command or cgo, etc. To compile a Go source file, simply run llgo <file.go>, which will emit LLVM bitcode to stdout. To produce human-readable LLVM assembly code, supply an additional -dump command line argument before <file.go>.

Testing

First make sure you have LLVM 3.2+ installed, then re-install gollvm package with the tag llvmsvn.

go clean -i github.com/axw/gollvm/llvm
go install -tags llvmsvn github.com/axw/gollvm/llvm
go test -i github.com/axw/llgo/llgo
go test -v github.com/axw/llgo/llgo

Documentation

Index

Constants

View Source
const (
	LLGOAuthor   = "Andrew Wilkins <[email protected]>"
	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

This section is empty.

Types

type Attribute

type Attribute interface {
	Apply(Value)
}

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

type Builder

type Builder struct {
	llvm.Builder
	// contains filtered or unexported fields
}

func (*Builder) CreateLoad

func (b *Builder) CreateLoad(v llvm.Value, name string) llvm.Value

func (*Builder) CreateStore

func (b *Builder) CreateStore(v, ptr llvm.Value)

type Compiler

type Compiler interface {
	Compile(fset *token.FileSet, files []*ast.File, importpath string) (*Module, error)
	Dispose()
}

TODO get rid of this, change compiler to Compiler.

func NewCompiler

func NewCompiler(opts CompilerOptions) (Compiler, error)

type CompilerOptions

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

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

type ExprTypeInfo

type ExprTypeInfo struct {
	types.Type

	// Constant value if non-nil.
	Value exact.Value
}

type ExprTypeMap

type ExprTypeMap map[ast.Expr]ExprTypeInfo

type FunctionCache

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

func NewFunctionCache

func NewFunctionCache(c *compiler) *FunctionCache

func (FunctionCache) Compile

func (compiler FunctionCache) Compile(fset *token.FileSet, files []*ast.File, importpath string) (m *Module, err error)

func (FunctionCache) Dispose

func (compiler FunctionCache) Dispose()

func (*FunctionCache) NamedFunction

func (c *FunctionCache) NamedFunction(name string, signature string) llvm.Value

func (FunctionCache) NewConstValue

func (c FunctionCache) NewConstValue(v exact.Value, typ types.Type) *LLVMValue

func (FunctionCache) NewValue

func (c FunctionCache) NewValue(v llvm.Value, t types.Type) *LLVMValue

Create a new dynamic value from a (LLVM Value, Type) pair.

func (FunctionCache) Resolve

func (c FunctionCache) Resolve(ident *ast.Ident) Value

func (FunctionCache) VisitAppend

func (c FunctionCache) VisitAppend(expr *ast.CallExpr) Value

func (FunctionCache) VisitAssignStmt

func (c FunctionCache) VisitAssignStmt(stmt *ast.AssignStmt)

func (FunctionCache) VisitBinaryExpr

func (c FunctionCache) VisitBinaryExpr(x *ast.BinaryExpr) Value

func (FunctionCache) VisitBlockStmt

func (c FunctionCache) VisitBlockStmt(stmt *ast.BlockStmt, createNewBlock bool)

func (FunctionCache) VisitBranchStmt

func (c FunctionCache) VisitBranchStmt(stmt *ast.BranchStmt)

func (FunctionCache) VisitCallExpr

func (c FunctionCache) VisitCallExpr(expr *ast.CallExpr) Value

func (FunctionCache) VisitCap

func (c FunctionCache) VisitCap(expr *ast.CallExpr) Value

func (FunctionCache) VisitCompositeLit

func (c FunctionCache) VisitCompositeLit(lit *ast.CompositeLit) (v *LLVMValue)

func (FunctionCache) VisitCopy

func (c FunctionCache) VisitCopy(expr *ast.CallExpr) Value

func (FunctionCache) VisitDecl

func (c FunctionCache) VisitDecl(decl ast.Decl) Value

func (FunctionCache) VisitDeferStmt

func (c FunctionCache) VisitDeferStmt(stmt *ast.DeferStmt)

func (FunctionCache) VisitExpr

func (c FunctionCache) VisitExpr(expr ast.Expr) Value

func (FunctionCache) VisitForStmt

func (c FunctionCache) VisitForStmt(stmt *ast.ForStmt)

func (FunctionCache) VisitFuncDecl

func (c FunctionCache) VisitFuncDecl(f *ast.FuncDecl) Value

func (FunctionCache) VisitFuncLit

func (c FunctionCache) VisitFuncLit(lit *ast.FuncLit) Value

func (FunctionCache) VisitGenDecl

func (c FunctionCache) VisitGenDecl(decl *ast.GenDecl)

func (FunctionCache) VisitGoStmt

func (c FunctionCache) VisitGoStmt(stmt *ast.GoStmt)

func (FunctionCache) VisitIfStmt

func (c FunctionCache) VisitIfStmt(stmt *ast.IfStmt)

func (FunctionCache) VisitIncDecStmt

func (c FunctionCache) VisitIncDecStmt(stmt *ast.IncDecStmt)

func (FunctionCache) VisitIndexExpr

func (c FunctionCache) VisitIndexExpr(expr *ast.IndexExpr) Value

func (FunctionCache) VisitLabeledStmt

func (c FunctionCache) VisitLabeledStmt(stmt *ast.LabeledStmt)

func (FunctionCache) VisitLen

func (c FunctionCache) VisitLen(expr *ast.CallExpr) Value

func (FunctionCache) VisitMake

func (c FunctionCache) VisitMake(expr *ast.CallExpr) Value

func (FunctionCache) VisitNew

func (c FunctionCache) VisitNew(expr *ast.CallExpr) Value

func (FunctionCache) VisitRangeStmt

func (c FunctionCache) VisitRangeStmt(stmt *ast.RangeStmt)

func (FunctionCache) VisitReturnStmt

func (c FunctionCache) VisitReturnStmt(stmt *ast.ReturnStmt)

func (FunctionCache) VisitSelectStmt

func (c FunctionCache) VisitSelectStmt(stmt *ast.SelectStmt)

func (FunctionCache) VisitSelectorExpr

func (c FunctionCache) VisitSelectorExpr(expr *ast.SelectorExpr) Value

func (FunctionCache) VisitSendStmt

func (c FunctionCache) VisitSendStmt(stmt *ast.SendStmt)

func (FunctionCache) VisitSliceExpr

func (c FunctionCache) VisitSliceExpr(expr *ast.SliceExpr) Value

func (FunctionCache) VisitStarExpr

func (c FunctionCache) VisitStarExpr(expr *ast.StarExpr) Value

func (FunctionCache) VisitStmt

func (c FunctionCache) VisitStmt(stmt ast.Stmt)

func (FunctionCache) VisitSwitchStmt

func (c FunctionCache) VisitSwitchStmt(stmt *ast.SwitchStmt)

func (FunctionCache) VisitTypeAssertExpr

func (c FunctionCache) VisitTypeAssertExpr(expr *ast.TypeAssertExpr) Value

func (FunctionCache) VisitTypeSwitchStmt

func (c FunctionCache) VisitTypeSwitchStmt(stmt *ast.TypeSwitchStmt)

func (FunctionCache) VisitUnaryExpr

func (c FunctionCache) VisitUnaryExpr(expr *ast.UnaryExpr) Value

func (FunctionCache) VisitValueSpec

func (c FunctionCache) VisitValueSpec(valspec *ast.ValueSpec)

type LLVMTypeMap

type LLVMTypeMap struct {
	TypeStringer
	// contains filtered or unexported fields
}

func NewLLVMTypeMap

func NewLLVMTypeMap(target llvm.TargetData) *LLVMTypeMap

func (*LLVMTypeMap) Alignof

func (tm *LLVMTypeMap) Alignof(typ types.Type) int64

func (*LLVMTypeMap) Offsetsof

func (tm *LLVMTypeMap) Offsetsof(fields []*types.Field) []int64

func (*LLVMTypeMap) Sizeof

func (tm *LLVMTypeMap) Sizeof(typ types.Type) int64

func (*LLVMTypeMap) ToLLVM

func (tm *LLVMTypeMap) ToLLVM(t types.Type) llvm.Type

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

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

func (*LLVMValue) UnaryOp

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

type LabelData

type LabelData struct {
	Goto, Break, Continue llvm.BasicBlock
}

type Module

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

func (Module) Dispose

func (m Module) Dispose()

type ObjectData

type ObjectData struct {
	Ident   *ast.Ident
	Package *types.Package
	Value   *LLVMValue
}

ObjectData stores information for a types.Object

type Resolver

type Resolver interface {
	Resolve(*ast.Ident) Value
}

Resolver is an interface for resolving AST objects to values.

type TypeMap

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

func NewTypeMap

func NewTypeMap(llvmtm *LLVMTypeMap, module llvm.Module, pkgpath string, exprTypes ExprTypeMap, c *FunctionCache, r Resolver) *TypeMap

func (*TypeMap) ToRuntime

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

type TypeStringer

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

func (*TypeStringer) TypeString

func (ts *TypeStringer) TypeString(typ types.Type) string

typeString returns a string representation for typ. below code based on go/types' typeString and friends.

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
llgo-go
Go is a tool for managing Go source code.
Go is a tool for managing Go source code.
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