11cb0ef41Sopenharmony_ci// Copyright 2016 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciimport { LogReader, parseString } from "./logreader.mjs";
61cb0ef41Sopenharmony_ciimport { CodeMap, CodeEntry } from "./codemap.mjs";
71cb0ef41Sopenharmony_ciexport {
81cb0ef41Sopenharmony_ci    ArgumentsProcessor, LinuxCppEntriesProvider,
91cb0ef41Sopenharmony_ci    WindowsCppEntriesProvider, MacOSCppEntriesProvider,
101cb0ef41Sopenharmony_ci  } from  "./tickprocessor.mjs";
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciexport class CppProcessor extends LogReader {
141cb0ef41Sopenharmony_ci  constructor(cppEntriesProvider, timedRange, pairwiseTimedRange) {
151cb0ef41Sopenharmony_ci    super(timedRange, pairwiseTimedRange);
161cb0ef41Sopenharmony_ci    this.setDispatchTable({
171cb0ef41Sopenharmony_ci         __proto__: null,
181cb0ef41Sopenharmony_ci        'shared-library': {
191cb0ef41Sopenharmony_ci          parsers: [parseString, parseInt, parseInt, parseInt],
201cb0ef41Sopenharmony_ci          processor: this.processSharedLibrary }
211cb0ef41Sopenharmony_ci    });
221cb0ef41Sopenharmony_ci    this.cppEntriesProvider_ = cppEntriesProvider;
231cb0ef41Sopenharmony_ci    this.codeMap_ = new CodeMap();
241cb0ef41Sopenharmony_ci    this.lastLogFileName_ = null;
251cb0ef41Sopenharmony_ci  }
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci  /**
281cb0ef41Sopenharmony_ci   * @override
291cb0ef41Sopenharmony_ci   */
301cb0ef41Sopenharmony_ci  printError(str) {
311cb0ef41Sopenharmony_ci    console.log(str);
321cb0ef41Sopenharmony_ci  }
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci  processLogFile(fileName) {
351cb0ef41Sopenharmony_ci    this.lastLogFileName_ = fileName;
361cb0ef41Sopenharmony_ci    let line;
371cb0ef41Sopenharmony_ci    while (line = readline()) {
381cb0ef41Sopenharmony_ci      this.processLogLine(line);
391cb0ef41Sopenharmony_ci    }
401cb0ef41Sopenharmony_ci  }
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci  processLogFileInTest(fileName) {
431cb0ef41Sopenharmony_ci    // Hack file name to avoid dealing with platform specifics.
441cb0ef41Sopenharmony_ci    this.lastLogFileName_ = 'v8.log';
451cb0ef41Sopenharmony_ci    const contents = d8.file.read(fileName);
461cb0ef41Sopenharmony_ci    this.processLogChunk(contents);
471cb0ef41Sopenharmony_ci  }
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci  processSharedLibrary(name, startAddr, endAddr, aslrSlide) {
501cb0ef41Sopenharmony_ci    const self = this;
511cb0ef41Sopenharmony_ci    const libFuncs = this.cppEntriesProvider_.parseVmSymbols(
521cb0ef41Sopenharmony_ci        name, startAddr, endAddr, aslrSlide, function(fName, fStart, fEnd) {
531cb0ef41Sopenharmony_ci      const entry = new CodeEntry(fEnd - fStart, fName, 'CPP');
541cb0ef41Sopenharmony_ci      self.codeMap_.addStaticCode(fStart, entry);
551cb0ef41Sopenharmony_ci    });
561cb0ef41Sopenharmony_ci  }
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci  dumpCppSymbols() {
591cb0ef41Sopenharmony_ci    const staticEntries = this.codeMap_.getAllStaticEntriesWithAddresses();
601cb0ef41Sopenharmony_ci    const total = staticEntries.length;
611cb0ef41Sopenharmony_ci    for (let i = 0; i < total; ++i) {
621cb0ef41Sopenharmony_ci      const entry = staticEntries[i];
631cb0ef41Sopenharmony_ci      const printValues = ['cpp', `0x${entry[0].toString(16)}`, entry[1].size,
641cb0ef41Sopenharmony_ci                        `"${entry[1].name}"`];
651cb0ef41Sopenharmony_ci                        console.log(printValues.join(','));
661cb0ef41Sopenharmony_ci    }
671cb0ef41Sopenharmony_ci  }
681cb0ef41Sopenharmony_ci}
69