51 unsigned IsVerboseAsm : 1;
52 unsigned ShowInst : 1;
55 unsigned UseDwarfDirectory : 1;
57 enum EHSymbolFlags { EHGlobal = 1,
58 EHWeakDefinition = 1 << 1,
59 EHPrivateExtern = 1 << 2 };
64 void EmitRegisterName(int64_t
Register);
73 :
MCStreamer(Context, TargetStreamer), OS(os), MAI(Context.getAsmInfo()),
74 InstPrinter(printer), Emitter(emitter), AsmBackend(asmbackend),
75 CommentStream(CommentToEmit), IsVerboseAsm(isVerboseAsm),
76 ShowInst(showInst), UseLoc(useLoc), UseCFI(useCFI),
77 UseDwarfDirectory(useDwarfDirectory) {
78 if (InstPrinter && IsVerboseAsm)
79 InstPrinter->setCommentStream(CommentStream);
83 inline void EmitEOL() {
91 void EmitCommentsAndEOL();
95 virtual bool isVerboseAsm()
const {
return IsVerboseAsm; }
98 virtual bool hasRawTextSupport()
const {
return true; }
104 virtual void AddComment(
const Twine &
T);
107 virtual void AddEncodingComment(
const MCInst &Inst);
115 return CommentStream;
119 virtual void AddBlankLine() {
127 const MCExpr *Subsection);
129 virtual void InitSections() {
133 virtual void InitToTextSection() {
134 SwitchSection(getContext().getObjectFileInfo()->getTextSection());
149 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
152 unsigned PointerSize);
153 virtual void EmitDwarfAdvanceFrameAddr(
const MCSymbol *LastLabel,
158 virtual void EmitSymbolDesc(
MCSymbol *
Symbol,
unsigned DescValue);
160 virtual void EmitCOFFSymbolStorageClass(
int StorageClass);
161 virtual void EmitCOFFSymbolType(
int Type);
162 virtual void EndCOFFSymbolDef();
173 virtual void EmitLocalCommonSymbol(
MCSymbol *
Symbol, uint64_t Size,
184 virtual void EmitValueImpl(
const MCExpr *
Value,
unsigned Size);
185 virtual void EmitIntValue(uint64_t
Value,
unsigned Size);
187 virtual void EmitULEB128Value(
const MCExpr *
Value);
189 virtual void EmitSLEB128Value(
const MCExpr *
Value);
191 virtual void EmitGPRel64Value(
const MCExpr *
Value);
193 virtual void EmitGPRel32Value(
const MCExpr *
Value);
196 virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
199 unsigned ValueSize = 1,
200 unsigned MaxBytesToEmit = 0);
203 unsigned MaxBytesToEmit = 0);
205 virtual bool EmitValueToOffset(
const MCExpr *Offset,
206 unsigned char Value = 0);
208 virtual void EmitFileDirective(
StringRef Filename);
209 virtual bool EmitDwarfFileDirective(
unsigned FileNo,
StringRef Directory,
211 virtual void EmitDwarfLocDirective(
unsigned FileNo,
unsigned Line,
212 unsigned Column,
unsigned Flags,
213 unsigned Isa,
unsigned Discriminator,
216 virtual void EmitIdent(
StringRef IdentString);
217 virtual void EmitCFISections(
bool EH,
bool Debug);
218 virtual void EmitCFIDefCfa(int64_t
Register, int64_t Offset);
219 virtual void EmitCFIDefCfaOffset(int64_t Offset);
220 virtual void EmitCFIDefCfaRegister(int64_t
Register);
221 virtual void EmitCFIOffset(int64_t
Register, int64_t Offset);
222 virtual void EmitCFIPersonality(
const MCSymbol *Sym,
unsigned Encoding);
223 virtual void EmitCFILsda(
const MCSymbol *Sym,
unsigned Encoding);
224 virtual void EmitCFIRememberState();
225 virtual void EmitCFIRestoreState();
226 virtual void EmitCFISameValue(int64_t
Register);
227 virtual void EmitCFIRelOffset(int64_t
Register, int64_t Offset);
228 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
229 virtual void EmitCFISignalFrame();
230 virtual void EmitCFIUndefined(int64_t
Register);
231 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
232 virtual void EmitCFIWindowSave();
235 virtual void EmitWin64EHEndProc();
236 virtual void EmitWin64EHStartChained();
237 virtual void EmitWin64EHEndChained();
238 virtual void EmitWin64EHHandler(
const MCSymbol *Sym,
bool Unwind,
240 virtual void EmitWin64EHHandlerData();
241 virtual void EmitWin64EHPushReg(
unsigned Register);
242 virtual void EmitWin64EHSetFrame(
unsigned Register,
unsigned Offset);
243 virtual void EmitWin64EHAllocStack(
unsigned Size);
244 virtual void EmitWin64EHSaveReg(
unsigned Register,
unsigned Offset);
245 virtual void EmitWin64EHSaveXMM(
unsigned Register,
unsigned Offset);
246 virtual void EmitWin64EHPushFrame(
bool Code);
247 virtual void EmitWin64EHEndProlog();
249 virtual void EmitInstruction(
const MCInst &Inst);
251 virtual void EmitBundleAlignMode(
unsigned AlignPow2);
252 virtual void EmitBundleLock(
bool AlignToEnd);
253 virtual void EmitBundleUnlock();
260 virtual void FinishImpl();
269 void MCAsmStreamer::AddComment(
const Twine &
T) {
270 if (!IsVerboseAsm)
return;
273 CommentStream.flush();
277 CommentToEmit.push_back(
'\n');
280 CommentStream.resync();
283 void MCAsmStreamer::EmitCommentsAndEOL() {
284 if (CommentToEmit.empty() && CommentStream.GetNumBytesInBuffer() == 0) {
289 CommentStream.flush();
292 assert(Comments.
back() ==
'\n' &&
293 "Comment array not newline terminated");
296 OS.PadToColumn(MAI->getCommentColumn());
297 size_t Position = Comments.
find(
'\n');
298 OS << MAI->getCommentString() <<
' ' << Comments.
substr(0, Position) <<
'\n';
300 Comments = Comments.
substr(Position+1);
301 }
while (!Comments.
empty());
303 CommentToEmit.clear();
305 CommentStream.resync();
309 assert(Bytes &&
"Invalid size!");
310 return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
314 const MCExpr *Subsection) {
315 assert(Section &&
"Cannot switch to a null section!");
324 unsigned Flags = FlagMap.lookup(Symbol);
326 if (Flags & EHGlobal)
328 if (Flags & EHWeakDefinition)
330 if (Flags & EHPrivateExtern)
334 void MCAsmStreamer::EmitLabel(
MCSymbol *Symbol) {
335 assert(Symbol->
isUndefined() &&
"Cannot define a symbol twice!");
338 OS << *Symbol << MAI->getLabelSuffix();
342 void MCAsmStreamer::EmitDebugLabel(
MCSymbol *Symbol) {
343 assert(Symbol->
isUndefined() &&
"Cannot define a symbol twice!");
346 OS << *Symbol << MAI->getDebugLabelSuffix();
354 case MCAF_Code16: OS <<
'\t'<< MAI->getCode16Directive();
break;
355 case MCAF_Code32: OS <<
'\t'<< MAI->getCode32Directive();
break;
356 case MCAF_Code64: OS <<
'\t'<< MAI->getCode64Directive();
break;
362 assert(!Options.
empty() &&
"At least one option is required!");
363 OS <<
"\t.linker_option \"" << Options[0] <<
'"';
365 ie = Options.end(); it != ie; ++it) {
366 OS <<
", " <<
'"' << *it <<
'"';
372 if (!MAI->doesSupportDataRegionDirectives())
387 OS <<
"\t.thumb_func";
389 if (MAI->hasSubsectionsViaSymbols())
395 OS << *Symbol <<
" = " << *Value;
402 void MCAsmStreamer::EmitWeakReference(
MCSymbol *Alias,
const MCSymbol *Symbol) {
403 OS <<
".weakref " << *Alias <<
", " << *
Symbol;
407 void MCAsmStreamer::EmitDwarfAdvanceLineAddr(int64_t LineDelta,
410 unsigned PointerSize) {
411 EmitDwarfSetLineAddr(LineDelta, Label, PointerSize);
414 void MCAsmStreamer::EmitDwarfAdvanceFrameAddr(
const MCSymbol *LastLabel,
417 const MCExpr *AddrDelta = BuildSymbolDiff(getContext(), Label, LastLabel);
418 AddrDelta = ForceExpAbs(AddrDelta);
419 EmitValue(AddrDelta, 4);
423 bool MCAsmStreamer::EmitSymbolAttribute(
MCSymbol *Symbol,
434 if (!MAI->hasDotTypeDotSizeDirective())
436 OS <<
"\t.type\t" << *Symbol <<
','
437 << ((MAI->getCommentString()[0] !=
'@') ?
'@' :
'%');
439 default:
return false;
451 OS << MAI->getGlobalDirective();
452 FlagMap[
Symbol] |= EHGlobal;
462 OS <<
"\t.private_extern\t";
463 FlagMap[
Symbol] |= EHPrivateExtern;
467 case MCSA_Weak: OS <<
"\t.weak\t";
break;
469 OS <<
"\t.weak_definition\t";
470 FlagMap[
Symbol] |= EHWeakDefinition;
483 void MCAsmStreamer::EmitSymbolDesc(
MCSymbol *Symbol,
unsigned DescValue) {
484 OS <<
".desc" <<
' ' << *Symbol <<
',' << DescValue;
488 void MCAsmStreamer::BeginCOFFSymbolDef(
const MCSymbol *Symbol) {
489 OS <<
"\t.def\t " << *Symbol <<
';';
493 void MCAsmStreamer::EmitCOFFSymbolStorageClass (
int StorageClass) {
494 OS <<
"\t.scl\t" << StorageClass <<
';';
498 void MCAsmStreamer::EmitCOFFSymbolType (
int Type) {
499 OS <<
"\t.type\t" << Type <<
';';
503 void MCAsmStreamer::EndCOFFSymbolDef() {
508 void MCAsmStreamer::EmitCOFFSecRel32(
MCSymbol const *Symbol) {
509 OS <<
"\t.secrel32\t" << *Symbol <<
'\n';
513 void MCAsmStreamer::EmitELFSize(
MCSymbol *Symbol,
const MCExpr *Value) {
514 assert(MAI->hasDotTypeDotSizeDirective());
515 OS <<
"\t.size\t" << *Symbol <<
", " << *Value <<
'\n';
518 void MCAsmStreamer::EmitCommonSymbol(
MCSymbol *Symbol, uint64_t Size,
521 AssignSection(Symbol, NULL);
523 OS <<
"\t.comm\t" << *Symbol <<
',' << Size;
524 if (ByteAlignment != 0) {
525 if (MAI->getCOMMDirectiveAlignmentIsInBytes())
526 OS <<
',' << ByteAlignment;
528 OS <<
',' <<
Log2_32(ByteAlignment);
537 void MCAsmStreamer::EmitLocalCommonSymbol(
MCSymbol *Symbol, uint64_t Size,
538 unsigned ByteAlign) {
540 AssignSection(Symbol, NULL);
542 OS <<
"\t.lcomm\t" << *Symbol <<
',' << Size;
544 switch (MAI->getLCOMMDirectiveAlignmentType()) {
548 OS <<
',' << ByteAlign;
551 assert(
isPowerOf2_32(ByteAlign) &&
"alignment must be a power of 2");
552 OS <<
',' <<
Log2_32(ByteAlign);
560 uint64_t Size,
unsigned ByteAlignment) {
562 AssignSection(Symbol, Section);
571 if (Symbol != NULL) {
572 OS <<
',' << *Symbol <<
',' << Size;
573 if (ByteAlignment != 0)
574 OS <<
',' <<
Log2_32(ByteAlignment);
583 uint64_t Size,
unsigned ByteAlignment) {
584 AssignSection(Symbol, Section);
586 assert(Symbol != NULL &&
"Symbol shouldn't be NULL!");
589 OS <<
".tbss " << *Symbol <<
", " << Size;
593 if (ByteAlignment > 1) OS <<
", " <<
Log2_32(ByteAlignment);
598 static inline char toOctal(
int X) {
return (X&7)+
'0'; }
603 for (
unsigned i = 0, e = Data.
size(); i != e; ++i) {
604 unsigned char C = Data[i];
605 if (C ==
'"' || C ==
'\\') {
606 OS <<
'\\' << (char)C;
610 if (isprint((
unsigned char)
C)) {
616 case '\b': OS <<
"\\b";
break;
617 case '\f': OS <<
"\\f";
break;
618 case '\n': OS <<
"\\n";
break;
619 case '\r': OS <<
"\\r";
break;
620 case '\t': OS <<
"\\t";
break;
623 OS << toOctal(C >> 6);
624 OS << toOctal(C >> 3);
625 OS << toOctal(C >> 0);
634 void MCAsmStreamer::EmitBytes(
StringRef Data) {
635 assert(getCurrentSection().first &&
636 "Cannot emit contents before setting section!");
637 if (Data.
empty())
return;
639 if (Data.
size() == 1) {
640 OS << MAI->getData8bitsDirective();
641 OS << (
unsigned)(
unsigned char)Data[0];
648 if (MAI->getAscizDirective() && Data.
back() == 0) {
649 OS << MAI->getAscizDirective();
652 OS << MAI->getAsciiDirective();
659 void MCAsmStreamer::EmitIntValue(uint64_t Value,
unsigned Size) {
663 void MCAsmStreamer::EmitValueImpl(
const MCExpr *Value,
unsigned Size) {
664 assert(getCurrentSection().first &&
665 "Cannot emit contents before setting section!");
666 const char *Directive = 0;
669 case 1: Directive = MAI->getData8bitsDirective();
break;
670 case 2: Directive = MAI->getData16bitsDirective();
break;
671 case 4: Directive = MAI->getData32bitsDirective();
break;
673 Directive = MAI->getData64bitsDirective();
675 if (Directive)
break;
677 if (!Value->EvaluateAsAbsolute(IntValue))
679 if (MAI->isLittleEndian()) {
680 EmitIntValue((uint32_t)(IntValue >> 0 ), 4);
681 EmitIntValue((uint32_t)(IntValue >> 32), 4);
683 EmitIntValue((uint32_t)(IntValue >> 32), 4);
684 EmitIntValue((uint32_t)(IntValue >> 0 ), 4);
689 assert(Directive &&
"Invalid size for machine code value!");
690 OS << Directive << *Value;
694 void MCAsmStreamer::EmitULEB128Value(
const MCExpr *Value) {
696 if (Value->EvaluateAsAbsolute(IntValue)) {
697 EmitULEB128IntValue(IntValue);
700 assert(MAI->hasLEB128() &&
"Cannot print a .uleb");
701 OS <<
".uleb128 " << *Value;
705 void MCAsmStreamer::EmitSLEB128Value(
const MCExpr *Value) {
707 if (Value->EvaluateAsAbsolute(IntValue)) {
708 EmitSLEB128IntValue(IntValue);
711 assert(MAI->hasLEB128() &&
"Cannot print a .sleb");
712 OS <<
".sleb128 " << *Value;
716 void MCAsmStreamer::EmitGPRel64Value(
const MCExpr *Value) {
717 assert(MAI->getGPRel64Directive() != 0);
718 OS << MAI->getGPRel64Directive() << *Value;
722 void MCAsmStreamer::EmitGPRel32Value(
const MCExpr *Value) {
723 assert(MAI->getGPRel32Directive() != 0);
724 OS << MAI->getGPRel32Directive() << *Value;
731 void MCAsmStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue) {
732 if (NumBytes == 0)
return;
734 if (
const char *ZeroDirective = MAI->getZeroDirective()) {
735 OS << ZeroDirective << NumBytes;
737 OS <<
',' << (int)FillValue;
746 void MCAsmStreamer::EmitValueToAlignment(
unsigned ByteAlignment, int64_t Value,
748 unsigned MaxBytesToEmit) {
754 case 1: OS << MAI->getAlignDirective();
break;
756 case 2: OS <<
".p2alignw ";
break;
757 case 4: OS <<
".p2alignl ";
break;
761 if (MAI->getAlignmentIsInBytes())
766 if (Value || MaxBytesToEmit) {
771 OS <<
", " << MaxBytesToEmit;
781 case 1: OS <<
".balign";
break;
782 case 2: OS <<
".balignw";
break;
783 case 4: OS <<
".balignl";
break;
790 OS <<
", " << MaxBytesToEmit;
794 void MCAsmStreamer::EmitCodeAlignment(
unsigned ByteAlignment,
795 unsigned MaxBytesToEmit) {
797 EmitValueToAlignment(ByteAlignment, MAI->getTextAlignFillValue(),
801 bool MCAsmStreamer::EmitValueToOffset(
const MCExpr *Offset,
802 unsigned char Value) {
804 OS <<
".org " << *Offset <<
", " << (
unsigned) Value;
810 void MCAsmStreamer::EmitFileDirective(
StringRef Filename) {
811 assert(MAI->hasSingleParameterDotFile());
817 bool MCAsmStreamer::EmitDwarfFileDirective(
unsigned FileNo,
StringRef Directory,
819 if (!UseDwarfDirectory && !Directory.
empty()) {
821 return EmitDwarfFileDirective(FileNo,
"", Filename, CUID);
825 return EmitDwarfFileDirective(FileNo,
"", FullPathName, CUID);
829 OS <<
"\t.file\t" << FileNo <<
' ';
830 if (!Directory.
empty()) {
843 void MCAsmStreamer::EmitDwarfLocDirective(
unsigned FileNo,
unsigned Line,
844 unsigned Column,
unsigned Flags,
846 unsigned Discriminator,
849 Isa, Discriminator, FileName);
853 OS <<
"\t.loc\t" << FileNo <<
" " << Line <<
" " << Column;
855 OS <<
" basic_block";
857 OS <<
" prologue_end";
859 OS <<
" epilogue_begin";
861 unsigned OldFlags = getContext().getCurrentDwarfLoc().getFlags();
865 if (Flags & DWARF2_FLAG_IS_STMT)
874 OS <<
"discriminator " << Discriminator;
877 OS.PadToColumn(MAI->getCommentColumn());
878 OS << MAI->getCommentString() <<
' ' << FileName <<
':'
879 << Line <<
':' << Column;
884 void MCAsmStreamer::EmitIdent(
StringRef IdentString) {
885 assert(MAI->hasIdentDirective() &&
".ident directive not supported");
891 void MCAsmStreamer::EmitCFISections(
bool EH,
bool Debug) {
897 OS <<
"\t.cfi_sections ";
901 OS <<
", .debug_frame";
903 OS <<
".debug_frame";
911 RecordProcStart(Frame);
915 OS <<
"\t.cfi_startproc";
921 RecordProcEnd(Frame);
929 OS <<
"\t.cfi_endproc";
933 void MCAsmStreamer::EmitRegisterName(int64_t
Register) {
934 if (InstPrinter && !MAI->useDwarfRegNumForCFI()) {
937 InstPrinter->printRegName(OS, LLVMRegister);
943 void MCAsmStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) {
949 OS <<
"\t.cfi_def_cfa ";
950 EmitRegisterName(Register);
951 OS <<
", " << Offset;
955 void MCAsmStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
961 OS <<
"\t.cfi_def_cfa_offset " << Offset;
965 void MCAsmStreamer::EmitCFIDefCfaRegister(int64_t Register) {
971 OS <<
"\t.cfi_def_cfa_register ";
972 EmitRegisterName(Register);
976 void MCAsmStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
982 OS <<
"\t.cfi_offset ";
983 EmitRegisterName(Register);
984 OS <<
", " << Offset;
988 void MCAsmStreamer::EmitCFIPersonality(
const MCSymbol *Sym,
995 OS <<
"\t.cfi_personality " << Encoding <<
", " << *Sym;
999 void MCAsmStreamer::EmitCFILsda(
const MCSymbol *Sym,
unsigned Encoding) {
1005 OS <<
"\t.cfi_lsda " << Encoding <<
", " << *Sym;
1009 void MCAsmStreamer::EmitCFIRememberState() {
1015 OS <<
"\t.cfi_remember_state";
1019 void MCAsmStreamer::EmitCFIRestoreState() {
1025 OS <<
"\t.cfi_restore_state";
1029 void MCAsmStreamer::EmitCFISameValue(int64_t Register) {
1035 OS <<
"\t.cfi_same_value ";
1036 EmitRegisterName(Register);
1040 void MCAsmStreamer::EmitCFIRelOffset(int64_t Register, int64_t Offset) {
1046 OS <<
"\t.cfi_rel_offset ";
1047 EmitRegisterName(Register);
1048 OS <<
", " << Offset;
1052 void MCAsmStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) {
1058 OS <<
"\t.cfi_adjust_cfa_offset " << Adjustment;
1062 void MCAsmStreamer::EmitCFISignalFrame() {
1068 OS <<
"\t.cfi_signal_frame";
1072 void MCAsmStreamer::EmitCFIUndefined(int64_t Register) {
1078 OS <<
"\t.cfi_undefined " <<
Register;
1082 void MCAsmStreamer::EmitCFIRegister(int64_t Register1, int64_t Register2) {
1088 OS <<
"\t.cfi_register " << Register1 <<
", " << Register2;
1092 void MCAsmStreamer::EmitCFIWindowSave() {
1098 OS <<
"\t.cfi_window_save";
1102 void MCAsmStreamer::EmitWin64EHStartProc(
const MCSymbol *Symbol) {
1105 OS <<
".seh_proc " << *
Symbol;
1109 void MCAsmStreamer::EmitWin64EHEndProc() {
1112 OS <<
"\t.seh_endproc";
1116 void MCAsmStreamer::EmitWin64EHStartChained() {
1119 OS <<
"\t.seh_startchained";
1123 void MCAsmStreamer::EmitWin64EHEndChained() {
1126 OS <<
"\t.seh_endchained";
1130 void MCAsmStreamer::EmitWin64EHHandler(
const MCSymbol *Sym,
bool Unwind,
1134 OS <<
"\t.seh_handler " << *Sym;
1149 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1150 COFF::IMAGE_SCN_MEM_READ |
1151 COFF::IMAGE_SCN_MEM_WRITE,
1155 void MCAsmStreamer::EmitWin64EHHandlerData() {
1166 SwitchSectionNoChange(xdataSect);
1168 OS <<
"\t.seh_handlerdata";
1172 void MCAsmStreamer::EmitWin64EHPushReg(
unsigned Register) {
1175 OS <<
"\t.seh_pushreg " <<
Register;
1179 void MCAsmStreamer::EmitWin64EHSetFrame(
unsigned Register,
unsigned Offset) {
1182 OS <<
"\t.seh_setframe " << Register <<
", " << Offset;
1186 void MCAsmStreamer::EmitWin64EHAllocStack(
unsigned Size) {
1189 OS <<
"\t.seh_stackalloc " << Size;
1193 void MCAsmStreamer::EmitWin64EHSaveReg(
unsigned Register,
unsigned Offset) {
1196 OS <<
"\t.seh_savereg " << Register <<
", " << Offset;
1200 void MCAsmStreamer::EmitWin64EHSaveXMM(
unsigned Register,
unsigned Offset) {
1203 OS <<
"\t.seh_savexmm " << Register <<
", " << Offset;
1207 void MCAsmStreamer::EmitWin64EHPushFrame(
bool Code) {
1210 OS <<
"\t.seh_pushframe";
1216 void MCAsmStreamer::EmitWin64EHEndProlog(
void) {
1219 OS <<
"\t.seh_endprologue";
1223 void MCAsmStreamer::AddEncodingComment(
const MCInst &Inst) {
1228 Emitter->EncodeInstruction(Inst, VecOS, Fixups);
1236 for (
unsigned i = 0, e = Code.
size() * 8; i != e; ++i)
1239 for (
unsigned i = 0, e = Fixups.
size(); i != e; ++i) {
1242 for (
unsigned j = 0; j != Info.
TargetSize; ++j) {
1244 assert(Index < Code.
size() * 8 &&
"Invalid offset in fixup!");
1245 FixupMap[Index] = 1 + i;
1251 OS <<
"encoding: [";
1252 for (
unsigned i = 0, e = Code.
size(); i != e; ++i) {
1257 uint8_t MapEntry = FixupMap[i * 8 + 0];
1258 for (
unsigned j = 1; j != 8; ++j) {
1259 if (FixupMap[i * 8 + j] == MapEntry)
1262 MapEntry = uint8_t(~0U);
1266 if (MapEntry != uint8_t(~0U)) {
1267 if (MapEntry == 0) {
1268 OS <<
format(
"0x%02x", uint8_t(Code[i]));
1272 OS <<
format(
"0x%02x", uint8_t(Code[i])) <<
'\''
1273 << char(
'A' + MapEntry - 1) <<
'\'';
1275 OS << char(
'A' + MapEntry - 1);
1280 for (
unsigned j = 8; j--;) {
1281 unsigned Bit = (Code[i] >> j) & 1;
1284 if (MAI->isLittleEndian())
1285 FixupBit = i * 8 + j;
1287 FixupBit = i * 8 + (7-j);
1289 if (uint8_t MapEntry = FixupMap[FixupBit]) {
1290 assert(Bit == 0 &&
"Encoder wrote into fixed up bit!");
1291 OS << char(
'A' + MapEntry - 1);
1299 for (
unsigned i = 0, e = Fixups.
size(); i != e; ++i) {
1302 OS <<
" fixup " << char(
'A' + i) <<
" - " <<
"offset: " << F.
getOffset()
1303 <<
", value: " << *F.
getValue() <<
", kind: " << Info.
Name <<
"\n";
1307 void MCAsmStreamer::EmitInstruction(
const MCInst &Inst) {
1308 assert(getCurrentSection().first &&
1309 "Cannot emit contents before setting section!");
1313 AddEncodingComment(Inst);
1317 Inst.
dump_pretty(GetCommentOS(), MAI, InstPrinter.get(),
"\n ");
1318 GetCommentOS() <<
"\n";
1323 InstPrinter->printInst(&Inst, OS,
"");
1325 Inst.
print(OS, MAI);
1329 void MCAsmStreamer::EmitBundleAlignMode(
unsigned AlignPow2) {
1330 OS <<
"\t.bundle_align_mode " << AlignPow2;
1334 void MCAsmStreamer::EmitBundleLock(
bool AlignToEnd) {
1335 OS <<
"\t.bundle_lock";
1337 OS <<
" align_to_end";
1341 void MCAsmStreamer::EmitBundleUnlock() {
1342 OS <<
"\t.bundle_unlock";
1350 if (!String.
empty() && String.
back() ==
'\n')
1356 void MCAsmStreamer::FinishImpl() {
1359 const MCSymbol *LineSectionSymbol = NULL;
1360 if (getContext().hasDwarfFiles() && !UseLoc)
1364 if (getContext().getGenDwarfForAssembly())
1368 EmitFrames(AsmBackend.get(),
false);
1374 bool isVerboseAsm,
bool useLoc,
bool useCFI,
1378 return new MCAsmStreamer(Context, TargetStreamer, OS, isVerboseAsm, useLoc,
1379 useCFI, useDwarfDirectory, IP, CE, MAB, ShowInst);
void toVector(SmallVectorImpl< char > &Out) const
virtual void EmitWin64EHPushFrame(bool Code)
virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, StringRef FileName)
EmitDwarfLocDirective - This implements the DWARF2.
virtual void EmitCFISameValue(int64_t Register)
virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding)
#define DWARF2_FLAG_PROLOGUE_END
size_t size() const
size - Get the string size.
.type _foo, STT_OBJECT # aka
const MCSymbol * Function
static const MCConstantExpr * Create(int64_t Value, MCContext &Ctx)
size_t find(char C, size_t From=0) const
static SectionKind getDataRel()
StringRef substr(size_t Start, size_t N=npos) const
std::string str() const
str - Get the contents as an std::string.
virtual void EmitCFIRegister(int64_t Register1, int64_t Register2)
virtual void EmitCFIDefCfaOffset(int64_t Offset)
.type _foo, STT_NOTYPE # aka
COFF::SymbolStorageClass StorageClass
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
static void Emit(MCStreamer *MCOS, const MCSymbol *LineSectionSymbol)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
unsigned TargetOffset
The bit offset to write the relocation into.
virtual void EmitWin64EHEndProlog()
virtual void EmitCFISections(bool EH, bool Debug)
static int64_t truncateToSize(int64_t Value, unsigned Bytes)
virtual void EmitCFIRememberState()
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding)
#define DWARF2_FLAG_IS_STMT
const MCSection * getXDataSection() const
#define llvm_unreachable(msg)
bool is_absolute(const Twine &path)
Is path absolute?
static const MCSection * getWin64EHTableSection(StringRef suffix, MCContext &context)
format_object1< T > format(const char *Fmt, const T &Val)
.code16 (X86) / .code 16 (ARM)
StringRef getSectionName() const
.type _foo, STT_GNU_IFUNC
virtual void EmitWin64EHStartChained()
virtual bool EmitDwarfFileDirective(unsigned FileNo, StringRef Directory, StringRef Filename, unsigned CUID=0)
virtual void EmitCFIRestoreState()
uint32_t getOffset() const
virtual void EmitWin64EHAllocStack(unsigned Size)
const MCExpr * getValue() const
.weak_def_can_be_hidden (MachO)
static char toOctal(int X)
virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue)
#define DWARF2_FLAG_EPILOGUE_BEGIN
char back() const
back - Get the last character in the string.
MCCodeEmitter - Generic instruction encoding interface.
static const MCSymbol * Emit(MCStreamer *MCOS)
virtual void EmitCFIDefCfaRegister(int64_t Register)
.subsections_via_symbols (MachO)
#define DWARF2_FLAG_BASIC_BLOCK
virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS, const MCExpr *Subsection) const =0
virtual void EmitCFIUndefined(int64_t Register)
bool empty() const
empty - Check if the array is empty.
int getLLVMRegNum(unsigned RegNum, bool isEH) const
Map a dwarf register back to a target register.
MCFixupKind getKind() const
static StringRef GetSectionSuffix(const MCSymbol *func)
const MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, int Selection=0, const MCSectionCOFF *Assoc=0)
virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind, bool Except)
virtual void EmitLabel(MCSymbol *Symbol)
virtual void EmitCFIOffset(int64_t Register, int64_t Offset)
virtual void EmitDebugLabel(MCSymbol *Symbol)
.type _foo, STT_TLS # aka
Promote Memory to Register
MCStreamer * createAsmStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer, formatted_raw_ostream &OS, bool isVerboseAsm, bool useLoc, bool useCFI, bool useDwarfDirectory, MCInstPrinter *InstPrint=0, MCCodeEmitter *CE=0, MCAsmBackend *TAB=0, bool ShowInst=false)
void setVariableValue(const MCExpr *Value)
virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset)
unsigned Log2_32(uint32_t Value)
virtual void EmitWin64EHEndProc()
virtual void EmitWin64EHHandlerData()
StringRef getSegmentName() const
.code32 (X86) / .code 32 (ARM)
.type _foo, STT_COMMON # aka
void dump_pretty(raw_ostream &OS, const MCAsmInfo *MAI=0, const MCInstPrinter *Printer=0, StringRef Separator=" ") const
Dump the MCInst as prettily as possible using the additional MC structures, if given. Operators are separated by the Separator string.
virtual void EmitCFISignalFrame()
virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset)
.type _foo, STT_FUNC # aka
virtual void EmitWin64EHEndChained()
virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset)
MCFixupKindInfo - Target independent information on a fixup kind.
virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset)
virtual void EmitWin64EHStartProc(const MCSymbol *Symbol)
LLVM Value Representation.
MCAsmBackend - Generic interface to target specific assembler backends.
const MCObjectFileInfo * getObjectFileInfo() const
static cl::opt< bool, true > Debug("debug", cl::desc("Enable debug output"), cl::Hidden, cl::location(DebugFlag))
raw_ostream & nulls()
nulls() - This returns a reference to a raw_ostream which discards output.
bool isPowerOf2_32(uint32_t Value)
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
const MCRegisterInfo & MRI
virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset)
static void PrintQuotedString(StringRef Data, raw_ostream &OS)
virtual void EmitWin64EHPushReg(unsigned Register)
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment)
virtual void EmitCFIWindowSave()
bool empty() const
empty - Check if the string is empty.