Skip to content

Add support for full assembly emit #14

Description

@SeeminglyScience

Here's a rough draft of how that would look:

using namespace System
using namespace System.IO
using namespace System.Reflection
using namespace System.Runtime.CompilerServices
using namespace System.Text

emitil -OutputPath ./bin {
    # All type resolution will be done by PowerShell, so referencing [StringBuilder] would
    # be encoded as [StringBuilder, System.Private.CoreLib] instead of [StringBuilder, netstandard].
    # `.bindforwards` would map any type forwards in the target assembly as the assembly to
    # encode against.
    .bindforwards netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51

    .module Example.IL.dll
    .imagebase 0x00400000
    .file alignment 0x00000200
    .stackreserve 0x00100000
    .subsystem 0x0003
    .corflags 0x00000001

    .assembly 'Example.IL' {
        # 8
        .custom { [void] [CompilationRelaxationsAttribute].new([int]) } = {
            0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00
        }

        # WrapNonExceptionThrows = true
        .custom { [void] [RuntimeCompatibilityAttribute].new() } = {
            0x01, 0x00, 0x01, 0x00, 0x54, 0x02, 0x16, 0x57, 0x72, 0x61, 0x70, 0x4E, 0x6F, 0x6E, 0x45, 0x78,
            0x63, 0x65, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x54, 0x68, 0x72, 0x6F, 0x77, 0x73, 0x01
        }

        # 1.0.0.0
        .custom { [void] [AssemblyFileVersionAttribute].new([string]) } = {
            0x01, 0x00, 0x07, 0x31, 0x2E, 0x30, 0x2E, 0x30, 0x2E, 0x30, 0x00, 0x00
        }

        # 1.0.0.0
        .custom { [void] [AssemblyInformationalVersionAttribute].new([string]) } = {
            0x01, 0x00, 0x07, 0x31, 0x2E, 0x30, 0x2E, 0x30, 0x2E, 0x30, 0x00, 0x00
        }

        # false
        .custom { [void] [CLSCompliantAttribute].new([bool]) } = { 0x01, 0x00, 0x00, 0x00, 0x00 }

        .hash algorithm 0x0000800c
        .ver 1:0:0:0
    }

    .namespace Example.IL {
        # Basically Vector128
        .class { [UnmanagedStruct] } extends { [ValueType] } {
            # In ilasm these would be in the line above but this would be easier to parse and
            # more readable imo.
            .attr { public sequential ansi sealed beforefieldinit }

            .field private initonly { [long] $_field1 }

            .field private initonly { [long] $_field2 }

            .method { [void] $this.new([long] $field1, [long] $field2) } {
                .attr { public hidebysig specialname rtspecialname cil managed }
                .maxstack 8

                ldarg.auto $this
                ldarg.auto $field1
                stfld { [long] [UnmanagedStruct]._field1 }

                ldarg.auto $this
                ldarg.auto $field2
                stfld { [long] [UnmanagedStruct]._field2 }

                ret
            }
        }

        .class { [StaticOpsMethods] } extends { [object] } {
            .attr { public auto ansi sealed abstract beforefieldinit }

            .method { [int] $this.Calli([pointer[int]] $this, [pointer[int]] $vtableSlot, [int] $arg) } {
                .attr { public hidebysig static cil managed aggressiveinlining }
                .maxstack 8

                ldarg.auto $this
                ldarg.auto $arg
                ldarg.auto $vtableSlot
                calli unmanaged stdcall { [int] $_::_([pointer[void]], [int]) }
                ret
            }
        }

        .class { [CustomWriter] } extends { [TextWriter] } {
            .attr { public auto ansi beforefieldinit }

            .property { [Encoding] $this.Encoding } {
                .get { [Encoding] $this.get_Encoding() }
            }

            # Maybe allow public/virtual/hidebysig/etc in both places.
            .method public virtual { [Encoding] $this.get_Encoding() } {
                .attr { hidebysig specialname }
                .maxstack 8

                .newobj { [void] [NotImplementedException].new() }
                throw
            }

            .method { [void] $this.new() } {
                .attr { public hidebysig specialname rtspecialname }
                .maxstack 8

                ldarg.0
                call { [void] [TextWriter].new() }
                ret
            }
        }
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions