From 6bd214af0bdbc3f3afe3459150da388f677eaa3c Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sat, 8 Feb 2014 22:01:51 -0800 Subject: [PATCH] Adding a shared scratch arena for compiler passes. --- src/alloy/compiler/compiler.cc | 5 +++++ src/alloy/compiler/compiler.h | 2 ++ src/alloy/compiler/compiler_pass.cc | 4 ++++ src/alloy/compiler/compiler_pass.h | 3 +++ 4 files changed, 14 insertions(+) diff --git a/src/alloy/compiler/compiler.cc b/src/alloy/compiler/compiler.cc index 07e786ade..a28f6b48b 100644 --- a/src/alloy/compiler/compiler.cc +++ b/src/alloy/compiler/compiler.cc @@ -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; } diff --git a/src/alloy/compiler/compiler.h b/src/alloy/compiler/compiler.h index ae6b48455..d2874cceb 100644 --- a/src/alloy/compiler/compiler.h +++ b/src/alloy/compiler/compiler.h @@ -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 PassList; PassList passes_; diff --git a/src/alloy/compiler/compiler_pass.cc b/src/alloy/compiler/compiler_pass.cc index 535bcb490..59f71902c 100644 --- a/src/alloy/compiler/compiler_pass.cc +++ b/src/alloy/compiler/compiler_pass.cc @@ -27,3 +27,7 @@ int CompilerPass::Initialize(Compiler* compiler) { compiler_ = compiler; return 0; } + +Arena* CompilerPass::scratch_arena() const { + return compiler_->scratch_arena(); +} diff --git a/src/alloy/compiler/compiler_pass.h b/src/alloy/compiler/compiler_pass.h index 1ed1b8144..4ba38b6c4 100644 --- a/src/alloy/compiler/compiler_pass.h +++ b/src/alloy/compiler/compiler_pass.h @@ -32,6 +32,9 @@ public: virtual int Run(hir::HIRBuilder* builder) = 0; +protected: + Arena* scratch_arena() const; + protected: runtime::Runtime* runtime_; Compiler* compiler_;