OpenASIP  2.0
WidthTransformations.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2017 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 LHSValue.hh
26 *
27 * @author Lasse Lehtonen 2017 (lasse.lehtonen-no.spam-tut.fi)
28 */
29 #pragma once
30 #include <HWGenTools.hh>
31 #include <LHSValue.hh>
32 #include <Generatable.hh>
33 #include <string>
34 
35 namespace HDLGenerator {
36  /**
37  * Unsigned extend.
38  */
39  class Ext : public LHSValue {
40  public:
41  Ext(std::string name, int extWidth, int signalWidth) {
42  readList_.insert(name);
43  if (extWidth > signalWidth) {
44  write_rtl(name, std::to_string(extWidth),
45  std::to_string(signalWidth));
46  } else {
47  vhdl_ = name;
48  verilog_ = name;
49  }
50  }
51  Ext(std::string name, std::string extWidth, int signalWidth) {
52  readList_.insert(name);
53  write_rtl(name, extWidth, std::to_string(signalWidth));
54  }
55 
56  void write_rtl(std::string name, std::string extWidth,
57  std::string signalWidth) {
58  vhdl_ = "((" + extWidth + "-1 downto " + signalWidth
59  + " => '0') & " + name + ")";
60  verilog_ = "{{" + extWidth + "-" + signalWidth + "{"
61  + "1'b0}}, " + name + "}";
62  }
63  };
64 
65  /**
66  * Splice of a vector.
67  */
68  class Splice : public LHSValue {
69  public:
70  Splice(std::string name, int upperBound, int lowerBound) {
71  readList_.insert(name);
72  vhdl_ = name + "(" + std::to_string(upperBound)
73  + " downto " + std::to_string(lowerBound) + ")";
74  verilog_ = name + "[" + std::to_string(upperBound)
75  + ":" + std::to_string(lowerBound) + "]";
76  }
77  };
78 
79  /**
80  * Signed extend.
81  */
82  class Sext : public LHSValue {
83  public:
84  Sext(std::string name, int extWidth, int signalWidth) {
85  readList_.insert(name);
86  if (extWidth > signalWidth) {
87  write_rtl(name, std::to_string(extWidth), signalWidth);
88  } else {
89  vhdl_ = name;
90  verilog_ = name;
91  }
92  }
93 
94  Sext(std::string name, std::string extWidth, int signalWidth) {
95  readList_.insert(name);
96  write_rtl(name, extWidth, signalWidth);
97  }
98 
99  void write_rtl(std::string name, std::string extWidth,
100  int signalWidth) {
101  std::string sigWidth = std::to_string(signalWidth);
102  vhdl_ = "((" + extWidth + "-1 downto " + sigWidth + " => " + name;
103  verilog_ = "{{" + extWidth + "-" + sigWidth + "{" + name + "}";
104  if (signalWidth > 1) {
105  vhdl_ += "(" + sigWidth + "-1)";
106  verilog_ += "[" + sigWidth + "-1]";
107  }
108  vhdl_ += ") & " + name + ")";
109  verilog_ += "}}" + name + "}";
110  }
111  };
112 }
HDLGenerator::LHSValue
Definition: LHSValue.hh:39
HDLGenerator
Definition: BinaryOps.hh:35
HDLGenerator::Ext::Ext
Ext(std::string name, std::string extWidth, int signalWidth)
Definition: WidthTransformations.hh:51
LHSValue.hh
HDLGenerator::LHSValue::vhdl_
std::string vhdl_
Definition: LHSValue.hh:59
HDLGenerator::Sext
Definition: WidthTransformations.hh:82
HDLGenerator::Sext::Sext
Sext(std::string name, int extWidth, int signalWidth)
Definition: WidthTransformations.hh:84
HDLGenerator::Ext::Ext
Ext(std::string name, int extWidth, int signalWidth)
Definition: WidthTransformations.hh:41
HDLGenerator::Splice
Definition: WidthTransformations.hh:68
HDLGenerator::Sext::Sext
Sext(std::string name, std::string extWidth, int signalWidth)
Definition: WidthTransformations.hh:94
HDLGenerator::Splice::Splice
Splice(std::string name, int upperBound, int lowerBound)
Definition: WidthTransformations.hh:70
HDLGenerator::Ext
Definition: WidthTransformations.hh:39
HWGenTools.hh
Generatable.hh
HDLGenerator::LHSValue::verilog_
std::string verilog_
Definition: LHSValue.hh:60
HDLGenerator::LHSValue::readList_
std::unordered_set< std::string > readList_
Definition: LHSValue.hh:58
HDLGenerator::Sext::write_rtl
void write_rtl(std::string name, std::string extWidth, int signalWidth)
Definition: WidthTransformations.hh:99
HDLGenerator::Ext::write_rtl
void write_rtl(std::string name, std::string extWidth, std::string signalWidth)
Definition: WidthTransformations.hh:56