Skip to content

Commit

Permalink
- Start of function expansion
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12142 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jun 20, 2012
1 parent 66acada commit 1c52a61
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions Compiler/FrontEnd/DAE.mo
Expand Up @@ -744,6 +744,7 @@ public constant Type T_NONE_DEFAULT = T_METAOPTION(T_UNKNOWN_DEFAULT, emp
public constant Type T_ANYTYPE_DEFAULT = T_ANYTYPE(NONE(), emptyTypeSource);
public constant Type T_UNKNOWN_DEFAULT = T_UNKNOWN(emptyTypeSource);
public constant Type T_NORETCALL_DEFAULT = T_NORETCALL(emptyTypeSource);
public constant Type T_FUNCTION_DEFAULT = T_FUNCTION({},T_ANYTYPE_DEFAULT,FUNCTION_ATTRIBUTES_DEFAULT,emptyTypeSource);
public constant Type T_METATYPE_DEFAULT = T_METATYPE(T_UNKNOWN_DEFAULT, emptyTypeSource);
public constant Type T_COMPLEX_DEFAULT = T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("")), {}, NONE(), emptyTypeSource) "default complex with unknown CiState";

Expand Down
1 change: 1 addition & 0 deletions Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -1473,6 +1473,7 @@ algorithm
case (DAE.T_FUNCTION(_, _, DAE.FUNCTION_ATTRIBUTES(_, _, _, DAE.FP_NON_PARALLEL()), _)) then "";
case (DAE.T_FUNCTION(_, _, DAE.FUNCTION_ATTRIBUTES(_, _, _, DAE.FP_PARALLEL_FUNCTION()), _)) then "parallel ";
case (DAE.T_FUNCTION(_, _, DAE.FUNCTION_ATTRIBUTES(_, _, _, DAE.FP_KERNEL_FUNCTION()), _)) then "kernel ";
else "#dumpParallelismStr failed#";
end match;
end dumpParallelismStr;

Expand Down
1 change: 1 addition & 0 deletions Compiler/FrontEnd/InstTypes.mo
Expand Up @@ -79,6 +79,7 @@ end Class;

public uniontype Function
record FUNCTION "A function has inputs,output and locals without binding. These are resolved to statements in the algorithm section"
Absyn.Path path;
list<Element> inputs;
list<Element> outputs;
list<Element> locals;
Expand Down
28 changes: 25 additions & 3 deletions Compiler/FrontEnd/SCodeExpand.mo
Expand Up @@ -39,11 +39,14 @@ encapsulated package SCodeExpand
"

public import DAE;
public import HashTablePathToFunction;
public import InstTypes;

protected import Absyn;
protected import BaseHashTable;
protected import ComponentReference;
protected import DAEDump;
protected import DAEUtil;
protected import Debug;
protected import Error;
protected import Expression;
Expand All @@ -57,6 +60,7 @@ protected import Types;
protected import Util;

protected type Equation = InstTypes.Equation;
public type FunctionHashTable = HashTablePathToFunction.HashTable;
protected type Statement = InstTypes.Statement;

replaceable type ElementType subtypeof Any;
Expand All @@ -72,25 +76,30 @@ end ExpandScalarFunc;
public function expand
input String inName;
input InstTypes.Class inClass;
input FunctionHashTable inFunctions;
output DAE.DAElist outDAE;
protected
list<DAE.Element> el;
DAE.FunctionTree tree;
algorithm
outDAE := matchcontinue(inName, inClass)
outDAE := matchcontinue(inName, inClass, inFunctions)
local
list<DAE.Element> el;
DAE.DAElist dae;
DAE.FunctionTree tree;
Integer vars, params;
list<DAE.Function> funcs;

case (_, _)
case (_, _, _)
equation
el = expandClass(inClass, {}, {});
el = listReverse(el);
dae = DAE.DAE({DAE.COMP(inName, el, DAE.emptyElementSource, NONE())});

funcs = List.map(BaseHashTable.hashTableValueList(inFunctions), expandFunction);

tree = DAE.AVLTREENODE(NONE(), 0, NONE(), NONE());
tree = DAEUtil.emptyFuncTree;
tree = DAEUtil.addDaeFunction(funcs, tree);
print("\nEXPANDED FORM:\n\n");
print(DAEDump.dumpStr(dae, tree) +& "\n");
(vars, params) = countElements(el, 0, 0);
Expand Down Expand Up @@ -893,4 +902,17 @@ algorithm
end match;
end expandIfStmt;

protected function expandFunction
input InstTypes.Function inFunction;
output DAE.Function outFunction;
algorithm
outFunction := match (inFunction)
local
Absyn.Path path;
case InstTypes.FUNCTION(path=path)
equation
then DAE.FUNCTION(path,{DAE.FUNCTION_DEF({})},DAE.T_FUNCTION_DEFAULT,false,DAE.NO_INLINE(),DAE.emptyElementSource,NONE());
end match;
end expandFunction;

end SCodeExpand;
6 changes: 3 additions & 3 deletions Compiler/FrontEnd/SCodeInst.mo
Expand Up @@ -147,7 +147,7 @@ algorithm

//print("SCodeInst took " +& realString(System.getTimerIntervalTime()) +& " seconds.\n");

_ = SCodeExpand.expand(name, cls /*, functions */);
_ = SCodeExpand.expand(name, cls, functions);
then
();

Expand Down Expand Up @@ -1790,7 +1790,7 @@ algorithm
InstTypes.NO_PREFIXES(), inEnv, InstTypes.emptyPrefix, INST_ALL(), functions);
(inputs,outputs,locals) = getFunctionParameters(cls);
stmts = List.flatten(algorithms);
outFunction = InstTypes.FUNCTION(inputs,outputs,locals,stmts);
outFunction = InstTypes.FUNCTION(path,inputs,outputs,locals,stmts);
functions = BaseHashTable.addUnique((path,outFunction),functions);
then
(path, outFunction, functions);
Expand All @@ -1817,7 +1817,7 @@ algorithm

// A qualified name with class origin should be prefixed with the package
// name.
case (_, Absyn.QUALIFIED(name = _), SCodeLookup.CLASS_ORIGIN(), _, _)
case (_, _, SCodeLookup.CLASS_ORIGIN(), _, _)
equation
name = SCodeEnv.getItemName(inItem);
path = SCodeEnv.mergePathWithEnvPath(Absyn.IDENT(name), inEnv);
Expand Down

0 comments on commit 1c52a61

Please sign in to comment.