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-forvis/tree-func.sml
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3690 - (download) (annotate)
Thu Mar 17 20:09:08 2016 UTC (3 years, 6 months ago) by cchiw
File size: 3394 byte(s)
tree-il code for vis15 branch
 (* Opr. Used to trigger types of c functions that need to be created during the next stage *)

structure TreeFunc = struct

    structure Ty = TreeTypes
    structure Op = TreeOps


    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 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)) = Op.sameint (a1, b1) andalso  a0 = b0
    | same (OP (Op.VSum ([n1], o1)), OP (Op.VSum ([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 (Op.VSum (n1, o1)), OP (Op.VSum (n2, o2))) = 
        if ( (n1 = n2) andalso (o1 = o2)) then true else false
    | 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 t= if (t) then  0w3 else 0w7

    fun  hash ( LDArr (a2, a0, a1)) = 0w3 + Op.hashint a0 + Op.hashint a1 + boolToHash a2
    | hash ( STORE (A, oSize, _)) =   0w17 + Op.hashint oSize + boolToHash A
    | hash (CONSV a0) = 0w29 + Op.hashint a0
    | hash ( OP (Op.VScale 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 isAligned t = if (t) then "Aligned" else "NotAligned"
    fun iTos m = Int.toString m
    fun toString (LDArr (A, nSize, oSize)) = String.concat["LDArr:", iTos oSize , "to", iTos nSize, isAligned A]
    | 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) =
        if (same (e1, e2)) then EQUAL
        else (case (Word.compare (hash e1, hash e2))
            of EQUAL => LESS
            |t => t
            (*end case*))

  fun cmp2(e1,e2)=String.compare(Ty.toString(e1), Ty.toString(e2))

    structure StringKey = 
        struct
            type ord_key = Ty.ty
            val compare = cmp2
        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