Ignore:
Timestamp:
Dec 18, 2014, 1:08:55 PM (5 years ago)
Author:
cameron
Message:

-print-REs, -print-pablo, -dump-generated-IR command-line options

File:
1 edited

Legend:

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

    r4346 r4348  
    2525#include <pablo/analysis/useanalysis.h>
    2626
    27 #define DEBUG_PRINT_RE_AST
    28 #define DEBUG_PRINT_PBIX_AST
     27#include "llvm/Support/CommandLine.h"
     28#include <re/printer_re.h>
     29#include <pablo/printer_pablos.h>
    2930
    30 #ifdef DEBUG_PRINT_RE_AST
    31 #include <re/printer_re.h>
    32 #endif
    33 #ifdef DEBUG_PRINT_PBIX_AST
    34 #include <pablo/printer_pablos.h>
    35 #endif
     31static cl::opt<bool> PrintAllREs("print-REs", cl::init(false), cl::desc("print regular expression passes"));
     32static cl::opt<bool> PrintParsedREs("print-parsed-REs", cl::init(false), cl::desc("print out parsed regular expressions"));
     33static cl::opt<bool> PrintStrippedREs("print-stripped-REs", cl::init(false), cl::desc("print out REs with nullable prefixes/suffixes removed"));
     34static cl::opt<bool> PrintNamedREs("print-named-REs", cl::init(false), cl::desc("print out named REs"));
     35static cl::opt<bool> PrintUTF8REs("print-utf8-REs", cl::init(false), cl::desc("print out UTF-8 REs"));
     36static cl::opt<bool> PrintSimplifiedREs("print-simplified-REs", cl::init(false), cl::desc("print out final simplified REs"));
     37static cl::opt<bool> PrintAllPablo("print-pablo", cl::init(false), cl::desc("print Pablo code passes"));
     38static cl::opt<bool> PrintCompiledCCcode("print-CC-pablo", cl::init(false), cl::desc("print Pablo output from character class compiler"));
     39static cl::opt<bool> PrintCompiledREcode("print-RE-pablo", cl::init(false), cl::desc("print Pablo output from the regular expression compiler"));
     40static cl::opt<bool> PrintOptimizedREcode("print-optimized-pablo", cl::init(false), cl::desc("print final optimized Pablo code"));
     41
    3642
    3743using namespace re;
     
    6167    }
    6268
    63     #ifdef DEBUG_PRINT_RE_AST
    64     //Print to the terminal the AST that was generated by the parser before adding the UTF encoding:
    65     std::cerr << "Parser:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    66     #endif
     69    if (PrintAllREs || PrintParsedREs) {
     70      std::cerr << "Parser:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
     71    }
    6772
    6873    //Optimization passes to simplify the AST.
    6974    re_ast = RE_Nullable::removeNullablePrefix(re_ast);
    70     #ifdef DEBUG_PRINT_RE_AST
    71     std::cerr << "RemoveNullablePrefix:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    72     #endif
    73 
     75    if (PrintAllREs || PrintStrippedREs) {
     76      std::cerr << "RemoveNullablePrefix:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
     77    }
    7478    re_ast = RE_Nullable::removeNullableSuffix(re_ast);
    75     #ifdef DEBUG_PRINT_RE_AST
    76     std::cerr << "RemoveNullableSuffix:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    77     #endif
    78 
     79    if (PrintAllREs || PrintStrippedREs) {
     80      std::cerr << "RemoveNullableSuffix:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
     81    }
     82   
    7983    CC_NameMap nameMap;
    8084    re_ast = nameMap.process(re_ast, UnicodeClass);
    8185
    82     #ifdef DEBUG_PRINT_RE_AST
    83     std::cerr << "Namer:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    84     std::cerr << "NameMap:\n" << nameMap.printMap() << std::endl;
    85     #endif
     86    if (PrintAllREs || PrintNamedREs) {
     87      std::cerr << "Namer:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
     88      std::cerr << "NameMap:\n" << nameMap.printMap() << std::endl;
     89    }
    8690
    8791    //Add the UTF encoding.
    8892    if (encoding.getType() == Encoding::Type::UTF_8) {
    8993        re_ast = UTF8_Encoder::toUTF8(nameMap, re_ast);
    90         #ifdef DEBUG_PRINT_RE_AST
    91         //Print to the terminal the AST that was generated by the utf8 encoder.
    92         std::cerr << "UTF8-encoder:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    93         #endif
     94        if (PrintAllREs || PrintUTF8REs) {
     95          //Print to the terminal the AST that was generated by the utf8 encoder.
     96          std::cerr << "UTF8-encoder:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
     97          std::cerr << "NameMap:\n" << nameMap.printMap() << std::endl;
     98        }
    9499    }
    95     #ifdef DEBUG_PRINT_RE_AST
    96     std::cerr << "NameMap:\n" << nameMap.printMap() << std::endl;
    97     #endif
    98100   
    99101    re_ast = RE_Simplifier::simplify(re_ast);
    100     #ifdef DEBUG_PRINT_RE_AST
    101     //Print to the terminal the AST that was generated by the simplifier.
    102     std::cerr << "Simplifier:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    103     #endif
     102    if (PrintAllREs || PrintSimplifiedREs) {
     103      //Print to the terminal the AST that was generated by the simplifier.
     104      std::cerr << "Simplifier:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
     105    }
    104106
    105107    SymbolGenerator symgen;
     
    111113   
    112114    auto basisBits = cc_compiler.getBasisBits(nameMap);
    113     #ifdef DEBUG_PRINT_PBIX_AST
    114     //Print to the terminal the AST that was generated by the character class compiler.
    115     std::cerr << "CC AST:" << std::endl;
    116     PabloPrinter::print(main.statements(), std::cerr);
    117     #endif
    118 
    119    
    120    
     115    if (PrintAllPablo || PrintCompiledCCcode) {
     116      //Print to the terminal the AST that was generated by the character class compiler.
     117      std::cerr << "CC AST:" << std::endl;
     118      PabloPrinter::print(main.statements(), std::cerr);
     119    }
    121120   
    122121    RE_Compiler re_compiler(main, nameMap);
    123122    re_compiler.initializeRequiredStreams(cc_compiler);
    124123    re_compiler.finalizeMatchResult(re_compiler.compile(re_ast));
    125     #ifdef DEBUG_PRINT_PBIX_AST
    126     //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
    127     std::cerr << "Initial Pablo AST:\n";
    128     PabloPrinter::print(main.statements(), std::cerr);
    129     #endif
     124    if (PrintAllPablo || PrintCompiledREcode) {
     125      //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
     126      std::cerr << "Initial Pablo AST:\n";
     127      PabloPrinter::print(main.statements(), std::cerr);
     128    }
    130129
    131130    // Scan through the pablo code and perform DCE and CSE
    132131    UseAnalysis::optimize(main);
    133132
    134     #ifdef DEBUG_PRINT_PBIX_AST
    135     //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
    136     std::cerr << "Final Pablo AST:\n";
    137     PabloPrinter::print(main.statements(), std::cerr);
    138     #endif
     133    if (PrintAllPablo || PrintOptimizedREcode) {
     134      //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
     135      std::cerr << "Final Pablo AST:\n";
     136      PabloPrinter::print(main.statements(), std::cerr);
     137    }
    139138
    140139    PabloCompiler pablo_compiler(basisBits);
Note: See TracChangeset for help on using the changeset viewer.