Ejemplo n.º 1
0
        protected override byte[] GenerateChildContent(string inputFilePath, string inputFileContents)
        {
            using (var s = new MemoryStream())
                switch (Path.GetExtension(inputFilePath))
                {
                case ".template":
                    if (!string.IsNullOrWhiteSpace(inputFileContents))
                    {
                        return(_templateFileContents = Encoding.ASCII.GetBytes(inputFileContents));
                    }
                    using (var rS = typeof(LALRC).Assembly.GetManifestResourceStream("Contoso.Resource_.Lempar.c"))
                        using (var r = new StreamReader(rS))
                            return(_templateFileContents = Encoding.ASCII.GetBytes(r.ReadToEnd()));

                case ".h":
                    using (var w = new StreamWriter(s))
                        EmitterC.EmitHeader(_ctx, w);
                    return(s.ToArray());

                case ".out":
                    using (var w = new StreamWriter(s))
                        Reporter.EmitOutput(_ctx, w, false);
                    return(s.ToArray());

                default: throw new InvalidOperationException();
                }
        }
Ejemplo n.º 2
0
        protected override byte[] GenerateContent(string inputFilePath, string inputFileContents)
        {
            var newFilePath = Path.Combine(Path.GetDirectoryName(inputFilePath), Path.GetFileNameWithoutExtension(inputFilePath) + GetDefaultExtension());

            using (var s = new MemoryStream())
            {
                using (var rS = new MemoryStream(_templateFileContents))
                    using (var r = new StreamReader(rS))
                        using (var w = new StreamWriter(s))
                            EmitterC.EmitTable(_ctx, r, w, false, newFilePath);
                return(s.ToArray());
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            // load solution
            string path     = Path.Combine(Environment.CurrentDirectory, @"..\..\..\");
            var    solution = new Solution(Path.Combine(path, @"TestApp\TestApp.csproj"));

            // parse solution
            var task = solution.Parse();

            task.Wait();

            // emit solution
            var emitter = new EmitterC(solution, Path.Combine(path, "TestOutput"), EmitterC.CVersions.c99, EmitterC.CompilerTargets.VC, EmitterC.PlatformTypes.Standalone, EmitterC.GCTypes.Boehm);

            emitter.Emit(false);
        }