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

Commit 5de59c3

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Fix runtime CFLAGS detection
The old code only worked for some combinations of CFLAGS. It did not actually find -fno-dollars-in-identifiers. Belonging to [master]: - #2371
1 parent 17ca1ee commit 5de59c3

7 files changed

Lines changed: 73 additions & 45 deletions

File tree

Compiler/Template/CodegenC.tpl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,21 +1506,21 @@ template globalDataVarDefine(SimVar simVar, String arrayName) "template globalDa
15061506
/* <%crefStrNoUnderscore(c)%> */
15071507
#define _<%cref(c)%>(i) data->localData[i]-><%arrayName%>[<%index%>]
15081508
#define <%cref(c)%> _<%cref(c)%>(0)
1509-
#define $P$PRE<%cref(c)%> data->simulationInfo-><%arrayName%>Pre[<%index%>]
1509+
#define <%cref(crefPrefixPre(c))%> data->simulationInfo-><%arrayName%>Pre[<%index%>]
15101510

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

15161516
>>
15171517
case SIMVAR(aliasvar=NOALIAS()) then
15181518
<<
15191519
/* <%crefStrNoUnderscore(name)%> */
15201520
#define _<%cref(name)%>(i) data->localData[i]-><%arrayName%>[<%index%>]
15211521
#define <%cref(name)%> _<%cref(name)%>(0)
1522-
#define $P$PRE<%cref(name)%> data->simulationInfo-><%arrayName%>Pre[<%index%>]
1523-
#define _$P$PRE<%cref(name)%>(i) $P$PRE<%cref(name)%>
1522+
#define <%cref(crefPrefixPre(name))%> data->simulationInfo-><%arrayName%>Pre[<%index%>]
1523+
#define _<%cref(crefPrefixPre(name))%>(i) <%cref(crefPrefixPre(name))%>
15241524

