summaryrefslogtreecommitdiff
path: root/tools/slang-eval-test/main.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-05-11 16:34:19 -0700
committerGitHub <noreply@github.com>2018-05-11 16:34:19 -0700
commite2c2c220c642cc5f1c622f909d0ddfd22e6c04d4 (patch)
tree2f8b2faa3ff61d07e106d4f049aa600b14ad8cf8 /tools/slang-eval-test/main.cpp
parent34ecdb71c04232fba4b097f04fc358c57e704e26 (diff)
Generate Visual Studio projects using Premake (#557)
* Generate Visual Studio projects using Premake This change adds a `premake5.lua` file that allows us to generate our Visual Studio solution using Premake 5 (https://premake.github.io/). The existing Visual Studio solution/projects are now replaced with the Premake-generated ones, and project contributors will be expected to update these by running premake after adding/removing files. I have *not* changed the Linux `Makefile` build at all, because that file is also used for things like running our tests, so that clobbering it with a premake-generated `Makefile` would break our continuous testing. Hopefully future changes can switch to a generated `Makefile` and perhaps even add an XCode project as well. Notes: * The `build/slang-build.props` file is no longer needed/used, so it has been removed. * The `slang-eval-test` test fixture wasn't following our naming conventions for its directory path, so it was updated to streamline the Premake build configuration work. This required changes to the `Makefile` as well * Some seemingly unncessary preprocessor definitions that were specified for `core` and `slang-glslang` have been dropped. We will see if anything breaks from that. * Possible fixup for Premake vpath issue Premake's `vpath` feature seems to be nondeterministic about the order it applies filters (because Lua isn't deterministic about the order of entries in a key/value table), and as a result we can end up in a weird case where it decides that a `foo.cpp.h` file matches the `**.cpp` filter (I'm not sure why) before it tests against the `**.h` filter. This change uses an (undocumented) Premake facility to set `vpath` using a list of singleton tables, which seems to fix the order in which things get tested. * Remove support for "single-file" build of Slang The `hello` example was the only bit of code that uses the "single-file" way of building Slang, and this had already run up against limitations of the Visual Studio compilers in its Debug|x64 build. Rather than mess with Premake to make it pass through the `/bigobj` linker flag that is needed to work around the issue, it makes more sense just to stop using/supporting the feature since we wouldn't want users to depend on it anyway (our documentation no longer refers to it). While I was at it I went ahead and made sure that the `SLANG_DYNAMIC` flag doesn't need to be set manually, so that instead there is a non-default `SLANG_STATIC` option (not that we have a static-library build of Slang at the moment).
Diffstat (limited to 'tools/slang-eval-test/main.cpp')
-rw-r--r--tools/slang-eval-test/main.cpp133
1 files changed, 133 insertions, 0 deletions
diff --git a/tools/slang-eval-test/main.cpp b/tools/slang-eval-test/main.cpp
new file mode 100644
index 000000000..e01d4441b
--- /dev/null
+++ b/tools/slang-eval-test/main.cpp
@@ -0,0 +1,133 @@
+// main.cpp
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "../../source/core/secure-crt.h"
+#include <slang.h>
+
+int main(
+ int argc,
+ char** argv)
+{
+ // TODO: parse arguments
+
+ assert(argc >= 2);
+ char const* inputPath = argv[1];
+
+ // Slurp in the input file, so that we can compile and run it
+ FILE* inputFile;
+ fopen_s(&inputFile, inputPath, "rb");
+ assert(inputFile);
+
+ fseek(inputFile, 0, SEEK_END);
+ size_t inputSize = ftell(inputFile);
+ fseek(inputFile, 0, SEEK_SET);
+
+ char* inputText = (char*) malloc(inputSize + 1);
+ fread(inputText, inputSize, 1, inputFile);
+ inputText[inputSize] = 0;
+ fclose(inputFile);
+
+ // TODO: scan through the text to find comments,
+ // that instruct us how to generate input and
+ // consume output when running the test.
+
+ //
+
+ SlangSession* session = spCreateSession(nullptr);
+ SlangCompileRequest* request = spCreateCompileRequest(session);
+
+ spSetOutputContainerFormat(
+ request,
+ SLANG_CONTAINER_FORMAT_SLANG_MODULE);
+
+ int translationUnitIndex = spAddTranslationUnit(
+ request,
+ SLANG_SOURCE_LANGUAGE_SLANG,
+ nullptr);
+
+ spAddTranslationUnitSourceString(
+ request,
+ translationUnitIndex,
+ inputPath,
+ inputText);
+
+ int entryPointIndex = spAddEntryPoint(
+ request,
+ translationUnitIndex,
+ "main",
+ spFindProfile(session, "cs_5_0"));
+
+ if( spCompile(request) != 0 )
+ {
+ char const* output = spGetDiagnosticOutput(request);
+ fputs(output, stderr);
+ exit(1);
+ }
+
+ // Things compiled, so now we need to run them...
+
+ // Extract the bytecode
+ size_t bytecodeSize = 0;
+ void const* bytecode = spGetCompileRequestCode(request, &bytecodeSize);
+
+ // Now we need to create an execution context to go and run the bytecode we got
+
+ SlangVM* vm = SlangVM_create();
+
+ SlangVMModule* vmModule = SlangVMModule_load(
+ vm,
+ bytecode,
+ bytecodeSize);
+
+ SlangVMFunc* vmFunc = (SlangVMFunc*)SlangVMModule_findGlobalSymbolPtr(
+ vmModule,
+ "main");
+
+ int32_t*& inputArg = *(int32_t**)SlangVMModule_findGlobalSymbolPtr(
+ vmModule,
+ "input");
+
+ int32_t*& outputArg = *(int32_t**)SlangVMModule_findGlobalSymbolPtr(
+ vmModule,
+ "output");
+
+ SlangVMThread* vmThread = SlangVMThread_create(
+ vm);
+
+ int32_t inputData[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
+ int32_t outputData[8] = { 0 };
+
+ inputArg = inputData;
+ outputArg = outputData;
+
+ // TODO: set arguments based on specification from the user...
+ for (uint32_t threadID = 0; threadID < 8; ++threadID)
+ {
+#if 0
+ fprintf(stderr, "\n\nthreadID = %u\n\n", threadID);
+ fflush(stderr);
+#endif
+
+ SlangVMThread_beginCall(vmThread, vmFunc);
+
+ SlangVMThread_setArg(
+ vmThread,
+ 0,
+ &threadID,
+ sizeof(threadID));
+
+ SlangVMThread_resume(vmThread);
+ }
+
+ for (uint32_t ii = 0; ii < 8; ++ii)
+ {
+ fprintf(stdout, "outputData[%u] = %d\n", ii, outputData[ii]);
+ }
+
+ spDestroyCompileRequest(request);
+ spDestroySession(session);
+
+ return 0;
+}