From d7a1808e11ed981c19d0921b0ab8fed456927275 Mon Sep 17 00:00:00 2001 From: LPeter1997 Date: Fri, 13 Oct 2023 13:33:02 +0200 Subject: [PATCH] Simplification --- .../OptimizingIr/FunctionBodyCodegen.cs | 4 ---- .../Internal/OptimizingIr/Model/Procedure.cs | 18 +++--------------- .../Internal/OptimizingIr/ModuleCodegen.cs | 3 +-- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/Draco.Compiler/Internal/OptimizingIr/FunctionBodyCodegen.cs b/src/Draco.Compiler/Internal/OptimizingIr/FunctionBodyCodegen.cs index 86209da05..c2b394440 100644 --- a/src/Draco.Compiler/Internal/OptimizingIr/FunctionBodyCodegen.cs +++ b/src/Draco.Compiler/Internal/OptimizingIr/FunctionBodyCodegen.cs @@ -79,10 +79,6 @@ private Procedure SynthetizeProcedure(SynthetizedFunctionSymbol func) { var codegen = new FunctionBodyCodegen(this.compilation, proc); func.Body.Accept(codegen); - // TODO: Kinda duplication - // Maybe we should move parameter definition to the proc construction simply? - // Or even simpler, just project from symbol? - foreach (var param in func.Parameters) proc.DefineParameter(param); } return proc; } diff --git a/src/Draco.Compiler/Internal/OptimizingIr/Model/Procedure.cs b/src/Draco.Compiler/Internal/OptimizingIr/Model/Procedure.cs index 0598fd279..05bc8ebb6 100644 --- a/src/Draco.Compiler/Internal/OptimizingIr/Model/Procedure.cs +++ b/src/Draco.Compiler/Internal/OptimizingIr/Model/Procedure.cs @@ -21,7 +21,7 @@ internal sealed class Procedure : IProcedure public BasicBlock Entry { get; } IBasicBlock IProcedure.Entry => this.Entry; public IReadOnlyList Generics => this.Symbol.GenericParameters; - public IReadOnlyList Parameters => this.parameters; + public IReadOnlyList Parameters => this.Symbol.Parameters; public TypeSymbol ReturnType => this.Symbol.ReturnType; public IReadOnlyDictionary BasicBlocks => this.basicBlocks; public IEnumerable BasicBlocksInDefinitionOrder => this.basicBlocks.Values @@ -30,7 +30,6 @@ internal sealed class Procedure : IProcedure public IReadOnlyList Locals => this.locals; public IReadOnlyList Registers => this.registers; - private readonly List parameters = new(); private readonly Dictionary basicBlocks = new(); private readonly List locals = new(); private readonly List registers = new(); @@ -44,22 +43,11 @@ public Procedure(Module declaringModule, FunctionSymbol symbol) public int GetParameterIndex(ParameterSymbol symbol) { - var idx = this.parameters.IndexOf(symbol); + var idx = this.Symbol.Parameters.IndexOf(symbol); if (idx == -1) throw new System.ArgumentOutOfRangeException(nameof(symbol)); return idx; } - public int DefineParameter(ParameterSymbol symbol) - { - var index = this.parameters.IndexOf(symbol); - if (index == -1) - { - index = this.parameters.Count; - this.parameters.Add(symbol); - } - return index; - } - public BasicBlock DefineBasicBlock(LabelSymbol symbol) { if (!this.basicBlocks.TryGetValue(symbol, out var block)) @@ -77,7 +65,7 @@ public int DefineLocal(LocalSymbol symbol) var index = this.locals.IndexOf(symbol); if (index == -1) { - index = this.parameters.Count; + index = this.locals.Count; this.locals.Add(symbol); } return index; diff --git a/src/Draco.Compiler/Internal/OptimizingIr/ModuleCodegen.cs b/src/Draco.Compiler/Internal/OptimizingIr/ModuleCodegen.cs index ae4e887ab..e9b824545 100644 --- a/src/Draco.Compiler/Internal/OptimizingIr/ModuleCodegen.cs +++ b/src/Draco.Compiler/Internal/OptimizingIr/ModuleCodegen.cs @@ -61,9 +61,8 @@ public override void VisitFunction(FunctionSymbol functionSymbol) { if (functionSymbol is not SourceFunctionSymbol sourceFunction) return; - // Add procedure, define parameters + // Add procedure var procedure = this.module.DefineProcedure(functionSymbol); - foreach (var param in functionSymbol.Parameters) procedure.DefineParameter(param); // Create the body var body = this.RewriteBody(sourceFunction.Body);