Skip to content

Conversation

@LunaStev
Copy link
Member

@LunaStev LunaStev commented Dec 7, 2025

Summary

Refactor the CLI interface to support optimization level specification and granular debug output capabilities. Improves developer experience through modularized structure and enhanced error handling.

Changes

Library Configuration

  • Add library target configuration to Cargo.toml
    • Expose wavec as both binary and library
    • Specify lib.rs path explicitly

CLI Argument Parsing Refactor

  • Extract commands module
    • Separate command handling into handle_run and handle_build functions
    • Introduce DebugFlags struct for modular debug output control
  • Add optimization flag support: -O0, -O1, -O2, -O3, -Oz, -Ofast
  • Remove verbose flag (replaced by debug modes)

Debug Output System

  • --debug-wave=tokens: Display lexer token stream
  • --debug-wave=ast: Show abstract syntax tree
  • --debug-wave=ir: Print LLVM intermediate representation
  • --debug-wave=mc: Display machine code path
  • --debug-wave=hex: Dump binary in hexadecimal format
  • --debug-wave=all: Enable all debug outputs

Compilation Pipeline Updates

  • Pass optimization flag to clang invocation
  • Thread debug flags through runner and backend
  • Remove standalone CompilerConfig system

Simplify runner.rs Execution Flow

  • Change from buffering to direct output
  • Remove unused import resolution code
  • Pass opt_flag and debug_flags to backend

Error Handling Improvements

  • Add dedicated errors module
  • Define CliError enum (NotEnoughArgs, UnknownCommand, MissingArgument)
  • Implement Display trait for formatted error messages

Help Output Improvements

  • Group commands, optimization, and debug options
  • Add practical usage examples
  • Remove verbose mode information

Usage Examples

# Basic execution
wavec run test.wave

# With optimization level
wavec run -O3 test.wave

# With IR debug output
wavec run --debug-wave=ir test.wave

# Maximum optimization with all debug outputs
wavec run -Ofast --debug-wave=all test.wave

Benefits

  • Granular Control: Independent control over optimization levels and debug outputs
  • Improved Developer Experience: Clear error messages and structured help text
  • Modularity: Separated command handling and error handling for better maintainability
  • Flexibility: Usable as both binary and library

Refactor command-line interface to support optimization levels and
comprehensive debug output modes with improved error handling.

Changes:
- Add library target configuration to Cargo.toml:
  - Expose wavec as both binary and library
  - Enable path specification for lib.rs
- Refactor CLI argument parsing:
  - Extract commands module with handle_run/handle_build functions
  - Add DebugFlags struct for modular debug output control
  - Support optimization flags (-O0, -O1, -O2, -O3, -Oz, -Ofast)
  - Remove verbose flag in favor of debug modes
- Implement debug output system:
  - --debug-wave=tokens: Display lexer token stream
  - --debug-wave=ast: Show abstract syntax tree
  - --debug-wave=ir: Print LLVM intermediate representation
  - --debug-wave=mc: Display machine code path
  - --debug-wave=hex: Dump binary in hexadecimal format
  - --debug-wave=all: Enable all debug outputs
- Update compilation pipeline:
  - Pass optimization flag to clang invocation
  - Thread debug flags through runner and backend
  - Remove standalone CompilerConfig system
- Simplify runner.rs execution flow:
  - Direct output instead of buffering
  - Remove unused import resolution code
  - Pass opt_flag and debug flags to backend
- Add dedicated errors module:
  - Define CliError enum (NotEnoughArgs, UnknownCommand, MissingArgument)
  - Implement Display trait for formatted error messages
- Streamline help output:
  - Group commands, optimization, and debug options
  - Add practical usage examples
  - Remove verbose mode information

Examples:
  wavec run test.wave
  wavec run -O3 test.wave
  wavec run --debug-wave=ir test.wave
  wavec run -Ofast --debug-wave=all test.wave

The refactored CLI provides better developer experience with granular
control over optimization and debugging output.
@LunaStev LunaStev merged commit 55a4cf9 into master Dec 7, 2025
2 checks passed
@LunaStev LunaStev deleted the cli_llvm branch December 13, 2025 11:35
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.

2 participants