Skip to content

feat: add freestanding RISC-V support, migrate to opaque pointers, and enhance test runner#310

Merged
LunaStev merged 1 commit into
wavefnd:masterfrom
LunaStev:feat/add-freestanding-RISC-V-support-and-improve-test-runner
Mar 29, 2026
Merged

feat: add freestanding RISC-V support, migrate to opaque pointers, and enhance test runner#310
LunaStev merged 1 commit into
wavefnd:masterfrom
LunaStev:feat/add-freestanding-RISC-V-support-and-improve-test-runner

Conversation

@LunaStev
Copy link
Copy Markdown
Member

1. RISC-V & Freestanding Target Support

Wave is now capable of targeting bare-metal/freestanding environments, specifically for RISC-V 64-bit systems.

  • New Targets: Added FreestandingX86_64, FreestandingArm64, and FreestandingRISCV64 (riscv64-unknown-none-elf).
  • RISC-V C-ABI Lowering: Implemented System V ABI rules for RV64, including complex parameter classification (ByVal/SRet) to ensure compatibility with existing C-based firmware and kernels.
  • RISC-V Inline Assembly:
    • Full physical register mapping (x0-x31, a0-a7, t0-t6, etc.).
    • Support for standard constraints (r, m, i) and width calculations.
    • Automatic default clobbers for RISC-V call conventions.
  • Introspection: Updated the CLI print command to list RISC-V specific CPUs and target features.

2. LLVM Opaque Pointer Migration

To align with modern LLVM standards (LLVM 15+), the backend has been migrated to use Opaque Pointers.

  • Updated abi_c.rs, legacy.rs, and standard I/O generation (printf/scanf) to use context.ptr_type() instead of specific typed pointers (like i8*).
  • This resolves several LLVM API deprecation warnings and prepares the compiler for future LLVM versions.

3. Advanced Test Runner (tools/run_tests.py)

The Python test suite is now much more "aware" of the host environment, preventing false failures on incompatible platforms.

  • Metadata Parsing: Supports // wave-test: host-os=<os>, host-arch=<arch> headers at the top of .wave files.
  • Automated Filtering: The runner now skips tests that don't match the host (e.g., Linux-specific syscall tests are skipped when running on macOS).
  • Workflow Improvements:
    • Gracefully falls back to the debug build if the release binary is missing.
    • Exits with code 1 if any test fails, making it suitable for CI/CD pipelines.

4. Code Hygiene & Maintenance

  • Warning Fixes: Resolved various unused variable and function warnings across the lexer, parser, and codegen.
  • Dead Code: Added #[allow(dead_code)] to internal runner functions that are reserved for future debugger/REPL features.
  • Safety: Removed an unnecessary unsafe block from the LLVM version fetcher.

Benefits

  • Systems Programming: RISC-V support enables Wave to be used for OS kernel and embedded firmware development.
  • Modernization: Opaque pointers ensure the compiler remains compatible with the latest LLVM toolchains.
  • Developer Efficiency: The smarter test runner reduces "noise" by automatically skipping irrelevant tests for the contributor's platform.

This commit introduces backend support for freestanding targets, including a complete initial implementation for RISC-V (rv64), migrates LLVM APIs to use opaque pointers, and drastically improves the Python test runner to support architecture-specific tests.

[Details]

1. RISC-V and Freestanding Targets Support
  - Added new target configurations: `FreestandingX86_64`, `FreestandingArm64`, and `FreestandingRISCV64` (`riscv64-unknown-none-elf`).
  - Implemented C-ABI lowering rules (ByVal/SRet handling) for RISC-V 64-bit (`classify_param_riscv64`, `classify_ret_riscv64`).
  - Added inline assembly support for RISC-V, including physical register mapping (`x0`-`x31`, `a0`-`a7`, etc.), width calculations, default clobbers, and constraint validation (`r`, `m`, `i`, etc.).
  - Added RISC-V CPUs and target features to the CLI `print` commands.

2. LLVM Opaque Pointer Migration
  - Updated `abi_c.rs`, `legacy.rs`, and standard I/O generation (`printf`, `scanf`) to use modern LLVM opaque pointers (`context.ptr_type()`) instead of typed pointers (`i8_type().ptr_type()`), fixing API deprecation issues.

3. Test Runner & Metadata Improvements
  - Enhanced `tools/run_tests.py` to parse `// wave-test: host-os=<os>, host-arch=<arch>` metadata at the top of test files.
  - The test runner now automatically skips tests that do not match the host's OS or Architecture (e.g., skipping Linux syscall tests on macOS).
  - Applied metadata headers to existing hardware/OS-dependent tests (e.g., inline assembly and syscall tests).
  - Test runner now gracefully falls back to the `debug` build if the `release` binary is missing, and exits with code `1` if any tests fail.

4. Code Cleanup and Warning Fixes
  - Cleaned up unused variables, imports, and functions (e.g., removed `is_zero_decimal`, fixed `ASTNode::Enum` resolution).
  - Fixed an OS-specific unused import warning in `version.rs` (`std::fs`).
  - Removed an unnecessary `unsafe` block from the LLVM version fetcher.
  - Added `#[allow(dead_code)]` to currently unused runner functions.

Signed-off-by: LunaStev <youngjae681@gmail.com>
@LunaStev LunaStev merged commit f88a757 into wavefnd:master Mar 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant