ast

package
v0.0.0-...-a689315 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLLBool

func NewLLBool(value bool) *constant.Int

func NewLLFloat

func NewLLFloat(bitSize uint64, value float64) *constant.Float

func NewLLInt

func NewLLInt(bitSize uint64, value int) *constant.Int

func NewLLTypeBool

func NewLLTypeBool() *types.IntType

func NewLLTypeFloat

func NewLLTypeFloat(bitSize uint64) *types.FloatType

func NewLLTypeInt

func NewLLTypeInt(bitSize uint64) *types.IntType

func NewLLTypeVoid

func NewLLTypeVoid() *types.VoidType

Types

type AccessorOp

type AccessorOp struct {
	Expr        ExpressionLike
	Field       string
	Dereference bool

	Scope ScopeLike
	Pos   lexer.Position
}

func (*AccessorOp) String

func (ao *AccessorOp) String() string

func (*AccessorOp) Value

func (ao *AccessorOp) Value() (*Value, error)

type ArrayType

type ArrayType struct {
	Type *Type
	Len  int
}

func (*ArrayType) Equals

func (at *ArrayType) Equals(o *ArrayType) bool

func (*ArrayType) String

func (at *ArrayType) String() string

type AssignStmt

type AssignStmt struct {
	Type  *Type
	Left  ExpressionLike
	Right ExpressionLike

	Scope ScopeLike
	Pos   lexer.Position
}

func (*AssignStmt) Generate

func (a *AssignStmt) Generate() error

func (*AssignStmt) String

func (a *AssignStmt) String() []string

type BasicType

type BasicType string
const (
	BasicTypeBool BasicType = "bool"
	BasicTypeVoid BasicType = "void"

	BasicTypeI8  BasicType = "i8"
	BasicTypeI16 BasicType = "i16"
	BasicTypeI32 BasicType = "i32"
	BasicTypeI64 BasicType = "i64"

	BasicTypeUI8  BasicType = "u8"
	BasicTypeUI16 BasicType = "u16"
	BasicTypeUI32 BasicType = "u32"
	BasicTypeUI64 BasicType = "u64"

	BasicTypeF32 BasicType = "f32"
	BasicTypeF64 BasicType = "f64"
)

type BinaryOp

type BinaryOp struct {
	Left  ExpressionLike
	Op    string
	Right ExpressionLike

	Scope ScopeLike
	Pos   lexer.Position
}

func (*BinaryOp) String

func (b *BinaryOp) String() string

func (*BinaryOp) Value

func (b *BinaryOp) Value() (*Value, error)

type Block

type Block struct {
	Stmts []StatementLike

	Locals []*Variable

	Scope *Scope
	Pos   lexer.Position
}

func (*Block) AddGlobal

func (b *Block) AddGlobal(v *Variable)

func (*Block) AddLocal

func (b *Block) AddLocal(v *Variable) error

func (*Block) AddLocalType

func (b *Block) AddLocalType(alias string, typ *Type)

func (*Block) AddModuleTypeDef

func (b *Block) AddModuleTypeDef(alias string, typ *Type)

func (*Block) BasicBlock

func (b *Block) BasicBlock() *ir.Block

func (*Block) Current

func (b *Block) Current() *Scope

func (*Block) CurrentFunction

func (b *Block) CurrentFunction() *Function

func (*Block) CurrentModule

func (b *Block) CurrentModule() *Module

func (*Block) FindFunction

func (b *Block) FindFunction(ident string) *Function

func (*Block) FindTypeDefByAlias

func (b *Block) FindTypeDefByAlias(alias string) *TypeDef

func (*Block) FindTypeDefByType

func (b *Block) FindTypeDefByType(typ *Type) *TypeDef

func (*Block) FindVariable

func (b *Block) FindVariable(ident string) *Variable

func (*Block) Generate

func (b *Block) Generate() error

func (*Block) SetBasicBlock

func (b *Block) SetBasicBlock(bb *ir.Block)

func (*Block) String

func (b *Block) String() []string

type CastingOp

type CastingOp struct {
	Type *Type
	Expr ExpressionLike

	Scope ScopeLike
	Pos   lexer.Position
}

func (*CastingOp) String

func (c *CastingOp) String() string

func (*CastingOp) Value

