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

Last change on this file was 6285, checked in by cameron, 5 months ago

-enable-cache-trace flag; base64 encoding for property kernels.

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 "UCD_property_kernel.h"
7#include <re/re_toolchain.h>
8#include <re/re_name.h>
9#include <cc/cc_compiler.h>
10#include <UCD/ucd_compiler.hpp>
11#include <pablo/pablo_toolchain.h>
12#include <kernels/kernel_builder.h>
13#include <pablo/builder.hpp>
14#include <llvm/Support/ErrorHandling.h>
15#include <boost/archive/iterators/base64_from_binary.hpp>
16#include <boost/archive/iterators/transform_width.hpp>
17
18using namespace kernel;
19using namespace pablo;
20using namespace boost::archive::iterators;
21
22std::string base64(std::string to_encode) {
23    typedef base64_from_binary< transform_width<std::string::const_iterator, 6, 8> > base64_t;
24    return std::string(base64_t(to_encode.begin()), base64_t(to_encode.end()));
25}
26
27
28UnicodePropertyKernelBuilder::UnicodePropertyKernelBuilder(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, re::Name * property_value_name, StreamSet *BasisBits, StreamSet * property)
29: PabloKernel(iBuilder,
30"UCD:" + base64(property_value_name->getFullName().c_str()),
31{Binding{"basis", BasisBits}},
32{Binding{"property_stream", property}}),
33  mName(property_value_name) {
34
35}
36
37void UnicodePropertyKernelBuilder::generatePabloMethod() {
38    PabloBuilder pb(getEntryScope());
39    cc::Parabix_CC_Compiler ccc(getEntryScope(), getInputStreamSet("basis"));
40    UCD::UCDCompiler ucdCompiler(ccc);
41    UCD::UCDCompiler::NameMap nameMap;
42    nameMap.emplace(mName, nullptr);
43    ucdCompiler.generateWithDefaultIfHierarchy(nameMap, pb);
44    auto f = nameMap.find(mName);
45    if (f == nameMap.end()) llvm::report_fatal_error("Unknown property");
46    PabloAST * theStream = f-> second;
47    Var * const property_stream = getOutputStreamVar("property_stream");
48    pb.createAssign(pb.createExtract(property_stream, pb.getInteger(0)), theStream);
49}
50
Note: See TracBrowser for help on using the repository browser.