public RoslynSimanticsModule(RoslynSimanticsContext context, GameIffResource file)
 {
     Context = context;
     File    = file;
     if (file is GameGlobalResource)
     {
         if (file.MainIff.Filename == "global.iff")
         {
             IsGlobal = true;
         }
         else
         {
             IsSemiGlobal = true;
         }
     }
     Name     = CSTranslationContext.FormatName(File.MainIff.Filename.Replace(".iff", ""));
     FilePath = Path.Combine(Context.CacheDirectory, Name);
 }
Exemple #2
0
        public RoslynSimanticsModule GetModuleFor(GameIffResource res)
        {
            var source = res.MainIff;
            var name   = CSTranslationContext.FormatName(source.Filename.Substring(0, source.Filename.Length - 4));
            RoslynSimanticsModule result;

            lock (FormattedNameToRoslynModule) {
                if (FormattedNameToRoslynModule.TryGetValue(name, out result))
                {
                    return(result);
                }
                else
                {
                    //try to create one!
                    result = new RoslynSimanticsModule(Context, res);
                    FormattedNameToRoslynModule[name] = result;
                    return(result);
                }
            }
        }
Exemple #3
0
        public SimAnticsModule GetModuleFor(IffFile source)
        {
            if (source.CachedJITModule != null)
            {
                return((SimAnticsModule)source.CachedJITModule);
            }
            var             name = CSTranslationContext.FormatName(source.Filename.Substring(0, source.Filename.Length - 4));
            SimAnticsModule result;

            if (FormattedNameToModule.TryGetValue(name, out result))
            {
                //TODO: checksum
                if (!result.Inited)
                {
                    result.Init();
                }
                source.CachedJITModule = result;
                return(result);
            }
            return(null);
        }
        private static Tuple <bool, string, string, int> GetInfoFromId(CSTranslationContext ctx, ushort call)
        {
            SimAnticsModule      module;
            CSTranslationContext ctx2;

            //find the bhav.
            if (call < 4096)
            {
                //global
                module = ctx.GlobalModule;
                ctx2   = ctx.GlobalContext as CSTranslationContext;
            }
            else if (call < 8192)
            {
                //local (can only be us)
                module = null;
                ctx2   = null;
            }
            else
            {
                //semiglobal
                module = ctx.SemiGlobalModule;
                ctx2   = ctx.SemiGlobalContext as CSTranslationContext;
            }

            if (ctx2 != null)
            {
                //in previously compiled context
                StructuredBHAV newBHAV;
                if (ctx2.BHAVInfo.TryGetValue(call, out newBHAV))
                {
                    return(new Tuple <bool, string, string, int>(newBHAV.Yields, ctx2.NamespaceName, CSTranslationContext.FormatName(newBHAV.Source.ChunkLabel) + "_" + newBHAV.Source.ChunkID, Math.Max(4, (int)newBHAV.Source.Args)));
                }
                return(new Tuple <bool, string, string, int>(true, null, null, 4));
            }
            if (module != null)
            {
                //in compiled module
                var func = module.GetFunction(call);
                if (func == null)
                {
                    return(new Tuple <bool, string, string, int>(true, null, null, 4));
                }
                return(new Tuple <bool, string, string, int>(func is IBHAV, module.GetType().Namespace, func.GetType().Name, (func as IInlineBHAV)?.ArgCount ?? 4));
            }
            else
            {
                StructuredBHAV newBHAV;
                if (ctx.BHAVInfo.TryGetValue(call, out newBHAV))
                {
                    return(new Tuple <bool, string, string, int>(newBHAV.Yields, null, CSTranslationContext.FormatName(newBHAV.Source.ChunkLabel) + "_" + newBHAV.Source.ChunkID, Math.Max(4, (int)newBHAV.Source.Args)));
                }
                return(new Tuple <bool, string, string, int>(true, null, null, 4));
            }
        }