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 2695 - (download) (annotate)
Fri Sep 12 01:55:00 2014 UTC (4 years, 11 months ago) by cchiw
File size: 2950 byte(s)
change to vector ops
(* 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*bool
            (*last bool: true for Array, false for vector*)
        | OP of Op.rator
        | CONS of  Ty.ty (*returns Diderot_real Prog-Ty*)
        | CONSV of int  (*returns vec*)
        | STORE of bool*int *int (*Aligned, RtnSize, ArgSize*)


    fun iTos m=Int.toString m

    fun same( LDArr(a0,a1,a2,a3), LDArr(b0,b1,b2,b3))=(a0=b0) andalso Op.sameint(a1, b1) andalso Op.sameint(a2, b2) andalso (a3=b3)
    | same ( STORE(a0,a1,a2),  STORE(b0,b1,b2))=(a0=b0) andalso Op.sameint(a1, b1) andalso Op.sameint(a2, b2)
    | same ( OP a0,  OP b0)     = Op.same(a0,b0)
    | same ( CONS(a0), CONS(b0))  = Ty.same(a0,b0)
    | same ( CONSV a0, CONSV b0)= Op.sameint(a0,b0)
    | same _ =false


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

    fun hash( LDArr(a2,a0,a1,a3)) =Op.hashint a0 + Op.hashint a1+boolToHash a2 +boolToHash a3
    | hash ( STORE  (true,nSize,oSize))= 0w13 + Op.hashint nSize  + Op.hashint oSize
    | hash ( STORE  (false,nSize,oSize))= 0w19 + Op.hashint nSize  + Op.hashint oSize
    | hash ( OP rator)= 0w7 + Op.hash(rator)
    | hash(  CONS a0)= 0w11 +Ty.hash(a0)
    | hash(  CONSV a0)= 0w13 +Op.hashint a0

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

    fun tyToString true="Arrays"
    | tyToString _ ="vectors"

    fun toString( LDArr (b,nSize,oSize,ty))=String.concat["LDArr:", iTos oSize , "to",iTos nSize,boolToString b,tyToString ty]
    | toString( STORE  (b,nSize,oSize))= String.concat["STOREToArr(",iTos nSize,"to",iTos oSize,")",boolToString b]
    | toString( OP rator)=String.concat["OP-",Op.toString rator]
    | toString( CONS(a0))= String.concat["CONStoArrayType-",Ty.toString a0]
    | toString( CONSV a0)= String.concat["CONStoVecType-",iTos a0]
 
    fun cmp(e1,e2)=String.compare(toString e1, toString e2)

    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