Repository: dotnet/runtime
File: src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs (C#)

Code before:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using ILCompiler.DependencyAnalysis;
using ILCompiler.DependencyAnalysisFramework;
using Internal.TypeSystem;

namespace ILCompiler.ObjectWriter
{
    // This is a placeholder for now. It will need to be filled in with ABI-specific signatures
    // for any method we want to emit into the Wasm module.
    public class WasmAbiContext
    {
        private Dictionary<MethodDesc, WasmFuncType> _methodSignatureMap = new();
        public WasmFuncType GetSignature(MethodDesc method)
        {
            return DummyValues.CreateWasmFunc_i32_i32();
        }
    }

    internal class WasmSection
    {
        public WasmSectionType Type { get; }
        public string Name { get; }
        public SectionData Data => _data;
        private SectionWriter? _writer;

        private SectionData _data;

        public Span<byte> Header
        {
            get
            {
                // Section header consists of:
                // 1 byte: section type
                // ULEB128: size of section
                ulong sectionSize = (ulong)_data.Length;
                var encodeLength = DwarfHelper.SizeOfULEB128(sectionSize);

                Span<byte> header = new byte[1+encodeLength];
                header[0] = (byte)Type;
                DwarfHelper.WriteULEB128(header.Slice(1), sectionSize);

Review comment (suggestion):
I think `Dummy` might not pass policheck but I'm not an expert on that and I don't know offhand what a better term would be. `PlaceholderValues` maybe.

Code after:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using ILCompiler.DependencyAnalysis;
using ILCompiler.DependencyAnalysis.ReadyToRun;
using ILCompiler.DependencyAnalysisFramework;
using Internal.Text;
using Internal.TypeSystem;

using ObjectData = ILCompiler.DependencyAnalysis.ObjectNode.ObjectData;

namespace ILCompiler.ObjectWriter
{
    /// <summary>
    /// Wasm object file format writer.
    /// </summary>
    internal sealed class WasmObjectWriter : ObjectWriter
    {
        public WasmObjectWriter(NodeFactory factory, ObjectWritingOptions options, OutputInfoBuilder outputInfoBuilder)
            : base(factory, options, outputInfoBuilder)
        {
        }

        private void EmitWasmHeader(Stream outputFileStream)
        {
            outputFileStream.Write("\0asm"u8);
            outputFileStream.Write([0x1, 0x0, 0x0, 0x0]);
        }

        // TODO: for now, we are fully overriding EmitObject. As we support more features, we should
        // see if we can re-use the base, or refactor the base method to allow for code sharing.
        public override void EmitObject(Stream outputFileStream, IReadOnlyCollection<DependencyNode> nodes, IObjectDumper dumper, Logger logger)
        {
            ArrayBuilder<WasmFuncType> methodSignatures = new();
            ArrayBuilder<string> methodNames = new();
            ArrayBuilder<ObjectData> methodBodies = new();
            foreach (DependencyNode node in nodes)
            {
                if (node is not ObjectNode)
                {