diff options
Diffstat (limited to 'source/slang/slang-ir-dll-export.cpp')
| -rw-r--r-- | source/slang/slang-ir-dll-export.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/source/slang/slang-ir-dll-export.cpp b/source/slang/slang-ir-dll-export.cpp new file mode 100644 index 000000000..a8b464b43 --- /dev/null +++ b/source/slang/slang-ir-dll-export.cpp @@ -0,0 +1,72 @@ +// slang-ir-dll-export.cpp +#include "slang-ir-dll-export.h" + +#include "slang-ir.h" +#include "slang-ir-insts.h" +#include "slang-ir-marshal-native-call.h" + +namespace Slang +{ + +struct DllExportContext +{ + IRModule* module; + DiagnosticSink* diagnosticSink; + + SharedIRBuilder sharedBuilder; + + void processFunc(IRFunc* func, IRDllExportDecoration* dllExportDecoration) + { + NativeCallMarshallingContext marshalContext; + marshalContext.diagnosticSink = diagnosticSink; + IRBuilder builder(sharedBuilder); + auto wrapper = marshalContext.generateDLLExportWrapperFunc(builder, func); + dllExportDecoration->removeFromParent(); + dllExportDecoration->insertAtStart(wrapper); + builder.addNameHintDecoration(wrapper, dllExportDecoration->getFunctionName()); + builder.addExternCppDecoration(wrapper, dllExportDecoration->getFunctionName()); + builder.addPublicDecoration(wrapper); + builder.addKeepAliveDecoration(wrapper); + builder.addHLSLExportDecoration(wrapper); + if (auto oldPublicDecoration = func->findDecoration<IRPublicDecoration>()) + { + oldPublicDecoration->removeFromParent(); + } + } + + void processModule() + { + struct Candidate { IRFunc* func; IRDllExportDecoration* exportDecoration; }; + List<Candidate> candidates; + for (auto childFunc : module->getGlobalInsts()) + { + switch(childFunc->getOp()) + { + case kIROp_Func: + if (auto dllExportDecoration = childFunc->findDecoration<IRDllExportDecoration>()) + { + candidates.add(Candidate{ as<IRFunc>(childFunc), dllExportDecoration }); + } + break; + default: + break; + } + } + + for (auto candidate : candidates) + { + processFunc(candidate.func, candidate.exportDecoration); + } + } +}; + +void generateDllExportFuncs(IRModule* module, DiagnosticSink* sink) +{ + DllExportContext context; + context.module = module; + context.diagnosticSink = sink; + context.sharedBuilder.init(module); + return context.processModule(); +} + +} |
