Exemple #1
0
        public void Compile(ICompilationJob job)
        {
            // Run parser on every input file
            PParser.ProgramContext[] trees = job.InputFiles.Select(file =>
            {
                PParser.ProgramContext tree = Parse(job, file);
                job.LocationResolver.RegisterRoot(tree, file);
                return(tree);
            }).ToArray();

            // Run typechecker and produce AST
            Scope scope = Analyzer.AnalyzeCompilationUnit(job.Handler, trees);

            // Convert functions to lowered SSA form with explicit cloning
            foreach (TypeChecker.AST.Declarations.Function fun in scope.GetAllMethods())
            {
                IRTransformer.SimplifyMethod(fun);
            }

            // Run the selected backend on the project and write the files.
            System.Collections.Generic.IEnumerable <CompiledFile> compiledFiles = job.Backend.GenerateCode(job, scope);
            foreach (CompiledFile file in compiledFiles)
            {
                job.Output.WriteMessage($"Generated {file.FileName}...", SeverityKind.Info);
                job.Output.WriteFile(file);
            }
        }
Exemple #2
0
        public void Compile(ICompilationJob job)
        {
            // Run parser on every input file
            var trees = job.InputFiles.Select(file =>
            {
                var tree = Parse(job, file);
                job.LocationResolver.RegisterRoot(tree, file);
                return(tree);
            }).ToArray();

            // Run typechecker and produce AST
            var scope = Analyzer.AnalyzeCompilationUnit(job.Handler, trees);

            // Convert functions to lowered SSA form with explicit cloning
            foreach (var fun in scope.GetAllMethods())
            {
                IRTransformer.SimplifyMethod(fun);
            }

            // Run the selected backend on the project and write the files.
            var compiledFiles = job.Backend.GenerateCode(job, scope);

            foreach (var file in compiledFiles)
            {
                job.Output.WriteMessage($"Writing {file.FileName}...", SeverityKind.Info);
                job.Output.WriteFile(file);
            }
        }
        void VisitInstr(IRInstrList instrs, IRInstruction instr, ref int index, IRTransformer tr)
        {
            switch (instr.OpCode)
            {
            case IROpCode.MOV:
            case IROpCode.NOR:
            case IROpCode.CMP:
            case IROpCode.ADD:
            case IROpCode.MUL:
            case IROpCode.DIV:
            case IROpCode.REM:
            case IROpCode.__OR:
            case IROpCode.__AND:
            case IROpCode.__XOR:
            case IROpCode.__GETF:
                break;

            default:
                return;
            }
            Debug.Assert(instr.Operand1 != null && instr.Operand2 != null);
            if (instr.Operand1 is IRConstant)
            {
                instr.Operand1 = PromoteConstant((IRConstant)instr.Operand1, instr.Operand2.Type);
            }
            if (instr.Operand2 is IRConstant)
            {
                instr.Operand2 = PromoteConstant((IRConstant)instr.Operand2, instr.Operand1.Type);
            }
        }
Exemple #4
0
        void VisitInstr(IRInstrList instrs, IRInstruction instr, ref int index, IRTransformer tr)
        {
            if (instr.OpCode != IROpCode.__CALL && instr.OpCode != IROpCode.__CALLVIRT &&
                instr.OpCode != IROpCode.__NEWOBJ)
            {
                return;
            }

            var method   = ((IMethod)((IRMetaTarget)instr.Operand1).MetadataItem).ResolveMethodDef();
            var callInfo = (InstrCallInfo)instr.Annotation;

            if (method == null ||
                method.Module != tr.Context.Method.Module ||             // TODO: cross-module direct call
                !tr.VM.Settings.IsVirtualized(method) ||
                instr.OpCode != IROpCode.__CALL)
            {
                callInfo.IsECall = true;
                ProcessECall(instrs, instr, index, tr);
            }
            else
            {
                callInfo.IsECall = false;
                ProcessDCall(instrs, instr, index, tr, method);
            }
        }
