Exemple #1
0
 /// <summary>
 /// Writes this exported value to the given WebAssembly file writer.
 /// </summary>
 /// <param name="Writer">The WebAssembly file writer.</param>
 public void WriteTo(BinaryWasmWriter Writer)
 {
     Writer.WriteVarUInt32(MemoryIndex);
     Offset.WriteTo(Writer);
     Writer.WriteVarUInt32((uint)Data.Length);
     Writer.Writer.Write(Data);
 }
 /// <summary>
 /// Writes this exported value to the given WebAssembly file writer.
 /// </summary>
 /// <param name="Writer">The WebAssembly file writer.</param>
 public void WriteTo(BinaryWasmWriter Writer)
 {
     Writer.WriteString(ModuleName);
     Writer.WriteString(FieldName);
     Writer.Writer.Write((byte)Kind);
     WriteContentsTo(Writer);
 }
Exemple #3
0
        /// <summary>
        /// Writes this WebAssembly file to the given stream using the binary WebAssembly file encoding.
        /// </summary>
        /// <param name="target">The stream to write to.</param>
        public void WriteBinaryTo(Stream target)
        {
            var writer     = new BinaryWriter(target);
            var wasmWriter = new BinaryWasmWriter(writer);

            wasmWriter.WriteFile(this);
        }
Exemple #4
0
 /// <inheritdoc/>
 public override void WritePayloadTo(BinaryWasmWriter Writer)
 {
     foreach (var entry in Names)
     {
         entry.WriteTo(Writer);
     }
 }
Exemple #5
0
 /// <summary>
 /// Writes this WebAssembly section's optional custom name and payload to the given
 /// WebAssembly writer.
 /// </summary>
 /// <param name="Writer">The writer to which the custom name and payload are written.</param>
 internal void WriteCustomNameAndPayloadTo(BinaryWasmWriter Writer)
 {
     if (Name.IsCustom)
     {
         Writer.WriteString(Name.CustomName);
     }
     WritePayloadTo(Writer);
 }
Exemple #6
0
 /// <summary>
 /// Writes this instruction's child instructions to the given WebAssembly file writer,
 /// followed by an 'end' opcode.
 /// </summary>
 /// <param name="writer">The writer to write this instruction's child instructions to.</param>
 public void WriteContentsTo(BinaryWasmWriter writer)
 {
     foreach (var instr in Contents)
     {
         instr.WriteTo(writer);
     }
     writer.Writer.Write(Operators.EndOpCode);
 }
Exemple #7
0
 /// <inheritdoc/>
 public override void WritePayloadTo(BinaryWasmWriter writer)
 {
     writer.WriteVarUInt32((uint)Segments.Count);
     foreach (var segment in Segments)
     {
         segment.WriteTo(writer);
     }
     writer.Writer.Write(ExtraPayload);
 }
Exemple #8
0
 /// <inheritdoc/>
 public override void WritePayloadTo(BinaryWasmWriter writer)
 {
     writer.WriteVarUInt32((uint)Exports.Count);
     foreach (var export in Exports)
     {
         export.WriteTo(writer);
     }
     writer.Writer.Write(ExtraPayload);
 }
 /// <summary>
 /// Writes this WebAssembly section's payload to the given binary WebAssembly writer.
 /// </summary>
 /// <param name="writer">The writer to which the payload is written.</param>
 public override void WritePayloadTo(BinaryWasmWriter writer)
 {
     writer.WriteVarUInt32((uint)GlobalVariables.Count);
     foreach (var index in GlobalVariables)
     {
         index.WriteTo(writer);
     }
     writer.Writer.Write(ExtraPayload);
 }
 /// <summary>
 /// Writes this instruction's immediates (but not its opcode)
 /// to the given WebAssembly file writer.
 /// </summary>
 /// <param name="writer">The writer to write this instruction's immediates to.</param>
 public override void WriteImmediatesTo(BinaryWasmWriter writer)
 {
     writer.WriteVarUInt32((uint)TargetTable.Count);
     foreach (var entry in TargetTable)
     {
         writer.WriteVarUInt32(entry);
     }
     writer.WriteVarUInt32(DefaultTarget);
 }
