+++ /dev/null
-//===-- llvm/Assembly/CachedWriter.h - Printer Accellerator -----*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines a 'CachedWriter' class that is used to accelerate printing
-// chunks of LLVM. This is used when a module is not being changed, but random
-// parts of it need to be printed. This can greatly speed up printing of LLVM
-// output.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_ASSEMBLY_CACHEDWRITER_H
-#define LLVM_ASSEMBLY_CACHEDWRITER_H
-
-#include "llvm/Value.h"
-#include <iostream>
-
-namespace llvm {
-
-class Module;
-class PointerType;
-class AssemblyWriter; // Internal private class
-class SlotMachine;
-
-class CachedWriter {
- AssemblyWriter *AW;
- SlotMachine *SC;
- bool SymbolicTypes;
- std::ostream &Out;
-
-public:
- enum TypeWriter {
- SymTypeOn,
- SymTypeOff
- };
-
- CachedWriter(std::ostream &O = std::cout)
- : AW(0), SC(0), SymbolicTypes(false), Out(O) { }
- CachedWriter(const Module *M, std::ostream &O = std::cout)
- : AW(0), SC(0), SymbolicTypes(false), Out(O) {
- setModule(M);
- }
- ~CachedWriter();
-
- // setModule - Invalidate internal state, use the new module instead.
- void setModule(const Module *M);
-
- CachedWriter &operator<<(const Value &V);
-
- CachedWriter &operator<<(const Type &X);
-
- inline CachedWriter &operator<<(std::ostream &(&Manip)(std::ostream &)) {
- Out << Manip; return *this;
- }
-
- inline CachedWriter& operator<<(const char *X) {
- Out << X;
- return *this;
- }
-
- inline CachedWriter &operator<<(enum TypeWriter tw) {
- SymbolicTypes = (tw == SymTypeOn);
- return *this;
- }
-};
-
-} // End llvm namespace
-
-#endif
//
//===----------------------------------------------------------------------===//
-#include "llvm/Assembly/CachedWriter.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Assembly/PrintModulePass.h"
#include "llvm/Assembly/AsmAnnotationWriter.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Streams.h"
#include <algorithm>
+#include <iostream>
using namespace llvm;
namespace llvm {
break;
default:
Result += "<unrecognized-type>";
+ break;
}
TypeStack.pop_back(); // Remove self from stack...
- return;
}
const Module *M) {
Out << ' ';
- // If they want us to print out a type, attempt to make it symbolic if there
- // is a symbol table in the module...
- if (M) {
- std::map<const Type *, std::string> TypeNames;
- fillTypeNameTable(M, TypeNames);
-
- return printTypeInt(Out, Ty, TypeNames);
- } else {
+ // If they want us to print out a type, but there is no context, we can't
+ // print it symbolically.
+ if (!M)
return Out << Ty->getDescription();
- }
+
+ std::map<const Type *, std::string> TypeNames;
+ fillTypeNameTable(M, TypeNames);
+ return printTypeInt(Out, Ty, TypeNames);
}
// PrintEscapedString - Print each character of the specified string, escaping
}
}
-static const char * getPredicateText(unsigned predicate) {
+static const char *getPredicateText(unsigned predicate) {
const char * pred = "unknown";
switch (predicate) {
case FCmpInst::FCMP_FALSE: pred = "false"; break;
void Type::dump() const { print(std::cerr); llvm_cerr << '\n'; }
//===----------------------------------------------------------------------===//
-// CachedWriter Class Implementation
-//===----------------------------------------------------------------------===//
-
-void CachedWriter::setModule(const Module *M) {
- delete SC; delete AW;
- if (M) {
- SC = new SlotMachine(M);
- AW = new AssemblyWriter(Out, *SC, M, 0);
- } else {
- SC = 0; AW = 0;
- }
-}
-
-CachedWriter::~CachedWriter() {
- delete AW;
- delete SC;
-}
-
-CachedWriter &CachedWriter::operator<<(const Value &V) {
- assert(AW && SC && "CachedWriter does not have a current module!");
- if (const Instruction *I = dyn_cast<Instruction>(&V))
- AW->write(I);
- else if (const BasicBlock *BB = dyn_cast<BasicBlock>(&V))
- AW->write(BB);
- else if (const Function *F = dyn_cast<Function>(&V))
- AW->write(F);
- else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(&V))
- AW->write(GV);
- else
- AW->writeOperand(&V, true);
- return *this;
-}
-
-CachedWriter& CachedWriter::operator<<(const Type &Ty) {
- if (SymbolicTypes) {
- const Module *M = AW->getModule();
- if (M) WriteTypeSymbolic(Out, &Ty, M);
- } else {
- AW->write(&Ty);
- }
- return *this;
-}
-
-//===----------------------------------------------------------------------===//
-//===-- SlotMachine Implementation
+// SlotMachine Implementation
//===----------------------------------------------------------------------===//
#if 0