emitter

package
v0.0.0-...-169fbab Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2023 License: GPL-3.0 Imports: 17 Imported by: 0

README

ReCT Emitter

*Slaps roof of abstract theoretical concept*
This bad boy can compile lowered and bound ReCT functions to LLVM IR.

Garbage Collection: The Deranged Mumblings of a Grown man at 3 am

So LLVM garbage collection is quite a huge rabbit hole. I've taken some time to look into possibilities of what we could use and how. LLVM does not provide a garbage collector but it does provide some functionality for interfacing with GCs and also has a few built in GC strategies you can use.

Our goal is to identify all pointers in the program at rune-time which requires us to check the stack and registers. LLVM provides support for creating safe-points where GC can happen safely, generating stack maps of object references the GC may need to update, and creating barriers when storing object references in the heap.

We can use built-in GC strategies like "The Shadow Stack GC" this strategy has high overhead per function call as it maintains a "shadow stack" which mirrors the machine stack - Note: a faster way would be to compile stack maps into the executable.

LLVM IR has a bunch of features to interface with the GC runtime. LLVM seems to rely on "statepoints".

MMm reddit time

So check out this reddit post from about 4 years ago, dude has the exact same problem, has a language that can compiler to IR but confused on how GC is put together. Unfortunately, the only decent reply is someone talking about how plugging in your own GC is hella confusing, and they recommend you use the Boehm-Demers-Weiser GC or the Memory Pool System GC. Another reply talks about how they researched the Boehm-Demers-Weiser GC...

Though I really like the idea of us figuring this out on our own, for the time being it may be easier to use a non-llvm approach. It seems boehm-demer-weider gc is the easiest to set up, so we should just use that for now.

Resources

LLVM Garbage Collection LLVM Accurate Garbage Collection

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AdapterModule string
View Source
var CompileAsPackage bool
View Source
var CurrentVersion string
View Source
var EmitDebugInfo = false
View Source
var PackageName string
View Source
var SourceFile string
View Source
var VerboseARC = false

Functions

func CB1

func CB1(val bool) value.Value

b o o l

func CI32

func CI32(val int32) value.Value

another little shortcut to create an integer constant

func CIC32

func CIC32(val int32) constant.Constant

func Emit

func Emit(program binder.BoundProgram, useFingerprints bool) *ir.Module

func FindType

func FindType(module *ir.Module, name string) types.Type

func GlobalExists

func GlobalExists(module *ir.Module, name string) bool

Types

type Class

type Class struct {
	Type types.Type

	Constructor *ir.Func
	Functions   map[string]*ir.Func
	Fields      map[string]int
	Name        string
	// contains filtered or unexported fields
}

type Comment

type Comment struct {
	Text string
	// embed a dummy ir.Instruction to have Comment implement the ir.Instruction
	// interface.
	ir.Instruction
}

func NewComment

func NewComment(s string) *Comment

func (*Comment) LLString

func (c *Comment) LLString() string

type ConvertedStruct

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

type Emitter

type Emitter struct {
	Program         binder.BoundProgram
	Module          *ir.Module
	UseFingerprints bool

	// referenced functions
	CFuncs   map[string]*ir.Func
	ExcFuncs map[string]*ir.Func

	// referenced classes
	Classes map[string]*Class

	// referenced structs
	Structs map[string]*Struct

	// referenced packages
	Packages map[string]*Package

	// global variables
	Globals          map[string]Global
	Functions        map[string]Function
	FunctionWrappers map[string]*ir.Func
	Lambdas          map[string]*ir.Func
	FunctionLocals   map[string]map[string]Local
	StrConstants     map[string]value.Value
	StrNameCounter   int

	// local things for this current class
	Class    *Class
	ClassSym symbols.ClassSymbol

	// local things for this current function
	Function    *ir.Func
	FunctionSym symbols.FunctionSymbol
	Locals      map[string]Local
	Temps       []string
	Labels      map[string]*ir.Block

	// flags
	IsInClass bool
}

func (*Emitter) Adapt

func (emt *Emitter) Adapt()

func (*Emitter) Box

func (emt *Emitter) Box(blk **ir.Block, val value.Value, typ symbols.TypeSymbol) value.Value

func (*Emitter) ConvertExternalCall

func (emt *Emitter) ConvertExternalCall(function symbols.FunctionSymbol) string

func (*Emitter) ConvertType

func (emt *Emitter) ConvertType(fld symbols.TypeSymbol, structsAsPointers bool) string

func (*Emitter) CreateObject

func (emt *Emitter) CreateObject(blk **ir.Block, src symbols.TypeSymbol, args ...value.Value) value.Value

