Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source/MetadataProcessor.Core/DumpGenerator/DumpAllTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class DumpAllTable
public List<AssemblyRef> AssemblyReferences = new List<AssemblyRef>();
public List<TypeRef> TypeReferences = new List<TypeRef>();
public List<TypeDef> TypeDefinitions = new List<TypeDef>();
public List<MethodDef> MethodDefinitions = new List<MethodDef>();
public List<InterfaceDef> InterfaceDefinitions = new List<InterfaceDef>();
public List<AttributeCustom> Attributes = new List<AttributeCustom>();
public List<UserString> UserStrings = new List<UserString>();
}
Expand Down
88 changes: 47 additions & 41 deletions source/MetadataProcessor.Core/DumpGenerator/DumpTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,58 @@ namespace nanoFramework.Tools.MetadataProcessor
{
internal partial class DumpTemplates
{
internal static string DumpAllTemplate =
@"{{#AssemblyReferences}}
AssemblyRefProps [{{ReferenceId}}]: Flags: {{Flags}} '{{Name}}'
{{/AssemblyReferences}}
internal const string DumpAllTemplate =
@"{{#each AssemblyReferences}}
AssemblyRefProps [{{ReferenceId}}]: Flags: {{Flags}} '{{Name}}'{{#newline}}
{{/each}}
{{#if AssemblyReferences}}{{#newline}}{{/if}}

{{#TypeReferences}}
TypeRefProps [{{ReferenceId}}]: Scope: {{Scope}} '{{Name}}'
{{#MemberReferences}}
MemberRefProps [{{ReferenceId}}]: '{{Name}}' [{{Signature}}]
{{/MemberReferences}}
{{/TypeReferences}}
{{#each TypeReferences}}
TypeRefProps [{{ReferenceId}}]: Scope: {{Scope}} '{{Name}}'{{#newline}}
{{#each MemberReferences}}
MemberRefProps [{{ReferenceId}}]: '{{Name}}' [{{Signature}}]{{#newline}}
{{/each}}
{{#newline}}
{{/each}}
{{#if TypeReferences}}{{#newline}}{{/if}}

{{#TypeDefinitions}}
TypeDefProps [{{ReferenceId}}]: Flags: {{Flags}} Extends: {{ExtendsType}} Enclosed: {{EnclosedType}} '{{Name}}'
{{#FieldDefinitions}}
FieldDefProps [{{ReferenceId}}]: Attr: {{Attributes}} Flags: {{Flags}} '{{Name}}' [{{Signature}}]
{{/FieldDefinitions}}
{{#MethodDefinitions}}
MethodDefProps [{{ReferenceId}}]: Flags: {{Flags}} Impl: {{Implementation}} RVA: {{RVA}} '{{Name}}' [{{Signature}}]
{{#Locals}}
Locals {{Locals}}
{{/Locals}}
{{#ExceptionHandlers}}
EH: {{ExceptionHandler}}
{{/ExceptionHandlers}}
{{#ILCodeInstructionsCount}}
IL count: {{ILCodeInstructionsCount}}
{{/ILCodeInstructionsCount}}
{{#ILCode}}
{{IL}}
{{/ILCode}}
{{/MethodDefinitions}}
{{#InterfaceDefinitions}}
InterfaceImplProps [{{ReferenceId}}]: Itf: {{Interface}}
{{/InterfaceDefinitions}}
{{#each TypeDefinitions}}
TypeDefProps [{{ReferenceId}}]: Flags: {{Flags}} Extends: {{ExtendsType}} Enclosed: {{EnclosedType}} '{{Name}}'{{#newline}}
{{#each FieldDefinitions}}
FieldDefProps [{{ReferenceId}}]: Attr: {{Attributes}} Flags: {{Flags}} '{{Name}}' [{{Signature}}]{{#newline}}
{{/each}}

{{/TypeDefinitions}}
{{#each MethodDefinitions}}
MethodDefProps [{{ReferenceId}}]: Flags: {{Flags}} Impl: {{Implementation}} RVA: {{RVA}} '{{Name}}' [{{Signature}}]{{#newline}}
{{#if Locals}}
Locals {{Locals}}{{#newline}}
{{/if}}
{{#each ExceptionHandlers}}
EH: {{Handler}}{{#newline}}
{{/each}}
{{#if ILCodeInstructionsCount}}
IL count: {{ILCodeInstructionsCount}}{{#newline}}
{{/if}}
{{#each ILCode}}
{{IL}}{{#newline}}
{{/each}}
{{/each}}

{{#Attributes}}
Attribute: {{Name}}::[{{ReferenceId}} {{TypeToken}}]
{{/Attributes}}
{{#each InterfaceDefinitions}}
InterfaceImplProps [{{ReferenceId}}]: Itf: {{Interface}}{{#newline}}
{{/each}}
{{#if InterfaceDefinitions}}{{#newline}}{{/if}}
{{#newline}}
{{/each}}

{{#UserStrings}}
UserString [{{ReferenceId}}]: '{{Content}}'
{{/UserStrings}}
";
{{#each Attributes}}
Attribute: {{Name}}::[{{ReferenceId}} {{TypeToken}}]{{#newline}}
{{/each}}
{{#if Attributes}}{{#newline}}{{/if}}

{{#each UserStrings}}
UserString [{{ReferenceId}}]: '{{Content}}'{{#newline}}
{{/each}}
";
}
}
18 changes: 2 additions & 16 deletions source/MetadataProcessor.Core/MetadataProcessor.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,12 @@
<Reference Include="Mono.Cecil.Rocks, Version=0.11.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.1\lib\net40\Mono.Cecil.Rocks.dll</HintPath>
</Reference>
<Reference Include="Stubble.Core, Version=1.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Stubble.Core.1.6.3\lib\net45\Stubble.Core.dll</HintPath>
<Reference Include="mustache-sharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5885df51f4df0041, processorArchitecture=MSIL">
<HintPath>..\packages\mustache-sharp.1.0.0\lib\net45\mustache-sharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
Expand Down Expand Up @@ -147,7 +135,5 @@
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.0.50\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.0.50\build\Nerdbank.GitVersioning.targets'))" />
<Error Condition="!Exists('..\packages\StrongNamer.0.2.5\build\StrongNamer.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\StrongNamer.0.2.5\build\StrongNamer.targets'))" />
</Target>
<Import Project="..\packages\StrongNamer.0.2.5\build\StrongNamer.targets" Condition="Exists('..\packages\StrongNamer.0.2.5\build\StrongNamer.targets')" />
</Project>
147 changes: 76 additions & 71 deletions source/MetadataProcessor.Core/SkeletonGenerator/SkeletonTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,84 @@ namespace nanoFramework.Tools.MetadataProcessor
{
internal partial class SkeletonTemplates
{
internal static string AssemblyHeaderTemplate =
@"//-----------------------------------------------------------------------------
//
// ** WARNING! **
// This file was generated automatically by a tool.
// Re-running the tool will overwrite this file.
// You should copy this file to a custom location
// before adding any customization in the copy to
// prevent loss of your changes when the tool is
// re-run.
//
//-----------------------------------------------------------------------------

#ifndef _{{ShortNameUpper}}_H_
#define _{{ShortNameUpper}}_H_

#include <nanoCLR_Interop.h>
#include <nanoCLR_Runtime.h>
#include <corlib_native.h>

{{#Classes}}
struct Library_{{AssemblyName}}_{{Name}}
{
{{#StaticFields}}
static const int FIELD_STATIC__{{Name}} = {{ReferenceIndex}};
{{/StaticFields}}

{{#InstanceFields}}
{{#FieldWarning}}
{{FieldWarning}}
{{/FieldWarning}}
static const int FIELD__{{Name}} = {{ReferenceIndex}};
{{/InstanceFields}}

{{#Methods}}
NANOCLR_NATIVE_DECLARE({{Declaration}});
{{/Methods}}

//--//

};

{{/Classes}}
extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_{{Name}};

#endif //_{{ShortNameUpper}}_H_
internal const string AssemblyHeaderTemplate =
@"//-----------------------------------------------------------------------------{{#newline}}
//{{#newline}}
// ** WARNING! ** {{#newline}}
// This file was generated automatically by a tool.{{#newline}}
// Re-running the tool will overwrite this file.{{#newline}}
// You should copy this file to a custom location{{#newline}}
// before adding any customization in the copy to{{#newline}}
// prevent loss of your changes when the tool is{{#newline}}
// re-run.{{#newline}}
//{{#newline}}
//-----------------------------------------------------------------------------{{#newline}}
{{#newline}}

#ifndef _{{ShortNameUpper}}_H_{{#newline}}
#define _{{ShortNameUpper}}_H_{{#newline}}
{{#newline}}

#include <nanoCLR_Interop.h>{{#newline}}
#include <nanoCLR_Runtime.h>{{#newline}}
#include <corlib_native.h>{{#newline}}
{{#newline}}

{{#each Classes}}
struct Library_{{AssemblyName}}_{{Name}}{{#newline}}
{{{#newline}}

{{#each StaticFields}}
static const int FIELD_STATIC__{{Name}} = {{ReferenceIndex}};{{#newline}}
{{/each}}
{{#if StaticFields}}{{#newline}}{{/if}}

{{#each InstanceFields}}
{{#if FieldWarning}}{{FieldWarning}}{{/if}}
static const int FIELD__{{Name}} = {{ReferenceIndex}};{{#newline}}
{{/each}}
{{#if InstanceFields}}{{#newline}}{{/if}}

{{#each Methods}}
NANOCLR_NATIVE_DECLARE({{Declaration}});{{#newline}}
{{/each}}
{{#if Methods}}{{#newline}}{{/if}}

//--//{{#newline}}
{{#newline}}
};{{#newline}}
{{#newline}}
{{/each}}
extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_{{Name}};{{#newline}}
{{#newline}}
#endif //_{{ShortNameUpper}}_H_{{#newline}}
";

internal static string AssemblyLookupTemplate =
@"#include ""{{HeaderFileName}}.h""

static const CLR_RT_MethodHandler method_lookup[] =
{
{{#LookupTable}}
{{Declaration}},
{{/LookupTable}}
};

const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_{{AssemblyName}} =
{
""{{Name}}"",
{{NativeCRC32}},
method_lookup,
////////////////////////////////////////////////////////////////////////////////////
// check if the version bellow matches the one in AssemblyNativeVersion attribute //
////////////////////////////////////////////////////////////////////////////////////
{ {{NativeVersion.Major}}, {{NativeVersion.Minor}}, {{NativeVersion.Build}}, {{NativeVersion.Revision}} }
};
internal const string AssemblyLookupTemplate =
@"#include ""{{HeaderFileName}}.h""{{#newline}}
{{#newline}}

static const CLR_RT_MethodHandler method_lookup[] ={{#newline}}
{{{#newline}}
{{#each LookupTable}}
{{Declaration}},{{#newline}}
{{/each}}
};{{#newline}}
{{#newline}}

const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_{{AssemblyName}} ={{#newline}}
{{{#newline}}
""{{Name}}"",{{#newline}}
{{NativeCRC32}},{{#newline}}
method_lookup,{{#newline}}
////////////////////////////////////////////////////////////////////////////////////{{#newline}}
// check if the version bellow matches the one in AssemblyNativeVersion attribute //{{#newline}}
////////////////////////////////////////////////////////////////////////////////////{{#newline}}
{ {{NativeVersion.Major}}, {{NativeVersion.Minor}}, {{NativeVersion.Build}}, {{NativeVersion.Revision}} }{{#newline}}
};{{#newline}}
";

internal static string ClassStubTemplate =
internal const string ClassStubTemplate =
@"//-----------------------------------------------------------------------------
//
// ** WARNING! **
Expand All @@ -92,7 +99,7 @@ struct Library_{{AssemblyName}}_{{Name}}

#include ""{{HeaderFileName}}.h""

{{#Functions}}
{{#each Functions}}
HRESULT {{Declaration}}( CLR_RT_StackFrame& stack )
{
NANOCLR_HEADER();
Expand All @@ -101,8 +108,6 @@ struct Library_{{AssemblyName}}_{{Name}}

NANOCLR_NOCLEANUP();
}

{{/Functions}}
";
{{/each}}";
}
}
1 change: 0 additions & 1 deletion source/MetadataProcessor.Core/nanoDependencyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

using Mono.Cecil;
using nanoFramework.Tools.MetadataProcessor.Core.Extensions;
using Stubble.Core.Builders;
using System;
using System.IO;
using System.Linq;
Expand Down
8 changes: 5 additions & 3 deletions source/MetadataProcessor.Core/nanoDumperGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using Mustache;
using nanoFramework.Tools.MetadataProcessor.Core.Extensions;
using Stubble.Core.Builders;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -45,11 +45,13 @@ public void DumpAll()
DumpCustomAttributes(dumpTable);
DumpUserStrings(dumpTable);

var stubble = new StubbleBuilder().Build();

FormatCompiler compiler = new FormatCompiler();
Generator generator = compiler.Compile(DumpTemplates.DumpAllTemplate);

using (var dumpFile = File.CreateText(_path))
{
var output = stubble.Render(DumpTemplates.DumpAllTemplate, dumpTable);
var output = generator.Render(dumpTable);
dumpFile.Write(output);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="$(OutDir)Stubble.Core.dll">
<InstallRoot>MSBuild</InstallRoot>
<VSIXSubPath>nanoFramework\v1.0\</VSIXSubPath>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="$(OutDir)System.Collections.Immutable.dll">
<InstallRoot>MSBuild</InstallRoot>
<VSIXSubPath>nanoFramework\v1.0\</VSIXSubPath>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="$(OutDir)System.Runtime.CompilerServices.Unsafe.dll">
<InstallRoot>MSBuild</InstallRoot>
<VSIXSubPath>nanoFramework\v1.0\</VSIXSubPath>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="$(OutDir)System.Threading.Tasks.Extensions.dll">
<Content Include="$(OutDir)mustache-sharp.dll">
<InstallRoot>MSBuild</InstallRoot>
<VSIXSubPath>nanoFramework\v1.0\</VSIXSubPath>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
Loading