| Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 1 | //===- AsmParser.cpp - Parser for Assembly Files --------------------------===// | 
 | 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 | // This class implements the parser for assembly files. | 
 | 11 | // | 
 | 12 | //===----------------------------------------------------------------------===// | 
 | 13 |  | 
| Chris Lattner | be343b3 | 2010-01-22 01:58:08 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCParser/AsmParser.h" | 
| Daniel Dunbar | 7c0a334 | 2009-08-26 22:49:51 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/SmallString.h" | 
| Daniel Dunbar | f9507ff | 2009-07-27 23:20:52 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/Twine.h" | 
| Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCContext.h" | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCExpr.h" | 
| Chris Lattner | 29dfe7c | 2009-06-23 18:41:30 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCInst.h" | 
| Chris Lattner | f9bdedd | 2009-08-10 18:15:01 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCSectionMachO.h" | 
| Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCStreamer.h" | 
| Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCSymbol.h" | 
| Chris Lattner | c6ef277 | 2010-01-22 01:44:57 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCParser/MCParsedAsmOperand.h" | 
| Bill Wendling | 9bc0af8 | 2009-12-28 01:34:57 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Compiler.h" | 
| Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 25 | #include "llvm/Support/SourceMgr.h" | 
 | 26 | #include "llvm/Support/raw_ostream.h" | 
| Daniel Dunbar | a3af370 | 2009-07-20 18:55:04 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetAsmParser.h" | 
| Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 28 | using namespace llvm; | 
 | 29 |  | 
| Chris Lattner | aaec205 | 2010-01-19 19:46:13 +0000 | [diff] [blame] | 30 |  | 
 | 31 | enum { DEFAULT_ADDRSPACE = 0 }; | 
 | 32 |  | 
| Chris Lattner | ebb89b4 | 2009-09-27 21:16:52 +0000 | [diff] [blame] | 33 | AsmParser::AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out, | 
 | 34 |                      const MCAsmInfo &_MAI)  | 
| Sean Callanan | fd0b028 | 2010-01-21 00:19:58 +0000 | [diff] [blame] | 35 |   : Lexer(_MAI), Ctx(_Ctx), Out(_Out), SrcMgr(_SM), TargetParser(0), | 
| Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 36 |     CurBuffer(0) { | 
| Sean Callanan | fd0b028 | 2010-01-21 00:19:58 +0000 | [diff] [blame] | 37 |   Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)); | 
 | 38 |    | 
| Chris Lattner | ebb89b4 | 2009-09-27 21:16:52 +0000 | [diff] [blame] | 39 |   // Debugging directives. | 
 | 40 |   AddDirectiveHandler(".file", &AsmParser::ParseDirectiveFile); | 
 | 41 |   AddDirectiveHandler(".line", &AsmParser::ParseDirectiveLine); | 
 | 42 |   AddDirectiveHandler(".loc", &AsmParser::ParseDirectiveLoc); | 
 | 43 | } | 
 | 44 |  | 
 | 45 |  | 
 | 46 |  | 
| Daniel Dunbar | 7c0a334 | 2009-08-26 22:49:51 +0000 | [diff] [blame] | 47 | AsmParser::~AsmParser() { | 
| Daniel Dunbar | 7c0a334 | 2009-08-26 22:49:51 +0000 | [diff] [blame] | 48 | } | 
 | 49 |  | 
| Daniel Dunbar | f9507ff | 2009-07-27 23:20:52 +0000 | [diff] [blame] | 50 | void AsmParser::Warning(SMLoc L, const Twine &Msg) { | 
| Sean Callanan | bf2013e | 2010-01-20 23:19:55 +0000 | [diff] [blame] | 51 |   PrintMessage(L, Msg.str(), "warning"); | 
| Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 52 | } | 
 | 53 |  | 
| Daniel Dunbar | f9507ff | 2009-07-27 23:20:52 +0000 | [diff] [blame] | 54 | bool AsmParser::Error(SMLoc L, const Twine &Msg) { | 
| Sean Callanan | bf2013e | 2010-01-20 23:19:55 +0000 | [diff] [blame] | 55 |   PrintMessage(L, Msg.str(), "error"); | 
| Chris Lattner | 14ee48a | 2009-06-21 21:22:11 +0000 | [diff] [blame] | 56 |   return true; | 
 | 57 | } | 
 | 58 |  | 
 | 59 | bool AsmParser::TokError(const char *Msg) { | 
| Sean Callanan | bf2013e | 2010-01-20 23:19:55 +0000 | [diff] [blame] | 60 |   PrintMessage(Lexer.getLoc(), Msg, "error"); | 
| Chris Lattner | 14ee48a | 2009-06-21 21:22:11 +0000 | [diff] [blame] | 61 |   return true; | 
 | 62 | } | 
 | 63 |  | 
| Sean Callanan | bf2013e | 2010-01-20 23:19:55 +0000 | [diff] [blame] | 64 | void AsmParser::PrintMessage(SMLoc Loc, const std::string &Msg,  | 
 | 65 |                              const char *Type) const { | 
 | 66 |   SrcMgr.PrintMessage(Loc, Msg, Type); | 
 | 67 | } | 
| Sean Callanan | fd0b028 | 2010-01-21 00:19:58 +0000 | [diff] [blame] | 68 |                    | 
 | 69 | bool AsmParser::EnterIncludeFile(const std::string &Filename) { | 
 | 70 |   int NewBuf = SrcMgr.AddIncludeFile(Filename, Lexer.getLoc()); | 
 | 71 |   if (NewBuf == -1) | 
 | 72 |     return true; | 
| Sean Callanan | 79036e4 | 2010-01-20 22:18:24 +0000 | [diff] [blame] | 73 |    | 
| Sean Callanan | fd0b028 | 2010-01-21 00:19:58 +0000 | [diff] [blame] | 74 |   CurBuffer = NewBuf; | 
 | 75 |    | 
 | 76 |   Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)); | 
 | 77 |    | 
 | 78 |   return false; | 
 | 79 | } | 
 | 80 |                    | 
 | 81 | const AsmToken &AsmParser::Lex() { | 
 | 82 |   const AsmToken *tok = &Lexer.Lex(); | 
 | 83 |    | 
 | 84 |   if (tok->is(AsmToken::Eof)) { | 
 | 85 |     // If this is the end of an included file, pop the parent file off the | 
 | 86 |     // include stack. | 
 | 87 |     SMLoc ParentIncludeLoc = SrcMgr.getParentIncludeLoc(CurBuffer); | 
 | 88 |     if (ParentIncludeLoc != SMLoc()) { | 
 | 89 |       CurBuffer = SrcMgr.FindBufferContainingLoc(ParentIncludeLoc); | 
 | 90 |       Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer),  | 
 | 91 |                       ParentIncludeLoc.getPointer()); | 
 | 92 |       tok = &Lexer.Lex(); | 
 | 93 |     } | 
 | 94 |   } | 
 | 95 |      | 
 | 96 |   if (tok->is(AsmToken::Error)) | 
| Sean Callanan | bf2013e | 2010-01-20 23:19:55 +0000 | [diff] [blame] | 97 |     PrintMessage(Lexer.getErrLoc(), Lexer.getErr(), "error"); | 
| Sean Callanan | 79036e4 | 2010-01-20 22:18:24 +0000 | [diff] [blame] | 98 |    | 
| Sean Callanan | fd0b028 | 2010-01-21 00:19:58 +0000 | [diff] [blame] | 99 |   return *tok; | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 100 | } | 
 | 101 |  | 
| Chris Lattner | 79180e2 | 2010-04-05 23:15:42 +0000 | [diff] [blame] | 102 | bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) { | 
| Daniel Dunbar | 5e6a7a2 | 2010-03-13 02:20:57 +0000 | [diff] [blame] | 103 |   // Create the initial section, if requested. | 
| Daniel Dunbar | 7c0a334 | 2009-08-26 22:49:51 +0000 | [diff] [blame] | 104 |   // | 
| Daniel Dunbar | 7c0a334 | 2009-08-26 22:49:51 +0000 | [diff] [blame] | 105 |   // FIXME: Target hook & command line option for initial section. | 
| Daniel Dunbar | 5e6a7a2 | 2010-03-13 02:20:57 +0000 | [diff] [blame] | 106 |   if (!NoInitialTextSection) | 
| Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 107 |     Out.SwitchSection(Ctx.getMachOSection("__TEXT", "__text", | 
| Daniel Dunbar | 5e6a7a2 | 2010-03-13 02:20:57 +0000 | [diff] [blame] | 108 |                                       MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, | 
 | 109 |                                       0, SectionKind::getText())); | 
| Daniel Dunbar | 7c0a334 | 2009-08-26 22:49:51 +0000 | [diff] [blame] | 110 |  | 
| Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 111 |   // Prime the lexer. | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 112 |   Lex(); | 
| Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 113 |    | 
| Chris Lattner | b717fb0 | 2009-07-02 21:53:43 +0000 | [diff] [blame] | 114 |   bool HadError = false; | 
| Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 115 |    | 
| Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 116 |   AsmCond StartingCondState = TheCondState; | 
 | 117 |  | 
| Chris Lattner | b717fb0 | 2009-07-02 21:53:43 +0000 | [diff] [blame] | 118 |   // While we have input, parse each statement. | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 119 |   while (Lexer.isNot(AsmToken::Eof)) { | 
| Chris Lattner | b717fb0 | 2009-07-02 21:53:43 +0000 | [diff] [blame] | 120 |     if (!ParseStatement()) continue; | 
 | 121 |    | 
| Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 122 |     // We had an error, remember it and recover by skipping to the next line. | 
| Chris Lattner | b717fb0 | 2009-07-02 21:53:43 +0000 | [diff] [blame] | 123 |     HadError = true; | 
 | 124 |     EatToEndOfStatement(); | 
 | 125 |   } | 
| Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 126 |  | 
 | 127 |   if (TheCondState.TheCond != StartingCondState.TheCond || | 
 | 128 |       TheCondState.Ignore != StartingCondState.Ignore) | 
 | 129 |     return TokError("unmatched .ifs or .elses"); | 
| Chris Lattner | b717fb0 | 2009-07-02 21:53:43 +0000 | [diff] [blame] | 130 |    | 
| Chris Lattner | 79180e2 | 2010-04-05 23:15:42 +0000 | [diff] [blame] | 131 |   // Finalize the output stream if there are no errors and if the client wants | 
 | 132 |   // us to. | 
 | 133 |   if (!HadError && !NoFinalize)   | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 134 |     Out.Finish(); | 
 | 135 |  | 
| Chris Lattner | b717fb0 | 2009-07-02 21:53:43 +0000 | [diff] [blame] | 136 |   return HadError; | 
| Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 137 | } | 
 | 138 |  | 
| Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 139 | /// EatToEndOfStatement - Throw away the rest of the line for testing purposes. | 
 | 140 | void AsmParser::EatToEndOfStatement() { | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 141 |   while (Lexer.isNot(AsmToken::EndOfStatement) && | 
 | 142 |          Lexer.isNot(AsmToken::Eof)) | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 143 |     Lex(); | 
| Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 144 |    | 
 | 145 |   // Eat EOL. | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 146 |   if (Lexer.is(AsmToken::EndOfStatement)) | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 147 |     Lex(); | 
| Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 148 | } | 
 | 149 |  | 
| Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 150 |  | 
| Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 151 | /// ParseParenExpr - Parse a paren expression and return it. | 
 | 152 | /// NOTE: This assumes the leading '(' has already been consumed. | 
 | 153 | /// | 
 | 154 | /// parenexpr ::= expr) | 
 | 155 | /// | 
| Chris Lattner | b4307b3 | 2010-01-15 19:28:38 +0000 | [diff] [blame] | 156 | bool AsmParser::ParseParenExpr(const MCExpr *&Res, SMLoc &EndLoc) { | 
| Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 157 |   if (ParseExpression(Res)) return true; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 158 |   if (Lexer.isNot(AsmToken::RParen)) | 
| Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 159 |     return TokError("expected ')' in parentheses expression"); | 
| Chris Lattner | b4307b3 | 2010-01-15 19:28:38 +0000 | [diff] [blame] | 160 |   EndLoc = Lexer.getLoc(); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 161 |   Lex(); | 
| Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 162 |   return false; | 
 | 163 | } | 
| Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 164 |  | 
| Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame] | 165 | MCSymbol *AsmParser::CreateSymbol(StringRef Name) { | 
| Chris Lattner | 9b97a73 | 2010-03-30 18:10:53 +0000 | [diff] [blame] | 166 |   // FIXME: Inline into callers. | 
| Chris Lattner | 00685bb | 2010-03-10 01:29:27 +0000 | [diff] [blame] | 167 |   return Ctx.GetOrCreateSymbol(Name); | 
| Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame] | 168 | } | 
 | 169 |  | 
| Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 170 | /// ParsePrimaryExpr - Parse a primary expression and return it. | 
 | 171 | ///  primaryexpr ::= (parenexpr | 
 | 172 | ///  primaryexpr ::= symbol | 
 | 173 | ///  primaryexpr ::= number | 
