[Lldb-commits] [lldb] [lldb] Add a compiler/interpreter of LLDB data formatter bytecode to lldb/examples (PR #113398)
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Fri Oct 25 13:52:23 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")
----------------
adrian-prantl wrote:
The Python code
```
if foo: bar
if foo: bar; else: baz;
if foo: bar; elsif foobar: baz;
```
would translate to
```
foo { bar } if
foo { bar } { baz } ifelse
foo { bar } { foobar { baz } if } ifelse
```
https://github.com/llvm/llvm-project/pull/113398
More information about the lldb-commits
mailing list