diff --git a/script/gen_ostream_ops.py b/script/gen_ostream_ops.py index f98a83b35b..38f7e757cd 100755 --- a/script/gen_ostream_ops.py +++ b/script/gen_ostream_ops.py @@ -76,7 +76,7 @@ HEADER = \ '\n' structs_done = {} -def process_struct(f,c,cppHeader,nname): +def process_struct(f,c,cppHeader,nname,apiname): if c not in cppHeader.classes: return @@ -104,9 +104,9 @@ def process_struct(f,c,cppHeader,nname): if mtype != "" and "union" not in mtype: if array_size == "": - str = " roctracer::kfd_support::output_streamer<"+mtype+">::put(out,v."+name+");\n" + str = " roctracer::" + apiname.lower() + "_support::output_streamer<"+mtype+">::put(out,v."+name+");\n" else: - str = " roctracer::kfd_support::output_streamer<"+mtype+"["+array_size+"]>::put(out,v."+name+");\n" + str = " roctracer::" + apiname.lower() + "_support::output_streamer<"+mtype+"["+array_size+"]>::put(out,v."+name+");\n" if nname != "" and nname not in str: #print("injecting ",nname, "in ", str) @@ -115,70 +115,79 @@ def process_struct(f,c,cppHeader,nname): f.write(str) else: nc = prop+"::" - process_struct(f,nc,cppHeader,name) + process_struct(f,nc,cppHeader,name,apiname) nc = prop+"::"+mtype+" " - process_struct(f,nc,cppHeader,name) + process_struct(f,nc,cppHeader,name,apiname) nc = c+"::" - process_struct(f,nc,cppHeader,name) + process_struct(f,nc,cppHeader,name,apiname) - -def gen_cppheader(infilepath,outfilepath): +def gen_cppheader(infilepath, outfilepath): try: cppHeader = CppHeaderParser.CppHeader(infilepath) except CppHeaderParser.CppParseError as e: print(e) sys.exit(1) - + mpath = os.path.dirname(outfilepath) + if mpath == "": + mpath = os.getcwd() + apiname = outfilepath.replace(mpath+"/","") + apiname = apiname.replace("_ostream_ops.h","") + apiname = apiname.upper() f = open(outfilepath,"w+") + f2 = open(mpath + "/basic_ostream_ops.h","w+") f.write("// automatically generated\n") - f.write(LICENSE) - f.write("\n") + f2.write("// automatically generated\n") + f.write(LICENSE + '\n') + f2.write(LICENSE + '\n') HEADER_S = \ - '#ifndef INC_KFD_OSTREAM_OPS_H_\n' + \ - '#define INC_KFD_OSTREAM_OPS_H_\n' + \ + '#ifndef INC_' + apiname + '_OSTREAM_OPS_H_\n' + \ + '#define INC_' + apiname + '_OSTREAM_OPS_H_\n' + \ '#include \n' + \ '\n' + \ - '#include "roctracer.h"\n' + \ - '#include "hsakmt.h"\n' + '#include "roctracer.h"\n' f.write(HEADER_S) f.write('\n') f.write('namespace roctracer {\n') - f.write('namespace kfd_support {\n') - f.write('// begin ostream ops for KFD \n') - f.write(HEADER) + f.write('namespace ' + apiname.lower() + '_support {\n') + f.write('// begin ostream ops for '+ apiname + ' \n') + f.write('#include "basic_ostream_ops.h"' + '\n') + f2.write(HEADER) for c in cppHeader.classes: if "union" in c: continue - f.write("\ntemplate<>\n") - f.write("struct output_streamer<"+c+"&> {\n") - f.write(" inline static std::ostream& put(std::ostream& out, "+c+"& v)\n") - f.write("{\n") - process_struct(f,c,cppHeader,"") - f.write(" return out;\n") - f.write("}\n") - f.write("};\n") + if len(cppHeader.classes[c]["properties"]["public"])!=0: + f.write("\ntemplate<>\n") + f.write("struct output_streamer<"+c+"&> {\n") + f.write(" inline static std::ostream& put(std::ostream& out, "+c+"& v)\n") + f.write("{\n") + process_struct(f,c,cppHeader,"",apiname) + f.write(" return out;\n") + f.write("}\n") + f.write("};\n") FOOTER = \ - '// end ostream ops for KFD \n' + '// end ostream ops for '+ apiname + ' \n' FOOTER += '};};\n' + \ '\n' + \ - '#endif // INC_KFD_OSTREAM_OPS_H_\n' + \ + '#endif // INC_' + apiname + '_OSTREAM_OPS_H_\n' + \ ' \n' FOOTER2 = '\n\n' + \ '#endif // INC_BASIC_OSTREAM_OPS_H_\n' + \ ' \n' f.write(FOOTER) - f.close() + f2.close() + print('File ' + outfilepath + ' generated') + print('File ' + mpath + '/basic_ostream_ops.h generated') + return parser = argparse.ArgumentParser(description='genOstreamOps.py: generates ostream operators for all typedefs in provided input file.') requiredNamed = parser.add_argument_group('Required arguments') -requiredNamed.add_argument('-in','--in', help='Header file to be parsed', required=True) -requiredNamed.add_argument('-out','--out', help='Output file with ostream operators', required=True) +requiredNamed.add_argument('-in', metavar='file', help='Header file to be parsed', required=True) +requiredNamed.add_argument('-out', metavar='file', help='Output file with ostream operators', required=True) args = vars(parser.parse_args()) if __name__ == '__main__': gen_cppheader(args['in'],args['out']) - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7a65896baa..cdbe606fe5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,7 +21,8 @@ set ( KFD_LIB "kfdwrapper64" ) set ( KFD_LIB_SRC ${LIB_DIR}/kfd/kfd_wrapper.cpp ) -execute_process ( COMMAND sh -xc "${ROOT_DIR}/script/gen_ostream_ops.py -in ${HSA_KMT_INC_PATH}/hsakmttypes.h -out ${ROOT_DIR}/inc/kfd_ostream_ops.h" ) +execute_process ( COMMAND sh -xc "gcc -E ${HSA_KMT_INC_PATH}/hsakmttypes.h > ${PROJECT_BINARY_DIR}/hsakmttypes_pp.h" ) +execute_process ( COMMAND sh -xc "${ROOT_DIR}/script/gen_ostream_ops.py -in ${PROJECT_BINARY_DIR}/hsakmttypes_pp.h -out ${ROOT_DIR}/inc/kfd_ostream_ops.h" ) add_library ( ${KFD_LIB} SHARED ${KFD_LIB_SRC} ) target_include_directories ( ${KFD_LIB} PRIVATE ${LIB_DIR} ${ROOT_DIR} ${ROOT_DIR}/inc ${HSA_RUNTIME_INC_PATH} ${HSA_RUNTIME_HSA_INC_PATH} ${HSA_KMT_INC_PATH} ) target_link_libraries( ${KFD_LIB} PRIVATE c stdc++ )