Moving some util types into poly.

This commit is contained in:
Ben Vanik 2015-03-22 22:12:37 -07:00
parent b392afbfae
commit 59395318f3
54 changed files with 280 additions and 242 deletions

View File

@ -9,13 +9,13 @@
#include "alloy/backend/x64/x64_assembler.h" #include "alloy/backend/x64/x64_assembler.h"
#include "alloy/reset_scope.h"
#include "alloy/backend/x64/x64_backend.h" #include "alloy/backend/x64/x64_backend.h"
#include "alloy/backend/x64/x64_emitter.h" #include "alloy/backend/x64/x64_emitter.h"
#include "alloy/backend/x64/x64_function.h" #include "alloy/backend/x64/x64_function.h"
#include "alloy/hir/hir_builder.h" #include "alloy/hir/hir_builder.h"
#include "alloy/hir/label.h" #include "alloy/hir/label.h"
#include "alloy/runtime/runtime.h" #include "alloy/runtime/runtime.h"
#include "poly/reset_scope.h"
#include "xenia/profiling.h" #include "xenia/profiling.h"
namespace BE { namespace BE {
@ -67,7 +67,7 @@ int X64Assembler::Assemble(FunctionInfo* symbol_info, HIRBuilder* builder,
SCOPE_profile_cpu_f("alloy"); SCOPE_profile_cpu_f("alloy");
// Reset when we leave. // Reset when we leave.
make_reset_scope(this); poly::make_reset_scope(this);
// Lower HIR -> x64. // Lower HIR -> x64.
void* machine_code = 0; void* machine_code = 0;
@ -97,7 +97,7 @@ int X64Assembler::Assemble(FunctionInfo* symbol_info, HIRBuilder* builder,
} }
void X64Assembler::DumpMachineCode(DebugInfo* debug_info, void* machine_code, void X64Assembler::DumpMachineCode(DebugInfo* debug_info, void* machine_code,
size_t code_size, StringBuffer* str) { size_t code_size, poly::StringBuffer* str) {
BE::DISASM disasm = {0}; BE::DISASM disasm = {0};
disasm.Archi = 64; disasm.Archi = 64;
disasm.Options = BE::Tabulation + BE::MasmSyntax + BE::PrefixedNumeral; disasm.Options = BE::Tabulation + BE::MasmSyntax + BE::PrefixedNumeral;

View File

@ -13,7 +13,7 @@
#include <memory> #include <memory>
#include "alloy/backend/assembler.h" #include "alloy/backend/assembler.h"
#include "alloy/string_buffer.h" #include "poly/string_buffer.h"
namespace alloy { namespace alloy {
namespace backend { namespace backend {
@ -39,14 +39,14 @@ class X64Assembler : public Assembler {
private: private:
void DumpMachineCode(runtime::DebugInfo* debug_info, void* machine_code, void DumpMachineCode(runtime::DebugInfo* debug_info, void* machine_code,
size_t code_size, StringBuffer* str); size_t code_size, poly::StringBuffer* str);
private: private:
X64Backend* x64_backend_; X64Backend* x64_backend_;
std::unique_ptr<X64Emitter> emitter_; std::unique_ptr<X64Emitter> emitter_;
std::unique_ptr<XbyakAllocator> allocator_; std::unique_ptr<XbyakAllocator> allocator_;
StringBuffer string_buffer_; poly::StringBuffer string_buffer_;
}; };
} // namespace x64 } // namespace x64

View File

@ -20,6 +20,7 @@
#include "alloy/runtime/runtime.h" #include "alloy/runtime/runtime.h"
#include "alloy/runtime/symbol_info.h" #include "alloy/runtime/symbol_info.h"
#include "alloy/runtime/thread_state.h" #include "alloy/runtime/thread_state.h"
#include "poly/vec128.h"
#include "xdb/protocol.h" #include "xdb/protocol.h"
#include "xenia/profiling.h" #include "xenia/profiling.h"
@ -31,6 +32,10 @@ namespace x64 {
using namespace alloy::hir; using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using poly::vec128b;
using poly::vec128f;
using poly::vec128i;
using namespace Xbyak; using namespace Xbyak;
using alloy::hir::HIRBuilder; using alloy::hir::HIRBuilder;
using alloy::hir::Instr; using alloy::hir::Instr;

View File

@ -11,6 +11,7 @@
#define ALLOY_BACKEND_X64_X64_EMITTER_H_ #define ALLOY_BACKEND_X64_X64_EMITTER_H_
#include "alloy/hir/value.h" #include "alloy/hir/value.h"
#include "poly/arena.h"
#include "third_party/xbyak/xbyak/xbyak.h" #include "third_party/xbyak/xbyak/xbyak.h"
namespace alloy { namespace alloy {
@ -30,6 +31,8 @@ namespace alloy {
namespace backend { namespace backend {
namespace x64 { namespace x64 {
using vec128_t = poly::vec128_t;
class X64Backend; class X64Backend;
class X64CodeCache; class X64CodeCache;
@ -193,7 +196,7 @@ class X64Emitter : public Xbyak::CodeGenerator {
hir::Instr* current_instr_; hir::Instr* current_instr_;
size_t source_map_count_; size_t source_map_count_;
Arena source_map_arena_; poly::Arena source_map_arena_;
size_t stack_size_; size_t stack_size_;

View File

@ -39,6 +39,8 @@ using namespace Xbyak;
using namespace alloy::hir; using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using poly::vec128b;
typedef bool (*SequenceSelectFn)(X64Emitter&, const Instr*, const Instr**); typedef bool (*SequenceSelectFn)(X64Emitter&, const Instr*, const Instr**);
std::unordered_multimap<uint32_t, SequenceSelectFn> sequence_table; std::unordered_multimap<uint32_t, SequenceSelectFn> sequence_table;

View File

@ -14,6 +14,7 @@
#include <vector> #include <vector>
#include "alloy/hir/hir_builder.h" #include "alloy/hir/hir_builder.h"
#include "poly/arena.h"
namespace alloy { namespace alloy {
namespace runtime { namespace runtime {
@ -32,7 +33,7 @@ class Compiler {
~Compiler(); ~Compiler();
runtime::Runtime* runtime() const { return runtime_; } runtime::Runtime* runtime() const { return runtime_; }
Arena* scratch_arena() { return &scratch_arena_; } poly::Arena* scratch_arena() { return &scratch_arena_; }
void AddPass(std::unique_ptr<CompilerPass> pass); void AddPass(std::unique_ptr<CompilerPass> pass);
@ -42,7 +43,7 @@ class Compiler {
private: private:
runtime::Runtime* runtime_; runtime::Runtime* runtime_;
Arena scratch_arena_; poly::Arena scratch_arena_;
std::vector<std::unique_ptr<CompilerPass>> passes_; std::vector<std::unique_ptr<CompilerPass>> passes_;
}; };

View File

@ -24,7 +24,7 @@ int CompilerPass::Initialize(Compiler* compiler) {
return 0; return 0;
} }
Arena* CompilerPass::scratch_arena() const { poly::Arena* CompilerPass::scratch_arena() const {
return compiler_->scratch_arena(); return compiler_->scratch_arena();
} }

View File

@ -11,6 +11,7 @@
#define ALLOY_COMPILER_COMPILER_PASS_H_ #define ALLOY_COMPILER_COMPILER_PASS_H_
#include "alloy/hir/hir_builder.h" #include "alloy/hir/hir_builder.h"
#include "poly/arena.h"
namespace alloy { namespace alloy {
namespace runtime { namespace runtime {
@ -33,7 +34,7 @@ class CompilerPass {
virtual int Run(hir::HIRBuilder* builder) = 0; virtual int Run(hir::HIRBuilder* builder) = 0;
protected: protected:
Arena* scratch_arena() const; poly::Arena* scratch_arena() const;
protected: protected:
runtime::Runtime* runtime_; runtime::Runtime* runtime_;

View File

@ -10,8 +10,8 @@
#ifndef ALLOY_FRONTEND_PPC_PPC_CONTEXT_H_ #ifndef ALLOY_FRONTEND_PPC_PPC_CONTEXT_H_
#define ALLOY_FRONTEND_PPC_PPC_CONTEXT_H_ #define ALLOY_FRONTEND_PPC_PPC_CONTEXT_H_
#include "alloy/vec128.h"
#include "poly/poly.h" #include "poly/poly.h"
#include "poly/vec128.h"
namespace alloy { namespace runtime { namespace alloy { namespace runtime {
class Runtime; class Runtime;
@ -22,7 +22,7 @@ namespace alloy {
namespace frontend { namespace frontend {
namespace ppc { namespace ppc {
using vec128_t = alloy::vec128_t; using vec128_t = poly::vec128_t;
// Map: // Map:
// 0-31: GPR // 0-31: GPR

View File

@ -10,61 +10,61 @@
#include "alloy/frontend/ppc/ppc_disasm.h" #include "alloy/frontend/ppc/ppc_disasm.h"
#include "poly/poly.h" #include "poly/poly.h"
#include "alloy/string_buffer.h" #include "poly/string_buffer.h"
namespace alloy { namespace alloy {
namespace frontend { namespace frontend {
namespace ppc { namespace ppc {
void Disasm_0(InstrData& i, StringBuffer* str) { void Disasm_0(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s ???", i.type->name); str->Append("%-8s ???", i.type->name);
} }
void Disasm__(InstrData& i, StringBuffer* str) { void Disasm__(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s", i.type->name); str->Append("%-8s", i.type->name);
} }
void Disasm_X_FRT_FRB(InstrData& i, StringBuffer* str) { void Disasm_X_FRT_FRB(InstrData& i, poly::StringBuffer* str) {
str->Append("%*s%s f%d, f%d", i.X.Rc ? -7 : -8, i.type->name, str->Append("%*s%s f%d, f%d", i.X.Rc ? -7 : -8, i.type->name,
i.X.Rc ? "." : "", i.X.RT, i.X.RB); i.X.Rc ? "." : "", i.X.RT, i.X.RB);
} }
void Disasm_A_FRT_FRB(InstrData& i, StringBuffer* str) { void Disasm_A_FRT_FRB(InstrData& i, poly::StringBuffer* str) {
str->Append("%*s%s f%d, f%d", i.A.Rc ? -7 : -8, i.type->name, str->Append("%*s%s f%d, f%d", i.A.Rc ? -7 : -8, i.type->name,
i.A.Rc ? "." : "", i.A.FRT, i.A.FRB); i.A.Rc ? "." : "", i.A.FRT, i.A.FRB);
} }
void Disasm_A_FRT_FRA_FRB(InstrData& i, StringBuffer* str) { void Disasm_A_FRT_FRA_FRB(InstrData& i, poly::StringBuffer* str) {
str->Append("%*s%s f%d, f%d, f%d", i.A.Rc ? -7 : -8, i.type->name, str->Append("%*s%s f%d, f%d, f%d", i.A.Rc ? -7 : -8, i.type->name,
i.A.Rc ? "." : "", i.A.FRT, i.A.FRA, i.A.FRB); i.A.Rc ? "." : "", i.A.FRT, i.A.FRA, i.A.FRB);
} }
void Disasm_A_FRT_FRA_FRB_FRC(InstrData& i, StringBuffer* str) { void Disasm_A_FRT_FRA_FRB_FRC(InstrData& i, poly::StringBuffer* str) {
str->Append("%*s%s f%d, f%d, f%d, f%d", i.A.Rc ? -7 : -8, i.type->name, str->Append("%*s%s f%d, f%d, f%d, f%d", i.A.Rc ? -7 : -8, i.type->name,
i.A.Rc ? "." : "", i.A.FRT, i.A.FRA, i.A.FRB, i.A.FRC); i.A.Rc ? "." : "", i.A.FRT, i.A.FRA, i.A.FRB, i.A.FRC);
} }
void Disasm_X_RT_RA_RB(InstrData& i, StringBuffer* str) { void Disasm_X_RT_RA_RB(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s r%d, r%d, r%d", i.type->name, i.X.RT, i.X.RA, i.X.RB); str->Append("%-8s r%d, r%d, r%d", i.type->name, i.X.RT, i.X.RA, i.X.RB);
} }
void Disasm_X_RT_RA0_RB(InstrData& i, StringBuffer* str) { void Disasm_X_RT_RA0_RB(InstrData& i, poly::StringBuffer* str) {
if (i.X.RA) { if (i.X.RA) {
str->Append("%-8s r%d, r%d, r%d", i.type->name, i.X.RT, i.X.RA, i.X.RB); str->Append("%-8s r%d, r%d, r%d", i.type->name, i.X.RT, i.X.RA, i.X.RB);
} else { } else {
str->Append("%-8s r%d, 0, r%d", i.type->name, i.X.RT, i.X.RB); str->Append("%-8s r%d, 0, r%d", i.type->name, i.X.RT, i.X.RB);
} }
} }
void Disasm_X_FRT_RA_RB(InstrData& i, StringBuffer* str) { void Disasm_X_FRT_RA_RB(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s f%d, r%d, r%d", i.type->name, i.X.RT, i.X.RA, i.X.RB); str->Append("%-8s f%d, r%d, r%d", i.type->name, i.X.RT, i.X.RA, i.X.RB);
} }
void Disasm_X_FRT_RA0_RB(InstrData& i, StringBuffer* str) { void Disasm_X_FRT_RA0_RB(InstrData& i, poly::StringBuffer* str) {
if (i.X.RA) { if (i.X.RA) {
str->Append("%-8s f%d, r%d, r%d", i.type->name, i.X.RT, i.X.RA, i.X.RB); str->Append("%-8s f%d, r%d, r%d", i.type->name, i.X.RT, i.X.RA, i.X.RB);
} else { } else {
str->Append("%-8s f%d, 0, r%d", i.type->name, i.X.RT, i.X.RB); str->Append("%-8s f%d, 0, r%d", i.type->name, i.X.RT, i.X.RB);
} }
} }
void Disasm_D_RT_RA_I(InstrData& i, StringBuffer* str) { void Disasm_D_RT_RA_I(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s r%d, r%d, %d", i.type->name, i.D.RT, i.D.RA, str->Append("%-8s r%d, r%d, %d", i.type->name, i.D.RT, i.D.RA,
(int32_t)(int16_t)XEEXTS16(i.D.DS)); (int32_t)(int16_t)XEEXTS16(i.D.DS));
} }
void Disasm_D_RT_RA0_I(InstrData& i, StringBuffer* str) { void Disasm_D_RT_RA0_I(InstrData& i, poly::StringBuffer* str) {
if (i.D.RA) { if (i.D.RA) {
str->Append("%-8s r%d, r%d, %d", i.type->name, i.D.RT, i.D.RA, str->Append("%-8s r%d, r%d, %d", i.type->name, i.D.RT, i.D.RA,
(int32_t)(int16_t)XEEXTS16(i.D.DS)); (int32_t)(int16_t)XEEXTS16(i.D.DS));
@ -73,11 +73,11 @@ void Disasm_D_RT_RA0_I(InstrData& i, StringBuffer* str) {
(int32_t)(int16_t)XEEXTS16(i.D.DS)); (int32_t)(int16_t)XEEXTS16(i.D.DS));
} }
} }
void Disasm_D_FRT_RA_I(InstrData& i, StringBuffer* str) { void Disasm_D_FRT_RA_I(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s f%d, r%d, %d", i.type->name, i.D.RT, i.D.RA, str->Append("%-8s f%d, r%d, %d", i.type->name, i.D.RT, i.D.RA,
(int32_t)(int16_t)XEEXTS16(i.D.DS)); (int32_t)(int16_t)XEEXTS16(i.D.DS));
} }
void Disasm_D_FRT_RA0_I(InstrData& i, StringBuffer* str) { void Disasm_D_FRT_RA0_I(InstrData& i, poly::StringBuffer* str) {
if (i.D.RA) { if (i.D.RA) {
str->Append("%-8s f%d, r%d, %d", i.type->name, i.D.RT, i.D.RA, str->Append("%-8s f%d, r%d, %d", i.type->name, i.D.RT, i.D.RA,
(int32_t)(int16_t)XEEXTS16(i.D.DS)); (int32_t)(int16_t)XEEXTS16(i.D.DS));
@ -86,11 +86,11 @@ void Disasm_D_FRT_RA0_I(InstrData& i, StringBuffer* str) {
(int32_t)(int16_t)XEEXTS16(i.D.DS)); (int32_t)(int16_t)XEEXTS16(i.D.DS));
} }
} }
void Disasm_DS_RT_RA_I(InstrData& i, StringBuffer* str) { void Disasm_DS_RT_RA_I(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s r%d, r%d, %d", i.type->name, i.DS.RT, i.DS.RA, str->Append("%-8s r%d, r%d, %d", i.type->name, i.DS.RT, i.DS.RA,
(int32_t)(int16_t)XEEXTS16(i.DS.DS << 2)); (int32_t)(int16_t)XEEXTS16(i.DS.DS << 2));
} }
void Disasm_DS_RT_RA0_I(InstrData& i, StringBuffer* str) { void Disasm_DS_RT_RA0_I(InstrData& i, poly::StringBuffer* str) {
if (i.DS.RA) { if (i.DS.RA) {
str->Append("%-8s r%d, r%d, %d", i.type->name, i.DS.RT, i.DS.RA, str->Append("%-8s r%d, r%d, %d", i.type->name, i.DS.RT, i.DS.RA,
(int32_t)(int16_t)XEEXTS16(i.DS.DS << 2)); (int32_t)(int16_t)XEEXTS16(i.DS.DS << 2));
@ -99,29 +99,29 @@ void Disasm_DS_RT_RA0_I(InstrData& i, StringBuffer* str) {
(int32_t)(int16_t)XEEXTS16(i.DS.DS << 2)); (int32_t)(int16_t)XEEXTS16(i.DS.DS << 2));
} }
} }
void Disasm_D_RA(InstrData& i, StringBuffer* str) { void Disasm_D_RA(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s r%d", i.type->name, i.D.RA); str->Append("%-8s r%d", i.type->name, i.D.RA);
} }
void Disasm_X_RA_RB(InstrData& i, StringBuffer* str) { void Disasm_X_RA_RB(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s r%d, r%d", i.type->name, i.X.RA, i.X.RB); str->Append("%-8s r%d, r%d", i.type->name, i.X.RA, i.X.RB);
} }
void Disasm_XO_RT_RA_RB(InstrData& i, StringBuffer* str) { void Disasm_XO_RT_RA_RB(InstrData& i, poly::StringBuffer* str) {
str->Append("%*s%s%s r%d, r%d, r%d", i.XO.Rc ? -7 : -8, i.type->name, str->Append("%*s%s%s r%d, r%d, r%d", i.XO.Rc ? -7 : -8, i.type->name,
i.XO.OE ? "o" : "", i.XO.Rc ? "." : "", i.XO.RT, i.XO.RA, i.XO.OE ? "o" : "", i.XO.Rc ? "." : "", i.XO.RT, i.XO.RA,
i.XO.RB); i.XO.RB);
} }
void Disasm_XO_RT_RA(InstrData& i, StringBuffer* str) { void Disasm_XO_RT_RA(InstrData& i, poly::StringBuffer* str) {
str->Append("%*s%s%s r%d, r%d", i.XO.Rc ? -7 : -8, i.type->name, str->Append("%*s%s%s r%d, r%d", i.XO.Rc ? -7 : -8, i.type->name,
i.XO.OE ? "o" : "", i.XO.Rc ? "." : "", i.XO.RT, i.XO.RA); i.XO.OE ? "o" : "", i.XO.Rc ? "." : "", i.XO.RT, i.XO.RA);
} }
void Disasm_X_RA_RT_RB(InstrData& i, StringBuffer* str) { void Disasm_X_RA_RT_RB(InstrData& i, poly::StringBuffer* str) {
str->Append("%*s%s r%d, r%d, r%d", i.X.Rc ? -7 : -8, i.type->name, str->Append("%*s%s r%d, r%d, r%d", i.X.Rc ? -7 : -8, i.type->name,
i.X.Rc ? "." : "", i.X.RA, i.X.RT, i.X.RB); i.X.Rc ? "." : "", i.X.RA, i.X.RT, i.X.RB);
} }
void Disasm_D_RA_RT_I(InstrData& i, StringBuffer* str) { void Disasm_D_RA_RT_I(InstrData& i, poly::StringBuffer* str) {
str->Append("%-7s. r%d, r%d, %.4Xh", i.type->name, i.D.RA, i.D.RT, i.D.DS); str->Append("%-7s. r%d, r%d, %.4Xh", i.type->name, i.D.RA, i.D.RT, i.D.DS);
} }
void Disasm_X_RA_RT(InstrData& i, StringBuffer* str) { void Disasm_X_RA_RT(InstrData& i, poly::StringBuffer* str) {
str->Append("%*s%s r%d, r%d", i.X.Rc ? -7 : -8, i.type->name, str->Append("%*s%s r%d, r%d", i.X.Rc ? -7 : -8, i.type->name,
i.X.Rc ? "." : "", i.X.RA, i.X.RT); i.X.Rc ? "." : "", i.X.RA, i.X.RT);
} }
@ -160,14 +160,14 @@ void Disasm_X_RA_RT(InstrData& i, StringBuffer* str) {
(i.VX128_R.VA128l | (i.VX128_R.VA128h << 5) | (i.VX128_R.VA128H << 6)) (i.VX128_R.VA128l | (i.VX128_R.VA128h << 5) | (i.VX128_R.VA128H << 6))
#define VX128_R_VB128 (i.VX128_R.VB128l | (i.VX128_R.VB128h << 5)) #define VX128_R_VB128 (i.VX128_R.VB128l | (i.VX128_R.VB128h << 5))
void Disasm_X_VX_RA0_RB(InstrData& i, StringBuffer* str) { void Disasm_X_VX_RA0_RB(InstrData& i, poly::StringBuffer* str) {
if (i.X.RA) { if (i.X.RA) {
str->Append("%-8s v%d, r%d, r%d", i.type->name, i.X.RT, i.X.RA, i.X.RB); str->Append("%-8s v%d, r%d, r%d", i.type->name, i.X.RT, i.X.RA, i.X.RB);
} else { } else {
str->Append("%-8s v%d, 0, r%d", i.type->name, i.X.RT, i.X.RB); str->Append("%-8s v%d, 0, r%d", i.type->name, i.X.RT, i.X.RB);
} }
} }
void Disasm_VX1281_VD_RA0_RB(InstrData& i, StringBuffer* str) { void Disasm_VX1281_VD_RA0_RB(InstrData& i, poly::StringBuffer* str) {
const uint32_t vd = VX128_1_VD128; const uint32_t vd = VX128_1_VD128;
if (i.VX128_1.RA) { if (i.VX128_1.RA) {
str->Append("%-8s v%d, r%d, r%d", i.type->name, vd, i.VX128_1.RA, str->Append("%-8s v%d, r%d, r%d", i.type->name, vd, i.VX128_1.RA,
@ -176,45 +176,45 @@ void Disasm_VX1281_VD_RA0_RB(InstrData& i, StringBuffer* str) {
str->Append("%-8s v%d, 0, r%d", i.type->name, vd, i.VX128_1.RB); str->Append("%-8s v%d, 0, r%d", i.type->name, vd, i.VX128_1.RB);
} }
} }
void Disasm_VX1283_VD_VB(InstrData& i, StringBuffer* str) { void Disasm_VX1283_VD_VB(InstrData& i, poly::StringBuffer* str) {
const uint32_t vd = VX128_3_VD128; const uint32_t vd = VX128_3_VD128;
const uint32_t vb = VX128_3_VB128; const uint32_t vb = VX128_3_VB128;
str->Append("%-8s v%d, v%d", i.type->name, vd, vb); str->Append("%-8s v%d, v%d", i.type->name, vd, vb);
} }
void Disasm_VX1283_VD_VB_I(InstrData& i, StringBuffer* str) { void Disasm_VX1283_VD_VB_I(InstrData& i, poly::StringBuffer* str) {
const uint32_t vd = VX128_VD128; const uint32_t vd = VX128_VD128;
const uint32_t va = VX128_VA128; const uint32_t va = VX128_VA128;
const uint32_t uimm = i.VX128_3.IMM; const uint32_t uimm = i.VX128_3.IMM;
str->Append("%-8s v%d, v%d, %.2Xh", i.type->name, vd, va, uimm); str->Append("%-8s v%d, v%d, %.2Xh", i.type->name, vd, va, uimm);
} }
void Disasm_VX_VD_VA_VB(InstrData& i, StringBuffer* str) { void Disasm_VX_VD_VA_VB(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s v%d, v%d, v%d", i.type->name, i.VX.VD, i.VX.VA, i.VX.VB); str->Append("%-8s v%d, v%d, v%d", i.type->name, i.VX.VD, i.VX.VA, i.VX.VB);
} }
void Disasm_VX128_VD_VA_VB(InstrData& i, StringBuffer* str) { void Disasm_VX128_VD_VA_VB(InstrData& i, poly::StringBuffer* str) {
const uint32_t vd = VX128_VD128; const uint32_t vd = VX128_VD128;
const uint32_t va = VX128_VA128; const uint32_t va = VX128_VA128;
const uint32_t vb = VX128_VB128; const uint32_t vb = VX128_VB128;
str->Append("%-8s v%d, v%d, v%d", i.type->name, vd, va, vb); str->Append("%-8s v%d, v%d, v%d", i.type->name, vd, va, vb);
} }
void Disasm_VX128_VD_VA_VD_VB(InstrData& i, StringBuffer* str) { void Disasm_VX128_VD_VA_VD_VB(InstrData& i, poly::StringBuffer* str) {
const uint32_t vd = VX128_VD128; const uint32_t vd = VX128_VD128;
const uint32_t va = VX128_VA128; const uint32_t va = VX128_VA128;
const uint32_t vb = VX128_VB128; const uint32_t vb = VX128_VB128;
str->Append("%-8s v%d, v%d, v%d, v%d", i.type->name, vd, va, vd, vb); str->Append("%-8s v%d, v%d, v%d, v%d", i.type->name, vd, va, vd, vb);
} }
void Disasm_VX1282_VD_VA_VB_VC(InstrData& i, StringBuffer* str) { void Disasm_VX1282_VD_VA_VB_VC(InstrData& i, poly::StringBuffer* str) {
const uint32_t vd = VX128_2_VD128; const uint32_t vd = VX128_2_VD128;
const uint32_t va = VX128_2_VA128; const uint32_t va = VX128_2_VA128;
const uint32_t vb = VX128_2_VB128; const uint32_t vb = VX128_2_VB128;
const uint32_t vc = i.VX128_2.VC; const uint32_t vc = i.VX128_2.VC;
str->Append("%-8s v%d, v%d, v%d, v%d", i.type->name, vd, va, vb, vc); str->Append("%-8s v%d, v%d, v%d, v%d", i.type->name, vd, va, vb, vc);
} }
void Disasm_VXA_VD_VA_VB_VC(InstrData& i, StringBuffer* str) { void Disasm_VXA_VD_VA_VB_VC(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s v%d, v%d, v%d, v%d", i.type->name, i.VXA.VD, i.VXA.VA, str->Append("%-8s v%d, v%d, v%d, v%d", i.type->name, i.VXA.VD, i.VXA.VA,
i.VXA.VB, i.VXA.VC); i.VXA.VB, i.VXA.VC);
} }
void Disasm_sync(InstrData& i, StringBuffer* str) { void Disasm_sync(InstrData& i, poly::StringBuffer* str) {
const char* name; const char* name;
int L = i.X.RT & 3; int L = i.X.RT & 3;
switch (L) { switch (L) {
@ -233,7 +233,7 @@ void Disasm_sync(InstrData& i, StringBuffer* str) {
str->Append("%-8s %.2X", name, L); str->Append("%-8s %.2X", name, L);
} }
void Disasm_dcbf(InstrData& i, StringBuffer* str) { void Disasm_dcbf(InstrData& i, poly::StringBuffer* str) {
const char* name; const char* name;
switch (i.X.RT & 3) { switch (i.X.RT & 3) {
case 0: case 0:
@ -255,7 +255,7 @@ void Disasm_dcbf(InstrData& i, StringBuffer* str) {
str->Append("%-8s r%d, r%d", name, i.X.RA, i.X.RB); str->Append("%-8s r%d, r%d", name, i.X.RA, i.X.RB);
} }
void Disasm_dcbz(InstrData& i, StringBuffer* str) { void Disasm_dcbz(InstrData& i, poly::StringBuffer* str) {
// or dcbz128 0x7C2007EC // or dcbz128 0x7C2007EC
if (i.X.RA) { if (i.X.RA) {
str->Append("%-8s r%d, r%d", i.type->name, i.X.RA, i.X.RB); str->Append("%-8s r%d, r%d", i.type->name, i.X.RA, i.X.RB);
@ -264,16 +264,16 @@ void Disasm_dcbz(InstrData& i, StringBuffer* str) {
} }
} }
void Disasm_fcmp(InstrData& i, StringBuffer* str) { void Disasm_fcmp(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s cr%d, f%d, f%d", i.type->name, i.X.RT >> 2, i.X.RA, i.X.RB); str->Append("%-8s cr%d, f%d, f%d", i.type->name, i.X.RT >> 2, i.X.RA, i.X.RB);
} }
void Disasm_mffsx(InstrData& i, StringBuffer* str) { void Disasm_mffsx(InstrData& i, poly::StringBuffer* str) {
str->Append("%*s%s f%d, FPSCR", i.X.Rc ? -7 : -8, i.type->name, str->Append("%*s%s f%d, FPSCR", i.X.Rc ? -7 : -8, i.type->name,
i.X.Rc ? "." : "", i.X.RT); i.X.Rc ? "." : "", i.X.RT);
} }
void Disasm_bx(InstrData& i, StringBuffer* str) { void Disasm_bx(InstrData& i, poly::StringBuffer* str) {
const char* name = i.I.LK ? "bl" : "b"; const char* name = i.I.LK ? "bl" : "b";
uint32_t nia; uint32_t nia;
if (i.I.AA) { if (i.I.AA) {
@ -284,7 +284,7 @@ void Disasm_bx(InstrData& i, StringBuffer* str) {
str->Append("%-8s %.8X", name, nia); str->Append("%-8s %.8X", name, nia);
// TODO(benvanik): resolve target name? // TODO(benvanik): resolve target name?
} }
void Disasm_bcx(InstrData& i, StringBuffer* str) { void Disasm_bcx(InstrData& i, poly::StringBuffer* str) {
const char* s0 = i.B.LK ? "lr, " : ""; const char* s0 = i.B.LK ? "lr, " : "";
const char* s1; const char* s1;
if (!select_bits(i.B.BO, 2, 2)) { if (!select_bits(i.B.BO, 2, 2)) {
@ -305,7 +305,7 @@ void Disasm_bcx(InstrData& i, StringBuffer* str) {
str->Append("%-8s %s%s%s%.8X", i.type->name, s0, s1, s2, nia); str->Append("%-8s %s%s%s%.8X", i.type->name, s0, s1, s2, nia);
// TODO(benvanik): resolve target name? // TODO(benvanik): resolve target name?
} }
void Disasm_bcctrx(InstrData& i, StringBuffer* str) { void Disasm_bcctrx(InstrData& i, poly::StringBuffer* str) {
// TODO(benvanik): mnemonics // TODO(benvanik): mnemonics
const char* s0 = i.XL.LK ? "lr, " : ""; const char* s0 = i.XL.LK ? "lr, " : "";
char s2[8] = {0}; char s2[8] = {0};
@ -315,7 +315,7 @@ void Disasm_bcctrx(InstrData& i, StringBuffer* str) {
str->Append("%-8s %s%sctr", i.type->name, s0, s2); str->Append("%-8s %s%sctr", i.type->name, s0, s2);
// TODO(benvanik): resolve target name? // TODO(benvanik): resolve target name?
} }
void Disasm_bclrx(InstrData& i, StringBuffer* str) { void Disasm_bclrx(InstrData& i, poly::StringBuffer* str) {
const char* name = "bclr"; const char* name = "bclr";
if (i.code == 0x4E800020) { if (i.code == 0x4E800020) {
name = "blr"; name = "blr";
@ -333,7 +333,7 @@ void Disasm_bclrx(InstrData& i, StringBuffer* str) {
str->Append("%-8s %s%s", name, s1, s2); str->Append("%-8s %s%s", name, s1, s2);
} }
void Disasm_mfcr(InstrData& i, StringBuffer* str) { void Disasm_mfcr(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s r%d, cr", i.type->name, i.X.RT); str->Append("%-8s r%d, cr", i.type->name, i.X.RT);
} }
const char* Disasm_spr_name(uint32_t n) { const char* Disasm_spr_name(uint32_t n) {
@ -351,40 +351,40 @@ const char* Disasm_spr_name(uint32_t n) {
} }
return reg; return reg;
} }
void Disasm_mfspr(InstrData& i, StringBuffer* str) { void Disasm_mfspr(InstrData& i, poly::StringBuffer* str) {
const uint32_t n = ((i.XFX.spr & 0x1F) << 5) | ((i.XFX.spr >> 5) & 0x1F); const uint32_t n = ((i.XFX.spr & 0x1F) << 5) | ((i.XFX.spr >> 5) & 0x1F);
const char* reg = Disasm_spr_name(n); const char* reg = Disasm_spr_name(n);
str->Append("%-8s r%d, %s", i.type->name, i.XFX.RT, reg); str->Append("%-8s r%d, %s", i.type->name, i.XFX.RT, reg);
} }
void Disasm_mtspr(InstrData& i, StringBuffer* str) { void Disasm_mtspr(InstrData& i, poly::StringBuffer* str) {
const uint32_t n = ((i.XFX.spr & 0x1F) << 5) | ((i.XFX.spr >> 5) & 0x1F); const uint32_t n = ((i.XFX.spr & 0x1F) << 5) | ((i.XFX.spr >> 5) & 0x1F);
const char* reg = Disasm_spr_name(n); const char* reg = Disasm_spr_name(n);
str->Append("%-8s %s, r%d", i.type->name, reg, i.XFX.RT); str->Append("%-8s %s, r%d", i.type->name, reg, i.XFX.RT);
} }
void Disasm_mftb(InstrData& i, StringBuffer* str) { void Disasm_mftb(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s r%d, tb", i.type->name, i.XFX.RT); str->Append("%-8s r%d, tb", i.type->name, i.XFX.RT);
} }
void Disasm_mfmsr(InstrData& i, StringBuffer* str) { void Disasm_mfmsr(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s r%d", i.type->name, i.X.RT); str->Append("%-8s r%d", i.type->name, i.X.RT);
} }
void Disasm_mtmsr(InstrData& i, StringBuffer* str) { void Disasm_mtmsr(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s r%d, %d", i.type->name, i.X.RT, (i.X.RA & 16) ? 1 : 0); str->Append("%-8s r%d, %d", i.type->name, i.X.RT, (i.X.RA & 16) ? 1 : 0);
} }
void Disasm_cmp(InstrData& i, StringBuffer* str) { void Disasm_cmp(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s cr%d, %.2X, r%d, r%d", i.type->name, i.X.RT >> 2, str->Append("%-8s cr%d, %.2X, r%d, r%d", i.type->name, i.X.RT >> 2,
i.X.RT & 1, i.X.RA, i.X.RB); i.X.RT & 1, i.X.RA, i.X.RB);
} }
void Disasm_cmpi(InstrData& i, StringBuffer* str) { void Disasm_cmpi(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s cr%d, %.2X, r%d, %d", i.type->name, i.D.RT >> 2, i.D.RT & 1, str->Append("%-8s cr%d, %.2X, r%d, %d", i.type->name, i.D.RT >> 2, i.D.RT & 1,
i.D.RA, XEEXTS16(i.D.DS)); i.D.RA, XEEXTS16(i.D.DS));
} }
void Disasm_cmpli(InstrData& i, StringBuffer* str) { void Disasm_cmpli(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s cr%d, %.2X, r%d, %.2X", i.type->name, i.D.RT >> 2, str->Append("%-8s cr%d, %.2X, r%d, %.2X", i.type->name, i.D.RT >> 2,
i.D.RT & 1, i.D.RA, XEEXTS16(i.D.DS)); i.D.RT & 1, i.D.RA, XEEXTS16(i.D.DS));
} }
void Disasm_rld(InstrData& i, StringBuffer* str) { void Disasm_rld(InstrData& i, poly::StringBuffer* str) {
if (i.MD.idx == 0) { if (i.MD.idx == 0) {
// XEDISASMR(rldiclx, 0x78000000, MD ) // XEDISASMR(rldiclx, 0x78000000, MD )
str->Append("%*s%s r%d, r%d, %d, %d", i.MD.Rc ? -7 : -8, "rldicl", str->Append("%*s%s r%d, r%d, %d, %d", i.MD.Rc ? -7 : -8, "rldicl",
@ -421,75 +421,75 @@ void Disasm_rld(InstrData& i, StringBuffer* str) {
assert_always(); assert_always();
} }
} }
void Disasm_rlwim(InstrData& i, StringBuffer* str) { void Disasm_rlwim(InstrData& i, poly::StringBuffer* str) {
str->Append("%*s%s r%d, r%d, %d, %d, %d", i.M.Rc ? -7 : -8, i.type->name, str->Append("%*s%s r%d, r%d, %d, %d, %d", i.M.Rc ? -7 : -8, i.type->name,
i.M.Rc ? "." : "", i.M.RA, i.M.RT, i.M.SH, i.M.MB, i.M.ME); i.M.Rc ? "." : "", i.M.RA, i.M.RT, i.M.SH, i.M.MB, i.M.ME);
} }
void Disasm_rlwnmx(InstrData& i, StringBuffer* str) { void Disasm_rlwnmx(InstrData& i, poly::StringBuffer* str) {
str->Append("%*s%s r%d, r%d, r%d, %d, %d", i.M.Rc ? -7 : -8, i.type->name, str->Append("%*s%s r%d, r%d, r%d, %d, %d", i.M.Rc ? -7 : -8, i.type->name,
i.M.Rc ? "." : "", i.M.RA, i.M.RT, i.M.SH, i.M.MB, i.M.ME); i.M.Rc ? "." : "", i.M.RA, i.M.RT, i.M.SH, i.M.MB, i.M.ME);
} }
void Disasm_srawix(InstrData& i, StringBuffer* str) { void Disasm_srawix(InstrData& i, poly::StringBuffer* str) {
str->Append("%*s%s r%d, r%d, %d", i.X.Rc ? -7 : -8, i.type->name, str->Append("%*s%s r%d, r%d, %d", i.X.Rc ? -7 : -8, i.type->name,
i.X.Rc ? "." : "", i.X.RA, i.X.RT, i.X.RB); i.X.Rc ? "." : "", i.X.RA, i.X.RT, i.X.RB);
} }
void Disasm_sradix(InstrData& i, StringBuffer* str) { void Disasm_sradix(InstrData& i, poly::StringBuffer* str) {
str->Append("%*s%s r%d, r%d, %d", i.XS.Rc ? -7 : -8, i.type->name, str->Append("%*s%s r%d, r%d, %d", i.XS.Rc ? -7 : -8, i.type->name,
i.XS.Rc ? "." : "", i.XS.RA, i.XS.RT, (i.XS.SH5 << 5) | i.XS.SH); i.XS.Rc ? "." : "", i.XS.RA, i.XS.RT, (i.XS.SH5 << 5) | i.XS.SH);
} }
void Disasm_vpermwi128(InstrData& i, StringBuffer* str) { void Disasm_vpermwi128(InstrData& i, poly::StringBuffer* str) {
const uint32_t vd = i.VX128_P.VD128l | (i.VX128_P.VD128h << 5); const uint32_t vd = i.VX128_P.VD128l | (i.VX128_P.VD128h << 5);
const uint32_t vb = i.VX128_P.VB128l | (i.VX128_P.VB128h << 5); const uint32_t vb = i.VX128_P.VB128l | (i.VX128_P.VB128h << 5);
str->Append("%-8s v%d, v%d, %.2X", i.type->name, vd, vb, str->Append("%-8s v%d, v%d, %.2X", i.type->name, vd, vb,
i.VX128_P.PERMl | (i.VX128_P.PERMh << 5)); i.VX128_P.PERMl | (i.VX128_P.PERMh << 5));
} }
void Disasm_vrfin128(InstrData& i, StringBuffer* str) { void Disasm_vrfin128(InstrData& i, poly::StringBuffer* str) {
const uint32_t vd = VX128_3_VD128; const uint32_t vd = VX128_3_VD128;
const uint32_t vb = VX128_3_VB128; const uint32_t vb = VX128_3_VB128;
str->Append("%-8s v%d, v%d", i.type->name, vd, vb); str->Append("%-8s v%d, v%d", i.type->name, vd, vb);
} }
void Disasm_vrlimi128(InstrData& i, StringBuffer* str) { void Disasm_vrlimi128(InstrData& i, poly::StringBuffer* str) {
const uint32_t vd = VX128_4_VD128; const uint32_t vd = VX128_4_VD128;
const uint32_t vb = VX128_4_VB128; const uint32_t vb = VX128_4_VB128;
str->Append("%-8s v%d, v%d, %.2X, %.2X", i.type->name, vd, vb, i.VX128_4.IMM, str->Append("%-8s v%d, v%d, %.2X, %.2X", i.type->name, vd, vb, i.VX128_4.IMM,
i.VX128_4.z); i.VX128_4.z);
} }
void Disasm_vsldoi128(InstrData& i, StringBuffer* str) { void Disasm_vsldoi128(InstrData& i, poly::StringBuffer* str) {
const uint32_t vd = VX128_5_VD128; const uint32_t vd = VX128_5_VD128;
const uint32_t va = VX128_5_VA128; const uint32_t va = VX128_5_VA128;
const uint32_t vb = VX128_5_VB128; const uint32_t vb = VX128_5_VB128;
const uint32_t sh = i.VX128_5.SH; const uint32_t sh = i.VX128_5.SH;
str->Append("%-8s v%d, v%d, v%d, %.2X", i.type->name, vd, va, vb, sh); str->Append("%-8s v%d, v%d, v%d, %.2X", i.type->name, vd, va, vb, sh);
} }
void Disasm_vspltb(InstrData& i, StringBuffer* str) { void Disasm_vspltb(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s v%d, v%d, %.2X", i.type->name, i.VX.VD, i.VX.VB, str->Append("%-8s v%d, v%d, %.2X", i.type->name, i.VX.VD, i.VX.VB,
i.VX.VA & 0xF); i.VX.VA & 0xF);
} }
void Disasm_vsplth(InstrData& i, StringBuffer* str) { void Disasm_vsplth(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s v%d, v%d, %.2X", i.type->name, i.VX.VD, i.VX.VB, str->Append("%-8s v%d, v%d, %.2X", i.type->name, i.VX.VD, i.VX.VB,
i.VX.VA & 0x7); i.VX.VA & 0x7);
} }
void Disasm_vspltw(InstrData& i, StringBuffer* str) { void Disasm_vspltw(InstrData& i, poly::StringBuffer* str) {
str->Append("%-8s v%d, v%d, %.2X", i.type->name, i.VX.VD, i.VX.VB, i.VX.VA); str->Append("%-8s v%d, v%d, %.2X", i.type->name, i.VX.VD, i.VX.VB, i.VX.VA);
} }
void Disasm_vspltisb(InstrData& i, StringBuffer* str) { void Disasm_vspltisb(InstrData& i, poly::StringBuffer* str) {
// 5bit -> 8bit sign extend // 5bit -> 8bit sign extend
int8_t simm = (i.VX.VA & 0x10) ? (i.VX.VA | 0xF0) : i.VX.VA; int8_t simm = (i.VX.VA & 0x10) ? (i.VX.VA | 0xF0) : i.VX.VA;
str->Append("%-8s v%d, %.2X", i.type->name, i.VX.VD, simm); str->Append("%-8s v%d, %.2X", i.type->name, i.VX.VD, simm);
} }
void Disasm_vspltish(InstrData& i, StringBuffer* str) { void Disasm_vspltish(InstrData& i, poly::StringBuffer* str) {
// 5bit -> 16bit sign extend // 5bit -> 16bit sign extend
int16_t simm = (i.VX.VA & 0x10) ? (i.VX.VA | 0xFFF0) : i.VX.VA; int16_t simm = (i.VX.VA & 0x10) ? (i.VX.VA | 0xFFF0) : i.VX.VA;
str->Append("%-8s v%d, %.4X", i.type->name, i.VX.VD, simm); str->Append("%-8s v%d, %.4X", i.type->name, i.VX.VD, simm);
} }
void Disasm_vspltisw(InstrData& i, StringBuffer* str) { void Disasm_vspltisw(InstrData& i, poly::StringBuffer* str) {
// 5bit -> 32bit sign extend // 5bit -> 32bit sign extend
int32_t simm = (i.VX.VA & 0x10) ? (i.VX.VA | 0xFFFFFFF0) : i.VX.VA; int32_t simm = (i.VX.VA & 0x10) ? (i.VX.VA | 0xFFFFFFF0) : i.VX.VA;
str->Append("%-8s v%d, %.8X", i.type->name, i.VX.VD, simm); str->Append("%-8s v%d, %.8X", i.type->name, i.VX.VD, simm);
} }
int DisasmPPC(InstrData& i, StringBuffer* str) { int DisasmPPC(InstrData& i, poly::StringBuffer* str) {
if (!i.type) { if (!i.type) {
str->Append("???"); str->Append("???");
} else { } else {

View File

@ -11,12 +11,13 @@
#define ALLOY_FRONTEND_PPC_PPC_DISASM_H_ #define ALLOY_FRONTEND_PPC_PPC_DISASM_H_
#include "alloy/frontend/ppc/ppc_instr.h" #include "alloy/frontend/ppc/ppc_instr.h"
#include "poly/string_buffer.h"
namespace alloy { namespace alloy {
namespace frontend { namespace frontend {
namespace ppc { namespace ppc {
int DisasmPPC(InstrData& i, StringBuffer* str); int DisasmPPC(InstrData& i, poly::StringBuffer* str);
} // namespace ppc } // namespace ppc
} // namespace frontend } // namespace frontend

View File

@ -18,6 +18,10 @@ namespace ppc {
// TODO(benvanik): remove when enums redefined. // TODO(benvanik): remove when enums redefined.
using namespace alloy::hir; using namespace alloy::hir;
using poly::vec128b;
using poly::vec128f;
using poly::vec128i;
using poly::vec128s;
using alloy::hir::Value; using alloy::hir::Value;

View File

@ -13,7 +13,7 @@
#include <mutex> #include <mutex>
#include "alloy/frontend/frontend.h" #include "alloy/frontend/frontend.h"
#include "alloy/type_pool.h" #include "poly/type_pool.h"
namespace alloy { namespace alloy {
namespace frontend { namespace frontend {
@ -43,7 +43,7 @@ class PPCFrontend : public Frontend {
runtime::Function** out_function) override; runtime::Function** out_function) override;
private: private:
TypePool<PPCTranslator, PPCFrontend*> translator_pool_; poly::TypePool<PPCTranslator, PPCFrontend*> translator_pool_;
PPCBuiltins builtins_; PPCBuiltins builtins_;
}; };

View File

@ -13,7 +13,7 @@
#include "alloy/hir/hir_builder.h" #include "alloy/hir/hir_builder.h"
#include "alloy/runtime/function.h" #include "alloy/runtime/function.h"
#include "alloy/runtime/symbol_info.h" #include "alloy/runtime/symbol_info.h"
#include "alloy/string_buffer.h" #include "poly/string_buffer.h"
namespace alloy { namespace alloy {
namespace frontend { namespace frontend {
@ -91,7 +91,7 @@ class PPCHIRBuilder : public hir::HIRBuilder {
PPCFrontend* frontend_; PPCFrontend* frontend_;
// Reset whenever needed: // Reset whenever needed:
StringBuffer comment_buffer_; poly::StringBuffer comment_buffer_;
// Reset each Emit: // Reset each Emit:
bool with_debug_info_; bool with_debug_info_;

View File

@ -13,8 +13,8 @@
#include <vector> #include <vector>
#include "alloy/frontend/ppc/ppc_instr_tables.h" #include "alloy/frontend/ppc/ppc_instr_tables.h"
#include "alloy/string_buffer.h"
#include "poly/poly.h" #include "poly/poly.h"
#include "poly/string_buffer.h"
namespace alloy { namespace alloy {
namespace frontend { namespace frontend {
@ -23,7 +23,7 @@ namespace ppc {
std::vector<InstrType*> all_instrs_; std::vector<InstrType*> all_instrs_;
void DumpAllInstrCounts() { void DumpAllInstrCounts() {
StringBuffer sb; poly::StringBuffer sb;
sb.Append("Instruction translation counts:\n"); sb.Append("Instruction translation counts:\n");
for (auto instr_type : all_instrs_) { for (auto instr_type : all_instrs_) {
if (instr_type->translation_count) { if (instr_type->translation_count) {

View File

@ -14,9 +14,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace alloy { #include "poly/string_buffer.h"
class StringBuffer;
} // namespace alloy
namespace alloy { namespace alloy {
namespace frontend { namespace frontend {
@ -549,7 +547,7 @@ class InstrDisasm {
void Dump(std::string& out_str, size_t pad = 13); void Dump(std::string& out_str, size_t pad = 13);
}; };
typedef void (*InstrDisasmFn)(InstrData& i, StringBuffer* str); typedef void (*InstrDisasmFn)(InstrData& i, poly::StringBuffer* str);
typedef void* InstrEmitFn; typedef void* InstrEmitFn;
class InstrType { class InstrType {

View File

@ -14,81 +14,82 @@
#include "alloy/frontend/ppc/ppc_instr.h" #include "alloy/frontend/ppc/ppc_instr.h"
#include "poly/poly.h" #include "poly/poly.h"
#include "poly/string_buffer.h"
namespace alloy { namespace alloy {
namespace frontend { namespace frontend {
namespace ppc { namespace ppc {
void Disasm_0(InstrData& i, StringBuffer* str); void Disasm_0(InstrData& i, poly::StringBuffer* str);
void Disasm__(InstrData& i, StringBuffer* str); void Disasm__(InstrData& i, poly::StringBuffer* str);
void Disasm_X_FRT_FRB(InstrData& i, StringBuffer* str); void Disasm_X_FRT_FRB(InstrData& i, poly::StringBuffer* str);
void Disasm_A_FRT_FRB(InstrData& i, StringBuffer* str); void Disasm_A_FRT_FRB(InstrData& i, poly::StringBuffer* str);
void Disasm_A_FRT_FRA_FRB(InstrData& i, StringBuffer* str); void Disasm_A_FRT_FRA_FRB(InstrData& i, poly::StringBuffer* str);
void Disasm_A_FRT_FRA_FRB_FRC(InstrData& i, StringBuffer* str); void Disasm_A_FRT_FRA_FRB_FRC(InstrData& i, poly::StringBuffer* str);
void Disasm_X_RT_RA_RB(InstrData& i, StringBuffer* str); void Disasm_X_RT_RA_RB(InstrData& i, poly::StringBuffer* str);
void Disasm_X_RT_RA0_RB(InstrData& i, StringBuffer* str); void Disasm_X_RT_RA0_RB(InstrData& i, poly::StringBuffer* str);
void Disasm_X_FRT_RA_RB(InstrData& i, StringBuffer* str); void Disasm_X_FRT_RA_RB(InstrData& i, poly::StringBuffer* str);
void Disasm_X_FRT_RA0_RB(InstrData& i, StringBuffer* str); void Disasm_X_FRT_RA0_RB(InstrData& i, poly::StringBuffer* str);
void Disasm_D_RT_RA_I(InstrData& i, StringBuffer* str); void Disasm_D_RT_RA_I(InstrData& i, poly::StringBuffer* str);
void Disasm_D_RT_RA0_I(InstrData& i, StringBuffer* str); void Disasm_D_RT_RA0_I(InstrData& i, poly::StringBuffer* str);
void Disasm_D_FRT_RA_I(InstrData& i, StringBuffer* str); void Disasm_D_FRT_RA_I(InstrData& i, poly::StringBuffer* str);
void Disasm_D_FRT_RA0_I(InstrData& i, StringBuffer* str); void Disasm_D_FRT_RA0_I(InstrData& i, poly::StringBuffer* str);
void Disasm_DS_RT_RA_I(InstrData& i, StringBuffer* str); void Disasm_DS_RT_RA_I(InstrData& i, poly::StringBuffer* str);
void Disasm_DS_RT_RA0_I(InstrData& i, StringBuffer* str); void Disasm_DS_RT_RA0_I(InstrData& i, poly::StringBuffer* str);
void Disasm_D_RA(InstrData& i, StringBuffer* str); void Disasm_D_RA(InstrData& i, poly::StringBuffer* str);
void Disasm_X_RA_RB(InstrData& i, StringBuffer* str); void Disasm_X_RA_RB(InstrData& i, poly::StringBuffer* str);
void Disasm_XO_RT_RA_RB(InstrData& i, StringBuffer* str); void Disasm_XO_RT_RA_RB(InstrData& i, poly::StringBuffer* str);
void Disasm_XO_RT_RA(InstrData& i, StringBuffer* str); void Disasm_XO_RT_RA(InstrData& i, poly::StringBuffer* str);
void Disasm_X_RA_RT_RB(InstrData& i, StringBuffer* str); void Disasm_X_RA_RT_RB(InstrData& i, poly::StringBuffer* str);
void Disasm_D_RA_RT_I(InstrData& i, StringBuffer* str); void Disasm_D_RA_RT_I(InstrData& i, poly::StringBuffer* str);
void Disasm_X_RA_RT(InstrData& i, StringBuffer* str); void Disasm_X_RA_RT(InstrData& i, poly::StringBuffer* str);
void Disasm_X_VX_RA0_RB(InstrData& i, StringBuffer* str); void Disasm_X_VX_RA0_RB(InstrData& i, poly::StringBuffer* str);
void Disasm_VX1281_VD_RA0_RB(InstrData& i, StringBuffer* str); void Disasm_VX1281_VD_RA0_RB(InstrData& i, poly::StringBuffer* str);
void Disasm_VX1283_VD_VB(InstrData& i, StringBuffer* str); void Disasm_VX1283_VD_VB(InstrData& i, poly::StringBuffer* str);
void Disasm_VX1283_VD_VB_I(InstrData& i, StringBuffer* str); void Disasm_VX1283_VD_VB_I(InstrData& i, poly::StringBuffer* str);
void Disasm_VX_VD_VA_VB(InstrData& i, StringBuffer* str); void Disasm_VX_VD_VA_VB(InstrData& i, poly::StringBuffer* str);
void Disasm_VX128_VD_VA_VB(InstrData& i, StringBuffer* str); void Disasm_VX128_VD_VA_VB(InstrData& i, poly::StringBuffer* str);
void Disasm_VX128_VD_VA_VD_VB(InstrData& i, StringBuffer* str); void Disasm_VX128_VD_VA_VD_VB(InstrData& i, poly::StringBuffer* str);
void Disasm_VX1282_VD_VA_VB_VC(InstrData& i, StringBuffer* str); void Disasm_VX1282_VD_VA_VB_VC(InstrData& i, poly::StringBuffer* str);
void Disasm_VXA_VD_VA_VB_VC(InstrData& i, StringBuffer* str); void Disasm_VXA_VD_VA_VB_VC(InstrData& i, poly::StringBuffer* str);
void Disasm_sync(InstrData& i, StringBuffer* str); void Disasm_sync(InstrData& i, poly::StringBuffer* str);
void Disasm_dcbf(InstrData& i, StringBuffer* str); void Disasm_dcbf(InstrData& i, poly::StringBuffer* str);
void Disasm_dcbz(InstrData& i, StringBuffer* str); void Disasm_dcbz(InstrData& i, poly::StringBuffer* str);
void Disasm_fcmp(InstrData& i, StringBuffer* str); void Disasm_fcmp(InstrData& i, poly::StringBuffer* str);
void Disasm_bx(InstrData& i, StringBuffer* str); void Disasm_bx(InstrData& i, poly::StringBuffer* str);
void Disasm_bcx(InstrData& i, StringBuffer* str); void Disasm_bcx(InstrData& i, poly::StringBuffer* str);
void Disasm_bcctrx(InstrData& i, StringBuffer* str); void Disasm_bcctrx(InstrData& i, poly::StringBuffer* str);
void Disasm_bclrx(InstrData& i, StringBuffer* str); void Disasm_bclrx(InstrData& i, poly::StringBuffer* str);
void Disasm_mfcr(InstrData& i, StringBuffer* str); void Disasm_mfcr(InstrData& i, poly::StringBuffer* str);
void Disasm_mfspr(InstrData& i, StringBuffer* str); void Disasm_mfspr(InstrData& i, poly::StringBuffer* str);
void Disasm_mtspr(InstrData& i, StringBuffer* str); void Disasm_mtspr(InstrData& i, poly::StringBuffer* str);
void Disasm_mftb(InstrData& i, StringBuffer* str); void Disasm_mftb(InstrData& i, poly::StringBuffer* str);
void Disasm_mfmsr(InstrData& i, StringBuffer* str); void Disasm_mfmsr(InstrData& i, poly::StringBuffer* str);
void Disasm_mtmsr(InstrData& i, StringBuffer* str); void Disasm_mtmsr(InstrData& i, poly::StringBuffer* str);
void Disasm_cmp(InstrData& i, StringBuffer* str); void Disasm_cmp(InstrData& i, poly::StringBuffer* str);
void Disasm_cmpi(InstrData& i, StringBuffer* str); void Disasm_cmpi(InstrData& i, poly::StringBuffer* str);
void Disasm_cmpli(InstrData& i, StringBuffer* str); void Disasm_cmpli(InstrData& i, poly::StringBuffer* str);
void Disasm_rld(InstrData& i, StringBuffer* str); void Disasm_rld(InstrData& i, poly::StringBuffer* str);
void Disasm_rlwim(InstrData& i, StringBuffer* str); void Disasm_rlwim(InstrData& i, poly::StringBuffer* str);
void Disasm_rlwnmx(InstrData& i, StringBuffer* str); void Disasm_rlwnmx(InstrData& i, poly::StringBuffer* str);
void Disasm_srawix(InstrData& i, StringBuffer* str); void Disasm_srawix(InstrData& i, poly::StringBuffer* str);
void Disasm_sradix(InstrData& i, StringBuffer* str); void Disasm_sradix(InstrData& i, poly::StringBuffer* str);
void Disasm_vpermwi128(InstrData& i, StringBuffer* str); void Disasm_vpermwi128(InstrData& i, poly::StringBuffer* str);
void Disasm_vrfin128(InstrData& i, StringBuffer* str); void Disasm_vrfin128(InstrData& i, poly::StringBuffer* str);
void Disasm_vrlimi128(InstrData& i, StringBuffer* str); void Disasm_vrlimi128(InstrData& i, poly::StringBuffer* str);
void Disasm_vsldoi128(InstrData& i, StringBuffer* str); void Disasm_vsldoi128(InstrData& i, poly::StringBuffer* str);
void Disasm_vspltb(InstrData& i, StringBuffer* str); void Disasm_vspltb(InstrData& i, poly::StringBuffer* str);
void Disasm_vsplth(InstrData& i, StringBuffer* str); void Disasm_vsplth(InstrData& i, poly::StringBuffer* str);
void Disasm_vspltw(InstrData& i, StringBuffer* str); void Disasm_vspltw(InstrData& i, poly::StringBuffer* str);
void Disasm_vspltisb(InstrData& i, StringBuffer* str); void Disasm_vspltisb(InstrData& i, poly::StringBuffer* str);
void Disasm_vspltish(InstrData& i, StringBuffer* str); void Disasm_vspltish(InstrData& i, poly::StringBuffer* str);
void Disasm_vspltisw(InstrData& i, StringBuffer* str); void Disasm_vspltisw(InstrData& i, poly::StringBuffer* str);
namespace tables { namespace tables {

View File

@ -16,8 +16,8 @@
#include "alloy/frontend/ppc/ppc_hir_builder.h" #include "alloy/frontend/ppc/ppc_hir_builder.h"
#include "alloy/frontend/ppc/ppc_instr.h" #include "alloy/frontend/ppc/ppc_instr.h"
#include "alloy/frontend/ppc/ppc_scanner.h" #include "alloy/frontend/ppc/ppc_scanner.h"
#include "alloy/reset_scope.h"
#include "alloy/runtime/runtime.h" #include "alloy/runtime/runtime.h"
#include "poly/reset_scope.h"
#include "xenia/profiling.h" #include "xenia/profiling.h"
namespace alloy { namespace alloy {
@ -91,10 +91,10 @@ int PPCTranslator::Translate(FunctionInfo* symbol_info,
SCOPE_profile_cpu_f("alloy"); SCOPE_profile_cpu_f("alloy");
// Reset() all caching when we leave. // Reset() all caching when we leave.
make_reset_scope(builder_); poly::make_reset_scope(builder_);
make_reset_scope(compiler_); poly::make_reset_scope(compiler_);
make_reset_scope(assembler_); poly::make_reset_scope(assembler_);
make_reset_scope(&string_buffer_); poly::make_reset_scope(&string_buffer_);
// Scan the function to find its extents. We only need to do this if we // Scan the function to find its extents. We only need to do this if we
// haven't already been provided with them from some other source. // haven't already been provided with them from some other source.
@ -175,7 +175,7 @@ int PPCTranslator::Translate(FunctionInfo* symbol_info,
}; };
void PPCTranslator::DumpSource(runtime::FunctionInfo* symbol_info, void PPCTranslator::DumpSource(runtime::FunctionInfo* symbol_info,
StringBuffer* string_buffer) { poly::StringBuffer* string_buffer) {
Memory* memory = frontend_->memory(); Memory* memory = frontend_->memory();
const uint8_t* p = memory->membase(); const uint8_t* p = memory->membase();

View File

@ -15,7 +15,7 @@
#include "alloy/backend/assembler.h" #include "alloy/backend/assembler.h"
#include "alloy/compiler/compiler.h" #include "alloy/compiler/compiler.h"
#include "alloy/runtime/symbol_info.h" #include "alloy/runtime/symbol_info.h"
#include "alloy/string_buffer.h" #include "poly/string_buffer.h"
namespace alloy { namespace alloy {
namespace frontend { namespace frontend {
@ -35,7 +35,7 @@ class PPCTranslator {
private: private:
void DumpSource(runtime::FunctionInfo* symbol_info, void DumpSource(runtime::FunctionInfo* symbol_info,
StringBuffer* string_buffer); poly::StringBuffer* string_buffer);
private: private:
PPCFrontend* frontend_; PPCFrontend* frontend_;
@ -44,7 +44,7 @@ class PPCTranslator {
std::unique_ptr<compiler::Compiler> compiler_; std::unique_ptr<compiler::Compiler> compiler_;
std::unique_ptr<backend::Assembler> assembler_; std::unique_ptr<backend::Assembler> assembler_;
StringBuffer string_buffer_; poly::StringBuffer string_buffer_;
}; };
} // namespace ppc } // namespace ppc

View File

@ -10,7 +10,7 @@
#ifndef ALLOY_HIR_BLOCK_H_ #ifndef ALLOY_HIR_BLOCK_H_
#define ALLOY_HIR_BLOCK_H_ #define ALLOY_HIR_BLOCK_H_
#include "alloy/arena.h" #include "poly/arena.h"
namespace llvm { namespace llvm {
class BitVector; class BitVector;
@ -45,7 +45,7 @@ class Edge {
class Block { class Block {
public: public:
Arena* arena; poly::Arena* arena;
Block* next; Block* next;
Block* prev; Block* prev;

View File

@ -13,7 +13,6 @@
#include "alloy/hir/instr.h" #include "alloy/hir/instr.h"
#include "alloy/hir/label.h" #include "alloy/hir/label.h"
#include "alloy/runtime/symbol_info.h" #include "alloy/runtime/symbol_info.h"
#include "alloy/string_buffer.h"
#include "xenia/profiling.h" #include "xenia/profiling.h"
namespace alloy { namespace alloy {
@ -30,7 +29,7 @@ using alloy::runtime::FunctionInfo;
assert_true((value1->type) == (value2->type)) assert_true((value1->type) == (value2->type))
HIRBuilder::HIRBuilder() { HIRBuilder::HIRBuilder() {
arena_ = new Arena(); arena_ = new poly::Arena();
Reset(); Reset();
} }
@ -90,7 +89,7 @@ int HIRBuilder::Finalize() {
return 0; return 0;
} }
void HIRBuilder::DumpValue(StringBuffer* str, Value* value) { void HIRBuilder::DumpValue(poly::StringBuffer* str, Value* value) {
if (value->IsConstant()) { if (value->IsConstant()) {
switch (value->type) { switch (value->type) {
case INT8_TYPE: case INT8_TYPE:
@ -131,7 +130,7 @@ void HIRBuilder::DumpValue(StringBuffer* str, Value* value) {
} }
} }
void HIRBuilder::DumpOp(StringBuffer* str, OpcodeSignatureType sig_type, void HIRBuilder::DumpOp(poly::StringBuffer* str, OpcodeSignatureType sig_type,
Instr::Op* op) { Instr::Op* op) {
switch (sig_type) { switch (sig_type) {
case OPCODE_SIG_TYPE_X: case OPCODE_SIG_TYPE_X:
@ -158,7 +157,7 @@ void HIRBuilder::DumpOp(StringBuffer* str, OpcodeSignatureType sig_type,
} }
} }
void HIRBuilder::Dump(StringBuffer* str) { void HIRBuilder::Dump(poly::StringBuffer* str) {
SCOPE_profile_cpu_f("alloy"); SCOPE_profile_cpu_f("alloy");
if (attributes_) { if (attributes_) {
@ -1910,12 +1909,12 @@ Value* HIRBuilder::Pack(Value* value1, Value* value2, uint32_t pack_flags) {
ASSERT_VECTOR_TYPE(value1); ASSERT_VECTOR_TYPE(value1);
ASSERT_VECTOR_TYPE(value2); ASSERT_VECTOR_TYPE(value2);
switch (pack_flags & PACK_TYPE_MODE) { switch (pack_flags & PACK_TYPE_MODE) {
case PACK_TYPE_D3DCOLOR: case PACK_TYPE_D3DCOLOR:
case PACK_TYPE_FLOAT16_2: case PACK_TYPE_FLOAT16_2:
case PACK_TYPE_FLOAT16_4: case PACK_TYPE_FLOAT16_4:
case PACK_TYPE_SHORT_2: case PACK_TYPE_SHORT_2:
assert_true(value2->IsConstantZero()); assert_true(value2->IsConstantZero());
break; break;
} }
Instr* i = AppendInstr(OPCODE_PACK_info, pack_flags, AllocValue(VEC128_TYPE)); Instr* i = AppendInstr(OPCODE_PACK_info, pack_flags, AllocValue(VEC128_TYPE));
i->set_src1(value1); i->set_src1(value1);

View File

@ -17,10 +17,8 @@
#include "alloy/hir/label.h" #include "alloy/hir/label.h"
#include "alloy/hir/opcodes.h" #include "alloy/hir/opcodes.h"
#include "alloy/hir/value.h" #include "alloy/hir/value.h"
#include "poly/arena.h"
namespace alloy { #include "poly/string_buffer.h"
class StringBuffer;
} // namespace alloy
namespace alloy { namespace alloy {
namespace hir { namespace hir {
@ -37,10 +35,10 @@ class HIRBuilder {
virtual void Reset(); virtual void Reset();
virtual int Finalize(); virtual int Finalize();
void Dump(StringBuffer* str); void Dump(poly::StringBuffer* str);
void AssertNoCycles(); void AssertNoCycles();
Arena* arena() const { return arena_; } poly::Arena* arena() const { return arena_; }
uint32_t attributes() const { return attributes_; } uint32_t attributes() const { return attributes_; }
void set_attributes(uint32_t value) { attributes_ = value; } void set_attributes(uint32_t value) { attributes_ = value; }
@ -230,8 +228,9 @@ class HIRBuilder {
Value* AtomicSub(Value* address, Value* value); Value* AtomicSub(Value* address, Value* value);
protected: protected:
void DumpValue(StringBuffer* str, Value* value); void DumpValue(poly::StringBuffer* str, Value* value);
void DumpOp(StringBuffer* str, OpcodeSignatureType sig_type, Instr::Op* op); void DumpOp(poly::StringBuffer* str, OpcodeSignatureType sig_type,
Instr::Op* op);
Value* AllocValue(TypeName type = INT64_TYPE); Value* AllocValue(TypeName type = INT64_TYPE);
Value* CloneValue(Value* source); Value* CloneValue(Value* source);
@ -246,7 +245,7 @@ class HIRBuilder {
TypeName part_type); TypeName part_type);
protected: protected:
Arena* arena_; poly::Arena* arena_;
uint32_t attributes_; uint32_t attributes_;

View File

@ -14,7 +14,7 @@
namespace alloy { namespace alloy {
namespace hir { namespace hir {
Value::Use* Value::AddUse(Arena* arena, Instr* instr) { Value::Use* Value::AddUse(poly::Arena* arena, Instr* instr) {
Use* use = arena->Alloc<Use>(); Use* use = arena->Alloc<Use>();
use->instr = instr; use->instr = instr;
use->prev = NULL; use->prev = NULL;

View File

@ -10,17 +10,19 @@
#ifndef ALLOY_HIR_VALUE_H_ #ifndef ALLOY_HIR_VALUE_H_
#define ALLOY_HIR_VALUE_H_ #define ALLOY_HIR_VALUE_H_
#include "alloy/arena.h"
#include "alloy/backend/machine_info.h" #include "alloy/backend/machine_info.h"
#include "alloy/hir/opcodes.h" #include "alloy/hir/opcodes.h"
#include "alloy/vec128.h" #include "poly/arena.h"
#include "poly/poly.h" #include "poly/poly.h"
#include "poly/vec128.h"
namespace alloy { namespace alloy {
namespace hir { namespace hir {
class Instr; class Instr;
using vec128_t = poly::vec128_t;
enum TypeName { enum TypeName {
// Many tables rely on this ordering. // Many tables rely on this ordering.
INT8_TYPE = 0, INT8_TYPE = 0,
@ -99,7 +101,7 @@ class Value {
// TODO(benvanik): remove to shrink size. // TODO(benvanik): remove to shrink size.
void* tag; void* tag;
Use* AddUse(Arena* arena, Instr* instr); Use* AddUse(poly::Arena* arena, Instr* instr);
void RemoveUse(Use* use); void RemoveUse(Use* use);
int8_t get_constant(int8_t) const { return constant.i8; } int8_t get_constant(int8_t) const { return constant.i8; }

View File

@ -12,6 +12,7 @@
#include "alloy/runtime/debugger.h" #include "alloy/runtime/debugger.h"
#include "alloy/runtime/symbol_info.h" #include "alloy/runtime/symbol_info.h"
#include "alloy/runtime/thread_state.h" #include "alloy/runtime/thread_state.h"
#include "poly/logging.h"
#include "xdb/protocol.h" #include "xdb/protocol.h"
namespace alloy { namespace alloy {

View File

@ -10,9 +10,9 @@
#include "alloy/runtime/test_module.h" #include "alloy/runtime/test_module.h"
#include "alloy/compiler/compiler_passes.h" #include "alloy/compiler/compiler_passes.h"
#include "alloy/reset_scope.h"
#include "alloy/runtime/runtime.h" #include "alloy/runtime/runtime.h"
#include "poly/platform.h" #include "poly/platform.h"
#include "poly/reset_scope.h"
#include "poly/string.h" #include "poly/string.h"
namespace alloy { namespace alloy {
@ -79,8 +79,8 @@ SymbolInfo::Status TestModule::DeclareFunction(uint64_t address,
auto symbol_info = *out_symbol_info; auto symbol_info = *out_symbol_info;
// Reset() all caching when we leave. // Reset() all caching when we leave.
make_reset_scope(compiler_); poly::make_reset_scope(compiler_);
make_reset_scope(assembler_); poly::make_reset_scope(assembler_);
if (!generate_(*builder_.get())) { if (!generate_(*builder_.get())) {
symbol_info->set_status(SymbolInfo::STATUS_FAILED); symbol_info->set_status(SymbolInfo::STATUS_FAILED);

View File

@ -4,15 +4,8 @@
'alloy-private.h', 'alloy-private.h',
'alloy.cc', 'alloy.cc',
'alloy.h', 'alloy.h',
'arena.cc',
'arena.h',
'memory.cc', 'memory.cc',
'memory.h', 'memory.h',
'reset_scope.h',
'string_buffer.cc',
'string_buffer.h',
'type_pool.h',
'vec128.h',
], ],
'conditions': [ 'conditions': [

View File

@ -14,6 +14,7 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using namespace alloy::test; using namespace alloy::test;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
using namespace poly;
TEST_CASE("BYTE_SWAP_V128", "[instr]") { TEST_CASE("BYTE_SWAP_V128", "[instr]") {
TestFunction([](hir::HIRBuilder& b) { TestFunction([](hir::HIRBuilder& b) {

View File

@ -16,6 +16,7 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using namespace alloy::test; using namespace alloy::test;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
using namespace poly;
TEST_CASE("EXTRACT_INT8", "[instr]") { TEST_CASE("EXTRACT_INT8", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) { TestFunction test([](hir::HIRBuilder& b) {

View File

@ -16,6 +16,7 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using namespace alloy::test; using namespace alloy::test;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
using namespace poly;
TEST_CASE("INSERT_INT8", "[instr]") { TEST_CASE("INSERT_INT8", "[instr]") {
for (int i = 0; i < 16; ++i) { for (int i = 0; i < 16; ++i) {

View File

@ -14,6 +14,7 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using namespace alloy::test; using namespace alloy::test;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
using namespace poly;
TEST_CASE("LOAD_VECTOR_SHL", "[instr]") { TEST_CASE("LOAD_VECTOR_SHL", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) { TestFunction test([](hir::HIRBuilder& b) {

View File

@ -14,6 +14,7 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using namespace alloy::test; using namespace alloy::test;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
using namespace poly;
TEST_CASE("PACK_D3DCOLOR", "[instr]") { TEST_CASE("PACK_D3DCOLOR", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) { TestFunction test([](hir::HIRBuilder& b) {

View File

@ -14,6 +14,7 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using namespace alloy::test; using namespace alloy::test;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
using namespace poly;
TEST_CASE("PERMUTE_V128_BY_INT32_CONSTANT", "[instr]") { TEST_CASE("PERMUTE_V128_BY_INT32_CONSTANT", "[instr]") {
{ {

View File

@ -14,6 +14,7 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using namespace alloy::test; using namespace alloy::test;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
using namespace poly;
TEST_CASE("SHR_I8", "[instr]") { TEST_CASE("SHR_I8", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) { TestFunction test([](hir::HIRBuilder& b) {

View File

@ -14,6 +14,7 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using namespace alloy::test; using namespace alloy::test;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
using namespace poly;
TEST_CASE("SWIZZLE_V128", "[instr]") { TEST_CASE("SWIZZLE_V128", "[instr]") {
TestFunction([](hir::HIRBuilder& b) { TestFunction([](hir::HIRBuilder& b) {

View File

@ -14,6 +14,7 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using namespace alloy::test; using namespace alloy::test;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
using namespace poly;
TEST_CASE("UNPACK_D3DCOLOR", "[instr]") { TEST_CASE("UNPACK_D3DCOLOR", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) { TestFunction test([](hir::HIRBuilder& b) {

View File

@ -16,6 +16,7 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using namespace alloy::test; using namespace alloy::test;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
using namespace poly;
TEST_CASE("VECTOR_ADD_I8", "[instr]") { TEST_CASE("VECTOR_ADD_I8", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) { TestFunction test([](hir::HIRBuilder& b) {

View File

@ -16,6 +16,7 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using namespace alloy::test; using namespace alloy::test;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
using namespace poly;
TEST_CASE("VECTOR_MAX_I8_SIGNED", "[instr]") { TEST_CASE("VECTOR_MAX_I8_SIGNED", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) { TestFunction test([](hir::HIRBuilder& b) {

View File

@ -16,6 +16,7 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using namespace alloy::test; using namespace alloy::test;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
using namespace poly;
TEST_CASE("VECTOR_MIN_I8_SIGNED", "[instr]") { TEST_CASE("VECTOR_MIN_I8_SIGNED", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) { TestFunction test([](hir::HIRBuilder& b) {

View File

@ -15,6 +15,7 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using namespace alloy::test; using namespace alloy::test;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
using namespace poly;
TEST_CASE("VECTOR_ROTATE_LEFT_I8", "[instr]") { TEST_CASE("VECTOR_ROTATE_LEFT_I8", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) { TestFunction test([](hir::HIRBuilder& b) {

View File

@ -14,6 +14,7 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using namespace alloy::test; using namespace alloy::test;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
using namespace poly;
TEST_CASE("VECTOR_SHA_I8", "[instr]") { TEST_CASE("VECTOR_SHA_I8", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) { TestFunction test([](hir::HIRBuilder& b) {

View File

@ -14,6 +14,7 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using namespace alloy::test; using namespace alloy::test;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
using namespace poly;
TEST_CASE("VECTOR_SHL_I8", "[instr]") { TEST_CASE("VECTOR_SHL_I8", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) { TestFunction test([](hir::HIRBuilder& b) {

View File

@ -14,6 +14,7 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
using namespace alloy::test; using namespace alloy::test;
using alloy::frontend::ppc::PPCContext; using alloy::frontend::ppc::PPCContext;
using namespace poly;
TEST_CASE("VECTOR_SHR_I8", "[instr]") { TEST_CASE("VECTOR_SHR_I8", "[instr]") {
TestFunction test([](hir::HIRBuilder& b) { TestFunction test([](hir::HIRBuilder& b) {

View File

@ -7,11 +7,13 @@
****************************************************************************** ******************************************************************************
*/ */
#include "alloy/arena.h" #include "poly/arena.h"
#include "poly/poly.h" #include <memory>
namespace alloy { #include "poly/assert.h"
namespace poly {
Arena::Arena(size_t chunk_size) Arena::Arena(size_t chunk_size)
: chunk_size_(chunk_size), head_chunk_(nullptr), active_chunk_(nullptr) {} : chunk_size_(chunk_size), head_chunk_(nullptr), active_chunk_(nullptr) {}
@ -37,7 +39,7 @@ void Arena::Reset() {
void Arena::DebugFill() { void Arena::DebugFill() {
auto chunk = head_chunk_; auto chunk = head_chunk_;
while (chunk) { while (chunk) {
memset(chunk->buffer, 0xCD, chunk->capacity); std::memset(chunk->buffer, 0xCD, chunk->capacity);
chunk = chunk->next; chunk = chunk->next;
} }
} }
@ -77,7 +79,7 @@ void* Arena::CloneContents() {
uint8_t* p = (uint8_t*)result; uint8_t* p = (uint8_t*)result;
chunk = head_chunk_; chunk = head_chunk_;
while (chunk) { while (chunk) {
memcpy(p, chunk->buffer, chunk->offset); std::memcpy(p, chunk->buffer, chunk->offset);
p += chunk->offset; p += chunk->offset;
if (chunk == active_chunk_) { if (chunk == active_chunk_) {
break; break;
@ -98,4 +100,4 @@ Arena::Chunk::~Chunk() {
} }
} }
} // namespace alloy } // namespace poly

View File

@ -7,13 +7,13 @@
****************************************************************************** ******************************************************************************
*/ */
#ifndef ALLOY_ARENA_H_ #ifndef POLY_ARENA_H_
#define ALLOY_ARENA_H_ #define POLY_ARENA_H_
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
namespace alloy { namespace poly {
class Arena { class Arena {
public: public:
@ -50,6 +50,6 @@ class Arena {
Chunk* active_chunk_; Chunk* active_chunk_;
}; };
} // namespace alloy } // namespace poly
#endif // ALLOY_ARENA_H_ #endif // POLY_ARENA_H_

View File

@ -23,6 +23,7 @@
#include "poly/platform.h" #include "poly/platform.h"
#include "poly/string.h" #include "poly/string.h"
#include "poly/threading.h" #include "poly/threading.h"
#include "poly/vec128.h"
namespace poly {} // namespace poly namespace poly {} // namespace poly

View File

@ -7,12 +7,12 @@
****************************************************************************** ******************************************************************************
*/ */
#ifndef ALLOY_RESET_SCOPE_H_ #ifndef POLY_RESET_SCOPE_H_
#define ALLOY_RESET_SCOPE_H_ #define POLY_RESET_SCOPE_H_
#include <mutex> #include <mutex>
namespace alloy { namespace poly {
template <typename T> template <typename T>
class ResetScope { class ResetScope {
@ -38,6 +38,6 @@ inline ResetScope<T> make_reset_scope(const std::unique_ptr<T>& value) {
return ResetScope<T>(value.get()); return ResetScope<T>(value.get());
} }
} // namespace alloy } // namespace poly
#endif // ALLOY_RESET_SCOPE_H_ #endif // POLY_RESET_SCOPE_H_

View File

@ -1,6 +1,8 @@
# Copyright 2014 Ben Vanik. All Rights Reserved. # Copyright 2014 Ben Vanik. All Rights Reserved.
{ {
'sources': [ 'sources': [
'arena.cc',
'arena.h',
'assert.h', 'assert.h',
'atomic.h', 'atomic.h',
'byte_order.h', 'byte_order.h',
@ -20,10 +22,15 @@
'memory.h', 'memory.h',
'platform.h', 'platform.h',
'poly.h', 'poly.h',
'reset_scope.h',
'string.cc', 'string.cc',
'string.h', 'string.h',
'string_buffer.cc',
'string_buffer.h',
'threading.cc', 'threading.cc',
'threading.h', 'threading.h',
'type_pool.h',
'vec128.h',
], ],
'conditions': [ 'conditions': [

View File

@ -7,12 +7,12 @@
****************************************************************************** ******************************************************************************
*/ */
#include "alloy/string_buffer.h" #include "poly/string_buffer.h"
#include <algorithm> #include <algorithm>
#include <cstdarg> #include <cstdarg>
namespace alloy { namespace poly {
StringBuffer::StringBuffer(size_t initial_capacity) { StringBuffer::StringBuffer(size_t initial_capacity) {
buffer_.reserve(std::max(initial_capacity, static_cast<size_t>(1024))); buffer_.reserve(std::max(initial_capacity, static_cast<size_t>(1024)));
@ -62,8 +62,10 @@ void StringBuffer::AppendBytes(const uint8_t* buffer, size_t length) {
const char* StringBuffer::GetString() const { return buffer_.data(); } const char* StringBuffer::GetString() const { return buffer_.data(); }
std::string StringBuffer::to_string() { return std::string(buffer_.data(), buffer_.size()); } std::string StringBuffer::to_string() {
return std::string(buffer_.data(), buffer_.size());
}
char* StringBuffer::ToString() { return strdup(buffer_.data()); } char* StringBuffer::ToString() { return strdup(buffer_.data()); }
} // namespace alloy } // namespace poly

View File

@ -7,14 +7,14 @@
****************************************************************************** ******************************************************************************
*/ */
#ifndef ALLOY_STRING_BUFFER_H_ #ifndef POLY_STRING_BUFFER_H_
#define ALLOY_STRING_BUFFER_H_ #define POLY_STRING_BUFFER_H_
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <vector> #include <vector>
namespace alloy { namespace poly {
class StringBuffer { class StringBuffer {
public: public:
@ -41,6 +41,6 @@ class StringBuffer {
std::vector<char> buffer_; std::vector<char> buffer_;
}; };
} // namespace alloy } // namespace poly
#endif // ALLOY_STRING_BUFFER_H_ #endif // POLY_STRING_BUFFER_H_

View File

@ -7,13 +7,13 @@
****************************************************************************** ******************************************************************************
*/ */
#ifndef ALLOY_TYPE_POOL_H_ #ifndef POLY_TYPE_POOL_H_
#define ALLOY_TYPE_POOL_H_ #define POLY_TYPE_POOL_H_
#include <mutex> #include <mutex>
#include <vector> #include <vector>
namespace alloy { namespace poly {
template <class T, typename A> template <class T, typename A>
class TypePool { class TypePool {
@ -54,6 +54,6 @@ class TypePool {
std::vector<T*> list_; std::vector<T*> list_;
}; };
} // namespace alloy } // namespace poly
#endif // ALLOY_TYPE_POOL_H_ #endif // POLY_TYPE_POOL_H_

View File

@ -7,12 +7,12 @@
****************************************************************************** ******************************************************************************
*/ */
#ifndef ALLOY_VEC128_H_ #ifndef POLY_VEC128_H_
#define ALLOY_VEC128_H_ #define POLY_VEC128_H_
#include "poly/poly.h" #include <cstddef>
namespace alloy { namespace poly {
// The first rule of vector programming is to only rely on exact positions // The first rule of vector programming is to only rely on exact positions
// when absolutely required - prefer dumb loops to exact offsets. // when absolutely required - prefer dumb loops to exact offsets.
@ -191,6 +191,6 @@ static inline vec128_t vec128b(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3,
return v; return v;
} }
} // namespace alloy } // namespace poly
#endif // ALLOY_VEC128_H_ #endif // POLY_VEC128_H_

View File

@ -12,13 +12,13 @@
#include <cstdint> #include <cstdint>
#include <alloy/vec128.h> #include "poly/atomic.h"
#include <poly/atomic.h> #include "poly/vec128.h"
namespace xdb { namespace xdb {
namespace protocol { namespace protocol {
using vec128_t = alloy::vec128_t; using vec128_t = poly::vec128_t;
#pragma pack(push, 4) #pragma pack(push, 4)
@ -96,7 +96,7 @@ struct Registers {
uint32_t vscr; uint32_t vscr;
uint64_t gpr[32]; uint64_t gpr[32];
double fpr[32]; double fpr[32];
alloy::vec128_t vr[128]; poly::vec128_t vr[128];
}; };
struct ThreadCreateEvent : public Event<ThreadCreateEvent> { struct ThreadCreateEvent : public Event<ThreadCreateEvent> {

View File

@ -12,7 +12,7 @@
#include <string> #include <string>
#include "alloy/string_buffer.h" #include "poly/string_buffer.h"
#include "xenia/common.h" #include "xenia/common.h"
#include "xenia/gpu/gl4/gl_context.h" #include "xenia/gpu/gl4/gl_context.h"
#include "xenia/gpu/gl4/gl4_shader.h" #include "xenia/gpu/gl4/gl4_shader.h"
@ -42,7 +42,7 @@ class GL4ShaderTranslator {
const uint32_t* dwords_; const uint32_t* dwords_;
static const int kOutputCapacity = 64 * 1024; static const int kOutputCapacity = 64 * 1024;
alloy::StringBuffer output_; poly::StringBuffer output_;
bool is_vertex_shader() const { return shader_type_ == ShaderType::kVertex; } bool is_vertex_shader() const { return shader_type_ == ShaderType::kVertex; }
bool is_pixel_shader() const { return shader_type_ == ShaderType::kPixel; } bool is_pixel_shader() const { return shader_type_ == ShaderType::kPixel; }