From eb331446e3bee812d1df19cf59eb2d23d287ac74 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 7 Jan 2019 09:31:31 -0500 Subject: Feature/serialization debug info (#767) * Remove AppContext. Use StdChannels to hold writers, and TestToolUtil to hold test tool specific functionality. * StdChannels -> StdWriters * getStdOut -> getOut, getStdError -> getError * Renamed main.cpp files of tools to try and stop visual studio getting confused between files - such that clicking on an error takes editor to the right location. * Work in progress on being able to serialize debug information. * * Added MemoryStream * First pass converting to IRSerialData * Able to read and write IRSerialData with debug data * Start at reconstruting IR serialized data. * First pass of generation debug SourceLocs from debug data. Works for test set for line nos. * Bug fixes. Moved testing of serialization into IRSerialUtil * Work around problem with irModule = generateIRForTranslationUnit(translationUnit); two times in a row produces different output(!). Fix by just creating once. * Remove problem with use of ternary op in slang.cpp on gcc/clang. * Added -verify-debug-serial-ir option that makes IR modules go through full serialization with debug information and verification. * Add a test that does serial debug verification that is run by default on linux. --- source/slang/source-loc.cpp | 74 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 17 deletions(-) (limited to 'source/slang/source-loc.cpp') diff --git a/source/slang/source-loc.cpp b/source/slang/source-loc.cpp index 6d6d63ae1..c567dbf22 100644 --- a/source/slang/source-loc.cpp +++ b/source/slang/source-loc.cpp @@ -159,7 +159,7 @@ PathInfo SourceView::_getPathInfo(StringSlicePool::Handle pathHandle) const // If there is no override path, then just the source files path if (pathHandle == StringSlicePool::Handle(0)) { - return m_sourceFile->pathInfo; + return m_sourceFile->getPathInfo(); } else { @@ -172,7 +172,7 @@ PathInfo SourceView::getPathInfo(SourceLoc loc, SourceLocType type) { if (type == SourceLocType::Actual) { - return m_sourceFile->pathInfo; + return m_sourceFile->getPathInfo(); } const int entryIndex = findEntryIndex(loc); @@ -181,6 +181,12 @@ PathInfo SourceView::getPathInfo(SourceLoc loc, SourceLocType type) /* !!!!!!!!!!!!!!!!!!!!!!! SourceFile !!!!!!!!!!!!!!!!!!!!!!!!!!!! */ +void SourceFile::setLineBreakOffsets(const uint32_t* offsets, UInt numOffsets) +{ + m_lineBreakOffsets.Clear(); + m_lineBreakOffsets.AddRange(offsets, numOffsets); +} + const List& SourceFile::getLineBreakOffsets() { // We now have a raw input file that we can search for line breaks. @@ -188,6 +194,8 @@ const List& SourceFile::getLineBreakOffsets() // cache an array of line break locations in the file. if (m_lineBreakOffsets.Count() == 0) { + UnownedStringSlice content = getContent(); + char const* begin = content.begin(); char const* end = content.end(); @@ -232,7 +240,7 @@ const List& SourceFile::getLineBreakOffsets() int SourceFile::calcLineIndexFromOffset(int offset) { - SLANG_ASSERT(UInt(offset) <= content.size()); + SLANG_ASSERT(UInt(offset) <= getContentSize()); // Make sure we have the line break offsets const auto& lineBreakOffsets = getLineBreakOffsets(); @@ -266,6 +274,38 @@ int SourceFile::calcColumnIndex(int lineIndex, int offset) return offset - lineBreakOffsets[lineIndex]; } +/* !!!!!!!!!!!!!!!!!!!!!!!!! SourceFile !!!!!!!!!!!!!!!!!!!!!!!!!!!! */ + +void SourceFile::setContents(ISlangBlob* blob) +{ + const UInt contentSize = blob->getBufferSize(); + + SLANG_ASSERT(contentSize == m_contentSize); + + char const* contentBegin = (char const*)blob->getBufferPointer(); + char const* contentEnd = contentBegin + contentSize; + + m_contentBlob = blob; + m_content = UnownedStringSlice(contentBegin, contentEnd); +} + +void SourceFile::setContents(const String& content) +{ + ComPtr contentBlob = StringUtil::createStringBlob(content); + setContents(contentBlob); +} + +SourceFile::SourceFile(const PathInfo& pathInfo, size_t contentSize) : + m_pathInfo(pathInfo), + m_contentSize(contentSize) +{ +} + +SourceFile::~SourceFile() +{ + +} + /* !!!!!!!!!!!!!!!!!!!!!!!!! SourceManager !!!!!!!!!!!!!!!!!!!!!!!!!!!! */ void SourceManager::initialize( @@ -319,29 +359,29 @@ SourceRange SourceManager::allocateSourceRange(UInt size) return SourceRange(beginLoc, endLoc); } -SourceFile* SourceManager::createSourceFile(const PathInfo& pathInfo, ISlangBlob* contentBlob) +RefPtr SourceManager::createSourceFileWithSize(const PathInfo& pathInfo, size_t contentSize) { - char const* contentBegin = (char const*) contentBlob->getBufferPointer(); - UInt contentSize = contentBlob->getBufferSize(); - char const* contentEnd = contentBegin + contentSize; + SourceFile* sourceFile = new SourceFile(pathInfo, contentSize); + return sourceFile; +} - SourceFile* sourceFile = new SourceFile(); - sourceFile->pathInfo = pathInfo; - sourceFile->contentBlob = contentBlob; - sourceFile->content = UnownedStringSlice(contentBegin, contentEnd); - +RefPtr SourceManager::createSourceFileWithString(const PathInfo& pathInfo, const String& contents) +{ + SourceFile* sourceFile = new SourceFile(pathInfo, contents.Length()); + sourceFile->setContents(contents); return sourceFile; } - -SourceFile* SourceManager::createSourceFile(const PathInfo& pathInfo, const String& content) + +RefPtr SourceManager::createSourceFileWithBlob(const PathInfo& pathInfo, ISlangBlob* blob) { - ComPtr contentBlob = StringUtil::createStringBlob(content); - return createSourceFile(pathInfo, contentBlob); + RefPtr sourceFile(new SourceFile(pathInfo, blob->getBufferSize())); + sourceFile->setContents(blob); + return sourceFile; } SourceView* SourceManager::createSourceView(SourceFile* sourceFile) { - SourceRange range = allocateSourceRange(sourceFile->content.size()); + SourceRange range = allocateSourceRange(sourceFile->getContentSize()); SourceView* sourceView = new SourceView(this, sourceFile, range); m_sourceViews.Add(sourceView); -- cgit v1.2.3