-
Notifications
You must be signed in to change notification settings - Fork 0
/
ADIDSPMemoryMap.js
49 lines (46 loc) · 1.63 KB
/
ADIDSPMemoryMap.js
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
46
47
48
49
const { ADIMemorySegment } = require('./ADIMemorySegment');
const fs = require('fs');
const parse = require('xml-parser');
class ADIDSPMemoryMap {
fullname = null;
filename = null;
processor = null;
cores = null;
memoryRegions = new Array();
constructor(mapfile) {
/* Parse an entire ADI XML memory map
** to build up a profile of a processor.
*/
var xml = fs.readFileSync(mapfile, 'utf8');
var obj = parse(xml);
try {
this.fullname = mapfile;
this.filename = obj.root.attributes.name;
this.processor = this.filename.replace(/-arm-memory.xml/g, '');
var schemaVersion = obj.root.attributes["schema-version"];
if (schemaVersion != 1) {
throw new Error("Unsupported schema version");
}
var memoryFound = false;
obj.root.children.forEach(child => {
if (child.name == "memory-definitions") {
memoryFound = true;
child.children.forEach(seg => {
if (seg.name == "memory-segment") {
this.memoryRegions.push(new ADIMemorySegment(seg));
}
})
}
})
if (!memoryFound) {
throw new Error("Failed to find memory definition");
}
}
catch (err) {
console.error("Error: " + mapfile + " is malformed");
console.error(err);
throw new Error("Could not parse XML file: "+mapfile);
}
}
};
module.exports = { ADIDSPMemoryMap };