Exemple #11
0
 /// <inheritdoc/>
 public override void WritePayloadTo(BinaryWasmWriter Writer)
 {
     Writer.WriteVarUInt32((uint)Bodies.Count);
     foreach (var body in Bodies)
     {
         body.WriteTo(Writer);
     }
     Writer.Writer.Write(ExtraPayload);
 }
Exemple #12
0
 /// <inheritdoc/>
 public override void WritePayloadTo(BinaryWasmWriter Writer)
 {
     Writer.WriteVarUInt32((uint)Segments.Count);
     foreach (var export in Segments)
     {
         export.WriteTo(Writer);
     }
     Writer.Writer.Write(ExtraPayload);
 }
Exemple #13
0
 /// <summary>
 /// Writes this WebAssembly section's payload to the given binary WebAssembly writer.
 /// </summary>
 /// <param name="writer">The writer to which the payload is written.</param>
 public override void WritePayloadTo(BinaryWasmWriter writer)
 {
     writer.WriteVarUInt32((uint)FunctionTypes.Count);
     foreach (var index in FunctionTypes)
     {
         writer.WriteVarUInt32(index);
     }
     writer.Writer.Write(ExtraPayload);
 }
Exemple #14
0
 /// <summary>
 /// Writes these resizable limits to the given WebAssembly file writer.
 /// </summary>
 /// <param name="writer">The WebAssembly file writer.</param>
 public void WriteTo(BinaryWasmWriter writer)
 {
     writer.WriteVarUInt1(HasMaximum);
     writer.WriteVarUInt32(Initial);
     if (HasMaximum)
     {
         writer.WriteVarUInt32(Maximum.Value);
     }
 }
Exemple #15
0
 /// <inheritdoc/>
 public override void WritePayloadTo(BinaryWasmWriter Writer)
 {
     Writer.WriteVarUInt32((uint)Memories.Count);
     foreach (var limits in Memories)
     {
         limits.WriteTo(Writer);
     }
     Writer.Writer.Write(ExtraPayload);
 }
Exemple #16
0
        /// <inheritdoc/>
        public override void WritePayloadTo(BinaryWasmWriter writer)
        {
            writer.WriteVarUInt32((uint)Tables.Count);
            foreach (var type in Tables)
            {
                type.WriteTo(writer);
            }

            writer.Writer.Write(ExtraPayload);
        }
Exemple #17
0
        /// <inheritdoc/>
        public override void WritePayloadTo(BinaryWasmWriter Writer)
        {
            Writer.WriteVarUInt32((uint)FunctionTypes.Count);
            foreach (var type in FunctionTypes)
            {
                type.WriteTo(Writer);
            }

            Writer.Writer.Write(ExtraPayload);
        }
Exemple #18
0
 /// <summary>
 /// Writes this element segment to the given WebAssembly file writer.
 /// </summary>
 /// <param name="Writer">The WebAssembly file writer.</param>
 public void WriteTo(BinaryWasmWriter Writer)
 {
     Writer.WriteVarUInt32(TableIndex);
     Offset.WriteTo(Writer);
     Writer.WriteVarUInt32((uint)Elements.Count);
     foreach (var item in Elements)
     {
         Writer.WriteVarUInt32(item);
     }
 }
Exemple #19
0
        /// <summary>
        /// Writes this function type to the given binary WebAssembly file.
        /// </summary>
        /// <param name="writer">The writer for a binary WebAssembly file.</param>
        public void WriteTo(BinaryWasmWriter writer)
        {
            writer.WriteWasmType(Form);
            writer.WriteVarUInt32((uint)ParameterTypes.Count);
            foreach (var item in ParameterTypes)
            {
                writer.WriteWasmValueType(item);
            }

            writer.WriteVarUInt32((uint)ReturnTypes.Count);
            foreach (var item in ReturnTypes)
            {
                writer.WriteWasmValueType(item);
            }
        }
 /// <summary>
 /// Writes this instruction's child instructions to the given WebAssembly file writer,
 /// followed by an 'end' opcode.
 /// </summary>
 /// <param name="writer">The writer to write this instruction's child instructions to.</param>
 public void WriteContentsTo(BinaryWasmWriter writer)
 {
     foreach (var instr in IfBranch)
     {
         instr.WriteTo(writer);
     }
     if (HasElseBranch)
     {
         writer.Writer.Write(Operators.ElseOpCode);
         foreach (var instr in ElseBranch)
         {
             instr.WriteTo(writer);
         }
     }
     writer.Writer.Write(Operators.EndOpCode);
 }
