8
8
9
9
namespace Slang
10
10
{
11
- SLANG_NO_THROW SlangResult SLANG_MCALL Module::precompileForTargets (
12
- DiagnosticSink* sink,
13
- EndToEndCompileRequest* endToEndReq,
14
- TargetRequest* targetReq)
11
+ SLANG_NO_THROW SlangResult SLANG_MCALL Module::precompileForTarget (
12
+ SlangCompileTarget target,
13
+ slang::IBlob** outDiagnostics)
15
14
{
16
- auto module = getIRModule ();
17
- Slang::Session* session = endToEndReq->getSession ();
18
- Slang::ASTBuilder* astBuilder = session->getGlobalASTBuilder ();
19
- Slang::Linkage* builtinLinkage = session->getBuiltinLinkage ();
20
- Slang::Linkage linkage (session, astBuilder, builtinLinkage);
21
-
22
- CapabilityName precompileRequirement = CapabilityName::Invalid;
23
- switch (targetReq->getTarget ())
15
+ if (target != SLANG_DXIL)
24
16
{
25
- case CodeGenTarget::DXIL:
26
- linkage.addTarget (Slang::CodeGenTarget::DXIL);
27
- precompileRequirement = CapabilityName::dxil_lib;
28
- break ;
29
- default :
30
- assert (!" Unhandled target" );
31
- break ;
17
+ return SLANG_FAIL;
32
18
}
33
- SLANG_ASSERT (precompileRequirement != CapabilityName::Invalid );
19
+ CodeGenTarget targetEnum = CodeGenTarget (target );
34
20
35
- // Ensure precompilation capability requirements are met.
36
- auto targetCaps = targetReq->getTargetCaps ();
37
- auto precompileRequirementsCapabilitySet = CapabilitySet (precompileRequirement);
38
- if (targetCaps.atLeastOneSetImpliedInOther (precompileRequirementsCapabilitySet) == CapabilitySet::ImpliesReturnFlags::NotImplied)
39
- {
40
- // If `RestrictiveCapabilityCheck` is true we will error, else we will warn.
41
- // error ...: dxil libraries require $0, entry point compiled with $1.
42
- // warn ...: dxil libraries require $0, entry point compiled with $1, implicitly upgrading capabilities.
43
- maybeDiagnoseWarningOrError (
44
- sink,
45
- targetReq->getOptionSet (),
46
- DiagnosticCategory::Capability,
47
- SourceLoc (),
48
- Diagnostics::incompatibleWithPrecompileLib,
49
- Diagnostics::incompatibleWithPrecompileLibRestrictive,
50
- precompileRequirementsCapabilitySet,
51
- targetCaps);
52
-
53
- // add precompile requirements to the cooked targetCaps
54
- targetCaps.join (precompileRequirementsCapabilitySet);
55
- if (targetCaps.isInvalid ())
56
- {
57
- sink->diagnose (SourceLoc (), Diagnostics::unknownCapability, targetCaps);
58
- return SLANG_FAIL;
59
- }
60
- else
61
- {
62
- targetReq->setTargetCaps (targetCaps);
63
- }
64
- }
21
+ auto module = getIRModule ();
22
+ auto linkage = getLinkage ();
23
+
24
+ DiagnosticSink sink (linkage->getSourceManager (), Lexer::sourceLocationLexer);
25
+ applySettingsToDiagnosticSink (&sink, &sink, linkage->m_optionSet );
26
+ applySettingsToDiagnosticSink (&sink, &sink, m_optionSet);
27
+
28
+ TargetRequest* targetReq = new TargetRequest (linkage, targetEnum);
65
29
66
30
List<RefPtr<ComponentType>> allComponentTypes;
67
31
allComponentTypes.add (this ); // Add Module as a component type
@@ -72,23 +36,34 @@ namespace Slang
72
36
}
73
37
74
38
auto composite = CompositeComponentType::create (
75
- & linkage,
39
+ linkage,
76
40
allComponentTypes);
77
41
78
42
TargetProgram tp (composite, targetReq);
79
- tp.getOrCreateLayout (sink);
43
+ tp.getOrCreateLayout (& sink);
80
44
Slang::Index const entryPointCount = m_entryPoints.getCount ();
45
+ tp.getOptionSet ().add (CompilerOptionName::GenerateWholeProgram, true );
46
+
47
+ switch (targetReq->getTarget ())
48
+ {
49
+ case CodeGenTarget::DXIL:
50
+ tp.getOptionSet ().add (CompilerOptionName::Profile, Profile::RawEnum::DX_Lib_6_6);
51
+ break ;
52
+ }
81
53
82
54
CodeGenContext::EntryPointIndices entryPointIndices;
83
55
84
56
entryPointIndices.setCount (entryPointCount);
85
57
for (Index i = 0 ; i < entryPointCount; i++)
86
58
entryPointIndices[i] = i;
87
- CodeGenContext::Shared sharedCodeGenContext (&tp, entryPointIndices, sink, endToEndReq );
59
+ CodeGenContext::Shared sharedCodeGenContext (&tp, entryPointIndices, & sink, nullptr );
88
60
CodeGenContext codeGenContext (&sharedCodeGenContext);
89
61
90
62
ComPtr<IArtifact> outArtifact;
91
63
SlangResult res = codeGenContext.emitTranslationUnit (outArtifact);
64
+
65
+ sink.getBlobIfNeeded (outDiagnostics);
66
+
92
67
if (res != SLANG_OK)
93
68
{
94
69
return res;
@@ -105,9 +80,6 @@ namespace Slang
105
80
case CodeGenTarget::DXIL:
106
81
builder.emitEmbeddedDXIL (blob);
107
82
break ;
108
- default :
109
- assert (!" Unhandled target" );
110
- break ;
111
83
}
112
84
113
85
return SLANG_OK;
0 commit comments