(* Copyright (C) 1989, Digital Equipment Corporation *) (* All rights reserved. *) (* See the file COPYRIGHT for a full description. *) (* File: ModExpr.m3 *) (* Last modified on Sat Feb 10 17:40:18 1990 by kalsow *) (* modified on Tue Oct 10 18:42:33 1989 by muller *) MODULE ModExpr; IMPORT Expr, ExprAB, ExprRep, Type, Int, Error, Emit, IntegerExpr, Temp, Wr; TYPE P = ExprAB.T OBJECT METHODS bind := ExprAB.Bind; check := Check; compile := Compile; evaluate := Fold; fprint := FPrinter; write := ExprRep.NoWriter; isEqual := ExprAB.EqCheck; getBounds := ExprRep.NoBounds; isWritable := ExprRep.IsNever; isDesignator := ExprRep.IsNever; isZeroes := ExprRep.IsNever; genLiteral := ExprRep.NoLiteral; END; PROCEDURE New (a, b: Expr.T): Expr.T = VAR p: P; BEGIN p := NEW (P); ExprRep.Init (p); p.a := a; p.b := b; p.type := Int.T; RETURN p; END New; PROCEDURE Check (p: P) = VAR ta, tb: Type.T; BEGIN Expr.TypeCheck (p.a); Expr.TypeCheck (p.b); ta := Type.Base (Expr.TypeOf (p.a)); tb := Type.Base (Expr.TypeOf (p.b)); IF (ta # Int.T) OR (tb # Int.T) THEN Error.Msg ("illegal operands for MOD"); END; END Check; PROCEDURE Compile (p: P): Temp.T = VAR t1, t2, t3, t11, t12: Temp.T; BEGIN t1 := Expr.Compile (p.a); t2 := Expr.Compile (p.b); t11 := Temp.AllocEmpty (Int.T); t12 := Temp.AllocEmpty (Int.T); t3 := Temp.Alloc (p); Emit.OpTT ("@ = @;\n", t11, t1); Emit.OpTT ("@ = @;\n", t12, t2); Emit.OpTT ("@ = @ - ", t3, t11); Emit.OpTTT ("(@ * (IDIV (@, @)));\n", t12, t11, t12); Temp.Free (t11); Temp.Free (t12); Temp.Free (t1); Temp.Free (t2); RETURN t3; END Compile; PROCEDURE Fold (p: P): Expr.T = VAR e1, e2, e3: Expr.T; BEGIN e1 := Expr.ConstValue (p.a); e2 := Expr.ConstValue (p.b); e3 := NIL; IF (e1 = NIL) OR (e2 = NIL) THEN ELSIF IntegerExpr.Mod (e1, e2, e3) THEN END; RETURN e3; END Fold; PROCEDURE FPrinter (p: P; map: Type.Map; wr: Wr.T) = BEGIN Wr.PutText (wr, "MOD "); Expr.Fingerprint (p.a, map, wr); Expr.Fingerprint (p.b, map, wr); END FPrinter; BEGIN END ModExpr.