@henols/c64-re-tools 2.8.0-rc.2 → 2.8.0-rc.3
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/package.json +1 -1
- package/skills/c64-assembler/SKILL.md +5 -2
- package/skills/c64-assembler/scripts/assembler.ts +55 -48
- package/skills/c64-disk/scripts/disk.ts +3 -3
- package/skills/c64-disk/scripts/lib/containers.ts +2 -2
- package/skills/c64-docs/SKILL.md +1 -1
- package/skills/c64-docs/scripts/docs.ts +12 -20
- package/skills/c64-docs/scripts/lib/links.ts +1 -1
- package/skills/c64-docs/scripts/lib/markdown.ts +1 -1
- package/skills/c64-docs/scripts/lib/reference.ts +59 -13
- package/skills/c64-knowledge/SKILL.md +17 -8
- package/skills/c64-knowledge/scripts/knowledge.ts +200 -218
- package/skills/c64-knowledge/scripts/lib/check.ts +2 -3
- package/skills/c64-knowledge/scripts/lib/listing.ts +56 -24
- package/skills/c64-packer/scripts/packer.ts +3 -3
- package/skills/c64-provenance/SKILL.md +25 -16
- package/skills/c64-provenance/scripts/lib/compare.ts +31 -21
- package/skills/c64-provenance/scripts/lib/leftovers.ts +17 -35
- package/skills/c64-provenance/scripts/lib/library.ts +10 -10
- package/skills/c64-provenance/scripts/lib/runtime.ts +3 -14
- package/skills/c64-provenance/scripts/provenance.ts +129 -98
- package/skills/c64-source/references/loader.md +2 -1
- package/skills/c64-source/scripts/lib/export.ts +54 -303
- package/skills/c64-source/scripts/lib/loader.ts +31 -51
- package/skills/c64-source/scripts/lib/source.ts +51 -41
- package/skills/c64-source/scripts/lib/stage.ts +9 -25
- package/skills/c64-source/scripts/source.ts +134 -294
- package/skills/c64-static-analysis/SKILL.md +10 -5
- package/skills/c64-static-analysis/scripts/lib/coverage.ts +1 -3
- package/skills/c64-static-analysis/scripts/lib/findings.ts +16 -3
- package/skills/c64-static-analysis/scripts/lib/idioms.ts +82 -10
- package/skills/c64-static-analysis/scripts/lib/triage.ts +112 -0
- package/skills/c64-static-analysis/scripts/static-analysis.ts +239 -147
- package/skills/c64-testing/SKILL.md +13 -7
- package/skills/c64-testing/scripts/lib/diff-files.ts +6 -13
- package/skills/c64-testing/scripts/lib/recording.ts +47 -66
- package/skills/c64-testing/scripts/lib/replay.ts +53 -9
- package/skills/c64-testing/scripts/lib/runs.ts +11 -29
- package/skills/c64-testing/scripts/lib/scenario.ts +30 -31
- package/skills/c64-testing/scripts/lib/start-screen.ts +42 -5
- package/skills/c64-testing/scripts/testing.ts +32 -7
- package/skills/c64-unpacker/SKILL.md +9 -7
- package/skills/c64-unpacker/scripts/lib/evidence.ts +23 -38
- package/skills/c64-unpacker/scripts/lib/loads.ts +24 -39
- package/skills/c64-unpacker/scripts/lib/machine.ts +38 -18
- package/skills/c64-unpacker/scripts/lib/stages.ts +124 -40
- package/skills/c64-unpacker/scripts/unpacker.ts +81 -68
- package/skills/emulator/SKILL.md +1 -0
- package/src/c64.ts +117 -10
- package/src/cli/ap-sdk.ts +1 -1
- package/src/cli/cleanup.ts +4 -2
- package/src/compare.ts +36 -16
- package/src/errors.ts +10 -1
- package/src/host/main.ts +2 -1
- package/src/host/server.ts +7 -11
- package/src/host/tools/c1541.ts +9 -3
- package/src/host/vice/adapter.ts +20 -43
- package/src/host/vice/binary-monitor.ts +22 -21
- package/src/host/vice/process.ts +31 -40
- package/src/host/vice/session.ts +187 -247
- package/src/host/vice/text-monitor.ts +3 -3
- package/src/host-client/autostart.ts +1 -1
- package/src/host-client/connect.ts +2 -1
- package/src/host-client/coverage.ts +0 -3
- package/src/host-client/entry-state.ts +4 -11
- package/src/host-client/image.ts +6 -11
- package/src/host-client/steps.ts +13 -113
- package/src/host-client/tools.ts +4 -4
- package/src/host-client/transfer.ts +10 -0
- package/src/host-client/vice-session.ts +10 -6
- package/src/knowledge/code-reach.ts +364 -0
- package/src/knowledge/conflicts.ts +34 -72
- package/src/knowledge/database.ts +40 -28
- package/src/knowledge/evidence.ts +2 -2
- package/src/knowledge/graph.ts +3 -3
- package/src/knowledge/history.ts +50 -90
- package/src/knowledge/import.ts +28 -68
- package/src/knowledge/join.ts +1 -1
- package/src/knowledge/names.ts +12 -7
- package/src/knowledge/program.ts +25 -46
- package/src/knowledge/read.ts +104 -100
- package/src/knowledge/schema.ts +9 -3
- package/src/knowledge/separate.ts +47 -19
- package/src/knowledge/start-screen.ts +7 -5
- package/src/knowledge/text.ts +56 -33
- package/src/knowledge/write.ts +274 -515
- package/src/loader.ts +7 -25
- package/src/mcp/inputs.ts +3 -3
- package/src/mcp/server.ts +19 -38
- package/src/mcp/session-source.ts +2 -1
- package/src/mcp/tools/debug.ts +97 -24
- package/src/mcp/tools/execution.ts +1 -1
- package/src/mcp/tools/input.ts +3 -3
- package/src/mcp/tools/machine.ts +3 -3
- package/src/mcp/tools/media.ts +4 -4
- package/src/mcp/tools/memory.ts +13 -17
- package/src/mcp/tools/video.ts +11 -25
- package/src/native/acme.ts +3 -3
- package/src/native/c64run.ts +2 -1
- package/src/native/decompiler/analyze.ts +10 -7
- package/src/native/decompiler/walk.ts +3 -4
- package/src/native/decompiler/wasm.ts +2 -2
- package/src/native/discover.ts +1 -1
- package/src/native/dxa.ts +9 -11
- package/src/native/exomizer.ts +1 -1
- package/src/native/processes.ts +4 -1
- package/src/native/run.ts +3 -3
- package/src/native/types.ts +5 -6
- package/src/opcodes.ts +3 -0
- package/src/platform.ts +9 -10
- package/src/program-code.ts +151 -0
- package/src/project.ts +8 -5
- package/src/protocol/framing.ts +51 -18
- package/src/protocol/messages.ts +1 -11
- package/src/protocol/tools.ts +0 -3
- package/src/protocol/vice.ts +588 -773
- package/src/script.ts +9 -14
- package/src/time.ts +1 -1
- package/src/trace.ts +3 -2
package/src/knowledge/read.ts
CHANGED
|
@@ -4,10 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import type { DatabaseSync } from "node:sqlite";
|
|
6
6
|
|
|
7
|
-
import type { AddressRange } from "../c64.ts";
|
|
7
|
+
import type { AddressRange, ReferenceKind } from "../c64.ts";
|
|
8
8
|
import { Refusal } from "../errors.ts";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { prepare } from "./database.ts";
|
|
10
|
+
import type { OperandSelect } from "./expression.ts";
|
|
11
|
+
import type { HistoryEntry } from "./history.ts";
|
|
12
|
+
import { DEFAULT_SPACE, spaceOrder, type CommentPlacement, type Origin, type RegionType, type Space, type StartScreenMode, type SuppressionEntity, type SwitchKind, type SymbolKind } from "./schema.ts";
|
|
13
|
+
import { compareText, NO_REVISION, sqlName, TABLES, tableSpec } from "./text.ts";
|
|
11
14
|
|
|
12
15
|
export interface SymbolRow {
|
|
13
16
|
space: Space;
|
|
@@ -197,25 +200,11 @@ const items = (text: string) => (text.trim() === "" ? [] : text.split(",").map((
|
|
|
197
200
|
|
|
198
201
|
type Raw = Record<string, unknown>;
|
|
199
202
|
|
|
200
|
-
|
|
201
|
-
export const REGION_COLUMNS = "space, start_address, end_address, type, element, origin, valid_from_revision";
|
|
202
|
-
export const COMMENT_COLUMNS = "space, address, placement, text, origin, valid_from_revision";
|
|
203
|
-
export const REFERENCE_COLUMNS = "space, from_address, to_address, kind, origin, valid_from_revision";
|
|
204
|
-
export const SUPPRESSION_COLUMNS = "space, entity, start_address, end_address, to_address, kind, origin, valid_from_revision";
|
|
205
|
-
export const MODULE_COLUMNS = "space, start_address, file, title, origin, valid_from_revision";
|
|
206
|
-
export const OPERAND_COLUMNS = "space, address, selector, symbol, offset, expression, origin, valid_from_revision";
|
|
207
|
-
export const PATCH_COLUMNS = "space, start_address, end_address, switch_name, code, comment, origin, valid_from_revision";
|
|
208
|
-
export const SWITCH_COLUMNS = "space, name, kind, default_value, releases, comment, origin, valid_from_revision";
|
|
209
|
-
export const RELEASE_COLUMNS = "space, label, base, file, sha256, comment, origin, valid_from_revision";
|
|
210
|
-
export const MACRO_COLUMNS = "space, name, params, body, comment, origin, valid_from_revision";
|
|
211
|
-
export const MACRO_USE_COLUMNS = "space, start_address, end_address, macro, args, origin, valid_from_revision";
|
|
212
|
-
export const START_SCREEN_COLUMNS = "space, mode, screen, bitmap, charset, colours, colour, border, background, stage, call_address, colour_ram, comment, origin, valid_from_revision";
|
|
213
|
-
|
|
214
|
-
export function toSymbol(row: Raw): SymbolRow {
|
|
203
|
+
function toSymbol(row: Raw): SymbolRow {
|
|
215
204
|
return { space: row.space as Space, address: row.address as number, name: row.name as string, kind: row.kind as SymbolKind, origin: row.origin as Origin, revision: row.valid_from_revision as string };
|
|
216
205
|
}
|
|
217
206
|
|
|
218
|
-
|
|
207
|
+
function toRegion(row: Raw): RegionRow {
|
|
219
208
|
const region: RegionRow = {
|
|
220
209
|
space: row.space as Space,
|
|
221
210
|
start: row.start_address as number,
|
|
@@ -228,7 +217,7 @@ export function toRegion(row: Raw): RegionRow {
|
|
|
228
217
|
return region;
|
|
229
218
|
}
|
|
230
219
|
|
|
231
|
-
|
|
220
|
+
function toComment(row: Raw): CommentRow {
|
|
232
221
|
return {
|
|
233
222
|
space: row.space as Space,
|
|
234
223
|
address: row.address as number,
|
|
@@ -239,11 +228,11 @@ export function toComment(row: Raw): CommentRow {
|
|
|
239
228
|
};
|
|
240
229
|
}
|
|
241
230
|
|
|
242
|
-
|
|
231
|
+
function toReference(row: Raw): ReferenceRow {
|
|
243
232
|
return { space: row.space as Space, from: row.from_address as number, to: row.to_address as number, kind: row.kind as ReferenceKind, origin: row.origin as Origin, revision: row.valid_from_revision as string };
|
|
244
233
|
}
|
|
245
234
|
|
|
246
|
-
|
|
235
|
+
function toSuppression(row: Raw): SuppressionRow {
|
|
247
236
|
const suppression: SuppressionRow = {
|
|
248
237
|
space: row.space as Space,
|
|
249
238
|
entity: row.entity as SuppressionEntity,
|
|
@@ -257,13 +246,13 @@ export function toSuppression(row: Raw): SuppressionRow {
|
|
|
257
246
|
return suppression;
|
|
258
247
|
}
|
|
259
248
|
|
|
260
|
-
|
|
249
|
+
function toModule(row: Raw): ModuleRow {
|
|
261
250
|
const module: ModuleRow = { space: row.space as Space, start: row.start_address as number, file: row.file as string, origin: row.origin as ModuleRow["origin"], revision: row.valid_from_revision as string };
|
|
262
251
|
if (row.title !== null && row.title !== undefined) module.title = row.title as string;
|
|
263
252
|
return module;
|
|
264
253
|
}
|
|
265
254
|
|
|
266
|
-
|
|
255
|
+
function toOperand(row: Raw): OperandRow {
|
|
267
256
|
const operand: OperandRow = {
|
|
268
257
|
space: row.space as Space,
|
|
269
258
|
address: row.address as number,
|
|
@@ -277,7 +266,7 @@ export function toOperand(row: Raw): OperandRow {
|
|
|
277
266
|
return operand;
|
|
278
267
|
}
|
|
279
268
|
|
|
280
|
-
|
|
269
|
+
function toPatch(row: Raw): PatchRow {
|
|
281
270
|
const patch: PatchRow = {
|
|
282
271
|
space: row.space as Space,
|
|
283
272
|
start: row.start_address as number,
|
|
@@ -291,7 +280,7 @@ export function toPatch(row: Raw): PatchRow {
|
|
|
291
280
|
return patch;
|
|
292
281
|
}
|
|
293
282
|
|
|
294
|
-
|
|
283
|
+
function toSwitch(row: Raw): SwitchRow {
|
|
295
284
|
const value: SwitchRow = {
|
|
296
285
|
space: row.space as Space,
|
|
297
286
|
name: row.name as string,
|
|
@@ -305,7 +294,7 @@ export function toSwitch(row: Raw): SwitchRow {
|
|
|
305
294
|
return value;
|
|
306
295
|
}
|
|
307
296
|
|
|
308
|
-
|
|
297
|
+
function toRelease(row: Raw): ReleaseRow {
|
|
309
298
|
const release: ReleaseRow = {
|
|
310
299
|
space: row.space as Space,
|
|
311
300
|
label: row.label as string,
|
|
@@ -319,7 +308,7 @@ export function toRelease(row: Raw): ReleaseRow {
|
|
|
319
308
|
return release;
|
|
320
309
|
}
|
|
321
310
|
|
|
322
|
-
|
|
311
|
+
function toStartScreen(row: Raw): StartScreenRow {
|
|
323
312
|
const value: StartScreenRow = {
|
|
324
313
|
space: row.space as Space,
|
|
325
314
|
mode: row.mode as StartScreenMode,
|
|
@@ -337,13 +326,13 @@ export function toStartScreen(row: Raw): StartScreenRow {
|
|
|
337
326
|
return value;
|
|
338
327
|
}
|
|
339
328
|
|
|
340
|
-
|
|
329
|
+
function toMacro(row: Raw): MacroRow {
|
|
341
330
|
const macro: MacroRow = { space: row.space as Space, name: row.name as string, params: items(row.params as string), body: row.body as string, origin: row.origin as MacroRow["origin"], revision: row.valid_from_revision as string };
|
|
342
331
|
if (row.comment !== null && row.comment !== undefined) macro.comment = row.comment as string;
|
|
343
332
|
return macro;
|
|
344
333
|
}
|
|
345
334
|
|
|
346
|
-
|
|
335
|
+
function toMacroUse(row: Raw): MacroUseRow {
|
|
347
336
|
return {
|
|
348
337
|
space: row.space as Space,
|
|
349
338
|
start: row.start_address as number,
|
|
@@ -355,22 +344,55 @@ export function toMacroUse(row: Raw): MacroUseRow {
|
|
|
355
344
|
};
|
|
356
345
|
}
|
|
357
346
|
|
|
347
|
+
/** A fact table as the reads give it: the kind of its rows in the history, its columns as a query selects them, and the row of the selected columns. */
|
|
348
|
+
export interface Fact<R = HistoryEntry["row"]> {
|
|
349
|
+
table: string;
|
|
350
|
+
entity: HistoryEntry["entity"];
|
|
351
|
+
columns: string;
|
|
352
|
+
map: (raw: Raw) => R;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const fact = <R>(table: string, entity: HistoryEntry["entity"], map: (raw: Raw) => R): Fact<R> => ({
|
|
356
|
+
table,
|
|
357
|
+
entity,
|
|
358
|
+
columns: [...tableSpec(table).fields.map((field) => field.column), "valid_from_revision"].join(", "),
|
|
359
|
+
map,
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
/** The fact tables, in the order that the history of a revision lists them. */
|
|
363
|
+
export const FACTS = {
|
|
364
|
+
symbols: fact("symbols", "symbol", toSymbol),
|
|
365
|
+
analyzer_names: fact("analyzer_names", "analyzer-name", toSymbol),
|
|
366
|
+
regions: fact("regions", "region", toRegion),
|
|
367
|
+
comments: fact("comments", "comment", toComment),
|
|
368
|
+
references: fact("references", "reference", toReference),
|
|
369
|
+
suppressions: fact("suppressions", "suppression", toSuppression),
|
|
370
|
+
modules: fact("modules", "module", toModule),
|
|
371
|
+
operands: fact("operands", "operand", toOperand),
|
|
372
|
+
patches: fact("patches", "patch", toPatch),
|
|
373
|
+
switches: fact("switches", "switch", toSwitch),
|
|
374
|
+
releases: fact("releases", "release", toRelease),
|
|
375
|
+
start_screens: fact("start_screens", "start-screen", toStartScreen),
|
|
376
|
+
macros: fact("macros", "macro", toMacro),
|
|
377
|
+
macro_uses: fact("macro_uses", "macro-use", toMacroUse),
|
|
378
|
+
};
|
|
379
|
+
|
|
358
380
|
/** The id of the newest revision, or "0" when the knowledge has none. */
|
|
359
381
|
export function currentRevision(db: DatabaseSync | undefined): string {
|
|
360
382
|
if (db === undefined) return "0";
|
|
361
|
-
return (
|
|
383
|
+
return (prepare(db, "SELECT max(id) AS id FROM revisions").get() as { id: string | null }).id ?? "0";
|
|
362
384
|
}
|
|
363
385
|
|
|
364
386
|
/**
|
|
365
387
|
* The newest revision that changed a row in one of `spaces`, or the revision
|
|
366
388
|
* of no knowledge when none did. A change in another space does not change it.
|
|
367
389
|
*/
|
|
368
|
-
|
|
390
|
+
function spacesRevision(db: DatabaseSync | undefined, spaces: readonly Space[]): string {
|
|
369
391
|
if (db === undefined || spaces.length === 0) return NO_REVISION;
|
|
370
392
|
const marks = spaces.map(() => "?").join(", ");
|
|
371
393
|
let newest = NO_REVISION;
|
|
372
394
|
for (const spec of TABLES) {
|
|
373
|
-
const row =
|
|
395
|
+
const row = prepare(db, `SELECT max(valid_from_revision) AS added, max(valid_to_revision) AS closed FROM ${sqlName(spec.table)} WHERE space IN (${marks})`).get(...spaces) as { added: string | null; closed: string | null };
|
|
374
396
|
for (const id of [row.added, row.closed]) if (id !== null && compareText(id, newest) > 0) newest = id;
|
|
375
397
|
}
|
|
376
398
|
return newest;
|
|
@@ -402,8 +424,7 @@ export interface CoverageRun {
|
|
|
402
424
|
*/
|
|
403
425
|
export function coverageRuns(db: DatabaseSync | undefined, at?: string): CoverageRun[] {
|
|
404
426
|
if (db === undefined || at === NO_REVISION) return [];
|
|
405
|
-
const rows = db
|
|
406
|
-
.prepare(
|
|
427
|
+
const rows = prepare(db,
|
|
407
428
|
`SELECT r.id AS id, r.operation AS operation, r.restored_revision AS restored, r.restored_space AS restoredSpace, e.ref AS name, e.sha256 AS sha256, coalesce(e.space, '${DEFAULT_SPACE}') AS space
|
|
408
429
|
FROM revisions r LEFT JOIN evidence e ON e.revision = r.id AND e.kind = 'coverage'
|
|
409
430
|
WHERE (r.operation = 'coverage' AND e.id IS NOT NULL) OR (r.operation = 'revert' AND r.restored_revision IS NOT NULL)
|
|
@@ -441,7 +462,7 @@ const NAMED_REVISIONS = 5;
|
|
|
441
462
|
export function resolveRevision(db: DatabaseSync | undefined, text: string): string {
|
|
442
463
|
if (text === NO_REVISION) return NO_REVISION;
|
|
443
464
|
if (!/^[0-9a-zT.-]+$/.test(text)) throw new Refusal("invalid-input", `${JSON.stringify(text)} is not a revision id. A revision id looks like 20261015T214501.123-k3f9qz; its start is enough when only one revision has it.`);
|
|
444
|
-
const found = (
|
|
465
|
+
const found = (prepare(db, "SELECT id FROM revisions WHERE substr(id, 1, ?) = ? ORDER BY id LIMIT ?")?.all(text.length, text, NAMED_REVISIONS + 1) ?? []) as Array<{ id: string }>;
|
|
445
466
|
if (found.length === 0) throw new Refusal("not-found", `There is no revision ${text}.`);
|
|
446
467
|
if (found.length > 1) {
|
|
447
468
|
const named = found.slice(0, NAMED_REVISIONS).map((row) => row.id).join(", ");
|
|
@@ -451,25 +472,25 @@ export function resolveRevision(db: DatabaseSync | undefined, text: string): str
|
|
|
451
472
|
}
|
|
452
473
|
|
|
453
474
|
export function symbolAt(db: DatabaseSync | undefined, address: number, space: Space = DEFAULT_SPACE): SymbolRow | undefined {
|
|
454
|
-
const row =
|
|
475
|
+
const row = prepare(db, `SELECT ${FACTS.symbols.columns} FROM current_symbols WHERE space = ? AND address = ?`)?.get(space, address) as Raw | undefined;
|
|
455
476
|
return row === undefined ? undefined : toSymbol(row);
|
|
456
477
|
}
|
|
457
478
|
|
|
458
479
|
export function symbolNamed(db: DatabaseSync | undefined, name: string, space: Space = DEFAULT_SPACE): SymbolRow | undefined {
|
|
459
|
-
const row =
|
|
480
|
+
const row = prepare(db, `SELECT ${FACTS.symbols.columns} FROM current_symbols WHERE space = ? AND name = ?`)?.get(space, name) as Raw | undefined;
|
|
460
481
|
return row === undefined ? undefined : toSymbol(row);
|
|
461
482
|
}
|
|
462
483
|
|
|
463
484
|
/** The analyzer names at an address: one for each analyzer, in the order heuristic, decompiler, DXA. */
|
|
464
485
|
export function analyzerNamesAt(db: DatabaseSync | undefined, address: number, space: Space = DEFAULT_SPACE): SymbolRow[] {
|
|
465
486
|
if (db === undefined) return [];
|
|
466
|
-
return (
|
|
487
|
+
return (prepare(db, `SELECT ${FACTS.analyzer_names.columns} FROM current_analyzer_names WHERE space = ? AND address = ?`).all(space, address) as Raw[]).map(toSymbol).sort(byAnalyzer);
|
|
467
488
|
}
|
|
468
489
|
|
|
469
490
|
/** The analyzer names with this name: more than one when two analyzers gave it to different addresses. */
|
|
470
491
|
export function analyzerNamed(db: DatabaseSync | undefined, name: string, space: Space = DEFAULT_SPACE): SymbolRow[] {
|
|
471
492
|
if (db === undefined) return [];
|
|
472
|
-
return (
|
|
493
|
+
return (prepare(db, `SELECT ${FACTS.analyzer_names.columns} FROM current_analyzer_names WHERE space = ? AND name = ?`).all(space, name) as Raw[]).map(toSymbol).sort(byAnalyzer);
|
|
473
494
|
}
|
|
474
495
|
|
|
475
496
|
/** The analyzers in the order that their names are used when no other name exists. */
|
|
@@ -479,7 +500,7 @@ const byAnalyzer = (a: SymbolRow, b: SymbolRow) => a.address - b.address || ANAL
|
|
|
479
500
|
/** Current analyzer names in a range, in address order and then heuristic, decompiler, DXA. */
|
|
480
501
|
export function listAnalyzerNames(db: DatabaseSync | undefined, range: AddressRange = ALL, kind?: SymbolKind, origins?: OriginFilter, space: Space = DEFAULT_SPACE): SymbolRow[] {
|
|
481
502
|
if (db === undefined) return [];
|
|
482
|
-
return (
|
|
503
|
+
return (prepare(db, `SELECT ${FACTS.analyzer_names.columns} FROM current_analyzer_names WHERE space = ? AND address BETWEEN ? AND ?`).all(space, range.start, range.end) as Raw[])
|
|
483
504
|
.map(toSymbol)
|
|
484
505
|
.filter((row) => (kind === undefined || row.kind === kind) && kept(origins)(row))
|
|
485
506
|
.sort(byAnalyzer);
|
|
@@ -488,41 +509,38 @@ export function listAnalyzerNames(db: DatabaseSync | undefined, range: AddressRa
|
|
|
488
509
|
/** Current regions that share at least one address with [start, end], in address order. */
|
|
489
510
|
export function regionsOverlapping(db: DatabaseSync | undefined, start: number, end: number, space: Space = DEFAULT_SPACE): RegionRow[] {
|
|
490
511
|
if (db === undefined) return [];
|
|
491
|
-
return db
|
|
492
|
-
.prepare(`SELECT ${REGION_COLUMNS} FROM current_regions WHERE space = ? AND start_address <= ? AND end_address >= ? ORDER BY start_address`)
|
|
512
|
+
return prepare(db, `SELECT ${FACTS.regions.columns} FROM current_regions WHERE space = ? AND start_address <= ? AND end_address >= ? ORDER BY start_address`)
|
|
493
513
|
.all(space, end, start)
|
|
494
514
|
.map((row) => toRegion(row as Raw));
|
|
495
515
|
}
|
|
496
516
|
|
|
497
517
|
export function commentsAt(db: DatabaseSync | undefined, address: number, space: Space = DEFAULT_SPACE): CommentRow[] {
|
|
498
518
|
if (db === undefined) return [];
|
|
499
|
-
return db
|
|
500
|
-
.prepare(`SELECT ${COMMENT_COLUMNS} FROM current_comments WHERE space = ? AND address = ? ORDER BY placement`)
|
|
519
|
+
return prepare(db, `SELECT ${FACTS.comments.columns} FROM current_comments WHERE space = ? AND address = ? ORDER BY placement`)
|
|
501
520
|
.all(space, address)
|
|
502
521
|
.map((row) => toComment(row as Raw));
|
|
503
522
|
}
|
|
504
523
|
|
|
505
524
|
export function referencesFrom(db: DatabaseSync | undefined, address: number, space: Space = DEFAULT_SPACE): ReferenceRow[] {
|
|
506
525
|
if (db === undefined) return [];
|
|
507
|
-
return db
|
|
508
|
-
.prepare(`SELECT ${REFERENCE_COLUMNS} FROM current_references WHERE space = ? AND from_address = ? ORDER BY to_address, kind`)
|
|
526
|
+
return prepare(db, `SELECT ${FACTS.references.columns} FROM current_references WHERE space = ? AND from_address = ? ORDER BY to_address, kind`)
|
|
509
527
|
.all(space, address)
|
|
510
528
|
.map((row) => toReference(row as Raw));
|
|
511
529
|
}
|
|
512
530
|
|
|
513
531
|
export function referencesTo(db: DatabaseSync | undefined, address: number, space: Space = DEFAULT_SPACE): ReferenceRow[] {
|
|
514
532
|
if (db === undefined) return [];
|
|
515
|
-
return db
|
|
516
|
-
.prepare(`SELECT ${REFERENCE_COLUMNS} FROM current_references WHERE space = ? AND to_address = ? ORDER BY from_address, kind`)
|
|
533
|
+
return prepare(db, `SELECT ${FACTS.references.columns} FROM current_references WHERE space = ? AND to_address = ?`)
|
|
517
534
|
.all(space, address)
|
|
518
|
-
.map((row) => toReference(row as Raw))
|
|
535
|
+
.map((row) => toReference(row as Raw))
|
|
536
|
+
// Sorted here: with ORDER BY from_address, SQLite reads the whole space by the from_address index instead of the few rows of the to_address index.
|
|
537
|
+
.sort((a, b) => a.from - b.from || (a.kind < b.kind ? -1 : a.kind > b.kind ? 1 : 0));
|
|
519
538
|
}
|
|
520
539
|
|
|
521
540
|
/** Current suppressions of one entity that share at least one address with [start, end], in address order. */
|
|
522
541
|
export function suppressionsOverlapping(db: DatabaseSync | undefined, entity: SuppressionEntity, start: number, end: number, space: Space = DEFAULT_SPACE): SuppressionRow[] {
|
|
523
542
|
if (db === undefined) return [];
|
|
524
|
-
return db
|
|
525
|
-
.prepare(`SELECT ${SUPPRESSION_COLUMNS} FROM current_suppressions WHERE space = ? AND entity = ? AND start_address <= ? AND end_address >= ? ORDER BY start_address, to_address, kind`)
|
|
543
|
+
return prepare(db, `SELECT ${FACTS.suppressions.columns} FROM current_suppressions WHERE space = ? AND entity = ? AND start_address <= ? AND end_address >= ? ORDER BY start_address, to_address, kind`)
|
|
526
544
|
.all(space, entity, end, start)
|
|
527
545
|
.map((row) => toSuppression(row as Raw));
|
|
528
546
|
}
|
|
@@ -536,36 +554,34 @@ export function referenceSuppressed(db: DatabaseSync | undefined, reference: { f
|
|
|
536
554
|
}
|
|
537
555
|
|
|
538
556
|
/** Current suppressions at an address: its symbol, the region range that holds it, references from or to it. */
|
|
539
|
-
|
|
557
|
+
function suppressionsAt(db: DatabaseSync | undefined, address: number, space: Space = DEFAULT_SPACE): SuppressionRow[] {
|
|
540
558
|
if (db === undefined) return [];
|
|
541
|
-
return db
|
|
542
|
-
|
|
543
|
-
`SELECT ${SUPPRESSION_COLUMNS} FROM current_suppressions WHERE space = ? AND ((start_address <= ? AND end_address >= ?) OR to_address = ?) ORDER BY entity, start_address, to_address, kind`,
|
|
559
|
+
return prepare(db,
|
|
560
|
+
`SELECT ${FACTS.suppressions.columns} FROM current_suppressions WHERE space = ? AND ((start_address <= ? AND end_address >= ?) OR to_address = ?) ORDER BY entity, start_address, to_address, kind`,
|
|
544
561
|
)
|
|
545
562
|
.all(space, address, address, address)
|
|
546
563
|
.map((row) => toSuppression(row as Raw));
|
|
547
564
|
}
|
|
548
565
|
|
|
549
566
|
export function moduleAt(db: DatabaseSync | undefined, start: number, space: Space = DEFAULT_SPACE): ModuleRow | undefined {
|
|
550
|
-
const row =
|
|
567
|
+
const row = prepare(db, `SELECT ${FACTS.modules.columns} FROM current_modules WHERE space = ? AND start_address = ?`)?.get(space, start) as Raw | undefined;
|
|
551
568
|
return row === undefined ? undefined : toModule(row);
|
|
552
569
|
}
|
|
553
570
|
|
|
554
571
|
export function moduleWithFile(db: DatabaseSync | undefined, file: string, space: Space = DEFAULT_SPACE): ModuleRow | undefined {
|
|
555
|
-
const row =
|
|
572
|
+
const row = prepare(db, `SELECT ${FACTS.modules.columns} FROM current_modules WHERE space = ? AND file = ? COLLATE NOCASE`)?.get(space, file) as Raw | undefined;
|
|
556
573
|
return row === undefined ? undefined : toModule(row);
|
|
557
574
|
}
|
|
558
575
|
|
|
559
576
|
export function operandAt(db: DatabaseSync | undefined, address: number, space: Space = DEFAULT_SPACE): OperandRow | undefined {
|
|
560
|
-
const row =
|
|
577
|
+
const row = prepare(db, `SELECT ${FACTS.operands.columns} FROM current_operands WHERE space = ? AND address = ?`)?.get(space, address) as Raw | undefined;
|
|
561
578
|
return row === undefined ? undefined : toOperand(row);
|
|
562
579
|
}
|
|
563
580
|
|
|
564
581
|
/** Current patches that share at least one address with [start, end], in address order. */
|
|
565
582
|
export function patchesOverlapping(db: DatabaseSync | undefined, start: number, end: number, space: Space = DEFAULT_SPACE): PatchRow[] {
|
|
566
583
|
if (db === undefined) return [];
|
|
567
|
-
return db
|
|
568
|
-
.prepare(`SELECT ${PATCH_COLUMNS} FROM current_patches WHERE space = ? AND start_address <= ? AND end_address >= ? ORDER BY start_address`)
|
|
584
|
+
return prepare(db, `SELECT ${FACTS.patches.columns} FROM current_patches WHERE space = ? AND start_address <= ? AND end_address >= ? ORDER BY start_address`)
|
|
569
585
|
.all(space, end, start)
|
|
570
586
|
.map((row) => toPatch(row as Raw));
|
|
571
587
|
}
|
|
@@ -573,45 +589,47 @@ export function patchesOverlapping(db: DatabaseSync | undefined, start: number,
|
|
|
573
589
|
/** Current macro uses that share at least one address with [start, end], in address order. */
|
|
574
590
|
export function macroUsesOverlapping(db: DatabaseSync | undefined, start: number, end: number, space: Space = DEFAULT_SPACE): MacroUseRow[] {
|
|
575
591
|
if (db === undefined) return [];
|
|
576
|
-
return db
|
|
577
|
-
.prepare(`SELECT ${MACRO_USE_COLUMNS} FROM current_macro_uses WHERE space = ? AND start_address <= ? AND end_address >= ? ORDER BY start_address`)
|
|
592
|
+
return prepare(db, `SELECT ${FACTS.macro_uses.columns} FROM current_macro_uses WHERE space = ? AND start_address <= ? AND end_address >= ? ORDER BY start_address`)
|
|
578
593
|
.all(space, end, start)
|
|
579
594
|
.map((row) => toMacroUse(row as Raw));
|
|
580
595
|
}
|
|
581
596
|
|
|
582
597
|
export function switchNamed(db: DatabaseSync | undefined, name: string, space: Space = DEFAULT_SPACE): SwitchRow | undefined {
|
|
583
|
-
const row =
|
|
598
|
+
const row = prepare(db, `SELECT ${FACTS.switches.columns} FROM current_switches WHERE space = ? AND name = ?`)?.get(space, name) as Raw | undefined;
|
|
584
599
|
return row === undefined ? undefined : toSwitch(row);
|
|
585
600
|
}
|
|
586
601
|
|
|
587
602
|
/** Current switches of a space, by name. */
|
|
588
603
|
export function listSwitches(db: DatabaseSync | undefined, origins?: OriginFilter, space: Space = DEFAULT_SPACE): SwitchRow[] {
|
|
589
604
|
if (db === undefined) return [];
|
|
590
|
-
return db
|
|
591
|
-
.prepare(`SELECT ${SWITCH_COLUMNS} FROM current_switches WHERE space = ? ORDER BY name`)
|
|
605
|
+
return prepare(db, `SELECT ${FACTS.switches.columns} FROM current_switches WHERE space = ? ORDER BY name`)
|
|
592
606
|
.all(space)
|
|
593
607
|
.map((row) => toSwitch(row as Raw))
|
|
594
608
|
.filter(kept(origins));
|
|
595
609
|
}
|
|
596
610
|
|
|
597
611
|
export function releaseLabeled(db: DatabaseSync | undefined, label: string, space: Space = DEFAULT_SPACE): ReleaseRow | undefined {
|
|
598
|
-
const row =
|
|
612
|
+
const row = prepare(db, `SELECT ${FACTS.releases.columns} FROM current_releases WHERE space = ? AND label = ?`)?.get(space, label) as Raw | undefined;
|
|
599
613
|
return row === undefined ? undefined : toRelease(row);
|
|
600
614
|
}
|
|
601
615
|
|
|
602
616
|
/** Current releases of a space: the base release first, then by label. */
|
|
603
617
|
export function listReleases(db: DatabaseSync | undefined, origins?: OriginFilter, space: Space = DEFAULT_SPACE): ReleaseRow[] {
|
|
604
618
|
if (db === undefined) return [];
|
|
605
|
-
return db
|
|
606
|
-
.prepare(`SELECT ${RELEASE_COLUMNS} FROM current_releases WHERE space = ? ORDER BY base DESC, label`)
|
|
619
|
+
return prepare(db, `SELECT ${FACTS.releases.columns} FROM current_releases WHERE space = ? ORDER BY base DESC, label`)
|
|
607
620
|
.all(space)
|
|
608
621
|
.map((row) => toRelease(row as Raw))
|
|
609
622
|
.filter(kept(origins));
|
|
610
623
|
}
|
|
611
624
|
|
|
625
|
+
/** The label of the base release of a space, whose bytes are the program of the knowledge; undefined without one. */
|
|
626
|
+
export function baseLabel(db: DatabaseSync | undefined, space: Space = DEFAULT_SPACE): string | undefined {
|
|
627
|
+
return listReleases(db, undefined, space).find((release) => release.base)?.label;
|
|
628
|
+
}
|
|
629
|
+
|
|
612
630
|
/** The current start screen of a space, if the knowledge has one. */
|
|
613
631
|
export function currentStartScreen(db: DatabaseSync | undefined, space: Space = DEFAULT_SPACE): StartScreenRow | undefined {
|
|
614
|
-
const row =
|
|
632
|
+
const row = prepare(db, `SELECT ${FACTS.start_screens.columns} FROM current_start_screens WHERE space = ?`)?.get(space) as Raw | undefined;
|
|
615
633
|
return row === undefined ? undefined : toStartScreen(row);
|
|
616
634
|
}
|
|
617
635
|
|
|
@@ -624,7 +642,7 @@ export function baseValue(row: Pick<SwitchRow, "releases">, base: string | undef
|
|
|
624
642
|
}
|
|
625
643
|
|
|
626
644
|
export function macroNamed(db: DatabaseSync | undefined, name: string, space: Space = DEFAULT_SPACE): MacroRow | undefined {
|
|
627
|
-
const row =
|
|
645
|
+
const row = prepare(db, `SELECT ${FACTS.macros.columns} FROM current_macros WHERE space = ? AND name = ?`)?.get(space, name) as Raw | undefined;
|
|
628
646
|
return row === undefined ? undefined : toMacro(row);
|
|
629
647
|
}
|
|
630
648
|
|
|
@@ -685,8 +703,8 @@ export function listSymbols(db: DatabaseSync | undefined, range: AddressRange =
|
|
|
685
703
|
if (db === undefined) return [];
|
|
686
704
|
const rows =
|
|
687
705
|
kind === undefined
|
|
688
|
-
?
|
|
689
|
-
:
|
|
706
|
+
? prepare(db, `SELECT ${FACTS.symbols.columns} FROM current_symbols WHERE space = ? AND address BETWEEN ? AND ? ORDER BY address`).all(space, range.start, range.end)
|
|
707
|
+
: prepare(db, `SELECT ${FACTS.symbols.columns} FROM current_symbols WHERE space = ? AND address BETWEEN ? AND ? AND kind = ? ORDER BY address`).all(space, range.start, range.end, kind);
|
|
690
708
|
return rows.map((row) => toSymbol(row as Raw)).filter(kept(origins));
|
|
691
709
|
}
|
|
692
710
|
|
|
@@ -696,8 +714,7 @@ export function listRegions(db: DatabaseSync | undefined, range: AddressRange =
|
|
|
696
714
|
|
|
697
715
|
export function listComments(db: DatabaseSync | undefined, range: AddressRange = ALL, origins?: OriginFilter, space: Space = DEFAULT_SPACE): CommentRow[] {
|
|
698
716
|
if (db === undefined) return [];
|
|
699
|
-
return db
|
|
700
|
-
.prepare(`SELECT ${COMMENT_COLUMNS} FROM current_comments WHERE space = ? AND address BETWEEN ? AND ? ORDER BY address, placement`)
|
|
717
|
+
return prepare(db, `SELECT ${FACTS.comments.columns} FROM current_comments WHERE space = ? AND address BETWEEN ? AND ? ORDER BY address, placement`)
|
|
701
718
|
.all(space, range.start, range.end)
|
|
702
719
|
.map((row) => toComment(row as Raw))
|
|
703
720
|
.filter(kept(origins));
|
|
@@ -706,9 +723,8 @@ export function listComments(db: DatabaseSync | undefined, range: AddressRange =
|
|
|
706
723
|
/** Current references whose source or target lies in the range. */
|
|
707
724
|
export function listReferences(db: DatabaseSync | undefined, range: AddressRange = ALL, kind?: ReferenceKind, origins?: OriginFilter, space: Space = DEFAULT_SPACE): ReferenceRow[] {
|
|
708
725
|
if (db === undefined) return [];
|
|
709
|
-
return db
|
|
710
|
-
|
|
711
|
-
`SELECT ${REFERENCE_COLUMNS} FROM current_references WHERE space = ? AND (from_address BETWEEN ? AND ? OR to_address BETWEEN ? AND ?) ORDER BY from_address, to_address, kind`,
|
|
726
|
+
return prepare(db,
|
|
727
|
+
`SELECT ${FACTS.references.columns} FROM current_references WHERE space = ? AND (from_address BETWEEN ? AND ? OR to_address BETWEEN ? AND ?) ORDER BY from_address, to_address, kind`,
|
|
712
728
|
)
|
|
713
729
|
.all(space, range.start, range.end, range.start, range.end)
|
|
714
730
|
.map((row) => toReference(row as Raw))
|
|
@@ -753,9 +769,8 @@ export function regionCounts(rows: readonly RegionRow[], range: AddressRange = A
|
|
|
753
769
|
/** Current suppressions whose place lies in the range: a reference by its source or target. */
|
|
754
770
|
export function listSuppressions(db: DatabaseSync | undefined, range: AddressRange = ALL, space: Space = DEFAULT_SPACE): SuppressionRow[] {
|
|
755
771
|
if (db === undefined) return [];
|
|
756
|
-
return db
|
|
757
|
-
|
|
758
|
-
`SELECT ${SUPPRESSION_COLUMNS} FROM current_suppressions WHERE space = ? AND ((start_address <= ? AND end_address >= ?) OR to_address BETWEEN ? AND ?) ORDER BY start_address, entity, to_address, kind`,
|
|
772
|
+
return prepare(db,
|
|
773
|
+
`SELECT ${FACTS.suppressions.columns} FROM current_suppressions WHERE space = ? AND ((start_address <= ? AND end_address >= ?) OR to_address BETWEEN ? AND ?) ORDER BY start_address, entity, to_address, kind`,
|
|
759
774
|
)
|
|
760
775
|
.all(space, range.end, range.start, range.start, range.end)
|
|
761
776
|
.map((row) => toSuppression(row as Raw));
|
|
@@ -764,8 +779,7 @@ export function listSuppressions(db: DatabaseSync | undefined, range: AddressRan
|
|
|
764
779
|
/** Current modules that start in the range, in address order. */
|
|
765
780
|
export function listModules(db: DatabaseSync | undefined, range: AddressRange = ALL, origins?: OriginFilter, space: Space = DEFAULT_SPACE): ModuleRow[] {
|
|
766
781
|
if (db === undefined) return [];
|
|
767
|
-
return db
|
|
768
|
-
.prepare(`SELECT ${MODULE_COLUMNS} FROM current_modules WHERE space = ? AND start_address BETWEEN ? AND ? ORDER BY start_address`)
|
|
782
|
+
return prepare(db, `SELECT ${FACTS.modules.columns} FROM current_modules WHERE space = ? AND start_address BETWEEN ? AND ? ORDER BY start_address`)
|
|
769
783
|
.all(space, range.start, range.end)
|
|
770
784
|
.map((row) => toModule(row as Raw))
|
|
771
785
|
.filter(kept(origins));
|
|
@@ -774,8 +788,7 @@ export function listModules(db: DatabaseSync | undefined, range: AddressRange =
|
|
|
774
788
|
/** Current operand expressions of instructions in the range, in address order. */
|
|
775
789
|
export function listOperands(db: DatabaseSync | undefined, range: AddressRange = ALL, origins?: OriginFilter, space: Space = DEFAULT_SPACE): OperandRow[] {
|
|
776
790
|
if (db === undefined) return [];
|
|
777
|
-
return db
|
|
778
|
-
.prepare(`SELECT ${OPERAND_COLUMNS} FROM current_operands WHERE space = ? AND address BETWEEN ? AND ? ORDER BY address`)
|
|
791
|
+
return prepare(db, `SELECT ${FACTS.operands.columns} FROM current_operands WHERE space = ? AND address BETWEEN ? AND ? ORDER BY address`)
|
|
779
792
|
.all(space, range.start, range.end)
|
|
780
793
|
.map((row) => toOperand(row as Raw))
|
|
781
794
|
.filter(kept(origins));
|
|
@@ -789,8 +802,7 @@ export function listPatches(db: DatabaseSync | undefined, range: AddressRange =
|
|
|
789
802
|
/** Current macros, by name. */
|
|
790
803
|
export function listMacros(db: DatabaseSync | undefined, origins?: OriginFilter, space: Space = DEFAULT_SPACE): MacroRow[] {
|
|
791
804
|
if (db === undefined) return [];
|
|
792
|
-
return db
|
|
793
|
-
.prepare(`SELECT ${MACRO_COLUMNS} FROM current_macros WHERE space = ? ORDER BY name`)
|
|
805
|
+
return prepare(db, `SELECT ${FACTS.macros.columns} FROM current_macros WHERE space = ? ORDER BY name`)
|
|
794
806
|
.all(space)
|
|
795
807
|
.map((row) => toMacro(row as Raw))
|
|
796
808
|
.filter(kept(origins));
|
|
@@ -804,13 +816,8 @@ export function listMacroUses(db: DatabaseSync | undefined, range: AddressRange
|
|
|
804
816
|
/** The spaces that hold current knowledge, the C64 first. */
|
|
805
817
|
export function listSpaces(db: DatabaseSync | undefined): Space[] {
|
|
806
818
|
if (db === undefined) return [];
|
|
807
|
-
const rows = db
|
|
808
|
-
|
|
809
|
-
`SELECT space FROM current_symbols UNION SELECT space FROM current_analyzer_names UNION SELECT space FROM current_regions UNION SELECT space FROM current_comments UNION SELECT space FROM current_references UNION SELECT space FROM current_suppressions UNION SELECT space FROM current_modules UNION SELECT space FROM current_operands UNION SELECT space FROM current_patches UNION SELECT space FROM current_switches UNION SELECT space FROM current_releases UNION SELECT space FROM current_macros UNION SELECT space FROM current_macro_uses UNION SELECT space FROM current_start_screens UNION SELECT space FROM current_memory UNION SELECT space FROM current_entries UNION SELECT space FROM current_coverage`,
|
|
810
|
-
)
|
|
811
|
-
.all() as Array<{ space: Space }>;
|
|
812
|
-
const order = (space: Space) => (space === "c64" ? -3 : space === "drive8" ? -2 : space === "loading" ? -1 : Number(space.slice(4)));
|
|
813
|
-
return rows.map((row) => row.space).sort((a, b) => order(a) - order(b));
|
|
819
|
+
const rows = prepare(db, TABLES.map((spec) => `SELECT space FROM current_${spec.table}`).join(" UNION ")).all() as Array<{ space: Space }>;
|
|
820
|
+
return rows.map((row) => row.space).sort((a, b) => spaceOrder(a) - spaceOrder(b));
|
|
814
821
|
}
|
|
815
822
|
|
|
816
823
|
/** Case-insensitive text search in current symbol names and comment texts of one space. */
|
|
@@ -819,16 +826,13 @@ export function search(db: DatabaseSync | undefined, text: string, limit = 50, o
|
|
|
819
826
|
const pattern = `%${text.replace(/[\\%_]/g, (character) => `\\${character}`)}%`;
|
|
820
827
|
const only = origins === undefined ? "" : ` AND origin IN (${origins.map(() => "?").join(", ")})`;
|
|
821
828
|
const values = origins ?? [];
|
|
822
|
-
const symbols = db
|
|
823
|
-
.prepare(`SELECT ${SYMBOL_COLUMNS} FROM current_symbols WHERE space = ? AND name LIKE ? ESCAPE '\\'${only} ORDER BY address LIMIT ?`)
|
|
829
|
+
const symbols = prepare(db, `SELECT ${FACTS.symbols.columns} FROM current_symbols WHERE space = ? AND name LIKE ? ESCAPE '\\'${only} ORDER BY address LIMIT ?`)
|
|
824
830
|
.all(space, pattern, ...values, limit)
|
|
825
831
|
.map((row) => toSymbol(row as Raw));
|
|
826
|
-
const analyzerNames = db
|
|
827
|
-
.prepare(`SELECT ${SYMBOL_COLUMNS} FROM current_analyzer_names WHERE space = ? AND name LIKE ? ESCAPE '\\'${only} ORDER BY address LIMIT ?`)
|
|
832
|
+
const analyzerNames = prepare(db, `SELECT ${FACTS.analyzer_names.columns} FROM current_analyzer_names WHERE space = ? AND name LIKE ? ESCAPE '\\'${only} ORDER BY address LIMIT ?`)
|
|
828
833
|
.all(space, pattern, ...values, limit)
|
|
829
834
|
.map((row) => toSymbol(row as Raw));
|
|
830
|
-
const comments = db
|
|
831
|
-
.prepare(`SELECT ${COMMENT_COLUMNS} FROM current_comments WHERE space = ? AND text LIKE ? ESCAPE '\\'${only} ORDER BY address, placement LIMIT ?`)
|
|
835
|
+
const comments = prepare(db, `SELECT ${FACTS.comments.columns} FROM current_comments WHERE space = ? AND text LIKE ? ESCAPE '\\'${only} ORDER BY address, placement LIMIT ?`)
|
|
832
836
|
.all(space, pattern, ...values, limit)
|
|
833
837
|
.map((row) => toComment(row as Raw));
|
|
834
838
|
return { symbols, analyzerNames, comments };
|
package/src/knowledge/schema.ts
CHANGED
|
@@ -40,6 +40,8 @@ export const REGION_TYPES = [
|
|
|
40
40
|
export type RegionType = (typeof REGION_TYPES)[number];
|
|
41
41
|
/** Region types that are code: a JMP table is code too. dual-use is neither code nor data. */
|
|
42
42
|
export const CODE_REGION_TYPES: readonly RegionType[] = ["code", "jumps"];
|
|
43
|
+
/** Region types whose bytes are instructions: the code types and dual-use. */
|
|
44
|
+
export const INSTRUCTION_REGION_TYPES: readonly RegionType[] = [...CODE_REGION_TYPES, "dual-use"];
|
|
43
45
|
/** Region types that take no element size: their elements are instructions. */
|
|
44
46
|
export const NO_ELEMENT_TYPES: readonly RegionType[] = ["code", "jumps"];
|
|
45
47
|
export const MAX_ELEMENT = 256;
|
|
@@ -48,12 +50,10 @@ export const EVIDENCE_KINDS = ["coverage", "test", "file", "note"] as const;
|
|
|
48
50
|
export type EvidenceKind = (typeof EVIDENCE_KINDS)[number];
|
|
49
51
|
export const COMMENT_PLACEMENTS = ["line", "side"] as const;
|
|
50
52
|
export type CommentPlacement = (typeof COMMENT_PLACEMENTS)[number];
|
|
51
|
-
export { REFERENCE_KINDS, type ReferenceKind };
|
|
52
53
|
/** The reference kind that only operand expressions write: code that builds the address of a symbol. */
|
|
53
54
|
export const POINTER_KIND: ReferenceKind = "pointer";
|
|
54
|
-
export { OPERAND_SELECTS, type OperandSelect } from "./expression.ts";
|
|
55
55
|
/** What a suppression blocks: a symbol address, a region range or one reference. */
|
|
56
|
-
|
|
56
|
+
const SUPPRESSION_ENTITIES = ["symbol", "region", "reference"] as const;
|
|
57
57
|
export type SuppressionEntity = (typeof SUPPRESSION_ENTITIES)[number];
|
|
58
58
|
|
|
59
59
|
/**
|
|
@@ -128,6 +128,12 @@ export function isGeneratedFile(file: string): boolean {
|
|
|
128
128
|
*/
|
|
129
129
|
export type Space = string;
|
|
130
130
|
export const DEFAULT_SPACE: Space = "c64";
|
|
131
|
+
|
|
132
|
+
/** The space of a request: the C64 when it names none. */
|
|
133
|
+
export const spaceOf = (request: { space?: Space }): Space => request.space ?? DEFAULT_SPACE;
|
|
134
|
+
|
|
135
|
+
/** The order of the spaces: the C64, the drive, the loading, then the banks by number. */
|
|
136
|
+
export const spaceOrder = (space: Space): number => (space === "c64" ? -3 : space === "drive8" ? -2 : space === "loading" ? -1 : Number(space.slice(4)));
|
|
131
137
|
const SPACE_CHECK = "space IN ('c64', 'drive8', 'loading') OR space GLOB 'bank[0-9]' OR space GLOB 'bank[1-9][0-9]' OR space GLOB 'bank[12][0-9][0-9]'";
|
|
132
138
|
|
|
133
139
|
const list = (values: readonly string[]) => values.map((value) => `'${value}'`).join(", ");
|