aboutsummaryrefslogtreecommitdiffstats
path: root/asm/ffi.py
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2023-02-08 04:15:54 +0000
committerGravatar Peter McGoron 2023-02-08 04:15:54 +0000
commit606814c4c079fc51102d4aa69079bbfb67b6f4b0 (patch)
tree5b93e620d5d3d2f88a4d3df81547553cc3c7701f /asm/ffi.py
parentmove tests (diff)
python ffi: test parsing
Diffstat (limited to 'asm/ffi.py')
-rw-r--r--asm/ffi.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/asm/ffi.py b/asm/ffi.py
new file mode 100644
index 0000000..87f6275
--- /dev/null
+++ b/asm/ffi.py
@@ -0,0 +1,29 @@
+from ctypes import *
+dll = CDLL("./libcreole.so")
+
+class CIns(Structure):
+ _fields_ = [("opcode", c_int),
+ ("w_flags", c_ubyte * 3),
+ ("w", c_uint * 3)]
+
+class CReader(Structure):
+ _fields_ = [("p", POINTER(c_ubyte)),
+ ("left", c_size_t)]
+def make_uchar_buf(s):
+ buf = (c_ubyte * len(s))()
+ buf[:] = s[:]
+ return buf
+
+class CParseLineException(Exception):
+ pass
+def parse_line(line):
+ buf = make_uchar_buf(line)
+
+ rd = CReader(buf, len(line))
+ ins = CIns()
+
+ ret = dll.creole_parse_line(byref(ins), byref(rd))
+
+ if ret != 0:
+ raise CParseLineException(ret)
+ return (ins.opcode, list(zip(ins.w_flags, ins.w)))