Exemple #5
0
        // Direct call
        void ProcessDCall(IRInstrList instrs, IRInstruction instr, int index, IRTransformer tr, MethodDef method)
        {
            var retVar   = (IRVariable)instr.Operand2;
            var callinfo = (InstrCallInfo)instr.Annotation;

            callinfo.Method = method;             // Ensure it's resolved

            var callInstrs = new List <IRInstruction>();

            callInstrs.Add(new IRInstruction(IROpCode.CALL, new IRMetaTarget(method)
            {
                LateResolve = true
            })
            {
                Annotation = instr.Annotation,
                ILAST      = instr.ILAST
            });
            if (retVar != null)
            {
                callInstrs.Add(new IRInstruction(IROpCode.MOV, retVar, new IRRegister(VMRegisters.R0, retVar.Type))
                {
                    Annotation = instr.Annotation,
                    ILAST      = instr.ILAST
                });
            }
            var stackAdjust = -callinfo.Arguments.Length;

            callInstrs.Add(new IRInstruction(IROpCode.ADD, IRRegister.SP, IRConstant.FromI4(stackAdjust))
            {
                Annotation = instr.Annotation,
                ILAST      = instr.ILAST
            });

            instrs.Replace(index, callInstrs);
        }
Exemple #6
0
        public void Initialize(IRTransformer tr)
        {
            int maxId = 0;
            BasicBlock <IRInstrList> entry = null;

            tr.RootScope.ProcessBasicBlocks <IRInstrList>(block => {
                block.Id++;
                if (block.Id > maxId)
                {
                    maxId = block.Id;
                }
                if (entry == null)
                {
                    entry = block;
                }
            });

            prolog = new BasicBlock <IRInstrList>(0, new IRInstrList {
                new IRInstruction(IROpCode.__ENTRY),
                new IRInstruction(IROpCode.JMP, new IRBlockTarget(entry))
            });
            prolog.Targets.Add(entry);
            entry.Sources.Add(prolog);

            epilog = new BasicBlock <IRInstrList>(maxId + 1, new IRInstrList {
                new IRInstruction(IROpCode.__EXIT)
            });
            InsertProlog(tr.RootScope);
            InsertEpilog(tr.RootScope);
        }
Exemple #7
0
 public void Transform(IRTransformer tr)
 {
     if (this.doWork)
     {
         tr.Block.Id += 3;
     }
 }
 public void Transform(IRTransformer tr)
 {
     if (!tr.Context.Method.Body.InitLocals)
     {
         return;
     }
     tr.Instructions.VisitInstrs(this.VisitInstr, tr);
 }
