From f039be92b6bd066853acbfadd2339ac8edc98074 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 27 Jan 2024 14:17:52 -0500 Subject: [PATCH] Remove redundant val variable/declaration generation --- generator/blockmanager.go | 4 ++-- generator/expression-multiplex.go | 11 +++-------- generator/expression-val.go | 16 ---------------- 3 files changed, 5 insertions(+), 26 deletions(-) diff --git a/generator/blockmanager.go b/generator/blockmanager.go index 1d22c61..3ef0308 100644 --- a/generator/blockmanager.go +++ b/generator/blockmanager.go @@ -60,8 +60,8 @@ func (this *blockManager) topLoop () *loopEntry { return this.loops[len(this.loops) - 1] } -func (this *blockManager) newAllocaFront (element llvm.Type) llvm.Value { - alloca := llvm.NewAlloca(element) +func (this *blockManager) newAllocaFront (ty llvm.Type) llvm.Value { + alloca := llvm.NewAlloca(ty) firstBlock := this.function.Blocks[0] if firstBlock.Terminated() { diff --git a/generator/expression-multiplex.go b/generator/expression-multiplex.go index 97dc420..9b12820 100644 --- a/generator/expression-multiplex.go +++ b/generator/expression-multiplex.go @@ -57,9 +57,6 @@ func (this *generator) generateExpression ( // whichever will generate the least IR. In the latter case, the boolean // "location" will be true. func (this *generator) generateExpressionAny (expression entity.Expression) (register llvm.Value, location bool, err error) { - // TODO: some of these could stand to know that they have a choice in - // the matter. - switch expression := expression.(type) { // these give us an address case *entity.Dereference, @@ -115,17 +112,15 @@ func (this *generator) generateExpressionVal (expression entity.Expression) (llv *entity.Subscript, *entity.LiteralArray, *entity.LiteralString, - *entity.LiteralStruct: + *entity.LiteralStruct, + *entity.Variable, + *entity.Declaration: pointer, err := this.generateExpressionLoc(expression) if err != nil { return nil, err } return this.locationToValue(pointer, expression.Type()) // we get a value from these, so we can return them as-is - case *entity.Variable: - return this.generateVariableVal(expression) - case *entity.Declaration: - return this.generateDeclarationVal(expression) case *entity.Call: return this.generateCallVal(expression) case *entity.MethodCall: diff --git a/generator/expression-val.go b/generator/expression-val.go index 053df1c..27bc07d 100644 --- a/generator/expression-val.go +++ b/generator/expression-val.go @@ -6,22 +6,6 @@ import "git.tebibyte.media/sashakoshka/fspl/llvm" import "git.tebibyte.media/sashakoshka/fspl/entity" import "git.tebibyte.media/sashakoshka/fspl/analyzer" -func (this *generator) generateVariableVal (variable *entity.Variable) (llvm.Value, error) { - location, err := this.generateVariableLoc(variable) - if err != nil { return nil, err } - irType, err := this.generateType(variable.Type()) - if err != nil { return nil, err } - return this.blockManager.NewLoad(irType, location), nil -} - -func (this *generator) generateDeclarationVal (declaration *entity.Declaration) (llvm.Value, error) { - location, err := this.blockManager.addDeclaration(declaration, nil) - if err != nil { return nil, err } - irType, err := this.generateType(declaration.Type()) - if err != nil { return nil, err } - return this.blockManager.NewLoad(irType, location), nil -} - func (this *generator) generateCallVal (call *entity.Call) (llvm.Value, error) { function, err := this.function(call.Name) if err != nil { return nil, err }