Beispiel #1
0
	def __init__(self):
		self.nid = -1
		self.name = "Programme"
		self.nb_elems = 0
		self.nb_errors = 0
		self.brains = []
		self.graph = open('graph.gv', 'w+')
		self.graph.write("digraph cerveau {\n")
		self.vhdl = VHDL()
Beispiel #2
0
class Ast(object):

	# Constructeur
	def __init__(self):
		self.nid = -1
		self.name = "Programme"
		self.nb_elems = 0
		self.nb_errors = 0
		self.brains = []
		self.graph = open('graph.gv', 'w+')
		self.graph.write("digraph cerveau {\n")
		self.vhdl = VHDL()

	# Destructeur
	def terminer(self):
		self.graph.write("}\n")
		self.graph.close()
		os.system("dot -Tpng graph.gv > output.png")
		self.vhdl.convertir(self)

	# Visiteur
	def visiter(self):
		for elem in self.brains: elem.elaguer_blocs()
		print "Nombre d'erreurs de contexte :\t", self.nb_errors
		for elem in self.brains: elem.gr_visit(self)
		for elem in self.brains: elem.verifier_interface()

	# Printeur
	def __str__(self):
		return ""

	# Erreur
	def raise_error(self, message):
		self.nb_errors += 1
		print "[Error] [" + message + "]"

	# Incrementer l'identifiant d'element
	def increment(self):
		self.nb_elems += 1
		return self.nb_elems - 1

	# Ajouter un cerveau
	def add_brain(self, brain):
		self.brains.append(brain)

	# Remplacer une constante integer
	def replace_int(self, name):
		str_ = str(name)
		if re.search(d.identifier, str_):
			for elem in self.brains[0].b_var[0].ints:
				if elem.name == str_:
					return int(elem.number)
			self.raise_error("Constante int inconnue :" + str_)
		else:
			return name

	# Remplacer une constante echelle
	def replace_scale(self, name):
		str_ = str(name)
		if str_ != "0_scale_perso" and str_ != "1_scale_unitaire":
			for elem in self.brains[0].b_var[0].scales:
				if elem.name == str_:
					return elem
			self.raise_error("Constante scale inconnue :" + str_)
		else:
			return name