# Path: pif_ir/bir/objects/value_instance.py
# class ValueInstance(object):
#     def __init__(self, name, bit_width, value=0):
#         if bit_width <= 0:
#             raise BIRFieldWidthError(name, bit_width)
#         logging.debug("Adding value {0}".format(name))
#         self.name = name
#         self.bit_width = bit_width  
#         self.value = value 
# 
#     def __len__(self):
#         return self.bit_width
# 
#     def __int__(self):
#         return self.value
# 
#     def extract(self, buf, bit_offset=0):
#         self.value = bytearray_to_int(buf, self.bit_width, bit_offset)
#         return self.value
# 
#     def update(self, buf, bit_offset=0):
#         byte_offset = bit_offset / 8 
#         offset = bit_offset % 8
# 
#         vals, masks = int_to_bytearray(offset, self.value, self.bit_width)
#         for idx, (val, mask) in enumerate(zip(vals,masks)):
#             buf[byte_offset + idx] &= mask
#             buf[byte_offset + idx] += val


import logging
import struct
from pif_ir.bir.objects.value_instance import ValueInstance
            case, hex(int(val)), hex(args[2])))
        exit(1)

values = range(16)
values.extend([0xaaaaaaaa, 0x55555555, 0xffffffff])

for width in range(1, 33):
    for offset in range(32):
        for value in values:
            test = "{0}_{1}".format(width, offset)
            val = ValueInstance(test, width, value)

            byte_list = bytearray(8)
            for idx in range(8):
                byte_list[idx] = 0xff
            val.update(byte_list, offset)
            val.extract(byte_list, offset)

            expect = value & ((2**width)-1)
            if int(val) != expect:
                msg = "value {0}, width {1}, offset {2}: {3} != {4}".format(
                    value, width, offset, hex(int(val)), hex(expect))
                logging.error(msg)
                exit(1)

# Test with all 0 bits as baseline
for width in range(1,33):
    for offset in range(32):
        for value in values:
            test = "{0}_{1}".format(width, offset)

# Path: pif_ir/bir/objects/value_instance.py
# class ValueInstance(object):
#     def __init__(self, name, bit_width, value=0):
#         if bit_width <= 0:
#             raise BIRFieldWidthError(name, bit_width)
#         logging.debug("Adding value {0}".format(name))
#         self.name = name
#         self.bit_width = bit_width  
#         self.value = value 
# 
#     def __len__(self):
#         return self.bit_width
# 
#     def __int__(self):
#         return self.value
# 
#     def extract(self, buf, bit_offset=0):
#         self.value = bytearray_to_int(buf, self.bit_width, bit_offset)
#         return self.value
# 
#     def update(self, buf, bit_offset=0):
#         byte_offset = bit_offset / 8 
#         offset = bit_offset % 8
# 
#         vals, masks = int_to_bytearray(offset, self.value, self.bit_width)
#         for idx, (val, mask) in enumerate(zip(vals,masks)):
#             buf[byte_offset + idx] &= mask
#             buf[byte_offset + idx] += val


# Path: pif_ir/bir/tests/test_value_instance.py
import logging
import struct
from pif_ir.bir.objects.value_instance import ValueInstance

            case, hex(int(val)), hex(args[2])))
        exit(1)

values = range(16)
values.extend([0xaaaaaaaa, 0x55555555, 0xffffffff])

for width in range(1, 33):
    for offset in range(32):
        for value in values:
            test = "{0}_{1}".format(width, offset)
            val = ValueInstance(test, width, value)

            byte_list = bytearray(8)
            for idx in range(8):
                byte_list[idx] = 0xff
            val.update(byte_list, offset)
            val.extract(byte_list, offset)

            expect = value & ((2**width)-1)
            if int(val) != expect:
                msg = "value {0}, width {1}, offset {2}: {3} != {4}".format(
                    value, width, offset, hex(int(val)), hex(expect))
                logging.error(msg)
                exit(1)

# Test with all 0 bits as baseline
for width in range(1,33):
    for offset in range(32):
        for value in values:
            test = "{0}_{1}".format(width, offset)

            val = ValueInstance(test, width, value)