summaryrefslogtreecommitdiffstats
path: root/source/slang/emit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/emit.cpp')
-rw-r--r--source/slang/emit.cpp99
1 files changed, 41 insertions, 58 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index c0e5e4296..2603df11e 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -79,8 +79,10 @@ void requireGLSLVersionImpl(
// Shared state for an entire emit session
struct SharedEmitContext
{
+ BackEndCompileRequest* compileRequest = nullptr;
+
// The entry point we are being asked to compile
- EntryPointRequest* entryPoint;
+ EntryPoint* entryPoint;
// The layout for the entry point
EntryPointLayout* entryPointLayout;
@@ -153,7 +155,7 @@ struct SharedEmitContext
// to use for it when emitting code.
Dictionary<IRInst*, String> mapInstToName;
- DiagnosticSink* getSink() { return &entryPoint->compileRequest->mSink; }
+ DiagnosticSink* getSink() { return compileRequest->getSink(); }
Dictionary<IRInst*, UInt> mapIRValueToRayPayloadLocation;
Dictionary<IRInst*, UInt> mapIRValueToCallablePayloadLocation;
@@ -165,6 +167,10 @@ struct EmitContext
SharedEmitContext* shared;
DiagnosticSink* getSink() { return shared->getSink(); }
+
+ LineDirectiveMode getLineDirectiveMode() { return shared->compileRequest->getLineDirectiveMode(); }
+ SourceManager* getSourceManager() { return shared->compileRequest->getSourceManager(); }
+ void noteInternalErrorLoc(SourceLoc loc) { return getSink()->noteInternalErrorLoc(loc); }
};
//
@@ -334,11 +340,6 @@ struct EmitVisitor
: context(context)
{}
- Session* getSession()
- {
- return context->shared->entryPoint->compileRequest->mSession;
- }
-
// Low-level emit logic
void emitRawTextSpan(char const* textBegin, char const* textEnd)
@@ -556,7 +557,7 @@ struct EmitVisitor
bool shouldUseGLSLStyleLineDirective = false;
- auto mode = context->shared->entryPoint->compileRequest->lineDirectiveMode;
+ auto mode = context->getLineDirectiveMode();
switch (mode)
{
case LineDirectiveMode::None:
@@ -664,7 +665,7 @@ struct EmitVisitor
{
// Don't do any of this work if the user has requested that we
// not emit line directives.
- auto mode = context->shared->entryPoint->compileRequest->lineDirectiveMode;
+ auto mode = context->getLineDirectiveMode();
switch(mode)
{
case LineDirectiveMode::None:
@@ -723,7 +724,7 @@ struct EmitVisitor
SourceManager* getSourceManager()
{
- return context->shared->entryPoint->compileRequest->getSourceManager();
+ return context->getSourceManager();
}
void advanceToSourceLocation(
@@ -747,7 +748,7 @@ struct EmitVisitor
DiagnosticSink* getSink()
{
- return &context->shared->entryPoint->compileRequest->mSink;
+ return context->getSink();
}
//
@@ -1875,8 +1876,7 @@ struct EmitVisitor
}
}
- void emitGLSLVersionDirective(
- ModuleDecl* /*program*/)
+ void emitGLSLVersionDirective()
{
auto effectiveProfile = context->shared->effectiveProfile;
if(effectiveProfile.getFamily() == ProfileFamily::GLSL)
@@ -1931,8 +1931,7 @@ struct EmitVisitor
Emit("#version 420\n");
}
- void emitGLSLPreprocessorDirectives(
- RefPtr<ModuleDecl> program)
+ void emitGLSLPreprocessorDirectives()
{
switch(context->shared->target)
{
@@ -1944,24 +1943,7 @@ struct EmitVisitor
break;
}
- emitGLSLVersionDirective(program);
-
-
- // TODO: when cross-compiling we may need to output additional `#extension` directives
- // based on the features that we have used.
-
- for( auto extensionDirective : program->GetModifiersOfType<GLSLExtensionDirective>() )
- {
- // TODO(tfoley): Emit an appropriate `#line` directive...
-
- Emit("#extension ");
- emit(extensionDirective->extensionNameToken.Content);
- Emit(" : ");
- emit(extensionDirective->dispositionToken.Content);
- Emit("\n");
- }
-
- // TODO: handle other cases...
+ emitGLSLVersionDirective();
}
/// Emit directives to control overall layout computation for the emitted code.
@@ -4115,7 +4097,7 @@ struct EmitVisitor
catch(AbortCompilationException&) { throw; }
catch(...)
{
- ctx->shared->entryPoint->compileRequest->noteInternalErrorLoc(inst->sourceLoc);
+ ctx->noteInternalErrorLoc(inst->sourceLoc);
throw;
}
}
@@ -6583,26 +6565,26 @@ struct EmitVisitor
//
EntryPointLayout* findEntryPointLayout(
- ProgramLayout* programLayout,
- EntryPointRequest* entryPointRequest)
+ ProgramLayout* programLayout,
+ EntryPoint* entryPoint)
{
for( auto entryPointLayout : programLayout->entryPoints )
{
- if(entryPointLayout->entryPoint->getName() != entryPointRequest->name)
+ if(entryPointLayout->entryPoint->getName() != entryPoint->getName())
continue;
// TODO: We need to be careful about this check, since it relies on
// the profile information in the layout matching that in the request.
//
// What we really seem to want here is some dictionary mapping the
- // `EntryPointRequest` directly to the `EntryPointLayout`, and maybe
+ // `EntryPoint` directly to the `EntryPointLayout`, and maybe
// that is precisely what we should build...
//
- if(entryPointLayout->profile != entryPointRequest->profile)
+ if(entryPointLayout->profile != entryPoint->getProfile())
continue;
// TODO: can't easily filter on translation unit here...
- // Ideally the `EntryPointRequest` should get filled in with a pointer
+ // Ideally the `EntryPoint` should get filled in with a pointer
// the specific function declaration that represents the entry point.
return entryPointLayout.Ptr();
@@ -6662,13 +6644,14 @@ void legalizeTypes(
IRModule* module);
static void dumpIRIfEnabled(
- CompileRequest* compileRequest,
+ BackEndCompileRequest* compileRequest,
IRModule* irModule,
char const* label = nullptr)
{
if(compileRequest->shouldDumpIR)
{
- WriterHelper writer(compileRequest->getWriter(WriterChannel::StdError));
+ DiagnosticSinkWriter writerImpl(compileRequest->getSink());
+ WriterHelper writer(&writerImpl);
if(label)
{
@@ -6687,16 +6670,22 @@ static void dumpIRIfEnabled(
}
String emitEntryPoint(
- EntryPointRequest* entryPoint,
- ProgramLayout* programLayout,
- CodeGenTarget target,
- TargetRequest* targetRequest)
+ BackEndCompileRequest* compileRequest,
+ EntryPoint* entryPoint,
+ CodeGenTarget target,
+ TargetRequest* targetRequest)
{
- auto translationUnit = entryPoint->getTranslationUnit();
+ auto sink = compileRequest->getSink();
+ auto program = compileRequest->getProgram();
+ auto targetProgram = program->getTargetProgram(targetRequest);
+ auto programLayout = targetProgram->getOrCreateLayout(sink);
+
+// auto translationUnit = entryPoint->getTranslationUnit();
SharedEmitContext sharedContext;
+ sharedContext.compileRequest = compileRequest;
sharedContext.target = target;
- sharedContext.finalTarget = targetRequest->target;
+ sharedContext.finalTarget = targetRequest->getTarget();
sharedContext.entryPoint = entryPoint;
sharedContext.effectiveProfile = getEffectiveProfile(entryPoint, targetRequest);
@@ -6715,16 +6704,13 @@ String emitEntryPoint(
StructTypeLayout* globalStructLayout = getGlobalStructLayout(programLayout);
sharedContext.globalStructLayout = globalStructLayout;
- auto translationUnitSyntax = translationUnit->SyntaxNode.Ptr();
-
EmitContext context;
context.shared = &sharedContext;
EmitVisitor visitor(&context);
{
- auto compileRequest = translationUnit->compileRequest;
- auto session = compileRequest->mSession;
+ auto session = targetRequest->getSession();
// We start out by performing "linking" at the level of the IR.
// This step will create a fresh IR module to be used for
@@ -6735,6 +6721,7 @@ String emitEntryPoint(
// any "profile-overloaded" symbols.
//
auto linkedIR = linkIR(
+ compileRequest,
entryPoint,
programLayout,
target,
@@ -6880,7 +6867,7 @@ String emitEntryPoint(
session,
irModule,
irEntryPoint,
- &compileRequest->mSink,
+ compileRequest->getSink(),
&sharedContext.extensionUsageTracker);
}
break;
@@ -6916,10 +6903,6 @@ String emitEntryPoint(
// TODO: do we want to emit directly from IR, or translate the
// IR back into AST for emission?
visitor.emitIRModule(&context, irModule);
-
- // retain the specialized ir module, because the current
- // GlobalGenericParamSubstitution implementation may reference ir objects
- targetRequest->compileRequest->compiledModules.Add(irModule);
}
// Deal with cases where a particular stage requires certain GLSL versions
@@ -6950,7 +6933,7 @@ String emitEntryPoint(
// it is time to stich together the final output.
// There may be global-scope modifiers that we should emit now
- visitor.emitGLSLPreprocessorDirectives(translationUnitSyntax);
+ visitor.emitGLSLPreprocessorDirectives();
visitor.emitLayoutDirectives(targetRequest);