summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile11
-rw-r--r--tests/test_def.c54
-rw-r--r--upb/bindings/googlepb/proto2.cc26
-rw-r--r--upb/json/parser.c894
-rw-r--r--upb/json/parser.h112
-rw-r--r--upb/json/parser.rl623
-rw-r--r--upb/json/printer.c (renamed from upb/json/typed_printer.c)63
-rw-r--r--upb/json/printer.h97
-rw-r--r--upb/json/typed_printer.h105
-rw-r--r--upb/pb/compile_decoder_x64.h859
-rw-r--r--upb/sink.h2
-rw-r--r--upb/symtab.c5
12 files changed, 2221 insertions, 630 deletions
diff --git a/Makefile b/Makefile
index e1c6f67..dcff210 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@
# Prevents the deletion of intermediate files.
.SECONDARY:
-UPB_MODULES = upb upb.pb upb.descriptor
+UPB_MODULES = upb upb.pb upb.json upb.descriptor
UPB_LIBS = $(patsubst %,lib/lib%.a,$(UPB_MODULES))
UPB_PICLIBS = $(patsubst %,lib/lib%_pic.a,$(UPB_MODULES))
@@ -155,7 +155,14 @@ upb/pb/compile_decoder_x64.h: upb/pb/compile_decoder_x64.dasc
endif
upb_json_SRCS = \
- upb/json/typed_printer.c
+ upb/json/parser.c \
+
+ # disabled until we move off YAJL (which should be soon).
+ #upb/json/printer.c \
+
+upb/json/parser.c: upb/json/parser.rl
+ $(E) RAGEL $<
+ $(Q) ragel -C -o upb/json/parser.c upb/json/parser.rl
# If the user doesn't specify an -O setting, we use -O3 for critical-path
# code and -Os for the rest.
diff --git a/tests/test_def.c b/tests/test_def.c
index 92b461f..84082df 100644
--- a/tests/test_def.c
+++ b/tests/test_def.c
@@ -73,6 +73,8 @@ static void test_cycles() {
const upb_fielddef *f = upb_msgdef_itof(m, 1);
ASSERT(f);
ASSERT(upb_fielddef_hassubdef(f));
+ ASSERT(upb_msgdef_ntofz(m, "b") == f);
+ ASSERT(upb_msgdef_ntof(m, "b", 1) == f);
const upb_def *def2 = upb_fielddef_subdef(f);
ASSERT(upb_downcast_msgdef(def2));
ASSERT(strcmp(upb_def_fullname(def2), "B") == 0);
@@ -85,6 +87,57 @@ static void test_cycles() {
upb_def_unref(def2, &def2);
}
+static void test_symbol_resolution() {
+ upb_status s = UPB_STATUS_INIT;
+
+ upb_symtab *symtab = upb_symtab_new(&symtab);
+ ASSERT(symtab);
+
+ // m1 has name "A.B.C" and no fields. We'll add it to the symtab now.
+ upb_msgdef *m1 = upb_msgdef_new(&m1);
+ ASSERT(m1);
+ ASSERT_STATUS(upb_msgdef_setfullname(m1, "A.B.C", &s), &s);
+ ASSERT_STATUS(upb_symtab_add(symtab, (upb_def**)&m1, 1,
+ NULL, &s), &s);
+
+ // m2 has name "D.E" and no fields. We'll add it in the same batch as m3
+ // below.
+ upb_msgdef *m2 = upb_msgdef_new(&m2);
+ ASSERT(m2);
+ ASSERT_STATUS(upb_msgdef_setfullname(m2, "D.E", &s), &s);
+
+ // m3 has name "F.G" and two fields, of type A.B.C and D.E respectively. We'll
+ // add it in the same batch as m2 above.
+ upb_msgdef *m3 = upb_msgdef_new(&m3);
+ ASSERT(m3);
+ ASSERT_STATUS(upb_msgdef_setfullname(m3, "F.G", &s), &s);
+ upb_fielddef *m3_field1 = upb_fielddef_new(&m3_field1);
+ ASSERT_STATUS(upb_fielddef_setname(m3_field1, "field1", &s), &s);
+ ASSERT_STATUS(upb_fielddef_setnumber(m3_field1, 1, &s), &s);
+ upb_fielddef_setlabel(m3_field1, UPB_LABEL_OPTIONAL);
+ upb_fielddef_settype(m3_field1, UPB_TYPE_MESSAGE);
+ ASSERT_STATUS(upb_fielddef_setsubdefname(m3_field1, ".A.B.C", &s), &s);
+ ASSERT_STATUS(upb_msgdef_addfield(m3, m3_field1, NULL, &s), &s);
+
+ upb_fielddef *m3_field2 = upb_fielddef_new(&m3_field2);
+ ASSERT_STATUS(upb_fielddef_setname(m3_field2, "field2", &s), &s);
+ ASSERT_STATUS(upb_fielddef_setnumber(m3_field2, 2, &s), &s);
+ upb_fielddef_setlabel(m3_field2, UPB_LABEL_OPTIONAL);
+ upb_fielddef_settype(m3_field2, UPB_TYPE_MESSAGE);
+ ASSERT_STATUS(upb_fielddef_setsubdefname(m3_field2, ".D.E", &s), &s);
+ ASSERT_STATUS(upb_msgdef_addfield(m3, m3_field2, NULL, &s), &s);
+
+ upb_def *defs[2] = { (upb_def*)m2, (upb_def*)m3 };
+ ASSERT_STATUS(upb_symtab_add(symtab, defs, 2, NULL, &s), &s);
+
+ upb_fielddef_unref(m3_field2, &m3_field2);
+ upb_fielddef_unref(m3_field1, &m3_field1);
+ upb_msgdef_unref(m3, &m3);
+ upb_msgdef_unref(m2, &m2);
+ upb_msgdef_unref(m1, &m1);
+ upb_symtab_unref(symtab, &symtab);
+}
+
static void test_fielddef_unref() {
upb_symtab *s = load_test_proto(&s);
const upb_msgdef *md = upb_symtab_lookupmsg(s, "A");
@@ -283,6 +336,7 @@ int run_tests(int argc, char *argv[]) {
descriptor_file = argv[1];
test_empty_symtab();
test_cycles();
+ test_symbol_resolution();
test_fielddef_accessors();
test_fielddef_unref();
test_replacement();
diff --git a/upb/bindings/googlepb/proto2.cc b/upb/bindings/googlepb/proto2.cc
index 498ae2d..3911172 100644
--- a/upb/bindings/googlepb/proto2.cc
+++ b/upb/bindings/googlepb/proto2.cc
@@ -978,32 +978,32 @@ case goog::FieldDescriptor::cpptype: \
}
};
-#ifdef GOOGLE_PROTOBUF_HAS_ARENAS
- // Closure is a RepeatedPtrField<SubMessageType>*, but we access it through
- // its base class RepeatedPtrFieldBase*.
- static goog::Message* StartRepeatedSubMessage(
- goog::internal::RepeatedPtrFieldBase* r,
- const SubMessageHandlerData* data) {
- goog::Message* submsg = data->prototype()->New(r->GetArenaNoVirtual());
- r->AddAllocated<RepeatedMessageTypeHandler>(submsg);
- return submsg;
- }
-#else // ifdef GOOGLE_PROTOBUF_HAS_ARENAS
// Closure is a RepeatedPtrField<SubMessageType>*, but we access it through
// its base class RepeatedPtrFieldBase*.
static goog::Message* StartRepeatedSubMessage(
goog::internal::RepeatedPtrFieldBase* r,
const SubMessageHandlerData* data) {
+#ifdef GOOGLE_PROTOBUF_HAS_ARENAS
+ return r->Add<RepeatedMessageTypeHandler>(
+ const_cast<goog::Message*>(data->prototype()));
+#else
+ // This code path is required not because of arena-related API changes but
+ // because the variant of Add<>() that takes a prototype object was added
+ // only recently. Without the prototype, there's no way for Add<>() to
+ // create a new submessage with out typehandler implementation because we
+ // don't have New() (because we don't template-specialize our typehandler
+ // class on concrete message types). So we have to implement the runtime
+ // polymorphism externally (in this function) and then use AddAllocated to
+ // insert the pointer.
goog::Message* submsg = r->AddFromCleared<RepeatedMessageTypeHandler>();
if (!submsg) {
submsg = data->prototype()->New();
r->AddAllocated<RepeatedMessageTypeHandler>(submsg);
}
return submsg;
+#endif
}
-#endif // ifdef GOOGLE_PROTOBUF_HAS_ARENAS
-
#ifdef GOOGLE_PROTOBUF_HAS_ONEOF
static goog::Message* StartOneofSubMessage(
goog::Message* m, const OneofSubMessageHandlerData* data) {
diff --git a/upb/json/parser.c b/upb/json/parser.c
new file mode 100644
index 0000000..ba8582b
--- /dev/null
+++ b/upb/json/parser.c
@@ -0,0 +1,894 @@
+
+#line 1 "upb/json/parser.rl"
+/*
+ * upb - a minimalist implementation of protocol buffers.
+ *
+ * Copyright (c) 2014 Google Inc. See LICENSE for details.
+ * Author: Josh Haberman <jhaberman@gmail.com>
+ *
+ * A parser that uses the Ragel State Machine Compiler to generate
+ * the finite automata.
+ *
+ * Ragel only natively handles regular languages, but we can manually
+ * program it a bit to handle context-free languages like JSON, by using
+ * the "fcall" and "fret" constructs.
+ *
+ * This parser can handle the basics, but needs several things to be fleshed
+ * out:
+ *
+ * - handling of unicode escape sequences (including high surrogate pairs).
+ * - properly check and report errors for unknown fields, stack overflow,
+ * improper array nesting (or lack of nesting).
+ * - handling of base64 sequences with padding characters.
+ * - handling of push-back (non-success returns from sink functions).
+ * - handling of keys/escape-sequences/etc that span input buffers.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <assert.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include "upb/json/parser.h"
+
+#define CHECK_RETURN(x) if (!(x)) return false
+
+static upb_selector_t getsel_for_handlertype(upb_json_parser *p,
+ upb_handlertype_t type) {
+ upb_selector_t sel;
+ bool ok = upb_handlers_getselector(p->top->f, type, &sel);
+ UPB_ASSERT_VAR(ok, ok);
+ return sel;
+}
+
+static upb_selector_t getsel(upb_json_parser *p) {
+ return getsel_for_handlertype(
+ p, upb_handlers_getprimitivehandlertype(p->top->f));
+}
+
+static void start_member(upb_json_parser *p) {
+ assert(!p->top->f);
+ assert(!p->accumulated);
+ p->accumulated_len = 0;
+}
+
+static bool end_member(upb_json_parser *p) {
+ // TODO(haberman): support keys that span buffers or have escape sequences.
+ assert(!p->top->f);
+ assert(p->accumulated);
+ const upb_fielddef *f =
+ upb_msgdef_ntof(p->top->m, p->accumulated, p->accumulated_len);
+
+ if (!f) {
+ // TODO(haberman): Ignore unknown fields if requested/configured to do so.
+ upb_status_seterrf(p->status, "No such field: %.*s\n",
+ (int)p->accumulated_len, p->accumulated);
+ return false;
+ }
+
+ p->top->f = f;
+ p->accumulated = NULL;
+
+ return true;
+}
+
+static void start_object(upb_json_parser *p) {
+ upb_sink_startmsg(&p->top->sink);
+}
+
+static void end_object(upb_json_parser *p) {
+ upb_status status;
+ upb_sink_endmsg(&p->top->sink, &status);
+}
+
+static bool check_stack(upb_json_parser *p) {
+ if ((p->top + 1) == p->limit) {
+ upb_status_seterrmsg(p->status, "Nesting too deep");
+ return false;
+ }
+
+ return true;
+}
+
+static bool start_subobject(upb_json_parser *p) {
+ assert(p->top->f);
+
+ if (!upb_fielddef_issubmsg(p->top->f)) {
+ upb_status_seterrf(p->status,
+ "Object specified for non-message/group field: %s",
+ upb_fielddef_name(p->top->f));
+ return false;
+ }
+
+ if (!check_stack(p)) return false;
+
+ upb_jsonparser_frame *inner = p->top + 1;
+
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG);
+ upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink);
+ inner->m = upb_fielddef_msgsubdef(p->top->f);
+ inner->f = NULL;
+ p->top = inner;
+
+ return true;
+}
+
+static void end_subobject(upb_json_parser *p) {
+ p->top--;
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG);
+ upb_sink_endsubmsg(&p->top->sink, sel);
+}
+
+static bool start_array(upb_json_parser *p) {
+ assert(p->top->f);
+
+ if (!upb_fielddef_isseq(p->top->f)) {
+ upb_status_seterrf(p->status,
+ "Array specified for non-repeated field: %s",
+ upb_fielddef_name(p->top->f));
+ return false;
+ }
+
+ if (!check_stack(p)) return false;
+
+ upb_jsonparser_frame *inner = p->top + 1;
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ);
+ upb_sink_startseq(&p->top->sink, sel, &inner->sink);
+ inner->m = p->top->m;
+ inner->f = p->top->f;
+ p->top = inner;
+
+ return true;
+}
+
+static void end_array(upb_json_parser *p) {
+ assert(p->top > p->stack);
+
+ p->top--;
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ);
+ upb_sink_endseq(&p->top->sink, sel);
+}
+
+static void clear_member(upb_json_parser *p) { p->top->f = NULL; }
+
+static bool putbool(upb_json_parser *p, bool val) {
+ if (upb_fielddef_type(p->top->f) != UPB_TYPE_BOOL) {
+ upb_status_seterrf(p->status,
+ "Boolean value specified for non-bool field: %s",
+ upb_fielddef_name(p->top->f));
+ return false;
+ }
+
+ bool ok = upb_sink_putbool(&p->top->sink, getsel(p), val);
+ UPB_ASSERT_VAR(ok, ok);
+ return true;
+}
+
+static void start_text(upb_json_parser *p, const char *ptr) {
+ p->text_begin = ptr;
+}
+
+static const signed char b64table[] = {
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 62/*+*/, -1, -1, -1, 63/*/ */,
+ 52/*0*/, 53/*1*/, 54/*2*/, 55/*3*/, 56/*4*/, 57/*5*/, 58/*6*/, 59/*7*/,
+ 60/*8*/, 61/*9*/, -1, -1, -1, -1, -1, -1,
+ -1, 0/*A*/, 1/*B*/, 2/*C*/, 3/*D*/, 4/*E*/, 5/*F*/, 6/*G*/,
+ 07/*H*/, 8/*I*/, 9/*J*/, 10/*K*/, 11/*L*/, 12/*M*/, 13/*N*/, 14/*O*/,
+ 15/*P*/, 16/*Q*/, 17/*R*/, 18/*S*/, 19/*T*/, 20/*U*/, 21/*V*/, 22/*W*/,
+ 23/*X*/, 24/*Y*/, 25/*Z*/, -1, -1, -1, -1, -1,
+ -1, 26/*a*/, 27/*b*/, 28/*c*/, 29/*d*/, 30/*e*/, 31/*f*/, 32/*g*/,
+ 33/*h*/, 34/*i*/, 35/*j*/, 36/*k*/, 37/*l*/, 38/*m*/, 39/*n*/, 40/*o*/,
+ 41/*p*/, 42/*q*/, 43/*r*/, 44/*s*/, 45/*t*/, 46/*u*/, 47/*v*/, 48/*w*/,
+ 49/*x*/, 50/*y*/, 51/*z*/, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1
+};
+
+// Returns the table value sign-extended to 32 bits. Knowing that the upper
+// bits will be 1 for unrecognized characters makes it easier to check for
+// this error condition later (see below).
+int32_t b64lookup(unsigned char ch) { return b64table[ch]; }
+
+// Returns true if the given character is not a valid base64 character or
+// padding.
+bool nonbase64(unsigned char ch) { return b64lookup(ch) == -1 && ch != '='; }
+
+static bool base64_push(upb_json_parser *p, upb_selector_t sel, const char *ptr,
+ size_t len) {
+ const char *limit = ptr + len;
+ for (; ptr < limit; ptr += 4) {
+ if (limit - ptr < 4) {
+ upb_status_seterrf(p->status,
+ "Base64 input for bytes field not a multiple of 4: %s",
+ upb_fielddef_name(p->top->f));
+ return false;
+ }
+
+ uint32_t val = b64lookup(ptr[0]) << 18 |
+ b64lookup(ptr[1]) << 12 |
+ b64lookup(ptr[2]) << 6 |
+ b64lookup(ptr[3]);
+
+ // Test the upper bit; returns true if any of the characters returned -1.
+ if (val & 0x80000000) {
+ goto otherchar;
+ }
+
+ char output[3];
+ output[0] = val >> 16;
+ output[1] = (val >> 8) & 0xff;
+ output[2] = val & 0xff;
+ upb_sink_putstring(&p->top->sink, sel, output, 3, NULL);
+ }
+ return true;
+
+otherchar:
+ if (nonbase64(ptr[0]) || nonbase64(ptr[1]) || nonbase64(ptr[2]) ||
+ nonbase64(ptr[3]) ) {
+ upb_status_seterrf(p->status,
+ "Non-base64 characters in bytes field: %s",
+ upb_fielddef_name(p->top->f));
+ return false;
+ } if (ptr[2] == '=') {
+ // Last group contains only two input bytes, one output byte.
+ if (ptr[0] == '=' || ptr[1] == '=' || ptr[3] != '=') {
+ goto badpadding;
+ }
+
+ uint32_t val = b64lookup(ptr[0]) << 18 |
+ b64lookup(ptr[1]) << 12;
+
+ assert(!(val & 0x80000000));
+ char output = val >> 16;
+ upb_sink_putstring(&p->top->sink, sel, &output, 1, NULL);
+ return true;
+ } else {
+ // Last group contains only three input bytes, two output bytes.
+ if (ptr[0] == '=' || ptr[1] == '=' || ptr[2] == '=') {
+ goto badpadding;
+ }
+
+ uint32_t val = b64lookup(ptr[0]) << 18 |
+ b64lookup(ptr[1]) << 12 |
+ b64lookup(ptr[2]) << 6;
+
+ char output[2];
+ output[0] = val >> 16;
+ output[1] = (val >> 8) & 0xff;
+ upb_sink_putstring(&p->top->sink, sel, output, 2, NULL);
+ return true;
+ }
+
+badpadding:
+ upb_status_seterrf(p->status,
+ "Incorrect base64 padding for field: %s (%.*s)",
+ upb_fielddef_name(p->top->f),
+ 4, ptr);
+ return false;
+}
+
+static bool end_text(upb_json_parser *p, const char *ptr) {
+ assert(!p->accumulated); // TODO: handle this case.
+ p->accumulated = p->text_begin;
+ p->accumulated_len = ptr - p->text_begin;
+
+ if (p->top->f && upb_fielddef_isstring(p->top->f)) {
+ // This is a string field (as opposed to a member name).
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STRING);
+ if (upb_fielddef_type(p->top->f) == UPB_TYPE_BYTES) {
+ CHECK_RETURN(base64_push(p, sel, p->accumulated, p->accumulated_len));
+ } else {
+ upb_sink_putstring(&p->top->sink, sel, p->accumulated, p->accumulated_len, NULL);
+ }
+ p->accumulated = NULL;
+ }
+
+ return true;
+}
+
+static bool start_stringval(upb_json_parser *p) {
+ assert(p->top->f);
+
+ if (!upb_fielddef_isstring(p->top->f)) {
+ upb_status_seterrf(p->status,
+ "String specified for non-string field: %s",
+ upb_fielddef_name(p->top->f));
+ return false;
+ }
+
+ if (!check_stack(p)) return false;
+
+ upb_jsonparser_frame *inner = p->top + 1; // TODO: check for overflow.
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR);
+ upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink);
+ inner->m = p->top->m;
+ inner->f = p->top->f;
+ p->top = inner;
+
+ return true;
+}
+
+static void end_stringval(upb_json_parser *p) {
+ p->top--;
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR);
+ upb_sink_endstr(&p->top->sink, sel);
+}
+
+static void start_number(upb_json_parser *p, const char *ptr) {
+ start_text(p, ptr);
+ assert(p->accumulated == NULL);
+}
+
+static void end_number(upb_json_parser *p, const char *ptr) {
+ end_text(p, ptr);
+ const char *myend = p->accumulated + p->accumulated_len;
+ char *end;
+
+ switch (upb_fielddef_type(p->top->f)) {
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32: {
+ long val = strtol(p->accumulated, &end, 0);
+ if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || end != myend)
+ assert(false);
+ else
+ upb_sink_putint32(&p->top->sink, getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_INT64: {
+ long long val = strtoll(p->accumulated, &end, 0);
+ if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || end != myend)
+ assert(false);
+ else
+ upb_sink_putint64(&p->top->sink, getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_UINT32: {
+ unsigned long val = strtoul(p->accumulated, &end, 0);
+ if (val > UINT32_MAX || errno == ERANGE || end != myend)
+ assert(false);
+ else
+ upb_sink_putuint32(&p->top->sink, getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_UINT64: {
+ unsigned long long val = strtoull(p->accumulated, &end, 0);
+ if (val > UINT64_MAX || errno == ERANGE || end != myend)
+ assert(false);
+ else
+ upb_sink_putuint64(&p->top->sink, getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_DOUBLE: {
+ double val = strtod(p->accumulated, &end);
+ if (errno == ERANGE || end != myend)
+ assert(false);
+ else
+ upb_sink_putdouble(&p->top->sink, getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_FLOAT: {
+ float val = strtof(p->accumulated, &end);
+ if (errno == ERANGE || end != myend)
+ assert(false);
+ else
+ upb_sink_putfloat(&p->top->sink, getsel(p), val);
+ break;
+ }
+ default:
+ assert(false);
+ }
+
+ p->accumulated = NULL;
+}
+
+static char escape_char(char in) {
+ switch (in) {
+ case 'r': return '\r';
+ case 't': return '\t';
+ case 'n': return '\n';
+ case 'f': return '\f';
+ case 'b': return '\b';
+ case '/': return '/';
+ case '"': return '"';
+ case '\\': return '\\';
+ default:
+ assert(0);
+ return 'x';
+ }
+}
+
+static void escape(upb_json_parser *p, const char *ptr) {
+ char ch = escape_char(*ptr);
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STRING);
+ upb_sink_putstring(&p->top->sink, sel, &ch, 1, NULL);
+}
+
+static uint8_t hexdigit(char ch) {
+ if (ch >= '0' && ch <= '9') {
+ return ch - '0';
+ } else if (ch >= 'a' && ch <= 'f') {
+ return ch - 'a' + 10;
+ } else {
+ assert(ch >= 'A' && ch <= 'F');
+ return ch - 'A' + 10;
+ }
+}
+
+static void start_hex(upb_json_parser *p, const char *ptr) {
+ start_text(p, ptr);
+}
+
+static void hex(upb_json_parser *p, const char *end) {
+ UPB_UNUSED(end);
+ const char *start = p->text_begin;
+ assert(end - start == 4);
+ uint16_t codepoint =
+ (hexdigit(start[0]) << 12) |
+ (hexdigit(start[1]) << 8) |
+ (hexdigit(start[2]) << 4) |
+ hexdigit(start[3]);
+ // TODO(haberman): convert to UTF-8 and emit (though if it is a high surrogate
+ // we have to wait for the next escape to get the full code point).
+ UPB_UNUSED(codepoint);
+}
+
+#define CHECK_RETURN_TOP(x) if (!(x)) goto error
+
+// What follows is the Ragel parser itself. The language is specified in Ragel
+// and the actions call our C functions above.
+
+#line 548 "upb/json/parser.rl"
+
+
+
+#line 466 "upb/json/parser.c"
+static const char _json_actions[] = {
+ 0, 1, 0, 1, 2, 1, 3, 1,
+ 4, 1, 5, 1, 6, 1, 7, 1,
+ 9, 1, 11, 1, 12, 1, 13, 1,
+ 14, 1, 15, 1, 16, 1, 24, 1,
+ 26, 2, 3, 7, 2, 5, 2, 2,
+ 5, 7, 2, 10, 8, 2, 12, 14,
+ 2, 13, 14, 2, 17, 1, 2, 18,
+ 26, 2, 19, 8, 2, 20, 26, 2,
+ 21, 26, 2, 22, 26, 2, 23, 26,
+ 2, 25, 26, 3, 13, 10, 8
+};
+
+static const unsigned char _json_key_offsets[] = {
+ 0, 0, 4, 9, 14, 18, 22, 27,
+ 32, 37, 41, 45, 48, 51, 53, 57,
+ 61, 63, 65, 70, 72, 74, 83, 89,
+ 95, 101, 107, 109, 118, 118, 118, 123,
+ 128, 133, 133, 134, 135, 136, 137, 137,
+ 138, 139, 140, 140, 141, 142, 143, 143,
+ 148, 153, 157, 161, 166, 171, 176, 180,
+ 180, 183, 183, 183
+};
+
+static const char _json_trans_keys[] = {
+ 32, 123, 9, 13, 32, 34, 125, 9,
+ 13, 32, 34, 125, 9, 13, 32, 58,
+ 9, 13, 32, 58, 9, 13, 32, 93,
+ 125, 9, 13, 32, 44, 125, 9, 13,
+ 32, 44, 125, 9, 13, 32, 34, 9,
+ 13, 45, 48, 49, 57, 48, 49, 57,
+ 46, 69, 101, 48, 57, 69, 101, 48,
+ 57, 43, 45, 48, 57, 48, 57, 48,
+ 57, 46, 69, 101, 48, 57, 34, 92,
+ 34, 92, 34, 47, 92, 98, 102, 110,
+ 114, 116, 117, 48, 57, 65, 70, 97,
+ 102, 48, 57, 65, 70, 97, 102, 48,
+ 57, 65, 70, 97, 102, 48, 57, 65,
+ 70, 97, 102, 34, 92, 34, 45, 91,
+ 102, 110, 116, 123, 48, 57, 32, 93,
+ 125, 9, 13, 32, 44, 93, 9, 13,
+ 32, 93, 125, 9, 13, 97, 108, 115,
+ 101, 117, 108, 108, 114, 117, 101, 32,
+ 34, 125, 9, 13, 32, 34, 125, 9,
+ 13, 32, 58, 9, 13, 32, 58, 9,
+ 13, 32, 93, 125, 9, 13, 32, 44,
+ 125, 9, 13, 32, 44, 125, 9, 13,
+ 32, 34, 9, 13, 32, 9, 13, 0
+};
+
+static const char _json_single_lengths[] = {
+ 0, 2, 3, 3, 2, 2, 3, 3,
+ 3, 2, 2, 1, 3, 0, 2, 2,
+ 0, 0, 3, 2, 2, 9, 0, 0,
+ 0, 0, 2, 7, 0, 0, 3, 3,
+ 3, 0, 1, 1, 1, 1, 0, 1,
+ 1, 1, 0, 1, 1, 1, 0, 3,
+ 3, 2, 2, 3, 3, 3, 2, 0,
+ 1, 0, 0, 0
+};
+
+static const char _json_range_lengths[] = {
+ 0, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 0, 1, 1, 1,
+ 1, 1, 1, 0, 0, 0, 3, 3,
+ 3, 3, 0, 1, 0, 0, 1, 1,
+ 1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 1, 1, 1, 1, 1, 1, 0,
+ 1, 0, 0, 0
+};
+
+static const short _json_index_offsets[] = {
+ 0, 0, 4, 9, 14, 18, 22, 27,
+ 32, 37, 41, 45, 48, 52, 54, 58,
+ 62, 64, 66, 71, 74, 77, 87, 91,
+ 95, 99, 103, 106, 115, 116, 117, 122,
+ 127, 132, 133, 135, 137, 139, 141, 142,
+ 144, 146, 148, 149, 151, 153, 155, 156,
+ 161, 166, 170, 174, 179, 184, 189, 193,
+ 194, 197, 198, 199
+};
+
+static const char _json_indicies[] = {
+ 0, 2, 0, 1, 3, 4, 5, 3,
+ 1, 6, 7, 8, 6, 1, 9, 10,
+ 9, 1, 11, 12, 11, 1, 12, 1,
+ 1, 12, 13, 14, 15, 16, 14, 1,
+ 17, 18, 8, 17, 1, 18, 7, 18,
+ 1, 19, 20, 21, 1, 20, 21, 1,
+ 23, 24, 24, 22, 25, 1, 24, 24,
+ 25, 22, 26, 26, 27, 1, 27, 1,
+ 27, 22, 23, 24, 24, 21, 22, 29,
+ 30, 28, 32, 33, 31, 34, 34, 34,
+ 34, 34, 34, 34, 34, 35, 1, 36,
+ 36, 36, 1, 37, 37, 37, 1, 38,
+ 38, 38, 1, 39, 39, 39, 1, 41,
+ 42, 40, 43, 44, 45, 46, 47, 48,
+ 49, 44, 1, 50, 51, 53, 54, 1,
+ 53, 52, 55, 56, 54, 55, 1, 56,
+ 1, 1, 56, 52, 57, 58, 1, 59,
+ 1, 60, 1, 61, 1, 62, 63, 1,
+ 64, 1, 65, 1, 66, 67, 1, 68,
+ 1, 69, 1, 70, 71, 72, 73, 71,
+ 1, 74, 75, 76, 74, 1, 77, 78,
+ 77, 1, 79, 80, 79, 1, 80, 1,
+ 1, 80, 81, 82, 83, 84, 82, 1,
+ 85, 86, 76, 85, 1, 86, 75, 86,
+ 1, 87, 88, 88, 1, 1, 1, 1,
+ 0
+};
+
+static const char _json_trans_targs[] = {
+ 1, 0, 2, 3, 4, 56, 3, 4,
+ 56, 5, 6, 5, 6, 7, 8, 9,
+ 56, 8, 9, 11, 12, 18, 57, 13,
+ 15, 14, 16, 17, 20, 58, 21, 20,
+ 58, 21, 19, 22, 23, 24, 25, 26,
+ 20, 58, 21, 28, 29, 30, 34, 39,
+ 43, 47, 59, 59, 31, 30, 33, 31,
+ 32, 59, 35, 36, 37, 38, 59, 40,
+ 41, 42, 59, 44, 45, 46, 59, 48,
+ 49, 55, 48, 49, 55, 50, 51, 50,
+ 51, 52, 53, 54, 55, 53, 54, 59,
+ 56
+};
+
+static const char _json_trans_actions[] = {
+ 0, 0, 0, 21, 75, 48, 0, 42,
+ 23, 17, 17, 0, 0, 15, 19, 19,
+ 45, 0, 0, 0, 0, 0, 1, 0,
+ 0, 0, 0, 0, 3, 13, 0, 0,
+ 33, 5, 11, 0, 7, 0, 0, 0,
+ 36, 39, 9, 57, 51, 25, 0, 0,
+ 0, 29, 60, 54, 15, 0, 27, 0,
+ 0, 31, 0, 0, 0, 0, 66, 0,
+ 0, 0, 69, 0, 0, 0, 63, 21,
+ 75, 48, 0, 42, 23, 17, 17, 0,
+ 0, 15, 19, 19, 45, 0, 0, 72,
+ 0
+};
+
+static const int json_start = 1;
+static const int json_first_final = 56;
+static const int json_error = 0;
+
+static const int json_en_number_machine = 10;
+static const int json_en_string_machine = 19;
+static const int json_en_value_machine = 27;
+static const int json_en_main = 1;
+
+
+#line 551 "upb/json/parser.rl"
+
+size_t parse(void *closure, const void *hd, const char *buf, size_t size,
+ const upb_bufhandle *handle) {
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+ upb_json_parser *parser = closure;
+
+ // Variables used by Ragel's generated code.
+ int cs = parser->current_state;
+ int *stack = parser->parser_stack;
+ int top = parser->parser_top;
+
+ const char *p = buf;
+ const char *pe = buf + size;
+
+
+#line 636 "upb/json/parser.c"
+ {
+ int _klen;
+ unsigned int _trans;
+ const char *_acts;
+ unsigned int _nacts;
+ const char *_keys;
+
+ if ( p == pe )
+ goto _test_eof;
+ if ( cs == 0 )
+ goto _out;
+_resume:
+ _keys = _json_trans_keys + _json_key_offsets[cs];
+ _trans = _json_index_offsets[cs];
+
+ _klen = _json_single_lengths[cs];
+ if ( _klen > 0 ) {
+ const char *_lower = _keys;
+ const char *_mid;
+ const char *_upper = _keys + _klen - 1;
+ while (1) {
+ if ( _upper < _lower )
+ break;
+
+ _mid = _lower + ((_upper-_lower) >> 1);
+ if ( (*p) < *_mid )
+ _upper = _mid - 1;
+ else if ( (*p) > *_mid )
+ _lower = _mid + 1;
+ else {
+ _trans += (unsigned int)(_mid - _keys);
+ goto _match;
+ }
+ }
+ _keys += _klen;
+ _trans += _klen;
+ }
+
+ _klen = _json_range_lengths[cs];
+ if ( _klen > 0 ) {
+ const char *_lower = _keys;
+ const char *_mid;
+ const char *_upper = _keys + (_klen<<1) - 2;
+ while (1) {
+ if ( _upper < _lower )
+ break;
+
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1);
+ if ( (*p) < _mid[0] )
+ _upper = _mid - 2;
+ else if ( (*p) > _mid[1] )
+ _lower = _mid + 2;
+ else {
+ _trans += (unsigned int)((_mid - _keys)>>1);
+ goto _match;
+ }
+ }
+ _trans += _klen;
+ }
+
+_match:
+ _trans = _json_indicies[_trans];
+ cs = _json_trans_targs[_trans];
+
+ if ( _json_trans_actions[_trans] == 0 )
+ goto _again;
+
+ _acts = _json_actions + _json_trans_actions[_trans];
+ _nacts = (unsigned int) *_acts++;
+ while ( _nacts-- > 0 )
+ {
+ switch ( *_acts++ )
+ {
+ case 0:
+#line 469 "upb/json/parser.rl"
+ { p--; {cs = stack[--top]; goto _again;} }
+ break;
+ case 1:
+#line 470 "upb/json/parser.rl"
+ { p--; {stack[top++] = cs; cs = 10; goto _again;} }
+ break;
+ case 2:
+#line 474 "upb/json/parser.rl"
+ { start_text(parser, p); }
+ break;
+ case 3:
+#line 475 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_text(parser, p)); }
+ break;
+ case 4:
+#line 481 "upb/json/parser.rl"
+ { start_hex(parser, p); }
+ break;
+ case 5:
+#line 482 "upb/json/parser.rl"
+ { hex(parser, p); }
+ break;
+ case 6:
+#line 488 "upb/json/parser.rl"
+ { escape(parser, p); }
+ break;
+ case 7:
+#line 491 "upb/json/parser.rl"
+ { {cs = stack[--top]; goto _again;} }
+ break;
+ case 8:
+#line 492 "upb/json/parser.rl"
+ { {stack[top++] = cs; cs = 19; goto _again;} }
+ break;
+ case 9:
+#line 494 "upb/json/parser.rl"
+ { p--; {stack[top++] = cs; cs = 27; goto _again;} }
+ break;
+ case 10:
+#line 499 "upb/json/parser.rl"
+ { start_member(parser); }
+ break;
+ case 11:
+#line 500 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_member(parser)); }
+ break;
+ case 12:
+#line 503 "upb/json/parser.rl"
+ { clear_member(parser); }
+ break;
+ case 13:
+#line 509 "upb/json/parser.rl"
+ { start_object(parser); }
+ break;
+ case 14:
+#line 512 "upb/json/parser.rl"
+ { end_object(parser); }
+ break;
+ case 15:
+#line 518 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(start_array(parser)); }
+ break;
+ case 16:
+#line 522 "upb/json/parser.rl"
+ { end_array(parser); }
+ break;
+ case 17:
+#line 527 "upb/json/parser.rl"
+ { start_number(parser, p); }
+ break;
+ case 18:
+#line 528 "upb/json/parser.rl"
+ { end_number(parser, p); }
+ break;
+ case 19:
+#line 530 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(start_stringval(parser)); }
+ break;
+ case 20:
+#line 531 "upb/json/parser.rl"
+ { end_stringval(parser); }
+ break;
+ case 21:
+#line 533 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(putbool(parser, true)); }
+ break;
+ case 22:
+#line 535 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(putbool(parser, false)); }
+ break;
+ case 23:
+#line 537 "upb/json/parser.rl"
+ { /* null value */ }
+ break;
+ case 24:
+#line 539 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(start_subobject(parser)); }
+ break;
+ case 25:
+#line 540 "upb/json/parser.rl"
+ { end_subobject(parser); }
+ break;
+ case 26:
+#line 545 "upb/json/parser.rl"
+ { p--; {cs = stack[--top]; goto _again;} }
+ break;
+#line 818 "upb/json/parser.c"
+ }
+ }
+
+_again:
+ if ( cs == 0 )
+ goto _out;
+ if ( ++p != pe )
+ goto _resume;
+ _test_eof: {}
+ _out: {}
+ }
+
+#line 567 "upb/json/parser.rl"
+
+ if (p != pe) {
+ upb_status_seterrf(parser->status, "Parse error at %s\n", p);
+ }
+
+error:
+ // Save parsing state back to parser.
+ parser->current_state = cs;
+ parser->parser_top = top;
+
+ return p - buf;
+}
+
+bool end(void *closure, const void *hd) {
+ UPB_UNUSED(closure);
+ UPB_UNUSED(hd);
+ return true;
+}
+
+void upb_json_parser_init(upb_json_parser *p, upb_status *status) {
+ p->limit = p->stack + UPB_JSON_MAX_DEPTH;
+ upb_byteshandler_init(&p->input_handler_);
+ upb_byteshandler_setstring(&p->input_handler_, parse, NULL);
+ upb_byteshandler_setendstr(&p->input_handler_, end, NULL);
+ upb_bytessink_reset(&p->input_, &p->input_handler_, p);
+ p->status = status;
+}
+
+void upb_json_parser_uninit(upb_json_parser *p) {
+ upb_byteshandler_uninit(&p->input_handler_);
+}
+
+void upb_json_parser_reset(upb_json_parser *p) {
+ p->top = p->stack;
+ p->top->f = NULL;
+
+ int cs;
+ int top;
+ // Emit Ragel initialization of the parser.
+
+#line 872 "upb/json/parser.c"
+ {
+ cs = json_start;
+ top = 0;
+ }
+
+#line 607 "upb/json/parser.rl"
+ p->current_state = cs;
+ p->parser_top = top;
+ p->text_begin = NULL;
+ p->accumulated = NULL;
+ p->accumulated_len = 0;
+}
+
+void upb_json_parser_resetoutput(upb_json_parser *p, upb_sink *sink) {
+ upb_json_parser_reset(p);
+ upb_sink_reset(&p->top->sink, sink->handlers, sink->closure);
+ p->top->m = upb_handlers_msgdef(sink->handlers);
+ p->accumulated = NULL;
+}
+
+upb_bytessink *upb_json_parser_input(upb_json_parser *p) {
+ return &p->input_;
+}
diff --git a/upb/json/parser.h b/upb/json/parser.h
new file mode 100644
index 0000000..a5833e7
--- /dev/null
+++ b/upb/json/parser.h
@@ -0,0 +1,112 @@
+/*
+ * upb - a minimalist implementation of protocol buffers.
+ *
+ * Copyright (c) 2014 Google Inc. See LICENSE for details.
+ * Author: Josh Haberman <jhaberman@gmail.com>
+ *
+ * upb::json::Parser can parse JSON according to a specific schema.
+ * Support for parsing arbitrary JSON (schema-less) will be added later.
+ */
+
+#ifndef UPB_JSON_PARSER_H_
+#define UPB_JSON_PARSER_H_
+
+#include "upb/sink.h"
+
+#ifdef __cplusplus
+namespace upb {
+namespace json {
+class Parser;
+} // namespace json
+} // namespace upb
+#endif
+
+UPB_DECLARE_TYPE(upb::json::Parser, upb_json_parser);
+
+// Internal-only struct used by the parser.
+typedef struct {
+ UPB_PRIVATE_FOR_CPP
+ upb_sink sink;
+ const upb_msgdef *m;
+ const upb_fielddef *f;
+} upb_jsonparser_frame;
+
+
+/* upb::json::Parser **********************************************************/
+
+#define UPB_JSON_MAX_DEPTH 64
+
+// Parses an incoming BytesStream, pushing the results to the destination sink.
+UPB_DEFINE_CLASS0(upb::json::Parser,
+ public:
+ Parser(Status* status);
+ ~Parser();
+
+ // Resets the state of the printer, so that it will expect to begin a new
+ // document.
+ void Reset();
+
+ // Resets the output pointer which will serve as our closure. Implies
+ // Reset().
+ void ResetOutput(Sink* output);
+
+ // The input to the printer.
+ BytesSink* input();
+,
+UPB_DEFINE_STRUCT0(upb_json_parser,
+ upb_byteshandler input_handler_;
+ upb_bytessink input_;
+
+ // Stack to track the JSON scopes we are in.
+ upb_jsonparser_frame stack[UPB_JSON_MAX_DEPTH];
+ upb_jsonparser_frame *top;
+ upb_jsonparser_frame *limit;
+
+ upb_status *status;
+
+ // Ragel's internal parsing stack for the parsing state machine.
+ int current_state;
+ int parser_stack[UPB_JSON_MAX_DEPTH];
+ int parser_top;
+
+ // A pointer to the beginning of whatever text we are currently parsing.
+ const char *text_begin;
+
+ // We have to accumulate text for member names, integers, unicode escapes, and
+ // base64 partial results.
+ const char *accumulated;
+ size_t accumulated_len;
+ // TODO: add members and code for allocating a buffer when necessary (when the
+ // member spans input buffers or contains escapes).
+));
+
+UPB_BEGIN_EXTERN_C
+
+void upb_json_parser_init(upb_json_parser *p, upb_status *status);
+void upb_json_parser_uninit(upb_json_parser *p);
+void upb_json_parser_reset(upb_json_parser *p);
+void upb_json_parser_resetoutput(upb_json_parser *p, upb_sink *output);
+upb_bytessink *upb_json_parser_input(upb_json_parser *p);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+namespace upb {
+namespace json {
+inline Parser::Parser(Status* status) { upb_json_parser_init(this, status); }
+inline Parser::~Parser() { upb_json_parser_uninit(this); }
+inline void Parser::Reset() { upb_json_parser_reset(this); }
+inline void Parser::ResetOutput(Sink* output) {
+ upb_json_parser_resetoutput(this, output);
+}
+inline BytesSink* Parser::input() {
+ return upb_json_parser_input(this);
+}
+} // namespace json
+} // namespace upb
+
+#endif
+
+
+#endif // UPB_JSON_PARSER_H_
diff --git a/upb/json/parser.rl b/upb/json/parser.rl
new file mode 100644
index 0000000..75860e5
--- /dev/null
+++ b/upb/json/parser.rl
@@ -0,0 +1,623 @@
+/*
+ * upb - a minimalist implementation of protocol buffers.
+ *
+ * Copyright (c) 2014 Google Inc. See LICENSE for details.
+ * Author: Josh Haberman <jhaberman@gmail.com>
+ *
+ * A parser that uses the Ragel State Machine Compiler to generate
+ * the finite automata.
+ *
+ * Ragel only natively handles regular languages, but we can manually
+ * program it a bit to handle context-free languages like JSON, by using
+ * the "fcall" and "fret" constructs.
+ *
+ * This parser can handle the basics, but needs several things to be fleshed
+ * out:
+ *
+ * - handling of unicode escape sequences (including high surrogate pairs).
+ * - properly check and report errors for unknown fields, stack overflow,
+ * improper array nesting (or lack of nesting).
+ * - handling of base64 sequences with padding characters.
+ * - handling of push-back (non-success returns from sink functions).
+ * - handling of keys/escape-sequences/etc that span input buffers.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <assert.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include "upb/json/parser.h"
+
+#define CHECK_RETURN(x) if (!(x)) return false
+
+static upb_selector_t getsel_for_handlertype(upb_json_parser *p,
+ upb_handlertype_t type) {
+ upb_selector_t sel;
+ bool ok = upb_handlers_getselector(p->top->f, type, &sel);
+ UPB_ASSERT_VAR(ok, ok);
+ return sel;
+}
+
+static upb_selector_t getsel(upb_json_parser *p) {
+ return getsel_for_handlertype(
+ p, upb_handlers_getprimitivehandlertype(p->top->f));
+}
+
+static void start_member(upb_json_parser *p) {
+ assert(!p->top->f);
+ assert(!p->accumulated);
+ p->accumulated_len = 0;
+}
+
+static bool end_member(upb_json_parser *p) {
+ // TODO(haberman): support keys that span buffers or have escape sequences.
+ assert(!p->top->f);
+ assert(p->accumulated);
+ const upb_fielddef *f =
+ upb_msgdef_ntof(p->top->m, p->accumulated, p->accumulated_len);
+
+ if (!f) {
+ // TODO(haberman): Ignore unknown fields if requested/configured to do so.
+ upb_status_seterrf(p->status, "No such field: %.*s\n",
+ (int)p->accumulated_len, p->accumulated);
+ return false;
+ }
+
+ p->top->f = f;
+ p->accumulated = NULL;
+
+ return true;
+}
+
+static void start_object(upb_json_parser *p) {
+ upb_sink_startmsg(&p->top->sink);
+}
+
+static void end_object(upb_json_parser *p) {
+ upb_status status;
+ upb_sink_endmsg(&p->top->sink, &status);
+}
+
+static bool check_stack(upb_json_parser *p) {
+ if ((p->top + 1) == p->limit) {
+ upb_status_seterrmsg(p->status, "Nesting too deep");
+ return false;
+ }
+
+ return true;
+}
+
+static bool start_subobject(upb_json_parser *p) {
+ assert(p->top->f);
+
+ if (!upb_fielddef_issubmsg(p->top->f)) {
+ upb_status_seterrf(p->status,
+ "Object specified for non-message/group field: %s",
+ upb_fielddef_name(p->top->f));
+ return false;
+ }
+
+ if (!check_stack(p)) return false;
+
+ upb_jsonparser_frame *inner = p->top + 1;
+
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG);
+ upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink);
+ inner->m = upb_fielddef_msgsubdef(p->top->f);
+ inner->f = NULL;
+ p->top = inner;
+
+ return true;
+}
+
+static void end_subobject(upb_json_parser *p) {
+ p->top--;
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG);
+ upb_sink_endsubmsg(&p->top->sink, sel);
+}
+
+static bool start_array(upb_json_parser *p) {
+ assert(p->top->f);
+
+ if (!upb_fielddef_isseq(p->top->f)) {
+ upb_status_seterrf(p->status,
+ "Array specified for non-repeated field: %s",
+ upb_fielddef_name(p->top->f));
+ return false;
+ }
+
+ if (!check_stack(p)) return false;
+
+ upb_jsonparser_frame *inner = p->top + 1;
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ);
+ upb_sink_startseq(&p->top->sink, sel, &inner->sink);
+ inner->m = p->top->m;
+ inner->f = p->top->f;
+ p->top = inner;
+
+ return true;
+}
+
+static void end_array(upb_json_parser *p) {
+ assert(p->top > p->stack);
+
+ p->top--;
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ);
+ upb_sink_endseq(&p->top->sink, sel);
+}
+
+static void clear_member(upb_json_parser *p) { p->top->f = NULL; }
+
+static bool putbool(upb_json_parser *p, bool val) {
+ if (upb_fielddef_type(p->top->f) != UPB_TYPE_BOOL) {
+ upb_status_seterrf(p->status,
+ "Boolean value specified for non-bool field: %s",
+ upb_fielddef_name(p->top->f));
+ return false;
+ }
+
+ bool ok = upb_sink_putbool(&p->top->sink, getsel(p), val);
+ UPB_ASSERT_VAR(ok, ok);
+ return true;
+}
+
+static void start_text(upb_json_parser *p, const char *ptr) {
+ p->text_begin = ptr;
+}
+
+static const signed char b64table[] = {
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 62/*+*/, -1, -1, -1, 63/*/ */,
+ 52/*0*/, 53/*1*/, 54/*2*/, 55/*3*/, 56/*4*/, 57/*5*/, 58/*6*/, 59/*7*/,
+ 60/*8*/, 61/*9*/, -1, -1, -1, -1, -1, -1,
+ -1, 0/*A*/, 1/*B*/, 2/*C*/, 3/*D*/, 4/*E*/, 5/*F*/, 6/*G*/,
+ 07/*H*/, 8/*I*/, 9/*J*/, 10/*K*/, 11/*L*/, 12/*M*/, 13/*N*/, 14/*O*/,
+ 15/*P*/, 16/*Q*/, 17/*R*/, 18/*S*/, 19/*T*/, 20/*U*/, 21/*V*/, 22/*W*/,
+ 23/*X*/, 24/*Y*/, 25/*Z*/, -1, -1, -1, -1, -1,
+ -1, 26/*a*/, 27/*b*/, 28/*c*/, 29/*d*/, 30/*e*/, 31/*f*/, 32/*g*/,
+ 33/*h*/, 34/*i*/, 35/*j*/, 36/*k*/, 37/*l*/, 38/*m*/, 39/*n*/, 40/*o*/,
+ 41/*p*/, 42/*q*/, 43/*r*/, 44/*s*/, 45/*t*/, 46/*u*/, 47/*v*/, 48/*w*/,
+ 49/*x*/, 50/*y*/, 51/*z*/, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1
+};
+
+// Returns the table value sign-extended to 32 bits. Knowing that the upper
+// bits will be 1 for unrecognized characters makes it easier to check for
+// this error condition later (see below).
+int32_t b64lookup(unsigned char ch) { return b64table[ch]; }
+
+// Returns true if the given character is not a valid base64 character or
+// padding.
+bool nonbase64(unsigned char ch) { return b64lookup(ch) == -1 && ch != '='; }
+
+static bool base64_push(upb_json_parser *p, upb_selector_t sel, const char *ptr,
+ size_t len) {
+ const char *limit = ptr + len;
+ for (; ptr < limit; ptr += 4) {
+ if (limit - ptr < 4) {
+ upb_status_seterrf(p->status,
+ "Base64 input for bytes field not a multiple of 4: %s",
+ upb_fielddef_name(p->top->f));
+ return false;
+ }
+
+ uint32_t val = b64lookup(ptr[0]) << 18 |
+ b64lookup(ptr[1]) << 12 |
+ b64lookup(ptr[2]) << 6 |
+ b64lookup(ptr[3]);
+
+ // Test the upper bit; returns true if any of the characters returned -1.
+ if (val & 0x80000000) {
+ goto otherchar;
+ }
+
+ char output[3];
+ output[0] = val >> 16;
+ output[1] = (val >> 8) & 0xff;
+ output[2] = val & 0xff;
+ upb_sink_putstring(&p->top->sink, sel, output, 3, NULL);
+ }
+ return true;
+
+otherchar:
+ if (nonbase64(ptr[0]) || nonbase64(ptr[1]) || nonbase64(ptr[2]) ||
+ nonbase64(ptr[3]) ) {
+ upb_status_seterrf(p->status,
+ "Non-base64 characters in bytes field: %s",
+ upb_fielddef_name(p->top->f));
+ return false;
+ } if (ptr[2] == '=') {
+ // Last group contains only two input bytes, one output byte.
+ if (ptr[0] == '=' || ptr[1] == '=' || ptr[3] != '=') {
+ goto badpadding;
+ }
+
+ uint32_t val = b64lookup(ptr[0]) << 18 |
+ b64lookup(ptr[1]) << 12;
+
+ assert(!(val & 0x80000000));
+ char output = val >> 16;
+ upb_sink_putstring(&p->top->sink, sel, &output, 1, NULL);
+ return true;
+ } else {
+ // Last group contains only three input bytes, two output bytes.
+ if (ptr[0] == '=' || ptr[1] == '=' || ptr[2] == '=') {
+ goto badpadding;
+ }
+
+ uint32_t val = b64lookup(ptr[0]) << 18 |
+ b64lookup(ptr[1]) << 12 |
+ b64lookup(ptr[2]) << 6;
+
+ char output[2];
+ output[0] = val >> 16;
+ output[1] = (val >> 8) & 0xff;
+ upb_sink_putstring(&p->top->sink, sel, output, 2, NULL);
+ return true;
+ }
+
+badpadding:
+ upb_status_seterrf(p->status,
+ "Incorrect base64 padding for field: %s (%.*s)",
+ upb_fielddef_name(p->top->f),
+ 4, ptr);
+ return false;
+}
+
+static bool end_text(upb_json_parser *p, const char *ptr) {
+ assert(!p->accumulated); // TODO: handle this case.
+ p->accumulated = p->text_begin;
+ p->accumulated_len = ptr - p->text_begin;
+
+ if (p->top->f && upb_fielddef_isstring(p->top->f)) {
+ // This is a string field (as opposed to a member name).
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STRING);
+ if (upb_fielddef_type(p->top->f) == UPB_TYPE_BYTES) {
+ CHECK_RETURN(base64_push(p, sel, p->accumulated, p->accumulated_len));
+ } else {
+ upb_sink_putstring(&p->top->sink, sel, p->accumulated, p->accumulated_len, NULL);
+ }
+ p->accumulated = NULL;
+ }
+
+ return true;
+}
+
+static bool start_stringval(upb_json_parser *p) {
+ assert(p->top->f);
+
+ if (!upb_fielddef_isstring(p->top->f)) {
+ upb_status_seterrf(p->status,
+ "String specified for non-string field: %s",
+ upb_fielddef_name(p->top->f));
+ return false;
+ }
+
+ if (!check_stack(p)) return false;
+
+ upb_jsonparser_frame *inner = p->top + 1; // TODO: check for overflow.
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR);
+ upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink);
+ inner->m = p->top->m;
+ inner->f = p->top->f;
+ p->top = inner;
+
+ return true;
+}
+
+static void end_stringval(upb_json_parser *p) {
+ p->top--;
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR);
+ upb_sink_endstr(&p->top->sink, sel);
+}
+
+static void start_number(upb_json_parser *p, const char *ptr) {
+ start_text(p, ptr);
+ assert(p->accumulated == NULL);
+}
+
+static void end_number(upb_json_parser *p, const char *ptr) {
+ end_text(p, ptr);
+ const char *myend = p->accumulated + p->accumulated_len;
+ char *end;
+
+ switch (upb_fielddef_type(p->top->f)) {
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32: {
+ long val = strtol(p->accumulated, &end, 0);
+ if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || end != myend)
+ assert(false);
+ else
+ upb_sink_putint32(&p->top->sink, getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_INT64: {
+ long long val = strtoll(p->accumulated, &end, 0);
+ if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || end != myend)
+ assert(false);
+ else
+ upb_sink_putint64(&p->top->sink, getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_UINT32: {
+ unsigned long val = strtoul(p->accumulated, &end, 0);
+ if (val > UINT32_MAX || errno == ERANGE || end != myend)
+ assert(false);
+ else
+ upb_sink_putuint32(&p->top->sink, getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_UINT64: {
+ unsigned long long val = strtoull(p->accumulated, &end, 0);
+ if (val > UINT64_MAX || errno == ERANGE || end != myend)
+ assert(false);
+ else
+ upb_sink_putuint64(&p->top->sink, getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_DOUBLE: {
+ double val = strtod(p->accumulated, &end);
+ if (errno == ERANGE || end != myend)
+ assert(false);
+ else
+ upb_sink_putdouble(&p->top->sink, getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_FLOAT: {
+ float val = strtof(p->accumulated, &end);
+ if (errno == ERANGE || end != myend)
+ assert(false);
+ else
+ upb_sink_putfloat(&p->top->sink, getsel(p), val);
+ break;
+ }
+ default:
+ assert(false);
+ }
+
+ p->accumulated = NULL;
+}
+
+static char escape_char(char in) {
+ switch (in) {
+ case 'r': return '\r';
+ case 't': return '\t';
+ case 'n': return '\n';
+ case 'f': return '\f';
+ case 'b': return '\b';
+ case '/': return '/';
+ case '"': return '"';
+ case '\\': return '\\';
+ default:
+ assert(0);
+ return 'x';
+ }
+}
+
+static void escape(upb_json_parser *p, const char *ptr) {
+ char ch = escape_char(*ptr);
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STRING);
+ upb_sink_putstring(&p->top->sink, sel, &ch, 1, NULL);
+}
+
+static uint8_t hexdigit(char ch) {
+ if (ch >= '0' && ch <= '9') {
+ return ch - '0';
+ } else if (ch >= 'a' && ch <= 'f') {
+ return ch - 'a' + 10;
+ } else {
+ assert(ch >= 'A' && ch <= 'F');
+ return ch - 'A' + 10;
+ }
+}
+
+static void start_hex(upb_json_parser *p, const char *ptr) {
+ start_text(p, ptr);
+}
+
+static void hex(upb_json_parser *p, const char *end) {
+ UPB_UNUSED(end);
+ const char *start = p->text_begin;
+ assert(end - start == 4);
+ uint16_t codepoint =
+ (hexdigit(start[0]) << 12) |
+ (hexdigit(start[1]) << 8) |
+ (hexdigit(start[2]) << 4) |
+ hexdigit(start[3]);
+ // TODO(haberman): convert to UTF-8 and emit (though if it is a high surrogate
+ // we have to wait for the next escape to get the full code point).
+ UPB_UNUSED(codepoint);
+}
+
+#define CHECK_RETURN_TOP(x) if (!(x)) goto error
+
+// What follows is the Ragel parser itself. The language is specified in Ragel
+// and the actions call our C functions above.
+%%{
+ machine json;
+
+ ws = space*;
+
+ integer = "0" | /[1-9]/ /[0-9]/*;
+ decimal = "." /[0-9]/+;
+ exponent = /[eE]/ /[+\-]/? /[0-9]/+;
+
+ number_machine :=
+ ("-"? integer decimal? exponent?)
+ <: any >{ fhold; fret; };
+ number = /[0-9\-]/ >{ fhold; fcall number_machine; };
+
+ text =
+ /[^\\"]/+
+ >{ start_text(parser, p); }
+ %{ CHECK_RETURN_TOP(end_text(parser, p)); }
+ ;
+
+ unicode_char =
+ "\\u"
+ /[0-9A-Fa-f]/{4}
+ >{ start_hex(parser, p); }
+ %{ hex(parser, p); }
+ ;
+
+ escape_char =
+ "\\"
+ /[rtbfn"\/\\]/
+ >{ escape(parser, p); }
+ ;
+
+ string_machine := (text | unicode_char | escape_char)** '"' @{ fret; } ;
+ string = '"' @{ fcall string_machine; };
+
+ value2 = ^(space | "]" | "}") >{ fhold; fcall value_machine; } ;
+
+ member =
+ ws
+ string
+ >{ start_member(parser); }
+ %{ CHECK_RETURN_TOP(end_member(parser)); }
+ ws ":" ws
+ value2
+ %{ clear_member(parser); }
+ ws;
+
+ object =
+ "{"
+ ws
+ >{ start_object(parser); }
+ (member ("," member)*)?
+ "}"
+ >{ end_object(parser); }
+ ;
+
+ element = ws value2 ws;
+ array =
+ "["
+ >{ CHECK_RETURN_TOP(start_array(parser)); }
+ ws
+ (element ("," element)*)?
+ "]"
+ >{ end_array(parser); }
+ ;
+
+ value =
+ number
+ >{ start_number(parser, p); }
+ %{ end_number(parser, p); }
+ | string
+ >{ CHECK_RETURN_TOP(start_stringval(parser)); }
+ %{ end_stringval(parser); }
+ | "true"
+ %{ CHECK_RETURN_TOP(putbool(parser, true)); }
+ | "false"
+ %{ CHECK_RETURN_TOP(putbool(parser, false)); }
+ | "null"
+ %{ /* null value */ }
+ | object
+ >{ CHECK_RETURN_TOP(start_subobject(parser)); }
+ %{ end_subobject(parser); }
+ | array;
+
+ value_machine :=
+ value
+ <: any >{ fhold; fret; } ;
+
+ main := ws object ws;
+}%%
+
+%% write data;
+
+size_t parse(void *closure, const void *hd, const char *buf, size_t size,
+ const upb_bufhandle *handle) {
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+ upb_json_parser *parser = closure;
+
+ // Variables used by Ragel's generated code.
+ int cs = parser->current_state;
+ int *stack = parser->parser_stack;
+ int top = parser->parser_top;
+
+ const char *p = buf;
+ const char *pe = buf + size;
+
+ %% write exec;
+
+ if (p != pe) {
+ upb_status_seterrf(parser->status, "Parse error at %s\n", p);
+ }
+
+error:
+ // Save parsing state back to parser.
+ parser->current_state = cs;
+ parser->parser_top = top;
+
+ return p - buf;
+}
+
+bool end(void *closure, const void *hd) {
+ UPB_UNUSED(closure);
+ UPB_UNUSED(hd);
+ return true;
+}
+
+void upb_json_parser_init(upb_json_parser *p, upb_status *status) {
+ p->limit = p->stack + UPB_JSON_MAX_DEPTH;
+ upb_byteshandler_init(&p->input_handler_);
+ upb_byteshandler_setstring(&p->input_handler_, parse, NULL);
+ upb_byteshandler_setendstr(&p->input_handler_, end, NULL);
+ upb_bytessink_reset(&p->input_, &p->input_handler_, p);
+ p->status = status;
+}
+
+void upb_json_parser_uninit(upb_json_parser *p) {
+ upb_byteshandler_uninit(&p->input_handler_);
+}
+
+void upb_json_parser_reset(upb_json_parser *p) {
+ p->top = p->stack;
+ p->top->f = NULL;
+
+ int cs;
+ int top;
+ // Emit Ragel initialization of the parser.
+ %% write init;
+ p->current_state = cs;
+ p->parser_top = top;
+ p->text_begin = NULL;
+ p->accumulated = NULL;
+ p->accumulated_len = 0;
+}
+
+void upb_json_parser_resetoutput(upb_json_parser *p, upb_sink *sink) {
+ upb_json_parser_reset(p);
+ upb_sink_reset(&p->top->sink, sink->handlers, sink->closure);
+ p->top->m = upb_handlers_msgdef(sink->handlers);
+ p->accumulated = NULL;
+}
+
+upb_bytessink *upb_json_parser_input(upb_json_parser *p) {
+ return &p->input_;
+}
diff --git a/upb/json/typed_printer.c b/upb/json/printer.c
index e79cfc1..8ff0676 100644
--- a/upb/json/typed_printer.c
+++ b/upb/json/printer.c
@@ -9,7 +9,7 @@
*
*/
-#include "upb/json/typed_printer.h"
+#include "upb/json/printer.h"
#include <stdlib.h>
#include <stdio.h>
@@ -18,7 +18,7 @@
#include <yajl/yajl_gen.h>
static void doprint(void *_p, const char *buf, unsigned int len) {
- upb_json_typedprinter *p = _p;
+ upb_json_printer *p = _p;
// YAJL doesn't support returning an error status here, so we can't properly
// support clients who return a value other than "len" here.
size_t n = upb_bytessink_putbuf(p->output_, p->subc_, buf, len, NULL);
@@ -77,7 +77,7 @@ static yajl_gen_status upbyajl_gen_uint64(yajl_gen yajl,
}
static bool putkey(void *closure, const void *handler_data) {
- upb_json_typedprinter *p = closure;
+ upb_json_printer *p = closure;
const strpc *key = handler_data;
CHKYAJL(yajl_gen_string2(p->yajl_gen_, key->ptr, key->len));
return true;
@@ -85,7 +85,7 @@ static bool putkey(void *closure, const void *handler_data) {
#define TYPE_HANDLERS(type, yajlfunc) \
static bool put##type(void *closure, const void *handler_data, type val) { \
- upb_json_typedprinter *p = closure; \
+ upb_json_printer *p = closure; \
UPB_UNUSED(handler_data); \
CHKYAJL(yajlfunc(p->yajl_gen_, val)); \
return true; \
@@ -113,7 +113,7 @@ static void *startsubmsg(void *closure, const void *handler_data) {
static bool startmap(void *closure, const void *handler_data) {
UPB_UNUSED(handler_data);
- upb_json_typedprinter *p = closure;
+ upb_json_printer *p = closure;
if (p->depth_++ == 0) {
upb_bytessink_start(p->output_, 0, &p->subc_);
}
@@ -124,7 +124,7 @@ static bool startmap(void *closure, const void *handler_data) {
static bool endmap(void *closure, const void *handler_data, upb_status *s) {
UPB_UNUSED(handler_data);
UPB_UNUSED(s);
- upb_json_typedprinter *p = closure;
+ upb_json_printer *p = closure;
if (--p->depth_ == 0) {
upb_bytessink_end(p->output_);
}
@@ -133,7 +133,7 @@ static bool endmap(void *closure, const void *handler_data, upb_status *s) {
}
static void *startseq(void *closure, const void *handler_data) {
- upb_json_typedprinter *p = closure;
+ upb_json_printer *p = closure;
CHK(putkey(closure, handler_data));
CHKYAJL(yajl_gen_array_open(p->yajl_gen_));
return closure;
@@ -141,7 +141,7 @@ static void *startseq(void *closure, const void *handler_data) {
static bool endseq(void *closure, const void *handler_data) {
UPB_UNUSED(handler_data);
- upb_json_typedprinter *p = closure;
+ upb_json_printer *p = closure;
CHKYAJL(yajl_gen_array_close(p->yajl_gen_));
return true;
}
@@ -149,7 +149,7 @@ static bool endseq(void *closure, const void *handler_data) {
static size_t putstr(void *closure, const void *handler_data, const char *str,
size_t len, const upb_bufhandle *handle) {
UPB_UNUSED(handle);
- upb_json_typedprinter *p = closure;
+ upb_json_printer *p = closure;
CHKYAJL(yajl_gen_string2(p->yajl_gen_, str, len));
return len;
}
@@ -158,7 +158,7 @@ static size_t putstr(void *closure, const void *handler_data, const char *str,
static size_t putbytes(void *closure, const void *handler_data, const char *str,
size_t len, const upb_bufhandle *handle) {
UPB_UNUSED(handle);
- upb_json_typedprinter *p = closure;
+ upb_json_printer *p = closure;
// This is the regular base64, not the "web-safe" version.
static const char base64[] =
@@ -175,8 +175,8 @@ static size_t putbytes(void *closure, const void *handler_data, const char *str,
UPB_ASSERT_VAR(limit, (limit - to) >= 4);
to[0] = base64[from[0] >> 2];
- to[1] = base64[((from[0] & 0x3) << 4) + (from[1] >> 4)];
- to[2] = base64[((from[1] & 0xf) << 2) + (from[2] >> 6)];
+ to[1] = base64[((from[0] & 0x3) << 4) | (from[1] >> 4)];
+ to[2] = base64[((from[1] & 0xf) << 2) | (from[2] >> 6)];
to[3] = base64[from[2] & 0x3f];
remaining -= 3;
@@ -184,6 +184,25 @@ static size_t putbytes(void *closure, const void *handler_data, const char *str,
from += 3;
}
+ switch (remaining) {
+ case 2:
+ to[0] = base64[from[0] >> 2];
+ to[1] = base64[((from[0] & 0x3) << 4) | (from[1] >> 4)];
+ to[2] = base64[(from[1] & 0xf) << 2];
+ to[3] = '=';
+ to += 4;
+ from += 2;
+ break;
+ case 1:
+ to[0] = base64[from[0] >> 2];
+ to[1] = base64[((from[0] & 0x3) << 4)];
+ to[2] = '=';
+ to[3] = '=';
+ to += 4;
+ from += 1;
+ break;
+ }
+
size_t bytes = to - data;
if (yajl_gen_string2(p->yajl_gen_, data, bytes) != yajl_gen_status_ok) {
return 0;
@@ -278,7 +297,7 @@ void sethandlers(const void *closure, upb_handlers *h) {
// YAJL unfortunately does not support stack allocation, nor resetting an
// allocated object, so we have to allocate on the heap and reallocate whenever
// there is a reset.
-static void reset(upb_json_typedprinter *p, bool free) {
+static void reset(upb_json_printer *p, bool free) {
if (free) {
yajl_gen_free(p->yajl_gen_);
}
@@ -289,34 +308,32 @@ static void reset(upb_json_typedprinter *p, bool free) {
/* Public API *****************************************************************/
-void upb_json_typedprinter_init(upb_json_typedprinter *p,
- const upb_handlers *h) {
+void upb_json_printer_init(upb_json_printer *p, const upb_handlers *h) {
p->output_ = NULL;
p->depth_ = 0;
reset(p, false);
upb_sink_reset(&p->input_, h, p);
}
-void upb_json_typedprinter_uninit(upb_json_typedprinter *p) {
+void upb_json_printer_uninit(upb_json_printer *p) {
yajl_gen_free(p->yajl_gen_);
}
-void upb_json_typedprinter_reset(upb_json_typedprinter *p) {
+void upb_json_printer_reset(upb_json_printer *p) {
p->depth_ = 0;
reset(p, true);
}
-void upb_json_typedprinter_resetoutput(upb_json_typedprinter *p,
- upb_bytessink *output) {
- upb_json_typedprinter_reset(p);
+void upb_json_printer_resetoutput(upb_json_printer *p, upb_bytessink *output) {
+ upb_json_printer_reset(p);
p->output_ = output;
}
-upb_sink *upb_json_typedprinter_input(upb_json_typedprinter *p) {
+upb_sink *upb_json_printer_input(upb_json_printer *p) {
return &p->input_;
}
-const upb_handlers *upb_json_typedprinter_newhandlers(const upb_msgdef *md,
- const void *owner) {
+const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md,
+ const void *owner) {
return upb_handlers_newfrozen(md, owner, sethandlers, NULL);
}
diff --git a/upb/json/printer.h b/upb/json/printer.h
new file mode 100644
index 0000000..3df7f4c
--- /dev/null
+++ b/upb/json/printer.h
@@ -0,0 +1,97 @@
+/*
+ * upb - a minimalist implementation of protocol buffers.
+ *
+ * Copyright (c) 2014 Google Inc. See LICENSE for details.
+ * Author: Josh Haberman <jhaberman@gmail.com>
+ *
+ * upb::json::Printer allows you to create handlers that emit JSON
+ * according to a specific protobuf schema.
+ */
+
+#ifndef UPB_JSON_TYPED_PRINTER_H_
+#define UPB_JSON_TYPED_PRINTER_H_
+
+#include "upb/sink.h"
+
+#ifdef __cplusplus
+namespace upb {
+namespace json {
+class Printer;
+} // namespace json
+} // namespace upb
+#endif
+
+UPB_DECLARE_TYPE(upb::json::Printer, upb_json_printer);
+
+
+/* upb::json::Printer *********************************************************/
+
+// Prints an incoming stream of data to a BytesSink in JSON format.
+UPB_DEFINE_CLASS0(upb::json::Printer,
+ public:
+ Printer(const upb::Handlers* handlers);
+ ~Printer();
+
+ // Resets the state of the printer, so that it will expect to begin a new
+ // document.
+ void Reset();
+
+ // Resets the output pointer which will serve as our closure. Implies
+ // Reset().
+ void ResetOutput(BytesSink* output);
+
+ // The input to the printer.
+ Sink* input();
+
+ // Returns handlers for printing according to the specified schema.
+ static reffed_ptr<const Handlers> NewHandlers(const upb::MessageDef* md);
+,
+UPB_DEFINE_STRUCT0(upb_json_printer,
+ upb_sink input_;
+ // Pointer to yajl_gen; void* here so we don't have to include YAJL headers.
+ void *yajl_gen_;
+ void *subc_;
+ upb_bytessink *output_;
+ // We track the depth so that we know when to emit startstr/endstr on the
+ // output.
+ int depth_;
+));
+
+UPB_BEGIN_EXTERN_C // {
+
+// Native C API.
+
+void upb_json_printer_init(upb_json_printer *p, const upb_handlers *h);
+void upb_json_printer_uninit(upb_json_printer *p);
+void upb_json_printer_reset(upb_json_printer *p);
+void upb_json_printer_resetoutput(upb_json_printer *p, upb_bytessink *output);
+upb_sink *upb_json_printer_input(upb_json_printer *p);
+const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md,
+ const void *owner);
+
+UPB_END_EXTERN_C // }
+
+#ifdef __cplusplus
+
+namespace upb {
+namespace json {
+inline Printer::Printer(const upb::Handlers* handlers) {
+ upb_json_printer_init(this, handlers);
+}
+inline Printer::~Printer() { upb_json_printer_uninit(this); }
+inline void Printer::Reset() { upb_json_printer_reset(this); }
+inline void Printer::ResetOutput(BytesSink* output) {
+ upb_json_printer_resetoutput(this, output);
+}
+inline Sink* Printer::input() { return upb_json_printer_input(this); }
+inline reffed_ptr<const Handlers> Printer::NewHandlers(
+ const upb::MessageDef *md) {
+ const Handlers* h = upb_json_printer_newhandlers(md, &h);
+ return reffed_ptr<const Handlers>(h, &h);
+}
+} // namespace json
+} // namespace upb
+
+#endif
+
+#endif // UPB_JSON_TYPED_PRINTER_H_
diff --git a/upb/json/typed_printer.h b/upb/json/typed_printer.h
deleted file mode 100644
index c9e36f7..0000000
--- a/upb/json/typed_printer.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * upb - a minimalist implementation of protocol buffers.
- *
- * Copyright (c) 2014 Google Inc. See LICENSE for details.
- * Author: Josh Haberman <jhaberman@gmail.com>
- *
- * upb::json::TypedPrinter allows you to create handlers that emit JSON
- * according to a specific protobuf schema.
- */
-
-#ifndef UPB_JSON_TYPED_PRINTER_H_
-#define UPB_JSON_TYPED_PRINTER_H_
-
-#include "upb/sink.h"
-
-#ifdef __cplusplus
-namespace upb {
-namespace json {
-class TypedPrinter;
-} // namespace json
-} // namespace upb
-#endif
-
-UPB_DECLARE_TYPE(upb::json::TypedPrinter, upb_json_typedprinter);
-
-
-/* upb::json::TypedPrinter ****************************************************/
-
-// Prints an incoming stream of data to a BytesSink in JSON format.
-UPB_DEFINE_CLASS0(upb::json::TypedPrinter,
- public:
- TypedPrinter(const upb::Handlers* handlers);
- ~TypedPrinter();
-
- // Resets the state of the printer, so that it will expect to begin a new
- // document.
- void Reset();
-
- // Resets the output pointer which will serve as our closure. Implies
- // Reset().
- void ResetOutput(BytesSink* output);
-
- // The input to the printer.
- Sink* input();
-
- // Returns handlers for printing according to the specified schema.
- static reffed_ptr<const Handlers> NewHandlers(const upb::MessageDef* md);
-,
-UPB_DEFINE_STRUCT0(upb_json_typedprinter,
- upb_sink input_;
- // Pointer to yajl_gen; void* here so we don't have to include YAJL headers.
- void *yajl_gen_;
- void *subc_;
- upb_bytessink *output_;
- // We track the depth so that we know when to emit startstr/endstr on the
- // output.
- int depth_;
-));
-
-UPB_BEGIN_EXTERN_C // {
-
-// Native C API.
-
-void upb_json_typedprinter_init(upb_json_typedprinter *p,
- const upb_handlers *h);
-void upb_json_typedprinter_uninit(upb_json_typedprinter *p);
-void upb_json_typedprinter_reset(upb_json_typedprinter *p);
-void upb_json_typedprinter_resetoutput(upb_json_typedprinter *p,
- upb_bytessink *output);
-upb_sink *upb_json_typedprinter_input(upb_json_typedprinter *p);
-const upb_handlers *upb_json_typedprinter_newhandlers(const upb_msgdef *md,
- const void *owner);
-
-UPB_END_EXTERN_C // }
-
-#ifdef __cplusplus
-
-namespace upb {
-namespace json {
-inline TypedPrinter::TypedPrinter(const upb::Handlers* handlers) {
- upb_json_typedprinter_init(this, handlers);
-}
-inline TypedPrinter::~TypedPrinter() {
- upb_json_typedprinter_uninit(this);
-}
-inline void TypedPrinter::Reset() {
- upb_json_typedprinter_reset(this);
-}
-inline void TypedPrinter::ResetOutput(BytesSink* output) {
- upb_json_typedprinter_resetoutput(this, output);
-}
-inline Sink* TypedPrinter::input() {
- return upb_json_typedprinter_input(this);
-}
-inline reffed_ptr<const Handlers> TypedPrinter::NewHandlers(
- const upb::MessageDef *md) {
- const Handlers* h = upb_json_typedprinter_newhandlers(md, &h);
- return reffed_ptr<const Handlers>(h, &h);
-}
-} // namespace json
-} // namespace upb
-
-#endif
-
-#endif // UPB_JSON_TYPED_PRINTER_H_
diff --git a/upb/pb/compile_decoder_x64.h b/upb/pb/compile_decoder_x64.h
index 9787a57..095d2ef 100644
--- a/upb/pb/compile_decoder_x64.h
+++ b/upb/pb/compile_decoder_x64.h
@@ -21,19 +21,22 @@
//|
//|.arch x64
//|.actionlist upb_jit_actionlist
-static const unsigned char upb_jit_actionlist[1914] = {
- 249,255,248,10,248,1,85,65,87,65,86,65,85,65,84,83,72,131,252,236,8,72,137,
- 252,243,73,137,252,255,255,72,184,237,237,252,255,208,255,133,192,15,137,
- 244,247,73,137,167,233,72,137,216,77,139,183,233,73,139,159,233,77,139,167,
- 233,77,139,174,233,73,139,174,233,73,43,175,233,73,3,175,233,73,139,151,233,
- 72,133,210,15,133,244,248,252,255,208,73,139,135,233,73,199,135,233,0,0,0,
- 0,248,1,72,131,196,8,91,65,92,65,93,65,94,65,95,93,195,248,2,73,141,183,233,
- 72,41,212,72,137,231,255,195,255,248,11,73,141,191,233,72,137,230,73,139,
- 151,233,72,41,226,73,137,151,233,137,195,255,137,216,73,139,167,233,72,131,
- 196,8,91,65,92,65,93,65,94,65,95,93,195,255,248,12,73,57,159,233,15,132,244,
- 247,73,137,159,233,248,1,77,137,183,233,73,137,159,233,77,137,167,233,73,
- 137,175,233,73,43,175,233,73,3,175,233,73,137,174,233,77,137,174,233,76,137,
- 252,255,255,252,233,244,11,255,248,13,248,1,77,137,174,233,73,137,159,233,
+static const unsigned char upb_jit_actionlist[2158] = {
+ 249,255,248,10,248,1,85,65,87,65,86,65,85,65,84,83,72,137,252,243,73,137,
+ 252,255,72,184,237,237,65,84,73,137,228,72,129,228,239,252,255,208,76,137,
+ 228,65,92,133,192,15,137,244,247,73,137,167,233,72,137,216,77,139,183,233,
+ 73,139,159,233,77,139,167,233,77,139,174,233,73,139,174,233,73,43,175,233,
+ 73,3,175,233,73,139,151,233,72,133,210,15,133,244,248,252,255,208,73,139,
+ 135,233,73,199,135,233,0,0,0,0,248,1,255,91,65,92,65,93,65,94,65,95,93,195,
+ 248,2,73,141,183,233,72,41,212,72,137,231,72,184,237,237,65,84,73,137,228,
+ 72,129,228,239,252,255,208,76,137,228,65,92,195,255,248,11,73,141,191,233,
+ 72,137,230,73,139,151,233,72,41,226,73,137,151,233,137,195,72,184,237,237,
+ 65,84,73,137,228,72,129,228,239,252,255,208,76,137,228,65,92,137,216,73,139,
+ 167,233,91,65,92,65,93,65,94,65,95,93,195,255,248,12,73,57,159,233,15,132,
+ 244,247,73,137,159,233,248,1,77,137,183,233,73,137,159,233,77,137,167,233,
+ 73,137,175,233,73,43,175,233,73,3,175,233,73,137,174,233,77,137,174,233,76,
+ 137,252,255,72,184,237,237,65,84,73,137,228,72,129,228,239,252,255,208,76,
+ 137,228,65,92,252,233,244,11,255,248,13,248,1,77,137,174,233,73,137,159,233,
255,76,57,227,15,132,244,253,255,76,137,225,72,41,217,72,131,252,249,1,15,
130,244,253,255,15,182,19,132,210,15,137,244,254,248,7,232,244,14,248,8,72,
131,195,1,72,137,252,233,72,41,217,72,41,209,15,130,244,15,73,137,142,233,
@@ -41,51 +44,58 @@ static const unsigned char upb_jit_actionlist[1914] = {
233,0,0,0,0,72,133,201,15,132,244,248,77,139,167,233,72,57,252,235,15,135,
244,248,76,57,229,15,135,244,248,255,73,137,252,236,248,2,195,248,3,73,139,
159,233,76,137,252,255,255,72,190,237,237,255,190,237,255,49,252,246,255,
- 232,244,12,252,233,244,1,255,248,16,72,131,252,236,16,72,137,188,253,36,233,
- 248,1,72,199,4,36,0,0,0,0,76,137,252,255,72,137,230,73,137,159,233,77,137,
- 183,233,73,137,159,233,77,137,167,233,73,137,175,233,73,43,175,233,73,3,175,
- 233,73,137,174,233,77,137,174,233,252,255,148,253,36,233,77,139,183,233,73,
- 139,159,233,77,139,167,233,77,139,174,233,73,139,174,233,73,43,175,233,73,
- 3,175,233,255,133,192,15,137,244,248,72,139,20,36,252,242,15,16,4,36,72,131,
- 196,16,195,248,2,232,244,11,252,233,244,1,255,248,17,76,137,252,255,137,214,
- 15,182,209,77,137,183,233,73,137,159,233,77,137,167,233,73,137,175,233,73,
- 43,175,233,73,3,175,233,73,137,174,233,77,137,174,233,255,77,139,183,233,
- 73,139,159,233,77,139,167,233,77,139,174,233,73,139,174,233,73,43,175,233,
- 73,3,175,233,129,252,248,239,15,133,244,247,195,248,1,129,252,248,239,15,
- 132,244,247,232,244,11,248,1,49,192,195,255,248,18,248,19,72,191,237,237,
- 232,244,16,72,131,252,235,4,73,137,159,233,195,255,248,20,248,21,72,191,237,
- 237,232,244,16,72,131,252,235,8,73,137,159,233,195,255,248,22,248,23,255,
- 76,57,227,15,132,244,247,255,76,137,225,72,41,217,72,131,252,249,16,15,130,
- 244,247,255,252,243,15,111,3,102,15,215,192,252,247,208,15,188,192,60,10,
- 15,131,244,24,72,1,195,195,248,1,72,141,139,233,72,137,216,76,57,225,73,15,
- 71,204,248,2,72,131,192,1,72,57,200,15,132,244,24,252,246,0,128,15,133,244,
- 2,248,3,72,137,195,195,255,248,25,72,131,252,236,16,248,1,72,57,252,235,15,
- 133,244,248,72,131,196,16,49,192,195,248,2,76,137,252,255,72,137,230,77,137,
- 183,233,73,137,159,233,77,137,167,233,73,137,175,233,73,43,175,233,73,3,175,
- 233,73,137,174,233,77,137,174,233,255,77,139,183,233,73,139,159,233,77,139,
- 167,233,77,139,174,233,73,139,174,233,73,43,175,233,73,3,175,233,131,252,
- 248,0,15,141,244,249,139,20,36,72,131,196,16,195,248,3,232,244,11,252,233,
- 244,1,255,248,14,248,26,255,76,57,227,15,132,244,24,255,76,137,225,72,41,
- 217,72,131,252,249,10,15,130,244,24,255,72,137,223,255,72,133,192,15,132,
+ 72,184,237,237,65,84,73,137,228,72,129,228,239,252,255,208,76,137,228,65,
+ 92,232,244,12,252,233,244,1,255,248,16,72,131,252,236,16,72,137,188,253,36,
+ 233,248,1,72,199,4,36,0,0,0,0,76,137,252,255,72,137,230,73,137,159,233,77,
+ 137,183,233,73,137,159,233,77,137,167,233,73,137,175,233,73,43,175,233,73,
+ 3,175,233,73,137,174,233,77,137,174,233,252,255,148,253,36,233,77,139,183,
+ 233,73,139,159,233,77,139,167,233,77,139,174,233,73,139,174,233,73,43,175,
+ 233,73,3,175,233,255,133,192,15,137,244,248,72,139,20,36,252,242,15,16,4,
+ 36,72,131,196,16,195,248,2,232,244,11,252,233,244,1,255,248,17,76,137,252,
+ 255,137,214,15,182,209,77,137,183,233,73,137,159,233,77,137,167,233,73,137,
+ 175,233,73,43,175,233,73,3,175,233,73,137,174,233,77,137,174,233,72,184,237,
+ 237,65,84,73,137,228,72,129,228,239,252,255,208,76,137,228,65,92,77,139,183,
+ 233,73,139,159,233,77,139,167,233,77,139,174,233,73,139,174,233,73,43,175,
+ 233,73,3,175,233,129,252,248,239,255,15,133,244,247,195,248,1,129,252,248,
+ 239,15,132,244,247,232,244,11,248,1,49,192,195,255,248,18,248,19,72,191,237,
+ 237,232,244,16,72,131,252,235,4,73,137,159,233,195,255,248,20,248,21,72,191,
+ 237,237,232,244,16,72,131,252,235,8,73,137,159,233,195,255,248,22,248,23,
+ 255,76,57,227,15,132,244,247,255,76,137,225,72,41,217,72,131,252,249,16,15,
+ 130,244,247,255,252,243,15,111,3,102,15,215,192,252,247,208,15,188,192,60,
+ 10,15,131,244,24,72,1,195,195,248,1,72,141,139,233,72,137,216,76,57,225,73,
+ 15,71,204,248,2,72,131,192,1,72,57,200,15,132,244,24,252,246,0,128,15,133,
+ 244,2,248,3,72,137,195,195,255,248,25,72,131,252,236,16,248,1,72,57,252,235,
+ 15,133,244,248,72,131,196,16,49,192,195,248,2,76,137,252,255,72,137,230,77,
+ 137,183,233,73,137,159,233,77,137,167,233,73,137,175,233,73,43,175,233,73,
+ 3,175,233,73,137,174,233,77,137,174,233,72,184,237,237,65,84,73,137,228,72,
+ 129,228,239,252,255,208,76,137,228,65,92,77,139,183,233,73,139,159,233,77,
+ 139,167,233,77,139,174,233,255,73,139,174,233,73,43,175,233,73,3,175,233,
+ 131,252,248,0,15,141,244,249,139,20,36,72,131,196,16,195,248,3,232,244,11,
+ 252,233,244,1,255,248,14,248,26,255,76,57,227,15,132,244,24,255,76,137,225,
+ 72,41,217,72,131,252,249,10,15,130,244,24,255,72,137,223,72,184,237,237,65,
+ 84,73,137,228,72,129,228,239,252,255,208,76,137,228,65,92,72,133,192,15,132,
244,24,72,137,195,72,131,252,235,1,73,137,159,233,195,255,248,24,72,191,237,
237,232,244,16,72,131,252,235,1,73,137,159,233,195,255,248,27,72,131,252,
236,8,72,137,52,36,248,1,76,137,252,255,77,137,183,233,73,137,159,233,77,
137,167,233,73,137,175,233,73,43,175,233,73,3,175,233,73,137,174,233,77,137,
- 174,233,73,137,159,233,255,77,139,183,233,73,139,159,233,77,139,167,233,77,
- 139,174,233,73,139,174,233,73,43,175,233,73,3,175,233,131,252,248,0,15,141,
- 244,248,72,131,196,8,195,248,2,232,244,11,72,139,52,36,72,57,252,235,15,133,
- 244,1,184,237,72,131,196,8,195,255,248,28,81,82,72,131,252,236,16,72,137,
- 252,247,72,137,214,72,137,226,255,72,131,196,16,90,89,132,192,15,132,244,
- 248,72,139,68,36,224,195,248,2,72,49,192,72,252,247,208,195,255,248,1,255,
- 76,57,227,15,133,244,249,255,76,137,225,72,41,217,72,129,252,249,239,15,131,
- 244,249,255,248,2,255,232,244,14,255,232,244,26,255,232,244,19,255,232,244,
- 21,255,252,233,244,250,255,248,3,255,139,19,255,72,139,19,255,252,243,15,
- 16,3,255,252,242,15,16,3,255,15,182,19,132,210,15,136,244,2,255,248,4,255,
- 137,208,209,252,234,131,224,1,252,247,216,49,194,255,72,137,208,72,209,252,
- 234,72,131,224,1,72,252,247,216,72,49,194,255,72,133,210,15,149,210,255,73,
- 137,149,233,255,65,137,149,233,255,252,242,65,15,17,133,233,255,252,243,65,
- 15,17,133,233,255,65,136,149,233,255,65,128,141,233,235,255,76,137,252,239,
- 255,132,192,15,133,244,251,232,244,12,252,233,244,1,248,5,255,72,129,195,
+ 174,233,73,137,159,233,72,184,237,237,65,84,73,137,228,72,129,228,239,252,
+ 255,208,76,137,228,65,92,77,139,183,233,73,139,159,233,77,139,167,233,77,
+ 139,174,233,73,139,174,233,73,43,175,233,255,73,3,175,233,131,252,248,0,15,
+ 141,244,248,72,131,196,8,195,248,2,232,244,11,72,139,52,36,72,57,252,235,
+ 15,133,244,1,184,237,72,131,196,8,195,255,248,28,81,82,72,131,252,236,16,
+ 72,137,252,247,72,137,214,72,137,226,72,184,237,237,65,84,73,137,228,72,129,
+ 228,239,252,255,208,76,137,228,65,92,72,131,196,16,90,89,132,192,15,132,244,
+ 248,72,139,68,36,224,195,248,2,72,49,192,72,252,247,208,195,255,76,57,227,
+ 15,133,244,249,255,76,137,225,72,41,217,72,129,252,249,239,15,131,244,249,
+ 255,248,2,255,232,244,14,255,232,244,26,255,232,244,19,255,232,244,21,255,
+ 252,233,244,250,255,248,3,255,139,19,255,72,139,19,255,252,243,15,16,3,255,
+ 252,242,15,16,3,255,15,182,19,132,210,15,136,244,2,255,248,4,255,137,208,
+ 209,252,234,131,224,1,252,247,216,49,194,255,72,137,208,72,209,252,234,72,
+ 131,224,1,72,252,247,216,72,49,194,255,72,133,210,15,149,210,255,73,137,149,
+ 233,255,65,137,149,233,255,252,242,65,15,17,133,233,255,252,243,65,15,17,
+ 133,233,255,65,136,149,233,255,65,128,141,233,235,255,76,137,252,239,255,
+ 72,184,237,237,65,84,73,137,228,72,129,228,239,252,255,208,76,137,228,65,
+ 92,255,132,192,15,133,244,251,232,244,12,252,233,244,1,248,5,255,72,129,195,
239,255,232,244,22,255,232,244,23,255,232,244,18,255,232,244,20,255,252,246,
3,128,15,133,244,2,255,249,248,1,255,76,57,227,15,132,244,252,255,76,137,
225,72,41,217,72,131,252,249,2,15,130,244,252,255,15,182,19,132,210,15,137,
@@ -104,11 +114,13 @@ static const unsigned char upb_jit_actionlist[1914] = {
59,239,15,133,244,249,128,187,233,235,255,15,132,244,250,248,3,255,232,245,
72,133,192,15,132,245,252,255,224,255,252,233,245,255,248,4,72,129,195,239,
248,5,255,248,1,76,137,252,239,255,132,192,15,133,244,248,232,244,12,252,
- 233,244,1,248,2,255,144,255,248,9,255,73,139,151,233,255,249,249,72,131,252,
- 236,8,255,72,137,252,234,72,41,218,255,72,133,192,15,133,244,248,232,244,
- 12,252,233,244,1,248,2,255,73,137,197,255,72,57,252,235,15,132,244,250,248,
- 1,76,57,227,15,133,244,248,232,244,12,252,233,244,1,248,2,255,72,137,218,
- 76,137,225,72,41,217,77,139,135,233,255,72,1,195,255,76,57,227,15,132,244,
+ 233,244,1,248,2,255,144,255,248,9,255,73,139,151,233,72,184,237,237,65,84,
+ 73,137,228,72,129,228,239,252,255,208,76,137,228,65,92,255,249,249,72,131,
+ 252,236,8,255,72,137,252,234,72,41,218,255,72,133,192,15,133,244,248,232,
+ 244,12,252,233,244,1,248,2,255,73,137,197,255,72,57,252,235,15,132,244,250,
+ 248,1,76,57,227,15,133,244,248,232,244,12,252,233,244,1,248,2,255,72,137,
+ 218,76,137,225,72,41,217,77,139,135,233,72,184,237,237,65,84,73,137,228,72,
+ 129,228,239,252,255,208,76,137,228,65,92,72,1,195,255,76,57,227,15,132,244,
249,232,244,29,248,3,255,76,137,227,255,72,57,252,235,15,133,244,1,248,4,
255,77,137,174,233,73,199,134,233,0,0,0,0,73,129,198,239,77,59,183,233,15,
132,244,15,65,199,134,233,237,255,232,244,13,255,73,129,252,238,239,77,139,
@@ -222,17 +234,21 @@ static const char *const upb_jit_globalnames[] = {
//| add DELIMEND, DECODER->buf
//|.endmacro
//|
-//| // OPT: use "call rel32" where possible.
+//| // Calls an external C function at address "addr".
//|.macro callp, addr
-//|| {
-//|| //int64_t ofs = (int64_t)addr - (int64_t)upb_status_init;
-//|| //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
//| mov64 rax, (uintptr_t)addr
+//|
+//| // Stack must be 16-byte aligned (x86-64 ABI requires this).
+//| //
+//| // OPT: possibly remove this by statically ensuring correct alignment.
+//| //
+//| // OPT: use "call rel32" where possible.
+//| push r12
+//| mov r12, rsp
+//| and rsp, 0xfffffffffffffff0UL // Align stack.
//| call rax
-//|| //} else {
-//| // call &addr
-//|| //}
-//|| }
+//| mov rsp, r12
+//| pop r12
//|.endmacro
//|
//|.macro ld64, val
@@ -331,7 +347,7 @@ static void asmlabel(jitcompiler *jc, const char *fmt, ...) {
// we do it here instead.
//|=>pclabel:
dasm_put(Dst, 0, pclabel);
-# 172 "upb/pb/compile_decoder_x64.dasc"
+# 176 "upb/pb/compile_decoder_x64.dasc"
upb_inttable_insert(&jc->asmlabels, pclabel, upb_value_ptr(str));
#endif
}
@@ -371,25 +387,10 @@ static void emit_static_asm(jitcompiler *jc) {
//| push r12
//| push rbx
//|
- //| // Align stack.
- //| // Since the JIT can call other functions (the JIT'ted code is not a leaf
- //| // function) we must respect alignment rules. All x86-64 systems require
- //| // 16-byte stack alignment.
- //| sub rsp, 8
- //|
//| mov rbx, ARG2_64 // Preserve JIT method.
//|
//| mov DECODER, rdi
//| callp upb_pbdecoder_resume // Same args as us; reuse regs.
- dasm_put(Dst, 2);
- {
- //int64_t ofs = (int64_t)upb_pbdecoder_resume - (int64_t)upb_status_init;
- //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
- dasm_put(Dst, 30, (unsigned int)((uintptr_t)upb_pbdecoder_resume), (unsigned int)(((uintptr_t)upb_pbdecoder_resume)>>32));
- //} else {
- //}
- }
-# 221 "upb/pb/compile_decoder_x64.dasc"
//| test eax, eax
//| jns >1
//| mov DECODER->saved_rsp, rsp
@@ -406,8 +407,9 @@ static void emit_static_asm(jitcompiler *jc) {
//| mov rax, DECODER->size_param
//| mov qword DECODER->call_len, 0
//|1:
- //| add rsp, 8 // Counter previous alignment.
//| pop rbx
+ dasm_put(Dst, 2, (unsigned int)((uintptr_t)upb_pbdecoder_resume), (unsigned int)(((uintptr_t)upb_pbdecoder_resume)>>32), 0xfffffffffffffff0UL, Dt2(->saved_rsp), Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt1(->sink.closure), Dt1(->end_ofs), Dt2(->bufstart_ofs), Dt2(->buf), Dt2(->call_len), Dt2(->size_param), Dt2(->call_len));
+# 236 "upb/pb/compile_decoder_x64.dasc"
//| pop r12
//| pop r13
//| pop r14
@@ -421,23 +423,14 @@ static void emit_static_asm(jitcompiler *jc) {
//| sub rsp, ARG3_64
//| mov ARG1_64, rsp
//| callp memcpy // Restore stack.
- dasm_put(Dst, 38, Dt2(->saved_rsp), Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt1(->sink.closure), Dt1(->end_ofs), Dt2(->bufstart_ofs), Dt2(->buf), Dt2(->call_len), Dt2(->size_param), Dt2(->call_len), Dt2(->callstack));
- {
- //int64_t ofs = (int64_t)memcpy - (int64_t)upb_status_init;
- //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
- dasm_put(Dst, 30, (unsigned int)((uintptr_t)memcpy), (unsigned int)(((uintptr_t)memcpy)>>32));
- //} else {
- //}
- }
-# 252 "upb/pb/compile_decoder_x64.dasc"
//| ret // Return to resumed function (not ->enterjit caller).
//|
//| // Other code can call this to suspend the JIT.
//| // To the calling code, it will appear that the function returns when
//| // the JIT resumes, and more buffer space will be available.
//| // Args: eax=the value that decode() should return.
- dasm_put(Dst, 135);
-# 258 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 115, Dt2(->callstack), (unsigned int)((uintptr_t)memcpy), (unsigned int)(((uintptr_t)memcpy)>>32), 0xfffffffffffffff0UL);
+# 255 "upb/pb/compile_decoder_x64.dasc"
asmlabel(jc, "exitjit");
//|->exitjit:
//| // Save the stack into DECODER->callstack.
@@ -448,21 +441,11 @@ static void emit_static_asm(jitcompiler *jc) {
//| mov DECODER->call_len, ARG3_64 // Preserve len for next resume.
//| mov ebx, eax // Preserve return value across memcpy.
//| callp memcpy // Copy stack into decoder.
- dasm_put(Dst, 137, Dt2(->callstack), Dt2(->saved_rsp), Dt2(->call_len));
- {
- //int64_t ofs = (int64_t)memcpy - (int64_t)upb_status_init;
- //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
- dasm_put(Dst, 30, (unsigned int)((uintptr_t)memcpy), (unsigned int)(((uintptr_t)memcpy)>>32));
- //} else {
- //}
- }
-# 268 "upb/pb/compile_decoder_x64.dasc"
//| mov eax, ebx // This will be our return value.
//|
//| // Must NOT do this before the memcpy(), otherwise memcpy() will
//| // clobber the stack we are trying to save!
//| mov rsp, DECODER->saved_rsp
- //| add rsp, 8 // Counter previous alignment.
//| pop rbx
//| pop r12
//| pop r13
@@ -474,8 +457,8 @@ static void emit_static_asm(jitcompiler *jc) {
//| // Like suspend() in the C decoder, except that the function appears
//| // (from the caller's perspective) not to return until the decoder is
//| // resumed.
- dasm_put(Dst, 160, Dt2(->saved_rsp));
-# 285 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 161, Dt2(->callstack), Dt2(->saved_rsp), Dt2(->call_len), (unsigned int)((uintptr_t)memcpy), (unsigned int)(((uintptr_t)memcpy)>>32), 0xfffffffffffffff0UL, Dt2(->saved_rsp));
+# 281 "upb/pb/compile_decoder_x64.dasc"
asmlabel(jc, "suspend");
//|->suspend:
//| cmp DECODER->ptr, PTR
@@ -485,32 +468,23 @@ static void emit_static_asm(jitcompiler *jc) {
//| commit_regs
//| mov rdi, DECODER
//| callp upb_pbdecoder_suspend
- dasm_put(Dst, 182, Dt2(->ptr), Dt2(->checkpoint), Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt2(->delim_end), Dt2(->buf), Dt2(->bufstart_ofs), Dt1(->end_ofs), Dt1(->sink.closure));
- {
- //int64_t ofs = (int64_t)upb_pbdecoder_suspend - (int64_t)upb_status_init;
- //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
- dasm_put(Dst, 30, (unsigned int)((uintptr_t)upb_pbdecoder_suspend), (unsigned int)(((uintptr_t)upb_pbdecoder_suspend)>>32));
- //} else {
- //}
- }
-# 294 "upb/pb/compile_decoder_x64.dasc"
//| jmp ->exitjit
//|
- dasm_put(Dst, 235);
-# 296 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 222, Dt2(->ptr), Dt2(->checkpoint), Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt2(->delim_end), Dt2(->buf), Dt2(->bufstart_ofs), Dt1(->end_ofs), Dt1(->sink.closure), (unsigned int)((uintptr_t)upb_pbdecoder_suspend), (unsigned int)(((uintptr_t)upb_pbdecoder_suspend)>>32), 0xfffffffffffffff0UL);
+# 292 "upb/pb/compile_decoder_x64.dasc"
asmlabel(jc, "pushlendelim");
//|->pushlendelim:
//|1:
//| mov FRAME->sink.closure, CLOSURE
//| mov DECODER->checkpoint, PTR
//| dv32
- dasm_put(Dst, 240, Dt1(->sink.closure), Dt2(->checkpoint));
+ dasm_put(Dst, 300, Dt1(->sink.closure), Dt2(->checkpoint));
if (1 == 1) {
- dasm_put(Dst, 253);
+ dasm_put(Dst, 313);
} else {
- dasm_put(Dst, 261);
+ dasm_put(Dst, 321);
}
-# 302 "upb/pb/compile_decoder_x64.dasc"
+# 298 "upb/pb/compile_decoder_x64.dasc"
//| mov rcx, DELIMEND
//| sub rcx, PTR
//| sub rcx, rdx
@@ -530,8 +504,8 @@ static void emit_static_asm(jitcompiler *jc) {
//| cmp DELIMEND, DATAEND
//| ja >2
//| mov DATAEND, DELIMEND // If DELIMEND >= PTR && DELIMEND < DATAEND
- dasm_put(Dst, 277, Dt1(->end_ofs), sizeof(upb_pbdecoder_frame), Dt2(->limit), Dt1(->groupnum), Dt2(->end));
-# 321 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 337, Dt1(->end_ofs), sizeof(upb_pbdecoder_frame), Dt2(->limit), Dt1(->groupnum), Dt2(->end));
+# 317 "upb/pb/compile_decoder_x64.dasc"
//|2:
//| ret
//|3:
@@ -540,34 +514,26 @@ static void emit_static_asm(jitcompiler *jc) {
//| // Prepare seterr args.
//| mov ARG1_64, DECODER
//| ld64 kPbDecoderStackOverflow
- dasm_put(Dst, 368, Dt2(->checkpoint));
+ dasm_put(Dst, 428, Dt2(->checkpoint));
{
uintptr_t v = (uintptr_t)kPbDecoderStackOverflow;
if (v > 0xffffffff) {
- dasm_put(Dst, 386, (unsigned int)(v), (unsigned int)((v)>>32));
+ dasm_put(Dst, 446, (unsigned int)(v), (unsigned int)((v)>>32));
} else if (v) {
- dasm_put(Dst, 391, v);
+ dasm_put(Dst, 451, v);
} else {
- dasm_put(Dst, 394);
+ dasm_put(Dst, 454);
}
}
-# 329 "upb/pb/compile_decoder_x64.dasc"
+# 325 "upb/pb/compile_decoder_x64.dasc"
//| callp upb_pbdecoder_seterr
- {
- //int64_t ofs = (int64_t)upb_pbdecoder_seterr - (int64_t)upb_status_init;
- //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
- dasm_put(Dst, 30, (unsigned int)((uintptr_t)upb_pbdecoder_seterr), (unsigned int)(((uintptr_t)upb_pbdecoder_seterr)>>32));
- //} else {
- //}
- }
-# 330 "upb/pb/compile_decoder_x64.dasc"
//| call ->suspend
//| jmp <1
//|
//| // For getting a value that spans a buffer seam. Falls back to C.
//| // Args: rdi=C decoding function (prototype: int f(upb_pbdecoder*, void*))
- dasm_put(Dst, 398);
-# 335 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 458, (unsigned int)((uintptr_t)upb_pbdecoder_seterr), (unsigned int)(((uintptr_t)upb_pbdecoder_seterr)>>32), 0xfffffffffffffff0UL);
+# 331 "upb/pb/compile_decoder_x64.dasc"
asmlabel(jc, "getvalue_slow");
//|->getvalue_slow:
//| sub rsp, 16 // Stack is [8-byte value, 8-byte func pointer]
@@ -581,8 +547,8 @@ static void emit_static_asm(jitcompiler *jc) {
//| call aword [rsp + 8]
//| load_regs
//| test eax, eax
- dasm_put(Dst, 406, 8, Dt2(->checkpoint), Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt2(->delim_end), Dt2(->buf), Dt2(->bufstart_ofs), Dt1(->end_ofs), Dt1(->sink.closure), 8, Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt1(->sink.closure), Dt1(->end_ofs), Dt2(->bufstart_ofs), Dt2(->buf));
-# 348 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 487, 8, Dt2(->checkpoint), Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt2(->delim_end), Dt2(->buf), Dt2(->bufstart_ofs), Dt1(->end_ofs), Dt1(->sink.closure), 8, Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt1(->sink.closure), Dt1(->end_ofs), Dt2(->bufstart_ofs), Dt2(->buf));
+# 344 "upb/pb/compile_decoder_x64.dasc"
//| jns >2
//| // Success; return parsed data (in rdx AND xmm0).
//| mov rdx, [rsp]
@@ -593,8 +559,8 @@ static void emit_static_asm(jitcompiler *jc) {
//| call ->exitjit // Return eax from decode function.
//| jmp <1
//|
- dasm_put(Dst, 507);
-# 358 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 588);
+# 354 "upb/pb/compile_decoder_x64.dasc"
asmlabel(jc, "parse_unknown");
//| // Args: edx=fieldnum, cl=wire type
//|->parse_unknown:
@@ -605,18 +571,11 @@ static void emit_static_asm(jitcompiler *jc) {
//| movzx ARG3_32, cl
//| commit_regs
//| callp upb_pbdecoder_skipunknown
- dasm_put(Dst, 538, Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt2(->delim_end), Dt2(->buf), Dt2(->bufstart_ofs), Dt1(->end_ofs), Dt1(->sink.closure));
- {
- //int64_t ofs = (int64_t)upb_pbdecoder_skipunknown - (int64_t)upb_status_init;
- //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
- dasm_put(Dst, 30, (unsigned int)((uintptr_t)upb_pbdecoder_skipunknown), (unsigned int)(((uintptr_t)upb_pbdecoder_skipunknown)>>32));
- //} else {
- //}
- }
-# 368 "upb/pb/compile_decoder_x64.dasc"
//| load_regs
//| cmp eax, DECODE_ENDGROUP
//| jne >1
+ dasm_put(Dst, 619, Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt2(->delim_end), Dt2(->buf), Dt2(->bufstart_ofs), Dt1(->end_ofs), Dt1(->sink.closure), (unsigned int)((uintptr_t)upb_pbdecoder_skipunknown), (unsigned int)(((uintptr_t)upb_pbdecoder_skipunknown)>>32), 0xfffffffffffffff0UL, Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt1(->sink.closure), Dt1(->end_ofs), Dt2(->bufstart_ofs), Dt2(->buf), DECODE_ENDGROUP);
+# 367 "upb/pb/compile_decoder_x64.dasc"
//| ret // Return eax=DECODE_ENDGROUP, not zero
//|1:
//| cmp eax, DECODE_OK
@@ -635,8 +594,8 @@ static void emit_static_asm(jitcompiler *jc) {
//| // re-join the fast path which will add fast_path_bytes after the callback
//| // completes. We also set DECODER->ptr to this value which is a signal to
//| // ->suspend that DECODER->checkpoint is up to date.
- dasm_put(Dst, 582, Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt1(->sink.closure), Dt1(->end_ofs), Dt2(->bufstart_ofs), Dt2(->buf), DECODE_ENDGROUP, DECODE_OK);
-# 389 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 716, DECODE_OK);
+# 385 "upb/pb/compile_decoder_x64.dasc"
asmlabel(jc, "skip_decode_f32_fallback");
//|->skipf32_fallback:
//|->decodef32_fallback:
@@ -646,8 +605,8 @@ static void emit_static_asm(jitcompiler *jc) {
//| mov DECODER->ptr, PTR
//| ret
//|
- dasm_put(Dst, 638, (unsigned int)((uintptr_t)upb_pbdecoder_decode_f32), (unsigned int)(((uintptr_t)upb_pbdecoder_decode_f32)>>32), Dt2(->ptr));
-# 398 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 740, (unsigned int)((uintptr_t)upb_pbdecoder_decode_f32), (unsigned int)(((uintptr_t)upb_pbdecoder_decode_f32)>>32), Dt2(->ptr));
+# 394 "upb/pb/compile_decoder_x64.dasc"
asmlabel(jc, "skip_decode_f64_fallback");
//|->skipf64_fallback:
//|->decodef64_fallback:
@@ -658,19 +617,19 @@ static void emit_static_asm(jitcompiler *jc) {
//| ret
//|
//| // Called for varint >= 1 byte.
- dasm_put(Dst, 660, (unsigned int)((uintptr_t)upb_pbdecoder_decode_f64), (unsigned int)(((uintptr_t)upb_pbdecoder_decode_f64)>>32), Dt2(->ptr));
-# 408 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 762, (unsigned int)((uintptr_t)upb_pbdecoder_decode_f64), (unsigned int)(((uintptr_t)upb_pbdecoder_decode_f64)>>32), Dt2(->ptr));
+# 404 "upb/pb/compile_decoder_x64.dasc"
asmlabel(jc, "skip_decode_v32_fallback");
//|->skipv32_fallback:
//|->skipv64_fallback:
//| chkeob 16, >1
- dasm_put(Dst, 682);
+ dasm_put(Dst, 784);
if (16 == 1) {
- dasm_put(Dst, 687);
+ dasm_put(Dst, 789);
} else {
- dasm_put(Dst, 695);
+ dasm_put(Dst, 797);
}
-# 412 "upb/pb/compile_decoder_x64.dasc"
+# 408 "upb/pb/compile_decoder_x64.dasc"
//| // With at least 16 bytes left, we can do a branch-less SSE version.
//| movdqu xmm0, [PTR]
//| pmovmskb eax, xmm0 // bits 0-15 are continuation bits, 16-31 are 0.
@@ -698,8 +657,8 @@ static void emit_static_asm(jitcompiler *jc) {
//| ret
//|
//| // Returns tag in edx
- dasm_put(Dst, 711, 10);
-# 439 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 813, 10);
+# 435 "upb/pb/compile_decoder_x64.dasc"
asmlabel(jc, "decode_unknown_tag_fallback");
//|->decode_unknown_tag_fallback:
//| sub rsp, 16
@@ -715,16 +674,9 @@ static void emit_static_asm(jitcompiler *jc) {
//| mov ARG2_64, rsp
//| commit_regs
//| callp upb_pbdecoder_decode_varint_slow
- dasm_put(Dst, 780, Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt2(->delim_end), Dt2(->buf), Dt2(->bufstart_ofs), Dt1(->end_ofs), Dt1(->sink.closure));
- {
- //int64_t ofs = (int64_t)upb_pbdecoder_decode_varint_slow - (int64_t)upb_status_init;
- //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
- dasm_put(Dst, 30, (unsigned int)((uintptr_t)upb_pbdecoder_decode_varint_slow), (unsigned int)(((uintptr_t)upb_pbdecoder_decode_varint_slow)>>32));
- //} else {
- //}
- }
-# 454 "upb/pb/compile_decoder_x64.dasc"
//| load_regs
+ dasm_put(Dst, 882, Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt2(->delim_end), Dt2(->buf), Dt2(->bufstart_ofs), Dt1(->end_ofs), Dt1(->sink.closure), (unsigned int)((uintptr_t)upb_pbdecoder_decode_varint_slow), (unsigned int)(((uintptr_t)upb_pbdecoder_decode_varint_slow)>>32), 0xfffffffffffffff0UL, Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt1(->sink.closure));
+# 451 "upb/pb/compile_decoder_x64.dasc"
//| cmp eax, 0
//| jge >3
//| mov edx, [rsp] // Success; return parsed data.
@@ -735,31 +687,22 @@ static void emit_static_asm(jitcompiler *jc) {
//| jmp <1
//|
//| // Called for varint >= 1 byte.
- dasm_put(Dst, 846, Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt1(->sink.closure), Dt1(->end_ofs), Dt2(->bufstart_ofs), Dt2(->buf));
-# 465 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 985, Dt1(->end_ofs), Dt2(->bufstart_ofs), Dt2(->buf));
+# 461 "upb/pb/compile_decoder_x64.dasc"
asmlabel(jc, "decode_v32_v64_fallback");
//|->decodev32_fallback:
//|->decodev64_fallback:
//| chkeob 10, ->decode_varint_slow
- dasm_put(Dst, 900);
+ dasm_put(Dst, 1023);
if (10 == 1) {
- dasm_put(Dst, 905);
+ dasm_put(Dst, 1028);
} else {
- dasm_put(Dst, 913);
+ dasm_put(Dst, 1036);
}
-# 469 "upb/pb/compile_decoder_x64.dasc"
+# 465 "upb/pb/compile_decoder_x64.dasc"
//| // OPT: do something faster than just calling the C version.
//| mov rdi, PTR
//| callp upb_vdecode_fast
- dasm_put(Dst, 929);
- {
- //int64_t ofs = (int64_t)upb_vdecode_fast - (int64_t)upb_status_init;
- //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
- dasm_put(Dst, 30, (unsigned int)((uintptr_t)upb_vdecode_fast), (unsigned int)(((uintptr_t)upb_vdecode_fast)>>32));
- //} else {
- //}
- }
-# 472 "upb/pb/compile_decoder_x64.dasc"
//| test rax, rax
//| je ->decode_varint_slow // Unterminated varint.
//| mov PTR, rax
@@ -767,8 +710,8 @@ static void emit_static_asm(jitcompiler *jc) {
//| mov DECODER->ptr, PTR
//| ret
//|
- dasm_put(Dst, 933, Dt2(->ptr));
-# 479 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1052, (unsigned int)((uintptr_t)upb_vdecode_fast), (unsigned int)(((uintptr_t)upb_vdecode_fast)>>32), 0xfffffffffffffff0UL, Dt2(->ptr));
+# 475 "upb/pb/compile_decoder_x64.dasc"
asmlabel(jc, "decode_varint_slow");
//|->decode_varint_slow:
//| // Slow path: end of buffer or error (varint length >= 10).
@@ -779,8 +722,8 @@ static void emit_static_asm(jitcompiler *jc) {
//| ret
//|
//| // Args: rsi=expected tag, return=rax (DECODE_{OK,MISMATCH})
- dasm_put(Dst, 954, (unsigned int)((uintptr_t)upb_pbdecoder_decode_varint_slow), (unsigned int)(((uintptr_t)upb_pbdecoder_decode_varint_slow)>>32), Dt2(->ptr));
-# 489 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1097, (unsigned int)((uintptr_t)upb_pbdecoder_decode_varint_slow), (unsigned int)(((uintptr_t)upb_pbdecoder_decode_varint_slow)>>32), Dt2(->ptr));
+# 485 "upb/pb/compile_decoder_x64.dasc"
asmlabel(jc, "checktag_fallback");
//|->checktag_fallback:
//| sub rsp, 8
@@ -790,16 +733,9 @@ static void emit_static_asm(jitcompiler *jc) {
//| commit_regs
//| mov DECODER->checkpoint, PTR
//| callp upb_pbdecoder_checktag_slow
- dasm_put(Dst, 974, Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt2(->delim_end), Dt2(->buf), Dt2(->bufstart_ofs), Dt1(->end_ofs), Dt1(->sink.closure), Dt2(->checkpoint));
- {
- //int64_t ofs = (int64_t)upb_pbdecoder_checktag_slow - (int64_t)upb_status_init;
- //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
- dasm_put(Dst, 30, (unsigned int)((uintptr_t)upb_pbdecoder_checktag_slow), (unsigned int)(((uintptr_t)upb_pbdecoder_checktag_slow)>>32));
- //} else {
- //}
- }
-# 498 "upb/pb/compile_decoder_x64.dasc"
//| load_regs
+ dasm_put(Dst, 1117, Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt2(->delim_end), Dt2(->buf), Dt2(->bufstart_ofs), Dt1(->end_ofs), Dt1(->sink.closure), Dt2(->checkpoint), (unsigned int)((uintptr_t)upb_pbdecoder_checktag_slow), (unsigned int)(((uintptr_t)upb_pbdecoder_checktag_slow)>>32), 0xfffffffffffffff0UL, Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt1(->sink.closure), Dt1(->end_ofs), Dt2(->bufstart_ofs));
+# 495 "upb/pb/compile_decoder_x64.dasc"
//| cmp eax, 0
//| jge >2
//| add rsp, 8
@@ -816,8 +752,8 @@ static void emit_static_asm(jitcompiler *jc) {
//| // Args: rsi=upb_inttable, rdx=key, return=rax (-1 if not found).
//| // Preserves: rcx, rdx
//| // OPT: Could write this in assembly if it's a hotspot.
- dasm_put(Dst, 1028, Dt2(->top), Dt2(->ptr), Dt2(->data_end), Dt1(->sink.closure), Dt1(->end_ofs), Dt2(->bufstart_ofs), Dt2(->buf), DECODE_EOF);
-# 515 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1216, Dt2(->buf), DECODE_EOF);
+# 511 "upb/pb/compile_decoder_x64.dasc"
asmlabel(jc, "hashlookup");
//|->hashlookup:
//| push rcx
@@ -827,15 +763,6 @@ static void emit_static_asm(jitcompiler *jc) {
//| mov rsi, rdx
//| mov rdx, rsp
//| callp upb_inttable_lookup
- dasm_put(Dst, 1094);
- {
- //int64_t ofs = (int64_t)upb_inttable_lookup - (int64_t)upb_status_init;
- //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
- dasm_put(Dst, 30, (unsigned int)((uintptr_t)upb_inttable_lookup), (unsigned int)(((uintptr_t)upb_inttable_lookup)>>32));
- //} else {
- //}
- }
-# 524 "upb/pb/compile_decoder_x64.dasc"
//| add rsp, 16
//| pop rdx
//| pop rcx
@@ -847,8 +774,8 @@ static void emit_static_asm(jitcompiler *jc) {
//| xor rax, rax
//| not rax
//| ret
- dasm_put(Dst, 1114);
-# 535 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1258, (unsigned int)((uintptr_t)upb_inttable_lookup), (unsigned int)(((uintptr_t)upb_inttable_lookup)>>32), 0xfffffffffffffff0UL);
+# 531 "upb/pb/compile_decoder_x64.dasc"
}
static void jitprimitive(jitcompiler *jc, opcode op,
@@ -865,85 +792,85 @@ static void jitprimitive(jitcompiler *jc, opcode op,
if (handler) {
//|1:
//| chkneob fastbytes, >3
- dasm_put(Dst, 1143);
+ dasm_put(Dst, 112);
if (fastbytes == 1) {
- dasm_put(Dst, 1146);
+ dasm_put(Dst, 1327);
} else {
- dasm_put(Dst, 1154, fastbytes);
+ dasm_put(Dst, 1335, fastbytes);
}
-# 551 "upb/pb/compile_decoder_x64.dasc"
+# 547 "upb/pb/compile_decoder_x64.dasc"
//|2:
- dasm_put(Dst, 1170);
-# 552 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1351);
+# 548 "upb/pb/compile_decoder_x64.dasc"
switch (type) {
case V32:
//| call ->decodev32_fallback
- dasm_put(Dst, 1173);
-# 555 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1354);
+# 551 "upb/pb/compile_decoder_x64.dasc"
break;
case V64:
//| call ->decodev64_fallback
- dasm_put(Dst, 1177);
-# 558 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1358);
+# 554 "upb/pb/compile_decoder_x64.dasc"
break;
case F32:
//| call ->decodef32_fallback
- dasm_put(Dst, 1181);
-# 561 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1362);
+# 557 "upb/pb/compile_decoder_x64.dasc"
break;
case F64:
//| call ->decodef64_fallback
- dasm_put(Dst, 1185);
-# 564 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1366);
+# 560 "upb/pb/compile_decoder_x64.dasc"
break;
case X: break;
}
//| jmp >4
- dasm_put(Dst, 1189);
-# 568 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1370);
+# 564 "upb/pb/compile_decoder_x64.dasc"
// Fast path decode; for when check_bytes bytes are available.
//|3:
- dasm_put(Dst, 1194);
-# 571 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1375);
+# 567 "upb/pb/compile_decoder_x64.dasc"
switch (op) {
case OP_PARSE_SFIXED32:
case OP_PARSE_FIXED32:
//| mov edx, dword [PTR]
- dasm_put(Dst, 1197);
-# 575 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1378);
+# 571 "upb/pb/compile_decoder_x64.dasc"
break;
case OP_PARSE_SFIXED64:
case OP_PARSE_FIXED64:
//| mov rdx, qword [PTR]
- dasm_put(Dst, 1200);
-# 579 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1381);
+# 575 "upb/pb/compile_decoder_x64.dasc"
break;
case OP_PARSE_FLOAT:
//| movss xmm0, dword [PTR]
- dasm_put(Dst, 1204);
-# 582 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1385);
+# 578 "upb/pb/compile_decoder_x64.dasc"
break;
case OP_PARSE_DOUBLE:
//| movsd xmm0, qword [PTR]
- dasm_put(Dst, 1210);
-# 585 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1391);
+# 581 "upb/pb/compile_decoder_x64.dasc"
break;
default:
// Inline one byte of varint decoding.
//| movzx edx, byte [PTR]
//| test dl, dl
//| js <2 // Fallback to slow path for >1 byte varint.
- dasm_put(Dst, 1216);
-# 591 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1397);
+# 587 "upb/pb/compile_decoder_x64.dasc"
break;
}
// Second-stage decode; used for both fast and slow paths
// (only needed for a few types).
//|4:
- dasm_put(Dst, 1226);
-# 597 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1407);
+# 593 "upb/pb/compile_decoder_x64.dasc"
switch (op) {
case OP_PARSE_SINT32:
// 32-bit zig-zag decode.
@@ -952,8 +879,8 @@ static void jitprimitive(jitcompiler *jc, opcode op,
//| and eax, 1
//| neg eax
//| xor edx, eax
- dasm_put(Dst, 1229);
-# 605 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1410);
+# 601 "upb/pb/compile_decoder_x64.dasc"
break;
case OP_PARSE_SINT64:
// 64-bit zig-zag decode.
@@ -962,14 +889,14 @@ static void jitprimitive(jitcompiler *jc, opcode op,
//| and rax, 1
//| neg rax
//| xor rdx, rax
- dasm_put(Dst, 1243);
-# 613 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1424);
+# 609 "upb/pb/compile_decoder_x64.dasc"
break;
case OP_PARSE_BOOL:
//| test rdx, rdx
//| setne dl
- dasm_put(Dst, 1262);
-# 617 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1443);
+# 613 "upb/pb/compile_decoder_x64.dasc"
break;
default: break;
}
@@ -982,30 +909,30 @@ static void jitprimitive(jitcompiler *jc, opcode op,
case UPB_TYPE_INT64:
case UPB_TYPE_UINT64:
//| mov [CLOSURE + data->offset], rdx
- dasm_put(Dst, 1269, data->offset);
-# 629 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1450, data->offset);
+# 625 "upb/pb/compile_decoder_x64.dasc"
break;
case UPB_TYPE_INT32:
case UPB_TYPE_UINT32:
case UPB_TYPE_ENUM:
//| mov [CLOSURE + data->offset], edx
- dasm_put(Dst, 1274, data->offset);
-# 634 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1455, data->offset);
+# 630 "upb/pb/compile_decoder_x64.dasc"
break;
case UPB_TYPE_DOUBLE:
//| movsd qword [CLOSURE + data->offset], XMMARG1
- dasm_put(Dst, 1279, data->offset);
-# 637 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1460, data->offset);
+# 633 "upb/pb/compile_decoder_x64.dasc"
break;
case UPB_TYPE_FLOAT:
//| movss dword [CLOSURE + data->offset], XMMARG1
- dasm_put(Dst, 1287, data->offset);
-# 640 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1468, data->offset);
+# 636 "upb/pb/compile_decoder_x64.dasc"
break;
case UPB_TYPE_BOOL:
//| mov [CLOSURE + data->offset], dl
- dasm_put(Dst, 1295, data->offset);
-# 643 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1476, data->offset);
+# 639 "upb/pb/compile_decoder_x64.dasc"
break;
case UPB_TYPE_STRING:
case UPB_TYPE_BYTES:
@@ -1014,98 +941,92 @@ static void jitprimitive(jitcompiler *jc, opcode op,
}
//| sethas CLOSURE, data->hasbit
if (data->hasbit >= 0) {
- dasm_put(Dst, 1300, ((uint32_t)data->hasbit / 8), (1 << ((uint32_t)data->hasbit % 8)));
+ dasm_put(Dst, 1481, ((uint32_t)data->hasbit / 8), (1 << ((uint32_t)data->hasbit % 8)));
}
-# 650 "upb/pb/compile_decoder_x64.dasc"
+# 646 "upb/pb/compile_decoder_x64.dasc"
} else if (handler) {
//| mov ARG1_64, CLOSURE
//| load_handler_data h, sel
- dasm_put(Dst, 1306);
+ dasm_put(Dst, 1487);
{
uintptr_t v = (uintptr_t)upb_handlers_gethandlerdata(h, sel);
if (v > 0xffffffff) {
- dasm_put(Dst, 386, (unsigned int)(v), (unsigned int)((v)>>32));
+ dasm_put(Dst, 446, (unsigned int)(v), (unsigned int)((v)>>32));
} else if (v) {
- dasm_put(Dst, 391, v);
+ dasm_put(Dst, 451, v);
} else {
- dasm_put(Dst, 394);
+ dasm_put(Dst, 454);
}
}
-# 653 "upb/pb/compile_decoder_x64.dasc"
+# 649 "upb/pb/compile_decoder_x64.dasc"
//| callp handler
- {
- //int64_t ofs = (int64_t)handler - (int64_t)upb_status_init;
- //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
- dasm_put(Dst, 30, (unsigned int)((uintptr_t)handler), (unsigned int)(((uintptr_t)handler)>>32));
- //} else {
- //}
- }
-# 654 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1492, (unsigned int)((uintptr_t)handler), (unsigned int)(((uintptr_t)handler)>>32), 0xfffffffffffffff0UL);
+# 650 "upb/pb/compile_decoder_x64.dasc"
if (!alwaysok(h, sel)) {
//| test al, al
//| jnz >5
//| call ->suspend
//| jmp <1
//|5:
- dasm_put(Dst, 1311);
-# 660 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1514);
+# 656 "upb/pb/compile_decoder_x64.dasc"
}
}
// We do this last so that the checkpoint is not advanced past the user's
// data until the callback has returned success.
//| add PTR, fastbytes
- dasm_put(Dst, 1327, fastbytes);
-# 666 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1530, fastbytes);
+# 662 "upb/pb/compile_decoder_x64.dasc"
} else {
// No handler registered for this value, just skip it.
//| chkneob fastbytes, >3
if (fastbytes == 1) {
- dasm_put(Dst, 1146);
+ dasm_put(Dst, 1327);
} else {
- dasm_put(Dst, 1154, fastbytes);
+ dasm_put(Dst, 1335, fastbytes);
}
-# 669 "upb/pb/compile_decoder_x64.dasc"
+# 665 "upb/pb/compile_decoder_x64.dasc"
//|2:
- dasm_put(Dst, 1170);
-# 670 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1351);
+# 666 "upb/pb/compile_decoder_x64.dasc"
switch (type) {
case V32:
//| call ->skipv32_fallback
- dasm_put(Dst, 1332);
-# 673 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1535);
+# 669 "upb/pb/compile_decoder_x64.dasc"
break;
case V64:
//| call ->skipv64_fallback
- dasm_put(Dst, 1336);
-# 676 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1539);
+# 672 "upb/pb/compile_decoder_x64.dasc"
break;
case F32:
//| call ->skipf32_fallback
- dasm_put(Dst, 1340);
-# 679 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1543);
+# 675 "upb/pb/compile_decoder_x64.dasc"
break;
case F64:
//| call ->skipf64_fallback
- dasm_put(Dst, 1344);
-# 682 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1547);
+# 678 "upb/pb/compile_decoder_x64.dasc"
break;
case X: break;
}
// Fast-path skip.
//|3:
- dasm_put(Dst, 1194);
-# 688 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1375);
+# 684 "upb/pb/compile_decoder_x64.dasc"
if (type == V32 || type == V64) {
//| test byte [PTR], 0x80
//| jnz <2
- dasm_put(Dst, 1348);
-# 691 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1551);
+# 687 "upb/pb/compile_decoder_x64.dasc"
}
//| add PTR, fastbytes
- dasm_put(Dst, 1327, fastbytes);
-# 693 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1530, fastbytes);
+# 689 "upb/pb/compile_decoder_x64.dasc"
}
}
@@ -1125,18 +1046,18 @@ static void jitdispatch(jitcompiler *jc,
//|=>define_jmptarget(jc, &method->dispatch):
//|1:
- dasm_put(Dst, 1357, define_jmptarget(jc, &method->dispatch));
-# 712 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1560, define_jmptarget(jc, &method->dispatch));
+# 708 "upb/pb/compile_decoder_x64.dasc"
// Decode the field tag.
//| mov aword DECODER->checkpoint, PTR
//| chkeob 2, >6
- dasm_put(Dst, 248, Dt2(->checkpoint));
+ dasm_put(Dst, 308, Dt2(->checkpoint));
if (2 == 1) {
- dasm_put(Dst, 1361);
+ dasm_put(Dst, 1564);
} else {
- dasm_put(Dst, 1369);
+ dasm_put(Dst, 1572);
}
-# 715 "upb/pb/compile_decoder_x64.dasc"
+# 711 "upb/pb/compile_decoder_x64.dasc"
//| movzx edx, byte [PTR]
//| test dl, dl
//| jns >7 // Jump if first byte has no continuation bit.
@@ -1160,49 +1081,49 @@ static void jitdispatch(jitcompiler *jc,
//| mov ecx, edx
//| shr edx, 3
//| and cl, 7
- dasm_put(Dst, 1385, 1);
-# 738 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1588, 1);
+# 734 "upb/pb/compile_decoder_x64.dasc"
// See comment attached to upb_pbdecodermethod.dispatch for layout of the
// dispatch table.
//|2:
//| cmp edx, dispatch->array_size
- dasm_put(Dst, 1450, dispatch->array_size);
-# 743 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1653, dispatch->array_size);
+# 739 "upb/pb/compile_decoder_x64.dasc"
if (has_hash_entries) {
//| jae >7
- dasm_put(Dst, 1457);
-# 745 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1660);
+# 741 "upb/pb/compile_decoder_x64.dasc"
} else {
//| jae >5
- dasm_put(Dst, 1462);
-# 747 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1665);
+# 743 "upb/pb/compile_decoder_x64.dasc"
}
//| // OPT: Compact the lookup arr into 32-bit entries.
if ((uintptr_t)dispatch->array > 0x7fffffff) {
//| mov64 rax, (uintptr_t)dispatch->array
//| mov rax, qword [rax + rdx * 8]
- dasm_put(Dst, 1467, (unsigned int)((uintptr_t)dispatch->array), (unsigned int)(((uintptr_t)dispatch->array)>>32));
-# 752 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1670, (unsigned int)((uintptr_t)dispatch->array), (unsigned int)(((uintptr_t)dispatch->array)>>32));
+# 748 "upb/pb/compile_decoder_x64.dasc"
} else {
//| mov rax, qword [rdx * 8 + dispatch->array]
- dasm_put(Dst, 1476, dispatch->array);
-# 754 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1679, dispatch->array);
+# 750 "upb/pb/compile_decoder_x64.dasc"
}
//|3:
//| // We take advantage of the fact that non-present entries are stored
//| // as -1, which will result in wire types that will never match.
//| cmp al, cl
- dasm_put(Dst, 1482);
-# 759 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1685);
+# 755 "upb/pb/compile_decoder_x64.dasc"
if (has_multi_wiretype) {
//| jne >6
- dasm_put(Dst, 1487);
-# 761 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1690);
+# 757 "upb/pb/compile_decoder_x64.dasc"
} else {
//| jne >5
- dasm_put(Dst, 1492);
-# 763 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1695);
+# 759 "upb/pb/compile_decoder_x64.dasc"
}
//| shr rax, 16
//|
@@ -1227,8 +1148,8 @@ static void jitdispatch(jitcompiler *jc,
//| jz <1
//| lea rax, [>9] // ENDGROUP; Load address of OP_ENDMSG.
//| ret
- dasm_put(Dst, 1497, define_jmptarget(jc, dispatch->array));
-# 787 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1700, define_jmptarget(jc, dispatch->array));
+# 783 "upb/pb/compile_decoder_x64.dasc"
if (has_multi_wiretype) {
//|6:
@@ -1238,46 +1159,46 @@ static void jitdispatch(jitcompiler *jc,
//| // Secondary wire type is a match, look up fn + UPB_MAX_FIELDNUMBER.
//| add rdx, UPB_MAX_FIELDNUMBER
//| // This key will never be in the array part, so do a hash lookup.
- dasm_put(Dst, 1531, UPB_MAX_FIELDNUMBER);
-# 796 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1734, UPB_MAX_FIELDNUMBER);
+# 792 "upb/pb/compile_decoder_x64.dasc"
assert(has_hash_entries);
//| ld64 dispatch
{
uintptr_t v = (uintptr_t)dispatch;
if (v > 0xffffffff) {
- dasm_put(Dst, 386, (unsigned int)(v), (unsigned int)((v)>>32));
+ dasm_put(Dst, 446, (unsigned int)(v), (unsigned int)((v)>>32));
} else if (v) {
- dasm_put(Dst, 391, v);
+ dasm_put(Dst, 451, v);
} else {
- dasm_put(Dst, 394);
+ dasm_put(Dst, 454);
}
}
-# 798 "upb/pb/compile_decoder_x64.dasc"
+# 794 "upb/pb/compile_decoder_x64.dasc"
//| jmp ->hashlookup // Tail call.
- dasm_put(Dst, 1544);
-# 799 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1747);
+# 795 "upb/pb/compile_decoder_x64.dasc"
}
if (has_hash_entries) {
//|7:
//| // Hash table lookup.
//| ld64 dispatch
- dasm_put(Dst, 1549);
+ dasm_put(Dst, 1752);
{
uintptr_t v = (uintptr_t)dispatch;
if (v > 0xffffffff) {
- dasm_put(Dst, 386, (unsigned int)(v), (unsigned int)((v)>>32));
+ dasm_put(Dst, 446, (unsigned int)(v), (unsigned int)((v)>>32));
} else if (v) {
- dasm_put(Dst, 391, v);
+ dasm_put(Dst, 451, v);
} else {
- dasm_put(Dst, 394);
+ dasm_put(Dst, 454);
}
}
-# 805 "upb/pb/compile_decoder_x64.dasc"
+# 801 "upb/pb/compile_decoder_x64.dasc"
//| call ->hashlookup
//| jmp <3
- dasm_put(Dst, 1552);
-# 807 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1755);
+# 803 "upb/pb/compile_decoder_x64.dasc"
}
}
@@ -1299,11 +1220,11 @@ static void jittag(jitcompiler *jc, uint64_t tag, int n, int ofs,
//| chkneob n, >1
if (n == 1) {
- dasm_put(Dst, 1560);
+ dasm_put(Dst, 1763);
} else {
- dasm_put(Dst, 1568, n);
+ dasm_put(Dst, 1771, n);
}
-# 827 "upb/pb/compile_decoder_x64.dasc"
+# 823 "upb/pb/compile_decoder_x64.dasc"
//| // OPT: this is way too much fallback code to put here.
//| // Reduce and/or move to a separate section to make better icache usage.
@@ -1311,36 +1232,36 @@ static void jittag(jitcompiler *jc, uint64_t tag, int n, int ofs,
{
uintptr_t v = (uintptr_t)tag;
if (v > 0xffffffff) {
- dasm_put(Dst, 386, (unsigned int)(v), (unsigned int)((v)>>32));
+ dasm_put(Dst, 446, (unsigned int)(v), (unsigned int)((v)>>32));
} else if (v) {
- dasm_put(Dst, 391, v);
+ dasm_put(Dst, 451, v);
} else {
- dasm_put(Dst, 394);
+ dasm_put(Dst, 454);
}
}
-# 831 "upb/pb/compile_decoder_x64.dasc"
+# 827 "upb/pb/compile_decoder_x64.dasc"
//| call ->checktag_fallback
//| cmp eax, DECODE_MISMATCH
//| je >3
//| cmp eax, DECODE_EOF
//| je =>jmptarget(jc, delimend)
//| jmp >5
- dasm_put(Dst, 1584, DECODE_MISMATCH, DECODE_EOF, jmptarget(jc, delimend));
-# 837 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1787, DECODE_MISMATCH, DECODE_EOF, jmptarget(jc, delimend));
+# 833 "upb/pb/compile_decoder_x64.dasc"
//|1:
- dasm_put(Dst, 1143);
-# 839 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 112);
+# 835 "upb/pb/compile_decoder_x64.dasc"
switch (n) {
case 1:
//| cmp byte [PTR], tag
- dasm_put(Dst, 1607, tag);
-# 842 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1810, tag);
+# 838 "upb/pb/compile_decoder_x64.dasc"
break;
case 2:
//| cmp word [PTR], tag
- dasm_put(Dst, 1611, tag);
-# 845 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1814, tag);
+# 841 "upb/pb/compile_decoder_x64.dasc"
break;
case 3:
//| // OPT: Slightly more efficient code, but depends on an extra byte.
@@ -1351,42 +1272,42 @@ static void jittag(jitcompiler *jc, uint64_t tag, int n, int ofs,
//| jne >2
//| cmp byte [PTR + 2], (tag >> 16)
//|2:
- dasm_put(Dst, 1616, (tag & 0xffff), 2, (tag >> 16));
-# 855 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1819, (tag & 0xffff), 2, (tag >> 16));
+# 851 "upb/pb/compile_decoder_x64.dasc"
break;
case 4:
//| cmp dword [PTR], tag
- dasm_put(Dst, 1631, tag);
-# 858 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1834, tag);
+# 854 "upb/pb/compile_decoder_x64.dasc"
break;
case 5:
//| cmp dword [PTR], (tag & 0xffffffff)
//| jne >3
//| cmp byte [PTR + 4], (tag >> 32)
- dasm_put(Dst, 1635, (tag & 0xffffffff), 4, (tag >> 32));
-# 863 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1838, (tag & 0xffffffff), 4, (tag >> 32));
+# 859 "upb/pb/compile_decoder_x64.dasc"
}
//| je >4
//|3:
- dasm_put(Dst, 1647);
-# 866 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1850);
+# 862 "upb/pb/compile_decoder_x64.dasc"
if (ofs == 0) {
//| call =>jmptarget(jc, &method->dispatch)
//| test rax, rax
//| jz =>jmptarget(jc, delimend)
//| jmp rax
- dasm_put(Dst, 1654, jmptarget(jc, &method->dispatch), jmptarget(jc, delimend));
-# 871 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1857, jmptarget(jc, &method->dispatch), jmptarget(jc, delimend));
+# 867 "upb/pb/compile_decoder_x64.dasc"
} else {
//| jmp =>jmptarget(jc, jc->pc + ofs)
- dasm_put(Dst, 1666, jmptarget(jc, jc->pc + ofs));
-# 873 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1869, jmptarget(jc, jc->pc + ofs));
+# 869 "upb/pb/compile_decoder_x64.dasc"
}
//|4:
//| add PTR, n
//|5:
- dasm_put(Dst, 1670, n);
-# 877 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1873, n);
+# 873 "upb/pb/compile_decoder_x64.dasc"
}
// Compile the bytecode to x64.
@@ -1409,7 +1330,7 @@ static void jitbytecode(jitcompiler *jc) {
// TODO: optimize this to only define pclabels that are actually used.
//|=>define_jmptarget(jc, jc->pc):
dasm_put(Dst, 0, define_jmptarget(jc, jc->pc));
-# 898 "upb/pb/compile_decoder_x64.dasc"
+# 894 "upb/pb/compile_decoder_x64.dasc"
}
jc->pc++;
@@ -1422,75 +1343,62 @@ static void jitbytecode(jitcompiler *jc) {
//|1:
//| mov ARG1_64, CLOSURE
//| load_handler_data h, UPB_STARTMSG_SELECTOR
- dasm_put(Dst, 1679);
+ dasm_put(Dst, 1882);
{
uintptr_t v = (uintptr_t)upb_handlers_gethandlerdata(h, UPB_STARTMSG_SELECTOR);
if (v > 0xffffffff) {
- dasm_put(Dst, 386, (unsigned int)(v), (unsigned int)((v)>>32));
+ dasm_put(Dst, 446, (unsigned int)(v), (unsigned int)((v)>>32));
} else if (v) {
- dasm_put(Dst, 391, v);
+ dasm_put(Dst, 451, v);
} else {
- dasm_put(Dst, 394);
+ dasm_put(Dst, 454);
}
}
-# 910 "upb/pb/compile_decoder_x64.dasc"
+# 906 "upb/pb/compile_decoder_x64.dasc"
//| callp startmsg
- {
- //int64_t ofs = (int64_t)startmsg - (int64_t)upb_status_init;
- //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
- dasm_put(Dst, 30, (unsigned int)((uintptr_t)startmsg), (unsigned int)(((uintptr_t)startmsg)>>32));
- //} else {
- //}
- }
-# 911 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1492, (unsigned int)((uintptr_t)startmsg), (unsigned int)(((uintptr_t)startmsg)>>32), 0xfffffffffffffff0UL);
+# 907 "upb/pb/compile_decoder_x64.dasc"
if (!alwaysok(h, UPB_STARTMSG_SELECTOR)) {
//| test al, al
//| jnz >2
//| call ->suspend
//| jmp <1
//|2:
- dasm_put(Dst, 1686);
-# 917 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1889);
+# 913 "upb/pb/compile_decoder_x64.dasc"
}
} else {
//| nop
- dasm_put(Dst, 1702);
-# 920 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1905);
+# 916 "upb/pb/compile_decoder_x64.dasc"
}
break;
}
case OP_ENDMSG: {
upb_func *endmsg = gethandler(h, UPB_ENDMSG_SELECTOR);
//|9:
- dasm_put(Dst, 1704);
-# 926 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1907);
+# 922 "upb/pb/compile_decoder_x64.dasc"
if (endmsg) {
// bool endmsg(void *closure, const void *hd, upb_status *status)
//| mov ARG1_64, CLOSURE
//| load_handler_data h, UPB_ENDMSG_SELECTOR
- dasm_put(Dst, 1306);
+ dasm_put(Dst, 1487);
{
uintptr_t v = (uintptr_t)upb_handlers_gethandlerdata(h, UPB_ENDMSG_SELECTOR);
if (v > 0xffffffff) {
- dasm_put(Dst, 386, (unsigned int)(v), (unsigned int)((v)>>32));
+ dasm_put(Dst, 446, (unsigned int)(v), (unsigned int)((v)>>32));
} else if (v) {
- dasm_put(Dst, 391, v);
+ dasm_put(Dst, 451, v);
} else {
- dasm_put(Dst, 394);
+ dasm_put(Dst, 454);
}
}
-# 930 "upb/pb/compile_decoder_x64.dasc"
+# 926 "upb/pb/compile_decoder_x64.dasc"
//| mov ARG3_64, DECODER->status
//| callp endmsg
- dasm_put(Dst, 1707, Dt2(->status));
- {
- //int64_t ofs = (int64_t)endmsg - (int64_t)upb_status_init;
- //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
- dasm_put(Dst, 30, (unsigned int)((uintptr_t)endmsg), (unsigned int)(((uintptr_t)endmsg)>>32));
- //} else {
- //}
- }
-# 932 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1910, Dt2(->status), (unsigned int)((uintptr_t)endmsg), (unsigned int)(((uintptr_t)endmsg)>>32), 0xfffffffffffffff0UL);
+# 928 "upb/pb/compile_decoder_x64.dasc"
}
break;
}
@@ -1521,8 +1429,8 @@ static void jitbytecode(jitcompiler *jc) {
//|=>define_jmptarget(jc, op_pc):
//|=>define_jmptarget(jc, method):
//| sub rsp, 8
- dasm_put(Dst, 1712, define_jmptarget(jc, op_pc), define_jmptarget(jc, method));
-# 962 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1936, define_jmptarget(jc, op_pc), define_jmptarget(jc, method));
+# 958 "upb/pb/compile_decoder_x64.dasc"
break;
}
@@ -1552,50 +1460,44 @@ static void jitbytecode(jitcompiler *jc) {
//|1:
//| mov ARG1_64, CLOSURE
//| load_handler_data h, arg
- dasm_put(Dst, 1679);
+ dasm_put(Dst, 1882);
{
uintptr_t v = (uintptr_t)upb_handlers_gethandlerdata(h, arg);
if (v > 0xffffffff) {
- dasm_put(Dst, 386, (unsigned int)(v), (unsigned int)((v)>>32));
+ dasm_put(Dst, 446, (unsigned int)(v), (unsigned int)((v)>>32));
} else if (v) {
- dasm_put(Dst, 391, v);
+ dasm_put(Dst, 451, v);
} else {
- dasm_put(Dst, 394);
+ dasm_put(Dst, 454);
}
}
-# 991 "upb/pb/compile_decoder_x64.dasc"
+# 987 "upb/pb/compile_decoder_x64.dasc"
if (op == OP_STARTSTR) {
//| mov ARG3_64, DELIMEND
//| sub ARG3_64, PTR
- dasm_put(Dst, 1720);
-# 994 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1944);
+# 990 "upb/pb/compile_decoder_x64.dasc"
}
//| callp start
- {
- //int64_t ofs = (int64_t)start - (int64_t)upb_status_init;
- //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
- dasm_put(Dst, 30, (unsigned int)((uintptr_t)start), (unsigned int)(((uintptr_t)start)>>32));
- //} else {
- //}
- }
-# 996 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1492, (unsigned int)((uintptr_t)start), (unsigned int)(((uintptr_t)start)>>32), 0xfffffffffffffff0UL);
+# 992 "upb/pb/compile_decoder_x64.dasc"
if (!alwaysok(h, arg)) {
//| test rax, rax
//| jnz >2
//| call ->suspend
//| jmp <1
//|2:
- dasm_put(Dst, 1728);
-# 1002 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1952);
+# 998 "upb/pb/compile_decoder_x64.dasc"
}
//| mov CLOSURE, rax
- dasm_put(Dst, 1745);
-# 1004 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1969);
+# 1000 "upb/pb/compile_decoder_x64.dasc"
} else {
// TODO: nop is only required because of asmlabel().
//| nop
- dasm_put(Dst, 1702);
-# 1007 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1905);
+# 1003 "upb/pb/compile_decoder_x64.dasc"
}
break;
}
@@ -1610,41 +1512,35 @@ static void jitbytecode(jitcompiler *jc) {
//|1:
//| mov ARG1_64, CLOSURE
//| load_handler_data h, arg
- dasm_put(Dst, 1679);
+ dasm_put(Dst, 1882);
{
uintptr_t v = (uintptr_t)upb_handlers_gethandlerdata(h, arg);
if (v > 0xffffffff) {
- dasm_put(Dst, 386, (unsigned int)(v), (unsigned int)((v)>>32));
+ dasm_put(Dst, 446, (unsigned int)(v), (unsigned int)((v)>>32));
} else if (v) {
- dasm_put(Dst, 391, v);
+ dasm_put(Dst, 451, v);
} else {
- dasm_put(Dst, 394);
+ dasm_put(Dst, 454);
}
}
-# 1021 "upb/pb/compile_decoder_x64.dasc"
+# 1017 "upb/pb/compile_decoder_x64.dasc"
//| callp end
- {
- //int64_t ofs = (int64_t)end - (int64_t)upb_status_init;
- //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
- dasm_put(Dst, 30, (unsigned int)((uintptr_t)end), (unsigned int)(((uintptr_t)end)>>32));
- //} else {
- //}
- }
-# 1022 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1492, (unsigned int)((uintptr_t)end), (unsigned int)(((uintptr_t)end)>>32), 0xfffffffffffffff0UL);
+# 1018 "upb/pb/compile_decoder_x64.dasc"
if (!alwaysok(h, arg)) {
//| test al, al
//| jnz >2
//| call ->suspend
//| jmp <1
//|2:
- dasm_put(Dst, 1686);
-# 1028 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1889);
+# 1024 "upb/pb/compile_decoder_x64.dasc"
}
} else {
// TODO: nop is only required because of asmlabel().
//| nop
- dasm_put(Dst, 1702);
-# 1032 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1905);
+# 1028 "upb/pb/compile_decoder_x64.dasc"
}
break;
}
@@ -1658,59 +1554,50 @@ static void jitbytecode(jitcompiler *jc) {
//| call ->suspend
//| jmp <1
//|2:
- dasm_put(Dst, 1749);
-# 1045 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1973);
+# 1041 "upb/pb/compile_decoder_x64.dasc"
if (str) {
// size_t str(void *closure, const void *hd, const char *str, size_t n)
//| mov ARG1_64, CLOSURE
//| load_handler_data h, arg
- dasm_put(Dst, 1306);
+ dasm_put(Dst, 1487);
{
uintptr_t v = (uintptr_t)upb_handlers_gethandlerdata(h, arg);
if (v > 0xffffffff) {
- dasm_put(Dst, 386, (unsigned int)(v), (unsigned int)((v)>>32));
+ dasm_put(Dst, 446, (unsigned int)(v), (unsigned int)((v)>>32));
} else if (v) {
- dasm_put(Dst, 391, v);
+ dasm_put(Dst, 451, v);
} else {
- dasm_put(Dst, 394);
+ dasm_put(Dst, 454);
}
}
-# 1049 "upb/pb/compile_decoder_x64.dasc"
+# 1045 "upb/pb/compile_decoder_x64.dasc"
//| mov ARG3_64, PTR
//| mov ARG4_64, DATAEND
//| sub ARG4_64, PTR
//| mov ARG5_64, qword DECODER->handle
//| callp str
- dasm_put(Dst, 1776, Dt2(->handle));
- {
- //int64_t ofs = (int64_t)str - (int64_t)upb_status_init;
- //if (ofs > (1 << 30) || ofs < -(1 << 30)) {
- dasm_put(Dst, 30, (unsigned int)((uintptr_t)str), (unsigned int)(((uintptr_t)str)>>32));
- //} else {
- //}
- }
-# 1054 "upb/pb/compile_decoder_x64.dasc"
//| add PTR, rax
- dasm_put(Dst, 1790);
-# 1055 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 2000, Dt2(->handle), (unsigned int)((uintptr_t)str), (unsigned int)(((uintptr_t)str)>>32), 0xfffffffffffffff0UL);
+# 1051 "upb/pb/compile_decoder_x64.dasc"
if (!alwaysok(h, arg)) {
//| cmp PTR, DATAEND
//| je >3
//| call ->strret_fallback
//|3:
- dasm_put(Dst, 1794);
-# 1060 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 2038);
+# 1056 "upb/pb/compile_decoder_x64.dasc"
}
} else {
//| mov PTR, DATAEND
- dasm_put(Dst, 1807);
-# 1063 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 2051);
+# 1059 "upb/pb/compile_decoder_x64.dasc"
}
//| cmp PTR, DELIMEND
//| jne <1
//|4:
- dasm_put(Dst, 1811);
-# 1067 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 2055);
+# 1063 "upb/pb/compile_decoder_x64.dasc"
break;
}
case OP_PUSHTAGDELIM:
@@ -1725,19 +1612,19 @@ static void jitbytecode(jitcompiler *jc) {
//| cmp FRAME, DECODER->limit
//| je ->err
//| mov dword FRAME->groupnum, arg
- dasm_put(Dst, 1822, Dt1(->sink.closure), Dt1(->end_ofs), sizeof(upb_pbdecoder_frame), Dt2(->limit), Dt1(->groupnum), arg);
-# 1081 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 2066, Dt1(->sink.closure), Dt1(->end_ofs), sizeof(upb_pbdecoder_frame), Dt2(->limit), Dt1(->groupnum), arg);
+# 1077 "upb/pb/compile_decoder_x64.dasc"
break;
case OP_PUSHLENDELIM:
//| call ->pushlendelim
- dasm_put(Dst, 1852);
-# 1084 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 2096);
+# 1080 "upb/pb/compile_decoder_x64.dasc"
break;
case OP_POP:
//| sub FRAME, sizeof(upb_pbdecoder_frame)
//| mov CLOSURE, FRAME->sink.closure
- dasm_put(Dst, 1856, sizeof(upb_pbdecoder_frame), Dt1(->sink.closure));
-# 1088 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 2100, sizeof(upb_pbdecoder_frame), Dt1(->sink.closure));
+# 1084 "upb/pb/compile_decoder_x64.dasc"
break;
case OP_SETDELIM:
// OPT: experiment with testing vs old offset to optimize away.
@@ -1749,36 +1636,36 @@ static void jitbytecode(jitcompiler *jc) {
//| ja >1 // OPT: try cmov.
//| mov DATAEND, DELIMEND
//|1:
- dasm_put(Dst, 1866, Dt2(->end), Dt1(->end_ofs), Dt2(->buf));
-# 1099 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 2110, Dt2(->end), Dt1(->end_ofs), Dt2(->buf));
+# 1095 "upb/pb/compile_decoder_x64.dasc"
break;
case OP_SETBIGGROUPNUM:
//| mov dword FRAME->groupnum, *jc->pc++
- dasm_put(Dst, 1846, Dt1(->groupnum), *jc->pc++);
-# 1102 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 2090, Dt1(->groupnum), *jc->pc++);
+# 1098 "upb/pb/compile_decoder_x64.dasc"
break;
case OP_CHECKDELIM:
//| cmp DELIMEND, PTR
//| je =>jmptarget(jc, jc->pc + longofs)
- dasm_put(Dst, 1896, jmptarget(jc, jc->pc + longofs));
-# 1106 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 2140, jmptarget(jc, jc->pc + longofs));
+# 1102 "upb/pb/compile_decoder_x64.dasc"
break;
case OP_CALL:
//| call =>jmptarget(jc, jc->pc + longofs)
- dasm_put(Dst, 1903, jmptarget(jc, jc->pc + longofs));
-# 1109 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 2147, jmptarget(jc, jc->pc + longofs));
+# 1105 "upb/pb/compile_decoder_x64.dasc"
break;
case OP_BRANCH:
//| jmp =>jmptarget(jc, jc->pc + longofs);
- dasm_put(Dst, 1666, jmptarget(jc, jc->pc + longofs));
-# 1112 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1869, jmptarget(jc, jc->pc + longofs));
+# 1108 "upb/pb/compile_decoder_x64.dasc"
break;
case OP_RET:
//|9:
//| add rsp, 8
//| ret
- dasm_put(Dst, 1906);
-# 1117 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 2150);
+# 1113 "upb/pb/compile_decoder_x64.dasc"
break;
case OP_TAG1:
jittag(jc, (arg >> 8) & 0xff, 1, (int8_t)arg, method);
@@ -1799,6 +1686,6 @@ static void jitbytecode(jitcompiler *jc) {
asmlabel(jc, "eof");
//| nop
- dasm_put(Dst, 1702);
-# 1137 "upb/pb/compile_decoder_x64.dasc"
+ dasm_put(Dst, 1905);
+# 1133 "upb/pb/compile_decoder_x64.dasc"
}
diff --git a/upb/sink.h b/upb/sink.h
index 4e3216b..479aaff 100644
--- a/upb/sink.h
+++ b/upb/sink.h
@@ -236,7 +236,7 @@ UPB_INLINE void upb_bytessink_reset(upb_bytessink *s, const upb_byteshandler *h,
UPB_INLINE bool upb_bytessink_start(upb_bytessink *s, size_t size_hint,
void **subc) {
- *subc = NULL;
+ *subc = s->closure;
if (!s->handler) return true;
upb_startstr_handlerfunc *start =
(upb_startstr_handlerfunc *)s->handler->table[UPB_STARTSTR_SELECTOR].func;
diff --git a/upb/symtab.c b/upb/symtab.c
index 0269618..2f2b444 100644
--- a/upb/symtab.c
+++ b/upb/symtab.c
@@ -298,8 +298,13 @@ bool upb_symtab_add(upb_symtab *s, upb_def *const*defs, int n, void *ref_donor,
upb_fielddef *f = upb_msg_iter_field(&j);
const char *name = upb_fielddef_subdefname(f);
if (name && !upb_fielddef_subdef(f)) {
+ // Try the lookup in the current set of to-be-added defs first. If not
+ // there, try existing defs.
upb_def *subdef = upb_resolvename(&addtab, base, name);
if (subdef == NULL) {
+ subdef = upb_resolvename(&s->symtab, base, name);
+ }
+ if (subdef == NULL) {
upb_status_seterrf(
status, "couldn't resolve name '%s' in message '%s'", name, base);
goto err;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback