llvm.org GIT mirror llvm / aaec205
Generalize mcasmstreamer data emission APIs to take an address space identifier. There is no way to work around it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93896 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
9 changed file(s) with 69 addition(s) and 61 deletion(s). Raw diff Collapse all Expand all
154154 ///
155155 /// This is used to implement assembler directives such as .byte, .ascii,
156156 /// etc.
157 virtual void EmitBytes(StringRef Data) = 0;
157 virtual void EmitBytes(StringRef Data, unsigned AddrSpace) = 0;
158158
159159 /// EmitValue - Emit the expression @param Value into the output as a native
160160 /// integer of the given @param Size bytes.
165165 /// @param Value - The value to emit.
166166 /// @param Size - The size of the integer (in bytes) to emit. This must
167167 /// match a native machine width.
168 virtual void EmitValue(const MCExpr *Value, unsigned Size) = 0;
168 virtual void EmitValue(const MCExpr *Value, unsigned Size,
169 unsigned AddrSpace) = 0;
169170
170171 /// EmitFill - Emit NumBytes bytes worth of the value specified by
171172 /// FillValue. This implements directives such as '.space'.
172 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue = 0);
173 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
174 unsigned AddrSpace);
173175
174176
175177 /// EmitValueToAlignment - Emit some number of copies of @param Value until
435435 // Emit inter-object padding for alignment.
436436 unsigned AlignMask = CPE.getAlignment() - 1;
437437 unsigned NewOffset = (Offset + AlignMask) & ~AlignMask;
438 OutStreamer.EmitFill(NewOffset - Offset);
438 OutStreamer.EmitFill(NewOffset - Offset, 0/*fillval*/, 0/*addrspace*/);
439439
440440 const Type *Ty = CPE.getType();
441441 Offset = NewOffset + TM.getTargetData()->getTypeAllocSize(Ty);
910910 FillValue = MAI->getTextAlignFillValue();
911911
912912 OutStreamer.EmitValueToAlignment(1 << NumBits, FillValue, 1, 0);
913 }
914
915 /// EmitZeros - Emit a block of zeros.
916 ///
917 void AsmPrinter::EmitZeros(uint64_t NumZeros, unsigned AddrSpace) const {
918 if (NumZeros == 0) return;
919 if (MAI->getZeroDirective() || AddrSpace == 0) {
920 OutStreamer.EmitFill(NumZeros);
921 } else {
922 for (; NumZeros; --NumZeros)
923 O << MAI->getData8bitsDirective(AddrSpace) << "0\n";
924 }
925913 }
926914
927915 // Print out the specified constant, without a storage class. Only the
10691057 }
10701058 }
10711059
1060 /// EmitZeros - Emit a block of zeros.
1061 ///
1062 void AsmPrinter::EmitZeros(uint64_t NumZeros, unsigned AddrSpace) const {
1063 OutStreamer.EmitFill(NumZeros, 0, AddrSpace);
1064 }
1065
10721066 /// printAsCString - Print the specified array as a C compatible string, only if
10731067 /// the predicate isString is true.
10741068 ///
5757 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
5858 unsigned Size = 0, unsigned ByteAlignment = 0);
5959
60 virtual void EmitBytes(StringRef Data);
61
62 virtual void EmitValue(const MCExpr *Value, unsigned Size);
63 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
60 virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
61
62 virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace);
63 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
64 unsigned AddrSpace);
6465
6566 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
6667 unsigned ValueSize = 1,
178179 OS << '\n';
179180 }
180181
181 void MCAsmStreamer::EmitBytes(StringRef Data) {
182 void MCAsmStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
182183 assert(CurSection && "Cannot emit contents before setting section!");
184 const char *Directive = MAI.getData8bitsDirective(AddrSpace);
183185 for (unsigned i = 0, e = Data.size(); i != e; ++i)
184 OS << ".byte " << (unsigned) (unsigned char) Data[i] << '\n';
185 }
186
187 void MCAsmStreamer::EmitValue(const MCExpr *Value, unsigned Size) {
186 OS << Directive << (unsigned)(unsigned char)Data[i] << '\n';
187 }
188
189 void MCAsmStreamer::EmitValue(const MCExpr *Value, unsigned Size,
190 unsigned AddrSpace) {
188191 assert(CurSection && "Cannot emit contents before setting section!");
189192 // Need target hooks to know how to print this.
190193 switch (Size) {
191 default:
192 llvm_unreachable("Invalid size for machine code value!");
193 case 1: OS << ".byte"; break;
194 case 2: OS << ".short"; break;
195 case 4: OS << ".long"; break;
196 case 8: OS << ".quad"; break;
197 }
198
199 OS << ' ' << *truncateToSize(Value, Size) << '\n';
194 default: assert(0 && "Invalid size for machine code value!");
195 case 1: OS << MAI.getData8bitsDirective(AddrSpace); break;
196 case 2: OS << MAI.getData16bitsDirective(AddrSpace); break;
197 case 4: OS << MAI.getData32bitsDirective(AddrSpace); break;
198 case 8: OS << MAI.getData64bitsDirective(AddrSpace); break;
199 }
200
201 OS << *truncateToSize(Value, Size) << '\n';
200202 }
201203
202204 /// EmitFill - Emit NumBytes bytes worth of the value specified by
203205 /// FillValue. This implements directives such as '.space'.
204 void MCAsmStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue) {
206 void MCAsmStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue,
207 unsigned AddrSpace) {
205208 if (NumBytes == 0) return;
206209
207 if (const char *ZeroDirective = MAI.getZeroDirective()) {
208 OS << ZeroDirective << NumBytes;
209 if (FillValue != 0)
210 OS << ',' << (int)FillValue;
211 OS << '\n';
212 } else {
213 // Emit a byte at a time.
214 MCStreamer::EmitFill(NumBytes, FillValue);
215 }
210 if (AddrSpace == 0)
211 if (const char *ZeroDirective = MAI.getZeroDirective()) {
212 OS << ZeroDirective << NumBytes;
213 if (FillValue != 0)
214 OS << ',' << (int)FillValue;
215 OS << '\n';
216 return;
217 }
218
219 // Emit a byte at a time.
220 MCStreamer::EmitFill(NumBytes, FillValue, AddrSpace);
216221 }
217222
218223 void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
133133 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
134134 unsigned Size = 0, unsigned ByteAlignment = 0);
135135
136 virtual void EmitBytes(StringRef Data);
137
138 virtual void EmitValue(const MCExpr *Value, unsigned Size);
136 virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
137
138 virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace);
139139
140140 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
141141 unsigned ValueSize = 1,
314314 SectData.setAlignment(ByteAlignment);
315315 }
316316
317 void MCMachOStreamer::EmitBytes(StringRef Data) {
317 void MCMachOStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
318318 MCDataFragment *DF = dyn_cast_or_null(getCurrentFragment());
319319 if (!DF)
320320 DF = new MCDataFragment(CurSectionData);
321321 DF->getContents().append(Data.begin(), Data.end());
322322 }
323323
324 void MCMachOStreamer::EmitValue(const MCExpr *Value, unsigned Size) {
324 void MCMachOStreamer::EmitValue(const MCExpr *Value, unsigned Size,
325 unsigned AddrSpace) {
325326 new MCFillFragment(*AddValueSymbols(Value), Size, 1, CurSectionData);
326327 }
327328
358359 SmallString<256> Code;
359360 raw_svector_ostream VecOS(Code);
360361 Emitter->EncodeInstruction(Inst, VecOS);
361 EmitBytes(VecOS.str());
362 EmitBytes(VecOS.str(), 0);
362363 }
363364
364365 void MCMachOStreamer::Finish() {
4444 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
4545 unsigned Size = 0, unsigned ByteAlignment = 0) {}
4646
47 virtual void EmitBytes(StringRef Data) {}
47 virtual void EmitBytes(StringRef Data, unsigned AddrSpace) {}
4848
49 virtual void EmitValue(const MCExpr *Value, unsigned Size) {}
49 virtual void EmitValue(const MCExpr *Value, unsigned Size,
50 unsigned AddrSpace) {}
5051
5152 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
5253 unsigned ValueSize = 1,
1919
2020 /// EmitFill - Emit NumBytes bytes worth of the value specified by
2121 /// FillValue. This implements directives such as '.space'.
22 void MCStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue) {
22 void MCStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue,
23 unsigned AddrSpace) {
2324 const MCExpr *E = MCConstantExpr::Create(FillValue, getContext());
2425 for (uint64_t i = 0, e = NumBytes; i != e; ++i)
25 EmitValue(E, 1);
26 EmitValue(E, 1, AddrSpace);
2627 }
628628 if (getParser().ParseExpression(Value))
629629 return true;
630630
631 getParser().getStreamer().EmitValue(Value, Size);
631 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
632632
633633 if (getLexer().is(AsmToken::EndOfStatement))
634634 break;
469469 if (getParser().ParseExpression(Value))
470470 return true;
471471
472 getParser().getStreamer().EmitValue(Value, Size);
472 getParser().getStreamer().EmitValue(Value, Size, 0 /*addrspace*/);
473473
474474 if (getLexer().is(AsmToken::EndOfStatement))
475475 break;
2727 #include "llvm/Support/raw_ostream.h"
2828 #include "llvm/Target/TargetAsmParser.h"
2929 using namespace llvm;
30
31
32 enum { DEFAULT_ADDRSPACE = 0 };
3033
3134 // Mach-O section uniquing.
3235 //
966969 if (ParseEscapedString(Data))
967970 return true;
968971
969 Out.EmitBytes(Data);
972 Out.EmitBytes(Data, DEFAULT_ADDRSPACE);
970973 if (ZeroTerminated)
971 Out.EmitBytes(StringRef("\0", 1));
974 Out.EmitBytes(StringRef("\0", 1), DEFAULT_ADDRSPACE);
972975
973976 Lexer.Lex();
974977
995998 if (ParseExpression(Value))
996999 return true;
9971000
998 Out.EmitValue(Value, Size);
1001 Out.EmitValue(Value, Size, DEFAULT_ADDRSPACE);
9991002
10001003 if (Lexer.is(AsmToken::EndOfStatement))
10011004 break;
10401043 return TokError("invalid number of bytes in '.space' directive");
10411044
10421045 // FIXME: Sometimes the fill expr is 'nop' if it isn't supplied, instead of 0.
1043 Out.EmitFill(NumBytes, FillExpr);
1046 Out.EmitFill(NumBytes, FillExpr, DEFAULT_ADDRSPACE);
10441047
10451048 return false;
10461049 }
10771080 return TokError("invalid '.fill' size, expected 1, 2, 4, or 8");
10781081
10791082 for (uint64_t i = 0, e = NumValues; i != e; ++i)
1080 Out.EmitValue(MCConstantExpr::Create(FillExpr, getContext()), FillSize);
1083 Out.EmitValue(MCConstantExpr::Create(FillExpr, getContext()), FillSize,
1084 DEFAULT_ADDRSPACE);
10811085
10821086 return false;
10831087 }