-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Slight refactoring of codegen structure (#460)
* Moved instructions * More * Fix
- Loading branch information
1 parent
24b9b33
commit b825016
Showing
39 changed files
with
116 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ptimizingIr/Model/AddressOfInstruction.cs → ...ngIr/Instructions/AddressOfInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...timizingIr/Model/ArithmeticInstruction.cs → ...gIr/Instructions/ArithmeticInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ternal/OptimizingIr/Model/ArithmeticOp.cs → ...OptimizingIr/Instructions/ArithmeticOp.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...imizingIr/Model/ArrayLengthInstruction.cs → ...Ir/Instructions/ArrayLengthInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...rnal/OptimizingIr/Model/BoxInstruction.cs → ...timizingIr/Instructions/BoxInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...l/OptimizingIr/Model/BranchInstruction.cs → ...izingIr/Instructions/BranchInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/Draco.Compiler/Internal/OptimizingIr/Instructions/CallInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Draco.Compiler.Internal.OptimizingIr.Model; | ||
using Draco.Compiler.Internal.Symbols; | ||
|
||
namespace Draco.Compiler.Internal.OptimizingIr.Instructions; | ||
|
||
/// <summary> | ||
/// A procedure call. | ||
/// </summary> | ||
internal sealed class CallInstruction( | ||
Register target, | ||
FunctionSymbol procedure, | ||
IOperand? receiver, | ||
IEnumerable<IOperand> arguments) : InstructionBase, IValueInstruction | ||
{ | ||
public override string InstructionKeyword => "call"; | ||
|
||
public Register Target { get; set; } = target; | ||
|
||
/// <summary> | ||
/// The called procedure. | ||
/// </summary> | ||
public FunctionSymbol Procedure { get; set; } = procedure; | ||
|
||
/// <summary> | ||
/// The receiver the method is called on. | ||
/// </summary> | ||
public IOperand? Receiver { get; set; } = receiver; | ||
|
||
/// <summary> | ||
/// The arguments that are passed to the procedure. | ||
/// </summary> | ||
public IList<IOperand> Arguments { get; set; } = arguments.ToList(); | ||
|
||
public override IEnumerable<Symbol> StaticOperands => [this.Procedure]; | ||
public override IEnumerable<IOperand> Operands => this.Receiver is null | ||
? this.Arguments | ||
: this.Arguments.Prepend(this.Receiver); | ||
|
||
public override string ToString() | ||
{ | ||
var target = this.Target.ToOperandString(); | ||
var receiver = this.Receiver is null | ||
? string.Empty | ||
: $"{this.Receiver.ToOperandString()}."; | ||
var args = string.Join(", ", this.Arguments.Select(a => a.ToOperandString())); | ||
return $"{target} := {this.InstructionKeyword} {receiver}[{this.Procedure.FullName}]({args})"; | ||
} | ||
|
||
public override CallInstruction Clone() => new(this.Target, this.Procedure, this.Receiver, this.Arguments); | ||
} |
2 changes: 1 addition & 1 deletion
2
...r/Internal/OptimizingIr/Model/EndScope.cs → ...nal/OptimizingIr/Instructions/EndScope.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ternal/OptimizingIr/Model/IInstruction.cs → ...OptimizingIr/Instructions/IInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...l/OptimizingIr/Model/IValueInstruction.cs → ...izingIr/Instructions/IValueInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...nal/OptimizingIr/Model/InstructionBase.cs → ...imizingIr/Instructions/InstructionBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...nal/OptimizingIr/Model/JumpInstruction.cs → ...imizingIr/Instructions/JumpInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...imizingIr/Model/LoadElementInstruction.cs → ...Ir/Instructions/LoadElementInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ptimizingIr/Model/LoadFieldInstruction.cs → ...ngIr/Instructions/LoadFieldInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...nal/OptimizingIr/Model/LoadInstruction.cs → ...imizingIr/Instructions/LoadInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...OptimizingIr/Model/NewArrayInstruction.cs → ...ingIr/Instructions/NewArrayInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...imizingIr/Model/NewDelegateInstruction.cs → ...Ir/Instructions/NewDelegateInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ptimizingIr/Model/NewObjectInstruction.cs → ...ngIr/Instructions/NewObjectInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rnal/OptimizingIr/Model/NopInstruction.cs → ...timizingIr/Instructions/NopInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...rnal/OptimizingIr/Model/RetInstruction.cs → ...timizingIr/Instructions/RetInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ernal/OptimizingIr/Model/SequencePoint.cs → ...ptimizingIr/Instructions/SequencePoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...mizingIr/Model/StoreElementInstruction.cs → ...r/Instructions/StoreElementInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...timizingIr/Model/StoreFieldInstruction.cs → ...gIr/Instructions/StoreFieldInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...al/OptimizingIr/Model/StoreInstruction.cs → ...mizingIr/Instructions/StoreInstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.