For loop generation should be more correct now
This commit is contained in:
parent
491a9b2369
commit
50f088842a
|
@ -234,12 +234,12 @@ func (this *generator) generateFor (loop *entity.For, mode resultMode) (llvm.Val
|
|||
body := this.blockManager.newBlock()
|
||||
exit := this.blockManager.newBlock()
|
||||
previous.NewBr(header)
|
||||
this.blockManager.Block = header
|
||||
|
||||
loopEntry := this.blockManager.pushLoop(mode)
|
||||
defer this.blockManager.popLoop()
|
||||
|
||||
// check bounds
|
||||
this.blockManager.Block = header
|
||||
var irLength llvm.Value
|
||||
if isArray {
|
||||
irLength = llvm.NewConstInt(irIndexType, int64(array.Length))
|
||||
|
@ -255,9 +255,8 @@ func (this *generator) generateFor (loop *entity.For, mode resultMode) (llvm.Val
|
|||
irLength),
|
||||
body, exit)
|
||||
|
||||
this.blockManager.Block = body
|
||||
|
||||
// set element
|
||||
this.blockManager.Block = body
|
||||
var irDataLoc llvm.Value
|
||||
if isArray {
|
||||
irDataLoc = irOverLoc
|
||||
|
@ -273,18 +272,18 @@ func (this *generator) generateFor (loop *entity.For, mode resultMode) (llvm.Val
|
|||
this.blockManager.NewLoad(irIndexType, irIndexLoc)),
|
||||
irElementLoc)
|
||||
|
||||
// generate loop body
|
||||
this.blockManager.Block = body
|
||||
_, _, err = this.generateExpressionAny(loop.Body)
|
||||
if err != nil { return nil, false, err }
|
||||
|
||||
// increment index and loop back around
|
||||
this.blockManager.NewStore (
|
||||
this.blockManager.NewAdd (
|
||||
this.blockManager.NewLoad(irIndexType, irIndexLoc),
|
||||
llvm.NewConstInt(irIndexType, 1)),
|
||||
irIndexLoc)
|
||||
this.blockManager.NewBr(body)
|
||||
if !this.blockManager.Terminated() {
|
||||
// increment index
|
||||
this.blockManager.NewStore (
|
||||
this.blockManager.NewAdd (
|
||||
this.blockManager.NewLoad(irIndexType, irIndexLoc),
|
||||
llvm.NewConstInt(irIndexType, 1)),
|
||||
irIndexLoc)
|
||||
}
|
||||
|
||||
this.blockManager.Block = exit
|
||||
if loopEntry.stub != nil {
|
||||
|
|
Loading…
Reference in New Issue