Skip to content

Instantly share code, notes, and snippets.

@playXE
Created July 3, 2019 18:30
Show Gist options
  • Save playXE/c3f6ea58ee3e01ed14c463cff774be44 to your computer and use it in GitHub Desktop.
Save playXE/c3f6ea58ee3e01ed14c463cff774be44 to your computer and use it in GitHub Desktop.
impl LIns {
/// Returns instruction result type
#[inline(always)]
pub const fn ret_type(&self) -> LIRTy {
RET_TYPES[self.opcode as usize]
}
#[inline]
pub const fn is_live(&self) -> bool {
self.is_v() | self.is_call() | self.is_op(LOpcode::ParamQ) | self.is_result_live
}
/// Returns true if machine register assigned to instruction
#[inline]
pub const fn in_reg(&self) -> bool {
self.in_reg
}
/// Returns true if instruction result located in stack memory
#[inline]
pub const fn in_ar(&self) -> bool {
self.in_ar
}
/// Returns true if this instruction result located somewhere
#[inline]
pub const fn is_extant(&self) -> bool {
let x = self.in_ar() | self.in_reg();
x
}
/// Get instruction result register
#[inline]
pub const fn get_reg(&self) -> u32 {
const_assert!(self.in_reg());
self.regnum
}
/// Returns stack location
#[inline]
pub const fn get_ar_index(&self) -> u32 {
const_assert!(self.in_ar());
self.ar_index
}
/// Returns true if result of instruction is void value
#[inline]
pub const fn is_v(&self) -> bool {
self.ret_type() as i32 == LIRTy::Void as i32
}
/// Returns true if result of instruction is integer value
#[inline]
pub const fn is_i(&self) -> bool {
self.ret_type() as i32 == Int as i32
}
/// Returns true if result of instruction is long (quad) value
#[inline]
pub const fn is_q(&self) -> bool {
self.ret_type() as i32 == Long as i32
}
/// Returns true if result of instruction is double (float64) value
#[inline]
pub const fn is_d(&self) -> bool {
self.ret_type() as i32 == Double as i32
}
/// Returns true if result of instruction is float (flaot32) value
#[inline]
pub const fn is_f(&self) -> bool {
self.ret_type() as i32 == Float as i32
}
/// Returns true if instruction result is double sized (quad word)
#[inline]
pub const fn is_q_or_d(&self) -> bool {
(self.is_q() | self.is_d())
}
/// Returns true if `self.opcode` is `op`
#[inline]
pub const fn is_op(&self, op: LOpcode) -> bool {
self.opcode as i32 == op as i32
}
/// Returns true if current opcode is call opcode
#[inline]
pub const fn is_call(&self) -> bool {
self.is_op(LOpcode::callv)
| self.is_op(LOpcode::calli)
| self.is_op(LOpcode::callq)
| self.is_op(LOpcode::calld)
| self.is_op(LOpcode::callf)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment