| 110 | } |
| 111 | |
| 112 | override async objdump(outputFilename: string, result: any, maxSize: number) { |
| 113 | const dirPath = path.dirname(outputFilename); |
| 114 | const files = await this.readdir(dirPath); |
| 115 | logger.verbose('Class files: ', files); |
| 116 | const results = await Promise.all( |
| 117 | files |
| 118 | .filter(f => f.endsWith('.class')) |
| 119 | .map(async classFile => { |
| 120 | const args = [ |
| 121 | ...this.compiler.objdumperArgs, |
| 122 | // Prints out disassembled code, i.e., the instructions that comprise the Java bytecodes, |
| 123 | // for each of the methods in the class. |
| 124 | '-c', |
| 125 | // Prints out line and local variable tables. |
| 126 | '-l', |
| 127 | // Private things |
| 128 | '-p', |
| 129 | // Final constants |
| 130 | '-constants', |
| 131 | // Verbose - ideally we'd enable this and then we get constant pools too. Needs work to parse. |
| 132 | //'-v', |
| 133 | classFile, |
| 134 | ]; |
| 135 | const objResult = await this.exec(this.compiler.objdumper, args, { |
| 136 | maxOutput: maxSize, |
| 137 | customCwd: dirPath, |
| 138 | }); |
| 139 | const oneResult: ParsedAsmResult = { |
| 140 | asm: [ |
| 141 | { |
| 142 | text: objResult.stdout, |
| 143 | }, |
| 144 | ], |
| 145 | }; |
| 146 | |
| 147 | if (objResult.code === 0) { |
| 148 | oneResult.objdumpTime = objResult.execTime; |
| 149 | } else { |
| 150 | oneResult.asm = [ |
| 151 | { |
| 152 | text: `<No output: javap returned ${objResult.code}>`, |
| 153 | }, |
| 154 | ]; |
| 155 | } |
| 156 | return oneResult; |
| 157 | }), |
| 158 | ); |
| 159 | |
| 160 | const merged: ParsedAsmResult = {asm: []}; |
| 161 | for (const result of results) { |
| 162 | const asmBackup = merged.asm; |
| 163 | Object.assign(merged, result); |
| 164 | merged.asm = [...asmBackup, ...result.asm]; |
| 165 | } |
| 166 | |
| 167 | result.asm = merged.asm; |
| 168 | return result; |
| 169 | } |