source: icGREP/icgrep-devel/icgrep/generate_predefined_ucd_functions.cpp @ 4661

Last change on this file since 4661 was 4661, checked in by nmedfort, 4 years ago

Start of work to make the pablo compiler reenterant. Fixed bug that prevented it from using Less optimization level.

File size: 3.1 KB
Line 
1/*
2 *  Copyright (c) 2015 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include <string>
8#include <iostream>
9#include <fstream>
10
11#include <cc/cc_compiler.h>
12#include <UCD/unicode_set.h>
13#include <UCD/PropertyObjectTable.h>
14#include <UCD/ucd_compiler.hpp>
15#include <pablo/pablo_compiler.h>
16#include <pablo/builder.hpp>
17#include <pablo/function.h>
18#include <llvm/Support/CommandLine.h>
19#include <utf_encoding.h>
20#include <pablo/optimizers/pablo_simplifier.hpp>
21#include <pablo/optimizers/pablo_codesinking.hpp>
22#include <pablo/optimizers/pablo_automultiplexing.hpp>
23#include <llvm/ExecutionEngine/ExecutionEngine.h>
24#include <boost/algorithm/string/case_conv.hpp>
25
26#include <iostream>
27
28using namespace pablo;
29using namespace UCD;
30using namespace cc;
31
32inline std::string lowercase(const std::string & name) {
33    std::locale loc;
34    return boost::algorithm::to_lower_copy(name, loc);
35}
36
37ExecutionEngine * compile(std::string name, const UnicodeSet & set, PabloCompiler & pc, ExecutionEngine * engine) {
38
39    PabloFunction function = PabloFunction::Create(std::move(name));
40    Encoding encoding(Encoding::Type::UTF_8, 8);
41    CC_Compiler ccCompiler(function, encoding);
42    UCDCompiler ucdCompiler(ccCompiler);
43    PabloBuilder builder(function.getEntryBlock());
44
45    std::cerr << "Compiling " << name << std::endl;
46
47    // Build the unicode set function
48    ucdCompiler.generateWithDefaultIfHierarchy(set, builder);
49    // Optimize it at the pablo level
50    Simplifier::optimize(function);
51    CodeSinking::optimize(function);
52    // AutoMultiplexing::optimize(function);
53
54
55    if (engine) {
56        engine->removeModule(pc.getModule());
57    }
58
59    // Now compile the function ...
60    return pc.compile(function).getExecutionEngine();
61}
62
63int main(int argc, char *argv[]) {
64
65    PabloCompiler pc;
66    ExecutionEngine * engine = nullptr;
67
68    for (PropertyObject * obj : property_object_table) {
69
70        if (isa<UnsupportedPropertyObject>(obj)) continue;
71
72        if (auto * enumObj = dyn_cast<EnumeratedPropertyObject>(obj)) {
73            for (const std::string value : *enumObj) {
74                const UnicodeSet & set = enumObj->GetCodepointSet(canonicalize_value_name(value));
75                engine = compile("__get_" + property_enum_name[enumObj->getPropertyCode()] + "_" + value, set, pc, engine);
76            }
77            break;
78        }
79
80//        if (auto * extObj = dyn_cast<ExtensionPropertyObject>(obj)) {
81//            for (const std::string value : *extObj) {
82//                const UnicodeSet & set = extObj->GetCodepointSet(canonicalize_value_name(value));
83//                engine = compile("__get_" + property_enum_name[extObj->getPropertyCode()] + "_" + value, set, pc, engine);
84//            }
85//        }
86
87//        if (auto * binObj = dyn_cast<BinaryPropertyObject>(obj)) {
88//            const UnicodeSet & set = binObj->GetCodepointSet(Binary_ns::Y);
89//            compile("__get_" + property_enum_name[binObj->getPropertyCode()] + "_Y", set, pc);
90//        }
91    }
92
93    pc.getModule()->dump();
94
95    return 0;
96}
Note: See TracBrowser for help on using the repository browser.