| Chris Lattner | d305035 | 2010-04-14 04:40:28 +0000 | [diff] [blame] | 174 | ///  primaryexpr ::= '.' | 
| Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 175 | ///  primaryexpr ::= ~,+,- primaryexpr | 
| Chris Lattner | b4307b3 | 2010-01-15 19:28:38 +0000 | [diff] [blame] | 176 | bool AsmParser::ParsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) { | 
| Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 177 |   switch (Lexer.getKind()) { | 
 | 178 |   default: | 
 | 179 |     return TokError("unknown token in expression"); | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 180 |   case AsmToken::Exclaim: | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 181 |     Lex(); // Eat the operator. | 
| Chris Lattner | b4307b3 | 2010-01-15 19:28:38 +0000 | [diff] [blame] | 182 |     if (ParsePrimaryExpr(Res, EndLoc)) | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 183 |       return true; | 
| Daniel Dunbar | 6ce004d | 2009-08-31 08:07:44 +0000 | [diff] [blame] | 184 |     Res = MCUnaryExpr::CreateLNot(Res, getContext()); | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 185 |     return false; | 
| Daniel Dunbar | 76c4d76 | 2009-07-31 21:55:09 +0000 | [diff] [blame] | 186 |   case AsmToken::String: | 
| Daniel Dunbar | fffff91 | 2009-10-16 01:34:54 +0000 | [diff] [blame] | 187 |   case AsmToken::Identifier: { | 
 | 188 |     // This is a symbol reference. | 
| Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 189 |     std::pair<StringRef, StringRef> Split = getTok().getIdentifier().split('@'); | 
 | 190 |     MCSymbol *Sym = CreateSymbol(Split.first); | 
 | 191 |  | 
| Daniel Dunbar | 525a3a6 | 2010-05-17 17:46:23 +0000 | [diff] [blame] | 192 |     // Mark the symbol as used in an expression. | 
 | 193 |     Sym->setUsedInExpr(true); | 
 | 194 |  | 
| Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 195 |     // Lookup the symbol variant if used. | 
 | 196 |     MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None; | 
 | 197 |     if (Split.first.size() != getTok().getIdentifier().size()) | 
 | 198 |       Variant = MCSymbolRefExpr::getVariantKindForName(Split.second); | 
 | 199 |  | 
| Chris Lattner | b4307b3 | 2010-01-15 19:28:38 +0000 | [diff] [blame] | 200 |     EndLoc = Lexer.getLoc(); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 201 |     Lex(); // Eat identifier. | 
| Daniel Dunbar | fffff91 | 2009-10-16 01:34:54 +0000 | [diff] [blame] | 202 |  | 
 | 203 |     // If this is an absolute variable reference, substitute it now to preserve | 
 | 204 |     // semantics in the face of reassignment. | 
| Daniel Dunbar | 08a408a | 2010-05-05 17:41:00 +0000 | [diff] [blame] | 205 |     if (Sym->isVariable() && isa<MCConstantExpr>(Sym->getVariableValue())) { | 
| Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 206 |       if (Variant) | 
 | 207 |         return Error(EndLoc, "unexpected modified on variable reference"); | 
 | 208 |  | 
| Daniel Dunbar | 08a408a | 2010-05-05 17:41:00 +0000 | [diff] [blame] | 209 |       Res = Sym->getVariableValue(); | 
| Daniel Dunbar | fffff91 | 2009-10-16 01:34:54 +0000 | [diff] [blame] | 210 |       return false; | 
 | 211 |     } | 
 | 212 |  | 
 | 213 |     // Otherwise create a symbol ref. | 
| Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 214 |     Res = MCSymbolRefExpr::Create(Sym, Variant, getContext()); | 
| Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 215 |     return false; | 
| Daniel Dunbar | fffff91 | 2009-10-16 01:34:54 +0000 | [diff] [blame] | 216 |   } | 
| Kevin Enderby | ebe7fcd | 2010-05-17 23:08:19 +0000 | [diff] [blame] | 217 |   case AsmToken::Integer: { | 
 | 218 |     SMLoc Loc = getTok().getLoc(); | 
 | 219 |     int64_t IntVal = getTok().getIntVal(); | 
 | 220 |     Res = MCConstantExpr::Create(IntVal, getContext()); | 
| Chris Lattner | b4307b3 | 2010-01-15 19:28:38 +0000 | [diff] [blame] | 221 |     EndLoc = Lexer.getLoc(); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 222 |     Lex(); // Eat token. | 
| Kevin Enderby | ebe7fcd | 2010-05-17 23:08:19 +0000 | [diff] [blame] | 223 |     // Look for 'b' or 'f' following an Integer as a directional label | 
 | 224 |     if (Lexer.getKind() == AsmToken::Identifier) { | 
 | 225 |       StringRef IDVal = getTok().getString(); | 
 | 226 |       if (IDVal == "f" || IDVal == "b"){ | 
 | 227 |         MCSymbol *Sym = Ctx.GetDirectionalLocalSymbol(IntVal, | 
 | 228 |                                                       IDVal == "f" ? 1 : 0); | 
 | 229 |         Res = MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None, | 
 | 230 |                                       getContext()); | 
 | 231 |         if(IDVal == "b" && Sym->isUndefined()) | 
 | 232 |           return Error(Loc, "invalid reference to undefined symbol"); | 
 | 233 |         EndLoc = Lexer.getLoc(); | 
 | 234 |         Lex(); // Eat identifier. | 
 | 235 |       } | 
 | 236 |     } | 
| Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 237 |     return false; | 
| Kevin Enderby | ebe7fcd | 2010-05-17 23:08:19 +0000 | [diff] [blame] | 238 |   } | 
| Chris Lattner | d305035 | 2010-04-14 04:40:28 +0000 | [diff] [blame] | 239 |   case AsmToken::Dot: { | 
 | 240 |     // This is a '.' reference, which references the current PC.  Emit a | 
 | 241 |     // temporary label to the streamer and refer to it. | 
 | 242 |     MCSymbol *Sym = Ctx.CreateTempSymbol(); | 
 | 243 |     Out.EmitLabel(Sym); | 
 | 244 |     Res = MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None, getContext()); | 
 | 245 |     EndLoc = Lexer.getLoc(); | 
 | 246 |     Lex(); // Eat identifier. | 
 | 247 |     return false; | 
 | 248 |   } | 
 | 249 |        | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 250 |   case AsmToken::LParen: | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 251 |     Lex(); // Eat the '('. | 
| Chris Lattner | b4307b3 | 2010-01-15 19:28:38 +0000 | [diff] [blame] | 252 |     return ParseParenExpr(Res, EndLoc); | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 253 |   case AsmToken::Minus: | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 254 |     Lex(); // Eat the operator. | 
| Chris Lattner | b4307b3 | 2010-01-15 19:28:38 +0000 | [diff] [blame] | 255 |     if (ParsePrimaryExpr(Res, EndLoc)) | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 256 |       return true; | 
| Daniel Dunbar | 6ce004d | 2009-08-31 08:07:44 +0000 | [diff] [blame] | 257 |     Res = MCUnaryExpr::CreateMinus(Res, getContext()); | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 258 |     return false; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 259 |   case AsmToken::Plus: | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 260 |     Lex(); // Eat the operator. | 
| Chris Lattner | b4307b3 | 2010-01-15 19:28:38 +0000 | [diff] [blame] | 261 |     if (ParsePrimaryExpr(Res, EndLoc)) | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 262 |       return true; | 
| Daniel Dunbar | 6ce004d | 2009-08-31 08:07:44 +0000 | [diff] [blame] | 263 |     Res = MCUnaryExpr::CreatePlus(Res, getContext()); | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 264 |     return false; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 265 |   case AsmToken::Tilde: | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 266 |     Lex(); // Eat the operator. | 
| Chris Lattner | b4307b3 | 2010-01-15 19:28:38 +0000 | [diff] [blame] | 267 |     if (ParsePrimaryExpr(Res, EndLoc)) | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 268 |       return true; | 
| Daniel Dunbar | 6ce004d | 2009-08-31 08:07:44 +0000 | [diff] [blame] | 269 |     Res = MCUnaryExpr::CreateNot(Res, getContext()); | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 270 |     return false; | 
| Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 271 |   } | 
 | 272 | } | 
| Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 273 |  | 
| Chris Lattner | b4307b3 | 2010-01-15 19:28:38 +0000 | [diff] [blame] | 274 | bool AsmParser::ParseExpression(const MCExpr *&Res) { | 
| Chris Lattner | 54482b4 | 2010-01-15 19:39:23 +0000 | [diff] [blame] | 275 |   SMLoc EndLoc; | 
 | 276 |   return ParseExpression(Res, EndLoc); | 
| Chris Lattner | b4307b3 | 2010-01-15 19:28:38 +0000 | [diff] [blame] | 277 | } | 
 | 278 |  | 
| Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 279 | /// ParseExpression - Parse an expression and return it. | 
 | 280 | ///  | 
 | 281 | ///  expr ::= expr +,- expr          -> lowest. | 
 | 282 | ///  expr ::= expr |,^,&,! expr      -> middle. | 
 | 283 | ///  expr ::= expr *,/,%,<<,>> expr  -> highest. | 
 | 284 | ///  expr ::= primaryexpr | 
 | 285 | /// | 
| Chris Lattner | 54482b4 | 2010-01-15 19:39:23 +0000 | [diff] [blame] | 286 | bool AsmParser::ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) { | 
| Daniel Dunbar | e9a60eb | 2010-02-13 01:28:07 +0000 | [diff] [blame] | 287 |   // Parse the expression. | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 288 |   Res = 0; | 
| Daniel Dunbar | e9a60eb | 2010-02-13 01:28:07 +0000 | [diff] [blame] | 289 |   if (ParsePrimaryExpr(Res, EndLoc) || ParseBinOpRHS(1, Res, EndLoc)) | 
 | 290 |     return true; | 
 | 291 |  | 
 | 292 |   // Try to constant fold it up front, if possible. | 
 | 293 |   int64_t Value; | 
 | 294 |   if (Res->EvaluateAsAbsolute(Value)) | 
 | 295 |     Res = MCConstantExpr::Create(Value, getContext()); | 
 | 296 |  | 
 | 297 |   return false; | 
| Chris Lattner | 74ec1a3 | 2009-06-22 06:32:03 +0000 | [diff] [blame] | 298 | } | 
| Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 299 |  | 
| Chris Lattner | b4307b3 | 2010-01-15 19:28:38 +0000 | [diff] [blame] | 300 | bool AsmParser::ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) { | 
| Chris Lattner | 75f265f | 2010-01-24 01:07:33 +0000 | [diff] [blame] | 301 |   Res = 0; | 
 | 302 |   return ParseParenExpr(Res, EndLoc) || | 
 | 303 |          ParseBinOpRHS(1, Res, EndLoc); | 
| Daniel Dunbar | c18274b | 2009-08-31 08:08:17 +0000 | [diff] [blame] | 304 | } | 
 | 305 |  | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 306 | bool AsmParser::ParseAbsoluteExpression(int64_t &Res) { | 
| Daniel Dunbar | 9643ac5 | 2009-08-31 08:07:22 +0000 | [diff] [blame] | 307 |   const MCExpr *Expr; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 308 |    | 
| Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 309 |   SMLoc StartLoc = Lexer.getLoc(); | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 310 |   if (ParseExpression(Expr)) | 
 | 311 |     return true; | 
 | 312 |  | 
| Daniel Dunbar | e00b011 | 2009-10-16 01:57:52 +0000 | [diff] [blame] | 313 |   if (!Expr->EvaluateAsAbsolute(Res)) | 
| Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 314 |     return Error(StartLoc, "expected absolute expression"); | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 315 |  | 
 | 316 |   return false; | 
 | 317 | } | 
 | 318 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 319 | static unsigned getBinOpPrecedence(AsmToken::TokenKind K,  | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 320 |                                    MCBinaryExpr::Opcode &Kind) { | 
| Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 321 |   switch (K) { | 
| Daniel Dunbar | 6ce004d | 2009-08-31 08:07:44 +0000 | [diff] [blame] | 322 |   default: | 
 | 323 |     return 0;    // not a binop. | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 324 |  | 
 | 325 |     // Lowest Precedence: &&, || | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 326 |   case AsmToken::AmpAmp: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 327 |     Kind = MCBinaryExpr::LAnd; | 
| Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 328 |     return 1; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 329 |   case AsmToken::PipePipe: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 330 |     Kind = MCBinaryExpr::LOr; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 331 |     return 1; | 
 | 332 |  | 
 | 333 |     // Low Precedence: +, -, ==, !=, <>, <, <=, >, >= | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 334 |   case AsmToken::Plus: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 335 |     Kind = MCBinaryExpr::Add; | 
| Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 336 |     return 2; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 337 |   case AsmToken::Minus: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 338 |     Kind = MCBinaryExpr::Sub; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 339 |     return 2; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 340 |   case AsmToken::EqualEqual: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 341 |     Kind = MCBinaryExpr::EQ; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 342 |     return 2; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 343 |   case AsmToken::ExclaimEqual: | 
 | 344 |   case AsmToken::LessGreater: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 345 |     Kind = MCBinaryExpr::NE; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 346 |     return 2; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 347 |   case AsmToken::Less: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 348 |     Kind = MCBinaryExpr::LT; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 349 |     return 2; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 350 |   case AsmToken::LessEqual: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 351 |     Kind = MCBinaryExpr::LTE; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 352 |     return 2; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 353 |   case AsmToken::Greater: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 354 |     Kind = MCBinaryExpr::GT; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 355 |     return 2; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 356 |   case AsmToken::GreaterEqual: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 357 |     Kind = MCBinaryExpr::GTE; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 358 |     return 2; | 
 | 359 |  | 
 | 360 |     // Intermediate Precedence: |, &, ^ | 
 | 361 |     // | 
 | 362 |     // FIXME: gas seems to support '!' as an infix operator? | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 363 |   case AsmToken::Pipe: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 364 |     Kind = MCBinaryExpr::Or; | 
| Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 365 |     return 3; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 366 |   case AsmToken::Caret: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 367 |     Kind = MCBinaryExpr::Xor; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 368 |     return 3; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 369 |   case AsmToken::Amp: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 370 |     Kind = MCBinaryExpr::And; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 371 |     return 3; | 
 | 372 |  | 
 | 373 |     // Highest Precedence: *, /, %, <<, >> | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 374 |   case AsmToken::Star: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 375 |     Kind = MCBinaryExpr::Mul; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 376 |     return 4; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 377 |   case AsmToken::Slash: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 378 |     Kind = MCBinaryExpr::Div; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 379 |     return 4; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 380 |   case AsmToken::Percent: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 381 |     Kind = MCBinaryExpr::Mod; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 382 |     return 4; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 383 |   case AsmToken::LessLess: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 384 |     Kind = MCBinaryExpr::Shl; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 385 |     return 4; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 386 |   case AsmToken::GreaterGreater: | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 387 |     Kind = MCBinaryExpr::Shr; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 388 |     return 4; | 
| Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 389 |   } | 
 | 390 | } | 
 | 391 |  | 
 | 392 |  | 
 | 393 | /// ParseBinOpRHS - Parse all binary operators with precedence >= 'Precedence'. | 
 | 394 | /// Res contains the LHS of the expression on input. | 
| Chris Lattner | b4307b3 | 2010-01-15 19:28:38 +0000 | [diff] [blame] | 395 | bool AsmParser::ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res, | 
 | 396 |                               SMLoc &EndLoc) { | 
| Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 397 |   while (1) { | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 398 |     MCBinaryExpr::Opcode Kind = MCBinaryExpr::Add; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 399 |     unsigned TokPrec = getBinOpPrecedence(Lexer.getKind(), Kind); | 
| Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 400 |      | 
 | 401 |     // If the next token is lower precedence than we are allowed to eat, return | 
 | 402 |     // successfully with what we ate already. | 
 | 403 |     if (TokPrec < Precedence) | 
 | 404 |       return false; | 
 | 405 |      | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 406 |     Lex(); | 
| Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 407 |      | 
 | 408 |     // Eat the next primary expression. | 
| Daniel Dunbar | 9643ac5 | 2009-08-31 08:07:22 +0000 | [diff] [blame] | 409 |     const MCExpr *RHS; | 
| Chris Lattner | b4307b3 | 2010-01-15 19:28:38 +0000 | [diff] [blame] | 410 |     if (ParsePrimaryExpr(RHS, EndLoc)) return true; | 
| Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 411 |      | 
 | 412 |     // If BinOp binds less tightly with RHS than the operator after RHS, let | 
 | 413 |     // the pending operator take RHS as its LHS. | 
| Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 414 |     MCBinaryExpr::Opcode Dummy; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 415 |     unsigned NextTokPrec = getBinOpPrecedence(Lexer.getKind(), Dummy); | 
| Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 416 |     if (TokPrec < NextTokPrec) { | 
| Chris Lattner | b4307b3 | 2010-01-15 19:28:38 +0000 | [diff] [blame] | 417 |       if (ParseBinOpRHS(Precedence+1, RHS, EndLoc)) return true; | 
| Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 418 |     } | 
 | 419 |  | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 420 |     // Merge LHS and RHS according to operator. | 
| Daniel Dunbar | 6ce004d | 2009-08-31 08:07:44 +0000 | [diff] [blame] | 421 |     Res = MCBinaryExpr::Create(Kind, Res, RHS, getContext()); | 
| Chris Lattner | 8dfbe6c | 2009-06-23 05:57:07 +0000 | [diff] [blame] | 422 |   } | 
 | 423 | } | 
 | 424 |  | 
| Chris Lattner | c419383 | 2009-06-22 05:51:26 +0000 | [diff] [blame] | 425 |    | 
 | 426 |    | 
 | 427 |    | 
| Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 428 | /// ParseStatement: | 
 | 429 | ///   ::= EndOfStatement | 
| Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 430 | ///   ::= Label* Directive ...Operands... EndOfStatement | 
 | 431 | ///   ::= Label* Identifier OperandList* EndOfStatement | 
| Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 432 | bool AsmParser::ParseStatement() { | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 433 |   if (Lexer.is(AsmToken::EndOfStatement)) { | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 434 |     Lex(); | 
| Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 435 |     return false; | 
| Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 436 |   } | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 437 |  | 
 | 438 |   // Statements always start with an identifier. | 
| Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 439 |   AsmToken ID = getTok(); | 
| Daniel Dunbar | 419aded | 2009-07-28 16:38:40 +0000 | [diff] [blame] | 440 |   SMLoc IDLoc = ID.getLoc(); | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 441 |   StringRef IDVal; | 
| Kevin Enderby | ebe7fcd | 2010-05-17 23:08:19 +0000 | [diff] [blame] | 442 |   int64_t LocalLabelVal = -1; | 
 | 443 |   // GUESS allow an integer followed by a ':' as a directional local label | 
 | 444 |   if (Lexer.is(AsmToken::Integer)) { | 
 | 445 |     LocalLabelVal = getTok().getIntVal(); | 
 | 446 |     if (LocalLabelVal < 0) { | 
 | 447 |       if (!TheCondState.Ignore) | 
 | 448 |         return TokError("unexpected token at start of statement"); | 
 | 449 |       IDVal = ""; | 
 | 450 |     } | 
 | 451 |     else { | 
 | 452 |       IDVal = getTok().getString(); | 
 | 453 |       Lex(); // Consume the integer token to be used as an identifier token. | 
 | 454 |       if (Lexer.getKind() != AsmToken::Colon) { | 
 | 455 | 	  if (!TheCondState.Ignore) | 
 | 456 | 	    return TokError("unexpected token at start of statement"); | 
 | 457 |       } | 
 | 458 |     } | 
 | 459 |   } | 
 | 460 |   else if (ParseIdentifier(IDVal)) { | 
| Chris Lattner | 7834fac | 2010-04-17 18:14:27 +0000 | [diff] [blame] | 461 |     if (!TheCondState.Ignore) | 
 | 462 |       return TokError("unexpected token at start of statement"); | 
 | 463 |     IDVal = ""; | 
 | 464 |   } | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 465 |  | 
| Chris Lattner | 7834fac | 2010-04-17 18:14:27 +0000 | [diff] [blame] | 466 |   // Handle conditional assembly here before checking for skipping.  We | 
 | 467 |   // have to do this so that .endif isn't skipped in a ".if 0" block for | 
 | 468 |   // example. | 
 | 469 |   if (IDVal == ".if") | 
 | 470 |     return ParseDirectiveIf(IDLoc); | 
 | 471 |   if (IDVal == ".elseif") | 
 | 472 |     return ParseDirectiveElseIf(IDLoc); | 
 | 473 |   if (IDVal == ".else") | 
 | 474 |     return ParseDirectiveElse(IDLoc); | 
 | 475 |   if (IDVal == ".endif") | 
 | 476 |     return ParseDirectiveEndIf(IDLoc); | 
 | 477 |      | 
 | 478 |   // If we are in a ".if 0" block, ignore this statement. | 
 | 479 |   if (TheCondState.Ignore) { | 
 | 480 |     EatToEndOfStatement(); | 
 | 481 |     return false; | 
 | 482 |   } | 
 | 483 |    | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 484 |   // FIXME: Recurse on local labels? | 
 | 485 |  | 
 | 486 |   // See what kind of statement we have. | 
 | 487 |   switch (Lexer.getKind()) { | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 488 |   case AsmToken::Colon: { | 
| Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 489 |     // identifier ':'   -> Label. | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 490 |     Lex(); | 
| Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 491 |  | 
 | 492 |     // Diagnose attempt to use a variable as a label. | 
 | 493 |     // | 
 | 494 |     // FIXME: Diagnostics. Note the location of the definition as a label. | 
 | 495 |     // FIXME: This doesn't diagnose assignment to a symbol which has been | 
 | 496 |     // implicitly marked as external. | 
| Kevin Enderby | ebe7fcd | 2010-05-17 23:08:19 +0000 | [diff] [blame] | 497 |     MCSymbol *Sym; | 
 | 498 |     if (LocalLabelVal == -1) | 
 | 499 |       Sym = CreateSymbol(IDVal); | 
 | 500 |     else | 
 | 501 |       Sym = Ctx.CreateDirectionalLocalSymbol(LocalLabelVal); | 
| Daniel Dunbar | c304718 | 2010-05-05 19:01:00 +0000 | [diff] [blame] | 502 |     if (!Sym->isUndefined() || Sym->isVariable()) | 
| Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 503 |       return Error(IDLoc, "invalid symbol redefinition"); | 
| Chris Lattner | c69485e | 2009-06-24 04:31:49 +0000 | [diff] [blame] | 504 |      | 
| Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame] | 505 |     // Emit the label. | 
| Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 506 |     Out.EmitLabel(Sym); | 
 | 507 |     | 
| Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 508 |     return ParseStatement(); | 
| Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 509 |   } | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 510 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 511 |   case AsmToken::Equal: | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 512 |     // identifier '=' ... -> assignment statement | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 513 |     Lex(); | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 514 |  | 
| Daniel Dunbar | e2ace50 | 2009-08-31 08:09:09 +0000 | [diff] [blame] | 515 |     return ParseAssignment(IDVal); | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 516 |  | 
 | 517 |   default: // Normal instruction or directive. | 
 | 518 |     break; | 
| Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 519 |   } | 
 | 520 |    | 
 | 521 |   // Otherwise, we have a normal instruction or directive.   | 
| Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 522 |   if (IDVal[0] == '.') { | 
| Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 523 |     // FIXME: This should be driven based on a hash lookup and callback. | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 524 |     if (IDVal == ".section") | 
| Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 525 |       return ParseDirectiveDarwinSection(); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 526 |     if (IDVal == ".text") | 
| Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 527 |       // FIXME: This changes behavior based on the -static flag to the | 
 | 528 |       // assembler. | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 529 |       return ParseDirectiveSectionSwitch("__TEXT", "__text", | 
 | 530 |                                      MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 531 |     if (IDVal == ".const") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 532 |       return ParseDirectiveSectionSwitch("__TEXT", "__const"); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 533 |     if (IDVal == ".static_const") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 534 |       return ParseDirectiveSectionSwitch("__TEXT", "__static_const"); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 535 |     if (IDVal == ".cstring") | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 536 |       return ParseDirectiveSectionSwitch("__TEXT","__cstring",  | 
 | 537 |                                          MCSectionMachO::S_CSTRING_LITERALS); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 538 |     if (IDVal == ".literal4") | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 539 |       return ParseDirectiveSectionSwitch("__TEXT", "__literal4", | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 540 |                                          MCSectionMachO::S_4BYTE_LITERALS, | 
 | 541 |                                          4); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 542 |     if (IDVal == ".literal8") | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 543 |       return ParseDirectiveSectionSwitch("__TEXT", "__literal8", | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 544 |                                          MCSectionMachO::S_8BYTE_LITERALS, | 
 | 545 |                                          8); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 546 |     if (IDVal == ".literal16") | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 547 |       return ParseDirectiveSectionSwitch("__TEXT","__literal16", | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 548 |                                          MCSectionMachO::S_16BYTE_LITERALS, | 
 | 549 |                                          16); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 550 |     if (IDVal == ".constructor") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 551 |       return ParseDirectiveSectionSwitch("__TEXT","__constructor"); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 552 |     if (IDVal == ".destructor") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 553 |       return ParseDirectiveSectionSwitch("__TEXT","__destructor"); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 554 |     if (IDVal == ".fvmlib_init0") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 555 |       return ParseDirectiveSectionSwitch("__TEXT","__fvmlib_init0"); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 556 |     if (IDVal == ".fvmlib_init1") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 557 |       return ParseDirectiveSectionSwitch("__TEXT","__fvmlib_init1"); | 
 | 558 |  | 
 | 559 |     // FIXME: The assembler manual claims that this has the self modify code | 
 | 560 |     // flag, at least on x86-32, but that does not appear to be correct. | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 561 |     if (IDVal == ".symbol_stub") | 
 | 562 |       return ParseDirectiveSectionSwitch("__TEXT","__symbol_stub", | 
 | 563 |                                          MCSectionMachO::S_SYMBOL_STUBS | | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 564 |                                        MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, | 
 | 565 |                                           // FIXME: Different on PPC and ARM. | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 566 |                                          0, 16); | 
 | 567 |     // FIXME: PowerPC only? | 
 | 568 |     if (IDVal == ".picsymbol_stub") | 
 | 569 |       return ParseDirectiveSectionSwitch("__TEXT","__picsymbol_stub", | 
 | 570 |                                          MCSectionMachO::S_SYMBOL_STUBS | | 
 | 571 |                                        MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, | 
 | 572 |                                          0, 26); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 573 |     if (IDVal == ".data") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 574 |       return ParseDirectiveSectionSwitch("__DATA", "__data"); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 575 |     if (IDVal == ".static_data") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 576 |       return ParseDirectiveSectionSwitch("__DATA", "__static_data"); | 
 | 577 |  | 
 | 578 |     // FIXME: The section names of these two are misspelled in the assembler | 
 | 579 |     // manual. | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 580 |     if (IDVal == ".non_lazy_symbol_pointer") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 581 |       return ParseDirectiveSectionSwitch("__DATA", "__nl_symbol_ptr", | 
 | 582 |                                      MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS, | 
 | 583 |                                          4); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 584 |     if (IDVal == ".lazy_symbol_pointer") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 585 |       return ParseDirectiveSectionSwitch("__DATA", "__la_symbol_ptr", | 
 | 586 |                                          MCSectionMachO::S_LAZY_SYMBOL_POINTERS, | 
 | 587 |                                          4); | 
 | 588 |  | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 589 |     if (IDVal == ".dyld") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 590 |       return ParseDirectiveSectionSwitch("__DATA", "__dyld"); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 591 |     if (IDVal == ".mod_init_func") | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 592 |       return ParseDirectiveSectionSwitch("__DATA", "__mod_init_func", | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 593 |                                        MCSectionMachO::S_MOD_INIT_FUNC_POINTERS, | 
 | 594 |                                          4); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 595 |     if (IDVal == ".mod_term_func") | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 596 |       return ParseDirectiveSectionSwitch("__DATA", "__mod_term_func", | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 597 |                                        MCSectionMachO::S_MOD_TERM_FUNC_POINTERS, | 
 | 598 |                                          4); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 599 |     if (IDVal == ".const_data") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 600 |       return ParseDirectiveSectionSwitch("__DATA", "__const"); | 
| Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 601 |      | 
 | 602 |      | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 603 |     if (IDVal == ".objc_class") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 604 |       return ParseDirectiveSectionSwitch("__OBJC", "__class",  | 
 | 605 |                                          MCSectionMachO::S_ATTR_NO_DEAD_STRIP); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 606 |     if (IDVal == ".objc_meta_class") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 607 |       return ParseDirectiveSectionSwitch("__OBJC", "__meta_class", | 
 | 608 |                                          MCSectionMachO::S_ATTR_NO_DEAD_STRIP); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 609 |     if (IDVal == ".objc_cat_cls_meth") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 610 |       return ParseDirectiveSectionSwitch("__OBJC", "__cat_cls_meth", | 
 | 611 |                                          MCSectionMachO::S_ATTR_NO_DEAD_STRIP); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 612 |     if (IDVal == ".objc_cat_inst_meth") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 613 |       return ParseDirectiveSectionSwitch("__OBJC", "__cat_inst_meth", | 
 | 614 |                                          MCSectionMachO::S_ATTR_NO_DEAD_STRIP); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 615 |     if (IDVal == ".objc_protocol") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 616 |       return ParseDirectiveSectionSwitch("__OBJC", "__protocol", | 
 | 617 |                                          MCSectionMachO::S_ATTR_NO_DEAD_STRIP); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 618 |     if (IDVal == ".objc_string_object") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 619 |       return ParseDirectiveSectionSwitch("__OBJC", "__string_object", | 
 | 620 |                                          MCSectionMachO::S_ATTR_NO_DEAD_STRIP); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 621 |     if (IDVal == ".objc_cls_meth") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 622 |       return ParseDirectiveSectionSwitch("__OBJC", "__cls_meth", | 
 | 623 |                                          MCSectionMachO::S_ATTR_NO_DEAD_STRIP); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 624 |     if (IDVal == ".objc_inst_meth") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 625 |       return ParseDirectiveSectionSwitch("__OBJC", "__inst_meth", | 
 | 626 |                                          MCSectionMachO::S_ATTR_NO_DEAD_STRIP); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 627 |     if (IDVal == ".objc_cls_refs") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 628 |       return ParseDirectiveSectionSwitch("__OBJC", "__cls_refs", | 
 | 629 |                                          MCSectionMachO::S_ATTR_NO_DEAD_STRIP | | 
 | 630 |                                          MCSectionMachO::S_LITERAL_POINTERS, | 
 | 631 |                                          4); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 632 |     if (IDVal == ".objc_message_refs") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 633 |       return ParseDirectiveSectionSwitch("__OBJC", "__message_refs", | 
 | 634 |                                          MCSectionMachO::S_ATTR_NO_DEAD_STRIP | | 
 | 635 |                                          MCSectionMachO::S_LITERAL_POINTERS, | 
 | 636 |                                          4); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 637 |     if (IDVal == ".objc_symbols") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 638 |       return ParseDirectiveSectionSwitch("__OBJC", "__symbols", | 
 | 639 |                                          MCSectionMachO::S_ATTR_NO_DEAD_STRIP); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 640 |     if (IDVal == ".objc_category") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 641 |       return ParseDirectiveSectionSwitch("__OBJC", "__category", | 
 | 642 |                                          MCSectionMachO::S_ATTR_NO_DEAD_STRIP); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 643 |     if (IDVal == ".objc_class_vars") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 644 |       return ParseDirectiveSectionSwitch("__OBJC", "__class_vars", | 
 | 645 |                                          MCSectionMachO::S_ATTR_NO_DEAD_STRIP); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 646 |     if (IDVal == ".objc_instance_vars") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 647 |       return ParseDirectiveSectionSwitch("__OBJC", "__instance_vars", | 
 | 648 |                                          MCSectionMachO::S_ATTR_NO_DEAD_STRIP); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 649 |     if (IDVal == ".objc_module_info") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 650 |       return ParseDirectiveSectionSwitch("__OBJC", "__module_info", | 
 | 651 |                                          MCSectionMachO::S_ATTR_NO_DEAD_STRIP); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 652 |     if (IDVal == ".objc_class_names") | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 653 |       return ParseDirectiveSectionSwitch("__TEXT", "__cstring", | 
 | 654 |                                          MCSectionMachO::S_CSTRING_LITERALS); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 655 |     if (IDVal == ".objc_meth_var_types") | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 656 |       return ParseDirectiveSectionSwitch("__TEXT", "__cstring", | 
 | 657 |                                          MCSectionMachO::S_CSTRING_LITERALS); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 658 |     if (IDVal == ".objc_meth_var_names") | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 659 |       return ParseDirectiveSectionSwitch("__TEXT", "__cstring", | 
 | 660 |                                          MCSectionMachO::S_CSTRING_LITERALS); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 661 |     if (IDVal == ".objc_selector_strs") | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 662 |       return ParseDirectiveSectionSwitch("__OBJC", "__selector_strs", | 
 | 663 |                                          MCSectionMachO::S_CSTRING_LITERALS); | 
| Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 664 |      | 
| Eric Christopher | c6177a4 | 2010-05-17 22:53:55 +0000 | [diff] [blame] | 665 |     if (IDVal == ".tdata") | 
 | 666 |       return ParseDirectiveSectionSwitch("__DATA", "__thread_data", | 
 | 667 |                                         MCSectionMachO::S_THREAD_LOCAL_REGULAR); | 
 | 668 |     if (IDVal == ".tlv") | 
 | 669 |       return ParseDirectiveSectionSwitch("__DATA", "__thread_vars", | 
 | 670 |                                       MCSectionMachO::S_THREAD_LOCAL_VARIABLES); | 
 | 671 |     if (IDVal == ".thread_init_func") | 
 | 672 |       return ParseDirectiveSectionSwitch("__DATA", "__thread_init", | 
 | 673 |                         MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS); | 
 | 674 |      | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 675 |     // Assembler features | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 676 |     if (IDVal == ".set") | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 677 |       return ParseDirectiveSet(); | 
 | 678 |  | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 679 |     // Data directives | 
 | 680 |  | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 681 |     if (IDVal == ".ascii") | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 682 |       return ParseDirectiveAscii(false); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 683 |     if (IDVal == ".asciz") | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 684 |       return ParseDirectiveAscii(true); | 
 | 685 |  | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 686 |     if (IDVal == ".byte") | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 687 |       return ParseDirectiveValue(1); | 
| Kevin Enderby | 9c65645 | 2009-09-10 20:51:44 +0000 | [diff] [blame] | 688 |     if (IDVal == ".short") | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 689 |       return ParseDirectiveValue(2); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 690 |     if (IDVal == ".long") | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 691 |       return ParseDirectiveValue(4); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 692 |     if (IDVal == ".quad") | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 693 |       return ParseDirectiveValue(8); | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 694 |  | 
 | 695 |     // FIXME: Target hooks for IsPow2. | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 696 |     if (IDVal == ".align") | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 697 |       return ParseDirectiveAlign(/*IsPow2=*/true, /*ExprSize=*/1); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 698 |     if (IDVal == ".align32") | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 699 |       return ParseDirectiveAlign(/*IsPow2=*/true, /*ExprSize=*/4); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 700 |     if (IDVal == ".balign") | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 701 |       return ParseDirectiveAlign(/*IsPow2=*/false, /*ExprSize=*/1); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 702 |     if (IDVal == ".balignw") | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 703 |       return ParseDirectiveAlign(/*IsPow2=*/false, /*ExprSize=*/2); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 704 |     if (IDVal == ".balignl") | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 705 |       return ParseDirectiveAlign(/*IsPow2=*/false, /*ExprSize=*/4); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 706 |     if (IDVal == ".p2align") | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 707 |       return ParseDirectiveAlign(/*IsPow2=*/true, /*ExprSize=*/1); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 708 |     if (IDVal == ".p2alignw") | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 709 |       return ParseDirectiveAlign(/*IsPow2=*/true, /*ExprSize=*/2); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 710 |     if (IDVal == ".p2alignl") | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 711 |       return ParseDirectiveAlign(/*IsPow2=*/true, /*ExprSize=*/4); | 
 | 712 |  | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 713 |     if (IDVal == ".org") | 
| Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 714 |       return ParseDirectiveOrg(); | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 715 |  | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 716 |     if (IDVal == ".fill") | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 717 |       return ParseDirectiveFill(); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 718 |     if (IDVal == ".space") | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 719 |       return ParseDirectiveSpace(); | 
 | 720 |  | 
| Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 721 |     // Symbol attribute directives | 
| Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 722 |  | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 723 |     if (IDVal == ".globl" || IDVal == ".global") | 
| Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 724 |       return ParseDirectiveSymbolAttribute(MCSA_Global); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 725 |     if (IDVal == ".hidden") | 
| Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 726 |       return ParseDirectiveSymbolAttribute(MCSA_Hidden); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 727 |     if (IDVal == ".indirect_symbol") | 
| Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 728 |       return ParseDirectiveSymbolAttribute(MCSA_IndirectSymbol); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 729 |     if (IDVal == ".internal") | 
| Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 730 |       return ParseDirectiveSymbolAttribute(MCSA_Internal); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 731 |     if (IDVal == ".lazy_reference") | 
| Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 732 |       return ParseDirectiveSymbolAttribute(MCSA_LazyReference); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 733 |     if (IDVal == ".no_dead_strip") | 
| Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 734 |       return ParseDirectiveSymbolAttribute(MCSA_NoDeadStrip); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 735 |     if (IDVal == ".private_extern") | 
| Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 736 |       return ParseDirectiveSymbolAttribute(MCSA_PrivateExtern); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 737 |     if (IDVal == ".protected") | 
| Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 738 |       return ParseDirectiveSymbolAttribute(MCSA_Protected); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 739 |     if (IDVal == ".reference") | 
| Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 740 |       return ParseDirectiveSymbolAttribute(MCSA_Reference); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 741 |     if (IDVal == ".weak") | 
| Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 742 |       return ParseDirectiveSymbolAttribute(MCSA_Weak); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 743 |     if (IDVal == ".weak_definition") | 
| Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 744 |       return ParseDirectiveSymbolAttribute(MCSA_WeakDefinition); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 745 |     if (IDVal == ".weak_reference") | 
| Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 746 |       return ParseDirectiveSymbolAttribute(MCSA_WeakReference); | 
| Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 747 |  | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 748 |     if (IDVal == ".comm") | 
| Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 749 |       return ParseDirectiveComm(/*IsLocal=*/false); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 750 |     if (IDVal == ".lcomm") | 
| Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 751 |       return ParseDirectiveComm(/*IsLocal=*/true); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 752 |     if (IDVal == ".zerofill") | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 753 |       return ParseDirectiveDarwinZerofill(); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 754 |     if (IDVal == ".desc") | 
| Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 755 |       return ParseDirectiveDarwinSymbolDesc(); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 756 |     if (IDVal == ".lsym") | 
| Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 757 |       return ParseDirectiveDarwinLsym(); | 
| Eric Christopher | 482eba0 | 2010-05-14 01:50:28 +0000 | [diff] [blame] | 758 |     if (IDVal == ".tbss") | 
 | 759 |       return ParseDirectiveDarwinTBSS(); | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 760 |  | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 761 |     if (IDVal == ".subsections_via_symbols") | 
| Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 762 |       return ParseDirectiveDarwinSubsectionsViaSymbols(); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 763 |     if (IDVal == ".abort") | 
| Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 764 |       return ParseDirectiveAbort(); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 765 |     if (IDVal == ".include") | 
| Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 766 |       return ParseDirectiveInclude(); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 767 |     if (IDVal == ".dump") | 
| Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 768 |       return ParseDirectiveDarwinDumpOrLoad(IDLoc, /*IsDump=*/true); | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 769 |     if (IDVal == ".load") | 
| Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 770 |       return ParseDirectiveDarwinDumpOrLoad(IDLoc, /*IsLoad=*/false); | 
| Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 771 |  | 
| Chris Lattner | ebb89b4 | 2009-09-27 21:16:52 +0000 | [diff] [blame] | 772 |     // Look up the handler in the handler table,  | 
 | 773 |     bool(AsmParser::*Handler)(StringRef, SMLoc) = DirectiveMap[IDVal]; | 
 | 774 |     if (Handler) | 
 | 775 |       return (this->*Handler)(IDVal, IDLoc); | 
 | 776 |      | 
| Kevin Enderby | 9c65645 | 2009-09-10 20:51:44 +0000 | [diff] [blame] | 777 |     // Target hook for parsing target specific directives. | 
 | 778 |     if (!getTargetParser().ParseDirective(ID)) | 
 | 779 |       return false; | 
 | 780 |  | 
| Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 781 |     Warning(IDLoc, "ignoring directive for now"); | 
| Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 782 |     EatToEndOfStatement(); | 
 | 783 |     return false; | 
 | 784 |   } | 
