Skip to content

Commit

Permalink
Add flag --dumpFlatModel (#8204)
Browse files Browse the repository at this point in the history
- Add flag --dumpFlatModel that can be used to dump the flat model at
  chosen stages of the frontend.
- Remove old flag -d=nfDumpFlat which is superseded by the new flag.
- Remove FrontEnd/NFInstUtil.mo since it's barely used, and only by the
  old frontend which already has equivalent functions.
- Add NFFrontEnd/NFInstUtil.mo and move some of the utility functions in
  NFInst to it, which includes functions for dumping the flat model.
  • Loading branch information
perost committed Nov 23, 2021
1 parent 25b5073 commit 9f0cb45
Show file tree
Hide file tree
Showing 17 changed files with 401 additions and 374 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/.cmake/meta_modelica_source_list.cmake
Expand Up @@ -44,7 +44,6 @@ set(OMC_MM_ALWAYS_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/FrontEnd/MMath.mo
${CMAKE_CURRENT_SOURCE_DIR}/FrontEnd/Mod.mo
# Remember: Only files needed for compiling MetaModelica
${CMAKE_CURRENT_SOURCE_DIR}/FrontEnd/NFInstUtil.mo
${CMAKE_CURRENT_SOURCE_DIR}/FrontEnd/OperatorOverloading.mo
${CMAKE_CURRENT_SOURCE_DIR}/FrontEnd/Parser.mo
${CMAKE_CURRENT_SOURCE_DIR}/FrontEnd/ParserExt.mo
Expand Down Expand Up @@ -333,6 +332,7 @@ set(OMC_MM_BACKEND_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/NFFrontEnd/NFInstContext.mo
${CMAKE_CURRENT_SOURCE_DIR}/NFFrontEnd/NFInst.mo
${CMAKE_CURRENT_SOURCE_DIR}/NFFrontEnd/NFInstNode.mo
${CMAKE_CURRENT_SOURCE_DIR}/NFFrontEnd/NFInstUtil.mo
${CMAKE_CURRENT_SOURCE_DIR}/NFFrontEnd/NFLookup.mo
${CMAKE_CURRENT_SOURCE_DIR}/NFFrontEnd/NFLookupState.mo
${CMAKE_CURRENT_SOURCE_DIR}/NFFrontEnd/NFLookupTree.mo
Expand Down
5 changes: 2 additions & 3 deletions OMCompiler/Compiler/FrontEnd/InstSection.mo
Expand Up @@ -69,7 +69,6 @@ protected import InstDAE;
protected import InstFunction;
protected import InstTypes;
protected import InstUtil;
protected import NFInstUtil;
protected import List;
protected import Lookup;
protected import Patternm;
Expand Down Expand Up @@ -4240,8 +4239,8 @@ algorithm
crefExp1 = Expression.crefExp(c1_1);
crefExp2 = Expression.crefExp(c2_1);
// Evaluate constant crefs away
const1 = NFInstUtil.toConst(vt1);
const2 = NFInstUtil.toConst(vt2);
const1 = Types.variabilityToConst(vt1);
const2 = Types.variabilityToConst(vt2);
(cache, crefExp1) = Ceval.cevalIfConstant(cache, env, crefExp1, DAE.PROP(t1,const1), true, info);
(cache, crefExp2) = Ceval.cevalIfConstant(cache, env, crefExp2, DAE.PROP(t2,const2), true, info);

Expand Down
5 changes: 2 additions & 3 deletions OMCompiler/Compiler/FrontEnd/InstVar.mo
Expand Up @@ -70,7 +70,6 @@ protected import Types;
protected import PrefixUtil;
protected import List;
protected import ComponentReference;
protected import NFInstUtil;
protected import UnitAbsynBuilder;
protected import Flags;
protected import Expression;
Expand Down Expand Up @@ -599,7 +598,7 @@ algorithm

source := ElementSource.createElementSource(inInfo, FGraph.getScopePath(inEnv), inPrefix);
(outCache, outDae) := addArrayVarEquation(outCache, inEnv, outIH, inState,
outDae, outType, mod, NFInstUtil.toConst(SCodeUtil.attrVariability(attr)),
outDae, outType, mod, Types.variabilityToConst(SCodeUtil.attrVariability(attr)),
inPrefix, inName, source);
outCache := InstFunction.addRecordConstructorFunction(outCache, inEnv,
Types.arrayElementType(outType), SCodeUtil.elementInfo(inClass));
Expand Down Expand Up @@ -1163,7 +1162,7 @@ algorithm
mod = if not listEmpty(inSubscripts) and not SCodeUtil.isParameterOrConst(vt) and not ClassInf.isFunctionOrRecord(inState) and not Types.isComplexType(Types.arrayElementType(ty)) and not Types.isExternalObject(Types.arrayElementType(ty)) and not Config.scalarizeBindings()
then DAE.NOMOD()
else inMod;
opt_binding = InstBinding.makeVariableBinding(ty, mod, NFInstUtil.toConst(vt), inPrefix, inName);
opt_binding = InstBinding.makeVariableBinding(ty, mod, Types.variabilityToConst(vt), inPrefix, inName);
start = InstBinding.instStartBindingExp(inMod /* Yup, let's keep the start-binding. It seems sane. */, ty, vt);
// Propagate the final prefix from the modifier.
//fin = InstUtil.propagateModFinal(mod, fin);
Expand Down
240 changes: 0 additions & 240 deletions OMCompiler/Compiler/FrontEnd/NFInstUtil.mo

This file was deleted.

28 changes: 23 additions & 5 deletions OMCompiler/Compiler/NFFrontEnd/NFFlatModel.mo
Expand Up @@ -113,12 +113,33 @@ public
function toString
input FlatModel flatModel;
input Boolean printBindingTypes = false;
output String str;
output String str = IOStream.string(toStream(flatModel, printBindingTypes));
end toString;

function printString
input FlatModel flatModel;
input Boolean printBindingTypes = false;
protected
IOStream.IOStream s;
algorithm
s := toStream(flatModel, printBindingTypes);
IOStream.print(s, IOStream.stdOutput);
end printString;

function toStream
input FlatModel flatModel;
input Boolean printBindingTypes = false;
output IOStream.IOStream s;
algorithm
s := IOStream.create(getInstanceName(), IOStream.IOStreamType.LIST());
s := appendStream(flatModel, printBindingTypes, s);
end toStream;

function appendStream
input FlatModel flatModel;
input Boolean printBindingTypes = false;
input output IOStream.IOStream s;
algorithm
s := IOStream.append(s, "class " + flatModel.name + "\n");

for v in flatModel.variables loop
Expand Down Expand Up @@ -151,10 +172,7 @@ public
end for;

s := IOStream.append(s, "end " + flatModel.name + ";\n");

str := IOStream.string(s);
IOStream.delete(s);
end toString;
end appendStream;

function toFlatString
"Returns a string containing the flat Modelica representation of the given model."
Expand Down
3 changes: 3 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -95,6 +95,7 @@ import UnorderedMap;
import UnorderedSet;
import Inline = NFInline;
import ExpandExp = NFExpandExp;
import InstUtil = NFInstUtil;

public
type FunctionTree = FunctionTreeImpl.Tree;
Expand Down Expand Up @@ -181,12 +182,14 @@ algorithm
end match;

execStat(getInstanceName());
InstUtil.dumpFlatModelDebug("flatten", flatModel);

if settings.arrayConnect then
flatModel := resolveArrayConnections(flatModel);
else
flatModel := resolveConnections(flatModel, deleted_vars);
end if;
InstUtil.dumpFlatModelDebug("connections", flatModel);
end flatten;

function collectFunctions
Expand Down

0 comments on commit 9f0cb45

Please sign in to comment.