Skip to content

Commit

Permalink
- Fixed some function definitions so it will be easier to use 64-bit …
Browse files Browse the repository at this point in the history
…integers in the simulation/function runtime

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7152 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 22, 2010
1 parent cc0d565 commit f3c24dc
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 76 deletions.
149 changes: 106 additions & 43 deletions Compiler/SimCodeC.mo
Expand Up @@ -19045,87 +19045,98 @@ end extFunCallVardecl;
protected function fun_456
input Tpl.Text in_txt;
input Boolean in_i_ia;
input DAE.ComponentRef in_i_c;
input Integer in_i_oi;
input DAE.ComponentRef in_i_c;
input DAE.ExpType in_i_ty;
input Tpl.Text in_i_varDecls;

output Tpl.Text out_txt;
output Tpl.Text out_i_varDecls;
algorithm
out_txt :=
matchcontinue(in_txt, in_i_ia, in_i_c, in_i_oi, in_i_ty)
(out_txt, out_i_varDecls) :=
matchcontinue(in_txt, in_i_ia, in_i_oi, in_i_c, in_i_ty, in_i_varDecls)
local
Tpl.Text txt;
DAE.ComponentRef i_c;
Integer i_oi;
DAE.ComponentRef i_c;
DAE.ExpType i_ty;
Tpl.Text i_varDecls;

case ( txt,
false,
_,
_,
_ )
then txt;
i_c,
i_ty,
i_varDecls )
equation
i_varDecls = extType(i_varDecls, i_ty);
i_varDecls = Tpl.writeTok(i_varDecls, Tpl.ST_STRING(" "));
i_varDecls = extVarName(i_varDecls, i_c);
i_varDecls = Tpl.writeTok(i_varDecls, Tpl.ST_STRING(";"));
i_varDecls = Tpl.writeTok(i_varDecls, Tpl.ST_NEW_LINE());
then (txt, i_varDecls);

case ( txt,
_,
i_c,
i_oi,
i_ty )
i_c,
i_ty,
i_varDecls )
equation
i_varDecls = expTypeArrayIf(i_varDecls, i_ty);
i_varDecls = Tpl.writeTok(i_varDecls, Tpl.ST_STRING(" "));
i_varDecls = extVarName(i_varDecls, i_c);
i_varDecls = Tpl.writeTok(i_varDecls, Tpl.ST_STRING(";"));
i_varDecls = Tpl.writeTok(i_varDecls, Tpl.ST_NEW_LINE());
txt = Tpl.writeTok(txt, Tpl.ST_STRING("convert_alloc_"));
txt = expTypeArray(txt, i_ty);
txt = Tpl.writeTok(txt, Tpl.ST_STRING("_to_f77(&out.targ"));
txt = Tpl.writeStr(txt, intString(i_oi));
txt = Tpl.writeTok(txt, Tpl.ST_STRING(", &"));
txt = extVarName(txt, i_c);
txt = Tpl.writeTok(txt, Tpl.ST_STRING(");"));
then txt;
then (txt, i_varDecls);
end matchcontinue;
end fun_456;

protected function fun_457
input Tpl.Text in_txt;
input Integer in_i_oi;
input Boolean in_i_ia;
input DAE.ComponentRef in_i_c;
input DAE.ExpType in_i_ty;
input Tpl.Text in_i_varDecls;
input Boolean in_i_ia;

output Tpl.Text out_txt;
output Tpl.Text out_i_varDecls;
algorithm
(out_txt, out_i_varDecls) :=
matchcontinue(in_txt, in_i_oi, in_i_ia, in_i_c, in_i_ty, in_i_varDecls)
matchcontinue(in_txt, in_i_oi, in_i_c, in_i_ty, in_i_varDecls, in_i_ia)
local
Tpl.Text txt;
Boolean i_ia;
DAE.ComponentRef i_c;
DAE.ExpType i_ty;
Tpl.Text i_varDecls;
Boolean i_ia;

case ( txt,
0,
_,
_,
_,
i_varDecls )
i_varDecls,
_ )
then (txt, i_varDecls);

