Exemplo n.º 1
0
    public bool Execute(string methodPath, int batch)
    {
        var reader           = new ProfileReader();
        var serializeOptions = new JsonSerializerOptions
        {
            PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
            ReferenceHandler     = ReferenceHandler.Preserve,
        };

        byte[] inputData = File.ReadAllBytes(Input !);
        var    writer    = new ProfileWriter();

        for (var i = 0; i < batch; i++)
        {
            ProfileData data            = JsonSerializer.Deserialize <ProfileData>(inputData, serializeOptions) !;
            var         outputPath      = Path.Combine(OutputDir, $"trimmed-{i}.profile");
            string[]    excludedMethods = GenerateRandomExclusions(10, methodPath);
            using (FileStream outStream = File.Create(outputPath))
            {
                writer.WriteAllData(outStream, data, excludedMethods);
            }
            var trackingPath = Path.Combine(OutputDir, $"methods-{i}.txt");
            File.WriteAllLines(trackingPath, excludedMethods);
        }

        return(true);
    }
Exemplo n.º 2
0
        public static void Main()
        {
            ProfileWriter.BeginSession("Startup", "BootProfile-Startup.json");
            var app = new Shoelace(Veldrid.GraphicsBackend.Direct3D11);

            ProfileWriter.EndSesison();

            ProfileWriter.BeginSession("Runtime", "BootProfile-Runtime.json");
            app.Run();
            ProfileWriter.EndSesison();
        }
Exemplo n.º 3
0
        public void WriteState(BrewProfile profile)
        {
            if (profile == null)
            {
                return;
            }

            var profileArray = ProfileWriter.Write(profile);

            if (profileArray != null)
            {
                File.WriteAllBytes(_path, profileArray);
            }
        }
Exemplo n.º 4
0
        public static void Main()
        {
            ProfileWriter.BeginSession("Startup", "BootProfile-Startup.json");
            Logger.Init();
            var app = new SandboxApp(Veldrid.GraphicsBackend.OpenGL);

            ProfileWriter.EndSesison();

            ProfileWriter.BeginSession("Runtime", "BootProfile-Runtime.json");
            app.Run();
            ProfileWriter.EndSesison();

            ProfileWriter.BeginSession("Shutdown", "BootProfile-Shutdown.json");
            app.Dispose();
            ProfileWriter.EndSesison();
        }
Exemplo n.º 5
0
    public bool Execute(string methodPath)
    {
        var         reader = new ProfileReader();
        ProfileData profile;

        string[] methodNames;
        using (FileStream stream = File.OpenRead(Input))
            profile = reader.ReadAllData(stream);
        if (ExcludeMethods != null)
        {
            var newMethods = new List <MethodRecord>();

            foreach (MethodRecord method in profile.Methods)
            {
                bool isFiltered = ExcludeMethods !.Any(e => method.Name == e);
                if (!isFiltered)
                {
                    newMethods.Add(method);
                }
            }
            profile.Methods = newMethods.ToArray();
        }
        if (Dump)
        {
            methodNames = DumpMethods(profile);
            File.WriteAllLines(methodPath, methodNames.ToArray());
        }
        if (Output != null)
        {
            var writer = new ProfileWriter();
            using (FileStream outStream = File.Create(Output !))
                writer.WriteAllData(outStream, profile);
        }

        return(true);
    }
