2009-06-21 22:16:42 +02:00
|
|
|
//===- AsmParser.h - Parser for Assembly Files ------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This class declares the parser for assembly files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef ASMPARSER_H
|
|
|
|
#define ASMPARSER_H
|
|
|
|
|
2009-08-08 00:46:00 +02:00
|
|
|
#include <vector>
|
2009-06-21 22:16:42 +02:00
|
|
|
#include "AsmLexer.h"
|
2009-08-08 00:46:00 +02:00
|
|
|
#include "AsmCond.h"
|
2009-07-20 20:55:04 +02:00
|
|
|
#include "llvm/MC/MCAsmParser.h"
|
2009-08-27 00:49:51 +02:00
|
|
|
#include "llvm/MC/MCSectionMachO.h"
|
2009-06-30 02:33:19 +02:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2009-09-04 23:45:34 +02:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2009-09-27 23:16:52 +02:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2009-06-21 22:16:42 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
2009-08-08 00:46:00 +02:00
|
|
|
class AsmCond;
|
2009-06-24 06:31:49 +02:00
|
|
|
class MCContext;
|
2009-08-31 10:06:59 +02:00
|
|
|
class MCExpr;
|
2009-06-23 20:41:30 +02:00
|
|
|
class MCInst;
|
2009-06-24 02:52:40 +02:00
|
|
|
class MCStreamer;
|
2009-09-04 23:45:34 +02:00
|
|
|
class MCAsmInfo;
|
2009-06-30 03:49:52 +02:00
|
|
|
class MCValue;
|
2009-07-20 22:01:54 +02:00
|
|
|
class TargetAsmParser;
|
2009-07-28 01:20:52 +02:00
|
|
|
class Twine;
|
2009-06-30 03:49:52 +02:00
|
|
|
|
2009-07-28 22:47:52 +02:00
|
|
|
class AsmParser : public MCAsmParser {
|
2009-07-01 01:38:38 +02:00
|
|
|
private:
|
2009-06-21 22:16:42 +02:00
|
|
|
AsmLexer Lexer;
|
2009-06-24 06:31:49 +02:00
|
|
|
MCContext &Ctx;
|
2009-06-24 02:52:40 +02:00
|
|
|
MCStreamer &Out;
|
2009-07-28 22:47:52 +02:00
|
|
|
TargetAsmParser *TargetParser;
|
2009-08-08 00:46:00 +02:00
|
|
|
|
|
|
|
AsmCond TheCondState;
|
|
|
|
std::vector<AsmCond> TheCondStack;
|
|
|
|
|
2009-08-27 00:49:51 +02:00
|
|
|
// FIXME: Figure out where this should leave, the code is a copy of that which
|
|
|
|
// is also used by TargetLoweringObjectFile.
|
|
|
|
mutable void *SectionUniquingMap;
|
|
|
|
|
2009-09-27 23:16:52 +02:00
|
|
|
/// DirectiveMap - This is a table handlers for directives. Each handler is
|
|
|
|
/// invoked after the directive identifier is read and is responsible for
|
|
|
|
/// parsing and validating the rest of the directive. The handler is passed
|
|
|
|
/// in the directive name and the location of the directive keyword.
|
|
|
|
StringMap<bool(AsmParser::*)(StringRef, SMLoc)> DirectiveMap;
|
2009-06-21 22:16:42 +02:00
|
|
|
public:
|
2009-09-04 23:45:34 +02:00
|
|
|
AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out,
|
2009-09-27 23:16:52 +02:00
|
|
|
const MCAsmInfo &_MAI);
|
2009-08-27 00:49:51 +02:00
|
|
|
~AsmParser();
|
2009-07-28 22:47:52 +02:00
|
|
|
|
2009-06-21 22:16:42 +02:00
|
|
|
bool Run();
|
2009-09-27 23:16:52 +02:00
|
|
|
|
2009-06-21 22:16:42 +02:00
|
|
|
|
2009-09-27 23:16:52 +02:00
|
|
|
void AddDirectiveHandler(StringRef Directive,
|
|
|
|
bool (AsmParser::*Handler)(StringRef, SMLoc)) {
|
|
|
|
DirectiveMap[Directive] = Handler;
|
|
|
|
}
|
2009-07-20 20:55:04 +02:00
|
|
|
public:
|
2009-07-28 22:47:52 +02:00
|
|
|
TargetAsmParser &getTargetParser() const { return *TargetParser; }
|
|
|
|
void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
|
2009-07-20 20:55:04 +02:00
|
|
|
|
2009-07-29 00:22:31 +02:00
|
|
|
/// @name MCAsmParser Interface
|
|
|
|
/// {
|
|
|
|
|
2009-07-20 22:01:54 +02:00
|
|
|
virtual MCAsmLexer &getLexer() { return Lexer; }
|
2009-08-31 10:07:44 +02:00
|
|
|
virtual MCContext &getContext() { return Ctx; }
|
2009-09-10 02:59:15 +02:00
|
|
|
virtual MCStreamer &getStreamer() { return Out; }
|
|
|
|
|
2009-07-29 00:22:31 +02:00
|
|
|
virtual void Warning(SMLoc L, const Twine &Meg);
|
|
|
|
virtual bool Error(SMLoc L, const Twine &Msg);
|
|
|
|
|
2009-08-31 10:07:22 +02:00
|
|
|
virtual bool ParseExpression(const MCExpr *&Res);
|
2009-08-31 10:08:17 +02:00
|
|
|
virtual bool ParseParenExpression(const MCExpr *&Res);
|
2009-07-29 00:22:31 +02:00
|
|
|
virtual bool ParseAbsoluteExpression(int64_t &Res);
|
|
|
|
|
|
|
|
/// }
|
|
|
|
|
2009-06-21 22:54:55 +02:00
|
|
|
private:
|
2009-08-27 00:13:22 +02:00
|
|
|
MCSymbol *CreateSymbol(StringRef Name);
|
|
|
|
|
2009-08-27 00:49:51 +02:00
|
|
|
// FIXME: See comment on SectionUniquingMap.
|
|
|
|
const MCSection *getMachOSection(const StringRef &Segment,
|
|
|
|
const StringRef &Section,
|
|
|
|
unsigned TypeAndAttributes,
|
|
|
|
unsigned Reserved2,
|
|
|
|
SectionKind Kind) const;
|
|
|
|
|
2009-06-21 22:54:55 +02:00
|
|
|
bool ParseStatement();
|
2009-06-30 02:49:23 +02:00
|
|
|
|
2009-06-21 23:22:11 +02:00
|
|
|
bool TokError(const char *Msg);
|
2009-06-22 03:29:09 +02:00
|
|
|
|
2009-08-08 00:46:00 +02:00
|
|
|
bool ParseConditionalAssemblyDirectives(StringRef Directive,
|
|
|
|
SMLoc DirectiveLoc);
|
2009-06-22 03:29:09 +02:00
|
|
|
void EatToEndOfStatement();
|
|
|
|
|
2009-08-31 10:09:09 +02:00
|
|
|
bool ParseAssignment(const StringRef &Name);
|
2009-06-29 22:37:27 +02:00
|
|
|
|
2009-08-31 10:07:22 +02:00
|
|
|
bool ParsePrimaryExpr(const MCExpr *&Res);
|
|
|
|
bool ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res);
|
|
|
|
bool ParseParenExpr(const MCExpr *&Res);
|
2009-08-01 02:48:30 +02:00
|
|
|
|
|
|
|
/// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
|
|
|
|
/// and set \arg Res to the identifier contents.
|
|
|
|
bool ParseIdentifier(StringRef &Res);
|
2009-06-23 20:41:30 +02:00
|
|
|
|
2009-06-24 06:43:34 +02:00
|
|
|
// Directive Parsing.
|
2009-06-24 07:13:15 +02:00
|
|
|
bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
|
2009-08-10 03:39:42 +02:00
|
|
|
bool ParseDirectiveSectionSwitch(const char *Segment, const char *Section,
|
2009-08-21 10:34:18 +02:00
|
|
|
unsigned TAA = 0, unsigned ImplicitAlign = 0,
|
|
|
|
unsigned StubSize = 0);
|
2009-06-25 01:30:00 +02:00
|
|
|
bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
|
|
|
|
bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
|
|
|
|
bool ParseDirectiveFill(); // ".fill"
|
|
|
|
bool ParseDirectiveSpace(); // ".space"
|
2009-06-25 23:56:11 +02:00
|
|
|
bool ParseDirectiveSet(); // ".set"
|
2009-06-26 00:44:51 +02:00
|
|
|
bool ParseDirectiveOrg(); // ".org"
|
2009-06-30 01:46:59 +02:00
|
|
|
// ".align{,32}", ".p2align{,w,l}"
|
|
|
|
bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
|
2009-06-30 02:33:19 +02:00
|
|
|
|
|
|
|
/// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
|
|
|
|
/// accepts a single symbol (which should be a label or an external).
|
|
|
|
bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
|
2009-07-14 20:17:10 +02:00
|
|
|
bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
|
2009-07-14 23:35:03 +02:00
|
|
|
bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
|
2009-07-07 22:30:46 +02:00
|
|
|
|
2009-07-09 19:25:12 +02:00
|
|
|
bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
|
2009-07-11 00:20:30 +02:00
|
|
|
bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
|
2009-07-13 23:03:15 +02:00
|
|
|
|
|
|
|
// Darwin specific ".subsections_via_symbols"
|
|
|
|
bool ParseDirectiveDarwinSubsectionsViaSymbols();
|
2009-07-15 17:30:11 +02:00
|
|
|
// Darwin specific .dump and .load
|
2009-07-20 22:25:37 +02:00
|
|
|
bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump);
|
2009-07-14 01:15:14 +02:00
|
|
|
|
|
|
|
bool ParseDirectiveAbort(); // ".abort"
|
2009-07-15 01:21:55 +02:00
|
|
|
bool ParseDirectiveInclude(); // ".include"
|
2009-08-08 00:46:00 +02:00
|
|
|
|
|
|
|
bool ParseDirectiveIf(SMLoc DirectiveLoc); // ".if"
|
|
|
|
bool ParseDirectiveElseIf(SMLoc DirectiveLoc); // ".elseif"
|
|
|
|
bool ParseDirectiveElse(SMLoc DirectiveLoc); // ".else"
|
|
|
|
bool ParseDirectiveEndIf(SMLoc DirectiveLoc); // .endif
|
|
|
|
|
2009-09-27 23:16:52 +02:00
|
|
|
bool ParseDirectiveFile(StringRef, SMLoc DirectiveLoc); // ".file"
|
|
|
|
bool ParseDirectiveLine(StringRef, SMLoc DirectiveLoc); // ".line"
|
|
|
|
bool ParseDirectiveLoc(StringRef, SMLoc DirectiveLoc); // ".loc"
|
2009-08-14 20:19:52 +02:00
|
|
|
|
|
|
|
/// ParseEscapedString - Parse the current token as a string which may include
|
|
|
|
/// escaped characters and return the string contents.
|
|
|
|
bool ParseEscapedString(std::string &Data);
|
2009-06-21 22:16:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|