Exemple #9
0
        // External call
        void ProcessECall(IRInstrList instrs, IRInstruction instr, int index, IRTransformer tr)
        {
            var method = (IMethod)((IRMetaTarget)instr.Operand1).MetadataItem;
            var retVar = (IRVariable)instr.Operand2;

            uint          opCode        = 0;
            ITypeDefOrRef constrainType = ((InstrCallInfo)instr.Annotation).ConstrainType;

            if (instr.OpCode == IROpCode.__CALL)
            {
                opCode = tr.VM.Runtime.VCallOps.ECALL_CALL;
            }
            else if (instr.OpCode == IROpCode.__CALLVIRT)
            {
                if (constrainType != null)
                {
                    opCode = tr.VM.Runtime.VCallOps.ECALL_CALLVIRT_CONSTRAINED;
                }
                else
                {
                    opCode = tr.VM.Runtime.VCallOps.ECALL_CALLVIRT;
                }
            }
            else if (instr.OpCode == IROpCode.__NEWOBJ)
            {
                opCode = tr.VM.Runtime.VCallOps.ECALL_NEWOBJ;
            }

            var methodId   = (int)(tr.VM.Data.GetId(method) | opCode << 30);
            var ecallId    = tr.VM.Runtime.VMCall.ECALL;
            var callInstrs = new List <IRInstruction>();

            if (constrainType != null)
            {
                callInstrs.Add(new IRInstruction(IROpCode.PUSH)
                {
                    Operand1   = IRConstant.FromI4((int)tr.VM.Data.GetId(constrainType)),
                    Annotation = instr.Annotation,
                    ILAST      = instr.ILAST
                });
            }
            callInstrs.Add(new IRInstruction(IROpCode.VCALL)
            {
                Operand1   = IRConstant.FromI4(ecallId),
                Operand2   = IRConstant.FromI4(methodId),
                Annotation = instr.Annotation,
                ILAST      = instr.ILAST
            });
            if (retVar != null)
            {
                callInstrs.Add(new IRInstruction(IROpCode.POP, retVar)
                {
                    Annotation = instr.Annotation,
                    ILAST      = instr.ILAST
                });
            }
            instrs.Replace(index, callInstrs);
        }
        private void AddTryStart(IRTransformer tr)
        {
            var tryStartInstrs = new List <IRInstruction>();

            for (var i = 0; i < thisScopes.Length; i++)
            {
                var scope = thisScopes[i];
                if (scope.Type != ScopeType.Try)
                {
                    continue;
                }
                if (scope.GetBasicBlocks().First() != tr.Block)
                {
                    continue;
                }

                // Search for handler/filter
                IBasicBlock handler = null, filter = null;
                SearchForHandlers(tr.RootScope, scope.ExceptionHandler, ref handler, ref filter);
                Debug.Assert(handler != null &&
                             (scope.ExceptionHandler.HandlerType != ExceptionHandlerType.Filter || filter != null));

                // Add instructions
                tryStartInstrs.Add(new IRInstruction(IROpCode.PUSH, new IRBlockTarget(handler)));

                IIROperand tryOperand = null;
                int        ehType;
                if (scope.ExceptionHandler.HandlerType == ExceptionHandlerType.Catch)
                {
                    tryOperand = IRConstant.FromI4((int)tr.VM.Data.GetId(scope.ExceptionHandler.CatchType));
                    ehType     = tr.VM.Runtime.RTFlags.EH_CATCH;
                }
                else if (scope.ExceptionHandler.HandlerType == ExceptionHandlerType.Filter)
                {
                    tryOperand = new IRBlockTarget(filter);
                    ehType     = tr.VM.Runtime.RTFlags.EH_FILTER;
                }
                else if (scope.ExceptionHandler.HandlerType == ExceptionHandlerType.Fault)
                {
                    ehType = tr.VM.Runtime.RTFlags.EH_FAULT;
                }
                else if (scope.ExceptionHandler.HandlerType == ExceptionHandlerType.Finally)
                {
                    ehType = tr.VM.Runtime.RTFlags.EH_FINALLY;
                }
                else
                {
                    throw new InvalidProgramException();
                }

                tryStartInstrs.Add(new IRInstruction(IROpCode.TRY, IRConstant.FromI4(ehType), tryOperand)
                {
                    Annotation = new EHInfo(scope.ExceptionHandler)
                });
            }
            tr.Instructions.InsertRange(0, tryStartInstrs);
        }
 public void Transform(IRTransformer tr)
 {
     thisScopes = tr.RootScope.SearchBlock(tr.Block);
     AddTryStart(tr);
     if (thisScopes[thisScopes.Length - 1].Type == ScopeType.Handler)
     {
         var tryScope = SearchForTry(tr.RootScope, thisScopes[thisScopes.Length - 1].ExceptionHandler);
         var scopes   = tr.RootScope.SearchBlock(tryScope.GetBasicBlocks().First());
         thisScopes = scopes.TakeWhile(s => s != tryScope).ToArray();
     }
     tr.Instructions.VisitInstrs(VisitInstr, tr);
 }
Exemple #12
0
 void VisitInstr(IRInstrList instrs, IRInstruction instr, ref int index, IRTransformer tr)
 {
     if (instr.OpCode == IROpCode.__LEA)
     {
         var source = (IRPointer)instr.Operand2;
         var target = instr.Operand1;
         Debug.Assert(source.Register == IRRegister.BP);
         instrs.Replace(index, new[] {
             new IRInstruction(IROpCode.MOV, target, IRRegister.BP, instr),
             new IRInstruction(IROpCode.ADD, target, IRConstant.FromI4(source.Offset), instr)
         });
     }
 }
