Adding a shared scratch arena for compiler passes.

This commit is contained in:
Ben Vanik 2014-02-08 22:01:51 -08:00
parent e6f3716d87
commit 6bd214af0b
4 changed files with 14 additions and 0 deletions

View File

@ -20,6 +20,8 @@ using namespace alloy::runtime;
Compiler::Compiler(Runtime* runtime) :
runtime_(runtime) {
scratch_arena_ = new Arena();
alloy::tracing::WriteEvent(EventType::Init({
}));
}
@ -32,6 +34,8 @@ Compiler::~Compiler() {
delete pass;
}
delete scratch_arena_;
alloy::tracing::WriteEvent(EventType::Deinit({
}));
}
@ -49,6 +53,7 @@ int Compiler::Compile(HIRBuilder* builder) {
// stop changing things, etc.
for (auto it = passes_.begin(); it != passes_.end(); ++it) {
CompilerPass* pass = *it;
scratch_arena_->Reset();
if (pass->Run(builder)) {
return 1;
}

View File

@ -28,6 +28,7 @@ public:
~Compiler();
runtime::Runtime* runtime() const { return runtime_; }
Arena* scratch_arena() const { return scratch_arena_; }
void AddPass(CompilerPass* pass);
@ -37,6 +38,7 @@ public:
private:
runtime::Runtime* runtime_;
Arena* scratch_arena_;
typedef std::vector<CompilerPass*> PassList;
PassList passes_;

View File

@ -27,3 +27,7 @@ int CompilerPass::Initialize(Compiler* compiler) {
compiler_ = compiler;
return 0;
}
Arena* CompilerPass::scratch_arena() const {
return compiler_->scratch_arena();
}

View File

@ -32,6 +32,9 @@ public:
virtual int Run(hir::HIRBuilder* builder) = 0;
protected:
Arena* scratch_arena() const;
protected:
runtime::Runtime* runtime_;
Compiler* compiler_;