public Import(string module, string name, [NotNull] TableType tableType) { Module = module; Name = name; Type = ExternalKind.Table; Table = tableType; }
public Import(string module, string name, [NotNull] MemoryType memoryType) { Module = module; Name = name; Type = ExternalKind.Memory; Memory = memoryType; }
public Import(string module, string name, [NotNull] GlobalType globalType) { Module = module; Name = name; Type = ExternalKind.Global; Global = globalType; }
private void ParseImportSection(BinaryParsingReader reader, uint payloadSize) { long startPosition = payloadSize; uint importsCount = reader.ReadVarUint32(); for (uint index = 0; index < importsCount; index++) { string moduleName = reader.ReadLengthPrefixedUTF8String(); List <ImportedItemDefinition> imports; if (!_perModuleImportedItems.TryGetValue(moduleName, out imports)) { imports = new List <ImportedItemDefinition>(); _perModuleImportedItems.Add(moduleName, imports); } string fieldName = reader.ReadLengthPrefixedUTF8String(); ExternalKind kind = (ExternalKind)reader.ReadVarUint7(); bool maxPresent; uint initialLength; uint maximumLength; switch (kind) { case ExternalKind.Function: imports.Add(new ImportedFunctionDefinition(fieldName, reader.ReadVarUint32())); continue; case ExternalKind.Global: bool mutable; BuiltinLanguageType contentType = reader.ReadGlobaltype(out mutable); imports.Add(new ImportedGlobalDefinition(fieldName, contentType, mutable)); continue; case ExternalKind.Memory: maxPresent = (0 != reader.ReadVarUint1()); initialLength = reader.ReadVarUint32(); maximumLength = maxPresent ? reader.ReadVarUint32() : 0; imports.Add(new ImportedMemoryDefinition(fieldName, initialLength, maxPresent ? (uint?)maximumLength : null)); continue; case ExternalKind.Table: BuiltinLanguageType elementType = (BuiltinLanguageType)reader.ReadVarInt7(); if (BuiltinLanguageType.AnyFunc != elementType) { throw new WasmParsingException(string.Format(ParsingErrorMessages.UnexpectedBuiltinType, elementType, BuiltinLanguageType.AnyFunc)); } maxPresent = (0 != reader.ReadVarUint1()); initialLength = reader.ReadVarUint32(); maximumLength = maxPresent ? reader.ReadVarUint32() : 0; imports.Add(new ImportedTableDefinition(fieldName, elementType, initialLength, maxPresent ? (uint?)maximumLength : null)); continue; default: throw new WasmParsingException(string.Format( ParsingErrorMessages.UnrecognizedExternalKind, kind)); } } // TODO Check for match between payloadSize and current stream position. return; }
public Import(string module, string name, uint functionType) { Module = module; Name = name; Type = ExternalKind.Function; Function = functionType; }
public void ToExternalKind(string hex, ExternalKind expect) { using (var reader = BinaryTools.HexToReader(hex)) { var kind = TypeParser.ToExternalKind(reader); Assert.That(kind, Is.EqualTo(expect)); } }
public ExportEntry(Reader reader, Module module) { Module_ = module; // Field: Field = reader.String(); // Kind: Kind_ = (ExternalKind)reader.ReadByte(); // Index: Index_ = (int)reader.VarUInt32(); }
private IEnumerable <T> EnumerateImports <T>(ExternalKind kind) where T : ImportedItemDefinition { foreach (List <ImportedItemDefinition> definitions in _perModuleImportedItems.Values) { foreach (ImportedItemDefinition definition in definitions) { if (kind == definition.Kind) { yield return((T)definition); } } } }
public override void Load(Reader reader, int length) { int count = (int)reader.VarUInt32(); // Read all: for (int i = 0; i < count; i++) { string module = reader.String(); string field = reader.String(); ExternalKind kind = (ExternalKind)reader.ReadByte(); ImportEntry ie; switch (kind) { case ExternalKind.Function: ie = new FunctionImportEntry(reader); Functions.Add(ie as FunctionImportEntry); break; case ExternalKind.Table: ie = new TableImportEntry(reader); Tables.Add(ie as TableImportEntry); break; case ExternalKind.Memory: ie = new MemoryImportEntry(reader); Memory.Add(ie as MemoryImportEntry); break; default: case ExternalKind.Global: ie = new GlobalImportEntry(reader); Globals.Add(ie as GlobalImportEntry); break; } // Update module etc: ie.Module = module; ie.Field = field; ie.Kind = kind; } }
public ExternalType([NotNull] TableType tableType) { Type = ExternalKind.Table; TableType = tableType; }
public ExternalType([NotNull] FunctionType functionType) { Type = ExternalKind.Function; FunctionType = functionType; }
public WasmExport(string fieldName, ExternalKind kind, uint index) { FieldName = fieldName; Kind = kind; Index = index; }
/// <summary> /// Creates a new <see cref="NativeExportAttribute"/> from the provided parameters. /// </summary> /// <param name="kind">The original export type.</param> /// <param name="name">Creates a new <see cref="NativeExportAttribute"/> from the provided parameters.</param> public NativeExportAttribute(ExternalKind kind, string name) { this.Kind = kind; this.Name = name; }
public ModuleExportDescriptor(ExternalKind kind, string name) { _kind = kind; _name = name; }
/// <summary> /// Creates an exported value from the given name, kind and index. /// </summary> /// <param name="Name">The name of the exported value.</param> /// <param name="Kind">The kind of value that is exported.</param> /// <param name="Index">The index into the index space for the value's kind.</param> public ExportedValue(string Name, ExternalKind Kind, uint Index) { this.Name = Name; this.Kind = Kind; this.Index = Index; }
internal ImportedItemDefinition(string name, ExternalKind kind) { Kind = kind; ItemName = name ?? throw new ArgumentNullException("name"); }
public Export(string name, ExternalKind type, uint index) { Name = name; Type = type; Index = index; }
public ExternalType([NotNull] MemoryType memoryType) { Type = ExternalKind.Memory; MemoryType = memoryType; }
/// <summary> /// Creates an exported value from the given name, kind and index. /// </summary> /// <param name="name">The name of the exported value.</param> /// <param name="kind">The kind of value that is exported.</param> /// <param name="index">The index into the index space for the value's kind.</param> public ExportedValue(string name, ExternalKind kind, uint index) { this.Name = name; this.Kind = kind; this.Index = index; }
public ExternalType([NotNull] GlobalType globalType) { Type = ExternalKind.Global; GlobalType = globalType; }
internal static CustomAttributeBuilder Emit(ExternalKind kind, string name) => new CustomAttributeBuilder(Constructor, new object[] { kind, name });