示例#1
0
        private void ApplyRuleForMoveTupleLiteral(ref bool appliedRule, Core.InstructionMoveLiteralTuple inst)
        {
            var destType = TypeResolver.GetDataAccessType(session, funct, inst.destination);

            var tupleElements = new Core.Type[inst.sourceElements.Length];

            for (var i = 0; i < inst.sourceElements.Length; i++)
            {
                tupleElements[i] = TypeResolver.GetDataAccessType(session, funct, inst.sourceElements[i]);
            }

            var srcTuple = Core.TypeTuple.Of(tupleElements);
            var srcType  = (Core.Type)srcTuple;

            var inferredDest = TypeInferencer.Try(session, srcType, ref destType);
            var inferredSrc  = TypeInferencer.Try(session, destType, ref srcType);

            if (inferredDest)
            {
                appliedRule = ApplyToDataAccess(inst.destination, destType);
            }

            if (inferredSrc)
            {
                for (var i = 0; i < inst.sourceElements.Length; i++)
                {
                    appliedRule = ApplyToDataAccess(inst.sourceElements[i], srcTuple.elementTypes[i]);
                }
            }
        }
示例#2
0
        private void ApplyRuleForMoveIntLiteral(ref bool appliedRule, Core.InstructionMoveLiteralInt inst)
        {
            var destType = TypeResolver.GetDataAccessType(session, funct, inst.destination);
            var srcType  = Core.TypeStruct.Of(session.PrimitiveInt);

            var inferredDest = TypeInferencer.Try(session, srcType, ref destType);

            if (inferredDest)
            {
                appliedRule = ApplyToDataAccess(inst.destination, destType);
            }
        }
示例#3
0
        private void ApplyRuleForBranch(ref bool appliedRule, Core.SegmentFlowBranch flow)
        {
            var destType = Core.TypeStruct.Of(session.PrimitiveBool);
            var srcType  = TypeResolver.GetDataAccessType(session, funct, flow.conditionReg);

            var inferredSrc = TypeInferencer.Try(session, destType, ref srcType);

            if (inferredSrc)
            {
                appliedRule = ApplyToDataAccess(flow.conditionReg, destType);
            }
        }
        public void Analyze()
        {
            var inferer      = new TypeInferencer();
            var sorted_nodes = cfg.ForwardOrder;

            // TODO: Propagate types over the CFG until a fixpoint is reached (i.e. when types do not change)

            for (var i = 0; i < sorted_nodes.Length; ++i)
            {
                var node = sorted_nodes[i];
                inferer.Visit(node);
            }
        }
示例#5
0
        /// <summary>
        /// Constructs a control and data flow graph for the given method body.
        /// </summary>
        public static ControlAndDataFlowGraph <BasicBlock, Instruction> GetControlAndDataFlowGraphFor(IMetadataHost host, IMethodBody methodBody, ILocalScopeProvider /*?*/ localScopeProvider = null)
        {
            Contract.Requires(host != null);
            Contract.Requires(methodBody != null);
            Contract.Ensures(Contract.Result <ControlAndDataFlowGraph <BasicBlock, Instruction> >() != null);

            var cdfg = ControlFlowInferencer <BasicBlock, Instruction> .SetupControlFlow(host, methodBody, localScopeProvider);

            DataFlowInferencer <BasicBlock, Instruction> .SetupDataFlow(host, methodBody, cdfg);

            TypeInferencer <BasicBlock, Instruction> .FillInTypes(host, cdfg);

            return(cdfg);
        }
示例#6
0
        private void ApplyRuleForMoveData(ref bool appliedRule, Core.InstructionMoveData inst)
        {
            var destType = TypeResolver.GetDataAccessType(session, funct, inst.destination);
            var srcType  = TypeResolver.GetDataAccessType(session, funct, inst.source);

            var inferredDest = TypeInferencer.Try(session, srcType, ref destType);
            var inferredSrc  = TypeInferencer.Try(session, destType, ref srcType);

            if (inferredDest)
            {
                appliedRule = ApplyToDataAccess(inst.destination, destType);
            }

            if (inferredSrc)
            {
                appliedRule = ApplyToDataAccess(inst.source, destType);
            }
        }
