xref: /freebsd/contrib/llvm-project/lld/ELF/ScriptLexer.h (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
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::elf {
18 
19 class ScriptLexer {
20 public:
21   explicit ScriptLexer(MemoryBufferRef mb);
22 
23   void setError(const Twine &msg);
24   void tokenize(MemoryBufferRef mb);
25   StringRef skipSpace(StringRef s);
26   bool atEOF();
27   StringRef next();
28   StringRef peek();
29   void skip();
30   bool consume(StringRef tok);
31   void expect(StringRef expect);
32   bool consumeLabel(StringRef tok);
33   std::string getCurrentLocation();
34   MemoryBufferRef getCurrentMB();
35 
36   std::vector<MemoryBufferRef> mbs;
37   std::vector<StringRef> tokens;
38   bool inExpr = false;
39   size_t pos = 0;
40 
41   size_t lastLineNumber = 0;
42   size_t lastLineNumberOffset = 0;
43 
44 private:
45   void maybeSplitExpr();
46   StringRef getLine();
47   size_t getLineNumber();
48   size_t getColumnNumber();
49 };
50 
51 } // namespace lld::elf
52 
53 #endif
54