blob: cfcf65a7fc9dfca8f4cb2f9b5e9a535a3ac9b9af (
plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
// slang-compiler-api.h
#pragma once
//
// This file provides utilities that are needed at the boundary
// between the public Slang API (the interfaces declared in
// `slang.h`) and the code that implements that API.
//
#include "slang-end-to-end-request.h"
#include "slang-global-session.h"
#include "slang-module.h"
#include "slang-session.h"
#include <slang.h>
namespace Slang
{
//
// The following functions are utilties to convert between
// matching "external" (public API) and "internal" (implementation)
// types. They are favored over explicit casts because they
// help avoid making incorrect conversions (e.g., when using
// `reinterpret_cast` or C-style casts), and because they
// abstract over the conversion required for each pair of types.
//
SLANG_FORCE_INLINE slang::IGlobalSession* asExternal(Session* session)
{
return static_cast<slang::IGlobalSession*>(session);
}
SLANG_FORCE_INLINE ComPtr<Session> asInternal(slang::IGlobalSession* session)
{
Slang::Session* internalSession = nullptr;
session->queryInterface(SLANG_IID_PPV_ARGS(&internalSession));
return ComPtr<Session>(INIT_ATTACH, static_cast<Session*>(internalSession));
}
SLANG_FORCE_INLINE slang::ISession* asExternal(Linkage* linkage)
{
return static_cast<slang::ISession*>(linkage);
}
SLANG_FORCE_INLINE Module* asInternal(slang::IModule* module)
{
return static_cast<Module*>(module);
}
SLANG_FORCE_INLINE slang::IModule* asExternal(Module* module)
{
return static_cast<slang::IModule*>(module);
}
ComponentType* asInternal(slang::IComponentType* inComponentType);
SLANG_FORCE_INLINE slang::IComponentType* asExternal(ComponentType* componentType)
{
return static_cast<slang::IComponentType*>(componentType);
}
SLANG_FORCE_INLINE slang::ProgramLayout* asExternal(ProgramLayout* programLayout)
{
return (slang::ProgramLayout*)programLayout;
}
SLANG_FORCE_INLINE Type* asInternal(slang::TypeReflection* type)
{
return reinterpret_cast<Type*>(type);
}
SLANG_FORCE_INLINE slang::TypeReflection* asExternal(Type* type)
{
return reinterpret_cast<slang::TypeReflection*>(type);
}
SLANG_FORCE_INLINE DeclRef<Decl> asInternal(slang::GenericReflection* generic)
{
return DeclRef<Decl>(reinterpret_cast<DeclRefBase*>(generic));
}
SLANG_FORCE_INLINE slang::GenericReflection* asExternal(DeclRef<Decl> generic)
{
return reinterpret_cast<slang::GenericReflection*>(generic.declRefBase);
}
SLANG_FORCE_INLINE TypeLayout* asInternal(slang::TypeLayoutReflection* type)
{
return reinterpret_cast<TypeLayout*>(type);
}
SLANG_FORCE_INLINE slang::TypeLayoutReflection* asExternal(TypeLayout* type)
{
return reinterpret_cast<slang::TypeLayoutReflection*>(type);
}
SLANG_FORCE_INLINE SlangCompileRequest* asExternal(EndToEndCompileRequest* request)
{
return static_cast<SlangCompileRequest*>(request);
}
SLANG_FORCE_INLINE EndToEndCompileRequest* asInternal(SlangCompileRequest* request)
{
// Converts to the internal type -- does a runtime type check through queryInterfae
SLANG_ASSERT(request);
EndToEndCompileRequest* endToEndRequest = nullptr;
// NOTE! We aren't using to access an interface, so *doesn't* return with a refcount
request->queryInterface(SLANG_IID_PPV_ARGS(&endToEndRequest));
SLANG_ASSERT(endToEndRequest);
return endToEndRequest;
}
SLANG_FORCE_INLINE SlangCompileTarget asExternal(CodeGenTarget target)
{
return (SlangCompileTarget)target;
}
SLANG_FORCE_INLINE SlangSourceLanguage asExternal(SourceLanguage sourceLanguage)
{
return (SlangSourceLanguage)sourceLanguage;
}
} // namespace Slang
|