a2-memory-map 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +56 -0
- package/Cargo.lock +106 -0
- package/Cargo.toml +19 -0
- package/README-crate.md +84 -0
- package/README.md +25 -9
- package/bindings/rust/lib.rs +278 -0
- package/build/index.js +86 -45
- package/build/index.js.map +1 -0
- package/build/map.json +336 -136
- package/build/map.schema.json +39 -0
- package/build/vendors.json +263 -0
- package/build/vendors.schema.json +28 -0
- package/build.rs +154 -0
- package/package.json +7 -7
- package/src/index.ts +99 -19
- package/src/map.json +336 -136
- package/src/map.schema.json +39 -0
- package/src/vendors.json +263 -0
- package/src/vendors.schema.json +28 -0
- package/tsconfig.json +12 -107
- package/build/index.d.ts +0 -25
package/build/index.js
CHANGED
|
@@ -1,30 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
|
|
6
|
+
exports.get_all = get_all;
|
|
7
|
+
exports.get_one = get_one;
|
|
8
|
+
exports.get_one_and_split = get_one_and_split;
|
|
9
|
+
exports.get_vendor_docstring = get_vendor_docstring;
|
|
10
|
+
exports.get_vendor_name = get_vendor_name;
|
|
11
|
+
exports.get_vendor_ctx = get_vendor_ctx;
|
|
12
|
+
const map_json_1 = __importDefault(require("./map.json"));
|
|
13
|
+
const vendors_json_1 = __importDefault(require("./vendors.json"));
|
|
14
|
+
function formatHex16(addr) {
|
|
15
|
+
// AI states that masking with 0xffff cleanly wraps negative numbers and truncates >16-bit values
|
|
16
|
+
const u16 = addr & 0xffff;
|
|
17
|
+
return `0x${u16.toString(16).padStart(4, '0')}`;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Converts a raw JSON object with hex keys into a normalized Map, ignoring $schema.
|
|
21
|
+
* This takes care of case sensitivity and gives us type checking.
|
|
22
|
+
*/
|
|
23
|
+
function createHexMap(rawJson) {
|
|
24
|
+
const map = new Map();
|
|
25
|
+
if (!rawJson || typeof rawJson !== 'object') {
|
|
26
|
+
return map;
|
|
27
|
+
}
|
|
28
|
+
for (const [key, value] of Object.entries(rawJson)) {
|
|
29
|
+
if (key === '$schema') {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const numericAddr = Number.parseInt(key, 16);
|
|
33
|
+
if (!Number.isNaN(numericAddr) && value && typeof value === 'object') {
|
|
34
|
+
map.set(formatHex16(numericAddr), value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return map;
|
|
38
|
+
}
|
|
39
|
+
const infoMap = createHexMap(map_json_1.default);
|
|
40
|
+
const vendorMap = createHexMap(vendors_json_1.default);
|
|
28
41
|
function get_contextual_str(str, count) {
|
|
29
42
|
const contexts = str.split('|');
|
|
30
43
|
if (count < contexts.length)
|
|
@@ -51,36 +64,20 @@ function get_contextual_info(info, count) {
|
|
|
51
64
|
};
|
|
52
65
|
}
|
|
53
66
|
/**
|
|
54
|
-
*
|
|
55
|
-
* @returns
|
|
67
|
+
* Get the whole map of AddressInfo objects.
|
|
68
|
+
* @returns shallow copy of the internal map.
|
|
56
69
|
*/
|
|
57
70
|
function get_all() {
|
|
58
|
-
|
|
59
|
-
for (const [key, obj] of Object.entries(memmap)) {
|
|
60
|
-
m.set(key, {
|
|
61
|
-
brief: 'brief' in obj ? obj.brief : undefined,
|
|
62
|
-
ctx: 'ctx' in obj ? obj.ctx : undefined,
|
|
63
|
-
desc: obj.desc,
|
|
64
|
-
label: 'label' in obj ? obj.label : undefined,
|
|
65
|
-
note: 'note' in obj ? obj.note : undefined,
|
|
66
|
-
subctx: 'subctx' in obj ? obj.subctx : undefined,
|
|
67
|
-
type: obj.type
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
return m;
|
|
71
|
+
return new Map(infoMap);
|
|
71
72
|
}
|
|
72
|
-
exports.get_all = get_all;
|
|
73
73
|
/**
|
|
74
74
|
* Get data for one address
|
|
75
75
|
* @param addr address in the range -32767 to 65535
|
|
76
76
|
* @returns AddressInfo object or undefined. Fields may contain logic operators.
|
|
77
77
|
*/
|
|
78
78
|
function get_one(addr) {
|
|
79
|
-
|
|
80
|
-
const hex = '0x' + pos_addr.toString(16).padStart(4, '0');
|
|
81
|
-
return Object(memmap)[hex];
|
|
79
|
+
return infoMap.get(formatHex16(addr));
|
|
82
80
|
}
|
|
83
|
-
exports.get_one = get_one;
|
|
84
81
|
/**
|
|
85
82
|
* Get data for one address and split by context
|
|
86
83
|
* @param addr Array of AddressInfo objects, one for each context, or undefined
|
|
@@ -103,4 +100,48 @@ function get_one_and_split(addr) {
|
|
|
103
100
|
}
|
|
104
101
|
return undefined;
|
|
105
102
|
}
|
|
106
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Get vendor's docstring from the map of entry points
|
|
105
|
+
* @param addr address of the entry point
|
|
106
|
+
* @param ctx optionally restrict the results to a given context
|
|
107
|
+
* @param vendor optionally restrict the results to a specific vendor
|
|
108
|
+
* @returns docstring
|
|
109
|
+
*/
|
|
110
|
+
function get_vendor_docstring(addr, ctx, vendor) {
|
|
111
|
+
const obj = vendorMap.get(formatHex16(addr));
|
|
112
|
+
if (!obj) {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
if (ctx !== undefined && obj.ctx !== ctx) {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
if (vendor !== undefined && obj.vendor !== vendor) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
return obj.docstr.join('\n');
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get the name of the vendor providing a docstring for the given address
|
|
125
|
+
* @param addr address of the entry point
|
|
126
|
+
* @returns name of vendor providing this docstring
|
|
127
|
+
*/
|
|
128
|
+
function get_vendor_name(addr) {
|
|
129
|
+
const obj = vendorMap.get(formatHex16(addr));
|
|
130
|
+
if (!obj) {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
return obj.vendor;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get context of a docstring for the given address
|
|
137
|
+
* @param addr address of the entry point
|
|
138
|
+
* @returns context of this docstring
|
|
139
|
+
*/
|
|
140
|
+
function get_vendor_ctx(addr) {
|
|
141
|
+
const obj = vendorMap.get(formatHex16(addr));
|
|
142
|
+
if (!obj) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
return obj.ctx;
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.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