diff options
| author | Yong He <yonghe@outlook.com> | 2022-07-25 10:08:28 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-25 10:08:28 -0700 |
| commit | 9566e8af25f87ad034a984db9d847942e454a180 (patch) | |
| tree | 2f295bf2bf60c39fd35b6b634b903d574b4ca99e /source/slang/slang-ir-dll-export.cpp | |
| parent | 70147fc7ba6abe0b669363ed5adfd8d4d9545c3f (diff) | |
Allow `class` to implement COM interface, [DLLExport] (#2338)
* Allow `class` to implement COM interface, [DLLExport]
* Fix [COM] usage in tests and examples with UUIDs.
Co-authored-by: Yong He <yhe@nvidia.com>
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(); +} + +} |
