original_docstring: 
      Change checklist before measuring coverage
      None, as objdump & func_dump is already generated by inst_cov
      
docstring: Change checklist before measuring coverage
  None, as objdump & func_dump is already generated by inst_cov
docstring_tokens: Change checklist before measuring coverage None as objdump & func_dump is already generated by inst_cov
code: def func_cov(cfg):
      '''
      Change checklist before measuring coverage
      None, as objdump & func_dump is already generated by inst_cov
      '''
  
      ## read in input from files
      # {int(addr): str(func_name)}, sorted by addr
      ft = {}
      # generated by:
      # arm-none-eabi-objdump -Cd BUILD/NUCLEO_F103RB/GCC_ARM/mbed.elf > objdump3
      # grep '<.*>:' objdump3 > func_dump
      # f is in format of 'addr name\n'
      print('Reading func_dump...')
      with open('func_dump') as f:
          for l in f:
              l = l.replace(':\n','')
              if '\t' in l:
                  # exclude ' 80006ca:    f000 fd94     bl    80011f6 <mbed::Callback<void ()>::Callback(void (*)())>'
                  continue
              (addr, name) = l.split(' ',1)
              ft[int(addr, 16)] = name[1:-1]
      # XXX: actually unnecessary as last few labels are actual data
      #text_end_addr = 0x8016fd4
      #ft[text_end_addr] = ".text_end"
  
      # {int(addr): int(hit_no)}, sorted by addr
      ic = {}
      # generated by inst_cov.py
      # f is printed by pprint from a dict
      print('Reading %s ...' % "inst_cov_w_boot" if cfg.count_boot_code else "inst_cov")
      with open("inst_cov_w_boot" if cfg.count_boot_code else "inst_cov") as f:
          for l in f:
              l = l.replace('{','').replace('}','').replace(',','') \
                  .replace('\'','').replace('\n','')
              (addr, cnt) = l.split(': ')
              ic[int(addr, 16)] = int(cnt)
      #print (ft)
      #print (ic)
  
  
      ## output
      # merge of func_dump and inst_cov by the order of addr
      # {}
      merge = {}
      # {func_name: True|False}
      func_cov = {}
  
      ## linear scan and merge
      i = 0
      j = 0
      ft_ks = sorted(ft.keys())
      ic_ks = sorted(ic.keys())
  
      print('linear scan and merge...')
      while i < len(ft)-1:
          ft_k = hex(ft_ks[i]) # hex str
          ft_v = ft[ft_ks[i]] # cannot directly use ft_k, a hex str
  
          merge[ft_k] = (ft_v, None)
          func_cov[ft_k] = (ft_v, False)
  
          while j < len(ic) and ic_ks[j] < ft_ks[i+1]:
              ic_k = hex(ic_ks[j]) # hex str
              ic_v = ic[ic_ks[j]] # cannot directly use ic_k, a hex str
  
              if ic_k not in list(merge.keys()):
                  merge[ic_k] = (None, ic_v) # or use (func_name, ic_v)
              else:
                  merge[ic_k] = (merge[ic_k][0], ic_v)
              func_cov[ft_k] = (ft_v, True)
              j += 1
          i += 1
  
      print('ouput to func_cov and func_cov_merge...')
      with open("func_cov_merge_w_boot" if cfg.count_boot_code else "func_cov_merge", "w") as f:
          #pickle.dump(merge, f)
          pprint(merge, stream=f)
      with open("func_cov_w_boot" if cfg.count_boot_code else "func_cov", "w") as f:
          # statistics
          # cal fun cov (percent)
          t = [ts[1] for ts in list(func_cov.values()) if ts[1] is True]
          f.write("Function coverage: %d/%d = %.2f%%\n\n" % (len(t), len(func_cov),
              len(t)*100.0/len(func_cov)))
  
          #pickle.dump(func_cov,f)
          pprint(func_cov,stream=f)
  
      print('Done')
