From 6fc2c37d9a4c408331db1b33deb3b46e74d2a7d2 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 12 Aug 2019 15:41:41 -0400 Subject: Callable CPU code support (#1014) * First pass support for compiling to a loaded shared library. * Improve documentation for cpu target. * Removed the SLANG_COMPILE_FLAG_LOAD_SHARED_LIBRARY flag. Use the SLANG_HOST_CALLABLE code target Document mechanism. * Fix typo in cpp-resource.slang In test code if the target is 'callable' we don't need to compile (indeed there is no source file). * Small refactor using CommandLineCPPCompiler as base class to implement VisualStudioCPPCompiler and GCCCPPCompiler. * Improvements around CPPCompiler. Mechanism to know products produced. Cleaning up products after execution. * Fix multiple definition of 'SourceType' --- tools/slang-test/slang-test-main.cpp | 51 ++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 19 deletions(-) (limited to 'tools') diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index 8be8f797a..8137733ee 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -556,6 +556,7 @@ static PassThroughFlags _getPassThroughFlagsForTarget(SlangCompileTarget target) return PassThroughFlag::Dxc; } + case SLANG_HOST_CALLABLE: case SLANG_EXECUTABLE: case SLANG_SHARED_LIBRARY: { @@ -590,6 +591,8 @@ static SlangCompileTarget _getCompileTarget(const UnownedStringSlice& name) CASE("exe", EXECUTABLE) CASE("sharedlib", SHARED_LIBRARY) CASE("dll", SHARED_LIBRARY) + CASE("callable", HOST_CALLABLE) + CASE("host-callable", HOST_CALLABLE) #undef CASE return SLANG_TARGET_UNKNOWN; @@ -1369,39 +1372,49 @@ static TestResult runCPPCompilerCompile(TestContext* context, TestInput& input) String ext = Path::getFileExt(filePath); String modulePath = Path::combine(directory, moduleName); - // Find the target UnownedStringSlice targetExt = UnownedStringSlice::fromLiteral("c"); + + // Find the target Index index = cmdLine.findArgIndex(UnownedStringSlice::fromLiteral("-target")); if (index >= 0 && index + 1 < cmdLine.getArgCount()) { targetExt = cmdLine.m_args[index + 1].value.getUnownedSlice(); } - CPPCompiler::CompileOptions options; - options.sourceType = (targetExt == "c") ? CPPCompiler::SourceType::C : CPPCompiler::SourceType::CPP; + // If output was C/C++ we should try compiling + if (targetExt == "c" || targetExt == "cpp") + { + CPPCompiler::CompileOptions options; + options.sourceType = (targetExt == "c") ? CPPCompiler::SourceType::C : CPPCompiler::SourceType::CPP; - options.includePaths.add("tests/cross-compile"); + options.includePaths.add("tests/cross-compile"); - // Create a filename to write this out to - String cppSource = modulePath + "." + targetExt; - Slang::File::writeAllText(cppSource, actualOutput); + // Create a filename to write this out to + String cppSource = modulePath + "." + targetExt; + Slang::File::writeAllText(cppSource, actualOutput); - // Okay we can now try compiling + // Okay we can now try compiling - // Compile this source - options.sourceFiles.add(cppSource); - options.modulePath = modulePath; - options.targetType = CPPCompiler::TargetType::SharedLibrary; + // Compile this source + options.sourceFiles.add(cppSource); + options.modulePath = modulePath; + options.targetType = CPPCompiler::TargetType::SharedLibrary; - CPPCompiler::Output output; - if (SLANG_FAILED(compiler->compile(options, output))) - { - return TestResult::Fail; - } + CPPCompiler::Output output; + if (SLANG_FAILED(compiler->compile(options, output))) + { + return TestResult::Fail; + } - if (output.getCountByType(CPPCompiler::OutputMessage::Type::Error) > 0) + if (output.getCountByType(CPPCompiler::OutputMessage::Type::Error) > 0) + { + return TestResult::Fail; + } + } + else { - return TestResult::Fail; + // Can only be callable + SLANG_ASSERT(targetExt == "callable" || targetExt == "host-callable"); } return TestResult::Pass; -- cgit v1.2.3