Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/TestingCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,22 @@ jobs:
run: cargo test --release --verbose
- name: Run fmt check
run: cargo fmt --all -- --check

windows-native:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup MSVC
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
- name: Install LLVM/Clang
run: choco install llvm -y
- name: Add LLVM to PATH
run: echo "C:\Program Files\LLVM\bin" >> $env:GITHUB_PATH
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Build
run: cargo build --release --verbose
- name: Run tests
run: cargo test --release --verbose
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ keywords = ["basic", "compiler", "x86-64", "retro", "programming-language"]
categories = ["compilers", "command-line-utilities", "development-tools"]
rust-version = "1.85"

[features]
default = []

[dependencies]
clap = { version = "4", features = ["derive"] }

Expand Down
62 changes: 62 additions & 0 deletions src/abi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//! ABI abstraction layer for x86-64 calling conventions
//!
//! Provides platform-specific constants for System V AMD64 (Linux, macOS, BSD)
//! and Win64 (Windows) ABIs.

// Copyright (c) 2025-2026 Jeff Garzik
// SPDX-License-Identifier: MIT

/// Calling convention abstraction for x86-64
pub trait Abi {
/// Integer/pointer argument registers (in order)
const INT_ARG_REGS: &'static [&'static str];

/// Symbol prefix for external symbols ("_" on macOS, "" elsewhere)
const SYMBOL_PREFIX: &'static str;
}

/// System V AMD64 ABI (Linux, macOS, BSD)
pub struct SysV64;

impl Abi for SysV64 {
const INT_ARG_REGS: &'static [&'static str] = &["rdi", "rsi", "rdx", "rcx", "r8", "r9"];

#[cfg(target_os = "macos")]
const SYMBOL_PREFIX: &'static str = "_";
#[cfg(not(target_os = "macos"))]
const SYMBOL_PREFIX: &'static str = "";
}

/// Windows x64 ABI
#[cfg(any(windows, test))]
pub struct Win64;

#[cfg(any(windows, test))]
impl Abi for Win64 {
const INT_ARG_REGS: &'static [&'static str] = &["rcx", "rdx", "r8", "r9"];
const SYMBOL_PREFIX: &'static str = "";
}

/// Type alias for the current platform's ABI
#[cfg(windows)]
pub type PlatformAbi = Win64;

#[cfg(not(windows))]
pub type PlatformAbi = SysV64;

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_sysv64_int_regs() {
assert_eq!(SysV64::INT_ARG_REGS.len(), 6);
assert_eq!(SysV64::INT_ARG_REGS[0], "rdi");
}

#[test]
fn test_win64_int_regs() {
assert_eq!(Win64::INT_ARG_REGS.len(), 4);
assert_eq!(Win64::INT_ARG_REGS[0], "rcx");
}
}
Loading