Ignore:
Timestamp:
May 20, 2015, 11:48:43 AM (4 years ago)
Author:
cameron
Message:

Use llvm:raw_ostream in Pablo printer

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

Legend:

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

    r4526 r4567  
    137137    if (PrintCompiledCCcode) {
    138138      //Print to the terminal the AST that was generated by the character class compiler.
    139       std::cerr << "CC AST:" << std::endl;
    140       PabloPrinter::print(main.statements(), std::cerr);
     139      llvm::raw_os_ostream cerr(std::cerr);
     140      cerr << "CC AST:" << "\n";
     141      PabloPrinter::print(main.statements(), cerr);
    141142    }
    142143   
     
    146147    if (PrintCompiledREcode) {
    147148      //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
    148       std::cerr << "Initial Pablo AST:\n";
    149       PabloPrinter::print(main.statements(), std::cerr);
     149      llvm::raw_os_ostream cerr(std::cerr);
     150      cerr << "Initial Pablo AST:\n";
     151      PabloPrinter::print(main.statements(), cerr);
    150152    }
    151153
     
    159161    if (PrintOptimizedREcode) {
    160162      //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
    161       std::cerr << "Final Pablo AST:\n";
    162       PabloPrinter::print(main.statements(), std::cerr);
     163      llvm::raw_os_ostream cerr(std::cerr);
     164      cerr << "Final Pablo AST:\n";
     165      PabloPrinter::print(main.statements(), cerr);
    163166    }
    164167
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4566 r4567  
    721721    }
    722722    else {
    723         PabloPrinter::print(stmt, std::cerr);
     723        llvm::raw_os_ostream cerr(std::cerr);
     724        PabloPrinter::print(stmt, cerr);
    724725        throw std::runtime_error("Unrecognized Pablo Statement! can't compile.");
    725726    }
     
    738739    auto f = mMarkerMap.find(expr);
    739740    if (f == mMarkerMap.end()) {
    740         std::stringstream str;
     741        std::string o;
     742        llvm::raw_string_ostream str(o);
    741743        str << "\"";
    742744        PabloPrinter::print(expr, str);
  • icGREP/icgrep-devel/icgrep/pablo/pe_string.h

    r4512 r4567  
    88#include <string>
    99#include <ostream>
     10#include <llvm/Support/raw_os_ostream.h>
    1011
    1112namespace pablo {
     
    7172}
    7273
     74inline llvm::raw_ostream & operator <<(llvm::raw_ostream & stream, const String & string) {
     75    stream << string.value().data();
     76    return stream;
     77}
     78
     79inline llvm::raw_ostream & operator <<(llvm::raw_ostream & stream, const String * string) {
     80    stream << string->value().data();
     81    return stream;
     82}
     83
    7384}
    7485
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.cpp

    r4518 r4567  
    88#include <iostream>
    99#include <ostream>
     10#include <llvm/Support/raw_os_ostream.h>
    1011
    1112//Regular Expressions
     
    3940using namespace pablo;
    4041
    41 void PabloPrinter::print(const PabloBlock & block, std::ostream & strm)
     42void PabloPrinter::print(const PabloBlock & block, llvm::raw_ostream & strm)
    4243{
    4344    print(block.statements(), "  ", strm);
    4445}
    4546
    46 void PabloPrinter::print(const StatementList & stmts, std::ostream & strm) {
     47void PabloPrinter::print(const StatementList & stmts, llvm::raw_ostream & strm) {
    4748    print(stmts, "  ", strm);
    4849}
    4950
    50 void PabloPrinter::print(const StatementList & stmts, std::string indent, std::ostream & strm) {
     51void PabloPrinter::print(const StatementList & stmts, std::string indent, llvm::raw_ostream & strm) {
    5152    for (const Statement * stmt : stmts) {
    5253        print(stmt, indent, strm);
    53         strm << std::endl;
     54        strm << "\n";
    5455    }
    5556}
    5657
    57 void PabloPrinter::print_vars(const DefinedVars & vars, std::string indent, std::ostream & strm) {
     58void PabloPrinter::print_vars(const DefinedVars & vars, std::string indent, llvm::raw_ostream & strm) {
    5859    for (const PabloAST * v : vars) {
    59         strm << indent << dyn_cast<Assign>(v)->getName() << " = 0" << std::endl;
     60        strm << indent << dyn_cast<Assign>(v)->getName() << " = 0" << "\n";
    6061    }
    6162}
    6263
    63 void PabloPrinter::print(const Statement * stmt, std::string indent, std::ostream & strm) {
     64void PabloPrinter::print(const Statement * stmt, std::string indent, llvm::raw_ostream & strm) {
    6465    strm << indent;
    6566    if (stmt == nullptr) {
     
    8081        strm << "if ";
    8182        print(ifstmt->getCondition(), strm);
    82         strm << ":" << std::endl;
     83        strm << ":" << "\n";
    8384        print(ifstmt->getBody(), indent + "  ", strm);
    84         strm << indent << "else:" << std::endl;
     85        strm << indent << "else:" << "\n";
    8586        print_vars(ifstmt->getDefined(), indent + "  ", strm);
    8687    }
     
    8889        strm << "while ";
    8990        print(whl->getCondition(), strm);
    90         strm << ":" << std::endl;
     91        strm << ":" << "\n";
    9192        print(whl->getBody(), indent + "  ", strm);
    9293    }
     
    158159    }
    159160    else {
    160         strm << indent << "**UNKNOWN Pablo Statement type **" << std::endl;
     161        strm << indent << "**UNKNOWN Pablo Statement type **" << "\n";
    161162    }
    162163}
    163164
    164 void PabloPrinter::print(const PabloAST * expr, std::ostream & strm) {
     165void PabloPrinter::print(const PabloAST * expr, llvm::raw_ostream & strm) {
    165166    if (expr == nullptr) {
    166167        strm << "<null-expr>";
     
    179180    }
    180181    else {
    181         strm << "**UNKNOWN Pablo Expression type **\n" << std::endl;
     182        strm << "**UNKNOWN Pablo Expression type **\n" << "\n";
    182183    }
    183184}
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.h

    r4518 r4567  
    1111#include <pablo/ps_if.h>
    1212#include <string>
     13#include <llvm/Support/raw_os_ostream.h>
    1314
    1415namespace pablo {
     
    1920public:
    2021    using DefinedVars = std::vector<pablo::PabloAST *, pablo::PabloAST::VectorAllocator>;
    21     static void print(const pablo::PabloBlock & block, std::ostream & strm);
    22     static void print(const pablo::StatementList & stmts, std::ostream & strm);
    23     static void print(const pablo::StatementList & stmts, std::string indent, std::ostream & strm);
    24     static void print_vars(const DefinedVars & vars, std::string indent, std::ostream & strm);
    25     static void print(const pablo::PabloAST * expr, std::ostream & strm);
    26     static void print(const pablo::Statement *stmt, std::string indent, std::ostream & strm);
     22    static void print(const pablo::PabloBlock & block, llvm::raw_ostream & strm);
     23    static void print(const pablo::StatementList & stmts, llvm::raw_ostream & strm);
     24    static void print(const pablo::StatementList & stmts, std::string indent, llvm::raw_ostream & strm);
     25    static void print_vars(const DefinedVars & vars, std::string indent, llvm::raw_ostream & strm);
     26    static void print(const pablo::PabloAST * expr, llvm::raw_ostream & strm);
     27    static void print(const pablo::Statement *stmt, std::string indent, llvm::raw_ostream & strm);
    2728};
    2829
Note: See TracChangeset for help on using the changeset viewer.