-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbasicTypes.py
More file actions
54 lines (48 loc) · 1.51 KB
/
basicTypes.py
File metadata and controls
54 lines (48 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from collections import namedtuple
Pointer = namedtuple('Pointer', 'pointedType target')
Array = namedtuple('Array', 'pointedType length')
Stack = namedtuple('Stack', 'offset')
Struct = namedtuple('Struct', 'name size parent members')
EnumType = namedtuple('EnumType', 'enum')
Enum = namedtuple('Enum', 'name base values')
Flag = namedtuple('Flag', 'base bits')
FunctionSignature = namedtuple('FunctionSignature', 'name args')
Variable = namedtuple('Variable', 'name type')
class Primitive:
lookup = {}
def __init__(self, name, size):
self.size = size
self.name = name
Primitive.lookup[name] = self
def __repr__(self):
return 'Primitive({})'.format(self.name)
def __format__(self, spec):
return self.name
unknown = Primitive('unknown', 0)
bad = Primitive('bad', 0)
boolean = Primitive('boolean', 4) #1/0 boolean, full word
word = Primitive('word', 4)
address = Primitive('address', 4)
short = Primitive('short', 2)
ushort = Primitive('ushort', 2)
byte = Primitive('byte', 1)
ubyte = Primitive('ubyte', 1)
single = Primitive('single' ,4)
double = Primitive('double', 8)
def getCode(t):
codeTable = {
unknown: '',
bad : 'x',
boolean: '?',
word : 'w',
address: 'p',
short : 'h',
ushort : 'H',
byte : 'b',
ubyte : 'B',
single : 'f',
double : 'd'
}
return codeTable[t] if isinstance(t, Primitive) else 'p'
def isIndexable(t):
return isinstance(t, Array) or isinstance(t, str)