Skip to content
Snippets Groups Projects
Commit 12698234 authored by Ettayeb Yassine's avatar Ettayeb Yassine
Browse files

final commit

parent 4b988dec
No related branches found
No related tags found
No related merge requests found
File added
......@@ -86,7 +86,7 @@ def fixpoint_iteration[T](transfer: Transfer[T], cfg: Cfg) -> dict[Node,T]:
output maps each node to the computed state
"""
# Étape 1 : Initialisation
# initialisation
mapping: dict[Node, T] = {}
for node in cfg.g.nodes:
if node == cfg.init_node:
......@@ -94,17 +94,17 @@ def fixpoint_iteration[T](transfer: Transfer[T], cfg: Cfg) -> dict[Node,T]:
else:
mapping[node] = transfer.bottom()
# Étape 2 : Initialisation de la worklist avec les successeurs du nœud initial
# initialisation de la worklist avec les successeurs du nœud initial
worklist: list[tuple[Node, Node, Label]] = []
for (dst, label) in cfg.init_node.succs:
worklist.append((cfg.init_node, dst, label))
# Étape 3 : Itération principale
# itération principale
while worklist:
src, dst, label = worklist.pop(0)
src_state = mapping[src]
# Appliquer la bonne fonction de transfert selon le label
# applique la fonction de transfert selon le label
match label:
case LSkip():
new_state = transfer.tr_skip(src_state)
......@@ -117,13 +117,13 @@ def fixpoint_iteration[T](transfer: Transfer[T], cfg: Cfg) -> dict[Node,T]:
case _:
continue # ou raise NotImplementedError
# Joindre avec l'ancien état
# joindre avc l'ancien état
joined_state = transfer.join(mapping[dst], new_state)
# Si le nouvel état apporte de l'information, on met à jour
# si nouvel état apporte de l'information, on met à jour
if not transfer.included(joined_state, mapping[dst]):
mapping[dst] = joined_state
# Et on ajoute les successeurs à la worklist
# + on ajoute les successeurs à la worklist
for (succ, lab) in dst.succs:
worklist.append((dst, succ, lab))
......
......@@ -34,18 +34,16 @@ def eval_aexp(env: dict[str,int], exp: ArithExpr) -> int | None:
if left_val is None or right_val is None:
return None
# Match on the binary operator using the available operations
if bop == Bop.ADD:
return left_val + right_val
elif bop == Bop.MUL:
return left_val * right_val
# Check for other potential operators in Bop
# Using string representation as fallback
# check for other potential operators in Bop
elif str(bop) == "Bop.SUB" or str(bop) == "-":
return left_val - right_val
elif str(bop) == "Bop.DIV" or str(bop) == "/":
if right_val == 0:
return None # Division by zero
return None # div by zero
return left_val // right_val
else:
return None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment