From 4b0c4ca7fb0aa9207af3398e04534b23fbb88f27 Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Fri, 9 Sep 2016 14:03:25 -0700 Subject: New upb_msg code and Lua bindings around it. There are still some things that are unfinished, but we are at parity with what Lua had before. --- upb/shim/shim.c | 84 --------------------------------------------------------- upb/shim/shim.h | 69 ----------------------------------------------- 2 files changed, 153 deletions(-) delete mode 100644 upb/shim/shim.c delete mode 100644 upb/shim/shim.h (limited to 'upb/shim') diff --git a/upb/shim/shim.c b/upb/shim/shim.c deleted file mode 100644 index 1429332..0000000 --- a/upb/shim/shim.c +++ /dev/null @@ -1,84 +0,0 @@ - -#include "upb/shim/shim.h" - -/* Fallback implementation if the shim is not specialized by the JIT. */ -#define SHIM_WRITER(type, ctype) \ - bool upb_shim_set ## type (void *c, const void *hd, ctype val) { \ - uint8_t *m = c; \ - const upb_shim_data *d = hd; \ - if (d->hasbit > 0) \ - *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \ - *(ctype*)&m[d->offset] = val; \ - return true; \ - } \ - -SHIM_WRITER(double, double) -SHIM_WRITER(float, float) -SHIM_WRITER(int32, int32_t) -SHIM_WRITER(int64, int64_t) -SHIM_WRITER(uint32, uint32_t) -SHIM_WRITER(uint64, uint64_t) -SHIM_WRITER(bool, bool) -#undef SHIM_WRITER - -bool upb_shim_set(upb_handlers *h, const upb_fielddef *f, size_t offset, - int32_t hasbit) { - upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; - bool ok; - - upb_shim_data *d = upb_gmalloc(sizeof(*d)); - if (!d) return false; - d->offset = offset; - d->hasbit = hasbit; - - upb_handlerattr_sethandlerdata(&attr, d); - upb_handlerattr_setalwaysok(&attr, true); - upb_handlers_addcleanup(h, d, upb_gfree); - -#define TYPE(u, l) \ - case UPB_TYPE_##u: \ - ok = upb_handlers_set##l(h, f, upb_shim_set##l, &attr); break; - - ok = false; - - switch (upb_fielddef_type(f)) { - TYPE(INT64, int64); - TYPE(INT32, int32); - TYPE(ENUM, int32); - TYPE(UINT64, uint64); - TYPE(UINT32, uint32); - TYPE(DOUBLE, double); - TYPE(FLOAT, float); - TYPE(BOOL, bool); - default: UPB_ASSERT(false); break; - } -#undef TYPE - - upb_handlerattr_uninit(&attr); - return ok; -} - -const upb_shim_data *upb_shim_getdata(const upb_handlers *h, upb_selector_t s, - upb_fieldtype_t *type) { - upb_func *f = upb_handlers_gethandler(h, s); - - if ((upb_int64_handlerfunc*)f == upb_shim_setint64) { - *type = UPB_TYPE_INT64; - } else if ((upb_int32_handlerfunc*)f == upb_shim_setint32) { - *type = UPB_TYPE_INT32; - } else if ((upb_uint64_handlerfunc*)f == upb_shim_setuint64) { - *type = UPB_TYPE_UINT64; - } else if ((upb_uint32_handlerfunc*)f == upb_shim_setuint32) { - *type = UPB_TYPE_UINT32; - } else if ((upb_double_handlerfunc*)f == upb_shim_setdouble) { - *type = UPB_TYPE_DOUBLE; - } else if ((upb_float_handlerfunc*)f == upb_shim_setfloat) { - *type = UPB_TYPE_FLOAT; - } else if ((upb_bool_handlerfunc*)f == upb_shim_setbool) { - *type = UPB_TYPE_BOOL; - } else { - return NULL; - } - - return (const upb_shim_data*)upb_handlers_gethandlerdata(h, s); -} diff --git a/upb/shim/shim.h b/upb/shim/shim.h deleted file mode 100644 index 935f085..0000000 --- a/upb/shim/shim.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -** For handlers that do very tiny, very simple operations, the function call -** overhead of calling a handler can be significant. This file allows the -** user to define handlers that do something very simple like store the value -** to memory and/or set a hasbit. JIT compilers can then special-case these -** handlers and emit specialized code for them instead of actually calling the -** handler. -** -** The functionality is very simple/limited right now but may expand to be able -** to call another function. -*/ - -#ifndef UPB_SHIM_H -#define UPB_SHIM_H - -#include "upb/handlers.h" - -typedef struct { - size_t offset; - int32_t hasbit; -} upb_shim_data; - -#ifdef __cplusplus - -namespace upb { - -struct Shim { - typedef upb_shim_data Data; - - /* Sets a handler for the given field that writes the value to the given - * offset and, if hasbit >= 0, sets a bit at the given bit offset. Returns - * true if the handler was set successfully. */ - static bool Set(Handlers *h, const FieldDef *f, size_t ofs, int32_t hasbit); - - /* If this handler is a shim, returns the corresponding upb::Shim::Data and - * stores the type in "type". Otherwise returns NULL. */ - static const Data* GetData(const Handlers* h, Handlers::Selector s, - FieldDef::Type* type); -}; - -} /* namespace upb */ - -#endif - -UPB_BEGIN_EXTERN_C - -/* C API. */ -bool upb_shim_set(upb_handlers *h, const upb_fielddef *f, size_t offset, - int32_t hasbit); -const upb_shim_data *upb_shim_getdata(const upb_handlers *h, upb_selector_t s, - upb_fieldtype_t *type); - -UPB_END_EXTERN_C - -#ifdef __cplusplus -/* C++ Wrappers. */ -namespace upb { -inline bool Shim::Set(Handlers* h, const FieldDef* f, size_t ofs, - int32_t hasbit) { - return upb_shim_set(h, f, ofs, hasbit); -} -inline const Shim::Data* Shim::GetData(const Handlers* h, Handlers::Selector s, - FieldDef::Type* type) { - return upb_shim_getdata(h, s, type); -} -} /* namespace upb */ -#endif - -#endif /* UPB_SHIM_H */ -- cgit v1.2.3