CompileX transforms the compilation process into an explainable, interactive, and sustainable experience. It's an AI-enhanced compiler sandbox that provides transparency into compiler decisions, sustainability metrics, and interactive learning tools.
- Multi-Language Support: C, C++, Java, Python
- AI-Powered Explanations: Gemini AI explains errors, optimizations, and IR code
- Green Score Analysis: Performance vs sustainability trade-offs
- Interactive Pipeline Visualization: See how your code flows through compilation stages
- RAG Chatbot: Ask questions about compilers, optimizations, and your code
- Real-time Error Fixing: AI suggests and applies fixes to your code
- Explainable Compilation: Visual pipeline with step-by-step explanations
- Sustainability Metrics: First compiler tool to show energy/carbon trade-offs
- Educational Focus: Perfect for students learning compiler internals
- Interactive Learning: Experiment with different optimization levels
- Python 3.8+
- Clang/LLVM (for C/C++ support)
- Java Development Kit (for Java support)
- Google Gemini API key
- Clone the repository
git clone <repository-url>
cd compilex- Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Set up environment variables
Create a
.envfile in the project root:
GEMINI_API_KEY=your_gemini_api_key_here- Create demo snippets directory
mkdir -p demo_snippetsCreate the demo files:
demo_snippets/hello_world.cdemo_snippets/error_missing_semicolon.cdemo_snippets/optimization_constfold.c
streamlit run app.pyThe application will be available at http://localhost:8501
compilex/
├── app.py # Main Streamlit application
├── compiler_utils.py # Core compilation engine
├── explainers.py # AI explanation engine
├── visualizers.py # Visualization components
├── rag_chatbot.py # RAG-based chatbot
├── demo_snippets/ # Sample code snippets
│ ├── hello_world.c
│ ├── error_missing_semicolon.c
│ └── optimization_constfold.c
├── outputs/ # Generated during runtime
├── chroma_db/ # Vector database (created automatically)
├── requirements.txt # Python dependencies
├── .env # Environment variables
└── README.md # This file
- Select your programming language (C, C++, Java, Python)
- Choose optimization level (-O0, -O1, -O2, -O3)
- Write or load demo code
- Click "Compile & Analyze"
- Diagnostics Tab: View compilation errors/warnings with AI explanations
- IR Analysis Tab: Explore intermediate representation with AI insights
- Optimizations Tab: See applied optimizations and their impacts
- Pipeline Tab: Visualize the compilation pipeline
- Performance Score: How fast your optimized code runs
- Sustainability Score: Energy efficiency of compilation choices
- Detailed Metrics: Breakdown of energy consumption factors
- Ask questions about compiler errors
- Get explanations of optimizations
- Learn about performance vs sustainability trade-offs
- Use quick question buttons for common queries
When compilation errors occur:
- Click "Apply AI Fix" button
- Review the suggested fix
- Apply it to your code automatically
- For C/C++: Clang compiler (
clang,clang++) - For Java: Java Development Kit (JDK 8+)
- For Python: Python 3.x (usually pre-installed)
sudo apt update
sudo apt install clang llvm default-jdk python3# Install Xcode Command Line Tools
xcode-select --install
# Or using Homebrew
brew install llvm openjdk- Install Visual Studio Build Tools or Visual Studio Community
- Download and install OpenJDK
- Ensure Python is installed from python.org
- Google Gemini API: Get your free API key from Google AI Studio
Our Green Score is based on research-backed proxies for energy consumption:
- Compile Time (50%): CPU energy during compilation
- Instruction Count (30%): Runtime execution complexity
- IR/Binary Size (20%): Memory and storage efficiency
- Green Software Foundation guidelines on measuring software energy consumption
- Academic research on compiler optimization energy trade-offs
- Industry best practices for sustainable software development
energy_proxy = 0.5×normalize(compile_time) + 0.3×normalize(inst_count) + 0.2×normalize(ir_size)
green_score = 100 - energy_proxy×100
- Error Explanations: Plain English explanations of compilation errors
- IR Analysis: Breaking down intermediate representations
- Optimization Insights: Understanding compiler optimizations
- Code Fixes: Automatic error correction suggestions
- Knowledge Base: Pre-loaded with compiler and optimization knowledge
- Context Aware: Understands your current code and compilation results
- Conversational: Maintains context across multiple questions
- Extensible: Knowledge base can be expanded with new information
- Compiler Theory: Visualize compilation pipeline stages
- Optimization Learning: See real optimization effects
- Error Understanding: Learn from AI explanations
- Interactive Experimentation: Try different code patterns
- Teaching Tool: Visual compiler pipeline demonstrations
- Assignment Platform: Students can experiment and learn
- Sustainability Education: Introduce green software concepts
- Assessment: Compare student approaches to optimization
- Debugging Aid: Understand complex compilation errors
- Optimization Analysis: Make informed performance decisions
- Sustainability Awareness: Consider environmental impact
- Learning Platform: Deepen compiler knowledge
Edit compiler_utils.py to add custom compiler configurations:
self.compilers['c']['compile_flags']['-Ofast'] = ['-Ofast', '-march=native']Extend the CompilerEngine class to support additional languages:
- Add compiler configuration
- Implement analysis methods
- Update language detection logic
Add new compiler knowledge to the RAG chatbot:
chatbot.add_to_knowledge_base(
content="Your compiler knowledge here",
metadata={"topic": "optimization", "language": "rust"},
doc_id="unique_identifier"
)- Use meaningful variable names for better IR readability
- Include comments to help AI explanations
- Try different optimization levels to see trade-offs
- Experiment with code patterns to learn optimization effects
- Ensure adequate RAM for large compilations
- Use SSD storage for faster I/O operations
- Close unnecessary applications during analysis
- Consider compiler caching for repeated analyses
Compiler Not Found
# Check if compilers are installed
clang --version
javac -version
python3 --versionAPI Key Issues
- Verify your Gemini API key is correct
- Check API quota limits
- Ensure
.envfile is in the project root
ChromaDB Issues
# Clear vector database if corrupted
rm -rf chroma_db/
# Restart the application to rebuildMemory Issues
- Reduce IR code size limits in
explainers.py - Limit conversation history in
rag_chatbot.py - Close browser tabs to free memory
- Check the error message in the application
- Review terminal output for detailed errors
- Verify all dependencies are installed
- Ensure API keys are properly configured
- Fork the repository
- Create feature branch
- Make changes with tests
- Submit pull request
- Follow PEP 8 for Python code
- Use meaningful variable names
- Add docstrings for public methods
- Comment complex algorithms
# Install development dependencies
pip install pytest black isort
# Run tests
pytest
# Format code
black .
isort .- Google Gemini AI for natural language processing
- Streamlit for the web application framework
- Plotly for interactive visualizations
- ChromaDB for vector database capabilities
- LLVM/Clang for compiler infrastructure
- Green Software Foundation for sustainability guidelines
CompileX promotes sustainable software development by:
- Making energy trade-offs visible to developers
- Educating about green software practices
- Providing tools to measure compilation sustainability
- Encouraging responsible optimization choices
For support, questions, or feedback:
- Create an issue in the repository
- Check the troubleshooting section
- Review documentation and examples
CompileX - Making compilers transparent, sustainable, and human-friendly! 🌱⚡