Ejemplo n.º 1
0
 public Import(string module, string name, [NotNull] TableType tableType)
 {
     Module = module;
     Name   = name;
     Type   = ExternalKind.Table;
     Table  = tableType;
 }
Ejemplo n.º 2
0
 public Import(string module, string name, [NotNull] MemoryType memoryType)
 {
     Module = module;
     Name   = name;
     Type   = ExternalKind.Memory;
     Memory = memoryType;
 }
Ejemplo n.º 3
0
 public Import(string module, string name, [NotNull] GlobalType globalType)
 {
     Module = module;
     Name   = name;
     Type   = ExternalKind.Global;
     Global = globalType;
 }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
 public Import(string module, string name, uint functionType)
 {
     Module   = module;
     Name     = name;
     Type     = ExternalKind.Function;
     Function = functionType;
 }
Ejemplo n.º 6
0
 public void ToExternalKind(string hex, ExternalKind expect)
 {
     using (var reader = BinaryTools.HexToReader(hex))
     {
         var kind = TypeParser.ToExternalKind(reader);
         Assert.That(kind, Is.EqualTo(expect));
     }
 }
Ejemplo n.º 7
0
        public ExportEntry(Reader reader, Module module)
        {
            Module_ = module;

            // Field:
            Field = reader.String();

            // Kind:
            Kind_ = (ExternalKind)reader.ReadByte();

            // Index:
            Index_ = (int)reader.VarUInt32();
        }
Ejemplo n.º 8
0
 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);
             }
         }
     }
 }
Ejemplo n.º 9
0
        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;
            }
        }
Ejemplo n.º 10
0
 public ExternalType([NotNull] TableType tableType)
 {
     Type      = ExternalKind.Table;
     TableType = tableType;
 }
Ejemplo n.º 11
0
 public ExternalType([NotNull] FunctionType functionType)
 {
     Type         = ExternalKind.Function;
     FunctionType = functionType;
 }
Ejemplo n.º 12
0
 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;
 }
Ejemplo n.º 14
0
 public ModuleExportDescriptor(ExternalKind kind, string name)
 {
     _kind = kind;
     _name = name;
 }
Ejemplo n.º 15
0
 /// <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;
 }
Ejemplo n.º 16
0
 internal ImportedItemDefinition(string name, ExternalKind kind)
 {
     Kind     = kind;
     ItemName = name ?? throw new ArgumentNullException("name");
 }
Ejemplo n.º 17
0
 public Export(string name, ExternalKind type, uint index)
 {
     Name  = name;
     Type  = type;
     Index = index;
 }
Ejemplo n.º 18
0
 public ExternalType([NotNull] MemoryType memoryType)
 {
     Type       = ExternalKind.Memory;
     MemoryType = memoryType;
 }
Ejemplo n.º 19
0
 /// <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;
 }
Ejemplo n.º 20
0
 public ExternalType([NotNull] GlobalType globalType)
 {
     Type       = ExternalKind.Global;
     GlobalType = globalType;
 }
Ejemplo n.º 21
0
 internal static CustomAttributeBuilder Emit(ExternalKind kind, string name) =>
 new CustomAttributeBuilder(Constructor, new object[] { kind, name });