private MidExp SimplifyLabelExpImpl( MidLabelExp labelExp, MidLetExp letExp, SimplifyEnv env) { // As long as the label doesn't occur in the // bound expression, we can move it outside // of the label's bounds. if (!UsesLabel(letExp.Exp, labelExp.Label)) { MidExp result = new MidLetExp( letExp.Range, letExp.Var, letExp.Exp, new MidLabelExp( labelExp.Range, labelExp.Label, letExp.Body, labelExp.Type)); result = SimplifyExp(result, env); return(result); } return(labelExp); }
private MidExp SimplifyExpImpl(MidLetExp exp, SimplifyEnv env) { if (exp.Exp is MidVal) { // The variable is just being bound to a simple // value, so substitute it away: var innerEnv = new SimplifyEnv(env); innerEnv.Insert(exp.Var, (MidVal)exp.Exp); return(SimplifyExp(exp.Body, innerEnv)); } if (exp.Exp is MidBreakExp) { // Well, we can't possibly get to the rest of the // expression, right? return(exp.Exp); } if (exp.Body is MidVarRef) { var midVarRef = (MidVarRef)exp.Body; if (midVarRef.Var == exp.Var) { return(exp.Exp); } } if (exp.Exp is MidPath) { var midPath = (MidPath)exp.Exp; // Try to substitute this path into // any down-stream field references... var midLet = exp; while (midLet != null) { midLet.Exp = TryFoldPath(exp.Var, midLet.Exp, midPath); midLet.Body = TryFoldPath(exp.Var, midLet.Body, midPath); midLet = midLet.Body as MidLetExp; } } if (!UsesVar(exp.Body, exp.Var) && !MightHaveSideEffects(exp.Exp)) { // \todo: Should be able to DCE the let expression away, // but to do that we need to be sure it doesn't have // any side-effects... :( return(exp.Body); } return(exp); }
private static void DumpExpImpl( MidLetExp let, Span span) { span.Write("let {0} = ", let.Var.Name); let.Exp.Dump(span.IndentSpan()); span.WriteLine(";"); let.Body.Dump(span); }
private EmitValHLSL EmitExpImpl(MidLetExp let, Span span) { var initVal = EmitExp(let.Exp, span); #if ALWAYSBIND // \todo: Just use the type from init? var varType = EmitType(let.Var.Type); var var = varType.CreateVal( _shared.GenerateName("_var")); _varVals[let.Var] = var; DeclareAndInitLocal( var, initVal, span); #else _varVals[let.Var] = initVal; #endif return EmitExp(let.Body, span); }
public void PreEmitExpImpl( MidLetExp exp, Span span) { PreEmitExp(exp.Exp, span); PreEmitExp(exp.Body, span); }
private void TransformChildrenImpl( MidLetExp let) { let.Exp = Transform(let.Exp); let.Body = Transform(let.Body); }
private MidExp SimplifyLabelExpImpl( MidLabelExp labelExp, MidLetExp letExp, SimplifyEnv env) { // As long as the label doesn't occur in the // bound expression, we can move it outside // of the label's bounds. if (!UsesLabel(letExp.Exp, labelExp.Label)) { MidExp result = new MidLetExp( letExp.Range, letExp.Var, letExp.Exp, new MidLabelExp( labelExp.Range, labelExp.Label, letExp.Body, labelExp.Type)); result = SimplifyExp(result, env); return result; } return labelExp; }
private MidExp SimplifyExpImpl(MidLetExp exp, SimplifyEnv env) { if (exp.Exp is MidVal) { // The variable is just being bound to a simple // value, so substitute it away: var innerEnv = new SimplifyEnv(env); innerEnv.Insert(exp.Var, (MidVal) exp.Exp); return SimplifyExp(exp.Body, innerEnv); } if (exp.Exp is MidBreakExp) { // Well, we can't possibly get to the rest of the // expression, right? return exp.Exp; } if (exp.Body is MidVarRef) { var midVarRef = (MidVarRef)exp.Body; if (midVarRef.Var == exp.Var) return exp.Exp; } if (exp.Exp is MidPath) { var midPath = (MidPath)exp.Exp; // Try to substitute this path into // any down-stream field references... var midLet = exp; while (midLet != null) { midLet.Exp = TryFoldPath(exp.Var, midLet.Exp, midPath); midLet.Body = TryFoldPath(exp.Var, midLet.Body, midPath); midLet = midLet.Body as MidLetExp; } } if (!UsesVar(exp.Body, exp.Var) && !MightHaveSideEffects(exp.Exp)) { // \todo: Should be able to DCE the let expression away, // but to do that we need to be sure it doesn't have // any side-effects... :( return exp.Body; } return exp; }