Skip to content

Commit 09716ec

Browse files
Initial scaffolding and partial implementation of ilasm in C# (#122112)
Co-authored-by: Copilot <[email protected]>
1 parent 6ab804e commit 09716ec

29 files changed

+8081
-0
lines changed

eng/Subsets.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@
253253
<SubsetName Include="Tools.Cdac" Description="Diagnostic data contract reader and related projects." />
254254
<SubsetName Include="Tools.ILLinkTests" OnDemand="true" Description="Unit tests for the tools.illink subset." />
255255
<SubsetName Include="Tools.CdacTests" OnDemand="true" Description="Unit tests for the diagnostic data contract reader." />
256+
<SubsetName Include="Tools.ILAsm" OnDemand="true" Description="Build only the managed ilasm tool." />
256257

257258
<!-- Host -->
258259
<SubsetName Include="Host" Description="The .NET hosts, packages, hosting libraries, and tests. Equivalent to: $(DefaultHostSubsets)" />
@@ -547,6 +548,11 @@
547548
Test="true" Category="tools"/>
548549
</ItemGroup>
549550

551+
<ItemGroup Condition="$(_subset.Contains('+tools.ilasm+'))">
552+
<ProjectToBuild Include="$(ToolsProjectRoot)ilasm\src\ILAssembler\ILAssembler.csproj" Category="tools" />
553+
<ProjectToBuild Include="$(ToolsProjectRoot)ilasm\tests\ILAssembler.Tests\ILAssembler.Tests.csproj" Category="tools" Test="true" />
554+
</ItemGroup>
555+
550556
<ItemGroup Condition="$(_subset.Contains('+clr.nativecorelib+'))">
551557
<ProjectToBuild Include="$(CoreClrProjectRoot)crossgen-corelib.proj" Category="clr" />
552558
</ItemGroup>

eng/Versions.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@
141141
<MicrosoftBuildUtilitiesCoreVersion>17.11.48</MicrosoftBuildUtilitiesCoreVersion>
142142
<DotnetSosVersion>7.0.412701</DotnetSosVersion>
143143
<DotnetSosTargetFrameworkVersion>6.0</DotnetSosTargetFrameworkVersion>
144+
<Antlr4CodeGeneratorVersion>4.6.6</Antlr4CodeGeneratorVersion>
145+
<Antlr4RuntimeVersion>4.6.6</Antlr4RuntimeVersion>
144146
<!-- Testing -->
145147
<MicrosoftNETCoreCoreDisToolsVersion>1.6.0</MicrosoftNETCoreCoreDisToolsVersion>
146148
<MicrosoftNETTestSdkVersion>17.4.0-preview-20220707-01</MicrosoftNETTestSdkVersion>

