ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
TracePrinter.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// This file is part of ETISS. It is licensed under the BSD 3-Clause License; you may not use this file except in
4// compliance with the License. You should have received a copy of the license along with this project. If not, see the
5// LICENSE file.
6
7#include <fstream>
8#include <iostream>
9
10#include "etiss/ETISS.h"
11#include "etiss/Plugin.h"
12#include "etiss/jit/ReturnCode.h"
13
27{
28 public:
29 // ctor
30 TracePrinter(etiss::uint32 terminateAddr, bool printOnScreen = false, char terminateHit = 1)
31 : CoroutinePlugin(), printOnScreen_(printOnScreen), terminateAddr_(terminateAddr), terminateHit_(terminateHit)
32 {
33 }
34
35 // dtor
37
38 etiss::int32 execute()
39 {
41 std::cout << "[INFO] {TracePrinter} : PC = 0x" << std::hex << cpu_->instructionPointer << std::endl;
42
43 pcTrace_ << "[INFO] {TracePrinter}: PC = 0x" << std::hex << cpu_->instructionPointer << std::endl;
44
46 {
47 if (++hitTimes_ == terminateHit_)
48 {
49 printLog();
50 return etiss::RETURNCODE::CPUTERMINATED;
51 }
52 }
53 return etiss::RETURNCODE::NOERROR;
54 }
55 std::string _getPluginName() const { return std::string("TracePrinter"); }
56
57 void init(ETISS_CPU *cpu, ETISS_System *system, etiss::CPUArch *arch)
58 {
59 this->cpu_ = cpu;
60 this->system_ = system;
61 this->arch_ = arch;
62 }
63
64 void cleanup()
65 {
66 cpu_ = nullptr;
67 system_ = nullptr;
68 arch_ = nullptr;
69 }
70
71 private:
75
76 std::stringstream pcTrace_;
77 char hitTimes_ = 0;
79 const etiss::uint32 terminateAddr_;
80 const char terminateHit_;
81
82 void printLog()
83 {
84 std::ofstream outPcTrace;
85 outPcTrace.open("Trace.log");
86 outPcTrace << pcTrace_.str();
87 outPcTrace.close();
88 }
89};
Header file of the ETISS library.
plugins for extensions to code translation and instruction execution
A simple logger dedicated to print PC trace.
ETISS_CPU * cpu_
void cleanup()
this function is called after cpu execution loop (etiss::CPUCore::execute) finished.
ETISS_System * system_
const char terminateHit_
void printLog()
bool printOnScreen_
etiss::int32 execute()
called before a block and may act in the same way as a block
void init(ETISS_CPU *cpu, ETISS_System *system, etiss::CPUArch *arch)
this function is called before the plugin is used in the cpu execution loop (etiss::CPUCore::execute)...
etiss::CPUArch * arch_
std::stringstream pcTrace_
const etiss::uint32 terminateAddr_
std::string _getPluginName() const
TracePrinter(etiss::uint32 terminateAddr, bool printOnScreen=false, char terminateHit=1)
the interface to translate instructions of and processor architecture
Definition CPUArch.h:116
this plugin will be called before a block is executed.
Definition Plugin.h:259
basic cpu state structure needed for execution of any cpu architecture.
Definition CPU.h:51
etiss_uint64 instructionPointer
pointer to next instruction.
Definition CPU.h:54
memory access and time synchronization functions.
Definition System.h:40