Skip to content

Commit

Permalink
Update FunctionBodyCodegen.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Dec 16, 2023
1 parent 3f09187 commit 52c7ce5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Draco.Compiler/Internal/OptimizingIr/FunctionBodyCodegen.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using Draco.Compiler.Api;
using Draco.Compiler.Internal.Binding;
Expand Down Expand Up @@ -69,8 +70,10 @@ private Module GetDefiningModule(Symbol symbol)
private int DefineLocal(LocalSymbol local) => this.procedure.DefineLocal(local);
public Register DefineRegister(TypeSymbol type) => this.procedure.DefineRegister(type);

private Procedure SynthetizeProcedure(SynthetizedFunctionSymbol func)
private Procedure SynthetizeProcedure(FunctionSymbol func)
{
Debug.Assert(func.Body is not null);

// We handle synthetized functions a bit specially, as they are not part of our symbol
// tree, so we compile them, in case they have not yet been
var compiledAlready = this.procedure.DeclaringModule.Procedures.ContainsKey(func);
Expand Down Expand Up @@ -501,11 +504,16 @@ public override IOperand VisitFunctionGroupExpression(BoundFunctionGroupExpressi

private FunctionSymbol TranslateFunctionSymbol(FunctionSymbol symbol) => symbol switch
{
// Functions with synthetized body
FunctionSymbol f when f.DeclaringSyntax is null && f.Body is not null => this.SynthetizeProcedure(f).Symbol,
// Functions with inline codegen
FunctionSymbol f when f.Codegen is not null => f,
// Source functions
SourceFunctionSymbol func => this.DefineProcedure(func).Symbol,
SynthetizedFunctionSymbol func => this.SynthetizeProcedure(func).Symbol,
// Metadata functions
MetadataMethodSymbol m => m,
// Generic functions
FunctionInstanceSymbol i => this.TranslateFunctionInstanceSymbol(i),
FunctionSymbol f when f.Codegen is not null => f,
_ => throw new System.ArgumentOutOfRangeException(nameof(symbol)),
};

Expand Down

0 comments on commit 52c7ce5

Please sign in to comment.