diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-24 11:57:50 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-24 11:57:50 +0300 |
commit | a2138eb93b9a5e4ad182dcad2059481e7d9f6eb3 (patch) | |
tree | ead16940c656314ae75441a38c4f738ee741c081 /build/scripts | |
parent | 6c7158b24a08e281736dee81a9fe98146982d58b (diff) | |
download | ydb-a2138eb93b9a5e4ad182dcad2059481e7d9f6eb3.tar.gz |
intermediate changes
ref:38621335ecd9e555f527a1d0da589e6042d8f9d1
Diffstat (limited to 'build/scripts')
-rw-r--r-- | build/scripts/rodata2asm.py | 31 | ||||
-rw-r--r-- | build/scripts/rodata2cpp.py | 34 |
2 files changed, 65 insertions, 0 deletions
diff --git a/build/scripts/rodata2asm.py b/build/scripts/rodata2asm.py new file mode 100644 index 0000000000..555639499f --- /dev/null +++ b/build/scripts/rodata2asm.py @@ -0,0 +1,31 @@ +import os +import argparse + + +def main(): + parser = argparse.ArgumentParser(description='Convert rodata into asm source with embedded file content') + parser.add_argument('symbol', help='symvol name exported from generated filr') + parser.add_argument('rodata', help='input .rodata file path') + parser.add_argument('asm', type=argparse.FileType('w', encoding='UTF-8'), help='destination .asm file path') + parser.add_argument('--elf', action='store_true') + + args = parser.parse_args() + + file_size = os.path.getsize(args.rodata) + + args.asm.write('global ' + args.symbol + '\n') + args.asm.write('global ' + args.symbol + 'Size' + '\n') + args.asm.write('SECTION .rodata ALIGN=16\n') + args.asm.write(args.symbol + ':\nincbin "' + args.rodata + '"\n') + args.asm.write('align 4, db 0\n') + args.asm.write(args.symbol + 'Size:\ndd ' + str(file_size) + '\n') + + if args.elf: + args.asm.write('size ' + args.symbol + ' ' + str(file_size) + '\n') + args.asm.write('size ' + args.symbol + 'Size 4\n') + + args.asm.close() + + +if __name__ == '__main__': + main() diff --git a/build/scripts/rodata2cpp.py b/build/scripts/rodata2cpp.py new file mode 100644 index 0000000000..be67d3af53 --- /dev/null +++ b/build/scripts/rodata2cpp.py @@ -0,0 +1,34 @@ +import argparse + + +def main(): + parser = argparse.ArgumentParser(description='Convert rodata into C++ source with embedded file content') + parser.add_argument('symbol', help='symbol name exported from generated file') + parser.add_argument('rodata', type=argparse.FileType('rb'), help='input .rodata file path') + parser.add_argument('cpp', type=argparse.FileType('w', encoding='UTF-8'), help='destination .cpp file path') + + args = parser.parse_args() + args.cpp.write('static_assert(sizeof(unsigned int) == 4, "ups, something gone wrong");\n\n') + args.cpp.write('extern "C" {\n') + args.cpp.write(' extern const unsigned char ' + args.symbol + '[] = {\n') + + cnt = 0 + + for ch in args.rodata.read(): + args.cpp.write('0x%02x, ' % ch) + + cnt += 1 + + if cnt % 50 == 1: + args.cpp.write('\n') + + args.cpp.write(' };\n') + args.cpp.write(' extern const unsigned int ' + args.symbol + 'Size = sizeof(' + args.symbol + ');\n') + args.cpp.write('}\n') + + args.rodata.close() + args.cpp.close() + + +if __name__ == '__main__': + main() |