Skip to content

Commit 3433e83

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Fixes for bootstrapping PDEModelica
1 parent 85b39a0 commit 3433e83

File tree

3 files changed

+94
-83
lines changed

3 files changed

+94
-83
lines changed

Compiler/FrontEnd/InstUtil.mo

Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -8732,7 +8732,7 @@ end propagateModFinal;
87328732
//------ PDE extension: ------
87338733
//------------------------------
87348734

8735-
public type DomainFieldsLst = List<tuple<DAE.ComponentRef,List<Absyn.ComponentRef>>>;
8735+
public type DomainFieldsLst = list<tuple<DAE.ComponentRef,list<Absyn.ComponentRef>>>;
87368736

87378737
public function elabField
87388738
//For field variables: finds the "domain" modifier,
@@ -8834,14 +8834,14 @@ protected function findN
88348834
"a map function to find N in domain class modifiers"
88358835
input DAE.Var inVar;
88368836
output Option<Integer> optN;
8837-
algorithm
8838-
optN := match inVar
8837+
algorithm
8838+
optN := match inVar
88398839
local
88408840
Integer N;
8841-
case DAE.TYPES_VAR(name="N",binding=DAE.Binding.EQBOUND(evaluatedExp=SOME(Values.INTEGER(N))))
8842-
then SOME(N);
8843-
else NONE();
8844-
end match;
8841+
case DAE.TYPES_VAR(name="N",binding=DAE.EQBOUND(evaluatedExp=SOME(Values.INTEGER(N))))
8842+
then SOME(N);
8843+
else NONE();
8844+
end match;
88458845
end findN;
88468846

