aboutsummaryrefslogtreecommitdiff
path: root/src/tools/mkgenome.c
blob: bb2e78793daaf0ac00b5f807d01865aa6d867ccf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* turns a genome image (little-endian 64-bit words on stdin, as written by
   src/tools/build.zc) into genome.h */
#include <stdio.h>
#include <stdint.h>
#ifdef _WIN32
#include <fcntl.h>
#include <io.h>
#endif
#include "memmap.h"
int main(void)
{
#ifdef _WIN32
	_setmode(_fileno(stdin), _O_BINARY);
	_setmode(_fileno(stdout), _O_BINARY);
#endif
	unsigned char b[8]; int n = 0; size_t got;
	printf("#define GORG %d\nstatic const int64_t genome[] = {", GORG);
	while ((got = fread(b, 1, 8, stdin)) == 8) {
		uint64_t u = (uint64_t)b[0] | (uint64_t)b[1] << 8 | (uint64_t)b[2] << 16 | (uint64_t)b[3] << 24
			| (uint64_t)b[4] << 32 | (uint64_t)b[5] << 40 | (uint64_t)b[6] << 48 | (uint64_t)b[7] << 56;
		if ((n == 0 && u != (uint64_t)FTOP * 2 + 1) ||
		    (n == 1 && u != (uint64_t)ZFP * 2 + 1) || (n == 2 && u != 4)) {
			fprintf(stderr, "mkgenome: input is not a genome for this map\n"); return 1;
		}
		printf("%s%lld", !n ? "\n" : n % 12 ? "," : ",\n", (long long)u);
		n++;
	}
	if (got || ferror(stdin) || n < 7) { fprintf(stderr, "mkgenome: incomplete genome\n"); return 1; }
	printf("\n};\n#define GLEN %d\n", n);
	return n ? 0 : 1;
}