C++11ing some things.

This commit is contained in:
Ben Vanik
2014-07-13 21:53:31 -07:00
parent 29e4c35c38
commit 0a250d5e91
28 changed files with 113 additions and 143 deletions

View File

@@ -17,24 +17,13 @@ namespace compiler {
using alloy::hir::HIRBuilder;
using alloy::runtime::Runtime;
Compiler::Compiler(Runtime* runtime) : runtime_(runtime) {
scratch_arena_ = new Arena();
}
Compiler::Compiler(Runtime* runtime) : runtime_(runtime) {}
Compiler::~Compiler() {
Reset();
Compiler::~Compiler() { Reset(); }
for (auto it = passes_.begin(); it != passes_.end(); ++it) {
CompilerPass* pass = *it;
delete pass;
}
delete scratch_arena_;
}
void Compiler::AddPass(CompilerPass* pass) {
void Compiler::AddPass(std::unique_ptr<CompilerPass> pass) {
pass->Initialize(this);
passes_.push_back(pass);
passes_.push_back(std::move(pass));
}
void Compiler::Reset() {}
@@ -44,9 +33,8 @@ int Compiler::Compile(HIRBuilder* builder) {
// TODO(benvanik): sophisticated stuff. Run passes in parallel, run until they
// stop changing things, etc.
for (auto it = passes_.begin(); it != passes_.end(); ++it) {
CompilerPass* pass = *it;
scratch_arena_->Reset();
for (auto& pass : passes_) {
scratch_arena_.Reset();
if (pass->Run(builder)) {
return 1;
}

View File

@@ -10,6 +10,9 @@
#ifndef ALLOY_COMPILER_COMPILER_H_
#define ALLOY_COMPILER_COMPILER_H_
#include <memory>
#include <vector>
#include <alloy/core.h>
#include <alloy/hir/hir_builder.h>
@@ -30,9 +33,9 @@ class Compiler {
~Compiler();
runtime::Runtime* runtime() const { return runtime_; }
Arena* scratch_arena() const { return scratch_arena_; }
Arena* scratch_arena() { return &scratch_arena_; }
void AddPass(CompilerPass* pass);
void AddPass(std::unique_ptr<CompilerPass> pass);
void Reset();
@@ -40,10 +43,9 @@ class Compiler {
private:
runtime::Runtime* runtime_;
Arena* scratch_arena_;
Arena scratch_arena_;
typedef std::vector<CompilerPass*> PassList;
PassList passes_;
std::vector<std::unique_ptr<CompilerPass>> passes_;
};
} // namespace compiler

View File

@@ -16,7 +16,7 @@ namespace compiler {
CompilerPass::CompilerPass() : runtime_(0), compiler_(0) {}
CompilerPass::~CompilerPass() {}
CompilerPass::~CompilerPass() = default;
int CompilerPass::Initialize(Compiler* compiler) {
runtime_ = compiler->runtime();

View File

@@ -19,9 +19,9 @@ namespace passes {
class ConstantPropagationPass : public CompilerPass {
public:
ConstantPropagationPass();
virtual ~ConstantPropagationPass();
~ConstantPropagationPass() override;
virtual int Run(hir::HIRBuilder* builder);
int Run(hir::HIRBuilder* builder) override;
private:
void PropagateCarry(hir::Value* v, bool did_carry);

View File

@@ -19,11 +19,11 @@ namespace passes {
class ContextPromotionPass : public CompilerPass {
public:
ContextPromotionPass();
virtual ~ContextPromotionPass();
virtual ~ContextPromotionPass() override;
virtual int Initialize(Compiler* compiler);
int Initialize(Compiler* compiler) override;
virtual int Run(hir::HIRBuilder* builder);
int Run(hir::HIRBuilder* builder) override;
private:
void PromoteBlock(hir::Block* block);

View File

@@ -19,9 +19,9 @@ namespace passes {
class ControlFlowAnalysisPass : public CompilerPass {
public:
ControlFlowAnalysisPass();
virtual ~ControlFlowAnalysisPass();
~ControlFlowAnalysisPass() override;
virtual int Run(hir::HIRBuilder* builder);
int Run(hir::HIRBuilder* builder) override;
private:
};

View File

@@ -21,9 +21,9 @@ namespace passes {
class DataFlowAnalysisPass : public CompilerPass {
public:
DataFlowAnalysisPass();
virtual ~DataFlowAnalysisPass();
~DataFlowAnalysisPass() override;
virtual int Run(hir::HIRBuilder* builder);
int Run(hir::HIRBuilder* builder) override;
private:
uint32_t LinearizeBlocks(hir::HIRBuilder* builder);

View File

@@ -21,9 +21,9 @@ namespace passes {
class DeadCodeEliminationPass : public CompilerPass {
public:
DeadCodeEliminationPass();
virtual ~DeadCodeEliminationPass();
~DeadCodeEliminationPass() override;
virtual int Run(hir::HIRBuilder* builder);
int Run(hir::HIRBuilder* builder) override;
private:
void MakeNopRecursive(hir::Instr* i);

View File

@@ -19,9 +19,9 @@ namespace passes {
class FinalizationPass : public CompilerPass {
public:
FinalizationPass();
virtual ~FinalizationPass();
~FinalizationPass() override;
virtual int Run(hir::HIRBuilder* builder);
int Run(hir::HIRBuilder* builder) override;
private:
};

View File

@@ -24,9 +24,9 @@ namespace passes {
class RegisterAllocationPass : public CompilerPass {
public:
RegisterAllocationPass(const backend::MachineInfo* machine_info);
virtual ~RegisterAllocationPass();
~RegisterAllocationPass() override;
virtual int Run(hir::HIRBuilder* builder);
int Run(hir::HIRBuilder* builder) override;
private:
// TODO(benvanik): rewrite all this set shit -- too much indirection, the

View File

@@ -19,9 +19,9 @@ namespace passes {
class SimplificationPass : public CompilerPass {
public:
SimplificationPass();
virtual ~SimplificationPass();
~SimplificationPass() override;
virtual int Run(hir::HIRBuilder* builder);
int Run(hir::HIRBuilder* builder) override;
private:
void EliminateConversions(hir::HIRBuilder* builder);

View File

@@ -19,9 +19,9 @@ namespace passes {
class ValidationPass : public CompilerPass {
public:
ValidationPass();
virtual ~ValidationPass();
~ValidationPass() override;
virtual int Run(hir::HIRBuilder* builder);
int Run(hir::HIRBuilder* builder) override;
private:
int ValidateInstruction(hir::Block* block, hir::Instr* instr);

View File

@@ -19,9 +19,9 @@ namespace passes {
class ValueReductionPass : public CompilerPass {
public:
ValueReductionPass();
virtual ~ValueReductionPass();
~ValueReductionPass() override;
virtual int Run(hir::HIRBuilder* builder);
int Run(hir::HIRBuilder* builder) override;
private:
void ComputeLastUse(hir::Value* value);