Skip to content

Commit

Permalink
- Fixed code generation for simulations and external functions
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7543 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Dec 21, 2010
1 parent 3c70ce6 commit 82dbb72
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 24 deletions.
28 changes: 6 additions & 22 deletions Compiler/susan_codegen/SimCode/SimCodeC.tpl
Expand Up @@ -2631,11 +2631,9 @@ end subscriptsToCStr;

template subscriptToCStr(Subscript subscript)
::=
let &preExp = buffer ""
let &varDecls = buffer ""
match subscript
case INDEX(__)
case SLICE(__) then daeExp(exp, contextSimulationNonDiscrete, &preExp /*BUFC*/, &varDecls /*BUFD*/)
case INDEX(exp=ICONST(integer=i)) then i
case SLICE(exp=ICONST(integer=i)) then i
case WHOLEDIM(__) then "WHOLEDIM"
else "UNKNOWN_SUBSCRIPT"
end subscriptToCStr;
Expand Down Expand Up @@ -2731,11 +2729,9 @@ template subscriptStr(Subscript subscript)
Only works for constant integer indicies."

::=
let &preExp = buffer ""
let &varDecls = buffer ""
match subscript
case INDEX(__)
case SLICE(__) then daeExp(exp, contextFunction, &preExp /*BUFC*/, &varDecls /*BUFD*/)
case INDEX(exp=ICONST(integer=i)) then i
case SLICE(exp=ICONST(integer=i)) then i
case WHOLEDIM(__) then "WHOLEDIM"
else "UNKNOWN_SUBSCRIPT"
end subscriptStr;
Expand Down Expand Up @@ -3076,10 +3072,8 @@ template extFunDefArg(SimExtArg extArg)
<%typeStr%>
>>
case SIMEXTARGSIZE(cref=c) then
let name = contextCref(c,contextFunction)
let eStr = daeExpToString(exp)
<<
size_t <%name%>_<%eStr%>
size_t
>>
end extFunDefArg;

Expand All @@ -3097,17 +3091,6 @@ template extFunDefArgF77(SimExtArg extArg)
end extFunDefArgF77;


template daeExpToString(Exp exp)
"Helper to extFunDefArg.
This only works for constants (or else the name of a temporary variable is
returned)."
::=
let &preExp = buffer "" /*BUFD*/
let &varDecls = buffer "" /*BUFD*/
daeExp(exp, contextFunction, &preExp /*BUFC*/, &varDecls /*BUFD*/)
end daeExpToString;


template functionBodies(list<Function> functions)
"Generates the body for a set of functions."
::=
Expand Down Expand Up @@ -3878,6 +3861,7 @@ template algStatement(DAE.Statement stmt, Context context, Text &varDecls /*BUFP
case s as STMT_ASSERT(__) then algStmtAssert(s, context, &varDecls /*BUFD*/)
case s as STMT_TERMINATE(__) then algStmtTerminate(s, context, &varDecls /*BUFD*/)


case s as STMT_WHEN(__) then algStmtWhen(s, context, &varDecls /*BUFD*/)
case s as STMT_BREAK(__) then 'break;<%\n%>'
case s as STMT_FAILURE(__) then algStmtFailure(s, context, &varDecls /*BUFD*/)
Expand Down
2 changes: 1 addition & 1 deletion c_runtime/meta_modelica.c
Expand Up @@ -308,7 +308,7 @@ inline static int anyStringWork(void* any, int ix)

if (numslots==1 && ctor==1) /* SOME(x) */ {
checkAnyStringBufSize(ix,5);
ix += sprintf(anyStringBuf+ix, "SOME)");
ix += sprintf(anyStringBuf+ix, "SOME(");
ix = anyStringWork(MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(any),1)),ix);
checkAnyStringBufSize(ix,1);
ix += sprintf(anyStringBuf+ix, ")");
Expand Down
3 changes: 2 additions & 1 deletion c_runtime/meta_modelica_builtin.cpp
Expand Up @@ -493,9 +493,10 @@ void equality(modelica_metatype in1, modelica_metatype in2)
}

/* Weird RML crap */
static modelica_metatype global_roots[1024];
static modelica_metatype global_roots[1024] = {0};

getGlobalRoot_rettype getGlobalRoot(int ix) {
assert(global_roots[ix]);
return global_roots[ix];
}

Expand Down

0 comments on commit 82dbb72

Please sign in to comment.