case ( txt,
i_oi,
i_ia,
i_c,
i_ty,
i_varDecls )
i_varDecls,
i_ia )
local
Integer i_oi;
equation
i_varDecls = expTypeArrayIf(i_varDecls, i_ty);
i_varDecls = Tpl.writeTok(i_varDecls, Tpl.ST_STRING(" "));
i_varDecls = extVarName(i_varDecls, i_c);
i_varDecls = Tpl.writeTok(i_varDecls, Tpl.ST_STRING(";"));
i_varDecls = Tpl.writeTok(i_varDecls, Tpl.ST_NEW_LINE());
txt = fun_456(txt, i_ia, i_c, i_oi, i_ty);
(txt, i_varDecls) = fun_456(txt, i_ia, i_oi, i_c, i_ty, i_varDecls);
then (txt, i_varDecls);
end matchcontinue;
end fun_457;
Expand Down Expand Up @@ -19174,7 +19185,7 @@ algorithm
Boolean i_ia;
Integer i_oi;
equation
(txt, i_varDecls) = fun_457(txt, i_oi, i_ia, i_c, i_ty, i_varDecls);
(txt, i_varDecls) = fun_457(txt, i_oi, i_c, i_ty, i_varDecls, i_ia);
then (txt, i_varDecls);

case ( txt,
Expand All @@ -19184,7 +19195,7 @@ algorithm
DAE.ComponentRef i_c;
DAE.ExpType i_ty;
equation
i_varDecls = expTypeArrayIf(i_varDecls, i_ty);
i_varDecls = extType(i_varDecls, i_ty);
i_varDecls = Tpl.writeTok(i_varDecls, Tpl.ST_STRING(" "));
i_varDecls = extVarName(i_varDecls, i_c);
i_varDecls = Tpl.writeTok(i_varDecls, Tpl.ST_STRING(";"));
Expand Down Expand Up @@ -19847,49 +19858,43 @@ end extArg;

protected function fun_474
input Tpl.Text in_txt;
input Boolean in_i_ia;
input Integer in_i_oi;

output Tpl.Text out_txt;
algorithm
out_txt :=
matchcontinue(in_txt, in_i_ia)
matchcontinue(in_txt, in_i_oi)
local
Tpl.Text txt;

case ( txt,
true )
equation
txt = Tpl.writeTok(txt, Tpl.ST_STRING("_ext"));
0 )
then txt;

case ( txt,
_ )
equation
txt = Tpl.writeTok(txt, Tpl.ST_STRING("_ext"));
then txt;
end matchcontinue;
end fun_474;

protected function fun_475
input Tpl.Text in_txt;
input Integer in_i_oi;
input Boolean in_i_ia;

output Tpl.Text out_txt;
algorithm
out_txt :=
matchcontinue(in_txt, in_i_oi, in_i_ia)
matchcontinue(in_txt, in_i_oi)
local
Tpl.Text txt;
Boolean i_ia;

case ( txt,
0,
i_ia )
equation
txt = fun_474(txt, i_ia);
0 )
then txt;

case ( txt,
_,
_ )
equation
txt = Tpl.writeTok(txt, Tpl.ST_STRING("_ext"));
Expand Down Expand Up @@ -19930,17 +19935,31 @@ algorithm
then (txt, i_preExp, i_varDecls);

case ( txt,
SimCode.SIMEXTARG(cref = i_c, isArray = i_ia, outputIndex = i_oi, type_ = i_t),
SimCode.SIMEXTARG(cref = i_c, outputIndex = i_oi, type_ = DAE.ET_INT()),
i_preExp,
i_varDecls )
local
Integer i_oi;
DAE.ComponentRef i_c;
Tpl.Text i_suffix;
equation
i_suffix = fun_474(Tpl.emptyTxt, i_oi);
txt = Tpl.writeTok(txt, Tpl.ST_STRING("(int*) &"));
txt = contextCref(txt, i_c, SimCode.contextFunction);
txt = Tpl.writeText(txt, i_suffix);
then (txt, i_preExp, i_varDecls);

