[m-rev.] diff: fix maxstack bug in .NET backend.

Tyson Dowd trd at cs.mu.OZ.AU
Wed Jul 25 01:27:01 AEST 2001


Hi,


===================================================================


Estimated hours taken: 1.0
Branches: main

Fix a bug the prevented tests/general/arithmetic.m from generating
a valid program.

compiler/il_peephole.m:
	Make sure we recalculate the maxstack after running the peephole
	optimizer.
	

Index: compiler/il_peephole.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/il_peephole.m,v
retrieving revision 1.4
diff -u -r1.4 il_peephole.m
--- compiler/il_peephole.m	2001/07/18 10:20:50	1.4
+++ compiler/il_peephole.m	2001/07/24 15:23:04
@@ -46,7 +46,7 @@
 
 :- type instrs == list(instr).
 
-:- import_module assoc_list, bool, map, string, std_util.
+:- import_module assoc_list, bool, map, string, std_util, int.
 :- import_module ilds, require.
 
 	% We zip down to the end of the instruction list, and start attempting
@@ -86,8 +86,27 @@
 optimize_class_decl(Decl0, Decl, Mod0, Mod) :-
 	( Decl0 = method(A, MethodDecls0) ->
 		list__map_foldl(optimize_method_decl, MethodDecls0,
-			MethodDecls, Mod0, Mod),
-		Decl = method(A, MethodDecls)
+			MethodDecls1, Mod0, Mod),
+		( Mod = yes ->
+				% find the new maxstack
+			MaxStacks = list__map((func(X) = 
+				( if X = instrs(I) 
+				  then calculate_max_stack(I) 
+				  else 0
+				)), MethodDecls1),
+			NewMaxStack = list__foldl((func(X, Y0) = X + Y0),
+				MaxStacks, 0
+			),
+				% set the maxstack
+			MethodDecls = list__map((func(X) = 
+				( if X = maxstack(_) 
+				  then maxstack(int32(NewMaxStack))
+				  else X
+				)), MethodDecls1),
+			Decl = method(A, MethodDecls)
+		;
+			Decl = method(A, MethodDecls1)
+		)
 	;
 		Mod = no,
 	 	Decl0 = Decl 

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list