func (c *CastingOp) Value() (*Value, error)

type ConstantBoolOp

type ConstantBoolOp struct {
	Constant string

	Scope ScopeLike
	Pos   lexer.Position
}

func (*ConstantBoolOp) String

func (c *ConstantBoolOp) String() string

func (*ConstantBoolOp) Value

func (c *ConstantBoolOp) Value() (*Value, error)

type ConstantCharOp

type ConstantCharOp struct {
	Constant string

	Scope ScopeLike
	Pos   lexer.Position
}

func (*ConstantCharOp) String

func (c *ConstantCharOp) String() string

func (*ConstantCharOp) Value

func (c *ConstantCharOp) Value() (*Value, error)

type ConstantNumberOp

type ConstantNumberOp struct {
	Sign     string
	Constant string

	Scope ScopeLike
	Pos   lexer.Position
}

func (*ConstantNumberOp) String

func (c *ConstantNumberOp) String() string

func (*ConstantNumberOp) Value

func (c *ConstantNumberOp) Value() (*Value, error)

type ConstantStringOp

type ConstantStringOp struct {
	Constant string

	Scope ScopeLike
	Pos   lexer.Position
}

func (*ConstantStringOp) String

func (c *ConstantStringOp) String() string

func (*ConstantStringOp) Value

func (c *ConstantStringOp) Value() (*Value, error)

type DeclStmt

type DeclStmt struct {
	Ident string
	Type  *Type
	Expr  ExpressionLike

	Scope ScopeLike
	Pos   lexer.Position
}

func (*DeclStmt) Generate

func (d *DeclStmt) Generate() error

func (*DeclStmt) String

func (d *DeclStmt) String() []string

type ExprStmt

type ExprStmt struct {
	Expr ExpressionLike

	Scope ScopeLike
	Pos   lexer.Position
}

func (*ExprStmt) Generate

func (a *ExprStmt) Generate() error

func (*ExprStmt) String

func (a *ExprStmt) String() []string

type ExpressionLike

type ExpressionLike interface {
	String() string
	Value() (*Value, error)
}

type ExpressionLikeList

type ExpressionLikeList []ExpressionLike

func (ExpressionLikeList) String

func (e ExpressionLikeList) String() string

type FnCallOp

type FnCallOp struct {
	Ident string
	Args  []ExpressionLike

	Scope ScopeLike
	Pos   lexer.Position
}

func (*FnCallOp) String

func (f *FnCallOp) String() string

func (*FnCallOp) Value

func (f *FnCallOp) Value() (*Value, error)

type Function

type Function struct {
	Name        string
	Params      []*Variable
	Variadic    bool
	ReturnType  *Type
	Body        []StatementLike
	OnlyDeclare bool

	Locals []*Variable

	Ptr *ir.Func

	Scope *Scope
	Pos   lexer.Position
}

func (*Function) AddGlobal

func (f *Function) AddGlobal(v *Variable)

func (*Function) AddLocal

func (f *Function) AddLocal(v *Variable) error

func (*Function) AddLocalType

func (f *Function) AddLocalType(alias string, typ *Type)

func (*Function) AddModuleTypeDef

func (f *Function) AddModuleTypeDef(alias string, typ *Type)

func (*Function) BasicBlock

func (f *Function) BasicBlock() *ir.Block

func (*Function) Current

func (f *Function) Current() *Scope

func (*Function) CurrentFunction

func (f *Function) CurrentFunction() *Function

func (*Function) CurrentModule

func (f *Function) CurrentModule() *Module

func (*Function) FindFunction

func (f *Function) FindFunction(ident string) *Function

func (*Function) FindTypeDefByAlias

func (f *Function) FindTypeDefByAlias(alias string) *TypeDef

func (*Function) FindTypeDefByType

func (f *Function) FindTypeDefByType(typ *Type) *TypeDef

func (*Function) FindVariable

func (f *Function) FindVariable(ident string) *Variable

func (*Function) Generate

func (f *Function) Generate() error

func (*Function) SetBasicBlock

func (f *Function) SetBasicBlock(block *ir.Block)

func (*Function) String

func (f *Function) String() []string

type Global

type Global struct {
	Variable *Variable
}

type IfStmt

