Skip to content

Commit

Permalink
- Started implementation of generateSeparateCode() API call
Browse files Browse the repository at this point in the history
  - Generates code for all loaded packages at the moment
- Fixed OMC source code where this new API call found errors (Main.main only found errors in functions that were actually used by the compiler)


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7673 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jan 10, 2011
1 parent cf2900c commit eb41dbe
Show file tree
Hide file tree
Showing 25 changed files with 588 additions and 1,146 deletions.
6 changes: 3 additions & 3 deletions Compiler/BackEnd/DAEQuery.mo
Expand Up @@ -298,7 +298,7 @@ algorithm
outVarLst:=
matchcontinue (inVariableArray)
local
Option<BackendDAE.Var>[:] arr;
array<Option<BackendDAE.Var>> arr;
BackendDAE.Var elt;
Integer lastpos,n,size;
list<BackendDAE.Var> lst;
Expand All @@ -321,7 +321,7 @@ protected function vararrayList2 "function: vararrayList2

Helper function to vararray_list
"
input Option<BackendDAE.Var>[:] inVarOptionArray1;
input array<Option<BackendDAE.Var>> inVarOptionArray1;
input Integer inInteger2;
input Integer inInteger3;
output list<BackendDAE.Var> outVarLst;
Expand All @@ -330,7 +330,7 @@ algorithm
matchcontinue (inVarOptionArray1,inInteger2,inInteger3)
local
BackendDAE.Var v;
Option<BackendDAE.Var>[:] arr;
array<Option<BackendDAE.Var>> arr;
Integer pos,lastpos,pos_1;
list<BackendDAE.Var> res;
case (arr,pos,lastpos)
Expand Down
23 changes: 18 additions & 5 deletions Compiler/BackEnd/SimCode.mo
Expand Up @@ -169,7 +169,7 @@ end DelayedExpression;
uniontype FunctionCode
record FUNCTIONCODE
String name;
Function mainFunction "This function is special; the 'in'-function should be generated for it";
Option<Function> mainFunction "This function is special; the 'in'-function should be generated for it";
list<Function> functions;
list<DAE.Exp> literals "shared literals";
list<String> externalFunctionIncludes;
Expand Down Expand Up @@ -1043,28 +1043,41 @@ public function translateFunctions
Called from other places in the compiler."
input String name;
input DAE.Function daeMainFunction;
input Option<DAE.Function> optMainFunction;
input list<DAE.Function> daeElements;
input list<DAE.Type> metarecordTypes;
algorithm
_ := match (name, daeMainFunction, daeElements, metarecordTypes)
_ := match (name, optMainFunction, daeElements, metarecordTypes)
local
DAE.Function daeMainFunction;
Function mainFunction;
list<Function> fns;
list<String> libs, includes;
MakefileParams makefileParams;
FunctionCode fnCode;
list<RecordDeclaration> extraRecordDecls;
list<DAE.Exp> literals;
case (name, daeMainFunction, daeElements, metarecordTypes)
case (name, SOME(daeMainFunction), daeElements, metarecordTypes)
equation
// Create FunctionCode
(daeElements,(_,(_,_,literals))) = DAEUtil.traverseDAEFunctions(daeMainFunction::daeElements,Expression.traverseSubexpressionsHelper,(replaceLiteralExp,(0,HashTableExpToIndex.emptyHashTableSized(24971),{})));
literals = listReverse(literals);
(mainFunction::fns, extraRecordDecls, includes, libs) = elaborateFunctions(daeElements, metarecordTypes, literals);
checkValidMainFunction(name, mainFunction);
makefileParams = createMakefileParams(libs);
fnCode = FUNCTIONCODE(name, mainFunction, fns, literals, includes, makefileParams, extraRecordDecls);
fnCode = FUNCTIONCODE(name, SOME(mainFunction), fns, literals, includes, makefileParams, extraRecordDecls);
// Generate code
_ = Tpl.tplString(SimCodeC.translateFunctions, fnCode);
then
();
case (name, NONE(), daeElements, metarecordTypes)
equation
// Create FunctionCode
(daeElements,(_,(_,_,literals))) = DAEUtil.traverseDAEFunctions(daeElements,Expression.traverseSubexpressionsHelper,(replaceLiteralExp,(0,HashTableExpToIndex.emptyHashTableSized(24971),{})));
literals = listReverse(literals);
(fns, extraRecordDecls, includes, libs) = elaborateFunctions(daeElements, metarecordTypes, literals);
makefileParams = createMakefileParams(libs);
fnCode = FUNCTIONCODE(name, NONE(), fns, literals, includes, makefileParams, extraRecordDecls);
// Generate code
_ = Tpl.tplString(SimCodeC.translateFunctions, fnCode);
then
Expand Down
8 changes: 8 additions & 0 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -1737,6 +1737,14 @@ output Path p;
algorithm p := IDENT(s);
end makeIdentPathFromString;

