dsp-asm/ins.hpp
Zack Buhman ddf46ce8fd stmt_ins: refactor
The overall intent is to make writing a decompiler require less code
duplication.

"bits.hpp" and "stmt_enum.hpp" are replaced with "stmt_ins.hpp" which
is generated directly from dsp-notes.csv.
2023-09-03 04:46:34 +00:00

46 lines
669 B
C++

#pragma once
#include <cstdint>
#include "imm.hpp"
namespace dsp {
template <typename T>
struct ins_t
{
/*
virtual uint32_t bits() const;
uint32_t render() const
{
return T::code() | bits();
}
*/
static bool pred(uint32_t ins)
{
return (ins & T::mask()) == T::code();
}
};
template <typename T, int N>
struct ins_imm_t : ins_t<T>
{
ins_imm_t(uimm_t<N> imm)
: imm(imm) {}
const uimm_t<N> imm;
uint32_t render(visitor_t<uint32_t> * visitor)
{
num_t value = imm.normalize(imm.expr->accept(visitor));
if (imm.in_range(value))
return render() | value;
else
throw imm_out_of_range(imm, value);
}
};
}