source: icGREP/icgrep-devel/icgrep/grep_engine.cpp @ 5135

Last change on this file since 5135 was 5135, checked in by lindanl, 3 years ago

Add pipeline parallel strategy to the framework.

File size: 21.9 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 *  icgrep is a trademark of International Characters.
5 */
6
7#include <grep_engine.h>
8#include <IDISA/idisa_builder.h>
9#include <IDISA/idisa_target.h>
10#include <llvm/Support/CommandLine.h>
11#include <re/re_toolchain.h>
12#include <re/re_cc.h>
13
14#include <pablo/pablo_toolchain.h>
15#include <toolchain.h>
16#include <utf_encoding.h>
17#include <pablo/pablo_compiler.h>
18#include <kernels/pipeline.h>
19#include <llvm/IR/Function.h>
20#include <llvm/IR/Type.h>
21#include <llvm/IR/Module.h>
22#include <llvm/ExecutionEngine/MCJIT.h>
23#include <llvm/IRReader/IRReader.h>
24#include <llvm/Support/Debug.h>
25#include <llvm/IR/Verifier.h>
26#include <llvm/IR/TypeBuilder.h>
27#include <UCD/UnicodeNameData.h>
28
29
30#include <kernels/streamset.h>
31#include <kernels/scanmatchgen.h>
32#include <kernels/s2p_kernel.h>
33#include <kernels/pipeline.h>
34
35#include <pablo/function.h>
36#include <pablo/pablo_kernel.h>
37#include <pablo/pablo_toolchain.h>
38
39#include <llvm/IR/Intrinsics.h>
40#include "llvm/Support/SourceMgr.h"
41#include "llvm/IRReader/IRReader.h"
42#include "llvm/Linker/Linker.h"
43
44
45#include <fstream>
46#include <sstream>
47#include <iostream>
48#include <string>
49#include <stdint.h>
50
51#include <stdio.h>
52#include <stdlib.h>
53#include <unistd.h>
54#include <errno.h>
55#include <sys/types.h>
56#include <sys/stat.h>
57#include <stdexcept>
58#include <cctype>
59
60
61#include <llvm/Support/raw_os_ostream.h>
62
63// mmap system
64#include <boost/filesystem.hpp>
65#include <boost/iostreams/device/mapped_file.hpp>
66
67#include <fcntl.h>
68
69#include <kernels/kernel.h>
70
71static cl::OptionCategory bGrepOutputOptions("Output Options",
72                                             "These options control the output.");
73
74static cl::opt<bool> NormalizeLineBreaks("normalize-line-breaks", cl::desc("Normalize line breaks to std::endl."), cl::init(false),  cl::cat(bGrepOutputOptions));
75
76static cl::opt<bool> ShowFileNames("H", cl::desc("Show the file name with each matching line."), cl::cat(bGrepOutputOptions));
77static cl::alias ShowFileNamesLong("with-filename", cl::desc("Alias for -H"), cl::aliasopt(ShowFileNames));
78
79static cl::opt<bool> ShowLineNumbers("n", cl::desc("Show the line number with each matching line."), cl::cat(bGrepOutputOptions));
80static cl::alias ShowLineNumbersLong("line-number", cl::desc("Alias for -n"), cl::aliasopt(ShowLineNumbers));
81
82static cl::opt<bool> pipelineParallel("enable-pipeline-parallel", cl::desc("Enable multithreading with pipeline parallelism."), cl::cat(bGrepOutputOptions));
83
84
85bool isUTF_16 = false;
86
87void GrepEngine::doGrep(const std::string & fileName, const int fileIdx, bool CountOnly, std::vector<size_t> & total_CountOnly, bool UTF_16) {
88    boost::filesystem::path file(fileName);
89    if (exists(file)) {
90        if (is_directory(file)) {
91            return;
92        }
93    } else {
94        std::cerr << "Error: cannot open " << fileName << " for processing. Skipped.\n";
95        return;
96    }
97
98    const auto fileSize = file_size(file);
99    if (fileSize > 0) {
100        try {
101            boost::iostreams::mapped_file_source source(fileName, fileSize, 0);
102            char * fileBuffer = const_cast<char *>(source.data());
103            if (CountOnly) {
104                total_CountOnly[fileIdx] = mGrepFunction_CountOnly(fileBuffer, fileSize, fileIdx);
105            } else {
106                mGrepFunction(fileBuffer, fileSize, fileIdx);
107            }
108            source.close();
109        } catch (std::exception & e) {
110            throw std::runtime_error("Boost mmap error: " + fileName + ": " + e.what());
111        }
112    } else {
113        if (CountOnly) {
114            total_CountOnly[fileIdx] = mGrepFunction_CountOnly(nullptr, 0, fileIdx);
115        } else {
116            mGrepFunction(nullptr, 0, fileIdx);
117        }
118    }
119}
120
121using namespace parabix;
122/*
123void GrepEngine::grepCodeGen(std::string moduleName, re::RE * re_ast, bool CountOnly, bool UTF_16, bool isNameExpression) {
124    isUTF_16 = UTF_16;
125    Module * M = new Module(moduleName, getGlobalContext());
126   
127    IDISA::IDISA_Builder * iBuilder = IDISA::GetIDISA_Builder(M);
128
129    const unsigned segmentSize = codegen::SegmentSize;
130
131    Encoding::Type type;
132    type = UTF_16 ? Encoding::Type::UTF_16 : Encoding::Type::UTF_8;
133    unsigned bits;
134    bits = UTF_16 ? 16 : 8;
135
136    Encoding encoding(type, bits);
137    mIsNameExpression = isNameExpression;
138
139    Type * const size_ty = iBuilder->getSizeTy();
140    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
141    Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(iBuilder->getBitBlockType(), (UTF_16 ? 16 : 8)), 1), 0);
142    Type * const resultTy = CountOnly ? size_ty : iBuilder->getVoidTy();
143    Function * const mainFn = cast<Function>(M->getOrInsertFunction("Main", resultTy, inputType, size_ty, size_ty, nullptr));
144    mainFn->setCallingConv(CallingConv::C);
145    iBuilder->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFn, 0));
146    Function::arg_iterator args = mainFn->arg_begin();
147   
148    Value * const inputStream = &*(args++);
149    inputStream->setName("input");
150    Value * const fileSize = &*(args++);
151    fileSize->setName("fileSize");
152    Value * const fileIdx = &*(args++);
153    fileIdx->setName("fileIdx");
154
155       
156    ExternalUnboundedBuffer ByteStream(iBuilder, StreamSetType(1, i8));
157    CircularBuffer BasisBits(iBuilder, StreamSetType(8, i1), segmentSize);
158
159    kernel::s2pKernel  s2pk(iBuilder);
160    s2pk.generateKernel({&ByteStream}, {&BasisBits});
161
162    re_ast = re::regular_expression_passes(encoding, re_ast);   
163    pablo::PabloFunction * function = re::re2pablo_compiler(encoding, re_ast, CountOnly);
164    pablo_function_passes(function);
165   
166    if (CountOnly) {
167        pablo::PabloKernel  icgrepK(iBuilder, "icgrep", function, {"matchedLineCount"});
168        icgrepK.generateKernel({&BasisBits}, {});
169
170        ByteStream.setStreamSetBuffer(inputStream);
171        BasisBits.allocateBuffer();
172       
173        Value * s2pInstance = s2pk.createInstance({});
174        Value * icgrepInstance = icgrepK.createInstance({});
175       
176        generatePipelineLoop(iBuilder, {&s2pk, &icgrepK}, {s2pInstance, icgrepInstance}, fileSize);
177        Value * matchCount = icgrepK.createGetAccumulatorCall(icgrepInstance, "matchedLineCount");
178        iBuilder->CreateRet(matchCount);
179    }
180    else {
181        CircularBuffer MatchResults(iBuilder, StreamSetType(2, i1), segmentSize);
182        pablo::PabloKernel  icgrepK(iBuilder, "icgrep", function, {});
183        icgrepK.generateKernel({&BasisBits},  {&MatchResults});
184
185        ByteStream.setStreamSetBuffer(inputStream);
186        BasisBits.allocateBuffer();
187        MatchResults.allocateBuffer();
188       
189        Value * s2pInstance = s2pk.createInstance({});
190        Value * icgrepInstance = icgrepK.createInstance({});
191        kernel::scanMatchKernel scanMatchK(iBuilder, mIsNameExpression);
192        scanMatchK.generateKernel({&MatchResults}, {});
193               
194        Value * scanMatchInstance = scanMatchK.createInstance({iBuilder->CreateBitCast(inputStream, int8PtrTy), fileSize, fileIdx});
195       
196        generatePipelineLoop(iBuilder, {&s2pk, &icgrepK, &scanMatchK}, {s2pInstance, icgrepInstance, scanMatchInstance}, fileSize);
197        iBuilder->CreateRetVoid();
198    }
199   
200    mEngine = JIT_to_ExecutionEngine(M);
201    ApplyObjectCache(mEngine);
202    icgrep_Linking(M, mEngine);
203
204#ifndef NDEBUG
205    verifyModule(*M, &dbgs());
206#endif
207
208    mEngine->finalizeObject();
209    delete iBuilder;
210   
211    if (CountOnly) {
212        mGrepFunction_CountOnly = reinterpret_cast<GrepFunctionType_CountOnly>(mEngine->getPointerToFunction(mainFn));
213    } else {
214        mGrepFunction = reinterpret_cast<GrepFunctionType>(mEngine->getPointerToFunction(mainFn));
215    }
216
217}
218*/
219void GrepEngine::grepCodeGen(std::string moduleName, re::RE * re_ast, bool CountOnly, bool UTF_16, bool isNameExpression) {
220    isUTF_16 = UTF_16; 
221    Module * M = new Module(moduleName, getGlobalContext());
222   
223    IDISA::IDISA_Builder * iBuilder = IDISA::GetIDISA_Builder(M);
224
225    const unsigned segmentSize = codegen::SegmentSize;
226    const unsigned bufferSegments = codegen::BufferSegments;
227
228    Encoding::Type type;
229    type = UTF_16 ? Encoding::Type::UTF_16 : Encoding::Type::UTF_8;
230    unsigned bits;
231    bits = UTF_16 ? 16 : 8;
232
233    Encoding encoding(type, bits);
234    mIsNameExpression = isNameExpression;
235
236    Type * const int64ty = iBuilder->getInt64Ty();
237    Type * const int32ty = iBuilder->getInt32Ty();
238    Type * const size_ty = iBuilder->getSizeTy();
239    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
240    Type * const voidTy = Type::getVoidTy(M->getContext());   
241    Type * const voidPtrTy = TypeBuilder<void *, false>::get(M->getContext());
242    Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(iBuilder->getBitBlockType(), (UTF_16 ? 16 : 8)), 1), 0);
243    Type * const resultTy = CountOnly ? size_ty : iBuilder->getVoidTy();
244    Function * const mainFn = cast<Function>(M->getOrInsertFunction("Main", resultTy, inputType, size_ty, size_ty, nullptr));
245    mainFn->setCallingConv(CallingConv::C);
246    iBuilder->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFn, 0));
247    Function::arg_iterator args = mainFn->arg_begin();
248   
249    Value * const inputStream = &*(args++);
250    inputStream->setName("input");
251    Value * const fileSize = &*(args++);
252    fileSize->setName("fileSize");
253    Value * const fileIdx = &*(args++);
254    fileIdx->setName("fileIdx");
255       
256    ExternalUnboundedBuffer ByteStream(iBuilder, StreamSetType(1, i8));
257    CircularBuffer BasisBits(iBuilder, StreamSetType(8, i1), segmentSize * bufferSegments);
258
259    kernel::s2pKernel  s2pk(iBuilder);
260    s2pk.generateKernel({&ByteStream}, {&BasisBits});
261
262    re_ast = re::regular_expression_passes(encoding, re_ast);   
263    pablo::PabloFunction * function = re::re2pablo_compiler(encoding, re_ast, CountOnly);
264    pablo_function_passes(function);
265
266    ByteStream.setStreamSetBuffer(inputStream);
267    BasisBits.allocateBuffer();
268
269    Value * producerPtr = ByteStream.getProducerPosPtr(ByteStream.getStreamSetStructPtr());
270    iBuilder->CreateAlignedStore(fileSize, producerPtr, 8)->setOrdering(Release);
271
272    Value * s2pInstance = s2pk.createInstance({});
273 
274    Type * pthreadTy = int64ty; //Pthread Type for 64-bit machine.
275    FunctionType * funVoidPtrVoidTy = FunctionType::get(voidTy, int8PtrTy, false);   
276   
277    Function * pthreadCreateFunc = cast<Function>(M->getOrInsertFunction("pthread_create",
278                                        int32ty, 
279                                        pthreadTy->getPointerTo(), 
280                                        voidPtrTy, 
281                                        static_cast<Type *>(funVoidPtrVoidTy)->getPointerTo(),
282                                        voidPtrTy, nullptr));
283    pthreadCreateFunc->setCallingConv(llvm::CallingConv::C);
284    Function * pthreadJoinFunc = cast<Function>(M->getOrInsertFunction("pthread_join", 
285                                        int32ty, 
286                                        pthreadTy, 
287                                        PointerType::get(int8PtrTy, 0), nullptr));
288    pthreadJoinFunc->setCallingConv(llvm::CallingConv::C);
289
290    Function * pthreadExitFunc = cast<Function>(M->getOrInsertFunction("pthread_exit", 
291                                        voidTy, 
292                                        voidPtrTy, nullptr));
293    pthreadExitFunc->addFnAttr(llvm::Attribute::NoReturn);
294    pthreadExitFunc->setCallingConv(llvm::CallingConv::C);
295   
296    // Type * const pthreadsTy = ArrayType::get(pthreadTy, 3);
297    // AllocaInst * const pthreads = iBuilder->CreateAlloca(pthreadsTy);
298    // Value * pthreadsPtr1 = iBuilder->CreateGEP(pthreads, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
299    // Value * pthreadsPtr2 = iBuilder->CreateGEP(pthreads, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
300    // Value * pthreadsPtr3 = iBuilder->CreateGEP(pthreads, {iBuilder->getInt32(0), iBuilder->getInt32(2)});
301    // Value * nullVal = Constant::getNullValue(voidPtrTy);
302    // AllocaInst * const status = iBuilder->CreateAlloca(int8PtrTy);
303
304    if (CountOnly) {
305        pablo::PabloKernel  icgrepK(iBuilder, "icgrep", function, {"matchedLineCount"});
306        icgrepK.generateKernel({&BasisBits}, {});       
307        Value * icgrepInstance = icgrepK.createInstance({});
308
309        if (pipelineParallel){
310            // const auto ip = iBuilder->saveIP();
311            // Function * s2p_func = s2pk.generateThreadFunction("s2p");
312            // Function * icgrep_func = icgrepK.generateThreadFunction("icgrep");
313            // iBuilder->restoreIP(ip);
314
315            // iBuilder->CreateCall(pthreadCreateFunc, std::vector<Value *>({pthreadsPtr1, nullVal, s2p_func, iBuilder->CreateBitCast(s2pInstance, int8PtrTy)}));
316            // iBuilder->CreateCall(pthreadCreateFunc, std::vector<Value *>({pthreadsPtr2, nullVal, icgrep_func, iBuilder->CreateBitCast(icgrepInstance, int8PtrTy)}));
317         
318            // Value * threadID1 = iBuilder->CreateLoad(pthreadsPtr1);
319            // Value * threadID2 = iBuilder->CreateLoad(pthreadsPtr2);
320
321            // iBuilder->CreateCall(pthreadJoinFunc, std::vector<Value *>({threadID1, status}));
322            // iBuilder->CreateCall(pthreadJoinFunc, std::vector<Value *>({threadID2, status}));
323            generatePipelineParallel(iBuilder, {&s2pk, &icgrepK}, {s2pInstance, icgrepInstance});
324
325        }
326        else{
327            generatePipelineLoop(iBuilder, {&s2pk, &icgrepK}, {s2pInstance, icgrepInstance}, fileSize);
328
329        }
330       
331        Value * matchCount = icgrepK.createGetAccumulatorCall(icgrepInstance, "matchedLineCount");
332        iBuilder->CreateRet(matchCount);
333
334    }
335    else {
336        CircularBuffer MatchResults(iBuilder, StreamSetType(2, i1), segmentSize * bufferSegments);
337        MatchResults.allocateBuffer();
338
339        pablo::PabloKernel  icgrepK(iBuilder, "icgrep", function, {});
340        icgrepK.generateKernel({&BasisBits},  {&MatchResults});
341        Value * icgrepInstance = icgrepK.createInstance({});
342
343        kernel::scanMatchKernel scanMatchK(iBuilder, mIsNameExpression);
344        scanMatchK.generateKernel({&MatchResults}, {});               
345        Value * scanMatchInstance = scanMatchK.createInstance({iBuilder->CreateBitCast(inputStream, int8PtrTy), fileSize, fileIdx});
346
347        if (pipelineParallel){
348            generatePipelineParallel(iBuilder, {&s2pk, &icgrepK, &scanMatchK}, {s2pInstance, icgrepInstance, scanMatchInstance});
349
350        }
351        else{
352            generatePipelineLoop(iBuilder, {&s2pk, &icgrepK, &scanMatchK}, {s2pInstance, icgrepInstance, scanMatchInstance}, fileSize);
353        }
354        // const auto ip = iBuilder->saveIP();
355        // Function * s2p_func = s2pk.generateThreadFunction("s2p");
356        // Function * icgrep_func = icgrepK.generateThreadFunction("icgrep");   
357        // Function * scan_func = scanMatchK.generateThreadFunction("scanMatch");
358        // iBuilder->restoreIP(ip);
359       
360        // iBuilder->CreateCall(pthreadCreateFunc, std::vector<Value *>({pthreadsPtr1, nullVal, s2p_func, iBuilder->CreateBitCast(s2pInstance, int8PtrTy)}));
361        // iBuilder->CreateCall(pthreadCreateFunc, std::vector<Value *>({pthreadsPtr2, nullVal, icgrep_func, iBuilder->CreateBitCast(icgrepInstance, int8PtrTy)}));
362        // iBuilder->CreateCall(pthreadCreateFunc, std::vector<Value *>({pthreadsPtr3, nullVal, scan_func, iBuilder->CreateBitCast(scanMatchInstance, int8PtrTy)}));
363
364        // Value * threadID1 = iBuilder->CreateLoad(pthreadsPtr1);
365        // Value * threadID2 = iBuilder->CreateLoad(pthreadsPtr2);
366        // Value * threadID3 = iBuilder->CreateLoad(pthreadsPtr3);
367     
368        // iBuilder->CreateCall(pthreadJoinFunc, std::vector<Value *>({threadID1, status}));
369        // iBuilder->CreateCall(pthreadJoinFunc, std::vector<Value *>({threadID2, status}));
370        // iBuilder->CreateCall(pthreadJoinFunc, std::vector<Value *>({threadID3, status}));
371        iBuilder->CreateRetVoid();
372
373    }
374     
375    mEngine = JIT_to_ExecutionEngine(M);
376    ApplyObjectCache(mEngine);
377    icgrep_Linking(M, mEngine);
378
379#ifndef NDEBUG
380    verifyModule(*M, &dbgs());
381#endif
382
383    mEngine->finalizeObject();
384    delete iBuilder;
385   
386    if (CountOnly) {
387        mGrepFunction_CountOnly = reinterpret_cast<GrepFunctionType_CountOnly>(mEngine->getPointerToFunction(mainFn));
388    } else {
389        mGrepFunction = reinterpret_cast<GrepFunctionType>(mEngine->getPointerToFunction(mainFn));
390    }
391
392}
393
394re::CC *  GrepEngine::grepCodepoints() {
395
396    setParsedCodePointSet();
397    char * mFileBuffer = getUnicodeNameDataPtr();
398    size_t mFileSize = getUnicodeNameDataSize();
399
400    mGrepFunction(mFileBuffer, mFileSize, 0);
401
402    return getParsedCodePointSet();
403}
404
405GrepEngine::~GrepEngine() {
406    delete mEngine;
407}
408
409
410static int * total_count;
411static std::stringstream * resultStrs = nullptr;
412static std::vector<std::string> inputFiles;
413
414void initResult(std::vector<std::string> filenames){
415    const int n = filenames.size();
416    if (n > 1) {
417        ShowFileNames = true;
418    }
419    inputFiles = filenames;
420    resultStrs = new std::stringstream[n];
421    total_count = new int[n];
422    for (unsigned i = 0; i < inputFiles.size(); ++i){
423        total_count[i] = 0;
424    }
425   
426}
427
428extern "C" {
429    void wrapped_report_match(size_t lineNum, size_t line_start, size_t line_end, const char * buffer, size_t filesize, int fileIdx) {
430        int index = isUTF_16 ? 2 : 1;
431        int idx = fileIdx;
432         
433        if (ShowFileNames) {
434            resultStrs[idx] << inputFiles[idx] << ':';
435        }
436        if (ShowLineNumbers) {
437            resultStrs[idx] << lineNum << ":";
438        }
439       
440        if ((!isUTF_16 && buffer[line_start] == 0xA) && (line_start != line_end)) {
441            // The line "starts" on the LF of a CRLF.  Really the end of the last line.
442            line_start++;
443        }
444        if (((isUTF_16 && buffer[line_start] == 0x0) && buffer[line_start + 1] == 0xA) && (line_start != line_end)) {
445            // The line "starts" on the LF of a CRLF.  Really the end of the last line.
446            line_start += 2;
447        }
448        if (line_end == filesize) {
449            // The match position is at end-of-file.   We have a final unterminated line.
450            resultStrs[idx].write(&buffer[line_start * index], (line_end - line_start) * index);
451            if (NormalizeLineBreaks) {
452                resultStrs[idx] << '\n';  // terminate it
453            }
454            return;
455        }
456        unsigned char end_byte = (unsigned char)buffer[line_end]; 
457        unsigned char penult_byte = (unsigned char)(buffer[line_end - 1]);
458        if (NormalizeLineBreaks) {
459            if (end_byte == 0x85) {
460                // Line terminated with NEL, on the second byte.  Back up 1.
461                line_end--;
462            } else if (end_byte > 0xD) {
463                // Line terminated with PS or LS, on the third byte.  Back up 2.
464                isUTF_16 ? line_end-- : line_end -= 2;
465            }
466            resultStrs[idx].write(&buffer[line_start * index], (line_end - line_start) * index);
467            resultStrs[idx] << '\n';
468        }
469        else {   
470            if ((!isUTF_16 && end_byte == 0x0D) || (isUTF_16 && (end_byte == 0x0D && penult_byte == 0x0))) {
471                // Check for line_end on first byte of CRLF;  note that we don't
472                // want to access past the end of buffer.
473                if (line_end + 1 < filesize) {
474                    if (!isUTF_16 && buffer[line_end + 1] == 0x0A) {
475                        // Found CRLF; preserve both bytes.
476                        line_end++;
477                    }
478                    if (isUTF_16 && buffer[line_end + 1] == 0x0 && buffer[line_end + 2] == 0x0A) {
479                        // Found CRLF; preserve both bytes.
480                        line_end += 2;
481                    }
482                }
483            }
484            resultStrs[idx].write(&buffer[line_start * index], (line_end - line_start + 1) * index);
485        }
486    }
487}
488
489void PrintResult(bool CountOnly, std::vector<size_t> & total_CountOnly){
490    if(CountOnly){
491        if (!ShowFileNames) {
492            for (unsigned i = 0; i < inputFiles.size(); ++i){
493                std::cout << total_CountOnly[i] << std::endl;
494            }
495        }
496        else {
497            for (unsigned i = 0; i < inputFiles.size(); ++i){
498                std::cout << inputFiles[i] << ':' << total_CountOnly[i] << std::endl;
499            };
500        }
501        return;
502    }
503   
504    for (unsigned i = 0; i < inputFiles.size(); ++i){
505        std::cout << resultStrs[i].str();
506    }
507}
508
509re::CC * parsedCodePointSet;
510
511extern "C" {
512    void insert_codepoints(size_t lineNum, size_t line_start, size_t line_end, const char * buffer) {
513        re::codepoint_t c = 0;
514        ssize_t line_pos = line_start;
515        while (isxdigit(buffer[line_pos])) {
516            if (isdigit(buffer[line_pos])) {
517                c = (c << 4) | (buffer[line_pos] - '0');
518            }
519            else {
520                c = (c << 4) | (tolower(buffer[line_pos]) - 'a' + 10);
521            }
522            line_pos++;
523        }
524        assert(((line_pos - line_start) >= 4) && ((line_pos - line_start) <= 6)); // UCD format 4 to 6 hex digits.       
525        parsedCodePointSet->insert(c);
526    }
527}
528
529void setParsedCodePointSet(){
530    parsedCodePointSet = re::makeCC();
531}
532
533re::CC * getParsedCodePointSet(){
534    return parsedCodePointSet;
535}
536
537
538
539
540void icgrep_Linking(Module * m, ExecutionEngine * e) {
541    Module::FunctionListType & fns = m->getFunctionList();
542    for (Module::FunctionListType::iterator it = fns.begin(), it_end = fns.end(); it != it_end; ++it) {
543        std::string fnName = it->getName().str();
544        if (fnName == "s2p_block") continue;
545        if (fnName == "process_block") continue;
546        if (fnName == "process_block_initialize_carries") continue;
547       
548        if (fnName == "wrapped_report_match") {
549            e->addGlobalMapping(cast<GlobalValue>(it), (void *)&wrapped_report_match);
550        }
551        if (fnName == "insert_codepoints") {
552            e->addGlobalMapping(cast<GlobalValue>(it), (void *)&insert_codepoints);
553        }
554#ifndef DISABLE_PREGENERATED_UCD_FUNCTIONS
555        else {
556            const UCD::ExternalProperty & ep = UCD::resolveExternalProperty(fnName);
557            e->addGlobalMapping(cast<GlobalValue>(it), std::get<0>(ep));
558        }
559#endif
560    }
561}
562
Note: See TracBrowser for help on using the repository browser.