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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
const fs = require('fs');
const path = require('path');
const srcPath = path.join(__dirname, '..', 'core', 'genome.h');
const outPath = path.join(__dirname, 'genome.json');
const text = fs.readFileSync(srcPath, 'utf8');
const gorgMatch = text.match(/#define\s+GORG\s+(\d+)/);
const glenMatch = text.match(/#define\s+GLEN\s+(\d+)/);
const gorg = parseInt(gorgMatch[1], 10);
const glen = parseInt(glenMatch[1], 10);
const arrMatch = text.match(/genome\[\]\s*=\s*\{([\s\S]*?)\};/);
if (!arrMatch) {
console.error('Could not find genome array in genome.h');
process.exit(1);
}
const words = arrMatch[1]
.split(',')
.map(s => s.trim())
.filter(s => s.length > 0)
.map(s => s); // keep as string numbers
console.log(`Parsed genome: GORG=${gorg}, GLEN=${words.length}`);
if (words.length !== glen) throw new Error('genome length does not match GLEN');
// the compiler's map, from src/core/memmap.h, as typescript constants: the js vm reads
// them instead of its own copies. the values are computed here, from the map.
const { mapValues } = require('./mapvalues.js');
const names = ['MW', 'PW', 'ZFP', 'GORG', 'DS0', 'DSLIM', 'RS0', 'RSLIM', 'SYSGATE', 'HEAP_LO', 'HEAP_HI'];
const map = mapValues(path.join(__dirname, '..', 'core', 'memmap.h'), names);
if (map.GORG !== gorg) throw new Error('genome GORG ' + gorg + ' is not the map GORG ' + map.GORG);
fs.writeFileSync(outPath, JSON.stringify({ gorg, glen, words }));
console.log(`saved genome to ${outPath}`);
const lines = names.map(k => ` ${k}: ${map[k]},`).join('\n');
fs.writeFileSync(path.join(__dirname, 'layout.ts'),
'// generated by src/js/extract_genome.js from src/core/memmap.h. do not edit.\n' +
'export const MAP = {\n' + lines + '\n} as const;\n');
console.log(`Saved the map to ${path.join(__dirname, 'layout.ts')}`);
fs.writeFileSync(path.join(__dirname, 'layout.js'),
'// generated by src/js/extract_genome.js from src/core/memmap.h. do not edit.\n' +
'exports.MAP = ' + JSON.stringify(map, null, 4) + ';\n');
|