Skip to content

Implement wrappers around the Architecture ID types#5431

Closed
rbran wants to merge 2 commits intoVector35:devfrom
rbran:no-naked-id
Closed

Implement wrappers around the Architecture ID types#5431
rbran wants to merge 2 commits intoVector35:devfrom
rbran:no-naked-id

Conversation

@rbran
Copy link
Copy Markdown
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
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@emesare
Copy link
Copy Markdown
Member

emesare commented Jan 2, 2025

This is available with ace9ba8

However I didn't add that field helper, I find that a little useless, maybe I misunderstand the purpose but it seems unnecessary. Please correct me if I'm wrong.

@rbran
Copy link
Copy Markdown
Contributor Author

rbran commented Jan 2, 2025

Do you mean the ArchitectureFromId::into_value? It was mostly to allow the creation of the function Architecture::field, that allow the user to get any kind of field using a single function.

@emesare emesare mentioned this pull request Jan 13, 2025
@emesare
Copy link
Copy Markdown
Member

emesare commented Jan 25, 2025

This PR was merged with the rust refactor, 6a63c17. Thank you @rbran!

@emesare emesare closed this Jan 25, 2025
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