ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
VariableValueLogger.cpp
Go to the documentation of this file.
1 /*
2 
3  @copyright
4 
5  <pre>
6 
7  Copyright 2018 Infineon Technologies AG
8 
9  This file is part of ETISS tool, see <https://github.com/tum-ei-eda/etiss>.
10 
11  The initial version of this software has been created with the funding support by the German Federal
12  Ministry of Education and Research (BMBF) in the project EffektiV under grant 01IS13022.
13 
14  Redistribution and use in source and binary forms, with or without modification, are permitted
15  provided that the following conditions are met:
16 
17  1. Redistributions of source code must retain the above copyright notice, this list of conditions and
18  the following disclaimer.
19 
20  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
21  and the following disclaimer in the documentation and/or other materials provided with the distribution.
22 
23  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
24  or promote products derived from this software without specific prior written permission.
25 
26  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
27  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
28  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
29  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  POSSIBILITY OF SUCH DAMAGE.
34 
35  </pre>
36 
37  @author Chair of Electronic Design Automation, TUM
38 
39  @version 0.1
40 
41 */
42 
44 #include "etiss/CPUCore.h"
45 #include "etiss/Instruction.h"
46 
47 #include <iostream>
48 
49 extern "C"
50 {
52  {
54  vvl.writeValue();
55  }
56 }
57 
58 namespace etiss
59 {
60 
61 namespace plugin
62 {
63 
65  const std::string &field, const std::string &file,
66  std::function<void(std::ostream &out, const std::string &field, uint64_t value)> writer)
67  : field_(field)
68 {
69  if (!writer)
70  writer = [](std::ostream &out, const std::string &field, uint64_t value) {
71  out << field << "," << value << "\n";
72  };
73  out_.open(file.c_str(), std::ios::binary);
74  writer_ = writer;
75 }
76 
78 {
79  block.fileglobalCode().insert("extern void etiss_plugin_VariableValueLogger(void *); ");
80 }
81 
83 {
84  auto f = plugin_core_->getStruct()->findName(field_);
85  unsigned width = f ? static_cast<unsigned>(f->width_) : 64;
86  mis.foreach ([this, width](etiss::instr::VariableInstructionSet &vis) {
87  vis.foreach ([this, width](etiss::instr::InstructionSet &is) {
88  is.foreach ([this, width](etiss::instr::Instruction &i) {
89  i.addCallback(
92  p.getRegisterDependencies().add(field_, width);
93  p.code() = std::string("etiss_plugin_VariableValueLogger(") + getPointerCode() + ");";
94  return true;
95  },
96  0);
97  });
98  });
99  });
100 }
101 
103 {
104  if (field_ == "instructionPointer")
105  {
107  }
108  else
109  {
110  writer_(out_, field_, plugin_core_->getStruct()->findName(field_)->read());
111  }
112  out_.flush();
113 }
114 
116 {
117  return std::string("VariableValueLogger for ") + field_;
118 }
119 
120 } // namespace plugin
121 
122 } // namespace etiss
defines main cpu core interface
contains container classes to store instruction definitions + translation functions and build a trans...
void etiss_plugin_VariableValueLogger(void *ptr)
static __inline__ uint64_t
Definition: arm_cde.h:31
virtual std::shared_ptr< VirtualStruct > getStruct()
Get the virtual structure of this CPUCore instance.
Definition: CPUCore.h:170
A list of CodeSets.
Definition: CodePart.h:570
std::set< std::string > & fileglobalCode()
Definition: CodePart.h:604
Contains a small code snipped.
Definition: CodePart.h:386
std::string & code()
Definition: CodePart.h:416
RegisterSet & getRegisterDependencies()
Definition: CodePart.h:413
A set of CodeParts.
Definition: CodePart.h:437
void append(const CodePart &part, CodePart::TYPE type)
Definition: CodePart.h:450
CPUCore * plugin_core_
holds a pointer to the associated CPUCore instance.
Definition: Plugin.h:200
ETISS_CPU * plugin_cpu_
holds a pointer to the cpu structure. will be set before init call and after cleanup call
Definition: Plugin.h:195
std::string getPointerCode() const
returns a C code expression that allows to get or assign a pointer to the variable assigned to this t...
Definition: Plugin.cpp:101
stores a bit vector
Definition: Instruction.h:161
this class contains parameters that persist in between instruction lookpus/translation within a trans...
Definition: Instruction.h:337
holds etiss::instr::Instruction instances and handles automatic instruction tree creation.
Definition: Instruction.h:442
void foreach(std::function< void(Instruction &)> func)
holds information and translation callbacks for an instruction.
Definition: Instruction.h:393
bool addCallback(std::function< bool(BitArray &, etiss::CodeSet &, InstructionContext &)> callback, uint32_t builtinGroups, const std::set< uint32_t > &groups=std::set< uint32_t >())
holds etiss::instr::VariableInstructionSet instances for different modes.
Definition: Instruction.h:562
void foreach(std::function< void(VariableInstructionSet &)> call)
holds etiss::instr::InstructionSet instances with different bit widths.
Definition: Instruction.h:500
void foreach(std::function< void(InstructionSet &)> func)
writes the value of a field before each instruction
std::ofstream out_
file stream for logger.
VariableValueLogger(const std::string &field, const std::string &file, std::function< void(std::ostream &out, const std::string &field, uint64_t value)> writer)
virtual std::string _getPluginName() const
returns the name of the Plugin.
virtual void initCodeBlock(etiss::CodeBlock &block) const
called before instructions are translated for the code block
void writeValue()
Calls the function specified with writer_ to log the variable.
std::function< void(std::ostream &out, const std::string &field, uint64_t value)> writer_
Function which specifies the outout format.
virtual void finalizeInstrSet(etiss::instr::ModedInstructionSet &) const
called after all instructions have been added to allow last changes
std::string field_
Name of the field to log.
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition: Benchmark.h:53
etiss_uint64 instructionPointer
pointer to next instruction.
Definition: CPU.h:92