private Function DefineFunction(Function function, ExpressionContext body) { if (!function.IsDeclaration) { throw new ArgumentException($"Function {function.Name} cannot be redefined", nameof(function)); } var basicBlock = function.AppendBasicBlock("entry"); InstructionBuilder.PositionAtEnd(basicBlock); NamedValues.Clear( ); foreach (var arg in function.Parameters) { NamedValues[arg.Name] = arg; } var funcReturn = body.Accept(this); if (funcReturn == null) { function.EraseFromParent( ); return(null); } InstructionBuilder.Return(funcReturn); function.Verify( ); return(function); }
private (Function Function, int JitHandle) DefineFunction(Function function, ExpressionContext body) { if (!function.IsDeclaration) { throw new ArgumentException($"Function {function.Name} cannot be redefined", nameof(function)); } var basicBlock = function.AppendBasicBlock("entry"); InstructionBuilder.PositionAtEnd(basicBlock); NamedValues.Clear( ); foreach (var arg in function.Parameters) { var argSlot = CreateEntryBlockAlloca(function, arg.Name); InstructionBuilder.Store(arg, argSlot); NamedValues[arg.Name] = argSlot; } var funcReturn = body.Accept(this); if (funcReturn == null) { function.EraseFromParent( ); return(null, default);
private Function DefineFunction(Function function, ExpressionContext body) { if (!function.IsDeclaration) { throw new ArgumentException($"Function {function.Name} cannot be redefined", nameof(function)); } var proto = FunctionPrototypes[function.Name]; var basicBlock = function.AppendBasicBlock("entry"); InstructionBuilder.PositionAtEnd(basicBlock); var diFile = Module.DICompileUnit.File; var scope = Module.DICompileUnit; LexicalBlocks.Push(function.DISubProgram); // Unset the location for the prologue emission (leading instructions with no // location in a function are considered part of the prologue and the debugger // will run past them when breaking on a function) EmitLocation(null); NamedValues.Clear( ); foreach (var arg in function.Parameters) { uint line = ( uint )proto.Parameters[( int )(arg.Index)].Span.StartLine; uint col = ( uint )proto.Parameters[( int )(arg.Index)].Span.StartColumn; var argSlot = CreateEntryBlockAlloca(function, arg.Name); DILocalVariable debugVar = Module.DIBuilder.CreateArgument(function.DISubProgram , arg.Name , diFile , line , DoubleType , true , DebugInfoFlags.None , checked (( ushort )(arg.Index + 1)) // Debug index starts at 1! ); Module.DIBuilder.InsertDeclare(argSlot , debugVar , new DILocation(Context, line, col, function.DISubProgram) , InstructionBuilder.InsertBlock ); InstructionBuilder.Store(arg, argSlot); NamedValues[arg.Name] = argSlot; } var funcReturn = body.Accept(this); if (funcReturn == null) { function.EraseFromParent( ); LexicalBlocks.Pop( ); return(null); } InstructionBuilder.Return(funcReturn); LexicalBlocks.Pop( ); Module.DIBuilder.Finish(function.DISubProgram); function.Verify( ); Trace.TraceInformation(function.ToString( )); return(function); }