llvm.org GIT mirror llvm / d99ce2f
MC: Add target hook to control symbol quoting git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239370 91177308-0d34-0410-b5e6-96231b3b80d8 Matt Arsenault 5 years ago
51 changed file(s) with 319 addition(s) and 213 deletion(s). Raw diff Collapse all Expand all
154154 /// Defaults to false.
155155 bool AllowAtInName;
156156
157 /// If this is true, symbol names with invalid characters will be printed in
158 /// quotes.
159 bool SupportsQuotedNames;
160
157161 /// This is true if data region markers should be printed as
158162 /// ".data_region/.end_data_region" directives. If false, use "$d/$a" labels
159163 /// instead.
405409 unsigned Encoding,
406410 MCStreamer &Streamer) const;
407411
412 /// Return true if the identifier \p Name does not need quotes to be
413 /// syntactically correct.
414 virtual bool isValidUnquotedName(StringRef Name) const;
415
408416 bool usesSunStyleELFSectionSwitchSyntax() const {
409417 return SunStyleELFSectionSwitchSyntax;
410418 }
455463 const char *getCode64Directive() const { return Code64Directive; }
456464 unsigned getAssemblerDialect() const { return AssemblerDialect; }
457465 bool doesAllowAtInName() const { return AllowAtInName; }
466 bool supportsNameQuoting() const { return SupportsQuotedNames; }
458467 bool doesSupportDataRegionDirectives() const {
459468 return UseDataRegionDirectives;
460469 }
7171 /// \name Utility Methods
7272 /// @{
7373
74 void print(raw_ostream &OS) const;
74 void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
7575 void dump() const;
7676
7777 /// @}
120120 };
121121
122122 inline raw_ostream &operator<<(raw_ostream &OS, const MCExpr &E) {
123 E.print(OS);
123 E.print(OS, nullptr);
124124 return OS;
125125 }
126126
550550 MCTargetExpr() : MCExpr(Target) {}
551551 virtual ~MCTargetExpr() {}
552552 public:
553
554 virtual void printImpl(raw_ostream &OS) const = 0;
553 virtual void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const = 0;
555554 virtual bool evaluateAsRelocatableImpl(MCValue &Res,
556555 const MCAsmLayout *Layout,
557556 const MCFixup *Fixup) const = 0;
2020 #include "llvm/Support/Compiler.h"
2121
2222 namespace llvm {
23 class MCAsmInfo;
2324 class MCExpr;
2425 class MCSymbol;
2526 class MCFragment;
301302 void setPrivateExtern(bool Value) { IsPrivateExtern = Value; }
302303
303304 /// print - Print the value to the stream \p OS.
304 void print(raw_ostream &OS) const;
305 void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
305306
306307 /// dump - Print the value to stderr.
307308 void dump() const;
320321 };
321322
322323 inline raw_ostream &operator<<(raw_ostream &OS, const MCSymbol &Sym) {
323 Sym.print(OS);
324 Sym.print(OS, nullptr);
324325 return OS;
325326 }
326327 } // end namespace llvm
401401 unsigned OpFlags = MI->getOperand(OpNo).getImm();
402402 ++OpNo; // Skip over the ID number.
403403
404 if (Modifier[0] == 'l') // labels are target independent
404 if (Modifier[0] == 'l') { // Labels are target independent.
405405 // FIXME: What if the operand isn't an MBB, report error?
406 OS << *MI->getOperand(OpNo).getMBB()->getSymbol();
407 else {
406 const MCSymbol *Sym = MI->getOperand(OpNo).getMBB()->getSymbol();
407 Sym->print(OS, AP->MAI);
408 } else {
408409 if (InlineAsm::isMemKind(OpFlags)) {
409410 Error = AP->PrintAsmMemoryOperand(MI, OpNo, InlineAsmVariant,
410411 Modifier[0] ? Modifier : nullptr,
4949 Code64Directive = ".code64";
5050 AssemblerDialect = 0;
5151 AllowAtInName = false;
52 SupportsQuotedNames = true;
5253 UseDataRegionDirectives = false;
5354 ZeroDirective = "\t.zero\t";
5455 AsciiDirective = "\t.ascii\t";
136137 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
137138 return MCBinaryExpr::createSub(Res, PC, Context);
138139 }
140
141 static bool isAcceptableChar(char C) {
142 return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
143 (C >= '0' && C <= '9') || C == '_' || C == '$' || C == '.' || C == '@';
144 }
145
146 bool MCAsmInfo::isValidUnquotedName(StringRef Name) const {
147 if (Name.empty())
148 return false;
149
150 // If any of the characters in the string is an unacceptable character, force
151 // quotes.
152 for (char C : Name) {
153 if (!isAcceptableChar(C))
154 return false;
155 }
156
157 return true;
158 }
307307 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
308308 MCStreamer::EmitLabel(Symbol);
309309
310 OS << *Symbol << MAI->getLabelSuffix();
310 Symbol->print(OS, MAI);
311 OS << MAI->getLabelSuffix();
312
311313 EmitEOL();
312314 }
313315
327329 if (!IsFirst)
328330 OS << ", ";
329331 IsFirst = false;
330 OS << **It;
332 (*It)->print(OS, MAI);
331333 }
332334 EmitEOL();
333335 }
383385 // MCSymbols when they have spaces in them.
384386 OS << "\t.thumb_func";
385387 // Only Mach-O hasSubsectionsViaSymbols()
386 if (MAI->hasSubsectionsViaSymbols())
387 OS << '\t' << *Func;
388 if (MAI->hasSubsectionsViaSymbols()) {
389 OS << '\t';
390 Func->print(OS, MAI);
391 }
388392 EmitEOL();
389393 }
390394
391395 void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
392 OS << *Symbol << " = " << *Value;
396 Symbol->print(OS, MAI);
397 OS << " = ";
398 Value->print(OS, MAI);
399
393400 EmitEOL();
394401
395402 MCStreamer::EmitAssignment(Symbol, Value);
396403 }
397404
398405 void MCAsmStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
399 OS << ".weakref " << *Alias << ", " << *Symbol;
406 OS << ".weakref ";
407 Alias->print(OS, MAI);
408 OS << ", ";
409 Symbol->print(OS, MAI);
400410 EmitEOL();
401411 }
402412
413423 case MCSA_ELF_TypeGnuUniqueObject: /// .type _foo, @gnu_unique_object
414424 if (!MAI->hasDotTypeDotSizeDirective())
415425 return false; // Symbol attribute not supported
416 OS << "\t.type\t" << *Symbol << ','
417 << ((MAI->getCommentString()[0] != '@') ? '@' : '%');
426 OS << "\t.type\t";
427 Symbol->print(OS, MAI);
428 OS << ',' << ((MAI->getCommentString()[0] != '@') ? '@' : '%');
418429 switch (Attribute) {
419430 default: return false;
420431 case MCSA_ELF_TypeFunction: OS << "function"; break;
455466 case MCSA_WeakDefAutoPrivate: OS << "\t.weak_def_can_be_hidden\t"; break;
456467 }
457468
458 OS << *Symbol;
469 Symbol->print(OS, MAI);
459470 EmitEOL();
460471
461472 return true;
462473 }
463474
464475 void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
465 OS << ".desc" << ' ' << *Symbol << ',' << DescValue;
476 OS << ".desc" << ' ';
477 Symbol->print(OS, MAI);
478 OS << ',' << DescValue;
466479 EmitEOL();
467480 }
468481
469482 void MCAsmStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
470 OS << "\t.def\t " << *Symbol << ';';
483 OS << "\t.def\t ";
484 Symbol->print(OS, MAI);
485 OS << ';';
471486 EmitEOL();
472487 }
473488
492507 }
493508
494509 void MCAsmStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
495 OS << "\t.secidx\t" << *Symbol;
510 OS << "\t.secidx\t";
511 Symbol->print(OS, MAI);
496512 EmitEOL();
497513 }
498514
499515 void MCAsmStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
500 OS << "\t.secrel32\t" << *Symbol;
516 OS << "\t.secrel32\t";
517 Symbol->print(OS, MAI);
501518 EmitEOL();
502519 }
503520
504521 void MCAsmStreamer::emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) {
505522 assert(MAI->hasDotTypeDotSizeDirective());
506 OS << "\t.size\t" << *Symbol << ", " << *Value << '\n';
523 OS << "\t.size\t";
524 Symbol->print(OS, MAI);
525 OS << ", ";
526 Value->print(OS, MAI);
527 OS << '\n';
507528 }
508529
509530 void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
511532 // Common symbols do not belong to any actual section.
512533 AssignSection(Symbol, nullptr);
513534
514 OS << "\t.comm\t" << *Symbol << ',' << Size;
535 OS << "\t.comm\t";
536 Symbol->print(OS, MAI);
537 OS << ',' << Size;
538
515539 if (ByteAlignment != 0) {
516540 if (MAI->getCOMMDirectiveAlignmentIsInBytes())
517541 OS << ',' << ByteAlignment;
530554 // Common symbols do not belong to any actual section.
531555 AssignSection(Symbol, nullptr);
532556
533 OS << "\t.lcomm\t" << *Symbol << ',' << Size;
557 OS << "\t.lcomm\t";
558 Symbol->print(OS, MAI);
559 OS << ',' << Size;
560
534561 if (ByteAlign > 1) {
535562 switch (MAI->getLCOMMDirectiveAlignmentType()) {
536563 case LCOMM::NoAlignment:
560587 OS << MOSection->getSegmentName() << "," << MOSection->getSectionName();
561588
562589 if (Symbol) {
563 OS << ',' << *Symbol << ',' << Size;
590 OS << ',';
591 Symbol->print(OS, MAI);
592 OS << ',' << Size;
564593 if (ByteAlignment != 0)
565594 OS << ',' << Log2_32(ByteAlignment);
566595 }
577606 assert(Symbol && "Symbol shouldn't be NULL!");
578607 // Instead of using the Section we'll just use the shortcut.
579608 // This is a mach-o specific directive and section.
580 OS << ".tbss " << *Symbol << ", " << Size;
609 OS << ".tbss ";
610 Symbol->print(OS, MAI);
611 OS << ", " << Size;
581612
582613 // Output align if we have it. We default to 1 so don't bother printing
583614 // that.
702733 }
703734
704735 assert(Directive && "Invalid size for machine code value!");
705 OS << Directive << *Value;
736 OS << Directive;
737 Value->print(OS, MAI);
706738 EmitEOL();
707739 }
708740
712744 EmitULEB128IntValue(IntValue);
713745 return;
714746 }
715 OS << ".uleb128 " << *Value;
747 OS << ".uleb128 ";
748 Value->print(OS, MAI);
716749 EmitEOL();
717750 }
718751
722755 EmitSLEB128IntValue(IntValue);
723756 return;
724757 }
725 OS << ".sleb128 " << *Value;
758 OS << ".sleb128 ";
759 Value->print(OS, MAI);
726760 EmitEOL();
727761 }
728762
729763 void MCAsmStreamer::EmitGPRel64Value(const MCExpr *Value) {
730764 assert(MAI->getGPRel64Directive() != nullptr);
731 OS << MAI->getGPRel64Directive() << *Value;
765 OS << MAI->getGPRel64Directive();
766 Value->print(OS, MAI);
732767 EmitEOL();
733768 }
734769
735770 void MCAsmStreamer::EmitGPRel32Value(const MCExpr *Value) {
736771 assert(MAI->getGPRel32Directive() != nullptr);
737 OS << MAI->getGPRel32Directive() << *Value;
772 OS << MAI->getGPRel32Directive();
773 Value->print(OS, MAI);
738774 EmitEOL();
739775 }
740776
821857 bool MCAsmStreamer::EmitValueToOffset(const MCExpr *Offset,
822858 unsigned char Value) {
823859 // FIXME: Verify that Offset is associated with the current section.
824 OS << ".org " << *Offset << ", " << (unsigned) Value;
860 OS << ".org ";
861 Offset->print(OS, MAI);
862 OS << ", " << (unsigned)Value;
825863 EmitEOL();
826864 return false;
827865 }
9921030 void MCAsmStreamer::EmitCFIPersonality(const MCSymbol *Sym,
9931031 unsigned Encoding) {
9941032 MCStreamer::EmitCFIPersonality(Sym, Encoding);
995 OS << "\t.cfi_personality " << Encoding << ", " << *Sym;
1033 OS << "\t.cfi_personality " << Encoding << ", ";
1034 Sym->print(OS, MAI);
9961035 EmitEOL();
9971036 }
9981037
9991038 void MCAsmStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
10001039 MCStreamer::EmitCFILsda(Sym, Encoding);
1001 OS << "\t.cfi_lsda " << Encoding << ", " << *Sym;
1040 OS << "\t.cfi_lsda " << Encoding << ", ";
1041 Sym->print(OS, MAI);
10021042 EmitEOL();
10031043 }
10041044
10621102 void MCAsmStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol) {
10631103 MCStreamer::EmitWinCFIStartProc(Symbol);
10641104
1065 OS << ".seh_proc " << *Symbol;
1105 OS << ".seh_proc ";
1106 Symbol->print(OS, MAI);
10661107 EmitEOL();
10671108 }
10681109
10911132 bool Except) {
10921133 MCStreamer::EmitWinEHHandler(Sym, Unwind, Except);
10931134
1094 OS << "\t.seh_handler " << *Sym;
1135 OS << "\t.seh_handler ";
1136 Sym->print(OS, MAI);
10951137 if (Unwind)
10961138 OS << ", @unwind";
10971139 if (Except)
11981198 case MCFragment::FT_SafeSEH: {
11991199 const MCSafeSEHFragment *F = cast(this);
12001200 OS << "\n ";
1201 OS << " Sym:";
1202 F->getSymbol()->print(OS);
1201 OS << " Sym:" << F->getSymbol();
12031202 break;
12041203 }
12051204 }
2929 }
3030 }
3131
32 void MCExpr::print(raw_ostream &OS) const {
32 void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
3333 switch (getKind()) {
3434 case MCExpr::Target:
35 return cast(this)->printImpl(OS);
35 return cast(this)->printImpl(OS, MAI);
3636 case MCExpr::Constant:
3737 OS << cast(*this).getValue();
3838 return;
4242 const MCSymbol &Sym = SRE.getSymbol();
4343 // Parenthesize names that start with $ so that they don't look like
4444 // absolute names.
45 bool UseParens = !Sym.getName().empty() && Sym.getName()[0] == '$';
46 if (UseParens)
47 OS << '(' << Sym << ')';
48 else
49 OS << Sym;
45 bool UseParens = Sym.getName()[0] == '$';
46 if (UseParens) {
47 OS << '(';
48 Sym.print(OS, MAI);
49 OS << ')';
50 } else
51 Sym.print(OS, MAI);
5052
5153 if (SRE.getKind() != MCSymbolRefExpr::VK_None)
5254 SRE.printVariantKind(OS);
6264 case MCUnaryExpr::Not: OS << '~'; break;
6365 case MCUnaryExpr::Plus: OS << '+'; break;
6466 }
65 OS << *UE.getSubExpr();
67 UE.getSubExpr()->print(OS, MAI);
6668 return;
6769 }
6870
7173
7274 // Only print parens around the LHS if it is non-trivial.
7375 if (isa(BE.getLHS()) || isa(BE.getLHS())) {
74 OS << *BE.getLHS();
76 BE.getLHS()->print(OS, MAI);
7577 } else {
76 OS << '(' << *BE.getLHS() << ')';
78 OS << '(';
79 BE.getLHS()->print(OS, MAI);
80 OS << ')';
7781 }
7882
7983 switch (BE.getOpcode()) {
110114
111115 // Only print parens around the LHS if it is non-trivial.
112116 if (isa(BE.getRHS()) || isa(BE.getRHS())) {
113 OS << *BE.getRHS();
117 BE.getRHS()->print(OS, MAI);
114118 } else {
115 OS << '(' << *BE.getRHS() << ')';
119 OS << '(';
120 BE.getRHS()->print(OS, MAI);
121 OS << ')';
116122 }
117123 return;
118124 }
9393 break;
9494 }
9595 assert(COMDATSymbol);
96 OS << *COMDATSymbol;
96 COMDATSymbol->print(OS, &MAI);
9797 }
9898 OS << '\n';
9999 }
6363
6464 if (ShouldOmitSectionDirective(SectionName, MAI)) {
6565 OS << '\t' << getSectionName();
66 if (Subsection)
67 OS << '\t' << *Subsection;
66 if (Subsection) {
67 OS << '\t';
68 Subsection->print(OS, &MAI);
69 }
6870 OS << '\n';
6971 return;
7072 }
152154
153155 OS << '\n';
154156
155 if (Subsection)
156 OS << "\t.subsection\t" << *Subsection << '\n';
157 if (Subsection) {
158 OS << "\t.subsection\t";
159 Subsection->print(OS, &MAI);
160 OS << '\n';
161 }
157162 }
158163
159164 bool MCSectionELF::UseCodeAlign() const {
77 //===----------------------------------------------------------------------===//
88
99 #include "llvm/MC/MCSymbol.h"
10 #include "llvm/MC/MCAsmInfo.h"
1011 #include "llvm/MC/MCExpr.h"
1112 #include "llvm/Support/Debug.h"
13 #include "llvm/Support/ErrorHandling.h"
1214 #include "llvm/Support/raw_ostream.h"
1315 using namespace llvm;
1416
1517 // Sentinel value for the absolute pseudo section.
1618 MCSection *MCSymbol::AbsolutePseudoSection = reinterpret_cast(1);
17
18 static bool isAcceptableChar(char C) {
19 if ((C < 'a' || C > 'z') &&
20 (C < 'A' || C > 'Z') &&
21 (C < '0' || C > '9') &&
22 C != '_' && C != '$' && C != '.' && C != '@')
23 return false;
24 return true;
25 }
26
27 /// NameNeedsQuoting - Return true if the identifier \p Str needs quotes to be
28 /// syntactically correct.
29 static bool NameNeedsQuoting(StringRef Str) {
30 assert(!Str.empty() && "Cannot create an empty MCSymbol");
31
32 // If any of the characters in the string is an unacceptable character, force
33 // quotes.
34 for (unsigned i = 0, e = Str.size(); i != e; ++i)
35 if (!isAcceptableChar(Str[i]))
36 return true;
37 return false;
38 }
3919
4020 void MCSymbol::setVariableValue(const MCExpr *Value) {
4121 assert(!IsUsed && "Cannot set a variable that has already been used.");
4424 SectionOrFragment = nullptr;
4525 }
4626
47 void MCSymbol::print(raw_ostream &OS) const {
27 void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
4828 // The name for this MCSymbol is required to be a valid target name. However,
4929 // some targets support quoting names with funny characters. If the name
5030 // contains a funny character, then print it quoted.
5131 StringRef Name = getName();
52 if (Name.empty()) {
53 OS << "\"\"";
54 return;
55 }
56 if (!NameNeedsQuoting(Name)) {
32 if (!MAI || MAI->isValidUnquotedName(Name)) {
5733 OS << Name;
5834 return;
5935 }
6036
37 if (MAI && !MAI->supportsNameQuoting())
38 report_fatal_error("Symbol name with unsupported characters");
39
6140 OS << '"';
62 for (unsigned I = 0, E = Name.size(); I != E; ++I) {
63 char C = Name[I];
41 for (char C : Name) {
6442 if (C == '\n')
6543 OS << "\\n";
6644 else if (C == '"')
205205 // FIXME: Can we get anything other than a plain symbol here?
206206 assert(!MO.getTargetFlags() && "Unknown operand target flag!");
207207
208 O << *Sym;
208 Sym->print(O, MAI);
209209 printOffset(MO.getOffset(), O);
210210 break;
211211 }
205205 else
206206 O << "\tmovn\t";
207207
208 O << getRegisterName(MI->getOperand(0).getReg()) << ", #"
209 << *MI->getOperand(1).getExpr();
208 O << getRegisterName(MI->getOperand(0).getReg()) << ", #";
209 MI->getOperand(1).getExpr()->print(O, &MAI);
210210 return;
211211 }
212212
213213 if ((Opcode == AArch64::MOVKXi || Opcode == AArch64::MOVKWi) &&
214214 MI->getOperand(2).isExpr()) {
215 O << "\tmovk\t" << getRegisterName(MI->getOperand(0).getReg()) << ", #"
216 << *MI->getOperand(2).getExpr();
215 O << "\tmovk\t" << getRegisterName(MI->getOperand(0).getReg()) << ", #";
216 MI->getOperand(2).getExpr()->print(O, &MAI);
217217 return;
218218 }
219219
907907 O << '#' << Op.getImm();
908908 } else {
909909 assert(Op.isExpr() && "unknown operand kind in printOperand");
910 O << *Op.getExpr();
910 Op.getExpr()->print(O, &MAI);
911911 }
912912 }
913913
965965 *CommentStream << '=' << (Val << Shift) << '\n';
966966 } else {
967967 assert(MO.isExpr() && "Unexpected operand type!");
968 O << *MO.getExpr();
968 MO.getExpr()->print(O, &MAI);
969969 printShifter(MI, OpNum + 1, STI, O);
970970 }
971971 }
10901090 O << "#" << (MO.getImm() * Scale);
10911091 } else {
10921092 assert(MO.isExpr() && "Unexpected operand type!");
1093 O << *MO.getExpr();
1093 MO.getExpr()->print(O, &MAI);
10941094 }
10951095 }
10961096
11021102 O << ", #" << (MO1.getImm() * Scale);
11031103 } else {
11041104 assert(MO1.isExpr() && "Unexpected operand type!");
1105 O << ", " << *MO1.getExpr();
1105 O << ", ";
1106 MO1.getExpr()->print(O, &MAI);
11061107 }
11071108 O << ']';
11081109 }
12851286 O.write_hex(Address);
12861287 } else {
12871288 // Otherwise, just print the expression.
1288 O << *MI->getOperand(OpNum).getExpr();
1289 MI->getOperand(OpNum).getExpr()->print(O, &MAI);
12891290 }
12901291 }
12911292
13021303 }
13031304
13041305 // Otherwise, just print the expression.
1305 O << *MI->getOperand(OpNum).getExpr();
1306 MI->getOperand(OpNum).getExpr()->print(O, &MAI);
13061307 }
13071308
13081309 void AArch64InstPrinter::printBarrierOption(const MCInst *MI, unsigned OpNo,
7474 }
7575 }
7676
77 void AArch64MCExpr::printImpl(raw_ostream &OS) const {
77 void AArch64MCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
7878 if (getKind() != VK_NONE)
7979 OS << getVariantKindName();
80 OS << *Expr;
80 Expr->print(OS, MAI);
8181 }
8282
8383 void AArch64MCExpr::visitUsedExpr(MCStreamer &Streamer) const {
144144 /// (e.g. ":got:", ":lo12:").
145145 StringRef getVariantKindName() const;
146146
147 void printImpl(raw_ostream &OS) const override;
147 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
148148
149149 void visitUsedExpr(MCStreamer &Streamer) const override;
150150
172172 break;
173173 }
174174 case MachineOperand::MO_MachineBasicBlock:
175 O << *MO.getMBB()->getSymbol();
175 MO.getMBB()->getSymbol()->print(O, MAI);
176176 return;
177177 case MachineOperand::MO_GlobalAddress: {
178178 const GlobalValue *GV = MO.getGlobal();
180180 O << ":lower16:";
181181 else if (TF & ARMII::MO_HI16)
182182 O << ":upper16:";
183 O << *GetARMGVSymbol(GV, TF);
183 GetARMGVSymbol(GV, TF)->print(O, MAI);
184184
185185 printOffset(MO.getOffset(), O);
186186 if (TF == ARMII::MO_PLT)
188188 break;
189189 }
190190 case MachineOperand::MO_ConstantPoolIndex:
191 O << *GetCPISymbol(MO.getIndex());
191 GetCPISymbol(MO.getIndex())->print(O, MAI);
192192 break;
193193 }
194194 }
328328 const MCExpr *Expr = Op.getExpr();
329329 switch (Expr->getKind()) {
330330 case MCExpr::Binary:
331 O << '#' << *Expr;
331 O << '#';
332 Expr->print(O, &MAI);
332333 break;
333334 case MCExpr::Constant: {
334335 // If a symbolic branch target was added as a constant expression then
337338 const MCConstantExpr *Constant = cast(Expr);
338339 int64_t TargetAddress;
339340 if (!Constant->evaluateAsAbsolute(TargetAddress)) {
340 O << '#' << *Expr;
341 O << '#';
342 Expr->print(O, &MAI);
341343 } else {
342344 O << "0x";
343345 O.write_hex(static_cast(TargetAddress));
347349 default:
348350 // FIXME: Should we always treat this as if it is a constant literal and
349351 // prefix it with '#'?
350 O << *Expr;
352 Expr->print(O, &MAI);
351353 break;
352354 }
353355 }
358360 raw_ostream &O) {
359361 const MCOperand &MO1 = MI->getOperand(OpNum);
360362 if (MO1.isExpr()) {
361 O << *MO1.getExpr();
363 MO1.getExpr()->print(O, &MAI);
362364 return;
363365 }
364366
10541056 const MCOperand &MO = MI->getOperand(OpNum);
10551057
10561058 if (MO.isExpr()) {
1057 O << *MO.getExpr();
1059 MO.getExpr()->print(O, &MAI);
10581060 return;
10591061 }
10601062
213213 }
214214
215215 void ARMTargetAsmStreamer::emitThumbSet(MCSymbol *Symbol, const MCExpr *Value) {
216 OS << "\t.thumb_set\t" << *Symbol << ", " << *Value << '\n';
216 const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
217
218 OS << "\t.thumb_set\t";
219 Symbol->print(OS, MAI);
220 OS << ", ";
221 Value->print(OS, MAI);
222 OS << '\n';
217223 }
218224
219225 void ARMTargetAsmStreamer::emitInst(uint32_t Inst, char Suffix) {
2020 return new (Ctx) ARMMCExpr(Kind, Expr);
2121 }
2222
23 void ARMMCExpr::printImpl(raw_ostream &OS) const {
23 void ARMMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
2424 switch (Kind) {
2525 default: llvm_unreachable("Invalid kind!");
2626 case VK_ARM_HI16: OS << ":upper16:"; break;
3030 const MCExpr *Expr = getSubExpr();
3131 if (Expr->getKind() != MCExpr::SymbolRef)
3232 OS << '(';
33 Expr->print(OS);
33 Expr->print(OS, MAI);
3434 if (Expr->getKind() != MCExpr::SymbolRef)
3535 OS << ')';
3636 }
5555
5656 /// @}
5757
58 void printImpl(raw_ostream &OS) const override;
58 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
5959 bool evaluateAsRelocatableImpl(MCValue &Res,
6060 const MCAsmLayout *Layout,
6161 const MCFixup *Fixup) const override {
7878 O << MO.getImm();
7979 return;
8080 case MachineOperand::MO_MachineBasicBlock:
81 O << *MO.getMBB()->getSymbol();
81 MO.getMBB()->getSymbol()->print(O, MAI);
8282 return;
8383 case MachineOperand::MO_ConstantPoolIndex:
84 O << *GetCPISymbol(MO.getIndex());
84 GetCPISymbol(MO.getIndex())->print(O, MAI);
8585 return;
8686 case MachineOperand::MO_GlobalAddress:
8787 // Computing the address of a global symbol, not calling it.
88 O << *getSymbol(MO.getGlobal());
88 getSymbol(MO.getGlobal())->print(O, MAI);
8989 printOffset(MO.getOffset(), O);
9090 return;
9191 }
163163 if (MO.isReg()) {
164164 printRegName(O, MO.getReg());
165165 } else if(MO.isExpr()) {
166 O << *MO.getExpr();
166 MO.getExpr()->print(O, &MAI);
167167 } else if(MO.isImm()) {
168168 printImmOperand(MI, OpNo, O);
169169 } else {
176176 const MCOperand& MO = MI->getOperand(OpNo);
177177
178178 if(MO.isExpr()) {
179 O << *MO.getExpr();
179 MO.getExpr()->print(O, &MAI);
180180 } else if(MO.isImm()) {
181181 O << MI->getOperand(OpNo).getImm();
182182 } else {
3838 O << Op.getImm();
3939 else {
4040 assert(Op.isExpr() && "unknown pcrel immediate operand");
41 O << *Op.getExpr();
41 Op.getExpr()->print(O, &MAI);
4242 }
4343 }
4444
5252 O << '#' << Op.getImm();
5353 } else {
5454 assert(Op.isExpr() && "unknown operand kind in printOperand");
55 O << '#' << *Op.getExpr();
55 O << '#';
56 Op.getExpr()->print(O, &MAI);
5657 }
5758 }
5859
7475 O << '&';
7576
7677 if (Disp.isExpr())
77 O << *Disp.getExpr();
78 Disp.getExpr()->print(O, &MAI);
7879 else {
7980 assert(Disp.isImm() && "Expected immediate in displacement field");
8081 O << Disp.getImm();
7474 O << MO.getImm();
7575 return;
7676 case MachineOperand::MO_MachineBasicBlock:
77 O << *MO.getMBB()->getSymbol();
77 MO.getMBB()->getSymbol()->print(O, MAI);
7878 return;
7979 case MachineOperand::MO_GlobalAddress: {
8080 bool isMemOp = Modifier && !strcmp(Modifier, "mem");
9191 if (Offset)
9292 O << '(' << Offset << '+';
9393
94 O << *getSymbol(MO.getGlobal());
94 getSymbol(MO.getGlobal())->print(O, MAI);
9595
9696 if (Offset)
9797 O << ')';
121121 }
122122 }
123123
124 static void printExpr(const MCExpr *Expr, raw_ostream &OS) {
124 static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI,
125 raw_ostream &OS) {
125126 int Offset = 0;
126127 const MCSymbolRefExpr *SRE;
127128
131132 assert(SRE && CE && "Binary expression must be sym+const.");
132133 Offset = CE->getValue();
133134 } else if (const MipsMCExpr *ME = dyn_cast(Expr)) {
134 ME->print(OS);
135 ME->print(OS, MAI);
135136 return;
136137 } else
137138 SRE = cast(Expr);
169170 case MCSymbolRefExpr::VK_Mips_PCREL_LO16: OS << "%pcrel_lo("; break;
170171 }
171172
172 OS << SRE->getSymbol();
173 SRE->getSymbol().print(OS, MAI);
173174
174175 if (Offset) {
175176 if (Offset > 0)
198199 }
199200
200201 assert(Op.isExpr() && "unknown operand kind in printOperand");
201 printExpr(Op.getExpr(), O);
202 printExpr(Op.getExpr(), &MAI, O);
202203 }
203204
204205 void MipsInstPrinter::printUnsignedImm(const MCInst *MI, int opNum,
6363 return new (Ctx) MipsMCExpr(Kind, Expr);
6464 }
6565
66 void MipsMCExpr::printImpl(raw_ostream &OS) const {
66 void MipsMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
6767 switch (Kind) {
6868 default: llvm_unreachable("Invalid kind!");
6969 case VK_Mips_LO: OS << "%lo"; break;
7373 }
7474
7575 OS << '(';
76 Expr->print(OS);
76 Expr->print(OS, MAI);
7777 OS << ')';
7878 }
7979
4545 /// getSubExpr - Get the child of this expression.
4646 const MCExpr *getSubExpr() const { return Expr; }
4747
48 void printImpl(raw_ostream &OS) const override;
48 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
4949 bool evaluateAsRelocatableImpl(MCValue &Res,
5050 const MCAsmLayout *Layout,
5151 const MCFixup *Fixup) const override;
593593 break;
594594
595595 case MachineOperand::MO_MachineBasicBlock:
596 O << *MO.getMBB()->getSymbol();
596 MO.getMBB()->getSymbol()->print(O, MAI);
597597 return;
598598
599599 case MachineOperand::MO_GlobalAddress:
600 O << *getSymbol(MO.getGlobal());
600 getSymbol(MO.getGlobal())->print(O, MAI);
601601 break;
602602
603603 case MachineOperand::MO_BlockAddress: {
8484 O << markup("");
8585 } else {
8686 assert(Op.isExpr() && "Unknown operand kind in printOperand");
87 O << *Op.getExpr();
87 Op.getExpr()->print(O, &MAI);
8888 }
8989 }
9090
466466 printReturnValStr(*MF, O);
467467 }
468468
469 O << *CurrentFnSym;
469 CurrentFnSym->print(O, MAI);
470470
471471 emitFunctionParamList(*MF, O);
472472
623623 else
624624 O << ".func ";
625625 printReturnValStr(F, O);
626 O << *getSymbol(F) << "\n";
626 getSymbol(F)->print(O, MAI);
627 O << "\n";
627628 emitFunctionParamList(F, O);
628629 O << ";\n";
629630 }
11701171 else
11711172 O << getPTXFundamentalTypeStr(ETy, false);
11721173 O << " ";
1173 O << *getSymbol(GVar);
1174 getSymbol(GVar)->print(O, MAI);
11741175
11751176 // Ptx allows variable initilization only for constant and global state
11761177 // spaces.
12161217 bufferAggregateConstant(Initializer, &aggBuffer);
12171218 if (aggBuffer.numSymbols) {
12181219 if (static_cast(TM).is64Bit()) {
1219 O << " .u64 " << *getSymbol(GVar) << "[";
1220 O << " .u64 ";
1221 getSymbol(GVar)->print(O, MAI);
1222 O << "[";
12201223 O << ElementSize / 8;
12211224 } else {
1222 O << " .u32 " << *getSymbol(GVar) << "[";
1225 O << " .u32 ";
1226 getSymbol(GVar)->print(O, MAI);
1227 O << "[";
12231228 O << ElementSize / 4;
12241229 }
12251230 O << "]";
12261231 } else {
1227 O << " .b8 " << *getSymbol(GVar) << "[";
1232 O << " .b8 ";
1233 getSymbol(GVar)->print(O, MAI);
1234 O << "[";
12281235 O << ElementSize;
12291236 O << "]";
12301237 }
12321239 aggBuffer.print();
12331240 O << "}";
12341241 } else {
1235 O << " .b8 " << *getSymbol(GVar);
1242 O << " .b8 ";
1243 getSymbol(GVar)->print(O, MAI);
12361244 if (ElementSize) {
12371245 O << "[";
12381246 O << ElementSize;
12401248 }
12411249 }
12421250 } else {
1243 O << " .b8 " << *getSymbol(GVar);
1251 O << " .b8 ";
1252 getSymbol(GVar)->print(O, MAI);
12441253 if (ElementSize) {
12451254 O << "[";
12461255 O << ElementSize;
13471356 O << " .";
13481357 O << getPTXFundamentalTypeStr(ETy);
13491358 O << " ";
1350 O << *getSymbol(GVar);
1359 getSymbol(GVar)->print(O, MAI);
13511360 return;
13521361 }
13531362
13621371 case Type::ArrayTyID:
13631372 case Type::VectorTyID:
13641373 ElementSize = TD->getTypeStoreSize(ETy);
1365 O << " .b8 " << *getSymbol(GVar) << "[";
1374 O << " .b8 ";
1375 getSymbol(GVar)->print(O, MAI);
1376 O << "[";
13661377 if (ElementSize) {
13671378 O << ElementSize;
13681379 }
14041415
14051416 void NVPTXAsmPrinter::printParamName(Function::const_arg_iterator I,
14061417 int paramIndex, raw_ostream &O) {
1407 O << *getSymbol(I->getParent()) << "_param_" << paramIndex;
1418 getSymbol(I->getParent())->print(O, MAI);
1419 O << "_param_" << paramIndex;
14081420 }
14091421
14101422 void NVPTXAsmPrinter::printParamName(int paramIndex, raw_ostream &O) {
1411 O << *CurrentFnSym << "_param_" << paramIndex;
1423 CurrentFnSym->print(O, MAI);
1424 O << "_param_" << paramIndex;
14121425 }
14131426
14141427 void NVPTXAsmPrinter::emitFunctionParamList(const Function *F, raw_ostream &O) {
14421455 O << "\t.param .u64 .ptr .surfref ";
14431456 else
14441457 O << "\t.param .surfref ";
1445 O << *CurrentFnSym << "_param_" << paramIndex;
1458 CurrentFnSym->print(O, MAI);
1459 O << "_param_" << paramIndex;
14461460 }
14471461 else { // Default image is read_only
14481462 if (nvptxSubtarget->hasImageHandles())
14491463 O << "\t.param .u64 .ptr .texref ";
14501464 else
14511465 O << "\t.param .texref ";
1452 O << *CurrentFnSym << "_param_" << paramIndex;
1466 CurrentFnSym->print(O, MAI);
1467 O << "_param_" << paramIndex;
14531468 }
14541469 } else {
14551470 if (nvptxSubtarget->hasImageHandles())
14561471 O << "\t.param .u64 .ptr .samplerref ";
14571472 else
14581473 O << "\t.param .samplerref ";
1459 O << *CurrentFnSym << "_param_" << paramIndex;
1474 CurrentFnSym->print(O, MAI);
1475 O << "_param_" << paramIndex;
14601476 }
14611477 continue;
14621478 }
17121728 }
17131729 if (EmitGeneric && !isa(CPV) && !IsNonGenericPointer) {
17141730 O << "generic(";
1715 O << *getSymbol(GVar);
1731 getSymbol(GVar)->print(O, MAI);
17161732 O << ")";
17171733 } else {
1718 O << *getSymbol(GVar);
1734 getSymbol(GVar)->print(O, MAI);
17191735 }
17201736 return;
17211737 }
17291745 if (const GlobalValue *GVar = dyn_cast(v)) {
17301746 if (EmitGeneric && !isa(v) && !IsNonGenericPointer) {
17311747 O << "generic(";
1732 O << *getSymbol(GVar);
1748 getSymbol(GVar)->print(O, MAI);
17331749 O << ")";
17341750 } else {
1735 O << *getSymbol(GVar);
1751 getSymbol(GVar)->print(O, MAI);
17361752 }
17371753 return;
17381754 } else {
1739 O << *lowerConstant(CPV);
1755 lowerConstant(CPV)->print(O, MAI);
17401756 return;
17411757 }
17421758 }
21192135 void NVPTXAsmPrinter::printMCExpr(const MCExpr &Expr, raw_ostream &OS) {
21202136 switch (Expr.getKind()) {
21212137 case MCExpr::Target:
2122 return cast(&Expr)->printImpl(OS);
2138 return cast(&Expr)->printImpl(OS, MAI);
21232139 case MCExpr::Constant:
21242140 OS << cast(Expr).getValue();
21252141 return;
21272143 case MCExpr::SymbolRef: {
21282144 const MCSymbolRefExpr &SRE = cast(Expr);
21292145 const MCSymbol &Sym = SRE.getSymbol();
2130 OS << Sym;
2146 Sym.print(OS, MAI);
21312147 return;
21322148 }
21332149
22522268 break;
22532269
22542270 case MachineOperand::MO_GlobalAddress:
2255 O << *getSymbol(MO.getGlobal());
2271 getSymbol(MO.getGlobal())->print(O, MAI);
22562272 break;
22572273
22582274 case MachineOperand::MO_MachineBasicBlock:
2259 O << *MO.getMBB()->getSymbol();
2275 MO.getMBB()->getSymbol()->print(O, MAI);
22602276 return;
22612277
22622278 default:
164164 }
165165 if (EmitGeneric && !isa(v) && !IsNonGenericPointer) {
166166 O << "generic(";
167 O << *Name;
167 Name->print(O, AP.MAI);
168168 O << ")";
169169 } else {
170 O << *Name;
170 Name->print(O, AP.MAI);
171171 }
172172 } else if (const ConstantExpr *CExpr = dyn_cast(v0)) {
173173 const MCExpr *Expr =
1919 return new (Ctx) NVPTXFloatMCExpr(Kind, Flt);
2020 }
2121
22 void NVPTXFloatMCExpr::printImpl(raw_ostream &OS) const {
22 void NVPTXFloatMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
2323 bool Ignored;
2424 unsigned NumHex;
2525 APFloat APF = getAPFloat();
5151 return new (Ctx) NVPTXGenericMCSymbolRefExpr(SymExpr);
5252 }
5353
54 void NVPTXGenericMCSymbolRefExpr::printImpl(raw_ostream &OS) const {
55 OS << "generic(" << *SymExpr << ")";
54 void NVPTXGenericMCSymbolRefExpr::printImpl(raw_ostream &OS,
55 const MCAsmInfo *MAI) const {
56 OS << "generic(";
57 SymExpr->print(OS, MAI);
58 OS << ")";
5659 }
6060
6161 /// @}
6262
63 void printImpl(raw_ostream &OS) const override;
63 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
6464 bool evaluateAsRelocatableImpl(MCValue &Res,
6565 const MCAsmLayout *Layout,
6666 const MCFixup *Fixup) const override {
102102
103103 /// @}
104104
105 void printImpl(raw_ostream &OS) const override;
105 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
106106 bool evaluateAsRelocatableImpl(MCValue &Res,
107107 const MCAsmLayout *Layout,
108108 const MCFixup *Fixup) const override {
444444 }
445445
446446 assert(Op.isExpr() && "unknown operand kind in printOperand");
447 O << *Op.getExpr();
448 }
449
447 Op.getExpr()->print(O, &MAI);
448 }
449
2323 return new (Ctx) PPCMCExpr(Kind, Expr, isDarwin);
2424 }
2525
26 void PPCMCExpr::printImpl(raw_ostream &OS) const {
26 void PPCMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
2727 if (isDarwinSyntax()) {
2828 switch (Kind) {
2929 default: llvm_unreachable("Invalid kind!");
3333 }
3434
3535 OS << '(';
36 getSubExpr()->print(OS);
36 getSubExpr()->print(OS, MAI);
3737 OS << ')';
3838 } else {
39 getSubExpr()->print(OS);
39 getSubExpr()->print(OS, MAI);
4040
4141 switch (Kind) {
4242 default: llvm_unreachable("Invalid kind!");
7676
7777 /// @}
7878
79 void printImpl(raw_ostream &OS) const override;
79 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
8080 bool evaluateAsRelocatableImpl(MCValue &Res,
8181 const MCAsmLayout *Layout,
8282 const MCFixup *Fixup) const override;
1515 #include "PPCMCAsmInfo.h"
1616 #include "PPCTargetStreamer.h"
1717 #include "llvm/MC/MCCodeGenInfo.h"
18 #include "llvm/MC/MCContext.h"
1819 #include "llvm/MC/MCELFStreamer.h"
1920 #include "llvm/MC/MCExpr.h"
2021 #include "llvm/MC/MCInstrInfo.h"
131132 OS << "\t.abiversion " << AbiVersion << '\n';
132133 }
133134 void emitLocalEntry(MCSymbolELF *S, const MCExpr *LocalOffset) override {
134 OS << "\t.localentry\t" << *S << ", " << *LocalOffset << '\n';
135 const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
136
137 OS << "\t.localentry\t";
138 S->print(OS, MAI);
139 OS << ", ";
140 LocalOffset->print(OS, MAI);
141 OS << '\n';
135142 }
136143 };
137144
180180 return;
181181
182182 case MachineOperand::MO_MachineBasicBlock:
183 O << *MO.getMBB()->getSymbol();
183 MO.getMBB()->getSymbol()->print(O, MAI);
184184 return;
185185 case MachineOperand::MO_ConstantPoolIndex:
186186 O << DL->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
187187 << '_' << MO.getIndex();
188188 return;
189189 case MachineOperand::MO_BlockAddress:
190 O << *GetBlockAddressSymbol(MO.getBlockAddress());
190 GetBlockAddressSymbol(MO.getBlockAddress())->print(O, MAI);
191191 return;
192192 case MachineOperand::MO_GlobalAddress: {
193193 // Computing the address of a global symbol, not calling it.
221221 } else {
222222 SymToPrint = getSymbol(GV);
223223 }
224
225 O << *SymToPrint;
224
225 SymToPrint->print(O, MAI);
226226
227227 printOffset(MO.getOffset(), O);
228228 return;
336336 }
337337 } else if (Op.isExpr()) {
338338 const MCExpr *Exp = Op.getExpr();
339 Exp->print(O);
339 Exp->print(O, &MAI);
340340 } else {
341341 llvm_unreachable("unknown operand type in printOperand");
342342 }
119119 }
120120
121121 assert(MO.isExpr() && "Unknown operand kind in printOperand");
122 MO.getExpr()->print(O);
122 MO.getExpr()->print(O, &MAI);
123123 }
124124
125125 void SparcInstPrinter::printMemOperand(const MCInst *MI, int opNum,
2929 return new (Ctx) SparcMCExpr(Kind, Expr);
3030 }
3131
32
33
34 void SparcMCExpr::printImpl(raw_ostream &OS) const
35 {
32 void SparcMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
3633
3734 bool closeParen = printVariantKind(OS, Kind);
3835
3936 const MCExpr *Expr = getSubExpr();
40 Expr->print(OS);
37 Expr->print(OS, MAI);
4138
4239 if (closeParen)
4340 OS << ')';
8484 Sparc::Fixups getFixupKind() const { return getFixupKind(Kind); }
8585
8686 /// @}
87 void printImpl(raw_ostream &OS) const override;
87 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
8888 bool evaluateAsRelocatableImpl(MCValue &Res,
8989 const MCAsmLayout *Layout,
9090 const MCFixup *Fixup) const override;
360360 O << (int)MO.getImm();
361361 break;
362362 case MachineOperand::MO_MachineBasicBlock:
363 O << *MO.getMBB()->getSymbol();
363 MO.getMBB()->getSymbol()->print(O, MAI);
364364 return;
365365 case MachineOperand::MO_GlobalAddress:
366 O << *getSymbol(MO.getGlobal());
366 getSymbol(MO.getGlobal())->print(O, MAI);
367367 break;
368368 case MachineOperand::MO_BlockAddress:
369369 O << GetBlockAddressSymbol(MO.getBlockAddress())->getName();
3636 }
3737 }
3838
39 void SystemZInstPrinter::printOperand(const MCOperand &MO, raw_ostream &O) {
39 void SystemZInstPrinter::printOperand(const MCOperand &MO, const MCAsmInfo *MAI,
40 raw_ostream &O) {
4041 if (MO.isReg())
4142 O << '%' << getRegisterName(MO.getReg());
4243 else if (MO.isImm())
4344 O << MO.getImm();
4445 else if (MO.isExpr())
45 O << *MO.getExpr();
46 MO.getExpr()->print(O, MAI);
4647 else
4748 llvm_unreachable("Invalid operand");
4849 }
146147 O << "0x";
147148 O.write_hex(MO.getImm());
148149 } else
149 O << *MO.getExpr();
150 MO.getExpr()->print(O, &MAI);
150151 }
151152
152153 void SystemZInstPrinter::printPCRelTLSOperand(const MCInst *MI, int OpNum,
174175
175176 void SystemZInstPrinter::printOperand(const MCInst *MI, int OpNum,
176177 raw_ostream &O) {
177 printOperand(MI->getOperand(OpNum), O);
178 printOperand(MI->getOperand(OpNum), &MAI, O);
178179 }
179180
180181 void SystemZInstPrinter::printBDAddrOperand(const MCInst *MI, int OpNum,
3434 raw_ostream &O);
3535
3636 // Print the given operand.
37 static void printOperand(const MCOperand &MO, raw_ostream &O);
37 static void printOperand(const MCOperand &MO, const MCAsmInfo *MAI,
38 raw_ostream &O);
3839
3940 // Override MCInstPrinter.
4041 void printRegName(raw_ostream &O, unsigned RegNo) const override;
304304 } else {
305305 SystemZMCInstLower Lower(MF->getContext(), *this);
306306 MCOperand MO(Lower.lowerOperand(MI->getOperand(OpNo)));
307 SystemZInstPrinter::printOperand(MO, OS);
307 SystemZInstPrinter::printOperand(MO, MAI, OS);
308308 }
309309 return false;
310310 }
153153 O << formatHex((uint64_t)Address);
154154 } else {
155155 // Otherwise, just print the expression.
156 O << *Op.getExpr();
156 Op.getExpr()->print(O, &MAI);
157157 }
158158 }
159159 }
177177
178178 } else {
179179 assert(Op.isExpr() && "unknown operand kind in printOperand");
180 O << markup(" << *Op.getExpr() << markup(">");
180 O << markup(";
181 Op.getExpr()->print(O, &MAI);
182 O << markup(">");
181183 }
182184 }
183185
202204 O << formatImm(DispVal);
203205 } else {
204206 assert(DispSpec.isExpr() && "non-immediate displacement for LEA?");
205 O << *DispSpec.getExpr();
207 DispSpec.getExpr()->print(O, &MAI);
206208 }
207209
208210 if (IndexReg.getReg() || BaseReg.getReg()) {
272274 O << formatImm(DispSpec.getImm());
273275 } else {
274276 assert(DispSpec.isExpr() && "non-immediate displacement?");
275 O << *DispSpec.getExpr();
277 DispSpec.getExpr()->print(O, &MAI);
276278 }
277279
278280 O << markup(">");
135135 }
136136 else {
137137 // Otherwise, just print the expression.
138 O << *Op.getExpr();
138 Op.getExpr()->print(O, &MAI);
139139 }
140140 }
141141 }
149149 O << formatImm((int64_t)Op.getImm());
150150 } else {
151151 assert(Op.isExpr() && "unknown operand kind in printOperand");
152 O << *Op.getExpr();
152 Op.getExpr()->print(O, &MAI);
153153 }
154154 }
155155
186186 if (!DispSpec.isImm()) {
187187 if (NeedPlus) O << " + ";
188188 assert(DispSpec.isExpr() && "non-immediate displacement for LEA?");
189 O << *DispSpec.getExpr();
189 DispSpec.getExpr()->print(O, &MAI);
190190 } else {
191191 int64_t DispVal = DispSpec.getImm();
192192 if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg())) {
244244 O << formatImm(DispSpec.getImm());
245245 } else {
246246 assert(DispSpec.isExpr() && "non-immediate displacement?");
247 O << *DispSpec.getExpr();
247 DispSpec.getExpr()->print(O, &MAI);
248248 }
249249
250250 O << ']';
7777 switch (MO.getType()) {
7878 default: llvm_unreachable("unknown symbol type!");
7979 case MachineOperand::MO_ConstantPoolIndex:
80 O << *P.GetCPISymbol(MO.getIndex());
80 P.GetCPISymbol(MO.getIndex())->print(O, P.MAI);
8181 P.printOffset(MO.getOffset(), O);
8282 break;
8383 case MachineOperand::MO_GlobalAddress: {
126126 // If the name begins with a dollar-sign, enclose it in parens. We do this
127127 // to avoid having it look like an integer immediate to the assembler.
128128 if (GVSym->getName()[0] != '$')
129 O << *GVSym;
130 else
131 O << '(' << *GVSym << ')';
129 GVSym->print(O, P.MAI);
130 else {
131 O << '(';
132 GVSym->print(O, P.MAI);
133 O << ')';
134 }
132135 P.printOffset(MO.getOffset(), O);
133136 break;
134137 }
145148 // These affect the name of the symbol, not any suffix.
146149 break;
147150 case X86II::MO_GOT_ABSOLUTE_ADDRESS:
148 O << " + [.-" << *P.MF->getPICBaseSymbol() << ']';
151 O << " + [.-";
152 P.MF->getPICBaseSymbol()->print(O, P.MAI);
153 O << ']';
149154 break;
150155 case X86II::MO_PIC_BASE_OFFSET:
151156 case X86II::MO_DARWIN_NONLAZY_PIC_BASE:
152157 case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE:
153 O << '-' << *P.MF->getPICBaseSymbol();
158 O << '-';
159 P.MF->getPICBaseSymbol()->print(O, P.MAI);
154160 break;
155161 case X86II::MO_TLSGD: O << "@TLSGD"; break;
156162 case X86II::MO_TLSLD: O << "@TLSLD"; break;
167173 case X86II::MO_PLT: O << "@PLT"; break;
168174 case X86II::MO_TLVP: O << "@TLVP"; break;
169175 case X86II::MO_TLVP_PIC_BASE:
170 O << "@TLVP" << '-' << *P.MF->getPICBaseSymbol();
176 O << "@TLVP" << '-';
177 P.MF->getPICBaseSymbol()->print(O, P.MAI);
171178 break;
172179 case X86II::MO_SECREL: O << "@SECREL32"; break;
173180 }
4444 report_fatal_error("can't handle InlineJT32");
4545 }
4646
47 static void printExpr(const MCExpr *Expr, raw_ostream &OS) {
47 static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI,
48 raw_ostream &OS) {
4849 int Offset = 0;
4950 const MCSymbolRefExpr *SRE;
5051
5960 }
6061 assert(SRE->getKind() == MCSymbolRefExpr::VK_None);
6162
62 OS << SRE->getSymbol();
63 SRE->getSymbol().print(OS, MAI);
6364
6465 if (Offset) {
6566 if (Offset > 0)
8283 }
8384
8485 assert(Op.isExpr() && "unknown operand kind in printOperand");
85 printExpr(Op.getExpr(), O);
86 printExpr(Op.getExpr(), &MAI, O);
8687 }
201201 MachineBasicBlock *MBB = JTBBs[i];
202202 if (i > 0)
203203 O << ",";
204 O << *MBB->getSymbol();
204 MBB->getSymbol()->print(O, MAI);
205205 }
206206 }
207207
217217 O << MO.getImm();
218218 break;
219219 case MachineOperand::MO_MachineBasicBlock:
220 O << *MO.getMBB()->getSymbol();
220 MO.getMBB()->getSymbol()->print(O, MAI);
221221 break;
222222 case MachineOperand::MO_GlobalAddress:
223 O << *getSymbol(MO.getGlobal());
223 getSymbol(MO.getGlobal())->print(O, MAI);
224224 break;
225225 case MachineOperand::MO_ConstantPoolIndex:
226226 O << DL->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
227227 << '_' << MO.getIndex();
228228 break;
229229 case MachineOperand::MO_BlockAddress:
230 O << *GetBlockAddressSymbol(MO.getBlockAddress());
230 GetBlockAddressSymbol(MO.getBlockAddress())->print(O, MAI);
231231 break;
232232 default:
233233 llvm_unreachable("not implemented");