HIR->LIR flow.

This commit is contained in:
Ben Vanik
2013-12-29 23:51:51 -08:00
parent cd9172ed62
commit 08cff81f6a
11 changed files with 394 additions and 52 deletions

View File

@@ -395,46 +395,6 @@ public:
#include <alloy/backend/x64/lowering/lowering_lir_opcodes.inl>
}
enum {
REG8, REG16, REG32, REG64, REGXMM,
AL, AX, EAX, RAX,
BL, BX, EBX, RBX,
CL, CX, ECX, RCX,
DL, DX, EDX, RDX,
R8B, R8W, R8D, R8,
R9B, R9W, R9D, R9,
R10B, R10W, R10D, R10,
R11B, R11W, R11D, R11,
R12B, R12W, R12D, R12,
R13B, R13W, R13D, R13,
R14B, R14W, R14D, R14,
R15B, R15W, R15D, R15,
SIL, SI, ESI, RSI,
DIL, DI, EDI, RDI,
RBP,
RSP,
XMM0,
XMM1,
XMM2,
XMM3,
XMM4,
XMM5,
XMM6,
XMM7,
XMM8,
XMM9,
XMM10,
XMM11,
XMM12,
XMM13,
XMM14,
XMM15,
};
void alloy::backend::x64::lowering::RegisterSequences(LoweringTable* table) {
Translate<tuple<

View File

@@ -43,14 +43,60 @@ void LoweringTable::AddSequence(hir::Opcode starting_opcode, FnWrapper* fn) {
lookup_[starting_opcode] = fn;
}
int LoweringTable::Process(lir::LIRBuilder* builder) {
/*LIRInstr* instr = 0;
auto fn = lookup_[instr->opcode->num];
while (fn) {
if ((*fn)(builder, instr)) {
return true;
int LoweringTable::Process(
hir::HIRBuilder* hir_builder, lir::LIRBuilder* lir_builder) {
lir_builder->EndBlock();
// Translate all labels ahead of time.
// We stash them on tags to make things easier later on.
auto hir_block = hir_builder->first_block();
while (hir_block) {
auto hir_label = hir_block->label_head;
while (hir_label) {
// TODO(benvanik): copy name to LIR label.
hir_label->tag = lir_builder->NewLabel();
hir_label = hir_label->next;
}
fn = fn->next;
}*/
hir_block = hir_block->next;
}
// Process each block.
hir_block = hir_builder->first_block();
while (hir_block) {
// Force a new block.
lir_builder->AppendBlock();
// Mark labels.
auto hir_label = hir_block->label_head;
while (hir_label) {
auto lir_label = (lir::LIRLabel*)hir_label->tag;
lir_builder->MarkLabel(lir_label);
hir_label = hir_label->next;
}
// Process instructions.
auto hir_instr = hir_block->instr_head;
while (hir_instr) {
bool processed = false;
auto fn = lookup_[hir_instr->opcode->num];
while (fn) {
if ((*fn)(lir_builder, hir_instr)) {
processed = true;
break;
}
fn = fn->next;
}
if (!processed) {
// No sequence found!
XELOGE("Unable to process HIR opcode %s", hir_instr->opcode->name);
return 1;
hir_instr = hir_instr->next;
}
}
lir_builder->EndBlock();
hir_block = hir_block->next;
}
return 0;
}

View File

@@ -11,15 +11,15 @@
#define ALLOY_BACKEND_X64_X64_LOWERING_LOWERING_TABLE_H_
#include <alloy/core.h>
#include <alloy/backend/x64/lir/lir_builder.h>
#include <alloy/backend/x64/lir/lir_instr.h>
#include <alloy/hir/instr.h>
#include <alloy/hir/hir_builder.h>
namespace alloy {
namespace backend {
namespace x64 {
class X64Backend;
namespace lir { class LIRBuilder; }
namespace lowering {
@@ -30,7 +30,7 @@ public:
int Initialize();
int Process(lir::LIRBuilder* builder);
int Process(hir::HIRBuilder* hir_builder, lir::LIRBuilder* lir_builder);
public:
class FnWrapper {