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.
π Quick Links¶
π¦ 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¶
- Building & Setup - Development environment setup
- Implementation Guide - Technical architecture deep dive
- Quick Start Guide - Get up and running in 5 minutes
ποΈ 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¶
- Semantic AST Analysis - Why we use Clang AST instead of string manipulation
- XC8 Integration - Deep technical analysis of XC8 compiler internals
- Memory Optimization - Code generation for 8-bit microcontroller constraints
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]
- Clang AST Analysis - Compiler-grade C++ parsing
- Semantic Extraction - Class/method/field analysis with full type information
- C Generation - Memory-efficient struct and function transformation
- XC8 Compilation - Native XC8 compilation to PIC firmware
π¬ Research¶
Technical Foundations¶
- Research Findings - Project achievements and technical discoveries
- Memory Constraints - Analysis of 8-bit PIC memory limitations
- XC8 Source Research - Investigation of XC8 compiler internals
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¶
- Fork the repository
- Set up development environment
- Make changes with proper tests
- Ensure all tests pass
- 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)