14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ciconst { XTools } = require('../engine/XTools'); 174514f5e3Sopenharmony_ciconst { X2DFast } = require('../engine/graphics/X2DFast'); 184514f5e3Sopenharmony_ciconst { NapiLog } = require('./NapiLog'); 194514f5e3Sopenharmony_ci 204514f5e3Sopenharmony_ciclass LogParser { 214514f5e3Sopenharmony_ci constructor(result) { 224514f5e3Sopenharmony_ci const regexVT100 = /\x1B\[[0-9;]*[A-Za-z]/g; // 匹配VT100字符的正则表达式 234514f5e3Sopenharmony_ci result = result.replace(regexVT100, ''); 244514f5e3Sopenharmony_ci result = result.replace(/\t/g, ' '); 254514f5e3Sopenharmony_ci result = result.replace(/\r/g, ''); 264514f5e3Sopenharmony_ci this.logLines_ = result.split('\n'); 274514f5e3Sopenharmony_ci this.stat_ = 0; 284514f5e3Sopenharmony_ci this.lineNum_ = 0; 294514f5e3Sopenharmony_ci this.initBlock_ = { 304514f5e3Sopenharmony_ci filePoint: null, 314514f5e3Sopenharmony_ci funcPoint: null, 324514f5e3Sopenharmony_ci blockType: -1, 334514f5e3Sopenharmony_ci }; 344514f5e3Sopenharmony_ci this.procBlock_ = { 354514f5e3Sopenharmony_ci blockStat: -1, 364514f5e3Sopenharmony_ci blockCollect: -1, 374514f5e3Sopenharmony_ci oneBlock: -1, 384514f5e3Sopenharmony_ci }; 394514f5e3Sopenharmony_ci this.procNormal_ = null; 404514f5e3Sopenharmony_ci this.output_ = {}; 414514f5e3Sopenharmony_ci } 424514f5e3Sopenharmony_ci 434514f5e3Sopenharmony_ci parsing() { 444514f5e3Sopenharmony_ci if (this.lineNum_ >= this.logLines_.length) { 454514f5e3Sopenharmony_ci return false; 464514f5e3Sopenharmony_ci } 474514f5e3Sopenharmony_ci 484514f5e3Sopenharmony_ci for (let i = 0; i < 300 && this.lineNum_ < this.logLines_.length; i++) { 494514f5e3Sopenharmony_ci this.parseLine(this.logLines_[this.lineNum_]); 504514f5e3Sopenharmony_ci this.lineNum_++; 514514f5e3Sopenharmony_ci } 524514f5e3Sopenharmony_ci 534514f5e3Sopenharmony_ci XTools.PROC_TO = this.lineNum_ * 20 / this.logLines_.length; 544514f5e3Sopenharmony_ci return true; 554514f5e3Sopenharmony_ci } 564514f5e3Sopenharmony_ci isBlock(l) { 574514f5e3Sopenharmony_ci for (let bt of XTools.CONFIG.BlockTypes) { 584514f5e3Sopenharmony_ci if (l.indexOf(bt) >= 0) { 594514f5e3Sopenharmony_ci this.stat_ = this.initBlock_.blockType; 604514f5e3Sopenharmony_ci this.procBlock_.blockStat = 0; 614514f5e3Sopenharmony_ci this.procBlock_.blockCollect = { 624514f5e3Sopenharmony_ci type: 'block:' + bt, 634514f5e3Sopenharmony_ci func: this.initBlock_.funcPoint, 644514f5e3Sopenharmony_ci file: this.initBlock_.filePoint, 654514f5e3Sopenharmony_ci irList: [], 664514f5e3Sopenharmony_ci startLine: l, 674514f5e3Sopenharmony_ci }; 684514f5e3Sopenharmony_ci this.procBlock_.oneBlock = null; 694514f5e3Sopenharmony_ci return true; 704514f5e3Sopenharmony_ci } 714514f5e3Sopenharmony_ci } 724514f5e3Sopenharmony_ci return false; 734514f5e3Sopenharmony_ci } 744514f5e3Sopenharmony_ci splitLast(s) { 754514f5e3Sopenharmony_ci let i = s.lastIndexOf('@'); 764514f5e3Sopenharmony_ci 774514f5e3Sopenharmony_ci return [s.substring(0, i), s.substring(i + 1)]; 784514f5e3Sopenharmony_ci } 794514f5e3Sopenharmony_ci isStart(l) { 804514f5e3Sopenharmony_ci //========= After bytecode2circuit lowering [func_main_0@484@arkcompiler/ets_runtime/sd_test/ttabs.abc] ======== 814514f5e3Sopenharmony_ci const regexStart = /=+ *After ([a-zA-Z0-9_ ]+) \[([#a-zA-Z0-9_@/.-]+)\] *=+/g; 824514f5e3Sopenharmony_ci //========= After inlining [OthreMath@test@arkcompiler/ets_runtime/sd_test/test.abc] Caller 834514f5e3Sopenharmony_ci //method [func_main_0@641@arkcompiler/ets_runtime/sd_test/test.abc]====================[0m 844514f5e3Sopenharmony_ci const regexStart2 = /=+ *After ([a-zA-Z0-9_ ]+) \[([a-zA-Z0-9_@/.-]+)\] *Caller method \[([#a-zA-Z0-9_@/.]+)\] *=+/g; 854514f5e3Sopenharmony_ci 864514f5e3Sopenharmony_ci if (l[11] !== '=') { 874514f5e3Sopenharmony_ci return; 884514f5e3Sopenharmony_ci } 894514f5e3Sopenharmony_ci let ret = regexStart.exec(l); 904514f5e3Sopenharmony_ci if (ret) { 914514f5e3Sopenharmony_ci let tt = this.splitLast(ret[2]); 924514f5e3Sopenharmony_ci this.procNormal_ = { 934514f5e3Sopenharmony_ci type: ret[1], //优化类型 944514f5e3Sopenharmony_ci func: tt[0], //函数名 954514f5e3Sopenharmony_ci file: tt[1], //文件名 964514f5e3Sopenharmony_ci irList: [], 974514f5e3Sopenharmony_ci startLine: l, 984514f5e3Sopenharmony_ci }; 994514f5e3Sopenharmony_ci this.stat_ = 1; 1004514f5e3Sopenharmony_ci [this.initBlock_.funcPoint, this.initBlock_.filePoint] = [tt[0], tt[tt.length - 1]]; 1014514f5e3Sopenharmony_ci this.initBlock_.blockType = 10; 1024514f5e3Sopenharmony_ci } 1034514f5e3Sopenharmony_ci else { 1044514f5e3Sopenharmony_ci ret = regexStart2.exec(l); 1054514f5e3Sopenharmony_ci if (ret) { 1064514f5e3Sopenharmony_ci let tt = this.splitLast(ret[2]); 1074514f5e3Sopenharmony_ci let tt2 = this.splitLast(ret[3]); 1084514f5e3Sopenharmony_ci NapiLog.logInfo(tt[0], 'Caller method(' + this.lineNum_ + '行)', ret[3]); 1094514f5e3Sopenharmony_ci this.procNormal_ = { 1104514f5e3Sopenharmony_ci type: ret[1] + ' ' + tt[0], //优化类型 1114514f5e3Sopenharmony_ci func: tt2[0], //函数名 1124514f5e3Sopenharmony_ci file: tt2[1], //文件名 1134514f5e3Sopenharmony_ci irList: [], 1144514f5e3Sopenharmony_ci startLine: l, 1154514f5e3Sopenharmony_ci }; 1164514f5e3Sopenharmony_ci this.stat_ = 1; 1174514f5e3Sopenharmony_ci [this.initBlock_.funcPoint, this.initBlock_.filePoint] = [tt2[0], tt2[tt2.length - 1]]; 1184514f5e3Sopenharmony_ci this.initBlock_.blockType = 10; 1194514f5e3Sopenharmony_ci } 1204514f5e3Sopenharmony_ci else { 1214514f5e3Sopenharmony_ci if (l.search('After') > 0) { 1224514f5e3Sopenharmony_ci alert(l); 1234514f5e3Sopenharmony_ci } 1244514f5e3Sopenharmony_ci } 1254514f5e3Sopenharmony_ci } 1264514f5e3Sopenharmony_ci } 1274514f5e3Sopenharmony_ci collectNormal(l) { 1284514f5e3Sopenharmony_ci let idx = l.search('{"id":'); 1294514f5e3Sopenharmony_ci if (idx >= 0) { 1304514f5e3Sopenharmony_ci let idx2 = l.lastIndexOf('}'); 1314514f5e3Sopenharmony_ci let str = l.substring(idx, idx2 + 1); 1324514f5e3Sopenharmony_ci 1334514f5e3Sopenharmony_ci let ir = JSON.parse(str); 1344514f5e3Sopenharmony_ci { //根据XTools.CONFIG.MTypeField切割MType 1354514f5e3Sopenharmony_ci let cutPos = []; 1364514f5e3Sopenharmony_ci for (let field of XTools.CONFIG.MTypeField) { 1374514f5e3Sopenharmony_ci let idx = ir.MType.indexOf(', ' + field); 1384514f5e3Sopenharmony_ci if (idx >= 0) { 1394514f5e3Sopenharmony_ci cutPos.push(idx); 1404514f5e3Sopenharmony_ci } 1414514f5e3Sopenharmony_ci } 1424514f5e3Sopenharmony_ci cutPos.push(ir.MType.length); 1434514f5e3Sopenharmony_ci cutPos.sort((a, b) => { return parseInt(a) - parseInt(b) }); 1444514f5e3Sopenharmony_ci if (cutPos[0] === 0) { 1454514f5e3Sopenharmony_ci cutPos.shift(); 1464514f5e3Sopenharmony_ci } 1474514f5e3Sopenharmony_ci let p = 0; 1484514f5e3Sopenharmony_ci let cutResult = []; 1494514f5e3Sopenharmony_ci for (let i of cutPos) { 1504514f5e3Sopenharmony_ci let tmp = ir.MType.substring(p, i); 1514514f5e3Sopenharmony_ci if (tmp.startsWith(', ')) { 1524514f5e3Sopenharmony_ci tmp = tmp.substring(2); 1534514f5e3Sopenharmony_ci } 1544514f5e3Sopenharmony_ci if (tmp.endsWith(', ')) { 1554514f5e3Sopenharmony_ci tmp = tmp.substring(0, tmp.length - 2); 1564514f5e3Sopenharmony_ci } 1574514f5e3Sopenharmony_ci cutResult.push(tmp); 1584514f5e3Sopenharmony_ci p = i; 1594514f5e3Sopenharmony_ci } 1604514f5e3Sopenharmony_ci cutResult.push('inNum=[' + ir.in[0].length + ',' + ir.in[1].length + ',' + ir.in[2].length + ',' + ir.in[3].length + ',' + ir.in[4].length + ']'); 1614514f5e3Sopenharmony_ci cutResult.push('outNum=' + ir.out.length); 1624514f5e3Sopenharmony_ci if ('comment' in ir) { 1634514f5e3Sopenharmony_ci cutResult.push('//' + ir.comment); 1644514f5e3Sopenharmony_ci } 1654514f5e3Sopenharmony_ci ir.maxDetailWidth = 0; 1664514f5e3Sopenharmony_ci for (let detail of cutResult) { 1674514f5e3Sopenharmony_ci let w = X2DFast.gi().getTextWidth(detail, 14); 1684514f5e3Sopenharmony_ci if (ir.maxDetailWidth < w) { 1694514f5e3Sopenharmony_ci ir.maxDetailWidth = w; 1704514f5e3Sopenharmony_ci } 1714514f5e3Sopenharmony_ci } 1724514f5e3Sopenharmony_ci ir.detailList = cutResult; 1734514f5e3Sopenharmony_ci } 1744514f5e3Sopenharmony_ci this.procNormal_.irList.push(ir); 1754514f5e3Sopenharmony_ci } 1764514f5e3Sopenharmony_ci else { 1774514f5e3Sopenharmony_ci //= End typeHitRate: 0.500000 = 1784514f5e3Sopenharmony_ci let regexEnd = /=+ End[a-zA-Z:.0-9 ]* =+/g; 1794514f5e3Sopenharmony_ci let tt = regexEnd.exec(l); 1804514f5e3Sopenharmony_ci if (tt) { //收集结束,入大表l.search('== End ==') > 0 1814514f5e3Sopenharmony_ci if (this.procNormal_.irList.length > 0) { 1824514f5e3Sopenharmony_ci if (!(this.procNormal_.file in this.output_)) { 1834514f5e3Sopenharmony_ci this.output_[this.procNormal_.file] = {}; 1844514f5e3Sopenharmony_ci } 1854514f5e3Sopenharmony_ci if (!(this.procNormal_.func in this.output_[this.procNormal_.file])) { 1864514f5e3Sopenharmony_ci this.output_[this.procNormal_.file][this.procNormal_.func] = []; 1874514f5e3Sopenharmony_ci } 1884514f5e3Sopenharmony_ci this.output_[this.procNormal_.file][this.procNormal_.func].push(this.procNormal_); 1894514f5e3Sopenharmony_ci } 1904514f5e3Sopenharmony_ci else { 1914514f5e3Sopenharmony_ci NapiLog.logError('After和End之间没有指令(' + this.lineNum_ + '行)'); 1924514f5e3Sopenharmony_ci } 1934514f5e3Sopenharmony_ci this.stat_ = 0; 1944514f5e3Sopenharmony_ci } 1954514f5e3Sopenharmony_ci else { 1964514f5e3Sopenharmony_ci NapiLog.logError('After和End之间解析失败(' + (this.lineNum_ + 1) + ')行'); 1974514f5e3Sopenharmony_ci this.stat_ = 0; 1984514f5e3Sopenharmony_ci } 1994514f5e3Sopenharmony_ci } 2004514f5e3Sopenharmony_ci } 2014514f5e3Sopenharmony_ci parseLine(l) { 2024514f5e3Sopenharmony_ci switch (this.stat_) { 2034514f5e3Sopenharmony_ci case 0: //搜索起始 2044514f5e3Sopenharmony_ci if (this.SearchBegin(l) || this.isBlock(l)) { 2054514f5e3Sopenharmony_ci return; 2064514f5e3Sopenharmony_ci } 2074514f5e3Sopenharmony_ci this.isStart(l); 2084514f5e3Sopenharmony_ci break; 2094514f5e3Sopenharmony_ci case 1: //收集ir表 2104514f5e3Sopenharmony_ci this.collectNormal(l); 2114514f5e3Sopenharmony_ci break; 2124514f5e3Sopenharmony_ci case 10: //收集block一 2134514f5e3Sopenharmony_ci if (this.CollectBlock(l)) { 2144514f5e3Sopenharmony_ci this.stat_ = 0; 2154514f5e3Sopenharmony_ci this.lineNum_ -= 1; 2164514f5e3Sopenharmony_ci } 2174514f5e3Sopenharmony_ci break; 2184514f5e3Sopenharmony_ci case 20: //收集block二 2194514f5e3Sopenharmony_ci if (this.CollectBlock2(l)) { 2204514f5e3Sopenharmony_ci this.stat_ = 0; 2214514f5e3Sopenharmony_ci this.lineNum_ -= 1; 2224514f5e3Sopenharmony_ci } 2234514f5e3Sopenharmony_ci break; 2244514f5e3Sopenharmony_ci } 2254514f5e3Sopenharmony_ci } 2264514f5e3Sopenharmony_ci 2274514f5e3Sopenharmony_ci static Load(fn, cb) { 2284514f5e3Sopenharmony_ci const xhr = new XMLHttpRequest(); 2294514f5e3Sopenharmony_ci xhr.open('GET', fn); 2304514f5e3Sopenharmony_ci xhr.setRequestHeader('Cache-Control', 'no-cache'); 2314514f5e3Sopenharmony_ci xhr.onreadystatechange = () => { 2324514f5e3Sopenharmony_ci if (xhr.readyState === XMLHttpRequest.DONE) { 2334514f5e3Sopenharmony_ci if (xhr.status === 200) { 2344514f5e3Sopenharmony_ci XTools.PORC_TO = 10; 2354514f5e3Sopenharmony_ci cb(fn, xhr.responseText); 2364514f5e3Sopenharmony_ci } 2374514f5e3Sopenharmony_ci } 2384514f5e3Sopenharmony_ci }; 2394514f5e3Sopenharmony_ci xhr.send(); 2404514f5e3Sopenharmony_ci } 2414514f5e3Sopenharmony_ci NumberStringToArray(ss) { 2424514f5e3Sopenharmony_ci let outs = ss.split(','); 2434514f5e3Sopenharmony_ci let ret = []; 2444514f5e3Sopenharmony_ci for (let s of outs) { 2454514f5e3Sopenharmony_ci let ttt = parseInt(s); 2464514f5e3Sopenharmony_ci if (!isNaN(ttt)) { 2474514f5e3Sopenharmony_ci ret.push(ttt); 2484514f5e3Sopenharmony_ci } 2494514f5e3Sopenharmony_ci } 2504514f5e3Sopenharmony_ci return ret; 2514514f5e3Sopenharmony_ci } 2524514f5e3Sopenharmony_ci SearchBegin(l) { 2534514f5e3Sopenharmony_ci let ret; 2544514f5e3Sopenharmony_ci let ib = this.initBlock_; 2554514f5e3Sopenharmony_ci 2564514f5e3Sopenharmony_ci if (l.startsWith('[compiler] aot method')) { 2574514f5e3Sopenharmony_ci //[compiler] aot method [func_main_0@b.abc] log: 2584514f5e3Sopenharmony_ci const regexFuncName = /^\[compiler\] aot method \[([#a-zA-Z0-9_@/.]+)\] (recordName \[[a-zA-Z0-9_]*\] )*log:/g; 2594514f5e3Sopenharmony_ci ret = regexFuncName.exec(l); 2604514f5e3Sopenharmony_ci if (ret) { 2614514f5e3Sopenharmony_ci [ib.funcPoint, ib.filePoint] = this.splitLast(ret[1]); 2624514f5e3Sopenharmony_ci ib.blockType = 10; 2634514f5e3Sopenharmony_ci return true; 2644514f5e3Sopenharmony_ci } 2654514f5e3Sopenharmony_ci } 2664514f5e3Sopenharmony_ci if (l.startsWith('[compiler] ==================== Before state split')) { 2674514f5e3Sopenharmony_ci const regexFuncName2 = /^\[compiler\] =+ Before state split linearizer \[([#a-zA-Z0-9_@/.]+)\] *=*/g; 2684514f5e3Sopenharmony_ci ret = regexFuncName2.exec(l); 2694514f5e3Sopenharmony_ci if (ret) { 2704514f5e3Sopenharmony_ci [ib.funcPoint, ib.filePoint] = this.splitLast(ret[1]); 2714514f5e3Sopenharmony_ci ib.blockType = 20; 2724514f5e3Sopenharmony_ci return true; 2734514f5e3Sopenharmony_ci } 2744514f5e3Sopenharmony_ci } 2754514f5e3Sopenharmony_ci if (l.startsWith('[compiler] ==================== After graph lineari')) { 2764514f5e3Sopenharmony_ci const regexFuncName3 = /^\[compiler\] =+ After graph linearizer \[([#a-zA-Z0-9_@/.]+)\] *=*/g; 2774514f5e3Sopenharmony_ci ret = regexFuncName3.exec(l); 2784514f5e3Sopenharmony_ci if (ret) { 2794514f5e3Sopenharmony_ci [ib.funcPoint, ib.filePoint] = this.splitLast(ret[1]); 2804514f5e3Sopenharmony_ci ib.blockType = 20; 2814514f5e3Sopenharmony_ci return true; 2824514f5e3Sopenharmony_ci } 2834514f5e3Sopenharmony_ci } 2844514f5e3Sopenharmony_ci return false; 2854514f5e3Sopenharmony_ci } 2864514f5e3Sopenharmony_ci CollectBlock(l) { 2874514f5e3Sopenharmony_ci const regexBlock = [ 2884514f5e3Sopenharmony_ci /^\[compiler\] B([0-9]+): ;preds=([0-9, ]*)$/g, //[compiler] B0: ;preds= 2894514f5e3Sopenharmony_ci /^\[compiler\] *Succes:([0-9, ]*)$/g, //[compiler] Succes: 2904514f5e3Sopenharmony_ci /^\[compiler\] *Bytecode\[\] = *(Empty)*$/g, //[compiler] Bytecode[] = Empty 2914514f5e3Sopenharmony_ci /^\[compiler\] *Trys:([0-9, ]*)$/g, //[compiler] Trys: 2924514f5e3Sopenharmony_ci ]; 2934514f5e3Sopenharmony_ci let ret; 2944514f5e3Sopenharmony_ci let pb = this.procBlock_; 2954514f5e3Sopenharmony_ci if (pb.blockStat === 0) { 2964514f5e3Sopenharmony_ci ret = regexBlock[0].exec(l); 2974514f5e3Sopenharmony_ci if (ret) { 2984514f5e3Sopenharmony_ci pb.oneBlock = { 2994514f5e3Sopenharmony_ci id: ret[1], 3004514f5e3Sopenharmony_ci op: 'B' + ret[1], 3014514f5e3Sopenharmony_ci detailList: [], 3024514f5e3Sopenharmony_ci maxDetailWidth: 0, 3034514f5e3Sopenharmony_ci }; 3044514f5e3Sopenharmony_ci pb.oneBlock.in = [[], [], [], [], this.NumberStringToArray(ret[2])]; 3054514f5e3Sopenharmony_ci return false; 3064514f5e3Sopenharmony_ci } 3074514f5e3Sopenharmony_ci if (!pb.oneBlock) { //完成了一个block的解析 3084514f5e3Sopenharmony_ci if (!(pb.blockCollect.file in this.output_)) { 3094514f5e3Sopenharmony_ci this.output_[pb.blockCollect.file] = {}; 3104514f5e3Sopenharmony_ci } 3114514f5e3Sopenharmony_ci if (!(pb.blockCollect.func in this.output_[pb.blockCollect.file])) { 3124514f5e3Sopenharmony_ci this.output_[pb.blockCollect.file][pb.blockCollect.func] = []; 3134514f5e3Sopenharmony_ci } 3144514f5e3Sopenharmony_ci this.output_[pb.blockCollect.file][pb.blockCollect.func].push(pb.blockCollect); 3154514f5e3Sopenharmony_ci return true; 3164514f5e3Sopenharmony_ci } 3174514f5e3Sopenharmony_ci ret = regexBlock[1].exec(l); 3184514f5e3Sopenharmony_ci if (ret) { 3194514f5e3Sopenharmony_ci pb.oneBlock.out = this.NumberStringToArray(ret[1]); 3204514f5e3Sopenharmony_ci return false; 3214514f5e3Sopenharmony_ci } 3224514f5e3Sopenharmony_ci ret = regexBlock[2].exec(l); 3234514f5e3Sopenharmony_ci if (ret) { 3244514f5e3Sopenharmony_ci pb.blockStat = 1; 3254514f5e3Sopenharmony_ci return false; 3264514f5e3Sopenharmony_ci } 3274514f5e3Sopenharmony_ci } 3284514f5e3Sopenharmony_ci else if (pb.blockStat === 1) { //开始记录bytecode,直到空行,结束这个block 3294514f5e3Sopenharmony_ci if (/^\[compiler\] *$/g.test(l)) { //遇到空行,完成block 3304514f5e3Sopenharmony_ci if (pb.oneBlock.maxDetailWidth === 0) { 3314514f5e3Sopenharmony_ci pb.oneBlock.maxDetailWidth = X2DFast.gi().getTextWidth('Empty', 14); 3324514f5e3Sopenharmony_ci pb.oneBlock.detailList.push('Empty'); 3334514f5e3Sopenharmony_ci } 3344514f5e3Sopenharmony_ci pb.blockCollect.irList.push(pb.oneBlock); 3354514f5e3Sopenharmony_ci pb.oneBlock = null; 3364514f5e3Sopenharmony_ci pb.blockStat = 0; 3374514f5e3Sopenharmony_ci } 3384514f5e3Sopenharmony_ci else { 3394514f5e3Sopenharmony_ci let s = l.substring(11); 3404514f5e3Sopenharmony_ci while (s.startsWith(' ')) { 3414514f5e3Sopenharmony_ci s = s.substring(1); 3424514f5e3Sopenharmony_ci } 3434514f5e3Sopenharmony_ci let w = X2DFast.gi().getTextWidth(s, 14); 3444514f5e3Sopenharmony_ci if (pb.oneBlock.maxDetailWidth < w) { 3454514f5e3Sopenharmony_ci pb.oneBlock.maxDetailWidth = w; 3464514f5e3Sopenharmony_ci } 3474514f5e3Sopenharmony_ci pb.oneBlock.detailList.push(s); 3484514f5e3Sopenharmony_ci } 3494514f5e3Sopenharmony_ci } 3504514f5e3Sopenharmony_ci return false; 3514514f5e3Sopenharmony_ci } 3524514f5e3Sopenharmony_ci CollectBlock2(l) { 3534514f5e3Sopenharmony_ci const regexBlock = [ 3544514f5e3Sopenharmony_ci /^\[compiler\] B([0-9]+):/g, //[compiler] B0: ;preds= 3554514f5e3Sopenharmony_ci /^\[compiler\] *Preds:([0-9, ]*)$/g, 3564514f5e3Sopenharmony_ci /^\[compiler\] *Succes:([0-9, ]*)$/g, //[compiler] Succes: 3574514f5e3Sopenharmony_ci /^\[compiler\] *Bytecode\[\] = *(Empty)*$/g, //[compiler] Bytecode[] = Empty 3584514f5e3Sopenharmony_ci /^\[compiler\] *Trys:([0-9, ]*)$/g, //[compiler] Trys: 3594514f5e3Sopenharmony_ci ]; 3604514f5e3Sopenharmony_ci let pb = this.procBlock_; 3614514f5e3Sopenharmony_ci let ret; 3624514f5e3Sopenharmony_ci switch (pb.blockStat) { 3634514f5e3Sopenharmony_ci case 0: 3644514f5e3Sopenharmony_ci ret = regexBlock[0].exec(l); 3654514f5e3Sopenharmony_ci if (ret) { 3664514f5e3Sopenharmony_ci pb.oneBlock = { 3674514f5e3Sopenharmony_ci id: ret[1], 3684514f5e3Sopenharmony_ci op: 'B' + ret[1], 3694514f5e3Sopenharmony_ci detailList: [], 3704514f5e3Sopenharmony_ci maxDetailWidth: 0, 3714514f5e3Sopenharmony_ci }; 3724514f5e3Sopenharmony_ci pb.blockStat = 1; 3734514f5e3Sopenharmony_ci return false; 3744514f5e3Sopenharmony_ci } 3754514f5e3Sopenharmony_ci if (!pb.oneBlock) { //完成了一个block的解析 3764514f5e3Sopenharmony_ci if (!(pb.blockCollect.file in this.output_)) { 3774514f5e3Sopenharmony_ci this.output_[pb.blockCollect.file] = {}; 3784514f5e3Sopenharmony_ci } 3794514f5e3Sopenharmony_ci if (!(pb.blockCollect.func in this.output_[pb.blockCollect.file])) { 3804514f5e3Sopenharmony_ci this.output_[pb.blockCollect.file][pb.blockCollect.func] = []; 3814514f5e3Sopenharmony_ci } 3824514f5e3Sopenharmony_ci this.output_[pb.blockCollect.file][pb.blockCollect.func].push(pb.blockCollect); 3834514f5e3Sopenharmony_ci return true; 3844514f5e3Sopenharmony_ci } 3854514f5e3Sopenharmony_ci break; 3864514f5e3Sopenharmony_ci case 1: 3874514f5e3Sopenharmony_ci ret = regexBlock[1].exec(l); 3884514f5e3Sopenharmony_ci if (ret) { 3894514f5e3Sopenharmony_ci pb.oneBlock.in = [[], [], [], [], this.NumberStringToArray(ret[1])]; 3904514f5e3Sopenharmony_ci pb.blockStat = 2; 3914514f5e3Sopenharmony_ci return false; 3924514f5e3Sopenharmony_ci } 3934514f5e3Sopenharmony_ci break; 3944514f5e3Sopenharmony_ci case 2: 3954514f5e3Sopenharmony_ci ret = regexBlock[2].exec(l); 3964514f5e3Sopenharmony_ci if (ret) { 3974514f5e3Sopenharmony_ci pb.oneBlock.out = this.NumberStringToArray(ret[1]); 3984514f5e3Sopenharmony_ci pb.blockStat = 3; 3994514f5e3Sopenharmony_ci return false; 4004514f5e3Sopenharmony_ci } 4014514f5e3Sopenharmony_ci break; 4024514f5e3Sopenharmony_ci case 3: //开始记录bytecode,直到空行,结束这个block 4034514f5e3Sopenharmony_ci if (/^\[compiler\] *$/g.test(l)) { //遇到空行,完成block 4044514f5e3Sopenharmony_ci if (pb.oneBlock.maxDetailWidth === 0) { 4054514f5e3Sopenharmony_ci pb.oneBlock.maxDetailWidth = X2DFast.gi().getTextWidth('Empty', 14); 4064514f5e3Sopenharmony_ci pb.oneBlock.detailList.push('Empty'); 4074514f5e3Sopenharmony_ci } 4084514f5e3Sopenharmony_ci pb.blockCollect.irList.push(pb.oneBlock); 4094514f5e3Sopenharmony_ci pb.oneBlock = null; 4104514f5e3Sopenharmony_ci pb.blockStat = 0; 4114514f5e3Sopenharmony_ci } 4124514f5e3Sopenharmony_ci else { 4134514f5e3Sopenharmony_ci let s = l.substring(11); 4144514f5e3Sopenharmony_ci while (s.startsWith(' ')) { 4154514f5e3Sopenharmony_ci s = s.substring(1); 4164514f5e3Sopenharmony_ci } 4174514f5e3Sopenharmony_ci let w = X2DFast.gi().getTextWidth(s, 14); 4184514f5e3Sopenharmony_ci if (pb.oneBlock.maxDetailWidth < w) { 4194514f5e3Sopenharmony_ci pb.oneBlock.maxDetailWidth = w; 4204514f5e3Sopenharmony_ci } 4214514f5e3Sopenharmony_ci pb.oneBlock.detailList.push(s); 4224514f5e3Sopenharmony_ci } 4234514f5e3Sopenharmony_ci return false; 4244514f5e3Sopenharmony_ci default: 4254514f5e3Sopenharmony_ci return false; 4264514f5e3Sopenharmony_ci } 4274514f5e3Sopenharmony_ci return false; 4284514f5e3Sopenharmony_ci } 4294514f5e3Sopenharmony_ci} 4304514f5e3Sopenharmony_ci 4314514f5e3Sopenharmony_cimodule.exports = { 4324514f5e3Sopenharmony_ci LogParser 4334514f5e3Sopenharmony_ci}; 434