Example #1
0
        public InternalFunction(MachineInfo machineInfo, string prototype, InternalFunctionAction?action = null)
        {
            var report   = new Report(new Report.TextWriterPrinter(Console.Out));
            var parser   = new CParser();
            var tu       = parser.ParseTranslationUnit("_internal.h", prototype + ";", ((_, __) => null), report);
            var compiler = new Compiler.CCompiler(machineInfo, report);

            compiler.Add(tu);
            var exe = compiler.Compile();

            if (tu.Functions.Count == 0)
            {
                throw new Exception("Failed to parse function prototype: " + prototype);
            }
            var f = tu.Functions[0];

            Name         = f.Name;
            NameContext  = f.NameContext;
            FunctionType = f.FunctionType;
            if (action != null)
            {
                Action = action;
            }
            else
            {
                Action = _ => { };
            }
        }
Example #2
0
        public InternalFunction(MachineInfo machineInfo, string prototype, InternalFunctionAction action = null)
        {
            var report = new Report(new Report.TextWriterPrinter(Console.Out));
            var parser = new CParser();
            var pp     = new Preprocessor(report);

            pp.AddCode("<Internal>", prototype + ";");
            var      tu       = parser.ParseTranslationUnit(new Lexer(pp));
            Compiler compiler = new Compiler(machineInfo, report);

            compiler.Add(tu);
            var exe = compiler.Compile();

            if (tu.Functions.Count == 0)
            {
                throw new Exception("Failed to parse function prototype: " + prototype);
            }
            var f = tu.Functions[0];

            Name         = f.Name;
            NameContext  = f.NameContext;
            FunctionType = f.FunctionType;

            Action = action;
        }
Example #3
0
        public void AddCode(string name, string code)
        {
            var pp = new Preprocessor(context.Report);

            pp.AddCode("machine.h", context.MachineInfo.HeaderCode);
            pp.AddCode(name, code);
            var lexer  = new Lexer(pp);
            var parser = new CParser();

            Add(parser.ParseTranslationUnit(lexer));
        }
Example #4
0
        TranslationUnit Parse(string code)
        {
            var report = new Report(new TestPrinter());
            var pp     = new Preprocessor(report);

            pp.AddCode("stdin", code);
            var lexer  = new Lexer(pp);
            var parser = new CParser();

            return(parser.ParseTranslationUnit(lexer, report));
        }
Example #5
0
        CType ParseType(string code)
        {
            var report = new Report(new TestPrinter());
            var pp     = new Preprocessor(report);

            pp.AddCode("stdin", code);
            var lexer  = new Lexer(pp);
            var parser = new CParser();
            var tu     = parser.ParseTranslationUnit(lexer, report);

            return(tu.Variables[0].VariableType);
        }
Example #6
0
        void ProcessDocument(Document document)
        {
            var lexed = new LexedDocument(document, options.Report);

            lexedDocuments[document.Path] = lexed;

            if (document.IsCompilable)
            {
                var parser = new CParser();

                var name = System.IO.Path.GetFileNameWithoutExtension(document.Path);

                Add(parser.ParseTranslationUnit(options.Report, name, Include, lexedDocuments["_machine.h"].Tokens, lexed.Tokens));
            }
        }