@@ -6,16 +6,18 @@ import { FunctionSignature } from "./types.js";
6
6
7
7
export class Extractor {
8
8
binaryen : typeof binaryen ;
9
+ module : binaryen . Module ;
9
10
program : Program ;
10
11
11
- constructor ( transform : Transform ) {
12
- this . binaryen = transform . binaryen ;
12
+ constructor ( transform : Transform , module : binaryen . Module ) {
13
13
this . program = transform . program ;
14
+ this . binaryen = transform . binaryen ;
15
+ this . module = module ;
14
16
}
15
17
16
- getExportedFunctions ( module : binaryen . Module ) : FunctionSignature [ ] {
18
+ getExportedFunctions ( ) : FunctionSignature [ ] {
17
19
const functions = this . getAllFunctions ( ) ;
18
- const paths = this . getExportedFunctionPaths ( module ) ;
20
+ const paths = this . getExportedFunctionPaths ( ) ;
19
21
20
22
const results = paths
21
23
. map ( ( path ) => functions . get ( path ) )
@@ -31,12 +33,18 @@ export class Extractor {
31
33
return visitor . functions ;
32
34
}
33
35
34
- private getExportedFunctionPaths ( module : binaryen . Module ) : string [ ] {
36
+ private getExportedFunctionPaths ( ) : string [ ] {
35
37
const paths = [ ] ;
36
- const n = module . getNumExports ( ) ;
37
38
38
- for ( let i = 0 ; i < n ; ++ i ) {
39
- const ref = module . getExportByIndex ( i ) ;
39
+ const funcs = new Map < string , binaryen . FunctionInfo > ( ) ;
40
+ for ( let i = 0 ; i < this . module . getNumFunctions ( ) ; ++ i ) {
41
+ const ref = this . module . getFunctionByIndex ( i ) ;
42
+ const info = this . binaryen . getFunctionInfo ( ref ) ;
43
+ funcs . set ( info . name , info ) ;
44
+ }
45
+
46
+ for ( let i = 0 ; i < this . module . getNumExports ( ) ; ++ i ) {
47
+ const ref = this . module . getExportByIndex ( i ) ;
40
48
const info = this . binaryen . getExportInfo ( ref ) ;
41
49
42
50
if ( info . kind !== binaryen . ExternalFunction ) {
@@ -47,6 +55,11 @@ export class Extractor {
47
55
continue ;
48
56
}
49
57
58
+ const f = funcs . get ( info . value ) ;
59
+ if ( f === undefined ) {
60
+ continue ;
61
+ }
62
+
50
63
paths . push ( info . value . replace ( / ^ e x p o r t : / , "" ) ) ;
51
64
}
52
65
0 commit comments