Skip to content

Commit 3763fb6

Browse files
authored
[RuntimeAsync] ilasm/ildasm support for the MethodImpl.Async (Take 2) (#115658)
* ilasm grammar * ildasm * Use newString helper function * More fixes * Regenerate grammar * Add tests for unquoted identifiers * Use live-built ilasm for tests * Fix tests
1 parent 8b3b6e5 commit 3763fb6

File tree

8 files changed

+4887
-4349
lines changed

8 files changed

+4887
-4349
lines changed

src/coreclr/ilasm/asmparse.y

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
%token VALUE_ VALUETYPE_ NATIVE_ INSTANCE_ SPECIALNAME_ FORWARDER_
7878
%token STATIC_ PUBLIC_ PRIVATE_ FAMILY_ FINAL_ SYNCHRONIZED_ INTERFACE_ SEALED_ NESTED_
7979
%token ABSTRACT_ AUTO_ SEQUENTIAL_ EXPLICIT_ ANSI_ UNICODE_ AUTOCHAR_ IMPORT_ ENUM_
80-
%token VIRTUAL_ NOINLINING_ AGGRESSIVEINLINING_ NOOPTIMIZATION_ AGGRESSIVEOPTIMIZATION_ UNMANAGEDEXP_ BEFOREFIELDINIT_
80+
%token VIRTUAL_ NOINLINING_ AGGRESSIVEINLINING_ NOOPTIMIZATION_ AGGRESSIVEOPTIMIZATION_ UNMANAGEDEXP_ BEFOREFIELDINIT_ ASYNC_
8181
%token STRICT_ RETARGETABLE_ WINDOWSRUNTIME_ NOPLATFORM_
8282
%token METHOD_ FIELD_ PINNED_ MODREQ_ MODOPT_ SERIALIZABLE_ PROPERTY_ TYPE_
8383
%token ASSEMBLY_ FAMANDASSEM_ FAMORASSEM_ PRIVATESCOPE_ HIDEBYSIG_ NEWSLOT_ RTSPECIALNAME_ PINVOKEIMPL_
@@ -244,6 +244,22 @@ languageDecl : _LANGUAGE SQSTRING
244244
;
245245
/* Basic tokens */
246246
id : ID { $$ = $1; }
247+
/* Allow methodImpl attributes to be used as identifiers */
248+
| NATIVE_ { $$ = newString("native"); }
249+
| CIL_ { $$ = newString("cil"); }
250+
| OPTIL_ { $$ = newString("optil"); }
251+
| MANAGED_ { $$ = newString("managed"); }
252+
| UNMANAGED_ { $$ = newString("unmanaged"); }
253+
| FORWARDREF_ { $$ = newString("forwardref"); }
254+
| PRESERVESIG_ { $$ = newString("preservesig"); }
255+
| RUNTIME_ { $$ = newString("runtime"); }
256+
| INTERNALCALL_ { $$ = newString("internalcall"); }
257+
| SYNCHRONIZED_ { $$ = newString("synchronized"); }
258+
| NOINLINING_ { $$ = newString("noinlining"); }
259+
| AGGRESSIVEINLINING_ { $$ = newString("aggressiveinlining"); }
260+
| NOOPTIMIZATION_ { $$ = newString("nooptimization"); }
261+
| AGGRESSIVEOPTIMIZATION_ { $$ = newString("aggressiveoptimization"); }
262+
| ASYNC_ { $$ = newString("async"); }
247263
| SQSTRING { $$ = $1; }
248264
;
249265

@@ -857,6 +873,7 @@ implAttr : /* EMPTY */ { $$ = (CorMethodImp
857873
| implAttr AGGRESSIVEINLINING_ { $$ = (CorMethodImpl) ($1 | miAggressiveInlining); }
858874
| implAttr NOOPTIMIZATION_ { $$ = (CorMethodImpl) ($1 | miNoOptimization); }
859875
| implAttr AGGRESSIVEOPTIMIZATION_ { $$ = (CorMethodImpl) ($1 | miAggressiveOptimization); }
876+
| implAttr ASYNC_ { $$ = (CorMethodImpl) ($1 | miAsync); }
860877
| implAttr FLAGS_ '(' int32 ')' { $$ = (CorMethodImpl) ($4); }
861878
;
862879

src/coreclr/ilasm/prebuilt/asmparse.cpp

Lines changed: 4800 additions & 4344 deletions
Large diffs are not rendered by default.

src/coreclr/ilasm/prebuilt/asmparse.grammar

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ languageDecl : '.language' SQSTRING
6868
;
6969
/* Basic tokens */
7070
id : ID
71+
/* Allow methodImpl attributes to be used as identifiers */
72+
| 'native'
73+
| 'cil'
74+
| 'optil'
75+
| 'managed'
76+
| 'unmanaged'
77+
| 'forwardref'
78+
| 'preservesig'
79+
| 'runtime'
80+
| 'internalcall'
81+
| 'synchronized'
82+
| 'noinlining'
83+
| 'aggressiveinlining'
84+
| 'nooptimization'
85+
| 'aggressiveoptimization'
86+
| 'async'
7187
| SQSTRING
7288
;
7389

@@ -528,6 +544,7 @@ implAttr : /* EMPTY */
528544
| implAttr 'aggressiveinlining'
529545
| implAttr 'nooptimization'
530546
| implAttr 'aggressiveoptimization'
547+
| implAttr 'async'
531548
| implAttr 'flags' '(' int32 ')'
532549
;
533550

src/coreclr/ildasm/dasm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3751,6 +3751,7 @@ BOOL DumpMethod(mdToken FuncToken, const char *pszClassName, DWORD dwEntryPointT
37513751
if(IsMiAggressiveInlining(dwImplAttrs)) szptr+=sprintf_s(szptr,SZSTRING_REMAINING_SIZE(szptr)," aggressiveinlining");
37523752
if(IsMiNoOptimization(dwImplAttrs)) szptr+=sprintf_s(szptr,SZSTRING_REMAINING_SIZE(szptr)," nooptimization");
37533753
if(IsMiAggressiveOptimization(dwImplAttrs)) szptr+=sprintf_s(szptr,SZSTRING_REMAINING_SIZE(szptr)," aggressiveoptimization");
3754+
if(IsMiAsync(dwImplAttrs)) szptr+=sprintf_s(szptr,SZSTRING_REMAINING_SIZE(szptr)," async");
37543755
szptr+=sprintf_s(szptr,SZSTRING_REMAINING_SIZE(szptr),KEYWORD((char*)-1));
37553756
printLine(GUICookie, szString);
37563757
VDELETE(buff);

src/coreclr/inc/il_kywd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
KYWD( "noinlining", NOINLINING_, NO_VALUE )
110110
KYWD( "nooptimization", NOOPTIMIZATION_, NO_VALUE )
111111
KYWD( "aggressiveoptimization", AGGRESSIVEOPTIMIZATION_, NO_VALUE )
112+
KYWD( "async", ASYNC_, NO_VALUE )
112113
KYWD( "nomangle", NOMANGLE_, NO_VALUE )
113114
KYWD( "lasterr", LASTERR_, NO_VALUE )
114115
KYWD( "winapi", WINAPI_, NO_VALUE )

src/tests/ilasm/MethodImplOptions/MethodImplOptionsTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ public MethodImplOptionsTests()
5454
}
5555

5656
[Theory]
57-
[InlineData("AggressiveOptimizationTest", "MiAggressiveOptimization.il", "aggressiveoptimization")]
57+
[InlineData("AggressiveOptimizationTest", "MiAggressiveOptimization.il", "Main", "aggressiveoptimization")]
58+
[InlineData("AsyncIdentifierTest", "MiAsUnquotedIdentifier.il", "'async'", "async")]
59+
[InlineData("RuntimeIdentifierNoInliningTest", "MiAsUnquotedIdentifier.il", "'runtime'", "noinlining")]
5860
public void RunMethodImplOptionsTest(
5961
string testName,
6062
string ilFileName,
63+
string methodName,
6164
string ilDisasmAttributeKeyword)
6265
{
6366
Console.WriteLine(testName);
@@ -77,7 +80,7 @@ public void RunMethodImplOptionsTest(
7780
string disasmIl = File.ReadAllText(disasmIlFileName);
7881
var findMainAttributeRegex =
7982
new Regex(
80-
@"\bvoid\s+Main\s*\(\s*\).*?\b" + ilDisasmAttributeKeyword + @"\b",
83+
$@"\bvoid\s+{methodName}\s*\(.*?\).*?\b{ilDisasmAttributeKeyword}\b",
8184
RegexOptions.Compiled | RegexOptions.Multiline);
8285

8386
Assert.True(findMainAttributeRegex.IsMatch(disasmIl), $"Attribute '{ilDisasmAttributeKeyword}' did not round-trip through ilasm and ildasm");
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#define CORE_ASSEMBLY "System.Runtime"
5+
6+
.assembly extern CORE_ASSEMBLY {}
7+
.assembly MiAsUnquotedIdentifier {}
8+
.module MiAsUnquotedIdentifier.dll
9+
10+
.class public auto ansi Program extends [CORE_ASSEMBLY]System.Object
11+
{
12+
.method public static int32 Main() il managed
13+
{
14+
.entrypoint
15+
.maxstack 8
16+
17+
ret
18+
}
19+
20+
.method public specialname rtspecialname instance void .ctor() cil managed
21+
{
22+
.maxstack 8
23+
24+
ldarg.0
25+
call instance void [CORE_ASSEMBLY]System.Object::.ctor()
26+
ret
27+
}
28+
29+
.method public instance void async(int32 async) cil managed async
30+
{
31+
.maxstack 8
32+
33+
ret
34+
}
35+
36+
.method public instance void runtime(int32 managed) cil managed noinlining
37+
{
38+
.maxstack 8
39+
40+
ret
41+
}
42+
43+
}

src/tests/ilasm/ilasm_tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
6565
<Link>TestFiles\%(FileName)%(Extension)</Link>
6666
</None>
67-
<None Include="MethodImplOptions/MiAggressiveOptimization.il">
67+
<None Include="MethodImplOptions/*.il">
6868
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
69-
<Link>MiAggressiveOptimization.il</Link>
69+
<Link>%(Filename).il</Link>
7070
</None>
7171
</ItemGroup>
7272
<Import Project="$(TestSourceDir)MergedTestRunner.targets" />

0 commit comments

Comments
 (0)