OpenASIP  2.0
TestBenchBlock.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2015 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /*
25  * @file TestBenchBlock.cc
26  *
27  * Implementation of TestBenchBlock class.
28  *
29  * Created on: 7.9.2015
30  * @author Henry Linjamäki 2015 (henry.linjamaki-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #include "TestBenchBlock.hh"
35 
36 #include "ProcessorWrapperBlock.hh"
37 
38 #include "Machine.hh"
39 #include "MachineInfo.hh"
40 
42 #include "FileSystem.hh"
43 #include "Environment.hh"
44 #include "Conversion.hh"
45 
46 namespace ProGe {
47 
48 /**
49  * Construct The test bench for the core TTA processor.
50  *
51  * The test bench creation is limited to TTAs with one address space for
52  * instruction and address spaces for data shared by one LSU at most.
53  *
54  * @param context The context for deriving necessary information about the
55  * core.
56  * @param coreBlock The DUT for test bench
57  * @exception Thrown if the test bench can not be created.
58  */
60  const ProGeContext& context, const BaseNetlistBlock& coreBlock)
61  : BaseNetlistBlock("testbench", ""), context_(context), proc_(nullptr) {
62  using namespace TTAMachine;
63 
64  std::map<std::string, unsigned> ASUserCounts;
65  std::map<std::string, unsigned> lockFUCounts;
66 
67  for (auto fu : MachineInfo::findLockUnits(context.adf())) {
68  if (fu->hasAddressSpace()) {
69  lockFUCounts[fu->addressSpace()->name()]++;
70  }
71  }
72 
73  for (auto fu : context.adf().functionUnitNavigator()) {
74  if (fu->hasAddressSpace()) {
75  ASUserCounts[fu->addressSpace()->name()]++;
76  }
77  }
78 
79  for (auto asUserCount : ASUserCounts) {
80  unsigned LSUCount(asUserCount.second);
81 
82  if (lockFUCounts.count(asUserCount.first) > 0) {
83  LSUCount -= lockFUCounts[asUserCount.first];
84  }
85 
86  if (LSUCount > 1) {
88  "Can not create test bench for TTA address spaces shared by "
89  "multiple LSUs.");
90  }
91  }
92  try {
93  proc_ = new ProcessorWrapperBlock(context, coreBlock);
94  } catch (Exception& e) {
96  }
97 }
98 
100 }
101 
102 void
103 TestBenchBlock::write(const Path& targetBaseDir, HDL targetLang) const {
104  // Check language compatibility //
105  if (targetLang != VHDL) {
106  THROW_EXCEPTION(NotAvailable, "Only VHDL is supported.");
107  }
108 
110 
111  instantiator.replacePlaceholder("dut-entity", proc_->moduleName());
112 
113  if (context_.idf().icDecoderParameterValue("debugger") == "external") {
114  instantiator.replacePlaceholder("proc-entity-db-signals",
115  "db_pc_start : in std_logic_vector(IMEMADDRWIDTH-1 downto 0);\n"
116  "db_tta_nreset : in std_logic;\n"
117  "db_lockrq : in std_logic;");
118 
119  instantiator.replacePlaceholder("proc-instance-db-signals",
120  "db_pc_start => (others => '0'),\n"
121  "db_tta_nreset => '1',\n"
122  "db_lockrq => '0',");
123  }
124 
125  FileSystem::createDirectory(targetBaseDir/"tb");
126 
127  Path progeDataDir(Environment::dataDirPath("ProGe"));
128  instantiator.instantiateTemplateFile(
129  progeDataDir/"tb"/"testbench.vhdl.tmpl",
130  targetBaseDir/"tb"/"testbench.vhdl");
131  instantiator.instantiateTemplateFile(
132  progeDataDir/"tb"/"clkgen.vhdl",
133  targetBaseDir/"tb"/"clkgen.vhdl");
134 
135  proc_->write(targetBaseDir, targetLang);
136 }
137 
138 } /* namespace ProGe */
ProGe::BaseNetlistBlock
Definition: BaseNetlistBlock.hh:59
Path
Definition: FileSystem.hh:197
FileSystem.hh
FileSystem::createDirectory
static bool createDirectory(const std::string &path)
Definition: FileSystem.cc:400
HDLTemplateInstantiator
Definition: HDLTemplateInstantiator.hh:45
ProGe::TestBenchBlock::context_
const ProGeContext & context_
The ProGe context for additional information.
Definition: TestBenchBlock.hh:63
ProGe::TestBenchBlock::write
virtual void write(const Path &targetBaseDir, HDL targetLang=VHDL) const override
Definition: TestBenchBlock.cc:103
ProGe::ProGeContext::adf
const TTAMachine::Machine & adf() const
Definition: ProGeContext.cc:57
ProcessorWrapperBlock.hh
MachineInfo.hh
HDLTemplateInstantiator.hh
MachineInfo::findLockUnits
static std::vector< const TTAMachine::FunctionUnit * > findLockUnits(const TTAMachine::Machine &machine)
Definition: MachineInfo.cc:759
NotAvailable
Definition: Exception.hh:728
TestBenchBlock.hh
IDF::MachineImplementation::icDecoderParameterValue
std::string icDecoderParameterValue(const std::string &name) const
Definition: MachineImplementation.cc:1415
ProGe::VHDL
@ VHDL
VHDL.
Definition: ProGeTypes.hh:41
THROW_EXCEPTION
#define THROW_EXCEPTION(exceptionType, message)
Exception wrapper macro that automatically includes file name, line number and function name where th...
Definition: Exception.hh:39
Conversion.hh
TTAMachine::Machine::functionUnitNavigator
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition: Machine.cc:380
ProGe::ProGeContext::idf
const IDF::MachineImplementation & idf() const
Definition: ProGeContext.cc:62
Environment.hh
Machine.hh
Exception
Definition: Exception.hh:54
ProGe::ProGeContext::coreEntityName
const std::string & coreEntityName() const
Definition: ProGeContext.cc:77
ProGe::TestBenchBlock::TestBenchBlock
TestBenchBlock()=delete
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
ProGe::ProcessorWrapperBlock
Definition: ProcessorWrapperBlock.hh:51
ProGe::TestBenchBlock::proc_
ProcessorWrapperBlock * proc_
The block that wraps the processor and instantiates memories for the GCU and LSUs.
Definition: TestBenchBlock.hh:66
ProGe::ProcessorWrapperBlock::write
virtual void write(const Path &targetBaseDir, HDL targetLang=VHDL) const override
Definition: ProcessorWrapperBlock.cc:112
HDLTemplateInstantiator::replacePlaceholder
void replacePlaceholder(const std::string &key, const std::string &replacer, bool append=false)
Definition: HDLTemplateInstantiator.cc:62
ProGe
Definition: FUGen.hh:54
ProGe::TestBenchBlock::~TestBenchBlock
virtual ~TestBenchBlock()
Definition: TestBenchBlock.cc:99
ProGe::HDL
HDL
HDLs supported by ProGe.
Definition: ProGeTypes.hh:40
ProGe::BaseNetlistBlock::moduleName
const std::string & moduleName() const
Definition: BaseNetlistBlock.cc:140
HDLTemplateInstantiator::instantiateTemplateFile
void instantiateTemplateFile(const std::string &templateFile, const std::string &dstFile)
Definition: HDLTemplateInstantiator.cc:113
TTAMachine
Definition: Assembler.hh:48
ProGe::ProGeContext
Definition: ProGeContext.hh:60
Environment::dataDirPath
static std::string dataDirPath(const std::string &prog)
Definition: Environment.cc:176