#include <msp/strings/format.h>
#include "compatibility.h"
#include "compiler.h"
+#include "debug.h"
#include "error.h"
#include "generate.h"
#include "optimize.h"
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)
return module->source_map;
}
+string Compiler::get_stage_debug(Stage::Type stage_type) const
+{
+ for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
+ if(i->type==stage_type)
+ return DumpTree().apply(*i);
+ throw key_error(Stage::get_stage_name(stage_type));
+}
+
void Compiler::append_module(Module &mod, DataFile::Collection *res)
{
module->source_map.merge_from(mod.source_map);
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);