Ejemplo n.º 1
0
def apply_generics(generics, expression):
    '''
    Resolve generic objects in the expression.
    '''
    substituted = make_substitute_generics_function(generics)(expression)
    value = math_parser.get_value(substituted)
    return value
Ejemplo n.º 2
0
    def ports_from_slv(self, slv, generics, direction, subset=None):
        '''
        Extract port values from an slv string.

        'slv': A string of 0's and 1's representing the port data.
        'generics': The generic parameters for the entity.
        'direction': Whether we are extracting input or output ports.
        `subset`: An optional list of the signals present in the slv.
        '''
        assert direction in ('in', 'out')
        pos = 0
        outputs = {}
        for port in self.ports.values():
            if ((port.direction == direction)
                    and (port.name not in CLOCK_NAMES)
                    and ((subset is None) or (port.name in subset))):
                width_symbol = typs.make_substitute_generics_function(
                    generics)(port.typ.width)
                width = math_parser.get_value(width_symbol)
                intwidth = int(width)
                assert width == intwidth
                if pos == 0:
                    piece = slv[-intwidth:]
                else:
                    piece = slv[-pos - intwidth:-pos]
                pos += intwidth
                port_value = port.typ.from_slv(piece, generics)
                outputs[port.name] = port_value
        return outputs
Ejemplo n.º 3
0
 def __init__(self, identifier, size):
     self.identifier = identifier
     self.size = size
     self.width = size
     size_value = math_parser.get_value(size)
     self.max_value = pow(2, size_value - 1) - 1
     self.min_value = -pow(2, size_value - 1)
Ejemplo n.º 4
0
 def output_width(self, generics):
     width = 0
     for port in self.output_ports().values():
         width_symbol = typs.make_substitute_generics_function(generics)(
             port.typ.width)
         width += math_parser.get_value(width_symbol)
     return width
Ejemplo n.º 5
0
 def value(self):
     '''
     Determine the value of this constant.
     '''
     return math_parser.get_value(self.expression)