Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

Commit 12dd347

Browse files
authored
Merge pull request #4480 from morganbr/NetscriptenPR
Experimental WebAssembly support
2 parents 61745f5 + 699b5a0 commit 12dd347

34 files changed

Lines changed: 3277 additions & 125 deletions

src/BuildIntegration/Microsoft.NETCore.Native.Unix.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ See the LICENSE file in the project root for more information.
3636
<NativeLibrary Condition="$(NativeCodeGen) == ''" Include="$(IlcPath)/sdk/libRuntime.a" />
3737
<NativeLibrary Condition="$(NativeCodeGen) == 'cpp'" Include="$(IlcPath)/sdk/libbootstrappercpp.a" />
3838
<NativeLibrary Condition="$(NativeCodeGen) == 'cpp'" Include="$(IlcPath)/sdk/libPortableRuntime.a" />
39+
<NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)/sdk/libbootstrappercpp.a" />
40+
<NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)/sdk/libPortableRuntime.a" />
3941
</ItemGroup>
4042

4143
<ItemGroup>

src/BuildIntegration/Microsoft.NETCore.Native.Windows.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ See the LICENSE file in the project root for more information.
3636
<NativeLibrary Condition="$(NativeCodeGen) == ''" Include="$(IlcPath)\sdk\Runtime.lib" />
3737
<NativeLibrary Condition="$(NativeCodeGen) == 'cpp'" Include="$(IlcPath)\sdk\bootstrappercpp.lib" />
3838
<NativeLibrary Condition="$(NativeCodeGen) == 'cpp'" Include="$(IlcPath)\sdk\PortableRuntime.lib" />
39+
<NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)\sdk\bootstrappercpp.lib" />
40+
<NativeLibrary Condition="$(NativeCodeGen) == 'wasm'" Include="$(IlcPath)\sdk\PortableRuntime.lib" />
3941
<NativeLibrary Condition="'$(IlcMultiModule)' == 'true' and $(NativeCodeGen) == ''" Include="$(SharedLibrary)" />
4042
</ItemGroup>
4143

src/BuildIntegration/Microsoft.NETCore.Native.targets

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,31 @@ See the LICENSE file in the project root for more information.
2727
<PropertyGroup>
2828
<NativeObjectExt Condition="'$(TargetOS)' == 'Windows_NT'">.obj</NativeObjectExt>
2929
<NativeObjectExt Condition="'$(TargetOS)' != 'Windows_NT'">.o</NativeObjectExt>
30+
<NativeObjectExt Condition="'$(NativeCodeGen)' == 'wasm'">.bc</NativeObjectExt>
3031
<LibFileExt Condition="'$(TargetOS)' == 'Windows_NT'">.lib</LibFileExt>
3132
<LibFileExt Condition="'$(TargetOS)' != 'Windows_NT'">.a</LibFileExt>
3233

3334
<IlcOutputFileExt>$(NativeObjectExt)</IlcOutputFileExt>
3435
<IlcOutputFileExt Condition="$(NativeCodeGen) == 'cpp'">.cpp</IlcOutputFileExt>
36+
<IlcOutputFileExt Condition="'$(NativeCodeGen)' == 'wasm'">.bc</IlcOutputFileExt>
3537

3638

3739
<NativeBinaryExt Condition="'$(OutputType)' == 'Exe' and '$(TargetOS)' == 'Windows_NT'">.exe</NativeBinaryExt>
3840
<NativeBinaryExt Condition="'$(OutputType)' == 'Exe' and '$(TargetOS)' != 'Windows_NT'"></NativeBinaryExt>
3941
<NativeBinaryExt Condition="'$(OutputType)' != 'Exe' and '$(TargetOS)' == 'Windows_NT'">.dll</NativeBinaryExt>
4042
<NativeBinaryExt Condition="'$(OutputType)' != 'Exe' and '$(TargetOS)' == 'OSX'">.dylib</NativeBinaryExt>
4143
<NativeBinaryExt Condition="'$(OutputType)' != 'Exe' and '$(TargetOS)' != 'Windows_NT' and '$(TargetOS)' != 'OSX'">.so</NativeBinaryExt>
44+
<NativeBinaryExt Condition="'$(NativeCodeGen)' == 'wasm'">.html</NativeBinaryExt>
4245

4346
<NativeObject>$(NativeIntermediateOutputPath)$(TargetName)$(NativeObjectExt)</NativeObject>
4447
<NativeBinary>$(NativeOutputPath)$(TargetName)$(NativeBinaryExt)</NativeBinary>
4548

4649
<IlcCompileOutput Condition="$(NativeCodeGen) == ''">$(NativeObject)</IlcCompileOutput>
4750
<IlcCompileOutput Condition="$(NativeCodeGen) == 'cpp'">$(NativeIntermediateOutputPath)$(TargetName).cpp</IlcCompileOutput>
51+
4852
<LinkNativeDependsOn Condition="$(NativeCodeGen) == ''">IlcCompile</LinkNativeDependsOn>
4953
<LinkNativeDependsOn Condition="$(NativeCodeGen) == 'cpp'">CppCompile</LinkNativeDependsOn>
54+
<LinkNativeDependsOn Condition="$(NativeCodeGen) == 'wasm'">IlcCompile</LinkNativeDependsOn>
5055

