Skip to content

Commit

Permalink
Compact operator dictionary: make the script generate a C++ example.
Browse files Browse the repository at this point in the history
  • Loading branch information
fred-wang committed Jan 27, 2022
1 parent 6b66e9e commit a80a3ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ unicode.xml
*.aux
*.dvi
wpt-tests-generator.py
tables/operator-dictionary-compact.cpp
28 changes: 24 additions & 4 deletions tables/operator-dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,27 @@ def cmp_key(x):
txt.close()
print("done.");

# Dump compact dictionary for C++-like table.
#for r in compact_table:
# print('{0x%04X, %d}, ' % (r[0], r[1] - r[0]), end="")
#print()
# Generate C++-like tables.
print("Generating operator-dictionary-compact.cpp... ", end="")
cpp = open("operator-dictionary-compact.cpp", "w")
cpp.write("\
struct EntryRange {\n\
uint16_t entry;\n\
unsigned range_bounds_delta : 4;\n\
};\n\
static inline uint16_t ExtractKey(const EntryRange& range) {\n\
return range.entry & 0x3FFF;\n\
}\n\
static inline uint16_t ExtractCategory(const EntryRange& range) {\n\
return range.entry >> 12;\n\
}\n");
cpp.write("static const EntryRange compact_dictionary[] = {")
for i in range(0, len(compact_table)):
if i > 0:
cpp.write(', ')
r = compact_table[i]
cpp.write('\n {0x%04X, %d}' % (r[0], r[1] - r[0]))
cpp.write("\n};")
cpp.close()

print("done.")

0 comments on commit a80a3ca

Please sign in to comment.