#include <msp/strings/format.h>
#include <msp/strings/utils.h>
#include "builtin.h"
-#include "compatibility.h"
#include "compiler.h"
#include "debug.h"
#include "error.h"
+#include "finalize.h"
#include "generate.h"
#include "glsl_error.h"
#include "optimize.h"
#include "output.h"
+#include "resolve.h"
#include "resources.h"
#include "validate.h"
void Compiler::compile(Mode mode)
{
for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
- generate(*i, mode);
+ generate(*i);
+ ConstantIdAssigner().apply(*module, features);
bool valid = true;
for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
if(!valid)
throw invalid_shader_source(get_diagnostics());
- unsigned n = 0;
- for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++n)
+ if(mode==PROGRAM && specialized)
+ {
+ for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
+ ConstantSpecializer().apply(*i, spec_values);
+ }
+ for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); )
{
OptimizeResult result = optimize(*i);
if(result==REDO_PREVIOUS)
append_module(import_parser.parse(*io, fn, module->source_map.get_count()), resources);
}
-void Compiler::generate(Stage &stage, Mode mode)
+void Compiler::generate(Stage &stage)
{
stage.required_features.gl_api = features.gl_api;
if(module->shared.required_features.glsl_version>stage.required_features.glsl_version)
variables through interfaces. */
InterfaceGenerator().apply(stage);
resolve(stage, RESOLVE_BLOCKS|RESOLVE_TYPES|RESOLVE_VARIABLES);
-
- ConstantSpecializer().apply(stage, (mode==PROGRAM && specialized ? &spec_values : 0));
- if(mode==PROGRAM)
- {
- LegacyConverter().apply(stage, features);
- resolve(stage, RESOLVE_VARIABLES|RESOLVE_FUNCTIONS);
- }
}
template<typename T>
bool Compiler::validate(Stage &stage)
{
- TypeValidator().apply(stage);
+ DeclarationValidator().apply(stage);
IdentifierValidator().apply(stage);
ReferenceValidator().apply(stage);
ExpressionValidator().apply(stage);
void Compiler::finalize(Stage &stage, Mode mode)
{
- if(get_gl_api()==OPENGL_ES2 && mode==PROGRAM)
- DefaultPrecisionGenerator().apply(stage);
- else if(mode==MODULE)
- PrecisionRemover().apply(stage);
+ if(mode==PROGRAM)
+ {
+ LegacyConverter().apply(stage, features);
+ resolve(stage, RESOLVE_VARIABLES|RESOLVE_FUNCTIONS);
+ PrecisionConverter().apply(stage);
+ }
}
void Compiler::inject_block(Block &target, const Block &source)