Skip to content

Commit

Permalink
Add helper function to get Stats from function bags
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Pfeiffer committed Nov 20, 2018
1 parent d87ce06 commit 3de9738
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ enum {
OFFSET_FIRST_STAT = sizeof(StatHeader)+sizeof(BodyHeader)
};



/****************************************************************************
**
*S T_<name> . . . . . . . . . . . . . . symbolic names for statement types
Expand Down Expand Up @@ -280,9 +278,25 @@ enum STAT_TNUM {
** 'ADDR_STAT' returns the absolute address of the memory block of the
** statement <stat>.
*/
#define ADDR_STAT(stat) ((Stat *)(((char *)STATE(PtrBody)) + (stat)))
#define CONST_ADDR_STAT(stat) \
((const Stat *)(((const char *)STATE(PtrBody)) + (stat)))
static inline Stat * ADDR_BODY_STAT(Stat * body, Stat stat)
{
return ((Stat *)(((char *)(body)) + (stat)));
}
static inline const Stat * CONST_ADDR_BODY_STAT(Stat * body, Stat stat)
{
return ((const Stat *)(((const char *)(body)) + (stat)));
}
static inline Stat * READ_BODY_STAT(Stat * body, Stat stat, UInt idx)
{
return (Stat *)ADDR_BODY_STAT(body, stat)[idx];
}
static inline const Stat *
CONST_READ_BODY_STAT(Stat * body, Stat stat, UInt idx)
{
return (const Stat *)CONST_ADDR_BODY_STAT(body, stat)[idx];
}
#define ADDR_STAT(stat) ADDR_BODY_STAT(STATE(PtrBody), stat)
#define CONST_ADDR_STAT(stat) CONST_ADDR_BODY_STAT(STATE(PtrBody), stat)

#define READ_STAT(stat, idx) (CONST_ADDR_STAT(stat)[idx])
#define WRITE_STAT(stat, idx, val) ADDR_STAT(stat)[idx] = val
Expand Down

0 comments on commit 3de9738

Please sign in to comment.