Skip to content

Commit

Permalink
- Extracted extra record declarations from uniontypes
Browse files Browse the repository at this point in the history
- Extracted libraries (arrays of libraries) from annotations
- Generated external type for meta types


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5193 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Rickard Lindberg committed Mar 24, 2010
1 parent c3d58ee commit 7e00010
Show file tree
Hide file tree
Showing 6 changed files with 1,517 additions and 1,268 deletions.
7 changes: 4 additions & 3 deletions Compiler/CevalScript.mo
Expand Up @@ -4111,8 +4111,9 @@ algorithm
pathstr = generateFunctionName(path);
Debug.fprintln("ceval", "/*- CevalScript.cevalGenerateFunction starting " +& pathstr +& " */");
(cache,dae as DAE.DAE(d,_),_) = cevalGenerateFunctionDAEs(cache, path, env, {});
//uniontypePaths = Codegen.getUniontypePaths(d);
//(cache,metarecordTypes) = Lookup.lookupMetarecordsRecursive(cache, env, uniontypePaths, {});

uniontypePaths = Codegen.getUniontypePaths(d);
(cache,metarecordTypes) = Lookup.lookupMetarecordsRecursive(cache, env, uniontypePaths, {});

cfilename = stringAppend(pathstr, ".c");
//Print.clearBuf();
Expand All @@ -4137,7 +4138,7 @@ algorithm
//" $(LDFLAGS)",
//" ",libsstr," -lm \n"});
//System.writeFile(makefilename, str);
SimCode.translateFunctions(pathstr, d);
SimCode.translateFunctions(pathstr, d, metarecordTypes);
compileModel(pathstr, {}, "", "");
then
(cache, pathstr);
Expand Down
80 changes: 73 additions & 7 deletions Compiler/SimCode.mo
Expand Up @@ -122,6 +122,7 @@ uniontype FunctionCode
String name;
list<Function> functions;
MakefileParams makefileParams;
list<RecordDeclaration> extraRecordDecls;
end FUNCTIONCODE;
end FunctionCode;

Expand Down Expand Up @@ -524,21 +525,23 @@ public function translateFunctions
"One of the entry points."
input String name;
input list<DAE.Element> daeElements;
input list<DAE.Type> metarecordTypes;
algorithm
_ :=
matchcontinue (name, daeElements)
matchcontinue (name, daeElements, metarecordTypes)
local
list<Function> fns;
list<String> libs;
MakefileParams makefileParams;
FunctionCode fnCode;
case (name, daeElements)
list<RecordDeclaration> extraRecordDecls;
case (name, daeElements, metarecordTypes)
equation
// Create FunctionCode
fns = elaborateFunctions(daeElements);
(fns, extraRecordDecls) = elaborateFunctions(daeElements, metarecordTypes);
libs = extractLibs(fns);
makefileParams = createMakefileParams(libs);
fnCode = FUNCTIONCODE(name, fns, makefileParams);
fnCode = FUNCTIONCODE(name, fns, makefileParams, extraRecordDecls);
// Generate code
_ = Tpl.tplString(SimCodeC.translateFunctions, fnCode);
then
Expand Down Expand Up @@ -585,7 +588,7 @@ algorithm
//libs1 = {};
//usless filter, all are already functions from generateFunctions2
//funcelems := Util.listFilter(funcelems, DAEUtil.isFunction);
fns = elaborateFunctions(funcelems);
(fns, _) = elaborateFunctions(funcelems, {}); // Do we need metarecords here as well?
//TODO: libs ? see in Codegen.cPrintFunctionIncludes(cfns)
libs2 = extractLibs(fns);
then
Expand Down Expand Up @@ -659,12 +662,16 @@ end generateExternalObjectInclude;

protected function elaborateFunctions
input list<DAE.Element> daeElements;
input list<DAE.Type> metarecordTypes;
output list<Function> functions;
output list<RecordDeclaration> extraRecordDecls;
protected
list<Function> fns;
list<String> outRecordTypes;
algorithm
(fns, _) := elaborateFunctions2(daeElements, {},{});
(fns, outRecordTypes) := elaborateFunctions2(daeElements, {},{});
functions := listReverse(fns); // Is there a reason why we reverse here?
(extraRecordDecls,_) := elaborateRecordDeclarationsFromTypes(metarecordTypes, {}, outRecordTypes);
end elaborateFunctions;

