summaryrefslogtreecommitdiffstats
path: root/source/slang/lower.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2017-09-27 11:17:39 -0700
committerGitHub <noreply@github.com>2017-09-27 11:17:39 -0700
commit74f2f47cb63b02638270beecd20acea1a0f5665e (patch)
treeaf50d0355c7fccb4fb93fc1a0d45c66b5d07f1c9 /source/slang/lower.cpp
parentb6cf0f4ae0f3f9d1f377d3f134dcf994676e68b4 (diff)
First attempt at a Linux build (#193)
* First attempt at a Linux build - Fix up places where C++ idioms were written assuming lenient behavior of Microsoft's compiler - Add a few more alternatives for platform-specific behavior where Windows was the only platform accounted for. - Add a basic Makefile that can at least invoke our build, even if it isn't going good dependency tracking, etc. - Build `libslang.so` and `slangc` that depends on it, using a relative `RPATH` to make the binary portable (I hope) - Add an initial `.travis.yml` to see if we can trigger their build process. * Fixup: const bug in `List::Sort` I'm not clear why this gets picked up by the gcc *and* clang that Travis uses, but not the (newer) gcc I'm using on Ubuntu here, but I'm hoping it is just some missing `const` qualifiers. * Fixup: reorder specialization of "class info" Clang complains about things being specialized after being instantiated (implicilty), and I hope it is just the fact that I generate the class info for the roots of the hierarchy after the other cases. We'll see. * Fixup: add `platform.cpp` to unified/lumped build * Fixup: Windows uses `FreeLibrary` and not `UnloadLibrary` * Fixup: fix Windows project file to include new source file This obviously points to the fact that we are going to need to be generating these files sooner or later.
Diffstat (limited to 'source/slang/lower.cpp')
-rw-r--r--source/slang/lower.cpp245
1 files changed, 129 insertions, 116 deletions
diff --git a/source/slang/lower.cpp b/source/slang/lower.cpp
index 391221f47..85f19f14c 100644
--- a/source/slang/lower.cpp
+++ b/source/slang/lower.cpp
@@ -36,6 +36,103 @@ struct CloneVisitor
//
+//
+
+class TupleExpr;
+class TupleVarDecl;
+class VaryingTupleExpr;
+class VaryingTupleVarDecl;
+
+
+// The result of lowering a declaration will usually be a declaration,
+// but it might also be a "tuple" declaration, in cases where we needed
+// to sclarize (or partially scalarize) things to guarantee validity.
+struct LoweredDecl
+{
+ enum class Flavor
+ {
+ Decl, // A single declaration (the default case)
+ Tuple, // A `TupleVarDecl` representing multiple decls
+ VaryingTuple, // A `VaryingTupleVarDecl` representing multiple decls
+ };
+
+ LoweredDecl()
+ : flavor(Flavor::Decl)
+ {}
+
+ LoweredDecl(Decl* decl)
+ : value(decl)
+ , flavor(Flavor::Decl)
+ {}
+
+ LoweredDecl(TupleVarDecl* decl)
+ : value((RefObject*) decl)
+ , flavor(Flavor::Tuple)
+ {}
+
+ LoweredDecl(VaryingTupleVarDecl* decl)
+ : value((RefObject*) decl)
+ , flavor(Flavor::VaryingTuple)
+ {}
+
+ Flavor getFlavor() const { return flavor; }
+ RefObject* getValue() const { return value; }
+
+ Decl* getDecl() const
+ {
+ SLANG_ASSERT(getFlavor() == Flavor::Decl);
+ return (Decl*) value.Ptr();
+ }
+
+ TupleVarDecl* getTupleDecl() const
+ {
+ SLANG_ASSERT(getFlavor() == Flavor::Tuple);
+ return (TupleVarDecl*) value.Ptr();
+ }
+
+ VaryingTupleVarDecl* getVaryingTupleDecl() const
+ {
+ SLANG_ASSERT(getFlavor() == Flavor::VaryingTuple);
+ return (VaryingTupleVarDecl*) value.Ptr();
+ }
+
+ Decl* asDecl() const
+ {
+ return (getFlavor() == Flavor::Decl) ? getDecl() : nullptr;
+ }
+
+ TupleVarDecl* asTupleDecl() const
+ {
+ return (getFlavor() == Flavor::Tuple) ? getTupleDecl() : nullptr;
+ }
+
+ VaryingTupleVarDecl* asVaryingTupleDecl() const
+ {
+ return (getFlavor() == Flavor::VaryingTuple) ? getVaryingTupleDecl() : nullptr;
+ }
+
+private:
+ RefPtr<RefObject> value;
+ Flavor flavor;
+};
+
+struct LoweredDeclRef
+{
+public:
+ LoweredDecl decl;
+ RefPtr<Substitutions> substitutions;
+
+ LoweredDecl getDecl() { return decl; }
+
+ template<typename T>
+ DeclRef<T> As()
+ {
+ return DeclRef<Decl>(decl.getDecl(), substitutions).As<T>();
+ }
+};
+
+//
+
template<typename V>
struct StructuralTransformVisitorBase
{
@@ -54,7 +151,8 @@ struct StructuralTransformVisitorBase
template<typename T>
DeclRef<T> transformDeclField(DeclRef<T> const& decl)
{
- return visitor->translateDeclRef(decl).As<T>();
+ LoweredDeclRef declRef = visitor->translateDeclRef(decl);
+ return declRef.As<T>();
}
TypeExp transformSyntaxField(TypeExp const& typeExp)
@@ -89,7 +187,8 @@ struct StructuralTransformVisitorBase
RefPtr<ScopeDecl> transformSyntaxField(ScopeDecl* decl)
{
if(!decl) return nullptr;
- return visitor->transformSyntaxField(decl).As<ScopeDecl>();
+ RefPtr<Decl> transformed = visitor->transformSyntaxField(decl);
+ return transformed.As<ScopeDecl>();
}
template<typename T>
@@ -104,6 +203,7 @@ struct StructuralTransformVisitorBase
}
};
+#if 0
template<typename V>
RefPtr<Stmt> structuralTransform(
Stmt* stmt,
@@ -113,6 +213,7 @@ RefPtr<Stmt> structuralTransform(
transformer.visitor = visitor;
return transformer.dispatch(stmt);
}
+#endif
template<typename V>
struct StructuralTransformExprVisitor
@@ -121,21 +222,26 @@ struct StructuralTransformExprVisitor
{
void transformFields(Expr* result, Expr* obj)
{
- result->type = transformSyntaxField(obj->type);
+ result->type = this->transformSyntaxField(obj->type);
}
+#define ABSTRACT_SYNTAX_CLASS(NAME, BASE, ...) \
+ void transformFields(NAME* result, NAME* obj) { \
+ this->transformFields((BASE*) result, (BASE*) obj); \
+ /* end */
+
#define SYNTAX_CLASS(NAME, BASE, ...) \
- RefPtr<Expr> visit##NAME(NAME* obj) { \
+ RefPtr<Expr> visit##NAME(NAME* obj) { \
RefPtr<NAME> result = new NAME(*obj); \
transformFields(result, obj); \
return result; \
} \
- void transformFields(NAME* result, NAME* obj) { \
- transformFields((BASE*) result, (BASE*) obj); \
+ ABSTRACT_SYNTAX_CLASS(NAME, BASE) \
+ /* end */
-#define SYNTAX_FIELD(TYPE, NAME) result->NAME = transformSyntaxField(obj->NAME);
-#define DECL_FIELD(TYPE, NAME) result->NAME = transformDeclField(obj->NAME);
+#define SYNTAX_FIELD(TYPE, NAME) result->NAME = this->transformSyntaxField(obj->NAME);
+#define DECL_FIELD(TYPE, NAME) result->NAME = this->transformDeclField(obj->NAME);
#define FIELD(TYPE, NAME) /* empty */
@@ -158,100 +264,6 @@ RefPtr<Expr> structuralTransform(
return transformer.dispatch(expr);
}
-//
-
-class TupleExpr;
-class TupleVarDecl;
-class VaryingTupleExpr;
-class VaryingTupleVarDecl;
-
-
-// The result of lowering a declaration will usually be a declaration,
-// but it might also be a "tuple" declaration, in cases where we needed
-// to sclarize (or partially scalarize) things to guarantee validity.
-struct LoweredDecl
-{
- enum class Flavor
- {
- Decl, // A single declaration (the default case)
- Tuple, // A `TupleVarDecl` representing multiple decls
- VaryingTuple, // A `VaryingTupleVarDecl` representing multiple decls
- };
-
- LoweredDecl()
- : flavor(Flavor::Decl)
- {}
-
- LoweredDecl(Decl* decl)
- : value(decl)
- , flavor(Flavor::Decl)
- {}
-
- LoweredDecl(TupleVarDecl* decl)
- : value((RefObject*) decl)
- , flavor(Flavor::Tuple)
- {}
-
- LoweredDecl(VaryingTupleVarDecl* decl)
- : value((RefObject*) decl)
- , flavor(Flavor::VaryingTuple)
- {}
-
- Flavor getFlavor() const { return flavor; }
- RefObject* getValue() const { return value; }
-
- Decl* getDecl() const
- {
- SLANG_ASSERT(getFlavor() == Flavor::Decl);
- return (Decl*) value.Ptr();
- }
-
- TupleVarDecl* getTupleDecl() const
- {
- SLANG_ASSERT(getFlavor() == Flavor::Tuple);
- return (TupleVarDecl*) value.Ptr();
- }
-
- VaryingTupleVarDecl* getVaryingTupleDecl() const
- {
- SLANG_ASSERT(getFlavor() == Flavor::VaryingTuple);
- return (VaryingTupleVarDecl*) value.Ptr();
- }
-
- Decl* asDecl() const
- {
- return (getFlavor() == Flavor::Decl) ? getDecl() : nullptr;
- }
-
- TupleVarDecl* asTupleDecl() const
- {
- return (getFlavor() == Flavor::Tuple) ? getTupleDecl() : nullptr;
- }
-
- VaryingTupleVarDecl* asVaryingTupleDecl() const
- {
- return (getFlavor() == Flavor::VaryingTuple) ? getVaryingTupleDecl() : nullptr;
- }
-
-private:
- RefPtr<RefObject> value;
- Flavor flavor;
-};
-
-struct LoweredDeclRef
-{
-public:
- LoweredDecl decl;
- RefPtr<Substitutions> substitutions;
-
- LoweredDecl getDecl() { return decl; }
-
- template<typename T>
- DeclRef<T> As()
- {
- return DeclRef<Decl>(decl.getDecl(), substitutions).As<T>();
- }
-};
// The result of lowering an exrpession will usually be just a single
@@ -321,9 +333,10 @@ struct LoweredExpr
return (getFlavor() == Flavor::VaryingTuple) ? getVaryingTupleExpr() : nullptr;
}
- bool operator!()
+ // Allow use in boolean contexts
+ operator void*()
{
- return !value;
+ return value.Ptr();
}
private:
@@ -754,7 +767,7 @@ struct LoweringVisitor
RefPtr<Type> visitArrayExpressionType(ArrayExpressionType* type)
{
RefPtr<ArrayExpressionType> loweredType = Slang::getArrayType(
- lowerType(type->BaseType),
+ lowerType(type->baseType),
lowerVal(type->ArrayLength).As<IntVal>());
return loweredType;
}
@@ -1074,7 +1087,7 @@ struct LoweringVisitor
if (auto rightVecType = rightType->As<VectorExpressionType>())
{
// RHS type was a vector
- if (auto leftElemVecType = leftArrayType->BaseType->As<VectorExpressionType>())
+ if (auto leftElemVecType = leftArrayType->baseType->As<VectorExpressionType>())
{
// LHS element type was also a vector, so this is a "scalar splat
// to array" case.
@@ -1102,7 +1115,7 @@ struct LoweringVisitor
swizzleExpr->elementIndices[0] = ee;
auto convertedArgExpr = convertExprForAssignmentWithFixups(
- leftArrayType->BaseType,
+ leftArrayType->baseType,
swizzleExpr);
ctorExpr->Arguments.Add(convertedArgExpr);
@@ -1222,7 +1235,7 @@ struct LoweringVisitor
if (auto rightVecType = rightType->As<VectorExpressionType>())
{
// RHS type was a vector
- if (auto leftElemVecType = leftArrayType->BaseType->As<VectorExpressionType>())
+ if (auto leftElemVecType = leftArrayType->baseType->As<VectorExpressionType>())
{
// LHS element type was also a vector, so this is a "scalar splat
// to array" case.
@@ -1243,7 +1256,7 @@ struct LoweringVisitor
// LHS array element
RefPtr<IndexExpr> arrayElemExpr = new IndexExpr();
arrayElemExpr->loc = leftExpr->loc;
- arrayElemExpr->type.type = leftArrayType->BaseType;
+ arrayElemExpr->type.type = leftArrayType->baseType;
arrayElemExpr->BaseExpression = leftExpr;
arrayElemExpr->IndexExpression = createConstIntExpr(ee);
@@ -1495,7 +1508,7 @@ struct LoweringVisitor
{
if (auto arrayType = type->As<ArrayExpressionType>())
{
- return arrayType->BaseType;
+ return arrayType->baseType;
}
return nullptr;
}
@@ -1702,7 +1715,7 @@ struct LoweringVisitor
while (auto arrayType = varType->As<ArrayExpressionType>())
{
- varType = arrayType->BaseType;
+ varType = arrayType->baseType;
}
if (auto constantBufferType = varType->As<ConstantBufferType>())
@@ -2834,7 +2847,7 @@ struct LoweringVisitor
auto type = inType;
while (auto arrayType = type->As<ArrayExpressionType>())
{
- type = arrayType->BaseType;
+ type = arrayType->baseType;
}
return type;
}
@@ -2848,7 +2861,7 @@ struct LoweringVisitor
{
while (auto arrayType = type->As<ArrayExpressionType>())
{
- type = arrayType->BaseType;
+ type = arrayType->baseType;
}
if (auto textureTypeBase = type->As<TextureTypeBase>())
@@ -3065,7 +3078,7 @@ struct LoweringVisitor
arraySpec.elementCount = arrayType->ArrayLength;
TupleSecondaryVarInfo subInfo = info;
- subInfo.tupleType = arrayType->BaseType;
+ subInfo.tupleType = arrayType->baseType;
subInfo.arraySpecs = &arraySpec;
createTupleTypeSecondaryVarDecls(subInfo);
return;
@@ -3685,7 +3698,7 @@ struct LoweringVisitor
{
if (auto baseType = type->As<BasicExpressionType>())
{
- switch (baseType->BaseType)
+ switch (baseType->baseType)
{
default:
return false;
@@ -4108,7 +4121,7 @@ struct LoweringVisitor
// heterogeneous stuff...
return lowerShaderParameterToGLSLGLobalsRec(
arrayInfo,
- arrayType->BaseType,
+ arrayType->baseType,
varLayout);
}
else if (auto declRefType = varType->As<DeclRefType>())