Files
jak-project/goalc/regalloc/Assignment.h
T
water111 90a7e9b4b9 Add addition and subtraction for integers, build macros, dgo building, and build/load test (#35)
* see if math works on windows

* add dgo

* windows debug

* windows debug 2

* one more debug try

* add extra debug print and change logic for slashes

* update

* again

* try again

* remove build game

* remove build game

* add back build-game

* remove runtime from test

* test

* reduce number of files

* go to c++ 14

* big stacks

* increase stack size again

* clean up cmake files
2020-09-12 20:41:12 -04:00

47 lines
1.2 KiB
C++

#ifndef JAK_ASSIGNMENT_H
#define JAK_ASSIGNMENT_H
#include "third-party/fmt/core.h"
#include "goalc/emitter/Register.h"
/*!
* The assignment of an IRegister to a real Register.
* For a single IR Instruction.
*/
struct Assignment {
enum class Kind { STACK, REGISTER, UNASSIGNED } kind = Kind::UNASSIGNED;
emitter::Register reg = -1; //! where the IRegister is now
int stack_slot = -1; //! index of the slot, if we are ever spilled
bool spilled = false; //! are we ever spilled
std::string to_string() const {
std::string result;
if (spilled) {
result += "*";
}
switch (kind) {
case Kind::STACK:
result += fmt::format("s[{:2d}]", stack_slot);
break;
case Kind::REGISTER:
result += emitter::gRegInfo.get_info(reg).name;
break;
case Kind::UNASSIGNED:
result += "unassigned";
break;
default:
assert(false);
}
return result;
}
bool occupies_same_reg(const Assignment& other) const { return other.reg == reg && (reg != -1); }
bool occupies_reg(emitter::Register other_reg) const { return reg == other_reg && (reg != -1); }
bool is_assigned() const { return kind != Kind::UNASSIGNED; }
};
#endif // JAK_ASSIGNMENT_H