More X64 backend skeleton work.
This commit is contained in:
parent
3d01efffac
commit
dec0e35957
|
@ -10,9 +10,9 @@
|
|||
#include <alloy/backend/ivm/ivm_assembler.h>
|
||||
|
||||
#include <alloy/backend/backend.h>
|
||||
#include <alloy/backend/tracing.h>
|
||||
#include <alloy/backend/ivm/ivm_intcode.h>
|
||||
#include <alloy/backend/ivm/ivm_function.h>
|
||||
#include <alloy/backend/ivm/tracing.h>
|
||||
#include <alloy/hir/hir_builder.h>
|
||||
#include <alloy/hir/label.h>
|
||||
#include <alloy/runtime/runtime.h>
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
|
||||
#include <alloy/backend/ivm/ivm_backend.h>
|
||||
|
||||
#include <alloy/backend/tracing.h>
|
||||
#include <alloy/backend/ivm/ivm_assembler.h>
|
||||
#include <alloy/backend/ivm/tracing.h>
|
||||
|
||||
using namespace alloy;
|
||||
using namespace alloy::backend;
|
||||
|
|
|
@ -9,5 +9,6 @@
|
|||
'ivm_backend.h',
|
||||
'ivm_function.cc',
|
||||
'ivm_function.h',
|
||||
'tracing.h',
|
||||
],
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_BACKEND_IVM_TRACING_H_
|
||||
#define ALLOY_BACKEND_IVM_TRACING_H_
|
||||
|
||||
#include <alloy/backend/tracing.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace backend {
|
||||
namespace ivm {
|
||||
|
||||
const uint32_t ALLOY_BACKEND_IVM =
|
||||
alloy::backend::EventType::ALLOY_BACKEND_IVM;
|
||||
|
||||
|
||||
class EventType {
|
||||
public:
|
||||
enum {
|
||||
ALLOY_BACKEND_IVM_INIT = ALLOY_BACKEND_IVM | (1),
|
||||
ALLOY_BACKEND_IVM_DEINIT = ALLOY_BACKEND_IVM | (2),
|
||||
|
||||
ALLOY_BACKEND_IVM_ASSEMBLER = ALLOY_BACKEND_IVM | (1 << 20),
|
||||
ALLOY_BACKEND_IVM_ASSEMBLER_INIT = ALLOY_BACKEND_IVM_ASSEMBLER | (1),
|
||||
ALLOY_BACKEND_IVM_ASSEMBLER_DEINIT = ALLOY_BACKEND_IVM_ASSEMBLER | (2),
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
static const uint32_t event_type = ALLOY_BACKEND_IVM_INIT;
|
||||
} Init;
|
||||
typedef struct {
|
||||
static const uint32_t event_type = ALLOY_BACKEND_IVM_DEINIT;
|
||||
} Deinit;
|
||||
|
||||
typedef struct {
|
||||
static const uint32_t event_type = ALLOY_BACKEND_IVM_ASSEMBLER_INIT;
|
||||
} AssemblerInit;
|
||||
typedef struct {
|
||||
static const uint32_t event_type = ALLOY_BACKEND_IVM_ASSEMBLER_DEINIT;
|
||||
} AssemblerDeinit;
|
||||
};
|
||||
|
||||
|
||||
} // namespace ivm
|
||||
} // namespace backend
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_BACKEND_IVM_TRACING_H_
|
|
@ -23,27 +23,9 @@ const uint32_t ALLOY_BACKEND = alloy::tracing::EventType::ALLOY_BACKEND;
|
|||
class EventType {
|
||||
public:
|
||||
enum {
|
||||
ALLOY_BACKEND_INIT = ALLOY_BACKEND | (1),
|
||||
ALLOY_BACKEND_DEINIT = ALLOY_BACKEND | (2),
|
||||
|
||||
ALLOY_BACKEND_ASSEMBLER = ALLOY_BACKEND | (1 << 25),
|
||||
ALLOY_BACKEND_ASSEMBLER_INIT = ALLOY_BACKEND_ASSEMBLER | (1),
|
||||
ALLOY_BACKEND_ASSEMBLER_DEINIT = ALLOY_BACKEND_ASSEMBLER | (2),
|
||||
ALLOY_BACKEND_IVM = ALLOY_BACKEND | (1 << 24),
|
||||
ALLOY_BACKEND_X64 = ALLOY_BACKEND | (2 << 24),
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
static const uint32_t event_type = ALLOY_BACKEND_INIT;
|
||||
} Init;
|
||||
typedef struct {
|
||||
static const uint32_t event_type = ALLOY_BACKEND_DEINIT;
|
||||
} Deinit;
|
||||
|
||||
typedef struct {
|
||||
static const uint32_t event_type = ALLOY_BACKEND_ASSEMBLER_INIT;
|
||||
} AssemblerInit;
|
||||
typedef struct {
|
||||
static const uint32_t event_type = ALLOY_BACKEND_ASSEMBLER_DEINIT;
|
||||
} AssemblerDeinit;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_BACKEND_X64_LIR_LIR_BUILDER_H_
|
||||
#define ALLOY_BACKEND_X64_LIR_LIR_BUILDER_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
#include <alloy/backend/x64/lir/lir_opcodes.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace backend {
|
||||
namespace x64 {
|
||||
namespace lir {
|
||||
|
||||
|
||||
class LIRBuilder {
|
||||
public:
|
||||
LIRBuilder();
|
||||
virtual ~LIRBuilder();
|
||||
|
||||
virtual void Reset();
|
||||
virtual int Finalize();
|
||||
|
||||
void Dump(StringBuffer* str);
|
||||
|
||||
Arena* arena() const { return arena_; }
|
||||
|
||||
protected:
|
||||
Arena* arena_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace lir
|
||||
} // namespace x64
|
||||
} // namespace backend
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_BACKEND_X64_LIR_LIR_BUILDER_H_
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_BACKEND_X64_LIR_LIR_INSTR_H_
|
||||
#define ALLOY_BACKEND_X64_LIR_LIR_INSTR_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
#include <alloy/backend/x64/lir/lir_opcodes.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace backend {
|
||||
namespace x64 {
|
||||
namespace lir {
|
||||
|
||||
|
||||
class LIRInstr {
|
||||
public:
|
||||
};
|
||||
|
||||
|
||||
} // namespace lir
|
||||
} // namespace x64
|
||||
} // namespace backend
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_BACKEND_X64_LIR_LIR_INSTR_H_
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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/backend/x64/lir/lir_opcodes.h>
|
||||
|
||||
using namespace alloy;
|
||||
using namespace alloy::backend::x64::lir;
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace backend {
|
||||
namespace x64 {
|
||||
namespace lir {
|
||||
|
||||
#define DEFINE_OPCODE(num, name, sig, flags) \
|
||||
static const LIROpcodeInfo num##_info = { flags, sig, name, num, };
|
||||
#include <alloy/backend/x64/lir/lir_opcodes.inl>
|
||||
#undef DEFINE_OPCODE
|
||||
|
||||
} // namespace lir
|
||||
} // namespace x64
|
||||
} // namespace backend
|
||||
} // namespace alloy
|
|
@ -0,0 +1,71 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_BACKEND_X64_LIR_LIR_OPCODES_H_
|
||||
#define ALLOY_BACKEND_X64_LIR_LIR_OPCODES_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace backend {
|
||||
namespace x64 {
|
||||
namespace lir {
|
||||
|
||||
|
||||
enum LIROpcode {
|
||||
LIR_OPCODE_MOV_I32,
|
||||
|
||||
__LIR_OPCODE_MAX_VALUE, // Keep at end.
|
||||
};
|
||||
|
||||
enum LIROpcodeFlags {
|
||||
LIR_OPCODE_FLAG_BRANCH = (1 << 1),
|
||||
LIR_OPCODE_FLAG_MEMORY = (1 << 2),
|
||||
LIR_OPCODE_FLAG_COMMUNATIVE = (1 << 3),
|
||||
LIR_OPCODE_FLAG_VOLATILE = (1 << 4),
|
||||
LIR_OPCODE_FLAG_IGNORE = (1 << 5),
|
||||
LIR_OPCODE_FLAG_HIDE = (1 << 6),
|
||||
};
|
||||
|
||||
enum LIROpcodeSignatureType {
|
||||
// 3 bits max (0-7)
|
||||
LIR_OPCODE_SIG_TYPE_X = 0,
|
||||
};
|
||||
|
||||
enum LIROpcodeSignature {
|
||||
LIR_OPCODE_SIG_X = (LIR_OPCODE_SIG_TYPE_X),
|
||||
};
|
||||
|
||||
#define GET_LIR_OPCODE_SIG_TYPE_DEST(sig) (LIROpcodeSignatureType)(sig & 0x7)
|
||||
#define GET_LIR_OPCODE_SIG_TYPE_SRC1(sig) (LIROpcodeSignatureType)((sig >> 3) & 0x7)
|
||||
#define GET_LIR_OPCODE_SIG_TYPE_SRC2(sig) (LIROpcodeSignatureType)((sig >> 6) & 0x7)
|
||||
#define GET_LIR_OPCODE_SIG_TYPE_SRC3(sig) (LIROpcodeSignatureType)((sig >> 9) & 0x7)
|
||||
|
||||
typedef struct {
|
||||
uint32_t flags;
|
||||
uint32_t signature;
|
||||
const char* name;
|
||||
LIROpcode num;
|
||||
} LIROpcodeInfo;
|
||||
|
||||
|
||||
#define DEFINE_OPCODE(num, name, sig, flags) \
|
||||
extern const LIROpcodeInfo num##_info;
|
||||
#include <alloy/backend/x64/lir/lir_opcodes.inl>
|
||||
#undef DEFINE_OPCODE
|
||||
|
||||
|
||||
} // namespace lir
|
||||
} // namespace x64
|
||||
} // namespace backend
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_BACKEND_X64_LIR_LIR_OPCODES_H_
|
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
DEFINE_OPCODE(
|
||||
LIR_OPCODE_MOV_I32,
|
||||
"mov.i32",
|
||||
LIR_OPCODE_SIG_X,
|
||||
0);
|
|
@ -4,9 +4,9 @@
|
|||
'lir_builder.cc',
|
||||
'lir_builder.h',
|
||||
'lir_instr.h',
|
||||
'lircodes.cc',
|
||||
'lircodes.h',
|
||||
'lircodes.inl',
|
||||
'lir_opcodes.cc',
|
||||
'lir_opcodes.h',
|
||||
'lir_opcodes.inl',
|
||||
'tracing.h',
|
||||
],
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_BACKEND_X64_LIR_TRACING_H_
|
||||
#define ALLOY_BACKEND_X64_LIR_TRACING_H_
|
||||
|
||||
#include <alloy/backend/x64/tracing.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace backend {
|
||||
namespace x64 {
|
||||
namespace lir {
|
||||
|
||||
const uint32_t ALLOY_BACKEND_X64_LIR =
|
||||
alloy::backend::x64::EventType::ALLOY_BACKEND_X64_LIR;
|
||||
|
||||
|
||||
class EventType {
|
||||
public:
|
||||
enum {
|
||||
ALLOY_BACKEND_X64_LIR_FOO = ALLOY_BACKEND_X64_LIR | (1),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
} // namespace lir
|
||||
} // namespace x64
|
||||
} // namespace backend
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_BACKEND_X64_LIR_TRACING_H_
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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/backend/x64/optimizer/optimizer.h>
|
||||
|
||||
#include <alloy/backend/x64/tracing.h>
|
||||
#include <alloy/backend/x64/optimizer/optimizer_pass.h>
|
||||
|
||||
using namespace alloy;
|
||||
using namespace alloy::backend::x64::lir;
|
||||
using namespace alloy::backend::x64::optimizer;
|
||||
using namespace alloy::runtime;
|
||||
|
||||
|
||||
Optimizer::Optimizer(Runtime* runtime) :
|
||||
runtime_(runtime) {
|
||||
alloy::tracing::WriteEvent(EventType::Init({
|
||||
}));
|
||||
}
|
||||
|
||||
Optimizer::~Optimizer() {
|
||||
Reset();
|
||||
|
||||
for (auto it = passes_.begin(); it != passes_.end(); ++it) {
|
||||
OptimizerPass* pass = *it;
|
||||
delete pass;
|
||||
}
|
||||
|
||||
alloy::tracing::WriteEvent(EventType::Deinit({
|
||||
}));
|
||||
}
|
||||
|
||||
void Optimizer::AddPass(OptimizerPass* pass) {
|
||||
pass->Initialize(this);
|
||||
passes_.push_back(pass);
|
||||
}
|
||||
|
||||
void Optimizer::Reset() {
|
||||
}
|
||||
|
||||
int Optimizer::Optimize(LIRBuilder* 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) {
|
||||
OptimizerPass* pass = *it;
|
||||
if (pass->Run(builder)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_BACKEND_X64_OPTIMIZER_OPTIMIZER_H_
|
||||
#define ALLOY_BACKEND_X64_OPTIMIZER_OPTIMIZER_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
#include <alloy/backend/x64/lir/lir_builder.h>
|
||||
|
||||
namespace alloy { namespace runtime { class Runtime; } }
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace backend {
|
||||
namespace x64 {
|
||||
namespace optimizer {
|
||||
|
||||
class OptimizerPass;
|
||||
|
||||
|
||||
class Optimizer {
|
||||
public:
|
||||
Optimizer(runtime::Runtime* runtime);
|
||||
~Optimizer();
|
||||
|
||||
runtime::Runtime* runtime() const { return runtime_; }
|
||||
|
||||
void AddPass(OptimizerPass* pass);
|
||||
|
||||
void Reset();
|
||||
|
||||
int Optimize(lir::LIRBuilder* builder);
|
||||
|
||||
private:
|
||||
runtime::Runtime* runtime_;
|
||||
|
||||
typedef std::vector<OptimizerPass*> PassList;
|
||||
PassList passes_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace optimizer
|
||||
} // namespace x64
|
||||
} // namespace backend
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_BACKEND_X64_OPTIMIZER_OPTIMIZER_H_
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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/backend/x64/optimizer/optimizer_pass.h>
|
||||
|
||||
#include <alloy/backend/x64/optimizer/optimizer.h>
|
||||
|
||||
using namespace alloy;
|
||||
using namespace alloy::backend::x64::optimizer;
|
||||
|
||||
|
||||
OptimizerPass::OptimizerPass() :
|
||||
runtime_(0), optimizer_(0) {
|
||||
}
|
||||
|
||||
OptimizerPass::~OptimizerPass() {
|
||||
}
|
||||
|
||||
int OptimizerPass::Initialize(Optimizer* optimizer) {
|
||||
runtime_ = optimizer->runtime();
|
||||
optimizer_ = optimizer;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_BACKEND_X64_OPTIMIZER_OPTIMIZER_PASS_H_
|
||||
#define ALLOY_BACKEND_X64_OPTIMIZER_OPTIMIZER_PASS_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
|
||||
#include <alloy/backend/x64/lir/lir_builder.h>
|
||||
|
||||
namespace alloy { namespace runtime { class Runtime; } }
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace backend {
|
||||
namespace x64 {
|
||||
namespace optimizer {
|
||||
|
||||
class Optimizer;
|
||||
|
||||
|
||||
class OptimizerPass {
|
||||
public:
|
||||
OptimizerPass();
|
||||
virtual ~OptimizerPass();
|
||||
|
||||
virtual int Initialize(Optimizer* optimizer);
|
||||
|
||||
virtual int Run(lir::LIRBuilder* builder) = 0;
|
||||
|
||||
protected:
|
||||
runtime::Runtime* runtime_;
|
||||
Optimizer* optimizer_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace optimizer
|
||||
} // namespace x64
|
||||
} // namespace backend
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_BACKEND_X64_OPTIMIZER_OPTIMIZER_PASS_H_
|
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_BACKEND_X64_OPTIMIZER_PASSES_H_
|
||||
#define ALLOY_BACKEND_X64_OPTIMIZER_PASSES_H_
|
||||
|
||||
#include <alloy/backend/x64/optimizer/passes/redundant_mov_pass.h>
|
||||
|
||||
#endif // ALLOY_BACKEND_X64_OPTIMIZER_PASSES_H_
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_COMPILER_PASSES_SIMPLIFICATION_PASS_H_
|
||||
#define ALLOY_COMPILER_PASSES_SIMPLIFICATION_PASS_H_
|
||||
|
||||
#include <alloy/backend/x64/optimizer/optimizer_pass.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace backend {
|
||||
namespace x64 {
|
||||
namespace optimizer {
|
||||
namespace passes {
|
||||
|
||||
|
||||
class RedundantMovPass : public OptimizerPass {
|
||||
public:
|
||||
RedundantMovPass();
|
||||
virtual ~RedundantMovPass();
|
||||
|
||||
virtual int Run(lir::LIRBuilder* builder);
|
||||
};
|
||||
|
||||
|
||||
} // namespace passes
|
||||
} // namespace optimizer
|
||||
} // namespace x64
|
||||
} // namespace backend
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_COMPILER_PASSES_SIMPLIFICATION_PASS_H_
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_BACKEND_X64_OPTIMIZER_TRACING_H_
|
||||
#define ALLOY_BACKEND_X64_OPTIMIZER_TRACING_H_
|
||||
|
||||
#include <alloy/backend/x64/tracing.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace backend {
|
||||
namespace x64 {
|
||||
namespace optimizer {
|
||||
|
||||
const uint32_t ALLOY_BACKEND_X64_OPTIMIZER =
|
||||
alloy::backend::x64::EventType::ALLOY_BACKEND_X64_OPTIMIZER;
|
||||
|
||||
|
||||
class EventType {
|
||||
public:
|
||||
enum {
|
||||
ALLOY_BACKEND_X64_OPTIMIZER_INIT = ALLOY_BACKEND_X64_OPTIMIZER | (1),
|
||||
ALLOY_BACKEND_X64_OPTIMIZER_DEINIT = ALLOY_BACKEND_X64_OPTIMIZER | (2),
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
static const uint32_t event_type = ALLOY_BACKEND_X64_OPTIMIZER_INIT;
|
||||
} Init;
|
||||
typedef struct {
|
||||
static const uint32_t event_type = ALLOY_BACKEND_X64_OPTIMIZER_DEINIT;
|
||||
} Deinit;
|
||||
};
|
||||
|
||||
|
||||
} // namespace optimizer
|
||||
} // namespace x64
|
||||
} // namespace backend
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_BACKEND_X64_OPTIMIZER_TRACING_H_
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_BACKEND_X64_TRACING_H_
|
||||
#define ALLOY_BACKEND_X64_TRACING_H_
|
||||
|
||||
#include <alloy/backend/tracing.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace backend {
|
||||
namespace x64 {
|
||||
|
||||
const uint32_t ALLOY_BACKEND_X64 =
|
||||
alloy::backend::EventType::ALLOY_BACKEND_X64;
|
||||
|
||||
|
||||
class EventType {
|
||||
public:
|
||||
enum {
|
||||
ALLOY_BACKEND_X64_INIT = ALLOY_BACKEND_X64 | (1),
|
||||
ALLOY_BACKEND_X64_DEINIT = ALLOY_BACKEND_X64 | (2),
|
||||
|
||||
ALLOY_BACKEND_X64_ASSEMBLER = ALLOY_BACKEND_X64 | (1 << 20),
|
||||
ALLOY_BACKEND_X64_ASSEMBLER_INIT = ALLOY_BACKEND_X64_ASSEMBLER | (1),
|
||||
ALLOY_BACKEND_X64_ASSEMBLER_DEINIT = ALLOY_BACKEND_X64_ASSEMBLER | (2),
|
||||
|
||||
ALLOY_BACKEND_X64_LIR = ALLOY_BACKEND_X64 | (2 << 20),
|
||||
ALLOY_BACKEND_X64_OPTIMIZER = ALLOY_BACKEND_X64 | (3 << 20),
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
static const uint32_t event_type = ALLOY_BACKEND_X64_INIT;
|
||||
} Init;
|
||||
typedef struct {
|
||||
static const uint32_t event_type = ALLOY_BACKEND_X64_DEINIT;
|
||||
} Deinit;
|
||||
|
||||
typedef struct {
|
||||
static const uint32_t event_type = ALLOY_BACKEND_X64_ASSEMBLER_INIT;
|
||||
} AssemblerInit;
|
||||
typedef struct {
|
||||
static const uint32_t event_type = ALLOY_BACKEND_X64_ASSEMBLER_DEINIT;
|
||||
} AssemblerDeinit;
|
||||
};
|
||||
|
||||
|
||||
} // namespace x64
|
||||
} // namespace backend
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_BACKEND_X64_TRACING_H_
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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/backend/x64/x64_assembler.h>
|
||||
|
||||
#include <alloy/backend/x64/tracing.h>
|
||||
#include <alloy/backend/x64/x64_backend.h>
|
||||
#include <alloy/backend/x64/x64_function.h>
|
||||
#include <alloy/hir/hir_builder.h>
|
||||
#include <alloy/hir/label.h>
|
||||
#include <alloy/runtime/runtime.h>
|
||||
|
||||
using namespace alloy;
|
||||
using namespace alloy::backend;
|
||||
using namespace alloy::backend::x64;
|
||||
using namespace alloy::hir;
|
||||
using namespace alloy::runtime;
|
||||
|
||||
|
||||
X64Assembler::X64Assembler(X64Backend* backend) :
|
||||
Assembler(backend) {
|
||||
}
|
||||
|
||||
X64Assembler::~X64Assembler() {
|
||||
alloy::tracing::WriteEvent(EventType::AssemblerDeinit({
|
||||
}));
|
||||
}
|
||||
|
||||
int X64Assembler::Initialize() {
|
||||
int result = Assembler::Initialize();
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
alloy::tracing::WriteEvent(EventType::AssemblerInit({
|
||||
}));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void X64Assembler::Reset() {
|
||||
Assembler::Reset();
|
||||
}
|
||||
|
||||
int X64Assembler::Assemble(
|
||||
FunctionInfo* symbol_info, HIRBuilder* builder,
|
||||
DebugInfo* debug_info, Function** out_function) {
|
||||
X64Function* fn = new X64Function(symbol_info);
|
||||
fn->set_debug_info(debug_info);
|
||||
|
||||
*out_function = fn;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_BACKEND_X64_X64_ASSEMBLER_H_
|
||||
#define ALLOY_BACKEND_X64_X64_ASSEMBLER_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
|
||||
#include <alloy/backend/assembler.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace backend {
|
||||
namespace x64 {
|
||||
|
||||
class X64Backend;
|
||||
|
||||
|
||||
class X64Assembler : public Assembler {
|
||||
public:
|
||||
X64Assembler(X64Backend* backend);
|
||||
virtual ~X64Assembler();
|
||||
|
||||
virtual int Initialize();
|
||||
|
||||
virtual void Reset();
|
||||
|
||||
virtual int Assemble(
|
||||
runtime::FunctionInfo* symbol_info, hir::HIRBuilder* builder,
|
||||
runtime::DebugInfo* debug_info, runtime::Function** out_function);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
} // namespace x64
|
||||
} // namespace backend
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_BACKEND_X64_X64_ASSEMBLER_H_
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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/backend/x64/x64_backend.h>
|
||||
|
||||
#include <alloy/backend/x64/tracing.h>
|
||||
#include <alloy/backend/x64/x64_assembler.h>
|
||||
|
||||
using namespace alloy;
|
||||
using namespace alloy::backend;
|
||||
using namespace alloy::backend::x64;
|
||||
using namespace alloy::runtime;
|
||||
|
||||
|
||||
X64Backend::X64Backend(Runtime* runtime) :
|
||||
Backend(runtime) {
|
||||
}
|
||||
|
||||
X64Backend::~X64Backend() {
|
||||
alloy::tracing::WriteEvent(EventType::Deinit({
|
||||
}));
|
||||
}
|
||||
|
||||
int X64Backend::Initialize() {
|
||||
int result = Backend::Initialize();
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
alloy::tracing::WriteEvent(EventType::Init({
|
||||
}));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Assembler* X64Backend::CreateAssembler() {
|
||||
return new X64Assembler(this);
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_BACKEND_X64_X64_BACKEND_H_
|
||||
#define ALLOY_BACKEND_X64_X64_BACKEND_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
|
||||
#include <alloy/backend/backend.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace backend {
|
||||
namespace x64 {
|
||||
|
||||
|
||||
#define ALLOY_HAS_X64_BACKEND 1
|
||||
|
||||
|
||||
class X64Backend : public Backend {
|
||||
public:
|
||||
X64Backend(runtime::Runtime* runtime);
|
||||
virtual ~X64Backend();
|
||||
|
||||
virtual int Initialize();
|
||||
|
||||
virtual Assembler* CreateAssembler();
|
||||
};
|
||||
|
||||
|
||||
} // namespace x64
|
||||
} // namespace backend
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_BACKEND_X64_X64_BACKEND_H_
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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/backend/x64/x64_codegen.h>
|
||||
|
||||
#include <alloy/backend/x64/x64_backend.h>
|
||||
|
||||
using namespace alloy;
|
||||
using namespace alloy::backend;
|
||||
using namespace alloy::backend::x64;
|
||||
using namespace alloy::runtime;
|
||||
|
||||
|
||||
X64Codegen::X64Codegen(X64Backend* backend) :
|
||||
backend_(backend) {
|
||||
}
|
||||
|
||||
X64Codegen::~X64Codegen() {
|
||||
}
|
||||
|
||||
int X64Codegen::Initialize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void X64Codegen::Reset() {
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_BACKEND_X64_X64_CODEGEN_H_
|
||||
#define ALLOY_BACKEND_X64_X64_CODEGEN_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace backend {
|
||||
namespace x64 {
|
||||
|
||||
class X64Backend;
|
||||
|
||||
|
||||
class X64Codegen {
|
||||
public:
|
||||
X64Codegen(X64Backend* backend);
|
||||
~X64Codegen();
|
||||
|
||||
int Initialize();
|
||||
|
||||
void Reset();
|
||||
|
||||
//
|
||||
|
||||
private:
|
||||
X64Backend* backend_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace x64
|
||||
} // namespace backend
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_BACKEND_X64_X64_CODEGEN_H_
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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/backend/x64/x64_emitter.h>
|
||||
|
||||
#include <alloy/backend/x64/x64_backend.h>
|
||||
|
||||
using namespace alloy;
|
||||
using namespace alloy::backend;
|
||||
using namespace alloy::backend::x64;
|
||||
using namespace alloy::runtime;
|
||||
|
||||
|
||||
X64Emitter::X64Emitter(X64Backend* backend) :
|
||||
backend_(backend) {
|
||||
}
|
||||
|
||||
X64Emitter::~X64Emitter() {
|
||||
}
|
||||
|
||||
int X64Emitter::Initialize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void X64Emitter::Reset() {
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_BACKEND_X64_X64_EMITTER_H_
|
||||
#define ALLOY_BACKEND_X64_X64_EMITTER_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace backend {
|
||||
namespace x64 {
|
||||
|
||||
class X64Backend;
|
||||
|
||||
|
||||
class X64Emitter {
|
||||
public:
|
||||
X64Emitter(X64Backend* backend);
|
||||
~X64Emitter();
|
||||
|
||||
int Initialize();
|
||||
|
||||
void Reset();
|
||||
|
||||
//
|
||||
|
||||
private:
|
||||
X64Backend* backend_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace x64
|
||||
} // namespace backend
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_BACKEND_X64_X64_EMITTER_H_
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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/backend/x64/x64_function.h>
|
||||
|
||||
#include <alloy/backend/x64/tracing.h>
|
||||
#include <alloy/runtime/runtime.h>
|
||||
#include <alloy/runtime/thread_state.h>
|
||||
|
||||
using namespace alloy;
|
||||
using namespace alloy::backend;
|
||||
using namespace alloy::backend::x64;
|
||||
using namespace alloy::runtime;
|
||||
|
||||
|
||||
X64Function::X64Function(FunctionInfo* symbol_info) :
|
||||
GuestFunction(symbol_info) {
|
||||
}
|
||||
|
||||
X64Function::~X64Function() {
|
||||
}
|
||||
|
||||
int X64Function::AddBreakpointImpl(Breakpoint* breakpoint) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int X64Function::RemoveBreakpointImpl(Breakpoint* breakpoint) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int X64Function::CallImpl(ThreadState* thread_state, uint64_t return_address) {
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* 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. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_BACKEND_X64_X64_FUNCTION_H_
|
||||
#define ALLOY_BACKEND_X64_X64_FUNCTION_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
#include <alloy/runtime/function.h>
|
||||
#include <alloy/runtime/symbol_info.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace backend {
|
||||
namespace x64 {
|
||||
|
||||
|
||||
class X64Function : public runtime::GuestFunction {
|
||||
public:
|
||||
X64Function(runtime::FunctionInfo* symbol_info);
|
||||
virtual ~X64Function();
|
||||
|
||||
//void Setup(TranslationContext& ctx);
|
||||
|
||||
protected:
|
||||
virtual int AddBreakpointImpl(runtime::Breakpoint* breakpoint);
|
||||
virtual int RemoveBreakpointImpl(runtime::Breakpoint* breakpoint);
|
||||
virtual int CallImpl(runtime::ThreadState* thread_state,
|
||||
uint64_t return_address);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
} // namespace x64
|
||||
} // namespace backend
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_BACKEND_X64_X64_FUNCTION_H_
|
|
@ -58,6 +58,7 @@ Runtime::~Runtime() {
|
|||
|
||||
// TODO(benvanik): based on compiler support
|
||||
#include <alloy/backend/ivm/ivm_backend.h>
|
||||
#include <alloy/backend/x64/x64_backend.h>
|
||||
|
||||
int Runtime::Initialize(Frontend* frontend, Backend* backend) {
|
||||
// Must be initialized by subclass before calling into this.
|
||||
|
@ -76,21 +77,31 @@ int Runtime::Initialize(Frontend* frontend, Backend* backend) {
|
|||
}
|
||||
|
||||
if (!backend) {
|
||||
#if defined(ALLOY_HAS_X64_BACKEND) && ALLOY_HAS_X64_BACKEND
|
||||
if (FLAGS_runtime_backend == "x64") {
|
||||
backend = new alloy::backend::x64::X64Backend(
|
||||
this);
|
||||
}
|
||||
#endif // ALLOY_HAS_X64_BACKEND
|
||||
#if defined(ALLOY_HAS_IVM_BACKEND) && ALLOY_HAS_IVM_BACKEND
|
||||
if (FLAGS_runtime_backend == "ivm") {
|
||||
backend = new alloy::backend::ivm::IVMBackend(
|
||||
this);
|
||||
}
|
||||
#endif
|
||||
// x64/etc
|
||||
#endif // ALLOY_HAS_IVM_BACKEND
|
||||
if (FLAGS_runtime_backend == "any") {
|
||||
// x64/etc
|
||||
#if defined(ALLOY_HAS_X64_BACKEND) && ALLOY_HAS_X64_BACKEND
|
||||
/*if (!backend) {
|
||||
backend = new alloy::backend::x64::X64Backend(
|
||||
this);
|
||||
}*/
|
||||
#endif // ALLOY_HAS_X64_BACKEND
|
||||
#if defined(ALLOY_HAS_IVM_BACKEND) && ALLOY_HAS_IVM_BACKEND
|
||||
if (!backend) {
|
||||
backend = new alloy::backend::ivm::IVMBackend(
|
||||
this);
|
||||
}
|
||||
#endif
|
||||
#endif // ALLOY_HAS_IVM_BACKEND
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue