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

Code before:
        // must be stored in little-endian order
        private const uint WasmMagicNumber = 0x6d736100;

        // must be stored in little-endian order
        private const uint WasmVersion = 0x1;

        private WasmAbiContext _wasmAbiContext;

        public WasmObjectWriter(NodeFactory factory, ObjectWritingOptions options, WasmAbiContext ctx, OutputInfoBuilder outputInfoBuilder)
            : base(factory, options, outputInfoBuilder)
        {
            _wasmAbiContext = ctx;
        }

        private void EmitWasmHeader(Stream outputFileStream)
        {
            SectionData data = new();
            SectionWriter headerWriter = new(this, 0, data);
            headerWriter.WriteLittleEndian(WasmMagicNumber);
            headerWriter.WriteLittleEndian(WasmVersion);

            data.GetReadStream().CopyTo(outputFileStream);
        }

        public override void EmitObject(Stream outputFileStream, IReadOnlyCollection<DependencyNode> nodes, IObjectDumper dumper, Logger logger)
        {            
            ArrayBuilder<WasmFuncType> methodSignatures = new();
            ArrayBuilder<IMethodBodyNode> methodBodies = new();
            foreach (DependencyNode node in nodes)
            {
                if (node is not ObjectNode)
                {
                    continue;
                }

                if (node is IMethodBodyNode methodNode)
                {
                    methodSignatures.Add(_wasmAbiContext.GetSignature(methodNode.Method));
                    methodBodies.Add(methodNode);
                    // TODO: record relocations and attached data
                }
            }

            Dictionary<WasmFuncType, int> signatureMap = new();
            int signatureIndex = 0;
            for (int i = 0; i < methodSignatures.Count; i++)
            {
                if (!signatureMap.ContainsKey(methodSignatures[i]))
                {
                    signatureMap[methodSignatures[i]] = signatureIndex++;
                }

Review comment (suggestion):
Line 104 contains trailing whitespace after the opening brace, which should be removed.
```suggestion
        {
```

Code after:
            writer.WriteULEB128((ulong)methodNodes.Count);
            for (int i = 0; i < methodNodes.Count; i++)
            {
                ObjectData methodNode = methodNodes[i];
                WasmFuncType methodSignature = methodSignatures[i];
                string exportName = methodNames[i];

                int length = Encoding.UTF8.GetByteCount(exportName);
                writer.WriteULEB128((ulong)length);
                writer.WriteUtf8StringNoNull(exportName);
                writer.WriteByte(0x00); // export kind: function
                writer.WriteULEB128((ulong)i);
                if (logger.IsVerbose)
                {
                    logger.LogMessage($"Emitting export: {exportName} for function index {i}");
                }
            }

            return exportSection;
        }

        private WasmSection WriteCodeSection(ArrayBuilder<ObjectData> methodBodies, Logger logger)
        {
            WasmSection codeSection = new WasmSection(WasmSectionType.Code, new SectionData(), "code");
            SectionWriter writer = codeSection.Writer;

            // Write the number of functions
            writer.WriteULEB128((ulong)methodBodies.Count);
            for (int i = 0; i < methodBodies.Count; i++)
            {
                ObjectData methodBody = methodBodies[i];
                writer.WriteULEB128((ulong)methodBody.Data.Length);
                writer.EmitData(methodBody.Data);
            }

            return codeSection;
        }

        private WasmSection WriteTypeSection(IEnumerable<WasmFuncType> functionSignatures, Logger logger)
        {
            SectionData sectionData = new();
            WasmSection typeSection = new WasmSection(WasmSectionType.Type, sectionData, "type");
            SectionWriter writer = typeSection.Writer;

            // Write the number of types
            writer.WriteULEB128((ulong)functionSignatures.Count());

            IBufferWriter<byte> buffer = sectionData.BufferWriter;
            foreach (WasmFuncType signature in functionSignatures)
            {
                if (logger.IsVerbose)