public void AddOperand <T>(T value) where T : struct { if (!typeof(T).IsPrimitive && !typeof(T).IsEnum) { throw new InvalidOperationException(); } AddOperand(LiteralInteger.CreateForEnum(value)); }
public Instruction ExtInst(Instruction resultType, Instruction set, LiteralInteger instruction, params Operand[] parameters) { Instruction result = new Instruction(Op.OpExtInst, GetNewId(), resultType); result.AddOperand(set); result.AddOperand(instruction); result.AddOperand(parameters); AddToFunctionDefinitions(result); return(result); }
public Module(uint version, GeneratorPool <Instruction> instPool = null, GeneratorPool <LiteralInteger> integerPool = null) { _version = version; _bound = 1; _capabilities = new List <Capability>(); _extensions = new List <string>(); _extInstImports = new Dictionary <DeterministicStringKey, Instruction>(); _addressingModel = AddressingModel.Logical; _memoryModel = MemoryModel.Simple; _entrypoints = new List <Instruction>(); _executionModes = new List <Instruction>(); _debug = new List <Instruction>(); _annotations = new List <Instruction>(); _typeDeclarations = new Dictionary <TypeDeclarationKey, Instruction>(); _constants = new Dictionary <ConstantKey, Instruction>(); _globals = new List <Instruction>(); _functionsDeclarations = new List <Instruction>(); _functionsDefinitions = new List <Instruction>(); _instPool = instPool ?? new GeneratorPool <Instruction>(); _integerPool = integerPool ?? new GeneratorPool <LiteralInteger>(); LiteralInteger.RegisterPool(_integerPool); }
public void AddOperand(LiteralInteger value) { AddOperand((Operand)value); }
public Instruction OpenClVstorea_halfn_r(Instruction resultType, Instruction data, Instruction offset, Instruction p, FPRoundingMode mode) { return(ExtInst(resultType, AddExtInstImport("OpenCL.std"), 181, data, offset, p, LiteralInteger.CreateForEnum(mode))); }
public Instruction OpenClVloada_halfn(Instruction resultType, Instruction offset, Instruction p, LiteralInteger n) { return(ExtInst(resultType, AddExtInstImport("OpenCL.std"), 179, offset, p, n)); }
public void AddOperand <T>(T value) where T : Enum { AddOperand(LiteralInteger.CreateForEnum(value)); }
public byte[] Generate() { // Estimate the size needed for the generated code, to avoid expanding the MemoryStream. int sizeEstimate = 1024 + _functionsDefinitions.Count * 32; using (MemoryStream stream = new MemoryStream(sizeEstimate)) { BinaryWriter writer = new BinaryWriter(stream, System.Text.Encoding.ASCII); // Header writer.Write(MagicNumber); writer.Write(_version); writer.Write(GeneratorId); writer.Write(_bound); writer.Write(0u); // 1. foreach (Capability capability in _capabilities) { Instruction capabilityInstruction = NewInstruction(Op.OpCapability); capabilityInstruction.AddOperand(capability); capabilityInstruction.Write(writer); } // 2. foreach (string extension in _extensions) { Instruction extensionInstruction = NewInstruction(Op.OpExtension); extensionInstruction.AddOperand(extension); extensionInstruction.Write(writer); } // 3. foreach (Instruction extInstImport in _extInstImports.Values) { extInstImport.Write(writer); } // 4. Instruction memoryModelInstruction = NewInstruction(Op.OpMemoryModel); memoryModelInstruction.AddOperand(_addressingModel); memoryModelInstruction.AddOperand(_memoryModel); memoryModelInstruction.Write(writer); // 5. foreach (Instruction entrypoint in _entrypoints) { entrypoint.Write(writer); } // 6. foreach (Instruction executionMode in _executionModes) { executionMode.Write(writer); } // 7. // TODO: Order debug information correctly. foreach (Instruction debug in _debug) { debug.Write(writer); } // 8. foreach (Instruction annotation in _annotations) { annotation.Write(writer); } // Ensure that everything is in the right order in the declarations section. List <Instruction> declarations = new List <Instruction>(); declarations.AddRange(_typeDeclarations.Values); declarations.AddRange(_globals); declarations.AddRange(_constants.Values); declarations.Sort((Instruction x, Instruction y) => x.Id.CompareTo(y.Id)); // 9. foreach (Instruction declaration in declarations) { declaration.Write(writer); } // 10. foreach (Instruction functionDeclaration in _functionsDeclarations) { functionDeclaration.Write(writer); } // 11. foreach (Instruction functionDefinition in _functionsDefinitions) { functionDefinition.Write(writer); } _instPool.Clear(); _integerPool.Clear(); LiteralInteger.UnregisterPool(); return(stream.ToArray()); } }