Exemplo n.º 6
0
        public static void Main(string [] args)
        {
            var path = ProcessArguments(args);

            if (args.Length == 1)
            {
                Modules = Types = Methods = true;
            }

            var         reader = new ProfileReader();
            ProfileData pd     = null;

            if (path == null)
            {
                if (Port < 0)
                {
                    Error($"You should specify path or -p PORT to read the profile.");
                    Environment.Exit(4);
                }
                else
                {
                    try {
                        pd = ReadProfileFromPort(reader);
                    } catch (Exception e) {
                        Error($"Unable to read profile through local port: {Port}.\n{e}");
                        Environment.Exit(5);
                    }
                }
            }
            else if (!File.Exists(path))
            {
                Error($"'{path}' doesn't exist.");
                Environment.Exit(3);
            }
            else
            {
                using (var stream = new FileStream(path, FileMode.Open)) {
                    if (Verbose)
                    {
                        ColorWriteLine($"Reading '{path}'...", ConsoleColor.Yellow);
                    }

                    pd = reader.ReadAllData(stream);
                }
            }

            List <MethodRecord>        methods = new List <MethodRecord> (pd.Methods);
            ICollection <TypeRecord>   types   = new List <TypeRecord> (pd.Types);
            ICollection <ModuleRecord> modules = new List <ModuleRecord> (pd.Modules);

            if (FilterMethod != null || FilterType != null || FilterModule != null)
            {
                methods = new List <MethodRecord> ();
                types   = new HashSet <TypeRecord> ();
                modules = new HashSet <ModuleRecord> ();

                foreach (var method in pd.Methods)
                {
                    var type   = method.Type;
                    var module = type.Module;

                    if (FilterModule != null)
                    {
                        var match = FilterModule.Match(module.ToString());

                        if (!match.Success)
                        {
                            continue;
                        }
                    }

                    if (FilterType != null)
                    {
                        var match = FilterType.Match(method.Type.ToString());

                        if (!match.Success)
                        {
                            continue;
                        }
                    }

                    if (FilterMethod != null)
                    {
                        var match = FilterMethod.Match(method.ToString());

                        if (!match.Success)
                        {
                            continue;
                        }
                    }

                    methods.Add(method);
                    types.Add(type);
                    modules.Add(module);
                }
            }

            if (FilterMethod == null && FilterType != null)
            {
                foreach (var type in pd.Types)
                {
                    if (types.Contains(type))
                    {
                        continue;
                    }

                    var match = FilterType.Match(type.ToString());

                    if (!match.Success)
                    {
                        continue;
                    }

                    types.Add(type);
                }
            }

            if (Modules)
            {
                ColorWriteLine($"Modules:", ConsoleColor.Green);

                foreach (var module in modules)
                {
                    WriteLine($"\t{module.Mvid} {module.ToString ()}");
                }
            }

            if (Types)
            {
                ColorWriteLine($"Types:", ConsoleColor.Green);

                foreach (var type in types)
                {
                    WriteLine($"\t{type}");
                }
            }

            if (Methods)
            {
                ColorWriteLine($"Methods:", ConsoleColor.Green);

                foreach (var method in methods)
                {
                    WriteLine($"\t{method}");
                }
            }

            if (Summary)
            {
                ColorWriteLine($"Summary:", ConsoleColor.Green);
                WriteLine($"\tModules: {modules.Count.ToString ("N0"),10}{(modules.Count != pd.Modules.Length ? $"  (of {pd.Modules.Length})" : "" )}");
                WriteLine($"\tTypes:   {types.Count.ToString ("N0"),10}{(types.Count != pd.Types.Length ? $"  (of {pd.Types.Length})" : "")}");
                WriteLine($"\tMethods: {methods.Count.ToString ("N0"),10}{(methods.Count != pd.Methods.Length ? $"  (of {pd.Methods.Length})" : "")}");
            }

            if (!string.IsNullOrEmpty(Output))
            {
                if (Verbose)
                {
                    ColorWriteLine($"Going to write the profile to '{Output}'", ConsoleColor.Yellow);
                }
                var modulesArray = new ModuleRecord [modules.Count];
                modules.CopyTo(modulesArray, 0);
                var typesArray = new TypeRecord [types.Count];
                types.CopyTo(typesArray, 0);
                var updatedPD = new ProfileData(modulesArray, typesArray, methods.ToArray());

                using (var stream = new FileStream(Output, FileMode.Create)) {
                    var writer = new ProfileWriter();
                    writer.WriteAllData(stream, updatedPD);
                }
            }
        }
Exemplo n.º 7
0
        public static void Main(string [] args)
        {
            var path = ProcessArguments(args);

            if (!File.Exists(path))
            {
                Error($"'{path}' doesn't exist.");
                Environment.Exit(3);
            }

            if (args.Length == 1)
            {
                Modules = Types = Methods = true;
            }

            var         reader = new ProfileReader();
            ProfileData pd;

            using (var stream = new FileStream(path, FileMode.Open)) {
                if (Verbose)
                {
                    ColorWriteLine($"Reading '{path}'...", ConsoleColor.Yellow);
                }

                pd = reader.Read(stream);
            }

            List <MethodRecord>        methods = pd.Methods;
            ICollection <TypeRecord>   types   = pd.Types;
            ICollection <ModuleRecord> modules = pd.Modules;

            if (FilterMethod != null || FilterType != null || FilterModule != null)
            {
                methods = new List <MethodRecord> ();
                types   = new HashSet <TypeRecord> ();
                modules = new HashSet <ModuleRecord> ();

                foreach (var method in pd.Methods)
                {
                    var type   = method.Type;
                    var module = type.Module;

                    if (FilterModule != null)
                    {
                        var match = FilterModule.Match(module.ToString());

                        if (!match.Success)
                        {
                            continue;
                        }
                    }

                    if (FilterType != null)
                    {
                        var match = FilterType.Match(method.Type.ToString());

                        if (!match.Success)
                        {
                            continue;
                        }
                    }

                    if (FilterMethod != null)
                    {
                        var match = FilterMethod.Match(method.ToString());

                        if (!match.Success)
                        {
                            continue;
                        }
                    }

                    methods.Add(method);
                    types.Add(type);
                    modules.Add(module);
                }
            }

            if (FilterMethod == null && FilterType != null)
            {
                foreach (var type in pd.Types)
                {
                    if (types.Contains(type))
                    {
                        continue;
                    }

                    var match = FilterType.Match(type.ToString());

                    if (!match.Success)
                    {
                        continue;
                    }

                    types.Add(type);
                }
            }

            if (Modules)
            {
                ColorWriteLine($"Modules:", ConsoleColor.Green);

                foreach (var module in modules)
                {
                    WriteLine($"\t{module.Mvid} {module}");
                }
            }

            if (Types)
            {
                ColorWriteLine($"Types:", ConsoleColor.Green);

                foreach (var type in types)
                {
                    WriteLine($"\t{type}");
                }
            }

            if (Methods)
            {
                ColorWriteLine($"Methods:", ConsoleColor.Green);

                foreach (var method in methods)
                {
                    WriteLine($"\t{method}");
                }
            }

            if (Summary)
            {
                ColorWriteLine($"Summary:", ConsoleColor.Green);
                WriteLine($"\tModules: {modules.Count.ToString ("N0"),10}{(modules.Count != pd.Modules.Count ? $"  (of {pd.Modules.Count})" : "" )}");
                WriteLine($"\tTypes:   {types.Count.ToString ("N0"),10}{(types.Count != pd.Types.Count ? $"  (of {pd.Types.Count})" : "")}");
                WriteLine($"\tMethods: {methods.Count.ToString ("N0"),10}{(methods.Count != pd.Methods.Count ? $"  (of {pd.Methods.Count})" : "")}");
            }

            if (!string.IsNullOrEmpty(Output))
            {
                if (Verbose)
                {
                    ColorWriteLine($"Going to write the profile to '{Output}'", ConsoleColor.Yellow);
                }

                var updatedPD = new ProfileData(new List <ModuleRecord>(modules), new List <TypeRecord> (types), methods);

                using (var stream = new FileStream(Output, FileMode.Create)) {
                    var writer = new ProfileWriter(stream, updatedPD);
                    writer.Write();
                }
            }
        }
Exemplo n.º 8
0
 public BrewProfile GetState()
 {
     return(HasStateFile ? ProfileWriter.Read(File.ReadAllBytes(_path)) : null);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Asynchronously generates bindings for the API described by the given <see cref="IGeneratorSettings"/>
        /// object.
        ///
        /// Broadly, this takes the following steps:
        /// 1) Load the base API.
        /// 2) Bake overrides into the API
        /// 3) Bake Documentation into the API
        /// 4) Create mappings between OpenGL types and C# types
        /// 5) Apply the mappings to the API
        /// 6) Bake convenience overloads into the API (adding unsafe, etc)
        /// 7) Write the bindings to the files.
        ///
        /// </summary>
        /// <param name="generatorSettings">The settings describing the API.</param>
        private static void GenerateBindings([NotNull] IGeneratorSettings generatorSettings)
        {
            var signaturePath = Path.Combine(Arguments.InputPath, generatorSettings.SpecificationFile);

            if (!_cachedProfiles.TryGetValue(signaturePath, out var profiles))
            {
                profiles = SignatureReader.GetAvailableProfiles(signaturePath).ToList();
                _cachedProfiles.TryAdd(signaturePath, profiles);
            }

            var profileOverrides = OverrideReader
                                   .GetProfileOverrides(generatorSettings.OverrideFiles.ToArray())
                                   .ToList();

            var baker        = new ProfileBaker(profiles, profileOverrides);
            var bakedProfile = baker.BakeProfile(
                generatorSettings.ProfileName,
                generatorSettings.Versions,
                generatorSettings.BaseProfileName);

            var documentationPath = Path.Combine(
                Arguments.DocumentationPath,
                generatorSettings.SpecificationDocumentationPath);

            var doc       = DocumentationReader.ReadProfileDocumentation(documentationPath, generatorSettings.FunctionPrefix);
            var bakedDocs = new DocumentationBaker(bakedProfile).BakeDocumentation(doc);

            var languageTypemapPath = Path.Combine(Arguments.InputPath, generatorSettings.LanguageTypemap);

            if (!_cachedTypemaps.TryGetValue(languageTypemapPath, out var languageTypemap))
            {
                using (var fs = File.OpenRead(languageTypemapPath))
                {
                    languageTypemap = new TypemapReader().ReadTypemap(fs);
                    _cachedTypemaps.TryAdd(languageTypemapPath, languageTypemap);
                }
            }

            var apiTypemapPath = Path.Combine(Arguments.InputPath, generatorSettings.APITypemap);

            if (!_cachedTypemaps.TryGetValue(apiTypemapPath, out var apiTypemap))
            {
                using (var fs = File.OpenRead(apiTypemapPath))
                {
                    apiTypemap = new TypemapReader().ReadTypemap(fs);
                    _cachedTypemaps.TryAdd(apiTypemapPath, apiTypemap);
                }
            }

            var bakedMap = TypemapBaker.BakeTypemaps(apiTypemap, languageTypemap);

            var mapper        = new ProfileMapper(bakedMap);
            var mappedProfile = mapper.Map(bakedProfile);

            // var bindingsWriter = new BindingWriter(generatorSettings, overloadedProfile, bakedDocs);
            // await bindingsWriter.WriteBindingsAsync();
            ProfileWriter.Write(
                generatorSettings,
                mappedProfile,
                bakedDocs,
                generatorSettings.NameContainer);
        }