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 2663 - (download) (annotate)
Fri May 30 18:02:41 2014 UTC (5 years, 4 months ago) by cchiw
File size: 2249 byte(s)
added decl
(* Get Types of Expressions *)

structure TreeFunc= struct

    structure Ty = TreeILTypes
    structure Op = TreeOps

    datatype oprator = LD of int * int  | MKVEC of int *Ty.ty | OP of Op.rator
        | CONS of Ty.ty |  REALTOVEC of int
        |  LDAligned of int * int  | MKVECAligned of int *Ty.ty


    
    fun q m=Int.toString(m)


    fun same( LD(a0,a1), LD(b0,b1))= Op.sameint(a0, b0) andalso Op.sameint(a1, b1)
    | same ( MKVEC(a0,a1),  MKVEC (b0,b1))=Op.sameint(a0, b0) andalso Ty.same(a1,b1)
    | same ( OP a0,  OP b0)= Op.same(a0,b0)
    | same ( CONS a0, CONS b0)= Ty.same(a0,b0)
    | same(REALTOVEC a0, REALTOVEC b0)=Op.sameint(a0,b0)
    | same( LDAligned (a0,a1), LDAligned (b0,b1))= Op.sameint(a0, b0) andalso Op.sameint(a1, b1)
    | same ( MKVECAligned (a0,a1),  MKVECAligned  (b0,b1))=Op.sameint(a0, b0) andalso Ty.same(a1,b1)
    | same _ =false

    fun hash( LD(a0,a1)) =0w3+Op.hashint a0 + Op.hashint a1
    | hash ( MKVEC (tyOrig,a1))= 0w5 + Op.hashint tyOrig+Ty.hash a1 
    | hash ( OP(rator))= 0w7 + Op.hash(rator)
    | hash(  CONS a0)= 0w11 +Ty.hash(a0)
    | hash(REALTOVEC a0)= 0w19 + Op.hashint a0
    | hash( LDAligned (a0,a1)) =0w3+Op.hashint a0 + Op.hashint a1
    | hash ( MKVECAligned  (tyOrig,a1))= 0w5 + Op.hashint tyOrig+Ty.hash a1

    fun toString( LD (tyNew,tyOrig))= String.concat["LD:", q tyOrig , "to",q tyNew]
    | toString( MKVEC (tyOrig,pieces))=String.concat["MKVEC(",q tyOrig,")",Ty.toString pieces]
    | toString( OP(rator))=String.concat["OP-",Op.toString rator]
    | toString( CONS a0)= String.concat["CONS-",Ty.toString(a0)]
    | toString(REALTOVEC a0)=String.concat["RealToVEC-", q a0]
    | toString( LDAligned  (tyNew,tyOrig))= String.concat["LD:", q tyOrig , "to",q tyNew]
    | toString( MKVECAligned (tyOrig,pieces))=String.concat["MKVEC(",q tyOrig,")",Ty.toString pieces]


    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);

end

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