
I am trying to implement a program transformation with Hoopl. The transformation replaces a particular statement with variable declarations provided that the variables have not been previously declared. A map keeps track of declared variables where the map keys store variable names. The transformation works only for programs without loops. In the program below, it should replace line 2 rec #3 INxt B37H00G with 1 Global Field B37H00G 2 Global Array B37HO3R 3 rec #3 INxt B37H00G but it doesn't. === Example graph == 0 goto L4 1 L4: 2 rec #3 INxt B37H00G 3 while #3 goto L5 goto L2 4 L5: 5 Global Field VSTF01a 6 goto L4 7 L2: I think the reason it fails is because there are two paths leading to L4, one from the program start (line 0) and a second when the loop repeats from line 6. In the first case the transformation produces the substitution graph since the two variables are not in the map. In the analysis of the second path however, the variables are in the name space so the rewrite function returns Nothing. In the end, the second transformation result is preserved (i.e. Nothing) and the graph is not transformed. Do I understand correctly why the transformation fails for loops? How would you suggest to solve this problem? Regards