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 2795 - (download) (annotate)
Tue Nov 4 21:58:11 2014 UTC (4 years, 11 months ago) by cchiw
File size: 3377 byte(s)
field problem
(* Opr. Used to trigger types of c functions that need to be created during the next stage *)

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 sameOPT(NONE,NONE)=true
      | sameOPT(SOME i, SOME j)=Op.sameint(i,j)
      | sameOPT _=false

    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))=(a0=b0) andalso Op.sameint(a1, b1) andalso Op.sameint(a2, b2)
    | same(OP( Op.ProjectTensor(a0,_)),OP(Op.ProjectTensor(b0, _ )))=Op.sameint(a0,b0)
    | 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))= 0w7 + boolToHash A+Op.hashint oSize  + Op.hashint nSize
    | hash ( OP (Op.ProjectTensor(a0,_)))= 0w23 + Op.hashint a0
    | hash ( OP rator)= 0w11 + Op.hash(rator)
    | hash(  CONS a0)= 0w13 +Op.hashint(a0)
    | hash(  CONSV a0)= 0w17 +Op.hashint a0
    | hash(  COPY a0)= 0w19 +Op.hashint a0

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

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

    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",iTos nSize,"to",iTos oSize]
        else String.concat["store",isAligned A,iTos nSize]    
    | toString(OP (Op.ProjectTensor(d,_)))=String.concat["OP-ProjectTensor",iTos d]
    | 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)=String.compare(toString e1, toString e2)

    structure StringKey =
            type ord_key = Ty.ty
            val compare = Ty.cmp

    structure TySet = RedBlackSetFn(StringKey);

    structure OprKey =
            type ord_key = oprator
            val compare = cmp

    structure  OprSet= RedBlackSetFn(OprKey);

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

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


ViewVC Help
Powered by ViewVC 1.0.0