@markw65/monkeyc-optimizer 1.1.18 → 1.1.20

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.
@@ -18,28 +18,27 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var optimizer_exports = {};
20
20
  __export(optimizer_exports, {
21
- StateNodeAttributes: () => import_chunk_YCLY27QH.StateNodeAttributes,
22
- buildOptimizedProject: () => import_chunk_TM6GLTGC.buildOptimizedProject,
23
- copyRecursiveAsNeeded: () => import_chunk_IAUHYWVN.copyRecursiveAsNeeded,
24
- defaultConfig: () => import_chunk_TM6GLTGC.defaultConfig,
25
- display: () => import_chunk_YCLY27QH.display,
26
- generateApiMirTests: () => import_chunk_TM6GLTGC.generateApiMirTests,
27
- generateOneConfig: () => import_chunk_TM6GLTGC.generateOneConfig,
28
- generateOptimizedProject: () => import_chunk_TM6GLTGC.generateOptimizedProject,
29
- getConfig: () => import_chunk_TM6GLTGC.getConfig,
30
- getProjectAnalysis: () => import_chunk_TM6GLTGC.getProjectAnalysis,
31
- get_jungle: () => import_chunk_TM6GLTGC.get_jungle,
32
- isErrorWithLocation: () => import_chunk_TM6GLTGC.isErrorWithLocation,
33
- launchSimulator: () => import_chunk_TM6GLTGC.launchSimulator,
34
- manifestProducts: () => import_chunk_TM6GLTGC.manifestProducts,
35
- mctree: () => import_chunk_TM6GLTGC.mctree,
36
- simulateProgram: () => import_chunk_TM6GLTGC.simulateProgram
21
+ StateNodeAttributes: () => import_chunk_DCGJCC63.StateNodeAttributes,
22
+ buildOptimizedProject: () => import_chunk_DCGJCC63.buildOptimizedProject,
23
+ copyRecursiveAsNeeded: () => import_chunk_APACX34C.copyRecursiveAsNeeded,
24
+ defaultConfig: () => import_chunk_DCGJCC63.defaultConfig,
25
+ display: () => import_chunk_DCGJCC63.display,
26
+ generateApiMirTests: () => import_chunk_DCGJCC63.generateApiMirTests,
27
+ generateOneConfig: () => import_chunk_DCGJCC63.generateOneConfig,
28
+ generateOptimizedProject: () => import_chunk_DCGJCC63.generateOptimizedProject,
29
+ getConfig: () => import_chunk_DCGJCC63.getConfig,
30
+ getProjectAnalysis: () => import_chunk_DCGJCC63.getProjectAnalysis,
31
+ get_jungle: () => import_chunk_DCGJCC63.get_jungle,
32
+ isErrorWithLocation: () => import_chunk_DCGJCC63.isErrorWithLocation,
33
+ launchSimulator: () => import_chunk_DCGJCC63.launchSimulator,
34
+ manifestProducts: () => import_chunk_DCGJCC63.manifestProducts,
35
+ mctree: () => import_chunk_DCGJCC63.mctree,
36
+ simulateProgram: () => import_chunk_DCGJCC63.simulateProgram
37
37
  });
38
38
  module.exports = __toCommonJS(optimizer_exports);
39
- var import_chunk_TM6GLTGC = require("./chunk-TM6GLTGC.cjs");
40
- var import_chunk_YCLY27QH = require("./chunk-YCLY27QH.cjs");
41
- var import_chunk_IAUHYWVN = require("./chunk-IAUHYWVN.cjs");
42
- (0, import_chunk_TM6GLTGC.init_optimizer)();
39
+ var import_chunk_DCGJCC63 = require("./chunk-DCGJCC63.cjs");
40
+ var import_chunk_APACX34C = require("./chunk-APACX34C.cjs");
41
+ (0, import_chunk_DCGJCC63.init_optimizer)();
43
42
  // Annotate the CommonJS export names for ESM import in node:
