-
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.
- Loading branch information
Showing
11 changed files
with
154 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections.Generic; | ||
using Draco.Compiler.Internal.Symbols; | ||
|
||
namespace Draco.Compiler.Internal.OptimizingIr.Model; | ||
internal class Field(FieldSymbol symbol, Type declaringType) : IField | ||
{ | ||
public FieldSymbol Symbol { get; } = symbol; | ||
|
||
public string Name => this.Symbol.Name; | ||
|
||
public Type DeclaringType { get; } = declaringType; | ||
IType IField.DeclaringType => this.DeclaringType; | ||
|
||
public IReadOnlyList<AttributeInstance> Attributes => this.Symbol.Attributes; | ||
|
||
public TypeSymbol Type => this.Symbol.Type; | ||
} |
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,32 @@ | ||
using System.Collections.Generic; | ||
using Draco.Compiler.Internal.Symbols; | ||
|
||
namespace Draco.Compiler.Internal.OptimizingIr.Model; | ||
|
||
/// <summary> | ||
/// Read-only interface of a field. | ||
/// </summary> | ||
internal interface IField | ||
{ | ||
public FieldSymbol Symbol { get; } | ||
|
||
/// <summary> | ||
/// The name of this field. | ||
/// </summary> | ||
public string Name { get; } | ||
|
||
/// <summary> | ||
/// The type this procedure is defined in. | ||
/// </summary> | ||
public IType DeclaringType { get; } | ||
|
||
/// <summary> | ||
/// The attributes on this field. | ||
/// </summary> | ||
public IReadOnlyList<AttributeInstance> Attributes { get; } | ||
|
||
/// <summary> | ||
/// The type of this field. | ||
/// </summary> | ||
public TypeSymbol Type { get; } | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Collections.Generic; | ||
using Draco.Compiler.Internal.Symbols; | ||
|
||
namespace Draco.Compiler.Internal.OptimizingIr.Model; | ||
|
||
internal interface IType | ||
{ | ||
/// <summary> | ||
/// The name of this type. | ||
/// </summary> | ||
public string Name { get; } | ||
|
||
/// <summary> | ||
/// The module this type is defined in. | ||
/// </summary> | ||
public IModule DeclaringModule { get; } | ||
|
||
/// <summary> | ||
/// The assembly this type is defined in. | ||
/// </summary> | ||
public IAssembly Assembly { get; } | ||
|
||
/// <summary> | ||
/// The generic parameters on this type. | ||
/// </summary> | ||
public IReadOnlyList<TypeParameterSymbol> Generics { get; } | ||
|
||
/// <summary> | ||
/// The methods on this type. | ||
/// </summary> | ||
public IReadOnlyDictionary<FunctionSymbol, IProcedure> Methods { get; } | ||
|
||
/// <summary> | ||
/// The fields on this type. | ||
/// </summary> | ||
public IReadOnlyDictionary<FieldSymbol, IField> Fields { get; } | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Collections.Generic; | ||
using Draco.Compiler.Internal.Symbols; | ||
|
||
namespace Draco.Compiler.Internal.OptimizingIr.Model; | ||
internal class Type(Module declaringModule, TypeSymbol symbol) : IType | ||
{ | ||
|
||
public TypeSymbol Symbol { get; } = symbol; | ||
public string Name => this.Symbol.Name; | ||
|
||
public Module DeclaringModule { get; } = declaringModule; | ||
IModule IType.DeclaringModule => this.DeclaringModule; | ||
public Assembly Assembly => this.DeclaringModule.Assembly; | ||
IAssembly IType.Assembly => this.Assembly; | ||
|
||
public IReadOnlyList<TypeParameterSymbol> Generics => this.Symbol.GenericParameters; | ||
public IReadOnlyDictionary<FunctionSymbol, IProcedure> Methods => this.methods; | ||
public IReadOnlyDictionary<FieldSymbol, IField> Fields => this.fields; | ||
|
||
private readonly Dictionary<FunctionSymbol, IProcedure> methods = []; | ||
private readonly Dictionary<FieldSymbol, IField> fields = []; | ||
|
||
public Procedure DefineMethod(FunctionSymbol functionSymbol) | ||
{ | ||
if (!this.methods.TryGetValue(functionSymbol, out var result)) | ||
{ | ||
result = new Procedure(this.DeclaringModule, this, functionSymbol); | ||
this.methods.Add(functionSymbol, result); | ||
} | ||
return (Procedure)result; | ||
} | ||
|
||
public Field DefineField(FieldSymbol fieldSymbol) | ||
{ | ||
if (!this.fields.TryGetValue(fieldSymbol, out var result)) | ||
{ | ||
result = new Field(fieldSymbol, this); | ||
this.fields.Add(fieldSymbol, result); | ||
} | ||
return (Field)result; | ||
} | ||
} |
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