Exemple #13
0
 void VisitInstr(IRInstrList instrs, IRInstruction instr, ref int index, IRTransformer tr)
 {
     if (instr.OpCode == IROpCode.RET)
     {
         instrs.Replace(index, new[] {
             new IRInstruction(IROpCode.JMP, new IRBlockTarget(epilog))
         });
         if (!tr.Block.Targets.Contains(epilog))
         {
             tr.Block.Targets.Add(epilog);
             epilog.Sources.Add(tr.Block);
         }
     }
 }
Exemple #14
0
 private IIROperand TransformMD(IIROperand operand, IRTransformer tr)
 {
     if (operand is IRMetaTarget target)
     {
         if (!target.LateResolve)
         {
             if (!(target.MetadataItem is IMemberRef))
             {
                 throw new NotSupportedException();
             }
             return(IRConstant.FromI4((int)tr.VM.Data.GetId((IMemberRef)target.MetadataItem)));
         }
     }
     return(operand);
 }
 void VisitInstr(IRInstrList instrs, IRInstruction instr, ref int index, IRTransformer tr)
 {
     if (instr.OpCode == IROpCode.__GETF)
     {
         instrs.Replace(index, new[] {
             new IRInstruction(IROpCode.MOV, instr.Operand1, IRRegister.FL, instr),
             new IRInstruction(IROpCode.__AND, instr.Operand1, instr.Operand2, instr)
         });
     }
     else if (instr.OpCode == IROpCode.__SETF)
     {
         instrs.Replace(index, new[] {
             new IRInstruction(IROpCode.__OR, IRRegister.FL, instr.Operand1, instr)
         });
     }
 }
        void VisitInstr(IRInstrList instrs, IRInstruction instr, ref int index, IRTransformer tr)
        {
            var callInfo = instr.Annotation as InstrCallInfo;

            if (callInfo == null || callInfo.ReturnValue == null)
            {
                return;
            }

            if (instr.Operand1 is IRRegister && ((IRRegister)instr.Operand1).SourceVariable == callInfo.ReturnValue)
            {
                callInfo.ReturnRegister = (IRRegister)instr.Operand1;
            }
            else if (instr.Operand1 is IRPointer && ((IRPointer)instr.Operand1).SourceVariable == callInfo.ReturnValue)
            {
                callInfo.ReturnSlot = (IRPointer)instr.Operand1;
            }
        }
Exemple #17
0
        private void CompileHelpers(MethodDef method, ScopeBlock scope)
        {
            var methodCtx = new IRContext(method, method.Body);

            methodCtx.IsRuntime = true;
            var irTransformer = new IRTransformer(scope, methodCtx, rt);

            irTransformer.Transform();

            var ilTranslator  = new ILTranslator(rt);
            var ilTransformer = new ILTransformer(method, scope, rt);

            ilTranslator.Translate(scope);
            ilTransformer.Transform();

            var postTransformer = new ILPostTransformer(method, scope, rt);

            postTransformer.Transform();
        }
Exemple #18
0
        public void Compile(ICompilationJob job)
        {
            job.Output.WriteInfo($"----------------------------------------");
            job.Output.WriteInfo($"Parsing ..");
            // Run parser on every input file
            PParser.ProgramContext[] trees = job.InputFiles.Select(file =>
            {
                PParser.ProgramContext tree = Parse(job, file);
                job.LocationResolver.RegisterRoot(tree, file);
                return(tree);
            }).ToArray();

            job.Output.WriteInfo($"Type checking ...");
            // Run typechecker and produce AST
            Scope scope = Analyzer.AnalyzeCompilationUnit(job.Handler, trees);

            // Convert functions to lowered SSA form with explicit cloning
            foreach (TypeChecker.AST.Declarations.Function fun in scope.GetAllMethods())
            {
                IRTransformer.SimplifyMethod(fun);
            }
            job.Output.WriteInfo($"Code generation ....");
            // Run the selected backend on the project and write the files.
            System.Collections.Generic.IEnumerable <CompiledFile> compiledFiles = job.Backend.GenerateCode(job, scope);
            foreach (CompiledFile file in compiledFiles)
            {
                job.Output.WriteInfo($"Generated {file.FileName}");
                job.Output.WriteFile(file);
            }
            job.Output.WriteInfo($"----------------------------------------");

            // Compiling the generated C# code
            // TODO: This is a special case right now but needs to be factored in after the Java code path is available
            if (job.OutputLanguage == CompilerOutput.CSharp)
            {
                job.Output.WriteInfo($"Compiling {job.ProjectName}.csproj ..\n");
                CSharpCodeCompiler.Compile(job);
                job.Output.WriteInfo($"----------------------------------------");
            }
        }
