Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Improved debugging of bad variables in codegen
Browse files Browse the repository at this point in the history
No real changes; just improving the C-code so you can see which
variables defines correspond to.

Belonging to [master]:
  - #1917
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Oct 17, 2017
1 parent 98136a9 commit 3486958
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
10 changes: 5 additions & 5 deletions Compiler/Template/CodegenC.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2611,17 +2611,17 @@ match system
let innerNLSSystems = functionNonLinearResiduals(nls.eqs,modelNamePrefix)
let backupOutputs = match nls.eqs
case (alg as SES_INVERSE_ALGORITHM(__))::{} then
let body = (alg.knownOutputCrefs |> cr =>
let &varDecls += '<%crefType(cr)%> $OLD_<%crefDefine(cr)%>;<%\n%>'
'$OLD_<%crefDefine(cr)%> = <%cref(cr)%>;'
let body = (alg.knownOutputCrefs |> cr hasindex i0 =>
let &varDecls += '<%crefType(cr)%> OLD_<%i0%>;<%\n%>'
'OLD_<%i0%> = <%cref(cr)%>;'
;separator="\n")
<<
/* backup outputs of the algorithm */
<%body%>
>>
let restoreKnownOutputs = match nls.eqs
case (alg as SES_INVERSE_ALGORITHM(__))::{} then
let body = (alg.knownOutputCrefs |> cr hasindex i0 => '<%cref(cr)%> = $OLD_<%crefDefine(cr)%>;' ;separator="\n")
let body = (alg.knownOutputCrefs |> cr hasindex i0 => '<%cref(cr)%> = OLD_<%i0%>;' ;separator="\n")
<<
/* restore previously known outputs of the algorithm */
<%body%>
Expand All @@ -2632,7 +2632,7 @@ match system
;separator="\n")
let body = match nls.eqs
case (alg as SES_INVERSE_ALGORITHM(__))::{} then
(alg.knownOutputCrefs |> cr hasindex i0 => 'res[<%i0%>] = $OLD_<%crefDefine(cr)%> - <%cref(cr)%>;' ;separator="\n")
(alg.knownOutputCrefs |> cr hasindex i0 => 'res[<%i0%>] = OLD_<%i0%> - <%cref(cr)%>;' ;separator="\n")
else
(nls.eqs |> eq2 as SES_RESIDUAL(__) hasindex i0 =>
let &preExp = buffer ""
Expand Down
16 changes: 9 additions & 7 deletions Compiler/Template/CodegenCFunctions.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4084,7 +4084,7 @@ template crefToCStr(ComponentRef cr, Integer ix, Boolean isPre, Boolean isStart)
::=
match cr
case CREF_QUAL(ident="$PRE", subscriptLst={}) then
(if isPre then error(sourceInfo(), 'Got $PRE for something that is already pre: <%crefStr(cr)%>')
(if isPre then error(sourceInfo(), 'Got $PRE for something that is already pre: <%crefStrNoUnderscore(cr)%>')
else crefToCStr(componentRef, ix, true, isStart))
case CREF_QUAL(ident="$START") then
crefToCStr(componentRef, ix, isPre, true)
Expand All @@ -4100,7 +4100,7 @@ template crefToCStr(ComponentRef cr, Integer ix, Boolean isPre, Boolean isStart)
then
if intEq(ix,0) then (if isPre then "$P$PRE")+crefDefine(cr)
else '_<%if isPre then "$P$PRE"%><%crefDefine(cr)%>(<%ix%>)'
case var as SIMVAR(index=-1) then error(sourceInfo(), 'crefToCStr got index=-1 for <%variabilityString(varKind)%> <%crefStr(name)%>')
case var as SIMVAR(index=-1) then error(sourceInfo(), 'crefToCStr got index=-1 for <%variabilityString(varKind)%> <%crefStrNoUnderscore(name)%>')
case var as SIMVAR(__) then '<%varArrayNameValues(var, ix, isPre, isStart)%>'
else "CREF_NOT_IDENT_OR_QUAL"
end crefToCStr;
Expand All @@ -4127,6 +4127,7 @@ template subscriptToCStr(Subscript subscript)
case SLICE(exp=ICONST(integer=i)) then i
case SLICE(__) then error(sourceInfo(), "Unknown slice " + ExpressionDumpTpl.dumpExp(exp,"\""))
case WHOLEDIM(__) then "WHOLEDIM"
case WHOLE_NONEXP(__) then "WHOLE_NONEXP"
case INDEX(__) then
match exp
case ICONST(integer=i) then i
Expand Down Expand Up @@ -4552,6 +4553,7 @@ template subscriptToMStr(Subscript subscript)
case SLICE(exp=ICONST(integer=i)) then i
case SLICE(__) then error(sourceInfo(), "Unknown slice " + ExpressionDumpTpl.dumpExp(exp,"\""))
case WHOLEDIM(__) then "WHOLEDIM"
case WHOLE_NONEXP(__) then "WHOLE_NONEXP"
case INDEX(__) then
match exp
case ICONST(integer=i) then i
Expand Down Expand Up @@ -4758,7 +4760,7 @@ template daeExpCrefLhsSimContext(Exp ecr, Context context, Text &preExp,
let vars = var_lst |> v => (", " + daeExp(makeCrefRecordExp(cr,v), context, &preExp, &varDecls, &auxFunction))
let record_type_name = underscorePath(ClassInf.getStateName(record_state))
// 'omc_<%record_type_name%>(threadData<%vars%>)'
error(sourceInfo(), 'daeExpCrefLhsSimContext got record <%crefStr(cr)%>. This does not make sense. Assigning to records is handled in a different way in the code generator, and reaching here is probably an error...') // '<%ret_var%>.c1'
error(sourceInfo(), 'daeExpCrefLhsSimContext got record <%crefStrNoUnderscore(cr)%>. This does not make sense. Assigning to records is handled in a different way in the code generator, and reaching here is probably an error...') // '<%ret_var%>.c1'

case ecr as CREF(componentRef=cr, ty=T_ARRAY(ty=aty, dims=dims)) then
let type = expTypeShort(aty)
Expand Down Expand Up @@ -6966,7 +6968,7 @@ template varArrayNameValues(SimVar var, Integer ix, Boolean isPre, Boolean isSta
case SIMVAR(varKind=OPT_TGRID())
then 'data->simulationInfo-><%crefShortType(name)%>Parameter[<%index%>]'
case SIMVAR(varKind=EXTOBJ()) then 'data->simulationInfo->extObjs[<%index%>]'
case SIMVAR(__) then '<%if isStart then '<%varAttributes(var)%>.start' else if isPre then 'data->simulationInfo-><%crefShortType(name)%>VarsPre[<%index%>] /* <%Util.escapeModelicaStringToCString(crefStr(name))%> <%variabilityString(varKind)%> */' else 'data->localData[<%ix%>]-><%crefShortType(name)%>Vars[<%index%>] /* <%Util.escapeModelicaStringToCString(crefStr(name))%> <%variabilityString(varKind)%> */'%>'
case SIMVAR(__) then '<%if isStart then '<%varAttributes(var)%>.start' else if isPre then 'data->simulationInfo-><%crefShortType(name)%>VarsPre[<%index%>] /* <%escapeCComments(crefStrNoUnderscore(name))%> <%variabilityString(varKind)%> */' else 'data->localData[<%ix%>]-><%crefShortType(name)%>Vars[<%index%>] /* <%escapeCComments(crefStrNoUnderscore(name))%> <%variabilityString(varKind)%> */'%>'
end varArrayNameValues;

template varArrayName(SimVar var)
Expand All @@ -6980,15 +6982,15 @@ template crefVarInfo(ComponentRef cr)
::=
match cref2simvar(cr, getSimCode())
case var as SIMVAR(__) then
'data->modelData-><%varArrayName(var)%>Data[<%index%>].info /* <%Util.escapeModelicaStringToCString(crefStr(name))%> */'
'data->modelData-><%varArrayName(var)%>Data[<%index%>].info /* <%escapeCComments(crefStrNoUnderscore(name))%> */'
end crefVarInfo;

template varAttributes(SimVar var)
::=
match var
case SIMVAR(index=-1) then crefAttributes(name) // input variable?
case SIMVAR(__) then
'data->modelData-><%varArrayName(var)%>Data[<%index%>].attribute /* <%Util.escapeModelicaStringToCString(crefStr(name))%> <%variabilityString(varKind)%> */'
'data->modelData-><%varArrayName(var)%>Data[<%index%>].attribute /* <%escapeCComments(crefStrNoUnderscore(name))%> <%variabilityString(varKind)%> */'
end varAttributes;

template crefAttributes(ComponentRef cr)
Expand All @@ -6997,7 +6999,7 @@ template crefAttributes(ComponentRef cr)
case var as SIMVAR(index=-1, varKind=JAC_VAR()) then "dummyREAL_ATTRIBUTE"
case var as SIMVAR(index=-1) then error(sourceInfo(), 'varAttributes got index=-1 for <%crefStr(name)%>')
case var as SIMVAR(__) then
'data->modelData-><%varArrayName(var)%>Data[<%index%>].attribute /* <%Util.escapeModelicaStringToCString(crefStr(name))%> */'
'data->modelData-><%varArrayName(var)%>Data[<%index%>].attribute /* <%escapeCComments(crefStrNoUnderscore(name))%> */'
end crefAttributes;

annotation(__OpenModelica_Interface="backend");
Expand Down
3 changes: 3 additions & 0 deletions Compiler/Template/CodegenUtil.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ template subscriptStr(Subscript subscript)
case INDEX(exp=ICONST(integer=i)) then i
case INDEX(exp=ENUM_LITERAL(name=n)) then dotPath(n)
case SLICE(exp=ICONST(integer=i)) then i
case INDEX(__)
case SLICE(__) then 'UNKNOWN_SUBSCRIPT /* <%escapeCComments(printExpStr(exp))%> */'
case WHOLEDIM(__) then "WHOLEDIM"
case WHOLE_NONEXP(__) then "WHOLE_NONEXP"
else "UNKNOWN_SUBSCRIPT"
end subscriptStr;

Expand Down
1 change: 1 addition & 0 deletions Compiler/Template/SimCodeTV.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,7 @@ package DAE

uniontype Subscript
record WHOLEDIM end WHOLEDIM;
record WHOLE_NONEXP end WHOLE_NONEXP;
record SLICE
Exp exp;
end SLICE;
Expand Down

0 comments on commit 3486958

Please sign in to comment.