source: icGREP/icgrep-devel/icgrep/kernels/linebreak_kernel.cpp @ 5358

Last change on this file since 5358 was 5358, checked in by xuedongx, 2 years ago

delete the linebreak computation in icgrep

File size: 3.0 KB
Line 
1/*
2 *  Copyright (c) 2016 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
6#include "linebreak_kernel.h"
7#include <re/re_cc.h>
8#include <re/re_toolchain.h>
9#include <pablo/pe_ones.h>          // for Ones
10#include <pablo/pe_var.h>           // for Var
11#include <pablo/pe_zeroes.h>        // for Zeroes
12#include <cc/cc_compiler.h>
13#include <pablo/builder.hpp>
14#include <llvm/IR/Module.h>
15
16using namespace cc;
17using namespace kernel;
18using namespace pablo;
19using namespace re;
20using namespace llvm;
21
22#define UNICODE_LINE_BREAK (!AlgorithmOptionIsSet(DisableUnicodeLineBreak))
23
24LineBreakKernelBuilder::LineBreakKernelBuilder (
25IDISA::IDISA_Builder * iBuilder
26, std::string linebreak
27, unsigned basisBitsCount)
28: PabloKernel(iBuilder, linebreak +"_kernel", {Binding{iBuilder->getStreamSetTy(basisBitsCount), "basis"}}) {
29
30    CC_Compiler ccc(this, getInput(0));
31    auto & builder = ccc.getBuilder();
32   
33    PabloAST * LF = ccc.compileCC("LF", makeCC(0x0A), builder);
34    PabloAST * CR = ccc.compileCC(makeCC(0x0D));
35    PabloAST * LF_VT_FF_CR = ccc.compileCC(makeCC(0x0A, 0x0D));
36
37    Zeroes * const zero = builder.createZeroes();
38    Var * crlf = builder.createVar("crlf", zero);
39    PabloBuilder crb = PabloBuilder::Create(builder);
40    PabloAST * cr1 = crb.createAdvance(CR, 1, "cr1");
41    crb.createAssign(crlf, crb.createAnd(cr1, LF));
42    builder.createIf(CR, crb);
43   
44    Var * NEL_LS_PS = builder.createVar("NEL_LS_PS", zero);
45
46    PabloAST * u8pfx = ccc.compileCC(makeCC(0xC0, 0xFF));
47    PabloBuilder it = PabloBuilder::Create(builder);
48    builder.createIf(u8pfx, it);
49    PabloAST * u8pfx2 = ccc.compileCC(makeCC(0xC2, 0xDF), it);
50    PabloAST * u8pfx3 = ccc.compileCC(makeCC(0xE0, 0xEF), it);
51
52    //
53    // Two-byte sequences
54    Var * NEL = it.createVar("NEL", zero);
55    PabloBuilder it2 = PabloBuilder::Create(it);
56    it2.createAssign(NEL, it2.createAnd(it2.createAdvance(ccc.compileCC(makeCC(0xC2), it2), 1), ccc.compileCC(makeCC(0x85), it2)));
57    it.createIf(u8pfx2, it2);
58
59    //
60    // Three-byte sequences
61
62    Var * LS_PS = it.createVar("LS_PS", zero);
63    PabloBuilder it3 = PabloBuilder::Create(it);
64    it.createIf(u8pfx3, it3);
65    PabloAST * E2_80 = it3.createAnd(it3.createAdvance(ccc.compileCC(makeCC(0xE2), it3), 1), ccc.compileCC(makeCC(0x80), it3));
66    it3.createAssign(LS_PS, it3.createAnd(it3.createAdvance(E2_80, 1), ccc.compileCC(makeCC(0xA8,0xA9), it3)));
67    it.createAssign(NEL_LS_PS, it.createOr(NEL, LS_PS));
68
69
70    PabloAST * LB_chars = builder.createOr(LF_VT_FF_CR, NEL_LS_PS);
71    PabloAST * UnicodeLineBreak = builder.createAnd(LB_chars, builder.createNot(crlf));  // count the CR, but not CRLF
72   
73    PabloAST * lb = UNICODE_LINE_BREAK ? UnicodeLineBreak : LF;
74    PabloAST * unterminatedLineAtEOF = builder.createAtEOF(builder.createAdvance(builder.createNot(LB_chars), 1));
75    PabloAST * LineBreak = builder.createOr(lb, unterminatedLineAtEOF);
76    Var * const r = addOutput("linebreak", getStreamTy());
77    builder.createAssign(r, LineBreak);
78}
Note: See TracBrowser for help on using the repository browser.