Internalize llvm::AssemblyWriter. It's not used outside of AsmWriter.cpp.

This is an artifact of an implementation detail of DebugIR that has been
long refactored away. NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232532 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2015-03-17 19:53:41 +00:00
parent 5850602050
commit 93920f0bcd
2 changed files with 86 additions and 136 deletions

View File

@ -14,9 +14,9 @@
//
//===----------------------------------------------------------------------===//
#include "AsmWriter.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/IR/AssemblyAnnotationWriter.h"
@ -32,6 +32,7 @@
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/TypeFinder.h"
#include "llvm/IR/UseListOrder.h"
#include "llvm/IR/ValueSymbolTable.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Dwarf.h"
@ -387,7 +388,29 @@ static void PrintLLVMName(raw_ostream &OS, const Value *V) {
}
namespace llvm {
namespace {
class TypePrinting {
TypePrinting(const TypePrinting &) = delete;
void operator=(const TypePrinting&) = delete;
public:
/// NamedTypes - The named types that are used by the current module.
TypeFinder NamedTypes;
/// NumberedTypes - The numbered types, along with their value.
DenseMap<StructType*, unsigned> NumberedTypes;
TypePrinting() {}
~TypePrinting() {}
void incorporateTypes(const Module &M);
void print(Type *Ty, raw_ostream &OS);
void printStructBody(StructType *Ty, raw_ostream &OS);
};
} // namespace
void TypePrinting::incorporateTypes(const Module &M) {
NamedTypes.run(M, false);
@ -517,6 +540,7 @@ void TypePrinting::printStructBody(StructType *STy, raw_ostream &OS) {
OS << '>';
}
namespace {
//===----------------------------------------------------------------------===//
// SlotTracker Class: Enumerate slot numbers for unnamed values
//===----------------------------------------------------------------------===//
@ -635,8 +659,9 @@ private:
SlotTracker(const SlotTracker &) = delete;
void operator=(const SlotTracker &) = delete;
};
} // namespace
SlotTracker *createSlotTracker(const Module *M) {
static SlotTracker *createSlotTracker(const Module *M) {
return new SlotTracker(M);
}
@ -2046,6 +2071,64 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Metadata *MD,
WriteAsOperandInternal(Out, V->getValue(), TypePrinter, Machine, Context);
}
namespace {
class AssemblyWriter {
formatted_raw_ostream &Out;
const Module *TheModule;
std::unique_ptr<SlotTracker> ModuleSlotTracker;
SlotTracker &Machine;
TypePrinting TypePrinter;
AssemblyAnnotationWriter *AnnotationWriter;
SetVector<const Comdat *> Comdats;
UseListOrderStack UseListOrders;
public:
/// Construct an AssemblyWriter with an external SlotTracker
AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
const Module *M, AssemblyAnnotationWriter *AAW);
/// Construct an AssemblyWriter with an internally allocated SlotTracker
AssemblyWriter(formatted_raw_ostream &o, const Module *M,
AssemblyAnnotationWriter *AAW);
void printMDNodeBody(const MDNode *MD);
void printNamedMDNode(const NamedMDNode *NMD);
void printModule(const Module *M);
void writeOperand(const Value *Op, bool PrintType);
void writeParamOperand(const Value *Operand, AttributeSet Attrs,unsigned Idx);
void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope);
void writeAtomicCmpXchg(AtomicOrdering SuccessOrdering,
AtomicOrdering FailureOrdering,
SynchronizationScope SynchScope);
void writeAllMDNodes();
void writeMDNode(unsigned Slot, const MDNode *Node);
void writeAllAttributeGroups();
void printTypeIdentities();
void printGlobal(const GlobalVariable *GV);
void printAlias(const GlobalAlias *GV);
void printComdat(const Comdat *C);
void printFunction(const Function *F);
void printArgument(const Argument *FA, AttributeSet Attrs, unsigned Idx);
void printBasicBlock(const BasicBlock *BB);
void printInstructionLine(const Instruction &I);
void printInstruction(const Instruction &I);
void printUseListOrder(const UseListOrder &Order);
void printUseLists(const Function *F);
private:
void init();
// printInfoComment - Print a little comment after the instruction indicating
// which slot it occupies.
void printInfoComment(const Value &V);
};
} // namespace
void AssemblyWriter::init() {
if (!TheModule)
return;
@ -2073,8 +2156,6 @@ AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, const Module *M,
init();
}
AssemblyWriter::~AssemblyWriter() { }
void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType) {
if (!Operand) {
Out << "<null operand!>";
@ -3073,8 +3154,6 @@ void AssemblyWriter::writeAllAttributeGroups() {
<< I->first.getAsString(AttributeSet::FunctionIndex, true) << " }\n";
}
} // namespace llvm
void AssemblyWriter::printUseListOrder(const UseListOrder &Order) {
bool IsInFunction = Machine.getFunction();
if (IsInFunction)

View File

@ -1,129 +0,0 @@
//===-- llvm/IR/AsmWriter.h - Printing LLVM IR as an assembly file - C++ --===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This files defines the interface for the AssemblyWriter class used to print
// LLVM IR and various helper classes that are used in printing.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_IR_ASMWRITER_H
#define LLVM_LIB_IR_ASMWRITER_H
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/TypeFinder.h"
#include "llvm/IR/UseListOrder.h"
#include "llvm/Support/FormattedStream.h"
namespace llvm {
class BasicBlock;
class Function;
class GlobalValue;
class Comdat;
class Module;
class NamedMDNode;
class Value;
class SlotTracker;
/// Create a new SlotTracker for a Module
SlotTracker *createSlotTracker(const Module *M);
//===----------------------------------------------------------------------===//
// TypePrinting Class: Type printing machinery
//===----------------------------------------------------------------------===//
class TypePrinting {
TypePrinting(const TypePrinting &) = delete;
void operator=(const TypePrinting&) = delete;
public:
/// NamedTypes - The named types that are used by the current module.
TypeFinder NamedTypes;
/// NumberedTypes - The numbered types, along with their value.
DenseMap<StructType*, unsigned> NumberedTypes;
TypePrinting() {}
~TypePrinting() {}
void incorporateTypes(const Module &M);
void print(Type *Ty, raw_ostream &OS);
void printStructBody(StructType *Ty, raw_ostream &OS);
};
class AssemblyWriter {
protected:
formatted_raw_ostream &Out;
const Module *TheModule;
private:
std::unique_ptr<SlotTracker> ModuleSlotTracker;
SlotTracker &Machine;
TypePrinting TypePrinter;
AssemblyAnnotationWriter *AnnotationWriter;
SetVector<const Comdat *> Comdats;
UseListOrderStack UseListOrders;
public:
/// Construct an AssemblyWriter with an external SlotTracker
AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
const Module *M, AssemblyAnnotationWriter *AAW);
/// Construct an AssemblyWriter with an internally allocated SlotTracker
AssemblyWriter(formatted_raw_ostream &o, const Module *M,
AssemblyAnnotationWriter *AAW);
virtual ~AssemblyWriter();
void printMDNodeBody(const MDNode *MD);
void printNamedMDNode(const NamedMDNode *NMD);
void printModule(const Module *M);
void writeOperand(const Value *Op, bool PrintType);
void writeParamOperand(const Value *Operand, AttributeSet Attrs,unsigned Idx);
void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope);
void writeAtomicCmpXchg(AtomicOrdering SuccessOrdering,
AtomicOrdering FailureOrdering,
SynchronizationScope SynchScope);
void writeAllMDNodes();
void writeMDNode(unsigned Slot, const MDNode *Node);
void writeAllAttributeGroups();
void printTypeIdentities();
void printGlobal(const GlobalVariable *GV);
void printAlias(const GlobalAlias *GV);
void printComdat(const Comdat *C);
void printFunction(const Function *F);
void printArgument(const Argument *FA, AttributeSet Attrs, unsigned Idx);
void printBasicBlock(const BasicBlock *BB);
void printInstructionLine(const Instruction &I);
void printInstruction(const Instruction &I);
void printUseListOrder(const UseListOrder &Order);
void printUseLists(const Function *F);
private:
void init();
// printInfoComment - Print a little comment after the instruction indicating
// which slot it occupies.
void printInfoComment(const Value &V);
};
} // namespace llvm
#endif