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 }
static void Main(string[] args) { #if debugenabled try { #endif string Code = File.ReadAllText("Tests\\Ackermann.cs"); CodeLexer lexer = new CodeLexer(Code); LexTokenList lexTokens = lexer.Analyze(); CPreprocessor preProcessor = new CPreprocessor(lexTokens); lexTokens = preProcessor.Process(); Console.WriteLine("LexTokens (post-processed):"); foreach (LexToken lexToken in lexTokens) { Console.WriteLine(lexToken.Kind.ToString() + " " + (lexToken.Value == null ? "" : lexToken.Value.ToString())); } Console.WriteLine("------\nGenerating AST.."); AstGenerator astGenerator = new AstGenerator(lexTokens); StatementList statements = astGenerator.Generate(); Console.WriteLine("Generated AST!"); Console.WriteLine(View.ASTView.GenerateStatements(statements)); #if debugenabled } catch (Exception ex) { Console.WriteLine(ex.Message + "\n" + ex.StackTrace); } #endif Console.ReadLine(); }
public void Initialize() { CIncludeReader = new TestIncludeReader(); CPreprocessor = new CPreprocessor(CIncludeReader); }