@markw65/monkeyc-optimizer 1.1.13 → 1.1.14
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/README.md +11 -0
- package/build/api.cjs +2 -1
- package/build/optimizer.cjs +13 -5
- package/build/sdk-util.cjs +10357 -615
- package/build/src/logger.d.ts +4 -0
- package/build/src/optimizer-types.d.ts +1 -0
- package/build/src/optimizer.d.ts +5 -0
- package/build/src/readprg/bytecode.d.ts +50 -0
- package/build/src/readprg/data.d.ts +4 -0
- package/build/src/readprg/dce.d.ts +2 -0
- package/build/src/readprg/emit.d.ts +12 -0
- package/build/src/readprg/exceptions.d.ts +9 -0
- package/build/src/readprg/linenum.d.ts +29 -0
- package/build/src/readprg/opcodes.d.ts +260 -0
- package/build/src/readprg/optimize.d.ts +3 -0
- package/build/src/readprg/signer.d.ts +8 -0
- package/build/src/readprg/symbols.d.ts +18 -0
- package/build/src/readprg.d.ts +21 -5
- package/build/src/sdk-util.d.ts +2 -1
- package/build/src/util.d.ts +1 -0
- package/build/src/xml-util.d.ts +2 -2
- package/build/util.cjs +48 -2
- package/package.json +9 -5
- package/build/src/type-flow/live-range.d.ts +0 -0
- package/build/src/type-flow/mimimize-modules.d.ts +0 -3
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function logger(module: string, level: number, message: unknown): void;
|
|
2
|
+
export declare function wouldLog(module: string, level: number): boolean;
|
|
3
|
+
export declare function log(message: unknown): void;
|
|
4
|
+
export declare function setLogger(log: (message: string) => void): void;
|
|
@@ -39,6 +39,7 @@ export declare type BuildConfig = {
|
|
|
39
39
|
trustDeclaredTypes?: boolean;
|
|
40
40
|
minimizeLocals?: boolean;
|
|
41
41
|
minimizeModules?: boolean;
|
|
42
|
+
postBuildOptimizer?: boolean;
|
|
42
43
|
singleUseCopyProp?: boolean;
|
|
43
44
|
covarianceWarnings?: boolean;
|
|
44
45
|
checkTypes?: DiagnosticType | "OFF";
|
package/build/src/optimizer.d.ts
CHANGED
|
@@ -20,6 +20,11 @@ export declare function isErrorWithLocation(e: Error): e is ErrorWithLocation;
|
|
|
20
20
|
declare global {
|
|
21
21
|
var lastModifiedSource: number;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* @param {BuildConfig} options
|
|
25
|
+
* @returns {Promise<BuildConfig>}
|
|
26
|
+
*/
|
|
27
|
+
export declare function getConfig(options: BuildConfig): Promise<BuildConfig>;
|
|
23
28
|
/**
|
|
24
29
|
*
|
|
25
30
|
* WARNING WARNING WARNING WARNING WARNING WARNING
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as crypto from "node:crypto";
|
|
3
|
+
import { xmlUtil } from "../sdk-util";
|
|
4
|
+
import { ExceptionEntry, ExceptionsMap } from "./exceptions";
|
|
5
|
+
import { LineNumber } from "./linenum";
|
|
6
|
+
import { Bytecode, Opcodes } from "./opcodes";
|
|
7
|
+
import { SymbolTable } from "./symbols";
|
|
8
|
+
export declare const enum SectionKinds {
|
|
9
|
+
TEXT = -1059145026,
|
|
10
|
+
DATA = -629491010,
|
|
11
|
+
SYMBOLS = 1461170197,
|
|
12
|
+
LINENUM = -1059161423,
|
|
13
|
+
EXCEPTIONS = 248410373,
|
|
14
|
+
SIGNATURE = -507453934,
|
|
15
|
+
STORE_SIG = 20833
|
|
16
|
+
}
|
|
17
|
+
export declare type SectionInfo = {
|
|
18
|
+
offset: number;
|
|
19
|
+
length: number;
|
|
20
|
+
view: DataView;
|
|
21
|
+
};
|
|
22
|
+
export declare type Logger = (module: string, level: number, message: string) => void;
|
|
23
|
+
export declare type Context = {
|
|
24
|
+
filepath: string;
|
|
25
|
+
sections: Record<number, SectionInfo>;
|
|
26
|
+
symbolTable: SymbolTable;
|
|
27
|
+
lineTable: Map<number, LineNumber>;
|
|
28
|
+
exceptionsMap: ExceptionsMap;
|
|
29
|
+
bytecodes: Bytecode[];
|
|
30
|
+
key?: crypto.KeyObject;
|
|
31
|
+
debugXml: xmlUtil.Document;
|
|
32
|
+
};
|
|
33
|
+
export declare type Block = {
|
|
34
|
+
offset: number;
|
|
35
|
+
bytecodes: Bytecode[];
|
|
36
|
+
try?: ExceptionEntry[];
|
|
37
|
+
next?: number;
|
|
38
|
+
taken?: number;
|
|
39
|
+
};
|
|
40
|
+
export declare type FuncEntry = {
|
|
41
|
+
name?: string;
|
|
42
|
+
offset: number;
|
|
43
|
+
blocks: Map<number, Block>;
|
|
44
|
+
};
|
|
45
|
+
export declare function offsetToString(offset: number): string;
|
|
46
|
+
export declare function fixSectionSize(section: SectionKinds, sections: Context["sections"], newSize: number): void;
|
|
47
|
+
export declare function optimizeBytecode(context: Context): void;
|
|
48
|
+
export declare function printFunction(func: FuncEntry, context: Context | null): void;
|
|
49
|
+
export declare function bytecodeToString(bytecode: Bytecode, symbolTable: SymbolTable | null | undefined): string;
|
|
50
|
+
export declare function makeArgless(bc: Bytecode, op: Opcodes): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Context, FuncEntry } from "./bytecode";
|
|
2
|
+
import { LineNumber } from "./linenum";
|
|
3
|
+
export declare type LocalsMap = Map<number, {
|
|
4
|
+
startPc: number;
|
|
5
|
+
endPc: number;
|
|
6
|
+
}>;
|
|
7
|
+
export declare type UpdateInfo = {
|
|
8
|
+
offsetMap: Map<number, number>;
|
|
9
|
+
localsMap: Map<FuncEntry, LocalsMap>;
|
|
10
|
+
lineMap: LineNumber[];
|
|
11
|
+
};
|
|
12
|
+
export declare function emitFunc(func: FuncEntry, view: DataView, start: number, updateInfo: UpdateInfo, context: Context): number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Context } from "./bytecode";
|
|
2
|
+
export declare type ExceptionEntry = {
|
|
3
|
+
tryStart: number;
|
|
4
|
+
tryEnd: number;
|
|
5
|
+
handler: number;
|
|
6
|
+
};
|
|
7
|
+
export declare type ExceptionsMap = Map<number, ExceptionEntry[]>;
|
|
8
|
+
export declare function parseExceptions(view: DataView): ExceptionsMap;
|
|
9
|
+
export declare function fixupExceptions(context: Context, offsetMap: Map<number, number>): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { xmlUtil } from "../sdk-util";
|
|
2
|
+
import { Context } from "./bytecode";
|
|
3
|
+
import { UpdateInfo } from "./emit";
|
|
4
|
+
interface BaseLineNumber {
|
|
5
|
+
pc: number;
|
|
6
|
+
file?: number | undefined;
|
|
7
|
+
fileStr?: string | undefined;
|
|
8
|
+
symbol?: number | undefined;
|
|
9
|
+
symbolStr?: string | undefined;
|
|
10
|
+
line: number;
|
|
11
|
+
}
|
|
12
|
+
interface LineNumberSym extends BaseLineNumber {
|
|
13
|
+
file: number;
|
|
14
|
+
symbol: number;
|
|
15
|
+
fileStr?: undefined;
|
|
16
|
+
symbolStr?: undefined;
|
|
17
|
+
}
|
|
18
|
+
interface LineNumberStr extends BaseLineNumber {
|
|
19
|
+
file?: undefined;
|
|
20
|
+
symbol?: undefined;
|
|
21
|
+
fileStr: string;
|
|
22
|
+
symbolStr: string;
|
|
23
|
+
parent?: string | undefined;
|
|
24
|
+
id: number;
|
|
25
|
+
}
|
|
26
|
+
export declare type LineNumber = LineNumberStr | LineNumberSym;
|
|
27
|
+
export declare function parseLineNum(view: DataView, debugXml: xmlUtil.Document): Map<number, LineNumber>;
|
|
28
|
+
export declare function fixupLineNum(context: Context, updateInfo: UpdateInfo): void;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { LineNumber } from "./linenum";
|
|
2
|
+
export declare enum Opcodes {
|
|
3
|
+
nop = 0,
|
|
4
|
+
incsp = 1,
|
|
5
|
+
popv = 2,
|
|
6
|
+
addv = 3,
|
|
7
|
+
subv = 4,
|
|
8
|
+
mulv = 5,
|
|
9
|
+
divv = 6,
|
|
10
|
+
andv = 7,
|
|
11
|
+
orv = 8,
|
|
12
|
+
modv = 9,
|
|
13
|
+
shlv = 10,
|
|
14
|
+
shrv = 11,
|
|
15
|
+
xorv = 12,
|
|
16
|
+
getv = 13,
|
|
17
|
+
putv = 14,
|
|
18
|
+
invokem = 15,
|
|
19
|
+
agetv = 16,
|
|
20
|
+
aputv = 17,
|
|
21
|
+
lgetv = 18,
|
|
22
|
+
lputv = 19,
|
|
23
|
+
newa = 20,
|
|
24
|
+
newc = 21,
|
|
25
|
+
return = 22,
|
|
26
|
+
ret = 23,
|
|
27
|
+
news = 24,
|
|
28
|
+
goto = 25,
|
|
29
|
+
eq = 26,
|
|
30
|
+
lt = 27,
|
|
31
|
+
lte = 28,
|
|
32
|
+
gt = 29,
|
|
33
|
+
gte = 30,
|
|
34
|
+
ne = 31,
|
|
35
|
+
isnull = 32,
|
|
36
|
+
isa = 33,
|
|
37
|
+
canhazplz = 34,
|
|
38
|
+
jsr = 35,
|
|
39
|
+
ts = 36,
|
|
40
|
+
ipush = 37,
|
|
41
|
+
fpush = 38,
|
|
42
|
+
spush = 39,
|
|
43
|
+
bt = 40,
|
|
44
|
+
bf = 41,
|
|
45
|
+
frpush = 42,
|
|
46
|
+
bpush = 43,
|
|
47
|
+
npush = 44,
|
|
48
|
+
invv = 45,
|
|
49
|
+
dup = 46,
|
|
50
|
+
newd = 47,
|
|
51
|
+
getm = 48,
|
|
52
|
+
lpush = 49,
|
|
53
|
+
dpush = 50,
|
|
54
|
+
throw = 51,
|
|
55
|
+
cpush = 52,
|
|
56
|
+
argc = 53,
|
|
57
|
+
newba = 54
|
|
58
|
+
}
|
|
59
|
+
interface BaseOpcode {
|
|
60
|
+
op: Opcodes;
|
|
61
|
+
offset: number;
|
|
62
|
+
size: number;
|
|
63
|
+
lineNum?: LineNumber;
|
|
64
|
+
arg?: unknown;
|
|
65
|
+
}
|
|
66
|
+
export interface Incsp extends BaseOpcode {
|
|
67
|
+
op: Opcodes.incsp;
|
|
68
|
+
arg: number;
|
|
69
|
+
}
|
|
70
|
+
export interface Argless extends BaseOpcode {
|
|
71
|
+
arg?: never;
|
|
72
|
+
}
|
|
73
|
+
export interface ByteArg extends BaseOpcode {
|
|
74
|
+
arg: number;
|
|
75
|
+
}
|
|
76
|
+
export interface ShortArg extends BaseOpcode {
|
|
77
|
+
arg: number;
|
|
78
|
+
}
|
|
79
|
+
export interface WordArg extends BaseOpcode {
|
|
80
|
+
arg: number;
|
|
81
|
+
}
|
|
82
|
+
export interface FloatArg extends BaseOpcode {
|
|
83
|
+
arg: number;
|
|
84
|
+
}
|
|
85
|
+
export interface LongArg extends BaseOpcode {
|
|
86
|
+
arg: bigint;
|
|
87
|
+
}
|
|
88
|
+
export interface DoubleArg extends BaseOpcode {
|
|
89
|
+
arg: number;
|
|
90
|
+
}
|
|
91
|
+
export interface Nop extends Argless {
|
|
92
|
+
op: Opcodes.nop;
|
|
93
|
+
}
|
|
94
|
+
export interface Popv extends Argless {
|
|
95
|
+
op: Opcodes.popv;
|
|
96
|
+
}
|
|
97
|
+
export interface Addv extends Argless {
|
|
98
|
+
op: Opcodes.addv;
|
|
99
|
+
}
|
|
100
|
+
export interface Subv extends Argless {
|
|
101
|
+
op: Opcodes.subv;
|
|
102
|
+
}
|
|
103
|
+
export interface Mulv extends Argless {
|
|
104
|
+
op: Opcodes.mulv;
|
|
105
|
+
}
|
|
106
|
+
export interface Divv extends Argless {
|
|
107
|
+
op: Opcodes.divv;
|
|
108
|
+
}
|
|
109
|
+
export interface Andv extends Argless {
|
|
110
|
+
op: Opcodes.andv;
|
|
111
|
+
}
|
|
112
|
+
export interface Orv extends Argless {
|
|
113
|
+
op: Opcodes.orv;
|
|
114
|
+
}
|
|
115
|
+
export interface Modv extends Argless {
|
|
116
|
+
op: Opcodes.modv;
|
|
117
|
+
}
|
|
118
|
+
export interface Shlv extends ByteArg {
|
|
119
|
+
op: Opcodes.shlv;
|
|
120
|
+
}
|
|
121
|
+
export interface Shrv extends ByteArg {
|
|
122
|
+
op: Opcodes.shrv;
|
|
123
|
+
}
|
|
124
|
+
export interface Xorv extends Argless {
|
|
125
|
+
op: Opcodes.xorv;
|
|
126
|
+
}
|
|
127
|
+
export interface Getv extends Argless {
|
|
128
|
+
op: Opcodes.getv;
|
|
129
|
+
}
|
|
130
|
+
export interface Putv extends Argless {
|
|
131
|
+
op: Opcodes.putv;
|
|
132
|
+
}
|
|
133
|
+
export interface Invokem extends ByteArg {
|
|
134
|
+
op: Opcodes.invokem;
|
|
135
|
+
}
|
|
136
|
+
export interface Agetv extends Argless {
|
|
137
|
+
op: Opcodes.agetv;
|
|
138
|
+
}
|
|
139
|
+
export interface Aputv extends Argless {
|
|
140
|
+
op: Opcodes.aputv;
|
|
141
|
+
}
|
|
142
|
+
export interface Lgetv extends ByteArg {
|
|
143
|
+
op: Opcodes.lgetv;
|
|
144
|
+
}
|
|
145
|
+
export interface Lputv extends ByteArg {
|
|
146
|
+
op: Opcodes.lputv;
|
|
147
|
+
}
|
|
148
|
+
export interface Newa extends Argless {
|
|
149
|
+
op: Opcodes.newa;
|
|
150
|
+
}
|
|
151
|
+
export interface Newc extends Argless {
|
|
152
|
+
op: Opcodes.newc;
|
|
153
|
+
}
|
|
154
|
+
export interface Return extends Argless {
|
|
155
|
+
op: Opcodes.return;
|
|
156
|
+
}
|
|
157
|
+
export interface Ret extends Argless {
|
|
158
|
+
op: Opcodes.ret;
|
|
159
|
+
}
|
|
160
|
+
export interface News extends WordArg {
|
|
161
|
+
op: Opcodes.news;
|
|
162
|
+
}
|
|
163
|
+
export interface Goto extends ShortArg {
|
|
164
|
+
op: Opcodes.goto;
|
|
165
|
+
}
|
|
166
|
+
export interface Bt extends ShortArg {
|
|
167
|
+
op: Opcodes.bt;
|
|
168
|
+
}
|
|
169
|
+
export interface Bf extends ShortArg {
|
|
170
|
+
op: Opcodes.bf;
|
|
171
|
+
}
|
|
172
|
+
export interface Jsr extends ShortArg {
|
|
173
|
+
op: Opcodes.jsr;
|
|
174
|
+
}
|
|
175
|
+
export interface Eq extends Argless {
|
|
176
|
+
op: Opcodes.eq;
|
|
177
|
+
}
|
|
178
|
+
export interface Lt extends Argless {
|
|
179
|
+
op: Opcodes.lt;
|
|
180
|
+
}
|
|
181
|
+
export interface Lte extends Argless {
|
|
182
|
+
op: Opcodes.lte;
|
|
183
|
+
}
|
|
184
|
+
export interface Gt extends Argless {
|
|
185
|
+
op: Opcodes.gt;
|
|
186
|
+
}
|
|
187
|
+
export interface Gte extends Argless {
|
|
188
|
+
op: Opcodes.gte;
|
|
189
|
+
}
|
|
190
|
+
export interface Ne extends Argless {
|
|
191
|
+
op: Opcodes.ne;
|
|
192
|
+
}
|
|
193
|
+
export interface Isnull extends Argless {
|
|
194
|
+
op: Opcodes.isnull;
|
|
195
|
+
}
|
|
196
|
+
export interface Isa extends Argless {
|
|
197
|
+
op: Opcodes.isa;
|
|
198
|
+
}
|
|
199
|
+
export interface Canhazplz extends Argless {
|
|
200
|
+
op: Opcodes.canhazplz;
|
|
201
|
+
}
|
|
202
|
+
export interface Ts extends Argless {
|
|
203
|
+
op: Opcodes.ts;
|
|
204
|
+
}
|
|
205
|
+
export interface Ipush extends WordArg {
|
|
206
|
+
op: Opcodes.ipush;
|
|
207
|
+
}
|
|
208
|
+
export interface Fpush extends FloatArg {
|
|
209
|
+
op: Opcodes.fpush;
|
|
210
|
+
}
|
|
211
|
+
export interface Spush extends WordArg {
|
|
212
|
+
op: Opcodes.spush;
|
|
213
|
+
}
|
|
214
|
+
export interface Frpush extends Argless {
|
|
215
|
+
op: Opcodes.frpush;
|
|
216
|
+
}
|
|
217
|
+
export interface Bpush extends ByteArg {
|
|
218
|
+
op: Opcodes.bpush;
|
|
219
|
+
}
|
|
220
|
+
export interface Npush extends Argless {
|
|
221
|
+
op: Opcodes.npush;
|
|
222
|
+
}
|
|
223
|
+
export interface Invv extends Argless {
|
|
224
|
+
op: Opcodes.invv;
|
|
225
|
+
}
|
|
226
|
+
export interface Dup extends ByteArg {
|
|
227
|
+
op: Opcodes.dup;
|
|
228
|
+
}
|
|
229
|
+
export interface Newd extends Argless {
|
|
230
|
+
op: Opcodes.newd;
|
|
231
|
+
}
|
|
232
|
+
export interface Getm extends Argless {
|
|
233
|
+
op: Opcodes.getm;
|
|
234
|
+
}
|
|
235
|
+
export interface Lpush extends LongArg {
|
|
236
|
+
op: Opcodes.lpush;
|
|
237
|
+
}
|
|
238
|
+
export interface Dpush extends DoubleArg {
|
|
239
|
+
op: Opcodes.dpush;
|
|
240
|
+
}
|
|
241
|
+
export interface Throw extends Argless {
|
|
242
|
+
op: Opcodes.throw;
|
|
243
|
+
}
|
|
244
|
+
export interface Cpush extends WordArg {
|
|
245
|
+
op: Opcodes.cpush;
|
|
246
|
+
}
|
|
247
|
+
export interface Newba extends Argless {
|
|
248
|
+
op: Opcodes.newba;
|
|
249
|
+
}
|
|
250
|
+
export interface Argc extends ByteArg {
|
|
251
|
+
op: Opcodes.argc;
|
|
252
|
+
}
|
|
253
|
+
export declare type Bytecode = Nop | Incsp | Popv | Addv | Subv | Mulv | Divv | Andv | Orv | Modv | Shlv | Shrv | Xorv | Getv | Putv | Invokem | Agetv | Aputv | Lgetv | Lputv | Newa | Newc | Return | Ret | News | Goto | Eq | Lt | Lte | Gt | Gte | Ne | Isnull | Isa | Canhazplz | Jsr | Ts | Ipush | Fpush | Spush | Bt | Bf | Frpush | Bpush | Npush | Invv | Dup | Newd | Getm | Lpush | Dpush | Throw | Cpush | Argc | Newba;
|
|
254
|
+
export declare function parseCode(view: DataView, lineTable: Map<number, LineNumber>): Bytecode[];
|
|
255
|
+
export declare function emitBytecode(bytecode: Bytecode, view: DataView, offset: number, linktable: Map<number, number>): number;
|
|
256
|
+
export declare function getOpInfo(bytecode: Bytecode): {
|
|
257
|
+
pop: number;
|
|
258
|
+
push: number;
|
|
259
|
+
};
|
|
260
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import * as crypto from "node:crypto";
|
|
4
|
+
import { Context } from "./bytecode";
|
|
5
|
+
export declare function getPrgSignature(context: Context): Buffer | undefined;
|
|
6
|
+
export declare function getDevKey(file: string): Promise<crypto.KeyObject>;
|
|
7
|
+
export declare function signatureFromContext(context: Context): Buffer | null;
|
|
8
|
+
export declare function signView(key: crypto.KeyObject, view: DataView): Buffer;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { xmlUtil } from "../sdk-util";
|
|
3
|
+
export declare class SymbolTable {
|
|
4
|
+
symbolToLabelMap: Map<number, number>;
|
|
5
|
+
symbols: Map<number, {
|
|
6
|
+
str: string;
|
|
7
|
+
label: string;
|
|
8
|
+
}>;
|
|
9
|
+
methods: Map<number, {
|
|
10
|
+
name: string;
|
|
11
|
+
id: number | null;
|
|
12
|
+
}>;
|
|
13
|
+
decoder: import("util").TextDecoder;
|
|
14
|
+
parseSymbolTable(view: DataView): number;
|
|
15
|
+
parse(view: DataView): void;
|
|
16
|
+
parseXml(debugXml: xmlUtil.Document): void;
|
|
17
|
+
parseSymbol(view: DataView, offset: number, current: number): number;
|
|
18
|
+
}
|
package/build/src/readprg.d.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import * as crypto from "node:crypto";
|
|
4
|
+
import { SectionInfo } from "./readprg/bytecode";
|
|
5
|
+
import { xmlUtil } from "./sdk-util";
|
|
6
|
+
export declare function readPrg(path: string): Promise<{
|
|
7
|
+
[k: string]: number;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function readPrgFromFile(prg: string): Promise<{
|
|
10
|
+
view: DataView;
|
|
11
|
+
sections: Record<number, SectionInfo>;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function readPrgWithOffsets(view: DataView): {
|
|
14
|
+
view: DataView;
|
|
15
|
+
sections: Record<number, SectionInfo>;
|
|
16
|
+
};
|
|
17
|
+
export declare function optimizeProgram(filepath: string, devKey?: string | undefined, output?: string): Promise<unknown>;
|
|
18
|
+
export declare function optimizeProgramBuffer(filepath: string, view: DataView, debugXml: xmlUtil.Document, key: crypto.KeyObject | undefined): {
|
|
19
|
+
signature: Buffer | undefined;
|
|
20
|
+
buffer: Buffer;
|
|
21
|
+
};
|
package/build/src/sdk-util.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { readPrg,
|
|
1
|
+
export { readPrg, optimizeProgram, readPrgWithOffsets } from "./readprg";
|
|
2
|
+
export { SectionKinds } from "./readprg/bytecode";
|
|
2
3
|
export * as xmlUtil from "./xml-util";
|
|
3
4
|
export declare const isWin: boolean;
|
|
4
5
|
export declare const appSupport: string;
|
package/build/src/util.d.ts
CHANGED
package/build/src/xml-util.d.ts
CHANGED
|
@@ -124,8 +124,8 @@ export interface Prolog extends BaseNode {
|
|
|
124
124
|
interface XmlDecl extends BaseNode {
|
|
125
125
|
type: "xmldecl";
|
|
126
126
|
version: "1.0";
|
|
127
|
-
encoding?: string
|
|
128
|
-
standalone?: string
|
|
127
|
+
encoding?: string;
|
|
128
|
+
standalone?: string;
|
|
129
129
|
}
|
|
130
130
|
export declare class Document {
|
|
131
131
|
prolog: Prolog | null;
|
package/build/util.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
0 && (module.exports = {copyRecursiveAsNeeded,every,first_modified,forEach,globSome,globa,last_modified,map,popcount,promiseAll,pushUnique,readByLine,reduce,sameArrays,some,spawnByLine});
|
|
1
|
+
0 && (module.exports = {copyRecursiveAsNeeded,every,first_modified,forEach,globSome,globa,last_modified,log,logger,map,popcount,promiseAll,pushUnique,readByLine,reduce,sameArrays,some,spawnByLine,wouldLog});
|
|
2
2
|
/******/ (() => { // webpackBootstrap
|
|
3
3
|
/******/ var __webpack_modules__ = ({
|
|
4
4
|
|
|
@@ -7719,6 +7719,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
7719
7719
|
"globSome": () => (/* binding */ globSome),
|
|
7720
7720
|
"globa": () => (/* binding */ globa),
|
|
7721
7721
|
"last_modified": () => (/* binding */ last_modified),
|
|
7722
|
+
"log": () => (/* reexport */ log),
|
|
7723
|
+
"logger": () => (/* reexport */ logger),
|
|
7722
7724
|
"map": () => (/* binding */ map),
|
|
7723
7725
|
"popcount": () => (/* binding */ popcount),
|
|
7724
7726
|
"promiseAll": () => (/* binding */ promiseAll),
|
|
@@ -7727,7 +7729,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
7727
7729
|
"reduce": () => (/* binding */ reduce),
|
|
7728
7730
|
"sameArrays": () => (/* binding */ sameArrays),
|
|
7729
7731
|
"some": () => (/* binding */ some),
|
|
7730
|
-
"spawnByLine": () => (/* binding */ spawnByLine)
|
|
7732
|
+
"spawnByLine": () => (/* binding */ spawnByLine),
|
|
7733
|
+
"wouldLog": () => (/* reexport */ wouldLog)
|
|
7731
7734
|
});
|
|
7732
7735
|
|
|
7733
7736
|
;// CONCATENATED MODULE: external "child_process"
|
|
@@ -7742,6 +7745,48 @@ var out = __webpack_require__(3294);
|
|
|
7742
7745
|
var external_path_ = __webpack_require__(1423);
|
|
7743
7746
|
;// CONCATENATED MODULE: external "readline"
|
|
7744
7747
|
const external_readline_namespaceObject = require("readline");
|
|
7748
|
+
;// CONCATENATED MODULE: ./src/logger.ts
|
|
7749
|
+
let loggerSettings = null;
|
|
7750
|
+
let theLogger = console.log;
|
|
7751
|
+
function logger(module, level, message) {
|
|
7752
|
+
if (wouldLog(module, level)) {
|
|
7753
|
+
log(message);
|
|
7754
|
+
}
|
|
7755
|
+
}
|
|
7756
|
+
function wouldLog(module, level) {
|
|
7757
|
+
if (!loggerSettings) {
|
|
7758
|
+
loggerSettings = getLoggerSettings();
|
|
7759
|
+
}
|
|
7760
|
+
return (loggerSettings.get(module) ?? 0) >= level;
|
|
7761
|
+
}
|
|
7762
|
+
function log(message) {
|
|
7763
|
+
if (theLogger === console.log) {
|
|
7764
|
+
theLogger(message);
|
|
7765
|
+
}
|
|
7766
|
+
else {
|
|
7767
|
+
theLogger(`${message}`);
|
|
7768
|
+
}
|
|
7769
|
+
}
|
|
7770
|
+
function setLogger(log) {
|
|
7771
|
+
theLogger = log;
|
|
7772
|
+
}
|
|
7773
|
+
function getLoggerSettings() {
|
|
7774
|
+
const ls = new Map();
|
|
7775
|
+
const settings = process.env["MC_LOGGER"];
|
|
7776
|
+
if (settings) {
|
|
7777
|
+
settings.split(";").forEach((setting) => {
|
|
7778
|
+
const results = setting.split(/[:=]/, 2);
|
|
7779
|
+
if (results.length === 1) {
|
|
7780
|
+
ls.set(results[0], 1);
|
|
7781
|
+
}
|
|
7782
|
+
else {
|
|
7783
|
+
ls.set(results[0], Number(results[1]));
|
|
7784
|
+
}
|
|
7785
|
+
});
|
|
7786
|
+
}
|
|
7787
|
+
return ls;
|
|
7788
|
+
}
|
|
7789
|
+
|
|
7745
7790
|
;// CONCATENATED MODULE: ./src/util.ts
|
|
7746
7791
|
|
|
7747
7792
|
|
|
@@ -7753,6 +7798,7 @@ const external_readline_namespaceObject = require("readline");
|
|
|
7753
7798
|
// recognize global.lastModifiedSource.
|
|
7754
7799
|
// @ts-ignore
|
|
7755
7800
|
__webpack_require__.g["lastModifiedSource" + ""] = 0;
|
|
7801
|
+
|
|
7756
7802
|
function globa(pattern, options) {
|
|
7757
7803
|
if (options?.mark) {
|
|
7758
7804
|
options.markDirectories = true;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markw65/monkeyc-optimizer",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.14",
|
|
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",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"prepack": "webpack --mode production",
|
|
24
24
|
"test": "npm run test-mocha && npm run test-optimized && npm run test-unopt && npm run test-remote && npm run test-remote-tests",
|
|
25
25
|
"test-mocha": "npx mocha --timeout 999999 build/mocha.cjs",
|
|
26
|
-
"test-remote": "node ./test/test.js --product=pick-one --github",
|
|
27
|
-
"test-remote-tests": "node ./test/test.js --product=pick-one --run-tests --github",
|
|
28
|
-
"test-optimized": "node test/test.js --typeCheckLevel Strict --run-tests --product=fenix5 --product=fr235 --jungle ./test/OptimizerTests/monkey.jungle",
|
|
26
|
+
"test-remote": "node ./test/test.js --showInfo --postOptimize --product=pick-one --github",
|
|
27
|
+
"test-remote-tests": "node ./test/test.js --showInfo --postOptimize --product=pick-one --run-tests --github",
|
|
28
|
+
"test-optimized": "node test/test.js --showInfo --postOptimize --typeCheckLevel Strict --run-tests --product=fenix5 --product=fr235 --jungle ./test/OptimizerTests/monkey.jungle",
|
|
29
29
|
"test-unopt": "node test/test.js --typeCheckLevel Strict --skipOptimization --run-tests --product=fenix5 --product=fr235 --jungle ./test/OptimizerTests/monkey.jungle",
|
|
30
30
|
"test-garmin-opt": "node test/test.js --typeCheckLevel Strict --skipOptimization --garminOptLevel=2 --run-tests --product=fenix5 --product=fr235 --jungle ./test/OptimizerTests/monkey.jungle",
|
|
31
31
|
"eslint": "npx eslint ."
|
|
@@ -48,6 +48,8 @@
|
|
|
48
48
|
"@types/mocha": "^10.0.1",
|
|
49
49
|
"@types/prettier": "^2.6.1",
|
|
50
50
|
"@types/priorityqueuejs": "^1.0.1",
|
|
51
|
+
"@types/yauzl": "^2.10.0",
|
|
52
|
+
"@types/yazl": "^2.4.2",
|
|
51
53
|
"@typescript-eslint/eslint-plugin": "^5.28.0",
|
|
52
54
|
"@typescript-eslint/parser": "^5.28.0",
|
|
53
55
|
"chai": "^4.3.7",
|
|
@@ -62,7 +64,9 @@
|
|
|
62
64
|
"ts-loader": "^9.3.0",
|
|
63
65
|
"typescript": "^4.6.4",
|
|
64
66
|
"webpack": "^5.72.0",
|
|
65
|
-
"webpack-cli": "^4.9.2"
|
|
67
|
+
"webpack-cli": "^4.9.2",
|
|
68
|
+
"yauzl": "^2.10.0",
|
|
69
|
+
"yazl": "^2.5.1"
|
|
66
70
|
},
|
|
67
71
|
"repository": {
|
|
68
72
|
"type": "git",
|
|
File without changes
|