Commit c962654d authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano

Partially implemented IR validation

parent d0feec64
Pipeline #879 failed with stages
in 3 minutes and 30 seconds
This diff is collapsed.
......@@ -785,7 +785,7 @@ impl BlockContent {
}
Instruction_::Call { ref resume, .. } |
Instruction_::CCall { ref resume, .. } |
Instruction_::SwapStack { ref resume, .. } |
Instruction_::SwapStackExc { ref resume, .. } |
Instruction_::ExnInstruction { ref resume, .. } => {
let mut live_outs = vec![];
live_outs.append(&mut resume.normal_dest.get_arguments(&ops));
......@@ -908,6 +908,25 @@ impl TreeNode {
_ => None
}
}
// The type of the node (for a value node)
pub fn ty(&self) -> P<MuType> {
match self.v {
TreeNode_::Instruction(ref inst) => {
if inst.value.is_some() {
let ref value = inst.value.as_ref().unwrap();
if value.len() != 1 {
panic!("the node {} does not have one result value", self);
}
value[0].ty.clone()
} else {
panic!("expected result from the node {}", self);
}
}
TreeNode_::Value(ref pv) => pv.ty.clone()
}
}
}
impl fmt::Display for TreeNode {
......
......@@ -13,7 +13,8 @@
// limitations under the License.
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum BinOp {
pub
enum BinOp {
// BinOp Int(n) Int(n) -> Int(n)
Add,
Sub,
......@@ -39,6 +40,19 @@ pub enum BinOp {
FRem
}
impl BinOp {
pub fn is_fp(self) -> bool {
use op::BinOp::*;
match self {
FAdd |
FSub |
FMul |
FDiv |
FRem => true,
_ => false
}
}
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum CmpOp {
// for Int comparison
......@@ -174,6 +188,22 @@ impl CmpOp {
}
}
pub fn is_fp_cmp(self) -> bool { !self.is_int_cmp() }
pub fn is_eq_cmp(self) -> bool {
use op::CmpOp::*;
match self {
EQ | NE => true,
_ => false
}
}
pub fn is_ult_cmp(self) -> bool {
use op::CmpOp::*;
match self {
UGE | UGT | ULE | ULT => true,
_ => false
}
}
pub fn is_symmetric(self) -> bool {
use op::CmpOp::*;
match self {
......
......@@ -75,6 +75,14 @@ lazy_static! {
MuType::new(new_internal_id(), MuType_::iref(VOID_TYPE.clone()))
);
pub static ref STACKREF_TYPE : P<MuType> = P(
MuType::new(new_internal_id(), MuType_::StackRef)
);
pub static ref THREADREF_TYPE : P<MuType> = P(
MuType::new(new_internal_id(), MuType_::ThreadRef)
);
pub static ref INTERNAL_TYPES : Vec<P<MuType>> = vec![
ADDRESS_TYPE.clone(),
UINT1_TYPE.clone(),
......@@ -89,6 +97,8 @@ lazy_static! {
VOID_TYPE.clone(),
REF_VOID_TYPE.clone(),
IREF_VOID_TYPE.clone(),
STACKREF_TYPE.clone(),
THREADREF_TYPE.clone(),
];
}
......@@ -106,7 +116,7 @@ pub fn init_types() {
}
/// MuType represents a Mu type
#[derive(PartialEq, Debug)]
#[derive(Debug)]
pub struct MuType {
pub hdr: MuEntityHeader,
pub v: MuType_
......@@ -114,6 +124,11 @@ pub struct MuType {
rodal_struct!(MuType { hdr, v });
impl PartialEq for MuType {
fn eq(&self, other: &MuType) -> bool { self.v == other.v }
fn ne(&self, other: &MuType) -> bool { self.v != other.v }
}
impl MuType {
/// creates a new Mu type
pub fn new(id: MuID, v: MuType_) -> MuType {
......@@ -123,6 +138,19 @@ impl MuType {
}
}
pub fn is_tagref64(&self) -> bool {
match self.v {
MuType_::Tagref64 => true,
_ => false
}
}
pub fn is_funcref(&self) -> bool {
match self.v {
MuType_::Struct(_) => true,
_ => false
}
}
/// is this type struct type?
pub fn is_struct(&self) -> bool {
match self.v {
......@@ -131,6 +159,13 @@ impl MuType {
}
}
pub fn is_void(&self) -> bool {
match self.v {
MuType_::Void => true,
_ => false
}
}
/// is this type hybrid type?
pub fn is_hybrid(&self) -> bool {
match self.v {
......@@ -155,6 +190,22 @@ impl MuType {
}
}
pub fn is_opaque_reference(&self) -> bool {
match self.v {
MuType_::FuncRef(_) | MuType_::StackRef | MuType_::ThreadRef => true,
_ => false
}
}
pub fn is_eq_comparable(&self) -> bool {
self.is_int() || self.is_ptr() || self.is_iref() || self.is_ref() || self.is_opaque_reference()
}
pub fn is_ult_comparable(&self) -> bool {
self.is_int() || self.is_ptr() || self.is_iref()
}
/// is this type a float type (single-precision floating point)
pub fn is_float(&self) -> bool {
match self.v {
......@@ -393,7 +444,7 @@ pub type StructTag = MuName;
pub type HybridTag = MuName;
/// MuType_ is used for pattern matching for MuType
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, Clone)]
pub enum MuType_ {
/// int <length>
Int(usize),
......@@ -441,7 +492,14 @@ pub enum MuType_ {
/// ufuncptr<@sig>
UFuncPtr(P<MuFuncSig>)
}
impl MuType_ {
pub fn strong_variant(&self) -> MuType_ {
match self {
&MuType_::WeakRef(ref t) => MuType_::Ref(t.clone()),
_ => self.clone()
}
}
}
rodal_enum!(MuType_{(Int: size), Float, Double, (Ref: ty), (IRef: ty), (WeakRef: ty), (UPtr: ty),
(Struct: tag), (Array: ty, size), (Hybrid: tag), Void, ThreadRef, StackRef, Tagref64,
(Vector: ty, size), (FuncRef: ty), (UFuncPtr: ty)});
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment