(* Copyright (C) 1989, Digital Equipment Corporation *) (* All rights reserved. *) (* See the file COPYRIGHT for a full description. *) (* File: Inc.m3 *) (* Last Modified On Tue Mar 20 03:11:41 1990 By muller *) (* Modified On Sat Feb 10 19:41:31 1990 By kalsow *) MODULE Inc; IMPORT CallExpr, Expr, Type, Procedure, Dec, Emit, Void, Temp, Target; IMPORT IntegerExpr, Address; VAR Z: CallExpr.MethodList; PROCEDURE Bind (<*UNUSED*> proc: Expr.T; <*UNUSED*> args: Expr.List): Type.T = BEGIN RETURN Void.T; END Bind; PROCEDURE Check (<*UNUSED*> proc: Expr.T; VAR args: Expr.List) = BEGIN Dec.DoCheck ("INC", args); END Check; PROCEDURE Compile (<*UNUSED*> proc: Expr.T; args: Expr.List): Temp.T = VAR t1, t2: Temp.T; bmin, bmax, imin, imax: INTEGER; inc: Expr.T; check: [0..3] := 0; BEGIN IF (NUMBER (args^) > 1) THEN inc := args[1]; ELSE inc := IntegerExpr.New (1); END; Expr.GetBounds (args[0], bmin, bmax); Expr.GetBounds (inc, imin, imax); IF (bmin # Target.MININT) AND (imin < 0) THEN INC (check) END; IF (bmax # Target.MAXINT) AND (imax > 0) THEN INC (check, 2) END; IF Type.IsSubtype (Expr.TypeOf (args[0]), Address.T) THEN check := 0; END; t1 := Expr.CompileLValue (args[0]); t2 := Expr.Compile (inc); CASE check OF | 0 => (* no range checking *) Emit.OpTT ("@ += @;\n", t1, t2); | 1 => (* check lower bound only *) Emit.OpTT ("if ((@ += @)", t1, t2); Emit.OpI (" < @) RANGEFAULT;\n", bmin); | 2 => (* check upper bound only *) Emit.OpTT ("if ((@ += @)", t1, t2); Emit.OpI (" > @) RANGEFAULT;\n", bmax); | 3 => (* check both bounds *) Emit.Op ("{\001\n"); Emit.OpI ("register t@ r;\n", Type.Name (Expr.TypeOf (args[0]))); Emit.OpTT ("r = (@ += @);\n", t1, t2); Emit.OpII ("if ((r < @) || (@ < r)) RANGEFAULT;\n", bmin, bmax); Emit.Op ("\002};\n"); END; Temp.Free (t2); Temp.Free (t1); RETURN t1; (*DUMMY*) END Compile; PROCEDURE Initialize () = BEGIN Z := CallExpr.NewMethodList (1, 2, FALSE, Bind, Check, Compile, CallExpr.NoValue, CallExpr.IsNever, (* writable *) CallExpr.IsNever(* designator *)); Procedure.Define ("INC", Z); END Initialize; BEGIN END Inc.