[lld] [ELF] ScriptLexer: generate tokens lazily (PR #100493)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 25 12:07:58 PDT 2024


================
@@ -10,18 +10,36 @@
 #define LLD_ELF_SCRIPT_LEXER_H
 
 #include "lld/Common/LLVM.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBufferRef.h"
 #include <vector>
 
 namespace lld::elf {
 
 class ScriptLexer {
+protected:
+  struct Buffer {
+    // The unparsed buffer and the filename.
+    StringRef s, filename;
+  };
+  // The current buffer and parent buffers due to INCLUDE.
+  Buffer cur;
+  SmallVector<Buffer, 0> buffers;
+
+  // The token before the last next().
+  StringRef prevTok;
+  // The cache value of peek(). This is valid if curTokState and inExpr match.
+  StringRef curTok;
+  // The inExpr state when curTok is cached.
+  bool curTokState = false;
----------------
smithp35 wrote:

Was thinking if `curTokInExpr` might work better given that these are just booleans.
```
if (curTokInExpr == inExpr) ... 
``` 

https://github.com/llvm/llvm-project/pull/100493


More information about the llvm-commits mailing list