88478847
protected function addEach
@@ -8923,84 +8923,84 @@ public function discretizePDE
89238923
output List<SCode.Equation> outDiscretizedEQs;
89248924
protected List<SCode.Equation> newDiscretizedEQs;
89258925
algorithm
8926-
newDiscretizedEQs := {inEQ};
8927-
//TODO: fix:
8928-
8929-
newDiscretizedEQs := matchcontinue inEQ
8930-
local
8931-
Absyn.Exp lhs_exp, rhs_exp;
8932-
Absyn.ComponentRef domainCr, domainCr1, fieldCr;
8933-
SCode.Comment comment;
8934-
SCode.SourceInfo info;
8935-
Integer N;
8936-
List<Absyn.ComponentRef> fieldLst;
8937-
Absyn.Ident name;
8938-
list<Absyn.Subscript> subscripts;
8939-
//Normal equation withhout domain specified, no field variables present:
8940-
case SCode.EQUATION(SCode.EQ_EQUALS())
8941-
then {inEQ};
8942-
//PDE with domain specified, allow for field variables:
8943-
case SCode.EQUATION(SCode.EQ_PDE(expLeft = lhs_exp, expRight = rhs_exp,
8944-
domain = domainCr as Absyn.CREF_IDENT(), comment = comment, info = info))
8945-
equation
8946-
(N,fieldLst) = getDomNFields(inDomFieldLst,domainCr,info);
8947-
// then list(newEQFun(i, lhs_exp, rhs_exp, domainCr, comment, info, fieldLst) for i in 2:N-1);
8948-
then creatFieldEqs(lhs_exp, rhs_exp, domainCr, N, comment, info, fieldLst);
8949-
//same as previous but with ".interior"
8950-
case SCode.EQUATION(SCode.EQ_PDE(expLeft = lhs_exp, expRight = rhs_exp,
8951-
domain = domainCr as Absyn.CREF_QUAL(name, subscripts, Absyn.CREF_IDENT(name="interior")),
8952-
comment = comment, info = info))
8953-
equation
8954-
domainCr1 = Absyn.CREF_IDENT(name, subscripts);
8955-
(N,fieldLst) = getDomNFields(inDomFieldLst,domainCr1,info);
8956-
// then list(newEQFun(i, lhs_exp, rhs_exp, domainCr1, comment, info, fieldLst) for i in 2:N-1);
8957-
then creatFieldEqs(lhs_exp, rhs_exp, domainCr, N, comment, info, fieldLst);
8958-
8959-
//left boundary extrapolation
8960-
case SCode.EQUATION(SCode.EQ_PDE(expLeft = lhs_exp, expRight = rhs_exp,
8961-
domain = domainCr as Absyn.CREF_QUAL(name, subscripts, Absyn.CREF_IDENT(name="left")),
8962-
comment = comment, info = info))
8963-
equation
8964-
// Absyn.CALL(function_ = Absyn.CREF_IDENT(name="extrapolateField", subscripts={}), functionArgs = Absyn.FUNCTIONARGS(args = {})) = rhs_exp;
8965-
// Absyn.CREF(fieldCr as Absyn.CREF_IDENT()) = lhs_exp;
8926+
newDiscretizedEQs := {inEQ};
8927+
//TODO: fix:
8928+
8929+
newDiscretizedEQs := matchcontinue inEQ
8930+
local
8931+
Absyn.Exp lhs_exp, rhs_exp;
8932+
Absyn.ComponentRef domainCr, domainCr1, fieldCr;
8933+
SCode.Comment comment;
8934+
SCode.SourceInfo info;
8935+
Integer N;
8936+
List<Absyn.ComponentRef> fieldLst;
8937+
Absyn.Ident name;
8938+
list<Absyn.Subscript> subscripts;
8939+
//Normal equation withhout domain specified, no field variables present:
8940+
case SCode.EQUATION(SCode.EQ_EQUALS())
8941+
then {inEQ};
8942+
//PDE with domain specified, allow for field variables:
8943+
case SCode.EQUATION(SCode.EQ_PDE(expLeft = lhs_exp, expRight = rhs_exp,
8944+
domain = domainCr as Absyn.CREF_IDENT(), comment = comment, info = info))
8945+
equation
8946+
(N,fieldLst) = getDomNFields(inDomFieldLst,domainCr,info);
8947+
// then list(newEQFun(i, lhs_exp, rhs_exp, domainCr, comment, info, fieldLst) for i in 2:N-1);
8948+
then creatFieldEqs(lhs_exp, rhs_exp, domainCr, N, comment, info, fieldLst);
8949+
//same as previous but with ".interior"
8950+
case SCode.EQUATION(SCode.EQ_PDE(expLeft = lhs_exp, expRight = rhs_exp,
8951+
domain = domainCr as Absyn.CREF_QUAL(name, subscripts, Absyn.CREF_IDENT(name="interior")),
8952+
comment = comment, info = info))
8953+
equation
8954+
domainCr1 = Absyn.CREF_IDENT(name, subscripts);
8955+
(N,fieldLst) = getDomNFields(inDomFieldLst,domainCr1,info);
8956+
// then list(newEQFun(i, lhs_exp, rhs_exp, domainCr1, comment, info, fieldLst) for i in 2:N-1);
8957+
then creatFieldEqs(lhs_exp, rhs_exp, domainCr, N, comment, info, fieldLst);
8958+
8959+
//left boundary extrapolation
8960+
case SCode.EQUATION(SCode.EQ_PDE(expLeft = lhs_exp, expRight = rhs_exp,
8961+
domain = domainCr as Absyn.CREF_QUAL(name, subscripts, Absyn.CREF_IDENT(name="left")),
8962+
comment = comment, info = info))
8963+
equation
8964+
// Absyn.CALL(function_ = Absyn.CREF_IDENT(name="extrapolateField", subscripts={}), functionArgs = Absyn.FUNCTIONARGS(args = {})) = rhs_exp;
8965+
// Absyn.CREF(fieldCr as Absyn.CREF_IDENT()) = lhs_exp;
89668966
fieldCr = matchExtrapAndField(lhs_exp, rhs_exp);
8967-
domainCr1 = Absyn.CREF_IDENT(name, subscripts);
8968-
(N,fieldLst) = getDomNFields(inDomFieldLst,domainCr1,info);
8969-
then
8967+
domainCr1 = Absyn.CREF_IDENT(name, subscripts);
8968+
(N,fieldLst) = getDomNFields(inDomFieldLst,domainCr1,info);
8969+
then
89708970
{extrapolateFieldEq(false, fieldCr, domainCr1, N, comment, info, fieldLst)};
89718971

