Skip to content

Commit

Permalink
Simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Oct 13, 2023
1 parent 4527669 commit d7a1808
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
18 changes: 3 additions & 15 deletions src/Draco.Compiler/Internal/OptimizingIr/Model/Procedure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal sealed class Procedure : IProcedure
public BasicBlock Entry { get; }
IBasicBlock IProcedure.Entry => this.Entry;
public IReadOnlyList<TypeParameterSymbol> Generics => this.Symbol.GenericParameters;
public IReadOnlyList<ParameterSymbol> Parameters => this.parameters;
public IReadOnlyList<ParameterSymbol> Parameters => this.Symbol.Parameters;
public TypeSymbol ReturnType => this.Symbol.ReturnType;
public IReadOnlyDictionary<LabelSymbol, IBasicBlock> BasicBlocks => this.basicBlocks;
public IEnumerable<IBasicBlock> BasicBlocksInDefinitionOrder => this.basicBlocks.Values
Expand All @@ -30,7 +30,6 @@ internal sealed class Procedure : IProcedure
public IReadOnlyList<LocalSymbol> Locals => this.locals;
public IReadOnlyList<Register> Registers => this.registers;

private readonly List<ParameterSymbol> parameters = new();
private readonly Dictionary<LabelSymbol, IBasicBlock> basicBlocks = new();
private readonly List<LocalSymbol> locals = new();
private readonly List<Register> registers = new();
Expand All @@ -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))
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/Draco.Compiler/Internal/OptimizingIr/ModuleCodegen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d7a1808

Please sign in to comment.