Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/charisee/src/compiler/tree-il/tree-func.sml
ViewVC logotype

View of /branches/charisee/src/compiler/tree-il/tree-func.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2845 - (download) (annotate)
Fri Dec 12 06:46:23 2014 UTC (4 years, 7 months ago) by cchiw
File size: 3911 byte(s)
added norm
(* Opr. Used to trigger types of c functions that need to be created during the next stage
* StoreAligned has been removed
*  hash needs help
*)

structure TreeFunc= struct

    structure Ty = TreeILTypes
    structure Op = TreeOps


    (*Local var for cons-> then Tree.Assign-> call vector function CONSV
    else  store stmt and uses arrays CONS
    *)
    datatype oprator = LDArr of bool*int * int
            (*Aligned,oldSize, to newSize*)
        | OP of Op.rator
        | CONS of  int (*returns an array*)
        | CONSV of int  (*returns vec*)
        | STORE of bool*int *int  (*Aligned, oSize,nSize*)
        | COPY of int (*copy two arrays of size int*)

    fun iTos m=Int.toString m

    fun same( LDArr(a0,a1,a2), LDArr(b0,b1,b2))=(a0=b0) andalso Op.sameint(a1, b1) andalso Op.sameint(a2, b2)
    (*| same ( STORE(a0,a1,a2),  STORE(b0,b1,b2))=
        if (a2>a1) then
             if (b2>b1) then Op.sameint(a1, b1) andalso Op.sameint(a2, b2)
             else false
        else  (a0=b0) andalso Op.sameint(a2, b2)*)
    | same ( STORE(a0,a1,a2),  STORE(b0,b1,b2))=Op.sameint(a1,b1)
    | same(OP(Op.sumVec (n1,o1)),OP(Op.sumVec (n2,o2)))=
            if(n1>o1) then
                if(n2>o2)   then Op.sameint(n1,n2) andalso Op.sameint(o1, o2)
                else false
            else Op.sameint(o1, o2)
    | same ( OP a0,  OP b0)     = Op.same(a0,b0)
    | same ( CONS(a0), CONS(b0))  = Op.sameint(a0,b0)
    | same ( CONSV a0, CONSV b0)= Op.sameint(a0,b0)
    | same ( COPY a0, COPY b0)= Op.sameint(a0,b0)
    | same _ =false

    fun boolToHash true=0w3
      | boolToHash _=0w7

    fun  hash( LDArr(a2,a0,a1)) =0w3+Op.hashint a0 + Op.hashint a1+boolToHash a2
    (* | hash ( STORE  (A,oSize,nSize))= 0w11 + boolToHash A+Op.hashint oSize  + Op.hashint nSize*)
    | hash ( STORE  (_,oSize,_))= 0w17 +Op.hashint oSize
    | hash(  CONSV a0)= 0w29 +Op.hashint a0
    | hash ( OP(Op.prodScaV n))= 0w71 +  Op.hashint n
    | hash ( OP rator)= 0w131 + Op.hash(rator)
    | hash(  CONS a0)= 0w141 +Op.hashint(a0)
    | hash(  COPY a0)= 0w147 +Op.hashint a0

    fun boolToString true="Aligned"
    | boolToString false="NotAligned"

    fun isAligned true = "Aligned"
    | isAligned _ = "NotAligned"

    fun toString(LDArr (A,nSize,oSize))=String.concat["LDArr:", iTos oSize , "to",iTos nSize,isAligned A]
   (* | toString(STORE  (A,oSize, nSize))= if (nSize>oSize)
        then String.concat["store",isAligned A,iTos nSize,"to",iTos oSize]
        else String.concat["store",isAligned A,iTos nSize,"to",iTos oSize]*)
    | toString(STORE  (A,oSize, nSize))=  String.concat["store",isAligned  A,":",iTos oSize,"-to-",iTos nSize]
    | toString(OP rator)=String.concat["OP-",Op.toString rator]
    | toString(CONS(a0))= String.concat["CONStoArrayType-",iTos a0]
    | toString(CONSV a0)= String.concat["CONStoVecType-",iTos a0]
    | toString(COPY a0)=String.concat["COPY-",iTos a0]

    fun cmp(e1,e2)=(case same(e1,e2)
        of true=>EQUAL
            | _ => (case (Word.compare(hash e1, hash e2))
            of EQUAL =>LESS
            |oo => oo
        (*end case*))
    (*end case*))

    structure StringKey =
        struct
            type ord_key = Ty.ty
            val compare = Ty.cmp
        end;

    structure TySet = RedBlackSetFn(StringKey);

    structure OprKey =
        struct
            type ord_key = oprator
            val compare = cmp
        end;

    structure  OprSet= RedBlackSetFn(OprKey);

    fun setListToString(typsList,oprList,prefix)=let
        val str1= List.map Ty.toString typsList
        val str2=List.map toString oprList
    in
        String.concat[prefix,"\n \t Types: ",String.concatWith "," str1,"\n \t cFn: ",String.concatWith "\n\t" str2]
    end

    fun setToString(typs,ops,prefix)=let
        val typsList=TySet.listItems(typs);
        val oprList=OprSet.listItems(ops);
    in setListToString(typsList,oprList,prefix) end

end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0