code: fix up header sizes

This commit is contained in:
Shiz 2020-06-02 04:37:25 +02:00
parent 49f3db1435
commit d33ea1bf6a
1 changed files with 11 additions and 7 deletions

View File

@ -14,30 +14,34 @@ class CILFlags(enum.Flag):
InitLocals = 0x10
class CILAttributes(MultiEnum):
format = (CILFormat, 0b0011)
flags = (CILFlags, 0x0FF0 | 0b1100)
size = (int, 0xF000)
format = (CILFormat, 0b0011)
flags = (CILFlags, 0x0FF0 | 0b1100)
header_size = (int, 0xF000, 12)
class CILTinyHeader(Struct, nocopy=True):
flags = Static(CILAttributes(CILFormat.Tiny.value))
attribs = Static(CILAttributes(CILFormat.Tiny.value))
stack_size = Static(0)
code_size = Process(UInt(8), lambda v: v >> 2)
vars = Static(None)
code = Data()
def on_attribs(self, spec, context):
self.attribs.header_size = 1
def on_code_size(self, spec, context):
spec.code.length = self.code_size
class CILExtendedHeader(Struct, nocopy=True):
flags = Enum(CILAttributes, UInt(16))
attribs = Enum(CILAttributes, UInt(16))
stack_size = UInt(16)
code_size = UInt(32)
vars = CLIToken
_pad = Data()
code = Data()
def on_flags(self, spec, context):
spec._pad.length = (self.flags.size >> 12) * 4 - 12
def on_attribs(self, spec, context):
self.attribs.header_size *= 4
spec._pad.length = self.attribs.header_size - 12
def on_code_size(self, spec, context):
spec.code.length = self.code_size