 (ns minijava.munch
-  (:use (minijava exp ir gas)))
+  (:use (minijava exp ir gas))
+  (:require [minijava.temp :as tm]))
 
 
 ;;helper method to do instanceof

(defmethod munchMap [:minijava.ir/Const java.lang.Integer]
  [x value] 	
  	;;Const(i) -> Movl $i Temp 
  	(let [d (Temp (minijava.ir.temp.Temp.))]  				
  				 (emit (movl (CONST value) d))
  				 d)) ;;Since Mem is an expression, it returns a temp.


 ;;Multiplication
(defmethod munchMap [:minijava.ir/BinaryOp :* :minijava.ir/Const  :minijava.exp/expression]
 [exp op rand1 rand2]       
  (let [d (tm/temp) ]
  		 	(emit (movl  (CONST (:val rand1)) d))
        (emit (imull  (munch rand2) d  ))
                    d))

(defmethod munchMap [:minijava.ir/BinaryOp :* :minijava.exp/expression :minijava.ir/Const ] 
  [exp op rand1 rand2]    
  (let [d (tm/temp) ]
  		 	(emit (movl  (munch rand1) d))
        (emit (imull (CONST (:val rand2)) d))
                    d))