Exemple #21
0
        private void WriteContentsTo(BinaryWasmWriter Writer)
        {
            // Write the number of local entries to the file.
            Writer.WriteVarUInt32((uint)Locals.Count);

            // Write the local variables to the file.
            foreach (var local in Locals)
            {
                local.WriteTo(Writer);
            }

            // Write the body to the file.
            Operators.Block.Create(WasmType.Empty, BodyInstructions).WriteContentsTo(Writer);

            if (HasExtraPayload)
            {
                // If we have at least one byte of additional payload,
                // then we should write it to the stream now.
                Writer.Writer.Write(ExtraPayload);
            }
        }
Exemple #22
0
 /// <summary>
 /// Writes the initializer expression to the given WebAssembly writer.
 /// </summary>
 /// <param name="Writer">The WebAssembly writer.</param>
 public void WriteTo(BinaryWasmWriter Writer)
 {
     Operators.Block.Create(WasmType.Empty, BodyInstructions).WriteContentsTo(Writer);
 }
Exemple #23
0
 /// <summary>
 /// Writes this instruction's immediates (but not its opcode)
 /// to the given WebAssembly file writer.
 /// </summary>
 /// <param name="Writer">The writer to write this instruction's immediates to.</param>
 public override void WriteImmediatesTo(BinaryWasmWriter Writer)
 {
     Writer.WriteVarInt64(Immediate);
 }
Exemple #24
0
 /// <inheritdoc/>
 public override void WritePayloadTo(BinaryWasmWriter writer)
 {
     writer.WriteVarUInt32(StartFunctionIndex);
     writer.Writer.Write(ExtraPayload);
 }
Exemple #25
0
 /// <summary>
 /// Writes this WebAssembly section's payload to the given binary WebAssembly writer.
 /// </summary>
 /// <param name="Writer">The writer to which the payload is written.</param>
 public abstract void WritePayloadTo(BinaryWasmWriter Writer);
 /// <summary>
 /// Writes this instruction's immediates (but not its opcode)
 /// to the given WebAssembly file writer.
 /// </summary>
 /// <param name="writer">The writer to write this instruction's immediates to.</param>
 public override void WriteImmediatesTo(BinaryWasmWriter writer)
 {
     writer.WriteWasmType(Type);
     WriteContentsTo(writer);
 }
 /// <summary>
 /// Writes this instruction's immediates (but not its opcode)
 /// to the given WebAssembly file writer.
 /// </summary>
 /// <param name="writer">The writer to write this instruction's immediates to.</param>
 public override void WriteImmediatesTo(BinaryWasmWriter writer)
 {
     writer.WriteVarUInt32(Immediate);
 }
Exemple #28
0
 /// <summary>
 /// Writes this local entry to the given WebAssembly file writer.
 /// </summary>
 /// <param name="Writer">The WebAssembly file writer.</param>
 public void WriteTo(BinaryWasmWriter Writer)
 {
     Writer.WriteVarUInt32(LocalCount);
     Writer.WriteWasmValueType(LocalType);
 }
Exemple #29
0
 /// <summary>
 /// Writes this memory description to the given binary WebAssembly file.
 /// </summary>
 /// <param name="Writer">The writer for a binary WebAssembly file.</param>
 public void WriteTo(BinaryWasmWriter Writer)
 {
     Limits.WriteTo(Writer);
 }
Exemple #30
0
 /// <summary>
 /// Writes this function body to the given WebAssembly file writer.
 /// </summary>
 /// <param name="Writer">The WebAssembly file writer.</param>
 public void WriteTo(BinaryWasmWriter Writer)
 {
     Writer.WriteLengthPrefixed(WriteContentsTo);
 }