8972-
//right boundary extrapolation
8973-
case SCode.EQUATION(SCode.EQ_PDE(expLeft = lhs_exp, expRight = rhs_exp,
8974-
domain = domainCr as Absyn.CREF_QUAL(name, subscripts, Absyn.CREF_IDENT(name="right")),
8975-
comment = comment, info = info))
8976-
equation
8977-
// Absyn.CALL(function_ = Absyn.CREF_IDENT(name="extrapolateField", subscripts={}), functionArgs = Absyn.FUNCTIONARGS(args = {})) = rhs_exp;
8978-
// Absyn.CREF(fieldCr as Absyn.CREF_IDENT()) = lhs_exp;
8972+
//right boundary extrapolation
8973+
case SCode.EQUATION(SCode.EQ_PDE(expLeft = lhs_exp, expRight = rhs_exp,
8974+
domain = domainCr as Absyn.CREF_QUAL(name, subscripts, Absyn.CREF_IDENT(name="right")),
8975+
comment = comment, info = info))
8976+
equation
8977+
// Absyn.CALL(function_ = Absyn.CREF_IDENT(name="extrapolateField", subscripts={}), functionArgs = Absyn.FUNCTIONARGS(args = {})) = rhs_exp;
8978+
// Absyn.CREF(fieldCr as Absyn.CREF_IDENT()) = lhs_exp;
89798979
fieldCr = matchExtrapAndField(lhs_exp, rhs_exp);
8980-
domainCr1 = Absyn.CREF_IDENT(name, subscripts);
8981-
(N,fieldLst) = getDomNFields(inDomFieldLst,domainCr1,info);
8982-
then
8980+
domainCr1 = Absyn.CREF_IDENT(name, subscripts);
8981+
(N,fieldLst) = getDomNFields(inDomFieldLst,domainCr1,info);
8982+
then
89838983
{extrapolateFieldEq(true, fieldCr, domainCr1, N, comment, info, fieldLst)};
8984-
//left boundary condition
8985-
case SCode.EQUATION(SCode.EQ_PDE(expLeft = lhs_exp, expRight = rhs_exp,
8986-
domain = domainCr as Absyn.CREF_QUAL(name, subscripts, Absyn.CREF_IDENT(name="left")),
8987-
comment = comment, info = info))
8988-
equation
8989-
domainCr1 = Absyn.CREF_IDENT(name, subscripts);
8990-
(N,fieldLst) = getDomNFields(inDomFieldLst,domainCr1,info);
8991-
then
8992-
{newEQFun(1, lhs_exp, rhs_exp, domainCr1, comment, info, fieldLst)};
8984+
//left boundary condition
8985+
case SCode.EQUATION(SCode.EQ_PDE(expLeft = lhs_exp, expRight = rhs_exp,
8986+
domain = domainCr as Absyn.CREF_QUAL(name, subscripts, Absyn.CREF_IDENT(name="left")),
8987+
comment = comment, info = info))
8988+
equation
8989+
domainCr1 = Absyn.CREF_IDENT(name, subscripts);
8990+
(N,fieldLst) = getDomNFields(inDomFieldLst,domainCr1,info);
8991+
then
8992+
{newEQFun(1, lhs_exp, rhs_exp, domainCr1, comment, info, fieldLst)};
89938993
//right boundary condition
8994-
case SCode.EQUATION(SCode.EQ_PDE(expLeft = lhs_exp, expRight = rhs_exp,
8995-
domain = domainCr as Absyn.CREF_QUAL(name, subscripts, Absyn.CREF_IDENT(name="right")),
8996-
comment = comment, info = info))
8997-
equation
8998-
domainCr1 = Absyn.CREF_IDENT(name, subscripts);
8999-
(N,fieldLst) = getDomNFields(inDomFieldLst,domainCr1,info);
9000-
then
9001-
{newEQFun(N, lhs_exp, rhs_exp, domainCr1, comment, info, fieldLst)};
9002-
9003-
end matchcontinue;
8994+
case SCode.EQUATION(SCode.EQ_PDE(expLeft = lhs_exp, expRight = rhs_exp,
8995+
domain = domainCr as Absyn.CREF_QUAL(name, subscripts, Absyn.CREF_IDENT(name="right")),
8996+
comment = comment, info = info))
8997+
equation
8998+
domainCr1 = Absyn.CREF_IDENT(name, subscripts);
8999+
(N,fieldLst) = getDomNFields(inDomFieldLst,domainCr1,info);
9000+
then
9001+
{newEQFun(N, lhs_exp, rhs_exp, domainCr1, comment, info, fieldLst)};
9002+
9003+
end matchcontinue;
90049004

90059005
outDiscretizedEQs := listAppend(inDiscretizedEQs, newDiscretizedEQs);
90069006
end discretizePDE;

