Skip to content

Commit

Permalink
Change daeExpSconst to use MMC string literals (since we do not optim…
Browse files Browse the repository at this point in the history
…ize away all literals in simulation context)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23568 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 26, 2014
1 parent acacf03 commit 09a1667
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -7885,7 +7885,7 @@ template daeExp(Exp exp, Context context, Text &preExp, Text &varDecls, Text &au
match exp
case e as ICONST(__) then '(modelica_integer) <%integer%>' /* Yes, we need to cast int to long on 64-bit arch... */
case e as RCONST(__) then real
case e as SCONST(__) then daeExpSconst(string)
case e as SCONST(__) then daeExpSconst(string, &preExp, &varDecls)
case e as BCONST(__) then if bool then "1" else "0"
case e as ENUM_LITERAL(__) then index
case e as CREF(__) then daeExpCrefRhs(e, context, &preExp, &varDecls, &auxFunction)
Expand Down Expand Up @@ -7945,10 +7945,17 @@ template daeExternalF77Exp(Exp exp, Context context, Text &preExp, Text &varDecl
'&<%tvar%>'
end daeExternalF77Exp;

template daeExpSconst(String string)
template daeExpSconst(String string, Text &preExp, Text &varDecls)
"Generates code for a string constant."
::=
'mmc_mk_scon("<%Util.escapeModelicaStringToCString(string)%>")'
let escstr = Util.escapeModelicaStringToCString(string)
match stringLength(string)
case 0 then "(modelica_string) mmc_emptystring"
case 1 then '(modelica_string) mmc_strings_len1[<%stringGet(string, 1)%>]'
else
let tmp = 'tmp<%System.tmpTick()%>'
let &varDecls += 'static const MMC_DEFSTRINGLIT(<%tmp%>,<%unescapedStringLength(escstr)%>,"<%escstr%>");<%\n%>'
'MMC_REFSTRINGLIT(<%tmp%>)'
end daeExpSconst;


Expand Down
11 changes: 11 additions & 0 deletions Compiler/Template/SimCodeTV.mo
Expand Up @@ -141,6 +141,17 @@ package builtin
output TypeVar result;
end listGet;

function stringLength
input String str;
output Integer length;
end stringLength;

function stringGet
input String str;
input Integer index;
output Integer ch;
end stringGet;

uniontype SourceInfo "The Info attribute provides location information for elements and classes."
record SOURCEINFO
String fileName;
Expand Down

0 comments on commit 09a1667

Please sign in to comment.