Skip to content

Commit fdd8b23

Browse files
committed
Some fixes for separate compilation
- Make sure all package are marked encapsulated since otherwise it does not work - Moved generation of literals to the body instead of the header (they have to be there since we want to include headers from other files) git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16372 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 2db502c commit fdd8b23

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

Compiler/BackEnd/MathematicaDump.mo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package MathematicaDump "Copyright (C) MathCore Engineering AB, 2005 "
1+
encapsulated package MathematicaDump "Copyright (C) MathCore Engineering AB, 2005 "
22

33
import BackendDAE;
44
import BackendVariable;
@@ -23,7 +23,7 @@ algorithm
2323
local
2424
BackendDAE.Variables vars,knvars;
2525
list<BackendDAE.Equation> eqns,ieqns;
26-
String allVarStr,s1_1,s1_2,s1_3,s1_4,s1_5,s3,s4,res;
26+
String allVarStr,s1_1,s1_2,s1_3,s1_4,s1_5,s3,s4;
2727
list<String> params,inputs,states,algs,outputs,inputsStates;
2828
case((vars,knvars,eqns,ieqns)) equation
2929

@@ -793,7 +793,7 @@ algorithm
793793
(params, inputs) := match(knvars)
794794
local
795795
list<BackendDAE.Var> varLst;
796-
case(knvars) equation
796+
case _ equation
797797
varLst = BackendVariable.varList(knvars);
798798
params = List.map(varLst,printMmaParamStr);
799799
inputs = List.map(varLst,printMmaInputStr);

Compiler/BackEnd/Uncertainties.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package Uncertainties
1+
encapsulated package Uncertainties
22

33
import DAE;
44
import Absyn;

Compiler/Script/CevalScript.mo

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4556,7 +4556,7 @@ protected function generateFunctions
45564556
input list<tuple<String,list<String>>> iacc;
45574557
output list<tuple<String,list<String>>> deps;
45584558
algorithm
4559-
deps := match (icache,ienv,p,isp,iacc)
4559+
deps := matchcontinue (icache,ienv,p,isp,iacc)
45604560
local
45614561
String name;
45624562
list<String> names,dependencies;
@@ -4568,14 +4568,14 @@ algorithm
45684568
list<SCode.Element> sp;
45694569
Env.Cache cache;
45704570
Env.Env env;
4571+
String file;
4572+
Integer n;
4573+
Absyn.Info info;
45714574

45724575
case (cache,env,_,{},acc) then acc;
4573-
case (cache,env,_,SCode.CLASS(name="OpenModelica")::sp,acc)
4574-
equation
4575-
acc = generateFunctions(cache,env,p,sp,acc);
4576-
then acc;
4577-
case (cache,env,_,SCode.CLASS(name=name,encapsulatedPrefix=SCode.ENCAPSULATED(),restriction=SCode.R_PACKAGE(),classDef=SCode.PARTS(elementLst=elementLst))::sp,acc)
4576+
case (cache,env,_,SCode.CLASS(name=name,encapsulatedPrefix=SCode.ENCAPSULATED(),restriction=SCode.R_PACKAGE(),classDef=SCode.PARTS(elementLst=elementLst),info=info as Absyn.INFO(fileName=file))::sp,acc)
45784577
equation
4578+
(0,_) = System.regex(file, "ModelicaBuiltin.mo$", 1, false, false);
45794579
names = List.map(List.filterOnTrue(List.map(List.filterOnTrue(elementLst, SCode.elementIsClass), SCode.getElementClass), SCode.isFunction), SCode.className);
45804580
paths = List.map1r(names,Absyn.makeQualifiedPathFromStrings,name);
45814581
cache = instantiateDaeFunctions(cache, env, paths);
@@ -4589,11 +4589,13 @@ algorithm
45894589
SimCodeMain.translateFunctions(p, name, NONE(), d, {}, dependencies);
45904590
acc = generateFunctions(cache,env,p,sp,acc);
45914591
then acc;
4592-
case (cache,env,_,_::sp,acc)
4592+
case (cache,env,_,SCode.CLASS(name=name,info=info as Absyn.INFO(fileName=file))::sp,acc)
45934593
equation
4594+
(n,_) = System.regex(file, "ModelicaBuiltin.mo$", 1, false, false);
4595+
Error.assertion(n > 0, "Not an encapsulated class (required for separate compilation): " +& name, info);
45944596
acc = generateFunctions(cache,env,p,sp,acc);
45954597
then acc;
4596-
end match;
4598+
end matchcontinue;
45974599
end generateFunctions;
45984600

45994601
protected function matchQualifiedCalls

Compiler/Template/CodegenC.tpl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ template translateFunctions(FunctionCode functionCode)
9494
case FUNCTIONCODE(__) then
9595
let filePrefix = name
9696
let _= (if mainFunction then textFile(functionsMakefile(functionCode), '<%filePrefix%>.makefile'))
97-
let()= textFile(functionsHeaderFile(filePrefix, mainFunction, functions, extraRecordDecls, externalFunctionIncludes, literals), '<%filePrefix%>.h')
98-
let()= textFile(functionsFile(filePrefix, mainFunction, functions), '<%filePrefix%>.c')
97+
let()= textFile(functionsHeaderFile(filePrefix, mainFunction, functions, extraRecordDecls, externalFunctionIncludes), '<%filePrefix%>.h')
98+
let()= textFile(functionsFile(filePrefix, mainFunction, functions, literals), '<%filePrefix%>.c')
9999
let()= textFile(recordsFile(filePrefix, extraRecordDecls), '<%filePrefix%>_records.c')
100100
// If ParModelica generate the kernels file too.
101101
if acceptParModelicaGrammar() then
@@ -3275,11 +3275,15 @@ end commonHeader;
32753275

32763276
template functionsFile(String filePrefix,
32773277
Option<Function> mainFunction,
3278-
list<Function> functions)
3278+
list<Function> functions,
3279+
list<Exp> literals)
32793280
"Generates the contents of the main C file for the function case."
32803281
::=
32813282
<<
32823283
#include "<%filePrefix%>.h"
3284+
<% /* Note: The literals may not be part of the header due to separate compilation */
3285+
literals |> literal hasindex i0 fromindex 0 => literalExpConst(literal,i0) ; separator="\n";empty
3286+
%>
32833287
#include "modelica.h"
32843288
void (*omc_assert)(FILE_INFO info,const char *msg,...) = omc_assert_function;
32853289
void (*omc_assert_warning)(FILE_INFO info,const char *msg,...) = omc_assert_warning_function;
@@ -3296,8 +3300,7 @@ template functionsHeaderFile(String filePrefix,
32963300
Option<Function> mainFunction,
32973301
list<Function> functions,
32983302
list<RecordDeclaration> extraRecordDecls,
3299-
list<String> includes,
3300-
list<Exp> literals)
3303+
list<String> includes)
33013304
"Generates the contents of the main C file for the function case."
33023305
::=
33033306
<<
@@ -3313,8 +3316,6 @@ template functionsHeaderFile(String filePrefix,
33133316
<%functionHeaders(functions)%>
33143317
<%externalFunctionIncludes(includes)%>
33153318
3316-
<%literals |> literal hasindex i0 fromindex 0 => literalExpConst(literal,i0) ; separator="\n";empty%>
3317-
33183319
#ifdef __cplusplus
33193320
}
33203321
#endif

configure.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ AC_SUBST(LIBSIMULATION)
5959
AC_SUBST(LIBRUNTIME)
6060
AC_SUBST(LIBFMIRUNTIME)
6161
AC_SUBST(SHREXT)
62+
AC_SUBST(LINK)
6263

6364
FINAL_MESSAGES="\nConfigured OpenModelica successfully using the following options:"
6465

@@ -653,6 +654,7 @@ if test "Darwin" = `uname`; then
653654
LIBRUNTIME=libOpenModelicaRuntimeC.a
654655
LIBFMIRUNTIME=libOpenModelicaFMIRuntimeC.a
655656
RT_LDFLAGS="$RT_LDFLAGS -liconv -lgc $OPENMP"
657+
LINK="cp -fr"
656658
else
657659
EXE=""
658660
SHREXT=".so"
@@ -661,6 +663,7 @@ else
661663
LIBRUNTIME=libOpenModelicaRuntimeC.so
662664
LIBFMIRUNTIME=libOpenModelicaFMIRuntimeC.a
663665
RT_LDFLAGS="$RT_LDFLAGS -lrt -lgc $OPENMP"
666+
LINK="cp -frl"
664667
fi
665668

666669
dnl should we compile modpar

0 commit comments

Comments
 (0)