[Lldb-commits] [lldb] [lldb] Add a compiler/interpreter of LLDB data formatter bytecode to lldb/examples (PR #113398)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 24 09:59:39 PDT 2024


================
@@ -0,0 +1,486 @@
+"""
+Specification, compiler, disassembler, and interpreter
+for LLDB dataformatter bytecode.
+
+See formatter-bytecode.md for more details.
+"""
+from __future__ import annotations
+
+# Types
+type_String = 1
+type_Int = 2
+type_UInt = 3
+type_Object = 4
+type_Type = 5
+
+# Opcodes
+opcode = dict()
+
+
+def define_opcode(n, mnemonic, name):
+    globals()["op_" + name] = n
+    if mnemonic:
+        opcode[mnemonic] = n
+    opcode[n] = mnemonic
+
+
+define_opcode(1, "dup", "dup")
+define_opcode(2, "drop", "drop")
+define_opcode(3, "pick", "pick")
+define_opcode(4, "over", "over")
+define_opcode(5, "swap", "swap")
+define_opcode(6, "rot", "rot")
+
+define_opcode(0x10, "{", "begin")
+define_opcode(0x11, "if", "if")
+define_opcode(0x12, "ifelse", "ifelse")
----------------
DavidSpickett wrote:

I don't see a `else`, how will these be used? Is it always one of:
```
if condition:
  <stuff>
```
Or:
```
if condition:
  <stuff>
else:
  <other stuff>
```
And you make `if`/`else if` chains by doing `ifelse` followed by another `ifelse`?

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


More information about the lldb-commits mailing list