You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -73,7 +71,7 @@ Each C function becomes a VHDL entity with clock/reset ports, input parameters a
73
71
- Self-contained functions with return value propagation, plus structs and arrays
74
72
- VHDL entity/architecture generation with clock/reset, signals, and synchronous processes
75
73
- Multi-level error diagnostics (error/warning/note across 5 categories)
76
-
-81 unit, integration, structural validation, and edge case tests (GoogleTest)
74
+
-GoogleTest-based unit, integration, structural validation, and edge case coverage
77
75
78
76
## Requirements
79
77
@@ -115,7 +113,7 @@ examples/ — Sample C input files
115
113
- No pointer support
116
114
- No `switch/case` or `do-while`
117
115
- Function calls are parsed, but cross-function hardware wiring is not yet synthesized. Multi-function files emit independent entities, so keep hardware-generating examples self-contained.
118
-
- Generated VHDL targets the currently supported C subset. Structural well-formedness is verified by self-contained validation tests (balanced constructs, declared signals, proper type wrapping). The output is unoptimized — no resource sharing, no pipelining, no constant folding (see [ROADMAP.md](ROADMAP.md)Phase 4 for planned optimizations)
116
+
- Generated VHDL targets the currently supported C subset. Structural well-formedness is verified by self-contained validation tests (balanced constructs, declared signals, proper type wrapping). Current output does not perform resource sharing, pipelining, or constant folding (see [ROADMAP.md](ROADMAP.md) for planned future work)
- Global tables for struct definitions and array size tracking.
73
-
- **Rationale**: Struct types and array sizes are needed during code generation but are discovered during parsing. A global table provides O(1) lookup without threading pointers through the AST.
73
+
- **Rationale**: Struct types and array sizes are needed during code generation but are discovered during parsing. A global table keeps that information available without threading additional context through the AST.
74
74
- **Limitation**: Not thread-safe. For parallel compilation, each thread would need isolated symbol tables.
75
75
- **Reset**: Call ``reset_struct_table()`` and ``reset_array_table()`` between compilations.
* Each helper function is easily testable in isolation
220
-
* Clear separation between different expression types
221
-
* Much easier to understand and maintain
218
+
* Each helper function can be tested in isolation
219
+
* Expression handling is separated into focused helpers
220
+
* The control flow is easier to follow and modify
222
221
223
222
parse_statement.c
224
223
~~~~~~~~~~~~~~~~~
@@ -275,13 +274,12 @@ parse_statement.c
275
274
ASTNode *struct_node, *field_node;
276
275
int index_value, array_size;
277
276
278
-
**Impact:**
277
+
**Result:**
279
278
280
-
* 87% reduction in main function size
281
-
* Each statement type has dedicated, testable function
282
-
* Much clearer control flow
283
-
* Easy to add new statement types
284
-
* Dramatically improved maintainability
279
+
* Each statement type has a dedicated, testable function
280
+
* Control flow is easier to trace
281
+
* New statement types can be added within the existing structure
282
+
* Maintenance work is localized to smaller helpers
285
283
286
284
parse_function.c
287
285
~~~~~~~~~~~~~~~~
@@ -590,12 +588,12 @@ The refactoring effort delivered significant improvements:
590
588
* Pattern is established and consistent
591
589
* New contributors can easily follow established style
592
590
593
-
**Quality Metrics:**
591
+
**Observed outcomes:**
594
592
595
-
* Average function length reduced by 70-85%
596
-
* Cyclomatic complexity reduced significantly
597
-
* Code duplication eliminated
598
-
* Named constants replace all magic numbers
593
+
* Helper functions are shorter and more focused
594
+
* Named constants replace magic numbers in the refactored areas
595
+
* Repeated parsing patterns were extracted into shared helpers
596
+
* Control-flow handling follows a consistent structure across modules
599
597
600
598
Future Refactoring Opportunities
601
599
---------------------------------
@@ -629,14 +627,14 @@ Areas for potential future improvement:
629
627
Conclusion
630
628
----------
631
629
632
-
The comprehensive refactoring of the parser modules has transformed the codebase from a collection of monolithic functions into a well-organized, maintainable, and extensible foundation. The established patterns and principles provide a clear model for future development and make the compiler significantly easier to understand, modify, and extend.
630
+
The parser refactoring replaced large monolithic functions with smaller helpers and clearer module boundaries. The resulting structure provides a concrete model for future changes and makes the compiler easier to review, modify, and extend.
633
631
634
632
The refactoring demonstrates that **code quality is not just about correctness** — it's about creating code that is:
635
633
636
634
* Easy to understand
637
635
* Easy to modify
638
636
* Easy to test
639
637
* Easy to extend
640
-
* A pleasure to work with
638
+
* Consistent with the surrounding codebase
641
639
642
640
These improvements lay a solid foundation for future compiler enhancements and serve as a model for maintaining high code quality throughout the project.
* **Efficient child storage** with amortized O(1) insertion
612
+
* **Geometric child-array growth** as nodes are added
637
613
* **Bidirectional tree links** for flexible traversal
638
-
* **Recursive memory deallocation** for easy cleanup
614
+
* **Recursive memory deallocation** for straightforward cleanup
639
615
640
-
The design prioritizes **simplicity and ease of use** over memory efficiency, making it straightforward to construct and traverse the AST during parsing and code generation.
616
+
The design prioritizes **simplicity and ease of use** over more specialized representations, making it straightforward to construct and traverse the AST during parsing and code generation.
Copy file name to clipboardExpand all lines: docs/source/internals/codegen.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,7 +76,7 @@ Internal function that dispatches to specialized generators based on node type:
76
76
}
77
77
}
78
78
79
-
**Design:** Uses switch statement for efficient dispatch. Ignores node types that don't directly produce VHDL output (e.g., ``NODE_VAR_DECL`` is handled within statement generation).
79
+
**Design:** Uses a central switch-based dispatcher. Node types that do not directly produce VHDL output are handled in the relevant higher-level generators (for example, ``NODE_VAR_DECL`` is handled within statement generation).
0 commit comments