llvm.org GIT mirror llvm / b0d78d0
Move emitInlineAsmEnd to the AsmPrinter interface. There is no inline asm in a .s file. Therefore, there should be no logic to handle it in the streamer. Inline asm only exists in bitcode files, so the logic can live in the (long misnamed) AsmPrinter class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200011 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
6 changed file(s) with 34 addition(s) and 41 deletion(s). Raw diff Collapse all Expand all
4444 class MCInstrInfo;
4545 class MCSection;
4646 class MCStreamer;
47 class MCSubtargetInfo;
4748 class MCSymbol;
4849 class MDNode;
4950 class DwarfDebug;
460461 unsigned AsmVariant,
461462 const char *ExtraCode, raw_ostream &OS);
462463
464 /// Let the target do anything it needs to do after emitting inlineasm.
465 /// This callback can be used restore the original mode in case the
466 /// inlineasm contains directives to switch modes.
467 /// \p StartInfo - the original subtarget info before inline asm
468 /// \p EndInfo - the final subtarget info after parsing the inline asm,
469 /// or NULL if the value is unknown.
470 virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
471 MCSubtargetInfo *EndInfo) const;
472
463473 private:
464474 /// Private state for PrintSpecial()
465475 // Assign a unique ID to this machine instruction.
7474
7575 // Allow a target to add behavior to the EmitLabel of MCStreamer.
7676 virtual void emitLabel(MCSymbol *Symbol);
77
78 /// Let the target do anything it needs to do after emitting inlineasm.
79 /// This callback can be used restore the original mode in case the
80 /// inlineasm contains directives to switch modes.
81 /// \p StartInfo - the original subtarget info before inline asm
82 /// \p EndInfo - the final subtarget info after parsing the inline asm,
83 // or NULL if the value is unknown.
84 virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
85 MCSubtargetInfo *EndInfo) {}
8677 };
8778
8879 // FIXME: declared here because it is used from
113104 virtual void emitArch(unsigned Arch) = 0;
114105 virtual void finishAttributeSection() = 0;
115106 virtual void emitInst(uint32_t Inst, char Suffix = '\0') = 0;
116 virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
117 MCSubtargetInfo *EndInfo);
118107 };
119108
120109 /// MCStreamer - Streaming machine code generation interface. This interface
688677 /// indicated by the hasRawTextSupport() predicate. By default this aborts.
689678 void EmitRawText(const Twine &String);
690679
691 /// EmitInlineAsmEnd - Used to perform any cleanup needed after emitting
692 /// inline assembly. Provides the start and end subtarget info values.
693 /// The end subtarget info may be NULL if it is not know, for example, when
694 /// emitting the inline assembly as raw text.
695 virtual void EmitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
696 MCSubtargetInfo *EndInfo) {
697 if (TargetStreamer)
698 TargetStreamer->emitInlineAsmEnd(StartInfo, EndInfo);
699 }
700
701680 /// Flush - Causes any cached state to be written out.
702681 virtual void Flush() {}
703682
8383 // system assembler does.
8484 if (OutStreamer.hasRawTextSupport()) {
8585 OutStreamer.EmitRawText(Str);
86 OutStreamer.EmitInlineAsmEnd(TM.getSubtarget(), 0);
86 emitInlineAsmEnd(TM.getSubtarget(), 0);
8787 return;
8888 }
8989
123123 const_cast(&TM.getSubtarget());
124124
125125 // Preserve a copy of the original STI because the parser may modify it.
126 // The target can restore the original state in EmitInlineAsmEnd().
126 // The target can restore the original state in emitInlineAsmEnd().
127127 MCSubtargetInfo STIOrig = *STI;
128128
129129 OwningPtr
137137 // Don't implicitly switch to the text section before the asm.
138138 int Res = Parser->Run(/*NoInitialTextSection*/ true,
139139 /*NoFinalize*/ true);
140 OutStreamer.EmitInlineAsmEnd(STIOrig, STI);
140 emitInlineAsmEnd(STIOrig, STI);
141141 if (Res && !HasDiagHandler)
142142 report_fatal_error("Error parsing inline asm\n");
143143 }
548548 return true;
549549 }
550550
551 void AsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
552 MCSubtargetInfo *EndInfo) const {}
437437 return false;
438438 }
439439
440 static bool isThumb(const MCSubtargetInfo& STI) {
441 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
442 }
443
444 void ARMAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
445 MCSubtargetInfo *EndInfo) const {
446 // If either end mode is unknown (EndInfo == NULL) or different than
447 // the start mode, then restore the start mode.
448 const bool WasThumb = isThumb(StartInfo);
449 if (EndInfo == NULL || WasThumb != isThumb(*EndInfo)) {
450 OutStreamer.EmitAssemblerFlag(WasThumb ? MCAF_Code16 : MCAF_Code32);
451 if (EndInfo)
452 EndInfo->ToggleFeature(ARM::ModeThumb);
453 }
454 }
455
440456 void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) {
441457 if (Subtarget->isTargetMachO()) {
442458 Reloc::Model RelocM = TM.getRelocationModel();
6262 unsigned AsmVariant, const char *ExtraCode,
6363 raw_ostream &O) LLVM_OVERRIDE;
6464
65 virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
66 MCSubtargetInfo *EndInfo) const LLVM_OVERRIDE;
67
6568 void EmitJumpTable(const MachineInstr *MI);
6669 void EmitJump2Table(const MachineInstr *MI);
6770 virtual void EmitInstruction(const MachineInstr *MI) LLVM_OVERRIDE;
103103 return 0;
104104 }
105105
106 static bool isThumb(const MCSubtargetInfo& STI) {
107 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
108 }
109
110106 void ARMTargetStreamer::anchor() {}
111
112 void ARMTargetStreamer::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
113 MCSubtargetInfo *EndInfo) {
114 // If either end mode is unknown (EndInfo == NULL) or different than
115 // the start mode, then restore the start mode.
116 const bool WasThumb = isThumb(StartInfo);
117 if (EndInfo == NULL || WasThumb != isThumb(*EndInfo)) {
118 assert(Streamer);
119 Streamer->EmitAssemblerFlag(WasThumb ? MCAF_Code16 : MCAF_Code32);
120 if (EndInfo)
121 EndInfo->ToggleFeature(ARM::ModeThumb);
122 }
123 }
124107
125108 namespace {
126109