Esempio n. 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);
                if (!(decl.Body is InlineMachineCode inline))
                {
                    continue;
                }
                var ici     = new InlineCodeInterpreter(constants);
                var syscall = ici.BuildSystemCallFromMachineCode(decl.Name, ft, inline.Opcodes);
                if (syscall != null)
                {
                    var svc = syscall.Build(platform, typelib);
                    PostProcessSignature(platform, svc);
                    if (!module.ServicesByVector.TryGetValue(svc.SyscallInfo !.Vector, out List <SystemService> svcs))
                    {
                        svcs = new List <SystemService>();
                        module.ServicesByVector.Add(svc.SyscallInfo.Vector, svcs);
                    }
                    svcs.Add(svc);
                }
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 3
0
        public override TypeLibrary Load(IPlatform platform, TypeLibrary dstLib)
        {
            var rdr          = new StreamReader(new MemoryStream(bytes));
            var lexer        = new PascalLexer(rdr, false); // It seems MPW pascal doesn't allow nesting comments.
            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(platform, tldser, constants, dstLib);

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