<commit_before>//===--- VMCore/PrintModulePass.cpp - Module/Function Printer -------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// PrintModulePass and PrintFunctionPass implementations.
//
//===----------------------------------------------------------------------===//

#include "llvm/Assembly/PrintModulePass.h"

#include "llvm/Function.h"
#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;

namespace {

  class VISIBILITY_HIDDEN PrintModulePass : public ModulePass {
    raw_ostream *Out;       // raw_ostream to print on
    bool DeleteStream;      // Delete the ostream in our dtor?
  public:
    static char ID;
    PrintModulePass() : ModulePass(&ID), Out(&errs()), 
      DeleteStream(false) {}
    PrintModulePass(raw_ostream *o, bool DS)
      : ModulePass(&ID), Out(o), DeleteStream(DS) {}
    
    ~PrintModulePass() {
      if (DeleteStream) delete Out;
    }
    
    bool runOnModule(Module &M) {
      (*Out) << M;
      Out->flush();
      return false;
    }
    
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.setPreservesAll();
    }
  };
  
  class PrintFunctionPass : public FunctionPass {
    std::string Banner;     // String to print before each function
    raw_ostream *Out;       // raw_ostream to print on
    bool DeleteStream;      // Delete the ostream in our dtor?
  public:
    static char ID;
    PrintFunctionPass() : FunctionPass(&ID), Banner(""), Out(&errs()), 
                          DeleteStream(false) {}
    PrintFunctionPass(const std::string &B, raw_ostream *o, bool DS)
      : FunctionPass(&ID), Banner(B), Out(o), DeleteStream(DS) {}
    
    inline ~PrintFunctionPass() {
      if (DeleteStream) delete Out;
    }
    
    // runOnFunction - This pass just prints a banner followed by the
    // function as it's processed.
    //
    bool runOnFunction(Function &F) {
      (*Out) << Banner << static_cast<Value&>(F);
      Out->flush();
      return false;
    }
    
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.setPreservesAll();
    }
  };
}

char PrintModulePass::ID = 0;
static RegisterPass<PrintModulePass>
X("print-module", "Print module to stderr");
char PrintFunctionPass::ID = 0;
static RegisterPass<PrintFunctionPass>
Y("print-function","Print function to stderr");
<commit_msg>It's not necessary for PrintModulePass to flush the output streams now that errs() is properly non-buffered.<commit_after>//===--- VMCore/PrintModulePass.cpp - Module/Function Printer -------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// PrintModulePass and PrintFunctionPass implementations.
//
//===----------------------------------------------------------------------===//

#include "llvm/Assembly/PrintModulePass.h"

#include "llvm/Function.h"
#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;

namespace {

  class VISIBILITY_HIDDEN PrintModulePass : public ModulePass {
    raw_ostream *Out;       // raw_ostream to print on
    bool DeleteStream;      // Delete the ostream in our dtor?
  public:
    static char ID;
    PrintModulePass() : ModulePass(&ID), Out(&errs()), 
      DeleteStream(false) {}
    PrintModulePass(raw_ostream *o, bool DS)
      : ModulePass(&ID), Out(o), DeleteStream(DS) {}
    
    ~PrintModulePass() {
      if (DeleteStream) delete Out;
    }
    
    bool runOnModule(Module &M) {
      (*Out) << M;
      return false;
    }
    
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.setPreservesAll();
    }
  };
  
  class PrintFunctionPass : public FunctionPass {
    std::string Banner;     // String to print before each function
    raw_ostream *Out;       // raw_ostream to print on
    bool DeleteStream;      // Delete the ostream in our dtor?
  public:
    static char ID;
    PrintFunctionPass() : FunctionPass(&ID), Banner(""), Out(&errs()), 
                          DeleteStream(false) {}
    PrintFunctionPass(const std::string &B, raw_ostream *o, bool DS)
      : FunctionPass(&ID), Banner(B), Out(o), DeleteStream(DS) {}
    
    inline ~PrintFunctionPass() {
      if (DeleteStream) delete Out;
    }
    
    // runOnFunction - This pass just prints a banner followed by the
    // function as it's processed.
    //
    bool runOnFunction(Function &F) {
      (*Out) << Banner << static_cast<Value&>(F);
      return false;
    }
    
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.setPreservesAll();
    }
  };
}

char PrintModulePass::ID = 0;
static RegisterPass<PrintModulePass>
X("print-module", "Print module to stderr");
char PrintFunctionPass::ID = 0;
static RegisterPass<PrintFunctionPass>
Y("print-function","Print function to stderr");

{'fraction_non_alphanumeric': 0.17925421162218436, 'fraction_numerical': 0.0007571455612341472, 'mean_word_length': 2.335858585858586, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2110673', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1478, 'n_words': 407}