diff options
| author | Tim Foley <tim.foley.is@gmail.com> | 2017-09-25 11:27:54 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-25 11:27:54 -0700 |
| commit | b6cf0f4ae0f3f9d1f377d3f134dcf994676e68b4 (patch) | |
| tree | bcc781497b36664cbebe10d91f888be674c82f8b /source/slang/ir.cpp | |
| parent | b206af702cbc8cc42c73052ad690d69984ecd7b7 (diff) | |
| parent | 0aa440a22ab18bc4a9077fcf17966ed4949d684b (diff) | |
Merge pull request #191 from tfoleyNV/ir-work
More work on IR-based lowering and cross-compilation
Diffstat (limited to 'source/slang/ir.cpp')
| -rw-r--r-- | source/slang/ir.cpp | 76 |
1 files changed, 61 insertions, 15 deletions
diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index 2c6395903..3e12ef1a2 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -83,7 +83,14 @@ namespace Slang auto entryBlock = getFirstBlock(); if(!entryBlock) return nullptr; - auto firstInst = entryBlock->firstChild; + return entryBlock->getFirstParam(); + } + + // IRBlock + + IRParam* IRBlock::getFirstParam() + { + auto firstInst = firstChild; if(!firstInst) return nullptr; if(firstInst->op != kIROp_Param) @@ -92,6 +99,7 @@ namespace Slang return (IRParam*) firstInst; } + // IRParam IRParam* IRParam::getNextParam() @@ -781,6 +789,18 @@ namespace Slang return getArrayType(elementType, nullptr); } + IRType* IRBuilder::getGenericParameterType(UInt index) + { + auto indexVal = getIntValue(getBaseType(BaseType::Int), index); + + return findOrEmitInst<IRGenericParameterType>( + this, + kIROp_GenericParameterType, + getTypeType(), + indexVal); + + } + IRType* IRBuilder::getTypeType() { @@ -1442,6 +1462,11 @@ namespace Slang { dump(context, "<null>"); } + else if( auto mangled = inst->findDecoration<IRMangledNameDecoration>() ) + { + dump(context, "@"); + dump(context, mangled->mangledName.Buffer()); + } else if(inst->id) { dump(context, "%"); @@ -1526,6 +1551,21 @@ namespace Slang dumpID(context, type); break; + case kIROp_FuncType: + { + auto funcType = (IRFuncType*) type; + UInt paramCount = funcType->getParamCount(); + dump(context, "("); + for( UInt pp = 0; pp < paramCount; ++pp ) + { + if(pp != 0) dump(context, ", "); + dumpType(context, funcType->getParamType(pp)); + } + dump(context, ") -> "); + dumpType(context, funcType->getResultType()); + } + break; + default: { dump(context, opInfo.name); @@ -1619,20 +1659,8 @@ namespace Slang dumpIndent(context); dump(context, "func "); dumpID(context, func); - dump(context, "(\n"); - context->indent++; - for (auto pp = func->getFirstParam(); pp; pp = pp->getNextParam()) - { - if (pp != func->getFirstParam()) - dump(context, ",\n"); - - dumpIndent(context); - dump(context, "param "); - dumpID(context, pp); - dumpInstTypeClause(context, pp->getType()); - } - context->indent--; - dump(context, ")\n"); + dumpInstTypeClause(context, func->getType()); + dump(context, "\n"); dumpIndent(context); dump(context, "{\n"); @@ -1665,6 +1693,24 @@ namespace Slang context->indent--; dump(context, "block "); dumpID(context, block); + + if( block->getFirstParam() ) + { + dump(context, "("); + context->indent++; + for (auto pp = block->getFirstParam(); pp; pp = pp->getNextParam()) + { + if (pp != block->getFirstParam()) + dump(context, ",\n"); + + dumpIndent(context); + dump(context, "param "); + dumpID(context, pp); + dumpInstTypeClause(context, pp->getType()); + } + context->indent--; + dump(context, ")\n"); + } dump(context, ":\n"); context->indent++; |
