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

Last change on this file since 5881 was 5881, checked in by cameron, 14 months ago

Grapheme Cluster Break kernel

File size: 1.8 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)
25: PabloKernel(iBuilder,
26              "gcb",
27              {Binding{iBuilder->getStreamSetTy(8), "basis"}, Binding{iBuilder->getStreamSetTy(1), "nonFinal"}},
28              {Binding{iBuilder->getStreamSetTy(1, 1), "\\b{g}", FixedRate(), Add1()}}) {
29}
30
31void GraphemeClusterBreakKernel::generatePabloMethod() {
32    PabloBuilder pb(getEntryScope());
33    cc::Parabix_CC_Compiler ccc(getEntryScope(), getInputStreamSet("basis"));
34    UCD::UCDCompiler ucdCompiler(ccc);
35    re::RE_Compiler re_compiler(this, ccc);
36    re::RE * GCB = re::generateGraphemeClusterBoundaryRule();
37    std::set<re::Name *> externals = re::gatherExternalNames(GCB);
38    UCD::UCDCompiler::NameMap nameMap;
39    for (auto & name : externals) {
40        nameMap.emplace(name, nullptr);
41    }
42    GCB = resolveUnicodeProperties(GCB);
43    ucdCompiler.generateWithDefaultIfHierarchy(nameMap, pb);
44    re_compiler.addPrecompiled("UTF8_nonfinal", pb.createExtract(getInputStreamVar("nonFinal"), pb.getInteger(0)));
45    PabloAST * const gcb = re_compiler.compile(GCB);
46    Var * const breaks = getOutputStreamVar("\\b{g}");
47    pb.createAssign(pb.createExtract(breaks, pb.getInteger(0)), gcb);
48}
49
Note: See TracBrowser for help on using the repository browser.