-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructures.js
82 lines (73 loc) · 2.67 KB
/
structures.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"use strict";
function structures_map()
{
// search for each structure in all the files
// build the content of the structure
for (let struct in debug_info.structures) {
let found = false
for (let fileID in debug_info.files) {
let lines = debug_info.files[fileID].text
let foundStruct = false
for (let i in lines) {
let l = lines[i].toLowerCase()
if (!foundStruct) {
if (l.indexOf(".struct") >= 0) {
if (l.indexOf(struct) >= 0) {
foundStruct = true
}
}
}
else {
if (l.indexOf(".endstruct") >= 0) {
foundStruct = false
found = true
break
}
else {
// split the line to extract (spaces)attribute_name(spaces)type
let re = /[ \t]*(\w*)[ \t]+(\.\w*)/i
let m = l.match(re)
if (m) {
let attr = {"name": m[1], "size": m[2], "index": 0}
if (m[2] == ".tag" || m[2] == ".TAG") {
re = /[ \t]*(\w*)[ \t]+(\.\w*)[ \t]+(\w*)/i
m = l.match(re)
if (m) {
attr.size = m[3]
}
}
debug_info.structures[struct].attributes.push(attr)
}
}
}
}
if (found) {
break // structure found in the current file, so move to the next file
}
}
}
// for each structure build the memory map
for (let struct in debug_info.structures) {
let memory = 0
for (let i in debug_info.structures[struct].attributes) {
debug_info.structures[struct].attributes[i].index = memory
let ssize = debug_info.structures[struct].attributes[i].size
let size = 0
switch (ssize) {
case ".byte":
size = 1
break
case ".word":
case ".addr":
size = 2
break
case ".res":
console.log("not implemented .RES")
break;
default:
size = debug_info.structures[ssize].size
}
memory += size
}
}
}