Skip to content

Commit

Permalink
Stackification works
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Oct 12, 2023
1 parent 298a543 commit 5588b09
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Draco.Compiler/Internal/Codegen/CilCodegen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public CilCodegen(MetadataCodegen metadataCodegen, IProcedure procedure)
if (SymbolEqualityComparer.Default.Equals(register.Type, IntrinsicSymbols.Unit)) return null;
if (!this.allocatedRegisters.TryGetValue(register, out var allocatedRegister))
{
allocatedRegister = this.allocatedRegisters.Count;
// NOTE: We need to offset by the number of locals
allocatedRegister = this.allocatedLocals.Count + this.allocatedRegisters.Count;
this.allocatedRegisters.Add(register, allocatedRegister);
}
return allocatedRegister;
Expand Down Expand Up @@ -281,7 +282,7 @@ IEnumerable<IOperand> RemainingOperands()
case StoreElementInstruction storeElement:
{
this.EncodePush(NextOperand());
var remainingOps = RemainingOperands();
var remainingOps = RemainingOperands().ToList();
foreach (var index in remainingOps.SkipLast(1)) this.EncodePush(index);
this.EncodePush(remainingOps.Last());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal sealed class BranchInstruction : InstructionBase
{
public override string InstructionKeyword => "jump_if";
public override bool IsBranch => true;
public override IEnumerable<IOperand> Operands => new[] { this.Condition };
public override IEnumerable<BasicBlock> JumpTargets => new[] { this.Then, this.Else };

/// <summary>
Expand Down

0 comments on commit 5588b09

Please sign in to comment.