arch

package
v0.0.0-...-94861f8 Latest Latest
Warning

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

Go to latest
Published: May 3, 2017 License: BSD-3-Clause, Unlicense Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Empty = iota
	AddrAuto
	AddrStatic
	AddrGlobal
	AddrLabel
	Literal
	AutoByte
	AutoWord
	StaticByte
	StaticWord
	GlobalByte
	GlobalWord
)

Addressing modes for the code synthesizer.

View Source
const (
	Cnone = iota
	Equal
	NotEqual
	Less
	Greater
	LessEqual
	GreaterEqual
	Below
	Above
	BelowEqual
	AboveEqual
)

Comparison operations.

View Source
const (
	Bnone = iota
	LogNot
	Normalize
)

Boolean operations.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Add()
	Align()
	And()
	Bool()
	BrEq(n int)
	BrFalse(n int)
	BrGe(n int)
	BrGt(n int)
	BrLe(n int)
	BrLt(n int)
	BrNe(n int)
	BrTrue(n int)
	BrUge(n int)
	BrUgt(n int)
	BrUle(n int)
	BrUlt(n int)
	Call(s string)
	Calr()
	CalSwtch()
	Case(v, l int)
	Clear()
	Clear2()
	Data()
	Dec1ib()
	Dec1iw()
	Dec1pi(v int)
	Dec2ib()
	Dec2iw()
	Dec2pi(v int)
	Decgb(s string)
	Decgw(s string)
	Declb(a int)
	Declw(a int)
	Decpg(s string, v int)
	Decpl(a, v int)
	Decps(a, v int)
	Decsb(a int)
	Decsw(a int)
	Defb(v int)
	Defc(c int)
	Defl(v int)
	Defp(v int)
	Defw(v int)
	Div()
	Entry()
	Eq()
	Exit()
	Gbss(s string, z int)
	Ge()
	Gt()
	Inc1ib()
	Inc1iw()
	Inc1pi(v int)
	Inc2ib()
	Inc2iw()
	Inc2pi(v int)
	Incgb(s string)
	Incgw(s string)
	Inclb(a int)
	Inclw(a int)
	Incpg(s string, v int)
	Incpl(a, v int)
	Incps(a, v int)
	Incsb(a int)
	Incsw(a int)
	Indb()
	Indw()
	Initlw(v, a int)
	Or()
	Jump(n int)
	Lbss(s string, z int)
	Ldga(s string)
	Ldgb(s string)
	Ldgw(s string)
	Ldinc()
	Ldla(n int)
	Ldlab(id int)
	Ldlb(n int)
	Ldlw(n int)
	Ldsa(n int)
	Ldsb(n int)
	Ldsw(n int)
	LdSwtch(n int)
	Le()
	Lit(v int)
	Load2() bool
	LogNot()
	Lt()
	Mod()
	Mul()
	Ne()
	Neg()
	Not()
	Pop2()
	PopPtr()
	Postlude()
	Prelude()
	Public(s string)
	Push()
	PushLit(n int)
	Scale()
	Scale2()
	Scale2By(v int)
	ScaleBy(v int)
	Shl()
	Shr()
	Stack(n int)
	Storgb(s string)
	Storgw(s string)
	Storib()
	Storiw()
	Storlb(n int)
	Storlw(n int)
	Storsb(n int)
	Storsw(n int)
	Sub()
	Swap()
	Text()
	Uge()
	Ugt()
	Ule()
	Ult()
	Unscale()
	UnscaleBy(v int)
	Xor()
}

Backend represents an interface a architecture specific code generator must have for the compiler to use for generating code.

type Emitter

type Emitter struct {
	types.Sizes
	W io.Writer
	B Backend

	Q      synth
	Retlab int
	Acc    bool
	// contains filtered or unexported fields
}

Emitter is uses to emit code.

func (*Emitter) Add

func (c *Emitter) Add(p1, p2 types.Type, swapped bool) types.Type

Add emits code for addition.

func (*Emitter) Addr

func (c *Emitter) Addr(lv LV)

Addr emits code for queuing up addresses.

func (*Emitter) Align

func (c *Emitter) Align(k, align int)

Align emits code to align to an alignment starting at k.

func (*Emitter) AlignText

func (c *Emitter) AlignText()

AlignText emits code for aligning the text segment.

func (*Emitter) And

func (c *Emitter) And()

And emits code for the bitwise and operator.

func (*Emitter) BSS

func (c *Emitter) BSS(name string, length int, static bool)

BSS emits code to store things on the .bss

func (*Emitter) Bool

func (c *Emitter) Bool()

Bool emits code for a bool.

func (*Emitter) BrFalse

func (c *Emitter) BrFalse(dest int)

BrFalse emits code for branching.

func (*Emitter) BrTrue

func (c *Emitter) BrTrue(dest int)

BrTrue emits code for branching.

func (*Emitter) Branch

func (c *Emitter) Branch(dest int, inv bool)

Branch emits code for branching.

func (*Emitter) Call

func (c *Emitter) Call(lv LV)

Call emits code to call a function with a name

func (*Emitter) Calr

func (c *Emitter) Calr(lv LV)

Calr emits code to call a function pointer.

func (*Emitter) Clear

func (c *Emitter) Clear(q bool)

Clear resets the accumulator.

func (*Emitter) Commit

func (c *Emitter) Commit()

Commit flushes the code synthesizer to load and spill the registers to memory.

func (*Emitter) Data

func (c *Emitter) Data()

Data emits code to switch to the data segment.

func (*Emitter) Defb

func (c *Emitter) Defb(v int)

Defb emits code for byte declaration.

func (*Emitter) Defp

func (c *Emitter) Defp(v int)

Defp emits code for pointer declaration.

func (*Emitter) Defs

func (c *Emitter) Defs(s string)

Defs emits code for storing a string on a data segment.

func (*Emitter) Defw

func (c *Emitter) Defw(v int)

Defw emits code for word declaration.

func (*Emitter) Div

func (c *Emitter) Div(swapped bool)

Div emits code for the division operator.

func (*Emitter) Entry

func (c *Emitter) Entry()

Entry emits code for entry.

func (*Emitter) Exit

func (c *Emitter) Exit()

Exit emits code for exit.

func (*Emitter) Gen

func (c *Emitter) Gen(s string)

Gen emits a line of assembly with an instruction.

func (*Emitter) Gsym

func (c *Emitter) Gsym(s string) string

Gsym returns a label string with the code prefix for string s.

func (*Emitter) Inc

func (c *Emitter) Inc(lv LV, inc, pre bool)

Inc emits code to increment a variable.

func (*Emitter) Ind

func (c *Emitter) Ind(lv LV)

Ind emits code to do an indirection.

func (*Emitter) Int

func (c *Emitter) Int() int

Int returns the size of an integer.

func (*Emitter) Jump

func (c *Emitter) Jump(dest int)

Jump emits code to jump to a destination.

func (*Emitter) Lab

func (c *Emitter) Lab(id int)

Lab emits a label.

func (*Emitter) Label

func (c *Emitter) Label() int

Label generates a new label ID for labels.

func (*Emitter) Labname

func (c *Emitter) Labname(id int) string

Labname returns a label name with an lprefix.

func (*Emitter) Ldlab

func (c *Emitter) Ldlab(id int)

Ldlab queues an address label with id.

func (*Emitter) Lgen

func (c *Emitter) Lgen(s, inst string, n int)

Lgen emits an instruction that acts on a label.

func (*Emitter) Lgen2

func (c *Emitter) Lgen2(s string, v1, v2 int)

Lgen2 emits an instruction with one argument that acts on a label.

func (*Emitter) Lit

func (c *Emitter) Lit(v int)

Lit queues a literal.

func (*Emitter) Load

func (c *Emitter) Load()

Load enables the accumulator, meaning it tells the later code generation it must spills if it wants to mess with the accumulator.

func (*Emitter) LocInit

func (c *Emitter) LocInit(localInits [][2]int)

LocInit emits code for initializing words with pair (addr, value)

func (*Emitter) LogBr

func (c *Emitter) LogBr(dest int, inv bool)

LogBr emits code for logical branching.

func (*Emitter) LogNot

func (c *Emitter) LogNot()

LogNot emits code for a logical not.

func (*Emitter) Mod

func (c *Emitter) Mod(swapped bool)

Mod emits code for the modulus operator.

func (*Emitter) Mul

func (c *Emitter) Mul()

Mul emits for code for the multiplication operator.

func (*Emitter) Name

func (c *Emitter) Name(name string)

Name emits a code label for name.

func (*Emitter) Neg

func (c *Emitter) Neg()

Neg emits code for switching a sign.

func (*Emitter) Ngen

func (c *Emitter) Ngen(s string, args ...interface{})

Ngen emits a line of assembly with instruction and one or zero argument.

func (*Emitter) Ngen2

func (c *Emitter) Ngen2(s, inst string, n, a int)

Ngen2 emits a line of assembly with instruction and two arguments.

func (*Emitter) Not

