program

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: May 27, 2017 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package program contains high-level orchestration and state of the input and output program during transpilation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFunctionDefinition added in v0.9.2

func AddFunctionDefinition(f FunctionDefinition)

AddFunctionDefinition registers a function definition. If the definition already exists it will be replaced.

Types

type FunctionDefinition added in v0.9.2

type FunctionDefinition struct {
	// The name of the function, like "printf".
	Name string

	// The C return type, like "int".
	ReturnType string

	// The C argument types, like ["bool", "int"]. There is currently no way
	// to represent a varargs.
	ArgumentTypes []string

	// If this is not empty then this function name should be used instead
	// of the Name. Many low level functions have an exact match with a Go
	// function. For example, "sin()".
	Substitution string

	// Can be overriden with the substitution to rearrange the return variables
	// and parameters. When either of these are nil the behavior is to keep the
	// single return value and parameters the same.
	ReturnParameters []int
	Parameters       []int
}

FunctionDefinition contains the prototype definition for a function.

func GetFunctionDefinition added in v0.9.2

func GetFunctionDefinition(functionName string) *FunctionDefinition

GetFunctionDefinition will return nil if the function does not exist (is not registered).

type Program

type Program struct {

	// These are for the output Go AST.
	FileSet *token.FileSet
	File    *goast.File

	// Contains the current function name during the transpilation.
	Function *ast.FunctionDecl

	// The definitions for defined structs.
	// TODO: This field should be protected through proper getters and setters.
	Structs map[string]*Struct

	// If verbose is on progress messages will be printed immediately as code
	// comments (so that they do not intefere with the program output).
	Verbose bool
	// contains filtered or unexported fields
}

Program contains all of the input, output and transpition state of a C program to a Go program.

func NewProgram

func NewProgram() *Program

NewProgram creates a new blank program.

func (*Program) AddImport

func (p *Program) AddImport(importPath string)

AddImport will append an absolute import if it is unique to the list of imports for this program.

func (*Program) AddImports added in v0.11.0

func (p *Program) AddImports(importPaths ...string)

AddImports is a convienience method for adding multiple imports.

func (*Program) AppendStartupExpr added in v0.11.0

func (p *Program) AppendStartupExpr(e goast.Expr)

AppendStartupExpr is a convienience method for adding a new startup statement that is in the form of an expression.

func (*Program) AppendStartupStatement added in v0.11.0

func (p *Program) AppendStartupStatement(stmt goast.Stmt)

AppendStartupStatement adds a new statement that must be executed when the program starts up before any other code. These are required to setup state for global variables like STDIN that might be referenced by the program.

func (*Program) GetNextIdentifier added in v0.11.0

func (p *Program) GetNextIdentifier(prefix string) string

GetNextIdentifier generates a new gloablly unique identifier name. This can be used for variables and functions in generated code.

The value of prefix is only useful for readability in the code. If the prefix is an empty string then the prefix "__temp" will be used.

func (*Program) ImportType

func (p *Program) ImportType(name string) string

func (*Program) Imports

func (p *Program) Imports() []string

Imports returns all of the Go imports for this program.

func (*Program) StartupStatements added in v0.11.0

func (p *Program) StartupStatements() []goast.Stmt

StartupStatements returns the statements that will be executed before the program starts. These are required to setup state for global variables like STDIN that might be referenced by the program.

func (*Program) TypeIsAlreadyDefined added in v0.9.0

func (p *Program) TypeIsAlreadyDefined(typeName string) bool

func (*Program) TypeIsNowDefined added in v0.9.0

func (p *Program) TypeIsNowDefined(typeName string)

type Struct added in v0.11.1

type Struct struct {
	// The name of the struct.
	Name string

	// Each of the fields and their C type. The field may be a string or an
	// instance of Struct for nested structures.
	Fields map[string]interface{}
}

Struct represents the definition for a C struct.

func NewStruct added in v0.11.1

func NewStruct(n *ast.RecordDecl) *Struct

NewStruct creates a new Struct definition from an ast.RecordDecl.

Jump to

Keyboard shortcuts

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