Remove redundant val variable/declaration generation

This commit is contained in:
Sasha Koshka 2024-01-27 14:17:52 -05:00
parent c0f004d3b8
commit f039be92b6
3 changed files with 5 additions and 26 deletions

View File

@ -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() {

View File

@ -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:

View File

@ -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 }