Move GALEC code generation to templates#332
Open
pradyunnkale wants to merge 8 commits into
Open
Conversation
Signed-off-by: Pradyunn Kale <kalepradyunn@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR moves GALEC export text generation fully onto minijinja templates by replacing Rust “string printers” with typed, serializable codegen contexts (GALEC .alg and embedded C). This aligns GALEC outputs with the existing rumoca-phase-codegen template ownership boundary and improves modularity of emitted text formatting.
Changes:
- Introduces a structured GALEC
.algtemplate context and updatesmodel.alg.jinjato render GALEC syntax directly. - Replaces the embedded-C Rust printer with a structured C codegen IR (
c_lower) and updates the C templates to render all C tokens. - Updates specs and tests to reflect template-owned code generation and the new structured context shapes.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| spec/SPEC_0034_GALEC_EFMI_EXPORT.md | Updates GALEC pipeline/spec text to make templates the sole owners of emitted GALEC/C/XML tokens. |
| spec/SPEC_0029_CRATE_BOUNDARIES.md | Removes the recorded .alg printer exception; documents template-owned .alg rendering. |
| crates/rumoca/src/target_manifest.rs | Adjusts GALEC render environment and wiring to support included templates and structured contexts. |
| crates/rumoca-phase-codegen/src/templates/galec/target.toml | Updates template ownership notes for .alg rendering from structured context. |
| crates/rumoca-phase-codegen/src/templates/galec/model.alg.jinja | Implements GALEC .alg rendering logic (names/refs/exprs/decls) in Jinja. |
| crates/rumoca-phase-codegen/src/templates/galec-production/target.toml | Updates documentation to reflect structured-context rendering for .alg/.h/.c. |
| crates/rumoca-phase-codegen/src/templates/galec-production/model.h.jinja | Switches to including the shared embedded-C header template. |
| crates/rumoca-phase-codegen/src/templates/galec-production/model.c.jinja | Switches to including the shared embedded-C source template. |
| crates/rumoca-phase-codegen/src/templates/galec-production/model.alg.jinja | Switches to including the shared GALEC .alg template (keeps output identical). |
| crates/rumoca-phase-codegen/src/templates/embedded-c-galec/target.toml | Updates ownership notes: templates now own all C token emission. |
| crates/rumoca-phase-codegen/src/templates/embedded-c-galec/model.h.jinja | Renders C scalar type spelling in-template from scalar_type. |
| crates/rumoca-phase-codegen/src/templates/embedded-c-galec/model.c.jinja | Adds full expression/statement rendering macros for structured C IR. |
| crates/rumoca-galec-codegen/tests/spec_0034_battery.rs | Updates tests to assert structured C IR normalization instead of printed C lines. |
| crates/rumoca-galec-codegen/tests/efmi_discrete_pid_lowering.rs | Updates tests to validate structured C IR shape and removal of c_lines. |
| crates/rumoca-galec-codegen/src/package.rs | Updates crate docs to reflect template-context validation boundary. |
| crates/rumoca-galec-codegen/src/lower.rs | Changes post-validation to validate template contexts rather than rendered strings. |
| crates/rumoca-galec-codegen/src/lib.rs | Re-exports new APIs (c_lower) and updates module docs to match new architecture. |
| crates/rumoca-galec-codegen/src/emit.rs | Adds GALEC algorithm template context; refactors C context to structured IR and scalar-type tags. |
| crates/rumoca-galec-codegen/src/c_print.rs | Removes the GALEC→C99 string printer implementation. |
| crates/rumoca-galec-codegen/src/c_lower.rs | Adds GALEC→structured C codegen IR lowering used by templates. |
| crates/rumoca-compile/src/galec_api.rs | Updates packaging plan to carry structured contexts and render via templates; adds equality check against formatter oracle. |
Comment on lines
271
to
284
| let ctx_value = plan | ||
| .template_ctx(template, checksums) | ||
| .map_err(anyhow::Error::from)?; | ||
| env.render_str( | ||
| source.as_ref(), | ||
| minijinja::context! { | ||
| model_name => model_identifier, | ||
| galec_alg_source => plan.alg_text(), | ||
| galec_c_header => plan.c_header(), | ||
| galec_c_source => plan.c_source(), | ||
| conformance_header => minijinja::context! { | ||
| lines => rumoca_compile::galec::PRODUCTION_CONFORMANCE_LINES, | ||
| summary => rumoca_compile::galec::PRODUCTION_CONFORMANCE_SUMMARY, | ||
| }, | ||
| ctx => minijinja::Value::from_serialize(&ctx_value), | ||
| ..minijinja::Value::from_serialize(&ctx_value) | ||
| }, |
Signed-off-by: Pradyunn Kale <kalepradyunn@gmail.com>
Signed-off-by: Pradyunn Kale <kalepradyunn@gmail.com>
Collaborator
Author
|
part of the changes here are also fixes to the GALEC projection itself, because the passthrough of the block structure is not preserved on the current DAE IR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moved the GALEC code generation from rust native to the templates to allow for more modularity in the actual printing of the text