From b2fb0f7134de4e0b1a0db685eb1ae3c0678a33c5 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 10 Jul 2017 10:44:02 -0700 Subject: Try to be more robust against un-checked types during lowering, etc. - Try to handle `ErrorType` gracefully when computing type layouts - When outputting a `TypeExp`, if the type part is errorneous (or missing), try to use the expression part - Make sure to lower the expressions side of a `TypeExp` during lowering --- source/slang/emit.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 7 deletions(-) (limited to 'source/slang/emit.cpp') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 155e1e39a..1630f1c79 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -1084,18 +1084,56 @@ struct EmitVisitor emitTypeImpl(type, nullptr); } + void emitTypeBasedOnExpr(ExpressionSyntaxNode* expr, EDeclarator* declarator) + { + if (auto subscriptExpr = dynamic_cast(expr)) + { + // Looks like an array + emitTypeBasedOnExpr(subscriptExpr->BaseExpression, declarator); + Emit("["); + if (auto indexExpr = subscriptExpr->IndexExpression) + { + EmitExpr(indexExpr); + } + Emit("]"); + } + else + { + // Default case + EmitExpr(expr); + EmitDeclarator(declarator); + } + } + + void EmitType(TypeExp const& typeExp, String const& name, CodePosition const& nameLoc) + { + if (!typeExp.type || typeExp.type->As()) + { + assert(typeExp.exp); + + EDeclarator nameDeclarator; + nameDeclarator.flavor = EDeclarator::Flavor::Name; + nameDeclarator.name = name; + nameDeclarator.loc = nameLoc; + + emitTypeBasedOnExpr(typeExp.exp, &nameDeclarator); + } + else + { + EmitType(typeExp.type, + typeExp.exp ? typeExp.exp->Position : CodePosition(), + name, nameLoc); + } + } + void EmitType(TypeExp const& typeExp, Token const& nameToken) { - EmitType(typeExp.type, - typeExp.exp ? typeExp.exp->Position : CodePosition(), - nameToken.Content, nameToken.Position); + EmitType(typeExp, nameToken.Content, nameToken.Position); } void EmitType(TypeExp const& typeExp, String const& name) { - EmitType(typeExp.type, - typeExp.exp ? typeExp.exp->Position : CodePosition(), - name, CodePosition()); + EmitType(typeExp, name, CodePosition()); } void emitTypeExp(TypeExp const& typeExp) @@ -2758,7 +2796,15 @@ struct EmitVisitor { EmitModifiers(declRef.getDecl()); - EmitType(GetType(declRef), declRef.getDecl()->getNameToken()); + auto type = GetType(declRef); + if (!type || type->As()) + { + EmitType(declRef.getDecl()->Type, declRef.getDecl()->getNameToken()); + } + else + { + EmitType(GetType(declRef), declRef.getDecl()->getNameToken()); + } EmitSemantics(declRef.getDecl()); -- cgit v1.2.3 From d6d49eac224a0d03c8f941deb59ee1520ff0ab5e Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 10 Jul 2017 10:52:30 -0700 Subject: Add support for `imageBuffer` This was mostly just a missing `typedef` in the Slang standard library code. This should also cover `textureBuffer` and `samplerBuffer`. --- source/slang/emit.cpp | 1 + source/slang/slang-stdlib.cpp | 1 + source/slang/type-defs.h | 1 + 3 files changed, 3 insertions(+) (limited to 'source/slang/emit.cpp') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 1630f1c79..2791a436e 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -776,6 +776,7 @@ struct EmitVisitor case TextureType::Shape2D: Emit("2D"); break; case TextureType::Shape3D: Emit("3D"); break; case TextureType::ShapeCube: Emit("Cube"); break; + case TextureType::ShapeBuffer: Emit("Buffer"); break; default: assert(!"unreachable"); break; diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index 23d66201a..9d6f812cd 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -1914,6 +1914,7 @@ namespace Slang { "2D", TextureType::Shape2D, 2 }, { "3D", TextureType::Shape3D, 3 }, { "Cube", TextureType::ShapeCube, 3 }, + { "Buffer", TextureType::ShapeBuffer, 1 }, }; static const int kBaseTextureTypeCount = sizeof(kBaseTextureTypes) / sizeof(kBaseTextureTypes[0]); diff --git a/source/slang/type-defs.h b/source/slang/type-defs.h index a01b49277..ae64cce2e 100644 --- a/source/slang/type-defs.h +++ b/source/slang/type-defs.h @@ -125,6 +125,7 @@ RAW( Shape2D = SLANG_TEXTURE_2D, Shape3D = SLANG_TEXTURE_3D, ShapeCube = SLANG_TEXTURE_CUBE, + ShapeBuffer = SLANG_TEXTURE_BUFFER, Shape1DArray = Shape1D | ArrayFlag, Shape2DArray = Shape2D | ArrayFlag, -- cgit v1.2.3