Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement wrappers around the Architecture ID types #5431

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

rbran
Copy link
Contributor

@rbran rbran commented May 17, 2024

Instead of using naked ids (u32) for types like: Register, Flag, Intrinsic, etc. This PR replaces those types with wrappers like: RegisterId, FlagId, IntrinsicId, etc.

The objective is to provide a more clear API for the user, once the type RegisterId can't be confused with any other u32.

This pattern also allow the creation of the ArchitectureExt::get_field that can receive any kind of id an return the corresponding type, eg:

let reg_id = get_reg_id();
let flag_id = get_flag_id();
let instrinsic_id = get_intrinsic_id();
let reg: CoreRegister = arch.get_field(reg_id).unwrap();
let flag: CoreFlag = arch.get_field(flag_id).unwrap();
let intrinsic: CoreIntrinsic = arch.get_field(instrinsic_id).unwrap();

@ElykDeer ElykDeer added the Component: Rust API Issue needs changes to the Rust API label May 28, 2024
@emesare emesare self-assigned this Sep 3, 2024
@emesare emesare self-requested a review September 3, 2024 14:44
@@ -2010,13 +2010,13 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
self.log(|| format!("Register {:?} ==> {:?}", reg, xreg));
self.arch
.register_by_name(xreg.to_string().to_lowercase())
.map(|reg| reg.id() as i64)
.map(|reg| reg.id().0 as i64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id().into()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but not using Into. Maybe something like reg.id().into_inner() or reg.raw_id().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The as i64 can be replaced with .into(). But the .0 can only be replaced with a appropriated named function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Rust API Issue needs changes to the Rust API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants