From 74f2f47cb63b02638270beecd20acea1a0f5665e Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 27 Sep 2017 11:17:39 -0700 Subject: 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. --- source/slang/lower.cpp | 245 ++++++++++++++++++++++++++----------------------- 1 file changed, 129 insertions(+), 116 deletions(-) (limited to 'source/slang/lower.cpp') 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 value; + Flavor flavor; +}; + +struct LoweredDeclRef +{ +public: + LoweredDecl decl; + RefPtr substitutions; + + LoweredDecl getDecl() { return decl; } + + template + DeclRef As() + { + return DeclRef(decl.getDecl(), substitutions).As(); + } +}; + +// + template struct StructuralTransformVisitorBase { @@ -54,7 +151,8 @@ struct StructuralTransformVisitorBase template DeclRef transformDeclField(DeclRef const& decl) { - return visitor->translateDeclRef(decl).As(); + LoweredDeclRef declRef = visitor->translateDeclRef(decl); + return declRef.As(); } TypeExp transformSyntaxField(TypeExp const& typeExp) @@ -89,7 +187,8 @@ struct StructuralTransformVisitorBase RefPtr transformSyntaxField(ScopeDecl* decl) { if(!decl) return nullptr; - return visitor->transformSyntaxField(decl).As(); + RefPtr transformed = visitor->transformSyntaxField(decl); + return transformed.As(); } template @@ -104,6 +203,7 @@ struct StructuralTransformVisitorBase } }; +#if 0 template RefPtr structuralTransform( Stmt* stmt, @@ -113,6 +213,7 @@ RefPtr structuralTransform( transformer.visitor = visitor; return transformer.dispatch(stmt); } +#endif template 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 visit##NAME(NAME* obj) { \ + RefPtr visit##NAME(NAME* obj) { \ RefPtr 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 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 value; - Flavor flavor; -}; - -struct LoweredDeclRef -{ -public: - LoweredDecl decl; - RefPtr substitutions; - - LoweredDecl getDecl() { return decl; } - - template - DeclRef As() - { - return DeclRef(decl.getDecl(), substitutions).As(); - } -}; // 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 visitArrayExpressionType(ArrayExpressionType* type) { RefPtr loweredType = Slang::getArrayType( - lowerType(type->BaseType), + lowerType(type->baseType), lowerVal(type->ArrayLength).As()); return loweredType; } @@ -1074,7 +1087,7 @@ struct LoweringVisitor if (auto rightVecType = rightType->As()) { // RHS type was a vector - if (auto leftElemVecType = leftArrayType->BaseType->As()) + if (auto leftElemVecType = leftArrayType->baseType->As()) { // 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()) { // RHS type was a vector - if (auto leftElemVecType = leftArrayType->BaseType->As()) + if (auto leftElemVecType = leftArrayType->baseType->As()) { // 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 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()) { - return arrayType->BaseType; + return arrayType->baseType; } return nullptr; } @@ -1702,7 +1715,7 @@ struct LoweringVisitor while (auto arrayType = varType->As()) { - varType = arrayType->BaseType; + varType = arrayType->baseType; } if (auto constantBufferType = varType->As()) @@ -2834,7 +2847,7 @@ struct LoweringVisitor auto type = inType; while (auto arrayType = type->As()) { - type = arrayType->BaseType; + type = arrayType->baseType; } return type; } @@ -2848,7 +2861,7 @@ struct LoweringVisitor { while (auto arrayType = type->As()) { - type = arrayType->BaseType; + type = arrayType->baseType; } if (auto textureTypeBase = type->As()) @@ -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()) { - 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()) -- cgit v1.2.3