code_tokens: def func_cov ( cfg ) : ft = { } print ( 'Reading func_dump...' ) with open ( 'func_dump' ) as f : for l in f : l = l . replace ( ':\n' , '' ) if '\t' in l : continue ( addr , name ) = l . split ( ' ' , 1 ) ft [ int ( addr , 16 ) ] = name [ 1 : - 1 ] ic = { } print ( 'Reading %s ...' % "inst_cov_w_boot" if cfg . count_boot_code else "inst_cov" ) with open ( "inst_cov_w_boot" if cfg . count_boot_code else "inst_cov" ) as f : for l in f : l = l . replace ( '{' , '' ) . replace ( '}' , '' ) . replace ( ',' , '' ) . replace ( '\'' , '' ) . replace ( '\n' , '' ) ( addr , cnt ) = l . split ( ': ' ) ic [ int ( addr , 16 ) ] = int ( cnt ) merge = { } func_cov = { } i = 0 j = 0 ft_ks = sorted ( ft . keys ( ) ) ic_ks = sorted ( ic . keys ( ) ) print ( 'linear scan and merge...' ) while i < len ( ft ) - 1 : ft_k = hex ( ft_ks [ i ] ) ft_v = ft [ ft_ks [ i ] ] merge [ ft_k ] = ( ft_v , None ) func_cov [ ft_k ] = ( ft_v , False ) while j < len ( ic ) and ic_ks [ j ] < ft_ks [ i + 1 ] : ic_k = hex ( ic_ks [ j ] ) ic_v = ic [ ic_ks [ j ] ] if ic_k not in list ( merge . keys ( ) ) : merge [ ic_k ] = ( None , ic_v ) else : merge [ ic_k ] = ( merge [ ic_k ] [ 0 ] , ic_v ) func_cov [ ft_k ] = ( ft_v , True ) j += 1 i += 1 print ( 'ouput to func_cov and func_cov_merge...' ) with open ( "func_cov_merge_w_boot" if cfg . count_boot_code else "func_cov_merge" , "w" ) as f : pprint ( merge , stream = f ) with open ( "func_cov_w_boot" if cfg . count_boot_code else "func_cov" , "w" ) as f : t = [ ts [ 1 ] for ts in list ( func_cov . values ( ) ) if ts [ 1 ] is True ] f . write ( "Function coverage: %d/%d = %.2f%%\n\n" % ( len ( t ) , len ( func_cov ) , len ( t ) * 100.0 / len ( func_cov ) ) ) pprint ( func_cov , stream = f ) print ( 'Done' )
short_docstring: Change checklist before measuring coverage
  None, as objdump & func_dump is already generated by inst_cov
short_docstring_tokens: Change checklist before measuring coverage None as objdump & func_dump is already generated by inst_cov
comment: '''
      Change checklist before measuring coverage
      None, as objdump & func_dump is already generated by inst_cov
      '''$SEP$## read in input from files$SEP$# {int(addr): str(func_name)}, sorted by addr$SEP$# generated by:$SEP$# arm-none-eabi-objdump -Cd BUILD/NUCLEO_F103RB/GCC_ARM/mbed.elf > objdump3$SEP$# grep '<.*>:' objdump3 > func_dump$SEP$# f is in format of 'addr name\n'$SEP$# exclude ' 80006ca:    f000 fd94     bl    80011f6 <mbed::Callback<void ()>::Callback(void (*)())>'$SEP$# XXX: actually unnecessary as last few labels are actual data$SEP$#text_end_addr = 0x8016fd4$SEP$#ft[text_end_addr] = ".text_end"$SEP$# {int(addr): int(hit_no)}, sorted by addr$SEP$# generated by inst_cov.py$SEP$# f is printed by pprint from a dict$SEP$#print (ft)$SEP$#print (ic)$SEP$## output$SEP$# merge of func_dump and inst_cov by the order of addr$SEP$# {}$SEP$# {func_name: True|False}$SEP$## linear scan and merge$SEP$# hex str$SEP$# cannot directly use ft_k, a hex str$SEP$# hex str$SEP$# cannot directly use ic_k, a hex str$SEP$# or use (func_name, ic_v)$SEP$#pickle.dump(merge, f)$SEP$# statistics$SEP$# cal fun cov (percent)$SEP$#pickle.dump(func_cov,f)