@tsvm/ir 0.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +238 -0
  2. package/dist/index.js +3593 -0
  3. package/package.json +33 -0
@@ -0,0 +1,238 @@
1
+ import { IRFunction, IRGlobal, IRImport, IRExport, ConstantKind, IRModule, OpCode, Operand, Register, TerminatorInstruction, BasicBlock, IRType, FunctionAttribute, Instruction, Diagnostic, ModuleInfo, ProjectSemanticGraph, FunctionCapabilityReport } from '@tsvm/shared';
2
+ import ts from 'typescript';
3
+
4
+ declare class IRModuleBuilder {
5
+ readonly sourceFile: string;
6
+ private functions;
7
+ private globals;
8
+ private imports;
9
+ private exports;
10
+ private constantPool;
11
+ private constantMap;
12
+ private nextFunctionId;
13
+ constructor(sourceFile: string);
14
+ addFunction(fn: IRFunction): void;
15
+ addGlobal(g: IRGlobal): void;
16
+ addImport(imp: IRImport): void;
17
+ addExport(exp: IRExport): void;
18
+ addConstant(kind: ConstantKind, value: string | number | boolean | null): number;
19
+ build(): IRModule;
20
+ getNextFunctionId(): string;
21
+ }
22
+ declare class IRFunctionBuilder {
23
+ readonly id: string;
24
+ readonly name: string;
25
+ readonly returnType: IRType;
26
+ private blocks;
27
+ private params;
28
+ private locals;
29
+ private attributes;
30
+ private capturedVariables;
31
+ private nextRegId;
32
+ private nextBlockId;
33
+ constructor(id: string, name: string, returnType: IRType);
34
+ addParam(name: string, type: IRType, isRest?: boolean, defaultValue?: number): Register;
35
+ addLocal(name: string, type: IRType, isCaptured?: boolean): Register;
36
+ addAttribute(attr: FunctionAttribute): void;
37
+ addCapturedVariable(name: string): void;
38
+ allocRegister(): Register;
39
+ createBlock(label: string): BasicBlockBuilder;
40
+ addBlock(block: BasicBlock): void;
41
+ getBlockCount(): number;
42
+ build(isVirtualized?: boolean, isExported?: boolean): IRFunction;
43
+ }
44
+ declare class BasicBlockBuilder {
45
+ readonly id: string;
46
+ readonly label: string;
47
+ private instructions;
48
+ private terminator?;
49
+ private predecessors;
50
+ private successors;
51
+ constructor(id: string, label: string);
52
+ addInstruction(opcode: OpCode, operands: Operand[], result?: Register): void;
53
+ setTerminator(term: TerminatorInstruction): void;
54
+ addPredecessor(id: string): void;
55
+ getInstructionCount(): number;
56
+ getPredecessorCount(): number;
57
+ getTerminatorKind(): TerminatorInstruction['kind'] | undefined;
58
+ build(): BasicBlock;
59
+ }
60
+ declare function createInstruction(opcode: OpCode, operands: Operand[], result?: Register): Instruction;
61
+ declare function createTerminator(kind: TerminatorInstruction['kind'], targets: string[], condition?: Register, returnValue?: Register): TerminatorInstruction;
62
+
63
+ type SupportedFunctionNode = ts.FunctionDeclaration | ts.FunctionExpression | ts.ArrowFunction | ts.MethodDeclaration | ts.GetAccessorDeclaration | ts.SetAccessorDeclaration | ts.ConstructorDeclaration;
64
+ interface LowerToIROptions {
65
+ readonly forceVirtualizeAll?: boolean;
66
+ readonly forceVirtualizeFunctionNames?: ReadonlySet<string>;
67
+ readonly skipTopLevelFunctionNames?: ReadonlySet<string>;
68
+ readonly compatibilityFallback?: boolean;
69
+ readonly diagnostics?: Diagnostic[];
70
+ }
71
+ interface ClosureAnalysis {
72
+ readonly localNames: ReadonlySet<string>;
73
+ readonly capturedFromOuter: readonly string[];
74
+ readonly capturedByDescendants: ReadonlySet<string>;
75
+ }
76
+ interface NormalizedClassFieldElement {
77
+ readonly kind: 'field';
78
+ readonly node: ts.PropertyDeclaration;
79
+ readonly isStatic: boolean;
80
+ readonly keyName?: string;
81
+ readonly computedBindingName?: string;
82
+ readonly privateBindingName?: string;
83
+ }
84
+
85
+ interface LoweringOptions {
86
+ readonly name: string;
87
+ readonly isExported: boolean;
88
+ readonly isVirtualized: boolean;
89
+ readonly analysis: ClosureAnalysis;
90
+ readonly attributes?: readonly FunctionAttribute[];
91
+ readonly isNested?: boolean;
92
+ readonly prologueEmitter?: ((lowering: ASTLowering) => void) | undefined;
93
+ readonly privateIdentifierBindings?: ReadonlyMap<string, string>;
94
+ readonly instanceFieldsToInitialize?: readonly NormalizedClassFieldElement[];
95
+ }
96
+ interface IASTLowering {
97
+ node: ts.Node;
98
+ fnBuilder: any;
99
+ currentBlock: any;
100
+ modBuilder: any;
101
+ scope: Map<string, any>;
102
+ outerCaptureBindings: Set<string>;
103
+ isAsyncFunction: boolean;
104
+ isGenerator: boolean;
105
+ instanceFieldsToInitialize: readonly any[] | undefined;
106
+ createTempLocal(name: string): any;
107
+ emitConstant(kind: any, value: unknown): any;
108
+ loadFromLocal(reg: any): any;
109
+ storeToLocal(reg1: any, reg2: any): void;
110
+ normalizeExpression(expr: ts.Expression): ts.Expression;
111
+ lowerNestedFunctionLike(expr: ts.FunctionLikeDeclaration, name?: string, options?: any): any;
112
+ resolveLexicalCapture(name: string, node: ts.Node, detail: string): any;
113
+ failUnsupported(node: ts.Node, msg?: string): never;
114
+ resolveVar(name: string): any;
115
+ storeValue(target: ts.Expression, valueReg: any): void;
116
+ readValue(target: ts.Expression): any;
117
+ resolvePrivateIdentifierRegister(identifier: ts.PrivateIdentifier): any;
118
+ emitObjectPropertyAssignment(objReg: any, keyReg: any, valueReg: any, computed?: boolean): void;
119
+ getPropertyNameText(name: ts.PropertyName): string;
120
+ materializeArgumentArray(args: readonly ts.Expression[]): any;
121
+ emitSpreadInto(targetReg: any, sourceReg: any): void;
122
+ emitSpreadIntoArray(targetReg: any, sourceReg: any, startIndexReg: any, destIndexLocal: any): void;
123
+ lowerClassLike(node: ts.ClassDeclaration | ts.ClassExpression, name?: string): any;
124
+ emitInstanceFieldInitializers(fields: readonly any[]): void;
125
+ }
126
+ declare class ASTLowering {
127
+ readonly modBuilder: IRModuleBuilder;
128
+ private readonly node;
129
+ private fnBuilder;
130
+ private currentBlock;
131
+ private scope;
132
+ readonly functionId: string;
133
+ private nestedFunctionCount;
134
+ private tempLocalCount;
135
+ private readonly sourceFile;
136
+ private readonly capturedLocals;
137
+ private readonly outerCaptureBindings;
138
+ private readonly breakTargets;
139
+ private readonly continueTargets;
140
+ private readonly finallyContexts;
141
+ private throwPassthroughFinallyDepth;
142
+ private readonly pendingParameterBindings;
143
+ private readonly isAsyncFunction;
144
+ private readonly isGenerator;
145
+ private readonly privateIdentifierBindings;
146
+ private readonly instanceFieldsToInitialize?;
147
+ constructor(modBuilder: IRModuleBuilder, node: SupportedFunctionNode, options: LoweringOptions);
148
+ private failUnsupported;
149
+ private isSyntheticDeadBlock;
150
+ private shouldEmitFallthroughReturn;
151
+ private enterBreakTarget;
152
+ private leaveBreakTarget;
153
+ private enterContinueTarget;
154
+ private leaveContinueTarget;
155
+ private emitJumpAndAdvance;
156
+ private emitConstant;
157
+ private storeToLocal;
158
+ private boxCapturedParameters;
159
+ private lowerPendingParameterBindings;
160
+ private loadOuterCaptureCell;
161
+ private resolveVar;
162
+ private findIdentifierNode;
163
+ private createNestedFunctionName;
164
+ private getAvailableOuterCaptureNames;
165
+ private canProvideLexicalThis;
166
+ private canProvideLexicalNewTarget;
167
+ private initializeLexicalSemanticCaptures;
168
+ private initializeLexicalCapture;
169
+ private resolveLexicalCapture;
170
+ private collectReferencedOuterNames;
171
+ private getFunctionAttributes;
172
+ private normalizeClassLike;
173
+ private lowerClassConstructor;
174
+ private lowerNestedFunctionLike;
175
+ private emitClassMethodOrAccessorDescriptor;
176
+ private lowerClassLike;
177
+ private emitClassConstructorGuard;
178
+ private emitInstanceFieldInitializers;
179
+ private resolvePrivateIdentifierRegister;
180
+ private lowerNestedFunction;
181
+ private buildClosureEnvironment;
182
+ private getCellForCapture;
183
+ private storeValue;
184
+ private readValue;
185
+ private emitObjectPropertyAssignment;
186
+ private normalizeExpression;
187
+ private createTempLocal;
188
+ private createSyntheticBindingName;
189
+ private declareScopedIdentifier;
190
+ private declareForcedBoxedIdentifier;
191
+ private withTemporaryBinding;
192
+ private getPropertyKeyRegister;
193
+ private buildAccessorDescriptorSource;
194
+ private emitObjectPropertyWrite;
195
+ private emitDefineProperty;
196
+ private initializeDeclaredIdentifier;
197
+ private applyDefaultValue;
198
+ private materializeBindingElementValue;
199
+ private emitRestArgs;
200
+ private emitArraySlice;
201
+ private emitSpreadInto;
202
+ private emitSpreadIntoArray;
203
+ private bindPattern;
204
+ private initializeVariableDeclaration;
205
+ private assignLoopBinding;
206
+ private loadFromLocal;
207
+ private getActiveFinallyContext;
208
+ private withFinallyContext;
209
+ private withPassthroughThrow;
210
+ private createFinallyContext;
211
+ private getCompletionTargetCode;
212
+ private setFinallyCompletion;
213
+ private routeAbruptCompletionThroughFinally;
214
+ private emitCompletionTargetDispatch;
215
+ private emitCompletionDispatch;
216
+ private bindCatchVariable;
217
+ private lowerTryCatchStatement;
218
+ private lowerTryFinallyStatement;
219
+ private lowerConditionalExpression;
220
+ private lowerNullishCoalesce;
221
+ private lowerTemplateExpression;
222
+ private lowerNestedFunctionNode;
223
+ private visitExpression;
224
+ private getPropertyNameText;
225
+ private materializeArgumentArray;
226
+ private parseAssignmentTargetWithDefault;
227
+ private storeArrayPattern;
228
+ private storeObjectPattern;
229
+ private visitStatement;
230
+ }
231
+ declare function lowerToIR(moduleInfo: ModuleInfo, graph: ProjectSemanticGraph, filePath: string, options?: LowerToIROptions): IRModule;
232
+
233
+ declare function analyzeFunctionCapabilities(filePath: string, sourceText?: string): FunctionCapabilityReport[];
234
+ declare function analyzeTopLevelFunctionCapabilities(filePath: string, sourceText?: string): FunctionCapabilityReport[];
235
+
236
+ declare function printIRModule(module: IRModule): string;
237
+
238
+ export { ASTLowering, BasicBlockBuilder, type IASTLowering, IRFunctionBuilder, IRModuleBuilder, type LowerToIROptions, analyzeFunctionCapabilities, analyzeTopLevelFunctionCapabilities, createInstruction, createTerminator, lowerToIR, printIRModule };