15251525
>>
15261526
end match
@@ -4025,7 +4025,7 @@ template functionODE(list<list<SimEqSystem>> derivativEquations, Text method, Op
40254025
TRACE_PUSH
40264026
#if !defined(OMC_MINIMAL_RUNTIME)
40274027
<% if profileFunctions() then "" else "if (measure_time_flag) " %>rt_tick(SIM_TIMER_FUNCTION_ODE);
4028-
#endif !defined(OMC_MINIMAL_RUNTIME)
4028+
#endif
40294029
40304030
<%varDecls%>
40314031
@@ -4239,7 +4239,7 @@ template functionDAE(list<SimEqSystem> allEquationsPlusWhen, String modelNamePre
42394239
<%addRootsTempArray()%>
42404240
#if !defined(OMC_MINIMAL_RUNTIME)
42414241
<% if profileFunctions() then "" else "if (measure_time_flag) " %>rt_tick(SIM_TIMER_DAE);
4242-
#endif !defined(OMC_MINIMAL_RUNTIME)
4242+
#endif
42434243
42444244
data->simulationInfo->needToIterate = 0;
42454245
data->simulationInfo->discreteCall = 1;
@@ -4250,7 +4250,7 @@ template functionDAE(list<SimEqSystem> allEquationsPlusWhen, String modelNamePre
42504250
42514251
#if !defined(OMC_MINIMAL_RUNTIME)
42524252
<% if profileFunctions() then "" else "if (measure_time_flag) " %>rt_accumulate(SIM_TIMER_DAE);
4253-
#endif !defined(OMC_MINIMAL_RUNTIME)
4253+
#endif
42544254
TRACE_POP
42554255
return 0;
42564256
}

Compiler/Template/CodegenCFunctions.tpl

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -607,15 +607,15 @@ template funArgName(Variable var)
607607
let &auxFunction = buffer ""
608608
match var
609609
case VARIABLE(__) then contextCref(name,contextFunction,&auxFunction)
610-
case FUNCTION_PTR(__) then '_' + name
610+
case FUNCTION_PTR(__) then '_' + System.unquoteIdentifier(name)
611611
end funArgName;
612612

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

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

783783
template extFunDef(Function fn)
@@ -4205,9 +4205,9 @@ template contextIteratorName(Ident name, Context context)
42054205
"Generates code for an iterator variable."
42064206
::=
42074207
match context
4208-
case FUNCTION_CONTEXT(__) then "_" + name
4209-
case PARALLEL_FUNCTION_CONTEXT(__) then "_" + name
4210-
else "$P" + name
4208+
case FUNCTION_CONTEXT(__)
4209+
case PARALLEL_FUNCTION_CONTEXT(__) then "_" + System.unquoteIdentifier(name)
4210+
else System.forceQuotedIdentifier(name)
42114211
end contextIteratorName;
42124212

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

42594259
template crefToCStr(ComponentRef cr, Integer ix, Boolean isPre, Boolean isStart)
@@ -4279,8 +4279,9 @@ template crefToCStr(ComponentRef cr, Integer ix, Boolean isPre, Boolean isStart)
42794279
case SIMVAR(varKind=DAE_AUX_VAR())
42804280
case SIMVAR(index=-2)
42814281
then
4282-
if intEq(ix,0) then (if isPre then "$P$PRE")+crefDefine(cr)
4283-
else '_<%if isPre then "$P$PRE"%><%crefDefine(cr)%>(<%ix%>)'
4282+
(let s = (if isPre then crefDefine(crefPrefixPre(cr)) else crefDefine(cr))
4283+
if intEq(ix,0) then s
4284+
else '_<%s%>(<%ix%>)')
42844285
case var as SIMVAR(index=-1) then error(sourceInfo(), 'crefToCStr got index=-1 for <%variabilityString(varKind)%> <%crefStrNoUnderscore(name)%>')
42854286
case var as SIMVAR(__) then '<%varArrayNameValues(var, ix, isPre, isStart)%>'
42864287
else "CREF_NOT_IDENT_OR_QUAL"
@@ -4374,8 +4375,8 @@ end contextArrayCref;
43744375
template arrayCrefStr(ComponentRef cr)
43754376
::=
43764377
match cr
4377-
case CREF_IDENT(__) then '<%ident%>'
4378-
case CREF_QUAL(__) then '<%ident%>._<%arrayCrefStr(componentRef)%>'
4378+
case CREF_IDENT(__) then System.unquoteIdentifier(ident)
4379+
case CREF_QUAL(__) then '<%System.unquoteIdentifier(ident)%>._<%arrayCrefStr(componentRef)%>'
43794380
else "CREF_NOT_IDENT_OR_QUAL"
43804381
end arrayCrefStr;
43814382

@@ -5656,11 +5657,7 @@ end daeExpIteratedCref;
56565657

56575658
template iteratedCrefStr(ComponentRef cref)
56585659
::=
5659-
match cref
5660-
case (CREF_IDENT(__)) then
5661-
<<$P<%ident%>>>
5662-
case (CREF_QUAL(__)) then
5663-
<<$P<%ident%><%iteratedCrefStr(componentRef)%>>>
5660+
System.forceQuotedIdentifier(crefStrNoUnderscore(cref))
56645661
end iteratedCrefStr;
56655662

56665663
template resultVarAssignment(DAE.Type ty, Text lhs, Text rhs) "Tuple need to be considered"
@@ -6295,16 +6292,16 @@ template daeExpTailCall(list<DAE.Exp> es, list<String> vs, Context context, Text
62956292
// adrpo: ignore _x = _x!
62966293
if stringEq(v, crefStr(cr))
62976294
then '<%daeExpTailCall(erest, vrest, context, &preExp, &postExp, &varDecls, &auxFunction)%>'
6298-
else '_<%v%> = <%exp%>;<%\n%><%daeExpTailCall(erest, vrest, context, &preExp, &postExp, &varDecls, &auxFunction)%>'
6295+
else '_<%System.unquoteIdentifier(v)%> = <%exp%>;<%\n%><%daeExpTailCall(erest, vrest, context, &preExp, &postExp, &varDecls, &auxFunction)%>'
62996296
case _ then
63006297
(if anyExpHasCrefName(erest, v) then
63016298
/* We might overwrite a value with something else, so make an extra copy of it */
63026299
let tmp = tempDecl(expTypeFromExpModelica(e),&varDecls)
6303-
let &postExp += '_<%v%> = <%tmp%>;<%\n%>'
6300+
let &postExp += '_<%System.unquoteIdentifier(v)%> = <%tmp%>;<%\n%>'
63046301
'<%tmp%> = <%exp%>;<%\n%><%daeExpTailCall(erest, vrest, context, &preExp, &postExp, &varDecls, &auxFunction)%>'
63056302
else
63066303
let restText = daeExpTailCall(erest, vrest, context, &preExp, &postExp, &varDecls, &auxFunction)
6307-
let v2 = '_<%v%>'
6304+
let v2 = '_<%System.unquoteIdentifier(v)%>'
63086305
if stringEq(v2, exp)
63096306
then restText
63106307
else '<%v2%> = <%exp%>;<%\n%><%restText%>')
@@ -6703,7 +6700,7 @@ template daeExpReduction(Exp exp, Context context, Text &preExp,
67036700
let identType = expTypeFromExpModelica(iter.exp)
67046701
let arrayType = expTypeFromExpArray(iter.exp)
67056702
let iteratorName = contextIteratorName(iter.id, context)
6706-
let loopVar = match iter.exp case RANGE(__) then iteratorName else '<%iter.id%>_loopVar'
6703+
let loopVar = match iter.exp case RANGE(__) then iteratorName else '<%iteratorName%>_loopVar'
67076704
let stepVar = match iter.exp case RANGE(__) then tempDecl(identType,&tmpVarDecls)
67086705
let stopVar = match iter.exp case RANGE(__) then tempDecl(identType,&tmpVarDecls)
67096706
let &guardExpPre = buffer ""
@@ -6731,12 +6728,12 @@ template daeExpReduction(Exp exp, Context context, Text &preExp,
67316728
case RANGE(step=SOME(DAE.ICONST(__))) then ""
67326729
else check)
67336730
let isArrayWithLength = if rangeExpStop then (match ri.path case IDENT(name="array") then "1" else "") else ""
6734-
let &tmpVarDecls += if isArrayWithLength then 'modelica_integer <%iter.id%>_length;<%\n%>'
6731+
let &tmpVarDecls += if isArrayWithLength then 'modelica_integer <%iteratorName%>_length;<%\n%>'
67356732
let &rangeExpPre += match iter.exp case RANGE(__) then "" else (if firstIndex then '<%firstIndex%> = 1;<%\n%>')
67366733
let guardCond = (match iter.guardExp case SOME(grd) then daeExp(grd, context, &guardExpPre, &tmpVarDecls, &auxFunction) else "")
67376734
let &tmpVarDecls += '<%identType%> <%iteratorName%>;<%\n%>'
67386735
let &rangeExpPre += if isArrayWithLength then
6739-
'<%iter.id%>_length = ((<%stopVar%>-<%if firstIndex then firstIndex else iteratorName %>)/<%stepVar%>)+1;<%\n%>'
6736+
'<%iteratorName%>_length = ((<%stopVar%>-<%if firstIndex then firstIndex else iteratorName %>)/<%stepVar%>)+1;<%\n%>'
67406737
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 */
67416738
let guardExp =
67426739
<<
@@ -6821,9 +6818,10 @@ template daeExpReduction(Exp exp, Context context, Text &preExp,
68216818
let length = tempDecl("int",&tmpVarDecls)
68226819
let &rangeExpPre += '<%length%> = 0;<%\n%>'
68236820
let _ = (iterators |> iter as REDUCTIONITER(__) =>
6824-
let loopVar = '<%iter.id%>_loopVar'
6821+
let iteratorName = contextIteratorName(iter.id, context)
6822+
let loopVar = '<%iteratorName%>_loopVar'
68256823
let identType = expTypeFromExpModelica(iter.exp)
6826-
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%>'
6824+
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%>'
68276825
"")
68286826
<<
68296827
<%arrIndex%> = 1;

Compiler/Template/CodegenCppCommon.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ template crefStr(ComponentRef cr)
121121
match cr
122122
case CREF_IDENT(ident = "xloc") then '__xd<%subscriptsStr(subscriptLst)%>'
123123
case CREF_IDENT(ident = "time") then "_simTime"
124-
case CREF_IDENT(__) then '<%ident%>_<%subscriptsStr(subscriptLst)%>'
125-
case CREF_QUAL(__) then '<%ident%>_<%subscriptsStr(subscriptLst)%>.<%crefStr(componentRef)%>'
124+
case CREF_IDENT(__) then '<%System.unquoteIdentifier(ident)%>_<%subscriptsStr(subscriptLst)%>'
125+
case CREF_QUAL(__) then '<%System.unquoteIdentifier(ident)%>_<%subscriptsStr(subscriptLst)%>.<%crefStr(componentRef)%>'
126126
else "CREF_NOT_IDENT_OR_QUAL"
127127
end crefStr;
128128

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

Compiler/Template/SimCodeTV.mo

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,11 @@ package System
15921592
output String outStr;
15931593
end unquoteIdentifier;
15941594

1595+
function forceQuotedIdentifier
1596+
input String str;
1597+
output String outStr;
1598+
end forceQuotedIdentifier;
1599+
15951600
function dirname
15961601
input String str;
15971602
output String outStr;
@@ -3439,6 +3444,11 @@ package ComponentReference
34393444
output DAE.ComponentRef outCref;
34403445
end crefPrefixDer;
34413446

3447+
function crefPrefixPre
3448+
input DAE.ComponentRef inCref;
3449+
output DAE.ComponentRef outCref;
3450+
end crefPrefixPre;
3451+
34423452
function makeUntypedCrefIdent
34433453
input DAE.Ident ident;
34443454
output DAE.ComponentRef outCrefIdent;

Compiler/Util/System.mo

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,12 +864,19 @@ literal in C. For example unescapedStringLength('\"')=1, unescapedStringLength('
864864
end unescapedStringLength;
865865

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

873+
public function forceQuotedIdentifier
874+
"Forced quoted identifiers, for example xyz is translated into canonical form; for example _omcQuot_0x78797A"
875+
input String str;
876+
output String outStr;
877+
external "C" outStr=System_forceQuotedIdentifier(str) annotation(Library = "omcruntime");
878+
end forceQuotedIdentifier;
879+
873880
public function intMaxLit "Returns the maximum integer that can be represent using this version of the compiler"
874881
output Integer outInt;
875882
external "builtin" outInt=intMaxLit();

Compiler/runtime/systemimpl.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,20 +1670,19 @@ extern char* SystemImpl__unescapedString(const char* str)
16701670
return res;
16711671
}
16721672

1673-
extern char* SystemImpl__unquoteIdentifier(const char* str)
1673+
extern char* System_forceQuotedIdentifier(const char* str)
16741674
{
16751675
const char lookupTbl[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
16761676
char *res,*cur;
16771677
int len,i;
16781678
const int offset = 10;
16791679
const char _omcQuot[]="_omcQuot_";
1680-
if (*str != '\'') return NULL;
1681-
len = strlen(str)-2;
1680+
len = strlen(str);
16821681
res = (char*) omc_alloc_interface.malloc_atomic(2*len+offset+64);
16831682
cur = res;
16841683
cur += sprintf(cur,"%s",_omcQuot);
16851684
for (i=0; i<len; i++) {
1686-
unsigned char c = str[i+1];
1685+
unsigned char c = str[i];
16871686
*cur = lookupTbl[c/16];
16881687
cur++;
16891688
*cur = lookupTbl[c%16];
@@ -1693,6 +1692,20 @@ extern char* SystemImpl__unquoteIdentifier(const char* str)
16931692
return res;
16941693
}
16951694

1695+
extern char* SystemImpl__unquoteIdentifier(const char* str)
1696+
{
1697+
char c = *str;
1698+
if ((c == '\'')
1699+
#if !defined(OPENMODELICA_BOOTSTRAPPING_STAGE_1)
1700+
|| strstr(str, "$")
1701+
#endif
1702+
)
1703+
{
1704+
return System_forceQuotedIdentifier(str);
1705+
}
1706+
return NULL;
1707+
}
1708+
16961709
#define TIMER_MAX_STACK 1000
16971710
static double timerIntervalTime = 0;
16981711
static double timerCummulatedTime = 0;

configure.ac

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,25 +449,25 @@ if test -z "$RUNTIMECFLAGS"; then
449449
AC_TRY_LINK([], [return 0;], [AC_MSG_RESULT($CC ok);],[AC_MSG_ERROR($CC failed)])
450450
CFLAGS="$FPIC"
451451
AC_MSG_CHECKING([runtime compiler CFLAGS])
452+
RUNTIMECFLAGS="$FPIC"
452453
for flag in -falign-functions -mfpmath=sse -fno-dollars-in-identifiers; do
453-
RUNTIMECFLAGS="$CFLAGS"
454-
CFLAGS="$RUNTIMECFLAGS $flag -Werror"
455-
AC_TRY_LINK([], [return 0;], [CFLAGS="$RUNTIMECFLAGS $flag"],[CFLAGS="$RUNTIMECFLAGS"])
454+
CFLAGS="$FPIC $flag -Werror"
455+
AC_TRY_LINK([], [return 0;], [RUNTIMECFLAGS="$RUNTIMECFLAGS $flag"],[])
456456
done
457457
else
458458
CFLAGS="$RUNTIMECFLAGS $FPIC -Werror"
459459
AC_TRY_LINK([], [return 0;], [RUNTIMECFLAGS="$RUNTIMECFLAGS $FPIC"],[AC_MSG_ERROR([$CC $CFLAGS -Werror failed])])
460460
fi
461461
AC_MSG_RESULT([$RUNTIMECFLAGS])
462462

463+
CC="$CC_OLD"
464+
CFLAGS="$CFLAGS_OLD"
465+
463466
LIBS=""
464467
AC_SEARCH_LIBS(dlopen,dl)
465468
LIBDL="$LIBS"
466469
LIBS=""
467470

468-
CC="$CC_OLD"
469-
CFLAGS="$CFLAGS_OLD"
470-
471471
dnl check for lpsolve55
472472

473473
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],[])

0 commit comments

Comments
 (0)