mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2026-01-07 06:58:15 +01:00
ir: separate components out a little more
This commit is contained in:
parent
9690d1423d
commit
841098a0bc
21 changed files with 617 additions and 508 deletions
85
src/frontend/ir/microinstruction.cpp
Normal file
85
src/frontend/ir/microinstruction.cpp
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/* This file is part of the dynarmic project.
|
||||
* Copyright (c) 2016 MerryMage
|
||||
* This software may be used and distributed according to the terms of the GNU
|
||||
* General Public License version 2 or any later version.
|
||||
*/
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "frontend/ir/microinstruction.h"
|
||||
|
||||
namespace Dynarmic {
|
||||
namespace IR {
|
||||
|
||||
Value Inst::GetArg(size_t index) const {
|
||||
DEBUG_ASSERT(index < GetNumArgsOf(op));
|
||||
DEBUG_ASSERT(!args[index].IsEmpty());
|
||||
|
||||
return args[index];
|
||||
}
|
||||
|
||||
void Inst::SetArg(size_t index, Value value) {
|
||||
DEBUG_ASSERT(index < GetNumArgsOf(op));
|
||||
DEBUG_ASSERT(value.GetType() == GetArgTypeOf(op, index) || Type::Opaque == GetArgTypeOf(op, index));
|
||||
|
||||
if (!args[index].IsImmediate()) {
|
||||
UndoUse(args[index]);
|
||||
}
|
||||
if (!value.IsImmediate()) {
|
||||
Use(value);
|
||||
}
|
||||
|
||||
args[index] = value;
|
||||
}
|
||||
|
||||
void Inst::Invalidate() {
|
||||
for (auto& value : args) {
|
||||
if (!value.IsImmediate()) {
|
||||
UndoUse(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Inst::ReplaceUsesWith(Value& replacement) {
|
||||
Invalidate();
|
||||
|
||||
op = Opcode::Identity;
|
||||
|
||||
if (!replacement.IsImmediate()) {
|
||||
Use(replacement);
|
||||
}
|
||||
|
||||
args[0] = replacement;
|
||||
}
|
||||
|
||||
void Inst::Use(Value& value) {
|
||||
value.GetInst()->use_count++;
|
||||
|
||||
switch (op){
|
||||
case Opcode::GetCarryFromOp:
|
||||
value.GetInst()->carry_inst = this;
|
||||
break;
|
||||
case Opcode::GetOverflowFromOp:
|
||||
value.GetInst()->overflow_inst = this;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Inst::UndoUse(Value& value) {
|
||||
value.GetInst()->use_count--;
|
||||
|
||||
switch (op){
|
||||
case Opcode::GetCarryFromOp:
|
||||
value.GetInst()->carry_inst = nullptr;
|
||||
break;
|
||||
case Opcode::GetOverflowFromOp:
|
||||
value.GetInst()->overflow_inst = nullptr;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace IR
|
||||
} // namespace Dynarmic
|
||||
Loading…
Add table
Add a link
Reference in a new issue