Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / ELF / ScriptLexer.h
blob17c0b529fa1760e06767e9ddea498804d0aaaf27
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/StringRef.h"
14 #include "llvm/Support/MemoryBufferRef.h"
15 #include <vector>
17 namespace lld::elf {
19 class ScriptLexer {
20 public:
21 explicit ScriptLexer(MemoryBufferRef mb);
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 StringRef peek2();
30 void skip();
31 bool consume(StringRef tok);
32 void expect(StringRef expect);
33 bool consumeLabel(StringRef tok);
34 std::string getCurrentLocation();
36 std::vector<MemoryBufferRef> mbs;
37 std::vector<StringRef> tokens;
38 bool inExpr = false;
39 size_t pos = 0;
41 size_t lastLineNumber = 0;
42 size_t lastLineNumberOffset = 0;
44 protected:
45 MemoryBufferRef getCurrentMB();
47 private:
48 void maybeSplitExpr();
49 StringRef getLine();
50 size_t getLineNumber();
51 size_t getColumnNumber();
54 } // namespace lld::elf
56 #endif