Add conversion between v-c oa_present and fellow stable values

parent 7576da5e
......@@ -303,6 +303,117 @@ fcsc_next(struct fcscursor *c)
return (&c->fcsl->segs[c->u++]);
}
/*
* fdo attribues we want to keep our own enum and, consequently, bitfield
* stable. so we define the enum manually and then generate code from the table
* files to ensure that all values in the tables are defined
*/
enum fdo_attr {
FDOA_FLAGS = 0,
FDOA_LEN,
FDOA_VXID,
FDOA_LASTMODIFIED,
FDOA_GZIPBITS,
FDOA_VARY,
FDOA_HEADERS,
FDOA_ESIDATA,
FDOA__MAX
};
/*
* the sl and sr functions are to avoid shift left/right by negative amount
* errors. the compiler emits these before eliminating dead code
*/
static inline uint16_t
sl(uint16_t v, uint8_t b) {
//lint -e{701} shift left of signed -- WEIRD
//lint -e{734} loss of precision
return (v << b);
}
static inline uint16_t
sr(uint16_t v, uint8_t b) {
return (v >> b);
}
static uint16_t
fdoa2oa_present(const uint16_t fdoa) {
uint16_t oa = 0;
//lint --e{506} constant value boolean
//lint --e{774} boolean always false
//lint --e{570} loss if sign
//lint --e{778} constant 0 in -
#define HANDLE_FDOA(x) do { \
assert((int)OA_##x < UINT8_MAX); \
assert((int)FDOA_##x < UINT8_MAX); \
if ((uint8_t)OA_##x == (uint8_t)FDOA_##x) \
oa |= fdoa & (1 << (uint8_t)FDOA_##x); \
else if ((uint8_t)OA_##x > (uint8_t)FDOA_##x) { \
oa |= sl(fdoa & (1 << (uint8_t)FDOA_##x), \
(uint8_t)OA_##x - (uint8_t)FDOA_##x); \
} \
else { \
oa |= sr(fdoa & (1 << (uint8_t)FDOA_##x), \
(uint8_t)FDOA_##x - (uint8_t)OA_##x); \
} \
} while(0)
#define FDO_FIXATTR(U, l, s, ss) HANDLE_FDOA(U);
#define FDO_VARATTR(U, l) HANDLE_FDOA(U);
#define FDO_AUXATTR(U, l) HANDLE_FDOA(U);
#include "tbl/fellow_obj_attr.h"
#undef HANDLE_FDOA
return (oa);
}
static uint16_t
oa2fdoa_present(const uint16_t oa) {
uint16_t fdoa = 0;
#define HANDLE_OA(x) do { \
assert((int)OA_##x < UINT8_MAX); \
assert((int)FDOA_##x < UINT8_MAX); \
if ((uint8_t)OA_##x == (uint8_t)FDOA_##x) \
fdoa |= oa & (1 << (uint8_t)OA_##x); \
else if ((uint8_t)OA_##x > (uint8_t)FDOA_##x) { \
fdoa |= sr(oa & (1 << (uint8_t)OA_##x), \
(uint8_t)OA_##x - (uint8_t)FDOA_##x); \
} \
else { \
fdoa |= sl(oa & (1 << (uint8_t)OA_##x), \
(uint8_t)FDOA_##x - (uint8_t)OA_##x); \
} \
} while(0)
#define OBJ_FIXATTR(U, l, s) HANDLE_OA(U);
#define OBJ_VARATTR(U, l) HANDLE_OA(U);
#define OBJ_AUXATTR(U, l) HANDLE_OA(U);
#include "tbl/obj_attr.h"
#undef HANDLE_OA
return (fdoa);
}
static void __attribute__((constructor))
assert_oa_fdoa(void)
{
assert(oa2fdoa_present(1 << (uint8_t)OA_LEN | 1 << (uint8_t)OA_VXID) ==
(1 << (uint8_t)FDOA_LEN | 1 << (uint8_t)FDOA_VXID));
#define HANDLE_OA(x) \
assert(oa2fdoa_present(1 << (uint8_t)OA_##x) == (1 << (uint8_t)FDOA_##x)); \
assert(fdoa2oa_present(1 << (uint8_t)FDOA_##x) == (1 << (uint8_t)OA_##x)); \
#define OBJ_FIXATTR(U, l, s) HANDLE_OA(U);
#define OBJ_VARATTR(U, l) HANDLE_OA(U);
#define OBJ_AUXATTR(U, l) HANDLE_OA(U);
#include "tbl/obj_attr.h"
#undef HANDLE_OA
}
// fdo_flags
#define FDO_F_INLOG 1
#define FDO_F_VXID64 2 // vxid uses 8 bytes
......
......@@ -22,6 +22,9 @@
-emacro(525, DLE_N) // Negative indent
-emacro(160, VSTAILQ_LAST) // sequence ({
-emacro(160, _vtake) // sequence ({
// conflict between OA and VXID() macro
-esym(123, VXID)
-esym(760, FH_*) // defined identically...
//bitf.h only used for test
-esym(768, bitf::extra)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment