Example #1
0
        static void Process()
        {
            var parameters = new RoslynConversionParameters
            {
                InputPath = @"stb_truetype.h",
                Defines   = new[]
                {
                    "STB_TRUETYPE_IMPLEMENTATION",
                },
                Classes = new[]
                {
                    "stbtt_pack_context",
                    "stbtt_fontinfo",
                },
                SkipStructs = new string[]
                {
                    "stbtt_fontinfo",
                },
                SkipGlobalVariables = new string[]
                {
                },
                SkipFunctions = new string[]
                {
                    "stbtt__find_table",
                },
            };

            var dump = TextCodeConverter.Convert(parameters.InputPath, parameters.Defines);

            File.WriteAllText(@"..\..\..\..\..\..\src\StbTrueType.txt", dump);

            var result = RoslynCodeConverter.Convert(parameters);

            // Post processing
            Logger.Info("Post processing...");

            var outputFiles = new Dictionary <string, string>();

            Write(result.NamedEnums, outputFiles);
            Write(result.UnnamedEnumValues, outputFiles);
            Write(result.GlobalVariables, outputFiles);
            Write(result.Delegates, outputFiles);
            Write(result.Structs, outputFiles);
            Write(result.Functions, outputFiles);

            foreach (var pair in outputFiles)
            {
                var data = PostProcess(pair.Value);

                var sb = new StringBuilder();
                sb.AppendLine(string.Format("// Generated by Sichem at {0}", DateTime.Now));
                sb.AppendLine();

                sb.AppendLine("using System;");
                sb.AppendLine("using System.Runtime.InteropServices;");
                sb.AppendLine("using Hebron.Runtime;");

                sb.AppendLine();

                sb.Append("namespace StbTrueTypeSharp\n{\n\t");
                sb.AppendLine("unsafe partial class StbTrueType\n\t{");

                data  = sb.ToString() + data;
                data += "}\n}";

                var fileName = @"..\..\..\..\..\..\src\StbTrueType.Generated." + pair.Key + ".cs";
                Logger.Info("Writing {0}", fileName);
                File.WriteAllText(fileName, data);
            }
        }
Example #2
0
        static void Process()
        {
            var parameters = new RoslynConversionParameters
            {
                InputPath = @"stb_image.h",
                Defines   = new[]
                {
                    "STBI_NO_SIMD",
                    "STBI_NO_PIC",
                    "STBI_NO_PNM",
                    "STBI_NO_STDIO",
                    "STB_IMAGE_IMPLEMENTATION",
                },
                SkipStructs = new[]
                {
                    "stbi_io_callbacks",
                    "stbi__context",
                },
                SkipGlobalVariables = new[]
                {
                    "stbi__g_failure_reason",
                    "stbi__vertically_flip_on_load",
                    "stbi__parse_png_file_invalid_chunk",
                },
                SkipFunctions = new[]
                {
                    "stbi_failure_reason",
                    "stbi_image_free",
                    "stbi__err",
                    "stbi_is_hdr_from_memory",
                    "stbi_is_hdr_from_callbacks",
                    "stbi__pnm_isspace",
                    "stbi__pnm_skip_whitespace",
                    "stbi__pic_is4",
                    "stbi__start_mem",
                    "stbi__start_callbacks",
                    "stbi__rewind",
                    "stbi_load_16_from_callbacks",
                    "stbi_load_from_callbacks",
                    "stbi__get8",
                    "stbi__refill_buffer",
                    "stbi__at_eof",
                    "stbi__skip",
                    "stbi__getn",
                    "stbi_load_16_from_memory",
                    "stbi_load_from_memory",
                    "stbi_load_gif_from_memory",
                    "stbi_info_from_memory",
                    "stbi_info_from_callbacks",
                    "stbi_is_16_bit_from_memory",
                    "stbi_is_16_bit_from_callbacks",
                    "stbi_loadf_from_memory",
                    "stbi_loadf_from_callbacks"
                }
            };

            //            var result = TextCodeConverter.Convert(parameters.InputPath, parameters.Defines);

            var result = RoslynCodeConverter.Convert(parameters);

            // Post processing
            Logger.Info("Post processing...");

            var outputFiles = new Dictionary <string, string>();

            Write(result.NamedEnums, outputFiles);
            Write(result.UnnamedEnumValues, outputFiles);
            Write(result.GlobalVariables, outputFiles);
            Write(result.Delegates, outputFiles);
            Write(result.Structs, outputFiles);
            Write(result.Functions, outputFiles);

            foreach (var pair in outputFiles)
            {
                var data = PostProcess(pair.Value);

                var sb = new StringBuilder();
                sb.AppendLine(string.Format("// Generated by Sichem at {0}", DateTime.Now));
                sb.AppendLine();

                sb.AppendLine("using System;");
                sb.AppendLine("using System.Runtime.InteropServices;");
                sb.AppendLine("using Hebron.Runtime;");

                sb.AppendLine();

                sb.Append("namespace StbImageSharp\n{\n\t");
                sb.AppendLine("unsafe partial class StbImage\n\t{");

                data  = sb.ToString() + data;
                data += "}\n}";

                File.WriteAllText(@"..\..\..\..\..\..\src\StbImage.Generated." + pair.Key + ".cs", data);
            }
        }