2013-12-07 07:57:16 +01:00
|
|
|
/**
|
|
|
|
|
******************************************************************************
|
|
|
|
|
* Xenia : Xbox 360 Emulator Research Project *
|
|
|
|
|
******************************************************************************
|
|
|
|
|
* Copyright 2013 Ben Vanik. All rights reserved. *
|
|
|
|
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
|
|
|
|
******************************************************************************
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <alloy/compiler/compiler.h>
|
|
|
|
|
|
2013-12-29 23:28:46 +01:00
|
|
|
#include <alloy/compiler/compiler_pass.h>
|
2013-12-07 07:57:16 +01:00
|
|
|
|
2014-07-11 05:20:00 +02:00
|
|
|
namespace alloy {
|
|
|
|
|
namespace compiler {
|
2013-12-07 07:57:16 +01:00
|
|
|
|
2014-07-11 05:20:00 +02:00
|
|
|
using alloy::hir::HIRBuilder;
|
|
|
|
|
using alloy::runtime::Runtime;
|
2013-12-07 07:57:16 +01:00
|
|
|
|
2014-07-14 06:53:31 +02:00
|
|
|
Compiler::Compiler(Runtime* runtime) : runtime_(runtime) {}
|
2013-12-29 23:28:46 +01:00
|
|
|
|
2014-07-14 06:53:31 +02:00
|
|
|
Compiler::~Compiler() { Reset(); }
|
2013-12-07 07:57:16 +01:00
|
|
|
|
2014-07-14 06:53:31 +02:00
|
|
|
void Compiler::AddPass(std::unique_ptr<CompilerPass> pass) {
|
2013-12-07 13:39:48 +01:00
|
|
|
pass->Initialize(this);
|
2014-07-14 06:53:31 +02:00
|
|
|
passes_.push_back(std::move(pass));
|
2013-12-07 07:57:16 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-11 05:20:00 +02:00
|
|
|
void Compiler::Reset() {}
|
2013-12-07 07:57:16 +01:00
|
|
|
|
2013-12-29 23:28:46 +01:00
|
|
|
int Compiler::Compile(HIRBuilder* builder) {
|
2014-05-29 04:19:39 +02:00
|
|
|
SCOPE_profile_cpu_f("alloy");
|
|
|
|
|
|
2013-12-07 07:57:16 +01:00
|
|
|
// TODO(benvanik): sophisticated stuff. Run passes in parallel, run until they
|
|
|
|
|
// stop changing things, etc.
|
2014-08-06 20:38:36 +02:00
|
|
|
for (size_t i = 0; i < passes_.size(); ++i) {
|
|
|
|
|
auto& pass = passes_[i];
|
2014-07-14 06:53:31 +02:00
|
|
|
scratch_arena_.Reset();
|
2013-12-07 10:36:13 +01:00
|
|
|
if (pass->Run(builder)) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2013-12-07 07:57:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2013-12-29 23:28:46 +01:00
|
|
|
}
|
2014-07-11 05:20:00 +02:00
|
|
|
|
|
|
|
|
} // namespace compiler
|
|
|
|
|
} // namespace alloy
|