rodata2asm.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import os
  2. import argparse
  3. def main():
  4. parser = argparse.ArgumentParser(description='Convert rodata into asm source with embedded file content')
  5. parser.add_argument('symbol', help='symvol name exported from generated filr')
  6. parser.add_argument('rodata', help='input .rodata file path')
  7. parser.add_argument('asm', type=argparse.FileType('w', encoding='UTF-8'), help='destination .asm file path')
  8. parser.add_argument('--elf', action='store_true')
  9. args = parser.parse_args()
  10. file_size = os.path.getsize(args.rodata)
  11. args.asm.write('global ' + args.symbol + '\n')
  12. args.asm.write('global ' + args.symbol + 'Size' + '\n')
  13. args.asm.write('SECTION .rodata ALIGN=16\n')
  14. args.asm.write(args.symbol + ':\nincbin "' + args.rodata + '"\n')
  15. args.asm.write('align 4, db 0\n')
  16. args.asm.write(args.symbol + 'Size:\ndd ' + str(file_size) + '\n')
  17. if args.elf:
  18. args.asm.write('size ' + args.symbol + ' ' + str(file_size) + '\n')
  19. args.asm.write('size ' + args.symbol + 'Size 4\n')
  20. args.asm.close()
  21. if __name__ == '__main__':
  22. main()