(* simplify-vars.sml * * This module analyses the use of variables in the Simple AST and rationalizes * their use in the following ways: * * -- for any strand parameter that is used in a method, we create a shadow state * variable * * -- unused constant and global variables are elminated * * -- unused strand state variables are eliminated * * -- unused local variables are eliminated * * -- strand-invariant state variables (except outputs) and expressions are * lifted to global scope * * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu) * * COPYRIGHT (c) 2015 The University of Chicago * All rights reserved. *) structure SimplifyVars : sig val transform : Simple.program -> Simple.program end = struct structure S = Simple (* analyze an expression using the `doVar` and `doFld` * functions to analyze variable uses. *) fun analyzeExp doVar doFld = let fun anal (env, e) = (case e of S.E_Var x => doVar(x, env) | S.E_Lit _ => env | S.E_Select(x, fld) => doFld (fld, doVar(x, env)) | S.E_Apply(f, xs, _) => List.foldl doVar env (f::xs) | S.E_Prim(_, _, xs, _) => List.foldl doVar env xs | S.E_Tensor(xs, _) => List.foldl doVar env xs | S.E_Seq(xs, _) => List.foldl doVar env xs | S.E_Slice(x, indices, _) => let fun doIndex (NONE, env) = env | doIndex (SOME ix, env) = doVar(ix, env) in doVar (x, List.foldl doIndex env indices) end | S.E_Coerce{x, ...} => doVar(x, env) | S.E_LoadSeq _ => () | S.E_LoadImage _ => () (* end case *)) in anal end (* transform a strand definition. This includes introducing shadow state variables for * parameters, eliminating unused state variables, and identifying and lifting invariant * computations. *) fun doStrand (S.Strand{name, params, state, stateInit, initM, updateM, stabilizeM}) = let in () end fun transform prog = prog end
Click to toggle
does not end with </html> tag
does not end with </body> tag
The output has ended thus: stateInit, initM, updateM, stabilizeM}) = let in () end fun transform prog = prog end