2021-09-28 23:09:38 +00:00
|
|
|
|
2023-03-06 04:19:49 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
2021-09-28 23:09:38 +00:00
|
|
|
pub enum ErrorType {
|
2022-09-10 06:17:33 +00:00
|
|
|
Assertion,
|
2023-05-15 04:12:38 +00:00
|
|
|
Emulator(EmulatorErrorKind),
|
2021-09-28 23:09:38 +00:00
|
|
|
Processor,
|
2021-11-03 22:33:22 +00:00
|
|
|
Breakpoint,
|
2021-09-28 23:09:38 +00:00
|
|
|
}
|
|
|
|
|
2023-05-15 04:12:38 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
|
|
|
pub enum EmulatorErrorKind {
|
|
|
|
Misc,
|
|
|
|
MemoryAlignment,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-28 23:09:38 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Error {
|
|
|
|
pub err: ErrorType,
|
|
|
|
pub native: u32,
|
|
|
|
pub msg: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Error {
|
2023-05-15 04:12:38 +00:00
|
|
|
pub fn new<S>(msg: S) -> Error
|
|
|
|
where
|
|
|
|
S: Into<String>,
|
|
|
|
{
|
|
|
|
Error {
|
|
|
|
err: ErrorType::Emulator(EmulatorErrorKind::Misc),
|
|
|
|
native: 0,
|
|
|
|
msg: msg.into(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn emulator<S>(kind: EmulatorErrorKind, msg: S) -> Error
|
|
|
|
where
|
|
|
|
S: Into<String>,
|
|
|
|
{
|
2021-09-28 23:09:38 +00:00
|
|
|
Error {
|
2023-05-15 04:12:38 +00:00
|
|
|
err: ErrorType::Emulator(kind),
|
2021-09-28 23:09:38 +00:00
|
|
|
native: 0,
|
2023-05-15 04:12:38 +00:00
|
|
|
msg: msg.into(),
|
2021-09-28 23:09:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn processor(native: u32) -> Error {
|
|
|
|
Error {
|
|
|
|
err: ErrorType::Processor,
|
|
|
|
native,
|
|
|
|
msg: "".to_string(),
|
|
|
|
}
|
|
|
|
}
|
2021-11-03 22:33:22 +00:00
|
|
|
|
2023-05-15 04:12:38 +00:00
|
|
|
pub fn breakpoint<S>(msg: S) -> Error
|
|
|
|
where
|
|
|
|
S: Into<String>,
|
|
|
|
{
|
2021-11-03 22:33:22 +00:00
|
|
|
Error {
|
|
|
|
err: ErrorType::Breakpoint,
|
|
|
|
native: 0,
|
2023-05-15 04:12:38 +00:00
|
|
|
msg: msg.into(),
|
2021-11-03 22:33:22 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-10 06:17:33 +00:00
|
|
|
|
2023-05-15 04:12:38 +00:00
|
|
|
pub fn assertion<S>(msg: S) -> Error
|
|
|
|
where
|
|
|
|
S: Into<String>,
|
|
|
|
{
|
2022-09-10 06:17:33 +00:00
|
|
|
Error {
|
|
|
|
err: ErrorType::Assertion,
|
|
|
|
native: 0,
|
2023-05-15 04:12:38 +00:00
|
|
|
msg: msg.into(),
|
2022-09-10 06:17:33 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-23 04:12:05 +00:00
|
|
|
|
|
|
|
pub fn is_processor(&self, native: u32) -> bool {
|
|
|
|
self.err == ErrorType::Processor && self.native == native
|
|
|
|
}
|
2021-09-28 23:09:38 +00:00
|
|
|
}
|
|
|
|
|