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 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 bin_expr(self, op, rhs): to_expr(rhs) rhs_e = pop_expr() lhs_e = pop_expr() e = ExprBinModel(lhs_e, op, rhs_e) if in_srcinfo_mode(): e.srcinfo = SourceInfo.mk(2) return expr(e)
def bin_expr(self, op, rhs): to_expr(rhs) rhs_e = pop_expr() # push_expr(ExprFieldRefModel(self._int_field_info.model)) # Push a reference to this field self.to_expr() lhs_e = pop_expr() e = ExprBinModel(lhs_e, op, rhs_e) if in_srcinfo_mode(): e.srcinfo = SourceInfo.mk(2) return expr(e)
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 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) c = ConstraintDistModel(lhs_e, weight_l) if in_srcinfo_mode(): c.srcinfo = SourceInfo.mk() push_constraint_stmt(c)
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()) if in_srcinfo_mode(): self.stmt.srcinfo = SourceInfo.mk() last_stmt.false_c = self.stmt