1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// slang-ir-marshal-native-call.h
#pragma once
#include "../core/slang-basic.h"
namespace Slang
{
class DiagnosticSink;
struct IRModule;
struct IRBuilder;
struct IRType;
struct IRFunc;
struct IRFuncType;
struct IRCall;
struct IRInst;
class NativeCallMarshallingContext
{
public:
DiagnosticSink* diagnosticSink = nullptr;
public:
// Get a native type for `type` that can be used directly in a native function signature.
IRType* getNativeType(IRBuilder& builder, IRType* type);
// Get a native function type of `func`.
IRFuncType* getNativeFuncType(IRBuilder& builder, IRFuncType* declaredFuncType);
// Insert a call at builder's current position into a native func with original arguments.
// `originalArgs` will be marshalled to native args before the actual call.
// returns the managed result value of the call.
// Note: additional insts maybe inserted after the call inst to marshal the native output values
// back to non-native arguments/return values.
IRInst* marshalNativeCall(
IRBuilder& builder,
IRFuncType* originalFuncType,
IRFuncType* nativeFuncType,
IRInst* nativeFunc,
Int argCount,
IRInst* const* originalArgs);
void marshalRefManagedValueToNativeValue(
IRBuilder& builder,
IRInst* originalArg,
List<IRInst*>& args);
// Marshal a managed value to a native value for input into a native functions.
void marshalManagedValueToNativeValue(
IRBuilder& builder,
IRType* originalParamType,
IRInst* originalArg,
List<IRInst*>& args);
// Marshal a managed value to a native value for the return value of a native function.
void marshalManagedValueToNativeResultValue(
IRBuilder& builder,
IRInst* originalArg,
List<IRInst*>& args);
IRInst* marshalNativeValueToManagedValue(IRBuilder& builder, IRInst* nativeValue);
IRInst* marshalNativeArgToManagedArg(
IRBuilder& builder,
const List<IRInst*>& args,
Index& consumeIndex,
IRType* expectedManagedType);
IRFunc* generateDLLExportWrapperFunc(IRBuilder& builder, IRFunc* originalFunc);
};
} // namespace Slang
|