1+ #****************************************************************************
2+ #* covergroup_callback_base.py
3+ #*
4+ #* Copyright 2022 Matthew Ballance and Contributors
5+ #*
6+ #* Licensed under the Apache License, Version 2.0 (the "License"); you may
7+ #* not use this file except in compliance with the License.
8+ #* You may obtain a copy of the License at:
9+ #*
10+ #* http://www.apache.org/licenses/LICENSE-2.0
11+ #*
12+ #* Unless required by applicable law or agreed to in writing, software
13+ #* distributed under the License is distributed on an "AS IS" BASIS,
14+ #* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ #* See the License for the specific language governing permissions and
16+ #* limitations under the License.
17+ #*
18+ #* Created on:
19+ #* Author:
20+ #*
21+ #****************************************************************************
22+
23+ from ..model .covergroup_model import CovergroupModel
24+ from ..model .coverpoint_model import CoverpointModel
25+ from ..model .coverpoint_cross_model import CoverpointCrossModel
26+
27+ class CovergroupCallbackBase (object ):
28+
29+ def __init__ (self ):
30+ self ._hit_m = {}
31+ self ._cb = None
32+
33+ def set_cb (self , cb ):
34+ self ._cb = cb
35+
36+ def sample_cb (self , * args , ** kwargs ):
37+ # Call the 'real' sample method
38+ self .sample (* args , ** kwargs )
39+
40+ self .call_callbacks ()
41+
42+ def call_callbacks (self ):
43+ model : CovergroupModel = self .get_model ()
44+ for cp in model .coverpoint_l :
45+ self .process_coverpoint (cp )
46+ for cr in model .cross_l :
47+ self .process_cross (cr )
48+
49+ def process_coverpoint (self , cp : CoverpointModel ):
50+ for bi in range (cp .get_n_bins ()):
51+ name = cp .name + "." + cp .get_bin_name (bi )
52+ if name not in self ._hit_m .keys ():
53+ self ._hit_m [name ] = 0
54+ hits = cp .get_bin_hits (bi )
55+ if self ._hit_m [name ] != hits :
56+ self ._hit_m [name ] = hits
57+ self ._cb (name , hits )
58+
59+ def process_cross (self , cp : CoverpointCrossModel ):
60+ for bi in range (cp .get_n_bins ()):
61+ name = cp .name + "." + cp .get_bin_name (bi )
62+ if name not in self ._hit_m .keys ():
63+ self ._hit_m [name ] = 0
64+ hits = cp .get_bin_hits (bi )
65+ if self ._hit_m [name ] != hits :
66+ self ._hit_m [name ] = hits
67+ self ._cb (name , hits )
68+
69+
70+
0 commit comments