protected function elaborateFunctions2
Expand Down Expand Up @@ -1348,6 +1355,31 @@ algorithm
end matchcontinue;
end extractLibs;

protected function elaborateRecordDeclarationsFromTypes
input list<DAE.Type> inTypes;
input list<RecordDeclaration> inAccRecordDecls;
input list<String> inReturnTypes;
output list<RecordDeclaration> outRecordDecls;
output list<String> outReturnTypes;
algorithm
(outRecordDecls, outReturnTypes) :=
matchcontinue (inTypes, inAccRecordDecls, inReturnTypes)
local
list<RecordDeclaration> accRecDecls;
DAE.Type firstType;
list<DAE.Type> restTypes;
case ({}, accRecDecls, inReturnTypes)
then (accRecDecls, inReturnTypes);
case (firstType :: restTypes, accRecDecls, inReturnTypes)
equation
(accRecDecls, inReturnTypes) =
elaborateRecordDeclarationsForRecord(firstType, accRecDecls, inReturnTypes);
(accRecDecls, inReturnTypes) =
elaborateRecordDeclarationsFromTypes(restTypes, accRecDecls, inReturnTypes);
then (accRecDecls, inReturnTypes);
end matchcontinue;
end elaborateRecordDeclarationsFromTypes;

protected function elaborateRecordDeclarations
"function elaborateRecordDeclarations
Translate all records used by varlist to structs."
Expand Down Expand Up @@ -1430,13 +1462,40 @@ algorithm
then (accRecDecls,rt_2);
case ((DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(name), complexVarLst = varlst),_), accRecDecls, rt)
then (accRecDecls,rt);
case ((DAE.T_METARECORD(fields = varlst), SOME(path)), accRecDecls, rt)
local String sname;
equation
sname = ModUtil.pathStringReplaceDot(path, "_");
failure(_ = Util.listGetMember(sname,rt));

fieldNames = Util.listMap(varlst, generateVarName);

accRecDecls = RECORD_DECL_DEF(path, fieldNames) :: accRecDecls;
rt_1 = sname::rt;

(accRecDecls,rt_2) = elaborateNestedRecordDeclarations(varlst, accRecDecls, rt_1);
then (accRecDecls,rt_2);
case ((_,_), accRecDecls, rt)
then (accRecDecls,rt);
case ((_,_), accRecDecls, rt) then
(RECORD_DECL_FULL("#an odd record#", Absyn.IDENT("?noname?"), {}) :: accRecDecls ,rt);
end matchcontinue;
end elaborateRecordDeclarationsForRecord;

protected function generateVarName
input DAE.Var inVar;
output String outName;
algorithm
outName :=
matchcontinue (inVar)
local
DAE.Ident name;
case DAE.TYPES_VAR(name = name)
then name;
case (_)
then "NULL";
end matchcontinue;
end generateVarName;

protected function elaborateNestedRecordDeclarations
"function elaborateNestedRecordDeclarations
Expand Down Expand Up @@ -5957,12 +6016,19 @@ algorithm
local
String lib;
list<Absyn.ElementArg> eltarg;
list<Absyn.Exp> arr;
case (eltarg)
equation
Absyn.CLASSMOD(_,SOME(Absyn.STRING(lib))) =
Interactive.getModificationValue(eltarg, Absyn.CREF_IDENT("Library",{})) "System.stringReplace(lib,\"\\\"\",\"\"\") => lib\'" ;
Interactive.getModificationValue(eltarg, Absyn.CREF_IDENT("Library",{}));
then
{lib};
case (eltarg)
equation
Absyn.CLASSMOD(_,SOME(Absyn.ARRAY(arr))) =
Interactive.getModificationValue(eltarg, Absyn.CREF_IDENT("Library",{}));
then
Util.listMap(arr, Absyn.expString);
case (_) then {};
end matchcontinue;
end generateExtFunctionIncludesLibstr;
Expand Down

0 comments on commit 7e00010

Please sign in to comment.