Remove redundant val variable/declaration generation
This commit is contained in:
		
							parent
							
								
									f994c4dc08
								
							
						
					
					
						commit
						3a4a5683b5
					
				@ -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() {
 | 
			
		||||
 | 
			
		||||
@ -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:
 | 
			
		||||
 | 
			
		||||
@ -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 }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user