From 9d514e65f00dde0e309f33591f31fbf7f132a005 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 12 Jun 2019 09:05:40 -0400 Subject: Runtime execution of Visual Studio Compiler (#978) * Work in progress to be able to invoke VS from within code. * First pass at windows version of refactor of OSProcessSpawner * Closer to getting VS path lookup working. * Make OSString assignable/ctor able * Work out program files directory directly, so don't have to expand %%. * WIP: Improve handling of process spawning. * Add support for splitting input by line. * * Correctly locates visual studio install * Added functionality to invoke vs via cmd * Add option to execute the command line. * Handle in ProcessUtil for windows -> WinHandle. * Rename files slang-win-visual-studio-util.cpp/.h and slang-process-util.h * First pass at unix/linux version of ProcessUtil. * Fix reading Visual Studio path from the registry. * Get compiling on linux with. * Fix vcvarsall.bat name * Use ProcessUtil to execute external code. * Remove OSProcessSpawner. * Remove includes for "os.h" where no longer needed. * Fix tabbing issue in premake5.lua Remove test code from slang-test-main.cpp * Fix premake4.lua tabbing issue. * Small fixes to slang-process-util.h Init ExecuteResult on Win execute. * Improve comments. * Fix bug in StringUtil::calcLines - with oddly terminated source input being able to read past end. Make slang-generate use StringUtil over it's own impl. * Fix off by one bug in working out Visual Studio version. * Fix bug in calculating Visual Studio Version * Fix compilation on linux with string parameter being passed to messageFormat. * Remove erroneous use of kOSError codes - use Result. --- tools/slang-generate/main.cpp | 45 +++++-------------------------------------- 1 file changed, 5 insertions(+), 40 deletions(-) (limited to 'tools/slang-generate/main.cpp') diff --git a/tools/slang-generate/main.cpp b/tools/slang-generate/main.cpp index ddd087072..046b2063c 100644 --- a/tools/slang-generate/main.cpp +++ b/tools/slang-generate/main.cpp @@ -7,6 +7,7 @@ #include "../../source/core/slang-list.h" #include "../../source/core/slang-string.h" +#include "../../source/core/slang-string-util.h" using namespace Slang; @@ -601,7 +602,7 @@ void emitCodeNodes( } // Given line starts and a location, find the line number. Returns -1 if not found -static Index _findLineIndex(const List& lineBreaks, const char* location) +static Index _findLineIndex(const List& lineBreaks, const char* location) { if (location == nullptr) { @@ -615,7 +616,7 @@ static Index _findLineIndex(const List& lineBreaks, const char* loc while (lo + 1 < hi) { const auto mid = (hi + lo) >> 1; - const auto midOffset = lineBreaks[mid]; + const auto midOffset = lineBreaks[mid].begin(); if (midOffset <= location) { lo = mid; @@ -629,50 +630,14 @@ static Index _findLineIndex(const List& lineBreaks, const char* loc return lo; } -static void _calcLineBreaks(const UnownedStringSlice& content, List& outLineStarts) -{ - char const* begin = content.begin(); - char const* end = content.end(); - - char const* cursor = begin; - - // Treat the beginning of the file as a line break - outLineStarts.add(cursor); - - while (cursor != end) - { - int c = *cursor++; - switch (c) - { - case '\r': case '\n': - { - // When we see a line-break character we need - // to record the line break, but we also need - // to deal with the annoying issue of encodings, - // where a multi-byte sequence might encode - // the line break. - - int d = *cursor; - if ((c^d) == ('\r' ^ '\n')) - cursor++; - - outLineStarts.add(cursor); - break; - } - default: - break; - } - } -} - void emitTemplateNodes( SourceFile* sourceFile, FILE* stream, Node* node) { // Work out - List lineBreaks; - _calcLineBreaks(sourceFile->text, lineBreaks); + List lineBreaks; + StringUtil::calcLines(sourceFile->text, lineBreaks); Node* prev = nullptr; for (auto nn = node; nn; prev = nn, nn = nn->next) -- cgit v1.2.3