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. --- tools/slang-embed/slang-embed.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'tools/slang-embed/slang-embed.cpp') diff --git a/tools/slang-embed/slang-embed.cpp b/tools/slang-embed/slang-embed.cpp index 17b71d216..4a81c1b95 100644 --- a/tools/slang-embed/slang-embed.cpp +++ b/tools/slang-embed/slang-embed.cpp @@ -19,6 +19,7 @@ #include "../../source/core/slang-string-util.h" #include "../../source/core/slang-io.h" + // Utility to free pointers on scope exit struct ScopedMemory { @@ -86,6 +87,8 @@ struct App bool useNewStringLit = true; void processInputFile(FILE* outputFile, Slang::String inputPath) { + using namespace Slang; + // We open the input file in text mode because we are currently // embedding textual source files. If/when this utility gets // used for binary files another mode could be called for. @@ -94,15 +97,22 @@ struct App // could lead to a difference in the embedded bytes based on // the line ending convention of the host platform) // - Slang::StreamReader streamReader(inputPath); - while (!streamReader.IsEnd()) + + String contents; + { + auto res = File::readAllText(inputPath, contents); + SLANG_ASSERT(SLANG_SUCCEEDED(res)); + } + + LineParser lineReader(contents.getUnownedSlice()); + + for (auto line : lineReader) { - auto line = streamReader.ReadLine(); - Slang::String trimedLine = line.trimStart(); + auto trimedLine = line.trimStart(); if (trimedLine.startsWith("#include")) { auto fileName = - Slang::StringUtil::getAtInSplit(trimedLine.getUnownedSlice(), ' ', 1); + Slang::StringUtil::getAtInSplit(trimedLine, ' ', 1); if (fileName[0] == '<') goto normalProcess; fileName = Slang::UnownedStringSlice(fileName.begin() + 1, fileName.end() - 1); -- cgit v1.2.3