/// <summary>Extracts all __asm4GCN blocks and removes comments from source</summary> /// <param name="source">This is the device source code. I can contain __kernels(OpenCL) and/or __asmBlocks.</param> /// <returns>A list of AsmBlocks. An AsmBlock contains the __asmBlock's information and binary code.</returns> private List <AsmBlock> ExtractAsm4GCNBlocks(ref string source, StringBuilder log, out bool success) { success = true; // true if either the Asm4GCNBlock format is incorrect // This remove comments source = commentSpace.Replace(source, me => { if (me.Value.StartsWith("/*") || me.Value.StartsWith("//")) { return(me.Value.StartsWith("//") ? Environment.NewLine : ""); } return(me.Value); // Keep the literal strings }); // Decode __asm4GCN block MatchCollection matches = matchAsm4GcnBlock.Matches(source); List <AsmBlock> asmBlocks = new List <AsmBlock>(); if (matches.Count == 0) { log.AppendLine("Info: There were no __asm4GCN blocks found."); return(asmBlocks); } foreach (Match m in matches) { AsmBlock blk = new AsmBlock(); blk.funcName = m.Groups["funcName"].Value;; blk.codeBlock = m.Groups["block"].Value; blk.locInSource = m.Index; blk.lenInSource = m.Length; blk.paramCt = m.Groups["dataType"].Captures.Count; blk.newlineCtInHeader = m.Groups["headerArea"].Value.Split('\n').Length - 1; for (int c = 0; c < blk.paramCt; c++) { string type = m.Groups["dataType"].Captures[c].Value; string name = m.Groups["name"].Captures[c].Value; if (name == "") { name = "auto_gen_var_name_" + c; } else { log.AppendLine("WARN: Parameter names are not used in __asm4GCN. Example Use: __asm4GCN myFunc(uint, uint) {...}"); } type = new string(type.ToCharArray().Where(w => !Char.IsWhiteSpace(w)).ToArray()); // remove whitespace string gcnType = ""; if (type.EndsWith("*")) { gcnType = "s4u"; } else { switch (type) { case "int": gcnType = "s4i"; break; case "uint": gcnType = "s4u"; break; case "char": gcnType = "s1i"; break; case "float": gcnType = "s4f"; break; case "double": gcnType = "s8f"; break; case "short": gcnType = "s2i"; break; case "ushort": gcnType = "s2u"; break; case "long": gcnType = "s8i"; break; case "ulong": gcnType = "s8u"; break; case "uchar": gcnType = "s1u"; break; case "bool": gcnType = "s4b"; break; case "void": gcnType = "s4u"; break; case "signedint": gcnType = "s4i"; break; case "unsignedint": gcnType = "s4u"; break; case "signedchar": gcnType = "s1i"; break; case "unsighedchar": gcnType = "s1u"; break; case "signedshort": gcnType = "s2i"; break; case "unsighedshort": gcnType = "s2u"; break; case "signedlong": gcnType = "s8i"; break; case "unsighedlong": gcnType = "s8u"; break; default: throw new Exception("ERROR: " + type + " is not a recognized param dataType for an _asm4GCN block."); } } blk.paramVars.Add(new GcnVar { cppType = type, gcnType = gcnType, name = name }); } // Count number of lines in the header so the error-line-# reports correctly if (blk.newlineCtInHeader < 0) { log.AppendLine("ERROR: The GCN function header should be on its own line."); success = false; continue; } asmBlocks.Add(blk); } return(asmBlocks); }
/// <summary>Extracts all __asm4GCN blocks and removes comments from source</summary> /// <param name="source">This is the device source code. I can contain __kernels(OpenCL) and/or __asmBlocks.</param> /// <returns>A list of AsmBlocks. An AsmBlock contains the __asmBlock's information and binary code.</returns> private List<AsmBlock> ExtractAsm4GCNBlocks(ref string source, StringBuilder log, out bool success) { success = true; // true if either the Asm4GCNBlock format is incorrect // This remove comments source = commentSpace.Replace(source, me => { if (me.Value.StartsWith("/*") || me.Value.StartsWith("//")) return me.Value.StartsWith("//") ? Environment.NewLine : ""; return me.Value; // Keep the literal strings }); // Decode __asm4GCN block MatchCollection matches = matchAsm4GcnBlock.Matches(source); List<AsmBlock> asmBlocks = new List<AsmBlock>(); if (matches.Count == 0) { log.AppendLine("Info: There were no __asm4GCN blocks found."); return asmBlocks; } foreach (Match m in matches) { AsmBlock blk = new AsmBlock(); blk.funcName = m.Groups["funcName"].Value; ; blk.codeBlock = m.Groups["block"].Value; blk.locInSource = m.Index; blk.lenInSource = m.Length; blk.paramCt = m.Groups["dataType"].Captures.Count; blk.newlineCtInHeader = m.Groups["headerArea"].Value.Split('\n').Length - 1; for (int c = 0; c < blk.paramCt; c++) { string type = m.Groups["dataType"].Captures[c].Value; string name = m.Groups["name"].Captures[c].Value; if (name == "") name = "auto_gen_var_name_" + c; else log.AppendLine("WARN: Parameter names are not used in __asm4GCN. Example Use: __asm4GCN myFunc(uint, uint) {...}"); type = new string(type.ToCharArray().Where(w => !Char.IsWhiteSpace(w)).ToArray()); // remove whitespace string gcnType = ""; if (type.EndsWith("*")) gcnType = "s4u"; else switch (type) { case "int": gcnType = "s4i"; break; case "uint": gcnType = "s4u"; break; case "char": gcnType = "s1i"; break; case "float": gcnType = "s4f"; break; case "double": gcnType = "s8f"; break; case "short": gcnType = "s2i"; break; case "ushort": gcnType = "s2u"; break; case "long": gcnType = "s8i"; break; case "ulong": gcnType = "s8u"; break; case "uchar": gcnType = "s1u"; break; case "bool": gcnType = "s4b"; break; case "void": gcnType = "s4u"; break; case "signedint": gcnType = "s4i"; break; case "unsignedint": gcnType = "s4u"; break; case "signedchar": gcnType = "s1i"; break; case "unsighedchar": gcnType = "s1u"; break; case "signedshort": gcnType = "s2i"; break; case "unsighedshort": gcnType = "s2u"; break; case "signedlong": gcnType = "s8i"; break; case "unsighedlong": gcnType = "s8u"; break; default: throw new Exception("ERROR: " + type + " is not a recognized param dataType for an _asm4GCN block."); } blk.paramVars.Add(new GcnVar { cppType = type, gcnType = gcnType, name = name }); } // Count number of lines in the header so the error-line-# reports correctly if (blk.newlineCtInHeader < 0) { log.AppendLine("ERROR: The GCN function header should be on its own line."); success = false; continue; } asmBlocks.Add(blk); } return asmBlocks; }