Changeset 4961 for icGREP


Ignore:
Timestamp:
Mar 8, 2016, 3:15:18 PM (3 years ago)
Author:
hongpum
Message:

Append the sha1sum of REs to Module ID

Location:
icGREP/icgrep-devel/icgrep
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r4952 r4961  
    161161void GrepEngine::grepCodeGen(std::string moduleName, re::RE * re_ast, bool isNameExpression) {
    162162                           
    163     Module * M = new Module("moduleName", getGlobalContext());
     163    Module * M = new Module(moduleName, getGlobalContext());
    164164   
    165165    IDISA::IDISA_Builder * idb = GetIDISA_Builder(M);
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r4949 r4961  
    88#include <iostream>
    99#include <fstream>
     10#include <cstdio>
    1011
    1112
     
    2324
    2425#include <grep_engine.h>
     26
     27#include <boost/uuid/sha1.hpp>
    2528
    2629static cl::OptionCategory aRegexSourceOptions("Regular Expression Options",
     
    5053
    5154static unsigned firstInputFile = 1;  // Normal case when first positional arg is a regex.
     55static std::string allREs;
    5256
    5357re::RE * get_icgrep_RE() {
     
    8589        re_ast = re::RE_Parser::parse(regexVector[i], globalFlags);
    8690        REs.push_back(re_ast);
     91        allREs += regexVector[i] + "\n";
    8792    }
    8893    if (REs.size() > 1) {
     
    9196   
    9297    return re_ast;
     98}
     99
     100std::string sha1sum(const std::string & str) {
     101    char buffer[41];    // 40 hex-digits and the terminating null
     102    unsigned int digest[5];     // 160 bits in total
     103
     104    boost::uuids::detail::sha1 sha1;
     105    sha1.process_bytes(str.c_str(), str.size());
     106    sha1.get_digest(digest);
     107    snprintf(buffer, sizeof(buffer), "%.8x%.8x%.8x%.8x%.8x",
     108             digest[0], digest[1], digest[2], digest[3], digest[4]);
     109    return std::string(buffer);
    93110}
    94111
     
    124141   
    125142    re::RE * re_ast = get_icgrep_RE();
     143    std::string module_name = "grepcode:" + sha1sum(allREs);
    126144   
    127145    GrepEngine grepEngine;
    128     grepEngine.grepCodeGen("grepcode", re_ast);
     146    grepEngine.grepCodeGen(module_name, re_ast);
    129147   
    130148    for (unsigned i = firstInputFile; i != inputFiles.size(); ++i) {
Note: See TracChangeset for help on using the changeset viewer.