From dc493d492d4d9c090dab410a0cb80eca490c32aa Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 14 Aug 2019 12:57:33 -0400 Subject: Small improvements around C/C++ testing (#1017) * * Simplify some of test code around CPPCompiler * Test using 'callable' with pass-through * Small cpu doc improvements * Improvements to Clang output parsing. * Remove temporary file (base filename) . * Improve handling of external errors - handle severity. * On error dumping out to 'actual' file for runCPPCompilerCompile. * Small fixes. Set the source language type correctly for pass thru. * Remove warning for test for clang backend c --- source/core/slang-gcc-compiler-util.cpp | 21 +++++++++++++---- source/slang/slang-compiler.cpp | 42 ++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 11 deletions(-) (limited to 'source') diff --git a/source/core/slang-gcc-compiler-util.cpp b/source/core/slang-gcc-compiler-util.cpp index c48e779d1..b7cc85cb3 100644 --- a/source/core/slang-gcc-compiler-util.cpp +++ b/source/core/slang-gcc-compiler-util.cpp @@ -184,6 +184,16 @@ static SlangResult _parseGCCFamilyLine(const UnownedStringSlice& line, LineParse outLineParseResult = LineParseResult::Start; return SLANG_OK; } + + if (SLANG_SUCCEEDED(_parseErrorType(split0, outMsg.type))) + { + // Command line errors can be just contain 'error:' etc. Can be seen on apple/clang + outMsg.stage = OutputMessage::Stage::Compile; + outMsg.text = split[1].trim(); + outLineParseResult = LineParseResult::Single; + return SLANG_OK; + } + outLineParseResult = LineParseResult::Ignore; return SLANG_OK; } @@ -193,8 +203,9 @@ static SlangResult _parseGCCFamilyLine(const UnownedStringSlice& line, LineParse const auto split1 = split[1].trim(); const auto text = split[2].trim(); - // Check for special handling for clang - if (split0.startsWith(UnownedStringSlice::fromLiteral("clang"))) + // Check for special handling for clang (Can be Clang or clang apparently) + if (split0.startsWith(UnownedStringSlice::fromLiteral("clang")) || + split0.startsWith(UnownedStringSlice::fromLiteral("Clang")) ) { // Extract the type SLANG_RETURN_ON_FAIL(_parseErrorType(split[1].trim(), outMsg.type)); @@ -387,11 +398,11 @@ static SlangResult _parseGCCFamilyLine(const UnownedStringSlice& line, LineParse /* static */SlangResult GCCCompilerUtil::calcArgs(const CompileOptions& options, CommandLine& cmdLine) { PlatformKind platformKind = (options.platform == PlatformKind::Unknown) ? PlatformUtil::getPlatformKind() : options.platform; - - cmdLine.addArg("-fvisibility=hidden"); - + if (options.sourceType == SourceType::CPP) { + cmdLine.addArg("-fvisibility=hidden"); + // Need C++14 for partial specialization cmdLine.addArg("-std=c++14"); } diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 8ead63784..5b8643b02 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -768,7 +768,7 @@ namespace Slang return result; } - void reportExternalCompileError(const char* compilerName, SlangResult res, const UnownedStringSlice& diagnostic, DiagnosticSink* sink) + void reportExternalCompileError(const char* compilerName, Severity severity, SlangResult res, const UnownedStringSlice& diagnostic, DiagnosticSink* sink) { StringBuilder builder; if (compilerName) @@ -792,10 +792,15 @@ namespace Slang PlatformUtil::appendResult(res, builder); } + sink->diagnoseRaw(severity, builder.getUnownedSlice()); + } + + void reportExternalCompileError(const char* compilerName, SlangResult res, const UnownedStringSlice& diagnostic, DiagnosticSink* sink) + { // TODO(tfoley): need a better policy for how we translate diagnostics // back into the Slang world (although we should always try to generate // HLSL that doesn't produce any diagnostics...) - sink->diagnoseRaw(SLANG_FAILED(res) ? Severity::Error : Severity::Warning, builder.getUnownedSlice()); + reportExternalCompileError(compilerName, SLANG_FAILED(res) ? Severity::Error : Severity::Warning, res, diagnostic, sink); } static String _getDisplayPath(DiagnosticSink* sink, SourceFile* sourceFile) @@ -1341,10 +1346,16 @@ SlangResult dissassembleDXILUsingDXC( CPPCompiler::CompileOptions options; + // Set the source type + options.sourceType = (rawSourceLanguage == SourceLanguage::C) ? CPPCompiler::SourceType::C : CPPCompiler::SourceType::CPP; + // Generate a path a temporary filename for output module String modulePath; SLANG_RETURN_ON_FAIL(File::generateTemporary(UnownedStringSlice::fromLiteral("slang-generated"), modulePath)); + // Remove the temporary path/file when done + temporaryFileSet.add(modulePath); + options.modulePath = modulePath; options.sourceFiles.add(compileSourcePath); @@ -1483,17 +1494,36 @@ SlangResult dissassembleDXILUsingDXC( builder << "link "; } + // + Severity severity = Severity::Error; + switch (msg.type) { - case OutputMessage::Type::Error: builder << "error"; break; - case OutputMessage::Type::Unknown: builder << "warning"; break; - case OutputMessage::Type::Info: builder << "info"; break; + case OutputMessage::Type::Unknown: + case OutputMessage::Type::Error: + { + severity = Severity::Error; + builder << "error"; + break; + } + case OutputMessage::Type::Warning: + { + severity = Severity::Warning; + builder << "warning"; + break; + } + case OutputMessage::Type::Info: + { + severity = Severity::Note; + builder << "info"; + break; + } default: break; } builder << " " << msg.code << ": " << msg.text; - reportExternalCompileError(compilerText.getBuffer(), SLANG_OK, builder.getUnownedSlice(), sink); + reportExternalCompileError(compilerText.getBuffer(), severity, SLANG_OK, builder.getUnownedSlice(), sink); } } -- cgit v1.2.3