public function makeQualifiedPathFromStrings ""
input String s1;
input String s2;
output Path p;
algorithm
p := QUALIFIED(s1,IDENT(s2));
end makeQualifiedPathFromStrings;

public function setTimeStampEdit "Function: getNewTimeStamp
Update current TimeStamp with a new Edit-time.
"
Expand Down
91 changes: 2 additions & 89 deletions Compiler/FrontEnd/Ceval.mo
Expand Up @@ -1174,17 +1174,6 @@ algorithm
String error_Str;
DAE.Function func;

// Try cevalFunction first
/*
case (cache,env,(e as DAE.CALL(path = funcpath,expLst = expl)),vallst,impl,st,_,msg)
equation
(cache,false) = Static.isExternalObjectFunction(cache,env,funcpath);
// Call of record constructors, etc., i.e. functions that can be constant propagated.
(cache,newval) = cevalFunction(cache, env, funcpath, vallst, impl, msg);
then
(cache,newval,st);
*/

// External functions that are "known" should be evaluated without compilation, e.g. all math functions
case (cache,env,(e as DAE.CALL(path = funcpath,expLst = expl,builtin = builtin)),vallst,impl,st,dim,msg)
equation
Expand Down Expand Up @@ -1526,59 +1515,6 @@ algorithm
end match;
end cevalKnownExternalFuncs2;

protected function cevalFunction "function: cevalFunction
For constant evaluation of functions returning a single value.
For now only record constructors."
input Env.Cache inCache;
input Env.Env inEnv;
input Absyn.Path inPath;
input list<Values.Value> inValuesValueLst;
input Boolean inBoolean;
input Msg inMsg;
output Env.Cache outCache;
output Values.Value outValue;
algorithm
(outCache,outValue) :=
matchcontinue (inCache,inEnv,inPath,inValuesValueLst,inBoolean,inMsg)
local
SCode.Class c;
list<Env.Frame> env_1,env;
list<String> compnames;
DAE.Mod mod;
list<DAE.Element> dae;
Values.Value value;
Absyn.Path funcname;
list<Values.Value> vallst;
Boolean impl;
Msg msg;
String s;
Env.Cache cache;
Env.Env env_2;
// Not working properly (only non-nested records)! /sjoelund
/*
case (cache,env,funcname,vallst,impl,msg) "For record constructors"
equation
(_,_) = Lookup.lookupRecordConstructorClass(env, funcname);
(cache,c,env_1) = Lookup.lookupClass(cache,env, funcname, false);
compnames = SCode.componentNames(c);
mod = Types.valuesToMods(vallst, compnames);
(cache,env_2,_,_,dae,_,_,_,_,_) = Inst.instClass(cache,env_1,InnerOuter.emptyInstHierarchy,UnitAbsyn.noStore, mod, Prefix.NOPRE(), Connect.emptySet, c, {}, impl,
Inst.TOP_CALL(),ConnectionGraph.EMPTY);
(cache, value) = DAE.daeToRecordValue(cache, env_2, funcname, dae, impl) "adrpo: We need the env here as we need to do variable Lookup!";
then
(cache,value);
*/

