Skip to content

Commit

Permalink
Implement --showStructuralAnnotations flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jan 25, 2019
1 parent 547468f commit e3d42ec
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 11 deletions.
36 changes: 33 additions & 3 deletions Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -748,9 +748,18 @@ algorithm
SCode.Mod ann_mod;

case (SOME(SCode.COMMENT(annotation_ = SOME(SCode.ANNOTATION(ann_mod)))), _, _)
equation
true = Config.showAnnotations();
ann = inPrefix + "annotation" + SCodeDump.printModStr(ann_mod,SCodeDump.defaultOptions) + inSuffix;
algorithm
if Config.showAnnotations() then
ann := inPrefix + "annotation" + SCodeDump.printModStr(ann_mod, SCodeDump.defaultOptions) + inSuffix;
elseif Config.showStructuralAnnotations() then
ann_mod := filterStructuralMods(ann_mod);

if not SCode.isEmptyMod(ann_mod) then
ann := inPrefix + "annotation" + SCodeDump.printModStr(ann_mod, SCodeDump.defaultOptions) + inSuffix;
end if;
else
ann := "";
end if;
then
ann;

Expand All @@ -759,6 +768,27 @@ algorithm
end matchcontinue;
end dumpAnnotationStr;

public function filterStructuralMods
input output SCode.Mod mod;
algorithm
mod := SCode.filterSubMods(mod, filterStructuralMod);
end filterStructuralMods;

public function filterStructuralMod
input SCode.SubMod mod;
output Boolean keep;
algorithm
keep := match mod.ident
case "Evaluate" then true;
case "Inline" then true;
case "LateInline" then true;
case "derivative" then true;
case "inverse" then true;
case "smoothOrder" then true;
else false;
end match;
end filterStructuralMod;

public function dumpCommentAnnotationStr
input Option<SCode.Comment> inComment;
output String outString;
Expand Down
24 changes: 24 additions & 0 deletions Compiler/FrontEnd/SCode.mo
Expand Up @@ -656,6 +656,30 @@ algorithm
end match;
end stripSubmod;

function filterSubMods
"Removes submods from a modifier based on a filter function."
input output Mod mod;
input FilterFunc filter;

partial function FilterFunc
input SubMod submod;
output Boolean keep;
end FilterFunc;
algorithm
mod := match mod
case MOD()
algorithm
mod.subModLst := list(m for m guard filter(m) in mod.subModLst);
then
match mod
case MOD(subModLst = {}, binding = NONE()) then NOMOD();
else mod;
end match;

else mod;
end match;
end filterSubMods;

public function getElementNamed
"Return the Element with the name given as first argument from the Class."
input Ident inIdent;
Expand Down
8 changes: 8 additions & 0 deletions Compiler/Template/DAEDumpTV.mo
Expand Up @@ -130,6 +130,10 @@ package Config
output Boolean outShowAnnotations;
end showAnnotations;

function showStructuralAnnotations
output Boolean outShowAnnotations;
end showStructuralAnnotations;

function showStartOrigin
output Boolean show;
end showStartOrigin;
Expand Down Expand Up @@ -216,6 +220,10 @@ uniontype functionList
end FUNCTION_LIST;
end functionList;

function filterStructuralMods
input SCode.Mod mod;
output SCode.Mod outMod;
end filterStructuralMods;

end DAEDump;

Expand Down
14 changes: 7 additions & 7 deletions Compiler/Template/DAEDumpTpl.tpl
Expand Up @@ -1032,19 +1032,19 @@ template dumpCompAnnotation(Option<SCode.Comment> comment)
end dumpCompAnnotation;

template dumpCommentAnnotation(Option<SCode.Comment> comment)
::=
if Config.showAnnotations() then
match comment
case SOME(cmt) then
dumpCommentAnnotationNoOpt(cmt)
::= match comment case SOME(cmt) then dumpCommentAnnotationNoOpt(cmt)
end dumpCommentAnnotation;

template dumpCommentAnnotationNoOpt(SCode.Comment comment)
::=
if Config.showAnnotations() then
match comment
case SCode.COMMENT(annotation_ = SOME(SCode.ANNOTATION(modification = ann_mod))) then
'annotation<%SCodeDumpTpl.dumpModifier(ann_mod, SCodeDump.defaultOptions)%>'
if Config.showAnnotations() then
'annotation<%SCodeDumpTpl.dumpModifier(ann_mod, SCodeDump.defaultOptions)%>'
else if Config.showStructuralAnnotations() then
let ann_str = SCodeDumpTpl.dumpModifier(DAEDump.filterStructuralMods(ann_mod), SCodeDump.defaultOptions)
if ann_str then
'annotation<%ann_str%>'
end dumpCommentAnnotationNoOpt;

template dumpCommentOpt(Option<SCode.Comment> comment)
Expand Down
6 changes: 6 additions & 0 deletions Compiler/Util/Config.mo
Expand Up @@ -249,6 +249,12 @@ algorithm
Flags.setConfigBool(Flags.SHOW_ANNOTATIONS, show);
end setShowAnnotations;

public function showStructuralAnnotations
output Boolean show;
algorithm
show := Flags.getConfigBool(Flags.SHOW_STRUCTURAL_ANNOTATIONS);
end showStructuralAnnotations;

public function showStartOrigin
output Boolean show;
algorithm
Expand Down
7 changes: 6 additions & 1 deletion Compiler/Util/Flags.mo
Expand Up @@ -1477,6 +1477,10 @@ constant ConfigFlag SINGLE_INSTANCE_AGLSOLVER = CONFIG_FLAG(127, "singleInstance
NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(),
Util.gettext("Sets to instantiate only one algebraic loop solver all algebraic loops"));

constant ConfigFlag SHOW_STRUCTURAL_ANNOTATIONS = CONFIG_FLAG(128, "showStructuralAnnotations",
NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(),
Util.gettext("Show annotations affecting the solution process in the flattened code."));

protected
// This is a list of all configuration flags. A flag can not be used unless it's
// in this list, and the list is checked at initialization so that all flags are
Expand Down Expand Up @@ -1608,7 +1612,8 @@ constant list<ConfigFlag> allConfigFlags = {
POST_OPT_MODULES_DAE,
EVAL_LOOP_LIMIT,
EVAL_RECURSION_LIMIT,
SINGLE_INSTANCE_AGLSOLVER
SINGLE_INSTANCE_AGLSOLVER,
SHOW_STRUCTURAL_ANNOTATIONS
};

public function new
Expand Down

0 comments on commit e3d42ec

Please sign in to comment.