summaryrefslogtreecommitdiffstats
path: root/lld/ELF/ScriptParser.h
blob: 7878bffee09ccffef4b2275d5f7e9ac335c8e445 (plain)
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
//===- ScriptParser.h -------------------------------------------*- C++ -*-===//
//
//                             The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef LLD_ELF_SCRIPT_PARSER_H
#define LLD_ELF_SCRIPT_PARSER_H

#include "lld/Core/LLVM.h"
#include "llvm/ADT/StringRef.h"
#include <vector>

namespace lld {
namespace elf {

class ScriptParserBase {
public:
  ScriptParserBase(StringRef S) : Input(S), Tokens(tokenize(S)) {}
  ScriptParserBase(std::vector<StringRef> Tokens) : Input(""), Tokens(Tokens) {}

protected:
  void setError(const Twine &Msg);
  static std::vector<StringRef> tokenize(StringRef S);
  static StringRef skipSpace(StringRef S);
  bool atEOF();
  StringRef next();
  StringRef peek();
  bool skip(StringRef Tok);
  void expect(StringRef Expect);

  size_t getPos();
  void printErrorPos();

  std::vector<uint8_t> parseHex(StringRef S);

  StringRef Input;
  std::vector<StringRef> Tokens;
  size_t Pos = 0;
  bool Error = false;
};

} // namespace elf
} // namespace lld

#endif
OpenPOWER on IntegriCloud