2017-10-19 20:04:20 +00:00
|
|
|
using System;
|
2018-04-24 09:31:23 +00:00
|
|
|
using System.Collections.Generic;
|
2017-10-19 20:04:20 +00:00
|
|
|
|
|
|
|
using Mono.Linker;
|
|
|
|
using Mono.Linker.Steps;
|
|
|
|
using Mono.Cecil;
|
|
|
|
|
|
|
|
namespace ILLink.CustomSteps
|
|
|
|
{
|
|
|
|
public class ClearInitLocalsStep : BaseStep
|
|
|
|
{
|
2018-04-24 09:31:23 +00:00
|
|
|
HashSet<string> _assemblies;
|
|
|
|
|
|
|
|
protected override void Process ()
|
|
|
|
{
|
|
|
|
string parameterName = "ClearInitLocalsAssemblies";
|
|
|
|
|
|
|
|
if (Context.HasParameter (parameterName)) {
|
|
|
|
string parameter = Context.GetParameter (parameterName);
|
|
|
|
_assemblies = new HashSet<string> (parameter.Split(','), StringComparer.OrdinalIgnoreCase);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void ProcessAssembly (AssemblyDefinition assembly)
|
2017-10-19 20:04:20 +00:00
|
|
|
{
|
2018-04-24 09:31:23 +00:00
|
|
|
if ((_assemblies != null) && (!_assemblies.Contains (assembly.Name.Name))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool changed = false;
|
|
|
|
|
2017-10-19 20:04:20 +00:00
|
|
|
foreach (ModuleDefinition module in assembly.Modules) {
|
|
|
|
foreach (TypeDefinition type in module.Types) {
|
|
|
|
foreach (MethodDefinition method in type.Methods) {
|
|
|
|
if (method.Body != null) {
|
2018-04-24 09:31:23 +00:00
|
|
|
if (method.Body.InitLocals) {
|
|
|
|
method.Body.InitLocals = false;
|
|
|
|
changed = true;
|
|
|
|
}
|
2017-10-19 20:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-24 09:31:23 +00:00
|
|
|
|
|
|
|
if (changed && (Annotations.GetAction (assembly) == AssemblyAction.Copy))
|
|
|
|
Annotations.SetAction (assembly, AssemblyAction.Save);
|
2017-10-19 20:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|