case (cache,env,funcname,vallst,(impl as true),msg)
equation
/*Debug.fprint("failtrace", "- Ceval.cevalFunction: Don't know what to do. impl was always false before:");
s = Absyn.pathString(funcname);
Debug.fprintln("failtrace", s);*/
then
fail();
end matchcontinue;
end cevalFunction;

protected function cevalMatrixElt "function: cevalMatrixElt
Evaluates the expression of a matrix constructor, e.g. {1,2;3,4}"
input Env.Cache inCache;
Expand Down Expand Up @@ -5578,29 +5514,6 @@ algorithm
end matchcontinue;
end getValueString;


protected function cevalTuple
input list<DAE.Exp> inexps;
output list<Values.Value> oval;
algorithm
oval := matchcontinue(inexps)
local
DAE.Exp e;
list<DAE.Exp> expl;
Values.Value v;
list<Values.Value> vs;

case({}) then {};

case(e ::expl)
equation
(_,v,_) = ceval(Env.emptyCache(), Env.emptyEnv, e,true,NONE(),NONE(),MSG);
vs = cevalTuple(expl);
then
v::vs;
end matchcontinue;
end cevalTuple;

protected function crefEqualValue ""
input DAE.ComponentRef c;
input DAE.Binding v;
Expand Down Expand Up @@ -5928,8 +5841,8 @@ public function emptyCevalHashTable
list<Option<tuple<Key,Value>>> lst;
array<Option<tuple<Key,Value>>> emptyarr;
algorithm
arr := fill({}, 1000);
emptyarr := fill(NONE(), 100);
arr := arrayCreate(1000, {});
emptyarr := arrayCreate(100, NONE());
hashTable := HASHTABLE(arr,VALUE_ARRAY(0,100,emptyarr),1000,0);
end emptyCevalHashTable;

Expand Down
8 changes: 4 additions & 4 deletions Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -191,9 +191,9 @@ algorithm
case(DAE.POW_SCALAR_ARRAY(ty=ty)) then " POW_SCALAR_ARRAY ";
case(DAE.POW_ARR(ty=ty)) then " POW_ARR ";
case(DAE.POW_ARR2(ty=ty)) then " POW_ARR2 ";
case(DAE.OR) then " OR ";
case(DAE.AND) then " AND ";
case(DAE.NOT) then " NOT ";
case(DAE.OR()) then " OR ";
case(DAE.AND()) then " AND ";
case(DAE.NOT()) then " NOT ";
case(DAE.LESSEQ(ty=ty)) then " LESSEQ ";
case(DAE.GREATER(ty=ty)) then " GREATER ";
case(DAE.GREATEREQ(ty=ty)) then " GREATEREQ ";
Expand Down Expand Up @@ -1291,7 +1291,7 @@ algorithm
then
str;

case(DAE.ZERO_DERIVATIVE) then "zeroDerivative";
case(DAE.ZERO_DERIVATIVE()) then "zeroDerivative";
end matchcontinue;
end derivativeCondStr;

Expand Down
22 changes: 7 additions & 15 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -980,18 +980,6 @@ algorithm
end matchcontinue;
end getStartAttrString;

protected function stringToString "function: stringToString

Convert a string to a Modelica string, enclosed in citation marks.
"
input String str;
output String str_1;
String str_1;
algorithm
str_1 := stringAppendList({"\"",str,"\""});
end stringToString;


public function getMatchingElements "function getMatchingElements
author: LS

