diff options
| author | Yong He <yonghe@outlook.com> | 2025-04-28 11:42:22 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-28 11:42:22 -0700 |
| commit | c39c29bf4c52a85d7c83cc8b66ae45e265f9e078 (patch) | |
| tree | 969339828d49d7db92ed9294a17bd34cc021db84 /tools/slang-test/slang-test-main.cpp | |
| parent | 8f6c6e333c06ae1c3b9f00396563c14a2ae09b4d (diff) | |
Add Slang Byte Code generation and interpreter. (#6896)
* Add Slang Byte Code generation and interpreter.
* Fix compile issues.
* format code
* More compile fix.
* Fix clang issue.
* Fix more clang issues.
* Another clang fix.
* Fix clang issues.
* Fix another clang issue.
* Fix wasm build.
* Update building.md
* Fix test-server.
* Fix compile error.
* Fix bug.
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'tools/slang-test/slang-test-main.cpp')
| -rw-r--r-- | tools/slang-test/slang-test-main.cpp | 83 |
1 files changed, 81 insertions, 2 deletions
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index 3f7e41cf6..c0697b4a4 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -28,6 +28,7 @@ #include "options.h" #include "parse-diagnostic-util.h" #include "slangc-tool.h" +#include "slangi-tool.h" #include "test-context.h" #include "test-reporter.h" @@ -860,7 +861,7 @@ Result spawnAndWaitSharedLibrary( stdWriters.setWriter(SLANG_WRITER_CHANNEL_STD_ERROR, &stdError); stdWriters.setWriter(SLANG_WRITER_CHANNEL_STD_OUTPUT, &stdOut); - if (exeName == "slangc") + if (exeName == "slangc" || exeName == "slangi") { stdWriters.setWriter(SLANG_WRITER_CHANNEL_DIAGNOSTIC, &stdError); } @@ -902,7 +903,7 @@ Result spawnAndWaitProxy( // Get the name of the thing to execute String exeName = Path::getFileNameWithoutExt(inCmdLine.m_executableLocation.m_pathOrName); - if (exeName == "slangc") + if (exeName == "slangc" || exeName == "slangi") { // If the test is slangc there is a command line version we can just directly use // return spawnAndWaitExe(context, testPath, inCmdLine, outRes); @@ -1065,6 +1066,7 @@ static PassThroughFlags _getPassThroughFlagsForTarget(SlangCompileTarget target) case SLANG_CUDA_SOURCE: case SLANG_METAL: case SLANG_WGSL: + case SLANG_HOST_VM: { return 0; } @@ -1303,6 +1305,10 @@ static SlangResult _extractTestRequirements(const CommandLine& cmdLine, TestRequ { return _extractSlangCTestRequirements(cmdLine, ioInfo); } + else if (exeName == "slangi") + { + return SLANG_OK; + } else if (exeName == "slang-reflection-test") { return _extractReflectionTestRequirements(cmdLine, ioInfo); @@ -1562,6 +1568,12 @@ String findExpectedPath(const TestInput& input, const char* postFix) return ""; } +static SlangResult _initSlangInterpreter(TestContext* context, CommandLine& ioCmdLine) +{ + ioCmdLine.setExecutableLocation(ExecutableLocation(context->options.binDir, "slangi")); + return SLANG_OK; +} + static SlangResult _initSlangCompiler(TestContext* context, CommandLine& ioCmdLine) { ioCmdLine.setExecutableLocation(ExecutableLocation(context->options.binDir, "slangc")); @@ -2373,6 +2385,67 @@ TestResult runSimpleLineTest(TestContext* context, TestInput& input) return _validateOutput(context, input, actualOutput, false); } +TestResult runInterpreterTest(TestContext* context, TestInput& input) +{ + // need to execute the stand-alone Slang compiler on the file, and compare its output to what we + // expect + auto outputStem = input.outputStem; + + CommandLine cmdLine; + + List<String> args; + + for (Index i = 0; i < input.testOptions->args.getCount(); i++) + { + auto& arg = input.testOptions->args[i]; + if (arg == "-disasm") + cmdLine.addArg(arg); + else if (arg == "-entry") + { + cmdLine.addArg(arg); + i++; + if (i < input.testOptions->args.getCount()) + { + cmdLine.addArg(input.testOptions->args[i]); + } + } + else + { + args.add(arg); + } + } + + cmdLine.addArg(input.filePath); + + for (auto arg : args) + { + cmdLine.addArg(arg); + } + + if (SLANG_FAILED(_initSlangInterpreter(context, cmdLine))) + { + return TestResult::Ignored; + } + + ExecuteResult exeRes; + TEST_RETURN_ON_DONE(spawnAndWait(context, outputStem, input.spawnType, cmdLine, exeRes)); + + if (context->isCollectingRequirements()) + { + return TestResult::Pass; + } + + String actualOutput = getOutput(exeRes); + + return _validateOutput( + context, + input, + actualOutput, + false, + "result code = 0\nstandard error = {\n}\nstandard output = {\n}\n", + [&input](auto e, auto a) { return _areResultsEqual(input.testOptions->type, e, a); }); +} + TestResult runCompile(TestContext* context, TestInput& input) { auto outputStem = input.outputStem; @@ -3952,6 +4025,7 @@ static const TestCommandInfo s_testCommandInfos[] = { {"SIMPLE", &runSimpleTest, 0}, {"SIMPLE_EX", &runSimpleTest, 0}, {"SIMPLE_LINE", &runSimpleLineTest, 0}, + {"INTERPRET", &runInterpreterTest, 0}, {"REFLECTION", &runReflectionTest, 0}, {"CPU_REFLECTION", &runReflectionTest, 0}, {"COMMAND_LINE_SIMPLE", &runSimpleCompareCommandLineTest, 0}, @@ -4851,6 +4925,11 @@ SlangResult innerMain(int argc, char** argv) context.setInnerMainFunc("slangc", &SlangCTool::innerMain); } + { + // We can set the slangc command line tool, to just use the function defined here + context.setInnerMainFunc("slangi", &SlangITool::innerMain); + } + SLANG_RETURN_ON_FAIL( Options::parse(argc, argv, &categorySet, StdWriters::getError(), &context.options)); |
