public Executable Compile() { var exe = new Executable(context.MachineInfo); // Put something at the zero address so we don't get 0 addresses of globals exe.Globals.Add(new VariableDeclaration("__zero__", CBasicType.SignedInt)); foreach (var tu in tus) { exe.Globals.AddRange(tu.Variables); foreach (var fdecl in tu.Functions) { var fexe = exe.Functions.FirstOrDefault(x => x.Name == fdecl.Name); if (fexe == null) { fexe = new CompiledFunction(fdecl.Name, fdecl.FunctionType); exe.Functions.Add(fexe); } var cfexe = fexe as CompiledFunction; if (cfexe != null && fdecl.Body != null) { var c = new FunctionContext(exe, fdecl, cfexe, context); fdecl.Body.Emit(c); cfexe.LocalVariables.AddRange(c.LocalVariables); // Make sure it returns if (fdecl.Body.Statements.Count == 0 || !fdecl.Body.AlwaysReturns) { if (fdecl.FunctionType.ReturnType.IsVoid) { c.Emit(OpCode.Return); } else { context.Report.Error(161, "'" + fdecl.Name + "' not all code paths return a value"); } } } } } return(exe); }
public override void Emit(Instruction instruction) { _forward.Emit(instruction); }
public override void Emit(Instruction instruction) { _parent.Emit(instruction); }