case ( txt,
SimCode.SIMEXTARG(cref = i_c, outputIndex = i_oi, type_ = i_t),
i_preExp,
i_varDecls )
local
DAE.ExpType i_t;
Integer i_oi;
Boolean i_ia;
DAE.ComponentRef i_c;
Tpl.Text i_suffix;
equation
i_suffix = fun_475(Tpl.emptyTxt, i_oi, i_ia);
i_suffix = fun_475(Tpl.emptyTxt, i_oi);
txt = Tpl.writeTok(txt, Tpl.ST_STRING("&"));
txt = contextCref(txt, i_c, SimCode.contextFunction);
txt = Tpl.writeText(txt, i_suffix);
Expand All @@ -19952,8 +19971,20 @@ algorithm
i_varDecls )
local
DAE.Exp i_exp;
Tpl.Text txt_2;
Tpl.Text i_tvar;
Tpl.Text i_texp;
equation
(txt, i_preExp, i_varDecls) = daeExp(txt, i_exp, SimCode.contextFunction, i_preExp, i_varDecls);
(i_texp, i_preExp, i_varDecls) = daeExp(Tpl.emptyTxt, i_exp, SimCode.contextFunction, i_preExp, i_varDecls);
txt_2 = expTypeFromExpFlag(Tpl.emptyTxt, i_exp, 8);
(i_tvar, i_varDecls) = tempDecl(Tpl.emptyTxt, Tpl.textString(txt_2), i_varDecls);
i_preExp = Tpl.writeText(i_preExp, i_tvar);
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_STRING(" = "));
i_preExp = Tpl.writeText(i_preExp, i_texp);
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_STRING(";"));
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_NEW_LINE());
txt = Tpl.writeTok(txt, Tpl.ST_STRING("&"));
txt = Tpl.writeText(txt, i_tvar);
then (txt, i_preExp, i_varDecls);

