Skip to content

Move GALEC code generation to templates#332

Open
pradyunnkale wants to merge 8 commits into
CogniPilot:mainfrom
pradyunnkale:galec-template-fix
Open

Move GALEC code generation to templates#332
pradyunnkale wants to merge 8 commits into
CogniPilot:mainfrom
pradyunnkale:galec-template-fix

Conversation

@pradyunnkale

Copy link
Copy Markdown
Collaborator

Moved the GALEC code generation from rust native to the templates to allow for more modularity in the actual printing of the text

Signed-off-by: Pradyunn Kale <kalepradyunn@gmail.com>
Copilot AI review requested due to automatic review settings July 24, 2026 15:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .alg template context and updates model.alg.jinja to 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)
},
@pradyunnkale

Copy link
Copy Markdown
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants