mirror of https://github.com/encounter/objdiff.git
133 lines
2.9 KiB
Rust
133 lines
2.9 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use flagset::{flags, FlagSet};
|
|
|
|
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
|
pub enum ObjSectionKind {
|
|
Code,
|
|
Data,
|
|
Bss,
|
|
}
|
|
flags! {
|
|
pub enum ObjSymbolFlags: u8 {
|
|
Global,
|
|
Local,
|
|
Weak,
|
|
Common,
|
|
}
|
|
}
|
|
#[derive(Debug, Copy, Clone, Default)]
|
|
pub struct ObjSymbolFlagSet(pub(crate) FlagSet<ObjSymbolFlags>);
|
|
#[derive(Debug, Clone)]
|
|
pub struct ObjSection {
|
|
pub name: String,
|
|
pub kind: ObjSectionKind,
|
|
pub address: u64,
|
|
pub size: u64,
|
|
pub data: Vec<u8>,
|
|
pub index: usize,
|
|
pub symbols: Vec<ObjSymbol>,
|
|
pub relocations: Vec<ObjReloc>,
|
|
}
|
|
#[derive(Debug, Clone)]
|
|
pub enum ObjInsArg {
|
|
Arg(ppc750cl::Argument),
|
|
Reloc,
|
|
RelocOffset,
|
|
}
|
|
#[derive(Debug, Copy, Clone)]
|
|
pub struct ObjInsArgDiff {
|
|
/// Incrementing index for coloring
|
|
pub idx: usize,
|
|
}
|
|
#[derive(Debug, Clone)]
|
|
pub struct ObjInsBranchFrom {
|
|
/// Source instruction indices
|
|
pub ins_idx: Vec<usize>,
|
|
/// Incrementing index for coloring
|
|
pub branch_idx: usize,
|
|
}
|
|
#[derive(Debug, Clone)]
|
|
pub struct ObjInsBranchTo {
|
|
/// Target instruction index
|
|
pub ins_idx: usize,
|
|
/// Incrementing index for coloring
|
|
pub branch_idx: usize,
|
|
}
|
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
|
|
pub enum ObjInsDiffKind {
|
|
#[default]
|
|
None,
|
|
OpMismatch,
|
|
ArgMismatch,
|
|
Replace,
|
|
Delete,
|
|
Insert,
|
|
}
|
|
#[derive(Debug, Clone)]
|
|
pub struct ObjIns {
|
|
pub ins: ppc750cl::Ins,
|
|
pub mnemonic: String,
|
|
pub args: Vec<ObjInsArg>,
|
|
pub reloc: Option<ObjReloc>,
|
|
}
|
|
#[derive(Debug, Clone, Default)]
|
|
pub struct ObjInsDiff {
|
|
pub ins: Option<ObjIns>,
|
|
/// Diff kind
|
|
pub kind: ObjInsDiffKind,
|
|
/// Branches from instruction
|
|
pub branch_from: Option<ObjInsBranchFrom>,
|
|
/// Branches to instruction
|
|
pub branch_to: Option<ObjInsBranchTo>,
|
|
/// Arg diffs
|
|
pub arg_diff: Vec<Option<ObjInsArgDiff>>,
|
|
}
|
|
#[derive(Debug, Clone)]
|
|
pub struct ObjSymbol {
|
|
pub name: String,
|
|
pub demangled_name: Option<String>,
|
|
pub address: u64,
|
|
pub size: u64,
|
|
pub size_known: bool,
|
|
pub flags: ObjSymbolFlagSet,
|
|
|
|
// Diff
|
|
pub diff_symbol: Option<String>,
|
|
pub instructions: Vec<ObjInsDiff>,
|
|
pub match_percent: f32,
|
|
}
|
|
#[derive(Debug, Clone)]
|
|
pub struct ObjInfo {
|
|
pub path: PathBuf,
|
|
pub sections: Vec<ObjSection>,
|
|
pub common: Vec<ObjSymbol>,
|
|
}
|
|
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
|
pub enum ObjRelocKind {
|
|
Absolute,
|
|
PpcAddr16Hi,
|
|
PpcAddr16Ha,
|
|
PpcAddr16Lo,
|
|
// PpcAddr32,
|
|
// PpcRel32,
|
|
// PpcAddr24,
|
|
PpcRel24,
|
|
// PpcAddr14,
|
|
PpcRel14,
|
|
PpcEmbSda21,
|
|
}
|
|
#[derive(Debug, Clone)]
|
|
pub struct ObjReloc {
|
|
pub kind: ObjRelocKind,
|
|
pub address: u64,
|
|
pub target: ObjSymbol,
|
|
pub target_section: Option<String>,
|
|
}
|
|
// #[derive(Debug, Clone)]
|
|
// pub struct ObjInsDiff {
|
|
// pub kind: ObjInsDiffKind,
|
|
// pub left: Option<ObjIns>,
|
|
// pub right: Option<ObjIns>,
|
|
// }
|