From cf1d28b473d4b735add0be405dc40676bd625da0 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Mon, 4 Dec 2017 12:44:28 -0800 Subject: Fix windows compile --- tools/codegen/core/gen_hpack_tables.c | 353 --------------------- tools/codegen/core/gen_hpack_tables.cc | 353 +++++++++++++++++++++ tools/codegen/core/gen_legal_metadata_characters.c | 66 ---- .../codegen/core/gen_legal_metadata_characters.cc | 66 ++++ tools/codegen/core/gen_percent_encoding_tables.c | 69 ---- tools/codegen/core/gen_percent_encoding_tables.cc | 69 ++++ tools/codegen/core/gen_static_metadata.py | 10 +- 7 files changed, 489 insertions(+), 497 deletions(-) delete mode 100644 tools/codegen/core/gen_hpack_tables.c create mode 100644 tools/codegen/core/gen_hpack_tables.cc delete mode 100644 tools/codegen/core/gen_legal_metadata_characters.c create mode 100644 tools/codegen/core/gen_legal_metadata_characters.cc delete mode 100644 tools/codegen/core/gen_percent_encoding_tables.c create mode 100644 tools/codegen/core/gen_percent_encoding_tables.cc (limited to 'tools/codegen') diff --git a/tools/codegen/core/gen_hpack_tables.c b/tools/codegen/core/gen_hpack_tables.c deleted file mode 100644 index 73dfa9fbd6..0000000000 --- a/tools/codegen/core/gen_hpack_tables.c +++ /dev/null @@ -1,353 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/* generates constant tables for hpack.c */ - -#include -#include -#include -#include - -#include -#include "src/core/ext/transport/chttp2/transport/huffsyms.h" - -/* - * first byte LUT generation - */ - -typedef struct { - const char *call; - /* bit prefix for the field type */ - unsigned char prefix; - /* length of the bit prefix for the field type */ - unsigned char prefix_length; - /* index value: 0 = all zeros, 2 = all ones, 1 otherwise */ - unsigned char index; -} spec; - -static const spec fields[] = { - {"INDEXED_FIELD", 0X80, 1, 1}, {"INDEXED_FIELD_X", 0X80, 1, 2}, - {"LITHDR_INCIDX", 0X40, 2, 1}, {"LITHDR_INCIDX_X", 0X40, 2, 2}, - {"LITHDR_INCIDX_V", 0X40, 2, 0}, {"LITHDR_NOTIDX", 0X00, 4, 1}, - {"LITHDR_NOTIDX_X", 0X00, 4, 2}, {"LITHDR_NOTIDX_V", 0X00, 4, 0}, - {"LITHDR_NVRIDX", 0X10, 4, 1}, {"LITHDR_NVRIDX_X", 0X10, 4, 2}, - {"LITHDR_NVRIDX_V", 0X10, 4, 0}, {"MAX_TBL_SIZE", 0X20, 3, 1}, - {"MAX_TBL_SIZE_X", 0X20, 3, 2}, -}; - -static const int num_fields = sizeof(fields) / sizeof(*fields); - -static unsigned char prefix_mask(unsigned char prefix_len) { - unsigned char i; - unsigned char out = 0; - for (i = 0; i < prefix_len; i++) { - /* NB: the following integer arithmetic operation needs to be in its - * expanded form due to the "integral promotion" performed (see section - * 3.2.1.1 of the C89 draft standard). A cast to the smaller container type - * is then required to avoid the compiler warning */ - out = (unsigned char)(out | (unsigned char)(1 << (7 - i))); - } - return out; -} - -static unsigned char suffix_mask(unsigned char prefix_len) { - return (unsigned char)~prefix_mask(prefix_len); -} - -static void generate_first_byte_lut(void) { - int i, j, n; - const spec *chrspec; - unsigned char suffix; - - n = printf("static CALLTYPE first_byte[256] = {"); - /* for each potential first byte of a header */ - for (i = 0; i < 256; i++) { - /* find the field type that matches it */ - chrspec = NULL; - for (j = 0; j < num_fields; j++) { - if ((prefix_mask(fields[j].prefix_length) & i) == fields[j].prefix) { - /* NB: the following integer arithmetic operation needs to be in its - * expanded form due to the "integral promotion" performed (see section - * 3.2.1.1 of the C89 draft standard). A cast to the smaller container - * type is then required to avoid the compiler warning */ - suffix = (unsigned char)(suffix_mask(fields[j].prefix_length) & - (unsigned char)i); - if (suffix == suffix_mask(fields[j].prefix_length)) { - if (fields[j].index != 2) continue; - } else if (suffix == 0) { - if (fields[j].index != 0) continue; - } else { - if (fields[j].index != 1) continue; - } - GPR_ASSERT(chrspec == NULL); - chrspec = &fields[j]; - } - } - if (chrspec) { - n += printf("%s, ", chrspec->call); - } else { - n += printf("ILLEGAL, "); - } - /* make some small effort towards readable output */ - if (n > 70) { - printf("\n "); - n = 2; - } - } - printf("};\n"); -} - -/* - * Huffman decoder table generation - */ - -#define MAXHUFFSTATES 1024 - -/* represents a set of symbols as an array of booleans indicating inclusion */ -typedef struct { char included[GRPC_CHTTP2_NUM_HUFFSYMS]; } symset; -/* represents a lookup table indexed by a nibble */ -typedef struct { unsigned values[16]; } nibblelut; - -#define NOT_SET (~(unsigned)0) - -/* returns a symset that includes all possible symbols */ -static symset symset_all(void) { - symset x; - memset(x.included, 1, sizeof(x.included)); - return x; -} - -/* returns a symset that includes no symbols */ -static symset symset_none(void) { - symset x; - memset(x.included, 0, sizeof(x.included)); - return x; -} - -/* returns an empty nibblelut */ -static nibblelut nibblelut_empty(void) { - nibblelut x; - int i; - for (i = 0; i < 16; i++) { - x.values[i] = NOT_SET; - } - return x; -} - -/* counts symbols in a symset - only used for debug builds */ -#ifndef NDEBUG -static int nsyms(symset s) { - int i; - int c = 0; - for (i = 0; i < GRPC_CHTTP2_NUM_HUFFSYMS; i++) { - c += s.included[i] != 0; - } - return c; -} -#endif - -/* global table of discovered huffman decoding states */ -static struct { - /* the bit offset that this state starts at */ - unsigned bitofs; - /* the set of symbols that this state started with */ - symset syms; - - /* lookup table for the next state */ - nibblelut next; - /* lookup table for what to emit */ - nibblelut emit; -} huffstates[MAXHUFFSTATES]; -static unsigned nhuffstates = 0; - -/* given a number of decoded bits and a set of symbols that are live, - return the index into the decoder table for this state. - set isnew to 1 if this state was previously undiscovered */ -static unsigned state_index(unsigned bitofs, symset syms, unsigned *isnew) { - unsigned i; - for (i = 0; i < nhuffstates; i++) { - if (huffstates[i].bitofs != bitofs) continue; - if (0 != memcmp(huffstates[i].syms.included, syms.included, - GRPC_CHTTP2_NUM_HUFFSYMS)) - continue; - *isnew = 0; - return i; - } - GPR_ASSERT(nhuffstates != MAXHUFFSTATES); - - i = nhuffstates; - nhuffstates++; - - huffstates[i].bitofs = bitofs; - huffstates[i].syms = syms; - huffstates[i].next = nibblelut_empty(); - huffstates[i].emit = nibblelut_empty(); - *isnew = 1; - return i; -} - -/* recursively build a decoding table - - state - the huffman state that we are trying to fill in - nibble - the current nibble - nibbits - the number of bits in the nibble that have been filled in - bitofs - the number of bits of symbol that have been decoded - emit - the symbol to emit on this nibble (or -1 if no symbol has been - found) - syms - the set of symbols that could be matched */ -static void build_dec_tbl(unsigned state, unsigned nibble, int nibbits, - unsigned bitofs, unsigned emit, symset syms) { - unsigned i; - unsigned bit; - - /* If we have four bits in the nibble we're looking at, then we can fill in - a slot in the lookup tables. */ - if (nibbits == 4) { - unsigned isnew; - /* Find the state that we are in: this may be a new state, in which case - we recurse to fill it in, or we may have already seen this state, in - which case the recursion terminates */ - unsigned st = state_index(bitofs, syms, &isnew); - GPR_ASSERT(huffstates[state].next.values[nibble] == NOT_SET); - huffstates[state].next.values[nibble] = st; - huffstates[state].emit.values[nibble] = emit; - if (isnew) { - build_dec_tbl(st, 0, 0, bitofs, NOT_SET, syms); - } - return; - } - - assert(nsyms(syms)); - - /* A bit can be 0 or 1 */ - for (bit = 0; bit < 2; bit++) { - /* walk over active symbols and see if they have this bit set */ - symset nextsyms = symset_none(); - for (i = 0; i < GRPC_CHTTP2_NUM_HUFFSYMS; i++) { - if (!syms.included[i]) continue; /* disregard inactive symbols */ - if (((grpc_chttp2_huffsyms[i].bits >> - (grpc_chttp2_huffsyms[i].length - bitofs - 1)) & - 1) == bit) { - /* the bit is set, include it in the next recursive set */ - if (grpc_chttp2_huffsyms[i].length == bitofs + 1) { - /* additionally, we've gotten to the end of a symbol - this is a - special recursion step: re-activate all the symbols, reset - bitofs to zero, and recurse */ - build_dec_tbl(state, (nibble << 1) | bit, nibbits + 1, 0, i, - symset_all()); - /* skip the remainder of this loop */ - goto next; - } - nextsyms.included[i] = 1; - } - } - /* recurse down for this bit */ - build_dec_tbl(state, (nibble << 1) | bit, nibbits + 1, bitofs + 1, emit, - nextsyms); - next:; - } -} - -static nibblelut ctbl[MAXHUFFSTATES]; -static int nctbl; - -static int ctbl_idx(nibblelut x) { - int i; - for (i = 0; i < nctbl; i++) { - if (0 == memcmp(&x, ctbl + i, sizeof(nibblelut))) return i; - } - ctbl[i] = x; - nctbl++; - return i; -} - -static void dump_ctbl(const char *name) { - int i, j; - printf("static const gpr_int16 %s[%d*16] = {\n", name, nctbl); - for (i = 0; i < nctbl; i++) { - for (j = 0; j < 16; j++) { - printf("%d,", ctbl[i].values[j]); - } - printf("\n"); - } - printf("};\n"); -} - -static void generate_huff_tables(void) { - unsigned i; - build_dec_tbl(state_index(0, symset_all(), &i), 0, 0, 0, NOT_SET, - symset_all()); - - nctbl = 0; - printf("static const gpr_uint8 next_tbl[%d] = {", nhuffstates); - for (i = 0; i < nhuffstates; i++) { - printf("%d,", ctbl_idx(huffstates[i].next)); - } - printf("};\n"); - dump_ctbl("next_sub_tbl"); - - nctbl = 0; - printf("static const gpr_uint16 emit_tbl[%d] = {", nhuffstates); - for (i = 0; i < nhuffstates; i++) { - printf("%d,", ctbl_idx(huffstates[i].emit)); - } - printf("};\n"); - dump_ctbl("emit_sub_tbl"); -} - -static void generate_base64_huff_encoder_table(void) { - static const char alphabet[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - int i; - - printf( - "static const struct { gpr_uint16 bits, gpr_uint8 length } " - "base64_syms[64] = {\n"); - for (i = 0; i < 64; i++) { - printf("{0x%x, %d},", grpc_chttp2_huffsyms[(unsigned char)alphabet[i]].bits, - grpc_chttp2_huffsyms[(unsigned char)alphabet[i]].length); - } - printf("};\n"); -} - -static void generate_base64_inverse_table(void) { - static const char alphabet[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; - unsigned char inverse[256]; - unsigned i; - - memset(inverse, 255, sizeof(inverse)); - for (i = 0; i < strlen(alphabet); i++) { - inverse[(unsigned char)alphabet[i]] = (unsigned char)i; - } - - printf("static const gpr_uint8 inverse_base64[256] = {"); - for (i = 0; i < 256; i++) { - printf("%d,", inverse[i]); - } - printf("};\n"); -} - -int main(void) { - generate_huff_tables(); - generate_first_byte_lut(); - generate_base64_huff_encoder_table(); - generate_base64_inverse_table(); - - return 0; -} diff --git a/tools/codegen/core/gen_hpack_tables.cc b/tools/codegen/core/gen_hpack_tables.cc new file mode 100644 index 0000000000..0e7a7b80d8 --- /dev/null +++ b/tools/codegen/core/gen_hpack_tables.cc @@ -0,0 +1,353 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* generates constant tables for hpack.cc */ + +#include +#include +#include +#include + +#include +#include "src/core/ext/transport/chttp2/transport/huffsyms.h" + +/* + * first byte LUT generation + */ + +typedef struct { + const char *call; + /* bit prefix for the field type */ + unsigned char prefix; + /* length of the bit prefix for the field type */ + unsigned char prefix_length; + /* index value: 0 = all zeros, 2 = all ones, 1 otherwise */ + unsigned char index; +} spec; + +static const spec fields[] = { + {"INDEXED_FIELD", 0X80, 1, 1}, {"INDEXED_FIELD_X", 0X80, 1, 2}, + {"LITHDR_INCIDX", 0X40, 2, 1}, {"LITHDR_INCIDX_X", 0X40, 2, 2}, + {"LITHDR_INCIDX_V", 0X40, 2, 0}, {"LITHDR_NOTIDX", 0X00, 4, 1}, + {"LITHDR_NOTIDX_X", 0X00, 4, 2}, {"LITHDR_NOTIDX_V", 0X00, 4, 0}, + {"LITHDR_NVRIDX", 0X10, 4, 1}, {"LITHDR_NVRIDX_X", 0X10, 4, 2}, + {"LITHDR_NVRIDX_V", 0X10, 4, 0}, {"MAX_TBL_SIZE", 0X20, 3, 1}, + {"MAX_TBL_SIZE_X", 0X20, 3, 2}, +}; + +static const int num_fields = sizeof(fields) / sizeof(*fields); + +static unsigned char prefix_mask(unsigned char prefix_len) { + unsigned char i; + unsigned char out = 0; + for (i = 0; i < prefix_len; i++) { + /* NB: the following integer arithmetic operation needs to be in its + * expanded form due to the "integral promotion" performed (see section + * 3.2.1.1 of the C89 draft standard). A cast to the smaller container type + * is then required to avoid the compiler warning */ + out = (unsigned char)(out | (unsigned char)(1 << (7 - i))); + } + return out; +} + +static unsigned char suffix_mask(unsigned char prefix_len) { + return (unsigned char)~prefix_mask(prefix_len); +} + +static void generate_first_byte_lut(void) { + int i, j, n; + const spec *chrspec; + unsigned char suffix; + + n = printf("static CALLTYPE first_byte[256] = {"); + /* for each potential first byte of a header */ + for (i = 0; i < 256; i++) { + /* find the field type that matches it */ + chrspec = NULL; + for (j = 0; j < num_fields; j++) { + if ((prefix_mask(fields[j].prefix_length) & i) == fields[j].prefix) { + /* NB: the following integer arithmetic operation needs to be in its + * expanded form due to the "integral promotion" performed (see section + * 3.2.1.1 of the C89 draft standard). A cast to the smaller container + * type is then required to avoid the compiler warning */ + suffix = (unsigned char)(suffix_mask(fields[j].prefix_length) & + (unsigned char)i); + if (suffix == suffix_mask(fields[j].prefix_length)) { + if (fields[j].index != 2) continue; + } else if (suffix == 0) { + if (fields[j].index != 0) continue; + } else { + if (fields[j].index != 1) continue; + } + GPR_ASSERT(chrspec == NULL); + chrspec = &fields[j]; + } + } + if (chrspec) { + n += printf("%s, ", chrspec->call); + } else { + n += printf("ILLEGAL, "); + } + /* make some small effort towards readable output */ + if (n > 70) { + printf("\n "); + n = 2; + } + } + printf("};\n"); +} + +/* + * Huffman decoder table generation + */ + +#define MAXHUFFSTATES 1024 + +/* represents a set of symbols as an array of booleans indicating inclusion */ +typedef struct { char included[GRPC_CHTTP2_NUM_HUFFSYMS]; } symset; +/* represents a lookup table indexed by a nibble */ +typedef struct { unsigned values[16]; } nibblelut; + +#define NOT_SET (~(unsigned)0) + +/* returns a symset that includes all possible symbols */ +static symset symset_all(void) { + symset x; + memset(x.included, 1, sizeof(x.included)); + return x; +} + +/* returns a symset that includes no symbols */ +static symset symset_none(void) { + symset x; + memset(x.included, 0, sizeof(x.included)); + return x; +} + +/* returns an empty nibblelut */ +static nibblelut nibblelut_empty(void) { + nibblelut x; + int i; + for (i = 0; i < 16; i++) { + x.values[i] = NOT_SET; + } + return x; +} + +/* counts symbols in a symset - only used for debug builds */ +#ifndef NDEBUG +static int nsyms(symset s) { + int i; + int c = 0; + for (i = 0; i < GRPC_CHTTP2_NUM_HUFFSYMS; i++) { + c += s.included[i] != 0; + } + return c; +} +#endif + +/* global table of discovered huffman decoding states */ +static struct { + /* the bit offset that this state starts at */ + unsigned bitofs; + /* the set of symbols that this state started with */ + symset syms; + + /* lookup table for the next state */ + nibblelut next; + /* lookup table for what to emit */ + nibblelut emit; +} huffstates[MAXHUFFSTATES]; +static unsigned nhuffstates = 0; + +/* given a number of decoded bits and a set of symbols that are live, + return the index into the decoder table for this state. + set isnew to 1 if this state was previously undiscovered */ +static unsigned state_index(unsigned bitofs, symset syms, unsigned *isnew) { + unsigned i; + for (i = 0; i < nhuffstates; i++) { + if (huffstates[i].bitofs != bitofs) continue; + if (0 != memcmp(huffstates[i].syms.included, syms.included, + GRPC_CHTTP2_NUM_HUFFSYMS)) + continue; + *isnew = 0; + return i; + } + GPR_ASSERT(nhuffstates != MAXHUFFSTATES); + + i = nhuffstates; + nhuffstates++; + + huffstates[i].bitofs = bitofs; + huffstates[i].syms = syms; + huffstates[i].next = nibblelut_empty(); + huffstates[i].emit = nibblelut_empty(); + *isnew = 1; + return i; +} + +/* recursively build a decoding table + + state - the huffman state that we are trying to fill in + nibble - the current nibble + nibbits - the number of bits in the nibble that have been filled in + bitofs - the number of bits of symbol that have been decoded + emit - the symbol to emit on this nibble (or -1 if no symbol has been + found) + syms - the set of symbols that could be matched */ +static void build_dec_tbl(unsigned state, unsigned nibble, int nibbits, + unsigned bitofs, unsigned emit, symset syms) { + unsigned i; + unsigned bit; + + /* If we have four bits in the nibble we're looking at, then we can fill in + a slot in the lookup tables. */ + if (nibbits == 4) { + unsigned isnew; + /* Find the state that we are in: this may be a new state, in which case + we recurse to fill it in, or we may have already seen this state, in + which case the recursion terminates */ + unsigned st = state_index(bitofs, syms, &isnew); + GPR_ASSERT(huffstates[state].next.values[nibble] == NOT_SET); + huffstates[state].next.values[nibble] = st; + huffstates[state].emit.values[nibble] = emit; + if (isnew) { + build_dec_tbl(st, 0, 0, bitofs, NOT_SET, syms); + } + return; + } + + assert(nsyms(syms)); + + /* A bit can be 0 or 1 */ + for (bit = 0; bit < 2; bit++) { + /* walk over active symbols and see if they have this bit set */ + symset nextsyms = symset_none(); + for (i = 0; i < GRPC_CHTTP2_NUM_HUFFSYMS; i++) { + if (!syms.included[i]) continue; /* disregard inactive symbols */ + if (((grpc_chttp2_huffsyms[i].bits >> + (grpc_chttp2_huffsyms[i].length - bitofs - 1)) & + 1) == bit) { + /* the bit is set, include it in the next recursive set */ + if (grpc_chttp2_huffsyms[i].length == bitofs + 1) { + /* additionally, we've gotten to the end of a symbol - this is a + special recursion step: re-activate all the symbols, reset + bitofs to zero, and recurse */ + build_dec_tbl(state, (nibble << 1) | bit, nibbits + 1, 0, i, + symset_all()); + /* skip the remainder of this loop */ + goto next; + } + nextsyms.included[i] = 1; + } + } + /* recurse down for this bit */ + build_dec_tbl(state, (nibble << 1) | bit, nibbits + 1, bitofs + 1, emit, + nextsyms); + next:; + } +} + +static nibblelut ctbl[MAXHUFFSTATES]; +static int nctbl; + +static int ctbl_idx(nibblelut x) { + int i; + for (i = 0; i < nctbl; i++) { + if (0 == memcmp(&x, ctbl + i, sizeof(nibblelut))) return i; + } + ctbl[i] = x; + nctbl++; + return i; +} + +static void dump_ctbl(const char *name) { + int i, j; + printf("static const gpr_int16 %s[%d*16] = {\n", name, nctbl); + for (i = 0; i < nctbl; i++) { + for (j = 0; j < 16; j++) { + printf("%d,", ctbl[i].values[j]); + } + printf("\n"); + } + printf("};\n"); +} + +static void generate_huff_tables(void) { + unsigned i; + build_dec_tbl(state_index(0, symset_all(), &i), 0, 0, 0, NOT_SET, + symset_all()); + + nctbl = 0; + printf("static const gpr_uint8 next_tbl[%d] = {", nhuffstates); + for (i = 0; i < nhuffstates; i++) { + printf("%d,", ctbl_idx(huffstates[i].next)); + } + printf("};\n"); + dump_ctbl("next_sub_tbl"); + + nctbl = 0; + printf("static const gpr_uint16 emit_tbl[%d] = {", nhuffstates); + for (i = 0; i < nhuffstates; i++) { + printf("%d,", ctbl_idx(huffstates[i].emit)); + } + printf("};\n"); + dump_ctbl("emit_sub_tbl"); +} + +static void generate_base64_huff_encoder_table(void) { + static const char alphabet[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + int i; + + printf( + "static const struct { gpr_uint16 bits, gpr_uint8 length } " + "base64_syms[64] = {\n"); + for (i = 0; i < 64; i++) { + printf("{0x%x, %d},", grpc_chttp2_huffsyms[(unsigned char)alphabet[i]].bits, + grpc_chttp2_huffsyms[(unsigned char)alphabet[i]].length); + } + printf("};\n"); +} + +static void generate_base64_inverse_table(void) { + static const char alphabet[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + unsigned char inverse[256]; + unsigned i; + + memset(inverse, 255, sizeof(inverse)); + for (i = 0; i < strlen(alphabet); i++) { + inverse[(unsigned char)alphabet[i]] = (unsigned char)i; + } + + printf("static const gpr_uint8 inverse_base64[256] = {"); + for (i = 0; i < 256; i++) { + printf("%d,", inverse[i]); + } + printf("};\n"); +} + +int main(void) { + generate_huff_tables(); + generate_first_byte_lut(); + generate_base64_huff_encoder_table(); + generate_base64_inverse_table(); + + return 0; +} diff --git a/tools/codegen/core/gen_legal_metadata_characters.c b/tools/codegen/core/gen_legal_metadata_characters.c deleted file mode 100644 index 5e292abb3b..0000000000 --- a/tools/codegen/core/gen_legal_metadata_characters.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/* generates constant table for metadata.c */ - -#include -#include - -static unsigned char legal_bits[256 / 8]; - -static void legal(int x) { - int byte = x / 8; - int bit = x % 8; - /* NB: the following integer arithmetic operation needs to be in its - * expanded form due to the "integral promotion" performed (see section - * 3.2.1.1 of the C89 draft standard). A cast to the smaller container type - * is then required to avoid the compiler warning */ - legal_bits[byte] = - (unsigned char)((legal_bits[byte] | (unsigned char)(1 << bit))); -} - -static void dump(void) { - int i; - - printf("static const uint8_t legal_header_bits[256/8] = "); - for (i = 0; i < 256 / 8; i++) - printf("%c 0x%02x", i ? ',' : '{', legal_bits[i]); - printf(" };\n"); -} - -static void clear(void) { memset(legal_bits, 0, sizeof(legal_bits)); } - -int main(void) { - int i; - - clear(); - for (i = 'a'; i <= 'z'; i++) legal(i); - for (i = '0'; i <= '9'; i++) legal(i); - legal('-'); - legal('_'); - legal('.'); - dump(); - - clear(); - for (i = 32; i <= 126; i++) { - legal(i); - } - dump(); - - return 0; -} diff --git a/tools/codegen/core/gen_legal_metadata_characters.cc b/tools/codegen/core/gen_legal_metadata_characters.cc new file mode 100644 index 0000000000..fbabd2464f --- /dev/null +++ b/tools/codegen/core/gen_legal_metadata_characters.cc @@ -0,0 +1,66 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* generates constant table for metadata.cc */ + +#include +#include + +static unsigned char legal_bits[256 / 8]; + +static void legal(int x) { + int byte = x / 8; + int bit = x % 8; + /* NB: the following integer arithmetic operation needs to be in its + * expanded form due to the "integral promotion" performed (see section + * 3.2.1.1 of the C89 draft standard). A cast to the smaller container type + * is then required to avoid the compiler warning */ + legal_bits[byte] = + (unsigned char)((legal_bits[byte] | (unsigned char)(1 << bit))); +} + +static void dump(void) { + int i; + + printf("static const uint8_t legal_header_bits[256/8] = "); + for (i = 0; i < 256 / 8; i++) + printf("%c 0x%02x", i ? ',' : '{', legal_bits[i]); + printf(" };\n"); +} + +static void clear(void) { memset(legal_bits, 0, sizeof(legal_bits)); } + +int main(void) { + int i; + + clear(); + for (i = 'a'; i <= 'z'; i++) legal(i); + for (i = '0'; i <= '9'; i++) legal(i); + legal('-'); + legal('_'); + legal('.'); + dump(); + + clear(); + for (i = 32; i <= 126; i++) { + legal(i); + } + dump(); + + return 0; +} diff --git a/tools/codegen/core/gen_percent_encoding_tables.c b/tools/codegen/core/gen_percent_encoding_tables.c deleted file mode 100644 index 49ea5ea53b..0000000000 --- a/tools/codegen/core/gen_percent_encoding_tables.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/* generates constant table for metadata.c */ - -#include -#include - -static unsigned char legal_bits[256 / 8]; - -static void legal(int x) { - int byte = x / 8; - int bit = x % 8; - /* NB: the following integer arithmetic operation needs to be in its - * expanded form due to the "integral promotion" performed (see section - * 3.2.1.1 of the C89 draft standard). A cast to the smaller container type - * is then required to avoid the compiler warning */ - legal_bits[byte] = - (unsigned char)((legal_bits[byte] | (unsigned char)(1 << bit))); -} - -static void dump(const char *name) { - int i; - - printf("const uint8_t %s[256/8] = ", name); - for (i = 0; i < 256 / 8; i++) - printf("%c 0x%02x", i ? ',' : '{', legal_bits[i]); - printf(" };\n"); -} - -static void clear(void) { memset(legal_bits, 0, sizeof(legal_bits)); } - -int main(void) { - int i; - - clear(); - for (i = 'a'; i <= 'z'; i++) legal(i); - for (i = 'A'; i <= 'Z'; i++) legal(i); - for (i = '0'; i <= '9'; i++) legal(i); - legal('-'); - legal('_'); - legal('.'); - legal('~'); - dump("grpc_url_percent_encoding_unreserved_bytes"); - - clear(); - for (i = 32; i <= 126; i++) { - if (i == '%') continue; - legal(i); - } - dump("grpc_compatible_percent_encoding_unreserved_bytes"); - - return 0; -} diff --git a/tools/codegen/core/gen_percent_encoding_tables.cc b/tools/codegen/core/gen_percent_encoding_tables.cc new file mode 100644 index 0000000000..a99024e5ed --- /dev/null +++ b/tools/codegen/core/gen_percent_encoding_tables.cc @@ -0,0 +1,69 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* generates constant table for metadata.cc */ + +#include +#include + +static unsigned char legal_bits[256 / 8]; + +static void legal(int x) { + int byte = x / 8; + int bit = x % 8; + /* NB: the following integer arithmetic operation needs to be in its + * expanded form due to the "integral promotion" performed (see section + * 3.2.1.1 of the C89 draft standard). A cast to the smaller container type + * is then required to avoid the compiler warning */ + legal_bits[byte] = + (unsigned char)((legal_bits[byte] | (unsigned char)(1 << bit))); +} + +static void dump(const char *name) { + int i; + + printf("const uint8_t %s[256/8] = ", name); + for (i = 0; i < 256 / 8; i++) + printf("%c 0x%02x", i ? ',' : '{', legal_bits[i]); + printf(" };\n"); +} + +static void clear(void) { memset(legal_bits, 0, sizeof(legal_bits)); } + +int main(void) { + int i; + + clear(); + for (i = 'a'; i <= 'z'; i++) legal(i); + for (i = 'A'; i <= 'Z'; i++) legal(i); + for (i = '0'; i <= '9'; i++) legal(i); + legal('-'); + legal('_'); + legal('.'); + legal('~'); + dump("grpc_url_percent_encoding_unreserved_bytes"); + + clear(); + for (i = 32; i <= 126; i++) { + if (i == '%') continue; + legal(i); + } + dump("grpc_compatible_percent_encoding_unreserved_bytes"); + + return 0; +} diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index c73cdc0816..9d99bbf096 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -348,17 +348,13 @@ put_banner([H, C], """WARNING: Auto-generated code. To make changes to this file, change tools/codegen/core/gen_static_metadata.py, and then re-run it. -See metadata.h for an explanation of the interface here, and metadata.c for +See metadata.h for an explanation of the interface here, and metadata.cc for an explanation of what's going on. """.splitlines()) print >> H, '#ifndef GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H' print >> H, '#define GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H' print >> H -print >> H, '#ifdef __cplusplus' -print >> H, 'extern "C" {' -print >> H, '#endif' -print >> H print >> H, '#include "src/core/lib/transport/metadata.h"' print >> H @@ -589,10 +585,6 @@ print >> C, '};' print >> H, '#define GRPC_MDELEM_ACCEPT_STREAM_ENCODING_FOR_ALGORITHMS(algs) (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[grpc_static_accept_stream_encoding_metadata[(algs)]], GRPC_MDELEM_STORAGE_STATIC))' -print >> H, '#ifdef __cplusplus' -print >> H, '}' -print >> H, '#endif' - print >> H, '#endif /* GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H */' H.close() -- cgit v1.2.3