func (c *Emitter) Not()

Not emits code for a negation.

func (*Emitter) Or

func (c *Emitter) Or()

Or emits code for the bitwise or operator.

func (*Emitter) Pointer

func (c *Emitter) Pointer() int

Pointer returns the size of a pointer.

func (*Emitter) Postlude

func (c *Emitter) Postlude()

Postlude emits code for the postlude.

func (*Emitter) Prelude

func (c *Emitter) Prelude()

Prelude emits code for the prelude.

func (*Emitter) Public

func (c *Emitter) Public(name string)

Public emits code for defining a global symbol, used for global identifiers.

func (*Emitter) Push

func (c *Emitter) Push()

Push emits code for pushing to the stack after flushing the code synthesizer.

func (*Emitter) PushLit

func (c *Emitter) PushLit(n int)

PushLit pushes a literal to the stack after flushing the code synthesizer.

func (*Emitter) Queue

func (c *Emitter) Queue(typ, value int, name string)

Queue queues a value into the code synthesizer.

func (*Emitter) QueueBool

func (c *Emitter) QueueBool(op int)

QueueBool queues a boolean operation.

func (*Emitter) QueueCmp

func (c *Emitter) QueueCmp(op int)

QueueCmp queues a comparison operator.

func (*Emitter) Raw

func (c *Emitter) Raw(s string)

Raw emits raw text.

func (*Emitter) Rval

func (c *Emitter) Rval(lv LV)

Rval emits code to load an address.

func (*Emitter) Scale

func (c *Emitter) Scale()

Scale emits code to scale indices for pointer arithmetic and array accesses.

func (*Emitter) ScaleBy

func (c *Emitter) ScaleBy(v int)

ScaleBy emits code to scale the indices.

func (*Emitter) Sgen

func (c *Emitter) Sgen(s, inst, s2 string)

Sgen emits a prefix and instruction with one argument.

func (*Emitter) Sgen2

func (c *Emitter) Sgen2(s, inst string, v int, s2 string)

Sgen2 emits a prefix and instruction with two arguments.

func (*Emitter) Shl

func (c *Emitter) Shl(swapped bool)

Shl emits code for left shifting.

func (*Emitter) Shr

func (c *Emitter) Shr(swapped bool)

Shr emits code for right shifting.

func (*Emitter) Sizeof

func (c *Emitter) Sizeof(T types.Type) int

Sizeof returns the sizze of a type.

func (*Emitter) Spill

func (c *Emitter) Spill()

Spill pushes the registers in use onto the stack.

func (*Emitter) Stack

func (c *Emitter) Stack(n int)

Stack emits a stack grows if n is not zero.

func (*Emitter) Store

func (c *Emitter) Store(lv LV)

Store emits code to store a value.

func (*Emitter) Sub

func (c *Emitter) Sub(p1, p2 types.Type, swapped bool) types.Type

Sub emits code for subtraction.

func (*Emitter) Switch

func (c *Emitter) Switch(vals, labs []int, dflt int)

Switch emits code for a switch statement.

func (*Emitter) Text

func (c *Emitter) Text()

Text emits code to switch to the text segment.

func (*Emitter) Xor

func (c *Emitter) Xor()

Xor emits code for the bitwise xor operator.

type LV

type LV struct {
	Ident       bool           // if the variable is an identifier
	Addressable bool           // if the variable is addressable
	Storage     types.Storage  // the storage type of the variable
	Type        types.Type     // type of the variable
	Btype       types.Type     // for binary expressions where it can implicitly cast the result  such as pointer - pointer becomes an integer
	Name        string         // name of the variable if any
	Size        int            // size of the variable, for sizeof
	Addr        int            // the location of the variable, such as the offset of where it is on the stack
	Value       constant.Value // if the variable is a constant, the constant will be stored here
}

LV is a structure that an emitter uses as arguments to generate code, it mainly contains data structure for variables and their resulting types after an expression has been done on them.

Directories

Path Synopsis
Package amd64 contains a code emitter for generating code for the x86_64 architecture.
Package amd64 contains a code emitter for generating code for the x86_64 architecture.
Package arm6 contains a code emitter to generate code for the ARMv6 architecture.
Package arm6 contains a code emitter to generate code for the ARMv6 architecture.
Package darwinamd64 contains code to generate a x86_64 architecture that is running on darwin.
Package darwinamd64 contains code to generate a x86_64 architecture that is running on darwin.
Package i386 contains code to generate code for the x86 architecture.
Package i386 contains code to generate code for the x86 architecture.

Jump to

Keyboard shortcuts

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