llvm.org GIT mirror llvm / 030f63a
Expose an InitToTextSection through MCStreamer. The aim of this patch is to fix the following piece of code in the platform-independent AsmParser: void AsmParser::CheckForValidSection() { if (!ParsingInlineAsm && !getStreamer().getCurrentSection()) { TokError("expected section directive before assembly directive"); Out.SwitchSection(Ctx.getMachOSection( "__TEXT", "__text", MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, 0, SectionKind::getText())); } } This was added for the "-n" option of llvm-mc. The proposed fix adds another virtual method to MCStreamer, called InitToTextSection. Conceptually, it's similar to the existing InitSections which initializes all common sections and switches to text. The new method is implemented by each platform streamer in a way that it sees fit. So AsmParser can now do this: void AsmParser::CheckForValidSection() { if (!ParsingInlineAsm && !getStreamer().getCurrentSection()) { TokError("expected section directive before assembly directive"); Out.InitToTextSection(); } } Which is much more reasonable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172450 91177308-0d34-0410-b5e6-96231b3b80d8 Eli Bendersky 6 years ago
10 changed file(s) with 40 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
4343 /// @{
4444
4545 virtual void InitSections();
46 virtual void InitToTextSection();
4647 virtual void ChangeSection(const MCSection *Section);
4748 virtual void EmitLabel(MCSymbol *Symbol);
4849 virtual void EmitDebugLabel(MCSymbol *Symbol);
232232
233233 /// InitSections - Create the default sections and set the initial one.
234234 virtual void InitSections() = 0;
235
236 /// InitToTextSection - Create a text section and switch the streamer to it.
237 virtual void InitToTextSection() = 0;
235238
236239 /// EmitLabel - Emit a label for @p Symbol into the current section.
237240 ///
126126 virtual void ChangeSection(const MCSection *Section);
127127
128128 virtual void InitSections() {
129 InitToTextSection();
130 }
131
132 virtual void InitToTextSection() {
129133 // FIXME, this is MachO specific, but the testsuite
130134 // expects this.
131 SwitchSection(getContext().getMachOSection("__TEXT", "__text",
132 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
133 0, SectionKind::getText()));
135 SwitchSection(getContext().getMachOSection(
136 "__TEXT", "__text",
137 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
138 0, SectionKind::getText()));
134139 }
135140
136141 virtual void EmitLabel(MCSymbol *Symbol);
6262 }
6363
6464 MCELFStreamer::~MCELFStreamer() {
65 }
66
67 void MCELFStreamer::InitToTextSection() {
68 SetSectionText();
6569 }
6670
6771 void MCELFStreamer::InitSections() {
4141 /// @{
4242
4343 virtual void InitSections();
44 virtual void InitToTextSection();
4445 virtual void EmitLabel(MCSymbol *Symbol);
4546 virtual void EmitDebugLabel(MCSymbol *Symbol);
4647 virtual void EmitEHSymAttributes(const MCSymbol *Symbol,
8990 } // end anonymous namespace.
9091
9192 void MCMachOStreamer::InitSections() {
92 SwitchSection(getContext().getMachOSection("__TEXT", "__text",
93 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
94 0, SectionKind::getText()));
95
93 InitToTextSection();
94 }
95
96 void MCMachOStreamer::InitToTextSection() {
97 SwitchSection(getContext().getMachOSection(
98 "__TEXT", "__text",
99 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, 0,
100 SectionKind::getText()));
96101 }
97102
98103 void MCMachOStreamer::EmitEHSymAttributes(const MCSymbol *Symbol,
2222
2323 /// @name MCStreamer Interface
2424 /// @{
25
26 virtual void InitToTextSection() {
27 }
2528
2629 virtual void InitSections() {
2730 }
707707 void AsmParser::CheckForValidSection() {
708708 if (!ParsingInlineAsm && !getStreamer().getCurrentSection()) {
709709 TokError("expected section directive before assembly directive");
710 Out.SwitchSection(Ctx.getMachOSection(
711 "__TEXT", "__text",
712 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
713 0, SectionKind::getText()));
710 Out.InitToTextSection();
714711 }
715712 }
716713
3535 /// @{
3636
3737 virtual void InitSections();
38 virtual void InitToTextSection();
3839 virtual void EmitLabel(MCSymbol *Symbol);
3940 virtual void EmitDebugLabel(MCSymbol *Symbol);
4041 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
103104 } // end anonymous namespace.
104105
105106 void MCPureStreamer::InitSections() {
107 InitToTextSection();
108 }
109
110 void MCPureStreamer::InitToTextSection() {
106111 // FIMXE: To what!?
107112 SwitchSection(getContext().getMachOSection("__TEXT", "__text",
108113 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
109114 0, SectionKind::getText()));
110
111115 }
112116
113117 void MCPureStreamer::EmitLabel(MCSymbol *Symbol) {
4949 // MCStreamer interface
5050
5151 virtual void InitSections();
52 virtual void InitToTextSection();
5253 virtual void EmitLabel(MCSymbol *Symbol);
5354 virtual void EmitDebugLabel(MCSymbol *Symbol);
5455 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
172173
173174 // MCStreamer interface
174175
176 void WinCOFFStreamer::InitToTextSection() {
177 SetSectionText();
178 }
179
175180 void WinCOFFStreamer::InitSections() {
176181 SetSectionText();
177182 SetSectionData();
770770
771771 // Noop calls.
772772 virtual void ChangeSection(const MCSection *Section) {}
773 virtual void InitToTextSection() {}
773774 virtual void InitSections() {}
774775 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) {}
775776 virtual void EmitThumbFunc(MCSymbol *Func) {}