93 RequiredAttrs(
const std::string& name) :
96 uint64_t cycle_time = 0;
97 uint64_t unique_id = 0;
98 std::string event_name =
"";
107 std::string prefix =
"";
108 std::string postfix =
"";
109 FormatFlags pre_format;
110 FormatFlags post_format;
112 char fill_char =
' ';
118 std::array<std::string,
sizeof...(CustomAttrs)> custom_attrs_names_;
121 std::array<PrePostTags,
sizeof...(CustomAttrs)> custom_attrs_formats_;
123 std::tuple<CustomAttrs...> custom_attrs_;
128 RequiredAttrs required_attrs_;
136 void writeRequiredData_(std::stringstream& s)
139 std::stringstream name_str;
140 name_str <<
"\"" << required_attrs_.event_name <<
"\"";
141 s.flags(FormatFlags(std::ios::left));
142 s << std::get<PEventProtection::EV>(PEventProtection::PEventProtectedAttrs) <<
"=" << std::setw(12) << name_str.str() <<
" ";
145 void appendCycle_(std::stringstream& s)
148 s << std::get<PEventProtection::CYCLE>(PEventProtection::PEventProtectedAttrs) <<
"=" << clk_->
currentCycle();
152 template <
class Tuple,
class Array,
class Formats, std::
size_t N>
153 struct TupleUnroller {
154 static void unroller_(
const Tuple& t,
const Array& a,
const Formats& f, std::stringstream& s){
155 TupleUnroller<Tuple, Array, Formats, N-1>::unroller_(t, a, f, s);
156 s << std::get<N-1>(a) <<
"=";
159 sparta_assert(PEventProtection::CheckNoQuotes(std::get<N-1>(t), std::get<N-1>(f).prefix, std::get<N-1>(f).postfix),
"Quotes are appended to string types for PEvent logging automatically and should not be done by the modeller in the prefix, postfix, or the string itself.");
161 PEventProtection::AppendQuote<
decltype(std::get<N-1>(t))>(s);
162 s.flags(std::get<N-1>(f).pre_format);
163 s << std::get<N-1>(f).prefix;
164 s << std::setfill(std::get<N-1>(f).fill_char);
165 s << std::setw(std::get<N-1>(f).swidth);
167 s << std::get<N-1>(t);
168 s << std::get<N-1>(f).postfix;
170 PEventProtection::AppendQuote<
decltype(std::get<N-1>(t))>(s);
172 s.flags(std::get<N-1>(f).post_format);
175 template <
class Tuple,
class Array,
class Formats>
176 struct TupleUnroller<Tuple,
Array, Formats, 1> {
177 static void unroller_(
const Tuple& t,
const Array& a,
const Formats& f, std::stringstream& s){
178 s << std::get<0>(a) <<
"=";
179 s.flags(std::get<0>(f).pre_format);
180 s << std::get<0>(f).prefix;
183 sparta_assert(PEventProtection::CheckNoQuotes(std::get<0>(t), std::get<0>(f).prefix, std::get<0>(f).postfix),
"Quotes are appended to string types for PEvent logging automatically and should not be done by the modeller in the prefix, postfix, or the string itself.");
185 PEventProtection::AppendQuote<decltype(std::get<0>(t))>(s);
186 s << std::get<0>(f).postfix;
187 s << std::setfill(std::get<0>(f).fill_char);
188 s << std::setw(std::get<0>(f).swidth);
191 s.flags(std::get<0>(f).post_format);
193 PEventProtection::AppendQuote<decltype(std::get<0>(t))>(s);
203 template<
typename ...ArgNames>
205 custom_attrs_names_{{names...}},
206 required_attrs_(name),
212 for(
auto n : custom_attrs_names_)
214 sparta_assert(n != PEventProtection::PEventProtectedAttrs[0],
"custom attribute name cannot be one of the protected attribute names");
215 sparta_assert(n != PEventProtection::PEventProtectedAttrs[1],
"custom attribute name cannot be one of the protected attribute names");
220 void setName(
const std::string& name)
222 required_attrs_.event_name = name;
240 void setFormatFlags(
const uint32_t n,
const FormatFlags& pre_flag,
241 const FormatFlags& post_flag,
242 const std::string& pre,
const std::string& post)
244 sparta_assert(n <
sizeof...(CustomAttrs),
"Cannot set the format flags for an attribute where n >= the number of custom attributes.");
246 custom_attrs_formats_[n].prefix = pre;
247 custom_attrs_formats_[n].postfix = post;
248 custom_attrs_formats_[n].pre_format = pre_flag;
249 custom_attrs_formats_[n].post_format = post_flag;
251 void setFormatFlags(
const uint32_t n,
const std::string& pre,
const std::string& post)
253 setFormatFlags(n, FormatFlags(), FormatFlags(), pre, post);
263 void setFormatLength(
const uint32_t n,
const int length,
const FormatFlags& align,
const char fill)
265 sparta_assert(n <
sizeof...(CustomAttrs),
"Cannot set the format flags for an attribute where n >= the number of custom attributes.");
266 custom_attrs_formats_.at(n).swidth = length;
267 custom_attrs_formats_.at(n).pre_format = custom_attrs_formats_.at(n).pre_format | align;
268 custom_attrs_formats_.at(n).fill_char = fill;
278 for(uint32_t i : list){
279 setFormatFlags(i,
"\"",
"\"");
288 void setAsHex(
const std::initializer_list<uint32_t>& list)
290 static const int hex_length = 8;
291 for(uint32_t i : list){
292 setFormatFlags(i, pevents::FormatFlags(std::ios::hex), pevents::FormatFlags(std::ios::dec),
"0x",
"");
293 setFormatLength(i, hex_length, pevents::FormatFlags(std::ios::right),
'0');
304 void setAttrs(CustomAttrs... attrs) { custom_attrs_ = std::make_tuple<CustomAttrs...>(std::forward<CustomAttrs>(attrs)...); }
308 template<
typename AttrType, u
int32_t N>
309 void setAttr(
const AttrType& attr) { std::get<N>(custom_attrs_) = attr; }
318 if(logger_.observed())
321 writeRequiredData_(s);
322 TupleUnroller<
decltype(custom_attrs_),
decltype(custom_attrs_names_),
decltype(custom_attrs_formats_),
sizeof...(CustomAttrs)>::unroller_(custom_attrs_, custom_attrs_names_, custom_attrs_formats_, s);
354 return logger_.observed();