Compiler::Compiler():
features(Features::from_context()),
- module(0)
+ module(0),
+ specialized(false)
{ }
Compiler::Compiler(const Features &f):
features(f),
- module(0)
+ module(0),
+ specialized(false)
{ }
Compiler::~Compiler()
load_source(io, 0, src_name);
}
+void Compiler::specialize(const map<string, int> &sv)
+{
+ specialized = true;
+ spec_values = sv;
+}
+
void Compiler::compile(Mode mode)
{
for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
inject_block(stage.content, module->shared.content);
DeclarationReorderer().apply(stage);
- BlockResolver().apply(stage);
+
+ // Initial resolving pass
+ BlockHierarchyResolver().apply(stage);
FunctionResolver().apply(stage);
VariableResolver().apply(stage);
+
+ /* All variables local to a stage have been resolved. Resolve non-local
+ variables through interfaces. */
InterfaceGenerator().apply(stage);
VariableResolver().apply(stage);
+
DeclarationReorderer().apply(stage);
FunctionResolver().apply(stage);
+ ConstantSpecializer().apply(stage, (mode==PROGRAM && specialized ? &spec_values : 0));
if(mode==PROGRAM)
LegacyConverter().apply(stage, features);
}
ConstantConditionEliminator().apply(stage);
FunctionInliner().apply(stage);
- BlockResolver().apply(stage);
+ BlockHierarchyResolver().apply(stage);
VariableResolver().apply(stage);
+ /* Removing variables or functions may cause things from the previous stage
+ to become unused. */
bool result = UnusedVariableRemover().apply(stage);
result |= UnusedFunctionRemover().apply(stage);