Skip to content

Commit

Permalink
src/ssDSym.c: fix build failure on -std=c23
Browse files Browse the repository at this point in the history
Without the change the build fails due to type mismatch as:

    ./escan.l: In function 'getVal':
    ./escan.l:156:20: error: too many arguments to function 'psym->getFn'
      156 |             return psym->getFn(viewPid);
          |                    ^~~~

C23 turned `REG (*)()` into `REG (*)(void)` instead of partially defined
type. `src/ssDSym.c` exploited partial definedness to store different
function accessor types. The change splits accessors into different
fields.
  • Loading branch information
trofi committed Nov 17, 2024
1 parent dea7c75 commit be3dee3
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 46 deletions.
8 changes: 4 additions & 4 deletions src/escan.l
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ static REG getVal(struct isym *psym)
{
switch (psym->type) {
case SINGLE_SYM:
return psym->getFn(viewPid);
return psym->getFn1(viewPid);
case REGSET_SYM:
return psym->getFn(viewPid, psym->ndx);
return psym->getFn2(viewPid, psym->ndx);
case BITF_SYM:
return (psym->getFn(viewPid) << (63 - psym->start)) >> (64 - psym->len);
return (psym->getFn1(viewPid) << (63 - psym->start)) >> (64 - psym->len);
case RS_BITF_SYM:
return (psym->getFn(viewPid, psym->ndx) << (63 - psym->start)) >> (64 - psym->len);
return (psym->getFn2(viewPid, psym->ndx) << (63 - psym->start)) >> (64 - psym->len);
default:
return 0;
}
Expand Down
20 changes: 10 additions & 10 deletions src/ssDDM.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ BOOL valAssign(unsigned argc, char *argv[])

switch (sym.type) {
case SINGLE_SYM:
if (sym.setFn) {
if (!sym.setFn(0, val)) {
if (sym.setFn2) {
if (!sym.setFn2(0, val)) {
cmdErr("Attempt to modify symbol failed\n");
return NO;
}
Expand All @@ -144,8 +144,8 @@ BOOL valAssign(unsigned argc, char *argv[])
}
break;
case REGSET_SYM:
if (sym.setFn) {
if (!sym.setFn(0, sym.ndx, val)) {
if (sym.setFn3) {
if (!sym.setFn3(0, sym.ndx, val)) {
cmdErr("Attempt to modify symbol failed\n");
return NO;
}
Expand All @@ -155,13 +155,13 @@ BOOL valAssign(unsigned argc, char *argv[])
}
break;
case BITF_SYM:
if (sym.setFn) {
REG oldval = sym.getFn(0), mask;
if (sym.setFn2) {
REG oldval = sym.getFn1(0), mask;

mask = ONES(sym.len) << (sym.start - (sym.len - 1));
val <<= sym.start - (sym.len - 1);
val = (oldval & ~mask) | (val & mask);
if (!sym.setFn(0, val)) {
if (!sym.setFn2(0, val)) {
cmdErr("Attempt to modify symbol failed\n");
return NO;
}
Expand All @@ -171,13 +171,13 @@ BOOL valAssign(unsigned argc, char *argv[])
}
break;
case RS_BITF_SYM:
if (sym.setFn) {
REG oldval = sym.getFn(0, sym.ndx), mask;
if (sym.setFn3) {
REG oldval = sym.getFn2(0, sym.ndx), mask;

mask = ONES(sym.len) << (sym.start - (sym.len - 1));
val <<= sym.start - (sym.len - 1);
val = (oldval & ~mask) | (val & mask);
if (!sym.setFn(0, sym.ndx, val)) {
if (!sym.setFn3(0, sym.ndx, val)) {
cmdErr("Attempt to modify symbol failed\n");
return NO;
}
Expand Down
49 changes: 33 additions & 16 deletions src/ssDSym.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,21 @@ static void isymChk(const char *sname)
* into the internal symbol table.
*---------------------------------------------------------------------------*/

static void isymIns1(const char *sname, PGetFn gf, PSetFn sf, int dbase)
static void isymIns1(const char *sname, PGetFn1 gf, PSetFn2 sf, int dbase)
{
isymChk(sname);
isymtbl[topisym].getFn = gf;
isymtbl[topisym].setFn = sf;
isymtbl[topisym].getFn1 = gf;
isymtbl[topisym].setFn2 = sf;
isymtbl[topisym].type = SINGLE_SYM;
isymtbl[topisym].dbase = dbase;
topisym++;
}

static void isymIns2(const char *sname, PGetFn gf, PSetFn sf, int dbase, int ndx)
static void isymIns2(const char *sname, PGetFn2 gf, PSetFn3 sf, int dbase, int ndx)
{
isymChk(sname);
isymtbl[topisym].getFn = gf;
isymtbl[topisym].setFn = sf;
isymtbl[topisym].getFn2 = gf;
isymtbl[topisym].setFn3 = sf;
isymtbl[topisym].type = REGSET_SYM;
if (ndx >= 0) { /* specific register in a register set */
isymtbl[topisym].ndx = ndx;
Expand All @@ -155,25 +155,25 @@ static void isymIns2(const char *sname, PGetFn gf, PSetFn sf, int dbase, int ndx

/* len is bit-field length, start is the little-endian bit number of the left
edge of the field */
static void isymIns3(const char *sname, PGetFn gf, PSetFn sf, int dbase,
static void isymIns3(const char *sname, PGetFn1 gf, PSetFn2 sf, int dbase,
unsigned start, unsigned len)
{
isymChk(sname);
isymtbl[topisym].getFn = gf;
isymtbl[topisym].setFn = sf;
isymtbl[topisym].getFn1 = gf;
isymtbl[topisym].setFn2 = sf;
isymtbl[topisym].type = BITF_SYM;
isymtbl[topisym].len = len;
isymtbl[topisym].start = start;
isymtbl[topisym].dbase = dbase;
topisym++;
}

static void isymIns4(const char *sname, PGetFn gf, PSetFn sf, int dbase, unsigned ndx,
static void isymIns4(const char *sname, PGetFn2 gf, PSetFn3 sf, int dbase, unsigned ndx,
unsigned start, unsigned len)
{
isymChk(sname);
isymtbl[topisym].getFn = gf;
isymtbl[topisym].setFn = sf;
isymtbl[topisym].getFn2 = gf;
isymtbl[topisym].setFn3 = sf;
isymtbl[topisym].type = RS_BITF_SYM;
isymtbl[topisym].ndx = ndx;
isymtbl[topisym].len = len;
Expand Down Expand Up @@ -214,6 +214,23 @@ struct isym *isymVLkp(const char *sname)
return NULL;
}

/* Wrappers to match types for the fetcher.
* TODO: extract 0-getters into it's own symbol type.
*/

#define MK_ACCESSOR_01(wrapper, orig) \
static REG wrapper(int unused) \
{ \
(void)unused; \
return orig(); \
}


MK_ACCESSOR_01(getTotalCycles1, getTotalCycles);
MK_ACCESSOR_01(getTotalInsts1, getTotalInsts);
MK_ACCESSOR_01(getTotalFaults1, getTotalFaults);
MK_ACCESSOR_01(getExited1, getExited);

/*---------------------------------------------------------------------------
* internalSymbol$Init - Initialize the internal symbol table.
*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -503,14 +520,14 @@ void isymInit(void)
isymIns4("eflags.pf", arGet, arSet, HEXEXP, EFLAGS_ID, 2, 1);
isymIns4("eflags.cf", arGet, arSet, HEXEXP, EFLAGS_ID, 0, 1);

isymIns1("$insts$", getTotalInsts, NULL, DECEXP);
isymIns1("$cycles$", getTotalCycles, NULL, DECEXP);
isymIns1("$faults$", getTotalFaults, NULL, DECEXP);
isymIns1("$insts$", getTotalInsts1, NULL, DECEXP);
isymIns1("$cycles$", getTotalCycles1, NULL, DECEXP);
isymIns1("$faults$", getTotalFaults1, NULL, DECEXP);
#ifdef NEW_MP
isymIns1("$pid$", getCurPid, NULL, DECEXP);
#endif
isymIns1("$heap$", heapGet, NULL, HEXEXP);
isymIns1("$exited$", getExited, NULL, HEXEXP);
isymIns1("$exited$", getExited1, NULL, HEXEXP);

qsort((void *)isymtbl, topisym, sizeof (struct isym), cmpisym);
#if 0
Expand Down
12 changes: 6 additions & 6 deletions src/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ BOOL grSet(int proc, int i, REG val)
return YES;
}

BOOL grNatSet(int proc, int i, BOOL nat)
BOOL grNatSet(int proc, int i, REG nat)
{
REG val;
BOOL old;
Expand Down Expand Up @@ -643,7 +643,7 @@ BOOL phyGrSet(int proc, int i, REG val)
return YES;
}

BOOL phyGrNatSet(int proc, int i, BOOL nat)
BOOL phyGrNatSet(int proc, int i, REG nat)
{
if (!i && nat)
return NO;
Expand Down Expand Up @@ -681,7 +681,7 @@ BOOL frSignSet(int proc, int i, REG val)
return YES;
}

BOOL frExpSet(int proc, int i, WORD exp)
BOOL frExpSet(int proc, int i, REG exp)
{
FREG fr;
BYTE sign;
Expand All @@ -697,7 +697,7 @@ BOOL frExpSet(int proc, int i, WORD exp)
return YES;
}

BOOL frMantSet(int proc, int i, DWORD mant)
BOOL frMantSet(int proc, int i, REG mant)
{
FREG fr;
BYTE sign;
Expand Down Expand Up @@ -771,7 +771,7 @@ BOOL phyFrMantSet(int proc, int i, DWORD mant)
return YES;
}

BOOL prSet(int proc, int i, BOOL val)
BOOL prSet(int proc, int i, REG val)
{
if (!i && !val)
return NO;
Expand Down Expand Up @@ -950,7 +950,7 @@ BOOL bkrSet(int proc, int i, REG val)
return YES;
}

BOOL bkrNatSet(int proc, int i, BOOL nat)
BOOL bkrNatSet(int proc, int i, REG nat)
{
#ifdef NEW_MP
mpState[proc].bankedGrs_[i].nat = nat & 1;
Expand Down
12 changes: 6 additions & 6 deletions src/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,16 +570,16 @@ void cfmSet(int cproc, REG val);
BOOL frSignSet(int cproc, int i, REG val);

/* Sets the exponent field of virtual FR[i] for cproc */
BOOL frExpSet(int cproc, int i, WORD exp);
BOOL frExpSet(int cproc, int i, REG exp);

/* Sets the mantissa field of virtual FR[i] for cproc */
BOOL frMantSet(int cproc, int i, DWORD mant);
BOOL frMantSet(int cproc, int i, REG mant);

/* Sets the ip for cproc */
BOOL ipSet(int cproc, REG val);

/* Sets the virtual GR[i].nat for cproc */
BOOL grNatSet(int cproc, int i, BOOL nat);
BOOL grNatSet(int cproc, int i, REG nat);

/* Sets the virtual GR[i] for cproc */
BOOL grSet(int cproc, int i, REG val);
Expand All @@ -594,7 +594,7 @@ BOOL phyFrExpSet(int cproc, int i, WORD exp);
BOOL phyFrMantSet(int cproc, int i, DWORD mant);

/* Sets the physical GR[i].nat for cproc */
BOOL phyGrNatSet(int cproc, int i, BOOL nat);
BOOL phyGrNatSet(int cproc, int i, REG nat);

/* Sets the physical GR[i] for cproc */
BOOL phyGrSet(int cproc, int i, REG val);
Expand All @@ -603,7 +603,7 @@ BOOL phyGrSet(int cproc, int i, REG val);
BOOL phyPrSet(int cproc, int i, BOOL val);

/* Sets the virtual PR[i] for cproc */
BOOL prSet(int cproc, int i, BOOL val);
BOOL prSet(int cproc, int i, REG val);

/* Sets the psr for cproc */
BOOL psrSet(int cproc, REG val);
Expand Down Expand Up @@ -646,7 +646,7 @@ BOOL crSet(int cproc, int i, REG val);
BOOL bkrSet(int cproc, int i, REG val);

/* Sets the banked GR[i].nat for cproc */
BOOL bkrNatSet(int cproc, int i, BOOL val);
BOOL bkrNatSet(int cproc, int i, REG val);

/* Sets RR[i] for cproc */
BOOL rrSet(int cproc, int i, REG val);
Expand Down
15 changes: 11 additions & 4 deletions src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ typedef enum {
* Internal symbol interface
*-------------------------------------------------------------------------*/

typedef REG (*PGetFn)(/* TODO: add prototype here */);
typedef BOOL (*PSetFn)(/* TODO: add prototype here */);
typedef REG (*PGetFn1)(int);
typedef REG (*PGetFn2)(int, int);
typedef BOOL (*PSetFn2)(int, REG);
typedef BOOL (*PSetFn3)(int, int, REG);

typedef enum {
SINGLE_SYM,
Expand Down Expand Up @@ -54,8 +56,13 @@ typedef enum {
struct isym {
char name[NAMLEN]; /* internal symbol name */
Symtyp type; /* internal symbol type */
PGetFn getFn;
PSetFn setFn;

PGetFn1 getFn1;
PGetFn2 getFn2;

PSetFn2 setFn2;
PSetFn3 setFn3;

void *pval;
BOOL readonly; /* is symbol read-only */
unsigned len; /* subfield length (len == 0 => not a subfld) */
Expand Down

0 comments on commit be3dee3

Please sign in to comment.