Files
avo/ast.go

84 lines
1.3 KiB
Go
Raw Normal View History

2018-11-06 21:10:54 -05:00
package avo
2018-11-20 11:44:44 -06:00
type Asm interface {
Asm() string
}
2018-11-06 21:10:54 -05:00
// GoType represents a Golang type.
type GoType interface{}
// Parameter represents a parameter to an assembly function.
type Parameter struct {
Name string
Type GoType
}
2018-11-20 11:44:44 -06:00
type Operand interface {
Asm
}
2018-11-30 21:37:17 -08:00
type Node interface {
node()
}
type Label string
func (l Label) node() {}
2018-11-06 21:10:54 -05:00
// Instruction is a single instruction in a function.
type Instruction struct {
2018-11-27 22:38:53 -08:00
Opcode string
2018-11-20 11:44:44 -06:00
Operands []Operand
}
2018-11-30 21:37:17 -08:00
func (i Instruction) node() {}
2018-11-06 21:10:54 -05:00
// File represents an assembly file.
type File struct {
2018-11-30 20:43:31 -08:00
Functions []*Function
}
func NewFile() *File {
return &File{}
2018-11-06 21:10:54 -05:00
}
// Function represents an assembly function.
type Function struct {
name string
params []Parameter
2018-11-30 21:37:17 -08:00
nodes []Node
2018-11-06 21:10:54 -05:00
}
func NewFunction(name string) *Function {
return &Function{
name: name,
}
}
func (f *Function) AddInstruction(i Instruction) {
2018-11-30 21:37:17 -08:00
f.AddNode(i)
}
func (f *Function) AddLabel(l Label) {
f.AddNode(l)
}
func (f *Function) AddNode(n Node) {
f.nodes = append(f.nodes, n)
2018-11-06 21:10:54 -05:00
}
// Name returns the function name.
func (f *Function) Name() string { return f.name }
// FrameBytes returns the size of the stack frame in bytes.
func (f *Function) FrameBytes() int {
// TODO(mbm): implement
return 0
}
// ArgumentBytes returns the size of the arguments in bytes.
func (f *Function) ArgumentBytes() int {
// TODO(mbm): implement
return 0
}