source: icGREP/icgrep-devel/icgrep/kernels/grapheme_kernel.cpp

Last change on this file was 6184, checked in by nmedfort, 8 months ago

Initial version of PipelineKernel? + revised StreamSet? model.

File size: 1.9 KB
Line 
1/*
2 *  Copyright (c) 2018 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
6#include "grapheme_kernel.h"
7#include <re/re_toolchain.h>
8#include <re/re_name.h>
9#include <cc/cc_compiler.h>         // for CC_Compiler
10#include <UCD/ucd_compiler.hpp>
11#include <re/re_compiler.h>
12#include <re/grapheme_clusters.h>
13#include <re/re_name_gather.h>
14#include <re/re_name_resolve.h>
15#include <re/to_utf8.h>
16#include <pablo/pablo_toolchain.h>
17#include <kernels/kernel_builder.h>
18#include <pablo/builder.hpp>
19
20using namespace kernel;
21using namespace pablo;
22
23
24GraphemeClusterBreakKernel::GraphemeClusterBreakKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, StreamSet *BasisBits, StreamSet * RequiredStreams, StreamSet * GCB_stream)
25: PabloKernel(iBuilder,
26"gcb",
27// inputs
28{Binding{"basis", BasisBits},
29 Binding{"nonFinal", RequiredStreams}},
30// output
31{Binding{"\\b{g}", GCB_stream, FixedRate(), Add1()}}) {
32
33}
34
35void GraphemeClusterBreakKernel::generatePabloMethod() {
36    PabloBuilder pb(getEntryScope());
37    cc::Parabix_CC_Compiler ccc(getEntryScope(), getInputStreamSet("basis"));
38    UCD::UCDCompiler ucdCompiler(ccc);
39    re::RE_Compiler re_compiler(getEntryScope(), ccc);
40    re::RE * GCB = re::generateGraphemeClusterBoundaryRule();
41    std::set<re::Name *> externals;
42    re::gatherUnicodeProperties(GCB, externals);
43    UCD::UCDCompiler::NameMap nameMap;
44    for (auto & name : externals) {
45        nameMap.emplace(name, nullptr);
46    }
47    GCB = resolveUnicodeNames(GCB);
48    ucdCompiler.generateWithDefaultIfHierarchy(nameMap, pb);
49    re_compiler.addPrecompiled("UTF8_nonfinal", pb.createExtract(getInputStreamVar("nonFinal"), pb.getInteger(0)));
50    PabloAST * const gcb = re_compiler.compile(GCB);
51    Var * const breaks = getOutputStreamVar("\\b{g}");
52    pb.createAssign(pb.createExtract(breaks, pb.getInteger(0)), gcb);
53}
54
Note: See TracBrowser for help on using the repository browser.