blob: 25964964f8ddc742eb742c6c935fa07ef3f7c426 (
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
// slang-downstream-dep1.cpp
#include "slang-downstream-dep1.h"
#include "slang-artifact-util.h"
#include "slang-artifact-associated-impl.h"
#include "../core/slang-castable-list-impl.h"
namespace Slang
{
/* !!!!!!!!!!!!!!!!!!!!!!!!! DownstreamArtifactRepresentation_Dep1 !!!!!!!!!!!!!!!!!!!!!!!! */
class DownstreamResultArtifactRepresentationAdapater_Dep1 : public ComBaseObject, public IArtifactRepresentation
{
public:
SLANG_COM_BASE_IUNKNOWN_ALL
// ICastable
virtual SLANG_NO_THROW void* SLANG_MCALL castAs(const SlangUUID& guid) SLANG_OVERRIDE;
// IArtifactRepresentation
virtual SLANG_NO_THROW SlangResult SLANG_MCALL createRepresentation(const Guid& typeGuid, ICastable** outCastable) SLANG_OVERRIDE;
virtual SLANG_NO_THROW bool SLANG_MCALL exists() SLANG_OVERRIDE { return true; }
DownstreamResultArtifactRepresentationAdapater_Dep1(DownstreamCompileResult_Dep1* result):
m_result(result)
{
}
void* getInterface(const Guid& guid);
void* getObject(const Guid& guid);
RefPtr<DownstreamCompileResult_Dep1> m_result;
};
void* DownstreamResultArtifactRepresentationAdapater_Dep1::castAs(const SlangUUID& guid)
{
if (auto ptr = getInterface(guid))
{
return ptr;
}
return getObject(guid);
}
void* DownstreamResultArtifactRepresentationAdapater_Dep1::getInterface(const Guid& guid)
{
if (guid == ISlangBlob::getTypeGuid() ||
guid == ICastable::getTypeGuid() ||
guid == IArtifactRepresentation::getTypeGuid())
{
IArtifactRepresentation* rep = this;
return rep;
}
return nullptr;
}
void* DownstreamResultArtifactRepresentationAdapater_Dep1::getObject(const Guid& guid)
{
SLANG_UNUSED(guid);
return nullptr;
}
SlangResult DownstreamResultArtifactRepresentationAdapater_Dep1::createRepresentation(const Guid& typeGuid, ICastable** outCastable)
{
if (typeGuid == ISlangSharedLibrary::getTypeGuid())
{
ComPtr<ISlangSharedLibrary> lib;
SLANG_RETURN_ON_FAIL(DownstreamUtil_Dep1::getDownstreamSharedLibrary(m_result, lib));
*outCastable = lib.detach();
return SLANG_OK;
}
else if (typeGuid == ISlangBlob::getTypeGuid())
{
ComPtr<ISlangBlob> blob;
SLANG_RETURN_ON_FAIL(m_result->getBinary(blob));
*outCastable = CastableUtil::getCastable(blob).detach();
return SLANG_OK;
}
return SLANG_E_NOT_AVAILABLE;
}
/* !!!!!!!!!!!!!!!!!!!!!!!!! DownstreamCompilerAdapter_Dep1 !!!!!!!!!!!!!!!!!!!!!!!! */
SlangResult DownstreamCompilerAdapter_Dep1::compile(const CompileOptions& options, IArtifact** outArtifact)
{
RefPtr<DownstreamCompileResult_Dep1> result;
SLANG_RETURN_ON_FAIL(m_dep->compile(options, result));
typedef CharSliceCaster Caster;
ComPtr<IArtifact> artifact = ArtifactUtil::createArtifactForCompileTarget(options.targetType);
// Convert the diagnostics
auto dstDiagnostics = ArtifactDiagnostics::create();
const DownstreamDiagnostics_Dep1* srcDiagnostics = &result->getDiagnostics();
dstDiagnostics->setResult(srcDiagnostics->result);
dstDiagnostics->setRaw(Caster::asCharSlice(srcDiagnostics->rawDiagnostics));
for (const auto& srcDiagnostic : srcDiagnostics->diagnostics)
{
IArtifactDiagnostics::Diagnostic dstDiagnostic;
dstDiagnostic.severity = ArtifactDiagnostic::Severity(srcDiagnostic.severity);
dstDiagnostic.stage = ArtifactDiagnostic::Stage(srcDiagnostic.stage);
dstDiagnostic.code = Caster::asTerminatedCharSlice(srcDiagnostic.code);
dstDiagnostic.text = Caster::asTerminatedCharSlice(srcDiagnostic.text);
dstDiagnostic.filePath = Caster::asTerminatedCharSlice(srcDiagnostic.filePath);
dstDiagnostic.location.line = srcDiagnostic.fileLine;
}
artifact->addAssociated(dstDiagnostics);
// We need to add a representation that can produce shared libraries/blobs on demand
auto rep = new DownstreamResultArtifactRepresentationAdapater_Dep1(result);
artifact->addRepresentation(rep);
*outArtifact = artifact.detach();
return SLANG_OK;
}
/* !!!!!!!!!!!!!!!!!!!!!!!!! SharedLibraryDep1Adapter !!!!!!!!!!!!!!!!!!!!!!!! */
// A temporary class that adapts `ISlangSharedLibrary_Dep1` to ISlangSharedLibrary
class SharedLibraryAdapter_Dep1 : public ComBaseObject, public ISlangSharedLibrary
{
public:
SLANG_COM_BASE_IUNKNOWN_ALL
// ICastable
virtual SLANG_NO_THROW void* SLANG_MCALL castAs(const SlangUUID& guid) SLANG_OVERRIDE;
// ISlangSharedLibrary
virtual SLANG_NO_THROW void* SLANG_MCALL findSymbolAddressByName(char const* name) SLANG_OVERRIDE { return m_contained->findSymbolAddressByName(name); }
SharedLibraryAdapter_Dep1(ISlangSharedLibrary_Dep1* dep1) :
m_contained(dep1)
{
}
protected:
void* getInterface(const Guid& guid)
{
if (guid == ISlangUnknown::getTypeGuid() ||
guid == ICastable::getTypeGuid() ||
guid == ISlangSharedLibrary::getTypeGuid())
{
return static_cast<ISlangSharedLibrary*>(this);
}
return nullptr;
}
void* getObject(const Guid& guid)
{
SLANG_UNUSED(guid);
return nullptr;
}
ComPtr<ISlangSharedLibrary_Dep1> m_contained;
};
void* SharedLibraryAdapter_Dep1::castAs(const SlangUUID& guid)
{
if (auto intf = getInterface(guid))
{
return intf;
}
return getObject(guid);
}
/* Hack to take into account downstream compilers shared library interface might need an adapter */
/* static */SlangResult DownstreamUtil_Dep1::getDownstreamSharedLibrary(DownstreamCompileResult_Dep1* downstreamResult, ComPtr<ISlangSharedLibrary>& outSharedLibrary)
{
ComPtr<ISlangSharedLibrary> lib;
SLANG_RETURN_ON_FAIL(downstreamResult->getHostCallableSharedLibrary(lib));
if (SLANG_SUCCEEDED(lib->queryInterface(ISlangSharedLibrary::getTypeGuid(), (void**)outSharedLibrary.writeRef())))
{
return SLANG_OK;
}
ComPtr<ISlangSharedLibrary_Dep1> libDep1;
if (SLANG_SUCCEEDED(lib->queryInterface(ISlangSharedLibrary_Dep1::getTypeGuid(), (void**)libDep1.writeRef())))
{
// Okay, we need to adapt for now
outSharedLibrary = new SharedLibraryAdapter_Dep1(libDep1);
return SLANG_OK;
}
return SLANG_E_NOT_FOUND;
}
}
|