예제 #1
0
파일: CCompiler.cs 프로젝트: soywiz/ilcc
        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;
        }
예제 #2
0
파일: Program.cs 프로젝트: soywiz/ilcc
        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
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="FileName"></param>
        /// <param name="Text"></param>
        /// <param name="Context"></param>
        public CPreprocessorInternal(string FileName, string Text, CPreprocessorContext Context)
        {
            // Remove comments.

            try { FileName = Path.GetFullPath(FileName); }
            catch { }

            if (Context.DebugPreprocessor)
            {
                Console.WriteLine("CPreprocessorInternal(FileName={0})", FileName);
            }

            Text = CPreprocessor.RemoveComments(Text.Replace("\r\n", "\n").Replace("\r", "\n"));

            this.Text            = Text;
            this.CurrentFileName = FileName;
            this.CTokenizer      = new CTokenizer(Text, TokenizeSpaces: true);
            this.Context         = Context;
            this.Tokens          = new CTokenReader(CTokenizer.Tokenize());
            this.Tokens.MoveNextSpace();

            OutputLine();
            //Console.WriteLine(Tokens.GetString());
        }
예제 #4
0
 public void Initialize()
 {
     CIncludeReader = new TestIncludeReader();
     CPreprocessor = new CPreprocessor(CIncludeReader);
 }
예제 #5
0
파일: CCompiler.cs 프로젝트: soywiz/ilcc
 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());
         }
     }
 }