コード例 #1
0
        public static IEnumerable <Operation> DevirtualizeRegisters(IReadOnlyList <Operation> code)
        {
            var ru      = new RegisterUsage(code);
            var replace = new Dictionary <int, Register.RegisterId>();

            foreach (var id in ru.GetPrioritisedVirtualRegisters())
            {
                var n  = ru.CanNotReplace(id);
                var to = PrioritisedRegisters.First(r => !n.Contains(RegisterUsage.ToReg(r)));
                replace[id] = to;
                ru.Replace(id, RegisterUsage.ToReg(to));
            }

            Operand Replace(Operand op)
            {
                return(op switch
                {
                    StubRegister stubRegister => new Register(replace[stubRegister.Number], stubRegister.Size),
                    Memory memory => new Memory(Replace(memory.Address), memory.Size),
                    Shift shift => new Shift(Replace(shift.Register) as AnyRegister, shift.Shft),
                    _ => op
                });
            }
コード例 #2
0
ファイル: NasmCompiler.cs プロジェクト: Tetrergeru/CimpleCI
 public AnyRegister NewRegister(int size) => LastRegister = new StubRegister(_usedRegisters++, size);