parameters: (path, instructions, docs, filter_list,
                               inst_category, capability_mapping, settings)
docstring: Updates SPIRVOps.td with newly generated op definition.
  
    Arguments:
      - path: path to SPIRVOps.td
      - instructions: SPIR-V JSON grammar for all instructions
      - docs: SPIR-V HTML doc for all instructions
      - filter_list: a list containing new opnames to include
      - capability_mapping: mapping from duplicated capability symbols to the
                     canonicalized symbol chosen for SPIRVBase.td.
  
    Returns:
      - A string containing all the TableGen op definitions
docstring_summary: Updates SPIRVOps.td with newly generated op definition.
docstring_tokens: Updates SPIRVOps . td with newly generated op definition .
function: def update_td_op_definitions(path, instructions, docs, filter_list,
                               inst_category, capability_mapping, settings):
    """Updates SPIRVOps.td with newly generated op definition.
  
    Arguments:
      - path: path to SPIRVOps.td
      - instructions: SPIR-V JSON grammar for all instructions
      - docs: SPIR-V HTML doc for all instructions
      - filter_list: a list containing new opnames to include
      - capability_mapping: mapping from duplicated capability symbols to the
                     canonicalized symbol chosen for SPIRVBase.td.
  
    Returns:
      - A string containing all the TableGen op definitions
    """
    with open(path, 'r') as f:
      content = f.read()
  
    # Split the file into chunks, each containing one op.
    ops = content.split(AUTOGEN_OP_DEF_SEPARATOR)
    header = ops[0]
    footer = ops[-1]
    ops = ops[1:-1]
  
    # For each existing op, extract the manually-written sections out to retain
    # them when re-generating the ops. Also append the existing ops to filter
    # list.
    name_op_map = {}  # Map from opname to its existing ODS definition
    op_info_dict = {}
    for op in ops:
      info_dict = extract_td_op_info(op)
      opname = info_dict['opname']
      name_op_map[opname] = op
      op_info_dict[opname] = info_dict
      filter_list.append(opname)
    filter_list = sorted(list(set(filter_list)))
  
    op_defs = []
  
    if settings.gen_ocl_ops:
      fix_opname = lambda src: src.replace('OCL','').lower()
    else:
      fix_opname = lambda src: src
  
    for opname in filter_list:
      # Find the grammar spec for this op
      try:
        fixed_opname = fix_opname(opname)
        instruction = next(
            inst for inst in instructions if inst['opname'] == fixed_opname)
  
        op_defs.append(
            get_op_definition(
                instruction, opname, docs[fixed_opname],
                op_info_dict.get(opname, {'inst_category': inst_category}),
                capability_mapping, settings))
      except StopIteration:
        # This is an op added by us; use the existing ODS definition.
        op_defs.append(name_op_map[opname])
  
    # Substitute the old op definitions
    op_defs = [header] + op_defs + [footer]
    content = AUTOGEN_OP_DEF_SEPARATOR.join(op_defs)
  
    with open(path, 'w') as f:
      f.write(content)
function_tokens: def update_td_op_definitions ( path , instructions , docs , filter_list , inst_category , capability_mapping , settings ) : with open ( path , 'r' ) as f : content = f . read ( ) # Split the file into chunks, each containing one op. ops = content . split ( AUTOGEN_OP_DEF_SEPARATOR ) header = ops [ 0 ] footer = ops [ - 1 ] ops = ops [ 1 : - 1 ] # For each existing op, extract the manually-written sections out to retain # them when re-generating the ops. Also append the existing ops to filter # list. name_op_map = { } # Map from opname to its existing ODS definition op_info_dict = { } for op in ops : info_dict = extract_td_op_info ( op ) opname = info_dict [ 'opname' ] name_op_map [ opname ] = op op_info_dict [ opname ] = info_dict filter_list . append ( opname ) filter_list = sorted ( list ( set ( filter_list ) ) ) op_defs = [ ] if settings . gen_ocl_ops : fix_opname = lambda src : src . replace ( 'OCL' , '' ) . lower ( ) else : fix_opname = lambda src : src for opname in filter_list : # Find the grammar spec for this op try : fixed_opname = fix_opname ( opname ) instruction = next ( inst for inst in instructions if inst [ 'opname' ] == fixed_opname ) op_defs . append ( get_op_definition ( instruction , opname , docs [ fixed_opname ] , op_info_dict . get ( opname , { 'inst_category' : inst_category } ) , capability_mapping , settings ) ) except StopIteration : # This is an op added by us; use the existing ODS definition. op_defs . append ( name_op_map [ opname ] ) # Substitute the old op definitions op_defs = [ header ] + op_defs + [ footer ] content = AUTOGEN_OP_DEF_SEPARATOR . join ( op_defs ) with open ( path , 'w' ) as f : f . write ( content )