eng/pipelines/coreclr/ilasm.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pr:
88
include:
99
- src/coreclr/ilasm/*
1010
- src/coreclr/ildasm/*
11+
- src/tools/ilasm/*
1112

1213
schedules:
1314
- cron: "0 19 * * 6"
@@ -34,3 +35,20 @@ extends:
3435
- windows_x86
3536
- windows_arm64
3637
testGroup: ilasm
38+
39+
stages:
40+
- stage: Managed_ILAsm
41+
displayName: Managed IL Assembler Tests
42+
dependsOn: []
43+
jobs:
44+
- template: /eng/pipelines/common/platform-matrix.yml
45+
parameters:
46+
jobTemplate: /eng/pipelines/common/global-build-job.yml
47+
buildConfig: Debug
48+
platforms:
49+
- windows_x64
50+
jobParameters:
51+
nameSuffix: ILAsm
52+
buildArgs: -s tools.ilasm -c $(_BuildConfig) -test
53+
timeoutInMinutes: 120
54+
condition: and(succeeded(), ne(variables['Build.Reason'], 'Schedule'))

eng/pipelines/coreclr/templates/jit-outerloop-pipeline.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ parameters:
44
- name: testGroup
55
type: string
66
default: outerloop
7+
- name: stages
8+
type: stageList
9+
default: []
710

811
extends:
912
template: /eng/pipelines/common/templates/pipeline-with-resources.yml
@@ -55,3 +58,5 @@ extends:
5558
testGroup: ${{ parameters.testGroup }}
5659
liveLibrariesBuildConfig: Release
5760
unifiedArtifactsName: BuildArtifacts_$(osGroup)$(osSubgroup)_$(archType)_$(_BuildConfig)
61+
- ${{ each stage in parameters.stages }}:
62+
- ${{ stage }}

src/tools/ilasm/ilasm.slnx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<Solution>
2+
<Project Path="src/ILAssembler/ILAssembler.csproj" />
3+
<Project Path="tests/ILAssembler.Tests/ILAssembler.Tests.csproj" />
4+
</Solution>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
using System;
5+
using System.Collections.Generic;
6+
using System.Collections.Immutable;
7+
using System.Reflection.Metadata;
8+
using System.Reflection.Metadata.Ecma335;
9+
using System.Text;
10+
11+
namespace ILAssembler
12+
{
13+
internal static class BlobBuilderExtensions
14+
{
15+
public static BlobBuilder SerializeSequence<T>(this ImmutableArray<T> sequence)
16+
{
17+
BlobBuilder builder = new BlobBuilder();
18+
builder.WriteSerializedSequence(sequence);
19+
return builder;
20+
}
21+
22+
public static void WriteSerializedSequence<T>(this BlobBuilder writer, ImmutableArray<T> sequence)
23+
{
24+
foreach (T value in sequence)
25+
{
26+
WriteSerializedValue(writer, value);
27+
}
28+
}
29+
30+
public static void WriteSerializedValue<T>(this BlobBuilder writer, T value)
31+
{
32+
if (typeof(T) == typeof(bool))
33+
{
34+
writer.WriteBoolean((bool)(object)value!);
35+
}
36+
else if (typeof(T) == typeof(int))
37+
{
38+
writer.WriteInt32((int)(object)value!);
39+
}
40+
else if (typeof(T) == typeof(byte))
41+
{
42+
writer.WriteByte((byte)(object)value!);
43+
}
44+
else if (typeof(T) == typeof(char))
45+
{
46+
writer.WriteUInt16((char)(object)value!);
47+
}
48+
else if (typeof(T) == typeof(double))
49+
{
50+
writer.WriteDouble((double)(object)value!);
51+
}
52+
else if (typeof(T) == typeof(short))
53+
{
54+
writer.WriteInt16((short)(object)value!);
55+
}
56+
else if (typeof(T) == typeof(long))
57+
{
58+
writer.WriteInt64((long)(object)value!);
59+
}
60+
else if (typeof(T) == typeof(sbyte))
61+
{
62+
writer.WriteSByte((sbyte)(object)value!);
63+
}
64+
else if (typeof(T) == typeof(float))
65+
{
66+
writer.WriteSingle((float)(object)value!);
67+
}
68+
else if (typeof(T) == typeof(ushort))
69+
{
70+
writer.WriteUInt16((ushort)(object)value!);
71+
}
72+
else if (typeof(T) == typeof(uint))
73+
{
74+
writer.WriteUInt32((uint)(object)value!);
75+
}
76+
else if (typeof(T) == typeof(ulong))
77+
{
78+
writer.WriteUInt64((ulong)(object)value!);
79+
}
80+
else if (typeof(T) == typeof(string))
81+
{
82+
writer.WriteSerializedString((string?)(object?)value);
83+
}
84+
}
85+
86+
public static void WriteTypeEntity(this BlobBuilder builder, EntityRegistry.TypeEntity entity)
87+
{
88+
if (entity is EntityRegistry.FakeTypeEntity fakeEntity)
89+
{
90+
builder.WriteCompressedInteger(CodedIndex.TypeDefOrRefOrSpec(fakeEntity.TypeSignatureHandle));
91+
}
92+
else
93+
{
94+
builder.WriteCompressedInteger(CodedIndex.TypeDefOrRefOrSpec(entity.Handle));
95+
}
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)