Skip to content

Commit

Permalink
- fix Compiler/boot for Windows (seems to work OK now)
Browse files Browse the repository at this point in the history
  * propagate the $defaultMakefileTarget as is different for Windows/Linux
  * use forward slash in Parser.parse filenames
  * remove MessagePack.mo and SerializeModelInfo.mo from Compiler/boot/LoadCompilerSources.mos as they are *not portable* yet
- add FFrontEnd files to the compilation
  * add builtin graph creation to Builtin.mo
  * add calls to FInst in CevalScript.mo


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19978 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Apr 4, 2014
1 parent a66c321 commit efd6fa0
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 28 deletions.
184 changes: 184 additions & 0 deletions Compiler/FrontEnd/Builtin.mo
Expand Up @@ -45,11 +45,14 @@ public import DAE;
public import Env;
public import Error;
public import SCode;
public import FCore;
public import FGraph;

// protected imports
protected import ClassInf;
protected import Config;
protected import Flags;
protected import FGraphBuild;
protected import Global;
protected import List;
protected import Parser;
Expand Down Expand Up @@ -805,5 +808,186 @@ algorithm
end matchcontinue;
end getSetInitialEnv;

public function initialFGraph
"The initial environment where instantiation takes place is built
up using this function. It creates an empty environment and adds
all the built-in definitions to it.
NOTE:
The following built in operators can not be described in
the type system, since they e.g. have arbitrary arguments, etc.
- fill
- cat
These operators are catched in the elabBuiltinHandler, along with all
others."
input Env.Cache inCache;
output Env.Cache outCache;
output FGraph.Graph graph;
protected
Env.Cache cache;
algorithm
(outCache, graph) := matchcontinue(inCache)
local
list<Absyn.Class> initialClasses;
SCode.Program initialProgram;

/*/ First look for cached version
case (cache) equation
graph = Graph.getCachedInitialFGraph(cache);
then (cache,graph);
// then look in the global roots[builtinEnvIndex]
case (cache)
equation
graph = getSetInitialFGraph(NONE());
then
(cache, graph);*/

// if no cached version found create initial graph.
case (cache)
equation
graph = FGraph.new(FCore.dummyTopModel);
graph = FGraphBuild.mkProgramGraph(
{rlType,
intType,
strType,
boolType,
enumType,
ExternalObjectType,
realType,
integerType,
stringType,
booleanType,
stateSelectType,
uncertaintyType},
FCore.BASIC_TYPE(),
graph);


graph = FGraphBuild.mkCompNode(timeComp, FGraph.top(graph), FCore.BUILTIN(), graph);

graph = initialFGraphOptimica(graph);

graph = initialFGraphMetaModelica(graph);

Absyn.PROGRAM(classes=initialClasses) = getInitialFunctions();
initialProgram = listReverse(List.fold(initialClasses, SCodeUtil.translate2, {}));
// add the ModelicaBuiltin/MetaModelicaBuiltin classes in the initial graph
graph = FGraphBuild.mkProgramGraph(initialProgram, FCore.BUILTIN(), graph);

graph = FGraphBuild.mkTypeNode(
{anyNonExpandableConnector2int,
anyExpandableConnector2int},
"cardinality", graph);
graph = FGraphBuild.mkTypeNode({enumeration2int}, "Integer", graph);
graph = FGraphBuild.mkTypeNode({enumeration2int}, "EnumToInteger", graph);
graph = FGraphBuild.mkTypeNode({real2real}, "noEvent", graph);
graph = FGraphBuild.mkTypeNode({real2real}, "actualStream", graph);
graph = FGraphBuild.mkTypeNode({real2real}, "inStream", graph);
graph = FGraphBuild.mkTypeNode({realrealreal2real,
array1dimrealarray1dimrealarray1dimreal2array1dimreal,
array1dimrealarray1dimrealarray1dimreal2array1dimreal},
"constrain", graph);
then
(cache,graph);

end matchcontinue;
end initialFGraph;

protected function getSetInitialFGraph
"gets/sets the initial environment depending on grammar flags"
input Option<FGraph.Graph> inEnvOpt;
output FGraph.Graph initialEnv;
algorithm
initialEnv := matchcontinue (inEnvOpt)
local
list<tuple<Integer,FGraph.Graph>> assocLst;
FGraph.Graph graph;

// nothing there
case (_)
equation
failure(_ = getGlobalRoot(Global.builtinFGraphIndex));
setGlobalRoot(Global.builtinFGraphIndex,FGraph.new(FCore.dummyTopModel));
then
fail();

// return the correct graph depending on flags
case (NONE())
equation
assocLst = getGlobalRoot(Global.builtinFGraphIndex);
then
Util.assoc(Flags.getConfigEnum(Flags.GRAMMAR), assocLst);

case (SOME(graph))
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.METAMODELICA);
assocLst = getGlobalRoot(Global.builtinFGraphIndex);
setGlobalRoot(Global.builtinFGraphIndex, (Flags.METAMODELICA,graph)::assocLst);
then
graph;

case (SOME(graph))
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PARMODELICA);
assocLst = getGlobalRoot(Global.builtinFGraphIndex);
setGlobalRoot(Global.builtinFGraphIndex, (Flags.PARMODELICA,graph)::assocLst);
then
graph;

case (SOME(graph))
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.MODELICA) or intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.OPTIMICA);
assocLst = getGlobalRoot(Global.builtinFGraphIndex);
setGlobalRoot(Global.builtinFGraphIndex, (Flags.MODELICA,graph)::assocLst);
then
graph;
end matchcontinue;
end getSetInitialFGraph;

protected function initialFGraphMetaModelica
input FGraph.Graph inEnv;
output FGraph.Graph outEnv;
algorithm
outEnv := matchcontinue(inEnv)
local
FGraph.Graph graph;

case (graph)
equation
true = Config.acceptMetaModelicaGrammar();
// getGlobalRoot can not be represented by a regular function...
graph = FGraphBuild.mkTypeNode({int2boxed}, "getGlobalRoot", graph);
then
graph;

case graph then graph;

end matchcontinue;
end initialFGraphMetaModelica;

protected function initialFGraphOptimica
input FGraph.Graph inEnv;
output FGraph.Graph outEnv;
algorithm
outEnv := matchcontinue(inEnv)
local
FGraph.Graph graph;

case (graph)
equation
//If Optimica add the startTime,finalTime,objectiveIntegrand and objective "builtin" variables.
true = Config.acceptOptimicaGrammar();
graph = FGraphBuild.mkCompNode(objectiveVarComp, FGraph.top(graph), FCore.BUILTIN(), graph);
graph = FGraphBuild.mkCompNode(objectiveIntegrandComp, FGraph.top(graph), FCore.BUILTIN(), graph);
graph = FGraphBuild.mkCompNode(startTimeComp, FGraph.top(graph), FCore.BUILTIN(), graph);
graph = FGraphBuild.mkCompNode(finalTimeComp, FGraph.top(graph), FCore.BUILTIN(), graph);
then
graph;

case graph then graph;

end matchcontinue;
end initialFGraphOptimica;

end Builtin;

2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Parser.mo
Expand Up @@ -83,7 +83,7 @@ public function parsebuiltin "Like parse, but skips the SCode check to avoid inf
protected
String realpath;
algorithm
realpath := System.realpath(filename);
realpath := Util.replaceWindowsBackSlashWithPathDelimiter(System.realpath(filename));
outProgram := ParserExt.parse(realpath, Util.testsuiteFriendly(realpath), Config.acceptedGrammar(), encoding, Flags.getConfigEnum(Flags.LANGUAGE_STANDARD), Config.getRunningTestsuite());
end parsebuiltin;

Expand Down
2 changes: 1 addition & 1 deletion Compiler/Global/Global.mo
Expand Up @@ -53,7 +53,7 @@ constant Integer builtinEnvIndex = 13;
constant Integer profilerTime1Index = 14;
constant Integer profilerTime2Index = 15;
constant Integer flagsIndex = 16;
constant Integer builtinGraphEnvIndex = 17;
constant Integer builtinFGraphIndex = 17;
constant Integer rewriteRulesIndex = 18;

// indexes in System.tick
Expand Down
22 changes: 18 additions & 4 deletions Compiler/Makefile.common
Expand Up @@ -22,15 +22,16 @@ $(srcdir)/runtime/runtime.a \
$(srcdir)/modpar/libmodpar.a

FRONTEND_DIR=$(srcdir)/FrontEnd
FFRONTEND_DIR=$(srcdir)/FFrontEnd
BACKEND_DIR=$(srcdir)/BackEnd
GLOBAL_DIR=$(srcdir)/Global
TEMPLATE_DIR=$(srcdir)/Template
SCRIPT_DIR=$(srcdir)/Script
UTIL_DIR=$(srcdir)/Util
MAIN_DIR=$(srcdir)/Main
ALL_DIRS = $(FRONTEND_DIR) $(BACKEND_DIR) $(TEMPLATE_DIR) $(UTIL_DIR) $(SCRIPT_DIR) $(MAIN_DIR) $(GLOBAL_DIR)
RML_INCLUDE_ALL_DIRS = -I$(FRONTEND_DIR) -I$(BACKEND_DIR) -I$(TEMPLATE_DIR) -I$(UTIL_DIR) -I$(SCRIPT_DIR) -I$(MAIN_DIR) -I$(GLOBAL_DIR)
RMLC_INCLUDE_ALL_DIRS = -I$(FRONTEND_DIR),-I$(BACKEND_DIR),-I$(TEMPLATE_DIR),-I$(UTIL_DIR),-I$(SCRIPT_DIR),-I$(MAIN_DIR),-I$(GLOBAL_DIR)
ALL_DIRS = $(FRONTEND_DIR) $(FFRONTEND_DIR) $(BACKEND_DIR) $(TEMPLATE_DIR) $(UTIL_DIR) $(SCRIPT_DIR) $(MAIN_DIR) $(GLOBAL_DIR)
RML_INCLUDE_ALL_DIRS = -I$(FRONTEND_DIR) -I$(FFRONTEND_DIR) -I$(BACKEND_DIR) -I$(TEMPLATE_DIR) -I$(UTIL_DIR) -I$(SCRIPT_DIR) -I$(MAIN_DIR) -I$(GLOBAL_DIR)
RMLC_INCLUDE_ALL_DIRS = -I$(FRONTEND_DIR),-I$(FFRONTEND_DIR),-I$(BACKEND_DIR),-I$(TEMPLATE_DIR),-I$(UTIL_DIR),-I$(SCRIPT_DIR),-I$(MAIN_DIR),-I$(GLOBAL_DIR)

FRONTEND = \
Absyn.mo \
Expand Down Expand Up @@ -123,6 +124,19 @@ UnitChecker.mo \
Values.mo \
ValuesUtil.mo

FFRONTEND = \
FCore.mo \
FExpand.mo \
FGraph.mo \
FGraphBuild.mo \
FGraphDump.mo \
FInst.mo \
FLookup.mo \
FNode.mo \
FResolve.mo \
FVisit.mo \
FTraverse.mo

BACKEND = \
BackendDAE.mo \
BackendDAEFunc.mo \
Expand Down Expand Up @@ -269,7 +283,7 @@ FMIExt.mo \


# all modules
SRCMO = $(FRONTEND) $(BACKEND) $(GLOBAL) $(TEMPLATE) $(UTIL) $(SCRIPT) $(MAIN)
SRCMO = $(FRONTEND) $(FFRONTEND) $(BACKEND) $(GLOBAL) $(TEMPLATE) $(UTIL) $(SCRIPT) $(MAIN)
ALLMO = $(SRCMO) $(EXTERNAL)
SRCC = $(SRCMO:%.mo=%.c)
SRCH = $(SRCC:%.c=%.h)
Expand Down
1 change: 1 addition & 0 deletions Compiler/Makefile.compiler_subdirs.common
Expand Up @@ -16,6 +16,7 @@ SRCHSRCDIR = $(SRCH:%.h=$(srcdir)/%.h)
.PHONY: all vctarget absyn_subdir clean reallyclean nolink $(SUBDIRS) $(PROG)

vpath %.mo $(FRONTEND_DIR)
vpath %.mo $(FFRONTEND_DIR)
vpath %.mo $(BACKEND_DIR)
vpath %.mo $(GLOBAL_DIR)
vpath %.mo $(TEMPLATE_DIR)
Expand Down
20 changes: 20 additions & 0 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -88,6 +88,7 @@ protected import Expression;
protected import ExpressionDump;
protected import FindZeroCrossings;
protected import Flags;
protected import FInst;
protected import Global;
protected import Graph;
protected import HashSetString;
Expand Down Expand Up @@ -3385,8 +3386,26 @@ algorithm
NFEnv.Env nfenv;
DAE.FunctionTree funcs;

