#ifndef ASMPARSER_H
#define ASMPARSER_H
#include <vector>
#include "llvm/MC/MCParser/AsmLexer.h"
#include "llvm/MC/MCParser/AsmCond.h"
#include "llvm/MC/MCParser/MCAsmParser.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/ADT/StringMap.h"
namespace llvm {
class AsmCond;
class AsmToken;
class MCContext;
class MCExpr;
class MCInst;
class MCStreamer;
class MCAsmInfo;
class SourceMgr;
class TargetAsmParser;
class Twine;
class AsmParser : public MCAsmParser {
private:
AsmLexer Lexer;
MCContext &Ctx;
MCStreamer &Out;
SourceMgr &SrcMgr;
TargetAsmParser *TargetParser;
int CurBuffer;
AsmCond TheCondState;
std::vector<AsmCond> TheCondStack;
mutable void *SectionUniquingMap;
StringMap<bool(AsmParser::*)(StringRef, SMLoc)> DirectiveMap;
public:
AsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
const MCAsmInfo &MAI);
~AsmParser();
bool Run(bool NoInitialTextSection);
void AddDirectiveHandler(StringRef Directive,
bool (AsmParser::*Handler)(StringRef, SMLoc)) {
DirectiveMap[Directive] = Handler;
}
public:
TargetAsmParser &getTargetParser() const { return *TargetParser; }
void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
virtual MCAsmLexer &getLexer() { return Lexer; }
virtual MCContext &getContext() { return Ctx; }
virtual MCStreamer &getStreamer() { return Out; }
virtual void Warning(SMLoc L, const Twine &Meg);
virtual bool Error(SMLoc L, const Twine &Msg);
const AsmToken &Lex();
bool ParseExpression(const MCExpr *&Res);
virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc);
virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc);
virtual bool ParseAbsoluteExpression(int64_t &Res);
private:
MCSymbol *CreateSymbol(StringRef Name);
const MCSection *getMachOSection(const StringRef &Segment,
const StringRef &Section,
unsigned TypeAndAttributes,
unsigned Reserved2,
SectionKind Kind) const;
bool ParseStatement();
bool TokError(const char *Msg);
void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const;
bool EnterIncludeFile(const std::string &Filename);
bool ParseConditionalAssemblyDirectives(StringRef Directive,
SMLoc DirectiveLoc);
void EatToEndOfStatement();
bool ParseAssignment(const StringRef &Name);
bool ParsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc);
bool ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res, SMLoc &EndLoc);
bool ParseParenExpr(const MCExpr *&Res, SMLoc &EndLoc);
bool ParseIdentifier(StringRef &Res);
bool ParseDirectiveDarwinSection(); bool ParseDirectiveSectionSwitch(const char *Segment, const char *Section,
unsigned TAA = 0, unsigned ImplicitAlign = 0,
unsigned StubSize = 0);
bool ParseDirectiveAscii(bool ZeroTerminated); bool ParseDirectiveValue(unsigned Size); bool ParseDirectiveFill(); bool ParseDirectiveSpace(); bool ParseDirectiveSet(); bool ParseDirectiveOrg(); bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
bool ParseDirectiveSymbolAttribute(MCSymbolAttr Attr);
bool ParseDirectiveDarwinSymbolDesc(); bool ParseDirectiveDarwinLsym();
bool ParseDirectiveComm(bool IsLocal); bool ParseDirectiveDarwinZerofill(); bool ParseDirectiveDarwinTBSS();
bool ParseDirectiveDarwinSubsectionsViaSymbols();
bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump);
bool ParseDirectiveAbort(); bool ParseDirectiveInclude();
bool ParseDirectiveIf(SMLoc DirectiveLoc); bool ParseDirectiveElseIf(SMLoc DirectiveLoc); bool ParseDirectiveElse(SMLoc DirectiveLoc); bool ParseDirectiveEndIf(SMLoc DirectiveLoc);
bool ParseDirectiveFile(StringRef, SMLoc DirectiveLoc); bool ParseDirectiveLine(StringRef, SMLoc DirectiveLoc); bool ParseDirectiveLoc(StringRef, SMLoc DirectiveLoc);
bool ParseEscapedString(std::string &Data);
};
}
#endif