| Chris Lattner | b0789ed | 2009-06-21 20:54:55 +0000 | [diff] [blame] | 785 |  | 
| Chris Lattner | 9898671 | 2010-01-14 22:21:20 +0000 | [diff] [blame] | 786 |   SmallVector<MCParsedAsmOperand*, 8> ParsedOperands; | 
| Daniel Dunbar | 31e8e1d | 2010-05-04 00:33:07 +0000 | [diff] [blame] | 787 |   bool HadError = getTargetParser().ParseInstruction(IDVal, IDLoc, | 
 | 788 |                                                      ParsedOperands); | 
 | 789 |   if (!HadError && Lexer.isNot(AsmToken::EndOfStatement)) | 
 | 790 |     HadError = TokError("unexpected token in argument list"); | 
| Chris Lattner | 2cf5f14 | 2009-06-22 01:29:09 +0000 | [diff] [blame] | 791 |  | 
| Daniel Dunbar | 31e8e1d | 2010-05-04 00:33:07 +0000 | [diff] [blame] | 792 |   // If parsing succeeded, match the instruction. | 
 | 793 |   if (!HadError) { | 
 | 794 |     MCInst Inst; | 
 | 795 |     if (!getTargetParser().MatchInstruction(ParsedOperands, Inst)) { | 
 | 796 |       // Emit the instruction on success. | 
 | 797 |       Out.EmitInstruction(Inst); | 
 | 798 |     } else { | 
 | 799 |       // Otherwise emit a diagnostic about the match failure and set the error | 
 | 800 |       // flag. | 
 | 801 |       // | 
 | 802 |       // FIXME: We should give nicer diagnostics about the exact failure. | 
 | 803 |       Error(IDLoc, "unrecognized instruction"); | 
 | 804 |       HadError = true; | 
 | 805 |     } | 
 | 806 |   } | 
| Chris Lattner | 9898671 | 2010-01-14 22:21:20 +0000 | [diff] [blame] | 807 |  | 
| Daniel Dunbar | 31e8e1d | 2010-05-04 00:33:07 +0000 | [diff] [blame] | 808 |   // If there was no error, consume the end-of-statement token. Otherwise this | 
 | 809 |   // will be done by our caller. | 
 | 810 |   if (!HadError) | 
 | 811 |     Lex(); | 
| Chris Lattner | 9898671 | 2010-01-14 22:21:20 +0000 | [diff] [blame] | 812 |  | 
 | 813 |   // Free any parsed operands. | 
 | 814 |   for (unsigned i = 0, e = ParsedOperands.size(); i != e; ++i) | 
 | 815 |     delete ParsedOperands[i]; | 
 | 816 |  | 
