Skip to content

Commit

Permalink
arch. specific property provider
Browse files Browse the repository at this point in the history
  • Loading branch information
xorpse committed Jun 11, 2024
1 parent 924f4cf commit 4b65329
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
5 changes: 4 additions & 1 deletion fugue-core/src/icfg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ use std::collections::VecDeque;

use fugue_ir::Address;

use crate::lifter::{InsnLifter, Lifter};
use crate::project::{Project, ProjectRawView};

pub struct ICFGBuilder<'a, R>
where
R: ProjectRawView,
{
project: &'a mut Project<R>,
fast_lifter: Box<dyn InsnLifter>,
candidates: VecDeque<Address>,
}

Expand All @@ -18,8 +20,9 @@ where
{
pub fn new(project: &'a mut Project<R>) -> Self {
Self {
project,
fast_lifter: project.language().lifter_for_arch(),
candidates: VecDeque::new(),
project,
}
}

Expand Down
17 changes: 16 additions & 1 deletion fugue-core/src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use rustc_hash::FxHashMap;
use static_init::dynamic;
use thiserror::Error;

use crate::lifter::Lifter;
use crate::arch::aarch64::AArch64InsnLifter;
use crate::arch::arm::ARMInsnLifter;
use crate::arch::x86::X86InsnLifter;
use crate::lifter::{DefaultInsnLifter, InsnLifter, Lifter};

#[derive(Debug, Error)]
pub enum LanguageBuilderError {
Expand Down Expand Up @@ -115,6 +118,18 @@ impl Language {
Lifter::new(&self.translator)
}

pub fn lifter_for_arch(&self) -> Box<dyn InsnLifter> {
let arch = self.translator().architecture();

match (arch.processor(), arch.bits()) {
("AARCH64", 64) => AArch64InsnLifter::new().boxed(),
("ARM", 32) => ARMInsnLifter::new().boxed(),
("x86", 64) => X86InsnLifter::new_64().boxed(),
("x86", 32) => X86InsnLifter::new_32().boxed(),
_ => DefaultInsnLifter::new().boxed(),
}
}

pub fn convention(&self) -> &Convention {
&self.convention
}
Expand Down
15 changes: 0 additions & 15 deletions fugue-core/src/lifter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ use fugue_ir::{Address, Translator};

use thiserror::Error;

use crate::arch::aarch64::AArch64InsnLifter;
use crate::arch::arm::ARMInsnLifter;
use crate::arch::x86::X86InsnLifter;
use crate::ir::{Insn, PCode};

#[derive(Debug, Error)]
Expand Down Expand Up @@ -119,18 +116,6 @@ impl<'a> Lifter<'a> {
})
}

pub fn lifter_for_arch(&self) -> Box<dyn InsnLifter> {
let arch = self.translator().architecture();

match (arch.processor(), arch.bits()) {
("AARCH64", 64) => AArch64InsnLifter::new().boxed(),
("ARM", 32) => ARMInsnLifter::new().boxed(),
("x86", 64) => X86InsnLifter::new_64().boxed(),
("x86", 32) => X86InsnLifter::new_32().boxed(),
_ => DefaultInsnLifter::new().boxed(),
}
}

pub fn translator(&self) -> &Translator {
self.0.translator()
}
Expand Down

0 comments on commit 4b65329

Please sign in to comment.