driver

package
v0.0.0-...-2f213e3 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package driver is amediator to glue all packages for GoCaqml. provides a compiler function for GoCaml codes. It provides compiler functinalities for GoCaml.

Example
// Compile testdata/from-mincaml/ack.ml
file := filepath.FromSlash("../testdata/from-mincaml/ack.ml")
src, err := locerr.NewSourceFromFile(file)
if err != nil {
	// File not found
	panic(err)
}

d := Driver{}

// Show list of tokens
d.PrintTokens(src)

// Show AST nodes
d.PrintAST(src)

// Parse file into AST
parsed, err := d.Parse(src)
if err != nil {
	panic(err)
}
fmt.Println(parsed)

// Resolving symbols and type analysis
env, inferred, err := d.SemanticAnalysis(src)
if err != nil {
	panic(err)
}

// Show environment of type analysis
env.Dump()

// Show inferred types of all AST nodes
for e, t := range inferred {
	fmt.Printf("Node '%s' at '%s' => Type '%s'", e.Name(), e.Pos(), t.String())
}

// Show LLVM IR for the source
ir, err := d.EmitLLVMIR(src)
if err != nil {
	panic(err)
}
fmt.Println(ir)

// Show native assembly code for the source
asm, err := d.EmitAsm(src)
if err != nil {
	panic(err)
}
fmt.Println(asm)

// Compile the source into an executable
if err := d.Compile(src); err != nil {
	panic(err)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver struct {
	Optimization OptLevel
	LinkFlags    string
	TargetTriple string
	DebugInfo    bool
}

Driver instance to compile GoCaml code into other representations.

func (*Driver) Compile

func (d *Driver) Compile(source *locerr.Source) error

func (*Driver) EmitAsm

func (d *Driver) EmitAsm(src *locerr.Source) (string, error)

func (*Driver) EmitLLVMIR

func (d *Driver) EmitLLVMIR(src *locerr.Source) (string, error)

func (*Driver) EmitMIR

func (d *Driver) EmitMIR(src *locerr.Source) (*mir.Program, *types.Env, error)

EmitMIR emits MIR tree representation.

func (*Driver) EmitObjFile

func (d *Driver) EmitObjFile(src *locerr.Source) error

func (*Driver) Lex

func (d *Driver) Lex(src *locerr.Source) chan token.Token

PrintTokens returns the lexed tokens for a source code.

func (*Driver) Parse

func (d *Driver) Parse(src *locerr.Source) (*ast.AST, error)

Parse parses the source and returns the parsed AST.

func (*Driver) PrintAST

func (d *Driver) PrintAST(src *locerr.Source)

PrintAST outputs AST structure to stdout.

func (*Driver) PrintTokens

func (d *Driver) PrintTokens(src *locerr.Source)

PrintTokens show list of tokens lexed.

func (*Driver) SemanticAnalysis

func (d *Driver) SemanticAnalysis(src *locerr.Source) (*types.Env, sema.InferredTypes, error)

SemanticAnalysis checks symbol duplicates, infers types and so on. It returns analyzed type environment and inferred types of AST node.

type OptLevel

type OptLevel int
const (
	O0 OptLevel = iota
	O1
	O2
	O3
)

Jump to

Keyboard shortcuts

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