case (cache,env,_,GlobalScript.SYMBOLTABLE(p,fp,ic,iv,cf,lf),_,_)
equation
true = Flags.isSet(Flags.GRAPH_INST);
false = Flags.isSet(Flags.SCODE_INST);
str = Absyn.pathString(className);
(absynClass as Absyn.CLASS(restriction = restriction)) = Interactive.getPathedClassInProgram(className, p);
re = Absyn.restrString(restriction);
Error.assertionOrAddSourceMessage(relaxedFrontEnd or not (Absyn.isFunctionRestriction(restriction) or Absyn.isPackageRestriction(restriction)),
Error.INST_INVALID_RESTRICTION,{str,re},Absyn.dummyInfo);
(p,true) = loadModel(Interactive.getUsesAnnotationOrDefault(Absyn.PROGRAM({absynClass},Absyn.TOP(),Absyn.dummyTimeStamp)),Settings.getModelicaPath(Config.getRunningTestsuite()),p,false,true);

scodeP = SCodeUtil.translateAbsyn2SCode(p);
dae = FInst.inst(className, scodeP);
ic_1 = ic;
then
(cache,env,dae,GlobalScript.SYMBOLTABLE(p,fp,ic_1,iv,cf,lf));

case (_, _, _, GlobalScript.SYMBOLTABLE(p, fp, ic, iv, cf, lf), _, _)
equation
false = Flags.isSet(Flags.GRAPH_INST);
true = Flags.isSet(Flags.SCODE_INST);
scodeP = SCodeUtil.translateAbsyn2SCode(p);
// remove extends Modelica.Icons.*
Expand All @@ -3409,6 +3428,7 @@ algorithm

case (cache,env,_,GlobalScript.SYMBOLTABLE(p,fp,ic,iv,cf,lf),_,_)
equation
false = Flags.isSet(Flags.GRAPH_INST);
false = Flags.isSet(Flags.SCODE_INST);
str = Absyn.pathString(className);
(absynClass as Absyn.CLASS(restriction = restriction)) = Interactive.getPathedClassInProgram(className, p);
Expand Down
13 changes: 13 additions & 0 deletions Compiler/Util/List.mo
Expand Up @@ -9717,4 +9717,17 @@ algorithm
end match;
end toListWithPositions;

public function mkOption
"@author: adrpo
make NONE() if the list is empty
make SOME(list) if the list is not empty"
input list<ElementType> inList;
output Option<list<ElementType>> outOption;
algorithm
outOption := match(inList)
case ({}) then NONE();
case (_) then SOME(inList);
end match;
end mkOption;

end List;
2 changes: 1 addition & 1 deletion Compiler/Util/Util.mo
Expand Up @@ -2520,7 +2520,7 @@ algorithm
s := intString(tick());
end tickStr;

protected function replaceWindowsBackSlashWithPathDelimiter
public function replaceWindowsBackSlashWithPathDelimiter
"@author: adrpo
replace \\ with path delimiter only in Windows!"
input String inPath;
Expand Down
17 changes: 15 additions & 2 deletions Compiler/boot/LoadCompilerSources.mos
Expand Up @@ -4,8 +4,8 @@
if true then /* Suppress output */
setCommandLineOptions("+g=MetaModelica");
files := {
"../Util/MessagePack.mo", // TODO: Add once we bootstrapped omc
"../BackEnd/SerializeModelInfo.mo", // TODO: Add once we bootstrapped omc
//"../Util/MessagePack.mo", // TODO: Add once we bootstrapped omc
//"../BackEnd/SerializeModelInfo.mo", // TODO: Add once we bootstrapped omc
"../FrontEnd/Absyn.mo",
"../FrontEnd/Algorithm.mo",
"../FrontEnd/Builtin.mo",
Expand Down Expand Up @@ -97,6 +97,19 @@ if true then /* Suppress output */
"../FrontEnd/UnitParserExt.mo",
"../FrontEnd/Values.mo",
"../FrontEnd/ValuesUtil.mo",

// "FFrontEnd";
"../FFrontEnd/FCore.mo",
"../FFrontEnd/FExpand.mo",
"../FFrontEnd/FGraph.mo",
"../FFrontEnd/FGraphBuild.mo",
"../FFrontEnd/FGraphDump.mo",
"../FFrontEnd/FInst.mo",
"../FFrontEnd/FLookup.mo",
"../FFrontEnd/FNode.mo",
"../FFrontEnd/FResolve.mo",
"../FFrontEnd/FTraverse.mo",
"../FFrontEnd/FVisit.mo",

// "BackEnd";
"../BackEnd/BackendDAE.mo",
Expand Down

0 comments on commit efd6fa0

Please sign in to comment.