(* Copyright (C) 1989, Digital Equipment Corporation *) (* All rights reserved. *) (* See the file COPYRIGHT for a full description. *) (* File: DivExpr.m3 *) (* Last modified on Sat Feb 10 17:34:27 1990 by kalsow *) (* modified on Tue Oct 10 18:42:50 1989 by muller *) MODULE DivExpr; 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 DIV"); END; END Check; PROCEDURE Compile (p: P): Temp.T = VAR t1, t2, t3: Temp.T; BEGIN t1 := Expr.Compile (p.a); t2 := Expr.Compile (p.b); t3 := Temp.Alloc (p); Emit.OpTTT ("@ = IDIV (@, @);\n", t3, t1, t2); 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 IntegerExpr.Div (e1, e2, e3) THEN END; RETURN e3; END Fold; PROCEDURE FPrinter (p: P; map: Type.Map; wr: Wr.T) = BEGIN Wr.PutText (wr, "DIV "); Expr.Fingerprint (p.a, map, wr); Expr.Fingerprint (p.b, map, wr); END FPrinter; BEGIN END DivExpr.