Пример #1
0
            public void Store(IStorableLiteral var, Expression val)
            {
                if (var.StoreMode != EStoreMode.Transfer)
                {
                    throw new NotSupportedException();
                }

                _isTarget = true;
                var.Accept(this);

                var rhs = val as LiteralReference;

                if (rhs == null)
                {
                    throw new NotSupportedException();
                }

                _isTarget = false;
                rhs.ReferencedObject.Accept(this);
            }
Пример #2
0
 public InlineFieldMapperTransactionSite(InlineFieldMapper mapper, Component host, IStorableLiteral literal) :
     base(host)
 {
     _mapper = mapper;
     _literal = literal;
 }
Пример #3
0
 /// <summary>
 /// Creates an instruction which stores its operand to a variable
 /// </summary>
 public XILInstr StoreVar(IStorableLiteral v)
 {
     return(new XILInstr(InstructionCodes.StoreVar, v));
 }
Пример #4
0
 /// <summary>
 /// Declares a literal as output argument.
 /// </summary>
 /// <param name="var">literal to declare as output argument</param>
 protected void DeclareOutput(IStorableLiteral var)
 {
     ResultFunction.OutputVariables.Add(var);
 }
Пример #5
0
        public virtual void DeclareLocal(IStorableLiteral var)
        {
            Contract.Assume(_cstack.Count > 0);

            _cstack.Peek().Locals.Add(var);
            ResultFunction.LocalVariables.Add(var);
        }
Пример #6
0
        public virtual void Store(IStorableLiteral var, Expression val)
        {
            if (var == null || val == null)
                throw new ArgumentException();

            StoreStatement stmt = new StoreStatement()
            {
                Container = var,
                Value = val
            };
            _cstack.Peek().Statements.Add(stmt);
        }
Пример #7
0
 public void Store(IStorableLiteral var, Expression val)
 {
     Contract.Requires(var != null);
     Contract.Requires(val != null);
 }
Пример #8
0
 public void DeclareLocal(IStorableLiteral v)
 {
     Contract.Requires(v != null);
 }
Пример #9
0
        private bool TryInline(ICallable callable, Expression[] args, out IStorableLiteral retv)
        {
            FunctionSpec fspec = callable as FunctionSpec;
            retv = null;
            if (fspec != null)
            {
                // Do not inline intrinsic functions
                if (fspec.IntrinsicRep != null)
                    return false;

                var md = fspec.SpecialSysDOMRep;
                if (md != null)
                {
                    var fun = md.Implementation;

                    InlineVerifier.CheckAllLocalsDeclared(fun);

                    // Recursion?
                    if (_funStack.Contains(fun))
                        return false;

                    if (fun.OutputVariables.Count == 0)
                    {
                        if (!fspec.ResultType.CILType.Equals(typeof(void)))
                        {
                            string name = _sim.GetUniqueName("$ret", new object());
                            IStorableLiteral rv = new Variable(fspec.ResultType)
                            {
                                Name = name
                            };
                            retv = _locals[Tuple.Create(fun, rv)];
                        }
                    }
                    else if (fun.OutputVariables.Count == 1)
                    {
                        retv = _locals[Tuple.Create(fun, fun.OutputVariables[0])];
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }

                    // account for possible "this" argument
                    int j = args.Length - fun.InputVariables.Count;

                    for (int i = j; i < args.Length; i++)
                    {
                        Expression rhs = args[i].Transform(this);
                        var lhs = _locals[Tuple.Create(fun, fun.InputVariables[i - j])];
                        Store(lhs, rhs);
                    }
                    if (retv != null)
                        _retStack.Push(retv);
                    _funStack.Push(fun);
                    _getOutStack.Push(new List<GotoStatement>());
                    fun.Body.Accept(this);
                    _funStack.Pop();
                    if (retv != null)
                        _retStack.Pop();
                    Nop();
                    foreach (var getOut in _getOutStack.Pop())
                    {
                        getOut.Target = LastStatement;
                    }

                    _inlinedFunctions.Add(fun);

                    return true;
                }
                else
                {
                    //System.Diagnostics.Debug.Assert(false, "function not decompiled - bug?");
                }
            }
            return false;
        }
Пример #10
0
        private bool TryInline(ICallable callable, Expression[] args, out IStorableLiteral retv)
        {
            FunctionSpec fspec = callable as FunctionSpec;

            retv = null;
            if (fspec != null)
            {
                // Do not inline intrinsic functions
                if (fspec.IntrinsicRep != null)
                {
                    return(false);
                }

                var md = fspec.SpecialSysDOMRep;
                if (md != null)
                {
                    var fun = md.Implementation;

                    InlineVerifier.CheckAllLocalsDeclared(fun);

                    // Recursion?
                    if (_funStack.Contains(fun))
                    {
                        return(false);
                    }

                    if (fun.OutputVariables.Count == 0)
                    {
                        if (!fspec.ResultType.CILType.Equals(typeof(void)))
                        {
                            string           name = _sim.GetUniqueName("$ret", new object());
                            IStorableLiteral rv   = new Variable(fspec.ResultType)
                            {
                                Name = name
                            };
                            retv = _locals[Tuple.Create(fun, rv)];
                        }
                    }
                    else if (fun.OutputVariables.Count == 1)
                    {
                        retv = _locals[Tuple.Create(fun, fun.OutputVariables[0])];
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }

                    // account for possible "this" argument
                    int j = args.Length - fun.InputVariables.Count;

                    for (int i = j; i < args.Length; i++)
                    {
                        Expression rhs = args[i].Transform(this);
                        var        lhs = _locals[Tuple.Create(fun, fun.InputVariables[i - j])];
                        Store(lhs, rhs);
                    }
                    if (retv != null)
                    {
                        _retStack.Push(retv);
                    }
                    _funStack.Push(fun);
                    _getOutStack.Push(new List <GotoStatement>());
                    fun.Body.Accept(this);
                    _funStack.Pop();
                    if (retv != null)
                    {
                        _retStack.Pop();
                    }
                    Nop();
                    foreach (var getOut in _getOutStack.Pop())
                    {
                        getOut.Target = LastStatement;
                    }

                    _inlinedFunctions.Add(fun);

                    return(true);
                }
                else
                {
                    //System.Diagnostics.Debug.Assert(false, "function not decompiled - bug?");
                }
            }
            return(false);
        }
Пример #11
0
 public void DeclareLocal(IStorableLiteral v)
 {
 }
Пример #12
0
 public InlineFieldMapperTransactionSite(InlineFieldMapper mapper, Component host, IStorableLiteral literal) :
     base(host)
 {
     _mapper  = mapper;
     _literal = literal;
 }