OMCompiler/Compiler/Template/CodegenFMU1.tpl
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of OpenModelica. | ||
| 3 | * | ||
| 4 | * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), | ||
| 5 | * c/o Linköpings universitet, Department of Computer and Information Science, | ||
| 6 | * SE-58183 Linköping, Sweden. | ||
| 7 | * | ||
| 8 | * All rights reserved. | ||
| 9 | * | ||
| 10 | * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR | ||
| 11 | * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. | ||
| 12 | * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES | ||
| 13 | * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL | ||
| 14 | * VERSION 3, ACCORDING TO RECIPIENTS CHOICE. | ||
| 15 | * | ||
| 16 | * The OpenModelica software and the OSMC (Open Source Modelica Consortium) | ||
| 17 | * Public License (OSMC-PL) are obtained from OSMC, either from the above | ||
| 18 | * address, from the URLs: | ||
| 19 | * http://www.openmodelica.org or | ||
| 20 | * https://github.com/OpenModelica/ or | ||
| 21 | * http://www.ida.liu.se/projects/OpenModelica, | ||
| 22 | * and in the OpenModelica distribution. | ||
| 23 | * | ||
| 24 | * GNU AGPL version 3 is obtained from: | ||
| 25 | * https://www.gnu.org/licenses/licenses.html#GPL | ||
| 26 | * | ||
| 27 | * This program is distributed WITHOUT ANY WARRANTY; without | ||
| 28 | * even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 29 | * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH | ||
| 30 | * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. | ||
| 31 | * | ||
| 32 | * See the full OSMC Public License conditions for more details. | ||
| 33 | * | ||
| 34 | */ | ||
| 35 | |||
| 36 | // This file defines templates for transforming Modelica/MetaModelica code to FMU | ||
| 37 | // code. They are used in the code generator phase of the compiler to write | ||
| 38 | // target code. | ||
| 39 | // | ||
| 40 | // There are one root template intended to be called from the code generator: | ||
| 41 | // translateModel. These template do not return any | ||
| 42 | // result but instead write the result to files. All other templates return | ||
| 43 | // text and are used by the root templates (most of them indirectly). | ||
| 44 | // | ||
| 45 | // To future maintainers of this file: | ||
| 46 | // | ||
| 47 | // - A line like this | ||
| 48 | // # var = "" /*BUFD*/ | ||
| 49 | // declares a text buffer that you can later append text to. It can also be | ||
| 50 | // passed to other templates that in turn can append text to it. In the new | ||
| 51 | // version of Susan it should be written like this instead: | ||
| 52 | // let &var = buffer "" | ||
| 53 | // | ||
| 54 | // - A line like this | ||
| 55 | // ..., Text var /*BUFP*/, ... | ||
| 56 | // declares that a template takes a text buffer as input parameter. In the | ||
| 57 | // new version of Susan it should be written like this instead: | ||
| 58 | // ..., Text &var, ... | ||
| 59 | // | ||
| 60 | // - A line like this: | ||
| 61 | // ..., var /*BUFC*/, ... | ||
| 62 | // passes a text buffer to a template. In the new version of Susan it should | ||
| 63 | // be written like this instead: | ||
| 64 | // ..., &var, ... | ||
| 65 | // | ||
| 66 | // - Style guidelines: | ||
| 67 | // | ||
| 68 | // - Try (hard) to limit each row to 80 characters | ||
| 69 | // | ||
| 70 | // - Code for a template should be indented with 2 spaces | ||
| 71 | // | ||
| 72 | // - Exception to this rule is if you have only a single case, then that | ||
| 73 | // single case can be written using no indentation | ||
| 74 | // | ||
| 75 | // This single case can be seen as a clarification of the input to the | ||
| 76 | // template | ||
| 77 | // | ||
| 78 | // - Code after a case should be indented with 2 spaces if not written on the | ||
| 79 | // same line | ||
| 80 | |||
| 81 | package CodegenFMU1 | ||
| 82 | |||
| 83 | import interface SimCodeTV; | ||
| 84 | import interface SimCodeBackendTV; | ||
| 85 | import CodegenUtil.*; | ||
| 86 | import CodegenUtilSimulation.*; | ||
| 87 | import CodegenFMUCommon.*; | ||
| 88 | |||
| 89 | // Code for generating modelDescription.xml file for FMI 1.0 ModelExchange. | ||
| 90 | 2 | template fmiModelDescription(SimCode simCode, String guid, String FMUType) | |
| 91 | "Generates code for ModelDescription file for FMU target." | ||
| 92 | ::= | ||
| 93 | // <%UnitDefinitions(simCode)%> | ||
| 94 | // <%VendorAnnotations(simCode)%> | ||
| 95 | match simCode | ||
| 96 | case SIMCODE(__) then | ||
| 97 | << | ||
| 98 | <fmiModelDescription | ||
| 99 | <%fmiModelDescriptionAttributes(simCode,guid)%>> | ||
| 100 | <%fmiTypeDefinitions(simCode, "1.0")%> | ||
| 101 | <%DefaultExperiment(simulationSettingsOpt, "1.0")%> | ||
| 102 | <%fmiModelVariables(simCode, "1.0")%> | ||
| 103 | <%if isFMICSType(FMUType) then Implementation()%> | ||
| 104 | </fmiModelDescription> | ||
| 105 | >> | ||
| 106 | end fmiModelDescription; | ||
| 107 | |||
| 108 | 2 | template fmiModelDescriptionAttributes(SimCode simCode, String guid) | |
| 109 | "Generates code for ModelDescription file for FMU target." | ||
| 110 | ::= | ||
| 111 | match simCode | ||
| 112 | case SIMCODE(modelInfo = MODELINFO(varInfo = vi as VARINFO(__), vars = SIMVARS(stateVars = listStates))) then | ||
| 113 | let fmiVersion = '1.0' | ||
| 114 | let modelName = dotPath(modelInfo.name) | ||
| 115 | let modelIdentifier = modelNamePrefix(simCode) | ||
| 116 | let description = modelInfo.description | ||
| 117 | let generationTool= 'OpenModelica Compiler <%getVersionNr()%>' | ||
| 118 | let generationDateAndTime = xsdateTime(Util.getCurrentDateTime()) | ||
| 119 | let variableNamingConvention = 'structured' | ||
| 120 | let numberOfContinuousStates = if intEq(vi.numStateVars,1) then statesnumwithDummy(listStates) else vi.numStateVars | ||
| 121 | let numberOfEventIndicators = getNumberOfEventIndicators(simCode) | ||
| 122 | << | ||
| 123 | fmiVersion="<%fmiVersion%>" | ||
| 124 | modelName="<%Util.escapeModelicaStringToXmlString(modelName)%>" | ||
| 125 | modelIdentifier="<%Util.escapeModelicaStringToXmlString(modelIdentifier)%>" | ||
| 126 | guid="{<%guid%>}" | ||
| 127 | description="<%Util.escapeModelicaStringToXmlString(description)%>" | ||
| 128 | generationTool="<%Util.escapeModelicaStringToXmlString(generationTool)%>" | ||
| 129 | generationDateAndTime="<%generationDateAndTime%>" | ||
| 130 | variableNamingConvention="<%variableNamingConvention%>" | ||
| 131 | numberOfContinuousStates="<%numberOfContinuousStates%>" | ||
| 132 | numberOfEventIndicators="<%numberOfEventIndicators%>" | ||
| 133 | >> | ||
| 134 | end fmiModelDescriptionAttributes; | ||
| 135 | |||
| 136 | annotation(__OpenModelica_Interface="codegen_fmu"); | ||
| 137 | end CodegenFMU1; | ||
| 138 | |||
| 139 | // vim: filetype=susan sw=2 sts=2 | ||
| 140 |