def __init__(self, l, it=None, idx=None): self.stmt = None if it is None and idx is None: # Default: use it it = True idx = False else: # One or more are specified if idx is None: idx = False if it is None: it = False if not idx and not it: raise Exception("Neither it nor idx specified") self.it = it self.idx = idx self.arr = l self.arr_model = l._int_field_info.model if not in_constraint_scope(): raise Exception( "Attempting to use foreach constraint outside constraint scope" ) to_expr(l) e = pop_expr() self.stmt = ConstraintForeachModel(e)
def __init__(self, l, it=None, idx=None): self.stmt = None if it is None and idx is None: # Default: use it it = True idx = False else: # One or more are specified if idx is None: idx = False if it is None: it = False if not idx and not it: raise Exception("Neither it nor idx specified") # Form an expression to the array to_expr(l) e = pop_expr() self.arr_ref_e = e self.elem_t = Expr2FieldTypeVisitor().fieldtype(e) self.it = it self.idx = idx if not in_constraint_scope(): raise Exception( "Attempting to use foreach constraint outside constraint scope" ) self.stmt = ConstraintForeachModel(e) if in_srcinfo_mode(): self.stmt.srcinfo = SourceInfo.mk()
def soft(e): to_expr(e) em = pop_expr() c = ConstraintSoftModel(em) c.srcinfo = em.srcinfo push_constraint_stmt(c)
def unique(*args): expr_l = [] for i in range(-1, -(len(args) + 1), -1): to_expr(args[i]) expr_l.insert(0, pop_expr()) push_constraint_stmt(ConstraintUniqueModel(expr_l))
def __init__(self, e): if not in_constraint_scope(): raise Exception("Attempting to use if_then constraint outside constraint scope") to_expr(e) self.stmt = ConstraintIfElseModel(pop_expr()) push_constraint_stmt(self.stmt)
def unique(*args): expr_l = [] for i in range(-1, -(len(args) + 1), -1): to_expr(args[i]) expr_l.insert(0, pop_expr()) c = ConstraintUniqueModel(expr_l) if in_srcinfo_mode(): c.srcinfo = SourceInfo.mk() push_constraint_stmt(c)
def __init__(self, e): if not in_constraint_scope(): raise Exception( "Attempting to use if_then constraint outside constraint scope" ) to_expr(e) self.stmt = ConstraintImpliesModel(pop_expr()) if in_srcinfo_mode(): self.stmt.srcinfo = SourceInfo.mk()
def dist(lhs, weights): """Applies distribution weights to the specified field""" to_expr(lhs) lhs_e = pop_expr() weight_l = [] for w in weights: if not isinstance(w, weight): raise Exception("Weight specifications must of type 'vsc.weight', not " + str(w)) weight_l.append(w.weight_e) push_constraint_stmt(ConstraintDistModel(lhs_e, weight_l))
def __init__(self, e): self.stmt = None if not in_constraint_scope(): raise Exception("Attempting to use if_then constraint outside constraint scope") last_stmt = last_constraint_stmt() if last_stmt == None or not isinstance(last_stmt, ConstraintIfElseModel): raise Exception("Attempting to use else_if where it doesn't follow if_then") to_expr(e) # Need to find where to think this in while last_stmt.false_c != None: last_stmt = last_stmt.false_c self.stmt = ConstraintIfElseModel(pop_expr()) last_stmt.false_c = self.stmt
def solve_order(before, after): if constraint_scope_depth() != 1: raise Exception( "solve_before can only be used at a constraint top level") before_l = [] after_l = [] if isinstance(before, list): for b in before: to_expr(b) b_e = pop_expr() if not isinstance(b_e, ExprFieldRefModel): raise Exception("Parameter " + str(b) + " is not a field reference") before_l.append(b_e.fm) else: to_expr(before) before_e = pop_expr() if not isinstance(before_e, ExprFieldRefModel): raise Exception("Parameter " + str(before) + " is not a field reference") before_l.append(before_e.fm) if isinstance(after, list): for a in after: to_expr(a) a_e = pop_expr() if not isinstance(a_e, ExprFieldRefModel): raise Exception("Parameter " + str(a) + " is not a field reference") before_l.append(a_e.fm) else: to_expr(after) after_e = pop_expr() if not isinstance(after_e, ExprFieldRefModel): raise Exception("Parameter " + str(after) + " is not a field reference") after_l.append(after_e.fm) c = ConstraintSolveOrderModel(before_l, after_l) if in_srcinfo_mode(): c.srcinfo = SourceInfo.mk() push_constraint_stmt(c)
def __init__(self, val, w): rng_lhs_e = None rng_rhs_e = None if isinstance(val, (list, tuple)): if len(val) != 2: raise Exception("Weight range must have two elements") to_expr(val[0]) rng_lhs_e = pop_expr() to_expr(val[1]) rng_rhs_e = pop_expr() elif isinstance(val, rng): rng_lhs_e = val.low rng_rhs_e = val.high else: to_expr(val) rng_lhs_e = pop_expr() to_expr(w) w_e = pop_expr() self.weight_e = DistWeightExprModel(rng_lhs_e, rng_rhs_e, w_e)
def soft(e): to_expr(e) push_constraint_stmt(ConstraintSoftModel(pop_expr()))