Ignore:
Timestamp:
Jul 14, 2015, 10:46:10 PM (4 years ago)
Author:
nmedfort
Message:

Moved responsibility of handling 'special cases of Unicode TR #18' and 'compatibility properties of UTR #18 Annex C' into RE_Parser.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/generate_predefined_ucd_functions.cpp

    r4669 r4671  
    5959#endif
    6060
     61using property_list = std::vector<std::pair<std::string, size_t>>;
     62
    6163/** ------------------------------------------------------------------------------------------------------------- *
    6264 * @brief compileUnicodeSet
    6365 ** ------------------------------------------------------------------------------------------------------------- */
    64 void compileUnicodeSet(std::string name, const UnicodeSet & set, PabloCompiler & pc, Module * module, raw_ostream & out) {
     66size_t compileUnicodeSet(std::string name, const UnicodeSet & set, PabloCompiler & pc, Module * module) {
    6567    PabloFunction function = PabloFunction::Create(std::move(name));
    6668    Encoding encoding(Encoding::Type::UTF_8, 8);
     
    8082    // Now compile the function ...
    8183    auto func = pc.compile(function, module);
    82     out << "    p.InstallExternalFunction(\"" + name + "\", &" + name + ", " + std::to_string(func.second) + ");\n";
    8384    releaseSlabAllocatorMemory();
    84 }
    85 
    86 /** ------------------------------------------------------------------------------------------------------------- *
    87  * @brief generateUCDModule
    88  ** ------------------------------------------------------------------------------------------------------------- */
    89 Module * generateUCDModule() {
     85
     86    return func.second;
     87}
     88
     89/** ------------------------------------------------------------------------------------------------------------- *
     90 * @brief writePropertyInstaller
     91 ** ------------------------------------------------------------------------------------------------------------- */
     92
     93void writePropertyInstaller(property_list && properties) {
    9094
    9195    #ifdef USE_LLVM_3_5
     
    105109    out << "#ifndef PROPERTYINSTALL\n";
    106110    out << "#define PROPERTYINSTALL\n\n";
     111    out << "#include <include/simd-lib/bitblock.hpp>\n";
    107112    out << "#include <pablo/pablo_compiler.h>\n\n";
    108     out << "void install_properties(pablo::PabloCompiler & p) {\n";
     113    out << "namespace UCD {\n\n";
     114    out << "struct Input {\n    BitBlock bit[8];\n};\n\n";
     115    out << "struct Output {\n    BitBlock bit[1];\n};\n\n";
     116    for (auto prop : properties) {
     117        out << "extern \"C\" void " + prop.first + "(const Input &, BitBlock *, Output &);\n";
     118    }
     119    out << "\nvoid install_properties(pablo::PabloCompiler & p) {\n";
     120    for (auto prop : properties) {
     121        out << "    p.InstallExternalFunction(\"" + prop.first + "\", reinterpret_cast<void *>(&" + prop.first + "), " + std::to_string(prop.second) + ");\n";
     122    }
     123    out << "}\n}\n\n#endif\n";
     124    out.close();
     125}
     126
     127
     128/** ------------------------------------------------------------------------------------------------------------- *
     129 * @brief generateUCDModule
     130 ** ------------------------------------------------------------------------------------------------------------- */
     131Module * generateUCDModule() {
     132
     133    property_list properties;
    109134
    110135    PabloCompiler pc;
     
    115140                const UnicodeSet & set = enumObj->GetCodepointSet(canonicalize_value_name(value));
    116141                std::string name = "__get_" + property_enum_name[enumObj->getPropertyCode()] + "_" + value;
    117                 compileUnicodeSet(name, set, pc, module, out);
     142                properties.emplace_back(name, compileUnicodeSet(name, set, pc, module));
    118143            }
    119144        }
     
    122147                const UnicodeSet & set = extObj->GetCodepointSet(canonicalize_value_name(value));
    123148                std::string name = "__get_" + property_enum_name[extObj->getPropertyCode()] + "_" + value;
    124                 compileUnicodeSet(name, set, pc, module, out);
     149                properties.emplace_back(name, compileUnicodeSet(name, set, pc, module));
    125150            }
    126151        }
     
    128153            const UnicodeSet & set = binObj->GetCodepointSet(Binary_ns::Y);
    129154            std::string name = "__get_" + property_enum_name[binObj->getPropertyCode()] + "_Y";
    130             compileUnicodeSet(name, set, pc, module, out);
     155            properties.emplace_back(name, compileUnicodeSet(name, set, pc, module));
    131156        }
    132157    }
    133 
    134     out << "}\n\n#endif\n"; out.close();
    135158
    136159    // Print an error message if our module is malformed in any way.
    137160    verifyModule(*module, &dbgs());
     161
     162    writePropertyInstaller(std::move(properties));
    138163
    139164    return module;
     
    214239    // Ask the target to add backend passes as necessary.
    215240    if (Target->addPassesToEmitFile(PM, FOS, TargetMachine::CGFT_ObjectFile)) {
    216         throw std::runtime_error("Target does not support generation of this file type!\n");
     241        throw std::runtime_error("Target does not support generation of object file type!\n");
    217242    }
    218243
     
    231256    }
    232257    if (ObjectFilename.empty()) {
    233         ObjectFilename = "ucd.o";
     258        ObjectFilename = "pregenerated_properties.o";
    234259    }
    235260    Module * module = generateUCDModule();
Note: See TracChangeset for help on using the changeset viewer.