Changeset 4428


Ignore:
Timestamp:
Jan 19, 2015, 8:43:56 PM (4 years ago)
Author:
cameron
Message:

Generator support for precompiled property cpp files

Location:
proto/charsetcompiler
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • proto/charsetcompiler/Makefile

    r4423 r4428  
    11OUTFILE=src/unicode_categories.h
     2
    23PABLO_SRC=cat.pablo
    34PABLO_TEMPLATE=category_template.h
     
    1617
    1718gc:
    18         python $(PABLO_COMPILER) DerivedGeneralCategory.pablo -Z -t ucd_precompiled_gc.h -o src/precompiled_gc.h
     19        python $(PABLO_COMPILER) DerivedGeneralCategory.pablo -Z -t precompiled_gc.cpp -o src/precompiled_gc.cpp
    1920
    2021sc:
    21         python $(PABLO_COMPILER) Scripts.pablo -Z -t ucd_precompiled_sc.h -o src/precompiled_sc.h
     22        python $(PABLO_COMPILER) Scripts.pablo -Z -t precompiled_sc.cpp -o src/precompiled_sc.cpp
    2223
    2324scx:
    24         python $(PABLO_COMPILER) ScriptExtensions.pablo -Z -t ucd_precompiled_scx.h -o src/precompiled_scx.h
     25        python $(PABLO_COMPILER) ScriptExtensions.pablo -Z -t precompiled_scx.cpp -o src/precompiled_scx.cpp
    2526
    2627blk:
    27         python $(PABLO_COMPILER) Blocks.pablo -Z -t ucd_precompiled_blk.h -o src/precompiled_blk.h
     28        python $(PABLO_COMPILER) Blocks.pablo -Z -t precompiled_blk.cpp -o src/precompiled_blk.cpp
    2829
    2930core:
    30         python $(PABLO_COMPILER) DerivedCoreProperties.pablo -Z -t ucd_precompiled_derivedcoreproperties.h -o src/precompiled_derivedcoreproperties.h
     31        python $(PABLO_COMPILER) DerivedCoreProperties.pablo -Z -t precompiled_derivedcoreproperties.cpp -o src/precompiled_derivedcoreproperties.cpp
    3132
    3233proplist:
    33         python $(PABLO_COMPILER) PropList.pablo -Z -t ucd_precompiled_proplist.h -o src/precompiled_proplist.h
     34        python $(PABLO_COMPILER) PropList.pablo -Z -t precompiled_proplist.cpp -o src/precompiled_proplist.cpp
     35
  • proto/charsetcompiler/UCD/cformat.py

    r4389 r4428  
    1212"""
    1313
     14cpp_template = r"""
     15/*
     16 *  Copyright (c) 2015 International Characters, Inc.
     17 *  This software is licensed to the public under the Open Software License 3.0.
     18 *  icgrep is a trademark of International Characters, Inc.
     19 *
     20 *  This file is generated by %s - manual edits may be lost.
     21 */
     22
     23#include "%s.h"
     24"""
     25
     26
     27
    1428def open_header_file_for_write(filename, generator_name='UCD_properties.py'):
    1529   f = open(filename + '.h', 'w')
     
    1832   return f
    1933
     34def open_cpp_file_for_write(filename, generator_name='UCD_properties.py'):
     35   f = open(filename + '.cpp', 'w')
     36   f.write(cpp_template % (generator_name, filename))
     37   return f
     38
    2039def close_header_file(f):
    2140   f.write("\n#endif\n")
     41   f.close()
     42
     43def close_cpp_file(f):
    2244   f.close()
    2345
  • proto/charsetcompiler/generate_UCD_property_functions.py

    r4424 r4428  
    4848Unicode_template_var = Template("struct_${property}_%s.cc")
    4949
     50install_fn_header = r"""
     51void install_property_%s_fn_ptrs(pablo::PabloCompiler & p);
     52"""
    5053install_fn = r"""
    5154void install_property_%s_fn_ptrs(pablo::PabloCompiler & p) {
     
    6467        (self.property_value_list, self.property_value_enum_integer, self.property_value_full_name_map, self.property_value_lookup_map, self.missing_specs) = parse_PropertyValueAlias_txt(self.property_lookup_map)
    6568
    66     def generate_enumerated_property_template(self, filename_root, property_code):
    67         f = cformat.open_header_file_for_write(os.path.basename("ucd_precompiled_%s" % property_code), 'generate_UCD_property_functions.py')
    68         cformat.write_imports(f, ['"pablo/pablo_compiler.h"'])
    69         f.write(Unicode_pablo_template)
     69    def generate_enumerated_property_header_and_template(self, filename_root, property_code):
     70        hf = cformat.open_header_file_for_write(os.path.basename("precompiled_%s" % property_code), 'generate_UCD_property_functions.py')
     71        cformat.write_imports(hf, ['"pablo/pablo_compiler.h"'])
    7072        pc = property_code.lower()
     73        hf.write(install_fn_header % pc)
     74        cformat.close_header_file(hf)
     75        tf = cformat.open_cpp_file_for_write(os.path.basename("precompiled_%s" % property_code), 'generate_UCD_property_functions.py')
     76        cformat.write_imports(tf, ['"icgrep.h"'])
     77        tf.write(Unicode_pablo_template)
    7178        vlist = self.property_value_list[property_code]
    7279        for v in vlist:
    73             f.write(Unicode_property_fn_template.substitute({'property': pc, 'value': v}))
     80            tf.write(Unicode_property_fn_template.substitute({'property': pc, 'value': v}))
    7481        install_stmt = "  p.InstallExternalFunction(\"__get_%s_%%s\", (void *) & __get_%s_%%s);\n" % (pc, pc)
    7582        install_list = [install_stmt % (k, k) for k in vlist]
    76         f.write(install_fn % (pc, "".join(install_list)))
    77         cformat.close_header_file(f)
    78        
     83        tf.write(install_fn % (pc, "".join(install_list)))
     84        cformat.close_cpp_file(tf)
     85
    7986    def generate_enumerated_property_file(self, filename_root, property_code):
    8087        vlist = self.property_value_list[property_code]
     
    108115        f.close()
    109116
    110     def generate_binary_property_template(self, filename_root):
     117    def generate_binary_property_header_and_template(self, filename_root):
    111118        (props, prop_map) = parse_UCD_codepoint_name_map(filename_root + '.txt', self.property_lookup_map)
    112119        lprops = [p.lower() for p in props]
    113         f = cformat.open_header_file_for_write(os.path.basename("ucd_precompiled_%s" % filename_root.lower()), 'generate_UCD_property_functions.py')
    114         cformat.write_imports(f, ['"pablo/pablo_compiler.h"'])
    115         f.write(Unicode_pablo_template)
     120        hf = cformat.open_header_file_for_write(os.path.basename("precompiled_%s" % filename_root.lower()), 'generate_UCD_property_functions.py')
     121        cformat.write_imports(hf, ['"pablo/pablo_compiler.h"'])
     122        hf.write(install_fn_header % filename_root)
     123        cformat.close_header_file(hf)
     124        tf = cformat.open_cpp_file_for_write(os.path.basename("precompiled_%s" % filename_root.lower()), 'generate_UCD_property_functions.py')
     125        cformat.write_imports(tf, ['"icgrep.h"'])
     126        tf.write(Unicode_pablo_template)
    116127        for p in lprops:
    117             f.write(Unicode_property_fn_template.substitute({'property': p, 'value': 'Y'}))
     128            tf.write(Unicode_property_fn_template.substitute({'property': p, 'value': 'Y'}))
    118129        install_stmt = "  p.InstallExternalFunction(\"__get_%s_Y\", (void *) & __get_%s_Y);\n"
    119130        install_list = [install_stmt % (p, p) for p in lprops]
    120         f.write(install_fn % (filename_root, "".join(install_list)))
    121         cformat.close_header_file(f)
     131        tf.write(install_fn % (filename_root, "".join(install_list)))
     132        cformat.close_cpp_file(tf)
    122133       
    123134    def generate_binary_properties_file(self, filename_root):
     
    145156    #
    146157    # The Block property
    147     ucd.generate_enumerated_property_template('Blocks', 'blk')
     158    ucd.generate_enumerated_property_header_and_template('Blocks', 'blk')
    148159    ucd.generate_enumerated_property_file('Blocks', 'blk')
    149160    #
    150161    # Scripts
    151     ucd.generate_enumerated_property_template('Scripts', 'sc')
     162    ucd.generate_enumerated_property_header_and_template('Scripts', 'sc')
    152163    ucd.generate_enumerated_property_file('Scripts', 'sc')
    153164    #
    154165    # Script Extensions
    155     ucd.generate_enumerated_property_template('ScriptExtensions', 'scx')
     166    ucd.generate_enumerated_property_header_and_template('ScriptExtensions', 'scx')
    156167    ucd.generate_ScriptExtensions_pablo()
    157168    #
    158169    # General Category
    159     ucd.generate_enumerated_property_template('GeneralCategory', 'gc')
     170    ucd.generate_enumerated_property_header_and_template('GeneralCategory', 'gc')
    160171    ucd.generate_enumerated_property_file('extracted/DerivedGeneralCategory', 'gc')
    161172    #
    162173    # Core Properties
    163     ucd.generate_binary_property_template('DerivedCoreProperties')
     174    ucd.generate_binary_property_header_and_template('DerivedCoreProperties')
    164175    ucd.generate_binary_properties_file('DerivedCoreProperties')
    165176    #
    166     ucd.generate_binary_property_template('PropList')
     177    ucd.generate_binary_property_header_and_template('PropList')
    167178    ucd.generate_binary_properties_file('PropList')
    168179
Note: See TracChangeset for help on using the changeset viewer.