Code Generator (code_gen.py)
code_gen
VersionInfo
Bases: object
Encapsulates build and version metadata for the code generator execution.
This class queries the current Git repository state to fetch the HEAD commit hash and checks if there are uncommitted changes, appending metadata to identify the exact codebase state used to generate the output files.
Source code in code/code_gen/code_gen.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
__init__(input_raw)
Initializes VersionInfo with build date, git hash, and terms metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_raw |
str
|
The raw input string containing DSL term definitions. |
required |
Source code in code/code_gen/code_gen.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
fparams()
Formats the collected build parameters into a single string.
Returns:
| Name | Type | Description |
|---|---|---|
str |
Multi-line string summarizing build date, revision, and terms details. |
Source code in code/code_gen/code_gen.py
68 69 70 71 72 73 74 | |
build_info(terms_raw)
Generates and prints build information for the current code generation run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
terms_raw |
str
|
The raw string contents of the DSL terms specification input file. |
required |
Source code in code/code_gen/code_gen.py
186 187 188 189 190 191 192 193 | |
compile_terms(terms_raw)
Parses DSL terms spec and runs it through the five compiler stages.
This function initializes a new CompilationContext and executes the compiler pipeline
sequentially: parsing, derivative/fluctuation expansion, SymPy expression simplification,
data dependency resolution, and array buffer pooling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
terms_raw |
str
|
The raw string contents of the DSL terms specification input file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
CompilationContext |
The fully compiled and optimized compilation context. |
Source code in code/code_gen/code_gen.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
escape_fortran_string(s)
Escapes string content for standard Fortran source formatting.
Converts internal double quotes into double-double quotes and splits the string lines,
wrapping them in Fortran concatenation syntax // char(10) // & to respect line length limit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s |
str
|
The raw string to escape. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The escaped and formatted Fortran string parameter literal. |
Source code in code/code_gen/code_gen.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
generate_build_info_module(terms_raw)
Generates a complete standard Fortran module containing build info and LaTeX equations.
The generated module contains metadata about the compiler run, including the build base Git hash, and a string representations of the LaTeX equations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
terms_raw |
str
|
The raw string contents of the DSL terms specification input file. |
required |
Source code in code/code_gen/code_gen.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
get_latex_equations_str(ctx)
Generates the LaTeX equations dictionary string from the context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx |
CompilationContext
|
The compiled context containing the averaged fields. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
A formatted string representing a Python dictionary mapping field names to LaTeX code. |
Source code in code/code_gen/code_gen.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
test(terms_raw, report=False, latex=False)
Compiles the post-processing term specifications from DSL into targets.
This compiles the Lark AST through all 4 pipeline stages and outputs the resulting Fortran source code via FortranProgramWriter, a LaTeX equation dictionary via LatexWriter, or an IR report via ReportWriter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
terms_raw |
str
|
The raw string contents of the DSL terms specification. |
required |
report |
bool
|
If True, prints a JSON-based compilation IR report instead. Defaults to False. |
False
|
latex |
bool
|
If True, prints LaTeX equation dictionary instead. Defaults to False. |
False
|
Source code in code/code_gen/code_gen.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |