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 = _ => { }; } }
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; }
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)); }
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)); }
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); }
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)); } }