示例#7
0
        private void ApplyRuleForMoveCallResult(ref bool appliedRule, Core.InstructionMoveCallResult inst)
        {
            var destType  = TypeResolver.GetDataAccessType(session, funct, inst.destination);
            var callType  = TypeResolver.GetDataAccessType(session, funct, inst.callTargetSource);
            var callFunct = callType as Core.TypeFunct;

            if (callFunct == null)
            {
                return;
            }

            var inferredResult = TypeInferencer.Try(session, callFunct.returnType, ref destType);

            if (inferredResult)
            {
                appliedRule = ApplyToDataAccess(inst.destination, destType);
            }

            /*var srcArgumentTypes = new Core.Type[inst.argumentSources.Length];
             * for (var i = 0; i < inst.argumentSources.Length; i++)
             *  srcArgumentTypes[i] = GetDataAccessType(inst.argumentSources[i]);
             *
             * var srcFunct = Core.TypeFunct.Of(destType, srcArgumentTypes);
             * var srcType = (Core.Type)srcFunct;
             *
             * var inferredFunct = TypeInferencer.Try(session, callType, ref srcType);
             * var inferredFunctArgs = TypeInferencer.Try(session, srcType, ref callType);
             * var inferredResult = TypeInferencer.Try(session, callFunct.returnType, ref destType);
             * var inferredFunctResult = TypeInferencer.Try(session, destType, ref callFunct.returnType);*/

            /*if (result)
             * {
             *  this.appliedAnyRule = true;
             *
             *  routine.registers[inst.calledSource.registerIndex].type = callType;
             *  routine.registers[inst.destination.registerIndex].type = callFunct.returnType;
             *
             *  for (var i = 0; i < inst.argumentSources.Count; i++)
             *  {
             *      this.routine.registers[inst.argumentSources[i].registerIndex].type =
             *          srcFunct.argumentTypes[i];
             *  }
             * }*/
        }
示例#8
0
        private void ApplyRuleForMoveAddr(ref bool appliedRule, Core.InstructionMoveAddr inst)
        {
            var destType = TypeResolver.GetDataAccessType(session, funct, inst.destination);

            var srcPtr = Core.TypePointer.Of(
                inst.mutable,
                TypeResolver.GetDataAccessType(session, funct, inst.source));

            var srcType = (Core.Type)srcPtr;

            var inferredDest = TypeInferencer.Try(session, srcType, ref destType);
            var inferredSrc  = TypeInferencer.Try(session, destType, ref srcType);

            if (inferredDest)
            {
                appliedRule = ApplyToDataAccess(inst.destination, destType);
            }

            if (inferredSrc)
            {
                appliedRule = ApplyToDataAccess(inst.source, srcPtr.pointedToType);
            }
        }
示例#9
0
        private void ApplyRuleForMoveFunctLiteral(ref bool appliedRule, Core.InstructionMoveLiteralFunct inst)
        {
            var destType = TypeResolver.GetDataAccessType(session, funct, inst.destination);
            var srcType  = (Core.Type) this.session.GetFunct(inst.functIndex).MakeFunctType();

            var inferredDest = TypeInferencer.Try(session, srcType, ref destType);

            if (inferredDest)
            {
                appliedRule = ApplyToDataAccess(inst.destination, destType);
            }

            /*if (inst.destination.fieldAccesses.Count > 0)
             *  throw new InternalException("not implemented");
             *
             * if (inst.potentialFuncts.Count > 0)
             * {
             *  for (var i = inst.potentialFuncts.Count - 1; i >= 0; i--)
             *  {
             *      var functType = new TypeFunct(inst.potentialFuncts[i]);
             *      if (!functType.IsMatch(this.routine.registers[inst.destination.registerIndex].type))
             *      {
             *          inst.potentialFuncts.RemoveAt(i);
             *          this.appliedAnyRule = true;
             *      }
             *  }
             * }
             *
             * if (inst.potentialFuncts.Count == 1)
             * {
             *  if (TryInference(this.session,
             *      new TypeFunct(inst.potentialFuncts[0]),
             *      ref routine.registers[inst.destination.registerIndex].type))
             *      this.appliedAnyRule = true;
             * }*/
        }