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

SCM Repository

[diderot] View of /branches/charisee/src/compiler/ein/phase-ein.sml
ViewVC logotype

View of /branches/charisee/src/compiler/ein/phase-ein.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2498 - (download) (annotate)
Wed Oct 30 17:35:23 2013 UTC (7 years, 10 months ago) by cchiw
File size: 2785 byte(s)
add type checking
(*checks to make sure ein_exp in correct phase*)
structure PhaseEin = struct

local

structure E = Ein
structure P = Printer
in

val errTy=1
val correct=0


fun err(msg)= (print "";errTy)


fun checkPhase (Ein.EIN{params, index, body},phase) = let

    fun checkTenParam id=
        if(id>length(params))then errTy
        else (case List.nth(params,id)
            of E.TEN => 0
            |  _ =>errTy
            (*end case*))


fun checkFldParam id=(
(*print(Int.toString(length(params)));print(Int.toString(id));*)

    if(id>length(params))then (print "in here";errTy)
        else(case List.nth(params,id)
        of  E.FLD _ =>0
            |_=> errTy
        (*end case*)))


        fun sort([])=0
        | sort(0::es)=sort(es)
        | sort _=1 

    (*make sure the finished expression is the shape it is suppose to be *)
    fun checkbody term = (case term
        of E.Const r => 0
        | E.Tensor(id, _) =>checkTenParam id
        | E.Delta(ix)=>0
        | E.Value(ix) =>0
        | E.Epsilon _ => 0
        | E.Sum (_,e1)=>checkbody e1
        | E.Neg e1=> checkbody e1
        | E.Partial a =>  0
        | E.Add es => sort(List.map checkbody es)
        | E.Sub(e1, e2) =>(case (checkbody e1 ,checkbody e2)
            of (0, 0)=> 0
            |_=>errTy
            (*end case*))
        | E.Prod el => sort(List.map checkbody el)
        | E.Div(e1,e2)=>(case (checkbody e1,checkbody e2)
            of(0 ,0)=>0
            | _=>errTy
            (*end case*))

        (*Phase dependent operators*)
        (*Phase 1 High-IL *)
        | E.Apply(e1, e2)=>
            if (2>phase) then
                (case (checkbody e1,checkbody e2)
                of (0,0)=>0
                |_ =>errTy
                (*end case*))
            else err "wrong phase for apply"
        | E.Probe (e1,e2)=>(
            if (2>phase) then
                (case (checkbody e1, checkbody e2)
                of (0,0)=>0
                | (0, _)=> err "wrong pos for field probe"
                |  _=>err "Not a fieldTy in probe"
                (*end case*))
            else err "wrong phase for Probe op")
        | E.Field(id, _)=>
            if (2>phase) then checkFldParam id
             else err "wrong phase for Field"
        | E.Conv (fid,_, tid, beta)=>(
             if (2>phase) then (checkFldParam(fid)+checkTenParam(tid))
            else err "wrong phase for convolution"
        )
        (*Phase 2 Mid-IL*)
        | E.Krn (_,dels,_) =>
            if (3>phase) then err "wrong phrase for kernel"
            else 0
        | E.Img(id,ix,pos)=>
            if(3 >phase) then errTy
            else 0
        (* end case *))

    val checked=checkbody body
    in (if (checked=0) then true
        else false)
    end


end; (* local *)

end (* local *)

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