Beispiel #1
0
def extract_sensitivity_from_dec(deco_list, fn_name):
    if len(deco_list) == 0:
        return CodeBlockType.Combinational, []
    else:
        assert len(
            deco_list
        ) == 1, "{0} is not called with multiple decorators blocks".format(
            fn_name)
        call_obj = deco_list[0]
        if isinstance(call_obj, ast.Call):
            call_name = call_obj.func.id
        else:
            assert isinstance(
                call_obj,
                ast.Name), "Unrecognized  function decorator {0}".format(
                    call_obj)
            call_name = call_obj.id
        if call_name == "always_comb":
            return CodeBlockType.Combinational, []
        elif call_name == "initial":
            return CodeBlockType.Initial, []
        elif call_name == "always_latch":
            return CodeBlockType.Latch, []
        else:
            assert call_name == "always_ff", "Unrecognized function decorator {0}".format(
                call_name)
        blk_type = CodeBlockType.Sequential
        raw_sensitivity = call_obj.args
        result = []
        # TODO: fix me. the frame num calculation is a hack
        local = get_frame_local(4)
        for entry in raw_sensitivity:
            assert len(entry.elts) == 2
            edge_node, signal_name_node = entry.elts
            if isinstance(edge_node, ast.Name):
                edge_type = edge_node.id
            else:
                edge_type = edge_node.attr
            edge_type = edge_type.capitalize()
            if isinstance(signal_name_node, ast.Name):
                name = signal_name_node.id
                assert name in local, "{0} not found".format(name)
                n = eval(name, local)
                assert isinstance(
                    n, _kratos.Var), "{0} is not a variable".format(name)
                signal_name = n
            elif isinstance(signal_name_node, ast.Attribute):
                # need to eval the actual name
                n = eval(astor.to_source(signal_name_node), local)
                assert isinstance(n,
                                  _kratos.Var), "{0} is not a variable".format(
                                      signal_name_node)
                signal_name = n
            else:
                signal_name = signal_name_node.s
            result.append((edge_type, signal_name))
        return blk_type, result
Beispiel #2
0
 def assert_(self, value, f_ln=None, **kargs):
     assert isinstance(value, (_kratos.Var, int))
     if isinstance(value, int):
         assert value == 0
         value = _kratos.constant(0, 1, False)
     stmt = _kratos.AssertValueStmt(value)
     if self.generator.debug:
         stmt.add_fn_ln((self.filename, f_ln + self.ln - 1), True)
         if self.add_local:
             # obtain the previous call frame info
             __local = get_frame_local()
             add_scope_context(stmt, __local)
             # this is additional info passed in
             add_scope_context(stmt, kargs)
     return stmt
Beispiel #3
0
 def assign(self, a, b, f_ln=None, **kargs):
     assert isinstance(a, _kratos.Var)
     try:
         stmt = a.assign(b)
     except _kratos.exception.VarException as ex:
         if f_ln is not None:
             print_src(self.filename, f_ln + self.ln - 1)
         # re-throw it
         raise ex
     if self.generator.debug:
         assert f_ln is not None
         stmt.add_fn_ln((self.filename, f_ln + self.ln - 1), True)
         if self.add_local:
             # obtain the previous call frame info
             __local = get_frame_local()
             add_scope_context(stmt, __local)
             # this is additional info passed in
             add_scope_context(stmt, kargs)
     return stmt