summaryrefslogtreecommitdiff
path: root/cffi/cffi_opcode.py
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2015-05-12 16:01:45 +0200
committerArmin Rigo <arigo@tunes.org>2015-05-12 16:01:45 +0200
commit375ef406e608c44827b06e39da8ebdff4a9a58f5 (patch)
treeeca10babf38b062b26dfb26eeacd378a3f7a26ab /cffi/cffi_opcode.py
parent8eabb2e5f5ff15744b4f3af89b9c90b7747587dc (diff)
downloadcffi-375ef406e608c44827b06e39da8ebdff4a9a58f5.tar.gz
in-progress
Diffstat (limited to 'cffi/cffi_opcode.py')
-rw-r--r--cffi/cffi_opcode.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/cffi/cffi_opcode.py b/cffi/cffi_opcode.py
index 7b727d5..0afe495 100644
--- a/cffi/cffi_opcode.py
+++ b/cffi/cffi_opcode.py
@@ -1,4 +1,3 @@
-import struct
class CffiOp(object):
def __init__(self, op, arg):
@@ -14,12 +13,19 @@ class CffiOp(object):
def as_bytes(self):
assert self.op is not None
- return struct.pack(">i", (self.arg << 8) | self.op)
+ return format_four_bytes((self.arg << 8) | self.op)
def __str__(self):
classname = CLASS_NAME.get(self.op, self.op)
return '(%s %s)' % (classname, self.arg)
+def format_four_bytes(num):
+ return '\\x%02X\\x%02X\\x%02X\\x%02X' % (
+ (num >> 24) & 0xFF,
+ (num >> 16) & 0xFF,
+ (num >> 8) & 0xFF,
+ (num ) & 0xFF)
+
OP_PRIMITIVE = 1
OP_POINTER = 3
OP_ARRAY = 5