diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2018-12-12 08:57:48 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-12 08:57:48 -0500 |
| commit | 49ed6b60d662906f290578f802f80b0ead1a2b9d (patch) | |
| tree | e47050f6508a4b3a4d38b756e9b3c53e0d159507 /source/slang | |
| parent | 62d3e387774255be4d507cca045ac97dabac9970 (diff) | |
Running tests in slang-test process (#740)
* First pass at having an interface to write text to that can be replaced.
Simplifed and made more rigerous the interface used to write formatted strings.
* Added AppContext to simplify setting up and parsing around of streams.
* Added more simplified way to get the std error/out from AppContext.
* Work in progress using dll for tools to speed up testing.
* First pass at ISlangWriter interface.
* Added support for writing VaArgs.
Added NullWriter.
* Use ISlangWriter for output.
* Use ISlangWriter for output - replacing OutputCallback.
Make IRDump go to ISlangWriter
* SlangWriterTargetType -> SlangWriterChannel
Improvements around AppContext
* Shared library working with slang-reflection-test.
* Dll testing working for render-test.
* Include va_list definintion from header.
* Fix errors from clang.
* Fix typo for linux.
* Added -usexes option
* Fix typo.
* Fix arguments problem on linux.
* Fix typo for linux.
* Add windows tool shared library projects.
* Fix warning from x86 win build.
Fix signed warning from slang-test/main.cpp
* First attempt at getting premake to work on travis, and run tests.
* Try moving build out into script.
* Invoke bash scripts so they don't have to be executable.
* Drive configuration/tests from env parameters set by travis
* Try using source to run travis tests.
* Remove the build.linux directory - but doing so will overwrite Makefile.
* Made -fno-delete-null-pointer-checks gcc only.
* Try to fix warning from -fno-delete-null-pointer-checks
* Turn of warnings for unknown switches.
* Try to make premake choose the correct tooling.
* Disabled missing braces warning.
* Disable -Wundefined-var-template on clang.
* -Wunused-function disabled for clang.
* Fix typo due to SlangBool.
* Remove this nullptr tests.
* "-Wno-unused-private-field" for clang.
* Added "-Wno-undefined-bool-conversion"
* Add DominatorList::end fix.
* Split scripts into travis_build.sh travis_test.sh
* Fix gcc/clang template pre-declaration issue around QualType.
* Fix premake to build such that pthread correctly links with slang-glslang
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/check.cpp | 31 | ||||
| -rw-r--r-- | source/slang/compiler.cpp | 46 | ||||
| -rw-r--r-- | source/slang/compiler.h | 20 | ||||
| -rw-r--r-- | source/slang/diagnostics.cpp | 8 | ||||
| -rw-r--r-- | source/slang/diagnostics.h | 3 | ||||
| -rw-r--r-- | source/slang/emit.cpp | 4 | ||||
| -rw-r--r-- | source/slang/ir.cpp | 20 | ||||
| -rw-r--r-- | source/slang/ir.h | 4 | ||||
| -rw-r--r-- | source/slang/lookup.cpp | 16 | ||||
| -rw-r--r-- | source/slang/lower-to-ir.cpp | 4 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 65 | ||||
| -rw-r--r-- | source/slang/syntax-base-defs.h | 1 | ||||
| -rw-r--r-- | source/slang/syntax.cpp | 13 | ||||
| -rw-r--r-- | source/slang/syntax.h | 12 | ||||
| -rw-r--r-- | source/slang/type-layout.cpp | 5 |
15 files changed, 191 insertions, 61 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp index 21e3b894b..4f914ee1f 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -1006,6 +1006,15 @@ namespace Slang } } + if (!type) + { + if (outProperType) + { + *outProperType = nullptr; + } + return false; + } + if (auto genericDeclRefType = type->As<GenericDeclRefType>()) { // We are using a reference to a generic declaration as a concrete @@ -1034,7 +1043,7 @@ namespace Slang } // TODO: this is one place where syntax should get cloned! - if(outProperType) + if (outProperType) args.Add(typeParam->initType.exp); } else if (auto valParam = member.As<GenericValueParamDecl>()) @@ -1050,7 +1059,7 @@ namespace Slang } // TODO: this is one place where syntax should get cloned! - if(outProperType) + if (outProperType) args.Add(valParam->initExpr); } else @@ -1065,15 +1074,13 @@ namespace Slang } return true; } - else + + // default case: we expect this to already be a proper type + if (outProperType) { - // default case: we expect this to already be a proper type - if (outProperType) - { - *outProperType = type; - } - return true; + *outProperType = type; } + return true; } @@ -1147,7 +1154,7 @@ namespace Slang { // TODO: we may want other cases here... - if (auto errorType = expr->type->As<ErrorType>()) + if (auto errorType = expr->type.As<ErrorType>()) return true; return false; @@ -7229,7 +7236,7 @@ namespace Slang // for anything applicable. AddDeclRefOverloadCandidates(LookupResultItem(declRefExpr->declRef), context); } - else if (auto funcType = funcExprType->As<FuncType>()) + else if (auto funcType = funcExprType.As<FuncType>()) { // TODO(tfoley): deprecate this path... AddFuncOverloadCandidate(funcType, context); @@ -7250,7 +7257,7 @@ namespace Slang AddOverloadCandidates(item, context); } } - else if (auto typeType = funcExprType->As<TypeType>()) + else if (auto typeType = funcExprType.As<TypeType>()) { // If none of the above cases matched, but we are // looking at a type, then I suppose we have diff --git a/source/slang/compiler.cpp b/source/slang/compiler.cpp index 0f333aa3d..172bc33b9 100644 --- a/source/slang/compiler.cpp +++ b/source/slang/compiler.cpp @@ -864,6 +864,23 @@ SlangResult dissassembleDXILUsingDXC( static void writeOutputFile( CompileRequest* compileRequest, + ISlangWriter* writer, + String const& path, + void const* data, + size_t size) + { + + if (SLANG_FAILED(writer->write((const char*)data, size))) + { + compileRequest->mSink.diagnose( + SourceLoc(), + Diagnostics::cannotWriteOutputFile, + path); + } + } + + static void writeOutputFile( + CompileRequest* compileRequest, String const& path, void const* data, size_t size, @@ -924,14 +941,10 @@ SlangResult dissassembleDXILUsingDXC( } static void writeOutputToConsole( - CompileRequest*, + ISlangWriter* writer, String const& text) { - fwrite( - text.begin(), - text.end() - text.begin(), - 1, - stdout); + writer->write(text.Buffer(), text.Length()); } static void writeEntryPointResultToStandardOutput( @@ -941,17 +954,19 @@ SlangResult dissassembleDXILUsingDXC( { auto compileRequest = entryPoint->compileRequest; + ISlangWriter* writer = compileRequest->getWriter(WriterChannel::StdOutput); + switch (result.format) { case ResultFormat::Text: - writeOutputToConsole(compileRequest, result.outputString); + writeOutputToConsole(writer, result.outputString); break; case ResultFormat::Binary: { auto& data = result.outputBinary; - int stdoutFileDesc = _fileno(stdout); - if (_isatty(stdoutFileDesc)) + + if (writer->isConsole()) { // Writing to console, so we need to generate text output. @@ -964,7 +979,7 @@ SlangResult dissassembleDXILUsingDXC( dissassembleDXBC(compileRequest, data.begin(), data.end() - data.begin(), assembly); - writeOutputToConsole(compileRequest, assembly); + writeOutputToConsole(writer, assembly); } break; #endif @@ -977,7 +992,7 @@ SlangResult dissassembleDXILUsingDXC( data.begin(), data.end() - data.begin(), assembly); - writeOutputToConsole(compileRequest, assembly); + writeOutputToConsole(writer, assembly); } break; #endif @@ -988,7 +1003,7 @@ SlangResult dissassembleDXILUsingDXC( dissassembleSPIRV(compileRequest, data.begin(), data.end() - data.begin(), assembly); - writeOutputToConsole(compileRequest, assembly); + writeOutputToConsole(writer, assembly); } break; @@ -1000,12 +1015,11 @@ SlangResult dissassembleDXILUsingDXC( else { // Redirecting stdout to a file, so do the usual thing - #ifdef _WIN32 - _setmode(stdoutFileDesc, _O_BINARY); - #endif + writer->setMode(SLANG_WRITER_MODE_BINARY); + writeOutputFile( compileRequest, - stdout, + writer, "stdout", data.begin(), data.end() - data.begin()); diff --git a/source/slang/compiler.h b/source/slang/compiler.h index fbd6b3f15..2a9b60d9b 100644 --- a/source/slang/compiler.h +++ b/source/slang/compiler.h @@ -212,6 +212,20 @@ namespace Slang Precise = SLANG_FLOATING_POINT_MODE_PRECISE, }; + enum class WriterChannel : SlangWriterChannel + { + Diagnostic = SLANG_WRITER_CHANNEL_DIAGNOSTIC, + StdOutput = SLANG_WRITER_CHANNEL_STD_OUTPUT, + StdError = SLANG_WRITER_CHANNEL_STD_ERROR, + CountOf = SLANG_WRITER_CHANNEL_COUNT_OF, + }; + + enum class WriterMode : SlangWriterMode + { + Text = SLANG_WRITER_MODE_TEXT, + Binary = SLANG_WRITER_MODE_BINARY, + }; + // A request to generate output in some target format class TargetRequest : public RefObject { @@ -401,6 +415,12 @@ namespace Slang /// or a wrapped impl that makes fileSystem operate as fileSystemExt ComPtr<ISlangFileSystemExt> fileSystemExt; + // For output + ComPtr<ISlangWriter> m_writers[SLANG_WRITER_CHANNEL_COUNT_OF]; + + void setWriter(WriterChannel chan, ISlangWriter* writer); + ISlangWriter* getWriter(WriterChannel chan) const { return m_writers[int(chan)]; } + /// Load a file into memory using the configured file system. /// /// @param path The path to attempt to load from diff --git a/source/slang/diagnostics.cpp b/source/slang/diagnostics.cpp index f1d0b63f9..4000fd967 100644 --- a/source/slang/diagnostics.cpp +++ b/source/slang/diagnostics.cpp @@ -237,13 +237,13 @@ void DiagnosticSink::diagnoseImpl(SourceLoc const& pos, DiagnosticInfo const& in } // Did the client supply a callback for us to use? - if( callback ) + if( writer ) { // If so, pass the error string along to them StringBuilder messageBuilder; formatDiagnostic(this, messageBuilder, diagnostic); - callback(messageBuilder.ProduceString().begin(), callbackUserData); + writer->write(messageBuilder.Buffer(), messageBuilder.Length()); } else { @@ -269,10 +269,10 @@ void DiagnosticSink::diagnoseRaw( } // Did the client supply a callback for us to use? - if( callback ) + if(writer) { // If so, pass the error string along to them - callback(message, callbackUserData); + writer->write(message, ::strlen(message)); } else { diff --git a/source/slang/diagnostics.h b/source/slang/diagnostics.h index 945dc6c73..420b936a3 100644 --- a/source/slang/diagnostics.h +++ b/source/slang/diagnostics.h @@ -143,8 +143,7 @@ namespace Slang // List<Diagnostic> diagnostics; int errorCount = 0; - SlangDiagnosticCallback callback = nullptr; - void* callbackUserData = nullptr; + ISlangWriter* writer = nullptr; /* void Error(int id, const String & msg, const SourceLoc & pos) diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index d7abbff24..f83ea894a 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -6434,7 +6434,9 @@ String emitEntryPoint( // un-specialized IR. if (translationUnit->compileRequest->shouldDumpIR) { - dumpIR(irModule); + ISlangWriter* writer = translationUnit->compileRequest->getWriter(WriterChannel::StdError); + + dumpIR(irModule, writer); } // Next, we need to ensure that the code we emit for diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index bc33527cf..784c5034d 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -3239,7 +3239,7 @@ namespace Slang dumpIRModule(&context, module); } - void dumpIR(IRGlobalValue* globalVal) + void dumpIR(IRGlobalValue* globalVal, ISlangWriter* writer) { StringBuilder sb; @@ -3249,8 +3249,11 @@ namespace Slang dumpInst(&context, globalVal); - fprintf(stderr, "%s\n", sb.Buffer()); - fflush(stderr); + writer->write(sb.Buffer(), sb.Length()); + char cr[] = "\n"; + writer->write(cr, 1); + + writer->flush(); } String getSlangIRAssembly(IRModule* module) @@ -3260,13 +3263,16 @@ namespace Slang return sb; } - void dumpIR(IRModule* module) + void dumpIR(IRModule* module, ISlangWriter* writer) { String ir = getSlangIRAssembly(module); - fprintf(stderr, "%s\n", ir.Buffer()); - fflush(stderr); - } + writer->write(ir.Buffer(), ir.Length()); + char cr[] = "\n"; + writer->write(cr, 1); + + writer->flush(); + } // // diff --git a/source/slang/ir.h b/source/slang/ir.h index 8183e038a..6fb0ff728 100644 --- a/source/slang/ir.h +++ b/source/slang/ir.h @@ -1105,8 +1105,8 @@ struct IRModule : RefObject void printSlangIRAssembly(StringBuilder& builder, IRModule* module); String getSlangIRAssembly(IRModule* module); -void dumpIR(IRModule* module); -void dumpIR(IRGlobalValue* globalVal); +void dumpIR(IRModule* module, ISlangWriter* writer); +void dumpIR(IRGlobalValue* globalVal, ISlangWriter* writer); String dumpIRFunc(IRFunc* func); diff --git a/source/slang/lookup.cpp b/source/slang/lookup.cpp index e4ae3c8bb..f74e11016 100644 --- a/source/slang/lookup.cpp +++ b/source/slang/lookup.cpp @@ -177,6 +177,11 @@ void DoMemberLookupImpl( LookupResult& ioResult, BreadcrumbInfo* breadcrumbs) { + if (!baseType) + { + return; + } + // If the type was pointer-like, then dereference it // automatically here. if (auto pointerLikeType = baseType->As<PointerLikeType>()) @@ -482,11 +487,14 @@ void DoLookupImpl( // in the target decl we are extending if (auto extDeclRef = containerDeclRef.As<ExtensionDecl>()) { - if (auto targetDeclRef = extDeclRef.getDecl()->targetType->AsDeclRefType()) + if (extDeclRef.getDecl()->targetType) { - if (auto aggDeclRef = targetDeclRef->declRef.As<AggTypeDecl>()) + if (auto targetDeclRef = extDeclRef.getDecl()->targetType->AsDeclRefType()) { - containerDeclRef = extDeclRef.Substitute(aggDeclRef); + if (auto aggDeclRef = targetDeclRef->declRef.As<AggTypeDecl>()) + { + containerDeclRef = extDeclRef.Substitute(aggDeclRef); + } } } } @@ -703,4 +711,4 @@ LookupResult lookUpMember( return result; } -}
\ No newline at end of file +} diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index 8af6292e6..2804854b7 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -5608,7 +5608,9 @@ IRModule* generateIRForTranslationUnit( // then we can dump the initial IR for the module here. if(compileRequest->shouldDumpIR) { - dumpIR(module); + ISlangWriter* writer = translationUnit->compileRequest->getWriter(WriterChannel::StdError); + + dumpIR(module, writer); } return module; diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 8fe08884e..b0adb2025 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -13,6 +13,7 @@ #include "../slang/type-layout.h" #include "slang-file-system.h" +#include "../core/slang-writer.h" #include "ir-serialize.h" @@ -305,6 +306,12 @@ CompileRequest::CompileRequest(Session* session) sourceManager->initialize(session->getBuiltinSourceManager()); + // Set all the default writers + for (int i = 0; i < int(WriterChannel::CountOf); ++i) + { + setWriter(WriterChannel(i), nullptr); + } + // Set up the default file system SLANG_ASSERT(fileSystem == nullptr); fileSystemExt = new CacheFileSystem(DefaultFileSystem::getSingleton()); @@ -368,9 +375,38 @@ MatrixLayoutMode TargetRequest::getDefaultMatrixLayoutMode() } - // +static ISlangWriter* _getDefaultWriter(WriterChannel chan) +{ + static FileWriter stdOut(stdout, WriterFlag::IsStatic | WriterFlag::IsUnowned); + static FileWriter stdError(stderr, WriterFlag::IsStatic | WriterFlag::IsUnowned); + static NullWriter nullWriter(WriterFlag::IsStatic | WriterFlag::IsConsole); + + switch (chan) + { + case WriterChannel::StdError: return &stdError; + case WriterChannel::StdOutput: return &stdOut; + case WriterChannel::Diagnostic: return &nullWriter; + default: + { + SLANG_ASSERT(!"Unknown type"); + return &stdError; + } + } +} + +void CompileRequest::setWriter(WriterChannel chan, ISlangWriter* writer) +{ + writer = writer ? writer : _getDefaultWriter(chan); + m_writers[int(chan)] = writer; + + if (chan == WriterChannel::Diagnostic) + { + mSink.writer = writer; + } +} + SlangResult CompileRequest::loadFile(String const& path, ISlangBlob** outBlob) { return fileSystemExt->loadFile(path.Buffer(), outBlob); @@ -1205,7 +1241,6 @@ SLANG_API void spSetFileSystem( } } - SLANG_API void spSetCompileFlags( SlangCompileRequest* request, SlangCompileFlags flags) @@ -1319,11 +1354,33 @@ SLANG_API void spSetDiagnosticCallback( SlangDiagnosticCallback callback, void const* userData) { + using namespace Slang; + if(!request) return; auto req = REQ(request); - req->mSink.callback = callback; - req->mSink.callbackUserData = (void*) userData; + ComPtr<ISlangWriter> writer(new CallbackWriter(callback, userData, WriterFlag::IsConsole)); + req->setWriter(WriterChannel::Diagnostic, writer); +} + +SLANG_API void spSetWriter( + SlangCompileRequest* request, + SlangWriterChannel chan, + ISlangWriter* writer) +{ + if (!request) return; + auto req = REQ(request); + + req->setWriter(Slang::WriterChannel(chan), writer); +} + +SLANG_API ISlangWriter* spGetWriter( + SlangCompileRequest* request, + SlangWriterChannel chan) +{ + if (!request) return nullptr; + auto req = REQ(request); + return req->getWriter(Slang::WriterChannel(chan)); } SLANG_API void spAddSearchPath( diff --git a/source/slang/syntax-base-defs.h b/source/slang/syntax-base-defs.h index acc795d8b..81f03d43f 100644 --- a/source/slang/syntax-base-defs.h +++ b/source/slang/syntax-base-defs.h @@ -22,6 +22,7 @@ ABSTRACT_SYNTAX_CLASS(SyntaxNodeBase, NodeBase) template<typename T> T* As() { + SLANG_ASSERT(this); return dynamic_cast<T*>(this); } ) diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index c1585a51a..d354057b2 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -153,7 +153,8 @@ void Type::accept(IValVisitor* visitor, void* extra) Type* Type::GetCanonicalType() { - if (!this) return nullptr; + SLANG_ASSERT(this); + Type* et = const_cast<Type*>(this); if (!et->canonicalType) { @@ -1314,7 +1315,7 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr<Substitutions> GenericSubstitution::applySubstitutionsShallow(SubstitutionSet substSet, RefPtr<Substitutions> substOuter, int* ioDiff) { - if (!this) return nullptr; + SLANG_ASSERT(this); int diff = 0; @@ -1366,7 +1367,7 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr<Substitutions> ThisTypeSubstitution::applySubstitutionsShallow(SubstitutionSet substSet, RefPtr<Substitutions> substOuter, int* ioDiff) { - if (!this) return nullptr; + SLANG_ASSERT(this); int diff = 0; @@ -1385,8 +1386,10 @@ void Type::accept(IValVisitor* visitor, void* extra) bool ThisTypeSubstitution::Equals(Substitutions* subst) { + SLANG_ASSERT(this); if (!subst) - return this == nullptr; + return false; + if (auto thisTypeSubst = dynamic_cast<ThisTypeSubstitution*>(subst)) { return witness->EqualsVal(thisTypeSubst->witness); @@ -1914,7 +1917,7 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr<Val> Val::Substitute(SubstitutionSet subst) { - if (!this) return nullptr; + SLANG_ASSERT(this); if (!subst) return this; int diff = 0; return SubstituteImpl(subst, &diff); diff --git a/source/slang/syntax.h b/source/slang/syntax.h index 7bd2afc12..5eb40fefb 100644 --- a/source/slang/syntax.h +++ b/source/slang/syntax.h @@ -293,6 +293,9 @@ namespace Slang RefPtr<Type> type; bool IsLeftValue; + template <typename T> + T* As(); + QualType() : IsLeftValue(false) {} @@ -1108,6 +1111,13 @@ namespace Slang #include "object-meta-end.h" + + template <typename T> + SLANG_FORCE_INLINE T* QualType::As() + { + return type ? type->As<T>() : nullptr; + } + inline RefPtr<Type> GetSub(DeclRef<GenericTypeConstraintDecl> const& declRef) { return declRef.Substitute(declRef.getDecl()->sub.Ptr()); @@ -1314,4 +1324,4 @@ namespace Slang RefPtr<GenericSubstitution> findInnerMostGenericSubstitution(Substitutions* subst); } // namespace Slang -#endif
\ No newline at end of file +#endif diff --git a/source/slang/type-layout.cpp b/source/slang/type-layout.cpp index 2d21d7aef..4281829be 100644 --- a/source/slang/type-layout.cpp +++ b/source/slang/type-layout.cpp @@ -1099,12 +1099,13 @@ createParameterGroupTypeLayout( // There are several different cases that need to be handled here, // depending on whether we have a `ParameterBlock`, a `ConstantBuffer`, // or some other kind of parameter group. Furthermore, in the - // `ParameterBlock` case, we need to deal with differnet layout + // `ParameterBlock` case, we need to deal with different layout // rules depending on whether a block should map to a register `space` // in HLSL or not. // Check if we are working with a parameter block... - auto parameterBlockType = parameterGroupType->As<ParameterBlockType>(); + auto parameterBlockType = parameterGroupType ? parameterGroupType->As<ParameterBlockType>() : nullptr; + // Check if we have a parameter block *and* it should be // allocated into its own register space(s) |
