summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2017-11-13 18:35:22 -0500
committerYong He <yonghe@outlook.com>2017-11-13 18:35:22 -0500
commit891c2c6055fe276e5527455ca59af80eea5c8328 (patch)
tree762a49add70dbb665a9e84fb09370ecc225719a7
parentbbf58baf84c704dff33f2b36d7277eebe573e11e (diff)
fix merge bug
-rw-r--r--source/slang/emit.cpp32
-rw-r--r--source/slang/lower-to-ir.cpp1
2 files changed, 28 insertions, 5 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index c72adea38..d41af9ef5 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -97,6 +97,8 @@ struct SharedEmitContext
Dictionary<IRValue*, UInt> mapIRValueToID;
HashSet<Decl*> irDeclsVisited;
+
+ Dictionary<IRBlock*, IRBlock*> irMapContinueTargetToLoopHead;
};
struct EmitContext
@@ -5564,10 +5566,9 @@ emitDeclImpl(decl, nullptr);
emit("for(;;)\n{\n");
- // TODO: Okay, we *said* we'd do this special
- // handling of the `continue` sites, but
- // we aren't actually setting anything up here...
- //
+ // Register information so that `continue` sites
+ // can do the right thing:
+ ctx->shared->irMapContinueTargetToLoopHead.Add(continueBlock, targetBlock);
emitIRStmtsForBlocks(
ctx,
@@ -5588,7 +5589,28 @@ emitDeclImpl(decl, nullptr);
return;
case kIROp_continue:
- emit("continue;\n");
+ // With out current strategy for outputting loops,
+ // just outputting an AST-level `continue` here won't
+ // actually execute the statements in the continue block.
+ //
+ // Instead, we have to manually output those statements
+ // directly here, and *then* do an AST-level `continue`.
+ //
+ // This leads to code duplication when we have multiple
+ // `continue` sites in the original program, but it avoids
+ // introducing additional temporaries for control flow.
+ {
+ auto continueInst = (IRContinue*)terminator;
+ auto targetBlock = continueInst->getTargetBlock();
+ IRBlock* loopHead = nullptr;
+ ctx->shared->irMapContinueTargetToLoopHead.TryGetValue(targetBlock, loopHead);
+ SLANG_ASSERT(loopHead);
+ emitIRStmtsForBlocks(
+ ctx,
+ targetBlock,
+ loopHead);
+ emit("continue;\n");
+ }
return;
case kIROp_loopTest:
diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp
index 759c386cd..bbbc1812b 100644
--- a/source/slang/lower-to-ir.cpp
+++ b/source/slang/lower-to-ir.cpp
@@ -2850,6 +2850,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
IRType* irParamType = irResultType;
paramTypes.Add(irParamType);
subBuilder->emitParam(irParamType);
+
// TODO: we need some way to wire this up to the `newValue`
// or whatever name we give for that parameter inside
// the setter body.