Exemple #19
0
 void VisitInstr(IRInstrList instrs, IRInstruction instr, ref int index, IRTransformer tr)
 {
     if (instr.OpCode == IROpCode.__NOT)
     {
         instrs.Replace(index, new[] {
             new IRInstruction(IROpCode.NOR, instr.Operand1, instr.Operand1, instr)
         });
     }
     else if (instr.OpCode == IROpCode.__AND)
     {
         var tmp = tr.Context.AllocateVRegister(instr.Operand2.Type);
         instrs.Replace(index, new[] {
             new IRInstruction(IROpCode.MOV, tmp, instr.Operand2, instr),
             new IRInstruction(IROpCode.NOR, instr.Operand1, instr.Operand1, instr),
             new IRInstruction(IROpCode.NOR, tmp, tmp, instr),
             new IRInstruction(IROpCode.NOR, instr.Operand1, tmp, instr)
         });
     }
     else if (instr.OpCode == IROpCode.__OR)
     {
         instrs.Replace(index, new[] {
             new IRInstruction(IROpCode.NOR, instr.Operand1, instr.Operand2, instr),
             new IRInstruction(IROpCode.NOR, instr.Operand1, instr.Operand1, instr)
         });
     }
     else if (instr.OpCode == IROpCode.__XOR)
     {
         var tmp1 = tr.Context.AllocateVRegister(instr.Operand2.Type);
         var tmp2 = tr.Context.AllocateVRegister(instr.Operand2.Type);
         instrs.Replace(index, new[] {
             new IRInstruction(IROpCode.MOV, tmp1, instr.Operand1, instr),
             new IRInstruction(IROpCode.NOR, tmp1, instr.Operand2, instr),
             new IRInstruction(IROpCode.MOV, tmp2, instr.Operand2, instr),
             new IRInstruction(IROpCode.NOR, instr.Operand1, instr.Operand1, instr),
             new IRInstruction(IROpCode.NOR, tmp2, tmp2, instr),
             new IRInstruction(IROpCode.NOR, instr.Operand1, tmp2, instr),
             new IRInstruction(IROpCode.NOR, instr.Operand1, tmp1, instr)
         });
     }
 }
Exemple #20
0
        void VisitInstr(IRInstrList instrs, IRInstruction instr, ref int index, IRTransformer tr)
        {
            if (instr.OpCode != IROpCode.__LEAVE)
            {
                return;
            }

            var targetScopes = tr.RootScope.SearchBlock(((IRBlockTarget)instr.Operand1).Target);

            var escapeTarget = FindCommonAncestor(thisScopes, targetScopes);
            var leaveInstrs  = new List <IRInstruction>();

            for (int i = thisScopes.Length - 1; i >= 0; i--)
            {
                if (thisScopes[i] == escapeTarget)
                {
                    break;
                }
                if (thisScopes[i].Type != ScopeType.Try)
                {
                    continue;
                }

                IBasicBlock handler = null, filter = null;
                SearchForHandlers(tr.RootScope, thisScopes[i].ExceptionHandler, ref handler, ref filter);
                if (handler == null)
                {
                    throw new InvalidProgramException();
                }

                leaveInstrs.Add(new IRInstruction(IROpCode.LEAVE, new IRBlockTarget(handler))
                {
                    Annotation = new EHInfo(thisScopes[i].ExceptionHandler)
                });
            }
            instr.OpCode = IROpCode.JMP;
            leaveInstrs.Add(instr);
            instrs.Replace(index, leaveInstrs);
        }
 void VisitInstr(IRInstrList instrs, IRInstruction instr, ref int index, IRTransformer tr)
 {
     if (instr.OpCode == IROpCode.__ENTRY && !doneEntry)
     {
         instrs.Replace(index, new[] {
             instr,
             new IRInstruction(IROpCode.PUSH, IRRegister.BP),
             new IRInstruction(IROpCode.MOV, IRRegister.BP, IRRegister.SP),
             new IRInstruction(IROpCode.ADD, IRRegister.SP, IRConstant.FromI4(allocator.LocalSize))
         });
         doneEntry = true;
     }
     else if (instr.OpCode == IROpCode.__EXIT && !doneExit)
     {
         instrs.Replace(index, new[] {
             new IRInstruction(IROpCode.MOV, IRRegister.SP, IRRegister.BP),
             new IRInstruction(IROpCode.POP, IRRegister.BP),
             instr
         });
         doneExit = true;
     }
 }
        void VisitInstr(IRInstrList instrs, IRInstruction instr, ref int index, IRTransformer tr)
        {
            if (instr.OpCode == IROpCode.__ENTRY && !done)
            {
                var init = new List <IRInstruction>();
                init.Add(instr);
                foreach (var local in tr.Context.Method.Body.Variables)
                {
                    if (local.Type.IsValueType && !local.Type.IsPrimitive)
                    {
                        var adr = tr.Context.AllocateVRegister(ASTType.ByRef);
                        init.Add(new IRInstruction(IROpCode.__LEA, adr, tr.Context.ResolveLocal(local)));

                        var typeId  = (int)tr.VM.Data.GetId(local.Type.RemovePinnedAndModifiers().ToTypeDefOrRef());
                        var ecallId = tr.VM.Runtime.VMCall.INITOBJ;
                        init.Add(new IRInstruction(IROpCode.PUSH, adr));
                        init.Add(new IRInstruction(IROpCode.VCALL, IRConstant.FromI4(ecallId), IRConstant.FromI4(typeId)));
                    }
                }
                instrs.Replace(index, init);
                done = true;
            }
        }
