diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-07-18 15:22:20 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-18 15:22:20 -0700 |
| commit | a01014567cccc2582547ed10870352629ffd6484 (patch) | |
| tree | 30e1bf209e232d7f8d6723959db68b2c0cb015dd /source/slang/lower.cpp | |
| parent | 3d313d963f29f6ca6a8d12bd5c403a70c49aca2a (diff) | |
| parent | 2476c035ec15d3ee22239ebd1fe10e6e8c1e01e3 (diff) | |
Merge pull request #120 from tfoleyNV/compile-time-loop
Add a compile-time loop construct to Slang
Diffstat (limited to 'source/slang/lower.cpp')
| -rw-r--r-- | source/slang/lower.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/source/slang/lower.cpp b/source/slang/lower.cpp index bbbfe724b..127ef75ca 100644 --- a/source/slang/lower.cpp +++ b/source/slang/lower.cpp @@ -1628,6 +1628,41 @@ struct LoweringVisitor lowerForStmtCommon(new UnscopedForStmt(), stmt); } + void visitCompileTimeForStmt(CompileTimeForStmt* stmt) + { + // We can either lower this here, so that emit logic doesn't have to deal with it, + // or else just translate it and then let emit deal with it. + // + // The right answer is really to lower it here, I guess. + + auto rangeBeginVal = GetIntVal(stmt->rangeBeginVal); + auto rangeEndVal = GetIntVal(stmt->rangeEndVal); + + if (rangeBeginVal >= rangeEndVal) + return; + + auto varDecl = stmt->varDecl; + + auto varType = lowerType(varDecl->Type); + + for (IntegerLiteralValue ii = rangeBeginVal; ii < rangeEndVal; ++ii) + { + RefPtr<ConstantExpressionSyntaxNode> constExpr = new ConstantExpressionSyntaxNode(); + constExpr->Type.type = varType.type; + constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Int; + constExpr->integerValue = ii; + + RefPtr<VaryingTupleVarDecl> loweredVarDecl = new VaryingTupleVarDecl(); + loweredVarDecl->Position = varDecl->Position; + loweredVarDecl->Type = varType; + loweredVarDecl->Expr = constExpr; + + shared->loweredDecls[varDecl] = loweredVarDecl; + + lowerStmtImpl(stmt->body); + } + } + void visitWhileStatementSyntaxNode(WhileStatementSyntaxNode* stmt) { RefPtr<WhileStatementSyntaxNode> loweredStmt = new WhileStatementSyntaxNode(); |
