[ucd] Print out table sizes

This commit is contained in:
Behdad Esfahbod 2019-06-19 17:34:12 -07:00
parent f4de0c7754
commit b1a2384a52
2 changed files with 19 additions and 9 deletions

View File

@ -3,19 +3,22 @@
from __future__ import print_function, division, absolute_import from __future__ import print_function, division, absolute_import
import io, os.path, sys, re import io, os.path, sys, re
import logging
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
if len (sys.argv) != 2: if len (sys.argv) != 2:
print("usage: ./gen-ucd-table ucd.nonunihan.grouped.xml", file=sys.stderr) print("usage: ./gen-ucd-table ucd.nonunihan.grouped.xml", file=sys.stderr)
sys.exit(1) sys.exit(1)
# https://github.com/harfbuzz/packtab # https://github.com/harfbuzz/packtab
import packTab import packTab
import packTab.ucdxml import packTab.ucdxml
logging.info('Loading UCDXML...')
ucdxml = packTab.ucdxml.load_ucdxml(sys.argv[1]) ucdxml = packTab.ucdxml.load_ucdxml(sys.argv[1])
ucd = packTab.ucdxml.ucdxml_get_repertoire(ucdxml) ucd = packTab.ucdxml.ucdxml_get_repertoire(ucdxml)
logging.info('Preparing data tables...')
gc = [u['gc'] for u in ucd] gc = [u['gc'] for u in ucd]
ccc = [int(u['ccc']) for u in ucd] ccc = [int(u['ccc']) for u in ucd]
@ -71,6 +74,7 @@ DEFAULT = 1
COMPACT = 3 COMPACT = 3
logging.info('Generating output...')
print("/* == Start of generated table == */") print("/* == Start of generated table == */")
print("/*") print("/*")
print(" * The following table is generated by running:") print(" * The following table is generated by running:")
@ -82,8 +86,6 @@ print(" */")
print() print()
print("#ifndef HB_UCD_TABLE_HH") print("#ifndef HB_UCD_TABLE_HH")
print("#define HB_UCD_TABLE_HH") print("#define HB_UCD_TABLE_HH")
print()
print() print()
print('#include "hb.hh"') print('#include "hb.hh"')
print() print()
@ -95,7 +97,16 @@ dm1_32_array, _ = code.addArray('uint32_t', 'dm1_u32_map', dm1_u32_array)
dm2_array, _ = code.addArray('uint64_t', 'dm2_map', dm2_array) dm2_array, _ = code.addArray('uint64_t', 'dm2_map', dm2_array)
code.print_c(linkage='static inline') code.print_c(linkage='static inline')
datasets = [
('gc', gc, 'Cn', gc_order),
('ccc', ccc, 0, None),
('bmg', bmg, 0, None),
('sc', sc, 'Zzzz', sc_order),
('dm', dm, None, dm_order),
]
for compression in (DEFAULT, COMPACT): for compression in (DEFAULT, COMPACT):
logging.info(' Compression=%d:' % compression)
print() print()
if compression == DEFAULT: if compression == DEFAULT:
print('#ifndef HB_OPTIMIZE_SIZE') print('#ifndef HB_OPTIMIZE_SIZE')
@ -105,11 +116,10 @@ for compression in (DEFAULT, COMPACT):
code = packTab.Code('_hb_ucd') code = packTab.Code('_hb_ucd')
packTab.pack_table(gc, 'Cn', mapping=gc_order, compression=compression).genCode(code, 'gc') for name,data,default,mapping in datasets:
packTab.pack_table(ccc, 0, compression=compression).genCode(code, 'ccc') sol = packTab.pack_table(data, default, mapping=mapping, compression=compression)
packTab.pack_table(bmg, 0, compression=compression).genCode(code, 'bmg') logging.info(' Dataset=%-8s FullCost=%d' % (name, sol.fullCost))
packTab.pack_table(sc, 'Zzzz', mapping=sc_order, compression=compression).genCode(code, 'sc') sol.genCode(code, name)
packTab.pack_table(dm, None, mapping=dm_order, compression=compression).genCode(code, 'dm')
code.print_c(linkage='static inline') code.print_c(linkage='static inline')
@ -123,3 +133,4 @@ print()
print("#endif /* HB_UCD_TABLE_HH */") print("#endif /* HB_UCD_TABLE_HH */")
print() print()
print("/* == End of generated table == */") print("/* == End of generated table == */")
logging.info('Done.')

View File

@ -10,7 +10,6 @@
#ifndef HB_UCD_TABLE_HH #ifndef HB_UCD_TABLE_HH
#define HB_UCD_TABLE_HH #define HB_UCD_TABLE_HH
#include "hb.hh" #include "hb.hh"
static const hb_script_t static const hb_script_t