Пример #1
0
        private IlProgram RunInternal(Method entryPoint, IReadOnlyList <Method> methods)
        {
            var callTree  = CallTree.Create(entryPoint, methods);
            var ilMethods = LinkMethods(InstructionFacts.SizeProgramHeader, callTree);

            var labelTable  = _labelTableBuilder.Build();
            var methodTable = _methodTableBuilder.Build();

            if (_entryPoint is null)
            {
                throw new VmrException("Entry point not found by linker.");
            }

            return(new IlProgram(_entryPoint, ilMethods, labelTable.GetTargets(), labelTable.GetNames(), methodTable.GetNames(), _comments));
        }
Пример #2
0
        private IReadOnlyList <IlMethod> LinkMethods(int startAddress, CallTree callTree)
        {
            var result  = new List <IlMethod>();
            var methods = callTree.Flatten().Select(m => m.Method).OrderBy(m => m.Order).ToList();

            GetMethodAddressLookup(_methodTableBuilder, startAddress, methods);

            foreach (var method in methods)
            {
                var address           = _methodTableBuilder.Targets[method.Name];
                var methdoBodyAddress = address.Value + InstructionFacts.SizeOfMethodHeader;
                var ilObjects         = LinkNodes(methdoBodyAddress, method.Nodes);
                var ilMethod          = new IlMethod(address, method.Args, ilObjects);

                if (method.IsEntryPoint)
                {
                    _entryPoint = ilMethod.Address;
                }

                result.Add(ilMethod);
            }

            return(result);