llvm.org GIT mirror llvm / 684c593
Thread an MCAsmInfo pointer through the various MC printing APIs, and fix a few things using << on MCSymbols to use ->print(). No functionality change other than unbreaking my previous patch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80890 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
10 changed file(s) with 49 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
1313 #include "llvm/Support/DataTypes.h"
1414
1515 namespace llvm {
16 class MCAsmInfo;
1617 class MCContext;
1718 class MCSymbol;
1819 class MCValue;
4849 /// @name Utility Methods
4950 /// @{
5051
51 void print(raw_ostream &OS) const;
52 void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
5253 void dump() const;
5354
5455 /// @}
2121
2222 namespace llvm {
2323 class raw_ostream;
24 class MCAsmInfo;
2425 class MCExpr;
2526
2627 /// MCOperand - Instances of this class represent operands of the MCInst class.
120121 return Op;
121122 }
122123
123 void print(raw_ostream &OS) const;
124 void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
124125 void dump() const;
125126 };
126127
146147 Operands.push_back(Op);
147148 }
148149
149 void print(raw_ostream &OS) const;
150 void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
150151 void dump() const;
151152 };
152153
1818 #include "llvm/Support/DataTypes.h"
1919
2020 namespace llvm {
21 class MCAsmInfo;
2122 class MCSection;
2223 class MCContext;
2324 class raw_ostream;
105106 /// @}
106107
107108 /// print - Print the value to the stream \arg OS.
108 void print(raw_ostream &OS) const;
109 void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
109110
110111 /// dump - Print the value to stderr.
111112 void dump() const;
5454 const MCSection *getAssociatedSection() const;
5555
5656 /// print - Print the value to the stream \arg OS.
57 void print(raw_ostream &OS) const;
57 void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
5858
5959 /// dump - Print the value to stderr.
6060 void dump() const;
100100 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
101101 assert(CurSection && "Cannot emit before setting section!");
102102
103 OS << Symbol << ":\n";
103 Symbol->print(OS, &MAI);
104 OS << ":\n";
104105 Symbol->setSection(*CurSection);
105106 }
106107
117118 assert((Symbol->isUndefined() || Symbol->isAbsolute()) &&
118119 "Cannot define a symbol twice!");
119120
120 OS << Symbol << " = ";
121 Value->print(OS);
121 Symbol->print(OS, &MAI);
122 OS << " = ";
123 Value->print(OS, &MAI);
122124 OS << '\n';
123125 }
124126
139141 case WeakReference: OS << ".weak_reference"; break;
140142 }
141143
142 OS << ' ' << Symbol << '\n';
144 OS << ' ';
145 Symbol->print(OS, &MAI);
146 OS << '\n';
143147 }
144148
145149 void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
146 OS << ".desc" << ' ' << Symbol << ',' << DescValue << '\n';
150 OS << ".desc" << ' ';
151 Symbol->print(OS, &MAI);
152 OS << ',' << DescValue << '\n';
147153 }
148154
149155 void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, unsigned Size,
150156 unsigned ByteAlignment) {
151 OS << ".comm";
152 OS << ' ' << Symbol << ',' << Size;
157 OS << ".comm ";
158 Symbol->print(OS, &MAI);
159 OS << ',' << Size;
153160 if (ByteAlignment != 0)
154161 OS << ',' << Log2_32(ByteAlignment);
155162 OS << '\n';
165172 OS << MOSection->getSegmentName() << "," << MOSection->getSectionName();
166173
167174 if (Symbol != NULL) {
168 OS << ',' << Symbol << ',' << Size;
175 OS << ',';
176 Symbol->print(OS, &MAI);
177 OS << ',' << Size;
169178 if (ByteAlignment != 0)
170179 OS << ',' << Log2_32(ByteAlignment);
171180 }
191200 }
192201
193202 OS << ' ';
194 truncateToSize(Value, Size)->print(OS);
203 truncateToSize(Value, Size)->print(OS, &MAI);
195204 OS << '\n';
196205 }
197206
247256 unsigned char Value) {
248257 // FIXME: Verify that Offset is associated with the current section.
249258 OS << ".org ";
250 Offset->print(OS);
259 Offset->print(OS, &MAI);
251260 OS << ", " << (unsigned) Value << '\n';
252261 }
253262
280289
281290 // Otherwise fall back to a structural printing for now. Eventually we should
282291 // always have access to the target specific printer.
283 Inst.print(OS);
292 Inst.print(OS, &MAI);
284293 OS << '\n';
285294 }
286295
1313 #include "llvm/Support/raw_ostream.h"
1414 using namespace llvm;
1515
16 void MCExpr::print(raw_ostream &OS) const {
16 void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
1717 switch (getKind()) {
1818 case MCExpr::Constant:
1919 OS << cast(*this).getValue();
2020 return;
2121
2222 case MCExpr::SymbolRef:
23 cast(*this).getSymbol().print(OS);
23 cast(*this).getSymbol().print(OS, MAI);
2424 return;
2525
2626 case MCExpr::Unary: {
3232 case MCUnaryExpr::Not: OS << '~'; break;
3333 case MCUnaryExpr::Plus: OS << '+'; break;
3434 }
35 UE.getSubExpr()->print(OS);
35 UE.getSubExpr()->print(OS, MAI);
3636 return;
3737 }
3838
3939 case MCExpr::Binary: {
4040 const MCBinaryExpr &BE = cast(*this);
4141 OS << '(';
42 BE.getLHS()->print(OS);
42 BE.getLHS()->print(OS, MAI);
4343 OS << ' ';
4444 switch (BE.getOpcode()) {
4545 default: assert(0 && "Invalid opcode!");
6363 case MCBinaryExpr::Xor: OS << '^'; break;
6464 }
6565 OS << ' ';
66 BE.getRHS()->print(OS);
66 BE.getRHS()->print(OS, MAI);
6767 OS << ')';
6868 return;
6969 }
7373 }
7474
7575 void MCExpr::dump() const {
76 print(errs());
76 print(errs(), 0);
7777 errs() << '\n';
7878 }
7979
1212
1313 using namespace llvm;
1414
15 void MCOperand::print(raw_ostream &OS) const {
15 void MCOperand::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
1616 OS << "
1717 if (!isValid())
1818 OS << "INVALID";
2525 << getMBBLabelBlock() << ")";
2626 else if (isExpr()) {
2727 OS << "Expr:(";
28 getExpr()->print(OS);
28 getExpr()->print(OS, MAI);
2929 OS << ")";
3030 } else
3131 OS << "UNDEFINED";
3333 }
3434
3535 void MCOperand::dump() const {
36 print(errs());
36 print(errs(), 0);
3737 errs() << "\n";
3838 }
3939
40 void MCInst::print(raw_ostream &OS) const {
40 void MCInst::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
4141 OS << "
4242 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
4343 OS << " ";
44 getOperand(i).print(OS);
44 getOperand(i).print(OS, MAI);
4545 }
4646 OS << ">";
4747 }
4848
4949 void MCInst::dump() const {
50 print(errs());
50 print(errs(), 0);
5151 errs() << "\n";
5252 }
4040 return false;
4141 }
4242
43 void MCSymbol::print(raw_ostream &OS) const {
43 void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
4444 if (NeedsQuoting(getName()))
4545 OS << '"' << getName() << '"';
4646 else
4848 }
4949
5050 void MCSymbol::dump() const {
51 print(errs());
51 print(errs(), 0);
5252 }
1111
1212 using namespace llvm;
1313
14 void MCValue::print(raw_ostream &OS) const {
14 void MCValue::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
1515 if (isAbsolute()) {
1616 OS << getConstant();
1717 return;
1818 }
1919
20 getSymA()->print(OS);
20 getSymA()->print(OS, MAI);
2121
2222 if (getSymB()) {
2323 OS << " - ";
24 getSymB()->print(OS);
24 getSymB()->print(OS, MAI);
2525 }
2626
2727 if (getConstant())
2929 }
3030
3131 void MCValue::dump() const {
32 print(errs());
32 print(errs(), 0);
3333 }
5656 if (Op.isImm())
5757 O << Op.getImm();
5858 else if (Op.isExpr())
59 Op.getExpr()->print(O);
59 Op.getExpr()->print(O, MAI);
6060 else if (Op.isMBBLabel())
6161 // FIXME: Keep in sync with printBasicBlockLabel. printBasicBlockLabel
6262 // should eventually call into this code, not the other way around.
9292 return;
9393 } else if (Op.isExpr()) {
9494 O << '$';
95 Op.getExpr()->print(O);
95 Op.getExpr()->print(O, MAI);
9696 return;
9797 }
9898
110110 if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg()))
111111 O << DispVal;
112112 } else if (DispSpec.isExpr()) {
113 DispSpec.getExpr()->print(O);
113 DispSpec.getExpr()->print(O, MAI);
114114 } else {
115115 llvm_unreachable("non-immediate displacement for LEA?");
116116 //assert(DispSpec.isGlobal() || DispSpec.isCPI() ||