Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Added support for LibraryDirectory and IncludeDirectory
  - The paths search are the default ones according to the Modelica specifiction, plus mingw32 on Windows and uname -sm | tr "[A-Z] " "[a-z]-" for other OS'es


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8426 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Mar 31, 2011
1 parent 41441b7 commit 34063dc
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 28 deletions.
99 changes: 87 additions & 12 deletions Compiler/BackEnd/SimCode.mo
Expand Up @@ -1601,11 +1601,12 @@ algorithm
local
Option<Absyn.Annotation> ann1,ann2;
list<String> includes1,libs1,includes2,libs2;
case (BackendDAE.EXTOBJCLASS(constructor=DAE.FUNCTION(functions={DAE.FUNCTION_EXT(externalDecl=DAE.EXTERNALDECL(ann=ann1))}),
Absyn.Path fpath;
case (BackendDAE.EXTOBJCLASS(path = fpath,constructor=DAE.FUNCTION(functions={DAE.FUNCTION_EXT(externalDecl=DAE.EXTERNALDECL(ann=ann1))}),
destructor=DAE.FUNCTION(functions={DAE.FUNCTION_EXT(externalDecl=DAE.EXTERNALDECL(ann=ann2))})))
equation
(includes1,libs1) = generateExtFunctionIncludes(ann1);
(includes2,libs2) = generateExtFunctionIncludes(ann2);
(includes1,libs1) = generateExtFunctionIncludes(fpath,ann1);
(includes2,libs2) = generateExtFunctionIncludes(fpath,ann2);
includes = Util.listListUnion({includes1, includes2});
libs = Util.listListUnion({libs1, libs2});
then (includes,libs);
Expand Down Expand Up @@ -1751,7 +1752,7 @@ algorithm
inVars = Util.listMap(DAEUtil.getInputVars(daeElts), daeInOutSimVar);
biVars = Util.listMap(DAEUtil.getBidirVars(daeElts), daeInOutSimVar);
(recordDecls,rt_1) = elaborateRecordDeclarations(daeElts, recordDecls, rt);
(fn_includes, fn_libs) = generateExtFunctionIncludes(ann);
(fn_includes, fn_libs) = generateExtFunctionIncludes(fpath,ann);
includes = Util.listUnion(fn_includes, includes);
libs = Util.listUnion(fn_libs, libs);
simextargs = Util.listMap(extargs, extArgsToSimExtArgs);
Expand Down Expand Up @@ -9053,24 +9054,98 @@ protected function generateExtFunctionIncludes
"function: generateExtFunctionIncludes
Collects the includes and libs for an external function
by investigating the annotation of an external function."
input Absyn.Path path;
input Option<Absyn.Annotation> inAbsynAnnotationOption;
output list<String> includes;
output list<String> libs;
algorithm
(includes,libs):=
match (inAbsynAnnotationOption)
match (path,inAbsynAnnotationOption)
local
list<Absyn.ElementArg> eltarg;
case (SOME(Absyn.ANNOTATION(eltarg)))
case (path,SOME(Absyn.ANNOTATION(eltarg)))
equation
libs = generateExtFunctionIncludesLibstr(eltarg);
includes = generateExtFunctionIncludesIncludestr(eltarg);
libs = generateExtFunctionLibraryDirectoryFlags(path,eltarg,libs);
libs = generateExtFunctionIncludeDirectoryFlags(path,eltarg,includes,libs);
then
(includes,libs);
case (NONE()) then ({},{});
case (_,NONE()) then ({},{});
end match;
end generateExtFunctionIncludes;

protected function generateExtFunctionIncludeDirectoryFlags
"Process LibraryDirectory and IncludeDirectory"
input Absyn.Path path;
input list<Absyn.ElementArg> eltarg;
input list<String> includes;
input list<String> libs;
output list<String> outLibs;
algorithm
outLibs := matchcontinue (path,eltarg,includes,libs)
local
String str;
case (_,eltarg,{},libs) then libs;
case (_,eltarg,_,libs)
equation
Absyn.CLASSMOD(eqMod=Absyn.EQMOD(exp=Absyn.STRING(str))) =
Interactive.getModificationValue(eltarg, Absyn.CREF_IDENT("IncludeDirectory",{}));
str = CevalScript.getFullPathFromUri(str);
str = "\"-I"+&str+&"\"";
// Yes, we have to append lists here so they appear in the correct order in the Makefile...
libs = listAppend(libs,{str});
then libs;
case (path,_,_,libs)
equation
str = "modelica://" +& Absyn.pathString(path) +& "/Resources/Include";
str = CevalScript.getFullPathFromUri(str);
str = "\"-I"+&str+&"\"";
// Yes, we have to append lists here so they appear in the correct order in the Makefile...
libs = listAppend(libs,{str});
then libs;
else libs;
end matchcontinue;
end generateExtFunctionIncludeDirectoryFlags;

protected function generateExtFunctionLibraryDirectoryFlags
"Process LibraryDirectory and IncludeDirectory"
input Absyn.Path path;
input list<Absyn.ElementArg> eltarg;
input list<String> libs;
output list<String> outLibs;
algorithm
outLibs := matchcontinue (path,eltarg,libs)
local
String str,str1,str2,str3,platform1,platform2;
case (_,eltarg,{}) then {};
case (_,eltarg,libs)
equation
Absyn.CLASSMOD(eqMod=Absyn.EQMOD(exp=Absyn.STRING(str))) =
Interactive.getModificationValue(eltarg, Absyn.CREF_IDENT("LibraryDirectory",{}));
str = CevalScript.getFullPathFromUri(str);
platform1 = System.openModelicaPlatform();
platform2 = System.modelicaPlatform();
str1 = Util.if_(platform1 ==& "", "", "\"-L" +& str +& "/" +& platform1 +& "\"");
str2 = Util.if_(platform2 ==& "", "", "\"-L" +& str +& "/" +& platform2 +& "\"");
str3 ="\"-L" +& str +& "\"";
libs = str1::str2::str3::libs;
then libs;
case (path,_,libs)
equation
str = "modelica://" +& Absyn.pathString(path) +& "/Resources/Library";
str = CevalScript.getFullPathFromUri(str);
platform1 = System.openModelicaPlatform();
platform2 = System.modelicaPlatform();
str1 = Util.if_(platform1 ==& "", "", "\"-L" +& str +& "/" +& platform1 +& "\"");
str2 = Util.if_(platform2 ==& "", "", "\"-L" +& str +& "/" +& platform2 +& "\"");
str3 ="\"-L" +& str +& "\"";
libs = str1::str2::str3::libs;
then libs;
else libs;
end matchcontinue;
end generateExtFunctionLibraryDirectoryFlags;

protected function getLibraryStringInGccFormat
"Takes an Absyn.STRING describing a library and outputs a list
of strings corresponding to it.
Expand Down Expand Up @@ -10809,8 +10884,8 @@ protected function setStatesVectorIndex "
sorts the states in the state vector correponding to the variable index (0,1,2) and
sets the vectorindex attribute for each state variable in the states vector(z)
e.g der(x)=y
der(y)=a
der(z)=a -> z={z,x,y}
der(y)=a
der(z)=a -> z={z,x,y}
"
input list<SimVar> in_vars;
output list<SimVar> out_vars;
Expand Down Expand Up @@ -10869,9 +10944,9 @@ end setStatesVectorIndex2;
protected function partitionStatesVector "
partitioning the input vector into 3 state vectors including variables with corresponding variable indexes 0,1,2
e.g der(x) = y;
der(y)= a;
der(z) =a;
z=b -> output: {z} {x} {y}
der(y)= a;
der(z) =a;
z=b -> output: {z} {x} {y}
"
input list<SimVar> in_vars "list with unsorted state variables";
output list<SimVar> oder_0;
Expand Down
58 changes: 52 additions & 6 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -1696,8 +1696,7 @@ algorithm

case (cache,env,"uriToFilename",{Values.STRING(str)},st,msg)
equation
(str1,str2,str3) = System.uriToClassAndPath(str);
str = getBasePathFromUri(str1,str2,Settings.getModelicaPath()) +& str3;
str = getFullPathFromUri(str);
then (cache,Values.STRING(str),st);

case (cache,env,"uriToFilename",_,st,msg)
Expand Down Expand Up @@ -3707,12 +3706,10 @@ algorithm
String gd,mp,bp,str;
case ("modelica://",name,mp)
equation
name::names = System.strtok(name,".");
names = System.strtok(name,".");
gd = System.groupDelimiter();
mps = System.strtok(mp, gd);
mps = Util.listMap1(mps,stringAppend,"/" +& name);
bp = Util.listSelectFirst(mps,System.directoryExists);
bp = stringAppendList(Util.listMap1(bp::names,stringAppend,"/"));
bp = findModelicaPath(mps,names);
then bp;
case ("file://",_,_) then "";
case ("modelica://",name,mp)
Expand All @@ -3724,4 +3721,53 @@ algorithm
end matchcontinue;
end getBasePathFromUri;

protected function findModelicaPath "Handle modelica:// URIs"
input list<String> mps;
input list<String> names;
output String basePath;
algorithm
basePath := matchcontinue (mps,names)
local
String mp;
case (mp::_,names)
then findModelicaPath2(mp,names,false);
case (_::mps,names)
then findModelicaPath(mps,names);
end matchcontinue;
end findModelicaPath;

protected function findModelicaPath2 "Handle modelica:// URIs"
input String mp;
input list<String> names;
input Boolean b;
output String basePath;
algorithm
basePath := matchcontinue (mp,names,b)
local
list<String> mps,names;
String gd,mp,bp,str,name;
case (mp,name::names,_)
equation
true = System.directoryExists(mp +& "/" +& name);
then findModelicaPath2(mp,names,true);
case (mp,name::names,_)
equation
true = System.regularFileExists(mp +& "/" +& name +& ".mo");
then mp;
// This class is part of the current package.mo, or whatever...
case (mp,name::names,true)
then mp;
end matchcontinue;
end findModelicaPath2;

public function getFullPathFromUri
input String uri;
output String path;
protected
String str1,str2,str3;
algorithm
(str1,str2,str3) := System.uriToClassAndPath(uri);
path := getBasePathFromUri(str1,str2,Settings.getModelicaPath()) +& str3;
end getFullPathFromUri;

end CevalScript;
19 changes: 19 additions & 0 deletions Compiler/Util/System.mo
Expand Up @@ -772,4 +772,23 @@ public function uriToClassAndPath "Handles modelica:// and file:// URI's. The re
external "C" System_uriToClassAndPath(uri,scheme,classname,pathname) annotation(Library = "omcruntime");
end uriToClassAndPath;

public function modelicaPlatform "Returns the standardized platform name according to the Modelica specification:
win32 [Microsoft Windows 32 bit]
win64 [Microsoft Windows 64 bit]
linux32 [Linux Intel 32 bit]
linux64 [Linux Intel 64 bit]
Else, the empty string is returned
"
output String platform;
external "C" System_modelicaPlatform() annotation(Library = "omcruntime");
end modelicaPlatform;

public function openModelicaPlatform "
Returns uname -sm (with spaces replaced by dashes and only lower-case letters) on Unix platforms
mingw32 is returned for OMDEV
"
output String platform;
external "C" System_openModelicaPlatform() annotation(Library = "omcruntime");
end openModelicaPlatform;

end System;
16 changes: 14 additions & 2 deletions Compiler/runtime/System_omc.cpp
Expand Up @@ -565,9 +565,21 @@ double System_getTimerCummulatedTime()
return timerCummulatedTime;
}

extern int System_uriToClassAndPath(const char *uri, const char **scheme, char **name, char **path)
extern void System_uriToClassAndPath(const char *uri, const char **scheme, char **name, char **path)
{
return SystemImpl__uriToClassAndPath(uri, scheme, name, path);
int res = SystemImpl__uriToClassAndPath(uri, scheme, name, path);
// TODO: Fix memory leak by using the external interface
if (res) MMC_THROW();
}

extern const char* System_modelicaPlatform()
{
return CONFIG_MODELICA_SPEC_PLATFORM;
}

extern const char* System_openModelicaPlatform()
{
return CONFIG_OPENMODELICA_SPEC_PLATFORM;
}

}
14 changes: 14 additions & 0 deletions Compiler/runtime/System_rml.c
Expand Up @@ -1961,6 +1961,7 @@ RML_BEGIN_LABEL(System__intMaxLit)
rmlA0 = mk_icon(LONG_MAX / 2);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__uriToClassAndPath)
{
Expand All @@ -1976,5 +1977,18 @@ RML_BEGIN_LABEL(System__uriToClassAndPath)
RML_TAILCALLK(rmlFC);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__modelicaPlatform)
{
rmlA0 = mk_scon(CONFIG_MODELICA_SPEC_PLATFORM);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__openModelicaPlatform)
{
rmlA0 = mk_scon(CONFIG_OPENMODELICA_SPEC_PLATFORM);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
2 changes: 2 additions & 0 deletions Compiler/runtime/config.h
Expand Up @@ -39,6 +39,8 @@
#define DEFAULT_LDFLAGS "-lc_runtime -lregex"

#define CONFIG_PLATFORM "WIN32"
#define CONFIG_MODELICA_SPEC_PLATFORM "win32"
#define CONFIG_OPENMODELICA_SPEC_PLATFORM "mingw32"
#define CONFIG_USER_IS_ROOT 0

#define CONFIG_DEFAULT_OPENMODELICAHOME NULL
Expand Down
2 changes: 2 additions & 0 deletions Compiler/runtime/config.unix.h.in
Expand Up @@ -5,6 +5,8 @@
#define CONFIG_EXE_EXT ""
#define CONFIG_DLL_EXT ".so"
#define CONFIG_PLATFORM "Unix"
#define CONFIG_MODELICA_SPEC_PLATFORM "@MODELICA_SPEC_PLATFORM@"
#define CONFIG_OPENMODELICA_SPEC_PLATFORM "@OPENMODELICA_SPEC_PLATFORM@"

#if defined(__sparc__)
#define DEFAULT_LINKER "g++ -G"
Expand Down
8 changes: 0 additions & 8 deletions Compiler/susan_codegen/SimCode/Makefile
Expand Up @@ -7,14 +7,6 @@ all : SimCodeC.mo SimCodeCSharp.mo SimCodeFMU.mo Unparsing.mo SimCodeQSS.mo SimC



SimCodeQSS.mo : SimCodeQSS.tpl SimCodeTV.mo
@echo " ** SimCodeC template compilation ** "
$(OMC) $< > $@.log || (cat $@.log && false)
cp -pf $@ ../../Template/
@echo " "



SimCodeC.mo : SimCodeC.tpl SimCodeTV.mo
@echo " ** SimCodeC template compilation ** "
$(OMC) $< > $@.log || (cat $@.log && false)
Expand Down
19 changes: 19 additions & 0 deletions configure
Expand Up @@ -609,6 +609,8 @@ CPPFLAGS
LDFLAGS
CFLAGS
CC
OPENMODELICA_SPEC_PLATFORM
MODELICA_SPEC_PLATFORM
OMSHELL_TERMINAL
LIBF2C
SOURCE_REVISION
Expand Down Expand Up @@ -2211,6 +2213,8 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu








Expand Down Expand Up @@ -4959,6 +4963,21 @@ test -z "$SOURCE_REVISION" && SOURCE_REVISION="????"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $SOURCE_REVISION" >&5
$as_echo "$SOURCE_REVISION" >&6; }

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for OpenModelica platform name" >&5
$as_echo_n "checking for OpenModelica platform name... " >&6; }
# I don't really agree with the Modelica specification since "Intel 32-bit" is
# very unspecific.
# Also, they forgot about Mac users. We will just default to uname -sm and patch
# to Modelica Spec standards as well.
OPENMODELICA_SPEC_PLATFORM=`uname -sm | tr "[:upper:] " "[:lower:]-"`
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $OPENMODELICA_SPEC_PLATFORM" >&5
$as_echo "$OPENMODELICA_SPEC_PLATFORM" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Modelica platform name" >&5
$as_echo_n "checking for Modelica platform name... " >&6; }
if test "$OPENMODELICA_SPEC_PLATFORM" = "linux-x86_64" -o "$OPENMODELICA_SPEC_PLATFORM" = "linux-i.86"; then MODELICA_SPEC_PLATFORM=`echo $OPENMODELICA_SPEC_PLATFORM | sed "s/linux-x86_64/linux64/" | sed "s/linux-i.86/linux32/"`; fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MODELICA_SPEC_PLATFORM" >&5
$as_echo "$MODELICA_SPEC_PLATFORM" >&6; }

date=`date "+%Y-%m-%d %H:%M:%S"`

GENERATED_AUTOCONF_FILES="Makefile c_runtime/Makefile mosh/src/Makefile \
Expand Down

0 comments on commit 34063dc

Please sign in to comment.