aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Target/TargetAsmLexer.h
blob: 9fcf449a86cdd6f0499179d0750621fea7697c1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//===-- llvm/Target/TargetAsmLexer.h - Target Assembly Lexer ----*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TARGET_TARGETASMLEXER_H
#define LLVM_TARGET_TARGETASMLEXER_H

#include "llvm/MC/MCParser/MCAsmLexer.h"

namespace llvm {
class Target;
  
/// TargetAsmLexer - Generic interface to target specific assembly lexers.
class TargetAsmLexer {
  /// The current token
  AsmToken CurTok;
  
  /// The location and description of the current error
  SMLoc ErrLoc;
  std::string Err;
  
  TargetAsmLexer(const TargetAsmLexer &);   // DO NOT IMPLEMENT
  void operator=(const TargetAsmLexer &);  // DO NOT IMPLEMENT
protected: // Can only create subclasses.
  TargetAsmLexer(const Target &);
  
  virtual AsmToken LexToken() = 0;
  
  void SetError(const SMLoc &errLoc, const std::string &err) {
    ErrLoc = errLoc;
    Err = err;
  }
  
  /// TheTarget - The Target that this machine was created for.
  const Target &TheTarget;
  MCAsmLexer *Lexer;
  
public:
  virtual ~TargetAsmLexer();
  
  const Target &getTarget() const { return TheTarget; }
  
  /// InstallLexer - Set the lexer to get tokens from lower-level lexer \arg L.
  void InstallLexer(MCAsmLexer &L) {
    Lexer = &L;
  }
  
  MCAsmLexer *getLexer() {
    return Lexer;
  }
  
  /// Lex - Consume the next token from the input stream and return it.
  const AsmToken &Lex() {
    return CurTok = LexToken();
  }
  
  /// getTok - Get the current (last) lexed token.
  const AsmToken &getTok() {
    return CurTok;
  }
  
  /// getErrLoc - Get the current error location
  const SMLoc &getErrLoc() {
    return ErrLoc;
  }
  
  /// getErr - Get the current error string
  const std::string &getErr() {
    return Err;
  }
  
  /// getKind - Get the kind of current token.
  AsmToken::TokenKind getKind() const { return CurTok.getKind(); }
  
  /// is - Check if the current token has kind \arg K.
  bool is(AsmToken::TokenKind K) const { return CurTok.is(K); }
  
  /// isNot - Check if the current token has kind \arg K.
  bool isNot(AsmToken::TokenKind K) const { return CurTok.isNot(K); }
};

} // End llvm namespace

#endif