public static Type CompileProgram(string CProgram, bool SaveTemp = false) { var CILConverter = new CILConverter(SaveAssembly: SaveTemp); CILConverter.Initialize("Program" + UniqueCounter++ + ".exe"); var CPreprocessor = new CPreprocessor(); CPreprocessor.PreprocessString(CProgram); var PreprocessedCProgram = CPreprocessor.TextWriter.ToString(); var CCompiler = new CCompiler(); var TranslationUnit = CParser.StaticParseTranslationUnit(PreprocessedCProgram); (CILConverter as ICConverter).ConvertTranslationUnit(CCompiler, TranslationUnit); return CILConverter.RootTypeBuilder; }
public static Type CompileProgram(string CProgram, bool SaveTemp = false) { var CILConverter = new CILConverter(SaveAssembly: SaveTemp); CILConverter.Initialize("Program" + UniqueCounter++ + ".exe"); var CPreprocessor = new CPreprocessor(); CPreprocessor.PreprocessString(CProgram); var PreprocessedCProgram = CPreprocessor.TextWriter.ToString(); var CCompiler = new CCompiler(); var TranslationUnit = CParser.StaticParseTranslationUnit(PreprocessedCProgram); (CILConverter as ICConverter).ConvertTranslationUnit(CCompiler, TranslationUnit); return(CILConverter.RootTypeBuilder); }
public void ConvertTranslationUnit(CCompiler CCompiler, CParser.TranslationUnit Program) { Console.WriteLine(Program.ToYaml()); }
public void ProcessArgs(string[] args) { CaptureExceptions(() => { #if false args = new[] { "-t=yaml" }; #endif var FileNames = new List<string>(); var CCompiler = new CCompiler(); CCompiler.SetTarget("cil"); if (args.Length == 0) { ShowHelp(); } var Getopt = new Getopt(args); { Getopt.AddRule(new[] { "--help", "-h", "-?" }, () => { ShowHelp(); }); Getopt.AddRule(new[] { "--target", "-t" }, (string Target) => { CCompiler.SetTarget(Target); }); Getopt.AddRule(new[] { "--version", "-v" }, () => { ShowVersion(); }); Getopt.AddRule(new[] { "-c" }, () => { CCompiler.CompileOnly = true; }); Getopt.AddRule(new[] { "--preprocess", "-E" }, () => { CCompiler.JustPreprocess = true; }); Getopt.AddRule(new[] { "--include_path", "-I" }, (string Path) => { CCompiler.AddIncludePath(Path); }); Getopt.AddRule(new[] { "--show_macros" }, () => { CCompiler.JustShowMacros = true; }); Getopt.AddRule(new[] { "-run" }, (string[] Left) => { CCompiler.ShouldRun = true; CCompiler.RunParameters = Left; }); Getopt.AddRule(new[] { "--show_targets" }, () => { ShowTargets(); }); Getopt.AddRule("", (string Name) => { FileNames.Add(Name); }); } Getopt.Process(); if (FileNames.Count == 0) { ShowHelp(); } CCompiler.CompileFiles(FileNames.ToArray()); }); }
/// <summary> /// /// </summary> /// <param name="CCompiler"></param> /// <param name="TranslationUnit"></param> void ICConverter.ConvertTranslationUnit(CCompiler CCompiler, CParser.TranslationUnit TranslationUnit) { this.CCompiler = CCompiler; Traverse(TranslationUnit); }