public void CompileFiles(string[] FileNames) { var CCodeWriter = new StringWriter(); if (FileNames.Length > 0) { this.OutputName = Path.GetFileNameWithoutExtension(FileNames[0]) + ".exe"; this.Target.SetOutputName(this.OutputName); //Console.WriteLine(this.OutputName); //Console.ReadKey(); } foreach (var FileName in FileNames) { var Text = File.ReadAllText(FileName); var CPreprocessor = new CPreprocessor(IncludeReader, CCodeWriter); CPreprocessor.PreprocessString(Text, FileName); if (JustShowMacros) { CPreprocessor.Context.DumpMacros(); } } if (!JustShowMacros) { if (JustPreprocess) { Console.WriteLine(CCodeWriter.ToString()); } else { CompileString(CCodeWriter.ToString()); } } }
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); }
static void SandboxTest(string[] args) { #if false var CPreprocessor = new CPreprocessor(); CPreprocessor.PreprocessString(@" //#define OF() () //typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); " ); var Text = (CPreprocessor.TextWriter.ToString()); Console.WriteLine(Text); #elif true //CLibTest.TestCall(); //new CCompilerProgram().ProcessArgs(new string[] { "--target=cil", @"c:\temp\zlib-1.2.7\adler32.c" }); //new CCompilerProgram().ProcessArgs(new string[] { "--target=cil", @"c:\temp\zlib-1.2.7\trees.c" }); new CCompilerProgram().ProcessArgs(new string[] { "--target=cil", @"c:\temp\ll.c", "-run" }); //new CCompilerProgram().ProcessArgs(new string[] { "--target=cil", @"c:\temp\stemmer.c", "-run", @"c:\temp\voc.txt", }); //new CCompilerProgram().ProcessArgs(new string[] { "--target=cil", @"C:\projects\@_opensource\libwebp-0.1.3\src\dec\alpha.c" }); //new CCompilerProgram().ProcessArgs(new string[] { "--target=cil", @"C:\temp\m.c" }); //Console.WriteLine(CLibTest.TestStackAlloc()); //new CCompilerProgram().ProcessArgs(new string[] { "--target=pinvoke", @"C:\temp\comp\complib.c", @"C:\temp\comp\comptoe.c" }); //new CCompilerProgram().ProcessArgs(new string[] { "--target=cil", @"C:\temp\comp\complib.c", @"C:\temp\comp\comptoe.c" }); //new CCompilerProgram().ProcessArgs(new string[] { "--target=cil", @"C:\temp\z5.c" }); //new CCompilerProgram().ProcessArgs(new string[] { "--target=cil", @"C:\temp\z.c" }); //new CCompilerProgram().ProcessArgs(new string[] { "--target=pinvoke", @"C:\temp\z.c" }); //new CCompilerProgram().ProcessArgs(new string[] { "--target=cil", @"c:\temp\zlib-1.2.7\adler32.c" }); #else var Node = CParser.StaticParseProgram(@" void test() { call(); } " ); Console.WriteLine(Node.ToYaml()); #endif }
public void TestInclude() { CPreprocessor.PreprocessString(@" #include ""local_file.c"" #include <system_file.c> " ); var Text = (CPreprocessor.TextWriter as StringWriter).ToString(); Console.WriteLine(Text); StringAssert.Contains(Text, "my_local_file"); StringAssert.Contains(Text, "our_system_file"); }