feat: implement TypeFlavor and enhance inline assembly operand handling#282
Merged
LunaStev merged 1 commit intowavefnd:masterfrom Feb 5, 2026
Conversation
This commit introduces the concept of "TypeFlavor" to distinguish between
high-level value types and ABI-compliant types during LLVM IR generation.
It also significantly improves the robustness of inline assembly by
implementing operand bit-width normalization and sign-aware extension.
Changes:
- **Type Flavoring & ABI Compatibility**:
- Introduced `TypeFlavor` (Value vs. AbiC) in `types.rs`.
- Updated `wave_type_to_llvm_type` to handle context-specific types;
for example, Booleans are now emitted as `i8` when using `TypeFlavor::AbiC`
to ensure C ABI compatibility.
- Refactored all codegen entry points (functions, structs, variables)
to utilize these flavors.
- **Enhanced Inline Assembly**:
- Implemented automatic sign/zero extension for inline assembly input
operands. The compiler now infers signedness from the source expression
to decide between `sext` and `zext` when promoting integers to
register widths.
- Added operand normalization for assembly outputs. If a target register
has a specific bit width (e.g., 64-bit for 'r' constraints), the
compiler now correctly truncates or extends the result to match the
destination variable.
- Refactored `coerce_basic_value_for_store` to handle a wider range
of integer-to-pointer and float-to-int conversions for assembly outputs.
- **LLVM Backend Improvements**:
- **Literals**: Added support for recursive literal generation when
an `ArrayType` is the expected target type.
- **Type Inference**: Added `infer_signedness` utility to assist
in correct integer promotion during codegen.
- **Cleanup**:
- Removed unused imports and clarified internal documentation in
the parser and codegen modules.
These changes provide more predictable behavior when interfacing with
system-level assembly and ensure better compatibility with external C
libraries.
Signed-off-by: LunaStev <luna@lunastev.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a significant enhancement to Wave's type system and LLVM backend by implementing "Type Flavors." This architectural change allows the compiler to distinguish between high-level value representations and ABI-compliant types required for C FFI. Additionally, the inline assembly (
asm) engine has been overhauled to handle register bit-width normalization and sign-aware operand promotion, making system-level programming more predictable and robust.Key Changes
1. Type Flavoring & ABI Compatibility
TypeFlavorEnum: IntroducedTypeFlavorintypes.rswith two variants:Value(internal representation) andAbiC(C ABI compliant).wave_type_to_llvm_typeto adjust types based on the flavor. For example, when usingAbiC, Booleans are now emitted asi8rather thani1to ensure correct parameter passing when calling external C functions.2. Robust Inline Assembly (
asm) Improvementsinfer_signednessutility to decide between sign-extension (sext) and zero-extension (zext) when promoting values to match target register widths.coerce_basic_value_for_storeto support a wider range of conversions for assembly results, including complex integer-to-pointer and float-to-int mappings.3. LLVM Backend Utilities
ArrayType. This allows complex nested initializers to be generated more reliably.infer_signednesshelper to assist the codegen engine in making mathematically correct decisions during type promotion and comparison.4. Maintenance & Hygiene
Impact
Before: Passing a
boolto a C function might result ini1being passed, which some C ABIs handle inconsistently.After: With
TypeFlavor::AbiC, theboolis correctly passed as ani8(0 or 1), matching standard C expectations.Benefits
asmblocks prevents subtle bugs related to sign-extension and bit-truncation.