Generate assignment to unions
This commit is contained in:
parent
9e6aebf518
commit
7154f5d333
@ -139,6 +139,31 @@ func (this *generator) generateAssignmentToDestination ( // TODO: add -Val suffi
|
||||
return this.blockManager.NewLoad(irDestType, irDestLoc), nil
|
||||
}
|
||||
|
||||
// conversion from any type to union
|
||||
case *entity.TypeUnion:
|
||||
irHashType := llvm.I64
|
||||
|
||||
// create destination union, if necessary
|
||||
irDestType, err := this.generateType(destType)
|
||||
if err != nil { return nil, err }
|
||||
if !destinationSpecified {
|
||||
irDestLoc = this.blockManager.newAllocaFront(irDestType)
|
||||
}
|
||||
destTypeFieldLoc := this.getUnionTypeFieldLoc(irDestLoc, irDestType)
|
||||
destDataFieldLoc := this.getUnionDataFieldLoc(irDestLoc, irDestType)
|
||||
|
||||
// store type hash
|
||||
hash := source.Type().Hash()
|
||||
this.blockManager.NewStore (
|
||||
llvm.NewConstInt(irHashType, int64(hash.Number())),
|
||||
destTypeFieldLoc)
|
||||
|
||||
// store data
|
||||
source, err := this.generateExpressionVal(source)
|
||||
if err != nil { return nil, err }
|
||||
this.blockManager.NewStore(source, destDataFieldLoc)
|
||||
return this.blockManager.NewLoad(irDestType, irDestLoc), nil
|
||||
|
||||
// conversion from any type to pointer
|
||||
case *entity.TypePointer:
|
||||
// assignments
|
||||
|
Loading…
Reference in New Issue
Block a user