public FunctionBody(BinaryReader reader) { // Bit of a hack, but we use positions in this method, so we need to ensure it works if (!reader.BaseStream.CanSeek) { throw new NotSupportedException("Stream passed does not support seeking."); } uint body_size = LEB128.ReadUInt32(reader); var before_pos = reader.BaseStream.Position; uint local_count = LEB128.ReadUInt32(reader); if (local_count > int.MaxValue) { throw new NotImplementedException($"Count larger than {int.MaxValue} bytes not supported."); } locals = new LocalEntry[local_count]; for (uint i = 0; i < local_count; i++) { locals[i] = new LocalEntry(reader); } var after_pos = reader.BaseStream.Position; code = reader.ReadBytes((int)(body_size - (after_pos - before_pos))); if (code[code.Length - 1] != (byte)WebAssemblyOpcode.END) { throw new Exception($"File is invalid. Expected byte {WebAssemblyOpcode.END}, received {code[code.Length-1]}."); } }
private void LocalidadEdit_Click(object sender, EventArgs e) { LocalEntry.Enabled = true; LocalEntry.Focus(); button2.Visible = true; LocalidadEdit.Visible = false; }
private void SetLocalValue(int id, LocalEntry entry) { if (_locals.ContainsKey(id)) { _locals[id] = entry; } else { _locals.Add(id, entry); } }
/// <summary> /// Merges adjacent local entries that have the same type and deletes empty /// local entries. /// </summary> /// <param name="body">The function body whose locals are to be compressed.</param> public static void CompressLocalEntries(this FunctionBody body) { var newLocals = new List <LocalEntry>(); var aggregateEntry = new LocalEntry(WasmValueType.Int32, 0); for (int i = 0; i < body.Locals.Count; i++) { var currentEntry = body.Locals[i]; if (currentEntry.LocalType == aggregateEntry.LocalType) { // If two adjacent local entries have the same type, then // we should merge them. aggregateEntry = new LocalEntry( aggregateEntry.LocalType, aggregateEntry.LocalCount + currentEntry.LocalCount); } else { // We can't merge `currentEntry` with `aggregateEntry`. But maybe // we'll be able to merge `currentEntry` and its successor. if (aggregateEntry.LocalCount > 0) { newLocals.Add(aggregateEntry); } aggregateEntry = currentEntry; } } // Append the final entry to the new list of locals. if (aggregateEntry.LocalCount > 0) { newLocals.Add(aggregateEntry); } // Clear the old local list and replace its contents with the new entries. body.Locals.Clear(); body.Locals.AddRange(newLocals); }
private StackEntry LocalToStackEntry(Instruction instruction, LocalEntry localEntry) { return new StackEntry(instruction, localEntry.IsValueKnown, localEntry.Value); }
private StackEntry LocalToStackEntry(Instruction instruction, LocalEntry localEntry) { return(new StackEntry(instruction, localEntry.IsValueKnown, localEntry.Value)); }