OpenASIP  2.0
LHSValue.cc
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 #include <LHSValue.hh>
30 #include <BinaryOps.hh>
31 #include <StringTools.hh>
32 #include <cassert>
33 
34 namespace HDLGenerator {
35 
36 void
37 LHSValue::hdl(std::ostream& stream, Language lang, int level) {
38  stream << StringTools::indent(level);
39  hdl(stream, lang);
40 }
41 
42 void
43 LHSValue::hdl(std::ostream& stream, Language lang) {
44  if (lang == Language::VHDL) {
45  stream << vhdl_;
46  } else {
47  stream << verilog_;
48  }
49 }
50 
51 void
52 LHSValue::writeSignals(std::unordered_set<std::string>& readList) const {
53  for (auto a : readList_) {
54  readList.insert(a);
55  }
56 }
57 
60  return LogicalOr(*this, rhs);
61 }
62 
65  return BitwiseOr(*this, rhs);
66 }
67 
70  return LogicalAnd(*this, rhs);
71 }
72 
75  return BitwiseAnd(*this, rhs);
76 }
77 
80  return BitwiseXor(*this, rhs);
81 }
82 
85  return LogicalNot(*this);
86 }
87 
90  return BitwiseNot(*this);
91 }
92 
93 LHSSignal::LHSSignal(std::string name) {
94  vhdl_ = name;
95  verilog_ = name;
96  readList_.insert(name);
97 }
98 
99 BinaryLiteral::BinaryLiteral(std::string value) : value_(value) {
100  std::string delim;
101  if (value.size() > 1) {
102  delim = "\"";
103  } else {
104  delim = "'";
105  }
106  vhdl_ = delim + value + delim;
107  verilog_ = value;
108 }
109 
110 BinaryLiteral::BinaryLiteral(int value, int width, bool signExtend)
111  : value_(std::to_string(value)) {
112  // e.g. std_logic_vector(to_signed(value, width))
113  std::string type = signExtend ? "signed" : "unsigned";
114  vhdl_ = "std_logic_vector(to_" + type + "(" + std::to_string(value) +
115  ", " + std::to_string(width) + "))";
116 
117  verilog_ = value;
118 }
119 } // namespace HDLGenerator
HDLGenerator::LHSValue
Definition: LHSValue.hh:39
HDLGenerator::LogicalAnd
Definition: BinaryOps.hh:51
HDLGenerator
Definition: BinaryOps.hh:35
HDLGenerator::LHSValue::operator~
LHSValue operator~()
Definition: LHSValue.cc:89
HDLGenerator::LogicalOr
Definition: BinaryOps.hh:63
BinaryOps.hh
LHSValue.hh
HDLGenerator::LHSValue::vhdl_
std::string vhdl_
Definition: LHSValue.hh:59
StringTools::indent
static std::string indent(int level)
Definition: StringTools.cc:319
HDLGenerator::LHSValue::operator^
LHSValue operator^(LHSValue rhs)
Definition: LHSValue.cc:79
HDLGenerator::LHSValue::operator||
LHSValue operator||(LHSValue rhs)
Definition: LHSValue.cc:59
HDLGenerator::LHSValue::operator&
LHSValue operator&(LHSValue rhs)
Definition: LHSValue.cc:74
StringTools.hh
HDLGenerator::LHSValue::writeSignals
void writeSignals(std::unordered_set< std::string > &readList) const
Definition: LHSValue.cc:52
HDLGenerator::LHSValue::operator|
LHSValue operator|(LHSValue rhs)
Definition: LHSValue.cc:64
HDLGenerator::Language
Language
Definition: HWGenTools.hh:33
HDLGenerator::BitwiseNot
Definition: BinaryOps.hh:108
HDLGenerator::BitwiseAnd
Definition: BinaryOps.hh:57
HDLGenerator::LHSValue::operator!
LHSValue operator!()
Definition: LHSValue.cc:84
HDLGenerator::BinaryLiteral::BinaryLiteral
BinaryLiteral(std::string value)
Definition: LHSValue.cc:99
HDLGenerator::BitwiseXor
Definition: BinaryOps.hh:75
HDLGenerator::LHSSignal::LHSSignal
LHSSignal(std::string name)
Definition: LHSValue.cc:93
HDLGenerator::LHSValue::hdl
void hdl(std::ostream &stream, Language lang, int level)
Definition: LHSValue.cc:37
HDLGenerator::BitwiseOr
Definition: BinaryOps.hh:69
HDLGenerator::LHSValue::verilog_
std::string verilog_
Definition: LHSValue.hh:60
HDLGenerator::LogicalNot
Definition: BinaryOps.hh:103
HDLGenerator::LHSValue::readList_
std::unordered_set< std::string > readList_
Definition: LHSValue.hh:58
HDLGenerator::Language::VHDL
@ VHDL
HDLGenerator::LHSValue::operator&&
LHSValue operator&&(LHSValue rhs)
Definition: LHSValue.cc:69