Esempio n. 1
0
        private void Process(XIL3Instr xil3i)
        {
            var preds = xil3i.Preds.Select(p => p.Remap(_slotRemap[p.PredIndex])).ToArray();
            _instRemap.Add(_outInstrs.Count);

            foreach (int oslot in xil3i.OperandSlots)
            {
                Emit(DefaultInstructionSet.Instance
                    .LoadVar(_interLocals[oslot]).CreateStk(preds, 0, _interLocals[oslot].Type));
            }
            _slotRemap.Add(_outInstrs.Count);
            var cmd = xil3i.Command;
            if (cmd.Name == InstructionCodes.BranchIfFalse ||
                cmd.Name == InstructionCodes.BranchIfTrue ||
                cmd.Name == InstructionCodes.Goto)
            {
                var target = (BranchLabel)cmd.Operand;
                var newTarget = new BranchLabel() { InstructionIndex = target.InstructionIndex };
                cmd = new XILInstr(cmd.Name, newTarget) { BackRef = cmd.BackRef };
                _labels.Add(newTarget);
            }
            Emit(cmd.CreateStk(preds, xil3i.OperandSlots.Length,
                xil3i.OperandSlots.Select(os => _interLocals[os].Type)
                .Concat(xil3i.ResultSlots.Select(rs => _interLocals[rs].Type))
                .ToArray()));
            foreach (int rslot in xil3i.ResultSlots.Reverse())
            {
                Emit(DefaultInstructionSet.Instance
                    .StoreVar(_interLocals[rslot]).CreateStk(1, _interLocals[rslot].Type));
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Retargets an input instruction branch label to the output side.
 /// </summary>
 /// <param name="label">branch label used by input instruction</param>
 /// <returns>branch label suitable for output instruction</returns>
 protected BranchLabel Retarget(BranchLabel label)
 {
     BranchLabel newLabel = new BranchLabel();
     _remapLabels.Add(new Tuple<BranchLabel, BranchLabel>(label, newLabel));
     return newLabel;
 }
Esempio n. 3
0
 public InlineBCUMapping(InlineBCUTransactionSite taSite, string instrName, BranchLabel target)
 {
     _instrName = instrName;
     _target = target;
     _taSite = taSite;
 }
Esempio n. 4
0
 public IEnumerable<TAVerb> BranchIfNot(ISignalSource<StdLogicVector> cond, BranchLabel target)
 {
     yield return Verb(ETVMode.Locked, 
             _brAltFlagP.Drive(SignalSource.Create<StdLogicVector>("0")),
             _brAltFlagN.Drive(cond),
             GetStateDriver(target));
 }
Esempio n. 5
0
 private IProcess GetStateDriver(BranchLabel target)
 {
     Array enumValues = _tState.GetEnumValues();
     Debug.Assert(target.CStep >= 0 && target.CStep < enumValues.Length);
     object stateValue = enumValues.GetValue(target.CStep);
     return _altState.Instance.DriveUT(SignalSource.CreateUT(stateValue));
 }
Esempio n. 6
0
 public override string ToString() => BranchLabel.ToString();
Esempio n. 7
0
        private XIL3Function Run()
        {
            List<XIL3Instr> xil3is = new List<XIL3Instr>();
            List<BranchLabel> targets = new List<BranchLabel>();
            foreach (XILSInstr xilsi in _func.Instructions)
            {
                switch (xilsi.Name)
                {
                    case InstructionCodes.Pop:
                        _stack.Pop();
                        break;

                    case InstructionCodes.Dup:
                        _stack.Push(_stack.Peek());
                        break;

                    case InstructionCodes.Swap:
                        {
                            int a = _stack.Pop();
                            int b = _stack.Pop();
                            _stack.Push(a);
                            _stack.Push(b);
                        }
                        break;

                    case InstructionCodes.Dig:
                        {
                            int pos = (int)xilsi.StaticOperand;
                            Stack<int> tmpStack = new Stack<int>();
                            for (int i = 0; i < pos; i++)
                                tmpStack.Push(_stack.Pop());
                            int dig = _stack.Pop();
                            for (int i = 0; i < pos; i++)
                                _stack.Push(tmpStack.Pop());
                            _stack.Push(dig);
                        }
                        break;

                    default:
                        {
                            int[] oslots, rslots;
                            InstructionDependency[] preds;
                            Remap(xilsi, out preds, out oslots, out rslots);
                            XIL3Instr xil3i;
                            switch (xilsi.Name)
                            {
                                case InstructionCodes.Goto:
                                case InstructionCodes.BranchIfFalse:
                                case InstructionCodes.BranchIfTrue:
                                    {
                                        BranchLabel orgTarget = (BranchLabel)xilsi.StaticOperand;
                                        BranchLabel target = new BranchLabel()
                                        {
                                            InstructionIndex = orgTarget.InstructionIndex
                                        };
                                        targets.Add(target);
                                        xil3i = new XILInstr(xilsi.Name, target).Create3AC(preds, oslots, rslots);
                                    }
                                    break;

                                default:
                                    xil3i = xilsi.Command.Create3AC(preds, oslots, rslots);
                                    break;
                            }
                            xil3i.Index = xil3is.Count;
                            xil3i.CILRef = xilsi.CILRef;
                            xil3is.Add(xil3i);
                            _indexMap[xilsi.Index] = xil3i.Index;
                        }
                        break;
                }
            }
            foreach (BranchLabel target in targets)
            {
                target.InstructionIndex = _indexMap[target.InstructionIndex];
            }
            return new XIL3Function(_func.Name, _func.Arguments, _func.Locals, xil3is.ToArray(), _slotTypes.ToArray());
        }