build_cmake/OMCompiler/Compiler/generated-mo/Template/CodegenEmbeddedC.mo
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | encapsulated package CodegenEmbeddedC | ||
| 2 | " | ||
| 3 | file: CodegenEmbeddedC.mo | ||
| 4 | package: CodegenEmbeddedC | ||
| 5 | description: Generated by Susan. | ||
| 6 | " | ||
| 7 | |||
| 8 | public import Tpl; | ||
| 9 | |||
| 10 | public import SimCodeVar; | ||
| 11 | public import HashTableCrefSimVar; | ||
| 12 | public import SimCode; | ||
| 13 | public import SimCodeFunction; | ||
| 14 | public import SimCodeCodegenUtil; | ||
| 15 | public import SimCodeFunctionUtil; | ||
| 16 | public import BackendDAE; | ||
| 17 | public import System; | ||
| 18 | public import Autoconf; | ||
| 19 | protected import Absyn; | ||
| 20 | protected import AbsynUtil; | ||
| 21 | public import MMath; | ||
| 22 | public import DAE; | ||
| 23 | public import ClassInf; | ||
| 24 | public import ClassInfUtil; | ||
| 25 | protected import SCode; | ||
| 26 | protected import SCodeDump; | ||
| 27 | public import StringUtil; | ||
| 28 | public import Util; | ||
| 29 | public import List; | ||
| 30 | public import ComponentReferenceBasics; | ||
| 31 | public import ComponentReference; | ||
| 32 | public import Expression; | ||
| 33 | protected import ExpressionDump; | ||
| 34 | public import ExpressionBasics; | ||
| 35 | public import Config; | ||
| 36 | public import Testsuite; | ||
| 37 | public import Flags; | ||
| 38 | public import FlagsUtil; | ||
| 39 | public import Settings; | ||
| 40 | public import Patternm; | ||
| 41 | public import Error; | ||
| 42 | public import Values; | ||
| 43 | public import ValuesUtil; | ||
| 44 | public import DAEDump; | ||
| 45 | public import Algorithm; | ||
| 46 | protected import ElementSource; | ||
| 47 | public import DAEUtil; | ||
| 48 | public import TypesDump; | ||
| 49 | public import Types; | ||
| 50 | public import HashTableCrIListArray; | ||
| 51 | public import BackendVariable; | ||
| 52 | public import HpcOmSimCode; | ||
| 53 | public import HpcOmCodegenUtil; | ||
| 54 | public import FMI; | ||
| 55 | public import CodegenUtil; | ||
| 56 | public import CodegenUtilSimulation; | ||
| 57 | protected import ExpressionDumpTpl; | ||
| 58 | protected import DAEDumpTpl; | ||
| 59 | |||
| 60 | protected function fun_51 | ||
| 61 | input Tpl.Text in_txt; | ||
| 62 | input Integer in_mArg; | ||
| 63 | |||
| 64 | output Tpl.Text out_txt; | ||
| 65 | algorithm | ||
| 66 | out_txt := | ||
| 67 | match(in_txt, in_mArg) | ||
| 68 | local | ||
| 69 | Tpl.Text txt; | ||
| 70 | Integer i_n; | ||
| 71 | |||
| 72 | case ( txt, | ||
| 73 | 0 ) | ||
| 74 | then txt; | ||
| 75 | |||
| 76 | case ( txt, | ||
| 77 | i_n ) | ||
| 78 | algorithm | ||
| 79 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Real fmi2RealVars[")); | |
| 80 | ✗ | txt := Tpl.writeStr(txt, intString(i_n)); | |
| 81 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("];")); | |
| 82 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 83 | then txt; | ||
| 84 | end match; | ||
| 85 | end fun_51; | ||
| 86 | |||
| 87 | protected function fun_52 | ||
| 88 | input Tpl.Text in_txt; | ||
| 89 | input Integer in_a_varInfo_numIntAlgVars; | ||
| 90 | |||
| 91 | output Tpl.Text out_txt; | ||
| 92 | algorithm | ||
| 93 | out_txt := | ||
| 94 | match(in_txt, in_a_varInfo_numIntAlgVars) | ||
| 95 | local | ||
| 96 | Tpl.Text txt; | ||
| 97 | Integer i_n; | ||
| 98 | |||
| 99 | case ( txt, | ||
| 100 | 0 ) | ||
| 101 | then txt; | ||
| 102 | |||
| 103 | case ( txt, | ||
| 104 | i_n ) | ||
| 105 | algorithm | ||
| 106 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Integer fmi2IntegerVars[")); | |
| 107 | ✗ | txt := Tpl.writeStr(txt, intString(i_n)); | |
| 108 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("];")); | |
| 109 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 110 | then txt; | ||
| 111 | end match; | ||
| 112 | end fun_52; | ||
| 113 | |||
| 114 | protected function fun_53 | ||
| 115 | input Tpl.Text in_txt; | ||
| 116 | input Integer in_a_varInfo_numBoolAlgVars; | ||
| 117 | |||
| 118 | output Tpl.Text out_txt; | ||
| 119 | algorithm | ||
| 120 | out_txt := | ||
| 121 | match(in_txt, in_a_varInfo_numBoolAlgVars) | ||
| 122 | local | ||
| 123 | Tpl.Text txt; | ||
| 124 | Integer i_n; | ||
| 125 | |||
| 126 | case ( txt, | ||
| 127 | 0 ) | ||
| 128 | then txt; | ||
| 129 | |||
| 130 | case ( txt, | ||
| 131 | i_n ) | ||
| 132 | algorithm | ||
| 133 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Boolean fmi2BooleanVars[")); | |
| 134 | ✗ | txt := Tpl.writeStr(txt, intString(i_n)); | |
| 135 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("];")); | |
| 136 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 137 | then txt; | ||
| 138 | end match; | ||
| 139 | end fun_53; | ||
| 140 | |||
| 141 | protected function fun_54 | ||
| 142 | input Tpl.Text in_txt; | ||
| 143 | input Integer in_a_varInfo_numStringAlgVars; | ||
| 144 | |||
| 145 | output Tpl.Text out_txt; | ||
| 146 | algorithm | ||
| 147 | out_txt := | ||
| 148 | match(in_txt, in_a_varInfo_numStringAlgVars) | ||
| 149 | local | ||
| 150 | Tpl.Text txt; | ||
| 151 | |||
| 152 | case ( txt, | ||
| 153 | 0 ) | ||
| 154 | then txt; | ||
| 155 | |||
| 156 | case ( txt, | ||
| 157 | _ ) | ||
| 158 | algorithm | ||
| 159 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 145, 16), "String variables not supported yet"); | |
| 160 | then txt; | ||
| 161 | end match; | ||
| 162 | end fun_54; | ||
| 163 | |||
| 164 | protected function fun_55 | ||
| 165 | input Tpl.Text in_txt; | ||
| 166 | input Integer in_a_varInfo_numParams; | ||
| 167 | |||
| 168 | output Tpl.Text out_txt; | ||
| 169 | algorithm | ||
| 170 | out_txt := | ||
| 171 | match(in_txt, in_a_varInfo_numParams) | ||
| 172 | local | ||
| 173 | Tpl.Text txt; | ||
| 174 | Integer i_n; | ||
| 175 | |||
| 176 | case ( txt, | ||
| 177 | 0 ) | ||
| 178 | then txt; | ||
| 179 | |||
| 180 | case ( txt, | ||
| 181 | i_n ) | ||
| 182 | algorithm | ||
| 183 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Real fmi2RealParameter[")); | |
| 184 | ✗ | txt := Tpl.writeStr(txt, intString(i_n)); | |
| 185 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("];")); | |
| 186 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 187 | then txt; | ||
| 188 | end match; | ||
| 189 | end fun_55; | ||
| 190 | |||
| 191 | protected function fun_56 | ||
| 192 | input Tpl.Text in_txt; | ||
| 193 | input Integer in_a_varInfo_numIntParams; | ||
| 194 | |||
| 195 | output Tpl.Text out_txt; | ||
| 196 | algorithm | ||
| 197 | out_txt := | ||
| 198 | match(in_txt, in_a_varInfo_numIntParams) | ||
| 199 | local | ||
| 200 | Tpl.Text txt; | ||
| 201 | Integer i_n; | ||
| 202 | |||
| 203 | case ( txt, | ||
| 204 | 0 ) | ||
| 205 | then txt; | ||
| 206 | |||
| 207 | case ( txt, | ||
| 208 | i_n ) | ||
| 209 | algorithm | ||
| 210 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Integer fmi2IntegerParameter[")); | |
| 211 | ✗ | txt := Tpl.writeStr(txt, intString(i_n)); | |
| 212 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("];")); | |
| 213 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 214 | then txt; | ||
| 215 | end match; | ||
| 216 | end fun_56; | ||
| 217 | |||
| 218 | protected function fun_57 | ||
| 219 | input Tpl.Text in_txt; | ||
| 220 | input Integer in_a_varInfo_numBoolParams; | ||
| 221 | |||
| 222 | output Tpl.Text out_txt; | ||
| 223 | algorithm | ||
| 224 | out_txt := | ||
| 225 | match(in_txt, in_a_varInfo_numBoolParams) | ||
| 226 | local | ||
| 227 | Tpl.Text txt; | ||
| 228 | Integer i_n; | ||
| 229 | |||
| 230 | case ( txt, | ||
| 231 | 0 ) | ||
| 232 | then txt; | ||
| 233 | |||
| 234 | case ( txt, | ||
| 235 | i_n ) | ||
| 236 | algorithm | ||
| 237 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Boolean fmi2BooleanParameter[")); | |
| 238 | ✗ | txt := Tpl.writeStr(txt, intString(i_n)); | |
| 239 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("];")); | |
| 240 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 241 | then txt; | ||
| 242 | end match; | ||
| 243 | end fun_57; | ||
| 244 | |||
| 245 | protected function fun_58 | ||
| 246 | input Tpl.Text in_txt; | ||
| 247 | input Integer in_a_varInfo_numIntParams; | ||
| 248 | |||
| 249 | output Tpl.Text out_txt; | ||
| 250 | algorithm | ||
| 251 | out_txt := | ||
| 252 | match(in_txt, in_a_varInfo_numIntParams) | ||
| 253 | local | ||
| 254 | Tpl.Text txt; | ||
| 255 | Integer i_n; | ||
| 256 | |||
| 257 | case ( txt, | ||
| 258 | 0 ) | ||
| 259 | then txt; | ||
| 260 | |||
| 261 | case ( txt, | ||
| 262 | i_n ) | ||
| 263 | algorithm | ||
| 264 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2String fmi2StringParameter[")); | |
| 265 | ✗ | txt := Tpl.writeStr(txt, intString(i_n)); | |
| 266 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("];")); | |
| 267 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 268 | then txt; | ||
| 269 | end match; | ||
| 270 | end fun_58; | ||
| 271 | |||
| 272 | protected function fun_59 | ||
| 273 | input Tpl.Text in_txt; | ||
| 274 | input Integer in_mArg; | ||
| 275 | |||
| 276 | output Tpl.Text out_txt; | ||
| 277 | algorithm | ||
| 278 | out_txt := | ||
| 279 | match(in_txt, in_mArg) | ||
| 280 | local | ||
| 281 | Tpl.Text txt; | ||
| 282 | Integer i_n; | ||
| 283 | |||
| 284 | case ( txt, | ||
| 285 | 0 ) | ||
| 286 | then txt; | ||
| 287 | |||
| 288 | case ( txt, | ||
| 289 | i_n ) | ||
| 290 | algorithm | ||
| 291 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("void* extObjs[")); | |
| 292 | ✗ | txt := Tpl.writeStr(txt, intString(i_n)); | |
| 293 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("];")); | |
| 294 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 295 | then txt; | ||
| 296 | end match; | ||
| 297 | end fun_59; | ||
| 298 | |||
| 299 | protected function lm_60 | ||
| 300 | input output Tpl.Text txt; | ||
| 301 | input list<SimCodeVar.SimVar> items; | ||
| 302 | algorithm | ||
| 303 | ✗ | for lstElt_60 in items loop | |
| 304 | txt := match lstElt_60 | ||
| 305 | local | ||
| 306 | SimCodeVar.SimVar i_var; | ||
| 307 | |||
| 308 | case i_var | ||
| 309 | algorithm | ||
| 310 | ✗ | txt := startValue(txt, i_var); | |
| 311 | then txt; | ||
| 312 | end match; | ||
| 313 | end for; | ||
| 314 | end lm_60; | ||
| 315 | |||
| 316 | protected function lm_61 | ||
| 317 | input output Tpl.Text txt; | ||
| 318 | input list<SimCodeVar.SimVar> items; | ||
| 319 | algorithm | ||
| 320 | ✗ | for lstElt_61 in items loop | |
| 321 | txt := match lstElt_61 | ||
| 322 | local | ||
| 323 | SimCodeVar.SimVar i_var; | ||
| 324 | |||
| 325 | case i_var | ||
| 326 | algorithm | ||
| 327 | ✗ | txt := startValue(txt, i_var); | |
| 328 | then txt; | ||
| 329 | end match; | ||
| 330 | end for; | ||
| 331 | end lm_61; | ||
| 332 | |||
| 333 | protected function lm_62 | ||
| 334 | input output Tpl.Text txt; | ||
| 335 | input list<SimCodeVar.SimVar> items; | ||
| 336 | algorithm | ||
| 337 | ✗ | for lstElt_62 in items loop | |
| 338 | txt := match lstElt_62 | ||
| 339 | local | ||
| 340 | SimCodeVar.SimVar i_var; | ||
| 341 | |||
| 342 | case i_var | ||
| 343 | algorithm | ||
| 344 | ✗ | txt := startValue(txt, i_var); | |
| 345 | then txt; | ||
| 346 | end match; | ||
| 347 | end for; | ||
| 348 | end lm_62; | ||
| 349 | |||
| 350 | protected function lm_63 | ||
| 351 | input output Tpl.Text txt; | ||
| 352 | input list<SimCodeVar.SimVar> items; | ||
| 353 | algorithm | ||
| 354 | ✗ | for lstElt_63 in items loop | |
| 355 | txt := match lstElt_63 | ||
| 356 | local | ||
| 357 | SimCodeVar.SimVar i_var; | ||
| 358 | |||
| 359 | case i_var | ||
| 360 | algorithm | ||
| 361 | ✗ | txt := startValue(txt, i_var); | |
| 362 | then txt; | ||
| 363 | end match; | ||
| 364 | end for; | ||
| 365 | end lm_63; | ||
| 366 | |||
| 367 | protected function lm_64 | ||
| 368 | input output Tpl.Text txt; | ||
| 369 | input list<SimCodeVar.SimVar> items; | ||
| 370 | algorithm | ||
| 371 | ✗ | for lstElt_64 in items loop | |
| 372 | txt := match lstElt_64 | ||
| 373 | local | ||
| 374 | SimCodeVar.SimVar i_var; | ||
| 375 | |||
| 376 | case i_var | ||
| 377 | algorithm | ||
| 378 | ✗ | txt := startValue(txt, i_var); | |
| 379 | then txt; | ||
| 380 | end match; | ||
| 381 | end for; | ||
| 382 | end lm_64; | ||
| 383 | |||
| 384 | protected function lm_65 | ||
| 385 | input output Tpl.Text txt; | ||
| 386 | input list<SimCodeVar.SimVar> items; | ||
| 387 | algorithm | ||
| 388 | ✗ | for lstElt_65 in items loop | |
| 389 | txt := match lstElt_65 | ||
| 390 | local | ||
| 391 | SimCodeVar.SimVar i_var; | ||
| 392 | |||
| 393 | case i_var | ||
| 394 | algorithm | ||
| 395 | ✗ | txt := startValue(txt, i_var); | |
| 396 | then txt; | ||
| 397 | end match; | ||
| 398 | end for; | ||
| 399 | end lm_65; | ||
| 400 | |||
| 401 | protected function fun_66 | ||
| 402 | input Tpl.Text in_txt; | ||
| 403 | input Integer in_mArg; | ||
| 404 | input list<SimCodeVar.SimVar> in_a_vars_realOptimizeFinalConstraintsVars; | ||
| 405 | input list<SimCodeVar.SimVar> in_a_vars_realOptimizeConstraintsVars; | ||
| 406 | input list<SimCodeVar.SimVar> in_a_vars_discreteAlgVars; | ||
| 407 | input list<SimCodeVar.SimVar> in_a_vars_algVars; | ||
| 408 | input list<SimCodeVar.SimVar> in_a_vars_derivativeVars; | ||
| 409 | input list<SimCodeVar.SimVar> in_a_vars_stateVars; | ||
| 410 | |||
| 411 | output Tpl.Text out_txt; | ||
| 412 | algorithm | ||
| 413 | out_txt := | ||
| 414 | match(in_txt, in_mArg, in_a_vars_realOptimizeFinalConstraintsVars, in_a_vars_realOptimizeConstraintsVars, in_a_vars_discreteAlgVars, in_a_vars_algVars, in_a_vars_derivativeVars, in_a_vars_stateVars) | ||
| 415 | local | ||
| 416 | Tpl.Text txt; | ||
| 417 | list<SimCodeVar.SimVar> a_vars_realOptimizeFinalConstraintsVars; | ||
| 418 | list<SimCodeVar.SimVar> a_vars_realOptimizeConstraintsVars; | ||
| 419 | list<SimCodeVar.SimVar> a_vars_discreteAlgVars; | ||
| 420 | list<SimCodeVar.SimVar> a_vars_algVars; | ||
| 421 | list<SimCodeVar.SimVar> a_vars_derivativeVars; | ||
| 422 | list<SimCodeVar.SimVar> a_vars_stateVars; | ||
| 423 | |||
| 424 | case ( txt, | ||
| 425 | 0, | ||
| 426 | _, | ||
| 427 | _, | ||
| 428 | _, | ||
| 429 | _, | ||
| 430 | _, | ||
| 431 | _ ) | ||
| 432 | then txt; | ||
| 433 | |||
| 434 | case ( txt, | ||
| 435 | _, | ||
| 436 | a_vars_realOptimizeFinalConstraintsVars, | ||
| 437 | a_vars_realOptimizeConstraintsVars, | ||
| 438 | a_vars_discreteAlgVars, | ||
| 439 | a_vars_algVars, | ||
| 440 | a_vars_derivativeVars, | ||
| 441 | a_vars_stateVars ) | ||
| 442 | algorithm | ||
| 443 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(".fmi2RealVars = {\n")); | |
| 444 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 445 | ✗ | txt := lm_60(txt, a_vars_stateVars); | |
| 446 | ✗ | txt := Tpl.softNewLine(txt); | |
| 447 | ✗ | txt := lm_61(txt, a_vars_derivativeVars); | |
| 448 | ✗ | txt := Tpl.softNewLine(txt); | |
| 449 | ✗ | txt := lm_62(txt, a_vars_algVars); | |
| 450 | ✗ | txt := Tpl.softNewLine(txt); | |
| 451 | ✗ | txt := lm_63(txt, a_vars_discreteAlgVars); | |
| 452 | ✗ | txt := Tpl.softNewLine(txt); | |
| 453 | ✗ | txt := lm_64(txt, a_vars_realOptimizeConstraintsVars); | |
| 454 | ✗ | txt := Tpl.softNewLine(txt); | |
| 455 | ✗ | txt := lm_65(txt, a_vars_realOptimizeFinalConstraintsVars); | |
| 456 | ✗ | txt := Tpl.softNewLine(txt); | |
| 457 | ✗ | txt := Tpl.popBlock(txt); | |
| 458 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("},")); | |
| 459 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 460 | then txt; | ||
| 461 | end match; | ||
| 462 | end fun_66; | ||
| 463 | |||
| 464 | protected function lm_67 | ||
| 465 | input output Tpl.Text txt; | ||
| 466 | input list<SimCodeVar.SimVar> items; | ||
| 467 | algorithm | ||
| 468 | ✗ | for lstElt_67 in items loop | |
| 469 | txt := match lstElt_67 | ||
| 470 | local | ||
| 471 | SimCodeVar.SimVar i_var; | ||
| 472 | |||
| 473 | case i_var | ||
| 474 | algorithm | ||
| 475 | ✗ | txt := startValue(txt, i_var); | |
| 476 | then txt; | ||
| 477 | end match; | ||
| 478 | end for; | ||
| 479 | end lm_67; | ||
| 480 | |||
| 481 | protected function fun_68 | ||
| 482 | input Tpl.Text in_txt; | ||
| 483 | input Integer in_a_varInfo_numIntAlgVars; | ||
| 484 | input list<SimCodeVar.SimVar> in_a_vars_intAlgVars; | ||
| 485 | |||
| 486 | output Tpl.Text out_txt; | ||
| 487 | algorithm | ||
| 488 | out_txt := | ||
| 489 | match(in_txt, in_a_varInfo_numIntAlgVars, in_a_vars_intAlgVars) | ||
| 490 | local | ||
| 491 | Tpl.Text txt; | ||
| 492 | list<SimCodeVar.SimVar> a_vars_intAlgVars; | ||
| 493 | |||
| 494 | case ( txt, | ||
| 495 | 0, | ||
| 496 | _ ) | ||
| 497 | then txt; | ||
| 498 | |||
| 499 | case ( txt, | ||
| 500 | _, | ||
| 501 | a_vars_intAlgVars ) | ||
| 502 | algorithm | ||
| 503 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(".fmi2IntegerVars = {\n")); | |
| 504 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 505 | ✗ | txt := lm_67(txt, a_vars_intAlgVars); | |
| 506 | ✗ | txt := Tpl.softNewLine(txt); | |
| 507 | ✗ | txt := Tpl.popBlock(txt); | |
| 508 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("},")); | |
| 509 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 510 | then txt; | ||
| 511 | end match; | ||
| 512 | end fun_68; | ||
| 513 | |||
| 514 | protected function lm_69 | ||
| 515 | input output Tpl.Text txt; | ||
| 516 | input list<SimCodeVar.SimVar> items; | ||
| 517 | algorithm | ||
| 518 | ✗ | for lstElt_69 in items loop | |
| 519 | txt := match lstElt_69 | ||
| 520 | local | ||
| 521 | SimCodeVar.SimVar i_var; | ||
| 522 | |||
| 523 | case i_var | ||
| 524 | algorithm | ||
| 525 | ✗ | txt := startValue(txt, i_var); | |
| 526 | then txt; | ||
| 527 | end match; | ||
| 528 | end for; | ||
| 529 | end lm_69; | ||
| 530 | |||
| 531 | protected function fun_70 | ||
| 532 | input Tpl.Text in_txt; | ||
| 533 | input Integer in_a_varInfo_numBoolAlgVars; | ||
| 534 | input list<SimCodeVar.SimVar> in_a_vars_boolAlgVars; | ||
| 535 | |||
| 536 | output Tpl.Text out_txt; | ||
| 537 | algorithm | ||
| 538 | out_txt := | ||
| 539 | match(in_txt, in_a_varInfo_numBoolAlgVars, in_a_vars_boolAlgVars) | ||
| 540 | local | ||
| 541 | Tpl.Text txt; | ||
| 542 | list<SimCodeVar.SimVar> a_vars_boolAlgVars; | ||
| 543 | |||
| 544 | case ( txt, | ||
| 545 | 0, | ||
| 546 | _ ) | ||
| 547 | then txt; | ||
| 548 | |||
| 549 | case ( txt, | ||
| 550 | _, | ||
| 551 | a_vars_boolAlgVars ) | ||
| 552 | algorithm | ||
| 553 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(".fmi2BooleanVars = {\n")); | |
| 554 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 555 | ✗ | txt := lm_69(txt, a_vars_boolAlgVars); | |
| 556 | ✗ | txt := Tpl.softNewLine(txt); | |
| 557 | ✗ | txt := Tpl.popBlock(txt); | |
| 558 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("},")); | |
| 559 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 560 | then txt; | ||
| 561 | end match; | ||
| 562 | end fun_70; | ||
| 563 | |||
| 564 | protected function lm_71 | ||
| 565 | input output Tpl.Text txt; | ||
| 566 | input list<SimCodeVar.SimVar> items; | ||
| 567 | algorithm | ||
| 568 | ✗ | for lstElt_71 in items loop | |
| 569 | txt := match lstElt_71 | ||
| 570 | local | ||
| 571 | SimCodeVar.SimVar i_var; | ||
| 572 | |||
| 573 | case i_var | ||
| 574 | algorithm | ||
| 575 | ✗ | txt := startValue(txt, i_var); | |
| 576 | then txt; | ||
| 577 | end match; | ||
| 578 | end for; | ||
| 579 | end lm_71; | ||
| 580 | |||
| 581 | protected function fun_72 | ||
| 582 | input Tpl.Text in_txt; | ||
| 583 | input Integer in_a_varInfo_numStringAlgVars; | ||
| 584 | input list<SimCodeVar.SimVar> in_a_vars_stringAlgVars; | ||
| 585 | |||
| 586 | output Tpl.Text out_txt; | ||
| 587 | algorithm | ||
| 588 | out_txt := | ||
| 589 | match(in_txt, in_a_varInfo_numStringAlgVars, in_a_vars_stringAlgVars) | ||
| 590 | local | ||
| 591 | Tpl.Text txt; | ||
| 592 | list<SimCodeVar.SimVar> a_vars_stringAlgVars; | ||
| 593 | |||
| 594 | case ( txt, | ||
| 595 | 0, | ||
| 596 | _ ) | ||
| 597 | then txt; | ||
| 598 | |||
| 599 | case ( txt, | ||
| 600 | _, | ||
| 601 | a_vars_stringAlgVars ) | ||
| 602 | algorithm | ||
| 603 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(".fmi2StringVars = {\n")); | |
| 604 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 605 | ✗ | txt := lm_71(txt, a_vars_stringAlgVars); | |
| 606 | ✗ | txt := Tpl.softNewLine(txt); | |
| 607 | ✗ | txt := Tpl.popBlock(txt); | |
| 608 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("},")); | |
| 609 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 610 | then txt; | ||
| 611 | end match; | ||
| 612 | end fun_72; | ||
| 613 | |||
| 614 | protected function lm_73 | ||
| 615 | input output Tpl.Text txt; | ||
| 616 | input list<SimCodeVar.SimVar> items; | ||
| 617 | algorithm | ||
| 618 | ✗ | for lstElt_73 in items loop | |
| 619 | txt := match lstElt_73 | ||
| 620 | local | ||
| 621 | SimCodeVar.SimVar i_var; | ||
| 622 | |||
| 623 | case i_var | ||
| 624 | algorithm | ||
| 625 | ✗ | txt := startValue(txt, i_var); | |
| 626 | then txt; | ||
| 627 | end match; | ||
| 628 | end for; | ||
| 629 | end lm_73; | ||
| 630 | |||
| 631 | protected function fun_74 | ||
| 632 | input Tpl.Text in_txt; | ||
| 633 | input Integer in_a_varInfo_numParams; | ||
| 634 | input list<SimCodeVar.SimVar> in_a_vars_paramVars; | ||
| 635 | |||
| 636 | output Tpl.Text out_txt; | ||
| 637 | algorithm | ||
| 638 | out_txt := | ||
| 639 | match(in_txt, in_a_varInfo_numParams, in_a_vars_paramVars) | ||
| 640 | local | ||
| 641 | Tpl.Text txt; | ||
| 642 | list<SimCodeVar.SimVar> a_vars_paramVars; | ||
| 643 | |||
| 644 | case ( txt, | ||
| 645 | 0, | ||
| 646 | _ ) | ||
| 647 | then txt; | ||
| 648 | |||
| 649 | case ( txt, | ||
| 650 | _, | ||
| 651 | a_vars_paramVars ) | ||
| 652 | algorithm | ||
| 653 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(".fmi2RealParameter = {\n")); | |
| 654 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 655 | ✗ | txt := lm_73(txt, a_vars_paramVars); | |
| 656 | ✗ | txt := Tpl.softNewLine(txt); | |
| 657 | ✗ | txt := Tpl.popBlock(txt); | |
| 658 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("},")); | |
| 659 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 660 | then txt; | ||
| 661 | end match; | ||
| 662 | end fun_74; | ||
| 663 | |||
| 664 | protected function lm_75 | ||
| 665 | input output Tpl.Text txt; | ||
| 666 | input list<SimCodeVar.SimVar> items; | ||
| 667 | algorithm | ||
| 668 | ✗ | for lstElt_75 in items loop | |
| 669 | txt := match lstElt_75 | ||
| 670 | local | ||
| 671 | SimCodeVar.SimVar i_var; | ||
| 672 | |||
| 673 | case i_var | ||
| 674 | algorithm | ||
| 675 | ✗ | txt := startValue(txt, i_var); | |
| 676 | then txt; | ||
| 677 | end match; | ||
| 678 | end for; | ||
| 679 | end lm_75; | ||
| 680 | |||
| 681 | protected function fun_76 | ||
| 682 | input Tpl.Text in_txt; | ||
| 683 | input Integer in_a_varInfo_numIntParams; | ||
| 684 | input list<SimCodeVar.SimVar> in_a_vars_intParamVars; | ||
| 685 | |||
| 686 | output Tpl.Text out_txt; | ||
| 687 | algorithm | ||
| 688 | out_txt := | ||
| 689 | match(in_txt, in_a_varInfo_numIntParams, in_a_vars_intParamVars) | ||
| 690 | local | ||
| 691 | Tpl.Text txt; | ||
| 692 | list<SimCodeVar.SimVar> a_vars_intParamVars; | ||
| 693 | |||
| 694 | case ( txt, | ||
| 695 | 0, | ||
| 696 | _ ) | ||
| 697 | then txt; | ||
| 698 | |||
| 699 | case ( txt, | ||
| 700 | _, | ||
| 701 | a_vars_intParamVars ) | ||
| 702 | algorithm | ||
| 703 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(".fmi2IntegerParameter = {\n")); | |
| 704 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 705 | ✗ | txt := lm_75(txt, a_vars_intParamVars); | |
| 706 | ✗ | txt := Tpl.softNewLine(txt); | |
| 707 | ✗ | txt := Tpl.popBlock(txt); | |
| 708 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("},")); | |
| 709 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 710 | then txt; | ||
| 711 | end match; | ||
| 712 | end fun_76; | ||
| 713 | |||
| 714 | protected function lm_77 | ||
| 715 | input output Tpl.Text txt; | ||
| 716 | input list<SimCodeVar.SimVar> items; | ||
| 717 | algorithm | ||
| 718 | ✗ | for lstElt_77 in items loop | |
| 719 | txt := match lstElt_77 | ||
| 720 | local | ||
| 721 | SimCodeVar.SimVar i_var; | ||
| 722 | |||
| 723 | case i_var | ||
| 724 | algorithm | ||
| 725 | ✗ | txt := startValue(txt, i_var); | |
| 726 | then txt; | ||
| 727 | end match; | ||
| 728 | end for; | ||
| 729 | end lm_77; | ||
| 730 | |||
| 731 | protected function fun_78 | ||
| 732 | input Tpl.Text in_txt; | ||
| 733 | input Integer in_a_varInfo_numBoolParams; | ||
| 734 | input list<SimCodeVar.SimVar> in_a_vars_boolParamVars; | ||
| 735 | |||
| 736 | output Tpl.Text out_txt; | ||
| 737 | algorithm | ||
| 738 | out_txt := | ||
| 739 | match(in_txt, in_a_varInfo_numBoolParams, in_a_vars_boolParamVars) | ||
| 740 | local | ||
| 741 | Tpl.Text txt; | ||
| 742 | list<SimCodeVar.SimVar> a_vars_boolParamVars; | ||
| 743 | |||
| 744 | case ( txt, | ||
| 745 | 0, | ||
| 746 | _ ) | ||
| 747 | then txt; | ||
| 748 | |||
| 749 | case ( txt, | ||
| 750 | _, | ||
| 751 | a_vars_boolParamVars ) | ||
| 752 | algorithm | ||
| 753 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(".fmi2BooleanParameter = {\n")); | |
| 754 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 755 | ✗ | txt := lm_77(txt, a_vars_boolParamVars); | |
| 756 | ✗ | txt := Tpl.softNewLine(txt); | |
| 757 | ✗ | txt := Tpl.popBlock(txt); | |
| 758 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("},")); | |
| 759 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 760 | then txt; | ||
| 761 | end match; | ||
| 762 | end fun_78; | ||
| 763 | |||
| 764 | protected function lm_79 | ||
| 765 | input output Tpl.Text txt; | ||
| 766 | input list<SimCodeVar.SimVar> items; | ||
| 767 | algorithm | ||
| 768 | ✗ | for lstElt_79 in items loop | |
| 769 | txt := match lstElt_79 | ||
| 770 | local | ||
| 771 | SimCodeVar.SimVar i_var; | ||
| 772 | |||
| 773 | case i_var | ||
| 774 | algorithm | ||
| 775 | ✗ | txt := startValue(txt, i_var); | |
| 776 | then txt; | ||
| 777 | end match; | ||
| 778 | end for; | ||
| 779 | end lm_79; | ||
| 780 | |||
| 781 | protected function fun_80 | ||
| 782 | input Tpl.Text in_txt; | ||
| 783 | input Integer in_a_varInfo_numStringParamVars; | ||
| 784 | input list<SimCodeVar.SimVar> in_a_vars_stringParamVars; | ||
| 785 | |||
| 786 | output Tpl.Text out_txt; | ||
| 787 | algorithm | ||
| 788 | out_txt := | ||
| 789 | match(in_txt, in_a_varInfo_numStringParamVars, in_a_vars_stringParamVars) | ||
| 790 | local | ||
| 791 | Tpl.Text txt; | ||
| 792 | list<SimCodeVar.SimVar> a_vars_stringParamVars; | ||
| 793 | |||
| 794 | case ( txt, | ||
| 795 | 0, | ||
| 796 | _ ) | ||
| 797 | then txt; | ||
| 798 | |||
| 799 | case ( txt, | ||
| 800 | _, | ||
| 801 | a_vars_stringParamVars ) | ||
| 802 | algorithm | ||
| 803 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(".fmi2StringParameter = {\n")); | |
| 804 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 805 | ✗ | txt := lm_79(txt, a_vars_stringParamVars); | |
| 806 | ✗ | txt := Tpl.softNewLine(txt); | |
| 807 | ✗ | txt := Tpl.popBlock(txt); | |
| 808 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("},")); | |
| 809 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 810 | then txt; | ||
| 811 | end match; | ||
| 812 | end fun_80; | ||
| 813 | |||
| 814 | protected function lm_81 | ||
| 815 | input output Tpl.Text txt; | ||
| 816 | input list<SimCode.SimEqSystem> items; | ||
| 817 | algorithm | ||
| 818 | ✗ | for lstElt_81 in items loop | |
| 819 | txt := match lstElt_81 | ||
| 820 | local | ||
| 821 | SimCode.SimEqSystem i_eq; | ||
| 822 | |||
| 823 | case i_eq | ||
| 824 | algorithm | ||
| 825 | ✗ | txt := equation_(txt, i_eq); | |
| 826 | ✗ | txt := Tpl.nextIter(txt); | |
| 827 | then txt; | ||
| 828 | end match; | ||
| 829 | end for; | ||
| 830 | end lm_81; | ||
| 831 | |||
| 832 | protected function fun_82 | ||
| 833 | input Tpl.Text in_txt; | ||
| 834 | input list<list<SimCode.SimEqSystem>> in_a_odeEquations; | ||
| 835 | |||
| 836 | output Tpl.Text out_txt; | ||
| 837 | algorithm | ||
| 838 | out_txt := | ||
| 839 | match(in_txt, in_a_odeEquations) | ||
| 840 | local | ||
| 841 | Tpl.Text txt; | ||
| 842 | list<SimCode.SimEqSystem> i_eqs; | ||
| 843 | |||
| 844 | case ( txt, | ||
| 845 | {} ) | ||
| 846 | then txt; | ||
| 847 | |||
| 848 | case ( txt, | ||
| 849 | {i_eqs} ) | ||
| 850 | algorithm | ||
| 851 | ✗ | txt := Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); | |
| 852 | ✗ | txt := lm_81(txt, i_eqs); | |
| 853 | ✗ | txt := Tpl.popIter(txt); | |
| 854 | then txt; | ||
| 855 | |||
| 856 | case ( txt, | ||
| 857 | _ ) | ||
| 858 | algorithm | ||
| 859 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 276, 14), "TODO"); | |
| 860 | then txt; | ||
| 861 | end match; | ||
| 862 | end fun_82; | ||
| 863 | |||
| 864 | protected function smf_83 | ||
| 865 | input Tpl.Text in_txt; | ||
| 866 | input SimCode.SimEqSystem in_it; | ||
| 867 | |||
| 868 | output Tpl.Text out_txt; | ||
| 869 | algorithm | ||
| 870 | out_txt := | ||
| 871 | match(in_txt, in_it) | ||
| 872 | local | ||
| 873 | Tpl.Text txt; | ||
| 874 | SimCode.SimEqSystem i_eq; | ||
| 875 | |||
| 876 | case ( txt, | ||
| 877 | i_eq ) | ||
| 878 | algorithm | ||
| 879 | ✗ | txt := equation_(txt, i_eq); | |
| 880 | then txt; | ||
| 881 | end match; | ||
| 882 | end smf_83; | ||
| 883 | |||
| 884 | protected function smf_84 | ||
| 885 | input Tpl.Text in_txt; | ||
| 886 | input SimCode.SimEqSystem in_it; | ||
| 887 | |||
| 888 | output Tpl.Text out_txt; | ||
| 889 | algorithm | ||
| 890 | out_txt := | ||
| 891 | match(in_txt, in_it) | ||
| 892 | local | ||
| 893 | Tpl.Text txt; | ||
| 894 | SimCode.SimEqSystem i_eq; | ||
| 895 | |||
| 896 | case ( txt, | ||
| 897 | i_eq ) | ||
| 898 | algorithm | ||
| 899 | ✗ | txt := equation_(txt, i_eq); | |
| 900 | then txt; | ||
| 901 | end match; | ||
| 902 | end smf_84; | ||
| 903 | |||
| 904 | protected function lm_85 | ||
| 905 | input output Tpl.Text txt; | ||
| 906 | input list<SimCode.SimEqSystem> items; | ||
| 907 | algorithm | ||
| 908 | ✗ | for lstElt_85 in items loop | |
| 909 | txt := match lstElt_85 | ||
| 910 | local | ||
| 911 | SimCode.SimEqSystem i_eqs; | ||
| 912 | |||
| 913 | case i_eqs | ||
| 914 | algorithm | ||
| 915 | ✗ | txt := smf_84(txt, i_eqs); | |
| 916 | ✗ | txt := Tpl.nextIter(txt); | |
| 917 | then txt; | ||
| 918 | end match; | ||
| 919 | end for; | ||
| 920 | end lm_85; | ||
| 921 | |||
| 922 | protected function fun_86 | ||
| 923 | input Tpl.Text in_txt; | ||
| 924 | input list<SimCode.SimEqSystem> in_a_allEquations; | ||
| 925 | |||
| 926 | output Tpl.Text out_txt; | ||
| 927 | algorithm | ||
| 928 | out_txt := | ||
| 929 | match(in_txt, in_a_allEquations) | ||
| 930 | local | ||
| 931 | Tpl.Text txt; | ||
| 932 | list<SimCode.SimEqSystem> i_allEquations; | ||
| 933 | SimCode.SimEqSystem i_eqs; | ||
| 934 | |||
| 935 | case ( txt, | ||
| 936 | {} ) | ||
| 937 | then txt; | ||
| 938 | |||
| 939 | case ( txt, | ||
| 940 | {i_eqs} ) | ||
| 941 | algorithm | ||
| 942 | ✗ | txt := smf_83(txt, i_eqs); | |
| 943 | then txt; | ||
| 944 | |||
| 945 | case ( txt, | ||
| 946 | i_allEquations ) | ||
| 947 | algorithm | ||
| 948 | ✗ | txt := Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); | |
| 949 | ✗ | txt := lm_85(txt, i_allEquations); | |
| 950 | ✗ | txt := Tpl.popIter(txt); | |
| 951 | then txt; | ||
| 952 | end match; | ||
| 953 | end fun_86; | ||
| 954 | |||
| 955 | protected function fun_87 | ||
| 956 | input Tpl.Text in_txt; | ||
| 957 | input Integer in_a_varInfo_numStateVars; | ||
| 958 | |||
| 959 | output Tpl.Text out_txt; | ||
| 960 | algorithm | ||
| 961 | out_txt := | ||
| 962 | match(in_txt, in_a_varInfo_numStateVars) | ||
| 963 | local | ||
| 964 | Tpl.Text txt; | ||
| 965 | Integer i_varInfo_numStateVars; | ||
| 966 | |||
| 967 | case ( txt, | ||
| 968 | 0 ) | ||
| 969 | then txt; | ||
| 970 | |||
| 971 | case ( txt, | ||
| 972 | i_varInfo_numStateVars ) | ||
| 973 | algorithm | ||
| 974 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 975 | "int i=0;\n", | ||
| 976 | "for (i=0; i<" | ||
| 977 | }, false)); | ||
| 978 | ✗ | txt := Tpl.writeStr(txt, intString(i_varInfo_numStateVars)); | |
| 979 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE("; i++) {\n")); | |
| 980 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 981 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("comp->fmi2RealVars[i] += comp->fmi2RealVars[i+")); | |
| 982 | ✗ | txt := Tpl.writeStr(txt, intString(i_varInfo_numStateVars)); | |
| 983 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE("]*communicationStepSize;\n")); | |
| 984 | ✗ | txt := Tpl.popBlock(txt); | |
| 985 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("}")); | |
| 986 | then txt; | ||
| 987 | end match; | ||
| 988 | end fun_87; | ||
| 989 | |||
| 990 | protected function fun_88 | ||
| 991 | input Tpl.Text in_txt; | ||
| 992 | input SimCode.SimCode in_a_simCode; | ||
| 993 | input Tpl.Text in_a_modelNamePrefixStr; | ||
| 994 | |||
| 995 | output Tpl.Text out_txt; | ||
| 996 | algorithm | ||
| 997 | out_txt := | ||
| 998 | match(in_txt, in_a_simCode, in_a_modelNamePrefixStr) | ||
| 999 | local | ||
| 1000 | Tpl.Text txt; | ||
| 1001 | Tpl.Text a_modelNamePrefixStr; | ||
| 1002 | Real i_settings_stepSize; | ||
| 1003 | Real i_settings_stopTime; | ||
| 1004 | Real i_settings_startTime; | ||
| 1005 | Integer i_varInfo_numStateVars; | ||
| 1006 | list<SimCode.SimEqSystem> i_allEquations; | ||
| 1007 | list<list<SimCode.SimEqSystem>> i_odeEquations; | ||
| 1008 | SimCode.ExtObjInfo i_extObjInfo; | ||
| 1009 | list<String> i_externalFunctionIncludes; | ||
| 1010 | list<DAE.Exp> i_literals; | ||
| 1011 | list<SimCodeFunction.Function> i_functions; | ||
| 1012 | list<SimCodeVar.SimVar> i_vars_stringParamVars; | ||
| 1013 | Integer i_varInfo_numStringParamVars; | ||
| 1014 | list<SimCodeVar.SimVar> i_vars_boolParamVars; | ||
| 1015 | list<SimCodeVar.SimVar> i_vars_intParamVars; | ||
| 1016 | list<SimCodeVar.SimVar> i_vars_paramVars; | ||
| 1017 | list<SimCodeVar.SimVar> i_vars_stringAlgVars; | ||
| 1018 | list<SimCodeVar.SimVar> i_vars_boolAlgVars; | ||
| 1019 | list<SimCodeVar.SimVar> i_vars_intAlgVars; | ||
| 1020 | list<SimCodeVar.SimVar> i_vars_realOptimizeFinalConstraintsVars; | ||
| 1021 | list<SimCodeVar.SimVar> i_vars_realOptimizeConstraintsVars; | ||
| 1022 | list<SimCodeVar.SimVar> i_vars_discreteAlgVars; | ||
| 1023 | list<SimCodeVar.SimVar> i_vars_algVars; | ||
| 1024 | list<SimCodeVar.SimVar> i_vars_derivativeVars; | ||
| 1025 | list<SimCodeVar.SimVar> i_vars_stateVars; | ||
| 1026 | list<SimCodeVar.SimVar> i_extObjVars; | ||
| 1027 | Integer i_varInfo_numBoolParams; | ||
| 1028 | Integer i_varInfo_numIntParams; | ||
| 1029 | Integer i_varInfo_numParams; | ||
| 1030 | Integer i_varInfo_numStringAlgVars; | ||
| 1031 | Integer i_varInfo_numBoolAlgVars; | ||
| 1032 | Integer i_varInfo_numIntAlgVars; | ||
| 1033 | SimCode.VarInfo i_varInfo; | ||
| 1034 | Integer ret_2; | ||
| 1035 | Integer ret_1; | ||
| 1036 | Integer ret_0; | ||
| 1037 | |||
| 1038 | case ( txt, | ||
| 1039 | SimCode.SIMCODE(simulationSettingsOpt = NONE()), | ||
| 1040 | _ ) | ||
| 1041 | algorithm | ||
| 1042 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 96, 9), "Missing simulation settings"); | |
| 1043 | then txt; | ||
| 1044 | |||
| 1045 | case ( txt, | ||
| 1046 | SimCode.SIMCODE(modelInfo = SimCode.MODELINFO(functions = i_functions, varInfo = (i_varInfo as SimCode.VARINFO(numIntAlgVars = i_varInfo_numIntAlgVars, numBoolAlgVars = i_varInfo_numBoolAlgVars, numStringAlgVars = i_varInfo_numStringAlgVars, numParams = i_varInfo_numParams, numIntParams = i_varInfo_numIntParams, numBoolParams = i_varInfo_numBoolParams, numStringParamVars = i_varInfo_numStringParamVars, numStateVars = i_varInfo_numStateVars)), vars = SimCodeVar.SIMVARS(stateVars = i_vars_stateVars, derivativeVars = i_vars_derivativeVars, algVars = i_vars_algVars, discreteAlgVars = i_vars_discreteAlgVars, realOptimizeConstraintsVars = i_vars_realOptimizeConstraintsVars, realOptimizeFinalConstraintsVars = i_vars_realOptimizeFinalConstraintsVars, intAlgVars = i_vars_intAlgVars, boolAlgVars = i_vars_boolAlgVars, stringAlgVars = i_vars_stringAlgVars, paramVars = i_vars_paramVars, intParamVars = i_vars_intParamVars, boolParamVars = i_vars_boolParamVars, stringParamVars = i_vars_stringParamVars)), extObjInfo = (i_extObjInfo as SimCode.EXTOBJINFO(vars = i_extObjVars)), simulationSettingsOpt = SOME(SimCode.SIMULATION_SETTINGS(startTime = i_settings_startTime, stopTime = i_settings_stopTime, stepSize = i_settings_stepSize)), literals = i_literals, externalFunctionIncludes = i_externalFunctionIncludes, odeEquations = i_odeEquations, allEquations = i_allEquations), | ||
| 1047 | a_modelNamePrefixStr ) | ||
| 1048 | algorithm | ||
| 1049 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1050 | "#define fmi2TypesPlatform_h\n", | ||
| 1051 | "\n", | ||
| 1052 | "#define fmi2TypesPlatform \"default\" /* Compatible */\n", | ||
| 1053 | "\n", | ||
| 1054 | "typedef struct " | ||
| 1055 | }, false)); | ||
| 1056 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2Component_s"); | |
| 1057 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1058 | "* fmi2Component;\n", | ||
| 1059 | "typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */\n", | ||
| 1060 | "typedef void* fmi2FMUstate; /* Pointer to internal FMU state */\n", | ||
| 1061 | "typedef unsigned int fmi2ValueReference;\n", | ||
| 1062 | "typedef double fmi2Real;\n", | ||
| 1063 | "typedef int fmi2Integer;\n", | ||
| 1064 | "typedef int fmi2Boolean;\n", | ||
| 1065 | "typedef char fmi2Char;\n", | ||
| 1066 | "typedef const fmi2Char* fmi2String;\n", | ||
| 1067 | "typedef char fmi2Byte;\n", | ||
| 1068 | "\n", | ||
| 1069 | "#define fmi2True 1\n", | ||
| 1070 | "#define fmi2False 0\n", | ||
| 1071 | "\n", | ||
| 1072 | "#include \"fmi2/fmi2Functions.h\"\n", | ||
| 1073 | "\n", | ||
| 1074 | "#include <stdint.h>\n", | ||
| 1075 | "#include <stdio.h>\n", | ||
| 1076 | "\n", | ||
| 1077 | "void ModelicaFormatMessage(const char *fmt, ...)\n", | ||
| 1078 | "{\n", | ||
| 1079 | " va_list args;\n", | ||
| 1080 | " va_start(args, fmt);\n", | ||
| 1081 | " vprintf(fmt, args);\n", | ||
| 1082 | " va_end(args);\n", | ||
| 1083 | "}\n", | ||
| 1084 | "\n", | ||
| 1085 | "typedef struct " | ||
| 1086 | }, false)); | ||
| 1087 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2Component_s"); | |
| 1088 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1089 | " {\n", | ||
| 1090 | " fmi2Real currentTime;\n" | ||
| 1091 | }, true)); | ||
| 1092 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1093 | ✗ | ret_0 := SimCodeCodegenUtil.nVariablesReal(i_varInfo); | |
| 1094 | ✗ | txt := fun_51(txt, ret_0); | |
| 1095 | ✗ | txt := fun_52(txt, i_varInfo_numIntAlgVars); | |
| 1096 | ✗ | txt := fun_53(txt, i_varInfo_numBoolAlgVars); | |
| 1097 | ✗ | txt := fun_54(txt, i_varInfo_numStringAlgVars); | |
| 1098 | ✗ | txt := fun_55(txt, i_varInfo_numParams); | |
| 1099 | ✗ | txt := fun_56(txt, i_varInfo_numIntParams); | |
| 1100 | ✗ | txt := fun_57(txt, i_varInfo_numBoolParams); | |
| 1101 | ✗ | txt := fun_58(txt, i_varInfo_numIntParams); | |
| 1102 | ✗ | ret_1 := listLength(i_extObjVars); | |
| 1103 | ✗ | txt := fun_59(txt, ret_1); | |
| 1104 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1105 | ✗ | txt := Tpl.popBlock(txt); | |
| 1106 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("} ")); | |
| 1107 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2Component"); | |
| 1108 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1109 | ";\n", | ||
| 1110 | "\n" | ||
| 1111 | }, true)); | ||
| 1112 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2Component"); | |
| 1113 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(" ")); | |
| 1114 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "component"); | |
| 1115 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(" = {\n")); | |
| 1116 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1117 | ✗ | ret_2 := SimCodeCodegenUtil.nVariablesReal(i_varInfo); | |
| 1118 | ✗ | txt := fun_66(txt, ret_2, i_vars_realOptimizeFinalConstraintsVars, i_vars_realOptimizeConstraintsVars, i_vars_discreteAlgVars, i_vars_algVars, i_vars_derivativeVars, i_vars_stateVars); | |
| 1119 | ✗ | txt := fun_68(txt, i_varInfo_numIntAlgVars, i_vars_intAlgVars); | |
| 1120 | ✗ | txt := fun_70(txt, i_varInfo_numBoolAlgVars, i_vars_boolAlgVars); | |
| 1121 | ✗ | txt := fun_72(txt, i_varInfo_numStringAlgVars, i_vars_stringAlgVars); | |
| 1122 | ✗ | txt := fun_74(txt, i_varInfo_numParams, i_vars_paramVars); | |
| 1123 | ✗ | txt := fun_76(txt, i_varInfo_numIntParams, i_vars_intParamVars); | |
| 1124 | ✗ | txt := fun_78(txt, i_varInfo_numBoolParams, i_vars_boolParamVars); | |
| 1125 | ✗ | txt := fun_80(txt, i_varInfo_numStringParamVars, i_vars_stringParamVars); | |
| 1126 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1127 | ✗ | txt := Tpl.popBlock(txt); | |
| 1128 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1129 | "};\n", | ||
| 1130 | "\n", | ||
| 1131 | "#include <math.h>\n", | ||
| 1132 | "/* TODO: Generate used builtin functions before SimCode */\n", | ||
| 1133 | "static inline double om_mod(double x, double y)\n", | ||
| 1134 | "{\n", | ||
| 1135 | " return x-floor(x/y)*y;\n", | ||
| 1136 | "}\n", | ||
| 1137 | "\n" | ||
| 1138 | }, true)); | ||
| 1139 | ✗ | txt := functionsFile(txt, i_functions, i_literals, i_externalFunctionIncludes); | |
| 1140 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1141 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1142 | "\n", | ||
| 1143 | "fmi2Component " | ||
| 1144 | }, false)); | ||
| 1145 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2Instantiate"); | |
| 1146 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1147 | "(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)\n", | ||
| 1148 | "{\n", | ||
| 1149 | " static int initDone=0;\n", | ||
| 1150 | " if (initDone) {\n", | ||
| 1151 | " return NULL;\n", | ||
| 1152 | " }\n" | ||
| 1153 | }, true)); | ||
| 1154 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1155 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("return &")); | |
| 1156 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "component"); | |
| 1157 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(";\n")); | |
| 1158 | ✗ | txt := Tpl.popBlock(txt); | |
| 1159 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1160 | "}\n", | ||
| 1161 | "\n", | ||
| 1162 | "fmi2Status " | ||
| 1163 | }, false)); | ||
| 1164 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2SetupExperiment"); | |
| 1165 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1166 | "(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime)\n", | ||
| 1167 | "{\n", | ||
| 1168 | " return fmi2OK;\n", | ||
| 1169 | "}\n", | ||
| 1170 | "\n", | ||
| 1171 | "fmi2Status " | ||
| 1172 | }, false)); | ||
| 1173 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2EnterInitializationMode"); | |
| 1174 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1175 | "(fmi2Component comp)\n", | ||
| 1176 | "{\n" | ||
| 1177 | }, true)); | ||
| 1178 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1179 | ✗ | txt := callExternalObjectConstructors(txt, i_extObjInfo); | |
| 1180 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1181 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE("return fmi2OK;\n")); | |
| 1182 | ✗ | txt := Tpl.popBlock(txt); | |
| 1183 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1184 | "}\n", | ||
| 1185 | "\n", | ||
| 1186 | "fmi2Status " | ||
| 1187 | }, false)); | ||
| 1188 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2ExitInitializationMode"); | |
| 1189 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1190 | "(fmi2Component comp)\n", | ||
| 1191 | "{\n", | ||
| 1192 | " return fmi2OK;\n", | ||
| 1193 | "}\n", | ||
| 1194 | "\n", | ||
| 1195 | "static fmi2Status " | ||
| 1196 | }, false)); | ||
| 1197 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "functionODE"); | |
| 1198 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1199 | "(fmi2Component comp)\n", | ||
| 1200 | "{\n" | ||
| 1201 | }, true)); | ||
| 1202 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1203 | ✗ | txt := fun_82(txt, i_odeEquations); | |
| 1204 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1205 | ✗ | txt := Tpl.popBlock(txt); | |
| 1206 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1207 | "}\n", | ||
| 1208 | "\n", | ||
| 1209 | "static fmi2Status " | ||
| 1210 | }, false)); | ||
| 1211 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "functionOutputs"); | |
| 1212 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1213 | "(fmi2Component comp)\n", | ||
| 1214 | "{\n" | ||
| 1215 | }, true)); | ||
| 1216 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1217 | ✗ | txt := fun_86(txt, i_allEquations); | |
| 1218 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1219 | ✗ | txt := Tpl.popBlock(txt); | |
| 1220 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1221 | "}\n", | ||
| 1222 | "\n", | ||
| 1223 | "fmi2Status " | ||
| 1224 | }, false)); | ||
| 1225 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2DoStep"); | |
| 1226 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1227 | "(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint)\n", | ||
| 1228 | "{\n", | ||
| 1229 | " comp->currentTime = currentCommunicationPoint;\n" | ||
| 1230 | }, true)); | ||
| 1231 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1232 | ✗ | txt := fun_87(txt, i_varInfo_numStateVars); | |
| 1233 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1234 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE("/* TODO: Calculate time/state-dependent variables here... */\n")); | |
| 1235 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "functionOutputs"); | |
| 1236 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1237 | "(comp);\n", | ||
| 1238 | "return fmi2OK;\n" | ||
| 1239 | }, true)); | ||
| 1240 | ✗ | txt := Tpl.popBlock(txt); | |
| 1241 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1242 | "}\n", | ||
| 1243 | "\n", | ||
| 1244 | "int main(int argc, char **argv)\n", | ||
| 1245 | "{\n", | ||
| 1246 | " int terminateSimulation = 0;\n", | ||
| 1247 | " fmi2Status status = fmi2OK;\n", | ||
| 1248 | " fmi2CallbackFunctions cbf = {\n", | ||
| 1249 | " .logger = NULL,\n", | ||
| 1250 | " .allocateMemory = NULL /*calloc*/,\n", | ||
| 1251 | " .freeMemory = NULL /*free*/,\n", | ||
| 1252 | " .stepFinished = NULL, //synchronous execution\n", | ||
| 1253 | " .componentEnvironment = NULL\n", | ||
| 1254 | " };\n", | ||
| 1255 | "\n" | ||
| 1256 | }, true)); | ||
| 1257 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1258 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Component comp = ")); | |
| 1259 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2Instantiate"); | |
| 1260 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1261 | "(\"\", fmi2CoSimulation, \"\", \"\", &cbf, fmi2False, fmi2False);\n", | ||
| 1262 | "if (comp==NULL) {\n", | ||
| 1263 | " return 1;\n", | ||
| 1264 | "}\n" | ||
| 1265 | }, true)); | ||
| 1266 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2SetupExperiment"); | |
| 1267 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(comp, fmi2False, 0.0, ")); | |
| 1268 | ✗ | txt := Tpl.writeStr(txt, realString(i_settings_startTime)); | |
| 1269 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(", fmi2False, ")); | |
| 1270 | ✗ | txt := Tpl.writeStr(txt, realString(i_settings_stopTime)); | |
| 1271 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(");\n")); | |
| 1272 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2EnterInitializationMode"); | |
| 1273 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1274 | "(comp);\n", | ||
| 1275 | "// Set start-values? Nah...\n" | ||
| 1276 | }, true)); | ||
| 1277 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2ExitInitializationMode"); | |
| 1278 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1279 | "(comp);\n", | ||
| 1280 | "\n", | ||
| 1281 | "double currentTime = " | ||
| 1282 | }, false)); | ||
| 1283 | ✗ | txt := Tpl.writeStr(txt, realString(i_settings_startTime)); | |
| 1284 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1285 | ";\n", | ||
| 1286 | "double h = " | ||
| 1287 | }, false)); | ||
| 1288 | ✗ | txt := Tpl.writeStr(txt, realString(i_settings_stepSize)); | |
| 1289 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1290 | ";\n", | ||
| 1291 | "uint32_t i = 0;\n", | ||
| 1292 | "\n", | ||
| 1293 | "while (status == fmi2OK) {\n", | ||
| 1294 | " //retrieve outputs\n", | ||
| 1295 | " // fmi2GetReal(m, ..., 1, &y1);\n", | ||
| 1296 | " //set inputs\n", | ||
| 1297 | " // fmi2SetReal(m, ..., 1, &y2);\n", | ||
| 1298 | "\n", | ||
| 1299 | " //call slave and check status\n" | ||
| 1300 | }, true)); | ||
| 1301 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1302 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("status = ")); | |
| 1303 | ✗ | txt := CodegenUtil.symbolName(txt, Tpl.textString(a_modelNamePrefixStr), "fmi2DoStep"); | |
| 1304 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1305 | "(comp, currentTime, h, fmi2True);\n", | ||
| 1306 | "switch (status) {\n", | ||
| 1307 | " case fmi2Discard:\n", | ||
| 1308 | " case fmi2Error:\n", | ||
| 1309 | " case fmi2Fatal:\n", | ||
| 1310 | " case fmi2Pending /* Cannot happen */:\n", | ||
| 1311 | " terminateSimulation = 1;\n", | ||
| 1312 | " break;\n", | ||
| 1313 | " case fmi2OK:\n", | ||
| 1314 | " case fmi2Warning:\n", | ||
| 1315 | " break;\n", | ||
| 1316 | "}\n", | ||
| 1317 | "if (terminateSimulation) {\n", | ||
| 1318 | " break;\n", | ||
| 1319 | "}\n", | ||
| 1320 | "i++;\n", | ||
| 1321 | "/* increment master time */\n", | ||
| 1322 | "currentTime = " | ||
| 1323 | }, false)); | ||
| 1324 | ✗ | txt := Tpl.writeStr(txt, realString(i_settings_startTime)); | |
| 1325 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(" + h*i;\n")); | |
| 1326 | ✗ | txt := Tpl.popBlock(txt); | |
| 1327 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1328 | "}\n", | ||
| 1329 | "\n" | ||
| 1330 | }, true)); | ||
| 1331 | ✗ | txt := Tpl.popBlock(txt); | |
| 1332 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING_LIST({ | |
| 1333 | "#if 0\n", | ||
| 1334 | " if ((status != fmi2Error) && (status != fmi2Fatal)) {\n", | ||
| 1335 | " fmi2Terminate(m);\n", | ||
| 1336 | " }\n", | ||
| 1337 | " if (status != fmi2Fatal) {\n", | ||
| 1338 | " fmi2FreeInstance(m);\n", | ||
| 1339 | " }\n", | ||
| 1340 | "#endif\n", | ||
| 1341 | "}\n", | ||
| 1342 | "\n" | ||
| 1343 | }, true)); | ||
| 1344 | then txt; | ||
| 1345 | |||
| 1346 | case ( txt, | ||
| 1347 | _, | ||
| 1348 | _ ) | ||
| 1349 | then txt; | ||
| 1350 | end match; | ||
| 1351 | end fun_88; | ||
| 1352 | |||
| 1353 | public function mainFile | ||
| 1354 | input Tpl.Text txt; | ||
| 1355 | input SimCode.SimCode a_simCode; | ||
| 1356 | |||
| 1357 | output Tpl.Text out_txt; | ||
| 1358 | protected | ||
| 1359 | Tpl.Text l_modelNamePrefixStr; | ||
| 1360 | algorithm | ||
| 1361 | ✗ | l_modelNamePrefixStr := CodegenUtilSimulation.modelNamePrefix(Tpl.emptyTxt, a_simCode); | |
| 1362 | ✗ | out_txt := fun_88(txt, a_simCode, l_modelNamePrefixStr); | |
| 1363 | end mainFile; | ||
| 1364 | |||
| 1365 | protected function lm_90 | ||
| 1366 | input output Tpl.Text txt; | ||
| 1367 | input list<DAE.Statement> items; | ||
| 1368 | algorithm | ||
| 1369 | ✗ | for lstElt_90 in items loop | |
| 1370 | txt := match lstElt_90 | ||
| 1371 | local | ||
| 1372 | DAE.Statement i_stmt; | ||
| 1373 | |||
| 1374 | case i_stmt | ||
| 1375 | algorithm | ||
| 1376 | ✗ | txt := statement(txt, i_stmt); | |
| 1377 | ✗ | txt := Tpl.nextIter(txt); | |
| 1378 | then txt; | ||
| 1379 | end match; | ||
| 1380 | end for; | ||
| 1381 | end lm_90; | ||
| 1382 | |||
| 1383 | public function equation_ | ||
| 1384 | input Tpl.Text in_txt; | ||
| 1385 | input SimCode.SimEqSystem in_a_eq; | ||
| 1386 | |||
| 1387 | output Tpl.Text out_txt; | ||
| 1388 | algorithm | ||
| 1389 | out_txt := | ||
| 1390 | match(in_txt, in_a_eq) | ||
| 1391 | local | ||
| 1392 | Tpl.Text txt; | ||
| 1393 | list<DAE.Statement> i_statements; | ||
| 1394 | Integer i_index; | ||
| 1395 | DAE.Exp i_exp; | ||
| 1396 | DAE.ComponentRef i_cref; | ||
| 1397 | |||
| 1398 | case ( txt, | ||
| 1399 | SimCode.SES_SIMPLE_ASSIGN(cref = i_cref, exp = i_exp, index = i_index) ) | ||
| 1400 | algorithm | ||
| 1401 | ✗ | txt := cref(txt, i_cref); | |
| 1402 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(" = ")); | |
| 1403 | ✗ | txt := daeExp(txt, i_exp); | |
| 1404 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("; /* equation ")); | |
| 1405 | ✗ | txt := Tpl.writeStr(txt, intString(i_index)); | |
| 1406 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(" */")); | |
| 1407 | then txt; | ||
| 1408 | |||
| 1409 | case ( txt, | ||
| 1410 | SimCode.SES_ALGORITHM(statements = i_statements) ) | ||
| 1411 | algorithm | ||
| 1412 | ✗ | txt := Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); | |
| 1413 | ✗ | txt := lm_90(txt, i_statements); | |
| 1414 | ✗ | txt := Tpl.popIter(txt); | |
| 1415 | then txt; | ||
| 1416 | |||
| 1417 | case ( txt, | ||
| 1418 | _ ) | ||
| 1419 | algorithm | ||
| 1420 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 381, 14), "Unsupported equation: ..."); | |
| 1421 | then txt; | ||
| 1422 | end match; | ||
| 1423 | end equation_; | ||
| 1424 | |||
| 1425 | protected function lm_92 | ||
| 1426 | input output Tpl.Text txt; | ||
| 1427 | input list<DAE.Statement> items; | ||
| 1428 | algorithm | ||
| 1429 | ✗ | for lstElt_92 in items loop | |
| 1430 | txt := match lstElt_92 | ||
| 1431 | local | ||
| 1432 | DAE.Statement i_stmt; | ||
| 1433 | |||
| 1434 | case i_stmt | ||
| 1435 | algorithm | ||
| 1436 | ✗ | txt := statement(txt, i_stmt); | |
| 1437 | ✗ | txt := Tpl.nextIter(txt); | |
| 1438 | then txt; | ||
| 1439 | end match; | ||
| 1440 | end for; | ||
| 1441 | end lm_92; | ||
| 1442 | |||
| 1443 | public function statement | ||
| 1444 | input Tpl.Text in_txt; | ||
| 1445 | input DAE.Statement in_a_stmt; | ||
| 1446 | |||
| 1447 | output Tpl.Text out_txt; | ||
| 1448 | algorithm | ||
| 1449 | out_txt := | ||
| 1450 | match(in_txt, in_a_stmt) | ||
| 1451 | local | ||
| 1452 | Tpl.Text txt; | ||
| 1453 | DAE.Statement i_stmt; | ||
| 1454 | DAE.Else i_else__; | ||
| 1455 | list<DAE.Statement> i_statementLst; | ||
| 1456 | DAE.Exp i_exp; | ||
| 1457 | DAE.ComponentRef i_cr; | ||
| 1458 | Tpl.Text txt_0; | ||
| 1459 | |||
| 1460 | case ( txt, | ||
| 1461 | DAE.STMT_ASSIGN(type_ = DAE.T_ARRAY(ty = _)) ) | ||
| 1462 | algorithm | ||
| 1463 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 388, 16), "Array assignments are not supported"); | |
| 1464 | then txt; | ||
| 1465 | |||
| 1466 | case ( txt, | ||
| 1467 | DAE.STMT_ASSIGN(exp1 = DAE.CREF(componentRef = i_cr), exp = i_exp) ) | ||
| 1468 | algorithm | ||
| 1469 | ✗ | txt := cref(txt, i_cr); | |
| 1470 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(" = ")); | |
| 1471 | ✗ | txt := daeExp(txt, i_exp); | |
| 1472 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(";")); | |
| 1473 | then txt; | ||
| 1474 | |||
| 1475 | case ( txt, | ||
| 1476 | DAE.STMT_NORETCALL(exp = i_exp) ) | ||
| 1477 | algorithm | ||
| 1478 | ✗ | txt := daeExp(txt, i_exp); | |
| 1479 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(";")); | |
| 1480 | then txt; | ||
| 1481 | |||
| 1482 | case ( txt, | ||
| 1483 | DAE.STMT_IF(exp = i_exp, statementLst = i_statementLst, else_ = i_else__) ) | ||
| 1484 | algorithm | ||
| 1485 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("if (")); | |
| 1486 | ✗ | txt := daeExp(txt, i_exp); | |
| 1487 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(") {\n")); | |
| 1488 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1489 | ✗ | txt := Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); | |
| 1490 | ✗ | txt := lm_92(txt, i_statementLst); | |
| 1491 | ✗ | txt := Tpl.popIter(txt); | |
| 1492 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1493 | ✗ | txt := Tpl.popBlock(txt); | |
| 1494 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("}")); | |
| 1495 | ✗ | txt := elseStatement(txt, i_else__); | |
| 1496 | then txt; | ||
| 1497 | |||
| 1498 | case ( txt, | ||
| 1499 | i_stmt ) | ||
| 1500 | algorithm | ||
| 1501 | ✗ | txt_0 := Tpl.writeTok(Tpl.emptyTxt, Tpl.ST_STRING("Unsupported statement: ")); | |
| 1502 | ✗ | txt_0 := DAEDumpTpl.dumpStatement(txt_0, i_stmt); | |
| 1503 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 399, 14), Tpl.textString(txt_0)); | |
| 1504 | then txt; | ||
| 1505 | end match; | ||
| 1506 | end statement; | ||
| 1507 | |||
| 1508 | protected function lm_94 | ||
| 1509 | input output Tpl.Text txt; | ||
| 1510 | input list<DAE.Statement> items; | ||
| 1511 | algorithm | ||
| 1512 | ✗ | for lstElt_94 in items loop | |
| 1513 | txt := match lstElt_94 | ||
| 1514 | local | ||
| 1515 | DAE.Statement i_stmt; | ||
| 1516 | |||
| 1517 | case i_stmt | ||
| 1518 | algorithm | ||
| 1519 | ✗ | txt := statement(txt, i_stmt); | |
| 1520 | ✗ | txt := Tpl.nextIter(txt); | |
| 1521 | then txt; | ||
| 1522 | end match; | ||
| 1523 | end for; | ||
| 1524 | end lm_94; | ||
| 1525 | |||
| 1526 | protected function lm_95 | ||
| 1527 | input output Tpl.Text txt; | ||
| 1528 | input list<DAE.Statement> items; | ||
| 1529 | algorithm | ||
| 1530 | ✗ | for lstElt_95 in items loop | |
| 1531 | txt := match lstElt_95 | ||
| 1532 | local | ||
| 1533 | DAE.Statement i_stmt; | ||
| 1534 | |||
| 1535 | case i_stmt | ||
| 1536 | algorithm | ||
| 1537 | ✗ | txt := statement(txt, i_stmt); | |
| 1538 | ✗ | txt := Tpl.nextIter(txt); | |
| 1539 | then txt; | ||
| 1540 | end match; | ||
| 1541 | end for; | ||
| 1542 | end lm_95; | ||
| 1543 | |||
| 1544 | public function elseStatement | ||
| 1545 | input Tpl.Text in_txt; | ||
| 1546 | input DAE.Else in_a_else__; | ||
| 1547 | |||
| 1548 | output Tpl.Text out_txt; | ||
| 1549 | algorithm | ||
| 1550 | out_txt := | ||
| 1551 | match(in_txt, in_a_else__) | ||
| 1552 | local | ||
| 1553 | Tpl.Text txt; | ||
| 1554 | DAE.Else i_else__; | ||
| 1555 | list<DAE.Statement> i_statementLst; | ||
| 1556 | DAE.Exp i_exp; | ||
| 1557 | |||
| 1558 | case ( txt, | ||
| 1559 | DAE.NOELSE() ) | ||
| 1560 | then txt; | ||
| 1561 | |||
| 1562 | case ( txt, | ||
| 1563 | DAE.ELSEIF(exp = i_exp, statementLst = i_statementLst, else_ = i_else__) ) | ||
| 1564 | algorithm | ||
| 1565 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("else if (")); | |
| 1566 | ✗ | txt := daeExp(txt, i_exp); | |
| 1567 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(") {\n")); | |
| 1568 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1569 | ✗ | txt := Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); | |
| 1570 | ✗ | txt := lm_94(txt, i_statementLst); | |
| 1571 | ✗ | txt := Tpl.popIter(txt); | |
| 1572 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1573 | ✗ | txt := Tpl.popBlock(txt); | |
| 1574 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("}")); | |
| 1575 | ✗ | txt := elseStatement(txt, i_else__); | |
| 1576 | then txt; | ||
| 1577 | |||
| 1578 | case ( txt, | ||
| 1579 | DAE.ELSE(statementLst = i_statementLst) ) | ||
| 1580 | algorithm | ||
| 1581 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE("else {\n")); | |
| 1582 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 1583 | ✗ | txt := Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); | |
| 1584 | ✗ | txt := lm_95(txt, i_statementLst); | |
| 1585 | ✗ | txt := Tpl.popIter(txt); | |
| 1586 | ✗ | txt := Tpl.softNewLine(txt); | |
| 1587 | ✗ | txt := Tpl.popBlock(txt); | |
| 1588 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("}")); | |
| 1589 | then txt; | ||
| 1590 | |||
| 1591 | case ( txt, | ||
| 1592 | _ ) | ||
| 1593 | then txt; | ||
| 1594 | end match; | ||
| 1595 | end elseStatement; | ||
| 1596 | |||
| 1597 | public function cref | ||
| 1598 | input Tpl.Text in_txt; | ||
| 1599 | input DAE.ComponentRef in_a_cr; | ||
| 1600 | |||
| 1601 | output Tpl.Text out_txt; | ||
| 1602 | algorithm | ||
| 1603 | out_txt := | ||
| 1604 | match(in_txt, in_a_cr) | ||
| 1605 | local | ||
| 1606 | Tpl.Text txt; | ||
| 1607 | DAE.ComponentRef i_cr; | ||
| 1608 | |||
| 1609 | case ( txt, | ||
| 1610 | DAE.CREF_IDENT(ident = "time") ) | ||
| 1611 | algorithm | ||
| 1612 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("comp->currentTime")); | |
| 1613 | then txt; | ||
| 1614 | |||
| 1615 | case ( txt, | ||
| 1616 | DAE.WILD() ) | ||
| 1617 | then txt; | ||
| 1618 | |||
| 1619 | case ( txt, | ||
| 1620 | i_cr ) | ||
| 1621 | algorithm | ||
| 1622 | ✗ | txt := crefToCStr(txt, i_cr, 0, false); | |
| 1623 | then txt; | ||
| 1624 | end match; | ||
| 1625 | end cref; | ||
| 1626 | |||
| 1627 | public function crefLocal | ||
| 1628 | input Tpl.Text in_txt; | ||
| 1629 | input DAE.ComponentRef in_a_cr; | ||
| 1630 | |||
| 1631 | output Tpl.Text out_txt; | ||
| 1632 | algorithm | ||
| 1633 | out_txt := | ||
| 1634 | match(in_txt, in_a_cr) | ||
| 1635 | local | ||
| 1636 | Tpl.Text txt; | ||
| 1637 | DAE.Ident i_ident; | ||
| 1638 | |||
| 1639 | case ( txt, | ||
| 1640 | DAE.CREF_IDENT(ident = i_ident) ) | ||
| 1641 | algorithm | ||
| 1642 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("om_")); | |
| 1643 | ✗ | txt := Tpl.writeStr(txt, i_ident); | |
| 1644 | then txt; | ||
| 1645 | |||
| 1646 | case ( txt, | ||
| 1647 | _ ) | ||
| 1648 | algorithm | ||
| 1649 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 436, 14), "Only CREF_IDENT as local identifiers (for now)"); | |
| 1650 | then txt; | ||
| 1651 | end match; | ||
| 1652 | end crefLocal; | ||
| 1653 | |||
| 1654 | protected function fun_99 | ||
| 1655 | input Tpl.Text in_txt; | ||
| 1656 | input Boolean in_a_isPre; | ||
| 1657 | input DAE.ComponentRef in_a_cr; | ||
| 1658 | input Integer in_a_ix; | ||
| 1659 | input DAE.ComponentRef in_a_componentRef; | ||
| 1660 | |||
| 1661 | output Tpl.Text out_txt; | ||
| 1662 | algorithm | ||
| 1663 | out_txt := | ||
| 1664 | match(in_txt, in_a_isPre, in_a_cr, in_a_ix, in_a_componentRef) | ||
| 1665 | local | ||
| 1666 | Tpl.Text txt; | ||
| 1667 | DAE.ComponentRef a_cr; | ||
| 1668 | Integer a_ix; | ||
| 1669 | DAE.ComponentRef a_componentRef; | ||
| 1670 | Tpl.Text txt_0; | ||
| 1671 | |||
| 1672 | case ( txt, | ||
| 1673 | false, | ||
| 1674 | _, | ||
| 1675 | a_ix, | ||
| 1676 | a_componentRef ) | ||
| 1677 | algorithm | ||
| 1678 | ✗ | txt := crefToCStr(txt, a_componentRef, a_ix, true); | |
| 1679 | then txt; | ||
| 1680 | |||
| 1681 | case ( txt, | ||
| 1682 | _, | ||
| 1683 | a_cr, | ||
| 1684 | _, | ||
| 1685 | _ ) | ||
| 1686 | algorithm | ||
| 1687 | ✗ | txt_0 := Tpl.writeTok(Tpl.emptyTxt, Tpl.ST_STRING("Got $PRE for something that is already pre: ")); | |
| 1688 | ✗ | txt_0 := CodegenUtil.crefStr(txt_0, a_cr); | |
| 1689 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 444, 26), Tpl.textString(txt_0)); | |
| 1690 | then txt; | ||
| 1691 | end match; | ||
| 1692 | end fun_99; | ||
| 1693 | |||
| 1694 | protected function fun_100 | ||
| 1695 | input Tpl.Text in_txt; | ||
| 1696 | input SimCodeVar.SimVar in_mArg; | ||
| 1697 | input Boolean in_a_isPre; | ||
| 1698 | input Integer in_a_ix; | ||
| 1699 | |||
| 1700 | output Tpl.Text out_txt; | ||
| 1701 | algorithm | ||
| 1702 | out_txt := | ||
| 1703 | match(in_txt, in_mArg, in_a_isPre, in_a_ix) | ||
| 1704 | local | ||
| 1705 | Tpl.Text txt; | ||
| 1706 | Boolean a_isPre; | ||
| 1707 | Integer a_ix; | ||
| 1708 | Integer i_index; | ||
| 1709 | SimCodeVar.SimVar i_var; | ||
| 1710 | DAE.ComponentRef i_name; | ||
| 1711 | BackendDAE.VarKind i_varKind; | ||
| 1712 | String ret_2; | ||
| 1713 | Tpl.Text txt_1; | ||
| 1714 | Tpl.Text txt_0; | ||
| 1715 | |||
| 1716 | case ( txt, | ||
| 1717 | SimCodeVar.SIMVAR(index = -1, varKind = i_varKind, name = i_name), | ||
| 1718 | _, | ||
| 1719 | _ ) | ||
| 1720 | algorithm | ||
| 1721 | ✗ | txt_0 := Tpl.writeTok(Tpl.emptyTxt, Tpl.ST_STRING("crefToCStr got index=-1 for ")); | |
| 1722 | ✗ | txt_0 := CodegenUtil.variabilityString(txt_0, i_varKind); | |
| 1723 | ✗ | txt_0 := Tpl.writeTok(txt_0, Tpl.ST_STRING(" ")); | |
| 1724 | ✗ | txt_0 := CodegenUtil.crefStr(txt_0, i_name); | |
| 1725 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 447, 43), Tpl.textString(txt_0)); | |
| 1726 | then txt; | ||
| 1727 | |||
| 1728 | case ( txt, | ||
| 1729 | (i_var as SimCodeVar.SIMVAR(index = i_index, name = i_name, varKind = i_varKind)), | ||
| 1730 | a_isPre, | ||
| 1731 | a_ix ) | ||
| 1732 | algorithm | ||
| 1733 | ✗ | txt := varArrayNameValues(txt, i_var, a_ix, a_isPre); | |
| 1734 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("[")); | |
| 1735 | ✗ | txt := Tpl.writeStr(txt, intString(i_index)); | |
| 1736 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("] /* ")); | |
| 1737 | ✗ | txt_1 := CodegenUtil.crefStr(Tpl.emptyTxt, i_name); | |
| 1738 | ✗ | ret_2 := Util.escapeModelicaStringToCString(Tpl.textString(txt_1)); | |
| 1739 | ✗ | txt := Tpl.writeStr(txt, ret_2); | |
| 1740 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(" ")); | |
| 1741 | ✗ | txt := CodegenUtil.variabilityString(txt, i_varKind); | |
| 1742 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(" */")); | |
| 1743 | then txt; | ||
| 1744 | |||
| 1745 | case ( txt, | ||
| 1746 | _, | ||
| 1747 | _, | ||
| 1748 | _ ) | ||
| 1749 | algorithm | ||
| 1750 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("CREF_NOT_IDENT_OR_QUAL")); | |
| 1751 | then txt; | ||
| 1752 | end match; | ||
| 1753 | end fun_100; | ||
| 1754 | |||
| 1755 | public function crefToCStr | ||
| 1756 | input Tpl.Text in_txt; | ||
| 1757 | input DAE.ComponentRef in_a_cr; | ||
| 1758 | input Integer in_a_ix; | ||
| 1759 | input Boolean in_a_isPre; | ||
| 1760 | |||
| 1761 | output Tpl.Text out_txt; | ||
| 1762 | algorithm | ||
| 1763 | out_txt := | ||
| 1764 | match(in_txt, in_a_cr, in_a_ix, in_a_isPre) | ||
| 1765 | local | ||
| 1766 | Tpl.Text txt; | ||
| 1767 | Integer a_ix; | ||
| 1768 | Boolean a_isPre; | ||
| 1769 | DAE.ComponentRef i_cr; | ||
| 1770 | DAE.ComponentRef i_componentRef; | ||
| 1771 | SimCodeVar.SimVar ret_1; | ||
| 1772 | SimCode.SimCode ret_0; | ||
| 1773 | |||
| 1774 | case ( txt, | ||
| 1775 | (i_cr as DAE.CREF_QUAL(ident = "$PRE", subscriptLst = {}, componentRef = i_componentRef)), | ||
| 1776 | a_ix, | ||
| 1777 | a_isPre ) | ||
| 1778 | algorithm | ||
| 1779 | ✗ | txt := fun_99(txt, a_isPre, i_cr, a_ix, i_componentRef); | |
| 1780 | then txt; | ||
| 1781 | |||
| 1782 | case ( txt, | ||
| 1783 | i_cr, | ||
| 1784 | a_ix, | ||
| 1785 | a_isPre ) | ||
| 1786 | algorithm | ||
| 1787 | ✗ | ret_0 := SimCodeCodegenUtil.getSimCode(); | |
| 1788 | ✗ | ret_1 := SimCodeCodegenUtil.cref2simvar(i_cr, ret_0); | |
| 1789 | ✗ | txt := fun_100(txt, ret_1, a_isPre, a_ix); | |
| 1790 | then txt; | ||
| 1791 | end match; | ||
| 1792 | end crefToCStr; | ||
| 1793 | |||
| 1794 | public function crefShortType | ||
| 1795 | input Tpl.Text in_txt; | ||
| 1796 | input DAE.ComponentRef in_a_cr; | ||
| 1797 | |||
| 1798 | output Tpl.Text out_txt; | ||
| 1799 | algorithm | ||
| 1800 | out_txt := | ||
| 1801 | match(in_txt, in_a_cr) | ||
| 1802 | local | ||
| 1803 | Tpl.Text txt; | ||
| 1804 | DAE.ComponentRef i_componentRef; | ||
| 1805 | DAE.Type i_identType; | ||
| 1806 | |||
| 1807 | case ( txt, | ||
| 1808 | DAE.CREF_IDENT(identType = i_identType) ) | ||
| 1809 | algorithm | ||
| 1810 | ✗ | txt := expTypeShort(txt, i_identType); | |
| 1811 | then txt; | ||
| 1812 | |||
| 1813 | case ( txt, | ||
| 1814 | DAE.CREF_QUAL(componentRef = i_componentRef) ) | ||
| 1815 | algorithm | ||
| 1816 | ✗ | txt := crefShortType(txt, i_componentRef); | |
| 1817 | then txt; | ||
| 1818 | |||
| 1819 | case ( txt, | ||
| 1820 | _ ) | ||
| 1821 | algorithm | ||
| 1822 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("crefType:ERROR")); | |
| 1823 | then txt; | ||
| 1824 | end match; | ||
| 1825 | end crefShortType; | ||
| 1826 | |||
| 1827 | public function expTypeShort | ||
| 1828 | input Tpl.Text in_txt; | ||
| 1829 | input DAE.Type in_a_type; | ||
| 1830 | |||
| 1831 | output Tpl.Text out_txt; | ||
| 1832 | algorithm | ||
| 1833 | out_txt := | ||
| 1834 | match(in_txt, in_a_type) | ||
| 1835 | local | ||
| 1836 | Tpl.Text txt; | ||
| 1837 | DAE.Type i_type; | ||
| 1838 | DAE.Type i_ty; | ||
| 1839 | DAE.Type i_complexType; | ||
| 1840 | Tpl.Text txt_0; | ||
| 1841 | String ret_0; | ||
| 1842 | |||
| 1843 | case ( txt, | ||
| 1844 | DAE.T_INTEGER(varLst = _) ) | ||
| 1845 | algorithm | ||
| 1846 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Integer")); | |
| 1847 | then txt; | ||
| 1848 | |||
| 1849 | case ( txt, | ||
| 1850 | DAE.T_REAL(varLst = _) ) | ||
| 1851 | algorithm | ||
| 1852 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Real")); | |
| 1853 | then txt; | ||
| 1854 | |||
| 1855 | case ( txt, | ||
| 1856 | DAE.T_STRING(varLst = _) ) | ||
| 1857 | algorithm | ||
| 1858 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2String")); | |
| 1859 | then txt; | ||
| 1860 | |||
| 1861 | case ( txt, | ||
| 1862 | DAE.T_BOOL(varLst = _) ) | ||
| 1863 | algorithm | ||
| 1864 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Boolean")); | |
| 1865 | then txt; | ||
| 1866 | |||
| 1867 | case ( txt, | ||
| 1868 | DAE.T_ENUMERATION(index = _) ) | ||
| 1869 | algorithm | ||
| 1870 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2Integer")); | |
| 1871 | then txt; | ||
| 1872 | |||
| 1873 | case ( txt, | ||
| 1874 | DAE.T_SUBTYPE_BASIC(complexType = i_complexType) ) | ||
| 1875 | algorithm | ||
| 1876 | ✗ | txt := expTypeShort(txt, i_complexType); | |
| 1877 | then txt; | ||
| 1878 | |||
| 1879 | case ( txt, | ||
| 1880 | DAE.T_ARRAY(ty = i_ty) ) | ||
| 1881 | algorithm | ||
| 1882 | ✗ | txt := expTypeShort(txt, i_ty); | |
| 1883 | then txt; | ||
| 1884 | |||
| 1885 | case ( txt, | ||
| 1886 | DAE.T_COMPLEX(complexClassType = ClassInf.EXTERNAL_OBJ(path = _)) ) | ||
| 1887 | algorithm | ||
| 1888 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("void*")); | |
| 1889 | then txt; | ||
| 1890 | |||
| 1891 | case ( txt, | ||
| 1892 | i_type ) | ||
| 1893 | algorithm | ||
| 1894 | ✗ | txt_0 := Tpl.writeTok(Tpl.emptyTxt, Tpl.ST_STRING("expTypeShort: ")); | |
| 1895 | ✗ | ret_0 := TypesDump.unparseType(i_type); | |
| 1896 | ✗ | txt_0 := Tpl.writeStr(txt_0, ret_0); | |
| 1897 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 474, 14), Tpl.textString(txt_0)); | |
| 1898 | then txt; | ||
| 1899 | end match; | ||
| 1900 | end expTypeShort; | ||
| 1901 | |||
| 1902 | protected function fun_104 | ||
| 1903 | input Tpl.Text in_txt; | ||
| 1904 | input Boolean in_a_bool; | ||
| 1905 | |||
| 1906 | output Tpl.Text out_txt; | ||
| 1907 | algorithm | ||
| 1908 | out_txt := | ||
| 1909 | match(in_txt, in_a_bool) | ||
| 1910 | local | ||
| 1911 | Tpl.Text txt; | ||
| 1912 | |||
| 1913 | case ( txt, | ||
| 1914 | false ) | ||
| 1915 | algorithm | ||
| 1916 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2False")); | |
| 1917 | then txt; | ||
| 1918 | |||
| 1919 | case ( txt, | ||
| 1920 | _ ) | ||
| 1921 | algorithm | ||
| 1922 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2True")); | |
| 1923 | then txt; | ||
| 1924 | end match; | ||
| 1925 | end fun_104; | ||
| 1926 | |||
| 1927 | public function daeExp | ||
| 1928 | input Tpl.Text in_txt; | ||
| 1929 | input DAE.Exp in_a_exp; | ||
| 1930 | |||
| 1931 | output Tpl.Text out_txt; | ||
| 1932 | algorithm | ||
| 1933 | out_txt := | ||
| 1934 | match(in_txt, in_a_exp) | ||
| 1935 | local | ||
| 1936 | Tpl.Text txt; | ||
| 1937 | DAE.Exp i_e; | ||
| 1938 | DAE.ComponentRef i_componentRef; | ||
| 1939 | DAE.Exp i_expElse; | ||
| 1940 | DAE.Exp i_expThen; | ||
| 1941 | DAE.Exp i_expCond; | ||
| 1942 | DAE.Exp i_exp2; | ||
| 1943 | DAE.Operator i_operator; | ||
| 1944 | DAE.Exp i_exp1; | ||
| 1945 | DAE.Exp i_exp; | ||
| 1946 | Integer i_index; | ||
| 1947 | Boolean i_bool; | ||
| 1948 | String i_string; | ||
| 1949 | Real i_real; | ||
| 1950 | Integer i_integer; | ||
| 1951 | Tpl.Text txt_2; | ||
| 1952 | Tpl.Text txt_1; | ||
| 1953 | String ret_0; | ||
| 1954 | |||
| 1955 | case ( txt, | ||
| 1956 | DAE.ICONST(integer = i_integer) ) | ||
| 1957 | algorithm | ||
| 1958 | ✗ | txt := Tpl.writeStr(txt, intString(i_integer)); | |
| 1959 | then txt; | ||
| 1960 | |||
| 1961 | case ( txt, | ||
| 1962 | DAE.RCONST(real = i_real) ) | ||
| 1963 | algorithm | ||
| 1964 | ✗ | txt := Tpl.writeStr(txt, realString(i_real)); | |
| 1965 | then txt; | ||
| 1966 | |||
| 1967 | case ( txt, | ||
| 1968 | DAE.SCONST(string = i_string) ) | ||
| 1969 | algorithm | ||
| 1970 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("\"")); | |
| 1971 | ✗ | ret_0 := Util.escapeModelicaStringToCString(i_string); | |
| 1972 | ✗ | txt := Tpl.writeStr(txt, ret_0); | |
| 1973 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("\"")); | |
| 1974 | then txt; | ||
| 1975 | |||
| 1976 | case ( txt, | ||
| 1977 | DAE.BCONST(bool = i_bool) ) | ||
| 1978 | algorithm | ||
| 1979 | ✗ | txt := fun_104(txt, i_bool); | |
| 1980 | then txt; | ||
| 1981 | |||
| 1982 | case ( txt, | ||
| 1983 | DAE.ENUM_LITERAL(index = i_index) ) | ||
| 1984 | algorithm | ||
| 1985 | ✗ | txt := Tpl.writeStr(txt, intString(i_index)); | |
| 1986 | then txt; | ||
| 1987 | |||
| 1988 | case ( txt, | ||
| 1989 | DAE.LUNARY(operator = DAE.NOT(ty = _), exp = i_exp) ) | ||
| 1990 | algorithm | ||
| 1991 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("!(")); | |
| 1992 | ✗ | txt := daeExp(txt, i_exp); | |
| 1993 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 1994 | then txt; | ||
| 1995 | |||
| 1996 | case ( txt, | ||
| 1997 | DAE.UNARY(operator = DAE.UMINUS(ty = _), exp = i_exp) ) | ||
| 1998 | algorithm | ||
| 1999 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("-(")); | |
| 2000 | ✗ | txt := daeExp(txt, i_exp); | |
| 2001 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2002 | then txt; | ||
| 2003 | |||
| 2004 | case ( txt, | ||
| 2005 | (i_exp as DAE.BINARY(exp1 = i_exp1, operator = i_operator, exp2 = i_exp2)) ) | ||
| 2006 | algorithm | ||
| 2007 | ✗ | txt := daeExpBinary(txt, i_exp1, i_operator, i_exp2, i_exp); | |
| 2008 | then txt; | ||
| 2009 | |||
| 2010 | case ( txt, | ||
| 2011 | (i_exp as DAE.RELATION(exp1 = i_exp1, operator = i_operator, exp2 = i_exp2)) ) | ||
| 2012 | algorithm | ||
| 2013 | ✗ | txt := daeExpBinary(txt, i_exp1, i_operator, i_exp2, i_exp); | |
| 2014 | then txt; | ||
| 2015 | |||
| 2016 | case ( txt, | ||
| 2017 | DAE.IFEXP(expCond = i_expCond, expThen = i_expThen, expElse = i_expElse) ) | ||
| 2018 | algorithm | ||
| 2019 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2020 | ✗ | txt := daeExp(txt, i_expCond); | |
| 2021 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(") ? (")); | |
| 2022 | ✗ | txt := daeExp(txt, i_expThen); | |
| 2023 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(") : (")); | |
| 2024 | ✗ | txt := daeExp(txt, i_expElse); | |
| 2025 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2026 | then txt; | ||
| 2027 | |||
| 2028 | case ( txt, | ||
| 2029 | (i_exp as DAE.CALL(attr = DAE.CALL_ATTR(builtin = true))) ) | ||
| 2030 | algorithm | ||
| 2031 | ✗ | txt := daeExpCallBuiltin(txt, i_exp); | |
| 2032 | then txt; | ||
| 2033 | |||
| 2034 | case ( txt, | ||
| 2035 | (i_exp as DAE.CALL(path = _)) ) | ||
| 2036 | algorithm | ||
| 2037 | ✗ | txt := daeExpCall(txt, i_exp); | |
| 2038 | then txt; | ||
| 2039 | |||
| 2040 | case ( txt, | ||
| 2041 | (i_exp as DAE.CREF(ty = DAE.T_ARRAY(ty = _))) ) | ||
| 2042 | algorithm | ||
| 2043 | ✗ | txt_1 := Tpl.writeTok(Tpl.emptyTxt, Tpl.ST_STRING("CREF array... ")); | |
| 2044 | ✗ | txt_1 := ExpressionDumpTpl.dumpExp(txt_1, i_exp, "\""); | |
| 2045 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 492, 40), Tpl.textString(txt_1)); | |
| 2046 | then txt; | ||
| 2047 | |||
| 2048 | case ( txt, | ||
| 2049 | DAE.CREF(componentRef = i_componentRef) ) | ||
| 2050 | algorithm | ||
| 2051 | ✗ | txt := cref(txt, i_componentRef); | |
| 2052 | then txt; | ||
| 2053 | |||
| 2054 | case ( txt, | ||
| 2055 | DAE.CAST(ty = DAE.T_REAL(varLst = _), exp = i_e) ) | ||
| 2056 | algorithm | ||
| 2057 | ✗ | txt := daeExp(txt, i_e); | |
| 2058 | then txt; | ||
| 2059 | |||
| 2060 | case ( txt, | ||
| 2061 | i_exp ) | ||
| 2062 | algorithm | ||
| 2063 | ✗ | txt_2 := Tpl.writeTok(Tpl.emptyTxt, Tpl.ST_STRING("daeExp: Not supporting ")); | |
| 2064 | ✗ | txt_2 := ExpressionDumpTpl.dumpExp(txt_2, i_exp, "\""); | |
| 2065 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 495, 14), Tpl.textString(txt_2)); | |
| 2066 | then txt; | ||
| 2067 | end match; | ||
| 2068 | end daeExp; | ||
| 2069 | |||
| 2070 | protected function fun_106 | ||
| 2071 | input Tpl.Text in_txt; | ||
| 2072 | input DAE.Operator in_a_op; | ||
| 2073 | input DAE.Exp in_a_exp1; | ||
| 2074 | input DAE.Exp in_a_exp2; | ||
| 2075 | input DAE.Exp in_a_origExp; | ||
| 2076 | |||
| 2077 | output Tpl.Text out_txt; | ||
| 2078 | algorithm | ||
| 2079 | out_txt := | ||
| 2080 | match(in_txt, in_a_op, in_a_exp1, in_a_exp2, in_a_origExp) | ||
| 2081 | local | ||
| 2082 | Tpl.Text txt; | ||
| 2083 | DAE.Exp a_exp1; | ||
| 2084 | DAE.Exp a_exp2; | ||
| 2085 | DAE.Exp a_origExp; | ||
| 2086 | Tpl.Text txt_0; | ||
| 2087 | |||
| 2088 | case ( txt, | ||
| 2089 | DAE.ADD(ty = _), | ||
| 2090 | a_exp1, | ||
| 2091 | a_exp2, | ||
| 2092 | _ ) | ||
| 2093 | algorithm | ||
| 2094 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2095 | ✗ | txt := daeExp(txt, a_exp1); | |
| 2096 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")+(")); | |
| 2097 | ✗ | txt := daeExp(txt, a_exp2); | |
| 2098 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2099 | then txt; | ||
| 2100 | |||
| 2101 | case ( txt, | ||
| 2102 | DAE.SUB(ty = _), | ||
| 2103 | a_exp1, | ||
| 2104 | a_exp2, | ||
| 2105 | _ ) | ||
| 2106 | algorithm | ||
| 2107 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2108 | ✗ | txt := daeExp(txt, a_exp1); | |
| 2109 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")-(")); | |
| 2110 | ✗ | txt := daeExp(txt, a_exp2); | |
| 2111 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2112 | then txt; | ||
| 2113 | |||
| 2114 | case ( txt, | ||
| 2115 | DAE.MUL(ty = _), | ||
| 2116 | a_exp1, | ||
| 2117 | a_exp2, | ||
| 2118 | _ ) | ||
| 2119 | algorithm | ||
| 2120 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2121 | ✗ | txt := daeExp(txt, a_exp1); | |
| 2122 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")*(")); | |
| 2123 | ✗ | txt := daeExp(txt, a_exp2); | |
| 2124 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2125 | then txt; | ||
| 2126 | |||
| 2127 | case ( txt, | ||
| 2128 | DAE.DIV(ty = _), | ||
| 2129 | a_exp1, | ||
| 2130 | a_exp2, | ||
| 2131 | _ ) | ||
| 2132 | algorithm | ||
| 2133 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2134 | ✗ | txt := daeExp(txt, a_exp1); | |
| 2135 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")/(")); | |
| 2136 | ✗ | txt := daeExp(txt, a_exp2); | |
| 2137 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2138 | then txt; | ||
| 2139 | |||
| 2140 | case ( txt, | ||
| 2141 | DAE.POW(ty = _), | ||
| 2142 | a_exp1, | ||
| 2143 | a_exp2, | ||
| 2144 | _ ) | ||
| 2145 | algorithm | ||
| 2146 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("pow((")); | |
| 2147 | ✗ | txt := daeExp(txt, a_exp1); | |
| 2148 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("),(")); | |
| 2149 | ✗ | txt := daeExp(txt, a_exp2); | |
| 2150 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("))")); | |
| 2151 | then txt; | ||
| 2152 | |||
| 2153 | case ( txt, | ||
| 2154 | DAE.GREATER(ty = _), | ||
| 2155 | a_exp1, | ||
| 2156 | a_exp2, | ||
| 2157 | _ ) | ||
| 2158 | algorithm | ||
| 2159 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2160 | ✗ | txt := daeExp(txt, a_exp1); | |
| 2161 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")>(")); | |
| 2162 | ✗ | txt := daeExp(txt, a_exp2); | |
| 2163 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2164 | then txt; | ||
| 2165 | |||
| 2166 | case ( txt, | ||
| 2167 | DAE.GREATEREQ(ty = _), | ||
| 2168 | a_exp1, | ||
| 2169 | a_exp2, | ||
| 2170 | _ ) | ||
| 2171 | algorithm | ||
| 2172 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2173 | ✗ | txt := daeExp(txt, a_exp1); | |
| 2174 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")>=(")); | |
| 2175 | ✗ | txt := daeExp(txt, a_exp2); | |
| 2176 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2177 | then txt; | ||
| 2178 | |||
| 2179 | case ( txt, | ||
| 2180 | DAE.LESS(ty = _), | ||
| 2181 | a_exp1, | ||
| 2182 | a_exp2, | ||
| 2183 | _ ) | ||
| 2184 | algorithm | ||
| 2185 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2186 | ✗ | txt := daeExp(txt, a_exp1); | |
| 2187 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")<(")); | |
| 2188 | ✗ | txt := daeExp(txt, a_exp2); | |
| 2189 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2190 | then txt; | ||
| 2191 | |||
| 2192 | case ( txt, | ||
| 2193 | DAE.EQUAL(ty = _), | ||
| 2194 | a_exp1, | ||
| 2195 | a_exp2, | ||
| 2196 | _ ) | ||
| 2197 | algorithm | ||
| 2198 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2199 | ✗ | txt := daeExp(txt, a_exp1); | |
| 2200 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")==(")); | |
| 2201 | ✗ | txt := daeExp(txt, a_exp2); | |
| 2202 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2203 | then txt; | ||
| 2204 | |||
| 2205 | case ( txt, | ||
| 2206 | DAE.NEQUAL(ty = _), | ||
| 2207 | a_exp1, | ||
| 2208 | a_exp2, | ||
| 2209 | _ ) | ||
| 2210 | algorithm | ||
| 2211 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2212 | ✗ | txt := daeExp(txt, a_exp1); | |
| 2213 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")!=(")); | |
| 2214 | ✗ | txt := daeExp(txt, a_exp2); | |
| 2215 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2216 | then txt; | ||
| 2217 | |||
| 2218 | case ( txt, | ||
| 2219 | _, | ||
| 2220 | _, | ||
| 2221 | _, | ||
| 2222 | a_origExp ) | ||
| 2223 | algorithm | ||
| 2224 | ✗ | txt_0 := Tpl.writeTok(Tpl.emptyTxt, Tpl.ST_STRING("daeExpBinary: Not supporting operator? ")); | |
| 2225 | ✗ | txt_0 := ExpressionDumpTpl.dumpExp(txt_0, a_origExp, "\""); | |
| 2226 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 514, 14), Tpl.textString(txt_0)); | |
| 2227 | then txt; | ||
| 2228 | end match; | ||
| 2229 | end fun_106; | ||
| 2230 | |||
| 2231 | public function daeExpBinary | ||
| 2232 | input Tpl.Text txt; | ||
| 2233 | input DAE.Exp a_exp1; | ||
| 2234 | input DAE.Operator a_op; | ||
| 2235 | input DAE.Exp a_exp2; | ||
| 2236 | input DAE.Exp a_origExp; | ||
| 2237 | |||
| 2238 | output Tpl.Text out_txt; | ||
| 2239 | algorithm | ||
| 2240 | ✗ | out_txt := fun_106(txt, a_op, a_exp1, a_exp2, a_origExp); | |
| 2241 | end daeExpBinary; | ||
| 2242 | |||
| 2243 | public function daeExpCallBuiltin | ||
| 2244 | input Tpl.Text in_txt; | ||
| 2245 | input DAE.Exp in_a_exp; | ||
| 2246 | |||
| 2247 | output Tpl.Text out_txt; | ||
| 2248 | algorithm | ||
| 2249 | out_txt := | ||
| 2250 | match(in_txt, in_a_exp) | ||
| 2251 | local | ||
| 2252 | Tpl.Text txt; | ||
| 2253 | DAE.Exp i_exp; | ||
| 2254 | String i_name; | ||
| 2255 | DAE.Exp i_exp2; | ||
| 2256 | DAE.Exp i_exp1; | ||
| 2257 | Tpl.Text txt_0; | ||
| 2258 | |||
| 2259 | case ( txt, | ||
| 2260 | DAE.CALL(path = Absyn.IDENT(name = "DIVISION"), expLst = i_exp1 :: i_exp2 :: _) ) | ||
| 2261 | algorithm | ||
| 2262 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2263 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2264 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")/(")); | |
| 2265 | ✗ | txt := daeExp(txt, i_exp2); | |
| 2266 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2267 | then txt; | ||
| 2268 | |||
| 2269 | case ( txt, | ||
| 2270 | DAE.CALL(path = Absyn.IDENT(name = "smooth"), expLst = {_, i_exp2}) ) | ||
| 2271 | algorithm | ||
| 2272 | ✗ | txt := daeExp(txt, i_exp2); | |
| 2273 | then txt; | ||
| 2274 | |||
| 2275 | case ( txt, | ||
| 2276 | DAE.CALL(path = Absyn.IDENT(name = "integer"), expLst = i_exp1 :: _) ) | ||
| 2277 | algorithm | ||
| 2278 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("((int)")); | |
| 2279 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2280 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2281 | then txt; | ||
| 2282 | |||
| 2283 | case ( txt, | ||
| 2284 | DAE.CALL(path = Absyn.IDENT(name = "abs"), expLst = {i_exp1}) ) | ||
| 2285 | algorithm | ||
| 2286 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fabs(")); | |
| 2287 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2288 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2289 | then txt; | ||
| 2290 | |||
| 2291 | case ( txt, | ||
| 2292 | DAE.CALL(path = Absyn.IDENT(name = "min"), expLst = {i_exp1, i_exp2}, attr = DAE.CALL_ATTR(ty = DAE.T_REAL(varLst = _))) ) | ||
| 2293 | algorithm | ||
| 2294 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmin(")); | |
| 2295 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2296 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(",")); | |
| 2297 | ✗ | txt := daeExp(txt, i_exp2); | |
| 2298 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2299 | then txt; | ||
| 2300 | |||
| 2301 | case ( txt, | ||
| 2302 | DAE.CALL(path = Absyn.IDENT(name = "max"), expLst = {i_exp1, i_exp2}, attr = DAE.CALL_ATTR(ty = DAE.T_REAL(varLst = _))) ) | ||
| 2303 | algorithm | ||
| 2304 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmax(")); | |
| 2305 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2306 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(",")); | |
| 2307 | ✗ | txt := daeExp(txt, i_exp2); | |
| 2308 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2309 | then txt; | ||
| 2310 | |||
| 2311 | case ( txt, | ||
| 2312 | DAE.CALL(path = Absyn.IDENT(name = (i_name as "sin")), expLst = {i_exp1}) ) | ||
| 2313 | algorithm | ||
| 2314 | ✗ | txt := Tpl.writeStr(txt, i_name); | |
| 2315 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2316 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2317 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2318 | then txt; | ||
| 2319 | |||
| 2320 | case ( txt, | ||
| 2321 | DAE.CALL(path = Absyn.IDENT(name = (i_name as "cos")), expLst = {i_exp1}) ) | ||
| 2322 | algorithm | ||
| 2323 | ✗ | txt := Tpl.writeStr(txt, i_name); | |
| 2324 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2325 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2326 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2327 | then txt; | ||
| 2328 | |||
| 2329 | case ( txt, | ||
| 2330 | DAE.CALL(path = Absyn.IDENT(name = (i_name as "tan")), expLst = {i_exp1}) ) | ||
| 2331 | algorithm | ||
| 2332 | ✗ | txt := Tpl.writeStr(txt, i_name); | |
| 2333 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2334 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2335 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2336 | then txt; | ||
| 2337 | |||
| 2338 | case ( txt, | ||
| 2339 | DAE.CALL(path = Absyn.IDENT(name = (i_name as "asin")), expLst = {i_exp1}) ) | ||
| 2340 | algorithm | ||
| 2341 | ✗ | txt := Tpl.writeStr(txt, i_name); | |
| 2342 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2343 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2344 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2345 | then txt; | ||
| 2346 | |||
| 2347 | case ( txt, | ||
| 2348 | DAE.CALL(path = Absyn.IDENT(name = (i_name as "acos")), expLst = {i_exp1}) ) | ||
| 2349 | algorithm | ||
| 2350 | ✗ | txt := Tpl.writeStr(txt, i_name); | |
| 2351 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2352 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2353 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2354 | then txt; | ||
| 2355 | |||
| 2356 | case ( txt, | ||
| 2357 | DAE.CALL(path = Absyn.IDENT(name = (i_name as "atan")), expLst = {i_exp1}) ) | ||
| 2358 | algorithm | ||
| 2359 | ✗ | txt := Tpl.writeStr(txt, i_name); | |
| 2360 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2361 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2362 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2363 | then txt; | ||
| 2364 | |||
| 2365 | case ( txt, | ||
| 2366 | DAE.CALL(path = Absyn.IDENT(name = (i_name as "sinh")), expLst = {i_exp1}) ) | ||
| 2367 | algorithm | ||
| 2368 | ✗ | txt := Tpl.writeStr(txt, i_name); | |
| 2369 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2370 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2371 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2372 | then txt; | ||
| 2373 | |||
| 2374 | case ( txt, | ||
| 2375 | DAE.CALL(path = Absyn.IDENT(name = (i_name as "cosh")), expLst = {i_exp1}) ) | ||
| 2376 | algorithm | ||
| 2377 | ✗ | txt := Tpl.writeStr(txt, i_name); | |
| 2378 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2379 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2380 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2381 | then txt; | ||
| 2382 | |||
| 2383 | case ( txt, | ||
| 2384 | DAE.CALL(path = Absyn.IDENT(name = (i_name as "tanh")), expLst = {i_exp1}) ) | ||
| 2385 | algorithm | ||
| 2386 | ✗ | txt := Tpl.writeStr(txt, i_name); | |
| 2387 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2388 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2389 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2390 | then txt; | ||
| 2391 | |||
| 2392 | case ( txt, | ||
| 2393 | DAE.CALL(path = Absyn.IDENT(name = (i_name as "exp")), expLst = {i_exp1}) ) | ||
| 2394 | algorithm | ||
| 2395 | ✗ | txt := Tpl.writeStr(txt, i_name); | |
| 2396 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2397 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2398 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2399 | then txt; | ||
| 2400 | |||
| 2401 | case ( txt, | ||
| 2402 | DAE.CALL(path = Absyn.IDENT(name = (i_name as "log")), expLst = {i_exp1}) ) | ||
| 2403 | algorithm | ||
| 2404 | ✗ | txt := Tpl.writeStr(txt, i_name); | |
| 2405 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2406 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2407 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2408 | then txt; | ||
| 2409 | |||
| 2410 | case ( txt, | ||
| 2411 | DAE.CALL(path = Absyn.IDENT(name = (i_name as "log10")), expLst = {i_exp1}) ) | ||
| 2412 | algorithm | ||
| 2413 | ✗ | txt := Tpl.writeStr(txt, i_name); | |
| 2414 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2415 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2416 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2417 | then txt; | ||
| 2418 | |||
| 2419 | case ( txt, | ||
| 2420 | DAE.CALL(path = Absyn.IDENT(name = (i_name as "atan2")), expLst = {i_exp1, i_exp2}) ) | ||
| 2421 | algorithm | ||
| 2422 | ✗ | txt := Tpl.writeStr(txt, i_name); | |
| 2423 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 2424 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2425 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(",")); | |
| 2426 | ✗ | txt := daeExp(txt, i_exp2); | |
| 2427 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2428 | then txt; | ||
| 2429 | |||
| 2430 | case ( txt, | ||
| 2431 | DAE.CALL(path = Absyn.IDENT(name = "mod"), expLst = i_exp1 :: i_exp2 :: _) ) | ||
| 2432 | algorithm | ||
| 2433 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("om_mod(")); | |
| 2434 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2435 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(",")); | |
| 2436 | ✗ | txt := daeExp(txt, i_exp2); | |
| 2437 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2438 | then txt; | ||
| 2439 | |||
| 2440 | case ( txt, | ||
| 2441 | DAE.CALL(path = Absyn.IDENT(name = "floor"), expLst = i_exp1 :: _ :: _) ) | ||
| 2442 | algorithm | ||
| 2443 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("floor(")); | |
| 2444 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2445 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2446 | then txt; | ||
| 2447 | |||
| 2448 | case ( txt, | ||
| 2449 | DAE.CALL(path = Absyn.IDENT(name = "ceil"), expLst = i_exp1 :: _ :: _) ) | ||
| 2450 | algorithm | ||
| 2451 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("ceil(")); | |
| 2452 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2453 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2454 | then txt; | ||
| 2455 | |||
| 2456 | case ( txt, | ||
| 2457 | DAE.CALL(path = Absyn.IDENT(name = "pre"), expLst = {i_exp1}) ) | ||
| 2458 | algorithm | ||
| 2459 | ✗ | txt := daeExp(txt, i_exp1); | |
| 2460 | then txt; | ||
| 2461 | |||
| 2462 | case ( txt, | ||
| 2463 | (i_exp as DAE.CALL(path = _)) ) | ||
| 2464 | algorithm | ||
| 2465 | ✗ | txt_0 := Tpl.writeTok(Tpl.emptyTxt, Tpl.ST_STRING("daeExpCallBuiltin: Not supported: ")); | |
| 2466 | ✗ | txt_0 := ExpressionDumpTpl.dumpExp(txt_0, i_exp, "\""); | |
| 2467 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 549, 28), Tpl.textString(txt_0)); | |
| 2468 | then txt; | ||
| 2469 | |||
| 2470 | case ( txt, | ||
| 2471 | _ ) | ||
| 2472 | then txt; | ||
| 2473 | end match; | ||
| 2474 | end daeExpCallBuiltin; | ||
| 2475 | |||
| 2476 | protected function lm_109 | ||
| 2477 | input output Tpl.Text txt; | ||
| 2478 | input list<DAE.Exp> items; | ||
| 2479 | algorithm | ||
| 2480 | ✗ | for lstElt_109 in items loop | |
| 2481 | txt := match lstElt_109 | ||
| 2482 | local | ||
| 2483 | DAE.Exp i_e; | ||
| 2484 | |||
| 2485 | case i_e | ||
| 2486 | algorithm | ||
| 2487 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(", ")); | |
| 2488 | ✗ | txt := daeExp(txt, i_e); | |
| 2489 | then txt; | ||
| 2490 | end match; | ||
| 2491 | end for; | ||
| 2492 | end lm_109; | ||
| 2493 | |||
| 2494 | public function daeExpCall | ||
| 2495 | input Tpl.Text in_txt; | ||
| 2496 | input DAE.Exp in_a_exp; | ||
| 2497 | |||
| 2498 | output Tpl.Text out_txt; | ||
| 2499 | algorithm | ||
| 2500 | out_txt := | ||
| 2501 | match(in_txt, in_a_exp) | ||
| 2502 | local | ||
| 2503 | Tpl.Text txt; | ||
| 2504 | DAE.Exp i_exp; | ||
| 2505 | list<DAE.Exp> i_expLst; | ||
| 2506 | Absyn.Path i_path; | ||
| 2507 | Tpl.Text txt_0; | ||
| 2508 | |||
| 2509 | case ( txt, | ||
| 2510 | DAE.CALL(path = i_path, attr = DAE.CALL_ATTR(ty = _), expLst = i_expLst) ) | ||
| 2511 | algorithm | ||
| 2512 | ✗ | txt := CodegenUtil.underscorePath(txt, i_path); | |
| 2513 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(comp")); | |
| 2514 | ✗ | txt := lm_109(txt, i_expLst); | |
| 2515 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(")")); | |
| 2516 | then txt; | ||
| 2517 | |||
| 2518 | case ( txt, | ||
| 2519 | (i_exp as DAE.CALL(path = _)) ) | ||
| 2520 | algorithm | ||
| 2521 | ✗ | txt_0 := Tpl.writeTok(Tpl.emptyTxt, Tpl.ST_STRING("daeExpCall: Not supported: ")); | |
| 2522 | ✗ | txt_0 := ExpressionDumpTpl.dumpExp(txt_0, i_exp, "\""); | |
| 2523 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 556, 28), Tpl.textString(txt_0)); | |
| 2524 | then txt; | ||
| 2525 | |||
| 2526 | case ( txt, | ||
| 2527 | _ ) | ||
| 2528 | then txt; | ||
| 2529 | end match; | ||
| 2530 | end daeExpCall; | ||
| 2531 | |||
| 2532 | protected function fun_111 | ||
| 2533 | input Tpl.Text in_txt; | ||
| 2534 | input Boolean in_a_isPre; | ||
| 2535 | |||
| 2536 | output Tpl.Text out_txt; | ||
| 2537 | algorithm | ||
| 2538 | out_txt := | ||
| 2539 | match(in_txt, in_a_isPre) | ||
| 2540 | local | ||
| 2541 | Tpl.Text txt; | ||
| 2542 | |||
| 2543 | case ( txt, | ||
| 2544 | false ) | ||
| 2545 | then txt; | ||
| 2546 | |||
| 2547 | case ( txt, | ||
| 2548 | _ ) | ||
| 2549 | algorithm | ||
| 2550 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("XXXPreVars???")); | |
| 2551 | then txt; | ||
| 2552 | end match; | ||
| 2553 | end fun_111; | ||
| 2554 | |||
| 2555 | protected function fun_112 | ||
| 2556 | input Tpl.Text in_txt; | ||
| 2557 | input Boolean in_a_isPre; | ||
| 2558 | |||
| 2559 | output Tpl.Text out_txt; | ||
| 2560 | algorithm | ||
| 2561 | out_txt := | ||
| 2562 | match(in_txt, in_a_isPre) | ||
| 2563 | local | ||
| 2564 | Tpl.Text txt; | ||
| 2565 | |||
| 2566 | case ( txt, | ||
| 2567 | false ) | ||
| 2568 | then txt; | ||
| 2569 | |||
| 2570 | case ( txt, | ||
| 2571 | _ ) | ||
| 2572 | algorithm | ||
| 2573 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("Pre")); | |
| 2574 | then txt; | ||
| 2575 | end match; | ||
| 2576 | end fun_112; | ||
| 2577 | |||
| 2578 | protected function fun_113 | ||
| 2579 | input Tpl.Text in_txt; | ||
| 2580 | input SimCodeVar.SimVar in_a_var; | ||
| 2581 | input Boolean in_a_isPre; | ||
| 2582 | |||
| 2583 | output Tpl.Text out_txt; | ||
| 2584 | algorithm | ||
| 2585 | out_txt := | ||
| 2586 | match(in_txt, in_a_var, in_a_isPre) | ||
| 2587 | local | ||
| 2588 | Tpl.Text txt; | ||
| 2589 | Boolean a_isPre; | ||
| 2590 | DAE.ComponentRef i_name; | ||
| 2591 | |||
| 2592 | case ( txt, | ||
| 2593 | SimCodeVar.SIMVAR(varKind = BackendDAE.PARAM(), name = i_name), | ||
| 2594 | _ ) | ||
| 2595 | algorithm | ||
| 2596 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("comp->")); | |
| 2597 | ✗ | txt := crefShortType(txt, i_name); | |
| 2598 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("Parameter")); | |
| 2599 | then txt; | ||
| 2600 | |||
| 2601 | case ( txt, | ||
| 2602 | SimCodeVar.SIMVAR(varKind = BackendDAE.OPT_TGRID(), name = i_name), | ||
| 2603 | _ ) | ||
| 2604 | algorithm | ||
| 2605 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("comp->")); | |
| 2606 | ✗ | txt := crefShortType(txt, i_name); | |
| 2607 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("Parameter")); | |
| 2608 | then txt; | ||
| 2609 | |||
| 2610 | case ( txt, | ||
| 2611 | SimCodeVar.SIMVAR(varKind = BackendDAE.EXTOBJ(fullClassName = _)), | ||
| 2612 | _ ) | ||
| 2613 | algorithm | ||
| 2614 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("comp->extObjs")); | |
| 2615 | then txt; | ||
| 2616 | |||
| 2617 | case ( txt, | ||
| 2618 | SimCodeVar.SIMVAR(name = i_name), | ||
| 2619 | a_isPre ) | ||
| 2620 | algorithm | ||
| 2621 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("comp")); | |
| 2622 | ✗ | txt := fun_111(txt, a_isPre); | |
| 2623 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("->")); | |
| 2624 | ✗ | txt := crefShortType(txt, i_name); | |
| 2625 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("Vars")); | |
| 2626 | ✗ | txt := fun_112(txt, a_isPre); | |
| 2627 | then txt; | ||
| 2628 | |||
| 2629 | case ( txt, | ||
| 2630 | _, | ||
| 2631 | _ ) | ||
| 2632 | then txt; | ||
| 2633 | end match; | ||
| 2634 | end fun_113; | ||
| 2635 | |||
| 2636 | protected function fun_114 | ||
| 2637 | input Tpl.Text in_txt; | ||
| 2638 | input Integer in_a_ix; | ||
| 2639 | input SimCodeVar.SimVar in_a_var; | ||
| 2640 | input Boolean in_a_isPre; | ||
| 2641 | |||
| 2642 | output Tpl.Text out_txt; | ||
| 2643 | algorithm | ||
| 2644 | out_txt := | ||
| 2645 | match(in_txt, in_a_ix, in_a_var, in_a_isPre) | ||
| 2646 | local | ||
| 2647 | Tpl.Text txt; | ||
| 2648 | SimCodeVar.SimVar a_var; | ||
| 2649 | Boolean a_isPre; | ||
| 2650 | |||
| 2651 | case ( txt, | ||
| 2652 | 0, | ||
| 2653 | a_var, | ||
| 2654 | a_isPre ) | ||
| 2655 | algorithm | ||
| 2656 | ✗ | txt := fun_113(txt, a_var, a_isPre); | |
| 2657 | then txt; | ||
| 2658 | |||
| 2659 | case ( txt, | ||
| 2660 | _, | ||
| 2661 | _, | ||
| 2662 | _ ) | ||
| 2663 | algorithm | ||
| 2664 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 568, 14), "varArrayNameValues ix>0"); | |
| 2665 | then txt; | ||
| 2666 | end match; | ||
| 2667 | end fun_114; | ||
| 2668 | |||
| 2669 | public function varArrayNameValues | ||
| 2670 | input Tpl.Text txt; | ||
| 2671 | input SimCodeVar.SimVar a_var; | ||
| 2672 | input Integer a_ix; | ||
| 2673 | input Boolean a_isPre; | ||
| 2674 | |||
| 2675 | output Tpl.Text out_txt; | ||
| 2676 | algorithm | ||
| 2677 | ✗ | out_txt := fun_114(txt, a_ix, a_var, a_isPre); | |
| 2678 | end varArrayNameValues; | ||
| 2679 | |||
| 2680 | protected function fun_116 | ||
| 2681 | input Tpl.Text in_txt; | ||
| 2682 | input Boolean in_a_bool; | ||
| 2683 | |||
| 2684 | output Tpl.Text out_txt; | ||
| 2685 | algorithm | ||
| 2686 | out_txt := | ||
| 2687 | match(in_txt, in_a_bool) | ||
| 2688 | local | ||
| 2689 | Tpl.Text txt; | ||
| 2690 | |||
| 2691 | case ( txt, | ||
| 2692 | false ) | ||
| 2693 | algorithm | ||
| 2694 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2False")); | |
| 2695 | then txt; | ||
| 2696 | |||
| 2697 | case ( txt, | ||
| 2698 | _ ) | ||
| 2699 | algorithm | ||
| 2700 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2True")); | |
| 2701 | then txt; | ||
| 2702 | end match; | ||
| 2703 | end fun_116; | ||
| 2704 | |||
| 2705 | protected function fun_117 | ||
| 2706 | input Tpl.Text in_txt; | ||
| 2707 | input DAE.Type in_a_ty__; | ||
| 2708 | input DAE.Exp in_a_value; | ||
| 2709 | |||
| 2710 | output Tpl.Text out_txt; | ||
| 2711 | algorithm | ||
| 2712 | out_txt := | ||
| 2713 | match(in_txt, in_a_ty__, in_a_value) | ||
| 2714 | local | ||
| 2715 | Tpl.Text txt; | ||
| 2716 | DAE.Exp a_value; | ||
| 2717 | Tpl.Text txt_0; | ||
| 2718 | |||
| 2719 | case ( txt, | ||
| 2720 | DAE.T_REAL(varLst = _), | ||
| 2721 | _ ) | ||
| 2722 | algorithm | ||
| 2723 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("0.0")); | |
| 2724 | then txt; | ||
| 2725 | |||
| 2726 | case ( txt, | ||
| 2727 | _, | ||
| 2728 | a_value ) | ||
| 2729 | algorithm | ||
| 2730 | ✗ | txt_0 := Tpl.writeTok(Tpl.emptyTxt, Tpl.ST_STRING("No start value for variable... ")); | |
| 2731 | ✗ | txt_0 := ExpressionDumpTpl.dumpExp(txt_0, a_value, "\""); | |
| 2732 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 582, 16), Tpl.textString(txt_0)); | |
| 2733 | then txt; | ||
| 2734 | end match; | ||
| 2735 | end fun_117; | ||
| 2736 | |||
| 2737 | public function constVal | ||
| 2738 | input Tpl.Text in_txt; | ||
| 2739 | input DAE.Exp in_a_value; | ||
| 2740 | input DAE.Type in_a_ty__; | ||
| 2741 | |||
| 2742 | output Tpl.Text out_txt; | ||
| 2743 | algorithm | ||
| 2744 | out_txt := | ||
| 2745 | match(in_txt, in_a_value, in_a_ty__) | ||
| 2746 | local | ||
| 2747 | Tpl.Text txt; | ||
| 2748 | DAE.Type a_ty__; | ||
| 2749 | DAE.Exp i_value; | ||
| 2750 | Integer i_index; | ||
| 2751 | Boolean i_bool; | ||
| 2752 | String i_string; | ||
| 2753 | Real i_real; | ||
| 2754 | Integer i_integer; | ||
| 2755 | String ret_0; | ||
| 2756 | |||
| 2757 | case ( txt, | ||
| 2758 | DAE.ICONST(integer = i_integer), | ||
| 2759 | _ ) | ||
| 2760 | algorithm | ||
| 2761 | ✗ | txt := Tpl.writeStr(txt, intString(i_integer)); | |
| 2762 | then txt; | ||
| 2763 | |||
| 2764 | case ( txt, | ||
| 2765 | DAE.RCONST(real = i_real), | ||
| 2766 | _ ) | ||
| 2767 | algorithm | ||
| 2768 | ✗ | txt := Tpl.writeStr(txt, realString(i_real)); | |
| 2769 | then txt; | ||
| 2770 | |||
| 2771 | case ( txt, | ||
| 2772 | DAE.SCONST(string = i_string), | ||
| 2773 | _ ) | ||
| 2774 | algorithm | ||
| 2775 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("\"")); | |
| 2776 | ✗ | ret_0 := Util.escapeModelicaStringToCString(i_string); | |
| 2777 | ✗ | txt := Tpl.writeStr(txt, ret_0); | |
| 2778 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("\"")); | |
| 2779 | then txt; | ||
| 2780 | |||
| 2781 | case ( txt, | ||
| 2782 | DAE.BCONST(bool = i_bool), | ||
| 2783 | _ ) | ||
| 2784 | algorithm | ||
| 2785 | ✗ | txt := fun_116(txt, i_bool); | |
| 2786 | then txt; | ||
| 2787 | |||
| 2788 | case ( txt, | ||
| 2789 | DAE.ENUM_LITERAL(index = i_index), | ||
| 2790 | _ ) | ||
| 2791 | algorithm | ||
| 2792 | ✗ | txt := Tpl.writeStr(txt, intString(i_index)); | |
| 2793 | then txt; | ||
| 2794 | |||
| 2795 | case ( txt, | ||
| 2796 | i_value, | ||
| 2797 | a_ty__ ) | ||
| 2798 | algorithm | ||
| 2799 | ✗ | txt := fun_117(txt, a_ty__, i_value); | |
| 2800 | then txt; | ||
| 2801 | end match; | ||
| 2802 | end constVal; | ||
| 2803 | |||
| 2804 | public function startValue | ||
| 2805 | input Tpl.Text in_txt; | ||
| 2806 | input SimCodeVar.SimVar in_a_var; | ||
| 2807 | |||
| 2808 | output Tpl.Text out_txt; | ||
| 2809 | algorithm | ||
| 2810 | out_txt := | ||
| 2811 | match(in_txt, in_a_var) | ||
| 2812 | local | ||
| 2813 | Tpl.Text txt; | ||
| 2814 | DAE.ComponentRef i_name; | ||
| 2815 | DAE.Type i_ty; | ||
| 2816 | DAE.Exp i_e; | ||
| 2817 | Tpl.Text txt_0; | ||
| 2818 | |||
| 2819 | case ( txt, | ||
| 2820 | SimCodeVar.SIMVAR(initialValue = SOME(i_e), type_ = i_ty, name = i_name) ) | ||
| 2821 | algorithm | ||
| 2822 | ✗ | txt := constVal(txt, i_e, i_ty); | |
| 2823 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(" /*")); | |
| 2824 | ✗ | txt := CodegenUtil.crefStr(txt, i_name); | |
| 2825 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("*/,")); | |
| 2826 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 2827 | then txt; | ||
| 2828 | |||
| 2829 | case ( txt, | ||
| 2830 | SimCodeVar.SIMVAR(type_ = DAE.T_REAL(varLst = _), name = i_name) ) | ||
| 2831 | algorithm | ||
| 2832 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("0.0 /*")); | |
| 2833 | ✗ | txt := CodegenUtil.crefStr(txt, i_name); | |
| 2834 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("*/,")); | |
| 2835 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 2836 | then txt; | ||
| 2837 | |||
| 2838 | case ( txt, | ||
| 2839 | SimCodeVar.SIMVAR(type_ = DAE.T_INTEGER(varLst = _), name = i_name) ) | ||
| 2840 | algorithm | ||
| 2841 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("0 /*")); | |
| 2842 | ✗ | txt := CodegenUtil.crefStr(txt, i_name); | |
| 2843 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("*/,")); | |
| 2844 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 2845 | then txt; | ||
| 2846 | |||
| 2847 | case ( txt, | ||
| 2848 | SimCodeVar.SIMVAR(type_ = DAE.T_BOOL(varLst = _), name = i_name) ) | ||
| 2849 | algorithm | ||
| 2850 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("fmi2False /*")); | |
| 2851 | ✗ | txt := CodegenUtil.crefStr(txt, i_name); | |
| 2852 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("*/,")); | |
| 2853 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 2854 | then txt; | ||
| 2855 | |||
| 2856 | case ( txt, | ||
| 2857 | SimCodeVar.SIMVAR(type_ = DAE.T_STRING(varLst = _), name = i_name) ) | ||
| 2858 | algorithm | ||
| 2859 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("\"\" /*")); | |
| 2860 | ✗ | txt := CodegenUtil.crefStr(txt, i_name); | |
| 2861 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("*/,")); | |
| 2862 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); | |
| 2863 | then txt; | ||
| 2864 | |||
| 2865 | case ( txt, | ||
| 2866 | SimCodeVar.SIMVAR(name = i_name) ) | ||
| 2867 | algorithm | ||
| 2868 | ✗ | txt_0 := Tpl.writeTok(Tpl.emptyTxt, Tpl.ST_STRING("No start value for variable ")); | |
| 2869 | ✗ | txt_0 := CodegenUtil.crefStr(txt_0, i_name); | |
| 2870 | ✗ | txt_0 := Tpl.writeTok(txt_0, Tpl.ST_STRING(".")); | |
| 2871 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 594, 30), Tpl.textString(txt_0)); | |
| 2872 | then txt; | ||
| 2873 | |||
| 2874 | case ( txt, | ||
| 2875 | _ ) | ||
| 2876 | then txt; | ||
| 2877 | end match; | ||
| 2878 | end startValue; | ||
| 2879 | |||
| 2880 | protected function lm_120 | ||
| 2881 | input output Tpl.Text txt; | ||
| 2882 | input list<DAE.Exp> items; | ||
| 2883 | algorithm | ||
| 2884 | ✗ | for lstElt_120 in items loop | |
| 2885 | txt := match lstElt_120 | ||
| 2886 | local | ||
| 2887 | Integer x_i0; | ||
| 2888 | DAE.Exp i_literal; | ||
| 2889 | |||
| 2890 | case i_literal | ||
| 2891 | algorithm | ||
| 2892 | ✗ | x_i0 := Tpl.getIteri_i0(txt); | |
| 2893 | ✗ | txt := literalExpConst(txt, i_literal, x_i0); | |
| 2894 | ✗ | txt := Tpl.nextIter(txt); | |
| 2895 | then txt; | ||
| 2896 | end match; | ||
| 2897 | end for; | ||
| 2898 | end lm_120; | ||
| 2899 | |||
| 2900 | protected function lm_121 | ||
| 2901 | input output Tpl.Text txt; | ||
| 2902 | input list<String> items; | ||
| 2903 | algorithm | ||
| 2904 | ✗ | for lstElt_121 in items loop | |
| 2905 | txt := match lstElt_121 | ||
| 2906 | local | ||
| 2907 | String i_inc; | ||
| 2908 | |||
| 2909 | case i_inc | ||
| 2910 | algorithm | ||
| 2911 | ✗ | txt := Tpl.writeStr(txt, i_inc); | |
| 2912 | ✗ | txt := Tpl.nextIter(txt); | |
| 2913 | then txt; | ||
| 2914 | end match; | ||
| 2915 | end for; | ||
| 2916 | end lm_121; | ||
| 2917 | |||
| 2918 | protected function lm_122 | ||
| 2919 | input output Tpl.Text txt; | ||
| 2920 | input list<SimCodeFunction.Function> items; | ||
| 2921 | algorithm | ||
| 2922 | ✗ | for lstElt_122 in items loop | |
| 2923 | txt := match lstElt_122 | ||
| 2924 | local | ||
| 2925 | SimCodeFunction.Function i_func; | ||
| 2926 | |||
| 2927 | case i_func | ||
| 2928 | algorithm | ||
| 2929 | ✗ | txt := functionDeclaration(txt, i_func); | |
| 2930 | ✗ | txt := Tpl.nextIter(txt); | |
| 2931 | then txt; | ||
| 2932 | end match; | ||
| 2933 | end for; | ||
| 2934 | end lm_122; | ||
| 2935 | |||
| 2936 | protected function lm_123 | ||
| 2937 | input output Tpl.Text txt; | ||
| 2938 | input list<SimCodeFunction.Function> items; | ||
| 2939 | algorithm | ||
| 2940 | ✗ | for lstElt_123 in items loop | |
| 2941 | txt := match lstElt_123 | ||
| 2942 | local | ||
| 2943 | SimCodeFunction.Function i_func; | ||
| 2944 | |||
| 2945 | case i_func | ||
| 2946 | algorithm | ||
| 2947 | ✗ | txt := functionBody(txt, i_func); | |
| 2948 | ✗ | txt := Tpl.nextIter(txt); | |
| 2949 | then txt; | ||
| 2950 | end match; | ||
| 2951 | end for; | ||
| 2952 | end lm_123; | ||
| 2953 | |||
| 2954 | public function functionsFile | ||
| 2955 | input Tpl.Text txt; | ||
| 2956 | input list<SimCodeFunction.Function> a_functions; | ||
| 2957 | input list<DAE.Exp> a_literals; | ||
| 2958 | input list<String> a_externalFunctionIncludes; | ||
| 2959 | |||
| 2960 | output Tpl.Text out_txt; | ||
| 2961 | algorithm | ||
| 2962 | ✗ | out_txt := Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, SOME(Tpl.ST_STRING("")), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); | |
| 2963 | ✗ | out_txt := lm_120(out_txt, a_literals); | |
| 2964 | ✗ | out_txt := Tpl.popIter(out_txt); | |
| 2965 | ✗ | out_txt := Tpl.softNewLine(out_txt); | |
| 2966 | ✗ | out_txt := Tpl.pushIter(out_txt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); | |
| 2967 | ✗ | out_txt := lm_121(out_txt, a_externalFunctionIncludes); | |
| 2968 | ✗ | out_txt := Tpl.popIter(out_txt); | |
| 2969 | ✗ | out_txt := Tpl.softNewLine(out_txt); | |
| 2970 | ✗ | out_txt := Tpl.writeTok(out_txt, Tpl.ST_NEW_LINE()); | |
| 2971 | ✗ | out_txt := Tpl.pushIter(out_txt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); | |
| 2972 | ✗ | out_txt := lm_122(out_txt, a_functions); | |
| 2973 | ✗ | out_txt := Tpl.popIter(out_txt); | |
| 2974 | ✗ | out_txt := Tpl.softNewLine(out_txt); | |
| 2975 | ✗ | out_txt := Tpl.writeTok(out_txt, Tpl.ST_NEW_LINE()); | |
| 2976 | ✗ | out_txt := Tpl.pushIter(out_txt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); | |
| 2977 | ✗ | out_txt := lm_123(out_txt, a_functions); | |
| 2978 | ✗ | out_txt := Tpl.popIter(out_txt); | |
| 2979 | end functionsFile; | ||
| 2980 | |||
| 2981 | public function functionBody | ||
| 2982 | input Tpl.Text in_txt; | ||
| 2983 | input SimCodeFunction.Function in_a_fn; | ||
| 2984 | |||
| 2985 | output Tpl.Text out_txt; | ||
| 2986 | algorithm | ||
| 2987 | out_txt := | ||
| 2988 | match(in_txt, in_a_fn) | ||
| 2989 | local | ||
| 2990 | Tpl.Text txt; | ||
| 2991 | SimCodeFunction.Function i_fn; | ||
| 2992 | |||
| 2993 | case ( txt, | ||
| 2994 | (i_fn as SimCodeFunction.FUNCTION(name = _)) ) | ||
| 2995 | algorithm | ||
| 2996 | ✗ | txt := functionBodyRegularFunction(txt, i_fn); | |
| 2997 | then txt; | ||
| 2998 | |||
| 2999 | case ( txt, | ||
| 3000 | (i_fn as SimCodeFunction.EXTERNAL_FUNCTION(name = _)) ) | ||
| 3001 | algorithm | ||
| 3002 | ✗ | txt := functionBodyExternalFunction(txt, i_fn); | |
| 3003 | then txt; | ||
| 3004 | |||
| 3005 | case ( txt, | ||
| 3006 | SimCodeFunction.RECORD_CONSTRUCTOR(name = _) ) | ||
| 3007 | algorithm | ||
| 3008 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 620, 57), "No records in embedded C yet"); | |
| 3009 | then txt; | ||
| 3010 | |||
| 3011 | case ( txt, | ||
| 3012 | SimCodeFunction.KERNEL_FUNCTION(name = _) ) | ||
| 3013 | algorithm | ||
| 3014 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 621, 57), "No kernel functions in embedded C"); | |
| 3015 | then txt; | ||
| 3016 | |||
| 3017 | case ( txt, | ||
| 3018 | _ ) | ||
| 3019 | then txt; | ||
| 3020 | end match; | ||
| 3021 | end functionBody; | ||
| 3022 | |||
| 3023 | public function functionDeclaration | ||
| 3024 | input Tpl.Text in_txt; | ||
| 3025 | input SimCodeFunction.Function in_a_fn; | ||
| 3026 | |||
| 3027 | output Tpl.Text out_txt; | ||
| 3028 | algorithm | ||
| 3029 | out_txt := | ||
| 3030 | match(in_txt, in_a_fn) | ||
| 3031 | local | ||
| 3032 | Tpl.Text txt; | ||
| 3033 | list<SimCodeFunction.Variable> i_funArgs; | ||
| 3034 | list<SimCodeFunction.Variable> i_outVars; | ||
| 3035 | list<SimCodeFunction.Variable> i_functionArguments; | ||
| 3036 | Absyn.Path i_name; | ||
| 3037 | Tpl.Text txt_1; | ||
| 3038 | Tpl.Text txt_0; | ||
| 3039 | |||
| 3040 | case ( txt, | ||
| 3041 | SimCodeFunction.FUNCTION(name = i_name, functionArguments = i_functionArguments, outVars = i_outVars) ) | ||
| 3042 | algorithm | ||
| 3043 | ✗ | txt_0 := CodegenUtil.underscorePath(Tpl.emptyTxt, i_name); | |
| 3044 | ✗ | (txt, txt_0) := functionPrototype(txt, txt_0, i_functionArguments, i_outVars); | |
| 3045 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(";")); | |
| 3046 | then txt; | ||
| 3047 | |||
| 3048 | case ( txt, | ||
| 3049 | SimCodeFunction.EXTERNAL_FUNCTION(name = i_name, funArgs = i_funArgs, outVars = i_outVars) ) | ||
| 3050 | algorithm | ||
| 3051 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("static inline ")); | |
| 3052 | ✗ | txt_1 := CodegenUtil.underscorePath(Tpl.emptyTxt, i_name); | |
| 3053 | ✗ | (txt, txt_1) := functionPrototype(txt, txt_1, i_funArgs, i_outVars); | |
| 3054 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(";")); | |
| 3055 | then txt; | ||
| 3056 | |||
| 3057 | case ( txt, | ||
| 3058 | SimCodeFunction.RECORD_CONSTRUCTOR(name = _) ) | ||
| 3059 | algorithm | ||
| 3060 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 630, 57), "No records in embedded C yet"); | |
| 3061 | then txt; | ||
| 3062 | |||
| 3063 | case ( txt, | ||
| 3064 | SimCodeFunction.KERNEL_FUNCTION(name = _) ) | ||
| 3065 | algorithm | ||
| 3066 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 631, 57), "No kernel functions in embedded C"); | |
| 3067 | then txt; | ||
| 3068 | |||
| 3069 | case ( txt, | ||
| 3070 | _ ) | ||
| 3071 | then txt; | ||
| 3072 | end match; | ||
| 3073 | end functionDeclaration; | ||
| 3074 | |||
| 3075 | protected function lm_127 | ||
| 3076 | input output Tpl.Text txt; | ||
| 3077 | input list<DAE.Statement> items; | ||
| 3078 | algorithm | ||
| 3079 | ✗ | for lstElt_127 in items loop | |
| 3080 | txt := match lstElt_127 | ||
| 3081 | local | ||
| 3082 | DAE.Statement i_stmt; | ||
| 3083 | |||
| 3084 | case i_stmt | ||
| 3085 | algorithm | ||
| 3086 | ✗ | txt := statement(txt, i_stmt); | |
| 3087 | ✗ | txt := Tpl.nextIter(txt); | |
| 3088 | then txt; | ||
| 3089 | end match; | ||
| 3090 | end for; | ||
| 3091 | end lm_127; | ||
| 3092 | |||
| 3093 | protected function fun_128 | ||
| 3094 | input Tpl.Text in_txt; | ||
| 3095 | input list<SimCodeFunction.Variable> in_a_outVars; | ||
| 3096 | |||
| 3097 | output Tpl.Text out_txt; | ||
| 3098 | algorithm | ||
| 3099 | out_txt := | ||
| 3100 | match(in_txt, in_a_outVars) | ||
| 3101 | local | ||
| 3102 | Tpl.Text txt; | ||
| 3103 | SimCodeFunction.Variable i_v; | ||
| 3104 | |||
| 3105 | case ( txt, | ||
| 3106 | i_v :: _ ) | ||
| 3107 | algorithm | ||
| 3108 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("return ")); | |
| 3109 | ✗ | txt := varName(txt, i_v); | |
| 3110 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(";")); | |
| 3111 | then txt; | ||
| 3112 | |||
| 3113 | case ( txt, | ||
| 3114 | _ ) | ||
| 3115 | then txt; | ||
| 3116 | end match; | ||
| 3117 | end fun_128; | ||
| 3118 | |||
| 3119 | public function functionBodyRegularFunction | ||
| 3120 | input Tpl.Text in_txt; | ||
| 3121 | input SimCodeFunction.Function in_a_fn; | ||
| 3122 | |||
| 3123 | output Tpl.Text out_txt; | ||
| 3124 | algorithm | ||
| 3125 | out_txt := | ||
| 3126 | match(in_txt, in_a_fn) | ||
| 3127 | local | ||
| 3128 | Tpl.Text txt; | ||
| 3129 | list<DAE.Statement> i_body; | ||
| 3130 | list<SimCodeFunction.Variable> i_outVars; | ||
| 3131 | list<SimCodeFunction.Variable> i_functionArguments; | ||
| 3132 | Absyn.Path i_name; | ||
| 3133 | Tpl.Text l_bodyPart; | ||
| 3134 | Tpl.Text l_prototype; | ||
| 3135 | Tpl.Text l_fname; | ||
| 3136 | |||
| 3137 | case ( txt, | ||
| 3138 | SimCodeFunction.FUNCTION(name = i_name, functionArguments = i_functionArguments, outVars = i_outVars, body = i_body) ) | ||
| 3139 | algorithm | ||
| 3140 | ✗ | l_fname := CodegenUtil.underscorePath(Tpl.emptyTxt, i_name); | |
| 3141 | ✗ | (l_prototype, l_fname) := functionPrototype(Tpl.emptyTxt, l_fname, i_functionArguments, i_outVars); | |
| 3142 | ✗ | l_bodyPart := Tpl.pushIter(Tpl.emptyTxt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); | |
| 3143 | ✗ | l_bodyPart := lm_127(l_bodyPart, i_body); | |
| 3144 | ✗ | l_bodyPart := Tpl.popIter(l_bodyPart); | |
| 3145 | ✗ | txt := Tpl.writeText(txt, l_prototype); | |
| 3146 | ✗ | txt := Tpl.softNewLine(txt); | |
| 3147 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE("{\n")); | |
| 3148 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 3149 | ✗ | txt := Tpl.writeText(txt, l_bodyPart); | |
| 3150 | ✗ | txt := Tpl.softNewLine(txt); | |
| 3151 | ✗ | txt := fun_128(txt, i_outVars); | |
| 3152 | ✗ | txt := Tpl.softNewLine(txt); | |
| 3153 | ✗ | txt := Tpl.popBlock(txt); | |
| 3154 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("}")); | |
| 3155 | then txt; | ||
| 3156 | |||
| 3157 | case ( txt, | ||
| 3158 | _ ) | ||
| 3159 | then txt; | ||
| 3160 | end match; | ||
| 3161 | end functionBodyRegularFunction; | ||
| 3162 | |||
| 3163 | protected function lm_130 | ||
| 3164 | input output Tpl.Text txt; | ||
| 3165 | input list<SimCodeFunction.SimExtArg> items; | ||
| 3166 | algorithm | ||
| 3167 | ✗ | for lstElt_130 in items loop | |
| 3168 | txt := match lstElt_130 | ||
| 3169 | local | ||
| 3170 | SimCodeFunction.SimExtArg i_arg; | ||
| 3171 | |||
| 3172 | case i_arg | ||
| 3173 | algorithm | ||
| 3174 | ✗ | txt := extArg(txt, i_arg); | |
| 3175 | ✗ | txt := Tpl.nextIter(txt); | |
| 3176 | then txt; | ||
| 3177 | end match; | ||
| 3178 | end for; | ||
| 3179 | end lm_130; | ||
| 3180 | |||
| 3181 | protected function lm_131 | ||
| 3182 | input output Tpl.Text txt; | ||
| 3183 | input list<SimCodeFunction.Variable> items; | ||
| 3184 | algorithm | ||
| 3185 | ✗ | for lstElt_131 in items loop | |
| 3186 | txt := match lstElt_131 | ||
| 3187 | local | ||
| 3188 | SimCodeFunction.Variable i_arg; | ||
| 3189 | |||
| 3190 | case i_arg | ||
| 3191 | algorithm | ||
| 3192 | ✗ | txt := varType(txt, i_arg); | |
| 3193 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(" ")); | |
| 3194 | ✗ | txt := varName(txt, i_arg); | |
| 3195 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(";")); | |
| 3196 | ✗ | txt := Tpl.nextIter(txt); | |
| 3197 | then txt; | ||
| 3198 | end match; | ||
| 3199 | end for; | ||
| 3200 | end lm_131; | ||
| 3201 | |||
| 3202 | protected function fun_132 | ||
| 3203 | input Tpl.Text in_txt; | ||
| 3204 | input SimCodeFunction.SimExtArg in_a_extReturn; | ||
| 3205 | |||
| 3206 | output Tpl.Text out_txt; | ||
| 3207 | algorithm | ||
| 3208 | out_txt := | ||
| 3209 | match(in_txt, in_a_extReturn) | ||
| 3210 | local | ||
| 3211 | Tpl.Text txt; | ||
| 3212 | DAE.ComponentRef i_c; | ||
| 3213 | |||
| 3214 | case ( txt, | ||
| 3215 | SimCodeFunction.SIMEXTARG(cref = i_c) ) | ||
| 3216 | algorithm | ||
| 3217 | ✗ | txt := crefLocal(txt, i_c); | |
| 3218 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(" = ")); | |
| 3219 | then txt; | ||
| 3220 | |||
| 3221 | case ( txt, | ||
| 3222 | _ ) | ||
| 3223 | then txt; | ||
| 3224 | end match; | ||
| 3225 | end fun_132; | ||
| 3226 | |||
| 3227 | protected function fun_133 | ||
| 3228 | input Tpl.Text in_txt; | ||
| 3229 | input list<SimCodeFunction.Variable> in_a_outVars; | ||
| 3230 | |||
| 3231 | output Tpl.Text out_txt; | ||
| 3232 | algorithm | ||
| 3233 | out_txt := | ||
| 3234 | match(in_txt, in_a_outVars) | ||
| 3235 | local | ||
| 3236 | Tpl.Text txt; | ||
| 3237 | DAE.ComponentRef i_cref; | ||
| 3238 | |||
| 3239 | case ( txt, | ||
| 3240 | {} ) | ||
| 3241 | then txt; | ||
| 3242 | |||
| 3243 | case ( txt, | ||
| 3244 | SimCodeFunction.VARIABLE(name = i_cref) :: _ ) | ||
| 3245 | algorithm | ||
| 3246 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("return ")); | |
| 3247 | ✗ | txt := crefLocal(txt, i_cref); | |
| 3248 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(";")); | |
| 3249 | then txt; | ||
| 3250 | |||
| 3251 | case ( txt, | ||
| 3252 | _ ) | ||
| 3253 | algorithm | ||
| 3254 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 673, 16), "Not variable return"); | |
| 3255 | then txt; | ||
| 3256 | end match; | ||
| 3257 | end fun_133; | ||
| 3258 | |||
| 3259 | protected function lm_134 | ||
| 3260 | input output Tpl.Text txt; | ||
| 3261 | input list<SimCodeFunction.Variable> items; | ||
| 3262 | algorithm | ||
| 3263 | ✗ | for lstElt_134 in items loop | |
| 3264 | txt := match lstElt_134 | ||
| 3265 | local | ||
| 3266 | SimCodeFunction.Variable i_var; | ||
| 3267 | |||
| 3268 | case i_var | ||
| 3269 | algorithm | ||
| 3270 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("*out")); | |
| 3271 | ✗ | txt := varName(txt, i_var); | |
| 3272 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(" = ")); | |
| 3273 | ✗ | txt := varName(txt, i_var); | |
| 3274 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(";")); | |
| 3275 | then txt; | ||
| 3276 | end match; | ||
| 3277 | end for; | ||
| 3278 | end lm_134; | ||
| 3279 | |||
| 3280 | protected function fun_135 | ||
| 3281 | input Tpl.Text in_txt; | ||
| 3282 | input list<SimCodeFunction.Variable> in_a_outVars; | ||
| 3283 | |||
| 3284 | output Tpl.Text out_txt; | ||
| 3285 | algorithm | ||
| 3286 | out_txt := | ||
| 3287 | match(in_txt, in_a_outVars) | ||
| 3288 | local | ||
| 3289 | Tpl.Text txt; | ||
| 3290 | list<SimCodeFunction.Variable> i_outVars; | ||
| 3291 | list<SimCodeFunction.Variable> ret_0; | ||
| 3292 | |||
| 3293 | case ( txt, | ||
| 3294 | {} ) | ||
| 3295 | then txt; | ||
| 3296 | |||
| 3297 | case ( txt, | ||
| 3298 | i_outVars ) | ||
| 3299 | algorithm | ||
| 3300 | ✗ | ret_0 := listRest(i_outVars); | |
| 3301 | ✗ | txt := lm_134(txt, ret_0); | |
| 3302 | then txt; | ||
| 3303 | end match; | ||
| 3304 | end fun_135; | ||
| 3305 | |||
| 3306 | public function functionBodyExternalFunction | ||
| 3307 | input Tpl.Text in_txt; | ||
| 3308 | input SimCodeFunction.Function in_a_fn; | ||
| 3309 | |||
| 3310 | output Tpl.Text out_txt; | ||
| 3311 | algorithm | ||
| 3312 | out_txt := | ||
| 3313 | match(in_txt, in_a_fn) | ||
| 3314 | local | ||
| 3315 | Tpl.Text txt; | ||
| 3316 | String i_extName; | ||
| 3317 | SimCodeFunction.SimExtArg i_extReturn; | ||
| 3318 | list<SimCodeFunction.SimExtArg> i_extArgs; | ||
| 3319 | list<SimCodeFunction.Variable> i_outVars; | ||
| 3320 | list<SimCodeFunction.Variable> i_funArgs; | ||
| 3321 | Absyn.Path i_name; | ||
| 3322 | Tpl.Text l_varAssign; | ||
| 3323 | Tpl.Text l_returnStatement; | ||
| 3324 | Tpl.Text l_returnAssign; | ||
| 3325 | Tpl.Text l_varDecl; | ||
| 3326 | Tpl.Text l_args; | ||
| 3327 | Tpl.Text l_prototype; | ||
| 3328 | Tpl.Text l_fname; | ||
| 3329 | |||
| 3330 | case ( txt, | ||
| 3331 | SimCodeFunction.EXTERNAL_FUNCTION(language = "C", name = i_name, funArgs = i_funArgs, outVars = i_outVars, extArgs = i_extArgs, extReturn = i_extReturn, extName = i_extName) ) | ||
| 3332 | algorithm | ||
| 3333 | ✗ | l_fname := CodegenUtil.underscorePath(Tpl.emptyTxt, i_name); | |
| 3334 | ✗ | (l_prototype, l_fname) := functionPrototype(Tpl.emptyTxt, l_fname, i_funArgs, i_outVars); | |
| 3335 | ✗ | l_args := Tpl.pushIter(Tpl.emptyTxt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_STRING(", ")), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); | |
| 3336 | ✗ | l_args := lm_130(l_args, i_extArgs); | |
| 3337 | ✗ | l_args := Tpl.popIter(l_args); | |
| 3338 | ✗ | l_varDecl := Tpl.pushIter(Tpl.emptyTxt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); | |
| 3339 | ✗ | l_varDecl := lm_131(l_varDecl, i_outVars); | |
| 3340 | ✗ | l_varDecl := Tpl.popIter(l_varDecl); | |
| 3341 | ✗ | l_returnAssign := fun_132(Tpl.emptyTxt, i_extReturn); | |
| 3342 | ✗ | l_returnStatement := fun_133(Tpl.emptyTxt, i_outVars); | |
| 3343 | ✗ | l_varAssign := fun_135(Tpl.emptyTxt, i_outVars); | |
| 3344 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("static inline ")); | |
| 3345 | ✗ | txt := Tpl.writeText(txt, l_prototype); | |
| 3346 | ✗ | txt := Tpl.softNewLine(txt); | |
| 3347 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE("{\n")); | |
| 3348 | ✗ | txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); | |
| 3349 | ✗ | txt := Tpl.writeText(txt, l_varDecl); | |
| 3350 | ✗ | txt := Tpl.softNewLine(txt); | |
| 3351 | ✗ | txt := Tpl.writeText(txt, l_returnAssign); | |
| 3352 | ✗ | txt := Tpl.writeStr(txt, i_extName); | |
| 3353 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("(")); | |
| 3354 | ✗ | txt := Tpl.writeText(txt, l_args); | |
| 3355 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_LINE(");\n")); | |
| 3356 | ✗ | txt := Tpl.writeText(txt, l_varAssign); | |
| 3357 | ✗ | txt := Tpl.softNewLine(txt); | |
| 3358 | ✗ | txt := Tpl.writeText(txt, l_returnStatement); | |
| 3359 | ✗ | txt := Tpl.softNewLine(txt); | |
| 3360 | ✗ | txt := Tpl.popBlock(txt); | |
| 3361 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("}")); | |
| 3362 | then txt; | ||
| 3363 | |||
| 3364 | case ( txt, | ||
| 3365 | _ ) | ||
| 3366 | algorithm | ||
| 3367 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 685, 14), "Unknown external language"); | |
| 3368 | then txt; | ||
| 3369 | end match; | ||
| 3370 | end functionBodyExternalFunction; | ||
| 3371 | |||
| 3372 | public function extArg | ||
| 3373 | input Tpl.Text in_txt; | ||
| 3374 | input SimCodeFunction.SimExtArg in_a_extArg; | ||
| 3375 | |||
| 3376 | output Tpl.Text out_txt; | ||
| 3377 | algorithm | ||
| 3378 | out_txt := | ||
| 3379 | match(in_txt, in_a_extArg) | ||
| 3380 | local | ||
| 3381 | Tpl.Text txt; | ||
| 3382 | DAE.Exp i_exp; | ||
| 3383 | DAE.ComponentRef i_cref; | ||
| 3384 | |||
| 3385 | case ( txt, | ||
| 3386 | SimCodeFunction.SIMEXTARG(isInput = true, isArray = false, cref = i_cref) ) | ||
| 3387 | algorithm | ||
| 3388 | ✗ | txt := crefLocal(txt, i_cref); | |
| 3389 | then txt; | ||
| 3390 | |||
| 3391 | case ( txt, | ||
| 3392 | SimCodeFunction.SIMEXTARGEXP(type_ = DAE.T_REAL(varLst = _), exp = i_exp) ) | ||
| 3393 | algorithm | ||
| 3394 | ✗ | txt := daeExp(txt, i_exp); | |
| 3395 | then txt; | ||
| 3396 | |||
| 3397 | case ( txt, | ||
| 3398 | SimCodeFunction.SIMEXTARGEXP(type_ = DAE.T_INTEGER(varLst = _), exp = i_exp) ) | ||
| 3399 | algorithm | ||
| 3400 | ✗ | txt := daeExp(txt, i_exp); | |
| 3401 | then txt; | ||
| 3402 | |||
| 3403 | case ( txt, | ||
| 3404 | SimCodeFunction.SIMEXTARGEXP(type_ = DAE.T_STRING(varLst = _), exp = i_exp) ) | ||
| 3405 | algorithm | ||
| 3406 | ✗ | txt := daeExp(txt, i_exp); | |
| 3407 | then txt; | ||
| 3408 | |||
| 3409 | case ( txt, | ||
| 3410 | SimCodeFunction.SIMEXTARGEXP(type_ = DAE.T_BOOL(varLst = _), exp = i_exp) ) | ||
| 3411 | algorithm | ||
| 3412 | ✗ | txt := daeExp(txt, i_exp); | |
| 3413 | then txt; | ||
| 3414 | |||
| 3415 | case ( txt, | ||
| 3416 | _ ) | ||
| 3417 | algorithm | ||
| 3418 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 696, 14), "Unknown extArg"); | |
| 3419 | then txt; | ||
| 3420 | end match; | ||
| 3421 | end extArg; | ||
| 3422 | |||
| 3423 | protected function lm_138 | ||
| 3424 | input output Tpl.Text txt; | ||
| 3425 | input list<SimCodeFunction.Variable> items; | ||
| 3426 | algorithm | ||
| 3427 | ✗ | for lstElt_138 in items loop | |
| 3428 | txt := match lstElt_138 | ||
| 3429 | local | ||
| 3430 | SimCodeFunction.Variable i_var; | ||
| 3431 | |||
| 3432 | case i_var | ||
| 3433 | algorithm | ||
| 3434 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(", ")); | |
| 3435 | ✗ | txt := varType(txt, i_var); | |
| 3436 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(" ")); | |
| 3437 | ✗ | txt := varName(txt, i_var); | |
| 3438 | then txt; | ||
| 3439 | end match; | ||
| 3440 | end for; | ||
| 3441 | end lm_138; | ||
| 3442 | |||
| 3443 | protected function fun_139 | ||
| 3444 | input Tpl.Text in_txt; | ||
| 3445 | input SimCodeFunction.Variable in_a_var; | ||
| 3446 | |||
| 3447 | output Tpl.Text out_txt; | ||
| 3448 | algorithm | ||
| 3449 | out_txt := | ||
| 3450 | match(in_txt, in_a_var) | ||
| 3451 | local | ||
| 3452 | Tpl.Text txt; | ||
| 3453 | SimCodeFunction.Variable i_var; | ||
| 3454 | |||
| 3455 | case ( txt, | ||
| 3456 | (i_var as SimCodeFunction.VARIABLE(name = _)) ) | ||
| 3457 | algorithm | ||
| 3458 | ✗ | txt := varType(txt, i_var); | |
| 3459 | then txt; | ||
| 3460 | |||
| 3461 | case ( txt, | ||
| 3462 | _ ) | ||
| 3463 | algorithm | ||
| 3464 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 705, 18), "modelica_fnptr"); | |
| 3465 | then txt; | ||
| 3466 | end match; | ||
| 3467 | end fun_139; | ||
| 3468 | |||
| 3469 | protected function fun_140 | ||
| 3470 | input Tpl.Text in_txt; | ||
| 3471 | input list<SimCodeFunction.Variable> in_a_outVars; | ||
| 3472 | |||
| 3473 | output Tpl.Text out_txt; | ||
| 3474 | algorithm | ||
| 3475 | out_txt := | ||
| 3476 | match(in_txt, in_a_outVars) | ||
| 3477 | local | ||
| 3478 | Tpl.Text txt; | ||
| 3479 | SimCodeFunction.Variable i_var; | ||
| 3480 | |||
| 3481 | case ( txt, | ||
| 3482 | i_var :: _ ) | ||
| 3483 | algorithm | ||
| 3484 | ✗ | txt := fun_139(txt, i_var); | |
| 3485 | then txt; | ||
| 3486 | |||
| 3487 | case ( txt, | ||
| 3488 | _ ) | ||
| 3489 | algorithm | ||
| 3490 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("void")); | |
| 3491 | then txt; | ||
| 3492 | end match; | ||
| 3493 | end fun_140; | ||
| 3494 | |||
| 3495 | protected function lm_141 | ||
| 3496 | input output Tpl.Text txt; | ||
| 3497 | input list<SimCodeFunction.Variable> items; | ||
| 3498 | algorithm | ||
| 3499 | ✗ | for lstElt_141 in items loop | |
| 3500 | txt := match lstElt_141 | ||
| 3501 | local | ||
| 3502 | SimCodeFunction.Variable i_var; | ||
| 3503 | |||
| 3504 | case i_var | ||
| 3505 | algorithm | ||
| 3506 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(", ")); | |
| 3507 | ✗ | txt := varType(txt, i_var); | |
| 3508 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(" *out")); | |
| 3509 | ✗ | txt := varName(txt, i_var); | |
| 3510 | then txt; | ||
| 3511 | end match; | ||
| 3512 | end for; | ||
| 3513 | end lm_141; | ||
| 3514 | |||
| 3515 | protected function fun_142 | ||
| 3516 | input Tpl.Text in_txt; | ||
| 3517 | input list<SimCodeFunction.Variable> in_a_outVars; | ||
| 3518 | |||
| 3519 | output Tpl.Text out_txt; | ||
| 3520 | algorithm | ||
| 3521 | out_txt := | ||
| 3522 | match(in_txt, in_a_outVars) | ||
| 3523 | local | ||
| 3524 | Tpl.Text txt; | ||
| 3525 | list<SimCodeFunction.Variable> i_outVars; | ||
| 3526 | list<SimCodeFunction.Variable> ret_0; | ||
| 3527 | |||
| 3528 | case ( txt, | ||
| 3529 | {} ) | ||
| 3530 | then txt; | ||
| 3531 | |||
| 3532 | case ( txt, | ||
| 3533 | i_outVars ) | ||
| 3534 | algorithm | ||
| 3535 | ✗ | ret_0 := listRest(i_outVars); | |
| 3536 | ✗ | txt := lm_141(txt, ret_0); | |
| 3537 | then txt; | ||
| 3538 | end match; | ||
| 3539 | end fun_142; | ||
| 3540 | |||
| 3541 | public function functionPrototype | ||
| 3542 | input Tpl.Text txt; | ||
| 3543 | input Tpl.Text a_fname; | ||
| 3544 | input list<SimCodeFunction.Variable> a_fargs; | ||
| 3545 | input list<SimCodeFunction.Variable> a_outVars; | ||
| 3546 | |||
| 3547 | output Tpl.Text out_txt; | ||
| 3548 | output Tpl.Text out_a_fname; | ||
| 3549 | protected | ||
| 3550 | Tpl.Text l_outargs; | ||
| 3551 | Tpl.Text l_outarg; | ||
| 3552 | Tpl.Text l_fargsStr; | ||
| 3553 | algorithm | ||
| 3554 | ✗ | l_fargsStr := lm_138(Tpl.emptyTxt, a_fargs); | |
| 3555 | ✗ | l_outarg := fun_140(Tpl.emptyTxt, a_outVars); | |
| 3556 | ✗ | l_outargs := fun_142(Tpl.emptyTxt, a_outVars); | |
| 3557 | ✗ | out_txt := Tpl.writeText(txt, l_outarg); | |
| 3558 | ✗ | out_txt := Tpl.writeTok(out_txt, Tpl.ST_STRING(" ")); | |
| 3559 | ✗ | out_txt := Tpl.writeText(out_txt, a_fname); | |
| 3560 | ✗ | out_txt := Tpl.writeTok(out_txt, Tpl.ST_STRING("(fmi2Component comp")); | |
| 3561 | ✗ | out_txt := Tpl.writeText(out_txt, l_fargsStr); | |
| 3562 | ✗ | out_txt := Tpl.writeText(out_txt, l_outargs); | |
| 3563 | ✗ | out_txt := Tpl.writeTok(out_txt, Tpl.ST_STRING(")")); | |
| 3564 | out_a_fname := a_fname; | ||
| 3565 | end functionPrototype; | ||
| 3566 | |||
| 3567 | public function varName | ||
| 3568 | input Tpl.Text in_txt; | ||
| 3569 | input SimCodeFunction.Variable in_a_var; | ||
| 3570 | |||
| 3571 | output Tpl.Text out_txt; | ||
| 3572 | algorithm | ||
| 3573 | out_txt := | ||
| 3574 | match(in_txt, in_a_var) | ||
| 3575 | local | ||
| 3576 | Tpl.Text txt; | ||
| 3577 | DAE.ComponentRef i_name; | ||
| 3578 | |||
| 3579 | case ( txt, | ||
| 3580 | SimCodeFunction.VARIABLE(name = i_name) ) | ||
| 3581 | algorithm | ||
| 3582 | ✗ | txt := crefLocal(txt, i_name); | |
| 3583 | then txt; | ||
| 3584 | |||
| 3585 | case ( txt, | ||
| 3586 | _ ) | ||
| 3587 | algorithm | ||
| 3588 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 715, 14), "Not VARIABLE(__)"); | |
| 3589 | then txt; | ||
| 3590 | end match; | ||
| 3591 | end varName; | ||
| 3592 | |||
| 3593 | public function varType | ||
| 3594 | input Tpl.Text in_txt; | ||
| 3595 | input SimCodeFunction.Variable in_a_var; | ||
| 3596 | |||
| 3597 | output Tpl.Text out_txt; | ||
| 3598 | algorithm | ||
| 3599 | out_txt := | ||
| 3600 | match(in_txt, in_a_var) | ||
| 3601 | local | ||
| 3602 | Tpl.Text txt; | ||
| 3603 | DAE.Type i_ty; | ||
| 3604 | |||
| 3605 | case ( txt, | ||
| 3606 | SimCodeFunction.VARIABLE(ty = i_ty) ) | ||
| 3607 | algorithm | ||
| 3608 | ✗ | txt := expTypeShort(txt, i_ty); | |
| 3609 | then txt; | ||
| 3610 | |||
| 3611 | case ( txt, | ||
| 3612 | _ ) | ||
| 3613 | algorithm | ||
| 3614 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 722, 14), "Not VARIABLE(__)"); | |
| 3615 | then txt; | ||
| 3616 | end match; | ||
| 3617 | end varType; | ||
| 3618 | |||
| 3619 | public function literalExpConst | ||
| 3620 | input Tpl.Text in_txt; | ||
| 3621 | input DAE.Exp in_a_e; | ||
| 3622 | input Integer in_a_i0; | ||
| 3623 | |||
| 3624 | output Tpl.Text out_txt; | ||
| 3625 | algorithm | ||
| 3626 | out_txt := | ||
| 3627 | match(in_txt, in_a_e, in_a_i0) | ||
| 3628 | local | ||
| 3629 | Tpl.Text txt; | ||
| 3630 | Integer a_i0; | ||
| 3631 | DAE.Exp i_e; | ||
| 3632 | String i_string; | ||
| 3633 | Tpl.Text txt_1; | ||
| 3634 | String ret_0; | ||
| 3635 | |||
| 3636 | case ( txt, | ||
| 3637 | DAE.SCONST(string = i_string), | ||
| 3638 | a_i0 ) | ||
| 3639 | algorithm | ||
| 3640 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("static const char * const OMCLIT")); | |
| 3641 | ✗ | txt := Tpl.writeStr(txt, intString(a_i0)); | |
| 3642 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(" = \"")); | |
| 3643 | ✗ | ret_0 := Util.escapeModelicaStringToCString(i_string); | |
| 3644 | ✗ | txt := Tpl.writeStr(txt, ret_0); | |
| 3645 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("\";")); | |
| 3646 | then txt; | ||
| 3647 | |||
| 3648 | case ( txt, | ||
| 3649 | i_e, | ||
| 3650 | _ ) | ||
| 3651 | algorithm | ||
| 3652 | ✗ | txt_1 := Tpl.writeTok(Tpl.emptyTxt, Tpl.ST_STRING("Literal expression: ")); | |
| 3653 | ✗ | txt_1 := ExpressionDumpTpl.dumpExp(txt_1, i_e, "\""); | |
| 3654 | ✗ | txt := CodegenUtil.error(txt, Tpl.sourceInfo("CodegenEmbeddedC.tpl", 729, 14), Tpl.textString(txt_1)); | |
| 3655 | then txt; | ||
| 3656 | end match; | ||
| 3657 | end literalExpConst; | ||
| 3658 | |||
| 3659 | protected function lm_147 | ||
| 3660 | input output Tpl.Text txt; | ||
| 3661 | input list<SimCodeVar.SimVar> items; | ||
| 3662 | algorithm | ||
| 3663 | ✗ | for lstElt_147 in items loop | |
| 3664 | txt := match lstElt_147 | ||
| 3665 | local | ||
| 3666 | DAE.Exp i_exp; | ||
| 3667 | DAE.ComponentRef i_var_name; | ||
| 3668 | |||
| 3669 | case SimCodeVar.SIMVAR(initialValue = SOME(i_exp), name = i_var_name) | ||
| 3670 | algorithm | ||
| 3671 | ✗ | txt := cref(txt, i_var_name); | |
| 3672 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(" = ")); | |
| 3673 | ✗ | txt := daeExp(txt, i_exp); | |
| 3674 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(";")); | |
| 3675 | ✗ | txt := Tpl.nextIter(txt); | |
| 3676 | then txt; | ||
| 3677 | |||
| 3678 | case _ | ||
| 3679 | then txt; | ||
| 3680 | end match; | ||
| 3681 | end for; | ||
| 3682 | end lm_147; | ||
| 3683 | |||
| 3684 | public function callExternalObjectConstructors | ||
| 3685 | input Tpl.Text in_txt; | ||
| 3686 | input SimCode.ExtObjInfo in_a_extObjInfo; | ||
| 3687 | |||
| 3688 | output Tpl.Text out_txt; | ||
| 3689 | algorithm | ||
| 3690 | out_txt := | ||
| 3691 | match(in_txt, in_a_extObjInfo) | ||
| 3692 | local | ||
| 3693 | Tpl.Text txt; | ||
| 3694 | list<SimCodeVar.SimVar> i_vars; | ||
| 3695 | |||
| 3696 | case ( txt, | ||
| 3697 | SimCode.EXTOBJINFO(vars = i_vars) ) | ||
| 3698 | algorithm | ||
| 3699 | ✗ | txt := Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); | |
| 3700 | ✗ | txt := lm_147(txt, i_vars); | |
| 3701 | ✗ | txt := Tpl.popIter(txt); | |
| 3702 | then txt; | ||
| 3703 | |||
| 3704 | case ( txt, | ||
| 3705 | _ ) | ||
| 3706 | then txt; | ||
| 3707 | end match; | ||
| 3708 | end callExternalObjectConstructors; | ||
| 3709 | |||
| 3710 | protected function lm_149 | ||
| 3711 | input output Tpl.Text txt; | ||
| 3712 | input list<SimCodeVar.SimVar> items; | ||
| 3713 | algorithm | ||
| 3714 | ✗ | for lstElt_149 in items loop | |
| 3715 | txt := match lstElt_149 | ||
| 3716 | local | ||
| 3717 | DAE.ComponentRef i_var_name; | ||
| 3718 | Absyn.Path i_ext_fullClassName; | ||
| 3719 | |||
| 3720 | case SimCodeVar.SIMVAR(varKind = BackendDAE.EXTOBJ(fullClassName = i_ext_fullClassName), name = i_var_name) | ||
| 3721 | algorithm | ||
| 3722 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("omc_")); | |
| 3723 | ✗ | txt := CodegenUtil.underscorePath(txt, i_ext_fullClassName); | |
| 3724 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING("_destructor(threadData,")); | |
| 3725 | ✗ | txt := cref(txt, i_var_name); | |
| 3726 | ✗ | txt := Tpl.writeTok(txt, Tpl.ST_STRING(");")); | |
| 3727 | ✗ | txt := Tpl.nextIter(txt); | |
| 3728 | then txt; | ||
| 3729 | |||
| 3730 | case _ | ||
| 3731 | then txt; | ||
| 3732 | end match; | ||
| 3733 | end for; | ||
| 3734 | end lm_149; | ||
| 3735 | |||
| 3736 | public function callExternalObjectDestructors | ||
| 3737 | input Tpl.Text in_txt; | ||
| 3738 | input SimCode.ExtObjInfo in_a_extObjInfo; | ||
| 3739 | |||
| 3740 | output Tpl.Text out_txt; | ||
| 3741 | algorithm | ||
| 3742 | out_txt := | ||
| 3743 | match(in_txt, in_a_extObjInfo) | ||
| 3744 | local | ||
| 3745 | Tpl.Text txt; | ||
| 3746 | list<SimCodeVar.SimVar> i_vars; | ||
| 3747 | |||
| 3748 | case ( txt, | ||
| 3749 | SimCode.EXTOBJINFO(vars = i_vars) ) | ||
| 3750 | algorithm | ||
| 3751 | ✗ | txt := Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); | |
| 3752 | ✗ | txt := lm_149(txt, i_vars); | |
| 3753 | ✗ | txt := Tpl.popIter(txt); | |
| 3754 | then txt; | ||
| 3755 | |||
| 3756 | case ( txt, | ||
| 3757 | _ ) | ||
| 3758 | then txt; | ||
| 3759 | end match; | ||
| 3760 | end callExternalObjectDestructors; | ||
| 3761 | |||
| 3762 | annotation(__OpenModelica_Interface="codegen"); | ||
| 3763 | end CodegenEmbeddedC; | ||
| 3764 |