shared

package
v0.0.0-...-3f1fa26 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: MIT Imports: 6 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TUint8   = &BaseType{T_Uint8}
	TUint16  = &BaseType{T_Uint16}
	TUint32  = &BaseType{T_Uint32}
	TUint64  = &BaseType{T_Uint64}
	TInt8    = &BaseType{T_Int8}
	TInt16   = &BaseType{T_Int16}
	TInt32   = &BaseType{T_Int32}
	TInt64   = &BaseType{T_Int64}
	TFloat64 = &BaseType{T_Float64}
	TBool    = &BaseType{T_Bool}
)

Functions

func IREXpression_length

func IREXpression_length(expr IRExpression, ctx *IR_Context, target lib.Operand) (int, error)

func IR_Length

func IR_Length(stmt IR, ctx *IR_Context) (int, error)

func IsFloat

func IsFloat(b Type) bool

func IsInteger

func IsInteger(b Type) bool

func IsLiteral

func IsLiteral(e IRExpression) bool

func IsLiteralOrVariable

func IsLiteralOrVariable(e IRExpression) bool

func IsNumber

func IsNumber(b Type) bool

func IsSignedInteger

func IsSignedInteger(b Type) bool

func IsVariable

func IsVariable(e IRExpression) bool

Types

type ABI

type ABI interface {
	GetRegistersForArgs(args []Type) []*encoding.Register
	ReturnTypeToOperand(ty Type) lib.Operand
}

TODO: should only contain call setup and teardown; this makes no sense.

type Allocator

type Allocator interface {
	AllocateRegister(typ Type) lib.Operand
	DeallocateRegister(lib.Operand)
	Copy() Allocator
}

type Architecture

type Architecture interface {
	EncodeExpression(expr IRExpression, ctx *IR_Context, target lib.Operand) ([]lib.Instruction, error)
	EncodeStatement(stmt IR, ctx *IR_Context) ([]lib.Instruction, error)
	EncodeDataSection(stmts []IR, ctx *IR_Context) (*Segments, error)
	GetAllocator() Allocator
}

type BaseIR

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

func NewBaseIR

func NewBaseIR(typ IRType) *BaseIR

func (*BaseIR) AddToDataSection

func (b *BaseIR) AddToDataSection(ctx *IR_Context) error

func (*BaseIR) Type

func (b *BaseIR) Type() IRType

type BaseIRExpression

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

func NewBaseIRExpression

func NewBaseIRExpression(typ IRExpressionType) *BaseIRExpression

func (*BaseIRExpression) AddToDataSection

func (b *BaseIRExpression) AddToDataSection(ctx *IR_Context) error

func (*BaseIRExpression) Type

type BaseType

type BaseType struct {
	TypeNr TypeNr
}

func (*BaseType) String

func (b *BaseType) String() string

func (*BaseType) Type

func (b *BaseType) Type() TypeNr

func (*BaseType) Width

func (b *BaseType) Width() lib.Size

type IR

type IR interface {
	Type() IRType
	String() string
	AddToDataSection(ctx *IR_Context) error
	SSA_Transform(*SSA_Context) IR
}

type IRExpression

type IRExpression interface {
	Type() IRExpressionType
	ReturnType(ctx *IR_Context) Type
	AddToDataSection(ctx *IR_Context) error
	String() string
	SSA_Transform(*SSA_Context) (SSA_Rewrites, IRExpression)
}

type IRType

type IRType int
const (
	Assignment      IRType = iota
	ArrayAssignment IRType = iota
	If              IRType = iota
	While           IRType = iota
	Return          IRType = iota
	AndThen         IRType = iota
	FunctionDef     IRType = iota
)

type IR_Context

type IR_Context struct {
	Architecture Architecture
	ABI          ABI
	Allocator    Allocator

	VariableMap        map[string]lib.Operand
	VariableTypes      map[string]Type
	ReturnOperandStack []lib.Operand
	Segments           *Segments
	InstructionPointer uint
	StackPointer       int
	Commit             bool // if false turns AddInstruction into a noop
	// contains filtered or unexported fields
}