type IfStmt struct {
	Condition ExpressionLike
	Then      []StatementLike
	Else      []StatementLike

	Scope ScopeLike
	Pos   lexer.Position
}

func (*IfStmt) Generate

func (i *IfStmt) Generate() error

func (*IfStmt) String

func (i *IfStmt) String() []string

type IndexOp

type IndexOp struct {
	Op        string
	Expr      ExpressionLike
	IndexExpr ExpressionLike

	Scope ScopeLike
	Pos   lexer.Position
}

func (*IndexOp) String

func (io *IndexOp) String() string

func (*IndexOp) Value

func (io *IndexOp) Value() (*Value, error)

type LoadOp

type LoadOp struct {
	Name string

	Scope ScopeLike
	Pos   lexer.Position
}

func (*LoadOp) String

func (l *LoadOp) String() string

func (*LoadOp) Value

func (l *LoadOp) Value() (*Value, error)

type Module

type Module struct {
	Functions []*Function

	ModuleTypeDefs []*TypeDef
	LocalTypes     []*TypeDef
	Globals        []*Global

	Ptr          *ir.Module
	LastID       int
	CurrentBlock *ir.Block

	Scope *Scope
	Pos   lexer.Position
}

func (*Module) AddGlobal

func (m *Module) AddGlobal(v *Variable)

func (*Module) AddLocal

func (m *Module) AddLocal(v *Variable) error

func (*Module) AddLocalType

func (m *Module) AddLocalType(alias string, typ *Type)

func (*Module) AddModuleTypeDef

func (m *Module) AddModuleTypeDef(alias string, typ *Type)

func (*Module) BasicBlock

func (m *Module) BasicBlock() *ir.Block

func (*Module) Current

func (m *Module) Current() *Scope

func (*Module) CurrentFunction

func (m *Module) CurrentFunction() *Function

func (*Module) CurrentModule

func (m *Module) CurrentModule() *Module

func (*Module) FindFunction

func (m *Module) FindFunction(ident string) *Function

func (*Module) FindTypeDefByAlias

func (m *Module) FindTypeDefByAlias(alias string) *TypeDef

func (*Module) FindTypeDefByType

func (m *Module) FindTypeDefByType(typ *Type) *TypeDef

func (*Module) FindVariable

func (m *Module) FindVariable(ident string) *Variable

func (*Module) Generate

func (m *Module) Generate() (*ir.Module, error)

func (*Module) GenerateID

func (m *Module) GenerateID(prefix string) string

func (*Module) SetBasicBlock

func (m *Module) SetBasicBlock(b *ir.Block)

func (*Module) String

func (m *Module) String() []string

type ReturnStmt

type ReturnStmt struct {
	Expr ExpressionLike

	Scope ScopeLike
	Pos   lexer.Position
}

func (*ReturnStmt) Generate

func (r *ReturnStmt) Generate() error

func (*ReturnStmt) String

func (r *ReturnStmt) String() []string

type Scope

type Scope struct {
	File   *utils.File
	Level  int
	Parent ScopeLike
}

func NewScope

func NewScope(file *utils.File) *Scope

func NewScopeFromParent

func NewScopeFromParent(parent ScopeLike) *Scope

func (*Scope) PrefixLines

func (s *Scope) PrefixLines(lines []string) []string

type ScopeLike

type ScopeLike interface {
	Current() *Scope
	AddModuleTypeDef(alias string, typ *Type)
	AddLocalType(alias string, typ *Type)
	AddGlobal(v *Variable)
	AddLocal(v *Variable) error
	FindTypeDefByAlias(alias string) *TypeDef
	FindTypeDefByType(typ *Type) *TypeDef
	FindVariable(ident string) *Variable
	FindFunction(ident string) *Function
	CurrentModule() *Module
	CurrentFunction() *Function
	BasicBlock() *ir.Block
	SetBasicBlock(b *ir.Block)
}

type SizeOfOp

type SizeOfOp struct {
	Type *Type
	Expr ExpressionLike

	Scope ScopeLike
	Pos   lexer.Position
}

func (*SizeOfOp) String

func (s *SizeOfOp) String() string

func (*SizeOfOp) Value

func (s *SizeOfOp) Value() (*Value, error)

type StatementLike

type StatementLike interface {
	String() []string
	Generate() error
}

type StatementLikeList

