Esempio n. 1
0
	def visit_expr_statement(self, sa, node):
		if isinstance(node.value, ast.Yield):
			yvalue = node.value.value
			if not isinstance(yvalue, ast.Call) or not isinstance(yvalue.func, ast.Name):
				raise NotImplementedError("Unrecognized I/O pattern")
			callee = self.symdict[yvalue.func.id]
			states, exit_states = gen_io(self, None, callee, yvalue.args, yvalue.keywords, [])
			sa.assemble(states, exit_states)
		else:
			raise NotImplementedError
Esempio n. 2
0
	def visit_expr_statement(self, sa, node):
		if isinstance(node.value, ast.Yield):
			yvalue = node.value.value
			if not isinstance(yvalue, ast.Call) or not isinstance(yvalue.func, ast.Name):
				raise NotImplementedError("Unrecognized I/O pattern")
			callee = self.symdict[yvalue.func.id]
			states, exit_states = gen_io(self, None, callee, yvalue.args, yvalue.keywords, [])
			sa.assemble(states, exit_states)
		else:
			raise NotImplementedError
Esempio n. 3
0
    def visit_io_pattern(self, sa, targets, model, args, keywords, statements):
        # first statement is <modelname> = <model>(<args>)
        if len(targets) != 1 or not isinstance(targets[0], ast.Name):
            raise NotImplementedError("Unrecognized I/O pattern")
        modelname = targets[0].id
        if modelname in self.symdict:
            raise NotImplementedError("I/O model name is not free")

            # second statement must be yield <modelname>
        try:
            ystatement = next(statements)
        except StopIteration:
            raise NotImplementedError("Incomplete or fragmented I/O pattern")
        if (
            not isinstance(ystatement, ast.Expr)
            or not isinstance(ystatement.value, ast.Yield)
            or not isinstance(ystatement.value.value, ast.Name)
            or ystatement.value.value.id != modelname
        ):
            print(ast.dump(ystatement))
            raise NotImplementedError("Unrecognized I/O pattern")

            # following optional statements are assignments to registers
            # with <modelname> used in expressions.
        from_model = []
        while True:
            try:
                fstatement = next(statements)
            except StopIteration:
                fstatement = None
            if not isinstance(fstatement, ast.Assign) or not _is_name_used(fstatement.value, modelname):
                break
            tregs = []
            for target in fstatement.targets:
                if isinstance(target, ast.Attribute) and target.attr == "store":
                    if isinstance(target.value, ast.Name):
                        tregs.append(self.symdict[target.value.id])
                    else:
                        raise NotImplementedError
                else:
                    raise NotImplementedError
            from_model.append((tregs, fstatement.value))

        states, exit_states = gen_io(self, modelname, model, args, keywords, from_model)
        sa.assemble(states, exit_states)
        return fstatement
Esempio n. 4
0
	def visit_io_pattern(self, sa, targets, model, args, keywords, statements):
		# first statement is <modelname> = <model>(<args>)
		if len(targets) != 1 or not isinstance(targets[0], ast.Name):
			raise NotImplementedError("Unrecognized I/O pattern")
		modelname = targets[0].id
		if modelname in self.symdict:
			raise NotImplementedError("I/O model name is not free")
		
		# second statement must be yield <modelname>
		try:
			ystatement = next(statements)
		except StopIteration:
			raise NotImplementedError("Incomplete or fragmented I/O pattern")
		if not isinstance(ystatement, ast.Expr) \
		  or not isinstance(ystatement.value, ast.Yield) \
		  or not isinstance(ystatement.value.value, ast.Name) \
		  or ystatement.value.value.id != modelname:
			print(ast.dump(ystatement))
			raise NotImplementedError("Unrecognized I/O pattern")
		
		# following optional statements are assignments to registers
		# with <modelname> used in expressions.
		from_model = []
		while True:
			try:
				fstatement = next(statements)
			except StopIteration:
				fstatement = None
			if not isinstance(fstatement, ast.Assign) \
			  or not _is_name_used(fstatement.value, modelname):
				break
			tregs = []
			for target in fstatement.targets:
				if isinstance(target, ast.Attribute) and target.attr == "store":
					if isinstance(target.value, ast.Name):
						tregs.append(self.symdict[target.value.id])
					else:
						raise NotImplementedError
				else:
					raise NotImplementedError
			from_model.append((tregs, fstatement.value))
		
		states, exit_states = gen_io(self, modelname, model, args, keywords, from_model)
		sa.assemble(states, exit_states)
		return fstatement