#!/usr/bin/env python3 # documentation precedes the symbol table; the boot header must skip those bytes. import pathlib import re source = pathlib.Path('src/core/genome.h').read_text() org = int(re.search(r'#define GORG (\d+)', source)[1]) length = int(re.search(r'#define GLEN (\d+)', source)[1]) words = [int(word.strip()) for word in re.search(r'genome\[\]\s*=\s*\{([\s\S]*?)\};', source)[1].split(',') if word.strip()] assert len(words) == length and words[6] == org + length cursor = words[5] - org assert 7 <= cursor < length records = {} while words[cursor]: kind, value, signature = words[cursor:cursor + 3] assert kind in (1, 2, 3, 4, 6, 8), (cursor, kind) cursor += 3 name = '' while words[cursor]: assert 0 < words[cursor] < 128, (cursor, words[cursor]) name += chr(words[cursor]) cursor += 1 cursor += 1 records[name] = (kind, value, signature) assert cursor == length - 1 assert len(records) > 1000 and records['start'][0] == 1 assert records['reserve_code'][0] == 1 and records['build_image_grow'][0] == 1 assert any(name.startswith('doc ') for name in records), 'the fixture contains documentation bytes' for name, (kind, value, _) in records.items(): if kind == 8: assert org <= value < org + length and words[value - org] >= 0, name print('ok documented genome starts its symbol table at the header address')