type StatementLikeList []StatementLike

func (StatementLikeList) String

func (s StatementLikeList) String() []string

type StructField

type StructField struct {
	Ident string
	Type  *Type
}

func (*StructField) String

func (st *StructField) String() string

type StructType

type StructType struct {
	Fields []*StructField
}

func (*StructType) Equals

func (st *StructType) Equals(o *StructType) bool

func (*StructType) FindField

func (st *StructType) FindField(field string) (int, *StructField, error)

func (*StructType) String

func (st *StructType) String() string

type Type

type Type struct {
	Scope ScopeLike
	Pos   lexer.Position
	// contains filtered or unexported fields
}

func NewTypeAlias

func NewTypeAlias(scope ScopeLike, pos lexer.Position, alias string) *Type

func NewTypeBasic

func NewTypeBasic(scope ScopeLike, pos lexer.Position, typ BasicType) *Type

func NewTypeStruct

func NewTypeStruct(scope ScopeLike, pos lexer.Position, fields ...*StructField) *Type

func (*Type) Alias

func (t *Type) Alias() string

func (*Type) AliasOf

func (t *Type) AliasOf(o *Type) bool

AliasOf returns true if types are compatible to each other to be used for casting

func (*Type) AliasedType

func (t *Type) AliasedType() *Type

AliasedType returns the type at the end of the alias chain.

func (*Type) Array

func (t *Type) Array() *ArrayType

func (*Type) Basic

func (t *Type) Basic() BasicType

func (*Type) BasicSize

func (t *Type) BasicSize() int

func (*Type) Equals

func (t *Type) Equals(o *Type) bool

func (*Type) IRType

func (t *Type) IRType() (types.Type, error)

func (*Type) IsAlias

func (t *Type) IsAlias() bool

func (*Type) IsArray

func (t *Type) IsArray() bool

func (*Type) IsBasic

func (t *Type) IsBasic() bool

func (*Type) IsBool

func (t *Type) IsBool() bool

func (*Type) IsFloat

func (t *Type) IsFloat() bool

func (*Type) IsInt

func (t *Type) IsInt() bool

func (*Type) IsPointer

func (t *Type) IsPointer() bool

func (*Type) IsStruct

func (t *Type) IsStruct() bool

func (*Type) IsUInt

func (t *Type) IsUInt() bool

func (*Type) IsVoid

func (t *Type) IsVoid() bool

func (*Type) LLVMFloatType

func (t *Type) LLVMFloatType() *types.FloatType

func (*Type) LLVMIntType

func (t *Type) LLVMIntType() *types.IntType

func (*Type) NewArray

func (t *Type) NewArray(len int) *Type

func (*Type) NewPointer

func (t *Type) NewPointer() *Type

func (*Type) Pointer

func (t *Type) Pointer() *Type

func (*Type) PointerLevel

func (t *Type) PointerLevel() int

func (*Type) String

func (t *Type) String() string

func (*Type) Struct

func (t *Type) Struct() *StructType

type TypeDef

type TypeDef struct {
	Alias string
	Type  *Type
}

func (*TypeDef) String

func (td *TypeDef) String() []string

type UnaryOp

type UnaryOp struct {
	Op        string
	Expr      ExpressionLike
	IsPostfix bool

	Scope ScopeLike
	Pos   lexer.Position
}

func (*UnaryOp) String

func (u *UnaryOp) String() string

func (*UnaryOp) Value

func (u *UnaryOp) Value() (*Value, error)

type Value

type Value struct {
	Type  *Type
	Ptr   value.Value
	Value value.Value
}

type Variable

type Variable struct {
	Ident   string
	Type    *Type
	IsParam bool

	// LLVM IR pointer to the variable
	Ptr value.Value

	Pos lexer.Position
}

func (*Variable) String

func (v *Variable) String() string

type VariableList

type VariableList []*Variable

func (VariableList) String

func (vl VariableList) String() string

type WhileStmt

type WhileStmt struct {
	Condition ExpressionLike
	Body      []StatementLike

	Scope ScopeLike
	Pos   lexer.Position
}

func (*WhileStmt) Generate

func (w *WhileStmt) Generate() error

func (*WhileStmt) String

func (w *WhileStmt) String() []string

Jump to

Keyboard shortcuts

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