parent
769f61f8c7
commit
ecb707ca7b
4 changed files with 39 additions and 108 deletions
@ -0,0 +1,34 @@ |
|||||||
|
file(GLOB cl_list "${CL_DIR}/*.cl" ) |
||||||
|
|
||||||
|
file(WRITE ${OUTPUT} "// This file is auto-generated. Do not edit! |
||||||
|
|
||||||
|
namespace cv |
||||||
|
{ |
||||||
|
namespace ocl |
||||||
|
{ |
||||||
|
") |
||||||
|
|
||||||
|
foreach(cl ${cl_list}) |
||||||
|
get_filename_component(cl_filename "${cl}" NAME_WE) |
||||||
|
#message("${cl_filename}") |
||||||
|
|
||||||
|
file(READ "${cl}" lines) |
||||||
|
|
||||||
|
string(REPLACE "\r" "" lines "${lines}\n") |
||||||
|
string(REPLACE "\t" " " lines "${lines}") |
||||||
|
|
||||||
|
string(REGEX REPLACE "/\\*([^*]/|\\*[^/]|[^*/])*\\*/" "" lines "${lines}") # multiline comments |
||||||
|
string(REGEX REPLACE "[ ]*//[^\n]*\n" "\n" lines "${lines}") # single-line comments |
||||||
|
string(REGEX REPLACE "\n[ ]*(\n[ ]*)*" "\n" lines "${lines}") # empty lines & leading whitespace |
||||||
|
string(REGEX REPLACE "^\n" "" lines "${lines}") # leading new line |
||||||
|
|
||||||
|
string(REPLACE "\\" "\\\\" lines "${lines}") |
||||||
|
string(REPLACE "\"" "\\\"" lines "${lines}") |
||||||
|
string(REPLACE "\n" "\\n\"\n\"" lines "${lines}") |
||||||
|
|
||||||
|
string(REGEX REPLACE "\"$" "" lines "${lines}") # unneeded " at the eof |
||||||
|
|
||||||
|
file(APPEND ${OUTPUT} "const char* ${cl_filename}=\"${lines};\n") |
||||||
|
endforeach() |
||||||
|
|
||||||
|
file(APPEND ${OUTPUT} "}\n}\n") |
@ -1,40 +0,0 @@ |
|||||||
var fso = new ActiveXObject("Scripting.FileSystemObject"), shell = new ActiveXObject("WScript.Shell"), args = WScript.Arguments, indir = args[0], outname = args[1], outDir, scriptFullPath = WScript.ScriptFullName; |
|
||||||
function getDir(a) { |
|
||||||
return a.substring(0, a.lastIndexOf("\\") || a.lastIndexOf("/")) |
|
||||||
} |
|
||||||
if (!indir || !outname) { |
|
||||||
var scriptPath = getDir(WScript.ScriptFullName.toString()), |
|
||||||
indir = indir || scriptPath + "/src/kernels"; |
|
||||||
outname || (outname = scriptPath + "/kernels.cpp", outDir = scriptPath) |
|
||||||
} else { |
|
||||||
outDir = getDir(outname); |
|
||||||
try { |
|
||||||
fso.CreateFolder(outDir) |
|
||||||
} catch (err) {} |
|
||||||
|
|
||||||
} |
|
||||||
var infldr = fso.GetFolder(indir), clrx = /([\w-]+)\.cl$/i, stripBeginningRx = /^(\s)+/i, stripSinglelineMstyle = /\/\*.*?\*\//ig, outStream = fso.OpenTextFile(outname, 2, !0, -2); |
|
||||||
outStream.write("// This file is auto-generated. Do not edit!\n\nnamespace cv{\n\tnamespace ocl{\n"); |
|
||||||
for (var res, cl_file, l, state, countFiles = 0, codeRows = 0, removedRows = 0, filei = new Enumerator(infldr.Files); !filei.atEnd(); filei.moveNext()) |
|
||||||
if (cl_file = filei.item(), res = cl_file.Name.match(clrx)) { |
|
||||||
var cl_filename = res[1], |
|
||||||
inStream = cl_file.OpenAsTextStream(1); |
|
||||||
outStream.writeLine("\t\tconst char* " + cl_filename + "="); |
|
||||||
state = 0; |
|
||||||
for (countFiles++; !inStream.AtEndOfStream; ) { |
|
||||||
l = inStream.readLine(); |
|
||||||
stripSinglelineMstyle.lastIndex = 0; |
|
||||||
l = l.replace(stripSinglelineMstyle, ""); |
|
||||||
var mline = l.indexOf("/*"); |
|
||||||
0 <= mline ? (l = l.substr(0, mline), |
|
||||||
state = 1) : (mline = l.indexOf("*/"), 0 <= mline && (l = l.substr(mline + 2), state = 0)); |
|
||||||
var slineBegin = l.indexOf("//"); |
|
||||||
0 <= slineBegin && (l = l.substr(0, slineBegin)); |
|
||||||
1 == state || !l ? removedRows++ : (l = l.replace(stripBeginningRx, "$1"), l = l.replace("\\", "\\\\"), l = l.replace("\r", ""), l = l.replace('"', '\\"'), l = l.replace("\t", " "), codeRows++, outStream.writeLine('\t\t\t"' + l + '\\n"')) |
|
||||||
} |
|
||||||
outStream.writeLine("\t\t;"); |
|
||||||
inStream.close() |
|
||||||
} |
|
||||||
outStream.writeLine("\t\t}\n\t}"); |
|
||||||
outStream.close(); |
|
||||||
shell.Popup("Merging OpenCL Kernels into cpp file has been FINISHED!\nFiles : " + countFiles + "\nCode rows : " + codeRows + "\nRemoved rows : " + removedRows, 1, "OpenCL Kernels to cpp file", 64); |
|
@ -1,55 +0,0 @@ |
|||||||
import os, os.path, sys, glob |
|
||||||
|
|
||||||
indir = sys.argv[1] |
|
||||||
outname = sys.argv[2] |
|
||||||
#indir = "/Users/vp/work/ocv/opencv/modules/ocl/src/kernels" |
|
||||||
#outname = "/Users/vp/work/ocv.build/xcode/modules/ocl/kernels.cpp" |
|
||||||
|
|
||||||
try: |
|
||||||
os.mkdir(os.path.dirname(outname)) |
|
||||||
except OSError: |
|
||||||
pass |
|
||||||
|
|
||||||
cl_list = glob.glob(os.path.join(indir, "*.cl")) |
|
||||||
kfile = open(outname, "wt") |
|
||||||
|
|
||||||
kfile.write("""// This file is auto-generated. Do not edit! |
|
||||||
|
|
||||||
namespace cv |
|
||||||
{ |
|
||||||
namespace ocl |
|
||||||
{ |
|
||||||
""") |
|
||||||
|
|
||||||
for cl in cl_list: |
|
||||||
cl_file = open(cl, "rt") |
|
||||||
cl_filename = os.path.basename(cl) |
|
||||||
cl_filename = cl_filename[:cl_filename.rfind(".")] |
|
||||||
kfile.write("const char* %s=" % cl_filename) |
|
||||||
state = 0 |
|
||||||
|
|
||||||
for cl_line in cl_file.readlines(): |
|
||||||
l = cl_line.strip() |
|
||||||
# skip the leading comments |
|
||||||
if l.startswith("//") and l.find("*/") < 0: |
|
||||||
if state == 0: |
|
||||||
state = 1 |
|
||||||
else: |
|
||||||
if state == 1 or l.find("*/") >= 0: |
|
||||||
state = 2 |
|
||||||
|
|
||||||
if state == 1: |
|
||||||
continue |
|
||||||
|
|
||||||
l = l.replace("\\", "\\\\") |
|
||||||
l = l.replace("\r", "") |
|
||||||
l = l.replace("\"", "\\\"") |
|
||||||
l = l.replace("\t", " ") |
|
||||||
kfile.write("\"%s\\n\"\n" % l) |
|
||||||
kfile.write(";\n") |
|
||||||
cl_file.close() |
|
||||||
|
|
||||||
kfile.write("""} |
|
||||||
} |
|
||||||
""") |
|
||||||
kfile.close() |
|
Loading…
Reference in new issue