Skip to content

Commit c5e16b0

Browse files
committed
Improved warnings/errors
* Add a warning if the specified module ordering will be ignored * Improve error message for invalid modules
1 parent ca7e447 commit c5e16b0

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7219,20 +7219,35 @@ protected function selectOptModules
72197219
protected
72207220
Boolean forceOrdering = Flags.getConfigBool(Flags.FORCE_RECOMMENDED_ORDERING);
72217221
String name;
7222+
Integer numModules = listLength(inOptModules);
7223+
array<Boolean> activeModules = arrayCreate(numModules, false);
7224+
Integer index;
7225+
Integer maxIndex = -1;
72227226
algorithm
72237227
if forceOrdering then
7224-
for module in inOptModules loop
7225-
(_, name) := module;
7226-
if listMember(name, inStrOptModules) then
7227-
outOptModules := module::outOptModules;
7228+
for name in inStrOptModules loop
7229+
index := getModuleIndex(name, inOptModules);
7230+
7231+
if index < maxIndex then
7232+
Error.addCompilerWarning("Specified ordering will be ignored. Use --" + Flags.configFlagName(Flags.FORCE_RECOMMENDED_ORDERING) + "=false to override module ordering.");
7233+
maxIndex := numModules;
7234+
else
7235+
maxIndex := intMax(maxIndex, index);
7236+
end if;
7237+
7238+
if index <> -1 then
7239+
activeModules[index] := true;
7240+
else
7241+
Error.addCompilerError("'" + name + "' is not a valid optimization module. Please check the flags carefully.");
7242+
fail();
72287243
end if;
72297244
end for;
72307245

7231-
// TODO: improve warning
7232-
if listLength(outOptModules) <> listLength(inStrOptModules) then
7233-
Error.addCompilerError("Specified modules are invalid.");
7234-
fail();
7235-
end if;
7246+
for i in 1:numModules loop
7247+
if activeModules[i] then
7248+
outOptModules := listGet(inOptModules, i)::outOptModules;
7249+
end if;
7250+
end for;
72367251
else
72377252
for name in inStrOptModules loop
72387253
outOptModules := selectOptModules1(name, inOptModules)::outOptModules;
@@ -7241,6 +7256,23 @@ algorithm
72417256
outOptModules := listReverse(outOptModules);
72427257
end selectOptModules;
72437258

7259+
protected function getModuleIndex
7260+
input String inModuleName;
7261+
input list<tuple<BackendDAEFunc.optimizationModule, String>> inModuleList;
7262+
output Integer outIndex = 1;
7263+
protected
7264+
String name;
7265+
algorithm
7266+
for module in inModuleList loop
7267+
(_, name) := module;
7268+
if stringEqual(inModuleName, name) then
7269+
return;
7270+
end if;
7271+
outIndex := outIndex+1;
7272+
end for;
7273+
outIndex := -1;
7274+
end getModuleIndex;
7275+
72447276
protected function selectOptModules1
72457277
input String strOptModule;
72467278
input list<tuple<BackendDAEFunc.optimizationModule, String>> inOptModules;

Compiler/Util/Flags.mo

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2637,6 +2637,14 @@ algorithm
26372637
DEBUG_FLAG(name = name) := inFlag;
26382638
end debugFlagName;
26392639

2640+
public function configFlagName
2641+
"Prints out name of a debug flag."
2642+
input ConfigFlag inFlag;
2643+
output String name;
2644+
algorithm
2645+
CONFIG_FLAG(name = name) := inFlag;
2646+
end configFlagName;
2647+
26402648
protected function getValidStringOptions
26412649
input ValidOptions inOptions;
26422650
output list<String> validOptions;

0 commit comments

Comments
 (0)