2009-06-21 20:16:42 +00: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
|
|
|
|
|
|
|
|
#include "AsmLexer.h"
|
2009-07-20 18:55:04 +00:00
|
|
|
#include "llvm/MC/MCAsmParser.h"
|
2009-06-30 00:33:19 +00:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2009-06-21 20:16:42 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2009-06-29 20:37:27 +00:00
|
|
|
class AsmExpr;
|
2009-06-24 04:31:49 +00:00
|
|
|
class MCContext;
|
2009-06-23 18:41:30 +00:00
|
|
|
class MCInst;
|
2009-06-24 00:52:40 +00:00
|
|
|
class MCStreamer;
|
2009-06-30 01:49:52 +00:00
|
|
|
class MCValue;
|
2009-07-20 20:01:54 +00:00
|
|
|
class TargetAsmParser;
|
2009-07-27 23:20:52 +00:00
|
|
|
class Twine;
|
2009-06-30 01:49:52 +00:00
|
|
|
|
2009-07-28 20:47:52 +00:00
|
|
|
class AsmParser : public MCAsmParser {
|
2009-06-30 23:38:38 +00:00
|
|
|
private:
|
2009-06-21 20:16:42 +00:00
|
|
|
AsmLexer Lexer;
|
2009-06-24 04:31:49 +00:00
|
|
|
MCContext &Ctx;
|
2009-06-24 00:52:40 +00:00
|
|
|
MCStreamer &Out;
|
2009-07-28 20:47:52 +00:00
|
|
|
TargetAsmParser *TargetParser;
|
2009-06-24 00:52:40 +00:00
|
|
|
|
2009-06-21 20:16:42 +00:00
|
|
|
public:
|
2009-07-28 20:47:52 +00:00
|
|
|
AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out)
|
|
|
|
: Lexer(_SM), Ctx(_Ctx), Out(_Out), TargetParser(0) {}
|
2009-06-21 20:16:42 +00:00
|
|
|
~AsmParser() {}
|
2009-07-28 20:47:52 +00:00
|
|
|
|
2009-06-21 20:16:42 +00:00
|
|
|
bool Run();
|
|
|
|
|
2009-07-20 18:55:04 +00:00
|
|
|
public:
|
2009-07-28 20:47:52 +00:00
|
|
|
TargetAsmParser &getTargetParser() const { return *TargetParser; }
|
|
|
|
void setTargetParser(TargetAsmParser &P) { TargetParser = &P; }
|
2009-07-20 18:55:04 +00:00
|
|
|
|
2009-07-28 22:22:31 +00:00
|
|
|
/// @name MCAsmParser Interface
|
|
|
|
/// {
|
|
|
|
|
2009-07-20 20:01:54 +00:00
|
|
|
virtual MCAsmLexer &getLexer() { return Lexer; }
|
|
|
|
|
2009-07-28 22:22:31 +00:00
|
|
|
virtual void Warning(SMLoc L, const Twine &Meg);
|
|
|
|
|
|
|
|
virtual bool Error(SMLoc L, const Twine &Msg);
|
|
|
|
|
|
|
|
virtual bool ParseExpression(AsmExpr *&Res);
|
|
|
|
|
|
|
|
virtual bool ParseAbsoluteExpression(int64_t &Res);
|
|
|
|
|
|
|
|
virtual bool ParseRelocatableExpression(MCValue &Res);
|
|
|
|
|
|
|
|
/// }
|
|
|
|
|
2009-06-21 20:54:55 +00:00
|
|
|
private:
|
|
|
|
bool ParseStatement();
|
2009-06-30 00:49:23 +00:00
|
|
|
|
2009-06-21 21:22:11 +00:00
|
|
|
bool TokError(const char *Msg);
|
2009-06-22 01:29:09 +00:00
|
|
|
|
|
|
|
void EatToEndOfStatement();
|
|
|
|
|
2009-07-27 21:49:56 +00:00
|
|
|
bool ParseAssignment(const StringRef &Name, bool IsDotSet);
|
2009-06-29 20:37:27 +00:00
|
|
|
|
2009-07-02 02:09:07 +00:00
|
|
|
/// ParseParenRelocatableExpression - Parse an expression which must be
|
|
|
|
/// relocatable, assuming that an initial '(' has already been consumed.
|
|
|
|
///
|
|
|
|
/// @param Res - The relocatable expression value. The result is undefined on
|
|
|
|
/// error.
|
|
|
|
/// @result - False on success.
|
|
|
|
///
|
|
|
|
/// @see ParseRelocatableExpression, ParseParenExpr.
|
|
|
|
bool ParseParenRelocatableExpression(MCValue &Res);
|
|
|
|
|
2009-06-29 20:37:27 +00:00
|
|
|
bool ParsePrimaryExpr(AsmExpr *&Res);
|
|
|
|
bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
|
|
|
|
bool ParseParenExpr(AsmExpr *&Res);
|
2009-06-23 18:41:30 +00:00
|
|
|
|
2009-06-24 04:43:34 +00:00
|
|
|
// Directive Parsing.
|
2009-06-24 05:13:15 +00:00
|
|
|
bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
|
|
|
|
bool ParseDirectiveSectionSwitch(const char *Section,
|
|
|
|
const char *Directives = 0);
|
2009-06-24 23:30:00 +00:00
|
|
|
bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
|
|
|
|
bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
|
|
|
|
bool ParseDirectiveFill(); // ".fill"
|
|
|
|
bool ParseDirectiveSpace(); // ".space"
|
2009-06-25 21:56:11 +00:00
|
|
|
bool ParseDirectiveSet(); // ".set"
|
2009-06-25 22:44:51 +00:00
|
|
|
bool ParseDirectiveOrg(); // ".org"
|
2009-06-29 23:46:59 +00:00
|
|
|
// ".align{,32}", ".p2align{,w,l}"
|
|
|
|
bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
|
2009-06-30 00:33:19 +00: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 18:17:10 +00:00
|
|
|
bool ParseDirectiveDarwinSymbolDesc(); // Darwin specific ".desc"
|
2009-07-14 21:35:03 +00:00
|
|
|
bool ParseDirectiveDarwinLsym(); // Darwin specific ".lsym"
|
2009-07-07 20:30:46 +00:00
|
|
|
|
2009-07-09 17:25:12 +00:00
|
|
|
bool ParseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
|
2009-07-10 22:20:30 +00:00
|
|
|
bool ParseDirectiveDarwinZerofill(); // Darwin specific ".zerofill"
|
2009-07-13 21:03:15 +00:00
|
|
|
|
|
|
|
// Darwin specific ".subsections_via_symbols"
|
|
|
|
bool ParseDirectiveDarwinSubsectionsViaSymbols();
|
2009-07-15 15:30:11 +00:00
|
|
|
// Darwin specific .dump and .load
|
2009-07-20 20:25:37 +00:00
|
|
|
bool ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump);
|
2009-07-13 23:15:14 +00:00
|
|
|
|
|
|
|
bool ParseDirectiveAbort(); // ".abort"
|
2009-07-14 23:21:55 +00:00
|
|
|
bool ParseDirectiveInclude(); // ".include"
|
2009-06-21 20:16:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|