summaryrefslogtreecommitdiff
path: root/source/slang/lower-to-ir.cpp
diff options
context:
space:
mode:
authorTim Foley <tim.foley.is@gmail.com>2017-08-17 15:22:24 -0700
committerGitHub <noreply@github.com>2017-08-17 15:22:24 -0700
commit7e05e062a0b7c39dbce6e850227d2038aca2f38e (patch)
tree53a6a509f3bba87d964ba3a5007b538db1d83a4e /source/slang/lower-to-ir.cpp
parent1965c3f3f265c43c8d1d96bb49d0850ce5d53cc3 (diff)
parentec8175c1f0afe3f7758f70da240aba03a791c3a9 (diff)
Merge pull request #170 from tfoleyNV/ir
Add some dummy logic to print IR to HLSL
Diffstat (limited to 'source/slang/lower-to-ir.cpp')
-rw-r--r--source/slang/lower-to-ir.cpp62
1 files changed, 33 insertions, 29 deletions
diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp
index a01279f2e..781209dce 100644
--- a/source/slang/lower-to-ir.cpp
+++ b/source/slang/lower-to-ir.cpp
@@ -394,7 +394,7 @@ struct ExprLoweringVisitor : ExprVisitor<ExprLoweringVisitor, LoweredValInfo>
LoweredValInfo extractField(
LoweredTypeInfo fieldType,
LoweredValInfo base,
- UInt fieldIndex)
+ LoweredValInfo field)
{
switch (base.flavor)
{
@@ -405,7 +405,7 @@ struct ExprLoweringVisitor : ExprVisitor<ExprLoweringVisitor, LoweredValInfo>
getBuilder()->emitFieldExtract(
getSimpleType(fieldType),
irBase,
- fieldIndex));
+ (IRStructField*) getSimpleVal(field)));
}
break;
@@ -424,22 +424,8 @@ struct ExprLoweringVisitor : ExprVisitor<ExprLoweringVisitor, LoweredValInfo>
{
// Okay, easy enough: we have a reference to a field of a struct type...
- // HACK: for now just scan the decl to find the right index.
- // TODO: we need to deal with the fact that the struct might get
- // tuple-ified.
- //
- UInt index = 0;
- for (auto fieldDecl : getMembersOfType<StructField>(fieldDeclRef.GetParent().As<AggTypeDecl>()))
- {
- if (fieldDecl == fieldDeclRef.getDecl())
- {
- break;
- }
-
- index++;
- }
-
- return extractField(loweredType, loweredBase, index);
+ auto loweredField = ensureDecl(context, fieldDeclRef);
+ return extractField(loweredType, loweredBase, loweredField);
}
SLANG_UNIMPLEMENTED_X("codegen for subscript expression");
@@ -559,20 +545,29 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
// User-defined aggregate type: need to translate into
// a corresponding IR aggregate type.
- List<LoweredTypeInfo> fieldTypes;
- List<IRType*> irFieldTypes;
+ auto builder = getBuilder();
+ IRStructDecl* irStruct = builder->createStructType();
for (auto fieldDecl : decl->GetFields())
{
+ // TODO: need to track relationship to original fields...
+
// TODO: need to be prepared to deal with tuple-ness of fields here
auto fieldType = lowerType(context, fieldDecl->getType());
- fieldTypes.Add(fieldType);
-
switch (fieldType.flavor)
{
case LoweredTypeInfo::Flavor::Simple:
- irFieldTypes.Add(fieldType.type);
+ {
+ auto irField = builder->createStructField(getSimpleType(fieldType));
+ builder->addInst(irStruct, irField);
+
+ builder->addHighLevelDeclDecoration(irField, fieldDecl);
+
+ context->shared->declValues.Add(
+ DeclRef<StructField>(fieldDecl, nullptr),
+ LoweredValInfo::simple(irField));
+ }
break;
default:
@@ -580,13 +575,11 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
}
}
- // TODO: need to track relationship to original fields...
+ builder->addHighLevelDeclDecoration(irStruct, decl);
- IRType* irStructType = getBuilder()->getStructType(
- irFieldTypes.Count(),
- &irFieldTypes[0]);
+ builder->addInst(irStruct);
- return LoweredValInfo::simple(irStructType);
+ return LoweredValInfo::simple(irStruct);
}
LoweredValInfo visitFunctionDeclBase(FunctionDeclBase* decl)
@@ -608,9 +601,13 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
// set up sub context for generating our new function
+ List<IRType*> paramTypes;
+
for( auto paramDecl : decl->GetParameters() )
{
IRType* irParamType = lowerSimpleType(context, paramDecl->getType());
+ paramTypes.Add(irParamType);
+
IRParam* irParam = subBuilder->emitParam(irParamType);
DeclRef<ParamDecl> paramDeclRef = makeDeclRef(paramDecl.Ptr());
@@ -620,11 +617,18 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
subContext->shared->declValues.Add(paramDeclRef, irParamVal);
}
- auto irResultType = lowerType(context, decl->ReturnType);
+ auto irResultType = lowerSimpleType(context, decl->ReturnType);
+ auto irFuncType = getBuilder()->getFuncType(
+ paramTypes.Count(),
+ &paramTypes[0],
+ irResultType);
+ irFunc->type.init(irFunc, irFuncType);
lowerStmt(subContext, decl->Body);
+ getBuilder()->addHighLevelDeclDecoration(irFunc, decl);
+
getBuilder()->addInst(irFunc);
return LoweredValInfo::simple(irFunc);