Skip to content

xc8plusplus Documentation

Welcome to xc8plusplus - a C++ to C transpiler for Microchip's XC8 compiler. This project enables modern C++ development for 8-bit PIC microcontrollers using semantic AST analysis.

Development Status

This project is currently in active development. APIs may change between versions.

AI-Generated Content Notice

A significant portion of this project's content (including code, documentation, and examples) has been generated using AI assistance. Please review all code and documentation carefully before use in production environments. We recommend thorough testing and validation of any AI-generated components.

Unofficial Project

This is an unofficial, community-driven project and is not affiliated with, endorsed by, or supported by Microchip Technology Inc. The XC8 compiler and PIC microcontrollers are products of Microchip Technology Inc.

πŸ“¦ Installation & Usage

Installation

# Install from source
git clone https://github.com/s-celles/xc8plusplus.git
cd xc8plusplus
pip install -e .

CLI Usage

# Transpile C++ to C with modern CLI
xc8plusplus transpile input.cpp --output output.c

# Show version and demo
xc8plusplus version
xc8plusplus demo

Python API

from xc8plusplus import XC8Transpiler

transpiler = XC8Transpiler()
success = transpiler.transpile("input.cpp", "output.c")

Project Documentation

πŸ—οΈ Architecture

Python Library

xc8plusplus is now a production-ready Python package with:

  • βœ… Modern CLI - Rich terminal interface with Typer and Rich
  • βœ… Python API - Clean programmatic interface
  • βœ… Comprehensive Tests - 13/13 tests passing with pytest
  • βœ… Modern Packaging - Standard src-layout with pyproject.toml
  • βœ… Real-world Validation - Tested with XC8 v3.00 on multiple PICs

Core Architecture Principles

Transformation Process

graph LR
    A[C++ Source] --> B[Clang AST Parser]
    B --> C[Semantic Analysis]
    C --> D[C Code Generator] 
    D --> E[XC8 Compatible C]
    E --> F[PIC Firmware]
  1. Clang AST Analysis - Compiler-grade C++ parsing
  2. Semantic Extraction - Class/method/field analysis with full type information
  3. C Generation - Memory-efficient struct and function transformation
  4. XC8 Compilation - Native XC8 compilation to PIC firmware

πŸ”¬ Research

Technical Foundations

Key Technical Discoveries

Discovery Impact Status
XC8 uses Clang 18.1.8 frontend Enables AST analysis approach βœ… Validated
PIC backend lacks C++ support Confirms need for transpilation βœ… Confirmed
Source-to-source is viable path Architectural validation βœ… Implemented
Memory constraints guide features Design principles established βœ… Applied

Validation Results

Successfully tested on real hardware: - βœ… PIC12F675 - Basic class transpilation and compilation - βœ… PIC16F84A - Method transformation validation
- βœ… PIC16F18877 - Complex feature testing

πŸ› οΈ Development

Python Library Status

Current Version: 0.1.0 - Production Ready!

  • βœ… Modern CLI - Rich terminal interface with Typer and Rich
  • βœ… Python API - Clean programmatic interface
  • βœ… Comprehensive Tests - 13/13 tests passing with pytest
  • βœ… Modern Packaging - Standard src-layout with pyproject.toml
  • βœ… Real-world Validation - Tested with XC8 v3.00 on multiple PICs

Supported Features

C++ Feature C Transformation Status
Classes C structs + functions βœ… Working
Member functions C functions with self βœ… Working
Member variables Struct fields βœ… Working
Constructors Init functions βœ… Working
Destructors Cleanup functions βœ… Working
Basic types XC8-compatible types βœ… Working

Development Environment

# Setup development environment
git clone https://github.com/s-celles/xc8plusplus.git
cd xc8plusplus
pip install -e ".[dev]"

# Run tests
pytest tests/ -v  # 13/13 passing!

Contributing

  1. Fork the repository
  2. Set up development environment
  3. Make changes with proper tests
  4. Ensure all tests pass
  5. Submit pull request

πŸ“š File Reference

Documentation Purpose
building.md Build instructions and development setup
implementation.md Technical architecture and implementation details
research-findings.md Project achievements and technical discoveries
why-python-is-wrong.md Why AST analysis beats string manipulation
xc8-architecture.md Deep dive into XC8 compiler internals
memory-constraints.md 8-bit PIC memory analysis and optimization
xc8-source-research.md XC8 source code investigation results

🎯 Project Roadmap

Current Release (v0.1.0)

  • βœ… Python package
  • βœ… CLI and API interfaces
  • βœ… Comprehensive test suite
  • βœ… Real hardware validation

Future Releases

  • πŸ”„ v0.2.0 - PyPI publication and extended C++ features
  • πŸ”„ v0.3.0 - IDE integration and advanced optimizations
  • πŸ”„ v1.0.0 - Full production release with complete C++ subset

πŸ“š API Reference

For detailed API documentation, see: - Python API Reference - Complete XC8Transpiler class documentation - CLI Commands - Command-line interface reference - Usage Examples - Code examples and patterns


License: Apache 2.0 + LLVM Exceptions (same as Clang)