func (*Emitter) DefaultConstant

func (emt *Emitter) DefaultConstant(blk **ir.Block, typ symbols.TypeSymbol) constant.Constant

func (*Emitter) EmitArrayAccessExpression

func (emt *Emitter) EmitArrayAccessExpression(blk **ir.Block, expr boundnodes.BoundArrayAccessExpressionNode) value.Value

func (*Emitter) EmitArrayAccessRef

func (emt *Emitter) EmitArrayAccessRef(blk **ir.Block, expr boundnodes.BoundArrayAccessExpressionNode) value.Value

func (*Emitter) EmitArrayAssignment

func (emt *Emitter) EmitArrayAssignment(blk **ir.Block, base value.Value, index value.Value, literalValue boundnodes.BoundExpressionNode)

func (*Emitter) EmitArrayAssignmentExpression

func (emt *Emitter) EmitArrayAssignmentExpression(blk **ir.Block, expr boundnodes.BoundArrayAssignmentExpressionNode) value.Value

func (*Emitter) EmitAssignment

func (emt *Emitter) EmitAssignment(blk **ir.Block, variable symbols.LocalVariableSymbol, val boundnodes.BoundExpressionNode)

func (*Emitter) EmitAssignmentExpression

func (emt *Emitter) EmitAssignmentExpression(blk **ir.Block, expr boundnodes.BoundAssignmentExpressionNode) value.Value

func (*Emitter) EmitBinaryExpression

func (emt *Emitter) EmitBinaryExpression(blk **ir.Block, expr boundnodes.BoundBinaryExpressionNode) value.Value

func (*Emitter) EmitBlockStatement

func (emt *Emitter) EmitBlockStatement(sym symbols.FunctionSymbol, fnc *ir.Func, body boundnodes.BoundBlockStatementNode)

func (*Emitter) EmitBoundExpressionStatement

func (emt *Emitter) EmitBoundExpressionStatement(blk **ir.Block, stmt boundnodes.BoundExpressionStatementNode)

func (*Emitter) EmitBuiltInFunctions

func (emt *Emitter) EmitBuiltInFunctions()

func (*Emitter) EmitCLibReferences

func (emt *Emitter) EmitCLibReferences()

func (*Emitter) EmitCallExpression

func (emt *Emitter) EmitCallExpression(blk **ir.Block, expr boundnodes.BoundCallExpressionNode) value.Value

func (*Emitter) EmitClass

func (emt *Emitter) EmitClass(cls binder.BoundClass)

</STRUCTS>------------------------------------------------------------------ <CLASSES>-------------------------------------------------------------------

func (*Emitter) EmitClassAndArcReferences

func (emt *Emitter) EmitClassAndArcReferences(module *ir.Module)

func (*Emitter) EmitClassCallExpression

func (emt *Emitter) EmitClassCallExpression(blk **ir.Block, expr boundnodes.BoundClassCallExpressionNode) value.Value

func (*Emitter) EmitClassConstructor

func (emt *Emitter) EmitClassConstructor(cls *Class, bcls binder.BoundClass, clsvConstant value.Value, clsFieldMap map[string]int) *ir.Func

func (*Emitter) EmitClassFieldAccessExpression

func (emt *Emitter) EmitClassFieldAccessExpression(blk **ir.Block, expr boundnodes.BoundClassFieldAccessExpressionNode) value.Value

func (*Emitter) EmitClassFieldAccessExpressionRef

func (emt *Emitter) EmitClassFieldAccessExpressionRef(blk **ir.Block, _base boundnodes.BoundExpressionNode, field symbols.VariableSymbol) (value.Value, value.Value)

func (*Emitter) EmitClassFieldAssignmentExpression

func (emt *Emitter) EmitClassFieldAssignmentExpression(blk **ir.Block, expr boundnodes.BoundClassFieldAssignmentExpressionNode) value.Value

func (*Emitter) EmitClassFunction

func (emt *Emitter) EmitClassFunction(cls symbols.ClassSymbol, sym symbols.FunctionSymbol, body boundnodes.BoundBlockStatementNode) *ir.Func

func (*Emitter) EmitConditionalGotoStatement

func (emt *Emitter) EmitConditionalGotoStatement(blk **ir.Block, stmt boundnodes.BoundConditionalGotoStatementNode)

func (*Emitter) EmitConversionExpression

func (emt *Emitter) EmitConversionExpression(blk **ir.Block, expr boundnodes.BoundConversionExpressionNode) value.Value

func (*Emitter) EmitDereferenceExpression

func (emt *Emitter) EmitDereferenceExpression(blk **ir.Block, expr boundnodes.BoundDereferenceExpressionNode) value.Value

