Пример #1
0
        private void LoadServices(
            List <Declaration> declarations,
            TypeImporter typeImporter,
            IDictionary <string, Constant> constants,
            IPlatform platform,
            TypeLibrary typelib)
        {
            var module = new ModuleDescriptor("");

            typelib.Modules.Add("", module);
            foreach (var decl in declarations.OfType <CallableDeclaration>())
            {
                var ft     = (SerializedSignature)decl.Accept(typeImporter);
                var inline = decl.Body as InlineMachineCode;
                if (inline == null)
                {
                    continue;
                }
                var ici     = new InlineCodeInterpreter(constants);
                var syscall = ici.BuildSystemCallFromMachineCode(decl.Name, ft, inline.Opcodes);
                if (syscall != null)
                {
                    var svc = syscall.Build(platform, typelib);
                    List <SystemService> svcs;
                    if (!module.ServicesByVector.TryGetValue(svc.SyscallInfo.Vector, out svcs))
                    {
                        svcs = new List <SystemService>();
                        module.ServicesByVector.Add(svc.SyscallInfo.Vector, svcs);
                    }
                    svcs.Add(svc);
                }
            }
        }
Пример #2
0
        private void LoadTypes(List <Declaration> declarations, TypeImporter typeImporter)
        {
            var decls = new Dictionary <string, PascalType>(StringComparer.OrdinalIgnoreCase);

            foreach (var typedef in declarations.OfType <TypeDeclaration>())
            {
                typedef.Accept(typeImporter);
            }
        }
Пример #3
0
        public override TypeLibrary Load(IPlatform platform, TypeLibrary dstLib)
        {
            var rdr          = new StreamReader(new MemoryStream(bytes));
            var lexer        = new PascalLexer(rdr);
            var parser       = new PascalParser(lexer);
            var symbolTable  = new SymbolTable(platform);
            var declarations = parser.Parse();
            var tldser       = new TypeLibraryDeserializer(platform, true, dstLib);
            var constants    = EvaluateConstants(declarations);
            var typeImporter = new TypeImporter(tldser, constants, dstLib);

            LoadTypes(declarations, typeImporter);
            LoadServices(declarations, typeImporter, constants, platform, dstLib);
            return(dstLib);
        }