blob: e4be79fc19efb3aa99c508639319de3879b58173 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
namespace ILCompiler
{
/// <summary>
/// A root provider that provides a runtime configuration blob that influences runtime behaviors.
/// See RhConfigValues.h for allowed values.
/// </summary>
public class RuntimeConfigurationRootProvider : ICompilationRootProvider
{
private readonly IEnumerable<string> _runtimeOptions;
public RuntimeConfigurationRootProvider(IEnumerable<string> runtimeOptions)
{
_runtimeOptions = runtimeOptions;
}
void ICompilationRootProvider.AddCompilationRoots(IRootingServiceProvider rootProvider)
{
rootProvider.RootReadOnlyDataBlob(GetRuntimeOptionsBlob(), 4, "Runtime configuration information", "g_compilerEmbeddedSettingsBlob");
}
protected byte[] GetRuntimeOptionsBlob()
{
const int HeaderSize = 4;
ArrayBuilder<byte> options = new ArrayBuilder<byte>();
// Reserve space for the header
options.ZeroExtend(HeaderSize);
foreach (string option in _runtimeOptions)
{
byte[] optionBytes = System.Text.Encoding.ASCII.GetBytes(option);
options.Append(optionBytes);
// Emit a null to separate the next option
options.Add(0);
}
byte[] result = options.ToArray();
int length = options.Count - HeaderSize;
// Encode the size of the blob into the header
result[0] = (byte)length;
result[1] = (byte)(length >> 8);
result[2] = (byte)(length >> 0x10);
result[3] = (byte)(length >> 0x18);
return result;
}
}
}
|