func (*Emitter) EmitEnumExpression

func (emt *Emitter) EmitEnumExpression(blk **ir.Block, expr boundnodes.BoundEnumExpressionNode) value.Value

func (*Emitter) EmitExpression

func (emt *Emitter) EmitExpression(blk **ir.Block, expr boundnodes.BoundExpressionNode) value.Value

func (*Emitter) EmitExternalFunction

func (emt *Emitter) EmitExternalFunction(sym symbols.FunctionSymbol) *ir.Func

func (*Emitter) EmitFunction

func (emt *Emitter) EmitFunction(sym symbols.FunctionSymbol, body boundnodes.BoundBlockStatementNode) *ir.Func

func (*Emitter) EmitFunctionExpression

func (emt *Emitter) EmitFunctionExpression(blk **ir.Block, expr boundnodes.BoundFunctionExpressionNode) value.Value

func (*Emitter) EmitGotoStatement

func (emt *Emitter) EmitGotoStatement(blk **ir.Block, stmt boundnodes.BoundGotoStatementNode)

func (*Emitter) EmitLambdaExpression

func (emt *Emitter) EmitLambdaExpression(blk **ir.Block, expr boundnodes.BoundLambdaExpressionNode) value.Value

func (*Emitter) EmitLiteralExpression

func (emt *Emitter) EmitLiteralExpression(blk **ir.Block, expr boundnodes.BoundLiteralExpressionNode) value.Value

func (*Emitter) EmitMakeArrayExpression

func (emt *Emitter) EmitMakeArrayExpression(blk **ir.Block, expr boundnodes.BoundMakeArrayExpressionNode) value.Value

func (*Emitter) EmitMakeExpression

func (emt *Emitter) EmitMakeExpression(blk **ir.Block, expr boundnodes.BoundMakeExpressionNode) value.Value

func (*Emitter) EmitMakeStructExpression

func (emt *Emitter) EmitMakeStructExpression(blk **ir.Block, expr boundnodes.BoundMakeStructExpressionNode) value.Value

func (*Emitter) EmitPackageCallExpression

func (emt *Emitter) EmitPackageCallExpression(blk **ir.Block, expr boundnodes.BoundPackageCallExpressionNode) value.Value

func (*Emitter) EmitPointerAccessExpression

func (emt *Emitter) EmitPointerAccessExpression(blk **ir.Block, expr boundnodes.BoundArrayAccessExpressionNode, base value.Value, index value.Value) value.Value

func (*Emitter) EmitPointerAccessRef

func (emt *Emitter) EmitPointerAccessRef(blk **ir.Block, expr boundnodes.BoundArrayAccessExpressionNode) value.Value

func (*Emitter) EmitPointerAssignmentExpression

func (emt *Emitter) EmitPointerAssignmentExpression(blk **ir.Block, expr boundnodes.BoundArrayAssignmentExpressionNode, base value.Value, index value.Value, value value.Value) value.Value

func (*Emitter) EmitReferenceExpression

func (emt *Emitter) EmitReferenceExpression(blk **ir.Block, expr boundnodes.BoundReferenceExpressionNode) value.Value

func (*Emitter) EmitReturnStatement

func (emt *Emitter) EmitReturnStatement(blk **ir.Block, stmt boundnodes.BoundReturnStatementNode)

func (*Emitter) EmitStruct

func (emt *Emitter) EmitStruct(stc symbols.StructSymbol)

<STRUCTS>-------------------------------------------------------------------

func (*Emitter) EmitStructFieldAccessExpression

func (emt *Emitter) EmitStructFieldAccessExpression(blk **ir.Block, expr boundnodes.BoundClassFieldAccessExpressionNode) value.Value

func (*Emitter) EmitStructFieldAccessExpressionRef

func (emt *Emitter) EmitStructFieldAccessExpressionRef(blk **ir.Block, base boundnodes.BoundExpressionNode, field symbols.VariableSymbol) value.Value

func (*Emitter) EmitStructFieldAssignmentExpression

func (emt *Emitter) EmitStructFieldAssignmentExpression(blk **ir.Block, expr boundnodes.BoundClassFieldAssignmentExpressionNode) value.Value

func (*Emitter) EmitTernaryExpression

func (emt *Emitter) EmitTernaryExpression(blk **ir.Block, expr boundnodes.BoundTernaryExpressionNode) value.Value

func (*Emitter) EmitThisExpression

func (emt *Emitter) EmitThisExpression(blk **ir.Block, expr boundnodes.BoundThisExpressionNode) value.Value

func (*Emitter) EmitTypeCallExpression

