Exemplo n.º 1
0
        public Module(ModuleHeader header, IReadOnlyList <ParsedInstruction> instructions)
        {
            Header       = header;
            Instructions = instructions;

            Read(Instructions, objects_);
        }
Exemplo n.º 2
0
        public Module(ModuleHeader header, List <ParsedInstruction> instructions)
        {
            Header        = header;
            instructions_ = instructions;

            Read(instructions_, objects_);
        }
Exemplo n.º 3
0
        public static Module ReadFrom(Stream stream)
        {
            BinaryReader br     = new BinaryReader(stream);
            Reader       reader = new Reader(br);

            uint    versionNumber = reader.ReadDWord();
            int     majorVersion  = (int)(versionNumber >> 16);
            int     minorVersion  = (int)((versionNumber >> 8) & 0xFF);
            Version version       = new Version(majorVersion, minorVersion);

            uint   generatorMagicNumber = reader.ReadDWord();
            int    generatorToolId      = (int)(generatorMagicNumber >> 16);
            string generatorVendor      = "unknown";
            string generatorName        = null;

            if (Meta.Tools.ContainsKey(generatorToolId))
            {
                Meta.ToolInfo toolInfo = Meta.Tools[generatorToolId];
                generatorVendor = toolInfo.Vendor;
                if (toolInfo.Name != null)
                {
                    generatorName = toolInfo.Name;
                }
            }

            // Read header
            ModuleHeader header = new ModuleHeader();

            header.Version          = version;
            header.GeneratorName    = generatorName;
            header.GeneratorVendor  = generatorVendor;
            header.GeneratorVersion = (int)(generatorMagicNumber & 0xFFFF);
            header.Bound            = reader.ReadDWord();
            header.Reserved         = reader.ReadDWord();

            List <ParsedInstruction> instructions = new List <ParsedInstruction>();

            while (!reader.EndOfStream)
            {
                uint   instructionStart = reader.ReadDWord();
                ushort wordCount        = (ushort)(instructionStart >> 16);
                int    opCode           = (int)(instructionStart & 0xFFFF);

                uint[] words = new uint[wordCount];
                words[0] = instructionStart;
                for (ushort i = 1; i < wordCount; ++i)
                {
                    words[i] = reader.ReadDWord();
                }

                ParsedInstruction instruction = new ParsedInstruction(opCode, words);
                instructions.Add(instruction);
            }

            return(new Module(header, instructions));
        }
Exemplo n.º 4
0
        public static Module ReadFrom(System.IO.Stream stream)
        {
            var br     = new System.IO.BinaryReader(stream);
            var reader = new Reader(br);

            var versionNumber = reader.ReadWord();
            var version       = new Version(
                (int)(versionNumber >> 16),
                (int)((versionNumber >> 8) & 0xFF));

            var generatorMagicNumber = reader.ReadWord();
            var generatorToolId      = (int)(generatorMagicNumber >> 16);

            string generatorVendor = "unknown";
            string generatorName   = null;

            if (SpirV.Meta.Tools.ContainsKey(generatorToolId))
            {
                var toolInfo = SpirV.Meta.Tools[generatorToolId];

                generatorVendor = toolInfo.Vendor;

                if (toolInfo.Name != null)
                {
                    generatorName = toolInfo.Name;
                }
            }

            // Read header
            var header = new ModuleHeader
            {
                Version          = version,
                GeneratorName    = generatorName,
                GeneratorVendor  = generatorVendor,
                GeneratorVersion = (int)(generatorMagicNumber & 0xFFFF),
                Bound            = reader.ReadWord(),
                Reserved         = reader.ReadWord()
            };

            var instructions = new List <ParsedInstruction> ();

            try {
                while (true)
                {
                    var instructionStart = reader.ReadWord();
                    var wordCount        = (ushort)(instructionStart >> 16);
                    var opCode           = (int)(instructionStart & 0xFFFF);

                    List <uint> words = new List <uint> ()
                    {
                        instructionStart
                    };

                    for (ushort i = 0; i < wordCount - 1; ++i)
                    {
                        words.Add(reader.ReadWord());
                    }

                    instructions.Add(new ParsedInstruction(opCode, words));
                }
            } catch (System.IO.EndOfStreamException) {
            }

            return(new Module(header, instructions));
        }