2009-06-22 04:16:42 +08: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-06-30 08:33:19 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2009-06-22 04:16:42 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2009-06-30 04:37:27 +08:00
|
|
|
class AsmExpr;
|
2009-06-24 12:31:49 +08:00
|
|
|
class MCContext;
|
2009-06-24 02:41:30 +08:00
|
|
|
class MCInst;
|
2009-06-24 08:52:40 +08:00
|
|
|
class MCStreamer;
|
2009-06-30 09:49:52 +08:00
|
|
|
class MCValue;
|
|
|
|
|
2009-06-22 04:16:42 +08:00
|
|
|
class AsmParser {
|
|
|
|
AsmLexer Lexer;
|
2009-06-24 12:31:49 +08:00
|
|
|
MCContext &Ctx;
|
2009-06-24 08:52:40 +08:00
|
|
|
MCStreamer &Out;
|
|
|
|
|
2009-06-22 09:29:09 +08:00
|
|
|
struct X86Operand;
|
2009-06-22 04:16:42 +08:00
|
|
|
|
|
|
|
public:
|
2009-06-24 12:31:49 +08:00
|
|
|
AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr)
|
|
|
|
: Lexer(SM), Ctx(ctx), Out(OutStr) {}
|
2009-06-22 04:16:42 +08:00
|
|
|
~AsmParser() {}
|
|
|
|
|
|
|
|
bool Run();
|
|
|
|
|
2009-06-22 04:54:55 +08:00
|
|
|
private:
|
|
|
|
bool ParseStatement();
|
2009-06-30 08:49:23 +08:00
|
|
|
|
|
|
|
void Warning(SMLoc L, const char *Msg);
|
2009-06-22 05:22:11 +08:00
|
|
|
bool Error(SMLoc L, const char *Msg);
|
|
|
|
bool TokError(const char *Msg);
|
2009-06-22 09:29:09 +08:00
|
|
|
|
|
|
|
void EatToEndOfStatement();
|
|
|
|
|
2009-06-26 05:56:11 +08:00
|
|
|
bool ParseAssignment(const char *Name, bool IsDotSet);
|
2009-06-30 04:37:27 +08:00
|
|
|
|
|
|
|
/// ParseExpression - Parse a general assembly expression.
|
|
|
|
///
|
|
|
|
/// @param Res - The resulting expression. The pointer value is null on error.
|
|
|
|
/// @result - False on success.
|
|
|
|
bool ParseExpression(AsmExpr *&Res);
|
2009-06-30 09:49:52 +08:00
|
|
|
|
|
|
|
/// ParseAbsoluteExpression - Parse an expression which must evaluate to an
|
|
|
|
/// absolute value.
|
2009-06-30 04:37:27 +08:00
|
|
|
///
|
|
|
|
/// @param Res - The value of the absolute expression. The result is undefined
|
|
|
|
/// on error.
|
|
|
|
/// @result - False on success.
|
|
|
|
bool ParseAbsoluteExpression(int64_t &Res);
|
|
|
|
|
2009-06-30 09:49:52 +08:00
|
|
|
/// ParseRelocatableExpression - Parse an expression which must be
|
|
|
|
/// relocatable.
|
|
|
|
///
|
|
|
|
/// @param Res - The relocatable expression value. The result is undefined on
|
|
|
|
/// error.
|
|
|
|
/// @result - False on success.
|
|
|
|
bool ParseRelocatableExpression(MCValue &Res);
|
|
|
|
|
2009-06-30 04:37:27 +08:00
|
|
|
bool ParsePrimaryExpr(AsmExpr *&Res);
|
|
|
|
bool ParseBinOpRHS(unsigned Precedence, AsmExpr *&Res);
|
|
|
|
bool ParseParenExpr(AsmExpr *&Res);
|
2009-06-24 02:41:30 +08:00
|
|
|
|
|
|
|
// X86 specific.
|
|
|
|
bool ParseX86InstOperands(MCInst &Inst);
|
|
|
|
bool ParseX86Operand(X86Operand &Op);
|
|
|
|
bool ParseX86MemOperand(X86Operand &Op);
|
2009-06-24 12:43:34 +08:00
|
|
|
|
|
|
|
// Directive Parsing.
|
2009-06-24 13:13:15 +08:00
|
|
|
bool ParseDirectiveDarwinSection(); // Darwin specific ".section".
|
|
|
|
bool ParseDirectiveSectionSwitch(const char *Section,
|
|
|
|
const char *Directives = 0);
|
2009-06-25 07:30:00 +08:00
|
|
|
bool ParseDirectiveAscii(bool ZeroTerminated); // ".ascii", ".asciiz"
|
|
|
|
bool ParseDirectiveValue(unsigned Size); // ".byte", ".long", ...
|
|
|
|
bool ParseDirectiveFill(); // ".fill"
|
|
|
|
bool ParseDirectiveSpace(); // ".space"
|
2009-06-26 05:56:11 +08:00
|
|
|
bool ParseDirectiveSet(); // ".set"
|
2009-06-26 06:44:51 +08:00
|
|
|
bool ParseDirectiveOrg(); // ".org"
|
2009-06-30 07:46:59 +08:00
|
|
|
// ".align{,32}", ".p2align{,w,l}"
|
|
|
|
bool ParseDirectiveAlign(bool IsPow2, unsigned ValueSize);
|
2009-06-30 08:33:19 +08: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-06-24 12:43:34 +08:00
|
|
|
|
2009-06-22 04:16:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|