case ( txt,
Expand Down Expand Up @@ -26923,7 +26954,27 @@ algorithm
then (txt, i_preExp, i_varDecls);

case ( txt,
DAE.CALL(tuple_ = false, builtin = true, path = Absyn.IDENT(name = "min"), expLst = {i_e1, i_e2}),
DAE.CALL(tuple_ = false, builtin = true, ty = DAE.ET_INT(), path = Absyn.IDENT(name = "min"), expLst = {i_e1, i_e2}),
i_context,
i_preExp,
i_varDecls )
local
DAE.Exp i_e2;
DAE.Exp i_e1;
Tpl.Text i_var2;
Tpl.Text i_var1;
equation
(i_var1, i_preExp, i_varDecls) = daeExp(Tpl.emptyTxt, i_e1, i_context, i_preExp, i_varDecls);
(i_var2, i_preExp, i_varDecls) = daeExp(Tpl.emptyTxt, i_e2, i_context, i_preExp, i_varDecls);
txt = Tpl.writeTok(txt, Tpl.ST_STRING("std::min((modelica_integer)"));
txt = Tpl.writeText(txt, i_var1);
txt = Tpl.writeTok(txt, Tpl.ST_STRING(",(modelica_integer)"));
txt = Tpl.writeText(txt, i_var2);
txt = Tpl.writeTok(txt, Tpl.ST_STRING(")"));
then (txt, i_preExp, i_varDecls);

case ( txt,
DAE.CALL(tuple_ = false, builtin = true, ty = DAE.ET_REAL(), path = Absyn.IDENT(name = "min"), expLst = {i_e1, i_e2}),
i_context,
i_preExp,
i_varDecls )
Expand Down Expand Up @@ -31419,6 +31470,12 @@ algorithm
local
Tpl.Text txt;

case ( txt,
8 )
equation
txt = Tpl.writeTok(txt, Tpl.ST_STRING("int"));
then txt;

case ( txt,
1 )
equation
Expand Down Expand Up @@ -31519,6 +31576,12 @@ algorithm
local
Tpl.Text txt;

case ( txt,
8 )
equation
txt = Tpl.writeTok(txt, Tpl.ST_STRING("int"));
then txt;

case ( txt,
1 )
equation
Expand Down
2 changes: 1 addition & 1 deletion Compiler/runtime/Makefile.common
Expand Up @@ -49,7 +49,7 @@ omc_communication.h: omc_communication_impl.cpp corbaimpl.cpp

omc_communication_impl.o: omc_communication.h
corbaimpl.o: omc_communication.h
Dynload_rml.o: systemimpl.h errorext.h rtopts.h ../Absyn.h ../Values.h
Dynload_rml.o: systemimpl.h errorext.h rtopts.h ../Absyn.h ../Values.h ../../c_runtime/read_write.h ../../c_runtime/memory_pool.h
Print_rml.o : printimpl.c
Print_omc.o : printimpl.c
Error_rml.o : errorext.cpp
Expand Down
39 changes: 26 additions & 13 deletions Compiler/susan_codegen/SimCode/SimCodeC.tpl
Expand Up @@ -3580,11 +3580,15 @@ template extFunCallVardeclF77(SimExtArg arg, Text &varDecls)
'convert_alloc_<%expTypeArray(ty)%>_to_f77(&<%contextCref(c,contextFunction)%>, &<%extVarName(c)%>);'
case SIMEXTARG(outputIndex = oi, isArray = ia, type_= ty, cref = c) then
match oi case 0 then "" else
let &varDecls += '<%expTypeArrayIf(ty)%> <%extVarName(c)%>;<%\n%>'
match ia case false then "" else
'convert_alloc_<%expTypeArray(ty)%>_to_f77(&out.targ<%oi%>, &<%extVarName(c)%>);'
match ia
case false then
let &varDecls += '<%extType(ty)%> <%extVarName(c)%>;<%\n%>'
""
else
let &varDecls += '<%expTypeArrayIf(ty)%> <%extVarName(c)%>;<%\n%>'
'convert_alloc_<%expTypeArray(ty)%>_to_f77(&out.targ<%oi%>, &<%extVarName(c)%>);'
case SIMEXTARG(type_ = ty, cref = c) then
let &varDecls += '<%expTypeArrayIf(ty)%> <%extVarName(c)%>;<%\n%>'
let &varDecls += '<%extType(ty)%> <%extVarName(c)%>;<%\n%>'
""
end extFunCallVardeclF77;

Expand Down Expand Up @@ -3671,15 +3675,19 @@ template extArgF77(SimExtArg extArg, Text &preExp, Text &varDecls)
case SIMEXTARG(cref=c, isArray=true, type_=t) then
// Arrays are converted to fortran format that are stored in _ext-variables.
'data_of_<%expTypeShort(t)%>_array(&(<%extVarName(c)%>))'
case SIMEXTARG(cref=c, isArray=ia, outputIndex=oi, type_=t) then
case SIMEXTARG(cref=c, outputIndex=oi, type_=ET_INT()) then
// Always prefix fortran arguments with &.
let suffix = if oi then
"_ext"
else
match ia case true then "_ext" else ""
let suffix = if oi then "_ext"
'(int*) &<%contextCref(c,contextFunction)%><%suffix%>'
case SIMEXTARG(cref=c, outputIndex=oi, type_=t) then
// Always prefix fortran arguments with &.
let suffix = if oi then "_ext"
'&<%contextCref(c,contextFunction)%><%suffix%>'
case SIMEXTARGEXP(__) then
daeExp(exp, contextFunction, &preExp /*BUFC*/, &varDecls /*BUFC*/)
let texp = daeExp(exp, contextFunction, &preExp /*BUFC*/, &varDecls /*BUFC*/)
let tvar = tempDecl(expTypeFromExpFlag(exp,8),&varDecls)
let &preExp += '<%tvar%> = <%texp%>;<%\n%>'
'&<%tvar%>'
case SIMEXTARGSIZE(cref=c) then
// Fortran functions only takes references to variables, so we must store
// the result from size_of_dimension_<type>_array in a temporary variable.
Expand Down Expand Up @@ -4725,7 +4733,12 @@ template daeExpCall(Exp call, Context context, Text &preExp /*BUFP*/,
let var1 = daeExp(e1, context, &preExp, &varDecls)
let var2 = daeExp(e2, context, &preExp, &varDecls)
'std::max(<%var1%>,<%var2%>)'
case CALL(tuple_=false, builtin=true,
case CALL(tuple_=false, builtin=true, ty = ET_INT(),
path=IDENT(name="min"), expLst={e1,e2}) then
let var1 = daeExp(e1, context, &preExp, &varDecls)
let var2 = daeExp(e2, context, &preExp, &varDecls)
'std::min((modelica_integer)<%var1%>,(modelica_integer)<%var2%>)'
case CALL(tuple_=false, builtin=true, ty = ET_REAL(),
path=IDENT(name="min"), expLst={e1,e2}) then
let var1 = daeExp(e1, context, &preExp, &varDecls)
let var2 = daeExp(e2, context, &preExp, &varDecls)
Expand Down Expand Up @@ -5554,11 +5567,11 @@ template expTypeFromExpFlag(Exp exp, Integer flag)
"Generate type helper."
::=
match exp
case ICONST(__) then match flag case 1 then "integer" else "modelica_integer"
case ICONST(__) then match flag case 8 then "int" case 1 then "integer" else "modelica_integer"
case RCONST(__) then match flag case 1 then "real" else "modelica_real"
case SCONST(__) then match flag case 1 then "string" else "modelica_string"
case BCONST(__) then match flag case 1 then "boolean" else "modelica_boolean"
case ENUM_LITERAL(__) then match flag case 1 then "integer" else "modelica_integer"
case ENUM_LITERAL(__) then match flag case 8 then "int" case 1 then "integer" else "modelica_integer"
case e as BINARY(__)
case e as UNARY(__)
case e as LBINARY(__)
Expand Down

0 comments on commit f3c24dc

Please sign in to comment.