xref: /freebsd/contrib/llvm-project/lld/ELF/ScriptLexer.h (revision 3c4ba5f55438f7afd4f4b0b56f88f2bb505fd6a6)
1 //===- ScriptLexer.h --------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLD_ELF_SCRIPT_LEXER_H
10 #define LLD_ELF_SCRIPT_LEXER_H
11 
12 #include "lld/Common/LLVM.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/MemoryBufferRef.h"
15 #include <vector>
16 
17 namespace lld {
18 namespace elf {
19 
20 class ScriptLexer {
21 public:
22   explicit ScriptLexer(MemoryBufferRef mb);
23 
24   void setError(const Twine &msg);
25   void tokenize(MemoryBufferRef mb);
26   StringRef skipSpace(StringRef s);
27   bool atEOF();
28   StringRef next();
29   StringRef peek();
30   StringRef peek2();
31   void skip();
32   bool consume(StringRef tok);
33   void expect(StringRef expect);
34   bool consumeLabel(StringRef tok);
35   std::string getCurrentLocation();
36 
37   std::vector<MemoryBufferRef> mbs;
38   std::vector<StringRef> tokens;
39   bool inExpr = false;
40   size_t pos = 0;
41 
42   size_t lastLineNumber = 0;
43   size_t lastLineNumberOffset = 0;
44 
45 protected:
46   MemoryBufferRef getCurrentMB();
47 
48 private:
49   void maybeSplitExpr();
50   StringRef getLine();
51   size_t getLineNumber();
52   size_t getColumnNumber();
53 };
54 
55 } // namespace elf
56 } // namespace lld
57 
58 #endif
59