func (emt *Emitter) EmitTypeCallExpression(blk **ir.Block, expr boundnodes.BoundTypeCallExpressionNode) value.Value

func (*Emitter) EmitUnaryExpression

func (emt *Emitter) EmitUnaryExpression(blk **ir.Block, expr boundnodes.BoundUnaryExpressionNode) value.Value

func (*Emitter) EmitUnloadedReference

func (emt *Emitter) EmitUnloadedReference(blk **ir.Block, expr boundnodes.BoundExpressionNode) (value.Value, value.Value)

func (*Emitter) EmitValidConversionCheck

func (emt *Emitter) EmitValidConversionCheck(blk **ir.Block, typ symbols.TypeSymbol, val value.Value)

func (*Emitter) EmitVariable

func (emt *Emitter) EmitVariable(blk **ir.Block, variable symbols.VariableSymbol, inMain bool) value.Value

func (*Emitter) EmitVariableDeclaration

func (emt *Emitter) EmitVariableDeclaration(blk **ir.Block, varibale symbols.LocalVariableSymbol, isTmp bool)

func (*Emitter) EmitVariableDeclarationStatement

func (emt *Emitter) EmitVariableDeclarationStatement(blk **ir.Block, stmt boundnodes.BoundVariableDeclarationStatementNode)

func (*Emitter) EmitVariableExpression

func (emt *Emitter) EmitVariableExpression(blk **ir.Block, expr boundnodes.BoundVariableExpressionNode) value.Value

func (*Emitter) EmitVariablePtr

func (emt *Emitter) EmitVariablePtr(blk **ir.Block, variable symbols.VariableSymbol, inMain bool) value.Value

func (*Emitter) GetConstantStringConstant

func (emt *Emitter) GetConstantStringConstant(literal string) constant.Constant

func (*Emitter) GetStringConstant

func (emt *Emitter) GetStringConstant(blk **ir.Block, literal string) value.Value

func (*Emitter) GetThreadWrapper

func (emt *Emitter) GetThreadWrapper(source symbols.TypeSymbol) *ir.Func

func (*Emitter) GetVtableConstant

func (emt *Emitter) GetVtableConstant(src symbols.TypeSymbol, typ string) value.Value

func (*Emitter) IRTypes

func (emt *Emitter) IRTypes(typ symbols.TypeSymbol) types.Type

func (*Emitter) Id

func (emt *Emitter) Id(sym symbols.Symbol) string

a little function to get the relevant name of a symbol (name or fingerprint)

func (*Emitter) ImportFunction

func (emt *Emitter) ImportFunction(fnc *ir.Func) *ir.Func

func (*Emitter) ImportPackage

func (emt *Emitter) ImportPackage(pack symbols.PackageSymbol)

func (*Emitter) ImportType

func (emt *Emitter) ImportType(typ types.Type)

func (*Emitter) InitDbg

func (emt *Emitter) InitDbg()

func (*Emitter) LoadAndReferenceClasses

func (emt *Emitter) LoadAndReferenceClasses(module *ir.Module)

func (*Emitter) LoadAndReferenceClassesFromPackage

func (emt *Emitter) LoadAndReferenceClassesFromPackage(module *ir.Module, pack symbols.PackageSymbol)

func (*Emitter) PopulateClass

func (emt *Emitter) PopulateClass(cls *Class, bcls binder.BoundClass)

func (*Emitter) PopulateStruct

func (emt *Emitter) PopulateStruct(stc *Struct, bstc symbols.StructSymbol)

func (*Emitter) ResolveArray

func (emt *Emitter) ResolveArray(typ symbols.TypeSymbol, cache *map[string]types.Type, generic symbols.TypeSymbol) types.Type

func (*Emitter) ResolveFunctionPointer

func (emt *Emitter) ResolveFunctionPointer(subTypes []symbols.TypeSymbol) types.Type

func (*Emitter) SizeOf

func (emt *Emitter) SizeOf(blk **ir.Block, typ symbols.TypeSymbol) value.Value

func (*Emitter) TypeExists

func (emt *Emitter) TypeExists(name string) bool

type Function

type Function struct {
	IRFunction    *ir.Func
	BoundFunction binder.BoundFunction
}

type Global

type Global struct {
	IRGlobal *ir.Global
	Type     symbols.TypeSymbol
}

type Local

type Local struct {
	IRLocal value.Value
	IRBlock *ir.Block
	Type    symbols.TypeSymbol
	IsSet   bool
}

type Package

type Package struct {
	Functions map[string]*ir.Func
}

type Struct

type Struct struct {
	Type   types.Type
	Fields map[string]int
	Name   string
	Symbol symbols.StructSymbol
}

Jump to

Keyboard shortcuts

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