Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 0.0% 0 / 0 / 2
Functions: -% 0 / 0 / 0
Branches: -% 0 / 0 / 0

OMCompiler/Compiler/Template/CodegenFMUCppHpcom.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 CodegenFMUCppHpcom
82
83
84
85 import interface SimCodeBackendTV;
86 import interface SimCodeTV;
87 import CodegenFMUCpp.*;
88 import CodegenCppHpcom.*;
89 import CodegenUtil;
90 import CodegenCpp;
91 import CodegenCppInit;
92
93 ✗ template translateModel(SimCode simCode, String FMUVersion, String FMUType)
94 "Generates C++ code and Makefile for compiling an FMU of a Modelica model.
95 Calls CodegenCpp.translateModel for the actual model code."
96 ::=
97 match simCode
98 case SIMCODE(modelInfo = MODELINFO(__), makefileParams = MAKEFILE_PARAMS(__), hpcomData = HPCOMDATA(__)) then
99 let guid = getUUIDStr()
100 let target = simulationCodeTarget()
101 let stateDerVectorName = "__zDot"
102 let &extraFuncs = buffer "" /*BUFD*/
103 let &extraFuncsDecl = buffer "" /*BUFD*/
104 let &complexStartExpressions = buffer ""
105
106 let className = CodegenCpp.lastIdentOfPath(modelInfo.name)
107 let numRealVars = numRealvarsHpcom(modelInfo, hpcomData.hpcOmMemory)
108 let numIntVars = numIntvarsHpcom(modelInfo, hpcomData.hpcOmMemory)
109 let numBoolVars = numBoolvarsHpcom(modelInfo, hpcomData.hpcOmMemory)
110 let numStringVars = numStringvarsHpcom(modelInfo, hpcomData.hpcOmMemory)
111 let numPreVars = numPreVarsHpcom(modelInfo, hpcomData.hpcOmMemory)
112
113 let()= textFile(CodegenCppInit.modelInitXMLFile(simCode, numRealVars, numIntVars, numBoolVars, numStringVars, FMUVersion, FMUType, guid, true, "hpcom cpp-runtime", complexStartExpressions, stateDerVectorName), 'modelDescription.xml')
114 let cpp = CodegenCpp.translateModel(simCode)
115 let()= textFile(fmuWriteOutputHeaderFile(simCode , &extraFuncs , &extraFuncsDecl, ""),'OMCpp<%fileNamePrefix%>WriteOutput.h')
116 let()= textFile(fmuModelHeaderFile(simCode, extraFuncs, extraFuncsDecl, "",guid, FMUVersion), 'OMCpp<%fileNamePrefix%>FMU.h')
117 let()= textFile(fmuModelCppFile(simCode, extraFuncs, extraFuncsDecl, "",guid, FMUVersion), 'OMCpp<%fileNamePrefix%>FMU.cpp')
118 //let()= textFile(modelInitXMLFile(simCode, numRealVars, numIntVars, numBoolVars, true, FMUVersion, FMUType, guid), '')
119 // Def file is only used on windows, to define exported symbols
120 //let()= textFile(fmudeffile(simCode, FMUVersion), '<%fileNamePrefix%>.def')
121 let()= textFile(fmuMakefile(target,simCode, extraFuncs, extraFuncsDecl, "", FMUVersion), '<%fileNamePrefix%>_FMU.makefile')
122 let()= textFile(fmuCalcHelperMainfile(simCode), 'OMCpp<%fileNamePrefix%>CalcHelperMain.cpp')
123
124 let() = textFile(CodegenCpp.simulationCppFile(simCode, contextOther, updateHpcom(allEquations, simCode, &extraFuncs, &extraFuncsDecl, "", contextOther, stateDerVectorName, false),
125 '<%numRealVars%>-1', '<%numIntVars%>-1', '<%numBoolVars%>-1', '<%numStringVars%>-1', &extraFuncs, &extraFuncsDecl, className,
126 additionalHpcomConstructorDefinitions(hpcomData.schedules),
127 additionalHpcomConstructorBodyStatements(hpcomData.schedules, className, CodegenUtil.dotPath(modelInfo.name)),
128 additionalHpcomDestructorBodyStatements(hpcomData.schedules),
129 stateDerVectorName, false), 'OMCpp<%fileNamePrefix%>.cpp')
130
131 let() = textFile(CodegenCpp.simulationHeaderFile(simCode ,contextOther, &extraFuncs, &extraFuncsDecl, "",
132 additionalHpcomIncludes(simCode, &extraFuncs, &extraFuncsDecl, className, false),
133 "",
134 additionalHpcomProtectedMemberDeclaration(simCode, &extraFuncs, &extraFuncsDecl, "", false),
135 CodegenCpp.memberVariableDefine(modelInfo, varToArrayIndexMapping, '<%numRealVars%>-1', '<%numIntVars%>-1', '<%numBoolVars%>-1', '<%numStringVars%>-1', Flags.isSet(Flags.GEN_DEBUG_SYMBOLS), false),
136 false), 'OMCpp<%fileNamePrefix%>.h')
137 ""
138 // empty result of the top-level template .., only side effects
139 end match
140 end translateModel;
141
142 ✗ template fmuMakefile(String target, SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace, String FMUVersion)
143 ::=
144 let type = getConfigString(HPCOM_CODE)
145
146 let &additionalCFlags_GCC = buffer ""
147 let &additionalCFlags_MSVC = buffer ""
148 let &additionalLinkerFlags_GCC = buffer ""
149 let &additionalLinkerFlags_MSVC = buffer ""
150
151 let &additionalLinkerFlags_GCC += if boolOr(stringEq(type,"pthreads"), stringEq(type,"pthreads_spin")) then " -lpthread" else ""
152
153 <<
154 <%CodegenCppHpcom.getAdditionalMakefileFlags(additionalCFlags_GCC, additionalCFlags_MSVC, additionalLinkerFlags_GCC, additionalLinkerFlags_MSVC)%>
155 <%CodegenFMUCpp.fmuMakefile(target, simCode, extraFuncs, extraFuncsDecl, extraFuncsNamespace, FMUVersion, additionalLinkerFlags_GCC, additionalLinkerFlags_MSVC, additionalCFlags_GCC, additionalCFlags_MSVC, "")%>
156 >>
157 end fmuMakefile;
158
159 annotation(__OpenModelica_Interface="codegen_cpp_ext");
160 end CodegenFMUCppHpcom;
161
162 // vim: filetype=susan sw=2 sts=2
163