Parses a C compilation unit and transforms all declarations to the XML syntax used by Reko.
Beispiel #1
0
        public int Execute(string [] args)
        {
            TextReader input;
            Stream     output = Console.OpenStandardOutput();
            var        sc     = new ServiceContainer();

            sc.AddService(typeof(IPluginLoaderService), new PluginLoaderService());
            var rekoCfg = RekoConfigurationService.Load(sc);

            sc.AddService <IConfigurationService>(rekoCfg);

            var docopt = new Docopt();
            IDictionary <string, ValueObject> options;

            try {
                options = docopt.Apply(usage, args);
            } catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
                return(1);
            }

            var arch = rekoCfg.GetArchitecture(options["-a"].ToString());

            if (arch == null)
            {
                Console.WriteLine(
                    "c2xml: unknown architecture '{0}'. Check the c2xml config file for supported architectures.",
                    options["-a"]);
                return(-1);
            }

            var envElem = rekoCfg.GetEnvironment(options["-e"].ToString());

            if (envElem == null)
            {
                Console.WriteLine(
                    "c2xml: unknown environment '{0}'. Check the c2xml config file for supported architectures.",
                    options["-e"]);
                return(-1);
            }
            var platform = envElem.Load(sc, arch);

            try
            {
                input = new StreamReader(options["<inputfile>"].ToString());
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("c2xml: unable to open file {0} for reading. {1}", options["<inputfile>"], ex.Message);
                return(1);
            }

            if (options.ContainsKey("<outputfile>") && options["<outputfile>"] != null)
            {
                try
                {
                    output = new FileStream(options["<outputfile>"].ToString(), FileMode.Create, FileAccess.Write);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("c2xml: unable to open file {0} for writing. {1}", options["<outputfile>"], ex.Message);
                    return(1);
                }
            }
            string dialect = null;

            if (options.TryGetValue("-d", out var optDialect) && optDialect != null)
            {
                dialect = (string)optDialect.Value;
            }
            var xWriter = new XmlTextWriter(output, new UTF8Encoding(false))
            {
                Formatting = Formatting.Indented
            };

            XmlConverter c = new XmlConverter(input, xWriter, platform, dialect);

            c.Convert();
            output.Flush();
            output.Close();
            return(0);
        }
Beispiel #2
0
        public int Execute(string [] args)
        {
            TextReader input   = Console.In;
            TextWriter output  = Console.Out;
            var        sc      = new ServiceContainer();
            var        rekoCfg = RekoConfigurationService.Load();

            sc.AddService <IConfigurationService>(rekoCfg);

            var docopt = new Docopt();
            IDictionary <string, ValueObject> options;

            try {
                options = docopt.Apply(usage, args);
            } catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
                return(1);
            }
            var arch = rekoCfg.GetArchitecture(options["-a"].ToString());

            if (arch == null)
            {
                Console.WriteLine(
                    "c2xml: unknown architecture '{0}'. Check the c2xml config file for supported architectures.",
                    options["-a"]);
                return(-1);
            }
            var envElem = rekoCfg.GetEnvironment(options["-e"].ToString());

            if (envElem == null)
            {
                Console.WriteLine(
                    "c2xml: unknown environment '{0}'. Check the c2xml config file for supported architectures.",
                    options["-e"]);
                return(-1);
            }

            var platform = envElem.Load(sc, arch);

            try
            {
                input = new StreamReader(options["<inputfile>"].ToString());
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("c2xml: unable to open file {0} for reading. {1}", options["<inputfile>"], ex.Message);
                return(1);
            }

            if (options.ContainsKey("<outputfile>") &&
                options["<outputfile>"] != null)
            {
                try
                {
                    output = new StreamWriter(options["<outputfile>"].ToString());
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("c2xml: unable to open file {0} for writing. {1}", options["<outputfile>"], ex.Message);
                    return(1);
                }
            }
            var xWriter = new XmlTextWriter(output)
            {
                Formatting = Formatting.Indented
            };

            XmlConverter c = new XmlConverter(input, xWriter, platform);

            c.Convert();
            output.Flush();
            return(0);
        }
Beispiel #3
0
 public TypeSizer(XmlConverter converter)
 {
     this.converter = converter;
     this.tagSizes  = new Dictionary <SerializedTaggedType, int>(new SerializedTypeComparer());
 }