Parser/Makefile.common

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Modelica_3_Lexer_BaseModelica_Lexer.o: Modelica_3_Lexer_BaseModelica_Lexer.h ../
7171
ModelicaParser_omc.o: ModelicaParser.c ModelicaParser.h ModelicaParserCommon.h ../Compiler/OpenModelicaBootstrappingHeader.h ../Compiler/runtime/errorext.h $(ANTLR)/antlr3config.h
7272
$(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) -I../Compiler
7373
ModelicaParser_omc.boot.o: ModelicaParser.c ModelicaParser.h ModelicaParserCommon.h ../Compiler/boot/tarball-include/OpenModelicaBootstrappingHeader.h ../Compiler/runtime/errorext.h $(ANTLR)/antlr3config.h
74-
$(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) -I../Compiler/boot/tarball-include
74+
$(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) -DOMC_BOOTSTRAPPING -I../Compiler/boot/tarball-include
7575
Parser_omc.o: $(HFILES) parse.c lookupTokenName.c
7676

7777
$(OBJS) : $(HFILES)

Parser/Modelica.g

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ goto rule ## func ## Ex; }}
111111
#include "OpenModelicaBootstrappingHeader.h"
112112
parser_members members;
113113
void* mmc_mk_box_eat_all(int ix, ...) {return NULL;}
114+
#if defined(OMC_BOOTSTRAPPING)
115+
/* The tarball version of OMC has a different order of fields in Absyn */
116+
#define Absyn__ATTR__BOOTSTRAPPING(A1,A2,A3,A4,A5,FIELD,A6) Absyn__ATTR(A1,A2,A3,A4,A5,A6)
117+
/* These do not exist in the bootstrapped version, but are returned in a grammar rule. Just do NULL. */
118+
#define Absyn__FIELD NULL
119+
#define Absyn__NONFIELD NULL
120+
/* Treat PDE equations as normal equations */
121+
#define Absyn__EQ_5fPDE(A1,A2,A3) Absyn__EQ_5fEQUALS(A1,A2)
122+
#else
123+
#define Absyn__ATTR__BOOTSTRAPPING Absyn__ATTR
124+
#endif
114125
}
115126

116127
/*------------------------------------------------------------------
@@ -228,7 +239,7 @@ class_specifier2 returns [void* ast, const char *s2]
228239
| SUBTYPEOF ts=type_specifier
229240
{
230241
$ast = Absyn__DERIVED(Absyn__TCOMPLEX(Absyn__IDENT(mmc_mk_scon("polymorphic")),mmc_mk_cons($ts.ast,mmc_mk_nil()),mmc_mk_nil()),
231-
Absyn__ATTR(MMC_FALSE,MMC_FALSE,Absyn__NON_5fPARALLEL,Absyn__VAR,Absyn__BIDIR,Absyn__NONFIELD,mmc_mk_nil()),mmc_mk_nil(),mmc_mk_none());
242+
Absyn__ATTR__BOOTSTRAPPING(MMC_FALSE,MMC_FALSE,Absyn__NON_5fPARALLEL,Absyn__VAR,Absyn__BIDIR,Absyn__NONFIELD,mmc_mk_nil()),mmc_mk_nil(),mmc_mk_none());
232243
}
233244
)
234245
;
@@ -259,7 +270,7 @@ overloading returns [void* ast]
259270
;
260271

261272
base_prefix returns [void* ast] :
262-
tp=type_prefix {ast = Absyn__ATTR(tp.flow, tp.stream, tp.parallelism, tp.variability, tp.direction, tp.field, mmc_mk_nil());}
273+
tp=type_prefix {ast = Absyn__ATTR__BOOTSTRAPPING(tp.flow, tp.stream, tp.parallelism, tp.variability, tp.direction, tp.field, mmc_mk_nil());}
263274
;
264275

265276
name_list returns [void* ast]
@@ -515,7 +526,7 @@ component_clause returns [void* ast]
515526
}
516527
}
517528

518-
ast = Absyn__COMPONENTS(Absyn__ATTR(tp.flow, tp.stream, tp.parallelism, tp.variability, tp.direction, tp.field, arr), $path.ast, clst);
529+
ast = Absyn__COMPONENTS(Absyn__ATTR__BOOTSTRAPPING(tp.flow, tp.stream, tp.parallelism, tp.variability, tp.direction, tp.field, arr), $path.ast, clst);
519530
}
520531
;
521532

0 commit comments

Comments
 (0)