llvm.org GIT mirror llvm / 1674b0b
Add AsmParser support for the ELF .previous directive. Patch by Roman Divacky. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112849 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 10 years ago
7 changed file(s) with 36 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
5353 /// kept up to date by SwitchSection.
5454 const MCSection *CurSection;
5555
56 /// PrevSection - This is the previous section code is being emitted to, it is
57 /// kept up to date by SwitchSection.
58 const MCSection *PrevSection;
59
5660 public:
5761 virtual ~MCStreamer();
5862
9498 /// getCurrentSection - Return the current section that the streamer is
9599 /// emitting code to.
96100 const MCSection *getCurrentSection() const { return CurSection; }
101
102 /// getPreviousSection - Return the previous section that the streamer is
103 /// emitting code to.
104 const MCSection *getPreviousSection() const { return PrevSection; }
97105
98106 /// SwitchSection - Set the current section where code is being emitted to
99107 /// @p Section. This is required to update CurSection.
216216 void MCAsmStreamer::SwitchSection(const MCSection *Section) {
217217 assert(Section && "Cannot switch to a null section!");
218218 if (Section != CurSection) {
219 PrevSection = CurSection;
219220 CurSection = Section;
220221 Section->PrintSwitchToSection(MAI, OS);
221222 }
2525 /// @{
2626
2727 virtual void SwitchSection(const MCSection *Section) {
28 PrevSection = CurSection;
2829 CurSection = Section;
2930 }
3031
7676 // If already in this section, then this is a noop.
7777 if (Section == CurSection) return;
7878
79 PrevSection = CurSection;
7980 CurSection = Section;
8081 CurSectionData = &getAssembler().getOrCreateSectionData(*Section);
8182 }
4949 AddDirectiveHandler<&ELFAsmParser::ParseDirectiveSize>(".size");
5050 AddDirectiveHandler<&ELFAsmParser::ParseDirectiveLEB128>(".sleb128");
5151 AddDirectiveHandler<&ELFAsmParser::ParseDirectiveLEB128>(".uleb128");
52 AddDirectiveHandler<&ELFAsmParser::ParseDirectivePrevious>(".previous");
5253 }
5354
5455 bool ParseSectionDirectiveData(StringRef, SMLoc) {
110111 bool ParseDirectiveLEB128(StringRef, SMLoc);
111112 bool ParseDirectiveSection(StringRef, SMLoc);
112113 bool ParseDirectiveSize(StringRef, SMLoc);
114 bool ParseDirectivePrevious(StringRef, SMLoc);
113115 };
114116
115117 }
271273 return TokError("LEB128 not supported yet");
272274 }
273275
276 bool ELFAsmParser::ParseDirectivePrevious(StringRef DirName, SMLoc) {
277 const MCSection *PreviousSection = getStreamer().getPreviousSection();
278 if (PreviousSection != NULL)
279 getStreamer().SwitchSection(PreviousSection);
280
281 return false;
282 }
283
274284 namespace llvm {
275285
276286 MCAsmParserExtension *createELFAsmParser() {
1414 #include
1515 using namespace llvm;
1616
17 MCStreamer::MCStreamer(MCContext &Ctx) : Context(Ctx), CurSection(0) {
17 MCStreamer::MCStreamer(MCContext &Ctx) : Context(Ctx), CurSection(0),
18 PrevSection(0) {
1819 }
1920
2021 MCStreamer::~MCStreamer() {
0 # RUN: llvm-mc -triple i386-pc-linux-gnu %s | FileCheck %s
1
2 .bss
3 # CHECK: .bss
4
5 .text
6 # CHECK: .text
7
8 .previous
9 # CHECK: .bss
10
11 .previous
12 # CHECK: .text