[RISCV][MCP] Remove redundant move from tail duplication (#89865)
[llvm-project.git] / lld / ELF / ScriptLexer.h
blobffd84411f22ac7c9e9c9c4036db7c0b21731898f
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 //===----------------------------------------------------------------------===//
9 #ifndef LLD_ELF_SCRIPT_LEXER_H
10 #define LLD_ELF_SCRIPT_LEXER_H
12 #include "lld/Common/LLVM.h"
13 #include "llvm/ADT/DenseSet.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/Support/MemoryBufferRef.h"
17 #include <vector>
19 namespace lld::elf {
21 class ScriptLexer {
22 protected:
23 struct Buffer {
24 // The remaining content to parse and the filename.
25 StringRef s, filename;
26 const char *begin = nullptr;
27 size_t lineNumber = 1;
28 // True if the script is opened as an absolute path under the --sysroot
29 // directory.
30 bool isUnderSysroot = false;
32 Buffer() = default;
33 Buffer(MemoryBufferRef mb);
35 // The current buffer and parent buffers due to INCLUDE.
36 Buffer curBuf;
37 SmallVector<Buffer, 0> buffers;
39 // Used to detect INCLUDE() cycles.
40 llvm::DenseSet<StringRef> activeFilenames;
42 struct Token {
43 StringRef str;
44 explicit operator bool() const { return !str.empty(); }
45 operator StringRef() const { return str; }
48 // The token before the last next().
49 StringRef prevTok;
50 // Rules for what is a token are different when we are in an expression.
51 // curTok holds the cached return value of peek() and is invalid when the
52 // expression state changes.
53 StringRef curTok;
54 size_t prevTokLine = 1;
55 // The inExpr state when curTok is cached.
56 bool curTokState = false;
57 bool eof = false;
59 public:
60 explicit ScriptLexer(MemoryBufferRef mb);
62 void setError(const Twine &msg);
63 void lex();
64 StringRef skipSpace(StringRef s);
65 bool atEOF();
66 StringRef next();
67 StringRef peek();
68 void skip();
69 bool consume(StringRef tok);
70 void expect(StringRef expect);
71 Token till(StringRef tok);
72 std::string getCurrentLocation();
73 MemoryBufferRef getCurrentMB();
75 std::vector<MemoryBufferRef> mbs;
76 bool inExpr = false;
78 private:
79 StringRef getLine();
80 size_t getColumnNumber();
83 } // namespace lld::elf
85 #endif