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
|
// slang-module-library.cpp
#include "slang-module-library.h"
#include <assert.h>
#include "../core/slang-blob.h"
#include "../core/slang-riff.h"
#include "../core/slang-type-text-util.h"
// Serialization
#include "slang-serialize-ir.h"
#include "slang-serialize-container.h"
namespace Slang {
SlangResult loadModuleLibrary(const Byte* inBytes, size_t bytesCount, EndToEndCompileRequest* req, RefPtr<ModuleLibrary>& outLibrary)
{
RefPtr<ModuleLibrary> library = new ModuleLibrary;
// Load up the module
MemoryStreamBase memoryStream(FileAccess::Read, inBytes, bytesCount);
RiffContainer riffContainer;
SLANG_RETURN_ON_FAIL(RiffUtil::read(&memoryStream, riffContainer));
auto linkage = req->getLinkage();
// TODO(JS): May be better to have a ITypeComponent that encapsulates a collection of modules
// For now just add to the linkage
{
SerialContainerData containerData;
SerialContainerUtil::ReadOptions options;
options.namePool = req->getNamePool();
options.session = req->getSession();
options.sharedASTBuilder = linkage->getASTBuilder()->getSharedASTBuilder();
options.sourceManager = linkage->getSourceManager();
options.linkage = req->getLinkage();
options.sink = req->getSink();
SLANG_RETURN_ON_FAIL(SerialContainerUtil::read(&riffContainer, options, containerData));
for (const auto& module : containerData.modules)
{
// If the irModule is set, add it
if (module.irModule)
{
library->m_modules.add(module.irModule);
}
}
for (const auto& entryPoint : containerData.entryPoints)
{
FrontEndCompileRequest::ExtraEntryPointInfo dst;
dst.mangledName = entryPoint.mangledName;
dst.name = entryPoint.name;
dst.profile = entryPoint.profile;
// Add entry point
library->m_entryPoints.add(dst);
}
}
outLibrary = library;
return SLANG_OK;
}
SlangResult loadModuleLibrary(ArtifactKeep keep, Artifact* product, EndToEndCompileRequest* req, RefPtr<ModuleLibrary>& outLibrary)
{
if (auto foundLibrary = product->findObjectInstance<ModuleLibrary>())
{
outLibrary = foundLibrary;
return SLANG_OK;
}
// Load the blob
ComPtr<ISlangBlob> blob;
SLANG_RETURN_ON_FAIL(product->loadBlob(getIntermediateKeep(keep), blob));
// Load the module
RefPtr<ModuleLibrary> library;
SLANG_RETURN_ON_FAIL(loadModuleLibrary((const Byte*)blob->getBufferPointer(), blob->getBufferSize(), req, library));
if (canKeep(keep))
{
product->add(Artifact::Entry::Style::Artifact, library);
}
outLibrary = library;
return SLANG_OK;
}
} // namespace Slang
|