Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Add testcases PartialFn15 and updated DumpTest (with Exp.printExpStr and DAEDump.dumpDebugDAE)
- These testcases all use function pointers as data (in lists or options), as well as pattern matching on these structures
- Added more functions to RTOpts_omc


git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/sjoelund-functiontree@6470 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 20, 2010
1 parent 8a6cdb5 commit 8e19c1e
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Compiler/Exp.mo
Expand Up @@ -7575,9 +7575,9 @@ algorithm
case (DAE.LIST(_,es),_)
local list<Exp> es;
equation
Print.printBuf("<list>{");
Print.printBuf("list(");
printList(es, printExp, ",");
Print.printBuf("}");
Print.printBuf(")");
then
();

Expand Down
41 changes: 21 additions & 20 deletions Compiler/RTOpts.mo
Expand Up @@ -52,25 +52,25 @@ end args;
public function typeinfo
output Boolean outBoolean;

external "C" ;
external "C" outBoolean = RTOpts_typeinfo();
end typeinfo;

public function splitArrays
output Boolean outBoolean;

external "C" ;
external "C" splitArrays = RTOpts_splitArrays();
end splitArrays;

public function paramsStruct
output Boolean outBoolean;

external "C" ;
external "C" outBoolean = RTOpts_paramsStruct();
end paramsStruct;

public function modelicaOutput
output Boolean outBoolean;

external "C" ;
external "C" outBoolean = RTOpts_modelicaOutput();
end modelicaOutput;

public function debugFlag
Expand All @@ -85,13 +85,13 @@ public function setDebugFlag
input Integer value;
output Boolean str;

external "C" ;
external "C" str = RTOpts_setDebugFlag(inString,value);
end setDebugFlag;

public function noProc
output Integer outInteger;

external "C" ;
external "C" noProc = RTOpts_noProc();
end noProc;

public function setEliminationLevel
Expand All @@ -103,25 +103,25 @@ end setEliminationLevel;
public function eliminationLevel
output Integer level;

external "C" ;
external "C" level = RTOpts_level();
end eliminationLevel;

public function latency
output Real outReal;

external "C" ;
external "C" outReal = RTOpts_latency();
end latency;

public function bandwidth
output Real outReal;

external "C" ;
external "C" outReal = RTOpts_bandwidth();
end bandwidth;

public function simulationCg
output Boolean outBoolean;

external "C" ;
external "C" outBoolean = RTOpts_simulationCg();
end simulationCg;

public function simulationCodeTarget
Expand All @@ -130,34 +130,34 @@ public function simulationCodeTarget
usage: omc [+target=gcc|msvc], default to 'gcc'."
output String outCodeTarget;

external "C" ;
external "C" outCodeTarget = RTOpts_simulationCodeTarget();
end simulationCodeTarget;

public function classToInstantiate
output String modelName;

external "C";
external "C" modelName = RTOpts_classToInstantiate();
end classToInstantiate;

public function silent
output Boolean outBoolean;

external "C" ;
external "C" outBoolean = RTOpts_silent();
end silent;

public function versionRequest
output Boolean outBoolean;

external "C";
end versionRequest;
external "C" outBoolean = RTOpts_versionRequest();
end versionRequest;

public function acceptMetaModelicaGrammar
"@author: adrpo 2007-06-11
returns: true if MetaModelica grammar is accepted or false otherwise
usage: omc [+g=Modelica|MetaModelica], default to 'Modelica'."
output Boolean outBoolean;

external "C";
external "C" outBoolean = RTOpts_acceptMetaModelicaGrammar();
end acceptMetaModelicaGrammar;

public function getAnnotationVersion
Expand All @@ -168,7 +168,7 @@ public function getAnnotationVersion
setAnnotationVersion(\"3.x\");
for annotations: 1.x or 2.x or 3.x"
output String annotationVersion;
external "C";
external "C" annotationVersion = RTOpts_getAnnotationVersion();
end getAnnotationVersion;

public function setAnnotationVersion
Expand All @@ -186,7 +186,7 @@ public function getNoSimplify
or via the API
setNoSimplify(true|false);"
output Boolean noSimplify;
external "C";
external "C" noSimplify = RTOpts_getNoSimplify();
end getNoSimplify;

public function setNoSimplify
Expand All @@ -201,7 +201,7 @@ public function vectorizationLimit
"Returns the vectorization limit that is used to determine how large an array
can be before it no longer is expanded by Static.crefVectorize."
output Integer limit;
external "C";
external "C" limit = RTOpts_vectorizationLimit();
end vectorizationLimit;

public function setVectorizationLimit
Expand All @@ -212,7 +212,7 @@ end setVectorizationLimit;

public function showAnnotations
output Boolean show;
external "C";
external "C" show = RTOpts_showAnnotations();
end showAnnotations;

public function setShowAnnotations
Expand All @@ -222,6 +222,7 @@ end setShowAnnotations;

public function getRunningTestsuite
output Boolean runningTestsuite;
external "C" runningTestsuite = RTOpts_getRunningTestsuite();
end getRunningTestsuite;

end RTOpts;
Expand Down
50 changes: 48 additions & 2 deletions Compiler/SimCodeC.mo
Expand Up @@ -20015,6 +20015,50 @@ algorithm
txt = Tpl.writeText(txt, i_preExp);
then (txt, i_varDecls);

case ( txt,
DAE.STMT_ASSIGN(exp1 = (i_exp1 as DAE.CREF(ty = DAE.ET_FUNCTION_REFERENCE_VAR())), exp = i_exp),
i_context,
i_varDecls )
local
DAE.Exp i_exp;
DAE.Exp i_exp1;
Tpl.Text i_expPart;
Tpl.Text i_varPart;
Tpl.Text i_preExp;
equation
i_preExp = emptyTxt;
(i_varPart, i_preExp, i_varDecls) = scalarLhsCref(emptyTxt, i_exp1, i_context, i_preExp, i_varDecls);
(i_expPart, i_preExp, i_varDecls) = daeExp(emptyTxt, i_exp, i_context, i_preExp, i_varDecls);
txt = Tpl.writeText(txt, i_preExp);
txt = Tpl.softNewLine(txt);
txt = Tpl.writeText(txt, i_varPart);
txt = Tpl.writeTok(txt, Tpl.ST_STRING(" = (modelica_fnptr) "));
txt = Tpl.writeText(txt, i_expPart);
txt = Tpl.writeTok(txt, Tpl.ST_STRING(";"));
then (txt, i_varDecls);

case ( txt,
DAE.STMT_ASSIGN(exp1 = (i_exp1 as DAE.CREF(ty = DAE.ET_FUNCTION_REFERENCE_FUNC(builtin = _))), exp = i_exp),
i_context,
i_varDecls )
local
DAE.Exp i_exp;
DAE.Exp i_exp1;
Tpl.Text i_expPart;
Tpl.Text i_varPart;
Tpl.Text i_preExp;
equation
i_preExp = emptyTxt;
(i_varPart, i_preExp, i_varDecls) = scalarLhsCref(emptyTxt, i_exp1, i_context, i_preExp, i_varDecls);
(i_expPart, i_preExp, i_varDecls) = daeExp(emptyTxt, i_exp, i_context, i_preExp, i_varDecls);
txt = Tpl.writeText(txt, i_preExp);
txt = Tpl.softNewLine(txt);
txt = Tpl.writeText(txt, i_varPart);
txt = Tpl.writeTok(txt, Tpl.ST_STRING(" = (modelica_fnptr) "));
txt = Tpl.writeText(txt, i_expPart);
txt = Tpl.writeTok(txt, Tpl.ST_STRING(";"));
then (txt, i_varDecls);

case ( txt,
DAE.STMT_ASSIGN(exp1 = (i_exp1 as DAE.CREF(componentRef = _)), exp = i_exp),
i_context,
Expand Down Expand Up @@ -23564,8 +23608,9 @@ algorithm
local
DAE.ComponentRef i_cr;
equation
txt = Tpl.writeTok(txt, Tpl.ST_STRING("(modelica_fnptr)boxptr_"));
txt = Tpl.writeTok(txt, Tpl.ST_STRING("((modelica_fnptr)boxptr_"));
txt = functionName(txt, i_cr);
txt = Tpl.writeTok(txt, Tpl.ST_STRING(")"));
then (txt, i_preExp, i_varDecls);

case ( txt,
Expand All @@ -23576,8 +23621,9 @@ algorithm
local
DAE.ComponentRef i_cr;
equation
txt = Tpl.writeTok(txt, Tpl.ST_STRING("(modelica_fnptr) _"));
txt = Tpl.writeTok(txt, Tpl.ST_STRING("((modelica_fnptr) _"));
txt = crefStr(txt, i_cr);
txt = Tpl.writeTok(txt, Tpl.ST_STRING(")"));
then (txt, i_preExp, i_varDecls);

case ( txt,
Expand Down
12 changes: 12 additions & 0 deletions Compiler/runtime/RTOpts_omc.cpp
Expand Up @@ -63,4 +63,16 @@ extern modelica_metatype RTOpts_args(modelica_metatype args) {
return listReverse(res);
}

extern int RTOpts_typeinfo() {
return type_info;
}

extern int RTOpts_modelicaOutput() {
return modelica_output;
}

extern int RTOpts_showAnnotations() {
return showAnnotations;
}

}
14 changes: 12 additions & 2 deletions Compiler/susan_codegen/SimCode/SimCodeC.tpl
Expand Up @@ -3651,6 +3651,7 @@ template extArgF77(SimExtArg extArg, Text &preExp, Text &varDecls)
end extArgF77;

template tempSizeVarName(ComponentRef c, DAE.Exp indices)

::=
match indices
case ICONST(__) then '<%contextCref(c,contextFunction)%>_size_<%integer%>'
Expand Down Expand Up @@ -3703,6 +3704,15 @@ template algStmtAssign(DAE.Statement stmt, Context context, Text &varDecls /*BUF
<<
<%preExp%>
>>
case STMT_ASSIGN(exp1=CREF(ty = ET_FUNCTION_REFERENCE_VAR(__)))
case STMT_ASSIGN(exp1=CREF(ty = ET_FUNCTION_REFERENCE_FUNC(__))) then
let &preExp = buffer "" /*BUFD*/
let varPart = scalarLhsCref(exp1, context, &preExp /*BUFC*/, &varDecls /*BUFC*/)
let expPart = daeExp(exp, context, &preExp /*BUFC*/, &varDecls /*BUFC*/)
<<
<%preExp%>
<%varPart%> = (modelica_fnptr) <%expPart%>;
>>
case STMT_ASSIGN(exp1=CREF(__)) then
let &preExp = buffer "" /*BUFD*/
let varPart = scalarLhsCref(exp1, context, &preExp /*BUFC*/, &varDecls /*BUFC*/)
Expand Down Expand Up @@ -4306,9 +4316,9 @@ template daeExpCrefRhs(Exp exp, Context context, Text &preExp /*BUFP*/,
else
daeExpRecordCrefRhs(t, cr, context, preExp, varDecls)
case CREF(componentRef = cr, ty = ET_FUNCTION_REFERENCE_FUNC(__)) then
'(modelica_fnptr)boxptr_<%functionName(cr)%>'
'((modelica_fnptr)boxptr_<%functionName(cr)%>)'
case CREF(componentRef = cr, ty = ET_FUNCTION_REFERENCE_VAR(__)) then
'(modelica_fnptr) _<%crefStr(cr)%>'
'((modelica_fnptr) _<%crefStr(cr)%>)'
else daeExpCrefRhs2(exp, context, &preExp, &varDecls)
end daeExpCrefRhs;

Expand Down
6 changes: 5 additions & 1 deletion c_runtime/modelica.h
Expand Up @@ -44,7 +44,11 @@ extern "C" {

typedef void* modelica_complex; /* currently only External objects are represented using modelica_complex.*/
typedef void* modelica_metatype; /* MetaModelica extension, added by sjoelund */
typedef void(* modelica_fnptr) (void); /*MetaModelica extension, function pointer, added by stefan */
/* MetaModelica extension.
We actually store function-pointers in lists, etc...
So it needs to be void*. If we use a platform with different sizes of function-
pointers, some changes need to be done to code generation */
typedef void* modelica_fnptr;

#include <stdlib.h>

Expand Down

0 comments on commit 8e19c1e

Please sign in to comment.