-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aac0ed2
commit 7bf61e4
Showing
6 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# ~~~ | ||
# SPDX-FileCopyrightText: Michael Popoloski | ||
# SPDX-License-Identifier: MIT | ||
# ~~~ | ||
|
||
add_executable(slang_threadtest threadtest.cpp) | ||
add_executable(slang::threadtest ALIAS slang_threadtest) | ||
|
||
target_link_libraries(slang_threadtest PRIVATE slang::slang) | ||
|
||
set_target_properties(slang_threadtest PROPERTIES OUTPUT_NAME | ||
"slang-threadtest") | ||
|
||
if(CMAKE_SYSTEM_NAME MATCHES "Windows") | ||
target_sources(slang_threadtest | ||
PRIVATE ${PROJECT_SOURCE_DIR}/scripts/win32.manifest) | ||
endif() | ||
|
||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL | ||
"GNU") | ||
target_compile_options(slang_threadtest PRIVATE "-fsanitize=thread") | ||
target_link_libraries(slang_threadtest PRIVATE "-fsanitize=thread") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
slang-threadtest | ||
================ | ||
A simple tool that allows testing the thread safety invariants of the AST. | ||
The AST, once an initial visitation has occurred and all diagnostics are collected, | ||
should then be able to be visited from multiple threads without issue. This tool | ||
runs many such visitations across a design to see if any asserts fire. | ||
|
||
Usage: | ||
|
||
``` | ||
slang-threadtest [-n num_iterations] <all-other-slang-args> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//------------------------------------------------------------------------------ | ||
// slang_main.cpp | ||
// Testing tool for multithreaded AST visitation | ||
// | ||
// SPDX-FileCopyrightText: Michael Popoloski | ||
// SPDX-License-Identifier: MIT | ||
//------------------------------------------------------------------------------ | ||
#include "slang/ast/ASTSerializer.h" | ||
#include "slang/ast/Compilation.h" | ||
#include "slang/ast/symbols/CompilationUnitSymbols.h" | ||
#include "slang/driver/Driver.h" | ||
#include "slang/text/Json.h" | ||
#include "slang/util/ThreadPool.h" | ||
|
||
using namespace slang; | ||
using namespace slang::ast; | ||
using namespace slang::driver; | ||
|
||
int main(int argc, char** argv) { | ||
SLANG_TRY { | ||
OS::setupConsole(); | ||
OS::tryEnableColors(); | ||
|
||
Driver driver; | ||
driver.addStandardArgs(); | ||
|
||
std::optional<int> count; | ||
driver.cmdLine.add("-n,--count", count, "Number of iterations to perform"); | ||
|
||
if (!driver.parseCommandLine(argc, argv) || !driver.processOptions() || | ||
!driver.parseAllSources()) { | ||
return 1; | ||
} | ||
|
||
auto compilation = driver.createCompilation(); | ||
if (!driver.reportCompilation(*compilation, true)) | ||
return 2; | ||
|
||
ThreadPool threadPool; | ||
threadPool.pushLoop(0, count.value_or(1000), [&](int from, int to) { | ||
SLANG_TRY { | ||
JsonWriter writer; | ||
ASTSerializer serializer(*compilation, writer); | ||
serializer.setTryConstantFold(false); | ||
|
||
serializer.startArray(); | ||
for (int i = from; i < to; i++) | ||
serializer.serialize(compilation->getRoot()); | ||
serializer.endArray(); | ||
} | ||
SLANG_CATCH(...) { | ||
#if defined(SLANG_USE_CPPTRACE) | ||
cpptrace::from_current_exception().print(); | ||
#endif | ||
throw; | ||
} | ||
}); | ||
|
||
return 0; | ||
} | ||
SLANG_CATCH(const std::exception& e) { | ||
#if __cpp_exceptions | ||
OS::printE(fmt::format("{}\n", e.what())); | ||
# if defined(SLANG_USE_CPPTRACE) | ||
cpptrace::from_current_exception().print(); | ||
# endif | ||
#endif | ||
} | ||
return 3; | ||
} |