Skip to content

Commit 9403273

Browse files
authored
CMake improvments (#6896)
@mahge Add missing susan template target. b5b4271 - This was working because the normal OpenModelica compilation generated the mo file from the tpl file. The CMake compilation was just picking that one and never complained. @mahge [cmake] Generate OpenModelicaScriptingAPI.mo 64eed1d - This was missing. CMake compilation worked only because the normal OpenModelica compilation generated this file. The CMake compilation was just picking up that file and never complained. @mahge [cmake] Move Dynload_omc.cpp to omcruntime lib. 423c76e - It was in omcbackendruntime. It seems like it "belongs" in omcruntime. @mahge [cmake] Remove omparse-boot. 2f1a1f4 - It is not needed. We are trying a different approach for bootstrapping @mahge Move some scripting API functions to CevalScript. e215985 - This were in CevalScriptBackend.mo before. The reason they were in there was that the original plan for bootstrapping with the CMake config was to not use the bootstrap tarball. Instead the plan was to use the latest C source files of the MetaModelica sources that passed the CI run. This meant these scripting api functions were not technically needed for the 'normal bootstrapping' so they could be in the "backend" interface. However, bootstrapping just changed. And the tarball(and related nuances) are mostly gone. So at this point it is worth to take the same source files that the normal bootstrapping uses since they are already available within the repo. @mahge Add boot folder to cmake configuration/compilation f5ffb54 @mahge A quick support for generating config.unix.h. 4aae339 @mahge Add boot libraries and use them for bootstrapping. 4795955 - Added omparse-boot - Added omcruntime-boot - Added omcgraphstream-boot All of this can probably be avoided if OpenModelciaBootstrapping header is added to version control and updated with the bootstrapping sources. For now I am going to do it this way since this is how the 'normal' bootstrapping works. @mahge Use OpenModelicaBootstrappingHeader.h from tarball 03ebe58 - Use OpenModelicaBootstrappingHeader.h from tarball-include for now. It would be nice if it is also added to source control just like the C bootstrapping source files. Otherwise it might actually break. If we add it to source control we can also remove the boot libraries like omparse-boot, omcruntime-boot .... @mahge Add generation of Util/Autoconf.mo 6714810 - This adds a quick and ugly generation of Autoconf.mo from Autoconf.mo.in (linux) or from (copy only) Autoconf.mo.omdev.mingw (windows) - The generation code is added in Compiler/runtime/CMakeLists because we have a few variables already defiend in there for generation of config.unix.h. This should probably be moved outside to some higher directory. @mahge Add (incomplete) generation of c/RuntimeSources.mo 7079cf4 - This just a quick way to enable bootstrapping. The contents of the file are not really complete and can not be expected to be used for simulation yet. But that is the case for many other things regarding simulation executable compilation. There is some work needed to handle that. @mahge Update 3rdParty submodule. 36ecba5 - The changes from the branch are merged to master on 3rdParty. Submodule head is updated now.
1 parent f62cc7f commit 9403273

File tree

198 files changed

+2980
-2267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+2980
-2267
lines changed

OMCompiler/Compiler/.cmake/template_compilation.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ omc_add_template_target(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/susan_codegen/TplCode
298298

299299

300300

301-
# omc_add_template_target(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/Template/CodegenModelica.tpl
302-
# DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Template/GraphvizDump.tpl)
301+
omc_add_template_target(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/Template/CodegenModelica.tpl)
303302

304303

OMCompiler/Compiler/CMakeLists.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11

22
omc_add_subdirectory(runtime)
3+
omc_add_subdirectory(boot)
34

45

5-
set(OMC_EXE ${PROJECT_SOURCE_DIR}/../build/bin/omc)
6+
# set(OMC_EXE ${PROJECT_SOURCE_DIR}/../build/bin/omc)
7+
set(OMC_EXE $<TARGET_FILE:bomc>)
68

79
# list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/.cmake")
810
# enable_language(MODELICA)
@@ -99,6 +101,23 @@ endmacro(add_compile_step)
99101

100102

101103

104+
add_custom_command(
105+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Script/OpenModelicaScriptingAPI.mos
106+
${CMAKE_CURRENT_SOURCE_DIR}/FrontEnd/ModelicaBuiltin.mo
107+
108+
# We want to generate OpenModelicaScriptingAPI.mo in scripts folder. Since the script
109+
# generates it in the current working directory we go there. Later we can fix the script to
110+
# take a path or change the MM source list to pick up the generated OpenModelicaScriptingAPI.mo
111+
# from <build_dir>/Compiler.
112+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Script
113+
114+
COMMAND ${OMC_EXE} -g=MetaModelica -n=1 ${CMAKE_CURRENT_SOURCE_DIR}/Script/OpenModelicaScriptingAPI.mos
115+
116+
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/Script/OpenModelicaScriptingAPI.mo
117+
COMMENT "Generating ${CMAKE_CURRENT_SOURCE_DIR}/Script/OpenModelicaScriptingAPI.mo using ${CMAKE_CURRENT_SOURCE_DIR}/Script/OpenModelicaScriptingAPI.mos"
118+
)
119+
120+
102121

103122

104123

OMCompiler/Compiler/Script/CevalScript.mo

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,26 @@ algorithm
11591159
then
11601160
v;
11611161

1162+
case ("getImportedNames",{Values.CODE(Absyn.C_TYPENAME(path))})
1163+
algorithm
1164+
(vals, cvars) := getImportedNames(Interactive.getPathedClassInProgram(path, SymbolTable.getAbsyn()));
1165+
v := Values.TUPLE({ValuesUtil.makeArray(vals),ValuesUtil.makeArray(cvars)});
1166+
then
1167+
v;
1168+
1169+
case ("getImportedNames",_)
1170+
then (Values.TUPLE({ValuesUtil.makeArray({}),ValuesUtil.makeArray({})}));
1171+
1172+
case ("getMMfileTotalDependencies",{Values.STRING(str1), Values.STRING(str2)})
1173+
algorithm
1174+
strs := getMMfileTotalDependencies(str1, str2);
1175+
vals := list(Values.STRING(s) for s in strs);
1176+
then
1177+
ValuesUtil.makeArray(vals);
1178+
1179+
case ("getMMfileTotalDependencies",_)
1180+
then ValuesUtil.makeArray({});
1181+
11621182
case ("loadModel",{Values.CODE(Absyn.C_TYPENAME(path)),Values.ARRAY(valueLst=cvars),Values.BOOL(b),Values.STRING(str),Values.BOOL(requireExactVersion)})
11631183
algorithm
11641184
p := SymbolTable.getAbsyn();
@@ -3228,5 +3248,160 @@ algorithm
32283248
end matchcontinue;
32293249
end generateSeparateCode;
32303250

3251+
3252+
public function getImportedNames
3253+
input Absyn.Class inClass;
3254+
output list<Values.Value> outPublicImports;
3255+
output list<Values.Value> outProtectedImports;
3256+
protected
3257+
String ident;
3258+
list<Absyn.Import> pub_imports_list , pro_imports_list;
3259+
algorithm
3260+
(pub_imports_list , pro_imports_list) := getImportList(inClass);
3261+
3262+
outPublicImports := {};
3263+
for imp in pub_imports_list loop
3264+
ident := AbsynUtil.pathFirstIdent(AbsynUtil.importPath(imp));
3265+
if ident <> "MetaModelica" then
3266+
outPublicImports := Values.STRING(ident)::outPublicImports;
3267+
end if;
3268+
end for;
3269+
3270+
outProtectedImports := {};
3271+
for imp in pro_imports_list loop
3272+
ident := AbsynUtil.pathFirstIdent(AbsynUtil.importPath(imp));
3273+
if ident <> "MetaModelica" then
3274+
outProtectedImports := Values.STRING(ident)::outProtectedImports;
3275+
end if;
3276+
end for;
3277+
end getImportedNames;
3278+
3279+
public function getImportList
3280+
"Counts the number of Import sections in a class."
3281+
input Absyn.Class inClass;
3282+
input output list<Absyn.Import> pub_imports_list = {};
3283+
input output list<Absyn.Import> pro_imports_list = {};
3284+
algorithm
3285+
() := match (inClass)
3286+
local
3287+
list<Absyn.ClassPart> parts;
3288+
3289+
case Absyn.CLASS(body = Absyn.PARTS(classParts = parts)) algorithm
3290+
for part in parts loop
3291+
(pub_imports_list, pro_imports_list) := getImportsInClassPart(part, pub_imports_list, pro_imports_list);
3292+
end for;
3293+
then ();
3294+
3295+
// check also the case model extends X end X;
3296+
case Absyn.CLASS(body = Absyn.CLASS_EXTENDS(parts = parts)) algorithm
3297+
for part in parts loop
3298+
(pub_imports_list, pro_imports_list) := getImportsInClassPart(part, pub_imports_list, pro_imports_list);
3299+
end for;
3300+
then ();
3301+
3302+
case Absyn.CLASS(body = Absyn.DERIVED()) then ();
3303+
end match;
3304+
end getImportList;
3305+
3306+
protected function getImportsInClassPart
3307+
input Absyn.ClassPart inAbsynClassPart;
3308+
input output list<Absyn.Import> pub_imports_list;
3309+
input output list<Absyn.Import> pro_imports_list;
3310+
algorithm
3311+
() := matchcontinue (inAbsynClassPart)
3312+
local
3313+
list<Absyn.ElementItem> els;
3314+
case Absyn.PUBLIC(contents = els) algorithm
3315+
for elem in els loop
3316+
pub_imports_list := getImportsInElementItem(elem, pub_imports_list);
3317+
end for;
3318+
then ();
3319+
3320+
case Absyn.PROTECTED(contents = els) algorithm
3321+
for elem in els loop
3322+
pro_imports_list := getImportsInElementItem(elem, pro_imports_list);
3323+
end for;
3324+
then ();
3325+
3326+
else ();
3327+
3328+
end matchcontinue;
3329+
end getImportsInClassPart;
3330+
3331+
protected function getImportsInElementItem
3332+
"Helper function to getImportCount"
3333+
input Absyn.ElementItem inAbsynElementItem;
3334+
input output list<Absyn.Import> imports_list;
3335+
algorithm
3336+
() := matchcontinue inAbsynElementItem
3337+
local
3338+
Absyn.Import import_;
3339+
Absyn.Class class_;
3340+
3341+
case Absyn.ELEMENTITEM(element = Absyn.ELEMENT(specification = Absyn.IMPORT(import_ = import_)))
3342+
algorithm
3343+
imports_list := import_::imports_list;
3344+
then ();
3345+
3346+
case Absyn.ELEMENTITEM(element = Absyn.ELEMENT(specification = Absyn.CLASSDEF(class_ = class_)))
3347+
algorithm
3348+
// imports_list := getImportList(class_, get_protected, imports_list);
3349+
then ();
3350+
3351+
else ();
3352+
end matchcontinue;
3353+
end getImportsInElementItem;
3354+
3355+
protected function getMMfileTotalDependencies
3356+
input String in_package_name;
3357+
input String public_imports_dir;
3358+
output list<String> total_pub_imports = {};
3359+
protected
3360+
Absyn.Class package_class;
3361+
list<Absyn.Import> pub_imports_list , pro_imports_list;
3362+
String imp_ident;
3363+
algorithm
3364+
package_class := Interactive.getPathedClassInProgram(Absyn.IDENT(in_package_name), SymbolTable.getAbsyn());
3365+
3366+
(pub_imports_list , pro_imports_list) := getImportList(package_class);
3367+
3368+
for imp in pub_imports_list loop
3369+
imp_ident := AbsynUtil.pathFirstIdent(AbsynUtil.importPath(imp));
3370+
if imp_ident <> "MetaModelica" then
3371+
total_pub_imports := getMMfilePublicDependencies(imp_ident, public_imports_dir, total_pub_imports);
3372+
end if;
3373+
end for;
3374+
3375+
for imp in pro_imports_list loop
3376+
imp_ident := AbsynUtil.pathFirstIdent(AbsynUtil.importPath(imp));
3377+
if imp_ident <> "MetaModelica" then
3378+
total_pub_imports := getMMfilePublicDependencies(imp_ident, public_imports_dir, total_pub_imports);
3379+
end if;
3380+
end for;
3381+
3382+
end getMMfileTotalDependencies;
3383+
3384+
protected function getMMfilePublicDependencies
3385+
input String in_package_name;
3386+
input String public_imports_dir;
3387+
input output list<String> packages;
3388+
protected
3389+
String dep_public_imports_file, pub_imports_total;
3390+
algorithm
3391+
if listMember(in_package_name, packages) then
3392+
return;
3393+
end if;
3394+
3395+
packages := in_package_name::packages;
3396+
3397+
dep_public_imports_file := public_imports_dir + "/" + in_package_name + ".public.imports";
3398+
pub_imports_total := System.readFile(dep_public_imports_file);
3399+
3400+
for pub_imp in System.strtok(pub_imports_total, ";") loop
3401+
packages := getMMfilePublicDependencies(pub_imp, public_imports_dir, packages);
3402+
end for;
3403+
3404+
end getMMfilePublicDependencies;
3405+
32313406
annotation(__OpenModelica_Interface="backend");
32323407
end CevalScript;

0 commit comments

Comments
 (0)