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
|
|
|
#include <alloy/compiler/tracing.h>
|
|
|
|
|
|
|
|
|
|
using namespace alloy;
|
|
|
|
|
using namespace alloy::compiler;
|
|
|
|
|
using namespace alloy::hir;
|
2013-12-07 13:39:48 +01:00
|
|
|
using namespace alloy::runtime;
|
2013-12-07 07:57:16 +01:00
|
|
|
|
|
|
|
|
|
2013-12-07 13:39:48 +01:00
|
|
|
Compiler::Compiler(Runtime* runtime) :
|
|
|
|
|
runtime_(runtime) {
|
2013-12-07 07:57:16 +01:00
|
|
|
alloy::tracing::WriteEvent(EventType::Init({
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Compiler::~Compiler() {
|
|
|
|
|
Reset();
|
2013-12-29 23:28:46 +01:00
|
|
|
|
|
|
|
|
for (auto it = passes_.begin(); it != passes_.end(); ++it) {
|
|
|
|
|
CompilerPass* pass = *it;
|
2013-12-07 07:57:16 +01:00
|
|
|
delete pass;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
alloy::tracing::WriteEvent(EventType::Deinit({
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-29 23:28:46 +01:00
|
|
|
void Compiler::AddPass(CompilerPass* pass) {
|
2013-12-07 13:39:48 +01:00
|
|
|
pass->Initialize(this);
|
2013-12-07 07:57:16 +01:00
|
|
|
passes_.push_back(pass);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Compiler::Reset() {
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-29 23:28:46 +01:00
|
|
|
int Compiler::Compile(HIRBuilder* builder) {
|
2013-12-07 07:57:16 +01:00
|
|
|
// TODO(benvanik): sophisticated stuff. Run passes in parallel, run until they
|
|
|
|
|
// stop changing things, etc.
|
2013-12-29 23:28:46 +01:00
|
|
|
for (auto it = passes_.begin(); it != passes_.end(); ++it) {
|
|
|
|
|
CompilerPass* pass = *it;
|
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
|
|
|
}
|