Example #1
0
    def type_check_bool_param(self, name):
        STR_BOOL = ("TRUE", "FALSE")
        v = getattr(self, name)
        if self._store_manager.serializer_cls == VerilogSerializer:
            # for verilog we need to convert it to  "TRUE" or "FALSE" string
            if not isinstance(v, STR.getValueCls()):
                if isinstance(v, (bool, BIT.getValueCls())):
                    v = "TRUE" if v else "FALSE"
                else:
                    assert v in STR_BOOL, (name, v)
                v = STR.from_py(v)
                object.__setattr__(self, name, v)
            else:
                assert v._dtype == STR, (name, "must be of type ", STR,
                                         " or compatible, is:", v)
        else:
            if not isinstance(v, BOOL.getValueCls()):
                if isinstance(v, (str, STR.getValueCls())):
                    v = str(v)
                    if v == "FALSE":
                        v = False
                    elif v == "TRUE":
                        v = True
                    else:
                        raise AssertionError(
                            name, "must be of type ", BOOL,
                            " or string \"TRUE\" or \"FALSE\" or compatible, is:",
                            v)

                v = BOOL.from_py(v)
                object.__setattr__(self, name, v)
            else:
                assert v._dtype == BOOL, (name, "must be of type ", BOOL,
                                          " or compatible, is:", v)
Example #2
0
 def type_check_bit_param(self, name):
     v = getattr(self, name)
     if not isinstance(v, BIT.getValueCls()):
         v = BIT.from_py(v)
         object.__setattr__(self, name, v)
     else:
         assert v._dtype == BIT, (name, "must be of type ", BIT,
                                  " or compatible, is:", v)
Example #3
0
def cast_hbool(self, sigOrVal, toType):
    if toType == BIT:
        if isinstance(sigOrVal, Value):
            v = BIT.getValueCls()(int(sigOrVal.val), BIT, sigOrVal.vldMask,
                                  sigOrVal.updateTime)
            return v
        else:
            return sigOrVal._ternary(BIT.fromPy(1), BIT.fromPy(0))

    return default_auto_cast_fn(self, sigOrVal, toType)