Remove unused StringRef that no compiler warned about, I wonder why.
[oota-llvm.git] / lib / MC / MCParser / ELFAsmParser.cpp
1 //===- ELFAsmParser.cpp - ELF Assembly Parser -----------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "llvm/MC/MCParser/MCAsmParserExtension.h"
11 #include "llvm/ADT/StringSwitch.h"
12 #include "llvm/ADT/Twine.h"
13 #include "llvm/MC/MCAsmInfo.h"
14 #include "llvm/MC/MCContext.h"
15 #include "llvm/MC/MCExpr.h"
16 #include "llvm/MC/MCParser/MCAsmLexer.h"
17 #include "llvm/MC/MCSectionELF.h"
18 #include "llvm/MC/MCStreamer.h"
19 #include "llvm/Support/ELF.h"
20 using namespace llvm;
21
22 namespace {
23
24 class ELFAsmParser : public MCAsmParserExtension {
25   template<bool (ELFAsmParser::*HandlerMethod)(StringRef, SMLoc)>
26   void addDirectiveHandler(StringRef Directive) {
27     MCAsmParser::ExtensionDirectiveHandler Handler = std::make_pair(
28         this, HandleDirective<ELFAsmParser, HandlerMethod>);
29
30     getParser().addDirectiveHandler(Directive, Handler);
31   }
32
33   bool ParseSectionSwitch(StringRef Section, unsigned Type,
34                           unsigned Flags, SectionKind Kind);
35   bool SeenIdent;
36
37 public:
38   ELFAsmParser() : SeenIdent(false) {
39     BracketExpressionsSupported = true;
40   }
41
42   virtual void Initialize(MCAsmParser &Parser) {
43     // Call the base implementation.
44     this->MCAsmParserExtension::Initialize(Parser);
45
46     addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveData>(".data");
47     addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveText>(".text");
48     addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveBSS>(".bss");
49     addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveRoData>(".rodata");
50     addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveTData>(".tdata");
51     addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveTBSS>(".tbss");
52     addDirectiveHandler<
53       &ELFAsmParser::ParseSectionDirectiveDataRel>(".data.rel");
54     addDirectiveHandler<
55       &ELFAsmParser::ParseSectionDirectiveDataRelRo>(".data.rel.ro");
56     addDirectiveHandler<
57       &ELFAsmParser::ParseSectionDirectiveDataRelRoLocal>(".data.rel.ro.local");
58     addDirectiveHandler<
59       &ELFAsmParser::ParseSectionDirectiveEhFrame>(".eh_frame");
60     addDirectiveHandler<&ELFAsmParser::ParseDirectiveSection>(".section");
61     addDirectiveHandler<
62       &ELFAsmParser::ParseDirectivePushSection>(".pushsection");
63     addDirectiveHandler<&ELFAsmParser::ParseDirectivePopSection>(".popsection");
64     addDirectiveHandler<&ELFAsmParser::ParseDirectiveSize>(".size");
65     addDirectiveHandler<&ELFAsmParser::ParseDirectivePrevious>(".previous");
66     addDirectiveHandler<&ELFAsmParser::ParseDirectiveType>(".type");
67     addDirectiveHandler<&ELFAsmParser::ParseDirectiveIdent>(".ident");
68     addDirectiveHandler<&ELFAsmParser::ParseDirectiveSymver>(".symver");
69     addDirectiveHandler<&ELFAsmParser::ParseDirectiveVersion>(".version");
70     addDirectiveHandler<&ELFAsmParser::ParseDirectiveWeakref>(".weakref");
71     addDirectiveHandler<&ELFAsmParser::ParseDirectiveSymbolAttribute>(".weak");
72     addDirectiveHandler<&ELFAsmParser::ParseDirectiveSymbolAttribute>(".local");
73     addDirectiveHandler<
74       &ELFAsmParser::ParseDirectiveSymbolAttribute>(".protected");
75     addDirectiveHandler<
76       &ELFAsmParser::ParseDirectiveSymbolAttribute>(".internal");
77     addDirectiveHandler<
78       &ELFAsmParser::ParseDirectiveSymbolAttribute>(".hidden");
79     addDirectiveHandler<&ELFAsmParser::ParseDirectiveSubsection>(".subsection");
80   }
81
82   // FIXME: Part of this logic is duplicated in the MCELFStreamer. What is
83   // the best way for us to get access to it?
84   bool ParseSectionDirectiveData(StringRef, SMLoc) {
85     return ParseSectionSwitch(".data", ELF::SHT_PROGBITS,
86                               ELF::SHF_WRITE |ELF::SHF_ALLOC,
87                               SectionKind::getDataRel());
88   }
89   bool ParseSectionDirectiveText(StringRef, SMLoc) {
90     return ParseSectionSwitch(".text", ELF::SHT_PROGBITS,
91                               ELF::SHF_EXECINSTR |
92                               ELF::SHF_ALLOC, SectionKind::getText());
93   }
94   bool ParseSectionDirectiveBSS(StringRef, SMLoc) {
95     return ParseSectionSwitch(".bss", ELF::SHT_NOBITS,
96                               ELF::SHF_WRITE |
97                               ELF::SHF_ALLOC, SectionKind::getBSS());
98   }
99   bool ParseSectionDirectiveRoData(StringRef, SMLoc) {
100     return ParseSectionSwitch(".rodata", ELF::SHT_PROGBITS,
101                               ELF::SHF_ALLOC,
102                               SectionKind::getReadOnly());
103   }
104   bool ParseSectionDirectiveTData(StringRef, SMLoc) {
105     return ParseSectionSwitch(".tdata", ELF::SHT_PROGBITS,
106                               ELF::SHF_ALLOC |
107                               ELF::SHF_TLS | ELF::SHF_WRITE,
108                               SectionKind::getThreadData());
109   }
110   bool ParseSectionDirectiveTBSS(StringRef, SMLoc) {
111     return ParseSectionSwitch(".tbss", ELF::SHT_NOBITS,
112                               ELF::SHF_ALLOC |
113                               ELF::SHF_TLS | ELF::SHF_WRITE,
114                               SectionKind::getThreadBSS());
115   }
116   bool ParseSectionDirectiveDataRel(StringRef, SMLoc) {
117     return ParseSectionSwitch(".data.rel", ELF::SHT_PROGBITS,
118                               ELF::SHF_ALLOC |
119                               ELF::SHF_WRITE,
120                               SectionKind::getDataRel());
121   }
122   bool ParseSectionDirectiveDataRelRo(StringRef, SMLoc) {
123     return ParseSectionSwitch(".data.rel.ro", ELF::SHT_PROGBITS,
124                               ELF::SHF_ALLOC |
125                               ELF::SHF_WRITE,
126                               SectionKind::getReadOnlyWithRel());
127   }
128   bool ParseSectionDirectiveDataRelRoLocal(StringRef, SMLoc) {
129     return ParseSectionSwitch(".data.rel.ro.local", ELF::SHT_PROGBITS,
130                               ELF::SHF_ALLOC |
131                               ELF::SHF_WRITE,
132                               SectionKind::getReadOnlyWithRelLocal());
133   }
134   bool ParseSectionDirectiveEhFrame(StringRef, SMLoc) {
135     return ParseSectionSwitch(".eh_frame", ELF::SHT_PROGBITS,
136                               ELF::SHF_ALLOC |
137                               ELF::SHF_WRITE,
138                               SectionKind::getDataRel());
139   }
140   bool ParseDirectivePushSection(StringRef, SMLoc);
141   bool ParseDirectivePopSection(StringRef, SMLoc);
142   bool ParseDirectiveSection(StringRef, SMLoc);
143   bool ParseDirectiveSize(StringRef, SMLoc);
144   bool ParseDirectivePrevious(StringRef, SMLoc);
145   bool ParseDirectiveType(StringRef, SMLoc);
146   bool ParseDirectiveIdent(StringRef, SMLoc);
147   bool ParseDirectiveSymver(StringRef, SMLoc);
148   bool ParseDirectiveVersion(StringRef, SMLoc);
149   bool ParseDirectiveWeakref(StringRef, SMLoc);
150   bool ParseDirectiveSymbolAttribute(StringRef, SMLoc);
151   bool ParseDirectiveSubsection(StringRef, SMLoc);
152
153 private:
154   bool ParseSectionName(StringRef &SectionName);
155   bool ParseSectionArguments(bool IsPush);
156 };
157
158 }
159
160 /// ParseDirectiveSymbolAttribute
161 ///  ::= { ".local", ".weak", ... } [ identifier ( , identifier )* ]
162 bool ELFAsmParser::ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc) {
163   MCSymbolAttr Attr = StringSwitch<MCSymbolAttr>(Directive)
164     .Case(".weak", MCSA_Weak)
165     .Case(".local", MCSA_Local)
166     .Case(".hidden", MCSA_Hidden)
167     .Case(".internal", MCSA_Internal)
168     .Case(".protected", MCSA_Protected)
169     .Default(MCSA_Invalid);
170   assert(Attr != MCSA_Invalid && "unexpected symbol attribute directive!");
171   if (getLexer().isNot(AsmToken::EndOfStatement)) {
172     for (;;) {
173       StringRef Name;
174
175       if (getParser().parseIdentifier(Name))
176         return TokError("expected identifier in directive");
177
178       MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
179
180       getStreamer().EmitSymbolAttribute(Sym, Attr);
181
182       if (getLexer().is(AsmToken::EndOfStatement))
183         break;
184
185       if (getLexer().isNot(AsmToken::Comma))
186         return TokError("unexpected token in directive");
187       Lex();
188     }
189   }
190
191   Lex();
192   return false;
193 }
194
195 bool ELFAsmParser::ParseSectionSwitch(StringRef Section, unsigned Type,
196                                       unsigned Flags, SectionKind Kind) {
197   const MCExpr *Subsection = 0;
198   if (getLexer().isNot(AsmToken::EndOfStatement)) {
199     if (getParser().parseExpression(Subsection))
200       return true;
201   }
202
203   getStreamer().SwitchSection(getContext().getELFSection(
204                                 Section, Type, Flags, Kind),
205                               Subsection);
206
207   return false;
208 }
209
210 bool ELFAsmParser::ParseDirectiveSize(StringRef, SMLoc) {
211   StringRef Name;
212   if (getParser().parseIdentifier(Name))
213     return TokError("expected identifier in directive");
214   MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
215
216   if (getLexer().isNot(AsmToken::Comma))
217     return TokError("unexpected token in directive");
218   Lex();
219
220   const MCExpr *Expr;
221   if (getParser().parseExpression(Expr))
222     return true;
223
224   if (getLexer().isNot(AsmToken::EndOfStatement))
225     return TokError("unexpected token in directive");
226
227   getStreamer().EmitELFSize(Sym, Expr);
228   return false;
229 }
230
231 bool ELFAsmParser::ParseSectionName(StringRef &SectionName) {
232   // A section name can contain -, so we cannot just use
233   // parseIdentifier.
234   SMLoc FirstLoc = getLexer().getLoc();
235   unsigned Size = 0;
236
237   if (getLexer().is(AsmToken::String)) {
238     SectionName = getTok().getIdentifier();
239     Lex();
240     return false;
241   }
242
243   for (;;) {
244     unsigned CurSize;
245
246     SMLoc PrevLoc = getLexer().getLoc();
247     if (getLexer().is(AsmToken::Minus)) {
248       CurSize = 1;
249       Lex(); // Consume the "-".
250     } else if (getLexer().is(AsmToken::String)) {
251       CurSize = getTok().getIdentifier().size() + 2;
252       Lex();
253     } else if (getLexer().is(AsmToken::Identifier)) {
254       CurSize = getTok().getIdentifier().size();
255       Lex();
256     } else {
257       break;
258     }
259
260     Size += CurSize;
261     SectionName = StringRef(FirstLoc.getPointer(), Size);
262
263     // Make sure the following token is adjacent.
264     if (PrevLoc.getPointer() + CurSize != getTok().getLoc().getPointer())
265       break;
266   }
267   if (Size == 0)
268     return true;
269
270   return false;
271 }
272
273 static SectionKind computeSectionKind(unsigned Flags) {
274   if (Flags & ELF::SHF_EXECINSTR)
275     return SectionKind::getText();
276   if (Flags & ELF::SHF_TLS)
277     return SectionKind::getThreadData();
278   return SectionKind::getDataRel();
279 }
280
281 static int parseSectionFlags(StringRef flagsStr) {
282   int flags = 0;
283
284   for (unsigned i = 0; i < flagsStr.size(); i++) {
285     switch (flagsStr[i]) {
286     case 'a':
287       flags |= ELF::SHF_ALLOC;
288       break;
289     case 'x':
290       flags |= ELF::SHF_EXECINSTR;
291       break;
292     case 'w':
293       flags |= ELF::SHF_WRITE;
294       break;
295     case 'M':
296       flags |= ELF::SHF_MERGE;
297       break;
298     case 'S':
299       flags |= ELF::SHF_STRINGS;
300       break;
301     case 'T':
302       flags |= ELF::SHF_TLS;
303       break;
304     case 'c':
305       flags |= ELF::XCORE_SHF_CP_SECTION;
306       break;
307     case 'd':
308       flags |= ELF::XCORE_SHF_DP_SECTION;
309       break;
310     case 'G':
311       flags |= ELF::SHF_GROUP;
312       break;
313     default:
314       return -1;
315     }
316   }
317
318   return flags;
319 }
320
321 bool ELFAsmParser::ParseDirectivePushSection(StringRef s, SMLoc loc) {
322   getStreamer().PushSection();
323
324   if (ParseSectionArguments(/*IsPush=*/true)) {
325     getStreamer().PopSection();
326     return true;
327   }
328
329   return false;
330 }
331
332 bool ELFAsmParser::ParseDirectivePopSection(StringRef, SMLoc) {
333   if (!getStreamer().PopSection())
334     return TokError(".popsection without corresponding .pushsection");
335   return false;
336 }
337
338 // FIXME: This is a work in progress.
339 bool ELFAsmParser::ParseDirectiveSection(StringRef, SMLoc) {
340   return ParseSectionArguments(/*IsPush=*/false);
341 }
342
343 bool ELFAsmParser::ParseSectionArguments(bool IsPush) {
344   StringRef SectionName;
345
346   if (ParseSectionName(SectionName))
347     return TokError("expected identifier in directive");
348
349   StringRef TypeName;
350   int64_t Size = 0;
351   StringRef GroupName;
352   unsigned Flags = 0;
353   const MCExpr *Subsection = 0;
354
355   // Set the defaults first.
356   if (SectionName == ".fini" || SectionName == ".init" ||
357       SectionName == ".rodata")
358     Flags |= ELF::SHF_ALLOC;
359   if (SectionName == ".fini" || SectionName == ".init")
360     Flags |= ELF::SHF_EXECINSTR;
361
362   if (getLexer().is(AsmToken::Comma)) {
363     Lex();
364
365     if (IsPush && getLexer().isNot(AsmToken::String)) {
366       if (getParser().parseExpression(Subsection))
367         return true;
368       if (getLexer().isNot(AsmToken::Comma))
369         goto EndStmt;
370       Lex();
371     }
372    
373     if (getLexer().isNot(AsmToken::String))
374       return TokError("expected string in directive");
375
376     StringRef FlagsStr = getTok().getStringContents();
377     Lex();
378
379     int extraFlags = parseSectionFlags(FlagsStr);
380     if (extraFlags < 0)
381       return TokError("unknown flag");
382     Flags |= extraFlags;
383
384     bool Mergeable = Flags & ELF::SHF_MERGE;
385     bool Group = Flags & ELF::SHF_GROUP;
386
387     if (getLexer().isNot(AsmToken::Comma)) {
388       if (Mergeable)
389         return TokError("Mergeable section must specify the type");
390       if (Group)
391         return TokError("Group section must specify the type");
392     } else {
393       Lex();
394       if (getLexer().isNot(AsmToken::Percent) && getLexer().isNot(AsmToken::At))
395         return TokError("expected '@' or '%' before type");
396
397       Lex();
398       if (getParser().parseIdentifier(TypeName))
399         return TokError("expected identifier in directive");
400
401       if (Mergeable) {
402         if (getLexer().isNot(AsmToken::Comma))
403           return TokError("expected the entry size");
404         Lex();
405         if (getParser().parseAbsoluteExpression(Size))
406           return true;
407         if (Size <= 0)
408           return TokError("entry size must be positive");
409       }
410
411       if (Group) {
412         if (getLexer().isNot(AsmToken::Comma))
413           return TokError("expected group name");
414         Lex();
415         if (getParser().parseIdentifier(GroupName))
416           return true;
417         if (getLexer().is(AsmToken::Comma)) {
418           Lex();
419           StringRef Linkage;
420           if (getParser().parseIdentifier(Linkage))
421             return true;
422           if (Linkage != "comdat")
423             return TokError("Linkage must be 'comdat'");
424         }
425       }
426     }
427   }
428
429 EndStmt:
430   if (getLexer().isNot(AsmToken::EndOfStatement))
431     return TokError("unexpected token in directive");
432
433   unsigned Type = ELF::SHT_PROGBITS;
434
435   if (TypeName.empty()) {
436     if (SectionName.startswith(".note"))
437       Type = ELF::SHT_NOTE;
438     else if (SectionName == ".init_array")
439       Type = ELF::SHT_INIT_ARRAY;
440     else if (SectionName == ".fini_array")
441       Type = ELF::SHT_FINI_ARRAY;
442     else if (SectionName == ".preinit_array")
443       Type = ELF::SHT_PREINIT_ARRAY;
444   } else {
445     if (TypeName == "init_array")
446       Type = ELF::SHT_INIT_ARRAY;
447     else if (TypeName == "fini_array")
448       Type = ELF::SHT_FINI_ARRAY;
449     else if (TypeName == "preinit_array")
450       Type = ELF::SHT_PREINIT_ARRAY;
451     else if (TypeName == "nobits")
452       Type = ELF::SHT_NOBITS;
453     else if (TypeName == "progbits")
454       Type = ELF::SHT_PROGBITS;
455     else if (TypeName == "note")
456       Type = ELF::SHT_NOTE;
457     else if (TypeName == "unwind")
458       Type = ELF::SHT_X86_64_UNWIND;
459     else
460       return TokError("unknown section type");
461   }
462
463   SectionKind Kind = computeSectionKind(Flags);
464   getStreamer().SwitchSection(getContext().getELFSection(SectionName, Type,
465                                                          Flags, Kind, Size,
466                                                          GroupName),
467                               Subsection);
468   return false;
469 }
470
471 bool ELFAsmParser::ParseDirectivePrevious(StringRef DirName, SMLoc) {
472   MCSectionSubPair PreviousSection = getStreamer().getPreviousSection();
473   if (PreviousSection.first == NULL)
474       return TokError(".previous without corresponding .section");
475   getStreamer().SwitchSection(PreviousSection.first, PreviousSection.second);
476
477   return false;
478 }
479
480 /// ParseDirectiveELFType
481 ///  ::= .type identifier , @attribute
482 bool ELFAsmParser::ParseDirectiveType(StringRef, SMLoc) {
483   StringRef Name;
484   if (getParser().parseIdentifier(Name))
485     return TokError("expected identifier in directive");
486
487   // Handle the identifier as the key symbol.
488   MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
489
490   if (getLexer().isNot(AsmToken::Comma))
491     return TokError("unexpected token in '.type' directive");
492   Lex();
493
494   if (getLexer().isNot(AsmToken::Percent) && getLexer().isNot(AsmToken::At))
495     return TokError("expected '@' or '%' before type");
496   Lex();
497
498   StringRef Type;
499   SMLoc TypeLoc;
500
501   TypeLoc = getLexer().getLoc();
502   if (getParser().parseIdentifier(Type))
503     return TokError("expected symbol type in directive");
504
505   MCSymbolAttr Attr = StringSwitch<MCSymbolAttr>(Type)
506     .Case("function", MCSA_ELF_TypeFunction)
507     .Case("object", MCSA_ELF_TypeObject)
508     .Case("tls_object", MCSA_ELF_TypeTLS)
509     .Case("common", MCSA_ELF_TypeCommon)
510     .Case("notype", MCSA_ELF_TypeNoType)
511     .Case("gnu_unique_object", MCSA_ELF_TypeGnuUniqueObject)
512     .Case("gnu_indirect_function", MCSA_ELF_TypeIndFunction)
513     .Default(MCSA_Invalid);
514
515   if (Attr == MCSA_Invalid)
516     return Error(TypeLoc, "unsupported attribute in '.type' directive");
517
518   if (getLexer().isNot(AsmToken::EndOfStatement))
519     return TokError("unexpected token in '.type' directive");
520
521   Lex();
522
523   getStreamer().EmitSymbolAttribute(Sym, Attr);
524
525   return false;
526 }
527
528 /// ParseDirectiveIdent
529 ///  ::= .ident string
530 bool ELFAsmParser::ParseDirectiveIdent(StringRef, SMLoc) {
531   if (getLexer().isNot(AsmToken::String))
532     return TokError("unexpected token in '.ident' directive");
533
534   StringRef Data = getTok().getIdentifier();
535
536   Lex();
537
538   const MCSection *Comment =
539     getContext().getELFSection(".comment", ELF::SHT_PROGBITS,
540                                ELF::SHF_MERGE |
541                                ELF::SHF_STRINGS,
542                                SectionKind::getReadOnly(),
543                                1, "");
544
545   getStreamer().PushSection();
546   getStreamer().SwitchSection(Comment);
547   if (!SeenIdent) {
548     getStreamer().EmitIntValue(0, 1);
549     SeenIdent = true;
550   }
551   getStreamer().EmitBytes(Data);
552   getStreamer().EmitIntValue(0, 1);
553   getStreamer().PopSection();
554   return false;
555 }
556
557 /// ParseDirectiveSymver
558 ///  ::= .symver foo, bar2@zed
559 bool ELFAsmParser::ParseDirectiveSymver(StringRef, SMLoc) {
560   StringRef Name;
561   if (getParser().parseIdentifier(Name))
562     return TokError("expected identifier in directive");
563
564   if (getLexer().isNot(AsmToken::Comma))
565     return TokError("expected a comma");
566
567   Lex();
568
569   StringRef AliasName;
570   if (getParser().parseIdentifier(AliasName))
571     return TokError("expected identifier in directive");
572
573   if (AliasName.find('@') == StringRef::npos)
574     return TokError("expected a '@' in the name");
575
576   MCSymbol *Alias = getContext().GetOrCreateSymbol(AliasName);
577   MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
578   const MCExpr *Value = MCSymbolRefExpr::Create(Sym, getContext());
579
580   getStreamer().EmitAssignment(Alias, Value);
581   return false;
582 }
583
584 /// ParseDirectiveVersion
585 ///  ::= .version string
586 bool ELFAsmParser::ParseDirectiveVersion(StringRef, SMLoc) {
587   if (getLexer().isNot(AsmToken::String))
588     return TokError("unexpected token in '.version' directive");
589
590   StringRef Data = getTok().getIdentifier();
591
592   Lex();
593
594   const MCSection *Note =
595     getContext().getELFSection(".note", ELF::SHT_NOTE, 0,
596                                SectionKind::getReadOnly());
597
598   getStreamer().PushSection();
599   getStreamer().SwitchSection(Note);
600   getStreamer().EmitIntValue(Data.size()+1, 4); // namesz.
601   getStreamer().EmitIntValue(0, 4);             // descsz = 0 (no description).
602   getStreamer().EmitIntValue(1, 4);             // type = NT_VERSION.
603   getStreamer().EmitBytes(Data);                // name.
604   getStreamer().EmitIntValue(0, 1);             // terminate the string.
605   getStreamer().EmitValueToAlignment(4);        // ensure 4 byte alignment.
606   getStreamer().PopSection();
607   return false;
608 }
609
610 /// ParseDirectiveWeakref
611 ///  ::= .weakref foo, bar
612 bool ELFAsmParser::ParseDirectiveWeakref(StringRef, SMLoc) {
613   // FIXME: Share code with the other alias building directives.
614
615   StringRef AliasName;
616   if (getParser().parseIdentifier(AliasName))
617     return TokError("expected identifier in directive");
618
619   if (getLexer().isNot(AsmToken::Comma))
620     return TokError("expected a comma");
621
622   Lex();
623
624   StringRef Name;
625   if (getParser().parseIdentifier(Name))
626     return TokError("expected identifier in directive");
627
628   MCSymbol *Alias = getContext().GetOrCreateSymbol(AliasName);
629
630   MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
631
632   getStreamer().EmitWeakReference(Alias, Sym);
633   return false;
634 }
635
636 bool ELFAsmParser::ParseDirectiveSubsection(StringRef, SMLoc) {
637   const MCExpr *Subsection = 0;
638   if (getLexer().isNot(AsmToken::EndOfStatement)) {
639     if (getParser().parseExpression(Subsection))
640      return true;
641   }
642
643   if (getLexer().isNot(AsmToken::EndOfStatement))
644     return TokError("unexpected token in directive");
645
646   getStreamer().SubSection(Subsection);
647   return false;
648 }
649
650 namespace llvm {
651
652 MCAsmParserExtension *createELFAsmParser() {
653   return new ELFAsmParser;
654 }
655
656 }