Exemple #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]);
                }
            }
        }
Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #4
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);
            }
        }
Exemple #5
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];
             *  }
             * }*/
        }
Exemple #6
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);
            }
        }
Exemple #7
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;
             * }*/
        }