44
43
  0 && (module.exports = {
45
44
  StateNodeAttributes,
@@ -18,23 +18,23 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var sdk_util_exports = {};
20
20
  __export(sdk_util_exports, {
21
- SectionKinds: () => import_chunk_YCLY27QH.SectionKinds,
22
- appSupport: () => import_chunk_YCLY27QH.appSupport,
23
- connectiq: () => import_chunk_YCLY27QH.connectiq,
24
- getDeviceInfo: () => import_chunk_YCLY27QH.getDeviceInfo,
25
- getFunctionDocumentation: () => import_chunk_YCLY27QH.getFunctionDocumentation,
26
- getLanguages: () => import_chunk_YCLY27QH.getLanguages,
27
- getSdkPath: () => import_chunk_YCLY27QH.getSdkPath,
28
- isWin: () => import_chunk_YCLY27QH.isWin,
29
- optimizeProgram: () => import_chunk_YCLY27QH.optimizeProgram,
30
- readPrg: () => import_chunk_YCLY27QH.readPrg,
31
- readPrgWithOffsets: () => import_chunk_YCLY27QH.readPrgWithOffsets,
32
- xmlUtil: () => import_chunk_YCLY27QH.xml_util_exports
21
+ SectionKinds: () => import_chunk_DCGJCC63.SectionKinds,
22
+ appSupport: () => import_chunk_DCGJCC63.appSupport,
23
+ connectiq: () => import_chunk_DCGJCC63.connectiq,
24
+ getDeviceInfo: () => import_chunk_DCGJCC63.getDeviceInfo,
25
+ getFunctionDocumentation: () => import_chunk_DCGJCC63.getFunctionDocumentation,
26
+ getLanguages: () => import_chunk_DCGJCC63.getLanguages,
27
+ getSdkPath: () => import_chunk_DCGJCC63.getSdkPath,
28
+ isWin: () => import_chunk_DCGJCC63.isWin,
29
+ optimizeProgram: () => import_chunk_DCGJCC63.optimizeProgram,
30
+ readPrg: () => import_chunk_DCGJCC63.readPrg,
31
+ readPrgWithOffsets: () => import_chunk_DCGJCC63.readPrgWithOffsets,
32
+ xmlUtil: () => import_chunk_DCGJCC63.xml_util_exports
33
33
  });
34
34
  module.exports = __toCommonJS(sdk_util_exports);
35
- var import_chunk_YCLY27QH = require("./chunk-YCLY27QH.cjs");
36
- var import_chunk_IAUHYWVN = require("./chunk-IAUHYWVN.cjs");
37
- (0, import_chunk_YCLY27QH.init_sdk_util)();
35
+ var import_chunk_DCGJCC63 = require("./chunk-DCGJCC63.cjs");
36
+ var import_chunk_APACX34C = require("./chunk-APACX34C.cjs");
37
+ (0, import_chunk_DCGJCC63.init_sdk_util)();
38
38
  // Annotate the CommonJS export names for ESM import in node:
39
39
  0 && (module.exports = {
40
40
  SectionKinds,
@@ -1,6 +1,7 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
2
  import { BaseEvent, Block } from "./control-flow";
3
3
  import { FunctionStateNode, ProgramStateAnalysis, StateNodeDecl } from "./optimizer-types";
4
+ import { GenericQueue } from "./util";
4
5
  export declare type RefNode = mctree.Identifier | mctree.MemberExpression | mctree.Literal;
5
6
  export declare type MemberDecl = {
6
7
  type: "MemberDecl";
@@ -101,10 +102,6 @@ export declare function buildDataFlowGraph(state: ProgramStateAnalysis, func: Fu
101
102
  identifiers: Set<string>;
102
103
  graph: Block<Event>;
103
104
  };
104
- export declare class DataflowQueue {
105
- private enqueued;
106
- private queue;
107
- enqueue(block: DataFlowBlock): void;
108
- dequeue(): DataFlowBlock;
109
- empty(): boolean;
105
+ export declare class DataflowQueue extends GenericQueue<DataFlowBlock> {
106
+ constructor();
110
107
  }
@@ -1,2 +1,2 @@
1
1
  import { Block, Context, FuncEntry } from "./bytecode";
2
- export declare function optimizeArrayInit(func: FuncEntry, block: Block, index: number, context: Context): boolean;
2
+ export declare function optimizeArrayInit(func: FuncEntry, block: Block, index: number, stackPreserving: boolean, context: Context): boolean;
@@ -2,10 +2,12 @@
2
2
  import * as crypto from "node:crypto";
3
3
  import { xmlUtil } from "../sdk-util";
4
4
  import { ExceptionEntry, ExceptionsMap } from "./exceptions";
5
+ import { Header } from "./header";
5
6
  import { LineNumber } from "./linenum";
6
7
  import { Bytecode, Opcodes } from "./opcodes";
7
8
  import { SymbolTable } from "./symbols";
8
9
  export declare const enum SectionKinds {
10
+ HEADER = -805253120,
9
11
  TEXT = -1059145026,
10
12
  DATA = -629491010,
11
13
  SYMBOLS = 1461170197,
@@ -23,6 +25,7 @@ export declare type Logger = (module: string, level: number, message: string) =>
23
25
  export declare type Context = {
24
26
  filepath: string;
25
27
  sections: Record<number, SectionInfo>;
28
+ header: Header;
26
29
  symbolTable: SymbolTable;
27
30
  lineTable: Map<number, LineNumber>;
28
31
  exceptionsMap: ExceptionsMap;
@@ -48,9 +51,9 @@ export declare type FuncEntry = {
48
51
  export declare function offsetToString(offset: number): string;
49
52
  export declare function fixSectionSize(section: SectionKinds, sections: Context["sections"], newSize: number): void;
50
53
  export declare function optimizeBytecode(context: Context): void;
51
- export declare function functionBanner(func: FuncEntry, context: Context | null, pass: string): () => string;
54
+ export declare function functionBanner(func: FuncEntry, context: Context | null, pass: string, footer?: (block: Block) => string): () => string;
52
55
  export declare function printFunction(func: FuncEntry, context: Context | null): void;
53
- export declare function functionToString(func: FuncEntry, context: Context | null): string;
56
+ export declare function functionToString(func: FuncEntry, context: Context | null, footer?: (block: Block) => string): string;
54
57
  export declare function blockToString(block: Block, context: Context | null): string;
55
58
  export declare function bytecodeToString(bytecode: Bytecode, symbolTable: SymbolTable | null | undefined): string;
56
59
  export declare function findFunctions({ bytecodes, symbolTable, exceptionsMap, }: Context): Map<number, FuncEntry>;
@@ -0,0 +1,5 @@
1
+ import { Block, FuncEntry } from "./bytecode";
2
+ export declare function postOrderTraverse(func: FuncEntry, visitor: (block: Block) => void): void;
3
+ export declare function intersect<T>(a: Set<T>, b: Set<T>): Set<T>;
4
+ export declare type DomLike = Map<number, Set<number>>;
5
+ export declare function computePostDominators(func: FuncEntry): DomLike;
@@ -1,2 +1,3 @@
1
1
  import { Context, FuncEntry } from "./bytecode";
2
2
  export declare function localDCE(func: FuncEntry, context: Context): boolean;
3
+ export declare function computeLiveLocals(func: FuncEntry): Map<number, Set<number>>;
@@ -0,0 +1,15 @@
1
+ import { Context } from "./bytecode";
2
+ import { UpdateInfo } from "./emit";
3
+ export declare type SectionOffset = {
4
+ data: number;
5
+ code: number;
6
+ };
7
+ export declare type Header = {
8
+ ciqVersion: number;
9
+ backgroundOffsets: SectionOffset;
10
+ appLock: boolean;
11
+ glanceOffsets: SectionOffset;
12
+ flags: number;
13
+ };
14
+ export declare function parseHeader(view: DataView): Header;
15
+ export declare function fixupHeader(context: Context, updateInfo: UpdateInfo): void;
@@ -0,0 +1,5 @@
1
+ import { Block, FuncEntry } from "./bytecode";
2
+ export declare function isSwitchLike(func: FuncEntry, block: Block, index: number): false | {
3
+ xpush: import("./opcodes").Ipush | import("./opcodes").Fpush | import("./opcodes").Spush | import("./opcodes").Bpush | import("./opcodes").Lpush | import("./opcodes").Dpush | import("./opcodes").Cpush;
4
+ index: number;
5
+ };
@@ -19,3 +19,12 @@ export declare function optimizeProgramBuffer(filepath: string, view: DataView,
19
19
  signature: Buffer | undefined;
20
20
  buffer: Buffer;
21
21
  };
22
+ export declare function optimizePrgAndDebug(prgName: string, prgBuffer: ArrayBuffer, prgOffset: number, prgLength: number, xmlName: string, xmlBuffer: ArrayBuffer, xmlOffset: number, xmlLength: number, key: crypto.KeyObject): Promise<{
23
+ sigBuffer: ArrayBufferLike | undefined;
24
+ sigOffset: number | undefined;
25
+ sigLength: number | undefined;
26
+ prgBuffer: ArrayBufferLike;
27
+ prgOffset: number;
28
+ prgLength: number;
29
+ debugXml: string;
30
+ }>;
@@ -23,3 +23,11 @@ export declare function readByLine(file: string, lineHandler: LineHandler): Prom
23
23
  export declare function promiseAll<T>(promiseFn: (i: number) => Promise<T> | null, parallelism: number): Promise<T[]>;
24
24
  export declare function copyRecursiveAsNeeded(source: string, target: string, filter?: (src: string, tgt: string) => boolean): Promise<void>;
25
25
  export declare function popcount(x: number): number;
26
+ export declare class GenericQueue<Block> {
27
+ private enqueued;
28
+ private queue;
29
+ constructor(sort: (a: Block, b: Block) => number);
30
+ enqueue(block: Block): void;
31
+ dequeue(): Block;
32
+ empty(): boolean;
33
+ }
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ import * as crypto from "node:crypto";
1
3
  import { JungleQualifier } from "./jungles";
2
4
  import { BuildConfig } from "./optimizer";
3
5
  import { xmlUtil } from "./sdk-util";
@@ -27,7 +29,21 @@ interface GenerateOptimizedProject extends BaseNode {
27
29
  options: BuildConfig;
28
30
  };
29
31
  }
30
- export declare type WorkerTask = BuildOptimizedProject | GenerateOptimizedProject | GenerateOneConfig;
32
+ interface OptimizePrgAndDebug extends BaseNode {
33
+ type: "optimizePrgAndDebug";
34
+ data: {
35
+ prgName: string;
36
+ prgBuffer: ArrayBuffer;
37
+ prgOffset: number;
38
+ prgLength: number;
39
+ xmlName: string;
40
+ xmlBuffer: ArrayBuffer;
41
+ xmlOffset: number;
42
+ xmlLength: number;
43
+ key: crypto.KeyObject;
44
+ };
45
+ }
46
+ export declare type WorkerTask = BuildOptimizedProject | GenerateOptimizedProject | GenerateOneConfig | OptimizePrgAndDebug;
31
47
  export declare const workerTaskHandlers: {
32
48
  readonly buildOptimizedProject: (data: BuildOptimizedProject["data"]) => Promise<{
33
49
  exe: string;
@@ -54,6 +70,15 @@ export declare const workerTaskHandlers: {
54
70
  hasTests: boolean;
55
71
  diagnostics: Record<string, import("./optimizer-types").Diagnostic[]> | undefined;
56
72
  }>;
73
+ readonly optimizePrgAndDebug: (data: OptimizePrgAndDebug["data"]) => Promise<{
74
+ sigBuffer: ArrayBufferLike | undefined;
75
+ sigOffset: number | undefined;
76
+ sigLength: number | undefined;
77
+ prgBuffer: ArrayBufferLike;
78
+ prgOffset: number;
79
+ prgLength: number;
80
+ debugXml: string;
81
+ }>;
57
82
  };
58
83
  declare type RemovePromise<T> = T extends Promise<infer U> ? U : T;
59
84
  export declare type WorkerTaskResult<T> = T extends WorkerTask ? RemovePromise<ReturnType<typeof workerTaskHandlers[T["type"]]>> : never;
package/build/util.cjs CHANGED
@@ -18,33 +18,35 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var util_exports = {};
20
20
  __export(util_exports, {
21
- bumpLogging: () => import_chunk_IAUHYWVN.bumpLogging,
22
- copyRecursiveAsNeeded: () => import_chunk_IAUHYWVN.copyRecursiveAsNeeded,
23
- every: () => import_chunk_IAUHYWVN.every,
24
- first_modified: () => import_chunk_IAUHYWVN.first_modified,
25
- forEach: () => import_chunk_IAUHYWVN.forEach,
26
- globSome: () => import_chunk_IAUHYWVN.globSome,
27
- globa: () => import_chunk_IAUHYWVN.globa,
28
- last_modified: () => import_chunk_IAUHYWVN.last_modified,
29
- log: () => import_chunk_IAUHYWVN.log,
30
- logger: () => import_chunk_IAUHYWVN.logger,
31
- map: () => import_chunk_IAUHYWVN.map,
32
- popcount: () => import_chunk_IAUHYWVN.popcount,
33
- promiseAll: () => import_chunk_IAUHYWVN.promiseAll,
34
- pushUnique: () => import_chunk_IAUHYWVN.pushUnique,
35
- readByLine: () => import_chunk_IAUHYWVN.readByLine,
36
- reduce: () => import_chunk_IAUHYWVN.reduce,
37
- sameArrays: () => import_chunk_IAUHYWVN.sameArrays,
38
- setBanner: () => import_chunk_IAUHYWVN.setBanner,
39
- some: () => import_chunk_IAUHYWVN.some,
40
- spawnByLine: () => import_chunk_IAUHYWVN.spawnByLine,
41
- wouldLog: () => import_chunk_IAUHYWVN.wouldLog
21
+ GenericQueue: () => import_chunk_APACX34C.GenericQueue,
22
+ bumpLogging: () => import_chunk_APACX34C.bumpLogging,
23
+ copyRecursiveAsNeeded: () => import_chunk_APACX34C.copyRecursiveAsNeeded,
24
+ every: () => import_chunk_APACX34C.every,
25
+ first_modified: () => import_chunk_APACX34C.first_modified,
26
+ forEach: () => import_chunk_APACX34C.forEach,
27
+ globSome: () => import_chunk_APACX34C.globSome,
28
+ globa: () => import_chunk_APACX34C.globa,
29
+ last_modified: () => import_chunk_APACX34C.last_modified,
30
+ log: () => import_chunk_APACX34C.log,
31
+ logger: () => import_chunk_APACX34C.logger,
32
+ map: () => import_chunk_APACX34C.map,
33
+ popcount: () => import_chunk_APACX34C.popcount,
34
+ promiseAll: () => import_chunk_APACX34C.promiseAll,
35
+ pushUnique: () => import_chunk_APACX34C.pushUnique,
36
+ readByLine: () => import_chunk_APACX34C.readByLine,
37
+ reduce: () => import_chunk_APACX34C.reduce,
38
+ sameArrays: () => import_chunk_APACX34C.sameArrays,
39
+ setBanner: () => import_chunk_APACX34C.setBanner,
40
+ some: () => import_chunk_APACX34C.some,
41
+ spawnByLine: () => import_chunk_APACX34C.spawnByLine,
42
+ wouldLog: () => import_chunk_APACX34C.wouldLog
42
43
  });
43
44
  module.exports = __toCommonJS(util_exports);
44
- var import_chunk_IAUHYWVN = require("./chunk-IAUHYWVN.cjs");
45
- (0, import_chunk_IAUHYWVN.init_util)();
45
+ var import_chunk_APACX34C = require("./chunk-APACX34C.cjs");
46
+ (0, import_chunk_APACX34C.init_util)();
46
47
  // Annotate the CommonJS export names for ESM import in node:
47
48
  0 && (module.exports = {
49
+ GenericQueue,
48
50
  bumpLogging,
49
51
  copyRecursiveAsNeeded,
50
52
  every,
@@ -18,15 +18,14 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var worker_pool_exports = {};
20
20
  __export(worker_pool_exports, {
21
- runTaskInPool: () => import_chunk_TM6GLTGC.runTaskInPool,
22
- startPool: () => import_chunk_TM6GLTGC.startPool,
23
- stopPool: () => import_chunk_TM6GLTGC.stopPool
21
+ runTaskInPool: () => import_chunk_DCGJCC63.runTaskInPool,
22
+ startPool: () => import_chunk_DCGJCC63.startPool,
23
+ stopPool: () => import_chunk_DCGJCC63.stopPool
24
24
  });
25
25
  module.exports = __toCommonJS(worker_pool_exports);
26
- var import_chunk_TM6GLTGC = require("./chunk-TM6GLTGC.cjs");
27
- var import_chunk_YCLY27QH = require("./chunk-YCLY27QH.cjs");
28
- var import_chunk_IAUHYWVN = require("./chunk-IAUHYWVN.cjs");
29
- (0, import_chunk_TM6GLTGC.init_worker_pool)();
26
+ var import_chunk_DCGJCC63 = require("./chunk-DCGJCC63.cjs");
27
+ var import_chunk_APACX34C = require("./chunk-APACX34C.cjs");
28
+ (0, import_chunk_DCGJCC63.init_worker_pool)();
30
29
  // Annotate the CommonJS export names for ESM import in node:
31
30
  0 && (module.exports = {
32
31
  runTaskInPool,
@@ -21,16 +21,15 @@ __export(worker_thread_exports, {
21
21
  default: () => worker_thread_default
22
22
  });
23
23
  module.exports = __toCommonJS(worker_thread_exports);
24
- var import_chunk_TM6GLTGC = require("./chunk-TM6GLTGC.cjs");
25
- var import_chunk_YCLY27QH = require("./chunk-YCLY27QH.cjs");
26
- var import_chunk_IAUHYWVN = require("./chunk-IAUHYWVN.cjs");
24
+ var import_chunk_DCGJCC63 = require("./chunk-DCGJCC63.cjs");
25
+ var import_chunk_APACX34C = require("./chunk-APACX34C.cjs");
27
26
  var import_node_worker_threads = require("node:worker_threads");
28
- var require_worker_thread = (0, import_chunk_IAUHYWVN.__commonJS)({
27
+ var require_worker_thread = (0, import_chunk_APACX34C.__commonJS)({
29
28
  "src/worker-thread.ts"() {
30
- (0, import_chunk_TM6GLTGC.init_worker_task)();
29
+ (0, import_chunk_DCGJCC63.init_worker_task)();
31
30
  if (import_node_worker_threads.parentPort) {
32
31
  import_node_worker_threads.parentPort.on("message", async (task) => {
33
- return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_TM6GLTGC.performTask)(task));
32
+ return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_DCGJCC63.performTask)(task));
34
33
  });
35
34
  }
36
35
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markw65/monkeyc-optimizer",
3
3
  "type": "commonjs",
4
- "version": "1.1.18",
4
+ "version": "1.1.20",
5
5
  "description": "Source to source optimizer for Garmin Monkey C code",
6
6
  "main": "build/optimizer.cjs",
7
7
  "types": "build/src/optimizer.d.ts",