public MidAttributeDecl CacheAttr( MidExp exp, MidType type) { MidAttributeDecl attrDecl = null; if (_attrCache.TryGetValue(exp, out attrDecl)) { return(attrDecl); } if (exp is MidAttributeRef) { var attrRef = (MidAttributeRef)exp; attrDecl = attrRef.Decl; if (attrDecl.Element == this && attrDecl.Exp != null) { _attrCache[exp] = attrDecl; return(attrDecl); } } attrDecl = new MidAttributeDecl( _name.Factory.unique("attr"), this, type, exp); _attrCache[exp] = attrDecl; AddAttribute(attrDecl); return(attrDecl); }
private MidExp PostTransform(MidExp exp) { if (_postTransform == null) { return(exp); } return(_postTransform(exp)); }
public MidExp Transform(MidExp exp) { var e = PreTransform(exp); TransformChildren(e); e = PostTransform(e); return(e); }
public static ISpan Dump( this MidExp exp) { var span = new Span(); exp.Dump(span); return(span); }
public MidCase( MidVal value, MidExp body, SourceRange range) { this.Value = value; this.Body = body; _range = range; }
public T MaybeMoveTemp <T>(MidExp exp, MidType type) where T : MidExp { if (exp is T) { return((T)exp); } return((T)(MidExp)CreateTemp(exp, type)); }
public MidExp Wrap(MidExp body) { var result = body; foreach (var wrapper in _wrappers) { result = wrapper(result); } return(result); }
public MidLabelExp( SourceRange range, MidLabel label, MidExp body, MidType type) : base(range, type) { _label = label; _body = body; }
public MidIfExp( MidVal condition, MidExp thenExp, MidExp elseExp, SourceRange range) : base(range, new MidDummyType()) { this.Condition = condition; this.Then = thenExp; this.Else = elseExp; }
public MidLetExp( SourceRange range, MidVar var, MidExp exp, MidExp body) : base(range, new MidDummyType()) { _var = var; _exp = exp; _body = body; }
public MidAttributeDecl( Identifier name, MidElementDecl element, MidType type, MidExp exp) { _name = name; _element = element; _type = type; _exp = exp; }
public MidForExp( SourceRange range, MidVar var, MidVal seq, MidExp body) : base(range, new MidVoidType()) { _var = var; _seq = seq; _body = body; }
private MidExp SimplifyLabelExpImpl( MidLabelExp labelExp, MidExp exp, SimplifyEnv env) { if (!UsesLabel(exp, labelExp.Label)) { return(exp); } return(labelExp); }
private MidExp SimplifyExp(MidExp exp, SimplifyEnv env) { if (exp == null) { return(null); } var transform = new MidTransform( null, // no pre-transform (e) => SimplifyExpImpl((dynamic)e, env)); return(transform.Transform(exp)); }
public static void MarkOutputs(MidExp exp) { MidTransform transform = new MidTransform( (e) => { if (e is MidAttributeFetch) { ((MidAttributeFetch)e).Attribute.IsOutput = true; } return(e); }); transform.Transform(exp); }
public override MidVal CreateTemp(MidExp exp, MidType type) { if (_element != null) { var attrDecl = _element.CacheAttr(exp, type); return(_exps.AttributeRef(exp.Range, attrDecl)); } else { MidVar var = new MidVar(_identifiers.unique("temp"), type); Func <MidExp, MidExp> wrapper = (body) => new MidLetExp(exp.Range, var, exp, body); _wrappers.Insert(0, wrapper); return(new MidVarRef(exp.Range, var)); } }
private bool UsesVar( MidExp exp, MidVar var) { bool result = false; var transform = new MidTransform( (e) => { if (e is MidVarRef && (e as MidVarRef).Var == var) { result = true; } return(e); }); transform.Transform(exp); return(result); }
private bool UsesLabel( MidExp exp, MidLabel label) { bool result = false; var transform = new MidTransform( (e) => { if (e is MidBreakExp && (e as MidBreakExp).Label == label) { result = true; } return(e); }); transform.Transform(exp); return(result); }
private MidExp TryFoldPath( MidVar var, MidExp exp, MidPath path) { if (exp is MidFieldRef) { var midFieldRef = (MidFieldRef)exp; if (midFieldRef.Obj is MidVarRef) { var midVarRef = (MidVarRef)midFieldRef.Obj; if (midVarRef.Var == var) { midFieldRef.Obj = path; return(midFieldRef); } } } return(exp); }
private bool MightHaveSideEffects( MidExp exp) { bool result = false; var transform = new MidTransform( (e) => { if (e is MidAssignExp) { result = true; } if (e is MidBreakExp) { result = true; } if (e is MidIfExp) { result = true; } if (e is MidForExp) { result = true; } if (e is MidBuiltinApp) { // \todo: Need a *huge* fix for this. Stdlib functions that might // have side-effects need to be marked in some way to avoid this kind of thing... :( var app = (MidBuiltinApp)e; if (app.Decl.Name.ToString() == "Append") { result = true; } } return(e); }); transform.Transform(exp); return(result); }
public override MidVal CreateTemp(MidExp exp, MidType type) { throw new NotImplementedException(); }
public void TransformChildren(MidExp exp) { TransformChildrenImpl((dynamic)exp); }
public abstract MidVal CreateTemp(MidExp exp, MidType type);
public override MidVal CreateTemp(MidExp exp, MidType type) { return(_parent.CreateTemp(exp, type)); }
public MidExp PreTransform(MidExp exp) { return(exp); }
private MidExp SimplifyExpImpl(MidExp exp, SimplifyEnv env) { return(exp); }
private MidExp Replace( MidExp exp) { return(ReplaceImpl((dynamic)exp)); }
public MidExp CleanupExp(MidExp exp) { return(exp); }
public static void Dump( this MidExp exp, Span span) { DumpExpImpl((dynamic)exp, span); }