How oceanosdev/mycc works
This repository implements the Com S 440 compiler project: it reads C-like source, parses and type-checks the documented language features, and includes a JVM bytecode generation backend. The principal workflow is source input through parsing, binding/type checking, and code generation; command-line modes also expose token, syntax-tree, and bound-tree output. The tree shows distinct flow-analysis and bound-tree-rewriting subsystems, but sampled excerpts do not establish their exact connection to code generation, so that wiring is omitted.
Main entry points: main.cpp Mode Dispatcher · binder.cpp Binder and Type Checker · driver.cpp Lexer and Parser · j_asm_builder.cpp JVM Assembler
Components 20
Front End
- Mode Dispatcher
main.cpp - Argument Parser
arg_parser.cpp - Lexer and Parser
driver.cpp - Lexical Analysis
lexer.h - Syntax Trees
syntax/translation_unit_node.cpp - Syntax Tree Output
syntax_tree_printer.cpp
Semantic Analysis
- Binder and Type Checker
binding/binder.cpp - Bound Trees
binding/bound_program.cpp - Symbols and Types
symbols/type_symbol.cpp - Bound Tree Output
bound_tree_printer.cpp - Bound Tree Rewriter
binding/tree_rewriter.cpp
JVM Backend
- Code Generator
codegen/code_generator.cpp - Statement and Expression Emission
codegen/code_gen_emit_stmt.cpp - JVM Assembler
jvm_processor/j_asm_builder.cpp - JVM Instructions
jvm_processor/instruction.cpp - Generated JVM Body
jvm_processor/finalized_body.h
Diagnostics and Analysis
- Control Flow Analysis
flow_analysis/control_flow_graph_factory.cpp - Diagnostics
logging/diagnostics.cpp - Output Logger
logging/logger.cpp
Other components
- Compiler User
Connections 18
- Compiler User → Mode Dispatcher: selects mode
- Mode Dispatcher → Argument Parser: parses options
- Mode Dispatcher → Lexer and Parser: runs parsing
- Lexer and Parser → Lexical Analysis: scans source
- Lexer and Parser → Syntax Trees: builds units
- Mode Dispatcher → Syntax Tree Output: prints syntax tree
- Mode Dispatcher → Binder and Type Checker: binds program
- Binder and Type Checker → Bound Trees: produces bound tree
- Binder and Type Checker → Symbols and Types: resolves types
- Binder and Type Checker → Diagnostics: reports errors
- Mode Dispatcher → Bound Tree Output: prints bound tree
- Mode Dispatcher → Code Generator: starts generation
- Code Generator → Statement and Expression Emission: emits statements
- Statement and Expression Emission → JVM Assembler: builds instructions
- JVM Assembler → JVM Instructions: records instructions
- JVM Assembler → Generated JVM Body: finalizes body
- Mode Dispatcher → Output Logger: selects output
- Diagnostics → Output Logger: logs diagnostics