5156
<FrameworkLibPath Condition="'$(FrameworkLibPath)' == ''">$(NativeOutputPath)</FrameworkLibPath>
5257
<FrameworkObjPath Condition="'$(FrameworkObjPath)' == ''">$(NativeIntermediateOutputPath)</FrameworkObjPath>
@@ -131,7 +136,7 @@ See the LICENSE file in the project root for more information.
131136
<WriteLinesToFile File="$(NativeIntermediateOutputPath)cl.rsp" Lines="@(CompilerArg)" Overwrite="true" Condition="'$(OS)' == 'Windows_NT'"/>
132137
<Exec Command="$(CppCompiler) @&quot;$(NativeIntermediateOutputPath)cl.rsp&quot;" Condition="'$(OS)' == 'Windows_NT'" />
133138
</Target>
134-
139+
135140
<Target Name="LinkNative"
136141
Inputs="$(NativeObject);@(NativeLibrary)"
137142
Outputs="$(NativeBinary)"
@@ -147,7 +152,10 @@ See the LICENSE file in the project root for more information.
147152
<MakeDir Directories="$([System.IO.Path]::GetDirectoryName($(NativeBinary)))" />
148153
<Exec Command="$(CppLinker) @(CustomLinkerArg, ' ')" Condition="'$(OS)' != 'Windows_NT'" />
149154
<WriteLinesToFile File="$(NativeIntermediateOutputPath)link.rsp" Lines="@(CustomLinkerArg)" Overwrite="true" Condition="'$(OS)' == 'Windows_NT'" />
150-
<Exec Command="$(CppLinker) @&quot;$(NativeIntermediateOutputPath)link.rsp&quot;" Condition="'$(OS)' == 'Windows_NT'" />
155+
<Exec Command="$(CppLinker) @&quot;$(NativeIntermediateOutputPath)link.rsp&quot;" Condition="'$(OS)' == 'Windows_NT' and '$(NativeCodeGen)' != 'wasm'" />
156+
<Exec Command="&quot;$(EMSCRIPTEN)\emcc.bat&quot; &quot;$(NativeObject)&quot; -o &quot;$(NativeBinary)&quot; -s WASM=1" Condition="'$(NativeCodeGen)' == 'wasm' and '$(EMSCRIPTEN)' != ''" />
157+
<Message Text="Emscripten not found, not linking WebAssembly. To enable WebAssembly linking, install Emscripten and ensure the EMSCRIPTEN environment variable points to the directory containing emcc.bat"
158+
Condition="'$(NativeCodeGen)' == 'wasm' and '$(EMSCRIPTEN)' == ''" />
151159
</Target>
152160

153161
<Target Name="CreateLib"

src/Common/src/TypeSystem/Common/TargetDetails.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public enum TargetArchitecture
1818
ARM64,
1919
X64,
2020
X86,
21+
Wasm32
2122
}
2223

2324
/// <summary>
@@ -92,6 +93,7 @@ public int PointerSize
9293
case TargetArchitecture.ARM:
9394
case TargetArchitecture.ARMEL:
9495
case TargetArchitecture.X86:
96+
case TargetArchitecture.Wasm32:
9597
return 4;
9698
default:
9799
throw new NotSupportedException();
@@ -201,6 +203,7 @@ public LayoutInt GetObjectAlignment(LayoutInt fieldAlignment)
201203
{
202204
case TargetArchitecture.ARM:
203205
case TargetArchitecture.ARMEL:
206+
case TargetArchitecture.Wasm32:
204207
// ARM supports two alignments for objects on the GC heap (4 byte and 8 byte)
205208
if (fieldAlignment.IsIndeterminate)
206209
return LayoutInt.Indeterminate;

src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/ArrayOfEmbeddedDataNode.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@
1111

1212
namespace ILCompiler.DependencyAnalysis
1313
{
14+
public interface IHasStartSymbol
15+
{
16+
ObjectAndOffsetSymbolNode StartSymbol { get; }
17+
}
18+
1419
/// <summary>
1520
/// Represents an array of <typeparamref name="TEmbedded"/> nodes. The contents of this node will be emitted
1621
/// by placing a starting symbol, followed by contents of <typeparamref name="TEmbedded"/> nodes (optionally
1722
/// sorted using provided comparer), followed by ending symbol.
1823
/// </summary>
19-
public class ArrayOfEmbeddedDataNode<TEmbedded> : ObjectNode
24+
public class ArrayOfEmbeddedDataNode<TEmbedded> : ObjectNode, IHasStartSymbol
2025
where TEmbedded : EmbeddedObjectNode
2126
{
2227
private HashSet<TEmbedded> _nestedNodes = new HashSet<TEmbedded>();
@@ -43,6 +48,7 @@ public void AddEmbeddedObject(TEmbedded symbol)
4348
{
4449
_nestedNodesList.Add(symbol);
4550
}
51+
symbol.ContainingNode = this;
4652
}
4753
}
4854

src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/EmbeddedObjectNode.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ public abstract class EmbeddedObjectNode : DependencyNodeCore<NodeFactory>
1616

1717
private int _offset;
1818

19+
public IHasStartSymbol ContainingNode { get; set; }
20+
1921
public EmbeddedObjectNode()
2022
{
2123
_offset = InvalidOffset;
2224
}
2325

24-
protected int OffsetFromBeginningOfArray
26+
public int OffsetFromBeginningOfArray
2527
{
2628
get
2729
{

src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/IObjectDumper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace ILCompiler.DependencyAnalysis
88
{
9-
internal interface IObjectDumper
9+
public interface IObjectDumper
1010
{
1111
void DumpObjectNode(NameMangler mangler, ObjectNode node, ObjectData objectData);
1212
}

0 commit comments

Comments
 (0)