MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / add_handle

Function add_handle

tools/api.py:896–946  ·  view source on GitHub ↗
(name: str,
               ctype: str,
               cpptype: str,
               destroy: Optional[str] = None,
               ref=False,
               skip_def=False)

Source from the content-addressed store, hash-verified

894
895
896def add_handle(name: str,
897 ctype: str,
898 cpptype: str,
899 destroy: Optional[str] = None,
900 ref=False,
901 skip_def=False) -> None:
902 opaque_type = ctype + '_t'
903 const_opaque_type = 'const_' + opaque_type
904
905 def handle_wrap(p: Parameter):
906 t = Type(opaque_type)
907 if p.type.is_const():
908 t = Type('const_' + opaque_type)
909 # p.read = 'object_cast<${ctype}>(&(${name}))'
910 if p.virtual:
911 p.add_param(t)
912 elif p.returns:
913 p.add_param(t.add_pointer())
914 else:
915 p.add_param(t)
916 p.bad_param('${name} == nullptr', 'Null pointer')
917 if p.type.is_reference():
918 p.virtual_read = ['object_cast<${ctype}>(&(${name}))']
919 p.cpp_write = '${cpptype}(${name}, false)'
920 p.write = ['*${name} = object_cast<${ctype}>(&(${result}))']
921 elif p.type.is_pointer():
922 p.virtual_read = ['object_cast<${ctype}>(${result})']
923 p.cpp_write = '${cpptype}(${name}, false)'
924 p.write = ['*${name} = object_cast<${ctype}>(${result})']
925 else:
926 p.virtual_read = ['object_cast<${ctype}>(&(${name}))']
927 p.cpp_write = '${cpptype}(${name})'
928 p.write = ['*${name} = allocate<${ctype}>(${result})']
929 if skip_def:
930 p.read = '*${name}'
931 else:
932 p.read = '${name}->object'
933 p.cpp_read = '${name}.get_handle_ptr()'
934
935 type_map[cpptype] = handle_wrap
936 if not ref:
937 add_function(destroy or ctype + '_' + 'destroy',
938 params({name: opaque_type}),
939 fname='destroy')
940 add_function(ctype + '_' + 'assign_to',
941 params(output=opaque_type, input=const_opaque_type),
942 invoke='*output = *input')
943 add_handle_preamble()
944 c_header_preamble.append(handle_typedef.substitute(locals()))
945 if not skip_def:
946 c_api_body_preamble.append(handle_definition.substitute(locals()))
947
948
949@cwrap('std::vector')

Callers 1

__init__Method · 0.85

Calls 5

add_functionFunction · 0.85
add_handle_preambleFunction · 0.85
paramsFunction · 0.70
appendMethod · 0.45
substituteMethod · 0.45

Tested by

no test coverage detected