parameters: (path, operand_kinds, filter_list)
docstring: Updates SPIRBase.td with new generated enum definitions.
  
    Arguments:
      - path: the path to SPIRBase.td
      - operand_kinds: a list containing all operand kinds' grammar
      - filter_list: a list containing new enums to add
docstring_summary: Updates SPIRBase.td with new generated enum definitions.
docstring_tokens: Updates SPIRBase . td with new generated enum definitions .
function: def update_td_enum_attrs(path, operand_kinds, filter_list):
    """Updates SPIRBase.td with new generated enum definitions.
  
    Arguments:
      - path: the path to SPIRBase.td
      - operand_kinds: a list containing all operand kinds' grammar
      - filter_list: a list containing new enums to add
    """
    with open(path, 'r') as f:
      content = f.read()
  
    content = content.split(AUTOGEN_ENUM_SECTION_MARKER)
    assert len(content) == 3
  
    # Extend filter list with existing enum definitions
    existing_kinds = [
        k[8:-4] for k in re.findall('def SPV_\w+Attr', content[1])]
    filter_list.extend(existing_kinds)
  
    capability_mapping = get_capability_mapping(operand_kinds)
  
    # Generate definitions for all enums in filter list
    defs = [
        gen_operand_kind_enum_attr(kind, capability_mapping)
        for kind in operand_kinds
        if kind['kind'] in filter_list
    ]
    # Sort alphabetically according to enum name
    defs.sort(key=lambda enum : enum[0])
    # Only keep the definitions from now on
    # Put Capability's definition at the very beginning because capability cases
    # will be referenced later
    defs = [enum[1] for enum in defs if enum[0] == 'Capability'
           ] + [enum[1] for enum in defs if enum[0] != 'Capability']
  
    # Substitute the old section
    content = content[0] + AUTOGEN_ENUM_SECTION_MARKER + '\n\n' + \
        '\n\n'.join(defs) + "\n\n// End " + AUTOGEN_ENUM_SECTION_MARKER  \
        + content[2];
  
    with open(path, 'w') as f:
      f.write(content)
function_tokens: def update_td_enum_attrs ( path , operand_kinds , filter_list ) : with open ( path , 'r' ) as f : content = f . read ( ) content = content . split ( AUTOGEN_ENUM_SECTION_MARKER ) assert len ( content ) == 3 # Extend filter list with existing enum definitions existing_kinds = [ k [ 8 : - 4 ] for k in re . findall ( 'def SPV_\w+Attr' , content [ 1 ] ) ] filter_list . extend ( existing_kinds ) capability_mapping = get_capability_mapping ( operand_kinds ) # Generate definitions for all enums in filter list defs = [ gen_operand_kind_enum_attr ( kind , capability_mapping ) for kind in operand_kinds if kind [ 'kind' ] in filter_list ] # Sort alphabetically according to enum name defs . sort ( key = lambda enum : enum [ 0 ] ) # Only keep the definitions from now on # Put Capability's definition at the very beginning because capability cases # will be referenced later defs = [ enum [ 1 ] for enum in defs if enum [ 0 ] == 'Capability' ] + [ enum [ 1 ] for enum in defs if enum [ 0 ] != 'Capability' ] # Substitute the old section content = content [ 0 ] + AUTOGEN_ENUM_SECTION_MARKER + '\n\n' + '\n\n' . join ( defs ) + "\n\n// End " + AUTOGEN_ENUM_SECTION_MARKER + content [ 2 ] with open ( path , 'w' ) as f : f . write ( content )