llvm.org GIT mirror llvm / cb37188
Use raw_ostream throughout the AsmPrinter. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55092 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 11 years ago
66 changed file(s) with 453 addition(s) and 185 deletion(s). Raw diff Collapse all Expand all
3333 class Mangler;
3434 class TargetAsmInfo;
3535 class Type;
36 class raw_ostream;
3637
3738 /// AsmPrinter - This class is intended to be used as a driving class for all
3839 /// asm writers.
6364 public:
6465 /// Output stream on which we're printing assembly code.
6566 ///
66 std::ostream &O;
67 raw_ostream &O;
6768
6869 /// Target machine description.
6970 ///
9596 bool IsInTextSection;
9697
9798 protected:
98 AsmPrinter(std::ostream &o, TargetMachine &TM, const TargetAsmInfo *T);
99 AsmPrinter(raw_ostream &o, TargetMachine &TM, const TargetAsmInfo *T);
99100
100101 public:
101102 virtual ~AsmPrinter();
3030 class MachineFunction;
3131 class Module;
3232 class TargetAsmInfo;
33 class raw_ostream;
3334
3435 //===----------------------------------------------------------------------===//
3536 // DwarfWriter - Emits Dwarf debug and exception handling directives.
4748
4849 public:
4950
50 DwarfWriter(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T);
51 DwarfWriter(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T);
5152 virtual ~DwarfWriter();
5253
5354 /// SetModuleInfo - Set machine module info when it's known that pass manager
2020 class PassManagerBase;
2121 class MachineCodeEmitter;
2222 class TargetMachine;
23 class raw_ostream;
2324
24 MachineCodeEmitter *AddELFWriter(PassManagerBase &FPM, std::ostream &O,
25 MachineCodeEmitter *AddELFWriter(PassManagerBase &FPM, raw_ostream &O,
2526 TargetMachine &TM);
26 MachineCodeEmitter *AddMachOWriter(PassManagerBase &FPM, std::ostream &O,
27 MachineCodeEmitter *AddMachOWriter(PassManagerBase &FPM, raw_ostream &O,
2728 TargetMachine &TM);
2829
2930 } // end llvm namespace
2828 namespace llvm {
2929
3030 class GCMetadataPrinter;
31 class raw_ostream;
3132
3233 /// GCMetadataPrinterRegistry - The GC assembly printer registry uses all the
3334 /// defaults from Registry.
6263 iterator end() { return S->end(); }
6364
6465 /// beginAssembly/finishAssembly - Emit module metadata as assembly code.
65 virtual void beginAssembly(std::ostream &OS, AsmPrinter &AP,
66 virtual void beginAssembly(raw_ostream &OS, AsmPrinter &AP,
6667 const TargetAsmInfo &TAI);
6768
68 virtual void finishAssembly(std::ostream &OS, AsmPrinter &AP,
69 virtual void finishAssembly(raw_ostream &OS, AsmPrinter &AP,
6970 const TargetAsmInfo &TAI);
7071
7172 virtual ~GCMetadataPrinter();
257257 }
258258 void print(std::ostream &OS, const TargetMachine *TM = 0) const;
259259 void print(std::ostream *OS) const { if (OS) print(*OS); }
260 void print(raw_ostream *OS, const TargetMachine *TM) const {
261 if (OS) print(*OS, TM);
262 }
263 void print(raw_ostream &OS, const TargetMachine *TM = 0) const;
264 void print(raw_ostream *OS) const { if (OS) print(*OS); }
260265 void dump() const;
261266
262267 //===--------------------------------------------------------------------===//
315320 return OS;
316321 }
317322
323 inline raw_ostream& operator<<(raw_ostream &OS, const MachineInstr &MI) {
324 MI.print(OS);
325 return OS;
326 }
327
318328 } // End llvm namespace
319329
320330 #endif
2525 class MachineInstr;
2626 class TargetMachine;
2727 class MachineRegisterInfo;
28 class raw_ostream;
2829
2930 /// MachineOperand class - Representation of each machine instruction operand.
3031 ///
116117 const MachineInstr *getParent() const { return ParentMI; }
117118
118119 void print(std::ostream &os, const TargetMachine *TM = 0) const;
120 void print(raw_ostream &os, const TargetMachine *TM = 0) const;
119121
120122 /// Accessors that tell you what kind of MachineOperand you're looking at.
121123 ///
424426 return OS;
425427 }
426428
429 inline raw_ostream &operator<<(raw_ostream &OS, const MachineOperand& MO) {
430 MO.print(OS, 0);
431 return OS;
432 }
433
427434 } // End llvm namespace
428435
429436 #endif
1313 #ifndef LLVM_SUPPORT_RAW_OSTREAM_H
1414 #define LLVM_SUPPORT_RAW_OSTREAM_H
1515
16 #include "llvm/ADT/StringExtras.h"
1617 #include
1718 #include
1819 #include
7172 return write(Str, strlen(Str));
7273 }
7374
74 raw_ostream &operator<<(unsigned N) {
75 raw_ostream &operator<<(const std::string& Str) {
76 return write(Str.data(), Str.length());
77 }
78
79 raw_ostream &operator<<(uint64_t N) {
7580 // Zero is a special case.
7681 if (N == 0)
7782 return *this << '0';
8590 N /= 10;
8691 }
8792 return write(CurPtr, EndPtr-CurPtr);
93 }
94
95 raw_ostream &operator<<(int64_t N) {
96 if (N < 0) {
97 if (OutBufCur >= OutBufEnd)
98 flush_impl();
99 *OutBufCur++ = '-';
100
101 N = -N;
102 }
103
104 return this->operator<<(static_cast(N));
105 }
106
107 raw_ostream &operator<<(uint32_t N) {
108 return this->operator<<(static_cast(N));
109 }
110
111 raw_ostream &operator<<(int32_t N) {
112 return this->operator<<(static_cast(N));
113 }
114
115 raw_ostream &operator<<(size_t N) {
116 return this->operator<<(static_cast(N));
117 }
118
119 raw_ostream &operator<<(double N) {
120 return this->operator<<(ftostr(N));
88121 }
89122
90123
3434 class Pass;
3535 class TargetMachOWriterInfo;
3636 class TargetELFWriterInfo;
37 class raw_ostream;
3738
3839 // Relocation model types.
3940 namespace Reloc {
195196 /// is not supported.
196197 ///
197198 virtual FileModel::Model addPassesToEmitFile(PassManagerBase &,
198 std::ostream &,
199 raw_ostream &,
199200 CodeGenFileType,
200201 bool /*Fast*/) {
201202 return FileModel::None;
226227 /// require having the entire module at once. This is not recommended, do not
227228 /// use this.
228229 virtual bool WantsWholeFile() const { return false; }
229 virtual bool addPassesToEmitWholeFile(PassManager &, std::ostream &,
230 virtual bool addPassesToEmitWholeFile(PassManager &, raw_ostream &,
230231 CodeGenFileType, bool /*Fast*/) {
231232 return true;
232233 }
252253 /// target-specific passes in standard locations.
253254 ///
254255 virtual FileModel::Model addPassesToEmitFile(PassManagerBase &PM,
255 std::ostream &Out,
256 raw_ostream &Out,
256257 CodeGenFileType FileType,
257258 bool Fast);
258259
308309 /// the asmprinter, if asm emission is supported. If this is not supported,
309310 /// 'true' should be returned.
310311 virtual bool addAssemblyEmitter(PassManagerBase &, bool /*Fast*/,
311 std::ostream &) {
312 raw_ostream &) {
312313 return true;
313314 }
314315
2020 #include "llvm/CodeGen/MachineJumpTableInfo.h"
2121 #include "llvm/CodeGen/MachineModuleInfo.h"
2222 #include "llvm/Support/Mangler.h"
23 #include "llvm/Support/MathExtras.h"
23 #include "llvm/Support/raw_ostream.h"
2424 #include "llvm/Support/Streams.h"
2525 #include "llvm/Target/TargetAsmInfo.h"
2626 #include "llvm/Target/TargetData.h"
3030 #include "llvm/Target/TargetRegisterInfo.h"
3131 #include "llvm/ADT/SmallPtrSet.h"
3232 #include "llvm/ADT/SmallString.h"
33 #include "llvm/ADT/StringExtras.h"
3334 #include
3435 using namespace llvm;
3536
3637 char AsmPrinter::ID = 0;
37 AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm,
38 AsmPrinter::AsmPrinter(raw_ostream &o, TargetMachine &tm,
3839 const TargetAsmInfo *T)
3940 : MachineFunctionPass((intptr_t)&ID), FunctionNumber(0), O(o),
4041 TM(tm), TAI(T), TRI(tm.getRegisterInfo()),
267268 EmitAlignment(Alignment);
268269 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
269270 O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
270 << CP[i].second << ":\t\t\t\t\t" << TAI->getCommentString() << ' ';
271 WriteTypeSymbolic(O, CP[i].first.getType(), 0);
271 << CP[i].second << ":\t\t\t\t\t";
272 // O << TAI->getCommentString() << ' ' <<
273 // WriteTypeSymbolic(O, CP[i].first.getType(), 0);
272274 O << '\n';
273275 if (CP[i].first.isMachineConstantPoolEntry())
274276 EmitMachineConstantPoolValue(CP[i].first.Val.MachineCPVal);
494496 unsigned Byte = Value & 0x7f;
495497 Value >>= 7;
496498 if (Value) Byte |= 0x80;
497 O << "0x" << std::hex << Byte << std::dec;
499 O << "0x" << utohexstr(Byte);
498500 if (Value) O << ", ";
499501 } while (Value);
500502 }
510512 Value >>= 7;
511513 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
512514 if (IsMore) Byte |= 0x80;
513 O << "0x" << std::hex << Byte << std::dec;
515 O << "0x" << utohexstr(Byte);
514516 if (IsMore) O << ", ";
515517 } while (IsMore);
516518 }
522524 /// PrintHex - Print a value as a hexidecimal value.
523525 ///
524526 void AsmPrinter::PrintHex(int Value) const {
525 O << "0x" << std::hex << Value << std::dec;
527 O << "0x" << utohexstr(static_cast(Value));
526528 }
527529
528530 /// EOL - Print a newline character to asm stream. If a comment is present
621623
622624 /// printStringChar - Print a char, escaped if necessary.
623625 ///
624 static void printStringChar(std::ostream &O, unsigned char C) {
626 static void printStringChar(raw_ostream &O, char C) {
625627 if (C == '"') {
626628 O << "\\\"";
627629 } else if (C == '\\') {
705707
706708 unsigned FillValue = TAI->getTextAlignFillValue();
707709 UseFillExpr &= IsInTextSection && FillValue;
708 if (UseFillExpr) O << ",0x" << std::hex << FillValue << std::dec;
710 if (UseFillExpr) O << ",0x" << utohexstr(FillValue);
709711 O << '\n';
710712 }
711713
854856 /// printAsCString - Print the specified array as a C compatible string, only if
855857 /// the predicate isString is true.
856858 ///
857 static void printAsCString(std::ostream &O, const ConstantArray *CVA,
859 static void printAsCString(raw_ostream &O, const ConstantArray *CVA,
858860 unsigned LastElt) {
859861 assert(CVA->isString() && "Array is not string compatible!");
860862
2727 #include "llvm/Support/CommandLine.h"
2828 #include "llvm/Support/DataTypes.h"
2929 #include "llvm/Support/Mangler.h"
30 #include "llvm/Support/raw_ostream.h"
3031 #include "llvm/System/Path.h"
3132 #include "llvm/Target/TargetAsmInfo.h"
3233 #include "llvm/Target/TargetRegisterInfo.h"
819820 //
820821 /// O - Stream to .s file.
821822 ///
822 std::ostream &O;
823 raw_ostream &O;
823824
824825 /// Asm - Target of Dwarf emission.
825826 ///
855856 const char * const Flavor;
856857
857858 unsigned SetCounter;
858 Dwarf(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T,
859 Dwarf(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T,
859860 const char *flavor)
860861 : O(OS)
861862 , Asm(A)
26722673 //===--------------------------------------------------------------------===//
26732674 // Main entry points.
26742675 //
2675 DwarfDebug(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
2676 DwarfDebug(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
26762677 : Dwarf(OS, A, T, "dbg")
26772678 , CompileUnits()
26782679 , AbbreviationsSet(InitAbbreviationsSetSize)
34783479 //===--------------------------------------------------------------------===//
34793480 // Main entry points.
34803481 //
3481 DwarfException(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
3482 DwarfException(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
34823483 : Dwarf(OS, A, T, "eh")
34833484 , shouldEmitTable(false)
34843485 , shouldEmitMoves(false)
38783879 /// DwarfWriter Implementation
38793880 ///
38803881
3881 DwarfWriter::DwarfWriter(std::ostream &OS, AsmPrinter *A,
3882 DwarfWriter::DwarfWriter(raw_ostream &OS, AsmPrinter *A,
38823883 const TargetAsmInfo *T) {
38833884 DE = new DwarfException(OS, A, T);
38843885 DD = new DwarfDebug(OS, A, T);
1414 #include "llvm/CodeGen/AsmPrinter.h"
1515 #include "llvm/CodeGen/GCMetadataPrinter.h"
1616 #include "llvm/Module.h"
17 #include "llvm/Support/raw_ostream.h"
1718 #include "llvm/Target/TargetAsmInfo.h"
1819 #include "llvm/Target/TargetData.h"
1920 #include "llvm/Target/TargetMachine.h"
2425
2526 class VISIBILITY_HIDDEN OcamlGCMetadataPrinter : public GCMetadataPrinter {
2627 public:
27 void beginAssembly(std::ostream &OS, AsmPrinter &AP,
28 void beginAssembly(raw_ostream &OS, AsmPrinter &AP,
2829 const TargetAsmInfo &TAI);
2930
30 void finishAssembly(std::ostream &OS, AsmPrinter &AP,
31 void finishAssembly(raw_ostream &OS, AsmPrinter &AP,
3132 const TargetAsmInfo &TAI);
3233 };
3334
3839
3940 void llvm::linkOcamlGCPrinter() { }
4041
41 static void EmitCamlGlobal(const Module &M, std::ostream &OS, AsmPrinter &AP,
42 static void EmitCamlGlobal(const Module &M, raw_ostream &OS, AsmPrinter &AP,
4243 const TargetAsmInfo &TAI, const char *Id) {
4344 const std::string &MId = M.getModuleIdentifier();
4445
5859 OS << Mangled << ":\n";
5960 }
6061
61 void OcamlGCMetadataPrinter::beginAssembly(std::ostream &OS, AsmPrinter &AP,
62 void OcamlGCMetadataPrinter::beginAssembly(raw_ostream &OS, AsmPrinter &AP,
6263 const TargetAsmInfo &TAI) {
6364 AP.SwitchToTextSection(TAI.getTextSection());
6465 EmitCamlGlobal(getModule(), OS, AP, TAI, "code_begin");
8384 /// (FrameSize and LiveOffsets would overflow). FrameTablePrinter will abort if
8485 /// either condition is detected in a function which uses the GC.
8586 ///
86 void OcamlGCMetadataPrinter::finishAssembly(std::ostream &OS, AsmPrinter &AP,
87 void OcamlGCMetadataPrinter::finishAssembly(raw_ostream &OS, AsmPrinter &AP,
8788 const TargetAsmInfo &TAI) {
8889 const char *AddressDirective;
8990 int AddressAlignLog;
4343 #include "llvm/Support/Mangler.h"
4444 #include "llvm/Support/OutputBuffer.h"
4545 #include "llvm/Support/Streams.h"
46 #include "llvm/Support/raw_ostream.h"
4647 #include
4748 using namespace llvm;
4849
5051 /// AddELFWriter - Concrete function to add the ELF writer to the function pass
5152 /// manager.
5253 MachineCodeEmitter *llvm::AddELFWriter(PassManagerBase &PM,
53 std::ostream &O,
54 raw_ostream &O,
5455 TargetMachine &TM) {
5556 ELFWriter *EW = new ELFWriter(O, TM);
5657 PM.add(EW);
192193 // ELFWriter Implementation
193194 //===----------------------------------------------------------------------===//
194195
195 ELFWriter::ELFWriter(std::ostream &o, TargetMachine &tm)
196 ELFWriter::ELFWriter(raw_ostream &o, TargetMachine &tm)
196197 : MachineFunctionPass((intptr_t)&ID), O(o), TM(tm) {
197198 e_flags = 0; // e_flags defaults to 0, no flags.
198199
535536 if (S.Align)
536537 for (size_t NewFileOff = (FileOff+S.Align-1) & ~(S.Align-1);
537538 FileOff != NewFileOff; ++FileOff)
538 O.put((char)0xAB);
539 O << (char)0xAB;
539540 O.write((char*)&S.SectionData[0], S.SectionData.size());
540541 FileOff += S.SectionData.size();
541542
556557 // Align output for the section table.
557558 for (size_t NewFileOff = (FileOff+TableAlign-1) & ~(TableAlign-1);
558559 FileOff != NewFileOff; ++FileOff)
559 O.put((char)0xAB);
560 O << (char)0xAB;
560561
561562 // Emit the section table itself.
562563 O.write((char*)&Table[0], Table.size());
2222 class Mangler;
2323 class MachineCodeEmitter;
2424 class ELFCodeEmitter;
25 class raw_ostream;
2526
2627 /// ELFWriter - This class implements the common target-independent code for
2728 /// writing ELF files. Targets should derive a class from this to
3637 return *(MachineCodeEmitter*)MCE;
3738 }
3839
39 ELFWriter(std::ostream &O, TargetMachine &TM);
40 ELFWriter(raw_ostream &O, TargetMachine &TM);
4041 ~ELFWriter();
4142
4243 typedef std::vector DataBuffer;
4445 protected:
4546 /// Output stream to send the resultant object file to.
4647 ///
47 std::ostream &O;
48 raw_ostream &O;
4849
4950 /// Target machine description.
5051 ///
1818
1919 GCMetadataPrinter::~GCMetadataPrinter() { }
2020
21 void GCMetadataPrinter::beginAssembly(std::ostream &OS, AsmPrinter &AP,
21 void GCMetadataPrinter::beginAssembly(raw_ostream &OS, AsmPrinter &AP,
2222 const TargetAsmInfo &TAI) {
2323 // Default is no action.
2424 }
2525
26 void GCMetadataPrinter::finishAssembly(std::ostream &OS, AsmPrinter &AP,
26 void GCMetadataPrinter::finishAssembly(raw_ostream &OS, AsmPrinter &AP,
2727 const TargetAsmInfo &TAI) {
2828 // Default is no action.
2929 }
2121 #include "llvm/Target/TargetAsmInfo.h"
2222 #include "llvm/Transforms/Scalar.h"
2323 #include "llvm/Support/CommandLine.h"
24 #include "llvm/Support/raw_ostream.h"
2425 using namespace llvm;
2526
2627 static cl::opt PrintLSR("print-lsr-output", cl::Hidden,
4950
5051 FileModel::Model
5152 LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
52 std::ostream &Out,
53 raw_ostream &Out,
5354 CodeGenFileType FileType,
5455 bool Fast) {
5556 // Standard LLVM-Level Passes.
3636 #include "llvm/Support/MathExtras.h"
3737 #include "llvm/Support/OutputBuffer.h"
3838 #include "llvm/Support/Streams.h"
39 #include "llvm/Support/raw_ostream.h"
3940 #include
4041 #include
4142 using namespace llvm;
4344 /// AddMachOWriter - Concrete function to add the Mach-O writer to the function
4445 /// pass manager.
4546 MachineCodeEmitter *llvm::AddMachOWriter(PassManagerBase &PM,
46 std::ostream &O,
47 raw_ostream &O,
4748 TargetMachine &TM) {
4849 MachOWriter *MOW = new MachOWriter(O, TM);
4950 PM.add(MOW);
333334 //===----------------------------------------------------------------------===//
334335
335336 char MachOWriter::ID = 0;
336 MachOWriter::MachOWriter(std::ostream &o, TargetMachine &tm)
337 MachOWriter::MachOWriter(raw_ostream &o, TargetMachine &tm)
337338 : MachineFunctionPass((intptr_t)&ID), O(o), TM(tm) {
338339 is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64;
339340 isLittleEndian = TM.getTargetData()->isLittleEndian();
2828 class MachineCodeEmitter;
2929 class MachOCodeEmitter;
3030 class OutputBuffer;
31 class raw_ostream;
3132
3233 /// MachOSym - This struct contains information about each symbol that is
3334 /// added to logical symbol table for the module. This is eventually
8990 return *(MachineCodeEmitter*)MCE;
9091 }
9192
92 MachOWriter(std::ostream &O, TargetMachine &TM);
93 MachOWriter(raw_ostream &O, TargetMachine &TM);
9394 virtual ~MachOWriter();
9495
9596 virtual const char *getPassName() const {
100101 protected:
101102 /// Output stream to send the resultant object file to.
102103 ///
103 std::ostream &O;
104 raw_ostream &O;
104105
105106 /// Target machine description.
106107 ///
1818
1919 #if defined(_MSC_VER)
2020 #include
21 #ifndef STDIN_FILENO
22 # define STDIN_FILENO 0
23 #endif
24 #ifndef STDOUT_FILENO
25 # define STDOUT_FILENO 1
26 #endif
27 #ifndef STDERR_FILENO
28 # define STDERR_FILENO 2
29 #endif
21 #ifndef STDIN_FILENO
22 # define STDIN_FILENO 0
23 #endif
24 #ifndef STDOUT_FILENO
25 # define STDOUT_FILENO 1
26 #endif
27 #ifndef STDERR_FILENO
28 # define STDERR_FILENO 2
29 #endif
3030 #endif
3131
3232 // An out of line virtual method to provide a home for the class vtable.
8181
8282 /// outs() - This returns a reference to a raw_ostream for standard output.
8383 /// Use it like: outs() << "foo" << "bar";
84 raw_ostream &outs() {
84 raw_ostream &llvm::outs() {
8585 static raw_stdout_ostream S;
8686 return S;
8787 }
8888
8989 /// errs() - This returns a reference to a raw_ostream for standard error.
9090 /// Use it like: errs() << "foo" << "bar";
91 raw_ostream &errs() {
91 raw_ostream &llvm::errs() {
9292 static raw_stderr_ostream S;
9393 return S;
9494 }
2222 class ARMTargetMachine;
2323 class FunctionPass;
2424 class MachineCodeEmitter;
25 class raw_ostream;
2526
2627 // Enums corresponding to ARM condition codes
2728 namespace ARMCC {
8687 }
8788
8889 FunctionPass *createARMISelDag(ARMTargetMachine &TM);
89 FunctionPass *createARMCodePrinterPass(std::ostream &O, ARMTargetMachine &TM);
90 FunctionPass *createARMCodePrinterPass(raw_ostream &O, ARMTargetMachine &TM);
9091 FunctionPass *createARMCodeEmitterPass(ARMTargetMachine &TM,
9192 MachineCodeEmitter &MCE);
9293 FunctionPass *createARMLoadStoreOptimizationPass();
1717 #include "llvm/PassManager.h"
1818 #include "llvm/CodeGen/Passes.h"
1919 #include "llvm/Support/CommandLine.h"
20 #include "llvm/Support/raw_ostream.h"
2021 #include "llvm/Target/TargetMachineRegistry.h"
2122 #include "llvm/Target/TargetOptions.h"
2223 using namespace llvm;
142143 }
143144
144145 bool ARMTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
145 std::ostream &Out) {
146 raw_ostream &Out) {
146147 // Output assembly language.
147148 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
148149 if (AsmPrinterCtor)
162163 if (DumpAsm) {
163164 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
164165 if (AsmPrinterCtor)
165 PM.add(AsmPrinterCtor(*cerr.stream(), *this));
166 PM.add(AsmPrinterCtor(errs(), *this));
166167 }
167168
168169 return false;
175176 if (DumpAsm) {
176177 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
177178 if (AsmPrinterCtor)
178 PM.add(AsmPrinterCtor(*cerr.stream(), *this));
179 PM.add(AsmPrinterCtor(errs(), *this));
179180 }
180181
181182 return false;
3737 protected:
3838 // To avoid having target depend on the asmprinter stuff libraries, asmprinter
3939 // set this functions to ctor pointer at startup time if they are linked in.
40 typedef FunctionPass *(*AsmPrinterCtorFn)(std::ostream &o,
40 typedef FunctionPass *(*AsmPrinterCtorFn)(raw_ostream &o,
4141 ARMTargetMachine &tm);
4242 static AsmPrinterCtorFn AsmPrinterCtor;
4343
6969 virtual bool addInstSelector(PassManagerBase &PM, bool Fast);
7070 virtual bool addPreEmitPass(PassManagerBase &PM, bool Fast);
7171 virtual bool addAssemblyEmitter(PassManagerBase &PM, bool Fast,
72 std::ostream &Out);
72 raw_ostream &Out);
7373 virtual bool addCodeEmitter(PassManagerBase &PM, bool Fast,
7474 bool DumpAsm, MachineCodeEmitter &MCE);
7575 virtual bool addSimpleCodeEmitter(PassManagerBase &PM, bool Fast,
3434 #include "llvm/Support/Compiler.h"
3535 #include "llvm/Support/Mangler.h"
3636 #include "llvm/Support/MathExtras.h"
37 #include "llvm/Support/raw_ostream.h"
3738 #include
3839 using namespace llvm;
3940
4142
4243 namespace {
4344 struct VISIBILITY_HIDDEN ARMAsmPrinter : public AsmPrinter {
44 ARMAsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
45 ARMAsmPrinter(raw_ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
4546 : AsmPrinter(O, TM, T), DW(O, this, T), MMI(NULL), AFI(NULL),
4647 InCPMode(false) {
4748 Subtarget = &TM.getSubtarget();
341342 }
342343 }
343344
344 static void printSOImm(std::ostream &O, int64_t V, const TargetAsmInfo *TAI) {
345 static void printSOImm(raw_ostream &O, int64_t V, const TargetAsmInfo *TAI) {
345346 assert(V < (1 << 12) && "Not a valid so_imm value!");
346347 unsigned Imm = ARM_AM::getSOImmValImm(V);
347348 unsigned Rot = ARM_AM::getSOImmValRot(V);
823824
824825 /// PrintUnmangledNameSafely - Print out the printable characters in the name.
825826 /// Don't print things like \n or \0.
826 static void PrintUnmangledNameSafely(const Value *V, std::ostream &OS) {
827 static void PrintUnmangledNameSafely(const Value *V, raw_ostream &OS) {
827828 for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen();
828829 Name != E; ++Name)
829830 if (isprint(*Name))
10291030 /// using the given target machine description. This should work
10301031 /// regardless of whether the function is in SSA form.
10311032 ///
1032 FunctionPass *llvm::createARMCodePrinterPass(std::ostream &o,
1033 FunctionPass *llvm::createARMCodePrinterPass(raw_ostream &o,
10331034 ARMTargetMachine &tm) {
10341035 return new ARMAsmPrinter(o, tm, tm.getTargetAsmInfo());
10351036 }
2222 class FunctionPass;
2323 class TargetMachine;
2424 class MachineCodeEmitter;
25 class raw_ostream;
2526
2627 FunctionPass *createAlphaISelDag(AlphaTargetMachine &TM);
27 FunctionPass *createAlphaCodePrinterPass(std::ostream &OS,
28 FunctionPass *createAlphaCodePrinterPass(raw_ostream &OS,
2829 TargetMachine &TM);
2930 FunctionPass *createAlphaPatternInstructionSelector(TargetMachine &TM);
3031 FunctionPass *createAlphaCodeEmitterPass(AlphaTargetMachine &TM,
2323 #include "llvm/Target/TargetMachine.h"
2424 #include "llvm/Support/Compiler.h"
2525 #include "llvm/Support/Mangler.h"
26 #include "llvm/Support/raw_ostream.h"
2627 #include "llvm/ADT/Statistic.h"
2728 using namespace llvm;
2829
3435 /// Unique incrementer for label values for referencing Global values.
3536 ///
3637
37 AlphaAsmPrinter(std::ostream &o, TargetMachine &tm, const TargetAsmInfo *T)
38 AlphaAsmPrinter(raw_ostream &o, TargetMachine &tm, const TargetAsmInfo *T)
3839 : AsmPrinter(o, tm, T) {
3940 }
4041
6465 /// using the given target machine description. This should work
6566 /// regardless of whether the function is in SSA form.
6667 ///
67 FunctionPass *llvm::createAlphaCodePrinterPass(std::ostream &o,
68 FunctionPass *llvm::createAlphaCodePrinterPass(raw_ostream &o,
6869 TargetMachine &tm) {
6970 return new AlphaAsmPrinter(o, tm, tm.getTargetAsmInfo());
7071 }
1616 #include "llvm/Module.h"
1717 #include "llvm/PassManager.h"
1818 #include "llvm/Target/TargetMachineRegistry.h"
19 #include "llvm/Support/raw_ostream.h"
1920
2021 using namespace llvm;
2122
7778 return false;
7879 }
7980 bool AlphaTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
80 std::ostream &Out) {
81 raw_ostream &Out) {
8182 PM.add(createAlphaLLRPPass(*this));
8283 PM.add(createAlphaCodePrinterPass(Out, *this));
8384 return false;
8687 bool DumpAsm, MachineCodeEmitter &MCE) {
8788 PM.add(createAlphaCodeEmitterPass(*this, MCE));
8889 if (DumpAsm)
89 PM.add(createAlphaCodePrinterPass(*cerr.stream(), *this));
90 PM.add(createAlphaCodePrinterPass(errs(), *this));
9091 return false;
9192 }
9293 bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
6060 virtual bool addInstSelector(PassManagerBase &PM, bool Fast);
6161 virtual bool addPreEmitPass(PassManagerBase &PM, bool Fast);
6262 virtual bool addAssemblyEmitter(PassManagerBase &PM, bool Fast,
63 std::ostream &Out);
63 raw_ostream &Out);
6464 virtual bool addCodeEmitter(PassManagerBase &PM, bool Fast,
6565 bool DumpAsm, MachineCodeEmitter &MCE);
6666 virtual bool addSimpleCodeEmitter(PassManagerBase &PM, bool Fast,
3838 #include "llvm/Support/InstVisitor.h"
3939 #include "llvm/Support/Mangler.h"
4040 #include "llvm/Support/MathExtras.h"
41 #include "llvm/Support/raw_ostream.h"
4142 #include "llvm/ADT/StringExtras.h"
4243 #include "llvm/ADT/STLExtras.h"
4344 #include "llvm/Support/MathExtras.h"
7576 /// CWriter - This class is the main chunk of code that converts an LLVM
7677 /// module to a C translation unit.
7778 class CWriter : public FunctionPass, public InstVisitor {
78 std::ostream &Out;
79 raw_ostream &Out;
7980 IntrinsicLowering *IL;
8081 Mangler *Mang;
8182 LoopInfo *LI;
8990
9091 public:
9192 static char ID;
92 explicit CWriter(std::ostream &o)
93 explicit CWriter(raw_ostream &o)
9394 : FunctionPass((intptr_t)&ID), Out(o), IL(0), Mang(0), LI(0),
9495 TheModule(0), TAsm(0), TD(0) {}
9596
125126 return false;
126127 }
127128
128 std::ostream &printType(std::ostream &Out, const Type *Ty,
129 raw_ostream &printType(raw_ostream &Out, const Type *Ty,
129130 bool isSigned = false,
130131 const std::string &VariableName = "",
131132 bool IgnoreName = false,
132133 const PAListPtr &PAL = PAListPtr());
133 std::ostream &printSimpleType(std::ostream &Out, const Type *Ty,
134 std::ostream &printType(std::ostream &Out, const Type *Ty,
135 bool isSigned = false,
136 const std::string &VariableName = "",
137 bool IgnoreName = false,
138 const PAListPtr &PAL = PAListPtr());
139 raw_ostream &printSimpleType(raw_ostream &Out, const Type *Ty,
134140 bool isSigned,
135141 const std::string &NameSoFar = "");
136
137 void printStructReturnPointerFunctionType(std::ostream &Out,
142 std::ostream &printSimpleType(std::ostream &Out, const Type *Ty,
143 bool isSigned,
144 const std::string &NameSoFar = "");
145
146 void printStructReturnPointerFunctionType(raw_ostream &Out,
138147 const PAListPtr &PAL,
139148 const PointerType *Ty);
140149
397406 /// printStructReturnPointerFunctionType - This is like printType for a struct
398407 /// return type, except, instead of printing the type as void (*)(Struct*, ...)
399408 /// print it as "Struct (*)(...)", for struct return functions.
400 void CWriter::printStructReturnPointerFunctionType(std::ostream &Out,
409 void CWriter::printStructReturnPointerFunctionType(raw_ostream &Out,
401410 const PAListPtr &PAL,
402411 const PointerType *TheTy) {
403412 const FunctionType *FTy = cast(TheTy->getElementType());
430439 std::string tstr = FunctionInnards.str();
431440 printType(Out, RetTy,
432441 /*isSigned=*/PAL.paramHasAttr(0, ParamAttr::SExt), tstr);
442 }
443
444 raw_ostream &
445 CWriter::printSimpleType(raw_ostream &Out, const Type *Ty, bool isSigned,
446 const std::string &NameSoFar) {
447 assert((Ty->isPrimitiveType() || Ty->isInteger() || isa(Ty)) &&
448 "Invalid type for printSimpleType");
449 switch (Ty->getTypeID()) {
450 case Type::VoidTyID: return Out << "void " << NameSoFar;
451 case Type::IntegerTyID: {
452 unsigned NumBits = cast(Ty)->getBitWidth();
453 if (NumBits == 1)
454 return Out << "bool " << NameSoFar;
455 else if (NumBits <= 8)
456 return Out << (isSigned?"signed":"unsigned") << " char " << NameSoFar;
457 else if (NumBits <= 16)
458 return Out << (isSigned?"signed":"unsigned") << " short " << NameSoFar;
459 else if (NumBits <= 32)
460 return Out << (isSigned?"signed":"unsigned") << " int " << NameSoFar;
461 else if (NumBits <= 64)
462 return Out << (isSigned?"signed":"unsigned") << " long long "<< NameSoFar;
463 else {
464 assert(NumBits <= 128 && "Bit widths > 128 not implemented yet");
465 return Out << (isSigned?"llvmInt128":"llvmUInt128") << " " << NameSoFar;
466 }
467 }
468 case Type::FloatTyID: return Out << "float " << NameSoFar;
469 case Type::DoubleTyID: return Out << "double " << NameSoFar;
470 // Lacking emulation of FP80 on PPC, etc., we assume whichever of these is
471 // present matches host 'long double'.
472 case Type::X86_FP80TyID:
473 case Type::PPC_FP128TyID:
474 case Type::FP128TyID: return Out << "long double " << NameSoFar;
475
476 case Type::VectorTyID: {
477 const VectorType *VTy = cast(Ty);
478 return printSimpleType(Out, VTy->getElementType(), isSigned,
479 " __attribute__((vector_size(" +
480 utostr(TD->getABITypeSize(VTy)) + " ))) " + NameSoFar);
481 }
482
483 default:
484 cerr << "Unknown primitive type: " << *Ty << "\n";
485 abort();
486 }
433487 }
434488
435489 std::ostream &
475529 cerr << "Unknown primitive type: " << *Ty << "\n";
476530 abort();
477531 }
532 }
533
534 // Pass the Type* and the variable name and this prints out the variable
535 // declaration.
536 //
537 raw_ostream &CWriter::printType(raw_ostream &Out, const Type *Ty,
538 bool isSigned, const std::string &NameSoFar,
539 bool IgnoreName, const PAListPtr &PAL) {
540 if (Ty->isPrimitiveType() || Ty->isInteger() || isa(Ty)) {
541 printSimpleType(Out, Ty, isSigned, NameSoFar);
542 return Out;
543 }
544
545 // Check to see if the type is named.
546 if (!IgnoreName || isa(Ty)) {
547 std::map::iterator I = TypeNames.find(Ty);
548 if (I != TypeNames.end()) return Out << I->second << ' ' << NameSoFar;
549 }
550
551 switch (Ty->getTypeID()) {
552 case Type::FunctionTyID: {
553 const FunctionType *FTy = cast(Ty);
554 std::stringstream FunctionInnards;
555 FunctionInnards << " (" << NameSoFar << ") (";
556 unsigned Idx = 1;
557 for (FunctionType::param_iterator I = FTy->param_begin(),
558 E = FTy->param_end(); I != E; ++I) {
559 const Type *ArgTy = *I;
560 if (PAL.paramHasAttr(Idx, ParamAttr::ByVal)) {
561 assert(isa(ArgTy));
562 ArgTy = cast(ArgTy)->getElementType();
563 }
564 if (I != FTy->param_begin())
565 FunctionInnards << ", ";
566 printType(FunctionInnards, ArgTy,
567 /*isSigned=*/PAL.paramHasAttr(Idx, ParamAttr::SExt), "");
568 ++Idx;
569 }
570 if (FTy->isVarArg()) {
571 if (FTy->getNumParams())
572 FunctionInnards << ", ...";
573 } else if (!FTy->getNumParams()) {
574 FunctionInnards << "void";
575 }
576 FunctionInnards << ')';
577 std::string tstr = FunctionInnards.str();
578 printType(Out, FTy->getReturnType(),
579 /*isSigned=*/PAL.paramHasAttr(0, ParamAttr::SExt), tstr);
580 return Out;
581 }
582 case Type::StructTyID: {
583 const StructType *STy = cast(Ty);
584 Out << NameSoFar + " {\n";
585 unsigned Idx = 0;
586 for (StructType::element_iterator I = STy->element_begin(),
587 E = STy->element_end(); I != E; ++I) {
588 Out << " ";
589 printType(Out, *I, false, "field" + utostr(Idx++));
590 Out << ";\n";
591 }
592 Out << '}';
593 if (STy->isPacked())
594 Out << " __attribute__ ((packed))";
595 return Out;
596 }
597
598 case Type::PointerTyID: {
599 const PointerType *PTy = cast(Ty);
600 std::string ptrName = "*" + NameSoFar;
601
602 if (isa(PTy->getElementType()) ||
603 isa(PTy->getElementType()))
604 ptrName = "(" + ptrName + ")";
605
606 if (!PAL.isEmpty())
607 // Must be a function ptr cast!
608 return printType(Out, PTy->getElementType(), false, ptrName, true, PAL);
609 return printType(Out, PTy->getElementType(), false, ptrName);
610 }
611
612 case Type::ArrayTyID: {
613 const ArrayType *ATy = cast(Ty);
614 unsigned NumElements = ATy->getNumElements();
615 if (NumElements == 0) NumElements = 1;
616 // Arrays are wrapped in structs to allow them to have normal
617 // value semantics (avoiding the array "decay").
618 Out << NameSoFar << " { ";
619 printType(Out, ATy->getElementType(), false,
620 "array[" + utostr(NumElements) + "]");
621 return Out << "; }";
622 }
623
624 case Type::OpaqueTyID: {
625 static int Count = 0;
626 std::string TyName = "struct opaque_" + itostr(Count++);
627 assert(TypeNames.find(Ty) == TypeNames.end());
628 TypeNames[Ty] = TyName;
629 return Out << TyName << ' ' << NameSoFar;
630 }
631 default:
632 assert(0 && "Unhandled case in getTypeProps!");
633 abort();
634 }
635
636 return Out;
478637 }
479638
480639 // Pass the Type* and the variable name and this prints out the variable
14261585 // generateCompilerSpecificCode - This is where we add conditional compilation
14271586 // directives to cater to specific compilers as need be.
14281587 //
1429 static void generateCompilerSpecificCode(std::ostream& Out,
1588 static void generateCompilerSpecificCode(raw_ostream& Out,
14301589 const TargetData *TD) {
14311590 // Alloca is hard to get, and we don't want to include stdlib.h here.
14321591 Out << "/* get a declaration for alloca */\n"
18702029 double Val = FPC->getValueAPF().convertToDouble();
18712030 uint64_t i = FPC->getValueAPF().convertToAPInt().getZExtValue();
18722031 Out << "static const ConstantDoubleTy FPConstant" << FPCounter++
1873 << " = 0x" << std::hex << i << std::dec
2032 << " = 0x" << utohexstr(i)
18742033 << "ULL; /* " << Val << " */\n";
18752034 } else if (FPC->getType() == Type::FloatTy) {
18762035 float Val = FPC->getValueAPF().convertToFloat();
18772036 uint32_t i = (uint32_t)FPC->getValueAPF().convertToAPInt().
18782037 getZExtValue();
18792038 Out << "static const ConstantFloatTy FPConstant" << FPCounter++
1880 << " = 0x" << std::hex << i << std::dec
2039 << " = 0x" << utohexstr(i)
18812040 << "U; /* " << Val << " */\n";
18822041 } else if (FPC->getType() == Type::X86_FP80Ty) {
18832042 // api needed to prevent premature destruction
18842043 APInt api = FPC->getValueAPF().convertToAPInt();
18852044 const uint64_t *p = api.getRawData();
18862045 Out << "static const ConstantFP80Ty FPConstant" << FPCounter++
1887 << " = { 0x" << std::hex
1888 << ((uint16_t)p[1] | (p[0] & 0xffffffffffffLL)<<16)
1889 << "ULL, 0x" << (uint16_t)(p[0] >> 48) << ",{0,0,0}"
1890 << "}; /* Long double constant */\n" << std::dec;
2046 << " = { 0x"
2047 << utohexstr((uint16_t)p[1] | (p[0] & 0xffffffffffffLL)<<16)
2048 << "ULL, 0x" << utohexstr((uint16_t)(p[0] >> 48)) << ",{0,0,0}"
2049 << "}; /* Long double constant */\n";
18912050 } else if (FPC->getType() == Type::PPC_FP128Ty) {
18922051 APInt api = FPC->getValueAPF().convertToAPInt();
18932052 const uint64_t *p = api.getRawData();
18942053 Out << "static const ConstantFP128Ty FPConstant" << FPCounter++
1895 << " = { 0x" << std::hex
1896 << p[0] << ", 0x" << p[1]
1897 << "}; /* Long double constant */\n" << std::dec;
2054 << " = { 0x"
2055 << utohexstr(p[0]) << ", 0x" << utohexstr(p[1])
2056 << "}; /* Long double constant */\n";
18982057
18992058 } else
19002059 assert(0 && "Unknown float type!");
28683027 case Intrinsic::dbg_stoppoint: {
28693028 // If we use writeOperand directly we get a "u" suffix which is rejected
28703029 // by gcc.
3030 std::stringstream SPIStr;
28713031 DbgStopPointInst &SPI = cast(I);
3032 SPI.getDirectory()->print(SPIStr);
28723033 Out << "\n#line "
28733034 << SPI.getLine()
2874 << " \"" << SPI.getDirectory()
2875 << SPI.getFileName() << "\"\n";
3035 << " \"";
3036 Out << SPIStr.str();
3037 SPIStr.clear();
3038 SPI.getFileName()->print(SPIStr);
3039 Out << SPIStr.str() << "\"\n";
28763040 return true;
28773041 }
28783042 case Intrinsic::x86_sse_cmp_ss:
33743538 //===----------------------------------------------------------------------===//
33753539
33763540 bool CTargetMachine::addPassesToEmitWholeFile(PassManager &PM,
3377 std::ostream &o,
3541 raw_ostream &o,
33783542 CodeGenFileType FileType,
33793543 bool Fast) {
33803544 if (FileType != TargetMachine::AssemblyFile) return true;
2525 : DataLayout(&M) {}
2626
2727 virtual bool WantsWholeFile() const { return true; }
28 virtual bool addPassesToEmitWholeFile(PassManager &PM, std::ostream &Out,
28 virtual bool addPassesToEmitWholeFile(PassManager &PM, raw_ostream &Out,
2929 CodeGenFileType FileType, bool Fast);
3030
3131 // This class always works, but shouldn't be the default in most cases.
1919 namespace llvm {
2020 class SPUTargetMachine;
2121 class FunctionPass;
22 class raw_ostream;
2223
2324 FunctionPass *createSPUISelDag(SPUTargetMachine &TM);
24 FunctionPass *createSPUAsmPrinterPass(std::ostream &o, SPUTargetMachine &tm);
25 FunctionPass *createSPUAsmPrinterPass(raw_ostream &o, SPUTargetMachine &tm);
2526
2627 /*--== Utility functions/predicates/etc used all over the place: --==*/
2728 //! Predicate test for a signed 10-bit value
2929 #include "llvm/Support/CommandLine.h"
3030 #include "llvm/Support/Debug.h"
3131 #include "llvm/Support/Compiler.h"
32 #include "llvm/Support/raw_ostream.h"
3233 #include "llvm/Target/TargetAsmInfo.h"
3334 #include "llvm/Target/TargetRegisterInfo.h"
3435 #include "llvm/Target/TargetInstrInfo.h"
4647 struct VISIBILITY_HIDDEN SPUAsmPrinter : public AsmPrinter {
4748 std::set FnStubs, GVStubs;
4849
49 SPUAsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T) :
50 SPUAsmPrinter(raw_ostream &O, TargetMachine &TM, const TargetAsmInfo *T) :
5051 AsmPrinter(O, TM, T)
5152 {
5253 }
274275 DwarfWriter DW;
275276 MachineModuleInfo *MMI;
276277
277 LinuxAsmPrinter(std::ostream &O, SPUTargetMachine &TM,
278 LinuxAsmPrinter(raw_ostream &O, SPUTargetMachine &TM,
278279 const TargetAsmInfo *T) :
279280 SPUAsmPrinter(O, TM, T),
280281 DW(O, this, T),
650651 /// assembly code for a MachineFunction to the given output stream, in a format
651652 /// that the Linux SPU assembler can deal with.
652653 ///
653 FunctionPass *llvm::createSPUAsmPrinterPass(std::ostream &o,
654 FunctionPass *llvm::createSPUAsmPrinterPass(raw_ostream &o,
654655 SPUTargetMachine &tm) {
655656 return new LinuxAsmPrinter(o, tm, tm.getTargetAsmInfo());
656657 }
7878 }
7979
8080 bool SPUTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
81 std::ostream &Out) {
81 raw_ostream &Out) {
8282 PM.add(createSPUAsmPrinterPass(Out, *this));
8383 return false;
8484 }
8484 // Pass Pipeline Configuration
8585 virtual bool addInstSelector(PassManagerBase &PM, bool Fast);
8686 virtual bool addAssemblyEmitter(PassManagerBase &PM, bool Fast,
87 std::ostream &Out);
87 raw_ostream &Out);
8888 };
8989
9090 } // end namespace llvm
2828 #include "llvm/ADT/SmallPtrSet.h"
2929 #include "llvm/Support/CommandLine.h"
3030 #include "llvm/Support/Streams.h"
31 #include "llvm/Support/raw_ostream.h"
3132 #include "llvm/Config/config.h"
3233 #include
3334 #include
8586 /// module to a C++ translation unit.
8687 class CppWriter : public ModulePass {
8788 const char* progname;
88 std::ostream &Out;
89 raw_ostream &Out;
8990 const Module *TheModule;
9091 uint64_t uniqueNum;
9192 TypeMap TypeNames;
100101
101102 public:
102103 static char ID;
103 explicit CppWriter(std::ostream &o) :
104 explicit CppWriter(raw_ostream &o) :
104105 ModulePass((intptr_t)&ID), Out(o), uniqueNum(0), is_inline(false) {}
105106
106107 virtual const char *getPassName() const { return "C++ backend"; }
153154 };
154155
155156 static unsigned indent_level = 0;
156 inline std::ostream& nl(std::ostream& Out, int delta = 0) {
157 inline raw_ostream& nl(raw_ostream& Out, int delta = 0) {
157158 Out << "\n";
158159 if (delta >= 0 || indent_level >= unsigned(-delta))
159160 indent_level += delta;
251252 else
252253 Out << StrVal << "f";
253254 } else if (CFP->getType() == Type::DoubleTy)
254 Out << "BitsToDouble(0x" << std::hex
255 << CFP->getValueAPF().convertToAPInt().getZExtValue()
256 << std::dec << "ULL) /* " << StrVal << " */";
255 Out << "BitsToDouble(0x"
256 << utohexstr(CFP->getValueAPF().convertToAPInt().getZExtValue())
257 << "ULL) /* " << StrVal << " */";
257258 else
258 Out << "BitsToFloat(0x" << std::hex
259 << (uint32_t)CFP->getValueAPF().convertToAPInt().getZExtValue()
260 << std::dec << "U) /* " << StrVal << " */";
259 Out << "BitsToFloat(0x"
260 << utohexstr((uint32_t)CFP->getValueAPF().convertToAPInt().getZExtValue())
261 << "U) /* " << StrVal << " */";
261262 Out << ")";
262263 #if HAVE_PRINTF_A
263264 }
19811982 //===----------------------------------------------------------------------===//
19821983
19831984 bool CPPTargetMachine::addPassesToEmitWholeFile(PassManager &PM,
1984 std::ostream &o,
1985 raw_ostream &o,
19851986 CodeGenFileType FileType,
19861987 bool Fast) {
19871988 if (FileType != TargetMachine::AssemblyFile) return true;
1818
1919 namespace llvm {
2020
21 class raw_ostream;
22
2123 struct CPPTargetMachine : public TargetMachine {
2224 const TargetData DataLayout; // Calculates type size & alignment
2325
2527 : DataLayout(&M) {}
2628
2729 virtual bool WantsWholeFile() const { return true; }
28 virtual bool addPassesToEmitWholeFile(PassManager &PM, std::ostream &Out,
30 virtual bool addPassesToEmitWholeFile(PassManager &PM, raw_ostream &Out,
2931 CodeGenFileType FileType, bool Fast);
3032
3133 // This class always works, but shouldn't be the default in most cases.
1919
2020 class IA64TargetMachine;
2121 class FunctionPass;
22 class raw_ostream;
2223
2324 /// createIA64DAGToDAGInstructionSelector - This pass converts an LLVM
2425 /// function into IA64 machine code in a sane, DAG->DAG transform.
3536 /// using the given target machine description. This should work
3637 /// regardless of whether the function is in SSA form.
3738 ///
38 FunctionPass *createIA64CodePrinterPass(std::ostream &o, IA64TargetMachine &tm);
39 FunctionPass *createIA64CodePrinterPass(raw_ostream &o, IA64TargetMachine &tm);
3940
4041 } // End llvm namespace
4142
2525 #include "llvm/Target/TargetAsmInfo.h"
2626 #include "llvm/Target/TargetMachine.h"
2727 #include "llvm/Support/Mangler.h"
28 #include "llvm/Support/raw_ostream.h"
2829 #include "llvm/ADT/Statistic.h"
2930 using namespace llvm;
3031
3435 struct IA64AsmPrinter : public AsmPrinter {
3536 std::set ExternalFunctionNames, ExternalObjectNames;
3637
37 IA64AsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
38 IA64AsmPrinter(raw_ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
3839 : AsmPrinter(O, TM, T) {
3940 }
4041
335336 O << "\t.size " << name << ',' << Size << '\n';
336337 }
337338
338 O << name << ":\t\t\t\t// " << *C << '\n';
339 O << name << ":\n";
339340 EmitGlobalConstant(C);
340341 }
341342
369370 /// assembly code for a MachineFunction to the given output stream, using
370371 /// the given target machine description.
371372 ///
372 FunctionPass *llvm::createIA64CodePrinterPass(std::ostream &o,
373 FunctionPass *llvm::createIA64CodePrinterPass(raw_ostream &o,
373374 IA64TargetMachine &tm) {
374375 return new IA64AsmPrinter(o, tm, tm.getTargetAsmInfo());
375376 }
8181 return true;
8282 }
8383 bool IA64TargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
84 std::ostream &Out) {
84 raw_ostream &Out) {
8585 PM.add(createIA64CodePrinterPass(Out, *this));
8686 return false;
8787 }
5050 virtual bool addInstSelector(PassManagerBase &PM, bool Fast);
5151 virtual bool addPreEmitPass(PassManagerBase &PM, bool Fast);
5252 virtual bool addAssemblyEmitter(PassManagerBase &PM, bool Fast,
53 std::ostream &Out);
53 raw_ostream &Out);
5454 };
5555 } // End llvm namespace
5656
3434 : DataLayout(&M) {}
3535
3636 virtual bool WantsWholeFile() const { return true; }
37 virtual bool addPassesToEmitWholeFile(PassManager &PM, std::ostream &Out,
37 virtual bool addPassesToEmitWholeFile(PassManager &PM, raw_ostream &Out,
3838 CodeGenFileType FileType, bool Fast);
3939
4040 // This class always works, but shouldn't be the default in most cases.
11901190 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) {
11911191 const Instruction* Inst = I;
11921192 // Comment llvm original instruction
1193 Out << "\n//" << *Inst << "\n";
1193 // Out << "\n//" << *Inst << "\n";
11941194 // Do not handle PHI instruction in current block
11951195 if (Inst->getOpcode()==Instruction::PHI) continue;
11961196 // Print instruction
13661366 for (std::vector::const_iterator I = InitList.begin(),
13671367 E = InitList.end(); I!=E; ++I) {
13681368 if (const ConstantExpr *CE = dyn_cast(I->constant)) {
1369 Out << "\n// Init " << getValueName(VarI->first) << ", offset " <<
1370 utostr(I->offset) << ", type "<< *I->constant->getType() << "\n\n";
1369 // Out << "\n// Init " << getValueName(VarI->first) << ", offset " <<
1370 // utostr(I->offset) << ", type "<< *I->constant->getType() << "\n\n";
13711371 // Load variable address
13721372 printValueLoad(VarI->first);
13731373 // Add offset
16471647 // External Interface declaration
16481648 //===----------------------------------------------------------------------===//
16491649
1650 bool MSILTarget::addPassesToEmitWholeFile(PassManager &PM, std::ostream &o,
1650 bool MSILTarget::addPassesToEmitWholeFile(PassManager &PM, raw_ostream &o,
16511651 CodeGenFileType FileType, bool Fast)
16521652 {
16531653 if (FileType != TargetMachine::AssemblyFile) return true;
2121 #include "llvm/Analysis/FindUsedTypes.h"
2222 #include "llvm/Analysis/LoopInfo.h"
2323 #include "llvm/Support/GetElementPtrTypeIterator.h"
24 #include "llvm/Support/raw_ostream.h"
2425 #include "llvm/Target/TargetData.h"
2526 #include "llvm/Target/TargetMachine.h"
2627 #include "llvm/Target/TargetMachineRegistry.h"
7475 }
7576
7677 public:
77 std::ostream &Out;
78 raw_ostream &Out;
7879 Module* ModulePtr;
7980 const TargetData* TD;
8081 Mangler* Mang;
8485 StaticInitList;
8586 const std::set* UsedTypes;
8687 static char ID;
87 MSILWriter(std::ostream &o) : FunctionPass((intptr_t)&ID), Out(o) {
88 MSILWriter(raw_ostream &o) : FunctionPass((intptr_t)&ID), Out(o) {
8889 UniqID = 0;
8990 }
9091
2020 class MipsTargetMachine;
2121 class FunctionPass;
2222 class MachineCodeEmitter;
23 class raw_ostream;
2324
2425 FunctionPass *createMipsISelDag(MipsTargetMachine &TM);
2526 FunctionPass *createMipsDelaySlotFillerPass(MipsTargetMachine &TM);
26 FunctionPass *createMipsCodePrinterPass(std::ostream &OS,
27 FunctionPass *createMipsCodePrinterPass(raw_ostream &OS,
2728 MipsTargetMachine &TM);
2829 } // end namespace llvm;
2930
3636 #include "llvm/Support/Debug.h"
3737 #include "llvm/Support/CommandLine.h"
3838 #include "llvm/Support/MathExtras.h"
39 #include "llvm/Support/raw_ostream.h"
3940 #include
4041
4142 using namespace llvm;
4748
4849 const MipsSubtarget *Subtarget;
4950
50 MipsAsmPrinter(std::ostream &O, MipsTargetMachine &TM,
51 MipsAsmPrinter(raw_ostream &O, MipsTargetMachine &TM,
5152 const TargetAsmInfo *T):
5253 AsmPrinter(O, TM, T) {
5354 Subtarget = &TM.getSubtarget();
8889 /// assembly code for a MachineFunction to the given output stream,
8990 /// using the given target machine description. This should work
9091 /// regardless of whether the function is in SSA form.
91 FunctionPass *llvm::createMipsCodePrinterPass(std::ostream &o,
92 FunctionPass *llvm::createMipsCodePrinterPass(raw_ostream &o,
9293 MipsTargetMachine &tm)
9394 {
9495 return new MipsAsmPrinter(o, tm, tm.getTargetAsmInfo());
174175 void MipsAsmPrinter::
175176 printHex32(unsigned int Value)
176177 {
177 O << "0x" << std::hex;
178 O << "0x";
178179 for (int i = 7; i >= 0; i--)
179 O << std::hex << ( (Value & (0xF << (i*4))) >> (i*4) );
180 O << std::dec;
180 O << utohexstr( (Value & (0xF << (i*4))) >> (i*4) );
181181 }
182182
183183 //===----------------------------------------------------------------------===//
116116 // true if AssemblyEmitter is supported
117117 bool MipsTargetMachine::
118118 addAssemblyEmitter(PassManagerBase &PM, bool Fast,
119 std::ostream &Out)
119 raw_ostream &Out)
120120 {
121121 // Output assembly language.
122122 PM.add(createMipsCodePrinterPass(Out, *this));
2121 #include "llvm/Target/TargetFrameInfo.h"
2222
2323 namespace llvm {
24 class raw_ostream;
25
2426 class MipsTargetMachine : public LLVMTargetMachine {
2527 MipsSubtarget Subtarget;
2628 const TargetData DataLayout; // Calculates type size & alignment
5759 virtual bool addInstSelector(PassManagerBase &PM, bool Fast);
5860 virtual bool addPreEmitPass(PassManagerBase &PM, bool Fast);
5961 virtual bool addAssemblyEmitter(PassManagerBase &PM, bool Fast,
60 std::ostream &Out);
62 raw_ostream &Out);
6163 };
6264
6365 /// MipselTargetMachine - Mipsel target machine.
2121 class FunctionPassManager;
2222 class FunctionPass;
2323 class MachineCodeEmitter;
24 class raw_ostream;
2425
2526 FunctionPass *createPIC16ISelDag(PIC16TargetMachine &TM);
26 FunctionPass *createPIC16CodePrinterPass(std::ostream &OS,
27 FunctionPass *createPIC16CodePrinterPass(raw_ostream &OS,
2728 PIC16TargetMachine &TM);
2829 } // end namespace llvm;
2930
3030 #include "llvm/Support/Debug.h"
3131 #include "llvm/Support/Mangler.h"
3232 #include "llvm/Support/MathExtras.h"
33 #include "llvm/Support/raw_ostream.h"
3334 #include "llvm/Target/TargetAsmInfo.h"
3435 #include "llvm/Target/TargetData.h"
3536 #include "llvm/Target/TargetMachine.h"
4243
4344 namespace {
4445 struct VISIBILITY_HIDDEN PIC16AsmPrinter : public AsmPrinter {
45 PIC16AsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
46 PIC16AsmPrinter(raw_ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
4647 : AsmPrinter(O, TM, T) {
4748 }
4849
108109 /// using the given target machine description. This should work
109110 /// regardless of whether the function is in SSA form.
110111 ///
111 FunctionPass *llvm::createPIC16CodePrinterPass(std::ostream &o,
112 FunctionPass *llvm::createPIC16CodePrinterPass(raw_ostream &o,
112113 PIC16TargetMachine &tm) {
113114 return new PIC16AsmPrinter(o, tm, tm.getTargetAsmInfo());
114115 }
274275 }
275276
276277 static void
277 printSOImm(std::ostream &O, int64_t V, const TargetAsmInfo *TAI)
278 printSOImm(raw_ostream &O, int64_t V, const TargetAsmInfo *TAI)
278279 {
279280 assert(V < (1 << 12) && "Not a valid so_imm value!");
280281
6060 }
6161
6262 bool PIC16TargetMachine::
63 addAssemblyEmitter(PassManagerBase &PM, bool Fast, std::ostream &Out)
63 addAssemblyEmitter(PassManagerBase &PM, bool Fast, raw_ostream &Out)
6464 {
6565 // Output assembly language.
6666 PM.add(createPIC16CodePrinterPass(Out, *this));
5353 virtual bool addPrologEpilogInserter(PassManagerBase &PM, bool Fast);
5454 virtual bool addPreEmitPass(PassManagerBase &PM, bool Fast);
5555 virtual bool addAssemblyEmitter(PassManagerBase &PM, bool Fast,
56 std::ostream &Out);
56 raw_ostream &Out);
5757 };
5858 } // end namespace llvm
5959
3535 #include "llvm/Support/CommandLine.h"
3636 #include "llvm/Support/Debug.h"
3737 #include "llvm/Support/Compiler.h"
38 #include "llvm/Support/raw_ostream.h"
3839 #include "llvm/Target/TargetAsmInfo.h"
3940 #include "llvm/Target/TargetRegisterInfo.h"
4041 #include "llvm/Target/TargetInstrInfo.h"
5152 std::set FnStubs, GVStubs;
5253 const PPCSubtarget &Subtarget;
5354
54 PPCAsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
55 PPCAsmPrinter(raw_ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
5556 : AsmPrinter(O, TM, T), Subtarget(TM.getSubtarget()) {
5657 }
5758
294295 DwarfWriter DW;
295296 MachineModuleInfo *MMI;
296297
297 PPCLinuxAsmPrinter(std::ostream &O, PPCTargetMachine &TM,
298 PPCLinuxAsmPrinter(raw_ostream &O, PPCTargetMachine &TM,
298299 const TargetAsmInfo *T)
299300 : PPCAsmPrinter(O, TM, T), DW(O, this, T), MMI(0) {
300301 }
326327 DwarfWriter DW;
327328 MachineModuleInfo *MMI;
328329
329 PPCDarwinAsmPrinter(std::ostream &O, PPCTargetMachine &TM,
330 PPCDarwinAsmPrinter(raw_ostream &O, PPCTargetMachine &TM,
330331 const TargetAsmInfo *T)
331332 : PPCAsmPrinter(O, TM, T), DW(O, this, T), MMI(0) {
332333 }
648649
649650 /// PrintUnmangledNameSafely - Print out the printable characters in the name.
650651 /// Don't print things like \n or \0.
651 static void PrintUnmangledNameSafely(const Value *V, std::ostream &OS) {
652 static void PrintUnmangledNameSafely(const Value *V, raw_ostream &OS) {
652653 for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen();
653654 Name != E; ++Name)
654655 if (isprint(*Name))
11061107 /// for a MachineFunction to the given output stream, in a format that the
11071108 /// Darwin assembler can deal with.
11081109 ///
1109 FunctionPass *llvm::createPPCAsmPrinterPass(std::ostream &o,
1110 FunctionPass *llvm::createPPCAsmPrinterPass(raw_ostream &o,
11101111 PPCTargetMachine &tm) {
11111112 const PPCSubtarget *Subtarget = &tm.getSubtarget();
11121113
2424 class PPCTargetMachine;
2525 class FunctionPass;
2626 class MachineCodeEmitter;
27 class raw_ostream;
2728
2829 FunctionPass *createPPCBranchSelectionPass();
2930 FunctionPass *createPPCISelDag(PPCTargetMachine &TM);
30 FunctionPass *createPPCAsmPrinterPass(std::ostream &OS,
31 FunctionPass *createPPCAsmPrinterPass(raw_ostream &OS,
3132 PPCTargetMachine &TM);
3233 FunctionPass *createPPCCodeEmitterPass(PPCTargetMachine &TM,
3334 MachineCodeEmitter &MCE);
1717 #include "llvm/PassManager.h"
1818 #include "llvm/Target/TargetMachineRegistry.h"
1919 #include "llvm/Target/TargetOptions.h"
20 #include "llvm/Support/raw_ostream.h"
2021 using namespace llvm;
2122
2223 // Register the targets
133134 }
134135
135136 bool PPCTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
136 std::ostream &Out) {
137 raw_ostream &Out) {
137138 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
138139 if (AsmPrinterCtor)
139140 PM.add(AsmPrinterCtor(Out, *this));
166167 if (DumpAsm) {
167168 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
168169 if (AsmPrinterCtor)
169 PM.add(AsmPrinterCtor(*cerr.stream(), *this));
170 PM.add(AsmPrinterCtor(errs(), *this));
170171 }
171172
172173 return false;
179180 if (DumpAsm) {
180181 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
181182 if (AsmPrinterCtor)
182 PM.add(AsmPrinterCtor(*cerr.stream(), *this));
183 PM.add(AsmPrinterCtor(errs(), *this));
183184 }
184185
185186 return false;
4343
4444 // To avoid having target depend on the asmprinter stuff libraries, asmprinter
4545 // set this functions to ctor pointer at startup time if they are linked in.
46 typedef FunctionPass *(*AsmPrinterCtorFn)(std::ostream &o,
46 typedef FunctionPass *(*AsmPrinterCtorFn)(raw_ostream &o,
4747 PPCTargetMachine &tm);
4848 static AsmPrinterCtorFn AsmPrinterCtor;
4949
7777 virtual bool addInstSelector(PassManagerBase &PM, bool Fast);
7878 virtual bool addPreEmitPass(PassManagerBase &PM, bool Fast);
7979 virtual bool addAssemblyEmitter(PassManagerBase &PM, bool Fast,
80 std::ostream &Out);
80 raw_ostream &Out);
8181 virtual bool addCodeEmitter(PassManagerBase &PM, bool Fast,
8282 bool DumpAsm, MachineCodeEmitter &MCE);
8383 virtual bool addSimpleCodeEmitter(PassManagerBase &PM, bool Fast,
2020 namespace llvm {
2121 class FunctionPass;
2222 class TargetMachine;
23 class raw_ostream;
2324
2425 FunctionPass *createSparcISelDag(TargetMachine &TM);
25 FunctionPass *createSparcCodePrinterPass(std::ostream &OS, TargetMachine &TM);
26 FunctionPass *createSparcCodePrinterPass(raw_ostream &OS, TargetMachine &TM);
2627 FunctionPass *createSparcDelaySlotFillerPass(TargetMachine &TM);
2728 FunctionPass *createSparcFPMoverPass(TargetMachine &TM);
2829 } // end namespace llvm;
2525 #include "llvm/Target/TargetData.h"
2626 #include "llvm/Target/TargetMachine.h"
2727 #include "llvm/Support/Mangler.h"
28 #include "llvm/Support/raw_ostream.h"
2829 #include "llvm/ADT/Statistic.h"
2930 #include "llvm/ADT/StringExtras.h"
3031 #include "llvm/Support/CommandLine.h"
3839
3940 namespace {
4041 struct VISIBILITY_HIDDEN SparcAsmPrinter : public AsmPrinter {
41 SparcAsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
42 SparcAsmPrinter(raw_ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
4243 : AsmPrinter(O, TM, T) {
4344 }
4445
7475 /// using the given target machine description. This should work
7576 /// regardless of whether the function is in SSA form.
7677 ///
77 FunctionPass *llvm::createSparcCodePrinterPass(std::ostream &o,
78 FunctionPass *llvm::createSparcCodePrinterPass(raw_ostream &o,
7879 TargetMachine &tm) {
7980 return new SparcAsmPrinter(o, tm, tm.getTargetAsmInfo());
8081 }
7474 }
7575
7676 bool SparcTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
77 std::ostream &Out) {
77 raw_ostream &Out) {
7878 // Output assembly language.
7979 PM.add(createSparcCodePrinterPass(Out, *this));
8080 return false;
4848 virtual bool addInstSelector(PassManagerBase &PM, bool Fast);
4949 virtual bool addPreEmitPass(PassManagerBase &PM, bool Fast);
5050 virtual bool addAssemblyEmitter(PassManagerBase &PM, bool Fast,
51 std::ostream &Out);
51 raw_ostream &Out);
5252 };
5353
5454 } // end namespace llvm
2727 #include "llvm/ADT/StringExtras.h"
2828 #include "llvm/CodeGen/MachineJumpTableInfo.h"
2929 #include "llvm/Support/Mangler.h"
30 #include "llvm/Support/raw_ostream.h"
3031 #include "llvm/Target/TargetAsmInfo.h"
3132 #include "llvm/Target/TargetOptions.h"
3233 using namespace llvm;
8384
8485 /// PrintUnmangledNameSafely - Print out the printable characters in the name.
8586 /// Don't print things like \n or \0.
86 static void PrintUnmangledNameSafely(const Value *V, std::ostream &OS) {
87 static void PrintUnmangledNameSafely(const Value *V, raw_ostream &OS) {
8788 for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen();
8889 Name != E; ++Name)
8990 if (isprint(*Name))
3333
3434 const X86Subtarget *Subtarget;
3535
36 X86ATTAsmPrinter(std::ostream &O, X86TargetMachine &TM,
36 X86ATTAsmPrinter(raw_ostream &O, X86TargetMachine &TM,
3737 const TargetAsmInfo *T)
3838 : AsmPrinter(O, TM, T), DW(O, this, T), MMI(0) {
3939 Subtarget = &TM.getSubtarget();
2222 /// for a MachineFunction to the given output stream, using the given target
2323 /// machine description.
2424 ///
25 FunctionPass *llvm::createX86CodePrinterPass(std::ostream &o,
25 FunctionPass *llvm::createX86CodePrinterPass(raw_ostream &o,
2626 X86TargetMachine &tm) {
2727 const X86Subtarget *Subtarget = &tm.getSubtarget();
2828
1919 #include "llvm/CodeGen/AsmPrinter.h"
2020 #include "llvm/ADT/StringSet.h"
2121 #include "llvm/Support/Compiler.h"
22 #include "llvm/Support/raw_ostream.h"
2223
2324 namespace llvm {
2425
2526 struct VISIBILITY_HIDDEN X86IntelAsmPrinter : public AsmPrinter {
26 X86IntelAsmPrinter(std::ostream &O, X86TargetMachine &TM,
27 X86IntelAsmPrinter(raw_ostream &O, X86TargetMachine &TM,
2728 const TargetAsmInfo *T)
2829 : AsmPrinter(O, TM, T) {
2930 }
2121 class X86TargetMachine;
2222 class FunctionPass;
2323 class MachineCodeEmitter;
24 class raw_ostream;
2425
2526 /// createX86ISelDag - This pass converts a legalized DAG into a
2627 /// X86-specific DAG, ready for instruction scheduling.
3738 /// assembly code for a MachineFunction to the given output stream,
3839 /// using the given target machine description.
3940 ///
40 FunctionPass *createX86CodePrinterPass(std::ostream &o, X86TargetMachine &tm);
41 FunctionPass *createX86CodePrinterPass(raw_ostream &o, X86TargetMachine &tm);
4142
4243 /// createX86CodeEmitterPass - Return a pass that emits the collected X86 code
4344 /// to the specified MCE object.
1717 #include "llvm/PassManager.h"
1818 #include "llvm/CodeGen/MachineFunction.h"
1919 #include "llvm/CodeGen/Passes.h"
20 #include "llvm/Support/raw_ostream.h"
2021 #include "llvm/Target/TargetOptions.h"
2122 #include "llvm/Target/TargetMachineRegistry.h"
2223 using namespace llvm;
188189 }
189190
190191 bool X86TargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
191 std::ostream &Out) {
192 raw_ostream &Out) {
192193 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
193194 if (AsmPrinterCtor)
194195 PM.add(AsmPrinterCtor(Out, *this));
217218 if (DumpAsm) {
218219 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
219220 if (AsmPrinterCtor)
220 PM.add(AsmPrinterCtor(*cerr.stream(), *this));
221 PM.add(AsmPrinterCtor(errs(), *this));
221222 }
222223
223224 return false;
229230 if (DumpAsm) {
230231 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
231232 if (AsmPrinterCtor)
232 PM.add(AsmPrinterCtor(*cerr.stream(), *this));
233 }
234
235 return false;
236 }
233 PM.add(AsmPrinterCtor(errs(), *this));
234 }
235
236 return false;
237 }
2424 #include "X86ISelLowering.h"
2525
2626 namespace llvm {
27
28 class raw_ostream;
2729
2830 class X86TargetMachine : public LLVMTargetMachine {
2931 X86Subtarget Subtarget;
4042
4143 // To avoid having target depend on the asmprinter stuff libraries, asmprinter
4244 // set this functions to ctor pointer at startup time if they are linked in.
43 typedef FunctionPass *(*AsmPrinterCtorFn)(std::ostream &o,
45 typedef FunctionPass *(*AsmPrinterCtorFn)(raw_ostream &o,
4446 X86TargetMachine &tm);
4547 static AsmPrinterCtorFn AsmPrinterCtor;
4648
7476 virtual bool addPreRegAlloc(PassManagerBase &PM, bool Fast);
7577 virtual bool addPostRegAlloc(PassManagerBase &PM, bool Fast);
7678 virtual bool addAssemblyEmitter(PassManagerBase &PM, bool Fast,
77 std::ostream &Out);
79 raw_ostream &Out);
7880 virtual bool addCodeEmitter(PassManagerBase &PM, bool Fast,
7981 bool DumpAsm, MachineCodeEmitter &MCE);
8082 virtual bool addSimpleCodeEmitter(PassManagerBase &PM, bool Fast,
3030 #include "llvm/Support/MemoryBuffer.h"
3131 #include "llvm/Support/PluginLoader.h"
3232 #include "llvm/Support/FileUtilities.h"
33 #include "llvm/Support/raw_ostream.h"
3334 #include "llvm/Analysis/Verifier.h"
3435 #include "llvm/System/Signals.h"
3536 #include "llvm/Config/config.h"
105106 return outputFilename;
106107 }
107108
108 static std::ostream *GetOutputStream(const char *ProgName) {
109 static raw_ostream *GetOutputStream(const char *ProgName) {
109110 if (OutputFilename != "") {
110111 if (OutputFilename == "-")
111 return &std::cout;
112 return &outs();
112113
113114 // Specified an output filename?
114115 if (!Force && std::ifstream(OutputFilename.c_str())) {
122123 // SIGINT
123124 sys::RemoveFileOnSignal(sys::Path(OutputFilename));
124125
125 return new std::ofstream(OutputFilename.c_str());
126 std::string error;
127 return new raw_fd_ostream(OutputFilename.c_str(), error);
126128 }
127129
128130 if (InputFilename == "-") {
129131 OutputFilename = "-";
130 return &std::cout;
132 return &outs();
131133 }
132134
133135 OutputFilename = GetFileNameRoot(InputFilename);
164166 // SIGINT
165167 sys::RemoveFileOnSignal(sys::Path(OutputFilename));
166168
167 std::ostream *Out = new std::ofstream(OutputFilename.c_str());
168 if (!Out->good()) {
169 std::cerr << ProgName << ": error opening " << OutputFilename << "!\n";
169 std::string error;
170 raw_ostream *Out = new raw_fd_ostream(OutputFilename.c_str(), error);
171 if (!error.empty()) {
172 std::cerr << error;
170173 delete Out;
171174 return 0;
172175 }
228231 TargetMachine &Target = *target.get();
229232
230233 // Figure out where we are going to send the output...
231 std::ostream *Out = GetOutputStream(argv[0]);
234 raw_ostream *Out = GetOutputStream(argv[0]);
232235 if (Out == 0) return 1;
233236
234237 // If this target requires addPassesToEmitWholeFile, do it now. This is
243246 if (Target.addPassesToEmitWholeFile(PM, *Out, FileType, Fast)) {
244247 std::cerr << argv[0] << ": target does not support generation of this"
245248 << " file type!\n";
246 if (Out != &std::cout) delete Out;
249 if (Out != &outs()) delete Out;
247250 // And the Out file is empty and useless, so remove it now.
248251 sys::Path(OutputFilename).eraseFromDisk();
249252 return 1;
270273 case FileModel::Error:
271274 std::cerr << argv[0] << ": target does not support generation of this"
272275 << " file type!\n";
273 if (Out != &std::cout) delete Out;
276 if (Out != &outs()) delete Out;
274277 // And the Out file is empty and useless, so remove it now.
275278 sys::Path(OutputFilename).eraseFromDisk();
276279 return 1;
287290 if (Target.addPassesToEmitFileFinish(Passes, MCE, Fast)) {
288291 std::cerr << argv[0] << ": target does not support generation of this"
289292 << " file type!\n";
290 if (Out != &std::cout) delete Out;
293 if (Out != &outs()) delete Out;
291294 // And the Out file is empty and useless, so remove it now.
292295 sys::Path(OutputFilename).eraseFromDisk();
293296 return 1;
305308 }
306309
307310 // Delete the ostream if it's not a stdout stream
308 if (Out != &std::cout) delete Out;
311 if (Out != &outs()) delete Out;
309312
310313 return 0;
311314 }
2626 #include "llvm/Support/SystemUtils.h"
2727 #include "llvm/Support/Mangler.h"
2828 #include "llvm/Support/MemoryBuffer.h"
29 #include "llvm/Support/raw_ostream.h"
2930 #include "llvm/System/Signals.h"
3031 #include "llvm/Analysis/Passes.h"
3132 #include "llvm/Analysis/LoopPass.h"
161162 sys::RemoveFileOnSignal(uniqueAsmPath);
162163
163164 // generate assembly code
164 std::ofstream asmFile(uniqueAsmPath.c_str());
165 bool genResult = this->generateAssemblyCode(asmFile, errMsg);
166 asmFile.close();
165 std::string error;
166 bool genResult = false;
167 {
168 raw_fd_ostream asmFile(uniqueAsmPath.c_str(), error);
169 genResult = this->generateAssemblyCode(asmFile, errMsg);
170 }
167171 if ( genResult ) {
168172 if ( uniqueAsmPath.exists() )
169173 uniqueAsmPath.eraseFromDisk();
308312 }
309313
310314 /// Optimize merged modules using various IPO passes
311 bool LTOCodeGenerator::generateAssemblyCode(std::ostream& out, std::string& errMsg)
315 bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out,
316 std::string& errMsg)
312317 {
313318 if ( this->determineTarget(errMsg) )
314319 return true;
2424 //
2525 // C++ class which implements the opaque lto_code_gen_t
2626 //
27
28 class llvm::raw_ostream;
2729 class LTOCodeGenerator {
2830 public:
2931 static const char* getVersionString();
4042 const void* compile(size_t* length, std::string& errMsg);
4143 void setCodeGenDebugOptions(const char *opts);
4244 private:
43 bool generateAssemblyCode(std::ostream& out,
44 std::string& errMsg);
45 bool generateAssemblyCode(llvm::raw_ostream& out,
46 std::string& errMsg);
4547 bool assemble(const std::string& asmPath,
4648 const std::string& objPath, std::string& errMsg);
4749 void applyScopeRestrictions();