2020-09-05 16:37:37 -04:00
|
|
|
#include "Val.h"
|
2020-09-06 12:45:31 -04:00
|
|
|
#include "Env.h"
|
2020-09-05 16:37:37 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Fallback to_gpr if a more optimized one is not provided.
|
|
|
|
*/
|
2020-09-05 18:55:07 -04:00
|
|
|
const RegVal* Val::to_gpr(FunctionEnv* fe) const {
|
2020-09-06 12:45:31 -04:00
|
|
|
auto rv = to_reg(fe);
|
|
|
|
if(rv->ireg().kind == emitter::RegKind::GPR) {
|
|
|
|
return rv;
|
|
|
|
} else {
|
|
|
|
throw std::runtime_error("Val::to_gpr NYI"); // todo
|
|
|
|
}
|
2020-09-05 16:37:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Fallback to_xmm if a more optimized one is not provided.
|
|
|
|
*/
|
2020-09-05 18:55:07 -04:00
|
|
|
const RegVal* Val::to_xmm(FunctionEnv* fe) const {
|
2020-09-05 16:37:37 -04:00
|
|
|
(void)fe;
|
2020-09-05 18:55:07 -04:00
|
|
|
throw std::runtime_error("Val::to_xmm NYI"); // todo
|
2020-09-05 16:37:37 -04:00
|
|
|
}
|
|
|
|
|
2020-09-05 18:55:07 -04:00
|
|
|
|
|
|
|
const RegVal* RegVal::to_reg(FunctionEnv* fe) const {
|
|
|
|
(void)fe;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const RegVal * RegVal::to_gpr(FunctionEnv* fe) const {
|
2020-09-05 16:37:37 -04:00
|
|
|
(void)fe;
|
2020-09-05 18:55:07 -04:00
|
|
|
if(m_ireg.kind == emitter::RegKind::GPR) {
|
|
|
|
return this;
|
|
|
|
} else {
|
|
|
|
throw std::runtime_error("RegVal::to_gpr NYI"); // todo
|
|
|
|
}
|
2020-09-05 16:37:37 -04:00
|
|
|
}
|
2020-09-05 18:55:07 -04:00
|
|
|
|
|
|
|
const RegVal * RegVal::to_xmm(FunctionEnv* fe) const {
|
|
|
|
(void)fe;
|
|
|
|
if(m_ireg.kind == emitter::RegKind::XMM) {
|
|
|
|
return this;
|
|
|
|
} else {
|
|
|
|
throw std::runtime_error("RegVal::to_xmm NYI"); // todo
|
|
|
|
}
|
2020-09-06 12:45:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const RegVal * IntegerConstantVal::to_reg(FunctionEnv* fe) const {
|
|
|
|
auto rv = fe->make_gpr(m_ts);
|
|
|
|
fe->emit(std::make_unique<IR_LoadConstant64>(rv, m_value));
|
|
|
|
return rv;
|
2020-09-05 18:55:07 -04:00
|
|
|
}
|