| Daniel Dunbar | 31e8e1d | 2010-05-04 00:33:07 +0000 | [diff] [blame] | 817 |   return HadError; | 
| Chris Lattner | 27aa7d2 | 2009-06-21 20:16:42 +0000 | [diff] [blame] | 818 | } | 
| Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 819 |  | 
| Daniel Dunbar | e2ace50 | 2009-08-31 08:09:09 +0000 | [diff] [blame] | 820 | bool AsmParser::ParseAssignment(const StringRef &Name) { | 
| Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 821 |   // FIXME: Use better location, we should use proper tokens. | 
 | 822 |   SMLoc EqualLoc = Lexer.getLoc(); | 
 | 823 |  | 
| Daniel Dunbar | 821e333 | 2009-08-31 08:09:28 +0000 | [diff] [blame] | 824 |   const MCExpr *Value; | 
| Daniel Dunbar | 883f920 | 2009-08-31 08:08:50 +0000 | [diff] [blame] | 825 |   SMLoc StartLoc = Lexer.getLoc(); | 
| Daniel Dunbar | 821e333 | 2009-08-31 08:09:28 +0000 | [diff] [blame] | 826 |   if (ParseExpression(Value)) | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 827 |     return true; | 
 | 828 |    | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 829 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 830 |     return TokError("unexpected token in assignment"); | 
 | 831 |  | 
 | 832 |   // Eat the end of statement marker. | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 833 |   Lex(); | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 834 |  | 
| Daniel Dunbar | 75773ff | 2009-10-16 01:57:39 +0000 | [diff] [blame] | 835 |   // Validate that the LHS is allowed to be a variable (either it has not been | 
 | 836 |   // used as a symbol, or it is an absolute symbol). | 
 | 837 |   MCSymbol *Sym = getContext().LookupSymbol(Name); | 
 | 838 |   if (Sym) { | 
 | 839 |     // Diagnose assignment to a label. | 
 | 840 |     // | 
 | 841 |     // FIXME: Diagnostics. Note the location of the definition as a label. | 
 | 842 |     // FIXME: Diagnose assignment to protected identifier (e.g., register name). | 
| Daniel Dunbar | 525a3a6 | 2010-05-17 17:46:23 +0000 | [diff] [blame] | 843 |     if (Sym->isUndefined() && !Sym->isUsedInExpr()) | 
 | 844 |       ; // Allow redefinitions of undefined symbols only used in directives. | 
 | 845 |     else if (!Sym->isUndefined() && !Sym->isAbsolute()) | 
| Daniel Dunbar | 75773ff | 2009-10-16 01:57:39 +0000 | [diff] [blame] | 846 |       return Error(EqualLoc, "redefinition of '" + Name + "'"); | 
 | 847 |     else if (!Sym->isVariable()) | 
 | 848 |       return Error(EqualLoc, "invalid assignment to '" + Name + "'"); | 
| Daniel Dunbar | 08a408a | 2010-05-05 17:41:00 +0000 | [diff] [blame] | 849 |     else if (!isa<MCConstantExpr>(Sym->getVariableValue())) | 
| Daniel Dunbar | 75773ff | 2009-10-16 01:57:39 +0000 | [diff] [blame] | 850 |       return Error(EqualLoc, "invalid reassignment of non-absolute variable '" + | 
 | 851 |                    Name + "'"); | 
 | 852 |   } else | 
 | 853 |     Sym = CreateSymbol(Name); | 
 | 854 |  | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 855 |   // FIXME: Handle '.'. | 
| Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 856 |  | 
| Daniel Dunbar | 525a3a6 | 2010-05-17 17:46:23 +0000 | [diff] [blame] | 857 |   Sym->setUsedInExpr(true); | 
 | 858 |  | 
| Daniel Dunbar | dce0f3c | 2009-06-29 23:43:14 +0000 | [diff] [blame] | 859 |   // Do the assignment. | 
| Daniel Dunbar | e2ace50 | 2009-08-31 08:09:09 +0000 | [diff] [blame] | 860 |   Out.EmitAssignment(Sym, Value); | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 861 |  | 
 | 862 |   return false; | 
 | 863 | } | 
 | 864 |  | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 865 | /// ParseIdentifier: | 
 | 866 | ///   ::= identifier | 
 | 867 | ///   ::= string | 
 | 868 | bool AsmParser::ParseIdentifier(StringRef &Res) { | 
 | 869 |   if (Lexer.isNot(AsmToken::Identifier) && | 
 | 870 |       Lexer.isNot(AsmToken::String)) | 
 | 871 |     return true; | 
 | 872 |  | 
| Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 873 |   Res = getTok().getIdentifier(); | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 874 |  | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 875 |   Lex(); // Consume the identifier token. | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 876 |  | 
 | 877 |   return false; | 
 | 878 | } | 
 | 879 |  | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 880 | /// ParseDirectiveSet: | 
 | 881 | ///   ::= .set identifier ',' expression | 
 | 882 | bool AsmParser::ParseDirectiveSet() { | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 883 |   StringRef Name; | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 884 |  | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 885 |   if (ParseIdentifier(Name)) | 
 | 886 |     return TokError("expected identifier after '.set' directive"); | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 887 |    | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 888 |   if (Lexer.isNot(AsmToken::Comma)) | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 889 |     return TokError("unexpected token in '.set'"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 890 |   Lex(); | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 891 |  | 
| Daniel Dunbar | e2ace50 | 2009-08-31 08:09:09 +0000 | [diff] [blame] | 892 |   return ParseAssignment(Name); | 
| Daniel Dunbar | 8f780cd | 2009-06-25 21:56:11 +0000 | [diff] [blame] | 893 | } | 
 | 894 |  | 
| Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 895 | /// ParseDirectiveSection: | 
| Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 896 | ///   ::= .section identifier (',' identifier)* | 
 | 897 | /// FIXME: This should actually parse out the segment, section, attributes and | 
 | 898 | /// sizeof_stub fields. | 
 | 899 | bool AsmParser::ParseDirectiveDarwinSection() { | 
| Daniel Dunbar | ace6312 | 2009-08-11 03:42:33 +0000 | [diff] [blame] | 900 |   SMLoc Loc = Lexer.getLoc(); | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 901 |  | 
| Daniel Dunbar | ace6312 | 2009-08-11 03:42:33 +0000 | [diff] [blame] | 902 |   StringRef SectionName; | 
 | 903 |   if (ParseIdentifier(SectionName)) | 
 | 904 |     return Error(Loc, "expected identifier after '.section' directive"); | 
 | 905 |  | 
 | 906 |   // Verify there is a following comma. | 
 | 907 |   if (!Lexer.is(AsmToken::Comma)) | 
 | 908 |     return TokError("unexpected token in '.section' directive"); | 
 | 909 |  | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 910 |   std::string SectionSpec = SectionName; | 
| Daniel Dunbar | ace6312 | 2009-08-11 03:42:33 +0000 | [diff] [blame] | 911 |   SectionSpec += ","; | 
 | 912 |  | 
 | 913 |   // Add all the tokens until the end of the line, ParseSectionSpecifier will | 
 | 914 |   // handle this. | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 915 |   StringRef EOL = Lexer.LexUntilEndOfStatement(); | 
 | 916 |   SectionSpec.append(EOL.begin(), EOL.end()); | 
| Daniel Dunbar | ace6312 | 2009-08-11 03:42:33 +0000 | [diff] [blame] | 917 |  | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 918 |   Lex(); | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 919 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
| Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 920 |     return TokError("unexpected token in '.section' directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 921 |   Lex(); | 
| Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 922 |  | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 923 |  | 
 | 924 |   StringRef Segment, Section; | 
 | 925 |   unsigned TAA, StubSize; | 
 | 926 |   std::string ErrorStr =  | 
 | 927 |     MCSectionMachO::ParseSectionSpecifier(SectionSpec, Segment, Section, | 
 | 928 |                                           TAA, StubSize); | 
 | 929 |    | 
 | 930 |   if (!ErrorStr.empty()) | 
| Daniel Dunbar | ace6312 | 2009-08-11 03:42:33 +0000 | [diff] [blame] | 931 |     return Error(Loc, ErrorStr.c_str()); | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 932 |    | 
| Chris Lattner | 56594f9 | 2009-07-31 17:47:16 +0000 | [diff] [blame] | 933 |   // FIXME: Arch specific. | 
| Chris Lattner | f60e9bb | 2010-02-26 18:32:26 +0000 | [diff] [blame] | 934 |   bool isText = Segment == "__TEXT";  // FIXME: Hack. | 
| Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 935 |   Out.SwitchSection(Ctx.getMachOSection(Segment, Section, TAA, StubSize, | 
 | 936 |                                         isText ? SectionKind::getText() | 
 | 937 |                                                : SectionKind::getDataRel())); | 
| Chris Lattner | 9a023f7 | 2009-06-24 04:43:34 +0000 | [diff] [blame] | 938 |   return false; | 
 | 939 | } | 
 | 940 |  | 
| Chris Lattner | e15c2d7 | 2009-08-10 18:05:55 +0000 | [diff] [blame] | 941 | /// ParseDirectiveSectionSwitch -  | 
| Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 942 | bool AsmParser::ParseDirectiveSectionSwitch(const char *Segment, | 
 | 943 |                                             const char *Section, | 
| Daniel Dunbar | b3f3c03 | 2009-08-21 08:34:18 +0000 | [diff] [blame] | 944 |                                             unsigned TAA, unsigned Align, | 
 | 945 |                                             unsigned StubSize) { | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 946 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
| Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 947 |     return TokError("unexpected token in section switching directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 948 |   Lex(); | 
| Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 949 |    | 
| Chris Lattner | 56594f9 | 2009-07-31 17:47:16 +0000 | [diff] [blame] | 950 |   // FIXME: Arch specific. | 
| Chris Lattner | f60e9bb | 2010-02-26 18:32:26 +0000 | [diff] [blame] | 951 |   bool isText = StringRef(Segment) == "__TEXT";  // FIXME: Hack. | 
| Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 952 |   Out.SwitchSection(Ctx.getMachOSection(Segment, Section, TAA, StubSize, | 
 | 953 |                                         isText ? SectionKind::getText() | 
 | 954 |                                                : SectionKind::getDataRel())); | 
| Daniel Dunbar | 2330df6 | 2009-08-21 23:30:15 +0000 | [diff] [blame] | 955 |  | 
 | 956 |   // Set the implicit alignment, if any. | 
 | 957 |   // | 
 | 958 |   // FIXME: This isn't really what 'as' does; I think it just uses the implicit | 
 | 959 |   // alignment on the section (e.g., if one manually inserts bytes into the | 
 | 960 |   // section, then just issueing the section switch directive will not realign | 
 | 961 |   // the section. However, this is arguably more reasonable behavior, and there | 
 | 962 |   // is no good reason for someone to intentionally emit incorrectly sized | 
 | 963 |   // values into the implicitly aligned sections. | 
 | 964 |   if (Align) | 
 | 965 |     Out.EmitValueToAlignment(Align, 0, 1, 0); | 
 | 966 |  | 
| Chris Lattner | 529fb54 | 2009-06-24 05:13:15 +0000 | [diff] [blame] | 967 |   return false; | 
 | 968 | } | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 969 |  | 
| Daniel Dunbar | 1ab7594 | 2009-08-14 18:19:52 +0000 | [diff] [blame] | 970 | bool AsmParser::ParseEscapedString(std::string &Data) { | 
 | 971 |   assert(Lexer.is(AsmToken::String) && "Unexpected current token!"); | 
 | 972 |  | 
 | 973 |   Data = ""; | 
| Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 974 |   StringRef Str = getTok().getStringContents(); | 
| Daniel Dunbar | 1ab7594 | 2009-08-14 18:19:52 +0000 | [diff] [blame] | 975 |   for (unsigned i = 0, e = Str.size(); i != e; ++i) { | 
 | 976 |     if (Str[i] != '\\') { | 
 | 977 |       Data += Str[i]; | 
 | 978 |       continue; | 
 | 979 |     } | 
 | 980 |  | 
 | 981 |     // Recognize escaped characters. Note that this escape semantics currently | 
 | 982 |     // loosely follows Darwin 'as'. Notably, it doesn't support hex escapes. | 
 | 983 |     ++i; | 
 | 984 |     if (i == e) | 
 | 985 |       return TokError("unexpected backslash at end of string"); | 
 | 986 |  | 
 | 987 |     // Recognize octal sequences. | 
 | 988 |     if ((unsigned) (Str[i] - '0') <= 7) { | 
 | 989 |       // Consume up to three octal characters. | 
 | 990 |       unsigned Value = Str[i] - '0'; | 
 | 991 |  | 
 | 992 |       if (i + 1 != e && ((unsigned) (Str[i + 1] - '0')) <= 7) { | 
 | 993 |         ++i; | 
 | 994 |         Value = Value * 8 + (Str[i] - '0'); | 
 | 995 |  | 
 | 996 |         if (i + 1 != e && ((unsigned) (Str[i + 1] - '0')) <= 7) { | 
 | 997 |           ++i; | 
 | 998 |           Value = Value * 8 + (Str[i] - '0'); | 
 | 999 |         } | 
 | 1000 |       } | 
 | 1001 |  | 
 | 1002 |       if (Value > 255) | 
 | 1003 |         return TokError("invalid octal escape sequence (out of range)"); | 
 | 1004 |  | 
 | 1005 |       Data += (unsigned char) Value; | 
 | 1006 |       continue; | 
 | 1007 |     } | 
 | 1008 |  | 
 | 1009 |     // Otherwise recognize individual escapes. | 
 | 1010 |     switch (Str[i]) { | 
 | 1011 |     default: | 
 | 1012 |       // Just reject invalid escape sequences for now. | 
 | 1013 |       return TokError("invalid escape sequence (unrecognized character)"); | 
 | 1014 |  | 
 | 1015 |     case 'b': Data += '\b'; break; | 
 | 1016 |     case 'f': Data += '\f'; break; | 
 | 1017 |     case 'n': Data += '\n'; break; | 
 | 1018 |     case 'r': Data += '\r'; break; | 
 | 1019 |     case 't': Data += '\t'; break; | 
 | 1020 |     case '"': Data += '"'; break; | 
 | 1021 |     case '\\': Data += '\\'; break; | 
 | 1022 |     } | 
 | 1023 |   } | 
 | 1024 |  | 
 | 1025 |   return false; | 
 | 1026 | } | 
 | 1027 |  | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1028 | /// ParseDirectiveAscii: | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 1029 | ///   ::= ( .ascii | .asciz ) [ "string" ( , "string" )* ] | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1030 | bool AsmParser::ParseDirectiveAscii(bool ZeroTerminated) { | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1031 |   if (Lexer.isNot(AsmToken::EndOfStatement)) { | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1032 |     for (;;) { | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1033 |       if (Lexer.isNot(AsmToken::String)) | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1034 |         return TokError("expected string in '.ascii' or '.asciz' directive"); | 
 | 1035 |        | 
| Daniel Dunbar | 1ab7594 | 2009-08-14 18:19:52 +0000 | [diff] [blame] | 1036 |       std::string Data; | 
 | 1037 |       if (ParseEscapedString(Data)) | 
 | 1038 |         return true; | 
 | 1039 |        | 
| Chris Lattner | aaec205 | 2010-01-19 19:46:13 +0000 | [diff] [blame] | 1040 |       Out.EmitBytes(Data, DEFAULT_ADDRSPACE); | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1041 |       if (ZeroTerminated) | 
| Chris Lattner | aaec205 | 2010-01-19 19:46:13 +0000 | [diff] [blame] | 1042 |         Out.EmitBytes(StringRef("\0", 1), DEFAULT_ADDRSPACE); | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1043 |        | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1044 |       Lex(); | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1045 |        | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1046 |       if (Lexer.is(AsmToken::EndOfStatement)) | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1047 |         break; | 
 | 1048 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1049 |       if (Lexer.isNot(AsmToken::Comma)) | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1050 |         return TokError("unexpected token in '.ascii' or '.asciz' directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1051 |       Lex(); | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1052 |     } | 
 | 1053 |   } | 
 | 1054 |  | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1055 |   Lex(); | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1056 |   return false; | 
 | 1057 | } | 
 | 1058 |  | 
 | 1059 | /// ParseDirectiveValue | 
 | 1060 | ///  ::= (.byte | .short | ... ) [ expression (, expression)* ] | 
 | 1061 | bool AsmParser::ParseDirectiveValue(unsigned Size) { | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1062 |   if (Lexer.isNot(AsmToken::EndOfStatement)) { | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1063 |     for (;;) { | 
| Daniel Dunbar | 821e333 | 2009-08-31 08:09:28 +0000 | [diff] [blame] | 1064 |       const MCExpr *Value; | 
| Bill Wendling | 9bc0af8 | 2009-12-28 01:34:57 +0000 | [diff] [blame] | 1065 |       SMLoc ATTRIBUTE_UNUSED StartLoc = Lexer.getLoc(); | 
| Daniel Dunbar | 821e333 | 2009-08-31 08:09:28 +0000 | [diff] [blame] | 1066 |       if (ParseExpression(Value)) | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1067 |         return true; | 
 | 1068 |  | 
| Chris Lattner | aaec205 | 2010-01-19 19:46:13 +0000 | [diff] [blame] | 1069 |       Out.EmitValue(Value, Size, DEFAULT_ADDRSPACE); | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1070 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1071 |       if (Lexer.is(AsmToken::EndOfStatement)) | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1072 |         break; | 
 | 1073 |        | 
 | 1074 |       // FIXME: Improve diagnostic. | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1075 |       if (Lexer.isNot(AsmToken::Comma)) | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1076 |         return TokError("unexpected token in directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1077 |       Lex(); | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1078 |     } | 
 | 1079 |   } | 
 | 1080 |  | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1081 |   Lex(); | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1082 |   return false; | 
 | 1083 | } | 
 | 1084 |  | 
 | 1085 | /// ParseDirectiveSpace | 
 | 1086 | ///  ::= .space expression [ , expression ] | 
 | 1087 | bool AsmParser::ParseDirectiveSpace() { | 
 | 1088 |   int64_t NumBytes; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 1089 |   if (ParseAbsoluteExpression(NumBytes)) | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1090 |     return true; | 
 | 1091 |  | 
 | 1092 |   int64_t FillExpr = 0; | 
 | 1093 |   bool HasFillExpr = false; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1094 |   if (Lexer.isNot(AsmToken::EndOfStatement)) { | 
 | 1095 |     if (Lexer.isNot(AsmToken::Comma)) | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1096 |       return TokError("unexpected token in '.space' directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1097 |     Lex(); | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1098 |      | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 1099 |     if (ParseAbsoluteExpression(FillExpr)) | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1100 |       return true; | 
 | 1101 |  | 
 | 1102 |     HasFillExpr = true; | 
 | 1103 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1104 |     if (Lexer.isNot(AsmToken::EndOfStatement)) | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1105 |       return TokError("unexpected token in '.space' directive"); | 
 | 1106 |   } | 
 | 1107 |  | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1108 |   Lex(); | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1109 |  | 
 | 1110 |   if (NumBytes <= 0) | 
 | 1111 |     return TokError("invalid number of bytes in '.space' directive"); | 
 | 1112 |  | 
 | 1113 |   // FIXME: Sometimes the fill expr is 'nop' if it isn't supplied, instead of 0. | 
| Chris Lattner | aaec205 | 2010-01-19 19:46:13 +0000 | [diff] [blame] | 1114 |   Out.EmitFill(NumBytes, FillExpr, DEFAULT_ADDRSPACE); | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1115 |  | 
 | 1116 |   return false; | 
 | 1117 | } | 
 | 1118 |  | 
 | 1119 | /// ParseDirectiveFill | 
 | 1120 | ///  ::= .fill expression , expression , expression | 
 | 1121 | bool AsmParser::ParseDirectiveFill() { | 
 | 1122 |   int64_t NumValues; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 1123 |   if (ParseAbsoluteExpression(NumValues)) | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1124 |     return true; | 
 | 1125 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1126 |   if (Lexer.isNot(AsmToken::Comma)) | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1127 |     return TokError("unexpected token in '.fill' directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1128 |   Lex(); | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1129 |    | 
 | 1130 |   int64_t FillSize; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 1131 |   if (ParseAbsoluteExpression(FillSize)) | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1132 |     return true; | 
 | 1133 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1134 |   if (Lexer.isNot(AsmToken::Comma)) | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1135 |     return TokError("unexpected token in '.fill' directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1136 |   Lex(); | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1137 |    | 
 | 1138 |   int64_t FillExpr; | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 1139 |   if (ParseAbsoluteExpression(FillExpr)) | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1140 |     return true; | 
 | 1141 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1142 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1143 |     return TokError("unexpected token in '.fill' directive"); | 
 | 1144 |    | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1145 |   Lex(); | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1146 |  | 
| Daniel Dunbar | bc38ca7 | 2009-08-21 15:43:35 +0000 | [diff] [blame] | 1147 |   if (FillSize != 1 && FillSize != 2 && FillSize != 4 && FillSize != 8) | 
 | 1148 |     return TokError("invalid '.fill' size, expected 1, 2, 4, or 8"); | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1149 |  | 
 | 1150 |   for (uint64_t i = 0, e = NumValues; i != e; ++i) | 
| Chris Lattner | aaec205 | 2010-01-19 19:46:13 +0000 | [diff] [blame] | 1151 |     Out.EmitValue(MCConstantExpr::Create(FillExpr, getContext()), FillSize, | 
 | 1152 |                   DEFAULT_ADDRSPACE); | 
| Daniel Dunbar | a0d1426 | 2009-06-24 23:30:00 +0000 | [diff] [blame] | 1153 |  | 
 | 1154 |   return false; | 
 | 1155 | } | 
| Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 1156 |  | 
 | 1157 | /// ParseDirectiveOrg | 
 | 1158 | ///  ::= .org expression [ , expression ] | 
 | 1159 | bool AsmParser::ParseDirectiveOrg() { | 
| Daniel Dunbar | 821e333 | 2009-08-31 08:09:28 +0000 | [diff] [blame] | 1160 |   const MCExpr *Offset; | 
| Daniel Dunbar | 883f920 | 2009-08-31 08:08:50 +0000 | [diff] [blame] | 1161 |   SMLoc StartLoc = Lexer.getLoc(); | 
| Daniel Dunbar | 821e333 | 2009-08-31 08:09:28 +0000 | [diff] [blame] | 1162 |   if (ParseExpression(Offset)) | 
| Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 1163 |     return true; | 
 | 1164 |  | 
 | 1165 |   // Parse optional fill expression. | 
 | 1166 |   int64_t FillExpr = 0; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1167 |   if (Lexer.isNot(AsmToken::EndOfStatement)) { | 
 | 1168 |     if (Lexer.isNot(AsmToken::Comma)) | 
| Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 1169 |       return TokError("unexpected token in '.org' directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1170 |     Lex(); | 
| Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 1171 |      | 
| Daniel Dunbar | 475839e | 2009-06-29 20:37:27 +0000 | [diff] [blame] | 1172 |     if (ParseAbsoluteExpression(FillExpr)) | 
| Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 1173 |       return true; | 
 | 1174 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1175 |     if (Lexer.isNot(AsmToken::EndOfStatement)) | 
| Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 1176 |       return TokError("unexpected token in '.org' directive"); | 
 | 1177 |   } | 
 | 1178 |  | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1179 |   Lex(); | 
| Daniel Dunbar | f4b830f | 2009-06-30 02:10:03 +0000 | [diff] [blame] | 1180 |  | 
 | 1181 |   // FIXME: Only limited forms of relocatable expressions are accepted here, it | 
 | 1182 |   // has to be relative to the current section. | 
 | 1183 |   Out.EmitValueToOffset(Offset, FillExpr); | 
| Daniel Dunbar | c238b58 | 2009-06-25 22:44:51 +0000 | [diff] [blame] | 1184 |  | 
 | 1185 |   return false; | 
 | 1186 | } | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1187 |  | 
 | 1188 | /// ParseDirectiveAlign | 
 | 1189 | ///  ::= {.align, ...} expression [ , expression [ , expression ]] | 
 | 1190 | bool AsmParser::ParseDirectiveAlign(bool IsPow2, unsigned ValueSize) { | 
| Daniel Dunbar | b58a804 | 2009-08-26 09:16:34 +0000 | [diff] [blame] | 1191 |   SMLoc AlignmentLoc = Lexer.getLoc(); | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1192 |   int64_t Alignment; | 
 | 1193 |   if (ParseAbsoluteExpression(Alignment)) | 
 | 1194 |     return true; | 
 | 1195 |  | 
 | 1196 |   SMLoc MaxBytesLoc; | 
 | 1197 |   bool HasFillExpr = false; | 
 | 1198 |   int64_t FillExpr = 0; | 
 | 1199 |   int64_t MaxBytesToFill = 0; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1200 |   if (Lexer.isNot(AsmToken::EndOfStatement)) { | 
 | 1201 |     if (Lexer.isNot(AsmToken::Comma)) | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1202 |       return TokError("unexpected token in directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1203 |     Lex(); | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1204 |  | 
 | 1205 |     // The fill expression can be omitted while specifying a maximum number of | 
 | 1206 |     // alignment bytes, e.g: | 
 | 1207 |     //  .align 3,,4 | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1208 |     if (Lexer.isNot(AsmToken::Comma)) { | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1209 |       HasFillExpr = true; | 
 | 1210 |       if (ParseAbsoluteExpression(FillExpr)) | 
 | 1211 |         return true; | 
 | 1212 |     } | 
 | 1213 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1214 |     if (Lexer.isNot(AsmToken::EndOfStatement)) { | 
 | 1215 |       if (Lexer.isNot(AsmToken::Comma)) | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1216 |         return TokError("unexpected token in directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1217 |       Lex(); | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1218 |  | 
 | 1219 |       MaxBytesLoc = Lexer.getLoc(); | 
 | 1220 |       if (ParseAbsoluteExpression(MaxBytesToFill)) | 
 | 1221 |         return true; | 
 | 1222 |        | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1223 |       if (Lexer.isNot(AsmToken::EndOfStatement)) | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1224 |         return TokError("unexpected token in directive"); | 
 | 1225 |     } | 
 | 1226 |   } | 
 | 1227 |  | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1228 |   Lex(); | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1229 |  | 
| Daniel Dunbar | 648ac51 | 2010-05-17 21:54:30 +0000 | [diff] [blame] | 1230 |   if (!HasFillExpr) | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1231 |     FillExpr = 0; | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1232 |  | 
 | 1233 |   // Compute alignment in bytes. | 
 | 1234 |   if (IsPow2) { | 
 | 1235 |     // FIXME: Diagnose overflow. | 
| Daniel Dunbar | b58a804 | 2009-08-26 09:16:34 +0000 | [diff] [blame] | 1236 |     if (Alignment >= 32) { | 
 | 1237 |       Error(AlignmentLoc, "invalid alignment value"); | 
 | 1238 |       Alignment = 31; | 
 | 1239 |     } | 
 | 1240 |  | 
| Benjamin Kramer | 12fd767 | 2009-09-06 09:35:10 +0000 | [diff] [blame] | 1241 |     Alignment = 1ULL << Alignment; | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1242 |   } | 
 | 1243 |  | 
| Daniel Dunbar | b58a804 | 2009-08-26 09:16:34 +0000 | [diff] [blame] | 1244 |   // Diagnose non-sensical max bytes to align. | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1245 |   if (MaxBytesLoc.isValid()) { | 
 | 1246 |     if (MaxBytesToFill < 1) { | 
| Daniel Dunbar | b58a804 | 2009-08-26 09:16:34 +0000 | [diff] [blame] | 1247 |       Error(MaxBytesLoc, "alignment directive can never be satisfied in this " | 
 | 1248 |             "many bytes, ignoring maximum bytes expression"); | 
| Daniel Dunbar | 0afb9f5 | 2009-08-21 23:01:53 +0000 | [diff] [blame] | 1249 |       MaxBytesToFill = 0; | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1250 |     } | 
 | 1251 |  | 
 | 1252 |     if (MaxBytesToFill >= Alignment) { | 
| Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 1253 |       Warning(MaxBytesLoc, "maximum bytes expression exceeds alignment and " | 
 | 1254 |               "has no effect"); | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1255 |       MaxBytesToFill = 0; | 
 | 1256 |     } | 
 | 1257 |   } | 
 | 1258 |  | 
| Daniel Dunbar | 648ac51 | 2010-05-17 21:54:30 +0000 | [diff] [blame] | 1259 |   // Check whether we should use optimal code alignment for this .align | 
 | 1260 |   // directive. | 
 | 1261 |   // | 
 | 1262 |   // FIXME: This should be using a target hook. | 
 | 1263 |   bool UseCodeAlign = false; | 
 | 1264 |   if (const MCSectionMachO *S = dyn_cast<MCSectionMachO>( | 
 | 1265 |         Out.getCurrentSection())) | 
 | 1266 |       UseCodeAlign = S->hasAttribute(MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS); | 
 | 1267 |   if ((!HasFillExpr || Lexer.getMAI().getTextAlignFillValue() == FillExpr) && | 
 | 1268 |       ValueSize == 1 && UseCodeAlign) { | 
| Kevin Enderby | d74acb0 | 2010-02-25 18:46:04 +0000 | [diff] [blame] | 1269 |     Out.EmitCodeAlignment(Alignment, MaxBytesToFill); | 
| Daniel Dunbar | 648ac51 | 2010-05-17 21:54:30 +0000 | [diff] [blame] | 1270 |   } else { | 
| Kevin Enderby | d74acb0 | 2010-02-25 18:46:04 +0000 | [diff] [blame] | 1271 |     // FIXME: Target specific behavior about how the "extra" bytes are filled. | 
 | 1272 |     Out.EmitValueToAlignment(Alignment, FillExpr, ValueSize, MaxBytesToFill); | 
| Daniel Dunbar | 648ac51 | 2010-05-17 21:54:30 +0000 | [diff] [blame] | 1273 |   } | 
| Daniel Dunbar | c29dfa7 | 2009-06-29 23:46:59 +0000 | [diff] [blame] | 1274 |  | 
 | 1275 |   return false; | 
 | 1276 | } | 
 | 1277 |  | 
| Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 1278 | /// ParseDirectiveSymbolAttribute | 
 | 1279 | ///  ::= { ".globl", ".weak", ... } [ identifier ( , identifier )* ] | 
| Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 1280 | bool AsmParser::ParseDirectiveSymbolAttribute(MCSymbolAttr Attr) { | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1281 |   if (Lexer.isNot(AsmToken::EndOfStatement)) { | 
| Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 1282 |     for (;;) { | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 1283 |       StringRef Name; | 
 | 1284 |  | 
 | 1285 |       if (ParseIdentifier(Name)) | 
| Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 1286 |         return TokError("expected identifier in directive"); | 
 | 1287 |        | 
| Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame] | 1288 |       MCSymbol *Sym = CreateSymbol(Name); | 
| Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 1289 |  | 
| Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 1290 |       Out.EmitSymbolAttribute(Sym, Attr); | 
 | 1291 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1292 |       if (Lexer.is(AsmToken::EndOfStatement)) | 
| Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 1293 |         break; | 
 | 1294 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1295 |       if (Lexer.isNot(AsmToken::Comma)) | 
| Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 1296 |         return TokError("unexpected token in directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1297 |       Lex(); | 
| Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 1298 |     } | 
 | 1299 |   } | 
 | 1300 |  | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1301 |   Lex(); | 
| Daniel Dunbar | d7b267b | 2009-06-30 00:33:19 +0000 | [diff] [blame] | 1302 |   return false;   | 
 | 1303 | } | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1304 |  | 
| Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 1305 | /// ParseDirectiveDarwinSymbolDesc | 
 | 1306 | ///  ::= .desc identifier , expression | 
 | 1307 | bool AsmParser::ParseDirectiveDarwinSymbolDesc() { | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 1308 |   StringRef Name; | 
 | 1309 |   if (ParseIdentifier(Name)) | 
| Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 1310 |     return TokError("expected identifier in directive"); | 
 | 1311 |    | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 1312 |   // Handle the identifier as the key symbol. | 
| Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame] | 1313 |   MCSymbol *Sym = CreateSymbol(Name); | 
| Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 1314 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1315 |   if (Lexer.isNot(AsmToken::Comma)) | 
| Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 1316 |     return TokError("unexpected token in '.desc' directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1317 |   Lex(); | 
| Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 1318 |  | 
 | 1319 |   SMLoc DescLoc = Lexer.getLoc(); | 
 | 1320 |   int64_t DescValue; | 
 | 1321 |   if (ParseAbsoluteExpression(DescValue)) | 
 | 1322 |     return true; | 
 | 1323 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1324 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
| Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 1325 |     return TokError("unexpected token in '.desc' directive"); | 
 | 1326 |    | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1327 |   Lex(); | 
| Kevin Enderby | 95cf30c | 2009-07-14 18:17:10 +0000 | [diff] [blame] | 1328 |  | 
 | 1329 |   // Set the n_desc field of this Symbol to this DescValue | 
 | 1330 |   Out.EmitSymbolDesc(Sym, DescValue); | 
 | 1331 |  | 
 | 1332 |   return false; | 
 | 1333 | } | 
 | 1334 |  | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1335 | /// ParseDirectiveComm | 
| Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 1336 | ///  ::= ( .comm | .lcomm ) identifier , size_expression [ , align_expression ] | 
 | 1337 | bool AsmParser::ParseDirectiveComm(bool IsLocal) { | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 1338 |   SMLoc IDLoc = Lexer.getLoc(); | 
 | 1339 |   StringRef Name; | 
 | 1340 |   if (ParseIdentifier(Name)) | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1341 |     return TokError("expected identifier in directive"); | 
 | 1342 |    | 
| Daniel Dunbar | 76c4d76 | 2009-07-31 21:55:09 +0000 | [diff] [blame] | 1343 |   // Handle the identifier as the key symbol. | 
| Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame] | 1344 |   MCSymbol *Sym = CreateSymbol(Name); | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1345 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1346 |   if (Lexer.isNot(AsmToken::Comma)) | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1347 |     return TokError("unexpected token in directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1348 |   Lex(); | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1349 |  | 
 | 1350 |   int64_t Size; | 
 | 1351 |   SMLoc SizeLoc = Lexer.getLoc(); | 
 | 1352 |   if (ParseAbsoluteExpression(Size)) | 
 | 1353 |     return true; | 
 | 1354 |  | 
 | 1355 |   int64_t Pow2Alignment = 0; | 
 | 1356 |   SMLoc Pow2AlignmentLoc; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1357 |   if (Lexer.is(AsmToken::Comma)) { | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1358 |     Lex(); | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1359 |     Pow2AlignmentLoc = Lexer.getLoc(); | 
 | 1360 |     if (ParseAbsoluteExpression(Pow2Alignment)) | 
 | 1361 |       return true; | 
| Chris Lattner | 258281d | 2010-01-19 06:22:22 +0000 | [diff] [blame] | 1362 |      | 
 | 1363 |     // If this target takes alignments in bytes (not log) validate and convert. | 
 | 1364 |     if (Lexer.getMAI().getAlignmentIsInBytes()) { | 
 | 1365 |       if (!isPowerOf2_64(Pow2Alignment)) | 
 | 1366 |         return Error(Pow2AlignmentLoc, "alignment must be a power of 2"); | 
 | 1367 |       Pow2Alignment = Log2_64(Pow2Alignment); | 
 | 1368 |     } | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1369 |   } | 
 | 1370 |    | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1371 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
| Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 1372 |     return TokError("unexpected token in '.comm' or '.lcomm' directive"); | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1373 |    | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1374 |   Lex(); | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1375 |  | 
| Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 1376 |   // NOTE: a size of zero for a .comm should create a undefined symbol | 
 | 1377 |   // but a size of .lcomm creates a bss symbol of size zero. | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1378 |   if (Size < 0) | 
| Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 1379 |     return Error(SizeLoc, "invalid '.comm' or '.lcomm' directive size, can't " | 
 | 1380 |                  "be less than zero"); | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1381 |  | 
| Eric Christopher | c260a3e | 2010-05-14 01:38:54 +0000 | [diff] [blame] | 1382 |   // NOTE: The alignment in the directive is a power of 2 value, the assembler | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1383 |   // may internally end up wanting an alignment in bytes. | 
 | 1384 |   // FIXME: Diagnose overflow. | 
 | 1385 |   if (Pow2Alignment < 0) | 
| Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 1386 |     return Error(Pow2AlignmentLoc, "invalid '.comm' or '.lcomm' directive " | 
 | 1387 |                  "alignment, can't be less than zero"); | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1388 |  | 
| Daniel Dunbar | 8906ff1 | 2009-08-22 07:22:36 +0000 | [diff] [blame] | 1389 |   if (!Sym->isUndefined()) | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1390 |     return Error(IDLoc, "invalid symbol redefinition"); | 
 | 1391 |  | 
| Daniel Dunbar | 7092c7e | 2009-08-30 06:17:16 +0000 | [diff] [blame] | 1392 |   // '.lcomm' is equivalent to '.zerofill'. | 
| Chris Lattner | 1fc3d75 | 2009-07-09 17:25:12 +0000 | [diff] [blame] | 1393 |   // Create the Symbol as a common or local common with Size and Pow2Alignment | 
| Daniel Dunbar | 7092c7e | 2009-08-30 06:17:16 +0000 | [diff] [blame] | 1394 |   if (IsLocal) { | 
| Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 1395 |     Out.EmitZerofill(Ctx.getMachOSection("__DATA", "__bss", | 
 | 1396 |                                          MCSectionMachO::S_ZEROFILL, 0, | 
 | 1397 |                                          SectionKind::getBSS()), | 
| Daniel Dunbar | 7092c7e | 2009-08-30 06:17:16 +0000 | [diff] [blame] | 1398 |                      Sym, Size, 1 << Pow2Alignment); | 
 | 1399 |     return false; | 
 | 1400 |   } | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1401 |  | 
| Daniel Dunbar | 7092c7e | 2009-08-30 06:17:16 +0000 | [diff] [blame] | 1402 |   Out.EmitCommonSymbol(Sym, Size, 1 << Pow2Alignment); | 
| Chris Lattner | 4e4db7a | 2009-07-07 20:30:46 +0000 | [diff] [blame] | 1403 |   return false; | 
 | 1404 | } | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1405 |  | 
 | 1406 | /// ParseDirectiveDarwinZerofill | 
 | 1407 | ///  ::= .zerofill segname , sectname [, identifier , size_expression [ | 
 | 1408 | ///      , align_expression ]] | 
 | 1409 | bool AsmParser::ParseDirectiveDarwinZerofill() { | 
| Chris Lattner | 7bb7c55 | 2010-05-13 00:10:34 +0000 | [diff] [blame] | 1410 |   StringRef Segment; | 
 | 1411 |   if (ParseIdentifier(Segment)) | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1412 |     return TokError("expected segment name after '.zerofill' directive"); | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1413 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1414 |   if (Lexer.isNot(AsmToken::Comma)) | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1415 |     return TokError("unexpected token in directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1416 |   Lex(); | 
| Chris Lattner | 7bb7c55 | 2010-05-13 00:10:34 +0000 | [diff] [blame] | 1417 |  | 
 | 1418 |   StringRef Section; | 
 | 1419 |   if (ParseIdentifier(Section)) | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1420 |     return TokError("expected section name after comma in '.zerofill' " | 
 | 1421 |                     "directive"); | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1422 |  | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1423 |   // If this is the end of the line all that was wanted was to create the | 
 | 1424 |   // the section but with no symbol. | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1425 |   if (Lexer.is(AsmToken::EndOfStatement)) { | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1426 |     // Create the zerofill section but no symbol | 
| Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 1427 |     Out.EmitZerofill(Ctx.getMachOSection(Segment, Section, | 
 | 1428 |                                          MCSectionMachO::S_ZEROFILL, 0, | 
 | 1429 |                                          SectionKind::getBSS())); | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1430 |     return false; | 
 | 1431 |   } | 
 | 1432 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1433 |   if (Lexer.isNot(AsmToken::Comma)) | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1434 |     return TokError("unexpected token in directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1435 |   Lex(); | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1436 |  | 
| Chris Lattner | 7bb7c55 | 2010-05-13 00:10:34 +0000 | [diff] [blame] | 1437 |   SMLoc IDLoc = Lexer.getLoc(); | 
 | 1438 |   StringRef IDStr; | 
 | 1439 |   if (ParseIdentifier(IDStr)) | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1440 |     return TokError("expected identifier in directive"); | 
 | 1441 |    | 
 | 1442 |   // handle the identifier as the key symbol. | 
| Chris Lattner | 7bb7c55 | 2010-05-13 00:10:34 +0000 | [diff] [blame] | 1443 |   MCSymbol *Sym = CreateSymbol(IDStr); | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1444 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1445 |   if (Lexer.isNot(AsmToken::Comma)) | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1446 |     return TokError("unexpected token in directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1447 |   Lex(); | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1448 |  | 
 | 1449 |   int64_t Size; | 
 | 1450 |   SMLoc SizeLoc = Lexer.getLoc(); | 
 | 1451 |   if (ParseAbsoluteExpression(Size)) | 
 | 1452 |     return true; | 
 | 1453 |  | 
 | 1454 |   int64_t Pow2Alignment = 0; | 
 | 1455 |   SMLoc Pow2AlignmentLoc; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1456 |   if (Lexer.is(AsmToken::Comma)) { | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1457 |     Lex(); | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1458 |     Pow2AlignmentLoc = Lexer.getLoc(); | 
 | 1459 |     if (ParseAbsoluteExpression(Pow2Alignment)) | 
 | 1460 |       return true; | 
 | 1461 |   } | 
 | 1462 |    | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1463 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1464 |     return TokError("unexpected token in '.zerofill' directive"); | 
 | 1465 |    | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1466 |   Lex(); | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1467 |  | 
 | 1468 |   if (Size < 0) | 
 | 1469 |     return Error(SizeLoc, "invalid '.zerofill' directive size, can't be less " | 
 | 1470 |                  "than zero"); | 
 | 1471 |  | 
| Eric Christopher | c260a3e | 2010-05-14 01:38:54 +0000 | [diff] [blame] | 1472 |   // NOTE: The alignment in the directive is a power of 2 value, the assembler | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1473 |   // may internally end up wanting an alignment in bytes. | 
 | 1474 |   // FIXME: Diagnose overflow. | 
 | 1475 |   if (Pow2Alignment < 0) | 
 | 1476 |     return Error(Pow2AlignmentLoc, "invalid '.zerofill' directive alignment, " | 
 | 1477 |                  "can't be less than zero"); | 
 | 1478 |  | 
| Daniel Dunbar | 8906ff1 | 2009-08-22 07:22:36 +0000 | [diff] [blame] | 1479 |   if (!Sym->isUndefined()) | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1480 |     return Error(IDLoc, "invalid symbol redefinition"); | 
 | 1481 |  | 
| Daniel Dunbar | bdee6df | 2009-08-27 23:58:10 +0000 | [diff] [blame] | 1482 |   // Create the zerofill Symbol with Size and Pow2Alignment | 
| Daniel Dunbar | 2e15292 | 2009-08-28 05:48:29 +0000 | [diff] [blame] | 1483 |   // | 
 | 1484 |   // FIXME: Arch specific. | 
| Chris Lattner | f0559e4 | 2010-04-08 20:30:37 +0000 | [diff] [blame] | 1485 |   Out.EmitZerofill(Ctx.getMachOSection(Segment, Section, | 
 | 1486 |                                        MCSectionMachO::S_ZEROFILL, 0, | 
 | 1487 |                                        SectionKind::getBSS()), | 
| Daniel Dunbar | 7092c7e | 2009-08-30 06:17:16 +0000 | [diff] [blame] | 1488 |                    Sym, Size, 1 << Pow2Alignment); | 
| Chris Lattner | 9be3fee | 2009-07-10 22:20:30 +0000 | [diff] [blame] | 1489 |  | 
 | 1490 |   return false; | 
 | 1491 | } | 
| Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 1492 |  | 
| Eric Christopher | 482eba0 | 2010-05-14 01:50:28 +0000 | [diff] [blame] | 1493 | /// ParseDirectiveDarwinTBSS | 
 | 1494 | ///  ::= .tbss identifier, size, align | 
 | 1495 | bool AsmParser::ParseDirectiveDarwinTBSS() { | 
 | 1496 |   SMLoc IDLoc = Lexer.getLoc(); | 
 | 1497 |   StringRef Name; | 
 | 1498 |   if (ParseIdentifier(Name)) | 
 | 1499 |     return TokError("expected identifier in directive"); | 
| Eric Christopher | d04d98d | 2010-05-17 02:13:02 +0000 | [diff] [blame] | 1500 |      | 
| Eric Christopher | 482eba0 | 2010-05-14 01:50:28 +0000 | [diff] [blame] | 1501 |   // Handle the identifier as the key symbol. | 
| Eric Christopher | d04d98d | 2010-05-17 02:13:02 +0000 | [diff] [blame] | 1502 |   MCSymbol *Sym = CreateSymbol(Name); | 
| Eric Christopher | 482eba0 | 2010-05-14 01:50:28 +0000 | [diff] [blame] | 1503 |  | 
 | 1504 |   if (Lexer.isNot(AsmToken::Comma)) | 
 | 1505 |     return TokError("unexpected token in directive"); | 
 | 1506 |   Lex(); | 
 | 1507 |  | 
 | 1508 |   int64_t Size; | 
 | 1509 |   SMLoc SizeLoc = Lexer.getLoc(); | 
 | 1510 |   if (ParseAbsoluteExpression(Size)) | 
 | 1511 |     return true; | 
 | 1512 |  | 
 | 1513 |   int64_t Pow2Alignment = 0; | 
 | 1514 |   SMLoc Pow2AlignmentLoc; | 
 | 1515 |   if (Lexer.is(AsmToken::Comma)) { | 
 | 1516 |     Lex(); | 
 | 1517 |     Pow2AlignmentLoc = Lexer.getLoc(); | 
 | 1518 |     if (ParseAbsoluteExpression(Pow2Alignment)) | 
 | 1519 |       return true; | 
 | 1520 |   } | 
 | 1521 |    | 
 | 1522 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
 | 1523 |     return TokError("unexpected token in '.tbss' directive"); | 
 | 1524 |    | 
 | 1525 |   Lex(); | 
 | 1526 |  | 
 | 1527 |   if (Size < 0) | 
 | 1528 |     return Error(SizeLoc, "invalid '.tbss' directive size, can't be less than" | 
 | 1529 |                  "zero"); | 
 | 1530 |  | 
 | 1531 |   // FIXME: Diagnose overflow. | 
 | 1532 |   if (Pow2Alignment < 0) | 
 | 1533 |     return Error(Pow2AlignmentLoc, "invalid '.tbss' alignment, can't be less" | 
 | 1534 |                  "than zero"); | 
 | 1535 |  | 
 | 1536 |   if (!Sym->isUndefined()) | 
 | 1537 |     return Error(IDLoc, "invalid symbol redefinition"); | 
 | 1538 |    | 
| Eric Christopher | 4d01cbe | 2010-05-18 21:16:04 +0000 | [diff] [blame^] | 1539 |   Out.EmitTBSSSymbol(Ctx.getMachOSection("__DATA", "__thread_bss", | 
 | 1540 |                                         MCSectionMachO::S_THREAD_LOCAL_ZEROFILL, | 
 | 1541 |                                         0, SectionKind::getThreadBSS()), | 
 | 1542 |                      Sym, Size, 1 << Pow2Alignment); | 
| Eric Christopher | 482eba0 | 2010-05-14 01:50:28 +0000 | [diff] [blame] | 1543 |    | 
 | 1544 |   return false; | 
 | 1545 | } | 
 | 1546 |  | 
| Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 1547 | /// ParseDirectiveDarwinSubsectionsViaSymbols | 
 | 1548 | ///  ::= .subsections_via_symbols | 
 | 1549 | bool AsmParser::ParseDirectiveDarwinSubsectionsViaSymbols() { | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1550 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
| Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 1551 |     return TokError("unexpected token in '.subsections_via_symbols' directive"); | 
 | 1552 |    | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1553 |   Lex(); | 
| Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 1554 |  | 
| Chris Lattner | a5ad93a | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 1555 |   Out.EmitAssemblerFlag(MCAF_SubsectionsViaSymbols); | 
| Kevin Enderby | a5c7832 | 2009-07-13 21:03:15 +0000 | [diff] [blame] | 1556 |  | 
 | 1557 |   return false; | 
 | 1558 | } | 
| Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 1559 |  | 
 | 1560 | /// ParseDirectiveAbort | 
 | 1561 | ///  ::= .abort [ "abort_string" ] | 
 | 1562 | bool AsmParser::ParseDirectiveAbort() { | 
| Daniel Dunbar | f9507ff | 2009-07-27 23:20:52 +0000 | [diff] [blame] | 1563 |   // FIXME: Use loc from directive. | 
 | 1564 |   SMLoc Loc = Lexer.getLoc(); | 
 | 1565 |  | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 1566 |   StringRef Str = ""; | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1567 |   if (Lexer.isNot(AsmToken::EndOfStatement)) { | 
 | 1568 |     if (Lexer.isNot(AsmToken::String)) | 
| Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 1569 |       return TokError("expected string in '.abort' directive"); | 
 | 1570 |      | 
| Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 1571 |     Str = getTok().getString(); | 
| Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 1572 |  | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1573 |     Lex(); | 
| Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 1574 |   } | 
 | 1575 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1576 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
| Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 1577 |     return TokError("unexpected token in '.abort' directive"); | 
 | 1578 |    | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1579 |   Lex(); | 
| Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 1580 |  | 
| Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 1581 |   // FIXME: Handle here. | 
| Daniel Dunbar | f9507ff | 2009-07-27 23:20:52 +0000 | [diff] [blame] | 1582 |   if (Str.empty()) | 
 | 1583 |     Error(Loc, ".abort detected. Assembly stopping."); | 
 | 1584 |   else | 
 | 1585 |     Error(Loc, ".abort '" + Str + "' detected. Assembly stopping."); | 
| Kevin Enderby | 5f1f0b8 | 2009-07-13 23:15:14 +0000 | [diff] [blame] | 1586 |  | 
 | 1587 |   return false; | 
 | 1588 | } | 
| Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 1589 |  | 
 | 1590 | /// ParseDirectiveLsym | 
 | 1591 | ///  ::= .lsym identifier , expression | 
 | 1592 | bool AsmParser::ParseDirectiveDarwinLsym() { | 
| Daniel Dunbar | a6b3c5d | 2009-08-01 00:48:30 +0000 | [diff] [blame] | 1593 |   StringRef Name; | 
 | 1594 |   if (ParseIdentifier(Name)) | 
| Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 1595 |     return TokError("expected identifier in directive"); | 
 | 1596 |    | 
| Daniel Dunbar | 76c4d76 | 2009-07-31 21:55:09 +0000 | [diff] [blame] | 1597 |   // Handle the identifier as the key symbol. | 
| Daniel Dunbar | 959fd88 | 2009-08-26 22:13:22 +0000 | [diff] [blame] | 1598 |   MCSymbol *Sym = CreateSymbol(Name); | 
| Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 1599 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1600 |   if (Lexer.isNot(AsmToken::Comma)) | 
| Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 1601 |     return TokError("unexpected token in '.lsym' directive"); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1602 |   Lex(); | 
| Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 1603 |  | 
| Daniel Dunbar | 821e333 | 2009-08-31 08:09:28 +0000 | [diff] [blame] | 1604 |   const MCExpr *Value; | 
| Daniel Dunbar | 883f920 | 2009-08-31 08:08:50 +0000 | [diff] [blame] | 1605 |   SMLoc StartLoc = Lexer.getLoc(); | 
| Daniel Dunbar | 821e333 | 2009-08-31 08:09:28 +0000 | [diff] [blame] | 1606 |   if (ParseExpression(Value)) | 
| Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 1607 |     return true; | 
 | 1608 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1609 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
| Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 1610 |     return TokError("unexpected token in '.lsym' directive"); | 
 | 1611 |    | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1612 |   Lex(); | 
| Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 1613 |  | 
| Daniel Dunbar | 7092c7e | 2009-08-30 06:17:16 +0000 | [diff] [blame] | 1614 |   // We don't currently support this directive. | 
 | 1615 |   // | 
 | 1616 |   // FIXME: Diagnostic location! | 
 | 1617 |   (void) Sym; | 
 | 1618 |   return TokError("directive '.lsym' is unsupported"); | 
| Kevin Enderby | 7114824 | 2009-07-14 21:35:03 +0000 | [diff] [blame] | 1619 | } | 
| Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 1620 |  | 
 | 1621 | /// ParseDirectiveInclude | 
 | 1622 | ///  ::= .include "filename" | 
 | 1623 | bool AsmParser::ParseDirectiveInclude() { | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1624 |   if (Lexer.isNot(AsmToken::String)) | 
| Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 1625 |     return TokError("expected string in '.include' directive"); | 
 | 1626 |    | 
| Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 1627 |   std::string Filename = getTok().getString(); | 
| Chris Lattner | 8e25e2d | 2009-07-16 06:14:39 +0000 | [diff] [blame] | 1628 |   SMLoc IncludeLoc = Lexer.getLoc(); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1629 |   Lex(); | 
| Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 1630 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1631 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
| Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 1632 |     return TokError("unexpected token in '.include' directive"); | 
 | 1633 |    | 
| Chris Lattner | 8e25e2d | 2009-07-16 06:14:39 +0000 | [diff] [blame] | 1634 |   // Strip the quotes. | 
 | 1635 |   Filename = Filename.substr(1, Filename.size()-2); | 
 | 1636 |    | 
 | 1637 |   // Attempt to switch the lexer to the included file before consuming the end | 
 | 1638 |   // of statement to avoid losing it when we switch. | 
| Sean Callanan | fd0b028 | 2010-01-21 00:19:58 +0000 | [diff] [blame] | 1639 |   if (EnterIncludeFile(Filename)) { | 
| Sean Callanan | bf2013e | 2010-01-20 23:19:55 +0000 | [diff] [blame] | 1640 |     PrintMessage(IncludeLoc, | 
 | 1641 |                  "Could not find include file '" + Filename + "'", | 
 | 1642 |                  "error"); | 
| Chris Lattner | 8e25e2d | 2009-07-16 06:14:39 +0000 | [diff] [blame] | 1643 |     return true; | 
 | 1644 |   } | 
| Kevin Enderby | 1f049b2 | 2009-07-14 23:21:55 +0000 | [diff] [blame] | 1645 |  | 
 | 1646 |   return false; | 
 | 1647 | } | 
| Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1648 |  | 
 | 1649 | /// ParseDirectiveDarwinDumpOrLoad | 
 | 1650 | ///  ::= ( .dump | .load ) "filename" | 
| Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 1651 | bool AsmParser::ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump) { | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1652 |   if (Lexer.isNot(AsmToken::String)) | 
| Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1653 |     return TokError("expected string in '.dump' or '.load' directive"); | 
 | 1654 |    | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1655 |   Lex(); | 
| Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1656 |  | 
| Daniel Dunbar | 3f87233 | 2009-07-28 16:08:33 +0000 | [diff] [blame] | 1657 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
| Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1658 |     return TokError("unexpected token in '.dump' or '.load' directive"); | 
 | 1659 |    | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1660 |   Lex(); | 
| Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1661 |  | 
| Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 1662 |   // FIXME: If/when .dump and .load are implemented they will be done in the | 
 | 1663 |   // the assembly parser and not have any need for an MCStreamer API. | 
| Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1664 |   if (IsDump) | 
| Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 1665 |     Warning(IDLoc, "ignoring directive .dump for now"); | 
| Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1666 |   else | 
| Kevin Enderby | 5026ae4 | 2009-07-20 20:25:37 +0000 | [diff] [blame] | 1667 |     Warning(IDLoc, "ignoring directive .load for now"); | 
| Kevin Enderby | 6e68cd9 | 2009-07-15 15:30:11 +0000 | [diff] [blame] | 1668 |  | 
 | 1669 |   return false; | 
 | 1670 | } | 
| Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 1671 |  | 
 | 1672 | /// ParseDirectiveIf | 
 | 1673 | /// ::= .if expression | 
 | 1674 | bool AsmParser::ParseDirectiveIf(SMLoc DirectiveLoc) { | 
| Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 1675 |   TheCondStack.push_back(TheCondState); | 
 | 1676 |   TheCondState.TheCond = AsmCond::IfCond; | 
 | 1677 |   if(TheCondState.Ignore) { | 
 | 1678 |     EatToEndOfStatement(); | 
 | 1679 |   } | 
 | 1680 |   else { | 
 | 1681 |     int64_t ExprValue; | 
 | 1682 |     if (ParseAbsoluteExpression(ExprValue)) | 
 | 1683 |       return true; | 
 | 1684 |  | 
 | 1685 |     if (Lexer.isNot(AsmToken::EndOfStatement)) | 
 | 1686 |       return TokError("unexpected token in '.if' directive"); | 
 | 1687 |      | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1688 |     Lex(); | 
| Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 1689 |  | 
 | 1690 |     TheCondState.CondMet = ExprValue; | 
 | 1691 |     TheCondState.Ignore = !TheCondState.CondMet; | 
 | 1692 |   } | 
 | 1693 |  | 
 | 1694 |   return false; | 
 | 1695 | } | 
 | 1696 |  | 
 | 1697 | /// ParseDirectiveElseIf | 
 | 1698 | /// ::= .elseif expression | 
 | 1699 | bool AsmParser::ParseDirectiveElseIf(SMLoc DirectiveLoc) { | 
 | 1700 |   if (TheCondState.TheCond != AsmCond::IfCond && | 
 | 1701 |       TheCondState.TheCond != AsmCond::ElseIfCond) | 
 | 1702 |       Error(DirectiveLoc, "Encountered a .elseif that doesn't follow a .if or " | 
 | 1703 |                           " an .elseif"); | 
 | 1704 |   TheCondState.TheCond = AsmCond::ElseIfCond; | 
 | 1705 |  | 
| Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 1706 |   bool LastIgnoreState = false; | 
 | 1707 |   if (!TheCondStack.empty()) | 
 | 1708 |       LastIgnoreState = TheCondStack.back().Ignore; | 
 | 1709 |   if (LastIgnoreState || TheCondState.CondMet) { | 
 | 1710 |     TheCondState.Ignore = true; | 
 | 1711 |     EatToEndOfStatement(); | 
 | 1712 |   } | 
 | 1713 |   else { | 
 | 1714 |     int64_t ExprValue; | 
 | 1715 |     if (ParseAbsoluteExpression(ExprValue)) | 
 | 1716 |       return true; | 
 | 1717 |  | 
 | 1718 |     if (Lexer.isNot(AsmToken::EndOfStatement)) | 
 | 1719 |       return TokError("unexpected token in '.elseif' directive"); | 
 | 1720 |      | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1721 |     Lex(); | 
| Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 1722 |     TheCondState.CondMet = ExprValue; | 
 | 1723 |     TheCondState.Ignore = !TheCondState.CondMet; | 
 | 1724 |   } | 
 | 1725 |  | 
 | 1726 |   return false; | 
 | 1727 | } | 
 | 1728 |  | 
 | 1729 | /// ParseDirectiveElse | 
 | 1730 | /// ::= .else | 
 | 1731 | bool AsmParser::ParseDirectiveElse(SMLoc DirectiveLoc) { | 
| Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 1732 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
 | 1733 |     return TokError("unexpected token in '.else' directive"); | 
 | 1734 |    | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1735 |   Lex(); | 
| Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 1736 |  | 
 | 1737 |   if (TheCondState.TheCond != AsmCond::IfCond && | 
 | 1738 |       TheCondState.TheCond != AsmCond::ElseIfCond) | 
 | 1739 |       Error(DirectiveLoc, "Encountered a .else that doesn't follow a .if or an " | 
 | 1740 |                           ".elseif"); | 
 | 1741 |   TheCondState.TheCond = AsmCond::ElseCond; | 
 | 1742 |   bool LastIgnoreState = false; | 
 | 1743 |   if (!TheCondStack.empty()) | 
 | 1744 |     LastIgnoreState = TheCondStack.back().Ignore; | 
 | 1745 |   if (LastIgnoreState || TheCondState.CondMet) | 
 | 1746 |     TheCondState.Ignore = true; | 
 | 1747 |   else | 
 | 1748 |     TheCondState.Ignore = false; | 
 | 1749 |  | 
 | 1750 |   return false; | 
 | 1751 | } | 
 | 1752 |  | 
 | 1753 | /// ParseDirectiveEndIf | 
 | 1754 | /// ::= .endif | 
 | 1755 | bool AsmParser::ParseDirectiveEndIf(SMLoc DirectiveLoc) { | 
| Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 1756 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
 | 1757 |     return TokError("unexpected token in '.endif' directive"); | 
 | 1758 |    | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1759 |   Lex(); | 
| Kevin Enderby | c114ed7 | 2009-08-07 22:46:00 +0000 | [diff] [blame] | 1760 |  | 
 | 1761 |   if ((TheCondState.TheCond == AsmCond::NoCond) || | 
 | 1762 |       TheCondStack.empty()) | 
 | 1763 |     Error(DirectiveLoc, "Encountered a .endif that doesn't follow a .if or " | 
 | 1764 |                         ".else"); | 
 | 1765 |   if (!TheCondStack.empty()) { | 
 | 1766 |     TheCondState = TheCondStack.back(); | 
 | 1767 |     TheCondStack.pop_back(); | 
 | 1768 |   } | 
 | 1769 |  | 
 | 1770 |   return false; | 
 | 1771 | } | 
| Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 1772 |  | 
 | 1773 | /// ParseDirectiveFile | 
 | 1774 | /// ::= .file [number] string | 
| Chris Lattner | ebb89b4 | 2009-09-27 21:16:52 +0000 | [diff] [blame] | 1775 | bool AsmParser::ParseDirectiveFile(StringRef, SMLoc DirectiveLoc) { | 
| Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 1776 |   // FIXME: I'm not sure what this is. | 
 | 1777 |   int64_t FileNumber = -1; | 
 | 1778 |   if (Lexer.is(AsmToken::Integer)) { | 
| Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 1779 |     FileNumber = getTok().getIntVal(); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1780 |     Lex(); | 
| Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 1781 |      | 
 | 1782 |     if (FileNumber < 1) | 
 | 1783 |       return TokError("file number less than one"); | 
 | 1784 |   } | 
 | 1785 |  | 
 | 1786 |   if (Lexer.isNot(AsmToken::String)) | 
 | 1787 |     return TokError("unexpected token in '.file' directive"); | 
 | 1788 |    | 
| Chris Lattner | d32e803 | 2010-01-25 19:02:58 +0000 | [diff] [blame] | 1789 |   StringRef Filename = getTok().getString(); | 
 | 1790 |   Filename = Filename.substr(1, Filename.size()-2); | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1791 |   Lex(); | 
| Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 1792 |  | 
 | 1793 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
 | 1794 |     return TokError("unexpected token in '.file' directive"); | 
 | 1795 |  | 
| Chris Lattner | d32e803 | 2010-01-25 19:02:58 +0000 | [diff] [blame] | 1796 |   if (FileNumber == -1) | 
 | 1797 |     Out.EmitFileDirective(Filename); | 
 | 1798 |   else | 
 | 1799 |     Out.EmitDwarfFileDirective(FileNumber, Filename); | 
 | 1800 |    | 
| Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 1801 |   return false; | 
 | 1802 | } | 
 | 1803 |  | 
 | 1804 | /// ParseDirectiveLine | 
 | 1805 | /// ::= .line [number] | 
| Chris Lattner | ebb89b4 | 2009-09-27 21:16:52 +0000 | [diff] [blame] | 1806 | bool AsmParser::ParseDirectiveLine(StringRef, SMLoc DirectiveLoc) { | 
| Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 1807 |   if (Lexer.isNot(AsmToken::EndOfStatement)) { | 
 | 1808 |     if (Lexer.isNot(AsmToken::Integer)) | 
 | 1809 |       return TokError("unexpected token in '.line' directive"); | 
 | 1810 |  | 
| Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 1811 |     int64_t LineNumber = getTok().getIntVal(); | 
| Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 1812 |     (void) LineNumber; | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1813 |     Lex(); | 
| Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 1814 |  | 
 | 1815 |     // FIXME: Do something with the .line. | 
 | 1816 |   } | 
 | 1817 |  | 
 | 1818 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
 | 1819 |     return TokError("unexpected token in '.file' directive"); | 
 | 1820 |  | 
 | 1821 |   return false; | 
 | 1822 | } | 
 | 1823 |  | 
 | 1824 |  | 
 | 1825 | /// ParseDirectiveLoc | 
 | 1826 | /// ::= .loc number [number [number]] | 
| Chris Lattner | ebb89b4 | 2009-09-27 21:16:52 +0000 | [diff] [blame] | 1827 | bool AsmParser::ParseDirectiveLoc(StringRef, SMLoc DirectiveLoc) { | 
| Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 1828 |   if (Lexer.isNot(AsmToken::Integer)) | 
 | 1829 |     return TokError("unexpected token in '.loc' directive"); | 
 | 1830 |  | 
 | 1831 |   // FIXME: What are these fields? | 
| Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 1832 |   int64_t FileNumber = getTok().getIntVal(); | 
| Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 1833 |   (void) FileNumber; | 
 | 1834 |   // FIXME: Validate file. | 
 | 1835 |  | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1836 |   Lex(); | 
| Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 1837 |   if (Lexer.isNot(AsmToken::EndOfStatement)) { | 
 | 1838 |     if (Lexer.isNot(AsmToken::Integer)) | 
 | 1839 |       return TokError("unexpected token in '.loc' directive"); | 
 | 1840 |  | 
| Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 1841 |     int64_t Param2 = getTok().getIntVal(); | 
| Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 1842 |     (void) Param2; | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1843 |     Lex(); | 
| Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 1844 |  | 
 | 1845 |     if (Lexer.isNot(AsmToken::EndOfStatement)) { | 
 | 1846 |       if (Lexer.isNot(AsmToken::Integer)) | 
 | 1847 |         return TokError("unexpected token in '.loc' directive"); | 
 | 1848 |  | 
| Sean Callanan | 18b8323 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 1849 |       int64_t Param3 = getTok().getIntVal(); | 
| Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 1850 |       (void) Param3; | 
| Sean Callanan | 79ed1a8 | 2010-01-19 20:22:31 +0000 | [diff] [blame] | 1851 |       Lex(); | 
| Daniel Dunbar | d0c14d6 | 2009-08-11 04:24:50 +0000 | [diff] [blame] | 1852 |  | 
 | 1853 |       // FIXME: Do something with the .loc. | 
 | 1854 |     } | 
 | 1855 |   } | 
 | 1856 |  | 
 | 1857 |   if (Lexer.isNot(AsmToken::EndOfStatement)) | 
 | 1858 |     return TokError("unexpected token in '.file' directive"); | 
 | 1859 |  | 
 | 1860 |   return false; | 
 | 1861 | } | 
 | 1862 |  |