mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-28 06:29:45 +00:00
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81416 91177308-0d34-0410-b5e6-96231b3b80d8
160 lines
5.1 KiB
C++
160 lines
5.1 KiB
C++
//===- 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
|
|
|
|
#include <vector>
|
|
#include "AsmLexer.h"
|
|
#include "AsmCond.h"
|
|
#include "llvm/MC/MCAsmParser.h"
|
|
#include "llvm/MC/MCSectionMachO.h"
|
|
#include "llvm/MC/MCStreamer.h"
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
|
|
namespace llvm {
|
|
class AsmCond;
|
|
class MCContext;
|
|
class MCExpr;
|
|
class MCInst;
|
|
class MCStreamer;
|
|
class MCAsmInfo;
|
|
class MCValue;
|
|
class TargetAsmParser;
|
|
class Twine;
|
|
|
|
class AsmParser : public MCAsmParser {
|
|
private:
|
|
AsmLexer Lexer;
|
|
MCContext &Ctx;
|
|
MCStreamer &Out;
|
|
TargetAsmParser *TargetParser;
|
|
|
|
AsmCond TheCondState;
|
|
std::vector<AsmCond> TheCondStack;
|
|
|
|
// FIXME: Figure out where this should leave, the code is a copy of that which
|
|
// is also used by TargetLoweringObjectFile.
|
|
mutable void *SectionUniquingMap;
|
|
|
|
public:
|
|
AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out,
|
|
const MCAsmInfo &_MAI)
|
|
: Lexer(_SM, _MAI), Ctx(_Ctx), Out(_Out), TargetParser(0),
|
|
SectionUniquingMap(0) {}
|
|
~AsmParser();
|
|
|
|
bool Run();
|
|
|
|
public:
|
|
TargetAsmParser &getTargetParser() const { return *TargetParser; }
|
|
void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
|
|
|
|
/// @name MCAsmParser Interface
|
|
/// {
|
|
|
|
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);
|
|
|
|
virtual bool ParseExpression(const MCExpr *&Res);
|
|
|
|
virtual bool ParseParenExpression(const MCExpr *&Res);
|
|
|
|
virtual bool ParseAbsoluteExpression(int64_t &Res);
|
|
|
|
/// }
|
|
|
|
private:
|
|
MCSymbol *CreateSymbol(StringRef Name);
|
|
|
|
// FIXME: See comment on SectionUniquingMap.
|
|
const MCSection *getMachOSection(const StringRef &Segment,
|
|
const StringRef &Section,
|
|
unsigned TypeAndAttributes,
|
|
unsigned Reserved2,
|
|
SectionKind Kind) const;
|
|
|
|
bool ParseStatement();
|
|
|
|
bool TokError(const char *Msg);
|
|
|
|
bool ParseConditionalAssemblyDirectives(StringRef Directive,
|
|
SMLoc DirectiveLoc);
|
|
void EatToEndOfStatement();
|
|
|
|
bool ParseAssignment(const StringRef &Name);
|
|
|
|
bool ParsePrimaryExpr(const MCExpr *&Res);
|
|
bool ParseBinOpRHS(unsigned Precedence, const MCExpr *&Res);
|
|
bool ParseParenExpr(const MCExpr *&Res);
|
|
|
|
/// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
|
|
/// and set \arg Res to the identifier contents.
|
|
bool ParseIdentifier(StringRef &Res);
|
|
|
|
// Directive Parsing.
|
|
bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
|
|
bool ParseDirectiveSectionSwitch(const char *Segment, const char *Section,
|
|
unsigned TAA = 0, unsigned ImplicitAlign = 0,
|
|
unsigned StubSize = 0);
|
|
bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
|
|
bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
|
|
bool ParseDirectiveFill(); // ".fill"
|
|
bool ParseDirectiveSpace(); // ".space"
|
|
bool ParseDirectiveSet(); // ".set"
|
|
bool ParseDirectiveOrg(); // ".org"
|
|
// ".align{,32}", ".p2align{,w,l}"
|
|
bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
|
|
|
|
/// ParseDirectiveSymbolAttribute - Parse a directive like ".globl" which
|
|
/// accepts a single symbol (which should be a label or an external).
|
|
bool ParseDirectiveSymbolAttribute(MCStreamer::SymbolAttr Attr);
|
|
bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
|
|
bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
|
|
|
|
bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
|
|
bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
|
|
|
|
// Darwin specific ".subsections_via_symbols"
|
|
bool ParseDirectiveDarwinSubsectionsViaSymbols();
|
|
// Darwin specific .dump and .load
|
|
bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump);
|
|
|
|
bool ParseDirectiveAbort(); // ".abort"
|
|
bool ParseDirectiveInclude(); // ".include"
|
|
|
|
bool ParseDirectiveIf(SMLoc DirectiveLoc); // ".if"
|
|
bool ParseDirectiveElseIf(SMLoc DirectiveLoc); // ".elseif"
|
|
bool ParseDirectiveElse(SMLoc DirectiveLoc); // ".else"
|
|
bool ParseDirectiveEndIf(SMLoc DirectiveLoc); // .endif
|
|
|
|
bool ParseDirectiveFile(SMLoc DirectiveLoc); // ".file"
|
|
bool ParseDirectiveLine(SMLoc DirectiveLoc); // ".line"
|
|
bool ParseDirectiveLoc(SMLoc DirectiveLoc); // ".loc"
|
|
|
|
/// ParseEscapedString - Parse the current token as a string which may include
|
|
/// escaped characters and return the string contents.
|
|
bool ParseEscapedString(std::string &Data);
|
|
};
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif
|