-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Summary
Summary
Currently size_t is determined in _get_size_t_type_from_triple() by checking architecture names inside the target triple string. While this works for common architectures, LLVM already exposes pointer size information through target_machine.target_data, which could be used to determine the correct size_t width more reliably.
Using LLVM’s data layout instead of string matching may simplify the implementation and make it more robust across different targets.
Current Implementation
In src/irx/builders/llvmliteir.py, _get_size_t_type_from_triple() determines the width of size_t by matching architecture names in the target triple.
Example logic:
x86_64,aarch64,arm64, etc → 64-biti386,i686,arm, etc → 32-bit- fallback → host
ctypessize
This requires maintaining architecture string checks manually.
Proposed Improvement
Instead of inferring the width from the triple string, it may be possible to derive size_t directly from the LLVM target data layout.
Example idea:
ptr_size = self.target_machine.target_data.pointer_size
return ir.IntType(ptr_size * 8)
This would rely on LLVM’s target information rather than architecture string matching.
Benefits
- More robust across different architectures
- Removes manual triple string checks
- Automatically supports additional targets
- Simpler and cleaner implementation
Additional Context
This builds on the work from PR #134 which fixed issue #132 by:
- setting
module.triple - setting
module.data_layout - removing the forced 64-bit
size_toverride
If this approach sounds reasonable, I’d be happy to work on implementing it and adding tests.
Additional Information
Code of Conduct
- I agree to follow the Code of Conduct