-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split sizeof(Identifier) and sizeof(TypeName)
- Loading branch information
1 parent
01d6c17
commit 281942c
Showing
11 changed files
with
200 additions
and
59 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
13 changes: 13 additions & 0 deletions
13
Cesium.CodeGen.Tests/verified/CodeGenSizeofTests.EnumSizeof.verified.txt
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,13 @@ | ||
System.Int32 <Module>::main() | ||
IL_0000: sizeof System.Int32 | ||
IL_0006: ret | ||
|
||
System.Int32 <Module>::<SyntheticEntrypoint>() | ||
Locals: | ||
System.Int32 V_0 | ||
IL_0000: call System.Int32 <Module>::main() | ||
IL_0005: stloc.s V_0 | ||
IL_0007: ldloc.s V_0 | ||
IL_0009: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32) | ||
IL_000e: ldloc.s V_0 | ||
IL_0010: ret |
18 changes: 18 additions & 0 deletions
18
Cesium.CodeGen.Tests/verified/CodeGenSizeofTests.GlobalIdentifierSizeof.verified.txt
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,18 @@ | ||
System.Void <Module>::.cctor() | ||
IL_0000: ldc.i4.1 | ||
IL_0001: stsfld System.Int32 <Module>::a | ||
IL_0006: ret | ||
|
||
System.Int32 <Module>::main() | ||
IL_0000: sizeof System.Int32 | ||
IL_0006: ret | ||
|
||
System.Int32 <Module>::<SyntheticEntrypoint>() | ||
Locals: | ||
System.Int32 V_0 | ||
IL_0000: call System.Int32 <Module>::main() | ||
IL_0005: stloc.s V_0 | ||
IL_0007: ldloc.s V_0 | ||
IL_0009: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32) | ||
IL_000e: ldloc.s V_0 | ||
IL_0010: ret |
17 changes: 17 additions & 0 deletions
17
Cesium.CodeGen.Tests/verified/CodeGenSizeofTests.IdentifierSizeof.verified.txt
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 @@ | ||
System.Int32 <Module>::main() | ||
Locals: | ||
System.Int32 V_0 | ||
IL_0000: ldc.i4.1 | ||
IL_0001: stloc.0 | ||
IL_0002: sizeof System.Int32 | ||
IL_0008: ret | ||
|
||
System.Int32 <Module>::<SyntheticEntrypoint>() | ||
Locals: | ||
System.Int32 V_0 | ||
IL_0000: call System.Int32 <Module>::main() | ||
IL_0005: stloc.s V_0 | ||
IL_0007: ldloc.s V_0 | ||
IL_0009: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32) | ||
IL_000e: ldloc.s V_0 | ||
IL_0010: ret |
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
31 changes: 31 additions & 0 deletions
31
Cesium.CodeGen/Ir/Expressions/IdentifierSizeOfOperatorExpression.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,31 @@ | ||
using Cesium.CodeGen.Contexts; | ||
using Cesium.CodeGen.Extensions; | ||
using Cesium.CodeGen.Ir.Types; | ||
using Cesium.Core; | ||
|
||
namespace Cesium.CodeGen.Ir.Expressions; | ||
|
||
internal class IdentifierSizeOfOperatorExpression : IExpression | ||
{ | ||
private readonly IdentifierExpression _identifier; | ||
|
||
public IdentifierSizeOfOperatorExpression(Ast.IdentifierSizeOfOperatorExpression astExpression) | ||
{ | ||
var expression = astExpression.Identifier.ToIntermediate(); | ||
|
||
if (expression is not IdentifierExpression identifierExpression) | ||
throw new CompilationException($"\"{astExpression.Identifier.Identifier}\" is not a valid identifier"); | ||
_identifier = identifierExpression; | ||
} | ||
|
||
public IExpression Lower(IDeclarationScope scope) | ||
{ | ||
var typeResolved = _identifier.Resolve(scope).GetValueType(); | ||
var sizeOfExpression = new SizeOfOperatorExpression(typeResolved); | ||
return sizeOfExpression.Lower(scope); | ||
} | ||
|
||
public void EmitTo(IEmitScope scope) => throw new AssertException("Should be lowered"); | ||
|
||
public IType GetExpressionType(IDeclarationScope scope) => throw new AssertException("Should be lowered"); | ||
} |
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
32 changes: 32 additions & 0 deletions
32
Cesium.CodeGen/Ir/Expressions/TypeNameSizeOfOperatorExpression.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,32 @@ | ||
using Cesium.Ast; | ||
using Cesium.CodeGen.Contexts; | ||
using Cesium.CodeGen.Ir.Declarations; | ||
using Cesium.CodeGen.Ir.Types; | ||
using Cesium.Core; | ||
|
||
namespace Cesium.CodeGen.Ir.Expressions; | ||
|
||
internal class TypeNameSizeOfOperatorExpression : IExpression | ||
{ | ||
private readonly IType _type; | ||
|
||
public TypeNameSizeOfOperatorExpression(Ast.TypeNameSizeOfOperatorExpression expression) | ||
{ | ||
var (specifiers, abstractDeclarator) = expression.TypeName; | ||
_type = (specifiers, abstractDeclarator) switch | ||
{ | ||
({ }, { }) => LocalDeclarationInfo.Of(specifiers, abstractDeclarator).Type, | ||
({ }, null) => LocalDeclarationInfo.Of(specifiers, (Declarator?)null).Type | ||
}; | ||
} | ||
|
||
public IExpression Lower(IDeclarationScope scope) | ||
{ | ||
var sizeOfExpression = new SizeOfOperatorExpression(_type); | ||
return sizeOfExpression.Lower(scope); | ||
} | ||
|
||
public void EmitTo(IEmitScope scope) => throw new AssertException("Should be lowered"); | ||
|
||
public IType GetExpressionType(IDeclarationScope scope) => throw new AssertException("Should be lowered"); | ||
} |
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