func NewIRContext

func NewIRContext(arch Architecture, abi ABI) *IR_Context

func (*IR_Context) AddInstruction

func (i *IR_Context) AddInstruction(instr ...lib.Instruction)

func (*IR_Context) AllocateRegister

func (i *IR_Context) AllocateRegister(typ Type) lib.Operand

func (*IR_Context) Copy

func (i *IR_Context) Copy() *IR_Context

func (*IR_Context) DeallocateRegister

func (i *IR_Context) DeallocateRegister(reg lib.Operand)

func (*IR_Context) GetInstructions

func (i *IR_Context) GetInstructions() []lib.Instruction

func (*IR_Context) PeekReturn

func (i *IR_Context) PeekReturn() lib.Operand

func (*IR_Context) PopReturn

func (i *IR_Context) PopReturn() lib.Operand

func (*IR_Context) PushReturnOperand

func (i *IR_Context) PushReturnOperand(op lib.Operand)

type SSA_Context

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

func NewSSA_Context

func NewSSA_Context() *SSA_Context

func (*SSA_Context) GenerateVariable

func (s *SSA_Context) GenerateVariable() string

type SSA_Rewrite

type SSA_Rewrite struct {
	Variable string
	Expr     IRExpression
}

func NewSSA_Rewrite

func NewSSA_Rewrite(v string, e IRExpression) SSA_Rewrite

type SSA_Rewrites

type SSA_Rewrites []SSA_Rewrite

type Segment

type Segment struct {
	Data []uint8
}

func NewSegment

func NewSegment() *Segment

func (Segment) String

func (s Segment) String() string

type SegmentPointer

type SegmentPointer struct {
	SegmentType
	Offset uint
}

type SegmentType

type SegmentType uint8
const (
	ReadOnly   SegmentType = 1
	ReadWrite  SegmentType = 2
	Executable SegmentType = 3
)

type Segments

type Segments struct {
	Segments map[SegmentType]*Segment
}

func NewSegments

func NewSegments() *Segments

func (*Segments) Add

func (s *Segments) Add(ty SegmentType, data ...uint8) *SegmentPointer

func (*Segments) Encode

func (s *Segments) Encode() []uint8

func (*Segments) GetAddress

func (s *Segments) GetAddress(p *SegmentPointer) int

func (*Segments) String

func (s *Segments) String() string

type TArray

type TArray struct {
	ItemType Type
	Size     int
}

func (*TArray) String

func (b *TArray) String() string

func (*TArray) Type

func (t *TArray) Type() TypeNr

func (*TArray) Width

func (b *TArray) Width() lib.Size

type TFunction

type TFunction struct {
	ReturnType Type
	Args       []Type
	ArgNames   []string
}

func (*TFunction) String

func (b *TFunction) String() string

func (*TFunction) Type

func (t *TFunction) Type() TypeNr

func (*TFunction) Width

func (b *TFunction) Width() lib.Size

type TStruct

type TStruct struct {
	FieldTypes []Type
	Fields     []string
}

func (*TStruct) String

func (b *TStruct) String() string

func (*TStruct) Type

func (t *TStruct) Type() TypeNr

func (*TStruct) Width

func (b *TStruct) Width() lib.Size

type Type

type Type interface {
	Type() TypeNr
	String() string
	Width() lib.Size
}

type TypeNr

type TypeNr int
const (
	T_Uint8    TypeNr = iota
	T_Uint16   TypeNr = iota
	T_Uint32   TypeNr = iota
	T_Uint64   TypeNr = iota
	T_Int8     TypeNr = iota
	T_Int16    TypeNr = iota
	T_Int32    TypeNr = iota
	T_Int64    TypeNr = iota
	T_Float64  TypeNr = iota
	T_Bool     TypeNr = iota
	T_Array    TypeNr = iota
	T_Function TypeNr = iota
	T_Struct   TypeNr = iota
)

func (TypeNr) String

func (i TypeNr) String() string

Jump to

Keyboard shortcuts

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