Skip to content

Commit

Permalink
Fix runtime CFLAGS detection
Browse files Browse the repository at this point in the history
The old code only worked for some combinations of CFLAGS. It did not
actually find -fno-dollars-in-identifiers.

Belonging to [master]:
  - OpenModelica/OMCompiler#2371
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Apr 2, 2019
1 parent 17ca1ee commit 5de59c3
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 45 deletions.
14 changes: 7 additions & 7 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -1506,21 +1506,21 @@ template globalDataVarDefine(SimVar simVar, String arrayName) "template globalDa
/* <%crefStrNoUnderscore(c)%> */
#define _<%cref(c)%>(i) data->localData[i]-><%arrayName%>[<%index%>]
#define <%cref(c)%> _<%cref(c)%>(0)
#define $P$PRE<%cref(c)%> data->simulationInfo-><%arrayName%>Pre[<%index%>]
#define <%cref(crefPrefixPre(c))%> data->simulationInfo-><%arrayName%>Pre[<%index%>]

/* <%crefStrNoUnderscore(name)%> */
#define _<%cref(name)%>(i) data->localData[i]-><%arrayName%>[<%index%>]
#define <%cref(name)%> _<%cref(name)%>(0)
#define $P$PRE<%cref(name)%> data->simulationInfo-><%arrayName%>Pre[<%index%>]
#define <%cref(crefPrefixPre(name))%> data->simulationInfo-><%arrayName%>Pre[<%index%>]

>>
case SIMVAR(aliasvar=NOALIAS()) then
<<
/* <%crefStrNoUnderscore(name)%> */
#define _<%cref(name)%>(i) data->localData[i]-><%arrayName%>[<%index%>]
#define <%cref(name)%> _<%cref(name)%>(0)
#define $P$PRE<%cref(name)%> data->simulationInfo-><%arrayName%>Pre[<%index%>]
#define _$P$PRE<%cref(name)%>(i) $P$PRE<%cref(name)%>
#define <%cref(crefPrefixPre(name))%> data->simulationInfo-><%arrayName%>Pre[<%index%>]
#define _<%cref(crefPrefixPre(name))%>(i) <%cref(crefPrefixPre(name))%>

>>
end match
Expand Down Expand Up @@ -4025,7 +4025,7 @@ template functionODE(list<list<SimEqSystem>> derivativEquations, Text method, Op
TRACE_PUSH
#if !defined(OMC_MINIMAL_RUNTIME)
<% if profileFunctions() then "" else "if (measure_time_flag) " %>rt_tick(SIM_TIMER_FUNCTION_ODE);
#endif !defined(OMC_MINIMAL_RUNTIME)
#endif
<%varDecls%>
Expand Down Expand Up @@ -4239,7 +4239,7 @@ template functionDAE(list<SimEqSystem> allEquationsPlusWhen, String modelNamePre
<%addRootsTempArray()%>
#if !defined(OMC_MINIMAL_RUNTIME)
<% if profileFunctions() then "" else "if (measure_time_flag) " %>rt_tick(SIM_TIMER_DAE);
#endif !defined(OMC_MINIMAL_RUNTIME)
#endif
data->simulationInfo->needToIterate = 0;
data->simulationInfo->discreteCall = 1;
Expand All @@ -4250,7 +4250,7 @@ template functionDAE(list<SimEqSystem> allEquationsPlusWhen, String modelNamePre
#if !defined(OMC_MINIMAL_RUNTIME)
<% if profileFunctions() then "" else "if (measure_time_flag) " %>rt_accumulate(SIM_TIMER_DAE);
#endif !defined(OMC_MINIMAL_RUNTIME)
#endif
TRACE_POP
return 0;
}
Expand Down
46 changes: 22 additions & 24 deletions Compiler/Template/CodegenCFunctions.tpl
Expand Up @@ -607,15 +607,15 @@ template funArgName(Variable var)
let &auxFunction = buffer ""
match var
case VARIABLE(__) then contextCref(name,contextFunction,&auxFunction)
case FUNCTION_PTR(__) then '_' + name
case FUNCTION_PTR(__) then '_' + System.unquoteIdentifier(name)
end funArgName;

template funArgDefinition(Variable var)
::=
let &auxFunction = buffer ""
match var
case VARIABLE(__) then ('<%varType(var)%> <%contextCref(name,contextFunction,&auxFunction)%>' + (if var.instDims then " = {0}"))
case FUNCTION_PTR(__) then 'modelica_fnptr _<%name%>'
case FUNCTION_PTR(__) then 'modelica_fnptr _<%System.unquoteIdentifier(name)%>'
end funArgDefinition;

template funArgDefinitionKernelFunctionInterface(Variable var)
Expand Down Expand Up @@ -777,7 +777,7 @@ template funArgBoxedDefinition(Variable var)
let &auxFunction = buffer ""
match var
case VARIABLE(__) then 'modelica_metatype <%contextCref(name,contextFunction,&auxFunction)%>'
case FUNCTION_PTR(__) then 'modelica_fnptr _<%name%>'
case FUNCTION_PTR(__) then 'modelica_fnptr _<%System.unquoteIdentifier(name)%>'
end funArgBoxedDefinition;

template extFunDef(Function fn)
Expand Down Expand Up @@ -4205,9 +4205,9 @@ template contextIteratorName(Ident name, Context context)
"Generates code for an iterator variable."
::=
match context
case FUNCTION_CONTEXT(__) then "_" + name
case PARALLEL_FUNCTION_CONTEXT(__) then "_" + name
else "$P" + name
case FUNCTION_CONTEXT(__)
case PARALLEL_FUNCTION_CONTEXT(__) then "_" + System.unquoteIdentifier(name)
else System.forceQuotedIdentifier(name)
end contextIteratorName;

/* public */ template cref(ComponentRef cr)
Expand Down Expand Up @@ -4253,7 +4253,7 @@ end crefPre;
case CREF_IDENT(ident = "xloc") then crefStr(cr)
case CREF_IDENT(ident = "time") then "data->localData[0]->timeValue"
case WILD(__) then ''
else "$P" + crefToCStrDefine(cr)
else System.forceQuotedIdentifier(crefStrNoUnderscore(cr))
end crefDefine;

template crefToCStr(ComponentRef cr, Integer ix, Boolean isPre, Boolean isStart)
Expand All @@ -4279,8 +4279,9 @@ template crefToCStr(ComponentRef cr, Integer ix, Boolean isPre, Boolean isStart)
case SIMVAR(varKind=DAE_AUX_VAR())
case SIMVAR(index=-2)
then
if intEq(ix,0) then (if isPre then "$P$PRE")+crefDefine(cr)
else '_<%if isPre then "$P$PRE"%><%crefDefine(cr)%>(<%ix%>)'
(let s = (if isPre then crefDefine(crefPrefixPre(cr)) else crefDefine(cr))
if intEq(ix,0) then s
else '_<%s%>(<%ix%>)')
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"
Expand Down Expand Up @@ -4374,8 +4375,8 @@ end contextArrayCref;
template arrayCrefStr(ComponentRef cr)
::=
match cr
case CREF_IDENT(__) then '<%ident%>'
case CREF_QUAL(__) then '<%ident%>._<%arrayCrefStr(componentRef)%>'
case CREF_IDENT(__) then System.unquoteIdentifier(ident)
case CREF_QUAL(__) then '<%System.unquoteIdentifier(ident)%>._<%arrayCrefStr(componentRef)%>'
else "CREF_NOT_IDENT_OR_QUAL"
end arrayCrefStr;

Expand Down Expand Up @@ -5656,11 +5657,7 @@ end daeExpIteratedCref;

template iteratedCrefStr(ComponentRef cref)
::=
match cref
case (CREF_IDENT(__)) then
<<$P<%ident%>>>
case (CREF_QUAL(__)) then
<<$P<%ident%><%iteratedCrefStr(componentRef)%>>>
System.forceQuotedIdentifier(crefStrNoUnderscore(cref))
end iteratedCrefStr;

template resultVarAssignment(DAE.Type ty, Text lhs, Text rhs) "Tuple need to be considered"
Expand Down Expand Up @@ -6295,16 +6292,16 @@ template daeExpTailCall(list<DAE.Exp> es, list<String> vs, Context context, Text
// adrpo: ignore _x = _x!
if stringEq(v, crefStr(cr))
then '<%daeExpTailCall(erest, vrest, context, &preExp, &postExp, &varDecls, &auxFunction)%>'
else '_<%v%> = <%exp%>;<%\n%><%daeExpTailCall(erest, vrest, context, &preExp, &postExp, &varDecls, &auxFunction)%>'
else '_<%System.unquoteIdentifier(v)%> = <%exp%>;<%\n%><%daeExpTailCall(erest, vrest, context, &preExp, &postExp, &varDecls, &auxFunction)%>'
case _ then
(if anyExpHasCrefName(erest, v) then
/* We might overwrite a value with something else, so make an extra copy of it */
let tmp = tempDecl(expTypeFromExpModelica(e),&varDecls)
let &postExp += '_<%v%> = <%tmp%>;<%\n%>'
let &postExp += '_<%System.unquoteIdentifier(v)%> = <%tmp%>;<%\n%>'
'<%tmp%> = <%exp%>;<%\n%><%daeExpTailCall(erest, vrest, context, &preExp, &postExp, &varDecls, &auxFunction)%>'
else
let restText = daeExpTailCall(erest, vrest, context, &preExp, &postExp, &varDecls, &auxFunction)
let v2 = '_<%v%>'
let v2 = '_<%System.unquoteIdentifier(v)%>'
if stringEq(v2, exp)
then restText
else '<%v2%> = <%exp%>;<%\n%><%restText%>')
Expand Down Expand Up @@ -6703,7 +6700,7 @@ template daeExpReduction(Exp exp, Context context, Text &preExp,
let identType = expTypeFromExpModelica(iter.exp)
let arrayType = expTypeFromExpArray(iter.exp)
let iteratorName = contextIteratorName(iter.id, context)
let loopVar = match iter.exp case RANGE(__) then iteratorName else '<%iter.id%>_loopVar'
let loopVar = match iter.exp case RANGE(__) then iteratorName else '<%iteratorName%>_loopVar'
let stepVar = match iter.exp case RANGE(__) then tempDecl(identType,&tmpVarDecls)
let stopVar = match iter.exp case RANGE(__) then tempDecl(identType,&tmpVarDecls)
let &guardExpPre = buffer ""
Expand Down Expand Up @@ -6731,12 +6728,12 @@ template daeExpReduction(Exp exp, Context context, Text &preExp,
case RANGE(step=SOME(DAE.ICONST(__))) then ""
else check)
let isArrayWithLength = if rangeExpStop then (match ri.path case IDENT(name="array") then "1" else "") else ""
let &tmpVarDecls += if isArrayWithLength then 'modelica_integer <%iter.id%>_length;<%\n%>'
let &tmpVarDecls += if isArrayWithLength then 'modelica_integer <%iteratorName%>_length;<%\n%>'
let &rangeExpPre += match iter.exp case RANGE(__) then "" else (if firstIndex then '<%firstIndex%> = 1;<%\n%>')
let guardCond = (match iter.guardExp case SOME(grd) then daeExp(grd, context, &guardExpPre, &tmpVarDecls, &auxFunction) else "")
let &tmpVarDecls += '<%identType%> <%iteratorName%>;<%\n%>'
let &rangeExpPre += if isArrayWithLength then
'<%iter.id%>_length = ((<%stopVar%>-<%if firstIndex then firstIndex else iteratorName %>)/<%stepVar%>)+1;<%\n%>'
'<%iteratorName%>_length = ((<%stopVar%>-<%if firstIndex then firstIndex else iteratorName %>)/<%stepVar%>)+1;<%\n%>'
let &rangeExpPre += match iter.exp case RANGE(__) then '<%iteratorName%> = (<%rangeExp%>)-<%stepVar%>;<%\n%>' /* We pre-increment the counter, so subtract the step for the first variable for ranges */
let guardExp =
<<
Expand Down Expand Up @@ -6821,9 +6818,10 @@ template daeExpReduction(Exp exp, Context context, Text &preExp,
let length = tempDecl("int",&tmpVarDecls)
let &rangeExpPre += '<%length%> = 0;<%\n%>'
let _ = (iterators |> iter as REDUCTIONITER(__) =>
let loopVar = '<%iter.id%>_loopVar'
let iteratorName = contextIteratorName(iter.id, context)
let loopVar = '<%iteratorName%>_loopVar'
let identType = expTypeFromExpModelica(iter.exp)
let &rangeExpPre += '<%length%> = modelica_integer_max(<%length%>,<%match identType case "modelica_metatype" then (if isMetaArray(iter.exp) then 'arrayLength(<%loopVar%>)' else 'listLength(<%loopVar%>)') else match iter.exp case RANGE(__) then '<%iter.id%>_length' else 'size_of_dimension_base_array(<%loopVar%>, 1)'%>);<%\n%>'
let &rangeExpPre += '<%length%> = modelica_integer_max(<%length%>,<%match identType case "modelica_metatype" then (if isMetaArray(iter.exp) then 'arrayLength(<%loopVar%>)' else 'listLength(<%loopVar%>)') else match iter.exp case RANGE(__) then '<%iteratorName%>_length' else 'size_of_dimension_base_array(<%loopVar%>, 1)'%>);<%\n%>'
"")
<<
<%arrIndex%> = 1;
Expand Down
6 changes: 3 additions & 3 deletions Compiler/Template/CodegenCppCommon.tpl
Expand Up @@ -121,8 +121,8 @@ template crefStr(ComponentRef cr)
match cr
case CREF_IDENT(ident = "xloc") then '__xd<%subscriptsStr(subscriptLst)%>'
case CREF_IDENT(ident = "time") then "_simTime"
case CREF_IDENT(__) then '<%ident%>_<%subscriptsStr(subscriptLst)%>'
case CREF_QUAL(__) then '<%ident%>_<%subscriptsStr(subscriptLst)%>.<%crefStr(componentRef)%>'
case CREF_IDENT(__) then '<%System.unquoteIdentifier(ident)%>_<%subscriptsStr(subscriptLst)%>'
case CREF_QUAL(__) then '<%System.unquoteIdentifier(ident)%>_<%subscriptsStr(subscriptLst)%>.<%crefStr(componentRef)%>'
else "CREF_NOT_IDENT_OR_QUAL"
end crefStr;

Expand Down Expand Up @@ -153,7 +153,7 @@ case CREF_QUAL(ident = "$PRE") then
else
let &varDeclsCref = buffer "" /*BUFD*/
match context
case FUNCTION_CONTEXT(__) then System.unquoteIdentifier(crefStr(cr))
case FUNCTION_CONTEXT(__) then crefStr(cr)
else '<%cref1(cr,simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace,context,varDeclsCref,stateDerVectorName,useFlatArrayNotation)%>'
end contextCref;

Expand Down
10 changes: 10 additions & 0 deletions Compiler/Template/SimCodeTV.mo
Expand Up @@ -1592,6 +1592,11 @@ package System
output String outStr;
end unquoteIdentifier;

function forceQuotedIdentifier
input String str;
output String outStr;
end forceQuotedIdentifier;

function dirname
input String str;
output String outStr;
Expand Down Expand Up @@ -3439,6 +3444,11 @@ package ComponentReference
output DAE.ComponentRef outCref;
end crefPrefixDer;

function crefPrefixPre
input DAE.ComponentRef inCref;
output DAE.ComponentRef outCref;
end crefPrefixPre;

function makeUntypedCrefIdent
input DAE.Ident ident;
output DAE.ComponentRef outCrefIdent;
Expand Down
9 changes: 8 additions & 1 deletion Compiler/Util/System.mo
Expand Up @@ -864,12 +864,19 @@ literal in C. For example unescapedStringLength('\"')=1, unescapedStringLength('
end unescapedStringLength;

public function unquoteIdentifier
"Quoted identifiers, for example 'xyz' need to be translated into canonical form; for example _omcQuot_0x78797A"
"Quoted identifiers, for example 'xyz' need to be translated into canonical form; for example _omcQuot_0x2778797A27"
input String str;
output String outStr;
external "C" outStr=System_unquoteIdentifier(str) annotation(Library = "omcruntime");
end unquoteIdentifier;

public function forceQuotedIdentifier
"Forced quoted identifiers, for example xyz is translated into canonical form; for example _omcQuot_0x78797A"
input String str;
output String outStr;
external "C" outStr=System_forceQuotedIdentifier(str) annotation(Library = "omcruntime");
end forceQuotedIdentifier;

public function intMaxLit "Returns the maximum integer that can be represent using this version of the compiler"
output Integer outInt;
external "builtin" outInt=intMaxLit();
Expand Down
21 changes: 17 additions & 4 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -1670,20 +1670,19 @@ extern char* SystemImpl__unescapedString(const char* str)
return res;
}

extern char* SystemImpl__unquoteIdentifier(const char* str)
extern char* System_forceQuotedIdentifier(const char* str)
{
const char lookupTbl[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
char *res,*cur;
int len,i;
const int offset = 10;
const char _omcQuot[]="_omcQuot_";
if (*str != '\'') return NULL;
len = strlen(str)-2;
len = strlen(str);
res = (char*) omc_alloc_interface.malloc_atomic(2*len+offset+64);
cur = res;
cur += sprintf(cur,"%s",_omcQuot);
for (i=0; i<len; i++) {
unsigned char c = str[i+1];
unsigned char c = str[i];
*cur = lookupTbl[c/16];
cur++;
*cur = lookupTbl[c%16];
Expand All @@ -1693,6 +1692,20 @@ extern char* SystemImpl__unquoteIdentifier(const char* str)
return res;
}

extern char* SystemImpl__unquoteIdentifier(const char* str)
{
char c = *str;
if ((c == '\'')
#if !defined(OPENMODELICA_BOOTSTRAPPING_STAGE_1)
|| strstr(str, "$")
#endif
)
{
return System_forceQuotedIdentifier(str);
}
return NULL;
}

#define TIMER_MAX_STACK 1000
static double timerIntervalTime = 0;
static double timerCummulatedTime = 0;
Expand Down
12 changes: 6 additions & 6 deletions configure.ac
Expand Up @@ -449,25 +449,25 @@ if test -z "$RUNTIMECFLAGS"; then
AC_TRY_LINK([], [return 0;], [AC_MSG_RESULT($CC ok);],[AC_MSG_ERROR($CC failed)])
CFLAGS="$FPIC"
AC_MSG_CHECKING([runtime compiler CFLAGS])
RUNTIMECFLAGS="$FPIC"
for flag in -falign-functions -mfpmath=sse -fno-dollars-in-identifiers; do
RUNTIMECFLAGS="$CFLAGS"
CFLAGS="$RUNTIMECFLAGS $flag -Werror"
AC_TRY_LINK([], [return 0;], [CFLAGS="$RUNTIMECFLAGS $flag"],[CFLAGS="$RUNTIMECFLAGS"])
CFLAGS="$FPIC $flag -Werror"
AC_TRY_LINK([], [return 0;], [RUNTIMECFLAGS="$RUNTIMECFLAGS $flag"],[])
done
else
CFLAGS="$RUNTIMECFLAGS $FPIC -Werror"
AC_TRY_LINK([], [return 0;], [RUNTIMECFLAGS="$RUNTIMECFLAGS $FPIC"],[AC_MSG_ERROR([$CC $CFLAGS -Werror failed])])
fi
AC_MSG_RESULT([$RUNTIMECFLAGS])

CC="$CC_OLD"
CFLAGS="$CFLAGS_OLD"

LIBS=""
AC_SEARCH_LIBS(dlopen,dl)
LIBDL="$LIBS"
LIBS=""

CC="$CC_OLD"
CFLAGS="$CFLAGS_OLD"

dnl check for lpsolve55

AC_ARG_WITH(lpsolve, [ --with-lpsolve (default searching for lpsolve; disable if only using omc to cross-compile)],[if test "$withval" = "no"; then NO_LPLIB="#define NO_LPLIB"; fi],[])
Expand Down

0 comments on commit 5de59c3

Please sign in to comment.