Example #1
0
        public void ApplyToPipeline(MidPipelineDecl p)
        {
            _attributesToKeep.Clear();
            _mapOldToNew.Clear();
            _mapOldToWrapper.Clear();
            _attributeWrappersToKeep.Clear();

            // Find all the attributes worth keeping...
            CollectPipelineInfo(p);

            // Now go ahead and blow away all the old attributes,
            // replacing them with shiny new ones!!!

            _transform = new MidTransform(
                (e) => CleanupExp((dynamic)e));

            foreach (var e in p.Elements)
            {
                e.Clear();
            }

            foreach (var a in _attributesToKeep)
            {
                if (a.Exp != null)
                {
                    a.Exp = _transform.Transform(a.Exp);
                }

                var newAttr = MapOldToNew(a);
            }

            // We copy the attributes array, since otherwise
            // we end up mutating it by adding new attributes
            foreach (var e in p.Elements)
            {
                foreach (var a in e.Attributes.ToArray())
                {
                    _transform.ApplyToAttribute(a);
                }
            }
            foreach (var m in p.Methods)
            {
                if (m.Body != null)
                {
                    m.Body = _transform.Transform(m.Body);
                }
            }

            foreach (var e in p.Elements)
            {
                var oldWrappers = e.AttributeWrappers.ToArray();

                var newWrappers = (from w in oldWrappers
                                   where _attributeWrappersToKeep.Contains(w)
                                   select w).ToArray();

                e.AttributeWrappers = newWrappers;
            }
        }
        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);
        }
Example #3
0
        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));
        }
Example #4
0
        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 void ApplyToPipeline( MidPipelineDecl p )
        {
            _attributesToKeep.Clear();
            _mapOldToNew.Clear();
            _mapOldToWrapper.Clear();
            _attributeWrappersToKeep.Clear();

            // Find all the attributes worth keeping...
            CollectPipelineInfo( p );

            // Now go ahead and blow away all the old attributes,
            // replacing them with shiny new ones!!!

            _transform = new MidTransform(
                ( e ) => CleanupExp( (dynamic) e ) );

            foreach( var e in p.Elements )
                 e.Clear();

            foreach( var a in _attributesToKeep )
            {
                if( a.Exp != null )
                    a.Exp = _transform.Transform( a.Exp );

                var newAttr = MapOldToNew( a );
            }

            // We copy the attributes array, since otherwise
            // we end up mutating it by adding new attributes
            foreach( var e in p.Elements )
                foreach( var a in e.Attributes.ToArray() )
                    _transform.ApplyToAttribute( a );
            foreach( var m in p.Methods )
            {
                if( m.Body != null )
                    m.Body = _transform.Transform( m.Body );
            }

            foreach( var e in p.Elements )
            {
                var oldWrappers = e.AttributeWrappers.ToArray();

                var newWrappers = (from w in oldWrappers
                                   where _attributeWrappersToKeep.Contains(w)
                                   select w).ToArray();

                e.AttributeWrappers = newWrappers;
            }
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #8
0
        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);
        }
        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 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);
        }
        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;
        }