Exemple #23
0
        public void Initialize(IRTransformer tr)
        {
            if (tr.Context.Method.Module == null)
            {
                this.doWork = false;
                return;
            }

            IRVariable counter = tr.Context.AllocateVRegister(ASTType.I4);
            IRVariable pointer = tr.Context.AllocateVRegister(ASTType.Ptr);
            IRVariable t1      = tr.Context.AllocateVRegister(ASTType.I4);
            IRVariable t2      = tr.Context.AllocateVRegister(ASTType.I4);
            IRVariable t3      = tr.Context.AllocateVRegister(ASTType.I4);

            var entry = (BasicBlock <IRInstrList>)tr.RootScope.GetBasicBlocks().First();

            var entryStub  = new BasicBlock <IRInstrList>(-3, new IRInstrList());
            var loopBody   = new BasicBlock <IRInstrList>(-2, new IRInstrList());
            var trampoline = new BasicBlock <IRInstrList>(-1, new IRInstrList());

            ITypeDefOrRef byteType = tr.Context.Method.Module.CorLibTypes.Byte.ToTypeDefOrRef();

            entryStub.Content.AddRange(new[]
            {
                new IRInstruction(IROpCode.MOV, counter, IRConstant.FromI4(0x0f000001), SMCBlock.CounterInit),
                new IRInstruction(IROpCode.MOV, pointer, new IRBlockTarget(trampoline)),
                new IRInstruction(IROpCode.ADD, pointer, IRConstant.FromI4(-1)),
                new IRInstruction(IROpCode.__LDOBJ, pointer, t1, new PointerInfo("LDOBJ", byteType)),
                new IRInstruction(IROpCode.CMP, t1, IRConstant.FromI4(0)),
                new IRInstruction(IROpCode.__GETF, t1, IRConstant.FromI4(1 << tr.VM.Architecture.Flags.ZERO)),
                new IRInstruction(IROpCode.JNZ, new IRBlockTarget(trampoline), t1),
                new IRInstruction(IROpCode.CMP, counter, IRConstant.FromI4(0)),
                new IRInstruction(IROpCode.__GETF, t1, IRConstant.FromI4(1 << tr.VM.Architecture.Flags.ZERO)),
                new IRInstruction(IROpCode.JZ, new IRBlockTarget(loopBody), t1),
                new IRInstruction(IROpCode.MOV, t3, new IRBlockTarget(entry), SMCBlock.AddressPart1),
                new IRInstruction(IROpCode.JMP, new IRBlockTarget(trampoline))
            });
            entryStub.LinkTo(loopBody);
            entryStub.LinkTo(trampoline);

            loopBody.Content.AddRange(new[]
            {
                new IRInstruction(IROpCode.__LDOBJ, pointer, t2, new PointerInfo("LDOBJ", byteType)),
                new IRInstruction(IROpCode.__XOR, t2, IRConstant.FromI4(0x0f000002), SMCBlock.EncryptionKey),
                new IRInstruction(IROpCode.__STOBJ, pointer, t2, new PointerInfo("STOBJ", byteType)),
                new IRInstruction(IROpCode.ADD, counter, IRConstant.FromI4(-1)),
                new IRInstruction(IROpCode.ADD, pointer, IRConstant.FromI4(1)),
                new IRInstruction(IROpCode.CMP, counter, IRConstant.FromI4(0)),
                new IRInstruction(IROpCode.__GETF, t2, IRConstant.FromI4(1 << tr.VM.Architecture.Flags.ZERO)),
                new IRInstruction(IROpCode.JZ, new IRBlockTarget(loopBody), t2),
                new IRInstruction(IROpCode.MOV, t3, new IRBlockTarget(entry), SMCBlock.AddressPart1),
                new IRInstruction(IROpCode.NOP),
                new IRInstruction(IROpCode.JMP, new IRBlockTarget(trampoline))
            });
            loopBody.LinkTo(loopBody);
            loopBody.LinkTo(trampoline);

            trampoline.Content.AddRange(new[]
            {
                new IRInstruction(IROpCode.NOP),
                new IRInstruction(IROpCode.NOP),
                new IRInstruction(IROpCode.__XOR, t3, IRConstant.FromI4(0x0f000003), SMCBlock.AddressPart2),
                new IRInstruction(IROpCode.JMP, new IRBlockTarget(entry))
            });
            trampoline.LinkTo(entry);

            ScopeBlock scope = tr.RootScope.SearchBlock(entry).Last();

            scope.Content.Insert(0, entryStub);
            scope.Content.Insert(1, loopBody);
            scope.Content.Insert(2, trampoline);
        }
 public void Initialize(IRTransformer tr)
 {
 }
Exemple #25
0
 public void Transform(IRTransformer tr)
 {
     tr.Instructions.VisitInstrs(VisitInstr, tr);
 }
 public void Initialize(IRTransformer tr)
 {
     allocator = (RegisterAllocator)tr.Annotations[RegisterAllocationTransform.RegAllocatorKey];
 }
Exemple #27
0
 public RegisterAllocator(IRTransformer transformer)
 {
     this.transformer = transformer;
 }
Exemple #28
0
        protected virtual void TransformVMIR()
        {
            var transformer = new IRTransformer(RootScope, IRContext, Runtime);

            transformer.Transform();
        }
 public void Transform(IRTransformer tr) => tr.Instructions.VisitInstrs(this.VisitInstr, tr);
Exemple #30
0
 void VisitInstr(IRInstrList instrs, IRInstruction instr, ref int index, IRTransformer tr)
 {
     instr.Operand1 = TransformMD(instr.Operand1, tr);
     instr.Operand2 = TransformMD(instr.Operand2, tr);
 }