(data_files)
| 255 | |
| 256 | |
| 257 | def generate_object_file(data_files): |
| 258 | embed_files = [f for f in data_files if f.mode == 'embed'] |
| 259 | assert embed_files |
| 260 | |
| 261 | asm_file = utils.replace_suffix(options.obj_output, '.s') |
| 262 | |
| 263 | used = set() |
| 264 | for f in embed_files: |
| 265 | f.c_symbol_name = '__em_file_data_%s' % to_c_symbol(f.dstpath, used) |
| 266 | |
| 267 | with open(asm_file, 'w', encoding='utf-8') as out: |
| 268 | out.write('# Emscripten embedded file data, generated by tools/file_packager.py\n') |
| 269 | |
| 270 | for f in embed_files: |
| 271 | if DEBUG: |
| 272 | err('embedding %s at %s' % (f.srcpath, f.dstpath)) |
| 273 | |
| 274 | size = os.path.getsize(f.srcpath) |
| 275 | dstpath = to_asm_string(f.dstpath) |
| 276 | srcpath = utils.normalize_path(f.srcpath) |
| 277 | out.write(dedent(f''' |
| 278 | .section .rodata.{f.c_symbol_name},"",@ |
| 279 | |
| 280 | # The name of file |
| 281 | {f.c_symbol_name}_name: |
| 282 | .asciz "{dstpath}" |
| 283 | .size {f.c_symbol_name}_name, {len(dstpath) + 1} |
| 284 | |
| 285 | # The size of the file followed by the content itself |
| 286 | {f.c_symbol_name}: |
| 287 | .incbin "{srcpath}" |
| 288 | .size {f.c_symbol_name}, {size} |
| 289 | ''')) |
| 290 | |
| 291 | if options.wasm64: |
| 292 | align = 3 |
| 293 | ptr_type = 'i64' |
| 294 | bits = 64 |
| 295 | else: |
| 296 | align = 2 |
| 297 | ptr_type = 'i32' |
| 298 | bits = 32 |
| 299 | out.write(dedent(f''' |
| 300 | .functype _emscripten_fs_load_embedded_files ({ptr_type}) -> () |
| 301 | .section .text,"",@ |
| 302 | init_file_data: |
| 303 | .functype init_file_data () -> () |
| 304 | global.get __emscripten_embedded_file_data@GOT |
| 305 | call _emscripten_fs_load_embedded_files |
| 306 | end_function |
| 307 | |
| 308 | # Run init_file_data on startup. |
| 309 | # See system/lib/README.md for ordering of system constructors. |
| 310 | .section .init_array.49,"",@ |
| 311 | .p2align {align} |
| 312 | .int{bits} init_file_data |
| 313 | |
| 314 | # A list of triples of: |
no test coverage detected