Skip to content

Commit

Permalink
- fix non-separate bootstrapping compilation (MainTest.mos)
Browse files Browse the repository at this point in the history
- beautify the C code a bit

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18106 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Nov 13, 2013
1 parent 32fc4ff commit 394cca5
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Compiler/BackEnd/SimCode.mo
Expand Up @@ -328,15 +328,18 @@ uniontype Function
end Function;

uniontype RecordDeclaration

record RECORD_DECL_FULL
String name "struct (record) name ? encoded";
Absyn.Path defPath "definition path";
list<Variable> variables "only name and type";
end RECORD_DECL_FULL;

record RECORD_DECL_DEF
Absyn.Path path "definition path .. encoded?";
list<String> fieldNames;
end RECORD_DECL_DEF;

end RecordDeclaration;

uniontype SimExtArg
Expand Down
70 changes: 70 additions & 0 deletions Compiler/BackEnd/SimCodeMain.mo
Expand Up @@ -607,6 +607,10 @@ algorithm
(daeElements,literals) = SimCodeUtil.findLiterals(daeElements);
(fns, extraRecordDecls, includes, includeDirs, libs) = SimCodeUtil.elaborateFunctions(program, daeElements, metarecordTypes, literals, includes);
makefileParams = SimCodeUtil.createMakefileParams(includeDirs, libs);
// remove OpenModelica.threadData.ThreadData
fns = removeThreadDataFunction(fns, {});
extraRecordDecls = removeThreadDataRecord(extraRecordDecls, {});

fnCode = SimCode.FUNCTIONCODE(name, NONE(), fns, literals, includes, makefileParams, extraRecordDecls);
// Generate code
_ = Tpl.tplString(CodegenC.translateFunctions, fnCode);
Expand All @@ -615,6 +619,72 @@ algorithm
end match;
end translateFunctions;

protected function removeThreadDataRecord
"remove OpenModelica.threadData.ThreadData
as is already defined in openmodelica.h"
input list<SimCode.RecordDeclaration> inRecs;
input list<SimCode.RecordDeclaration> inAcc;
output list<SimCode.RecordDeclaration> outRecs;
algorithm
outRecs := match(inRecs, inAcc)
local
Absyn.Path p;
list<SimCode.RecordDeclaration> acc, rest;
SimCode.RecordDeclaration r;

case ({}, _) then listReverse(inAcc);

case (SimCode.RECORD_DECL_FULL(name = "OpenModelica_threadData_ThreadData")::rest, _)
equation
acc = removeThreadDataRecord(rest, inAcc);
then
acc;

case (SimCode.RECORD_DECL_DEF(path = Absyn.QUALIFIED("OpenModelica",Absyn.QUALIFIED("threadData",Absyn.IDENT("ThreadData"))))::rest, _)
equation
acc = removeThreadDataRecord(rest, inAcc);
then
acc;

case (r::rest, _)
equation
acc = removeThreadDataRecord(rest, r::inAcc);
then
acc;

end match;
end removeThreadDataRecord;

protected function removeThreadDataFunction
"remove OpenModelica.threadData.ThreadData
as is already defined in openmodelica.h"
input list<SimCode.Function> inFuncs;
input list<SimCode.Function> inAcc;
output list<SimCode.Function> outFuncs;
algorithm
outFuncs := match(inFuncs, inAcc)
local
Absyn.Path p;
list<SimCode.Function> acc, rest;
SimCode.Function f;

case ({}, _) then listReverse(inAcc);

case (SimCode.RECORD_CONSTRUCTOR(name = Absyn.FULLYQUALIFIED(Absyn.QUALIFIED("OpenModelica",Absyn.QUALIFIED("threadData",Absyn.IDENT("ThreadData")))))::rest, _)
equation
acc = removeThreadDataFunction(rest, inAcc);
then
acc;

case (f::rest, _)
equation
acc = removeThreadDataFunction(rest, f::inAcc);
then
acc;

end match;
end removeThreadDataFunction;

public function getCalledFunctionsInFunction
"Goes through the given DAE, finds the given function and collects
the names of the functions called from within those functions"
Expand Down
8 changes: 5 additions & 3 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -3605,7 +3605,8 @@ template recordsFile(String filePrefix, list<RecordDeclaration> recordDecls)
<<
/* Additional record code for <%filePrefix%> generated by the OpenModelica Compiler <%getVersionNr()%>. */
#include "meta_modelica.h"
<%recordDecls |> rd => recordDeclaration(rd) ;separator="\n"%>

<%recordDecls |> rd => recordDeclaration(rd) ;separator="\n\n"%>

>>
/* adpro: leave a newline at the end of file to get rid of warnings! */
Expand Down Expand Up @@ -3954,7 +3955,9 @@ template functionsHeaderFile(String filePrefix,
#endif
<%extraRecordDecls |> rd => recordDeclarationHeader(rd) ;separator="\n"%>
<%match mainFunction case SOME(fn) then functionHeader(fn,true)%>
<%functionHeaders(functions)%>
/* start - annotation(Include=...) if we have any */
Expand Down Expand Up @@ -4334,7 +4337,6 @@ template recordDeclarationHeader(RecordDeclaration recDecl)
<%variables |> var as VARIABLE(__) => '<%varType(var)%> _<%crefStr(var.name)%>;' ;separator="\n"%>
} <%name%>;
typedef base_array_t <%name%>_array;

<%recordDefinitionHeader(dotPath(defPath),
underscorePath(defPath),
listLength(variables))%>
Expand All @@ -4357,7 +4359,7 @@ template recordDefinition(String origName, String encName, String fieldNames, In
'const char* <%encName%>__desc__fields[1] = {"no fields"};'
case _ then
'const char* <%encName%>__desc__fields[<%numFields%>] = {<%fieldNames%>};'
<<
<<
#define <%encName%>__desc_added 1
<%fieldsDescription%>
struct record_description <%encName%>__desc = {
Expand Down

0 comments on commit 394cca5

Please sign in to comment.