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 static Interpreter.Executable Compile(string code, MachineInfo machineInfo = null, Report.Printer printer = null) { var report = new Report(printer); var mi = machineInfo ?? new MachineInfo(); var pp = new Preprocessor(report); pp.AddCode("machine.h", mi.HeaderCode); pp.AddCode(DefaultName, code); var lexer = new Lexer(pp); var parser = new CParser(); var tu = parser.ParseTranslationUnit(lexer); var c = new Interpreter.Compiler(mi, report); c.Add(tu); var exe = c.Compile(); return(exe); }