support simplified mnemonic conditions

This commit is contained in:
Richard Patel 2022-04-07 01:17:31 +02:00
parent c8c1daaa64
commit e9041072e9
4 changed files with 515 additions and 94 deletions

View File

@ -6967,7 +6967,14 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "li", mnemonic: "li",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![
Argument::GPR(GPR(
(((self.code) >> (32 - 11u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::Simm(Simm(
(((self.code) >> (32 - 32u8)) & ((1 << 16usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -6977,7 +6984,14 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "lis", mnemonic: "lis",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![
Argument::GPR(GPR(
(((self.code) >> (32 - 11u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::Uimm(Uimm(
(((self.code) >> (32 - 32u8)) & ((1 << 16usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -6992,7 +7006,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7005,7 +7026,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7018,7 +7046,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7031,7 +7066,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7044,7 +7086,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7057,7 +7106,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7070,7 +7126,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7083,7 +7146,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7098,7 +7168,9 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
))],
ins: self, ins: self,
}; };
} }
@ -7113,7 +7185,9 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
))],
ins: self, ins: self,
}; };
} }
@ -7127,7 +7201,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7139,7 +7220,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7151,7 +7239,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7163,7 +7258,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7175,7 +7277,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7187,7 +7296,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7199,7 +7315,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7211,7 +7334,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7235,7 +7365,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7247,7 +7384,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7259,7 +7403,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7271,7 +7422,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7283,7 +7441,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7295,7 +7460,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7307,7 +7479,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7319,7 +7498,14 @@ impl Ins {
m.lk = self.bit(31); m.lk = self.bit(31);
m m
}, },
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 14u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::BranchDest(BranchDest(
(((self.code) >> (32 - 30u8)) & ((1 << 14usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7329,7 +7515,14 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "cmpw", mnemonic: "cmpw",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![
Argument::GPR(GPR(
(((self.code) >> (32 - 16u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::GPR(GPR(
(((self.code) >> (32 - 21u8)) & ((1 << 5usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7339,7 +7532,14 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "cmpwi", mnemonic: "cmpwi",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![
Argument::GPR(GPR(
(((self.code) >> (32 - 16u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::Simm(Simm(
(((self.code) >> (32 - 32u8)) & ((1 << 16usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7347,7 +7547,17 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "cmpwi", mnemonic: "cmpwi",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 9u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::GPR(GPR(
(((self.code) >> (32 - 16u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::Simm(Simm(
(((self.code) >> (32 - 32u8)) & ((1 << 16usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7357,7 +7567,14 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "cmplw", mnemonic: "cmplw",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![
Argument::GPR(GPR(
(((self.code) >> (32 - 16u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::GPR(GPR(
(((self.code) >> (32 - 21u8)) & ((1 << 5usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7367,7 +7584,14 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "cmplwi", mnemonic: "cmplwi",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![
Argument::GPR(GPR(
(((self.code) >> (32 - 16u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::Uimm(Uimm(
(((self.code) >> (32 - 32u8)) & ((1 << 16usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7375,7 +7599,17 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "cmplwi", mnemonic: "cmplwi",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![
Argument::CRBit(CRBit(
(((self.code) >> (32 - 9u8)) & ((1 << 3usize) - 1)) as _,
)),
Argument::GPR(GPR(
(((self.code) >> (32 - 16u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::Uimm(Uimm(
(((self.code) >> (32 - 32u8)) & ((1 << 16usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7385,7 +7619,9 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "mfxer", mnemonic: "mfxer",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![Argument::GPR(GPR((((self.code) >> (32 - 11u8))
& ((1 << 5usize) - 1))
as _))],
ins: self, ins: self,
}; };
} }
@ -7393,7 +7629,9 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "mflr", mnemonic: "mflr",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![Argument::GPR(GPR((((self.code) >> (32 - 11u8))
& ((1 << 5usize) - 1))
as _))],
ins: self, ins: self,
}; };
} }
@ -7401,7 +7639,9 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "mfctr", mnemonic: "mfctr",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![Argument::GPR(GPR((((self.code) >> (32 - 11u8))
& ((1 << 5usize) - 1))
as _))],
ins: self, ins: self,
}; };
} }
@ -7409,7 +7649,9 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "mfdsisr", mnemonic: "mfdsisr",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![Argument::GPR(GPR((((self.code) >> (32 - 11u8))
& ((1 << 5usize) - 1))
as _))],
ins: self, ins: self,
}; };
} }
@ -7417,7 +7659,9 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "mfdbatu", mnemonic: "mfdbatu",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![Argument::GPR(GPR((((self.code) >> (32 - 11u8))
& ((1 << 5usize) - 1))
as _))],
ins: self, ins: self,
}; };
} }
@ -7425,7 +7669,9 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "mftdu", mnemonic: "mftdu",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![Argument::GPR(GPR((((self.code) >> (32 - 11u8))
& ((1 << 5usize) - 1))
as _))],
ins: self, ins: self,
}; };
} }
@ -7435,7 +7681,9 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "mtxer", mnemonic: "mtxer",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![Argument::GPR(GPR((((self.code) >> (32 - 11u8))
& ((1 << 5usize) - 1))
as _))],
ins: self, ins: self,
}; };
} }
@ -7443,7 +7691,9 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "mtlr", mnemonic: "mtlr",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![Argument::GPR(GPR((((self.code) >> (32 - 11u8))
& ((1 << 5usize) - 1))
as _))],
ins: self, ins: self,
}; };
} }
@ -7451,7 +7701,9 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "mtctr", mnemonic: "mtctr",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![Argument::GPR(GPR((((self.code) >> (32 - 11u8))
& ((1 << 5usize) - 1))
as _))],
ins: self, ins: self,
}; };
} }
@ -7459,7 +7711,9 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "mtdsisr", mnemonic: "mtdsisr",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![Argument::GPR(GPR((((self.code) >> (32 - 11u8))
& ((1 << 5usize) - 1))
as _))],
ins: self, ins: self,
}; };
} }
@ -7467,7 +7721,9 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "mtdbatu", mnemonic: "mtdbatu",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![Argument::GPR(GPR((((self.code) >> (32 - 11u8))
& ((1 << 5usize) - 1))
as _))],
ins: self, ins: self,
}; };
} }
@ -7475,12 +7731,32 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "mttdu", mnemonic: "mttdu",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![Argument::GPR(GPR((((self.code) >> (32 - 11u8))
& ((1 << 5usize) - 1))
as _))],
ins: self,
};
}
}
Opcode::Or => {
if (((self.code) >> (32 - 11u8)) & ((1 << 5usize) - 1))
== (((self.code) >> (32 - 21u8)) & ((1 << 5usize) - 1))
{
return SimplifiedIns {
mnemonic: "mr",
modifiers: Modifiers::default(),
args: vec![
Argument::GPR(GPR(
(((self.code) >> (32 - 16u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::GPR(GPR(
(((self.code) >> (32 - 11u8)) & ((1 << 5usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
} }
Opcode::Or => {}
Opcode::Ori => { Opcode::Ori => {
if (((self.code) >> (32 - 16u8)) & ((1 << 5usize) - 1)) == 0 if (((self.code) >> (32 - 16u8)) & ((1 << 5usize) - 1)) == 0
&& (((self.code) >> (32 - 11u8)) & ((1 << 5usize) - 1)) == 0 && (((self.code) >> (32 - 11u8)) & ((1 << 5usize) - 1)) == 0
@ -7494,13 +7770,103 @@ impl Ins {
}; };
} }
} }
Opcode::Rlwinm => {} Opcode::Rlwinm => {
if (((self.code) >> (32 - 21u8)) & ((1 << 5usize) - 1)) == 0
&& (((self.code) >> (32 - 31u8)) & ((1 << 5usize) - 1)) == 31
{
return SimplifiedIns {
mnemonic: "clrlwi",
modifiers: Modifiers::default(),
args: vec![
Argument::GPR(GPR(
(((self.code) >> (32 - 16u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::GPR(GPR(
(((self.code) >> (32 - 11u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::OpaqueU(OpaqueU(
(((self.code) >> (32 - 26u8)) & ((1 << 5usize) - 1)) as _,
)),
],
ins: self,
};
}
if (((self.code) >> (32 - 26u8)) & ((1 << 5usize) - 1)) == 0
&& (((self.code) >> (32 - 31u8)) & ((1 << 5usize) - 1)) == 31
{
return SimplifiedIns {
mnemonic: "rotlwi",
modifiers: Modifiers::default(),
args: vec![
Argument::GPR(GPR(
(((self.code) >> (32 - 16u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::GPR(GPR(
(((self.code) >> (32 - 11u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::OpaqueU(OpaqueU(
(((self.code) >> (32 - 21u8)) & ((1 << 5usize) - 1)) as _,
)),
],
ins: self,
};
}
if (((self.code) >> (32 - 26u8)) & ((1 << 5usize) - 1)) == 0
&& 31 - (((self.code) >> (32 - 21u8)) & ((1 << 5usize) - 1))
== (((self.code) >> (32 - 31u8)) & ((1 << 5usize) - 1))
{
return SimplifiedIns {
mnemonic: "slwi",
modifiers: Modifiers::default(),
args: vec![
Argument::GPR(GPR(
(((self.code) >> (32 - 16u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::GPR(GPR(
(((self.code) >> (32 - 11u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::OpaqueU(OpaqueU(
(((self.code) >> (32 - 31u8)) & ((1 << 5usize) - 1)) as _,
)),
],
ins: self,
};
}
if (((self.code) >> (32 - 31u8)) & ((1 << 5usize) - 1)) == 31
&& 32 - (((self.code) >> (32 - 26u8)) & ((1 << 5usize) - 1))
== (((self.code) >> (32 - 21u8)) & ((1 << 5usize) - 1))
{
return SimplifiedIns {
mnemonic: "srwi",
modifiers: Modifiers::default(),
args: vec![
Argument::GPR(GPR(
(((self.code) >> (32 - 16u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::GPR(GPR(
(((self.code) >> (32 - 11u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::OpaqueU(OpaqueU(
(((self.code) >> (32 - 26u8)) & ((1 << 5usize) - 1)) as _,
)),
],
ins: self,
};
}
}
Opcode::Twi => { Opcode::Twi => {
if (((self.code) >> (32 - 11u8)) & ((1 << 5usize) - 1)) == 8 { if (((self.code) >> (32 - 11u8)) & ((1 << 5usize) - 1)) == 8 {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "twgti", mnemonic: "twgti",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![
Argument::GPR(GPR(
(((self.code) >> (32 - 16u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::Simm(Simm(
(((self.code) >> (32 - 32u8)) & ((1 << 16usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }
@ -7508,7 +7874,14 @@ impl Ins {
return SimplifiedIns { return SimplifiedIns {
mnemonic: "twllei", mnemonic: "twllei",
modifiers: Modifiers::default(), modifiers: Modifiers::default(),
args: vec![], args: vec![
Argument::GPR(GPR(
(((self.code) >> (32 - 16u8)) & ((1 << 5usize) - 1)) as _,
)),
Argument::Simm(Simm(
(((self.code) >> (32 - 32u8)) & ((1 << 16usize) - 1)) as _,
)),
],
ins: self, ins: self,
}; };
} }

View File

@ -6,16 +6,17 @@ use num_traits::{AsPrimitive, PrimInt};
pub use crate::iter::{disasm_iter, DisasmIterator}; pub use crate::iter::{disasm_iter, DisasmIterator};
pub mod formatter; pub mod formatter;
mod iter;
mod generated; mod generated;
mod iter;
use generated::*; use generated::*;
pub mod prelude { pub mod prelude {
pub use crate::formatter::FormattedIns; pub use crate::formatter::FormattedIns;
pub use crate::Argument;
pub use crate::Field::*; pub use crate::Field::*;
pub use crate::Ins; pub use crate::Ins;
pub use crate::Opcode::*;
pub use crate::Modifiers; pub use crate::Modifiers;
pub use crate::Opcode::*;
pub use crate::SimplifiedIns; pub use crate::SimplifiedIns;
pub use crate::{ pub use crate::{
Bit, BranchDest, CRBit, CRField, Offset, OpaqueU, Simm, Uimm, FPR, GPR, GQR, SPR, SR, Bit, BranchDest, CRBit, CRField, Offset, OpaqueU, Simm, Uimm, FPR, GPR, GQR, SPR, SR,

View File

@ -3,6 +3,7 @@ use std::fs::File;
use std::io::Write; use std::io::Write;
use std::ops::Range; use std::ops::Range;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use std::str::FromStr;
use itertools::Itertools; use itertools::Itertools;
use proc_macro2::{Ident, Literal, Span, TokenStream, TokenTree}; use proc_macro2::{Ident, Literal, Span, TokenStream, TokenTree};
@ -30,16 +31,19 @@ fn _main() -> Result<()> {
let isa = load_isa()?; let isa = load_isa()?;
let mut unformatted_code = Vec::<u8>::new(); let mut unformatted_code = Vec::<u8>::new();
writeln!(&mut unformatted_code, "{}", quote! { writeln!(
&mut unformatted_code,
"{}",
quote! {
use crate::prelude::*; use crate::prelude::*;
})?; }
)?;
writeln!(&mut unformatted_code, "{}", isa.gen_opcode_enum()?)?; writeln!(&mut unformatted_code, "{}", isa.gen_opcode_enum()?)?;
writeln!(&mut unformatted_code, "{}", isa.gen_field_enum()?)?; writeln!(&mut unformatted_code, "{}", isa.gen_field_enum()?)?;
writeln!(&mut unformatted_code, "{}", isa.gen_ins_impl()?)?; writeln!(&mut unformatted_code, "{}", isa.gen_ins_impl()?)?;
let formatted_code = rustfmt(unformatted_code); let formatted_code = rustfmt(unformatted_code);
File::create("./disasm/src/generated.rs")? File::create("./disasm/src/generated.rs")?.write_all(&formatted_code)?;
.write_all(&formatted_code)?;
Ok(()) Ok(())
} }
@ -321,7 +325,6 @@ impl Isa {
Ok(field_enum) Ok(field_enum)
} }
pub(crate) fn gen_ins_impl(&self) -> Result<TokenStream> { pub(crate) fn gen_ins_impl(&self) -> Result<TokenStream> {
// Map fields by name. // Map fields by name.
let mut field_by_name = HashMap::<String, &Field>::new(); let mut field_by_name = HashMap::<String, &Field>::new();
@ -331,7 +334,10 @@ impl Isa {
// Map mnemonics by opcode. // Map mnemonics by opcode.
let mut mnemonics_by_opcode = HashMap::<&String, Vec<&Mnemonic>>::new(); let mut mnemonics_by_opcode = HashMap::<&String, Vec<&Mnemonic>>::new();
for simple in &self.mnemonics { for simple in &self.mnemonics {
mnemonics_by_opcode.entry(&simple.opcode).or_insert_with(|| Vec::new()).push(simple) mnemonics_by_opcode
.entry(&simple.opcode)
.or_insert_with(|| Vec::new())
.push(simple)
} }
// Generate match arms for each opcode. // Generate match arms for each opcode.
let mut field_match_arms = Vec::new(); let mut field_match_arms = Vec::new();
@ -343,9 +349,9 @@ impl Isa {
// Generate fields of opcode. // Generate fields of opcode.
let mut fields = Vec::new(); let mut fields = Vec::new();
for arg in &opcode.args { for arg in &opcode.args {
let field: &Field = field_by_name.get(arg).ok_or_else(|| { let field: &Field = field_by_name
Error::from(format!("undefined field {}", arg)) .get(arg)
})?; .ok_or_else(|| Error::from(format!("undefined field {}", arg)))?;
let variant = field.construct_variant_self(); let variant = field.construct_variant_self();
fields.extend(quote! { #variant, }) fields.extend(quote! { #variant, })
} }
@ -360,7 +366,8 @@ impl Isa {
let modifiers = ModifiersExpr { let modifiers = ModifiersExpr {
modifiers: opcode.modifiers.clone(), modifiers: opcode.modifiers.clone(),
side_effects: opcode.side_effects.clone(), side_effects: opcode.side_effects.clone(),
}.build()?; }
.build()?;
modifier_match_arms.push(quote! { modifier_match_arms.push(quote! {
Opcode::#ident => #modifiers, Opcode::#ident => #modifiers,
}); });
@ -424,7 +431,7 @@ impl Isa {
if let Some(mnemonics) = mnemonics_by_opcode.get(&opcode.name) { if let Some(mnemonics) = mnemonics_by_opcode.get(&opcode.name) {
let mut simplified_conditions = Vec::new(); let mut simplified_conditions = Vec::new();
for mnemonic in mnemonics { for mnemonic in mnemonics {
if mnemonic.matcher.is_empty() { if mnemonic.matcher.is_empty() && mnemonic.condition.is_empty() {
continue; // TODO else branch continue; // TODO else branch
} }
// Emit if condition. // Emit if condition.
@ -439,21 +446,44 @@ impl Isa {
})?; })?;
simplified_conditions.push(field.express_value_self()); simplified_conditions.push(field.express_value_self());
// Equate with literal. // Equate with literal.
let lit_int = LitInt::new(&format!("{}", condition.value), Span::call_site()); let lit_int =
LitInt::new(&format!("{}", condition.value), Span::call_site());
simplified_conditions.push(quote!(== #lit_int)); simplified_conditions.push(quote!(== #lit_int));
} }
if !mnemonic.condition.is_empty() {
if mnemonic.matcher.len() > 0 {
simplified_conditions.push(quote!(&&));
}
simplified_conditions.push(compile_mnemonic_condition(
&field_by_name,
&mnemonic.condition,
)?);
}
// Emit branch. // Emit branch.
let mnemonic_lit = LitStr::new(&mnemonic.name, Span::call_site()); let mnemonic_lit = LitStr::new(&mnemonic.name, Span::call_site());
// Extract modifier bits.
let modifiers = ModifiersExpr { let modifiers = ModifiersExpr {
modifiers: mnemonic.modifiers.clone(), modifiers: mnemonic.modifiers.clone(),
side_effects: vec![], side_effects: vec![],
}.build()?; }
.build()?;
// Extract arguments.
let mut args = Vec::new();
for arg in &mnemonic.args {
let field = field_by_name
.get(arg)
.expect(&format!("field not found: {}", arg));
let variant = Ident::new(field.arg.as_ref().unwrap(), Span::call_site());
let value = field.express_value_self();
args.push(quote!(Argument::#variant(#variant(#value as _)),));
}
let args = token_stream!(args);
simplified_conditions.push(quote! { simplified_conditions.push(quote! {
{ {
return SimplifiedIns { return SimplifiedIns {
mnemonic: #mnemonic_lit, mnemonic: #mnemonic_lit,
modifiers: #modifiers, modifiers: #modifiers,
args: vec![], args: vec![#args],
ins: self, ins: self,
}; };
} }
@ -622,3 +652,20 @@ impl ModifiersExpr {
quote!(Modifiers::default()) quote!(Modifiers::default())
} }
} }
/// Compiles conditions such as `S == B` into valid Rust expressions on a PowerPC instruction.
fn compile_mnemonic_condition(
field_by_name: &HashMap<String, &Field>,
code: &str,
) -> Result<TokenStream> {
let src_stream = TokenStream::from_str(code)?;
let token_iter = src_stream.into_iter().flat_map(|token| {
if let TokenTree::Ident(ref ident) = token {
if let Some(field) = field_by_name.get(&ident.to_string()) {
return field.express_value_self();
}
}
token.into()
});
Ok(TokenStream::from_iter(token_iter))
}

View File

@ -1968,7 +1968,7 @@ mnemonics:
- name: "mr" - name: "mr"
opcode: "or" opcode: "or"
args: [ "rA", "rS" ] args: [ "rA", "rS" ]
condition: "S == B" condition: "rS == rB"
- name: "nop" - name: "nop"
opcode: "ori" opcode: "ori"
match: match:
@ -2148,56 +2148,56 @@ mnemonics:
- name: "blt" - name: "blt"
opcode: "bc" opcode: "bc"
modifiers: [ "AA", "LK" ] modifiers: [ "AA", "LK" ]
args: [ "crS.LT", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 12 value: 12
- name: "ble" - name: "ble"
opcode: "bc" opcode: "bc"
modifiers: [ "AA", "LK" ] modifiers: [ "AA", "LK" ]
args: [ "crS.GT", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 4 value: 4
- name: "beq" - name: "beq"
opcode: "bc" opcode: "bc"
modifiers: [ "AA", "LK" ] modifiers: [ "AA", "LK" ]
args: [ "crS.EQ", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 12 value: 12
- name: "bge" - name: "bge"
opcode: "bc" opcode: "bc"
modifiers: [ "AA", "LK" ] modifiers: [ "AA", "LK" ]
args: [ "crS.LT", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 4 value: 4
- name: "bgt" - name: "bgt"
opcode: "bc" opcode: "bc"
modifiers: [ "AA", "LK" ] modifiers: [ "AA", "LK" ]
args: [ "crS.GT", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 12 value: 12
- name: "bne" - name: "bne"
opcode: "bc" opcode: "bc"
modifiers: [ "AA", "LK" ] modifiers: [ "AA", "LK" ]
args: [ "crS.EQ", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 4 value: 4
- name: "bso" - name: "bso"
opcode: "bc" opcode: "bc"
modifiers: [ "AA", "LK" ] modifiers: [ "AA", "LK" ]
args: [ "crS.SO", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 12 value: 12
- name: "bns" - name: "bns"
opcode: "bc" opcode: "bc"
modifiers: [ "AA", "LK" ] modifiers: [ "AA", "LK" ]
args: [ "crS.SO", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 4 value: 4
@ -2225,56 +2225,56 @@ mnemonics:
- name: "bltctr" - name: "bltctr"
opcode: "bcctr" opcode: "bcctr"
modifiers: [ "LK" ] modifiers: [ "LK" ]
args: [ "crS.LT", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 12 value: 12
- name: "blectr" - name: "blectr"
opcode: "bcctr" opcode: "bcctr"
modifiers: [ "LK" ] modifiers: [ "LK" ]
args: [ "crS.GT", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 4 value: 4
- name: "beqctr" - name: "beqctr"
opcode: "bcctr" opcode: "bcctr"
modifiers: [ "LK" ] modifiers: [ "LK" ]
args: [ "crS.EQ", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 12 value: 12
- name: "bgectr" - name: "bgectr"
opcode: "bcctr" opcode: "bcctr"
modifiers: [ "LK" ] modifiers: [ "LK" ]
args: [ "crS.LT", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 4 value: 4
- name: "bgtctr" - name: "bgtctr"
opcode: "bcctr" opcode: "bcctr"
modifiers: [ "LK" ] modifiers: [ "LK" ]
args: [ "crS.GT", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 12 value: 12
- name: "bnectr" - name: "bnectr"
opcode: "bcctr" opcode: "bcctr"
modifiers: [ "LK" ] modifiers: [ "LK" ]
args: [ "crS.EQ", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 4 value: 4
- name: "bsoctr" - name: "bsoctr"
opcode: "bcctr" opcode: "bcctr"
modifiers: [ "LK" ] modifiers: [ "LK" ]
args: [ "crS.SO", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 12 value: 12
- name: "bnsctr" - name: "bnsctr"
opcode: "bcctr" opcode: "bcctr"
modifiers: [ "LK" ] modifiers: [ "LK" ]
args: [ "crS.SO", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 4 value: 4
@ -2283,56 +2283,56 @@ mnemonics:
- name: "bltlr" - name: "bltlr"
opcode: "bclr" opcode: "bclr"
modifiers: [ "LK" ] modifiers: [ "LK" ]
args: [ "crS.LT", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 12 value: 12
- name: "blelr" - name: "blelr"
opcode: "bclr" opcode: "bclr"
modifiers: [ "LK" ] modifiers: [ "LK" ]
args: [ "crS.GT", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 4 value: 4
- name: "beqlr" - name: "beqlr"
opcode: "bclr" opcode: "bclr"
modifiers: [ "LK" ] modifiers: [ "LK" ]
args: [ "crS.EQ", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 12 value: 12
- name: "bgelr" - name: "bgelr"
opcode: "bclr" opcode: "bclr"
modifiers: [ "LK" ] modifiers: [ "LK" ]
args: [ "crS.LT", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 4 value: 4
- name: "bgtlr" - name: "bgtlr"
opcode: "bclr" opcode: "bclr"
modifiers: [ "LK" ] modifiers: [ "LK" ]
args: [ "crS.GT", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 12 value: 12
- name: "bnelr" - name: "bnelr"
opcode: "bclr" opcode: "bclr"
modifiers: [ "LK" ] modifiers: [ "LK" ]
args: [ "crS.EQ", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 4 value: 4
- name: "bsolr" - name: "bsolr"
opcode: "bclr" opcode: "bclr"
modifiers: [ "LK" ] modifiers: [ "LK" ]
args: [ "crS.SO", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 12 value: 12
- name: "bnslr" - name: "bnslr"
opcode: "bclr" opcode: "bclr"
modifiers: [ "LK" ] modifiers: [ "LK" ]
args: [ "crS.SO", "BD" ] args: [ "crfS", "BD" ]
match: match:
- arg: BO - arg: BO
value: 4 value: 4