Expand Down Expand Up @@ -1102,7 +1090,7 @@ input DAE.Function inElem;
output Boolean b;
algorithm
b := matchcontinue(inElem)
case(DAE.FUNCTION(inlineType=DAE.AFTER_INDEX_RED_INLINE)) then true;
case(DAE.FUNCTION(inlineType=DAE.AFTER_INDEX_RED_INLINE())) then true;
case(_) then false;
end matchcontinue;
end isAfterIndexInlineFunc;
Expand Down Expand Up @@ -2043,10 +2031,14 @@ public function getNamedFunction "Return the FUNCTION with the given name. Fails
algorithm
outElement := matchcontinue (path,functions)
local
String msg;
case (path,functions) then Util.getOption(avlTreeGet(functions, path));
case (path,_)
case (path,functions)
equation
Debug.fprintln("failtrace", "- DAEUtil.getNamedFunction failed " +& Absyn.pathString(path));
msg = Util.stringDelimitList(Util.listMapMap(getFunctionList(functions), functionName, Absyn.pathString), "\n ");
msg = "DAEUtil.getNamedFunction failed: " +& Absyn.pathString(path) +& "\nThe following functions were part of the cache:\n ";
// Error.addMessage(Error.INTERNAL_ERROR,{msg});
Debug.fprintln("failtrace", msg);
then
fail();
end matchcontinue;
Expand Down
25 changes: 13 additions & 12 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -546,8 +546,8 @@ algorithm
end matchcontinue;
end expand;

public function abs
"function: abs
public function expAbs
"function: expAbs
author: PA
Makes the expression absolute. i.e. non-negative."
input DAE.Exp inExp;
Expand Down Expand Up @@ -575,20 +575,20 @@ algorithm

case (DAE.UNARY(operator = DAE.UMINUS(ty = tp),exp = e))
equation
e_1 = abs(e);
e_1 = expAbs(e);
then
e_1;

case (DAE.BINARY(exp1 = e1,operator = op,exp2 = e2))
equation
e1_1 = abs(e1);
e2_1 = abs(e2);
e1_1 = expAbs(e1);
e2_1 = expAbs(e2);
then
DAE.BINARY(e1_1,op,e2_1);

case (e) then e;
end matchcontinue;
end abs;
end expAbs;

public function stripNoEvent
"Function that strips all noEvent() calls in an expression"
Expand Down Expand Up @@ -4735,7 +4735,7 @@ algorithm
case(DAE.ET_ARRAY(ty=t2))
then
isReal(t2);
case(DAE.ET_INT) then true;
case(DAE.ET_INT()) then true;
case(_) then false;
end matchcontinue;
end isInt;
Expand All @@ -4750,7 +4750,7 @@ algorithm
case(DAE.ET_ARRAY(ty=t2))
then
isReal(t2);
case(DAE.ET_REAL) then true;
case(DAE.ET_REAL()) then true;
case(_) then false;
end matchcontinue;
end isReal;
Expand Down Expand Up @@ -5331,17 +5331,18 @@ expCanBeZero(1+a^2) => false (all terms positive)
output Boolean canBeZero;
algorithm
canBeZero := matchcontinue(e)
local list<DAE.Exp> terms;
local
list<DAE.Exp> terms_;

case(e) equation
true = isConst(e) and not isZero(e);
then false;

/* For several terms, all must be positive or zero and at least one must be > 0 */
case(e) equation
(terms as _::_) = terms(e);
true = Util.listMapAllValue(terms,expIsPositiveOrZero,true);
_::_ = Util.listSelect(terms,expIsPositive);
(terms_ as _::_) = terms(e);
true = Util.listMapAllValue(terms_,expIsPositiveOrZero,true);
_::_ = Util.listSelect(terms_,expIsPositive);
then
false;

Expand Down
1 change: 0 additions & 1 deletion Compiler/FrontEnd/ExpressionDump.mo
Expand Up @@ -1620,7 +1620,6 @@ public function typeOfString
output String str;
protected
Type ty;
String str;
algorithm
ty := Expression.typeof(inExp);
str := typeString(ty);
Expand Down

0 comments on commit eb41dbe

Please sign in to comment.