def guarantees(self): """ Return G(tok_i -> Fsends_i) """ #TODO: introduce Globally/Finally class expr = UnaryOp( 'G', BinOp( '->', BinOp('=', QuantifiedSignal(HAS_TOK_NAME, 'i'), Number(1)), UnaryOp( 'F', BinOp('=', QuantifiedSignal(SENDS_NAME, 'i'), Number(1))))) tok_released = ForallExpr(['i'], expr) return [tok_released]
def visit_binary_op(self, binary_op: BinOp): arg1 = self.dispatch(binary_op.arg1) arg2 = self.dispatch(binary_op.arg2) if binary_op.name == '*': return '({arg1}) && ({arg2})'.format(arg1=arg1, arg2=arg2) if binary_op.name == '=': if isinstance(arg1, Number): number_arg, signal_arg = arg1, arg2 else: number_arg, signal_arg = arg2, arg1 return '{neg}{signal}'.format(signal=signal_arg, neg=['', '!'][number_arg == Number(0)]) if binary_op.name == '+': return '({arg1}) || ({arg2})'.format(arg1=arg1, arg2=arg2) if binary_op.name == 'U' or binary_op.name == '->' or binary_op.name == '<->': return '({arg1}) {op} ({arg2})'.format(arg1=arg1, arg2=arg2, op=binary_op.name) assert 0, 'unknown binary operator: ' + "'" + str(binary_op.name) + "'"
def implications(self) -> list: expr = UnaryOp( 'G', UnaryOp('F', BinOp('=', QuantifiedSignal(HAS_TOK_NAME, 'i'), Number(1)))) fair_tok_sched = ForallExpr(['i'], expr) return [fair_tok_sched]
def _get_log_encoded_expr(signal:QuantifiedSignal, new_sched_signal_name:str, cutoff:int) -> Expr: assert len(signal.binding_indices) == 1 proc_index = signal.binding_indices[0] nof_sched_bits = int(max(1, math.ceil(math.log(cutoff, 2)))) bits = bin_fixed_list(proc_index, nof_sched_bits) #TODO: use quantified signal or signal? conjuncts = [BinOp('=', QuantifiedSignal(new_sched_signal_name, bit_index), Number(1 if bit_value else 0)) for bit_index, bit_value in enumerate(bits)] conjunction = and_expressions(conjuncts) return conjunction
def visit_binary_op(self, binary_op:BinOp): arg1 = self.dispatch(binary_op.arg1) arg2 = self.dispatch(binary_op.arg2) elem = None if binary_op.name == '*': elem = ET.Element('And') if binary_op.name == '=': if isinstance(arg1, Number): number_arg, signal_arg = arg1, arg2 else: number_arg, signal_arg = arg2, arg1 if number_arg == Number(1): elem = signal_arg else: elem = ET.Element('Not') elem.append(signal_arg) return elem if binary_op.name == '+': elem = ET.Element('Or') if binary_op.name == 'U': elem = ET.Element('U') if binary_op.name == '->': elem = ET.Element('Or') orig_arg1 = arg1 arg1 = ET.Element('Not') arg1.append(orig_arg1) arg2 = arg2 if binary_op.name == '<->': elem = ET.Element('Iff') assert elem is not None, 'unknown binary operator: ' + "'" + str(binary_op.name) + "'" elem.extend([arg1, arg2]) return elem
def assumptions(self): return [ForallExpr(['i'], UnaryOp('G', UnaryOp('F', BinOp('=', QuantifiedSignal(self._FAIR_SCHED_NAME, 'i'), Number(1)))))]
def _get_is_false(signal_name: str, *binding_indices): return _get_is_value(signal_name, Number(0), *binding_indices)