Example #1
0
        private void HandleStoreVar(XILSInstr i)
        {
            int      readPoint;
            Variable local = i.StaticOperand as Variable;

            if (DflowAnalyzer.IsReadAfterWrite(i.Index, out readPoint))
            {
                var preds = RemapPreds(i.Preds);

                // keep expression on the stack, but bury it at the very bottom.
                for (int j = 1; j < _resultStack.Count; j++)
                {
                    var resultTypes = TypeStack.Reverse().Skip(1).Concat(TypeStack.Skip(_resultStack.Count - 1)).ToArray();
                    Emit(DefaultInstructionSet.Instance.Dig(_resultStack.Count - 1).CreateStk(
                             preds,
                             TypeStack.Reverse().ToArray(),
                             resultTypes));
                    preds = new InstructionDependency[0];
                }
                _read2write[readPoint] = _resultStack[0];
            }
            else if (local == null)
            {
                ProcessDefault(i);
            }
            else if (DflowAnalyzer.EliminableLocals.Contains(local.LocalIndex))
            {
                Emit(DefaultInstructionSet.Instance.Pop().CreateStk(1, local.Type));
            }
            else
            {
                ProcessDefault(i);
            }
        }
Example #2
0
 private void Remap(XILSInstr xilsi, out InstructionDependency[] preds, out int[] oslots, out int[] rslots)
 {
     oslots = new int[xilsi.OperandTypes.Length];
     rslots = new int[xilsi.ResultTypes.Length];
     for (int i = oslots.Length - 1; i >= 0; i--)
     {
         oslots[i] = _stack.Pop();
     }
     for (int i = 0; i < rslots.Length; i++)
     {
         rslots[i] = _curSlot;
         _stack.Push(_curSlot);
         Debug.Assert(xilsi.ResultTypes[i] != null);
         _slotTypes.Add(xilsi.ResultTypes[i]);
         ++_curSlot;
     }
     preds = xilsi.Preds.SelectMany(i =>
     {
         int j;
         if (_indexMap.TryGetValue(i.PredIndex, out j))
         {
             return new InstructionDependency[] { i.Remap(j) }
         }
         ;
         else
         {
             return(empty);
         }
     }).ToArray();
 }
Example #3
0
        private void EmitDig(XILSInstr i, int stackIndex)
        {
            base.Emit(i);
            var elem = _resultStack[_resultStack.Count - stackIndex - 1];

            _resultStack.RemoveAt(_resultStack.Count - stackIndex - 1);
            _resultStack.Add(elem);
        }
Example #4
0
 private void Emit(XILSInstr i)
 {
     i.Index = NextInstructionIndex;
     if (_curCILRef != null)
     {
         i.CILRef = _curCILRef;
     }
     _curBB.Add(i.Index);
     _instrs.Add(i);
 }
Example #5
0
        /// <summary>
        /// Creates a control-flow graph from a given XIL-S instruction list
        /// </summary>
        /// <param name="ilist">XIL-S instruction list</param>
        /// <returns>XIL-S control-flow graph</returns>
        public static ControlFlowGraph <XILSInstr> CreateCFG(IList <XILSInstr> ilist)
        {
            XILSInstr marshal = DefaultInstructionSet
                                .Instance
                                .ExitMarshal()
                                .CreateStk(
                DefaultInstructionSet.Empty,
                new TypeDescriptor[0],
                new TypeDescriptor[0]);

            marshal.Index = ilist.Count;
            XILSInstructionInfo iinfo = new XILSInstructionInfo();

            return(new ControlFlowGraph <XILSInstr>(ilist, marshal, iinfo));
        }
Example #6
0
 protected override void Emit(XILSInstr i)
 {
     if (i.Name == InstructionCodes.Dig)
     {
         EmitDig(i, (int)i.StaticOperand);
     }
     else if (i.Name == InstructionCodes.Dig)
     {
         EmitDig(i, (int)1);
     }
     else
     {
         _resultStack.RemoveRange(
             _resultStack.Count - i.OperandTypes.Length,
             i.OperandTypes.Length);
         base.Emit(i);
         for (int j = 0; j < i.ResultTypes.Length; j++)
         {
             _resultStack.Add(Tuple.Create(i.Index, j));
         }
     }
 }
Example #7
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("xils:" + Name + "(");
            sb.Append(string.Join <ArgumentDescriptor>(", ", Arguments));
            sb.AppendLine(")");
            sb.AppendLine("{");
            foreach (Variable local in Locals)
            {
                sb.Append("  " + local.Type + " " + local.Name);
            }
            sb.AppendLine();
            string fmt = "D" + ((Instructions.Length - 1).ToString()).Length.ToString();

            for (int i = 0; i < Instructions.Length; i++)
            {
                sb.Append(i.ToString(fmt) + ": ");
                XILSInstr instr = Instructions[i];
                sb.AppendLine(instr.ToString());
            }
            sb.AppendLine("}");
            return(sb.ToString());
        }
Example #8
0
        private void HandleLoadVar(XILSInstr i)
        {
            Tuple <int, int> stackRef;

            if (_read2write.TryGetValue(i.Index, out stackRef))
            {
                int stackP = _resultStack.IndexOf(stackRef);
                Debug.Assert(stackP >= 0);
                Debug.Assert(_resultStack.Count == TypeStack.Count);
                int depth = _resultStack.Count;
                int relP  = depth - stackP - 1;
                if (relP > 0)
                {
                    var preds = RemapPreds(i.Preds);
                    TypeDescriptor[] opTypes = TypeStack.Take(depth - stackP).Reverse().ToArray();
                    Debug.Assert(opTypes.First().Equals(i.ResultTypes[0]));
                    TypeDescriptor[] rTypes = (TypeDescriptor[])opTypes.Clone();
                    for (int j = 1; j <= relP; j++)
                    {
                        var tmp = rTypes[j];
                        rTypes[j]     = rTypes[j - 1];
                        rTypes[j - 1] = tmp;

                        var tmpi = _resultStack[stackP + j];
                        _resultStack[stackP + j]     = _resultStack[stackP + j - 1];
                        _resultStack[stackP + j - 1] = tmpi;
                    }
                    TypeDescriptor[] allTypes = opTypes.Concat(rTypes).ToArray();
                    base.Emit(DefaultInstructionSet.Instance.Dig(relP).CreateStk(preds, opTypes.Length, allTypes));
                }
            }
            else
            {
                ProcessDefault(i);
            }
        }
Example #9
0
 private void Emit(XILSInstr xilsi)
 {
     _outInstrs.Add(xilsi);
 }
Example #10
0
 public void Emit(XILSInstr instr)
 {
     _compiler.Emit(instr);
 }