From 97bb82ebcdf8f1391b9d93b5a8d7b1dfc4e88e52 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 4 Oct 2021 14:15:51 -0400 Subject: Removing exceptions from core/compiler-core (#1953) * #include an absolute path didn't work - because paths were taken to always be relative. * Refactor Stream. Working on all tests. * Split out CharEncode. * Make method names lower camel. m_prefix in Writer/Reader * Tidy up around CharEncode interface. * Small improvements around encode/decode. * Better use of types. * Remove readLine from TextReader. * Remove exceptions from Stream/Text handling. * Fix some typos. * Fix tabbing. * Fix missing override. * Remove remaining exception throw/catch via using signal mechanism. * Remove exceptions that are not used anymore. * Document the Stream interface. * Remove index for decoding 'get byte' function. * Fix CharReader -> ByteReader. --- source/compiler-core/slang-diagnostic-sink.cpp | 8 ++--- source/compiler-core/slang-downstream-compiler.cpp | 39 ++++++---------------- 2 files changed, 15 insertions(+), 32 deletions(-) (limited to 'source/compiler-core') diff --git a/source/compiler-core/slang-diagnostic-sink.cpp b/source/compiler-core/slang-diagnostic-sink.cpp index a6502abc9..c92610e85 100644 --- a/source/compiler-core/slang-diagnostic-sink.cpp +++ b/source/compiler-core/slang-diagnostic-sink.cpp @@ -112,7 +112,7 @@ static void formatDiagnosticMessage(StringBuilder& sb, char const* format, int a if (index >= argCount) { // TODO(tfoley): figure out what a good policy will be for "panic" situations like this - throw InvalidOperationException("too few arguments for diagnostic message"); + SLANG_INVALID_OPERATION("too few arguments for diagnostic message"); } else { @@ -123,7 +123,7 @@ static void formatDiagnosticMessage(StringBuilder& sb, char const* format, int a break; default: - throw InvalidOperationException("invalid diagnostic message format"); + SLANG_INVALID_OPERATION("invalid diagnostic message format"); break; } @@ -512,7 +512,7 @@ void DiagnosticSink::diagnoseImpl(DiagnosticInfo const& info, const UnownedStrin if (info.severity >= Severity::Fatal) { // TODO: figure out a better policy for aborting compilation - throw AbortCompilationException(); + SLANG_ABORT_COMPILATION(""); } } @@ -573,7 +573,7 @@ void DiagnosticSink::diagnoseRaw( if (severity >= Severity::Fatal) { // TODO: figure out a better policy for aborting compilation - throw InvalidOperationException(); + SLANG_ABORT_COMPILATION(""); } } diff --git a/source/compiler-core/slang-downstream-compiler.cpp b/source/compiler-core/slang-downstream-compiler.cpp index 2a172eb3a..9312554ae 100644 --- a/source/compiler-core/slang-downstream-compiler.cpp +++ b/source/compiler-core/slang-downstream-compiler.cpp @@ -391,20 +391,14 @@ SlangResult CommandLineDownstreamCompileResult::getBinary(ComPtr& ou return SLANG_OK; } + List contents; // Read the binary - try - { // Read the contents of the binary - List contents = File::readAllBytes(m_moduleFilePath); + SLANG_RETURN_ON_FAIL(File::readAllBytes(m_moduleFilePath, contents)); - m_binaryBlob = new ScopeRefObjectBlob(ListBlob::moveCreate(contents), m_temporaryFiles); - outBlob = m_binaryBlob; - return SLANG_OK; - } - catch (const Slang::IOException&) - { - return SLANG_FAIL; - } + m_binaryBlob = new ScopeRefObjectBlob(ListBlob::moveCreate(contents), m_temporaryFiles); + outBlob = m_binaryBlob; + return SLANG_OK; } /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CommandLineDownstreamCompiler !!!!!!!!!!!!!!!!!!!!!!*/ @@ -428,15 +422,12 @@ static bool _isContentsInFile(const DownstreamCompiler::CompileOptions& options) // file either from some specialized ISlangFileSystem, so this is probably as good as it gets // until we can integrate directly to a C/C++ compiler through say a shared library where we can control // file system access. - try + String readContents; + + if (SLANG_SUCCEEDED(File::readAllText(options.sourceContentsPath, readContents))) { - String readContents = File::readAllText(options.sourceContentsPath); - // We should see if they are the same return options.sourceContents == readContents.getUnownedSlice(); } - catch (const Slang::IOException&) - { - } } return false; } @@ -484,17 +475,9 @@ SlangResult CommandLineDownstreamCompiler::compile(const CompileOptions& inOptio } // Write it out - try - { - productFileSet->add(compileSourcePath); - - File::writeAllText(compileSourcePath, options.sourceContents); - } - catch (...) - { - return SLANG_FAIL; - } - + productFileSet->add(compileSourcePath); + SLANG_RETURN_ON_FAIL(File::writeAllText(compileSourcePath, options.sourceContents)); + // Add it as a source file options.sourceFiles.add(compileSourcePath); } -- cgit v1.2.3