No public description PiperOrigin-RevId: 795060273 Change-Id: I24b1ba07ef568e51289243262cd3395ecc7c5d01
diff --git a/mpact/sim/decoder/antlr_parser_wrapper.h b/mpact/sim/decoder/antlr_parser_wrapper.h index cee8e73..86a5e64 100644 --- a/mpact/sim/decoder/antlr_parser_wrapper.h +++ b/mpact/sim/decoder/antlr_parser_wrapper.h
@@ -28,14 +28,14 @@ template <typename Parser, typename Lexer> class AntlrParserWrapper { public: - explicit AntlrParserWrapper(std::istream *source_stream) { + explicit AntlrParserWrapper(std::istream* source_stream) { instruction_set_input_.load(*source_stream, /*lenient=*/true); lexer_ = new Lexer(&instruction_set_input_); tokens_ = new antlr4::CommonTokenStream(lexer_); parser_ = new Parser(tokens_); } - explicit AntlrParserWrapper(const std::string &source) { + explicit AntlrParserWrapper(const std::string& source) { instruction_set_input_.load(source, /*lenient=*/true); lexer_ = new Lexer(&instruction_set_input_); tokens_ = new antlr4::CommonTokenStream(lexer_); @@ -48,13 +48,13 @@ delete lexer_; } - Parser *parser() const { return parser_; } + Parser* parser() const { return parser_; } private: antlr4::ANTLRInputStream instruction_set_input_; - Lexer *lexer_; - antlr4::CommonTokenStream *tokens_; - Parser *parser_; + Lexer* lexer_; + antlr4::CommonTokenStream* tokens_; + Parser* parser_; }; } // namespace decoder
diff --git a/mpact/sim/decoder/base_class.h b/mpact/sim/decoder/base_class.h index 7e04b66..2deb0ba 100644 --- a/mpact/sim/decoder/base_class.h +++ b/mpact/sim/decoder/base_class.h
@@ -27,11 +27,11 @@ template <typename T> struct BaseClass { - const T *base; - TemplateInstantiationArgs *arguments = nullptr; - BaseClass(const T *base_, TemplateInstantiationArgs *arguments_) + const T* base; + TemplateInstantiationArgs* arguments = nullptr; + BaseClass(const T* base_, TemplateInstantiationArgs* arguments_) : base(base_), arguments(arguments_) {} - explicit BaseClass(const T *base_) : base(base_) {} + explicit BaseClass(const T* base_) : base(base_) {} }; } // namespace instruction_set
diff --git a/mpact/sim/decoder/bin_decoder.cc b/mpact/sim/decoder/bin_decoder.cc index 799871b..0c29cc4 100644 --- a/mpact/sim/decoder/bin_decoder.cc +++ b/mpact/sim/decoder/bin_decoder.cc
@@ -25,20 +25,20 @@ namespace decoder { namespace bin_format { -BinDecoder::BinDecoder(std::string name, BinEncodingInfo *encoding_info, - DecoderErrorListener *error_listener) +BinDecoder::BinDecoder(std::string name, BinEncodingInfo* encoding_info, + DecoderErrorListener* error_listener) : name_(name), encoding_info_(encoding_info), error_listener_(error_listener) {} BinDecoder::~BinDecoder() { instruction_group_vec_.clear(); } -void BinDecoder::AddInstructionGroup(InstructionGroup *group) { +void BinDecoder::AddInstructionGroup(InstructionGroup* group) { instruction_group_vec_.push_back(group); } void BinDecoder::CheckEncodings() { - for (auto *group : instruction_group_vec_) { + for (auto* group : instruction_group_vec_) { group->ProcessEncodings(); group->CheckEncodings(); }
diff --git a/mpact/sim/decoder/bin_decoder.h b/mpact/sim/decoder/bin_decoder.h index e8b3572..f2e7f25 100644 --- a/mpact/sim/decoder/bin_decoder.h +++ b/mpact/sim/decoder/bin_decoder.h
@@ -37,35 +37,35 @@ class BinDecoder { public: using InstructionGroupMultiMap = - absl::btree_multimap<std::string, InstructionGroup *>; + absl::btree_multimap<std::string, InstructionGroup*>; - BinDecoder(std::string name, BinEncodingInfo *encoding_info, - DecoderErrorListener *error_listener); + BinDecoder(std::string name, BinEncodingInfo* encoding_info, + DecoderErrorListener* error_listener); ~BinDecoder(); // Checks for invalid encodings, such as some duplicates. void CheckEncodings(); // Select instruction group for decoder generation. - void AddInstructionGroup(InstructionGroup *group); + void AddInstructionGroup(InstructionGroup* group); // Accessors. - const std::string &name() const { return name_; } - DecoderErrorListener *error_listener() const { return error_listener_; } - BinEncodingInfo *encoding_info() const { return encoding_info_; } - std::vector<InstructionGroup *> instruction_group_vec() { + const std::string& name() const { return name_; } + DecoderErrorListener* error_listener() const { return error_listener_; } + BinEncodingInfo* encoding_info() const { return encoding_info_; } + std::vector<InstructionGroup*> instruction_group_vec() { return instruction_group_vec_; } - std::deque<std::string> &namespaces() { return namespaces_; } + std::deque<std::string>& namespaces() { return namespaces_; } private: // Decoder name. std::string name_; // The global encoding structure. - BinEncodingInfo *encoding_info_; + BinEncodingInfo* encoding_info_; // Error handler. - DecoderErrorListener *error_listener_; + DecoderErrorListener* error_listener_; // The set of instruction groups in this decoder. - std::vector<InstructionGroup *> instruction_group_vec_; + std::vector<InstructionGroup*> instruction_group_vec_; // Namespace container. std::deque<std::string> namespaces_; };
diff --git a/mpact/sim/decoder/bin_encoding_info.cc b/mpact/sim/decoder/bin_encoding_info.cc index b0880a1..92bc125 100644 --- a/mpact/sim/decoder/bin_encoding_info.cc +++ b/mpact/sim/decoder/bin_encoding_info.cc
@@ -32,16 +32,16 @@ namespace bin_format { BinEncodingInfo::BinEncodingInfo(std::string opcode_enum, - DecoderErrorListener *error_listener) + DecoderErrorListener* error_listener) : opcode_enum_(opcode_enum), error_listener_(error_listener) {} BinEncodingInfo::~BinEncodingInfo() { delete decoder_; - for (auto &[unused, format_ptr] : format_map_) { + for (auto& [unused, format_ptr] : format_map_) { delete format_ptr; } format_map_.clear(); - for (auto &[unused, group_ptr] : instruction_group_map_) { + for (auto& [unused, group_ptr] : instruction_group_map_) { delete group_ptr; } instruction_group_map_.clear(); @@ -53,8 +53,8 @@ } // Adding a format that does not have a parent (to inherit from ). -absl::StatusOr<Format *> BinEncodingInfo::AddFormat(std::string name, - int width) { +absl::StatusOr<Format*> BinEncodingInfo::AddFormat(std::string name, + int width) { // Verify that the format name hasn't been used. if (format_map_.contains(name)) { return absl::AlreadyExistsError( @@ -66,8 +66,8 @@ } // Adding a format that does have a parent. -absl::StatusOr<Format *> BinEncodingInfo::AddFormat(std::string name, int width, - std::string parent_name) { +absl::StatusOr<Format*> BinEncodingInfo::AddFormat(std::string name, int width, + std::string parent_name) { // Verify that the format name hasn't been used. if (format_map_.contains(name)) { return absl::AlreadyExistsError( @@ -79,7 +79,7 @@ } // Lookup a format by name. Return nullptr if it isn't found. -Format *BinEncodingInfo::GetFormat(absl::string_view name) const { +Format* BinEncodingInfo::GetFormat(absl::string_view name) const { auto iter = format_map_.find(name); if (iter == format_map_.end()) return nullptr; return iter->second; @@ -87,7 +87,7 @@ // Add the named instruction group. Instruction encodings are added directly // to the group using the returned pointer. -absl::StatusOr<InstructionGroup *> BinEncodingInfo::AddInstructionGroup( +absl::StatusOr<InstructionGroup*> BinEncodingInfo::AddInstructionGroup( std::string name, int width, std::string format_name) { if (instruction_group_map_.contains(name)) { return absl::AlreadyExistsError( @@ -102,26 +102,26 @@ // Top level method that calls the checking method of each format. This is // called after all the formats have been added. void BinEncodingInfo::PropagateExtractors() { - for (auto &[unused, format] : format_map_) { + for (auto& [unused, format] : format_map_) { // For the base formats (those who do not inherit from another format). if (format->base_format() == nullptr) { format->PropagateExtractorsUp(); } } - for (auto &[unused, format] : format_map_) { + for (auto& [unused, format] : format_map_) { if (format->base_format() == nullptr) { format->PropagateExtractorsDown(); } } } -BinDecoder *BinEncodingInfo::AddBinDecoder(std::string name) { +BinDecoder* BinEncodingInfo::AddBinDecoder(std::string name) { if (decoder_ != nullptr) { error_listener_->semanticError(nullptr, "Can only select one decoder"); return nullptr; } - auto *bin_decoder = new BinDecoder(name, this, error_listener()); + auto* bin_decoder = new BinDecoder(name, this, error_listener()); decoder_ = bin_decoder; return bin_decoder; }
diff --git a/mpact/sim/decoder/bin_encoding_info.h b/mpact/sim/decoder/bin_encoding_info.h index 918198c..f046b64 100644 --- a/mpact/sim/decoder/bin_encoding_info.h +++ b/mpact/sim/decoder/bin_encoding_info.h
@@ -36,57 +36,57 @@ // instruction format input file. class BinEncodingInfo { public: - using InstructionGroupMap = absl::btree_map<std::string, InstructionGroup *>; - using FormatMap = absl::btree_map<std::string, Format *>; + using InstructionGroupMap = absl::btree_map<std::string, InstructionGroup*>; + using FormatMap = absl::btree_map<std::string, Format*>; BinEncodingInfo() = delete; BinEncodingInfo(std::string opcode_enum, - DecoderErrorListener *error_listener); + DecoderErrorListener* error_listener); ~BinEncodingInfo(); // Add a file to be included in the generated code. void AddIncludeFile(std::string include_file); // Add instruction format declaration - no parent (inherited) format. - absl::StatusOr<Format *> AddFormat(std::string name, int width); + absl::StatusOr<Format*> AddFormat(std::string name, int width); // Add instruction format declaration with a parent format. - absl::StatusOr<Format *> AddFormat(std::string name, int width, - std::string parent_name); + absl::StatusOr<Format*> AddFormat(std::string name, int width, + std::string parent_name); // Returns the pointer to the format with the given name, or nullptr if it // hasn't been added. - Format *GetFormat(absl::string_view name) const; + Format* GetFormat(absl::string_view name) const; // Add the instruction group declaration. - absl::StatusOr<InstructionGroup *> AddInstructionGroup( + absl::StatusOr<InstructionGroup*> AddInstructionGroup( std::string name, int width, std::string format_name); // Propagates bitfield extractors where possible. void PropagateExtractors(); // Create and add binary decoder descriptor. - BinDecoder *AddBinDecoder(std::string name); + BinDecoder* AddBinDecoder(std::string name); // Accessors. - const FormatMap &format_map() const { return format_map_; } - const InstructionGroupMap &instruction_group_map() const { + const FormatMap& format_map() const { return format_map_; } + const InstructionGroupMap& instruction_group_map() const { return instruction_group_map_; } - DecoderErrorListener *error_listener() const { return error_listener_; } - const absl::btree_set<std::string> &include_files() const { + DecoderErrorListener* error_listener() const { return error_listener_; } + const absl::btree_set<std::string>& include_files() const { return include_files_; } - BinDecoder *decoder() const { return decoder_; } + BinDecoder* decoder() const { return decoder_; } std::string opcode_enum() const { return opcode_enum_; } private: std::string opcode_enum_; // The error listener is passed from the parse tree visitor. It is used to // report semantic errors found during later checks. - DecoderErrorListener *error_listener_; + DecoderErrorListener* error_listener_; FormatMap format_map_; InstructionGroupMap instruction_group_map_; // Include files. absl::btree_set<std::string> include_files_; - BinDecoder *decoder_ = nullptr; + BinDecoder* decoder_ = nullptr; }; } // namespace bin_format
diff --git a/mpact/sim/decoder/bin_format_gen_main.cc b/mpact/sim/decoder/bin_format_gen_main.cc index e2107f3..782abdb 100644 --- a/mpact/sim/decoder/bin_format_gen_main.cc +++ b/mpact/sim/decoder/bin_format_gen_main.cc
@@ -36,7 +36,7 @@ ABSL_FLAG(std::string, decoder_name, "", "decoder name to generate"); ABSL_FLAG(std::string, include, "", "include file root(s)"); -int main(int argc, char **argv) { +int main(int argc, char** argv) { auto arg_vec = absl::ParseCommandLine(argc, argv); std::vector<std::string> file_names;
diff --git a/mpact/sim/decoder/bin_format_visitor.cc b/mpact/sim/decoder/bin_format_visitor.cc index 75e5477..2d8fc8a 100644 --- a/mpact/sim/decoder/bin_format_visitor.cc +++ b/mpact/sim/decoder/bin_format_visitor.cc
@@ -131,7 +131,7 @@ } BinFormatVisitor::~BinFormatVisitor() { - for (auto *wrapper : antlr_parser_wrappers_) { + for (auto* wrapper : antlr_parser_wrappers_) { delete wrapper; } antlr_parser_wrappers_.clear(); @@ -140,17 +140,17 @@ using ::mpact::sim::machine_description::instruction_set::ToHeaderGuard; absl::Status BinFormatVisitor::Process( - const std::vector<std::string> &file_names, const std::string &decoder_name, - absl::string_view prefix, const std::vector<std::string> &include_roots, + const std::vector<std::string>& file_names, const std::string& decoder_name, + absl::string_view prefix, const std::vector<std::string>& include_roots, absl::string_view directory) { decoder_name_ = decoder_name; include_dir_vec_.push_back("."); - for (const auto &root : include_roots) { + for (const auto& root : include_roots) { include_dir_vec_.push_back(root); } - std::istream *source_stream = &std::cin; + std::istream* source_stream = &std::cin; if (!file_names.empty()) { source_stream = new std::fstream(file_names[0], std::fstream::in); @@ -166,7 +166,7 @@ parser_wrapper.parser()->addErrorListener(error_listener()); // Parse the file and then create the data structures. - TopLevelCtx *top_level = parser_wrapper.parser()->top_level(); + TopLevelCtx* top_level = parser_wrapper.parser()->top_level(); (void)top_level; if (!file_names.empty()) { delete source_stream; @@ -247,13 +247,13 @@ return absl::OkStatus(); } -void BinFormatVisitor::PerformEncodingChecks(BinEncodingInfo *encoding) { +void BinFormatVisitor::PerformEncodingChecks(BinEncodingInfo* encoding) { encoding->decoder()->CheckEncodings(); } BinFormatVisitor::StringTriple BinFormatVisitor::EmitDecoderFilePrefix( - const std::string &dot_h_name, const std::string &types_dot_h_name, - BinEncodingInfo *encoding_info) const { + const std::string& dot_h_name, const std::string& types_dot_h_name, + BinEncodingInfo* encoding_info) const { std::string h_string; std::string cc_string; std::string types_string; @@ -284,7 +284,7 @@ "#include <iostream>\n" "#include <cstdint>\n" "\n"); - for (auto const &include_file : encoding_info->include_files()) { + for (auto const& include_file : encoding_info->include_files()) { absl::StrAppend(&h_string, "#include ", include_file, "\n"); } absl::StrAppend(&h_string, "\n"); @@ -292,7 +292,7 @@ "\"\n" "#include \"", types_dot_h_name, "\"\n\n"); - for (auto &name_space : encoding_info->decoder()->namespaces()) { + for (auto& name_space : encoding_info->decoder()->namespaces()) { auto name_space_str = absl::StrCat("namespace ", name_space, " {\n"); absl::StrAppend(&h_string, name_space_str); absl::StrAppend(&cc_string, name_space_str); @@ -308,7 +308,7 @@ "enum class FormatEnum {\n" " kNone = 0,\n"); int i = 1; - for (auto &[name, unused] : encoding_info->format_map()) { + for (auto& [name, unused] : encoding_info->format_map()) { absl::StrAppend(&h_string, " k", ToPascalCase(name), " = ", i++, ",\n"); } absl::StrAppend(&h_string, "};\n\n"); @@ -316,8 +316,8 @@ } BinFormatVisitor::StringTriple BinFormatVisitor::EmitFileSuffix( - const std::string &dot_h_name, const std::string &types_dot_h_name, - BinEncodingInfo *encoding_info) { + const std::string& dot_h_name, const std::string& types_dot_h_name, + BinEncodingInfo* encoding_info) { std::string h_string; std::string cc_string; std::string types_string; @@ -325,7 +325,7 @@ absl::StrAppend(&h_string, "\n"); absl::StrAppend(&cc_string, "\n"); if (!types_dot_h_name.empty()) absl::StrAppend(&types_string, "\n"); - auto &namespaces = encoding_info->decoder()->namespaces(); + auto& namespaces = encoding_info->decoder()->namespaces(); for (auto rptr = namespaces.rbegin(); rptr != namespaces.rend(); rptr++) { std::string name_space = absl::StrCat("} // namespace ", *rptr, "\n"); absl::StrAppend(&h_string, name_space); @@ -342,7 +342,7 @@ } BinFormatVisitor::StringTriple BinFormatVisitor::EmitDecoderCode( - BinEncodingInfo *encoding) { + BinEncodingInfo* encoding) { std::string h_string; std::string cc_string; std::string group_string; @@ -350,16 +350,16 @@ std::string extractor_class = absl::StrCat("class Extractors {\n", "public: \n"); // Write out the inline functions for bitfield and overlay extractions. - for (auto &[unused, format_ptr] : encoding->format_map()) { + for (auto& [unused, format_ptr] : encoding->format_map()) { auto extractors = format_ptr->GenerateExtractors(); absl::StrAppend(&h_string, extractors.h_output); absl::StrAppend(&extractor_class, extractors.class_output); absl::StrAppend(&extractor_types, extractors.types_output); } absl::StrAppend(&h_string, extractor_class, "};\n\n"); - auto *decoder = encoding->decoder(); + auto* decoder = encoding->decoder(); // Generate the code for decoders. - for (auto *group : decoder->instruction_group_vec()) { + for (auto* group : decoder->instruction_group_vec()) { auto [h_decoder, cc_decoder] = group->EmitDecoderCode(); absl::StrAppend(&h_string, h_decoder); absl::StrAppend(&cc_string, cc_decoder); @@ -372,8 +372,8 @@ } std::tuple<std::string, std::string> BinFormatVisitor::EmitEncoderFilePrefix( - const std::string &dot_h_name, const std::string &enum_h_name, - const std::string &types_dot_h_name, BinEncodingInfo *encoding_info) const { + const std::string& dot_h_name, const std::string& enum_h_name, + const std::string& types_dot_h_name, BinEncodingInfo* encoding_info) const { std::string h_string; std::string cc_string; @@ -404,7 +404,7 @@ "\"\n" "#include \"", types_dot_h_name, "\"\n\n"); - for (auto &name_space : encoding_info->decoder()->namespaces()) { + for (auto& name_space : encoding_info->decoder()->namespaces()) { auto name_space_str = absl::StrCat("namespace ", name_space, " {\n"); absl::StrAppend(&cc_string, name_space_str); absl::StrAppend(&h_string, name_space_str); @@ -416,21 +416,21 @@ } std::tuple<std::string, std::string> BinFormatVisitor::EmitEncoderCode( - BinEncodingInfo *encoding) { + BinEncodingInfo* encoding) { std::string h_string; std::string cc_string; // Write out the inline functions for bitfield and overlay encoding. absl::StrAppend(&h_string, "struct Encoder {\n\n"); - for (auto &[unused, format_ptr] : encoding->format_map()) { + for (auto& [unused, format_ptr] : encoding->format_map()) { auto functions = format_ptr->GenerateInserters(); absl::StrAppend(&h_string, functions); } absl::StrAppend(&h_string, "}; // struct Encoder\n\n"); absl::flat_hash_set<std::string> groups; - auto *decoder = encoding->decoder(); + auto* decoder = encoding->decoder(); // Generate the code for decoders. absl::btree_map<std::string, std::tuple<uint64_t, int>> encodings; - for (auto *group : decoder->instruction_group_vec()) { + for (auto* group : decoder->instruction_group_vec()) { group->GetInstructionEncodings(encodings); } std::string opcode_enum = encoding->opcode_enum(); @@ -441,7 +441,7 @@ opcode_enum, ", std::tuple<uint64_t, int>>> kOpcodeEncodings({\n"); absl::StrAppend(&cc_string, " {", opcode_enum, "::kNone, {0x0ULL, 0}},\n"); - for (auto &[name, pair] : encodings) { + for (auto& [name, pair] : encodings) { auto [value, width] = pair; std::string enum_name = absl::StrCat(opcode_enum, "::k", ToPascalCase(name)); @@ -453,7 +453,7 @@ } // Parse the range and convert to a BitRange. -BitRange BinFormatVisitor::GetBitIndexRange(BitIndexRangeCtx *ctx) { +BitRange BinFormatVisitor::GetBitIndexRange(BitIndexRangeCtx* ctx) { int start = ConvertToInt(ctx->number(0)); int stop = start; if (ctx->number().size() == 2) { @@ -464,7 +464,7 @@ // Parse a binary number string such as 0b1010'0111 and return a BinaryNum // to encode the value and width. -BinaryNum BinFormatVisitor::ParseBinaryNum(TerminalNode *node) { +BinaryNum BinFormatVisitor::ParseBinaryNum(TerminalNode* node) { std::string bin_str = node->getText(); if (bin_str.substr(0, 2) != "0b") { error_listener_->semanticError(node->getSymbol(), @@ -489,7 +489,7 @@ } // Parse a number string and return the value. -int BinFormatVisitor::ConvertToInt(NumberCtx *ctx) { +int BinFormatVisitor::ConvertToInt(NumberCtx* ctx) { // Binary has to be handled separately. auto bin_number = ctx->BIN_NUMBER(); if (bin_number != nullptr) { @@ -501,7 +501,7 @@ } std::unique_ptr<BinEncodingInfo> BinFormatVisitor::ProcessTopLevel( - const std::string &decoder_name) { + const std::string& decoder_name) { // At this point we have the contexts for all slots, bundles and isas. // First make sure the named isa (decoder) has been defined. auto decoder_iter = decoder_decl_map_.find(decoder_name); @@ -517,10 +517,10 @@ // will have been visited. Build a multi-map from referenced format to parent // format. absl::btree_multimap<std::string, std::string> reference_map; - for (auto &[format_name, ctx_ptr] : format_decl_map_) { + for (auto& [format_name, ctx_ptr] : format_decl_map_) { // Skip those that have already been visited. if (bin_encoding_info->GetFormat(format_name) != nullptr) continue; - for (auto *field_ctx : ctx_ptr->format_field_defs()->field_def()) { + for (auto* field_ctx : ctx_ptr->format_field_defs()->field_def()) { if (field_ctx->format_name != nullptr) { reference_map.emplace(field_ctx->format_name->getText(), format_name); } @@ -528,12 +528,12 @@ } // Now, starting at each visited format, traverse links in the reference_map // to transitively visit any "parent" formats. - std::list<Format *> format_list; - for (auto &[unused, fmt_ptr] : bin_encoding_info->format_map()) { + std::list<Format*> format_list; + for (auto& [unused, fmt_ptr] : bin_encoding_info->format_map()) { format_list.push_back(fmt_ptr); } while (!format_list.empty()) { - auto *format = format_list.front(); + auto* format = format_list.front(); format_list.pop_front(); for (auto iter = reference_map.lower_bound(format->name()); iter != reference_map.upper_bound(format->name()); iter++) { @@ -547,10 +547,10 @@ return bin_encoding_info; } -void BinFormatVisitor::PreProcessDeclarations(DeclarationListCtx *ctx) { - std::vector<IncludeFileCtx *> include_files; +void BinFormatVisitor::PreProcessDeclarations(DeclarationListCtx* ctx) { + std::vector<IncludeFileCtx*> include_files; - for (auto *declaration : ctx->declaration()) { + for (auto* declaration : ctx->declaration()) { context_file_map_.insert({declaration, current_file_index_}); // Create map from format name to format ctx. if (declaration->format_def() != nullptr) { @@ -589,7 +589,7 @@ include_files.push_back(declaration->include_file()); } // Create map from decoder name to decoder ctx. - for (auto *decoder_def : ctx->decoder_def()) { + for (auto* decoder_def : ctx->decoder_def()) { context_file_map_.insert({decoder_def, current_file_index_}); auto name = decoder_def->name->getText(); auto iter = decoder_decl_map_.find(name); @@ -602,18 +602,18 @@ } decoder_decl_map_.emplace(name, decoder_def); } - for (auto *include_file_ctx : include_files) { + for (auto* include_file_ctx : include_files) { VisitIncludeFile(include_file_ctx); } } -void BinFormatVisitor::VisitIncludeFile(IncludeFileCtx *ctx) { +void BinFormatVisitor::VisitIncludeFile(IncludeFileCtx* ctx) { // The literal includes the double quotes. std::string literal = ctx->STRING_LITERAL()->getText(); // Remove the double quotes from the literal and construct the full file name. std::string file_name = literal.substr(1, literal.length() - 2); // Check for recursive include. - for (auto const &name : include_file_stack_) { + for (auto const& name : include_file_stack_) { if (name == file_name) { error_listener()->semanticError( ctx->start, absl::StrCat("Recursive include of '", file_name, "'")); @@ -623,14 +623,14 @@ ParseIncludeFile(ctx, file_name, include_dir_vec_); } -void BinFormatVisitor::ParseIncludeFile(antlr4::ParserRuleContext *ctx, - const std::string &file_name, - std::vector<std::string> const &dirs) { +void BinFormatVisitor::ParseIncludeFile(antlr4::ParserRuleContext* ctx, + const std::string& file_name, + std::vector<std::string> const& dirs) { std::fstream include_file; // Open include file. // Try each of the include file directories. std::string include_name; - for (auto const &dir : dirs) { + for (auto const& dir : dirs) { include_name = absl::StrCat(dir, "/", file_name); include_file.open(include_name, std::fstream::in); if (include_file.is_open()) break; @@ -656,16 +656,16 @@ error_listener()->set_file_name(file_name); file_names_.push_back(file_name); current_file_index_ = file_names_.size() - 1; - auto *include_parser = new BinFmtAntlrParserWrapper(&include_file); + auto* include_parser = new BinFmtAntlrParserWrapper(&include_file); // We need to save the parser state so it's available for analysis after // we are done with building the parse trees. antlr_parser_wrappers_.push_back(include_parser); // Add the error listener. include_parser->parser()->removeErrorListeners(); include_parser->parser()->addErrorListener(error_listener()); - auto *top_level = include_parser->parser()->top_level(); + auto* top_level = include_parser->parser()->top_level(); // Start parsing at the declaratition_list rule. - DeclarationListCtx *declaration_list = top_level->declaration_list(); + DeclarationListCtx* declaration_list = top_level->declaration_list(); include_file.close(); if (error_listener()->syntax_error_count() > 0) { error_listener()->set_file_name(previous_file_name); @@ -675,7 +675,7 @@ include_file_stack_.push_back(file_name); PreProcessDeclarations(declaration_list); // See if there is a once declaration in the file. - OnceCtx *once_ctx = top_level->once(); + OnceCtx* once_ctx = top_level->once(); if (once_ctx != nullptr) { once_include_files_.insert(include_name); } @@ -684,8 +684,8 @@ current_file_index_ = previous_file_index_; } -void BinFormatVisitor::VisitFormatDef(FormatDefCtx *ctx, - BinEncodingInfo *encoding_info) { +void BinFormatVisitor::VisitFormatDef(FormatDefCtx* ctx, + BinEncodingInfo* encoding_info) { if (ctx == nullptr) return; // Get the format name and width. std::string format_name = ctx->IDENT()->getText(); @@ -703,10 +703,10 @@ "': must specify a width or inherited format")); return; } - absl::StatusOr<Format *> format_res; + absl::StatusOr<Format*> format_res; if (ctx->inherits_from() != nullptr) { std::string parent_name = ctx->inherits_from()->IDENT()->getText(); - auto *parent_format = encoding_info->GetFormat(parent_name); + auto* parent_format = encoding_info->GetFormat(parent_name); if (parent_format == nullptr) { auto iter = format_decl_map_.find(parent_name); if (iter != format_decl_map_.end()) { @@ -767,8 +767,8 @@ } } -void BinFormatVisitor::VisitFieldDef(FieldDefCtx *ctx, Format *format, - BinEncodingInfo *encoding_info) { +void BinFormatVisitor::VisitFieldDef(FieldDefCtx* ctx, Format* format, + BinEncodingInfo* encoding_info) { if (ctx == nullptr) return; std::string field_name(ctx->field_name->getText()); @@ -804,7 +804,7 @@ } std::string format_ref_name = ctx->format_name->getText(); // Make sure that the referred to format is fully parsed. - auto *format_ref = encoding_info->GetFormat(format_ref_name); + auto* format_ref = encoding_info->GetFormat(format_ref_name); if (format_ref == nullptr) { auto iter = format_decl_map_.find(format_ref_name); if (iter != format_decl_map_.end()) { @@ -823,7 +823,7 @@ ctx->start); } -void BinFormatVisitor::VisitOverlayDef(OverlayDefCtx *ctx, Format *format) { +void BinFormatVisitor::VisitOverlayDef(OverlayDefCtx* ctx, Format* format) { if (ctx == nullptr) return; std::string name(ctx->IDENT()->getText()); @@ -843,9 +843,9 @@ ctx->start, overlay_res.status().message()); return; } - auto *overlay = overlay_res.value(); + auto* overlay = overlay_res.value(); int file_index = context_file_map_.at(ctx); - for (auto *bit_field : ctx->bit_field_list()->bit_field_spec()) { + for (auto* bit_field : ctx->bit_field_list()->bit_field_spec()) { context_file_map_.insert({bit_field, file_index}); VisitOverlayBitField(bit_field, overlay); } @@ -858,15 +858,15 @@ } } -void BinFormatVisitor::VisitOverlayBitField(BitFieldCtx *ctx, - Overlay *overlay) { +void BinFormatVisitor::VisitOverlayBitField(BitFieldCtx* ctx, + Overlay* overlay) { if (ctx == nullptr) return; if (ctx->IDENT() != nullptr) { // This is a reference to a bit field in the format. if (ctx->bit_range_list() != nullptr) { std::vector<BitRange> bit_ranges_; - for (auto *range : ctx->bit_range_list()->bit_index_range()) { + for (auto* range : ctx->bit_range_list()->bit_index_range()) { bit_ranges_.push_back(GetBitIndexRange(range)); } auto status = overlay->AddFieldReference(ctx->IDENT()->getText(), @@ -887,7 +887,7 @@ // Is this a reference to the format itself? if (ctx->bit_range_list() != nullptr) { std::vector<BitRange> bit_ranges_; - for (auto *range : ctx->bit_range_list()->bit_index_range()) { + for (auto* range : ctx->bit_range_list()->bit_index_range()) { bit_ranges_.push_back(GetBitIndexRange(range)); } auto status = overlay->AddFormatReference(std::move(bit_ranges_)); @@ -903,8 +903,8 @@ overlay->AddBitConstant(bin_num); } -InstructionGroup *BinFormatVisitor::VisitInstructionGroupDef( - InstructionGroupDefCtx *ctx, BinEncodingInfo *encoding_info) { +InstructionGroup* BinFormatVisitor::VisitInstructionGroupDef( + InstructionGroupDefCtx* ctx, BinEncodingInfo* encoding_info) { if (ctx == nullptr) return nullptr; // Create the named instruction group. @@ -929,7 +929,7 @@ return nullptr; } else { VisitFormatDef(iter->second, encoding_info); - auto *format = encoding_info->GetFormat(format_name); + auto* format = encoding_info->GetFormat(format_name); // Verify that the format width = declared width and also <= 64 bits wide. if (format->declared_width() != width) { error_listener_->semanticError( @@ -958,9 +958,9 @@ return nullptr; } // Parse the instruction encoding definitions in the instruction group. - auto *inst_group = inst_group_res.value(); + auto* inst_group = inst_group_res.value(); int file_index = context_file_map_.at(ctx); - for (auto *inst_def : ctx->instruction_def_list()->instruction_def()) { + for (auto* inst_def : ctx->instruction_def_list()->instruction_def()) { context_file_map_.insert({inst_def, file_index}); VisitInstructionDef(inst_def, inst_group); } @@ -974,8 +974,8 @@ group_name_set, encoding_info); } -void BinFormatVisitor::VisitInstructionDef(InstructionDefCtx *ctx, - InstructionGroup *inst_group) { +void BinFormatVisitor::VisitInstructionDef(InstructionDefCtx* ctx, + InstructionGroup* inst_group) { if (ctx == nullptr) return; // If it is a generator, process it. if (ctx->generate != nullptr) { @@ -1015,30 +1015,30 @@ ") differs from the declared width of the instruction group (", inst_group->width(), ")")); } - auto *inst_encoding = + auto* inst_encoding = inst_group->AddInstructionEncoding(ctx->format_name, name, format); if (format == nullptr) return; // Add constraints to the instruction encoding. - for (auto *constraint : ctx->field_constraint_list()->field_constraint()) { + for (auto* constraint : ctx->field_constraint_list()->field_constraint()) { context_file_map_.insert({constraint, file_index}); VisitConstraint(format, constraint, inst_encoding); } } void BinFormatVisitor::ProcessInstructionDefGenerator( - InstructionDefCtx *ctx, InstructionGroup *inst_group) { + InstructionDefCtx* ctx, InstructionGroup* inst_group) { if (ctx == nullptr) return; absl::flat_hash_set<std::string> range_variable_names; - std::vector<RangeAssignmentInfo *> range_info_vec; + std::vector<RangeAssignmentInfo*> range_info_vec; // Process range assignment lists. The range assignment is either a single // value or a structured binding assignment. If it's a binding assignment we // need to make sure each tuple has the same number of values as there are // idents to assign them to. int file_index = context_file_map_.at(ctx); - for (auto *assign_ctx : ctx->range_assignment()) { - auto *range_info = new RangeAssignmentInfo(); + for (auto* assign_ctx : ctx->range_assignment()) { + auto* range_info = new RangeAssignmentInfo(); range_info_vec.push_back(range_info); - for (auto *ident_ctx : assign_ctx->IDENT()) { + for (auto* ident_ctx : assign_ctx->IDENT()) { std::string name = ident_ctx->getText(); if (range_variable_names.contains(name)) { error_listener()->semanticError( @@ -1061,7 +1061,7 @@ } // See if it's a list of simple values. if (!assign_ctx->gen_value().empty()) { - for (auto *gen_value_ctx : assign_ctx->gen_value()) { + for (auto* gen_value_ctx : assign_ctx->gen_value()) { if (gen_value_ctx->IDENT() != nullptr) { range_info->range_values[0].push_back( gen_value_ctx->IDENT()->getText()); @@ -1078,10 +1078,10 @@ continue; } // It's a list of tuples with a structured binding assignment. - for (auto *tuple_ctx : assign_ctx->tuple()) { + for (auto* tuple_ctx : assign_ctx->tuple()) { if (tuple_ctx->gen_value().size() != range_info->range_names.size()) { // Clean up. - for (auto *info : range_info_vec) delete info; + for (auto* info : range_info_vec) delete info; error_listener_->semanticError( file_names_[file_index], assign_ctx->start, "Number of values differs from number of identifiers"); @@ -1123,7 +1123,7 @@ } if (error_listener()->HasError()) { // Clean up. - for (auto *info : range_info_vec) delete info; + for (auto* info : range_info_vec) delete info; return; } @@ -1132,23 +1132,23 @@ std::string generated_text = GenerateInstructionDefList(range_info_vec, 0, input_text); // Parse and process the generated text. - auto *parser = new BinFmtAntlrParserWrapper(generated_text); + auto* parser = new BinFmtAntlrParserWrapper(generated_text); antlr_parser_wrappers_.push_back(parser); // Parse the text starting at the opcode_spec_list rule. auto instruction_defs = parser->parser()->instruction_def_list()->instruction_def(); // Process the opcode spec. - for (auto *inst_def : instruction_defs) { + for (auto* inst_def : instruction_defs) { context_file_map_.insert({inst_def, file_index}); VisitInstructionDef(inst_def, inst_group); } // Clean up. - for (auto *info : range_info_vec) delete info; + for (auto* info : range_info_vec) delete info; } std::string BinFormatVisitor::GenerateInstructionDefList( - const std::vector<RangeAssignmentInfo *> &range_info_vec, int index, - const std::string &template_str_in) const { + const std::vector<RangeAssignmentInfo*>& range_info_vec, int index, + const std::string& template_str_in) const { std::string generated; // Iterate for the number of values. for (int i = 0; i < range_info_vec[index]->range_values[0].size(); ++i) { @@ -1158,7 +1158,7 @@ // current set of values. int var_index = 0; int replace_count = 0; - for (auto &re : range_info_vec[index]->range_regexes) { + for (auto& re : range_info_vec[index]->range_regexes) { replace_count += RE2::GlobalReplace( &template_str, re, range_info_vec[index]->range_values[var_index++][i]); @@ -1181,8 +1181,8 @@ return generated; } -void BinFormatVisitor::VisitConstraint(Format *format, FieldConstraintCtx *ctx, - InstructionEncoding *inst_encoding) { +void BinFormatVisitor::VisitConstraint(Format* format, FieldConstraintCtx* ctx, + InstructionEncoding* inst_encoding) { if (ctx == nullptr) return; if (inst_encoding == nullptr) return; @@ -1200,8 +1200,8 @@ // field width. if (ctx->number()->BIN_NUMBER() != nullptr) { int length = ParseBinaryNum(ctx->number()->BIN_NUMBER()).width; - auto *field = format->GetField(field_name); - auto *overlay = format->GetOverlay(field_name); + auto* field = format->GetField(field_name); + auto* overlay = format->GetOverlay(field_name); if (field != nullptr) { if (field->width != length) { error_listener_->semanticWarning( @@ -1234,14 +1234,14 @@ } std::unique_ptr<BinEncodingInfo> BinFormatVisitor::VisitDecoderDef( - DecoderDefCtx *ctx) { + DecoderDefCtx* ctx) { if (ctx == nullptr) return nullptr; std::string name = ctx->name->getText(); // First get the opcode enum. int opcode_count = 0; std::string opcode_enum; - for (auto *attr_ctx : ctx->decoder_attribute()) { + for (auto* attr_ctx : ctx->decoder_attribute()) { if (attr_ctx->opcode_enum_decl() != nullptr) { auto opcode_enum_literal = attr_ctx->opcode_enum_decl()->STRING_LITERAL()->getText(); @@ -1262,14 +1262,14 @@ } auto encoding_info = std::make_unique<BinEncodingInfo>(opcode_enum, error_listener_.get()); - auto *decoder = encoding_info->AddBinDecoder(name); + auto* decoder = encoding_info->AddBinDecoder(name); if (decoder == nullptr) return nullptr; absl::flat_hash_set<std::string> group_name_set; int namespace_count = 0; - for (auto *attr_ctx : ctx->decoder_attribute()) { + for (auto* attr_ctx : ctx->decoder_attribute()) { // Include files. if (attr_ctx->include_files() != nullptr) { - for (auto *include_file : attr_ctx->include_files()->include_file()) { + for (auto* include_file : attr_ctx->include_files()->include_file()) { auto include_text = include_file->STRING_LITERAL()->getText(); encoding_info->AddIncludeFile(include_text); } @@ -1278,7 +1278,7 @@ // Namespace declaration. if (attr_ctx->namespace_decl() != nullptr) { auto decl = attr_ctx->namespace_decl(); - for (auto *namespace_name : decl->namespace_ident()) { + for (auto* namespace_name : decl->namespace_ident()) { decoder->namespaces().push_back(namespace_name->getText()); } if (namespace_count > 0) { @@ -1304,7 +1304,7 @@ } auto map_iter = encoding_info->instruction_group_map().find(group_name); - InstructionGroup *inst_group = nullptr; + InstructionGroup* inst_group = nullptr; if (map_iter != encoding_info->instruction_group_map().end()) { inst_group = map_iter->second; } else { @@ -1338,7 +1338,7 @@ auto file_index = context_file_map_.at(ctx); context_file_map_.insert( {attr_ctx->group_name()->group_name_list(), file_index}); - auto *parent_group = VisitInstructionGroupNameList( + auto* parent_group = VisitInstructionGroupNameList( group_name, attr_ctx->group_name()->group_name_list(), group_name_set, encoding_info.get()); if (parent_group == nullptr) { @@ -1356,14 +1356,14 @@ return encoding_info; } -InstructionGroup *BinFormatVisitor::VisitInstructionGroupNameList( - const std::string &group_name, GroupNameListCtx *ctx, - absl::flat_hash_set<std::string> &group_name_set, - BinEncodingInfo *encoding_info) { - std::vector<InstructionGroup *> child_groups; +InstructionGroup* BinFormatVisitor::VisitInstructionGroupNameList( + const std::string& group_name, GroupNameListCtx* ctx, + absl::flat_hash_set<std::string>& group_name_set, + BinEncodingInfo* encoding_info) { + std::vector<InstructionGroup*> child_groups; std::string group_format_name; // Iterate through the list of named "child" groups to combine. - for (auto *ident : ctx->IDENT()) { + for (auto* ident : ctx->IDENT()) { auto child_name = ident->getText(); if (group_name_set.contains(child_name)) { error_listener_->semanticError( @@ -1372,7 +1372,7 @@ "' - ignored")); continue; } - InstructionGroup *child_group = nullptr; + InstructionGroup* child_group = nullptr; auto map_iter = encoding_info->instruction_group_map().find(child_name); if (map_iter != encoding_info->instruction_group_map().end()) { child_group = map_iter->second; @@ -1420,26 +1420,26 @@ return nullptr; } auto parent_group = res.value(); - for (auto *child_group : child_groups) { - for (auto *encoding : child_group->encoding_vec()) { + for (auto* child_group : child_groups) { + for (auto* encoding : child_group->encoding_vec()) { parent_group->AddInstructionEncoding(new InstructionEncoding(*encoding)); } } return parent_group; } -void BinFormatVisitor::ProcessSpecializations(BinEncodingInfo *encoding_info) { - for (auto *ctx : specializations_) { +void BinFormatVisitor::ProcessSpecializations(BinEncodingInfo* encoding_info) { + for (auto* ctx : specializations_) { auto file_index = context_file_map_.at(ctx); std::string name = ctx->name->getText(); std::string parent_name = ctx->parent->getText(); - for (auto &[unused, grp_ptr] : encoding_info->instruction_group_map()) { + for (auto& [unused, grp_ptr] : encoding_info->instruction_group_map()) { auto iter = grp_ptr->encoding_name_map().find(parent_name); if (iter != grp_ptr->encoding_name_map().end()) { - auto *parent_encoding = iter->second; - auto *format = parent_encoding->format(); - auto *inst_encoding = new InstructionEncoding(name, format); - for (auto *constraint : + auto* parent_encoding = iter->second; + auto* format = parent_encoding->format(); + auto* inst_encoding = new InstructionEncoding(name, format); + for (auto* constraint : ctx->field_constraint_list()->field_constraint()) { context_file_map_.insert({constraint, file_index}); VisitConstraint(format, constraint, inst_encoding);
diff --git a/mpact/sim/decoder/bin_format_visitor.h b/mpact/sim/decoder/bin_format_visitor.h index b824b34..e1ba70f 100644 --- a/mpact/sim/decoder/bin_format_visitor.h +++ b/mpact/sim/decoder/bin_format_visitor.h
@@ -88,72 +88,72 @@ // Entry point for processing a source_stream input, generating any output // files in the given directory. Returns OK if no errors were encountered. - absl::Status Process(const std::vector<std::string> &file_names, - const std::string &decoder_name, + absl::Status Process(const std::vector<std::string>& file_names, + const std::string& decoder_name, absl::string_view prefix, - const std::vector<std::string> &include_roots, + const std::vector<std::string>& include_roots, absl::string_view directory); private: // Check the encodings to make sure there aren't any obvious errors. - void PerformEncodingChecks(BinEncodingInfo *encoding); + void PerformEncodingChecks(BinEncodingInfo* encoding); // Called to generate and emit code for the decoder according to the parsed // input file. - StringTriple EmitDecoderCode(BinEncodingInfo *encoding); - StringTriple EmitDecoderFilePrefix(const std::string &dot_h_name, - const std::string &types_dot_h_name, - BinEncodingInfo *encoding_info) const; + StringTriple EmitDecoderCode(BinEncodingInfo* encoding); + StringTriple EmitDecoderFilePrefix(const std::string& dot_h_name, + const std::string& types_dot_h_name, + BinEncodingInfo* encoding_info) const; // Called to generate and emit code for the decoder according to the parsed // input file. std::tuple<std::string, std::string> EmitEncoderCode( - BinEncodingInfo *encoding); + BinEncodingInfo* encoding); std::tuple<std::string, std::string> EmitEncoderFilePrefix( - const std::string &dot_h_name, const std::string &enum_h_name, - const std::string &types_dot_h_name, - BinEncodingInfo *encoding_info) const; + const std::string& dot_h_name, const std::string& enum_h_name, + const std::string& types_dot_h_name, + BinEncodingInfo* encoding_info) const; // Generate the file suffixes (namespace closing etc.) - StringTriple EmitFileSuffix(const std::string &dot_h_name, - const std::string &types_dot_h_name, - BinEncodingInfo *encoding_info); + StringTriple EmitFileSuffix(const std::string& dot_h_name, + const std::string& types_dot_h_name, + BinEncodingInfo* encoding_info); // Utility methods to parse certain nodes. - BinaryNum ParseBinaryNum(TerminalNode *node); - BitRange GetBitIndexRange(BitIndexRangeCtx *ctx); - int ConvertToInt(NumberCtx *ctx); + BinaryNum ParseBinaryNum(TerminalNode* node); + BitRange GetBitIndexRange(BitIndexRangeCtx* ctx); + int ConvertToInt(NumberCtx* ctx); // Methods that visit the nodes of the parse tree. std::unique_ptr<BinEncodingInfo> ProcessTopLevel( - const std::string &decoder_name); - void PreProcessDeclarations(DeclarationListCtx *ctx); - void VisitDeclarations(DeclarationListCtx *ctx, - BinEncodingInfo *encoding_info); - void VisitFormatDef(FormatDefCtx *ctx, BinEncodingInfo *encoding_info); - void VisitFieldDef(FieldDefCtx *ctx, Format *format, - BinEncodingInfo *encoding_info); - void VisitIncludeFile(IncludeFileCtx *ctx); - void ParseIncludeFile(antlr4::ParserRuleContext *ctx, - const std::string &file_name, - const std::vector<std::string> &dirs); - void VisitOverlayDef(OverlayDefCtx *ctx, Format *format); - void VisitOverlayBitField(BitFieldCtx *ctx, Overlay *overlay); - InstructionGroup *VisitInstructionGroupDef(InstructionGroupDefCtx *ctx, - BinEncodingInfo *encoding_info); - std::unique_ptr<BinEncodingInfo> VisitDecoderDef(DecoderDefCtx *ctx); - void VisitInstructionDef(InstructionDefCtx *ctx, - InstructionGroup *inst_group); - void ProcessInstructionDefGenerator(InstructionDefCtx *ctx, - InstructionGroup *inst_group); + const std::string& decoder_name); + void PreProcessDeclarations(DeclarationListCtx* ctx); + void VisitDeclarations(DeclarationListCtx* ctx, + BinEncodingInfo* encoding_info); + void VisitFormatDef(FormatDefCtx* ctx, BinEncodingInfo* encoding_info); + void VisitFieldDef(FieldDefCtx* ctx, Format* format, + BinEncodingInfo* encoding_info); + void VisitIncludeFile(IncludeFileCtx* ctx); + void ParseIncludeFile(antlr4::ParserRuleContext* ctx, + const std::string& file_name, + const std::vector<std::string>& dirs); + void VisitOverlayDef(OverlayDefCtx* ctx, Format* format); + void VisitOverlayBitField(BitFieldCtx* ctx, Overlay* overlay); + InstructionGroup* VisitInstructionGroupDef(InstructionGroupDefCtx* ctx, + BinEncodingInfo* encoding_info); + std::unique_ptr<BinEncodingInfo> VisitDecoderDef(DecoderDefCtx* ctx); + void VisitInstructionDef(InstructionDefCtx* ctx, + InstructionGroup* inst_group); + void ProcessInstructionDefGenerator(InstructionDefCtx* ctx, + InstructionGroup* inst_group); std::string GenerateInstructionDefList( - const std::vector<RangeAssignmentInfo *> &range_info_vec, int index, - const std::string &template_str_in) const; - void VisitConstraint(Format *format, FieldConstraintCtx *ctx, - InstructionEncoding *inst_encoding); - InstructionGroup *VisitInstructionGroupNameList( - const std::string &group_name, GroupNameListCtx *ctx, - absl::flat_hash_set<std::string> &group_name_set, - BinEncodingInfo *encoding_info); - void ProcessSpecializations(BinEncodingInfo *encoding_info); + const std::vector<RangeAssignmentInfo*>& range_info_vec, int index, + const std::string& template_str_in) const; + void VisitConstraint(Format* format, FieldConstraintCtx* ctx, + InstructionEncoding* inst_encoding); + InstructionGroup* VisitInstructionGroupNameList( + const std::string& group_name, GroupNameListCtx* ctx, + absl::flat_hash_set<std::string>& group_name_set, + BinEncodingInfo* encoding_info); + void ProcessSpecializations(BinEncodingInfo* encoding_info); // Accessors. - decoder::DecoderErrorListener *error_listener() const { + decoder::DecoderErrorListener* error_listener() const { return error_listener_.get(); } void set_error_listener( @@ -165,7 +165,7 @@ // Vector of file names. std::vector<std::string> file_names_; // Map from context pointer to file index. - absl::flat_hash_map<const antlr4::ParserRuleContext *, int> context_file_map_; + absl::flat_hash_map<const antlr4::ParserRuleContext*, int> context_file_map_; // This stores a vector of include file root directories. std::vector<std::string> include_dir_vec_; // Keep track of files that are included in case there is recursive includes. @@ -174,17 +174,17 @@ std::unique_ptr<decoder::DecoderErrorListener> error_listener_ = nullptr; std::string decoder_name_; // Maps from identifiers to declaration contexts. - absl::flat_hash_map<std::string, FormatDefCtx *> format_decl_map_; - absl::flat_hash_map<std::string, InstructionGroupDefCtx *> group_decl_map_; - absl::flat_hash_map<std::string, DecoderDefCtx *> decoder_decl_map_; + absl::flat_hash_map<std::string, FormatDefCtx*> format_decl_map_; + absl::flat_hash_map<std::string, InstructionGroupDefCtx*> group_decl_map_; + absl::flat_hash_map<std::string, DecoderDefCtx*> decoder_decl_map_; // AntlrParserWrapper vector. - std::vector<BinFmtAntlrParserWrapper *> antlr_parser_wrappers_; + std::vector<BinFmtAntlrParserWrapper*> antlr_parser_wrappers_; // Map from comparator string to constraint type. absl::flat_hash_map<std::string, ConstraintType> constraint_string_to_type_; // Set of include files marked as once. absl::flat_hash_set<std::string> once_include_files_; // Specializations to process after all instructions have been processed. - std::vector<InstructionDefCtx *> specializations_; + std::vector<InstructionDefCtx*> specializations_; }; } // namespace bin_format
diff --git a/mpact/sim/decoder/bundle.cc b/mpact/sim/decoder/bundle.cc index 5d7f484..dc6ef5d 100644 --- a/mpact/sim/decoder/bundle.cc +++ b/mpact/sim/decoder/bundle.cc
@@ -29,8 +29,8 @@ namespace machine_description { namespace instruction_set { -Bundle::Bundle(absl::string_view name, InstructionSet *instruction_set, - BundleDeclCtx *ctx) +Bundle::Bundle(absl::string_view name, InstructionSet* instruction_set, + BundleDeclCtx* ctx) : ctx_(ctx), instruction_set_(instruction_set), name_(name), @@ -42,7 +42,7 @@ } void Bundle::AppendSlot(absl::string_view name, - const std::vector<int> &instance_vec) { + const std::vector<int>& instance_vec) { slot_uses_.push_back({std::string(name), instance_vec}); } @@ -64,21 +64,21 @@ " *encoding);\n" " virtual SemFunc GetSemanticFunction() = 0;\n" "\n"); - for (const auto &bundle_name : bundle_names()) { + for (const auto& bundle_name : bundle_names()) { absl::StrAppend(&output, " ", ToPascalCase(bundle_name), "Decoder *", bundle_name, "_decoder() { return ", bundle_name, "_decoder_.get(); }\n"); } - for (const auto &[slot_name, unused] : slot_uses()) { + for (const auto& [slot_name, unused] : slot_uses()) { absl::StrAppend(&output, " ", ToPascalCase(slot_name), "Slot *", slot_name, "_decoder() { return ", slot_name, "_decoder_.get(); }\n"); } absl::StrAppend(&output, " private:\n"); - for (const auto &bundle_name : bundle_names()) { + for (const auto& bundle_name : bundle_names()) { absl::StrAppend(&output, " std::unique_ptr<", ToPascalCase(bundle_name), "Decoder> ", bundle_name, "_decoder_;\n"); } - for (const auto &[slot_name, unused] : slot_uses()) { + for (const auto& [slot_name, unused] : slot_uses()) { absl::StrAppend(&output, " std::unique_ptr<", ToPascalCase(slot_name), "Slot> ", slot_name, "_decoder_;\n"); } @@ -100,11 +100,11 @@ " arch_state_(arch_state)\n" "{\n"); - for (const auto &bundle_name : bundle_names()) { + for (const auto& bundle_name : bundle_names()) { absl::StrAppend(&output, " ", bundle_name, "_decoder = std::make_unique<", ToPascalCase(bundle_name), "Decoder>(arch_state_);\n"); } - for (const auto &[slot_name, unused] : slot_uses()) { + for (const auto& [slot_name, unused] : slot_uses()) { absl::StrAppend(&output, " ", slot_name, "_decoder = std::make_unique<", ToPascalCase(slot_name), "Slot>(arch_state_);\n"); } @@ -117,13 +117,13 @@ " Instruction *inst = new Instruction(address, arch_state_);\n" " Instruction *tmp_inst;\n"); // Decoded bundles are added to the child list. - for (const auto &bundle_name : bundle_names()) { + for (const auto& bundle_name : bundle_names()) { absl::StrAppend(&output, " tmp_inst = ", bundle_name, "_decoder_->Decode(address, encoding);\n" " inst->AppendChild(tmp_inst);\n"); } // Instructions for decoded slots are added to the "next" list. - for (const auto &[slot_name, instance_vec] : slot_uses()) { + for (const auto& [slot_name, instance_vec] : slot_uses()) { if (instance_vec.empty()) { absl::StrAppend(&output, " tmp_inst = ", slot_name, "_decoder_->Decode(address, encoding, 0);\n"
diff --git a/mpact/sim/decoder/bundle.h b/mpact/sim/decoder/bundle.h index 315cd42..2d8158d 100644 --- a/mpact/sim/decoder/bundle.h +++ b/mpact/sim/decoder/bundle.h
@@ -38,15 +38,15 @@ class Bundle { public: // Constructor and destructor. - Bundle(absl::string_view name, InstructionSet *instruction_set, - BundleDeclCtx *ctx); + Bundle(absl::string_view name, InstructionSet* instruction_set, + BundleDeclCtx* ctx); virtual ~Bundle() = default; // Append a slot to the bundle. In case the slot has multiple instances, // a non-empty vector of instance numbers specify which slot instances are // part of this bundle. void AppendSlot(absl::string_view slot_name, - const std::vector<int> &instance_vec); + const std::vector<int>& instance_vec); // Append a sub bundle to this bundle. void AppendBundleName(absl::string_view bundle_name); // Return string for bundle class declaration. @@ -55,15 +55,15 @@ std::string GenerateClassDefinition(absl::string_view encoding_type) const; // Getters and setters. - const BundleDeclCtx *ctx() const { return ctx_; } - const std::string &name() const { return name_; } - const std::string &pascal_name() const { return pascal_name_; } - const std::vector<std::pair<std::string, const std::vector<int>>> &slot_uses() + const BundleDeclCtx* ctx() const { return ctx_; } + const std::string& name() const { return name_; } + const std::string& pascal_name() const { return pascal_name_; } + const std::vector<std::pair<std::string, const std::vector<int>>>& slot_uses() const { return slot_uses_; } - const std::vector<std::string> &bundle_names() const { return bundle_names_; } - InstructionSet *instruction_set() const { return instruction_set_; } + const std::vector<std::string>& bundle_names() const { return bundle_names_; } + InstructionSet* instruction_set() const { return instruction_set_; } bool is_marked() const { return is_marked_; } void set_is_marked(bool value) { is_marked_ = value; } std::string semfunc_code_string() const { return semfunc_code_string_; } @@ -72,11 +72,11 @@ } private: - BundleDeclCtx *ctx_; + BundleDeclCtx* ctx_; // The is_marked flag is used to ensure bundle classes are only added once. bool is_marked_ = false; // Parent instruction set. - InstructionSet *instruction_set_; + InstructionSet* instruction_set_; std::string name_; // Name in PascalCase. std::string pascal_name_;
diff --git a/mpact/sim/decoder/decoder_error_listener.cc b/mpact/sim/decoder/decoder_error_listener.cc index 10335b3..1f4ece4 100644 --- a/mpact/sim/decoder/decoder_error_listener.cc +++ b/mpact/sim/decoder/decoder_error_listener.cc
@@ -27,18 +27,18 @@ namespace decoder { // Error listener methods. -void DecoderErrorListener::semanticError(antlr4::Token *token, +void DecoderErrorListener::semanticError(antlr4::Token* token, absl::string_view msg) { semanticError(file_name_, token, msg); } -void DecoderErrorListener::semanticWarning(antlr4::Token *token, +void DecoderErrorListener::semanticWarning(antlr4::Token* token, absl::string_view msg) { semanticWarning(file_name_, token, msg); } -void DecoderErrorListener::semanticError(const std::string &file_name, - antlr4::Token *token, +void DecoderErrorListener::semanticError(const std::string& file_name, + antlr4::Token* token, absl::string_view msg) { if (token != nullptr) { size_t line = token->getLine(); @@ -51,8 +51,8 @@ semantic_error_count_++; } -void DecoderErrorListener::semanticWarning(const std::string &file_name, - antlr4::Token *token, +void DecoderErrorListener::semanticWarning(const std::string& file_name, + antlr4::Token* token, absl::string_view msg) { if (token != nullptr) { size_t line = token->getLine(); @@ -65,35 +65,35 @@ semantic_warning_count_++; } -void DecoderErrorListener::syntaxError(antlr4::Recognizer *recognizer, - antlr4::Token *offendingSymbol, +void DecoderErrorListener::syntaxError(antlr4::Recognizer* recognizer, + antlr4::Token* offendingSymbol, size_t line, size_t charPositionInLine, - const std::string &msg, + const std::string& msg, std::exception_ptr e) { LOG(ERROR) << absl::StrCat(file_name_, ":", line, ":", charPositionInLine, "\n ", msg, "\n"); syntax_error_count_++; } -void DecoderErrorListener::reportAmbiguity(antlr4::Parser *recognizer, - const antlr4::dfa::DFA &dfa, +void DecoderErrorListener::reportAmbiguity(antlr4::Parser* recognizer, + const antlr4::dfa::DFA& dfa, size_t startIndex, size_t stopIndex, bool exact, - const antlrcpp::BitSet &ambigAlts, - antlr4::atn::ATNConfigSet *configs) { + const antlrcpp::BitSet& ambigAlts, + antlr4::atn::ATNConfigSet* configs) { // Empty. } void DecoderErrorListener::reportAttemptingFullContext( - antlr4::Parser *recognizer, const antlr4::dfa::DFA &dfa, size_t startIndex, - size_t stopIndex, const antlrcpp::BitSet &conflictingAlts, - antlr4::atn::ATNConfigSet *configs) { + antlr4::Parser* recognizer, const antlr4::dfa::DFA& dfa, size_t startIndex, + size_t stopIndex, const antlrcpp::BitSet& conflictingAlts, + antlr4::atn::ATNConfigSet* configs) { // Empty. } void DecoderErrorListener::reportContextSensitivity( - antlr4::Parser *recognizer, const antlr4::dfa::DFA &dfa, size_t startIndex, - size_t stopIndex, size_t prediction, antlr4::atn::ATNConfigSet *configs) { + antlr4::Parser* recognizer, const antlr4::dfa::DFA& dfa, size_t startIndex, + size_t stopIndex, size_t prediction, antlr4::atn::ATNConfigSet* configs) { // Empty. }
diff --git a/mpact/sim/decoder/decoder_error_listener.h b/mpact/sim/decoder/decoder_error_listener.h index 77eb3d8..004e46b 100644 --- a/mpact/sim/decoder/decoder_error_listener.h +++ b/mpact/sim/decoder/decoder_error_listener.h
@@ -32,29 +32,29 @@ // An Antlr4 error listener to check for syntax errors. class DecoderErrorListener : public antlr4::BaseErrorListener { public: - void semanticError(antlr4::Token *token, absl::string_view msg); - void semanticWarning(antlr4::Token *token, absl::string_view msg); - void semanticError(const std::string &file_name, antlr4::Token *token, + void semanticError(antlr4::Token* token, absl::string_view msg); + void semanticWarning(antlr4::Token* token, absl::string_view msg); + void semanticError(const std::string& file_name, antlr4::Token* token, absl::string_view msg); - void semanticWarning(const std::string &file_name, antlr4::Token *token, + void semanticWarning(const std::string& file_name, antlr4::Token* token, absl::string_view msg); - void syntaxError(antlr4::Recognizer *recognizer, - antlr4::Token *offendingSymbol, size_t line, - size_t charPositionInLine, const std::string &msg, + void syntaxError(antlr4::Recognizer* recognizer, + antlr4::Token* offendingSymbol, size_t line, + size_t charPositionInLine, const std::string& msg, std::exception_ptr e) override; - void reportAmbiguity(antlr4::Parser *recognizer, const antlr4::dfa::DFA &dfa, + void reportAmbiguity(antlr4::Parser* recognizer, const antlr4::dfa::DFA& dfa, size_t startIndex, size_t stopIndex, bool exact, - const antlrcpp::BitSet &ambigAlts, - antlr4::atn::ATNConfigSet *configs) override; - void reportAttemptingFullContext(antlr4::Parser *recognizer, - const antlr4::dfa::DFA &dfa, + const antlrcpp::BitSet& ambigAlts, + antlr4::atn::ATNConfigSet* configs) override; + void reportAttemptingFullContext(antlr4::Parser* recognizer, + const antlr4::dfa::DFA& dfa, size_t startIndex, size_t stopIndex, - const antlrcpp::BitSet &conflictingAlts, - antlr4::atn::ATNConfigSet *configs) override; - void reportContextSensitivity(antlr4::Parser *recognizer, - const antlr4::dfa::DFA &dfa, size_t startIndex, + const antlrcpp::BitSet& conflictingAlts, + antlr4::atn::ATNConfigSet* configs) override; + void reportContextSensitivity(antlr4::Parser* recognizer, + const antlr4::dfa::DFA& dfa, size_t startIndex, size_t stopIndex, size_t prediction, - antlr4::atn::ATNConfigSet *configs) override; + antlr4::atn::ATNConfigSet* configs) override; bool HasError() const { return (syntax_error_count_ + semantic_error_count_) > 0; @@ -63,7 +63,7 @@ int syntax_error_count() const { return syntax_error_count_; } int semantic_error_count() const { return semantic_error_count_; } // Current active file. - const std::string &file_name() const { return file_name_; } + const std::string& file_name() const { return file_name_; } void set_file_name(std::string file_name) { file_name_ = std::move(file_name); }
diff --git a/mpact/sim/decoder/decoder_gen_main.cc b/mpact/sim/decoder/decoder_gen_main.cc index 20cedba..4c28d3f 100644 --- a/mpact/sim/decoder/decoder_gen_main.cc +++ b/mpact/sim/decoder/decoder_gen_main.cc
@@ -54,7 +54,7 @@ ABSL_FLAG(std::string, isa_name, "", "isa name"); ABSL_FLAG(std::string, include, "", "include file directories"); -int main(int argc, char **argv) { +int main(int argc, char** argv) { auto arg_vec = absl::ParseCommandLine(argc, argv); std::vector<std::string> file_names;
diff --git a/mpact/sim/decoder/encoding_group.cc b/mpact/sim/decoder/encoding_group.cc index f722d84..33cd871 100644 --- a/mpact/sim/decoder/encoding_group.cc +++ b/mpact/sim/decoder/encoding_group.cc
@@ -41,7 +41,7 @@ using machine_description::instruction_set::ToPascalCase; // Indexed by the members of the ConstraintType enum in instruction_encoding.h. -const char *kComparison[] = { +const char* kComparison[] = { /* kEq */ "==", /* kNe */ "!=", /* kLt */ "<", @@ -52,22 +52,22 @@ // Helper function to provide a less than comparison of instruction encodings. // This is used in call to std::sort. -static bool EncodingLess(uint64_t mask, InstructionEncoding *lhs, - InstructionEncoding *rhs) { +static bool EncodingLess(uint64_t mask, InstructionEncoding* lhs, + InstructionEncoding* rhs) { uint64_t lhs_val = lhs->GetValue() & mask; uint64_t rhs_val = rhs->GetValue() & mask; return lhs_val < rhs_val; } -EncodingGroup::EncodingGroup(InstructionGroup *inst_group, uint64_t ignore) +EncodingGroup::EncodingGroup(InstructionGroup* inst_group, uint64_t ignore) : EncodingGroup(nullptr, inst_group, ignore) {} -EncodingGroup::EncodingGroup(EncodingGroup *parent, - InstructionGroup *inst_group, uint64_t ignore) +EncodingGroup::EncodingGroup(EncodingGroup* parent, + InstructionGroup* inst_group, uint64_t ignore) : inst_group_(inst_group), parent_(parent), ignore_(ignore) {} EncodingGroup::~EncodingGroup() { - for (auto *group : encoding_group_vec_) { + for (auto* group : encoding_group_vec_) { delete group; } encoding_group_vec_.clear(); @@ -87,7 +87,7 @@ } // Adds an instruction encoding to the encoding group. -void EncodingGroup::AddEncoding(InstructionEncoding *enc) { +void EncodingGroup::AddEncoding(InstructionEncoding* enc) { if (encoding_vec_.empty()) { last_value_ = enc->GetValue(); mask_ = enc->GetMask(); @@ -104,7 +104,7 @@ // Returns true if there is overlap between the encoding and those already // in the group. Returns false if it would clear the mask of common "fixed" // bits. -bool EncodingGroup::CanAddEncoding(InstructionEncoding *enc) { +bool EncodingGroup::CanAddEncoding(InstructionEncoding* enc) { if (encoding_vec_.empty()) return true; uint64_t new_mask = mask_ & enc->GetMask(); if (new_mask == 0) return false; @@ -115,7 +115,7 @@ // opposed to a function that performs comparisons. bool EncodingGroup::IsSimpleDecode() { if (!encoding_group_vec().empty()) return false; - for (auto *enc : encoding_vec_) { + for (auto* enc : encoding_vec_) { if (!enc->other_constraints().empty()) return false; if (!enc->equal_extracted_constraints().empty()) return false; if (!enc->HasSpecialization()) return false; @@ -150,9 +150,9 @@ // Iterate across the possible values of the compressed varying bits. for (int i = 0; i < (1 << absl::popcount(discriminator_)); i++) { // Create a new group for the current value 'i'. - auto *encoding_group = new EncodingGroup( + auto* encoding_group = new EncodingGroup( this, inst_group_, ignore_ | constant_ | discriminator_); - for (auto *enc : encoding_vec_) { + for (auto* enc : encoding_vec_) { // Add all encodings that have value 'i' for the varying bits. if (ExtractValue(enc->GetValue(), recipe) != static_cast<unsigned>(i)) continue; @@ -181,11 +181,11 @@ // But undo it if the max number of "varying" bits across the groups // is less than 2. int max = 0; - for (auto *group : encoding_group->encoding_group_vec_) { + for (auto* group : encoding_group->encoding_group_vec_) { max = std::max(max, absl::popcount(group->varying())); } if (max < 2) { - for (auto *group : encoding_group->encoding_group_vec_) { + for (auto* group : encoding_group->encoding_group_vec_) { delete group; } encoding_group->encoding_group_vec_.clear(); @@ -222,8 +222,8 @@ // The encodings are in order of discriminator value, so checking for // duplicates are easy. int prev_value = -1; - InstructionEncoding *prev_enc = nullptr; - for (auto *enc : encoding_vec_) { + InstructionEncoding* prev_enc = nullptr; + for (auto* enc : encoding_vec_) { int value = ExtractValue(enc->GetValue(), discriminator_recipe_); if (value == prev_value) { inst_group_->encoding_info()->error_listener()->semanticError( @@ -235,7 +235,7 @@ prev_value = value; } } - for (auto const *enc_grp : encoding_group_vec_) { + for (auto const* enc_grp : encoding_group_vec_) { enc_grp->CheckEncodings(); } } @@ -243,8 +243,8 @@ // Emit the initializers of the decode function tables/opcode tables used // by the decoding functions. void EncodingGroup::EmitInitializers(absl::string_view name, - std::string *initializers_ptr, - const std::string &opcode_enum) const { + std::string* initializers_ptr, + const std::string& opcode_enum) const { if (discriminator_size_ == 0) return; absl::StrAppend(initializers_ptr, "constexpr int kParseGroup", name, "_Size = ", discriminator_size_, ";\n\n"); @@ -283,7 +283,7 @@ } } absl::StrAppend(initializers_ptr, "};\n\n"); - for (auto const *enc_grp : encoding_group_vec_) { + for (auto const* enc_grp : encoding_group_vec_) { // Don't create initializers for leaf encoding groups. They don't need them. if (enc_grp->encoding_group_vec_.empty()) continue; std::string grp_name = absl::StrCat( @@ -297,9 +297,9 @@ // Generate the code for the decoders, both the declarations in the .h file as // well as the definitions in the .cc file. void EncodingGroup::EmitDecoders(absl::string_view name, - std::string *declarations_ptr, - std::string *definitions_ptr, - const std::string &opcode_enum) const { + std::string* declarations_ptr, + std::string* definitions_ptr, + const std::string& opcode_enum) const { // Generate the decode function signature. std::string signature = absl::StrCat("std::pair<", opcode_enum, ", FormatEnum> Decode", name, "(", @@ -352,7 +352,7 @@ opcode_enum, ", FormatEnum> opcodes[", count, "] = {\n"); int entry = 0; - for (auto *enc : encoding_vec_) { + for (auto* enc : encoding_vec_) { int value = ExtractValue(enc->GetValue(), discriminator_recipe_); while (entry < value) { absl::StrAppend(definitions_ptr, " {", opcode_enum, @@ -387,7 +387,7 @@ if (encoding_group_vec_.empty()) return; - for (auto const *enc_grp : encoding_group_vec_) { + for (auto const* enc_grp : encoding_group_vec_) { uint64_t value = ExtractValue(enc_grp->encoding_vec_[0]->GetValue(), discriminator_recipe_); std::string grp_name = absl::StrCat(name, "_", absl::Hex(value)); @@ -397,7 +397,7 @@ } void EncodingGroup::EmitComplexDecoderBody( - std::string *definitions_ptr, absl::string_view index_extraction, + std::string* definitions_ptr, absl::string_view index_extraction, absl::string_view opcode_enum) const { // If the index_extraction is empty, use a series of if statements. if (index_extraction.empty()) { @@ -405,8 +405,8 @@ return; } // Group the encodings by index value. - absl::btree_map<uint64_t, std::vector<InstructionEncoding *>> encoding_map; - for (auto *encoding : encoding_vec_) { + absl::btree_map<uint64_t, std::vector<InstructionEncoding*>> encoding_map; + for (auto* encoding : encoding_vec_) { // Get the discriminator value. uint64_t index_value = ExtractValue(encoding->GetValue(), discriminator_recipe_); @@ -414,13 +414,13 @@ } absl::StrAppend(definitions_ptr, " switch (index) {\n"); // For each index value, generate the 'case' statement. - for (auto &[index_value, encodings] : encoding_map) { + for (auto& [index_value, encodings] : encoding_map) { absl::flat_hash_set<std::string> extracted; absl::StrAppend(definitions_ptr, " case 0x", absl::Hex(index_value), ": {\n"); int if_count = 0; - for (auto *encoding : encodings) { - for (auto *constraint : encoding->equal_constraints()) { + for (auto* encoding : encodings) { + for (auto* constraint : encoding->equal_constraints()) { ProcessConstraint(extracted, constraint, definitions_ptr); } if_count += EmitEncodingIfStatement(/*indent*/ 4, encoding, opcode_enum, @@ -435,15 +435,15 @@ } void EncodingGroup::EmitComplexDecoderBodyIfSequence( - std::string *definitions_ptr, absl::string_view opcode_enum) const { + std::string* definitions_ptr, absl::string_view opcode_enum) const { // For each instruction in the encoding vec, generate the if statement // to see if the instruction is matched. absl::flat_hash_set<std::string> extracted; int count = 0; // For equal constraints, some can be ignored because those bits are // wholly considered by the parent groups or the discriminator. - for (auto *encoding : encoding_vec_) { - for (auto *constraint : encoding->equal_constraints()) { + for (auto* encoding : encoding_vec_) { + for (auto* constraint : encoding->equal_constraints()) { ProcessConstraint(extracted, constraint, definitions_ptr); } count += EmitEncodingIfStatement(/*indent*/ 0, encoding, opcode_enum, @@ -456,11 +456,11 @@ } void EncodingGroup::ProcessConstraint( - const absl::flat_hash_set<std::string> &extracted, Constraint *constraint, - std::string *definitions_ptr) const { + const absl::flat_hash_set<std::string>& extracted, Constraint* constraint, + std::string* definitions_ptr) const { if (constraint->field != nullptr) { // Field constraint. - Field *field = constraint->field; + Field* field = constraint->field; std::string name = absl::StrCat(field->name, "_value"); if (extracted.contains(name)) return; uint64_t mask = ((1ULL << field->width) - 1); @@ -474,7 +474,7 @@ } // It's an overlay constraint. - Overlay *overlay = constraint->overlay; + Overlay* overlay = constraint->overlay; std::string name = absl::StrCat(overlay->name(), "_value"); uint64_t mask = 0; // Get the bits that correspond to the overlay. @@ -496,9 +496,9 @@ } int EncodingGroup::EmitEncodingIfStatement( - int indent, const InstructionEncoding *encoding, - absl::string_view opcode_enum, absl::flat_hash_set<std::string> &extracted, - std::string *definitions_ptr) const { + int indent, const InstructionEncoding* encoding, + absl::string_view opcode_enum, absl::flat_hash_set<std::string>& extracted, + std::string* definitions_ptr) const { std::string indent_str(indent + 2, ' '); // Write any field/overlay extractions needed for the encoding (that // haven't already been extracted). @@ -510,7 +510,7 @@ definitions_ptr); // Write any field/overlay extractions needed for the specializations (that // haven't already been extracted). - for (auto const &[unused, encoding] : encoding->specializations()) { + for (auto const& [unused, encoding] : encoding->specializations()) { EmitExtractions(indent, encoding->equal_constraints(), extracted, definitions_ptr); EmitExtractions(indent, encoding->equal_extracted_constraints(), extracted, @@ -546,7 +546,7 @@ // specialization. std::string if_str = "if "; if (specialization) { - for (auto const &[name, encoding] : encoding->specializations()) { + for (auto const& [name, encoding] : encoding->specializations()) { int spec_count = 0; std::string spec_condition; std::string spec_connector; @@ -590,9 +590,9 @@ } void EncodingGroup::EmitFieldExtraction( - const Field *field, const std::string &indent_str, - absl::flat_hash_set<std::string> &extracted, - std::string *definitions_ptr) const { + const Field* field, const std::string& indent_str, + absl::flat_hash_set<std::string>& extracted, + std::string* definitions_ptr) const { std::string name = absl::StrCat(field->name, "_value"); if (!extracted.contains(name)) { std::string data_type; @@ -620,9 +620,9 @@ } void EncodingGroup::EmitOverlayExtraction( - const Overlay *overlay, const std::string &indent_str, - absl::flat_hash_set<std::string> &extracted, - std::string *definitions_ptr) const { + const Overlay* overlay, const std::string& indent_str, + absl::flat_hash_set<std::string>& extracted, + std::string* definitions_ptr) const { std::string name = absl::StrCat(overlay->name(), "_value"); if (!extracted.contains(name)) { auto ovl_width = overlay->declared_width(); @@ -649,16 +649,16 @@ } } -void EncodingGroup::EmitExtractions( - int indent, const std::vector<Constraint *> &constraints, - absl::flat_hash_set<std::string> &extracted, - std::string *definitions_ptr) const { +void EncodingGroup::EmitExtractions(int indent, + const std::vector<Constraint*>& constraints, + absl::flat_hash_set<std::string>& extracted, + std::string* definitions_ptr) const { std::string indent_str(indent + 2, ' '); // Write any field/overlay extractions needed for the constraints. // Note, the extractions may be wider than the instruction word width, due // to constant bits being added, so make sure to use appropriate type for // each extraction. - for (auto const *constraint : constraints) { + for (auto const* constraint : constraints) { if (constraint->can_ignore) continue; if (constraint->field != nullptr) { EmitFieldExtraction(constraint->field, indent_str, extracted, @@ -678,10 +678,10 @@ } int EncodingGroup::EmitOtherConstraintConditions( - const std::vector<Constraint *> &constraints, std::string &connector, - std::string *condition) const { + const std::vector<Constraint*>& constraints, std::string& connector, + std::string* condition) const { int count = 0; - for (auto const *constraint : constraints) { + for (auto const* constraint : constraints) { if (constraint->can_ignore) continue; std::string comparison(kComparison[static_cast<int>(constraint->type)]); @@ -709,10 +709,10 @@ } int EncodingGroup::EmitConstraintConditions( - const std::vector<Constraint *> &constraints, absl::string_view comparison, - std::string &connector, std::string *condition) const { + const std::vector<Constraint*>& constraints, absl::string_view comparison, + std::string& connector, std::string* condition) const { int count = 0; - for (auto const *constraint : constraints) { + for (auto const* constraint : constraints) { std::string comparison(kComparison[static_cast<int>(constraint->type)]); if (constraint->can_ignore) continue; std::string name = absl::StrCat((constraint->field != nullptr) @@ -757,7 +757,7 @@ " encodings: ", encoding_vec_.size(), "\n"); if (encoding_group_vec_.empty()) { auto recipe = GetExtractionRecipe(varying_ & mask_ & ~ignore_); - for (auto *enc : encoding_vec_) { + for (auto* enc : encoding_vec_) { uint64_t value = ExtractValue(enc->GetValue(), recipe); absl::StrAppend(&output, "//", indent, " ", enc->name(), ": ", absl::Hex(enc->GetValue() & varying_ & mask_, pad), " : ", @@ -770,7 +770,7 @@ mask &= ~ignore_; absl::StrAppend(&output, absl::Hex(mask, pad), ": "); } - for (auto *constraint : enc->equal_extracted_constraints()) { + for (auto* constraint : enc->equal_extracted_constraints()) { std::string name = constraint->field == nullptr ? constraint->overlay->name() : constraint->field->name; @@ -778,7 +778,7 @@ absl::Hex(constraint->value, absl::PadSpec::kZeroPad8), " "); } - for (auto *constraint : enc->other_constraints()) { + for (auto* constraint : enc->other_constraints()) { std::string name = constraint->field == nullptr ? constraint->overlay->name() : constraint->field->name; @@ -797,7 +797,7 @@ absl::StrAppend(&output, "\n"); } } else { - for (auto *group : encoding_group_vec_) { + for (auto* group : encoding_group_vec_) { absl::StrAppend(&output, group->DumpGroup("SUB" + prefix, indent + " ")); } }
diff --git a/mpact/sim/decoder/encoding_group.h b/mpact/sim/decoder/encoding_group.h index 5ff661d..9f470ba 100644 --- a/mpact/sim/decoder/encoding_group.h +++ b/mpact/sim/decoder/encoding_group.h
@@ -42,17 +42,17 @@ // can be used to differentiate the encodings. class EncodingGroup { public: - EncodingGroup(InstructionGroup *inst_group, uint64_t ignore); - EncodingGroup(EncodingGroup *parent, InstructionGroup *inst_group, + EncodingGroup(InstructionGroup* inst_group, uint64_t ignore); + EncodingGroup(EncodingGroup* parent, InstructionGroup* inst_group, uint64_t ignore); ~EncodingGroup(); // Remove bits from a mask that are already handled by parent encoding group. void AdjustMask(); - void AddEncoding(InstructionEncoding *enc); + void AddEncoding(InstructionEncoding* enc); // True if the encoding can be added to the group (i.e., there are // sufficiently many "overlapping" bits. - bool CanAddEncoding(InstructionEncoding *enc); + bool CanAddEncoding(InstructionEncoding* enc); // True if the encodings can be decoded using a simple lookup table without // any further comparisons. bool IsSimpleDecode(); @@ -61,11 +61,11 @@ // Verify that there are no collisions of opcodes in the simple decoders. void CheckEncodings() const; // Emit code for the initializers (decode tables) and the decoder functions. - void EmitInitializers(absl::string_view name, std::string *initializers_ptr, - const std::string &opcode_enum) const; - void EmitDecoders(absl::string_view name, std::string *declarations_ptr, - std::string *definitions_ptr, - const std::string &opcode_enum) const; + void EmitInitializers(absl::string_view name, std::string* initializers_ptr, + const std::string& opcode_enum) const; + void EmitDecoders(absl::string_view name, std::string* declarations_ptr, + std::string* definitions_ptr, + const std::string& opcode_enum) const; // Return a string containing information about the current group. This will // be removed at a later stage. // TODO(torerik): remove when no longer needed. @@ -73,7 +73,7 @@ // Accessors. // Return the parent encoding group if it exists. - EncodingGroup *parent() const { return parent_; } + EncodingGroup* parent() const { return parent_; } // The mask is the intersection of the bits that are significant to the // instruction encodings in this group. The bits that are used to select this // group from the parent are removed from the mask. @@ -97,49 +97,49 @@ // be non-zero). bool simple_decoding() const { return simple_decoding_; } // The vector of encodings in this group. - const std::vector<InstructionEncoding *> &encoding_vec() const { + const std::vector<InstructionEncoding*>& encoding_vec() const { return encoding_vec_; } // The vector of subgroups in this group. - std::vector<EncodingGroup *> &encoding_group_vec() { + std::vector<EncodingGroup*>& encoding_group_vec() { return encoding_group_vec_; } private: // Methods that factors out some of the complexities of the public code // emitting methods. - void EmitComplexDecoderBody(std::string *definitions_ptr, + void EmitComplexDecoderBody(std::string* definitions_ptr, absl::string_view index_extraction, absl::string_view opcode_enum) const; - void EmitComplexDecoderBodyIfSequence(std::string *definitions_ptr, + void EmitComplexDecoderBodyIfSequence(std::string* definitions_ptr, absl::string_view opcode_enum) const; - int EmitEncodingIfStatement(int indent, const InstructionEncoding *encoding, + int EmitEncodingIfStatement(int indent, const InstructionEncoding* encoding, absl::string_view opcode_enum, - absl::flat_hash_set<std::string> &extracted, - std::string *definitions_ptr) const; - void ProcessConstraint(const absl::flat_hash_set<std::string> &extracted, - Constraint *constraint, - std::string *definitions_ptr) const; - void EmitFieldExtraction(const Field *field, const std::string &indent_str, - absl::flat_hash_set<std::string> &extracted, - std::string *definitions_ptr) const; - void EmitOverlayExtraction(const Overlay *overlay, - const std::string &indent_str, - absl::flat_hash_set<std::string> &extracted, - std::string *definitions_ptr) const; - void EmitExtractions(int indent, const std::vector<Constraint *> &constraints, - absl::flat_hash_set<std::string> &extracted, - std::string *definitions_ptr) const; - int EmitConstraintConditions(const std::vector<Constraint *> &constraints, + absl::flat_hash_set<std::string>& extracted, + std::string* definitions_ptr) const; + void ProcessConstraint(const absl::flat_hash_set<std::string>& extracted, + Constraint* constraint, + std::string* definitions_ptr) const; + void EmitFieldExtraction(const Field* field, const std::string& indent_str, + absl::flat_hash_set<std::string>& extracted, + std::string* definitions_ptr) const; + void EmitOverlayExtraction(const Overlay* overlay, + const std::string& indent_str, + absl::flat_hash_set<std::string>& extracted, + std::string* definitions_ptr) const; + void EmitExtractions(int indent, const std::vector<Constraint*>& constraints, + absl::flat_hash_set<std::string>& extracted, + std::string* definitions_ptr) const; + int EmitConstraintConditions(const std::vector<Constraint*>& constraints, absl::string_view comparison, - std::string &connector, - std::string *condition) const; - int EmitOtherConstraintConditions( - const std::vector<Constraint *> &constraints, std::string &connector, - std::string *condition) const; + std::string& connector, + std::string* condition) const; + int EmitOtherConstraintConditions(const std::vector<Constraint*>& constraints, + std::string& connector, + std::string* condition) const; - InstructionGroup *inst_group_ = nullptr; - EncodingGroup *parent_ = nullptr; + InstructionGroup* inst_group_ = nullptr; + EncodingGroup* parent_ = nullptr; uint64_t varying_ = 0; uint64_t discriminator_ = 0; size_t discriminator_size_ = 0; @@ -151,8 +151,8 @@ uint64_t ignore_ = 0; bool simple_decoding_ = false; std::string inst_word_type_; - std::vector<InstructionEncoding *> encoding_vec_; - std::vector<EncodingGroup *> encoding_group_vec_; + std::vector<InstructionEncoding*> encoding_vec_; + std::vector<EncodingGroup*> encoding_group_vec_; }; } // namespace bin_format
diff --git a/mpact/sim/decoder/extract.cc b/mpact/sim/decoder/extract.cc index b2e4cf7..c73db46 100644 --- a/mpact/sim/decoder/extract.cc +++ b/mpact/sim/decoder/extract.cc
@@ -14,10 +14,12 @@ #include "mpact/sim/decoder/extract.h" +#include <cstdint> #include <string> #include <vector> #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" namespace mpact { namespace sim { @@ -25,7 +27,7 @@ namespace bin_format { uint64_t ExtractValue(uint64_t value, - const std::vector<ExtractionStep> &recipe) { + const std::vector<ExtractionStep>& recipe) { uint64_t extracted_value = 0; for (auto [mask, shift] : recipe) { extracted_value |= ((value >> shift) & mask); @@ -33,7 +35,7 @@ return extracted_value; } -std::string WriteExtraction(const std::vector<ExtractionStep> &recipe, +std::string WriteExtraction(const std::vector<ExtractionStep>& recipe, absl::string_view value, absl::string_view result, absl::string_view indent) { std::string output;
diff --git a/mpact/sim/decoder/extract.h b/mpact/sim/decoder/extract.h index 585b6d9..bcb263a 100644 --- a/mpact/sim/decoder/extract.h +++ b/mpact/sim/decoder/extract.h
@@ -41,13 +41,13 @@ // Using the extraction recipe given, perform the extraction from the input // value and return the result. -uint64_t ExtractValue(uint64_t value, const ExtractionRecipe &recipe); +uint64_t ExtractValue(uint64_t value, const ExtractionRecipe& recipe); // Using the extraction recipe given, return a string that has the C code for // performing the extraction assuming the input value is stored in a variable // with the name stored in 'value' and the result should be stored in variable // named as stored in 'result'. Each line in the code is indented by 'indent'. -std::string WriteExtraction(const ExtractionRecipe &recipe, +std::string WriteExtraction(const ExtractionRecipe& recipe, absl::string_view value, absl::string_view result, absl::string_view indent);
diff --git a/mpact/sim/decoder/format.cc b/mpact/sim/decoder/format.cc index 5005388..0acecfd 100644 --- a/mpact/sim/decoder/format.cc +++ b/mpact/sim/decoder/format.cc
@@ -45,7 +45,7 @@ // The equality operator compares to verify that the field/format definitions // are equivalent, i.e., refers to the same bits. -bool FieldOrFormat::operator==(const FieldOrFormat &rhs) const { +bool FieldOrFormat::operator==(const FieldOrFormat& rhs) const { if (is_field_ != rhs.is_field_) return false; if (is_field_) { if (high_ != rhs.high_) return false; @@ -56,17 +56,17 @@ return true; } -bool FieldOrFormat::operator!=(const FieldOrFormat &rhs) const { +bool FieldOrFormat::operator!=(const FieldOrFormat& rhs) const { return !(*this == rhs); } using ::mpact::sim::machine_description::instruction_set::ToPascalCase; -Format::Format(std::string name, int width, BinEncodingInfo *encoding_info) +Format::Format(std::string name, int width, BinEncodingInfo* encoding_info) : Format(name, width, "", encoding_info) {} Format::Format(std::string name, int width, std::string base_format_name, - BinEncodingInfo *encoding_info) + BinEncodingInfo* encoding_info) : name_(name), base_format_name_(base_format_name), declared_width_(width), @@ -77,11 +77,11 @@ // delete field_ptr; // } field_map_.clear(); - for (auto &[unused, overlay_ptr] : overlay_map_) { + for (auto& [unused, overlay_ptr] : overlay_map_) { delete overlay_ptr; } overlay_map_.clear(); - for (auto *field : field_vec_) { + for (auto* field : field_vec_) { delete field; } field_vec_.clear(); @@ -105,14 +105,14 @@ // format. This will be resolved once all the formats have been parsed. void Format::AddFormatReferenceField(std::string format_alias, std::string format_name, int size, - antlr4::Token *ctx) { + antlr4::Token* ctx) { field_vec_.push_back(new FieldOrFormat(format_alias, format_name, size, ctx)); } // Add an overlay to the current format. An overlay is a named alias for a // not necessarily contiguous nor in order collection of bits in the format. -absl::StatusOr<Overlay *> Format::AddFieldOverlay(std::string name, - bool is_signed, int width) { +absl::StatusOr<Overlay*> Format::AddFieldOverlay(std::string name, + bool is_signed, int width) { // Make sure that the name isn't used already in the format. if (overlay_map_.contains(name)) { return absl::InvalidArgumentError( @@ -128,14 +128,14 @@ } // Return the named field if it exists, nullptr otherwise. -Field *Format::GetField(absl::string_view field_name) const { +Field* Format::GetField(absl::string_view field_name) const { auto iter = field_map_.find(field_name); if (iter == field_map_.end()) return nullptr; return iter->second; } // Return the named field if it exists, nullptr otherwise. -Overlay *Format::GetOverlay(absl::string_view overlay_name) const { +Overlay* Format::GetOverlay(absl::string_view overlay_name) const { auto iter = overlay_map_.find(overlay_name); if (iter == overlay_map_.end()) return nullptr; return iter->second; @@ -172,7 +172,7 @@ // If there is a base format name, look up that format, verify that the widths // are the same. if (!base_format_name_.empty()) { - auto *base_format = encoding_info_->GetFormat(base_format_name_); + auto* base_format = encoding_info_->GetFormat(base_format_name_); if (base_format == nullptr) { return absl::InternalError( absl::StrCat("Format ", name(), " refers to undefined base format ", @@ -191,10 +191,10 @@ // Go through the list of fields/format references. Get the declared widths // of the formats and add to the computed width. Signal error if the // computed width differs from the declared width. - for (auto *field_or_format : field_vec_) { + for (auto* field_or_format : field_vec_) { // Field. if (field_or_format->is_field()) { - auto *field = field_or_format->field(); + auto* field = field_or_format->field(); field->high = declared_width_ - computed_width_ - 1; field->low = field->high - field->width + 1; computed_width_ += field->width; @@ -203,7 +203,7 @@ } // Format; - auto *format = field_or_format->format(); + auto* format = field_or_format->format(); if (format == nullptr) { std::string fmt_name = field_or_format->format_name(); format = encoding_info_->GetFormat(fmt_name); @@ -224,7 +224,7 @@ ") differs from computed width (", computed_width_, ")")); } } - for (auto &[name, overlay_ptr] : overlay_map_) { + for (auto& [name, overlay_ptr] : overlay_map_) { auto status = overlay_ptr->ComputeHighLow(); if (!status.ok()) return status; overlay_extractors_.insert(std::make_pair(name, overlay_ptr)); @@ -241,12 +241,12 @@ // in the base format namespace. This method is used to propagate such // potential promotions upward in the inheritance tree. void Format::PropagateExtractorsUp() { - for (auto *fmt : derived_formats_) { + for (auto* fmt : derived_formats_) { fmt->PropagateExtractorsUp(); } if (base_format_ != nullptr) { // Try to propagate extractors up the inheritance tree. - for (auto const &[name, field_or_format_ptr] : extractors_) { + for (auto const& [name, field_or_format_ptr] : extractors_) { // Ignore those that have a nullptr, they have already failed to be // promoted. if (field_or_format_ptr == nullptr) continue; @@ -264,7 +264,7 @@ base_format_->extractors_[name] = nullptr; } } - for (auto const &[name, overlay_ptr] : overlay_extractors_) { + for (auto const& [name, overlay_ptr] : overlay_extractors_) { // Ignore those that have a nullptr, they have already failed to be // promoted. if (overlay_ptr == nullptr) continue; @@ -323,14 +323,14 @@ continue; } } - for (auto *fmt : derived_formats_) { + for (auto* fmt : derived_formats_) { fmt->PropagateExtractorsDown(); } } // Returns true if the current format, or a base format, contains an // extractor for field 'name'. -bool Format::HasExtract(const std::string &name) const { +bool Format::HasExtract(const std::string& name) const { auto iter = extractors_.find(name); if ((iter != extractors_.end()) && (iter->second != nullptr)) return true; @@ -341,7 +341,7 @@ // Returns true if the current format, or a base format, contains an // extractor for overlay 'name'. -bool Format::HasOverlayExtract(const std::string &name) const { +bool Format::HasOverlayExtract(const std::string& name) const { auto iter = overlay_extractors_.find(name); if ((iter != overlay_extractors_.end()) && (iter->second != nullptr)) { return true; @@ -353,7 +353,7 @@ } std::string Format::GeneratePackedStructFieldExtractor( - const Field *field) const { + const Field* field) const { std::string h_output; int width = field->width; std::string return_type = GetUIntType(width); @@ -380,7 +380,7 @@ // This method generates the C++ code for the field extractors for the current // format. -std::string Format::GenerateFieldExtractor(const Field *field) const { +std::string Format::GenerateFieldExtractor(const Field* field) const { std::string h_output; int return_width = GetIntTypeBitWidth(field->width); std::string result_type_name = @@ -452,7 +452,7 @@ } std::string Format::GeneratePackedStructFieldInserter( - const Field *field) const { + const Field* field) const { std::string h_output; std::string field_type_name; std::string inst_word_type_name; @@ -486,7 +486,7 @@ // This method generates the C++ code for field inserters for the current // format. That is, the generated code will take the value of a field and // insert it into the right place in the instruction word. -std::string Format::GenerateFieldInserter(const Field *field) const { +std::string Format::GenerateFieldInserter(const Field* field) const { std::string h_output; std::string field_type_name; std::string inst_word_type_name = GetUIntType(computed_width_); @@ -542,7 +542,7 @@ // This method generates the C++ code for overlay inserters for the current // format. That is, the generated code will take the value of an overlay and // insert its components into the right places in the instruction word. -std::string Format::GenerateOverlayInserter(Overlay *overlay) const { +std::string Format::GenerateOverlayInserter(Overlay* overlay) const { std::string h_output; std::string result_type_name = GetUIntType(computed_width_); std::string overlay_type_name; @@ -580,7 +580,7 @@ use_mask_variable = true; } } - for (auto &bits_or_field : overlay->component_vec()) { + for (auto& bits_or_field : overlay->component_vec()) { int width = bits_or_field->width(); // Ignore the bit fields in the overlay. if (bits_or_field->high() < 0) { @@ -622,7 +622,7 @@ } std::string Format::GeneratePackedStructFormatInserter( - std::string_view format_alias, const Format *format, int high, + std::string_view format_alias, const Format* format, int high, int size) const { std::string h_output; std::string inst_word_type_name; @@ -657,7 +657,7 @@ // format. That is, the generated code will take the value of a format and // insert it into the right place in the instruction word. std::string Format::GenerateFormatInserter(std::string_view format_alias, - const Format *format, int high, + const Format* format, int high, int size) const { if (size > 1) { return GenerateReplicatedFormatInserter(format_alias, format, high, size); @@ -666,7 +666,7 @@ } std::string Format::GenerateReplicatedFormatInserter( - std::string_view format_alias, const Format *format, int high, + std::string_view format_alias, const Format* format, int high, int size) const { std::string h_output; std::string target_type_name = GetUIntType(declared_width_); @@ -719,7 +719,7 @@ } std::string Format::GenerateSingleFormatInserter(std::string_view format_alias, - const Format *format, + const Format* format, int high) const { std::string h_output; std::string target_type_name = GetUIntType(declared_width_); @@ -773,7 +773,7 @@ } std::string Format::GeneratePackedStructFormatExtractor( - absl::string_view format_alias, const Format *format, int high, + absl::string_view format_alias, const Format* format, int high, int size) const { std::string h_output; int width = format->declared_width(); @@ -802,7 +802,7 @@ // This method generates the format extractors for the current format (for // when a format contains other formats). std::string Format::GenerateFormatExtractor(absl::string_view format_alias, - const Format *format, int high, + const Format* format, int high, int size) const { std::string h_output; // For each format generate an extractor. int width = format->declared_width(); @@ -890,7 +890,7 @@ } std::string Format::GeneratePackedStructOverlayExtractor( - Overlay *overlay) const { + Overlay* overlay) const { std::string h_output; std::string arg_type; if (declared_width_ > 128) { @@ -921,7 +921,7 @@ } // Generates the C++ code for the overlay extractors in the current format. -std::string Format::GenerateOverlayExtractor(Overlay *overlay) const { +std::string Format::GenerateOverlayExtractor(Overlay* overlay) const { std::string h_output; std::string return_type = overlay->is_signed() @@ -975,7 +975,7 @@ absl::StrAppend(&h_output, "struct ", ToPascalCase(name()), " {\n\n"); // First fields and formats. std::string inserter; - for (auto &[unused, field_or_format_ptr] : extractors_) { + for (auto& [unused, field_or_format_ptr] : extractors_) { if (field_or_format_ptr->is_field()) { if (layout() == Layout::kPackedStruct) { inserter = @@ -998,7 +998,7 @@ } } // Next the overlays. - for (auto &[unused, overlay_ptr] : overlay_extractors_) { + for (auto& [unused, overlay_ptr] : overlay_extractors_) { auto inserter = GenerateOverlayInserter(overlay_ptr); absl::StrAppend(&h_output, inserter); } @@ -1011,7 +1011,7 @@ // First the struct. absl::StrAppend(&h_output, "struct Packed", ToPascalCase(name()), " {\n"); for (auto it = field_vec_.rbegin(); it != field_vec_.rend(); ++it) { - auto *component = *it; + auto* component = *it; if (component->is_field()) { int width = component->field()->width; std::string field_type = component->field()->is_signed @@ -1073,7 +1073,7 @@ } // First fields and formats. - for (auto &[unused, field_or_format_ptr] : extractors_) { + for (auto& [unused, field_or_format_ptr] : extractors_) { if (field_or_format_ptr->is_field()) { std::string extractor; if (layout() == Layout::kPackedStruct) { @@ -1101,7 +1101,7 @@ } // Then the overlays. - for (auto &[unused, overlay_ptr] : overlay_extractors_) { + for (auto& [unused, overlay_ptr] : overlay_extractors_) { std::string extractor; if (layout() == Layout::kPackedStruct) { extractor = GeneratePackedStructOverlayExtractor(overlay_ptr); @@ -1120,7 +1120,7 @@ return extractors; } -bool Format::IsDerivedFrom(const Format *format) { +bool Format::IsDerivedFrom(const Format* format) { if (format == this) return true; if (base_format_ == nullptr) return false; if (base_format_ == format) return true;
diff --git a/mpact/sim/decoder/format.h b/mpact/sim/decoder/format.h index deb4a55..36081f5 100644 --- a/mpact/sim/decoder/format.h +++ b/mpact/sim/decoder/format.h
@@ -46,8 +46,8 @@ int high; int low; int width; - Format *format = nullptr; - Field(std::string name_, bool is_signed_, int width_, Format *format_) + Format* format = nullptr; + Field(std::string name_, bool is_signed_, int width_, Format* format_) : name(name_), is_signed(is_signed_), high(-1), @@ -70,9 +70,9 @@ class FieldOrFormat { public: - explicit FieldOrFormat(Field *field) : is_field_(true), field_(field) {} + explicit FieldOrFormat(Field* field) : is_field_(true), field_(field) {} FieldOrFormat(std::string format_alias, std::string fmt_name, int size, - antlr4::Token *ctx) + antlr4::Token* ctx) : is_field_(false), format_name_(fmt_name), format_alias_(format_alias), @@ -81,28 +81,28 @@ ~FieldOrFormat(); bool is_field() const { return is_field_; } - Field *field() const { return field_; } + Field* field() const { return field_; } int high() const { return high_; } void set_high(int value) { high_ = value; } - const std::string &format_name() const { return format_name_; } - antlr4::Token *ctx() const { return ctx_; } - Format *format() const { return format_; } + const std::string& format_name() const { return format_name_; } + antlr4::Token* ctx() const { return ctx_; } + Format* format() const { return format_; } absl::string_view format_alias() const { return format_alias_; } int size() const { return size_; } - void set_format(Format *fmt) { format_ = fmt; } + void set_format(Format* fmt) { format_ = fmt; } - bool operator==(const FieldOrFormat &rhs) const; - bool operator!=(const FieldOrFormat &rhs) const; + bool operator==(const FieldOrFormat& rhs) const; + bool operator!=(const FieldOrFormat& rhs) const; private: bool is_field_; - Field *field_ = nullptr; + Field* field_ = nullptr; std::string format_name_; std::string format_alias_; int high_ = 0; int size_ = 0; - antlr4::Token *ctx_ = nullptr; - Format *format_ = nullptr; + antlr4::Token* ctx_ = nullptr; + Format* format_ = nullptr; }; struct Extractors { @@ -120,9 +120,9 @@ }; Format() = delete; - Format(std::string name, int width, BinEncodingInfo *encoding_info); + Format(std::string name, int width, BinEncodingInfo* encoding_info); Format(std::string name, int width, std::string base_format_name, - BinEncodingInfo *encoding_info); + BinEncodingInfo* encoding_info); ~Format(); // Adds a field (signed or unsigned) of the given width to the format. @@ -131,18 +131,18 @@ // another format later, or generate an error at that time. void AddFormatReferenceField(std::string format_alias, std::string format_name, int size, - antlr4::Token *ctx); + antlr4::Token* ctx); // Adds an overlay to the format. An overlay is an alias to a set of bits // in the instruction format. - absl::StatusOr<Overlay *> AddFieldOverlay(std::string name, bool is_signed, - int width); + absl::StatusOr<Overlay*> AddFieldOverlay(std::string name, bool is_signed, + int width); // Returns the named field if it exists in the format. Otherwise it returns // nullptr. - Field *GetField(absl::string_view field_name) const; + Field* GetField(absl::string_view field_name) const; // Returns the named overlay if it exists in the format. Otherwise it returns // nullptr. - Overlay *GetOverlay(absl::string_view overlay_name) const; + Overlay* GetOverlay(absl::string_view overlay_name) const; // Performs a consistency check on the format. absl::Status ComputeAndCheckFormatWidth(); @@ -156,54 +156,54 @@ std::string GenerateInserters() const; // True if the current format is a descendent of format. - bool IsDerivedFrom(const Format *format); + bool IsDerivedFrom(const Format* format); // Accessors. - const std::string &name() const { return name_; } + const std::string& name() const { return name_; } // The unsigned integer type name larger or equal to the format width. // E.g. uint32_t etc. - const std::string &uint_type_name() const { return uint_type_name_; } + const std::string& uint_type_name() const { return uint_type_name_; } int declared_width() const { return declared_width_; } int computed_width() const { return computed_width_; } - Format *base_format() const { return base_format_; } + Format* base_format() const { return base_format_; } // Return pointer to the parent encoding info class. - BinEncodingInfo *encoding_info() const { return encoding_info_; } + BinEncodingInfo* encoding_info() const { return encoding_info_; } // Field layout. Layout layout() const { return layout_; } void set_layout(Layout layout) { layout_ = layout; } private: - bool HasExtract(const std::string &name) const; - bool HasOverlayExtract(const std::string &name) const; + bool HasExtract(const std::string& name) const; + bool HasOverlayExtract(const std::string& name) const; // Extractor generators. std::string GeneratePackedStructTypes() const; - std::string GeneratePackedStructFieldExtractor(const Field *field) const; + std::string GeneratePackedStructFieldExtractor(const Field* field) const; std::string GeneratePackedStructFormatExtractor(std::string_view format_alias, - const Format *format, + const Format* format, int high, int size) const; - std::string GeneratePackedStructOverlayExtractor(Overlay *overlay) const; - std::string GenerateFieldExtractor(const Field *field) const; + std::string GeneratePackedStructOverlayExtractor(Overlay* overlay) const; + std::string GenerateFieldExtractor(const Field* field) const; std::string GenerateFormatExtractor(std::string_view format_alias, - const Format *format, int high, + const Format* format, int high, int size) const; - std::string GenerateOverlayExtractor(Overlay *overlay) const; + std::string GenerateOverlayExtractor(Overlay* overlay) const; // Inserters. - std::string GenerateFieldInserter(const Field *field) const; - std::string GeneratePackedStructFieldInserter(const Field *field) const; + std::string GenerateFieldInserter(const Field* field) const; + std::string GeneratePackedStructFieldInserter(const Field* field) const; std::string GenerateFormatInserter(std::string_view format_alias, - const Format *format, int high, + const Format* format, int high, int size) const; std::string GeneratePackedStructFormatInserter(std::string_view format_alias, - const Format *format, int high, + const Format* format, int high, int size) const; std::string GenerateReplicatedFormatInserter(std::string_view format_alias, - const Format *format, int high, + const Format* format, int high, int size) const; std::string GenerateSingleFormatInserter(std::string_view format_alias, - const Format *format, + const Format* format, int high) const; - std::string GenerateOverlayInserter(Overlay *overlay) const; + std::string GenerateOverlayInserter(Overlay* overlay) const; // Return string representation of the int type that contains bitwidth bits. std::string GetIntType(int bitwidth) const; std::string GetUIntType(int bitwidth) const; @@ -216,17 +216,17 @@ int declared_width_; int computed_width_ = 0; Layout layout_ = Layout::kDefault; - Format *base_format_ = nullptr; - std::vector<Format *> derived_formats_; - BinEncodingInfo *encoding_info_; + Format* base_format_ = nullptr; + std::vector<Format*> derived_formats_; + BinEncodingInfo* encoding_info_; - absl::btree_map<std::string, Overlay *> overlay_map_; - absl::btree_map<std::string, Field *> field_map_; - std::vector<FieldOrFormat *> field_vec_; + absl::btree_map<std::string, Overlay*> overlay_map_; + absl::btree_map<std::string, Field*> field_map_; + std::vector<FieldOrFormat*> field_vec_; // Using std::map because of sorted traversal and better iterator stability // when elements are erased. - std::map<std::string, FieldOrFormat *> extractors_; - std::map<std::string, Overlay *> overlay_extractors_; + std::map<std::string, FieldOrFormat*> extractors_; + std::map<std::string, Overlay*> overlay_extractors_; }; } // namespace bin_format
diff --git a/mpact/sim/decoder/instruction.cc b/mpact/sim/decoder/instruction.cc index 6232b11..e784d8a 100644 --- a/mpact/sim/decoder/instruction.cc +++ b/mpact/sim/decoder/instruction.cc
@@ -28,27 +28,27 @@ namespace machine_description { namespace instruction_set { -Instruction::Instruction(Opcode *opcode, Slot *slot) +Instruction::Instruction(Opcode* opcode, Slot* slot) : Instruction(opcode, nullptr, slot) {} -Instruction::Instruction(Opcode *opcode, Instruction *child, Slot *slot) +Instruction::Instruction(Opcode* opcode, Instruction* child, Slot* slot) : opcode_(opcode), child_(child), slot_(slot) {} Instruction::~Instruction() { delete child_; delete opcode_; - for (auto *ref : resource_use_vec_) { + for (auto* ref : resource_use_vec_) { delete ref; } resource_use_vec_.clear(); - for (auto *ref : resource_acquire_vec_) { + for (auto* ref : resource_acquire_vec_) { delete ref; } resource_acquire_vec_.clear(); - for (auto *disasm_format : disasm_format_vec_) { + for (auto* disasm_format : disasm_format_vec_) { delete disasm_format; } disasm_format_vec_.clear(); - for (auto &[ignored, expr] : attribute_map_) { + for (auto& [ignored, expr] : attribute_map_) { delete expr; } attribute_map_.clear(); @@ -57,7 +57,7 @@ // Append is implemented recursively. Few instructions have child instances, // and when they do it's likely to be a very small number. Not concern for // efficiency here. -void Instruction::AppendChild(Instruction *child) { +void Instruction::AppendChild(Instruction* child) { if (child_ == nullptr) { child_ = child; return; @@ -65,16 +65,16 @@ child_->AppendChild(child); } -void Instruction::AppendResourceUse(const ResourceReference *resource_ref) { +void Instruction::AppendResourceUse(const ResourceReference* resource_ref) { resource_use_vec_.push_back(resource_ref); } -void Instruction::AppendResourceAcquire(const ResourceReference *resource_ref) { +void Instruction::AppendResourceAcquire(const ResourceReference* resource_ref) { resource_acquire_vec_.push_back(resource_ref); } void Instruction::AddInstructionAttribute(absl::string_view attr_name, - TemplateExpression *expression) { + TemplateExpression* expression) { // See if the attribute is already defined. If not, create a new attribute // in the map, otherwise update the expression. auto iter = attribute_map_.find(attr_name); @@ -91,14 +91,14 @@ AddInstructionAttribute(attr_name, new TemplateConstant(1)); } -void Instruction::AppendDisasmFormat(DisasmFormat *disasm_format) { +void Instruction::AppendDisasmFormat(DisasmFormat* disasm_format) { disasm_format_vec_.push_back(disasm_format); } // Creating a derived instruction involves copying attributes and re-evaluating // any expressions that depend on any slot template instantiation values. -absl::StatusOr<Instruction *> Instruction::CreateDerivedInstruction( - TemplateInstantiationArgs *args) const { +absl::StatusOr<Instruction*> Instruction::CreateDerivedInstruction( + TemplateInstantiationArgs* args) const { // First try to create a derived opcode object. Fail if it fails. auto op_result = slot_->instruction_set()->opcode_factory()->CreateDerivedOpcode(opcode(), @@ -106,17 +106,17 @@ if (!op_result.ok()) return op_result.status(); // Create a new instruction object with the derived opcode object. - auto *new_inst = new Instruction(op_result.value(), slot_); + auto* new_inst = new Instruction(op_result.value(), slot_); // Disassembly format. - for (auto const *disasm_fmt : disasm_format_vec()) { + for (auto const* disasm_fmt : disasm_format_vec()) { new_inst->AppendDisasmFormat(new DisasmFormat(*disasm_fmt)); } // Semantic function string. new_inst->set_semfunc_code_string(semfunc_code_string()); // Resource uses. - for (auto const &resource_use : resource_use_vec()) { + for (auto const& resource_use : resource_use_vec()) { auto ref_result = CreateDerivedResourceRef(resource_use, args); if (!ref_result.status().ok()) { delete new_inst; @@ -126,7 +126,7 @@ } // Resource reservations. - for (auto const *resource_def : resource_acquire_vec()) { + for (auto const* resource_def : resource_acquire_vec()) { auto ref_result = CreateDerivedResourceRef(resource_def, args); if (!ref_result.status().ok()) { delete new_inst; @@ -136,7 +136,7 @@ } // Instruction attributes. - for (auto const &[attr_name, expr_ptr] : attribute_map_) { + for (auto const& [attr_name, expr_ptr] : attribute_map_) { auto result = expr_ptr->Evaluate(args); if (result.ok()) { new_inst->AddInstructionAttribute(attr_name, result.value()); @@ -159,10 +159,10 @@ return result.status(); } -absl::StatusOr<ResourceReference *> Instruction::CreateDerivedResourceRef( - const ResourceReference *ref, TemplateInstantiationArgs *args) const { - TemplateExpression *begin_expr = nullptr; - TemplateExpression *end_expr = nullptr; +absl::StatusOr<ResourceReference*> Instruction::CreateDerivedResourceRef( + const ResourceReference* ref, TemplateInstantiationArgs* args) const { + TemplateExpression* begin_expr = nullptr; + TemplateExpression* end_expr = nullptr; // Evaluate the begin expression in the context of any template instantiation // arguments. if (ref->begin_expression != nullptr) { @@ -185,7 +185,7 @@ } end_expr = result.value(); } - auto *new_ref = new ResourceReference(ref->resource, ref->is_array, + auto* new_ref = new ResourceReference(ref->resource, ref->is_array, ref->dest_op, begin_expr, end_expr); return new_ref; } @@ -193,7 +193,7 @@ // The destination op is stored in the opcode object, however, the child pointer // is in the instruction object, so traverse the instructions along the child // chain to find the destination operand. -DestinationOperand *Instruction::GetDestOp(absl::string_view op_name) const { +DestinationOperand* Instruction::GetDestOp(absl::string_view op_name) const { auto dest_op = opcode()->GetDestOp(op_name); if (dest_op != nullptr) return dest_op; @@ -207,7 +207,7 @@ // This is called prior to overriding the attribute value to clean up any // allocated memory. void Instruction::ClearDisasmFormat() { - for (auto *disasm_format : disasm_format_vec_) { + for (auto* disasm_format : disasm_format_vec_) { delete disasm_format; } disasm_format_vec_.clear(); @@ -216,18 +216,18 @@ void Instruction::ClearSemfuncCodeString() { semfunc_code_string_.clear(); } void Instruction::ClearResourceSpecs() { - for (auto *ref : resource_use_vec_) { + for (auto* ref : resource_use_vec_) { delete ref; } resource_use_vec_.clear(); - for (auto *ref : resource_acquire_vec_) { + for (auto* ref : resource_acquire_vec_) { delete ref; } resource_acquire_vec_.clear(); } void Instruction::ClearAttributeSpecs() { - for (auto &[ignored, expr] : attribute_map_) { + for (auto& [ignored, expr] : attribute_map_) { delete expr; } attribute_map_.clear();
diff --git a/mpact/sim/decoder/instruction.h b/mpact/sim/decoder/instruction.h index a04ab90..e2f6563 100644 --- a/mpact/sim/decoder/instruction.h +++ b/mpact/sim/decoder/instruction.h
@@ -41,32 +41,32 @@ // globally unique. class Instruction { public: - Instruction(Opcode *opcode, Slot *slot); - Instruction(Opcode *opcode, Instruction *child, Slot *slot); + Instruction(Opcode* opcode, Slot* slot); + Instruction(Opcode* opcode, Instruction* child, Slot* slot); virtual ~Instruction(); // Append a child instruction. - void AppendChild(Instruction *child); + void AppendChild(Instruction* child); // Create an instruction object that inherits from another. This may require // evaluation of expressions within the instruction/opcode that rely on // template instantiation arguments. - absl::StatusOr<Instruction *> CreateDerivedInstruction( - TemplateInstantiationArgs *args) const; + absl::StatusOr<Instruction*> CreateDerivedInstruction( + TemplateInstantiationArgs* args) const; // Resources used and acquired/released. - void AppendResourceUse(const ResourceReference *resource_ref); - void AppendResourceAcquire(const ResourceReference *resource_ref); + void AppendResourceUse(const ResourceReference* resource_ref); + void AppendResourceAcquire(const ResourceReference* resource_ref); // Instruction attributes. These methods add the instruction attribute to the // opcode if it does not already exist. If it exists, then the new attribute // definition overrides the previous (replaces the expression). void AddInstructionAttribute(absl::string_view attr_name, - TemplateExpression *expression); + TemplateExpression* expression); void AddInstructionAttribute(absl::string_view attr_name); // Append disassembly format string and info. - void AppendDisasmFormat(DisasmFormat *disasm_format); + void AppendDisasmFormat(DisasmFormat* disasm_format); // Searches opcodes in the instruction (and any child instructions) for the // destination op with name op_name. - DestinationOperand *GetDestOp(absl::string_view op_name) const; + DestinationOperand* GetDestOp(absl::string_view op_name) const; // Methods to clear parts of the instructions that may be overridden when // inherited. @@ -76,43 +76,43 @@ void ClearAttributeSpecs(); // Getters and setters. - Opcode *opcode() const { return opcode_; } - Instruction *child() const { return child_; } - Slot *slot() const { return slot_; } + Opcode* opcode() const { return opcode_; } + Instruction* child() const { return child_; } + Slot* slot() const { return slot_; } void set_semfunc_code_string(std::string code_string) { semfunc_code_string_ = code_string; } - const std::string &semfunc_code_string() const { + const std::string& semfunc_code_string() const { return semfunc_code_string_; } - const std::vector<const ResourceReference *> &resource_use_vec() const { + const std::vector<const ResourceReference*>& resource_use_vec() const { return resource_use_vec_; } - const std::vector<const ResourceReference *> &resource_acquire_vec() const { + const std::vector<const ResourceReference*>& resource_acquire_vec() const { return resource_acquire_vec_; } - const std::vector<DisasmFormat *> &disasm_format_vec() const { + const std::vector<DisasmFormat*>& disasm_format_vec() const { return disasm_format_vec_; } - const absl::flat_hash_map<std::string, TemplateExpression *> &attribute_map() + const absl::flat_hash_map<std::string, TemplateExpression*>& attribute_map() const { return attribute_map_; } private: - absl::StatusOr<ResourceReference *> CreateDerivedResourceRef( - const ResourceReference *ref, TemplateInstantiationArgs *args) const; - Opcode *opcode_; - Instruction *child_; - Slot *slot_; - std::vector<const ResourceReference *> resource_use_vec_; - std::vector<const ResourceReference *> resource_acquire_vec_; + absl::StatusOr<ResourceReference*> CreateDerivedResourceRef( + const ResourceReference* ref, TemplateInstantiationArgs* args) const; + Opcode* opcode_; + Instruction* child_; + Slot* slot_; + std::vector<const ResourceReference*> resource_use_vec_; + std::vector<const ResourceReference*> resource_acquire_vec_; std::string semfunc_code_string_; - std::vector<DisasmFormat *> disasm_format_vec_; - absl::flat_hash_map<std::string, TemplateExpression *> attribute_map_; + std::vector<DisasmFormat*> disasm_format_vec_; + absl::flat_hash_map<std::string, TemplateExpression*> attribute_map_; }; } // namespace instruction_set
diff --git a/mpact/sim/decoder/instruction_encoding.cc b/mpact/sim/decoder/instruction_encoding.cc index 3fd17b7..c57afa9 100644 --- a/mpact/sim/decoder/instruction_encoding.cc +++ b/mpact/sim/decoder/instruction_encoding.cc
@@ -29,13 +29,13 @@ namespace decoder { namespace bin_format { -InstructionEncoding::InstructionEncoding(std::string name, Format *format) +InstructionEncoding::InstructionEncoding(std::string name, Format* format) : name_(name), format_(format) { if (format) format_name_ = format->name(); } // Custom copy constructor. -InstructionEncoding::InstructionEncoding(const InstructionEncoding &encoding) +InstructionEncoding::InstructionEncoding(const InstructionEncoding& encoding) : name_(encoding.name_), format_name_(encoding.format_name_), format_(encoding.format_), @@ -45,42 +45,42 @@ extracted_mask_(encoding.extracted_mask_), value_(encoding.value_) { // Copy construct each of the constraints. - for (auto *constraint : encoding.equal_constraints_) { + for (auto* constraint : encoding.equal_constraints_) { equal_constraints_.push_back(new Constraint(*constraint)); } - for (auto *constraint : encoding.equal_extracted_constraints_) { + for (auto* constraint : encoding.equal_extracted_constraints_) { equal_extracted_constraints_.push_back(new Constraint(*constraint)); } - for (auto *constraint : encoding.other_constraints_) { + for (auto* constraint : encoding.other_constraints_) { other_constraints_.push_back(new Constraint(*constraint)); } } InstructionEncoding::~InstructionEncoding() { - for (auto *constraint : equal_constraints_) { + for (auto* constraint : equal_constraints_) { delete constraint; } equal_constraints_.clear(); - for (auto *constraint : equal_extracted_constraints_) { + for (auto* constraint : equal_extracted_constraints_) { delete constraint; } equal_extracted_constraints_.clear(); - for (auto *constraint : other_constraints_) { + for (auto* constraint : other_constraints_) { delete constraint; } other_constraints_.clear(); - for (auto &[name, enc_ptr] : specializations_) { + for (auto& [name, enc_ptr] : specializations_) { delete enc_ptr; } specializations_.clear(); } -absl::StatusOr<Constraint *> InstructionEncoding::CreateConstraint( +absl::StatusOr<Constraint*> InstructionEncoding::CreateConstraint( ConstraintType type, std::string lhs_name, std::string rhs_name) { Constraint constraint; constraint.type = type; // Check if the field name is indeed a field. - auto *lhs_field = format_->GetField(lhs_name); + auto* lhs_field = format_->GetField(lhs_name); if (lhs_field != nullptr) { if (lhs_field->width >= 64) { return absl::OutOfRangeError(absl::StrCat( @@ -90,7 +90,7 @@ constraint.field = lhs_field; } else { // If not a field, is it an overlay? - auto *lhs_overlay = format_->GetOverlay(lhs_name); + auto* lhs_overlay = format_->GetOverlay(lhs_name); if (lhs_overlay == nullptr) { // If neither, it's an error. return absl::NotFoundError(absl::StrCat( @@ -100,7 +100,7 @@ constraint.overlay = lhs_overlay; } // Check if the field name is indeed a field. - auto *rhs_field = format_->GetField(rhs_name); + auto* rhs_field = format_->GetField(rhs_name); if (rhs_field != nullptr) { if (rhs_field->width >= 64) { return absl::OutOfRangeError(absl::StrCat( @@ -110,7 +110,7 @@ constraint.rhs_field = rhs_field; } else { // If not a field, is it an overlay? - auto *rhs_overlay = format_->GetOverlay(rhs_name); + auto* rhs_overlay = format_->GetOverlay(rhs_name); if (rhs_overlay == nullptr) { // If neither, it's an error. return absl::NotFoundError(absl::StrCat( @@ -119,14 +119,14 @@ } constraint.rhs_overlay = rhs_overlay; } - Constraint *result = new Constraint(constraint); + Constraint* result = new Constraint(constraint); return result; } -absl::StatusOr<Constraint *> InstructionEncoding::CreateConstraint( +absl::StatusOr<Constraint*> InstructionEncoding::CreateConstraint( ConstraintType type, std::string field_name, int64_t value) { // Check if the field name is indeed a field. - auto *field = format_->GetField(field_name); + auto* field = format_->GetField(field_name); if (field != nullptr) { if (field->width >= 64) { return absl::OutOfRangeError(absl::StrCat( @@ -164,14 +164,14 @@ } } value &= (1 << field->width) - 1; - auto *constraint = new Constraint(); + auto* constraint = new Constraint(); constraint->type = type; constraint->field = field; constraint->value = value; return constraint; } // If not a field, is it an overlay? - auto *overlay = format_->GetOverlay(field_name); + auto* overlay = format_->GetOverlay(field_name); if (overlay == nullptr) { // If neither, it's an error. return absl::NotFoundError(absl::StrCat( @@ -208,7 +208,7 @@ } } value &= (1 << width) - 1; - auto *constraint = new Constraint(); + auto* constraint = new Constraint(); constraint->type = type; constraint->overlay = overlay; constraint->value = value; @@ -222,7 +222,7 @@ mask_set_ = false; auto res = CreateConstraint(ConstraintType::kEq, field_name, value); if (!res.ok()) return res.status(); - auto *constraint = res.value(); + auto* constraint = res.value(); if ((constraint->overlay != nullptr) && constraint->overlay->must_be_extracted()) { // If the value is not 100% based on extracted bits (i.e., it is an @@ -241,17 +241,17 @@ int64_t value) { auto res = CreateConstraint(type, field_name, value); if (!res.ok()) return res.status(); - auto *constraint = res.value(); + auto* constraint = res.value(); other_constraints_.push_back(constraint); return absl::OkStatus(); } absl::Status InstructionEncoding::AddOtherConstraint( - ConstraintType type, const std::string &lhs_name, - const std::string &rhs_name) { + ConstraintType type, const std::string& lhs_name, + const std::string& rhs_name) { auto res = CreateConstraint(type, lhs_name, rhs_name); if (!res.ok()) return res.status(); - auto *constraint = res.value(); + auto* constraint = res.value(); other_constraints_.push_back(constraint); return absl::OkStatus(); } @@ -259,7 +259,7 @@ absl::Status InstructionEncoding::ComputeMaskAndValue() { // First consider equal constraints. mask_ = 0; - for (auto *constraint : equal_constraints_) { + for (auto* constraint : equal_constraints_) { uint64_t mask = 0; uint64_t value = 0; if (constraint->field != nullptr) { @@ -279,7 +279,7 @@ } // The overlays with bit constant concatenations. extracted_mask_ = 0; - for (auto *constraint : equal_extracted_constraints_) { + for (auto* constraint : equal_extracted_constraints_) { uint64_t mask = 0; if (constraint->field != nullptr) { int width = constraint->field->width; @@ -293,7 +293,7 @@ } // Other constraints. other_mask_ = 0; - for (auto *constraint : other_constraints_) { + for (auto* constraint : other_constraints_) { uint64_t mask = 0; if (constraint->field != nullptr) { int width = constraint->field->width; @@ -343,7 +343,7 @@ } absl::Status InstructionEncoding::AddSpecialization( - const std::string &name, InstructionEncoding *encoding) { + const std::string& name, InstructionEncoding* encoding) { if (specializations_.contains(name)) { format_->encoding_info()->error_listener()->semanticError( nullptr, absl::StrCat("Duplicate instruction specialization name '",
diff --git a/mpact/sim/decoder/instruction_encoding.h b/mpact/sim/decoder/instruction_encoding.h index 6e7a246..4dcda6e 100644 --- a/mpact/sim/decoder/instruction_encoding.h +++ b/mpact/sim/decoder/instruction_encoding.h
@@ -34,10 +34,10 @@ // Helper struct to group the information of a constraint (either == or !=). struct Constraint { ConstraintType type; - Field *field = nullptr; - Overlay *overlay = nullptr; - Field *rhs_field = nullptr; - Overlay *rhs_overlay = nullptr; + Field* field = nullptr; + Overlay* overlay = nullptr; + Field* rhs_field = nullptr; + Overlay* rhs_overlay = nullptr; bool can_ignore = false; uint64_t value; }; @@ -50,9 +50,9 @@ public: // Disable default constructor and assignment operator. InstructionEncoding() = delete; - InstructionEncoding(std::string name, Format *format); - InstructionEncoding(const InstructionEncoding &encoding); - InstructionEncoding &operator=(const InstructionEncoding &) = delete; + InstructionEncoding(std::string name, Format* format); + InstructionEncoding(const InstructionEncoding& encoding); + InstructionEncoding& operator=(const InstructionEncoding&) = delete; ~InstructionEncoding(); // Add a constraint on a field/overlay (in the format associated with the @@ -65,8 +65,8 @@ // Add a constraint on a field/overlay (in the format associated with the // instruction) that compares against another field/overlay. absl::Status AddOtherConstraint(ConstraintType type, - const std::string &lhs_name, - const std::string &rhs_name); + const std::string& lhs_name, + const std::string& rhs_name); // Get the value of the constant bits in the instruction (as defined by the // equal constraints). @@ -78,63 +78,63 @@ // not equal constraints. uint64_t GetCombinedMask(); // Add specialization to this encoding. - absl::Status AddSpecialization(const std::string &name, - InstructionEncoding *encoding); + absl::Status AddSpecialization(const std::string& name, + InstructionEncoding* encoding); bool HasSpecialization() const { return !specializations_.empty(); } // Accessors. - const std::string &name() const { return name_; } - const std::string &format_name() const { return format_name_; } + const std::string& name() const { return name_; } + const std::string& format_name() const { return format_name_; } // Return the vector of constraints on the values of this encoding. These // constraints determine the value that a masked set of bits have to be equal // to in order to match this encoding. - const std::vector<Constraint *> &equal_constraints() const { + const std::vector<Constraint*>& equal_constraints() const { return equal_constraints_; } // Additionally, overlays may add constant bits to field references. These // constraints have to be compared one by one after performing an overlay // extraction that adds in the bits as specified in the overlay. Thus, they // cannot be used in a simple mask and compare. - const std::vector<Constraint *> &equal_extracted_constraints() const { + const std::vector<Constraint*>& equal_extracted_constraints() const { return equal_extracted_constraints_; } // The vector of not-equal, greater, less, etc., constraints that have to be // satisfied for an instruction to match this encoding. - const std::vector<Constraint *> &other_constraints() const { + const std::vector<Constraint*>& other_constraints() const { return other_constraints_; } - const absl::btree_map<std::string, InstructionEncoding *> &specializations() + const absl::btree_map<std::string, InstructionEncoding*>& specializations() const { return specializations_; } - Format *format() const { return format_; } + Format* format() const { return format_; } private: // Internal helper to create and check a constraint. - absl::StatusOr<Constraint *> CreateConstraint(ConstraintType type, - std::string lhs_name, - std::string rhs_name); + absl::StatusOr<Constraint*> CreateConstraint(ConstraintType type, + std::string lhs_name, + std::string rhs_name); - absl::StatusOr<Constraint *> CreateConstraint(ConstraintType type, - std::string field_name, - int64_t value); + absl::StatusOr<Constraint*> CreateConstraint(ConstraintType type, + std::string field_name, + int64_t value); // Recomputes the masks and values. absl::Status ComputeMaskAndValue(); std::string name_; std::string format_name_; - Format *format_ = nullptr; - std::vector<Constraint *> equal_constraints_; - std::vector<Constraint *> equal_extracted_constraints_; - std::vector<Constraint *> other_constraints_; + Format* format_ = nullptr; + std::vector<Constraint*> equal_constraints_; + std::vector<Constraint*> equal_extracted_constraints_; + std::vector<Constraint*> other_constraints_; bool mask_set_ = false; uint64_t mask_ = 0; uint64_t other_mask_ = 0; uint64_t extracted_mask_ = 0; uint64_t value_ = 0; - absl::btree_map<std::string, InstructionEncoding *> specializations_; + absl::btree_map<std::string, InstructionEncoding*> specializations_; }; } // namespace bin_format
diff --git a/mpact/sim/decoder/instruction_group.cc b/mpact/sim/decoder/instruction_group.cc index 527c0f4..294a5da 100644 --- a/mpact/sim/decoder/instruction_group.cc +++ b/mpact/sim/decoder/instruction_group.cc
@@ -42,7 +42,7 @@ InstructionGroup::InstructionGroup(std::string name, int width, std::string format_name, std::string opcode_enum, - BinEncodingInfo *encoding_info) + BinEncodingInfo* encoding_info) : name_(name), width_(width), format_name_(format_name), @@ -52,12 +52,12 @@ } InstructionGroup::~InstructionGroup() { - for (auto *enc : encoding_vec_) { + for (auto* enc : encoding_vec_) { delete enc; } encoding_map_.clear(); encoding_vec_.clear(); - for (auto *group : encoding_group_vec_) { + for (auto* group : encoding_group_vec_) { delete group; } encoding_group_vec_.clear(); @@ -66,8 +66,8 @@ // Add an instruction encoding into the current group. Check that the format // has the correct width, and that the format the encoding is defined in, or // derives from the format associated with the instruction group. -InstructionEncoding *InstructionGroup::AddInstructionEncoding( - antlr4::Token *token, std::string name, Format *format) { +InstructionEncoding* InstructionGroup::AddInstructionEncoding( + antlr4::Token* token, std::string name, Format* format) { if ((format != nullptr) && ((format_ == nullptr) || (!format->IsDerivedFrom(format_)))) { encoding_info_->error_listener()->semanticError( @@ -88,13 +88,13 @@ token, absl::StrCat("Duplicate instruction opcode name '", name, "' in group '", this->name(), "'.")); } - auto *encoding = new InstructionEncoding(name, format); + auto* encoding = new InstructionEncoding(name, format); encoding_vec_.push_back(encoding); encoding_name_map_.insert(std::make_pair(name, encoding)); return encoding; } -void InstructionGroup::AddInstructionEncoding(InstructionEncoding *encoding) { +void InstructionGroup::AddInstructionEncoding(InstructionEncoding* encoding) { if (encoding_name_map_.contains(encoding->name())) { encoding_info_->error_listener()->semanticWarning( nullptr, absl::StrCat("Duplicate instruction opcode name '", @@ -113,13 +113,13 @@ } // Insert the encodings into a map based on the mask value - grouping // instructions with the same mask. - for (auto *enc : encoding_vec_) { + for (auto* enc : encoding_vec_) { encoding_map_.insert(std::make_pair(enc->GetMask(), enc)); } encoding_group_vec_.push_back(new EncodingGroup(this, 0)); - for (auto &[unused, enc_ptr] : encoding_map_) { + for (auto& [unused, enc_ptr] : encoding_map_) { bool is_added = false; - for (auto *group : encoding_group_vec_) { + for (auto* group : encoding_group_vec_) { if (group->CanAddEncoding(enc_ptr)) { group->AddEncoding(enc_ptr); is_added = true; @@ -132,21 +132,21 @@ is_added = true; } } - for (auto *grp : encoding_group_vec_) { + for (auto* grp : encoding_group_vec_) { grp->AddSubGroups(); } } // Check for encoding errors. void InstructionGroup::CheckEncodings() { - for (auto *enc_grp : encoding_group_vec_) { + for (auto* enc_grp : encoding_group_vec_) { enc_grp->CheckEncodings(); } } absl::Status InstructionGroup::AddSpecialization( - const std::string &name, const std::string &parent_name, - InstructionEncoding *encoding) { + const std::string& name, const std::string& parent_name, + InstructionEncoding* encoding) { if (encoding_name_map_.contains(name)) { encoding_info_->error_listener()->semanticError( nullptr, @@ -157,12 +157,12 @@ "' in group '", this->name(), "'.")); } encoding_name_map_.insert(std::make_pair(name, encoding)); - auto *parent_encoding = encoding_name_map_.at(parent_name); + auto* parent_encoding = encoding_name_map_.at(parent_name); return parent_encoding->AddSpecialization(name, encoding); } // Helper function used to sort the instruction group elements in a vector. -static bool InstructionGroupLess(EncodingGroup *lhs, EncodingGroup *rhs) { +static bool InstructionGroupLess(EncodingGroup* lhs, EncodingGroup* rhs) { uint64_t lhs_value = 0; uint64_t rhs_value = 0; if (lhs->parent() == nullptr) { @@ -210,7 +210,7 @@ format_->uint_type_name(), ") {\n return std::make_pair(", opcode_enum_, "::kNone, FormatEnum::kNone);\n}\n\n"); for (size_t i = 0; i < encoding_group_vec_.size(); i++) { - auto *grp = encoding_group_vec_[i]; + auto* grp = encoding_group_vec_[i]; std::string name = absl::StrCat(this->name(), "_", absl::Hex(i)); grp->EmitInitializers(name, &initializers, opcode_enum_); grp->EmitDecoders(name, &declarations, &definitions, opcode_enum_); @@ -242,8 +242,8 @@ // Emit code to encode the instructions in the group. void InstructionGroup::GetInstructionEncodings( - absl::btree_map<std::string, std::tuple<uint64_t, int>> &encodings) { - for (auto *enc : encoding_vec_) { + absl::btree_map<std::string, std::tuple<uint64_t, int>>& encodings) { + for (auto* enc : encoding_vec_) { encodings.insert(std::make_pair(ToPascalCase(enc->name()), std::make_tuple(enc->GetValue(), width()))); } @@ -272,12 +272,12 @@ break; } uint64_t common_mask = 0xffff'ffff'ffff'ffff; - for (auto &[key, unused] : encoding_map_) { + for (auto& [key, unused] : encoding_map_) { common_mask &= key; } absl::StrAppend(&output, "// common bits: ", absl::Hex(common_mask, pad), "\n"); - for (auto *grp : encoding_group_vec_) { + for (auto* grp : encoding_group_vec_) { absl::StrAppend(&output, grp->DumpGroup("", " ")); } return output;
diff --git a/mpact/sim/decoder/instruction_group.h b/mpact/sim/decoder/instruction_group.h index f235daa..943c1f5 100644 --- a/mpact/sim/decoder/instruction_group.h +++ b/mpact/sim/decoder/instruction_group.h
@@ -43,12 +43,12 @@ public: InstructionGroup() = default; InstructionGroup(std::string name, int width, std::string format_name, - std::string opcode_enum, BinEncodingInfo *encoding_info); + std::string opcode_enum, BinEncodingInfo* encoding_info); ~InstructionGroup(); - InstructionEncoding *AddInstructionEncoding(antlr4::Token *token, - std::string name, Format *format); - void AddInstructionEncoding(InstructionEncoding *encoding); + InstructionEncoding* AddInstructionEncoding(antlr4::Token* token, + std::string name, Format* format); + void AddInstructionEncoding(InstructionEncoding* encoding); // Process the encodings in the group, partitioning them into subgroups // according to their opcode bits to make it easy to generate a hierarchical // decoding tree. @@ -59,42 +59,42 @@ std::tuple<std::string, std::string> EmitDecoderCode(); // Collect the encodings for these instructions. void GetInstructionEncodings( - absl::btree_map<std::string, std::tuple<uint64_t, int>> &encodings); + absl::btree_map<std::string, std::tuple<uint64_t, int>>& encodings); // Return a string containing information about this instruction group and // how it has been partitioned across encoding groups. std::string WriteGroup(); // Add a specialization to this instruction group. - absl::Status AddSpecialization(const std::string &name, - const std::string &parent_name, - InstructionEncoding *encoding); + absl::Status AddSpecialization(const std::string& name, + const std::string& parent_name, + InstructionEncoding* encoding); // Accessors. - const std::string &name() const { return name_; } - const std::string &format_name() const { return format_name_; } - const std::string &opcode_enum() const { return opcode_enum_; } - const std::vector<InstructionEncoding *> &encoding_vec() const { + const std::string& name() const { return name_; } + const std::string& format_name() const { return format_name_; } + const std::string& opcode_enum() const { return opcode_enum_; } + const std::vector<InstructionEncoding*>& encoding_vec() const { return encoding_vec_; } int width() const { return width_; } - BinEncodingInfo *encoding_info() const { return encoding_info_; } - const absl::flat_hash_map<std::string, InstructionEncoding *> & + BinEncodingInfo* encoding_info() const { return encoding_info_; } + const absl::flat_hash_map<std::string, InstructionEncoding*>& encoding_name_map() const { return encoding_name_map_; } - Format *format() const { return format_; } + Format* format() const { return format_; } private: std::string name_; int width_; std::string format_name_; - Format *format_; + Format* format_; std::string opcode_enum_; - BinEncodingInfo *encoding_info_; - std::vector<InstructionEncoding *> encoding_vec_; - absl::flat_hash_map<std::string, InstructionEncoding *> encoding_name_map_; - absl::btree_multimap<uint64_t, InstructionEncoding *> encoding_map_; - std::vector<EncodingGroup *> encoding_group_vec_; + BinEncodingInfo* encoding_info_; + std::vector<InstructionEncoding*> encoding_vec_; + absl::flat_hash_map<std::string, InstructionEncoding*> encoding_name_map_; + absl::btree_multimap<uint64_t, InstructionEncoding*> encoding_map_; + std::vector<EncodingGroup*> encoding_group_vec_; }; } // namespace bin_format
diff --git a/mpact/sim/decoder/instruction_set.cc b/mpact/sim/decoder/instruction_set.cc index 287f9b8..710326d 100644 --- a/mpact/sim/decoder/instruction_set.cc +++ b/mpact/sim/decoder/instruction_set.cc
@@ -38,12 +38,12 @@ namespace machine_description { namespace instruction_set { -absl::btree_set<std::string> *InstructionSet::attribute_names_ = nullptr; +absl::btree_set<std::string>* InstructionSet::attribute_names_ = nullptr; -static void EmitEnumNames(const absl::btree_set<std::string> &names, +static void EmitEnumNames(const absl::btree_set<std::string>& names, absl::string_view namespace_name, - absl::string_view op_name, std::string &h_output, - std::string &cc_output) { + absl::string_view op_name, std::string& h_output, + std::string& cc_output) { // Emit array of enum names. absl::StrAppend(&cc_output, "const char *k", op_name, "Names[static_cast<int>(", op_name, @@ -53,7 +53,7 @@ absl::StrAppend(&h_output, "namespace ", namespace_name, " {\n" " constexpr char kNoneName[] = \"none\";\n"); - for (auto const &name : names) { + for (auto const& name : names) { absl::StrAppend(&h_output, " constexpr char k", name, "Name[] = \"", name, "\";\n"); absl::StrAppend(&cc_output, " ", namespace_name, "::k", name, "Name,\n"); @@ -74,41 +74,41 @@ InstructionSet::~InstructionSet() { delete bundle_; - for (auto &[unused, bundle_ptr] : bundle_map_) { + for (auto& [unused, bundle_ptr] : bundle_map_) { delete bundle_ptr; } - for (auto &[unused, slot_ptr] : slot_map_) { + for (auto& [unused, slot_ptr] : slot_map_) { delete slot_ptr; } bundle_map_.clear(); slot_map_.clear(); } -void InstructionSet::AddBundle(Bundle *bundle) { +void InstructionSet::AddBundle(Bundle* bundle) { bundle_map_.insert({bundle->name(), bundle}); } -void InstructionSet::AddSlot(Slot *slot) { +void InstructionSet::AddSlot(Slot* slot) { slot_map_.insert({slot->name(), slot}); } // Lookup bundle and slot by name. -Bundle *InstructionSet::GetBundle(absl::string_view bundle_name) const { +Bundle* InstructionSet::GetBundle(absl::string_view bundle_name) const { auto iter = bundle_map_.find(bundle_name); if (iter == bundle_map_.end()) return nullptr; return iter->second; } -Slot *InstructionSet::GetSlot(absl::string_view slot_name) const { +Slot* InstructionSet::GetSlot(absl::string_view slot_name) const { auto iter = slot_map_.find(slot_name); if (iter == slot_map_.end()) return nullptr; return iter->second; } absl::Status InstructionSet::AnalyzeResourceUse() { - for (auto const *slot : slot_order_) { - for (auto &[unused, inst_ptr] : slot->instruction_map()) { - for (auto const *def : inst_ptr->resource_acquire_vec()) { + for (auto const* slot : slot_order_) { + for (auto& [unused, inst_ptr] : slot->instruction_map()) { + for (auto const* def : inst_ptr->resource_acquire_vec()) { if (def->begin_expression != nullptr) { auto result = def->begin_expression->GetValue(); if (!result.ok()) return result.status(); @@ -128,38 +128,38 @@ void InstructionSet::ComputeSlotAndBundleOrders() { // Compute order of slot definitions - for (auto const &[unused, slot_ptr] : slot_map_) { + for (auto const& [unused, slot_ptr] : slot_map_) { if (slot_ptr->is_marked()) continue; AddToSlotOrder(slot_ptr); } // Compute order of bundle definitions - for (auto const &[unused, bundle_ptr] : bundle_map_) { + for (auto const& [unused, bundle_ptr] : bundle_map_) { if (bundle_ptr->is_marked()) continue; AddToBundleOrder(bundle_ptr); } } -void InstructionSet::AddToBundleOrder(Bundle *bundle) { +void InstructionSet::AddToBundleOrder(Bundle* bundle) { if (bundle->is_marked()) return; - for (auto const &bundle_name : bundle->bundle_names()) { - Bundle *sub_bundle = bundle_map_[bundle_name]; + for (auto const& bundle_name : bundle->bundle_names()) { + Bundle* sub_bundle = bundle_map_[bundle_name]; AddToBundleOrder(sub_bundle); } bundle_order_.push_back(bundle); bundle->set_is_marked(true); } -void InstructionSet::AddToSlotOrder(Slot *slot) { +void InstructionSet::AddToSlotOrder(Slot* slot) { if (slot->is_marked()) return; - for (auto const &base_slot : slot->base_slots()) { + for (auto const& base_slot : slot->base_slots()) { AddToSlotOrder(slot_map_[base_slot.base->name()]); } slot->set_is_marked(true); slot_order_.push_back(slot); } -void InstructionSet::AddAttributeName(const std::string &name) { +void InstructionSet::AddAttributeName(const std::string& name) { if (attribute_names_ == nullptr) { attribute_names_ = new absl::btree_set<std::string>(); } @@ -302,11 +302,11 @@ std::string factory_class_name = pascal_name() + "InstructionSetFactory"; absl::StrAppend(&output, "class ", factory_class_name, ";\n"); - for (auto const *slot : slot_order_) { + for (auto const* slot : slot_order_) { absl::StrAppend(&output, slot->GenerateClassDeclaration(encoding_type)); } - for (auto const *bundle : bundle_order_) { + for (auto const* bundle : bundle_order_) { absl::StrAppend(&output, bundle->GenerateClassDeclaration(encoding_type)); } // Generate factory class. @@ -352,11 +352,11 @@ " *encoding);\n" "\n" " private:\n"); - for (auto const &bundle_name : bundle_->bundle_names()) { + for (auto const& bundle_name : bundle_->bundle_names()) { absl::StrAppend(&output, " std::unique_ptr<", ToPascalCase(bundle_name), "Decoder> ", bundle_name, "_decoder_;\n"); } - for (auto const &[slot_name, unused] : bundle_->slot_uses()) { + for (auto const& [slot_name, unused] : bundle_->slot_uses()) { absl::StrAppend(&output, " std::unique_ptr<", ToPascalCase(slot_name), "Slot> ", slot_name, "_decoder_;\n"); } @@ -374,7 +374,7 @@ std::string class_name = pascal_name() + "InstructionSet"; std::string factory_class_name = class_name + "Factory"; - for (auto *slot : slot_order_) { + for (auto* slot : slot_order_) { absl::StrAppend(&output, slot->GenerateClassDefinition(encoding_type)); } // Constructor. @@ -382,11 +382,11 @@ "(ArchState *arch_state, ", factory_class_name, "*factory) : \n" " arch_state_(arch_state) {\n"); - for (auto const &bundle_name : bundle_->bundle_names()) { + for (auto const& bundle_name : bundle_->bundle_names()) { absl::StrAppend(&output, " ", bundle_name, "_decoder_ = factory->Create", ToPascalCase(bundle_name), "Decoder(arch_state_);\n"); } - for (auto const &[slot_name, unused] : bundle_->slot_uses()) { + for (auto const& [slot_name, unused] : bundle_->slot_uses()) { absl::StrAppend(&output, " ", slot_name, "_decoder_ = factory->Create", ToPascalCase(slot_name), "Slot(arch_state_);\n"); } @@ -410,7 +410,7 @@ absl::StrAppend(&output, " inst = new Instruction(address, arch_state_);\n"); // Generate calls to each of the top level bundle Decode methods. - for (auto const &bundle_name : bundle_->bundle_names()) { + for (auto const& bundle_name : bundle_->bundle_names()) { absl::StrAppend(&output, " tmp_inst = ", bundle_name, "_decoder_->Decode(address, encoding);\n" " inst->AppendChild(tmp_inst);\n" @@ -420,7 +420,7 @@ } } // Generate calls to each of the top level slot Decode methods. - for (auto const &[slot_name, instance_vec] : bundle_->slot_uses()) { + for (auto const& [slot_name, instance_vec] : bundle_->slot_uses()) { std::string enum_name = absl::StrCat("SlotEnum::", "k", ToPascalCase(slot_name)); if (instance_vec.empty()) { @@ -473,14 +473,14 @@ absl::StrAppend(&h_output, " enum class SlotEnum {\n" " kNone = 0,\n"); - absl::btree_map<std::string, const Slot *> slots_by_name; - for (auto const *slot : slot_order_) { + absl::btree_map<std::string, const Slot*> slots_by_name; + for (auto const* slot : slot_order_) { if (slot->is_referenced()) { std::string name = slot->pascal_name(); slots_by_name.emplace(name, slot); } } - for (auto const &[name, unused] : slots_by_name) { + for (auto const& [name, unused] : slots_by_name) { absl::StrAppend(&h_output, " k", name, ",\n"); } absl::StrAppend(&h_output, " };\n\n"); @@ -493,23 +493,23 @@ absl::btree_set<std::string> list_dest_operands; absl::btree_set<std::string> dest_latency; // Insert PascalCase operand names into the sets to select unique names. - for (auto const &[unused, slot] : slots_by_name) { + for (auto const& [unused, slot] : slots_by_name) { // Slot specific operands. absl::btree_set<std::string> slot_predicate_operands; absl::btree_set<std::string> slot_source_operands; absl::btree_set<std::string> slot_list_source_operands; absl::btree_set<std::string> slot_dest_operands; absl::btree_set<std::string> slot_list_dest_operands; - for (auto const &[unused, inst_ptr] : slot->instruction_map()) { - auto *inst = inst_ptr; + for (auto const& [unused, inst_ptr] : slot->instruction_map()) { + auto* inst = inst_ptr; while (inst != nullptr) { - auto *opcode = inst->opcode(); + auto* opcode = inst->opcode(); if (!opcode->predicate_op_name().empty()) { predicate_operands.insert(ToPascalCase(opcode->predicate_op_name())); slot_predicate_operands.insert( ToPascalCase(opcode->predicate_op_name())); } - for (auto const &source_op : opcode->source_op_vec()) { + for (auto const& source_op : opcode->source_op_vec()) { if (source_op.is_array) { list_source_operands.insert(ToPascalCase(source_op.name)); slot_list_source_operands.insert(ToPascalCase(source_op.name)); @@ -518,7 +518,7 @@ slot_source_operands.insert(ToPascalCase(source_op.name)); } } - for (auto const *dest_op : opcode->dest_op_vec()) { + for (auto const* dest_op : opcode->dest_op_vec()) { if (dest_op->is_array()) { list_dest_operands.insert(dest_op->pascal_case_name()); slot_list_dest_operands.insert(dest_op->pascal_case_name()); @@ -539,7 +539,7 @@ absl::StrAppend(&h_output, " enum class ", slot_name, "PredOpEnum {\n"); int pred_count = 0; absl::StrAppend(&h_output, " kNone = ", pred_count++, ",\n"); - for (auto const &pred_name : slot_predicate_operands) { + for (auto const& pred_name : slot_predicate_operands) { pred_op_map_.insert({pred_name, pred_count}); absl::StrAppend(&h_output, " k", pred_name, " = ", pred_count++, ",\n"); @@ -551,7 +551,7 @@ absl::StrAppend(&h_output, " enum class ", slot_name, "SourceOpEnum {\n"); int src_count = 0; absl::StrAppend(&h_output, " kNone = ", src_count++, ",\n"); - for (auto const &source_name : slot_source_operands) { + for (auto const& source_name : slot_source_operands) { source_op_map_.insert({source_name, src_count}); absl::StrAppend(&h_output, " k", source_name, " = ", src_count++, ",\n"); @@ -564,7 +564,7 @@ "ListSourceOpEnum {\n"); int list_src_count = 0; absl::StrAppend(&h_output, " kNone = ", list_src_count++, ",\n"); - for (auto const &source_name : slot_list_source_operands) { + for (auto const& source_name : slot_list_source_operands) { list_source_op_map_.insert({source_name, list_src_count}); absl::StrAppend(&h_output, " k", source_name, " = ", list_src_count++, ",\n"); @@ -576,7 +576,7 @@ absl::StrAppend(&h_output, " enum class ", slot_name, "DestOpEnum {\n"); int dst_count = 0; absl::StrAppend(&h_output, " kNone = ", dst_count++, ",\n"); - for (auto const &dest_name : slot_dest_operands) { + for (auto const& dest_name : slot_dest_operands) { dest_op_map_.insert({dest_name, dst_count}); absl::StrAppend(&h_output, " k", dest_name, " = ", dst_count++, ",\n"); } @@ -588,7 +588,7 @@ "ListDestOpEnum {\n"); int list_dst_count = 0; absl::StrAppend(&h_output, " kNone = ", list_dst_count++, ",\n"); - for (auto const &dest_name : slot_list_dest_operands) { + for (auto const& dest_name : slot_list_dest_operands) { list_dest_op_map_.insert({dest_name, list_dst_count}); absl::StrAppend(&h_output, " k", dest_name, " = ", list_dst_count++, ",\n"); @@ -604,7 +604,7 @@ absl::StrAppend(&h_output, " enum class PredOpEnum {\n"); int pred_count = 0; absl::StrAppend(&h_output, " kNone = ", pred_count++, ",\n"); - for (auto const &pred_name : predicate_operands) { + for (auto const& pred_name : predicate_operands) { pred_op_map_.insert({pred_name, pred_count}); absl::StrAppend(&h_output, " k", pred_name, " = ", pred_count++, ",\n"); } @@ -615,7 +615,7 @@ absl::StrAppend(&h_output, " enum class SourceOpEnum {\n"); int src_count = 0; absl::StrAppend(&h_output, " kNone = ", src_count++, ",\n"); - for (auto const &source_name : source_operands) { + for (auto const& source_name : source_operands) { source_op_map_.insert({source_name, src_count}); absl::StrAppend(&h_output, " k", source_name, " = ", src_count++, ",\n"); } @@ -626,7 +626,7 @@ absl::StrAppend(&h_output, " enum class ListSourceOpEnum {\n"); int list_src_count = 0; absl::StrAppend(&h_output, " kNone = ", list_src_count++, ",\n"); - for (auto const &source_name : list_source_operands) { + for (auto const& source_name : list_source_operands) { list_source_op_map_.insert({source_name, list_src_count}); absl::StrAppend(&h_output, " k", source_name, " = ", list_src_count++, ",\n"); @@ -638,7 +638,7 @@ absl::StrAppend(&h_output, " enum class DestOpEnum {\n"); int dst_count = 0; absl::StrAppend(&h_output, " kNone = ", dst_count++, ",\n"); - for (auto const &dest_name : dest_operands) { + for (auto const& dest_name : dest_operands) { dest_op_map_.insert({dest_name, dst_count}); absl::StrAppend(&h_output, " k", dest_name, " = ", dst_count++, ",\n"); } @@ -649,7 +649,7 @@ absl::StrAppend(&h_output, " enum class ListDestOpEnum {\n"); int list_dst_count = 0; absl::StrAppend(&h_output, " kNone = ", list_dst_count++, ",\n"); - for (auto const &dest_name : list_dest_operands) { + for (auto const& dest_name : list_dest_operands) { list_dest_op_map_.insert({dest_name, list_dst_count}); absl::StrAppend(&h_output, " k", dest_name, " = ", list_dst_count++, ",\n"); @@ -662,11 +662,11 @@ " enum class OpcodeEnum {\n" " kNone = 0,\n"); absl::btree_set<std::string> name_set; - for (auto const *opcode : opcode_factory_->opcode_vec()) { + for (auto const* opcode : opcode_factory_->opcode_vec()) { name_set.insert(opcode->pascal_name()); } int opcode_value = 1; - for (auto const &name : name_set) { + for (auto const& name : name_set) { absl::StrAppend(&h_output, " k", name, " = ", opcode_value++, ",\n"); } absl::StrAppend(&h_output, " kPastMaxValue = ", opcode_value, "\n"); @@ -687,7 +687,7 @@ "OpcodeEnum::kPastMaxValue)] = {\n" " kNoneName,\n"); absl::StrAppend(&h_output, " constexpr char kNoneName[] = \"none\";\n"); - for (auto const &name : name_set) { + for (auto const& name : name_set) { absl::StrAppend(&h_output, " constexpr char k", name, "Name[] = \"", name, "\";\n"); absl::StrAppend(&cc_output, " k", name, "Name,\n"); @@ -702,12 +702,12 @@ " kNone = 0,\n"); int resource_count = 1; name_set.clear(); - for (auto const &[unused, resource_ptr] : resource_factory_->resource_map()) { + for (auto const& [unused, resource_ptr] : resource_factory_->resource_map()) { if (resource_ptr->is_simple()) { name_set.insert(resource_ptr->pascal_name()); } } - for (auto const &name : name_set) { + for (auto const& name : name_set) { absl::StrAppend(&h_output, " k", name, " = ", resource_count++, ",\n"); } absl::StrAppend(&h_output, " kPastMaxValue = ", resource_count, @@ -720,12 +720,12 @@ " kNone = 0,\n"); resource_count = 1; name_set.clear(); - for (auto const &[unused, resource_ptr] : resource_factory_->resource_map()) { + for (auto const& [unused, resource_ptr] : resource_factory_->resource_map()) { if (!resource_ptr->is_simple() && !resource_ptr->is_array()) { name_set.insert(resource_ptr->pascal_name()); } } - for (auto const &name : name_set) { + for (auto const& name : name_set) { absl::StrAppend(&h_output, " k", name, " = ", resource_count++, ",\n"); } absl::StrAppend(&h_output, " kPastMaxValue = ", resource_count, @@ -738,12 +738,12 @@ " kNone = 0,\n"); resource_count = 1; name_set.clear(); - for (auto const &[unused, resource_ptr] : resource_factory_->resource_map()) { + for (auto const& [unused, resource_ptr] : resource_factory_->resource_map()) { if (!resource_ptr->is_simple() && resource_ptr->is_array()) { name_set.insert(resource_ptr->pascal_name()); } } - for (auto const &name : name_set) { + for (auto const& name : name_set) { absl::StrAppend(&h_output, " k", name, " = ", resource_count++, ",\n"); } absl::StrAppend(&h_output, " kPastMaxValue = ", resource_count, @@ -754,7 +754,7 @@ absl::StrAppend(&h_output, " enum class AttributeEnum {\n"); int attribute_count = 0; if (InstructionSet::attribute_names_ != nullptr) { - for (auto const &name : *InstructionSet::attribute_names_) { + for (auto const& name : *InstructionSet::attribute_names_) { absl::StrAppend(&h_output, " k", ToPascalCase(name), " = ", attribute_count++, ",\n"); } @@ -766,8 +766,8 @@ } std::string InstructionSet::GenerateOperandEncoder( - int position, absl::string_view op_name, const OperandLocator &locator, - const Opcode *opcode) const { + int position, absl::string_view op_name, const OperandLocator& locator, + const Opcode* opcode) const { std::string output; switch (locator.type) { case OperandLocator::kPredicate: { @@ -931,10 +931,10 @@ "&, ResolverInterface *, std::vector<RelocationInfo> &);\n" "EncodeFcn encode_fcns[] = {\n" " EncodeNone,\n"); - for (auto &[name, inst_ptr] : instruction_map_) { + for (auto& [name, inst_ptr] : instruction_map_) { std::string prefix; std::string suffix; - auto *opcode = inst_ptr->opcode(); + auto* opcode = inst_ptr->opcode(); absl::StrAppend(&array, " Encode", opcode->pascal_name(), ",\n"); absl::StrAppend(&prefix, "absl::StatusOr<std::tuple<uint64_t, int>> Encode", opcode->pascal_name(), "(\n ", encoder, @@ -951,8 +951,8 @@ " auto [encoding, bit_size] = res_opcode.value();\n" " absl::StatusOr<uint64_t> result;\n"); int position = 0; - for (auto const *disasm_format : inst_ptr->disasm_format_vec()) { - for (auto const *format_info : disasm_format->format_info_vec) { + for (auto const* disasm_format : inst_ptr->disasm_format_vec()) { + for (auto const* format_info : disasm_format->format_info_vec) { if (format_info->op_name.empty()) continue; auto iter = opcode->op_locator_map().find(format_info->op_name); if (iter == opcode->op_locator_map().end()) { @@ -1001,7 +1001,7 @@ "};\n\n"); // Generate the regex matchers for each slot. - for (auto *slot : slot_order_) { + for (auto* slot : slot_order_) { if (!slot->is_referenced()) continue; auto [h_slot, cc_slot] = slot->GenerateAsmRegexMatcher(); absl::StrAppend(&h_output, h_slot);
diff --git a/mpact/sim/decoder/instruction_set.h b/mpact/sim/decoder/instruction_set.h index 0db705c..a1a2efc 100644 --- a/mpact/sim/decoder/instruction_set.h +++ b/mpact/sim/decoder/instruction_set.h
@@ -52,14 +52,14 @@ virtual ~InstructionSet(); // Add bundle and slot to instruction set. - void AddBundle(Bundle *bundle); - void AddSlot(Slot *slot); + void AddBundle(Bundle* bundle); + void AddSlot(Slot* slot); void PrependNamespace(absl::string_view namespace_name); // Look up bundle and slot names and return pointers to their respective // objects. If not found, return nullptr. - Bundle *GetBundle(absl::string_view) const; - Slot *GetSlot(absl::string_view) const; + Bundle* GetBundle(absl::string_view) const; + Slot* GetSlot(absl::string_view) const; // Compute the set of reachable bundles and slots. void ComputeSlotAndBundleOrders(); // Analyze the resource use in the opcodes in the slots. This is done to @@ -80,40 +80,40 @@ // defined. StringPair GenerateEnums(absl::string_view file_name); - static void AddAttributeName(const std::string &name); + static void AddAttributeName(const std::string& name); - void AddInstruction(Instruction *inst) { + void AddInstruction(Instruction* inst) { if (instruction_map_.contains(inst->opcode()->name())) return; instruction_map_.emplace(inst->opcode()->name(), inst); } // Getters and setters. - std::vector<std::string> &namespaces() { return namespaces_; } - const std::string &name() const { return name_; } - const std::string &pascal_name() const { return pascal_name_; } - void set_bundle(Bundle *bundle) { bundle_ = bundle; } - Bundle *bundle() { return bundle_; } - OpcodeFactory *opcode_factory() const { return opcode_factory_.get(); } - ResourceFactory *resource_factory() const { return resource_factory_.get(); } + std::vector<std::string>& namespaces() { return namespaces_; } + const std::string& name() const { return name_; } + const std::string& pascal_name() const { return pascal_name_; } + void set_bundle(Bundle* bundle) { bundle_ = bundle; } + Bundle* bundle() { return bundle_; } + OpcodeFactory* opcode_factory() const { return opcode_factory_.get(); } + ResourceFactory* resource_factory() const { return resource_factory_.get(); } // Attribute names are shared across the isa's. - static const absl::btree_set<std::string> *attribute_names() { + static const absl::btree_set<std::string>* attribute_names() { return attribute_names_; } - absl::flat_hash_map<std::string, Bundle *> &bundle_map() { + absl::flat_hash_map<std::string, Bundle*>& bundle_map() { return bundle_map_; } - absl::flat_hash_map<std::string, Slot *> &slot_map() { return slot_map_; } + absl::flat_hash_map<std::string, Slot*>& slot_map() { return slot_map_; } // Maps from operand names to enum values. - absl::flat_hash_map<std::string, int> &pred_op_map() { return pred_op_map_; } - absl::flat_hash_map<std::string, int> &source_op_map() { + absl::flat_hash_map<std::string, int>& pred_op_map() { return pred_op_map_; } + absl::flat_hash_map<std::string, int>& source_op_map() { return source_op_map_; } - absl::flat_hash_map<std::string, int> &list_source_op_map() { + absl::flat_hash_map<std::string, int>& list_source_op_map() { return list_source_op_map_; } - absl::flat_hash_map<std::string, int> &dest_op_map() { return dest_op_map_; } - absl::flat_hash_map<std::string, int> &list_dest_op_map() { + absl::flat_hash_map<std::string, int>& dest_op_map() { return dest_op_map_; } + absl::flat_hash_map<std::string, int>& list_dest_op_map() { return list_dest_op_map_; } @@ -121,28 +121,28 @@ private: std::string GenerateOperandEncoder(int position, absl::string_view op_name, - const OperandLocator &locator, - const Opcode *opcode) const; + const OperandLocator& locator, + const Opcode* opcode) const; // Add bundle and slot to list of classes that need to be generated. - void AddToBundleOrder(Bundle *); - void AddToSlotOrder(Slot *); + void AddToBundleOrder(Bundle*); + void AddToSlotOrder(Slot*); // Data members. std::vector<std::string> namespaces_; - std::vector<Slot *> slot_order_; - std::vector<Bundle *> bundle_order_; + std::vector<Slot*> slot_order_; + std::vector<Bundle*> bundle_order_; std::unique_ptr<OpcodeFactory> opcode_factory_; std::unique_ptr<ResourceFactory> resource_factory_; std::string name_; // Name in PascalCase. std::string pascal_name_; - Bundle *bundle_ = nullptr; + Bundle* bundle_ = nullptr; // Map from instruction name to pointer. - absl::btree_map<std::string, Instruction *> instruction_map_; + absl::btree_map<std::string, Instruction*> instruction_map_; // Maps from names to bundle/slot pointers. - absl::flat_hash_map<std::string, Bundle *> bundle_map_; - absl::flat_hash_map<std::string, Slot *> slot_map_; + absl::flat_hash_map<std::string, Bundle*> bundle_map_; + absl::flat_hash_map<std::string, Slot*> slot_map_; // Attribute name list - shared across all the isas. - static absl::btree_set<std::string> *attribute_names_; + static absl::btree_set<std::string>* attribute_names_; // Maps from operand names to enum values. absl::flat_hash_map<std::string, int> pred_op_map_; absl::flat_hash_map<std::string, int> source_op_map_;
diff --git a/mpact/sim/decoder/instruction_set_visitor.cc b/mpact/sim/decoder/instruction_set_visitor.cc index ed68626..fd5d6f5 100644 --- a/mpact/sim/decoder/instruction_set_visitor.cc +++ b/mpact/sim/decoder/instruction_set_visitor.cc
@@ -57,7 +57,7 @@ namespace instruction_set { static absl::StatusOr<TemplateValue> AbsoluteValueTemplateFunc( - TemplateInstantiationArgs *args) { + TemplateInstantiationArgs* args) { if (args->size() != 1) { return absl::InternalError(absl::StrCat( "Wrong number of arguments, expected 1, was given ", args->size())); @@ -65,7 +65,7 @@ auto result = (*args)[0]->GetValue(); if (!result.ok()) return result.status(); - auto *value_ptr = std::get_if<int>(&result.value()); + auto* value_ptr = std::get_if<int>(&result.value()); if (value_ptr == nullptr) { return absl::InternalError("Type mismatch - int expected"); } @@ -79,22 +79,22 @@ } InstructionSetVisitor::~InstructionSetVisitor() { - for (auto &[unused, expr_ptr] : constant_map_) { + for (auto& [unused, expr_ptr] : constant_map_) { delete expr_ptr; } constant_map_.clear(); - for (auto *wrapper : antlr_parser_wrappers_) { + for (auto* wrapper : antlr_parser_wrappers_) { delete wrapper; } antlr_parser_wrappers_.clear(); - for (auto *expr : disasm_field_widths_) delete expr; + for (auto* expr : disasm_field_widths_) delete expr; disasm_field_widths_.clear(); } // Main entry point for processing the file. absl::Status InstructionSetVisitor::Process( - const std::vector<std::string> &file_names, const std::string &prefix, - const std::string &isa_name, const std::vector<std::string> &include_roots, + const std::vector<std::string>& file_names, const std::string& prefix, + const std::string& isa_name, const std::vector<std::string>& include_roots, absl::string_view directory) { generator_version_ = absl::GetFlag(FLAGS_generator); // Create and add the error listener. @@ -104,12 +104,12 @@ return absl::InvalidArgumentError("Isa name cannot be empty"); } - for (auto &include_root : include_roots) { + for (auto& include_root : include_roots) { include_dir_vec_.push_back(include_root); } std::string isa_prefix = prefix; - std::istream *source_stream = &std::cin; + std::istream* source_stream = &std::cin; if (!file_names.empty()) { source_stream = new std::fstream(file_names[0], std::fstream::in); @@ -122,7 +122,7 @@ parser_wrapper.parser()->addErrorListener(error_listener()); // Parse the file and then create the data structures. - TopLevelCtx *top_level = parser_wrapper.parser()->top_level(); + TopLevelCtx* top_level = parser_wrapper.parser()->top_level(); if (!file_names.empty()) { delete source_stream; @@ -241,20 +241,20 @@ } void InstructionSetVisitor::PerformBundleReferenceChecks( - InstructionSet *instruction_set, Bundle *bundle) { + InstructionSet* instruction_set, Bundle* bundle) { // Verify that all referenced bundles were declared. - for (const auto &bundle_name : bundle->bundle_names()) { - Bundle *bundle_ref = instruction_set->GetBundle(bundle_name); + for (const auto& bundle_name : bundle->bundle_names()) { + Bundle* bundle_ref = instruction_set->GetBundle(bundle_name); // Perform the check recursively on the referenced bundles. PerformBundleReferenceChecks(instruction_set, bundle_ref); } // Verify that all the slot uses were declared. - for (auto &[slot_name, instance_vec] : bundle->slot_uses()) { - Slot *slot = instruction_set->GetSlot(slot_name); + for (auto& [slot_name, instance_vec] : bundle->slot_uses()) { + Slot* slot = instruction_set->GetSlot(slot_name); // Verify that the instance number of the slot falls within valid range. - for (auto &instance_number : instance_vec) { + for (auto& instance_number : instance_vec) { if (instance_number >= slot->size()) { - auto *token = bundle->ctx() == nullptr ? nullptr : bundle->ctx()->start; + auto* token = bundle->ctx() == nullptr ? nullptr : bundle->ctx()->start; error_listener()->semanticError( token, absl::StrCat("Index ", instance_number, " out of range for slot ", @@ -276,14 +276,14 @@ instruction_set->ComputeSlotAndBundleOrders(); } -void InstructionSetVisitor::VisitTopLevel(TopLevelCtx *ctx) { +void InstructionSetVisitor::VisitTopLevel(TopLevelCtx* ctx) { auto declarations = ctx->declaration(); // Process disasm widths. Only the one in the top level file is used if there // are additional ones in included files. int count = 0; - DisasmWidthsCtx *disasm_ctx = nullptr; - for (auto *decl : declarations) { + DisasmWidthsCtx* disasm_ctx = nullptr; + for (auto* decl : declarations) { context_file_map_[decl] = current_file_index_; if (decl->disasm_widths() == nullptr) continue; if (count > 0) { @@ -319,14 +319,14 @@ } void InstructionSetVisitor::PreProcessDeclarations( - const std::vector<DeclarationCtx *> &ctx_vec) { - std::vector<IncludeFileCtx *> include_files; + const std::vector<DeclarationCtx*>& ctx_vec) { + std::vector<IncludeFileCtx*> include_files; // Get handles to the slot, bundle and isa declarations. // Create map from slot name to slot ctx. - for (auto *decl : ctx_vec) { + for (auto* decl : ctx_vec) { if (decl->slot_declaration() != nullptr) { - auto *slot_ctx = decl->slot_declaration(); + auto* slot_ctx = decl->slot_declaration(); context_file_map_.insert({slot_ctx, current_file_index_}); auto name = slot_ctx->slot_name->getText(); auto ptr = slot_decl_map_.find(name); @@ -341,7 +341,7 @@ } // Create map from bundle name to bundle ctx. if (decl->bundle_declaration() != nullptr) { - auto *bundle_ctx = decl->bundle_declaration(); + auto* bundle_ctx = decl->bundle_declaration(); context_file_map_.insert({bundle_ctx, current_file_index_}); auto name = bundle_ctx->bundle_name->getText(); auto ptr = bundle_decl_map_.find(name); @@ -357,7 +357,7 @@ } // Create map from isa name to isa ctx. if (decl->isa_declaration() != nullptr) { - auto *isa_ctx = decl->isa_declaration(); + auto* isa_ctx = decl->isa_declaration(); context_file_map_.insert({isa_ctx, current_file_index_}); auto name = isa_ctx->instruction_set_name->getText(); auto ptr = isa_decl_map_.find(name); @@ -374,7 +374,7 @@ // Process global include file specifications. if (decl->include_file_list() != nullptr) { - for (auto *include_file : decl->include_file_list()->include_file()) { + for (auto* include_file : decl->include_file_list()->include_file()) { // Insert the string - the call will always succeed, but the insertion // does not happen if it already exists. include_files_.insert(include_file->STRING_LITERAL()->getText()); @@ -394,13 +394,13 @@ } // Process all include files - this adds to all isa, slot and bundle // context maps, as well as all global variables, etc. - for (auto *include_file_ctx : include_files) { + for (auto* include_file_ctx : include_files) { VisitIncludeFile(include_file_ctx); } } std::unique_ptr<InstructionSet> InstructionSetVisitor::VisitIsaDeclaration( - IsaDeclCtx *ctx) { + IsaDeclCtx* ctx) { if (ctx == nullptr) return nullptr; auto instruction_set = std::make_unique<InstructionSet>(ctx->instruction_set_name->getText()); @@ -418,16 +418,16 @@ return instruction_set; } -void InstructionSetVisitor::VisitNamespaceDecl(NamespaceDeclCtx *ctx, - InstructionSet *isa) { +void InstructionSetVisitor::VisitNamespaceDecl(NamespaceDeclCtx* ctx, + InstructionSet* isa) { if (ctx == nullptr) return; - for (auto *namespace_name : ctx->namespace_ident()) { + for (auto* namespace_name : ctx->namespace_ident()) { isa->namespaces().push_back(namespace_name->getText()); } } -void InstructionSetVisitor::VisitBundleList(BundleListCtx *ctx, - Bundle *bundle) { +void InstructionSetVisitor::VisitBundleList(BundleListCtx* ctx, + Bundle* bundle) { if (ctx == nullptr) return; // Append the list of named bundles referenced within the containing bundle. auto bundle_specs_vec = ctx->bundle_spec(); @@ -449,7 +449,7 @@ } } -void InstructionSetVisitor::VisitSlotList(SlotListCtx *ctx, Bundle *bundle) { +void InstructionSetVisitor::VisitSlotList(SlotListCtx* ctx, Bundle* bundle) { if (ctx == nullptr) return; // Append the list of named slots referenced within the containing bundle. auto slot_specs_vec = ctx->slot_spec(); @@ -473,7 +473,7 @@ } } -std::vector<int> InstructionSetVisitor::VisitArraySpec(ArraySpecCtx *ctx) { +std::vector<int> InstructionSetVisitor::VisitArraySpec(ArraySpecCtx* ctx) { std::vector<int> instances; // If there are not array specifications, return the empty vector. @@ -496,12 +496,12 @@ return instances; } -void InstructionSetVisitor::VisitConstantDef(ConstantDefCtx *ctx) { +void InstructionSetVisitor::VisitConstantDef(ConstantDefCtx* ctx) { if (ctx == nullptr) return; std::string ident = ctx->ident()->getText(); std::string type = ctx->template_parameter_type()->getText(); context_file_map_.insert({ctx->expression(), context_file_map_.at(ctx)}); - auto *expr = VisitExpression(ctx->expression(), nullptr, nullptr); + auto* expr = VisitExpression(ctx->expression(), nullptr, nullptr); auto status = AddConstant(ident, type, expr); if (!status.ok()) { delete expr; @@ -509,14 +509,14 @@ } } -void InstructionSetVisitor::VisitIncludeFile(IncludeFileCtx *ctx) { +void InstructionSetVisitor::VisitIncludeFile(IncludeFileCtx* ctx) { // The literal includes the double quotes. std::string literal = ctx->STRING_LITERAL()->getText(); // Remove the double quotes from the literal and construct the full file // name. std::string file_name = literal.substr(1, literal.length() - 2); // Check for recursive include. - for (auto const &name : include_file_stack_) { + for (auto const& name : include_file_stack_) { if (name == file_name) { error_listener()->semanticError( ctx->start, @@ -528,14 +528,14 @@ } void InstructionSetVisitor::ParseIncludeFile( - antlr4::ParserRuleContext *ctx, const std::string &file_name, - const std::vector<std::string> &dirs) { + antlr4::ParserRuleContext* ctx, const std::string& file_name, + const std::vector<std::string>& dirs) { std::fstream include_file; // Open include file. include_file.open(file_name, std::fstream::in); if (!include_file.is_open()) { // Try each of the include file directories. - for (auto const &dir : dirs) { + for (auto const& dir : dirs) { std::string include_name = dir + "/" + file_name; include_file.open(include_name, std::fstream::in); if (include_file.is_open()) break; @@ -553,7 +553,7 @@ file_names_.push_back(file_name); current_file_index_ = file_names_.size() - 1; // Create an antlr4 stream from the input stream. - auto *include_parser = new IsaAntlrParserWrapper(&include_file); + auto* include_parser = new IsaAntlrParserWrapper(&include_file); // We need to save the parser state so it's available for analysis after // we are done with building the parse trees. antlr_parser_wrappers_.push_back(include_parser); @@ -577,16 +577,16 @@ } void InstructionSetVisitor::VisitBundleDeclaration( - BundleDeclCtx *ctx, InstructionSet *instruction_set) { + BundleDeclCtx* ctx, InstructionSet* instruction_set) { if (ctx == nullptr) return; - Bundle *bundle = + Bundle* bundle = new Bundle(ctx->bundle_name->getText(), instruction_set, ctx); instruction_set->AddBundle(bundle); int num_slot_lists = 0; int num_bundle_lists = 0; int num_include_file_lists = 0; int num_semfunc_specs = 0; - for (auto *part : ctx->bundle_parts()) { + for (auto* part : ctx->bundle_parts()) { if (part->slot_list() != nullptr) { if (num_slot_lists > 0) { error_listener()->semanticError(file_names_[context_file_map_.at(ctx)], @@ -618,7 +618,7 @@ "Multiple include file lists in bundle"); return; } - for (auto *include_file : part->include_file_list()->include_file()) { + for (auto* include_file : part->include_file_list()->include_file()) { // Insert the string - the call will always succeed, but the insertion // does not happen if it already exists. include_files_.insert(include_file->STRING_LITERAL()->getText()); @@ -649,12 +649,12 @@ } void InstructionSetVisitor::VisitSlotDeclaration( - SlotDeclCtx *ctx, InstructionSet *instruction_set) { + SlotDeclCtx* ctx, InstructionSet* instruction_set) { bool is_templated = ctx->template_decl() != nullptr; - Slot *slot = new Slot(ctx->slot_name->getText(), instruction_set, + Slot* slot = new Slot(ctx->slot_name->getText(), instruction_set, is_templated, ctx, generator_version_); if (is_templated) { - for (auto const ¶m : ctx->template_decl()->template_parameter_decl()) { + for (auto const& param : ctx->template_decl()->template_parameter_decl()) { auto status = slot->AddTemplateFormal(param->IDENT()->getText()); if (!status.ok()) { error_listener()->semanticError( @@ -666,7 +666,7 @@ // Set the base slot if it inherits. if (ctx->base_item_list() != nullptr) { // For each entry in the list of slots to derive from. - for (auto *base_item : ctx->base_item_list()->base_item()) { + for (auto* base_item : ctx->base_item_list()->base_item()) { std::string base_name = base_item->IDENT()->getText(); // If the base slot does has not been seen - undefined error. auto slot_iter = slot_decl_map_.find(base_name); @@ -677,14 +677,14 @@ continue; } // If the slot hasn't been visited, visit it. - auto *base = instruction_set->GetSlot(base_name); + auto* base = instruction_set->GetSlot(base_name); if (base == nullptr) { VisitSlotDeclaration(slot_iter->second, instruction_set); base = instruction_set->GetSlot(base_name); } // Now check if the base slot is templated or not, and if the template // arguments are present or not. - auto *template_spec = base_item->template_spec(); + auto* template_spec = base_item->template_spec(); if ((template_spec != nullptr) && !base->is_templated()) { // Template arguments are present but the slot isn't templated. error_listener()->semanticError( @@ -713,10 +713,10 @@ } bool has_error = false; // Build up the argument vector. - auto *arguments = new TemplateInstantiationArgs; - for (auto *template_arg : template_spec->expression()) { + auto* arguments = new TemplateInstantiationArgs; + for (auto* template_arg : template_spec->expression()) { context_file_map_.insert({template_arg, context_file_map_.at(ctx)}); - auto *expr = VisitExpression(template_arg, slot, nullptr); + auto* expr = VisitExpression(template_arg, slot, nullptr); if (expr == nullptr) { error_listener()->semanticError( file_names_[context_file_map_.at(ctx)], template_arg->start, @@ -727,7 +727,7 @@ arguments->push_back(expr); } if (has_error) { - for (auto *expr : *arguments) { + for (auto* expr : *arguments) { delete expr; } delete arguments; @@ -757,7 +757,7 @@ } // Add the slot to the ISA. instruction_set->AddSlot(slot); - for (auto *decl_ctx : ctx->const_and_default_decl()) { + for (auto* decl_ctx : ctx->const_and_default_decl()) { context_file_map_[decl_ctx] = context_file_map_.at(ctx); VisitConstAndDefaultDecls(decl_ctx, slot); } @@ -765,10 +765,10 @@ VisitOpcodeList(ctx->opcode_list(), slot); } -void InstructionSetVisitor::VisitDisasmWidthsDecl(DisasmWidthsCtx *ctx) { - for (auto *expr : ctx->expression()) { +void InstructionSetVisitor::VisitDisasmWidthsDecl(DisasmWidthsCtx* ctx) { + for (auto* expr : ctx->expression()) { context_file_map_.insert({expr, context_file_map_.at(ctx)}); - auto *width_expr = VisitExpression(expr, nullptr, nullptr); + auto* width_expr = VisitExpression(expr, nullptr, nullptr); if ((width_expr == nullptr) || (!width_expr->IsConstant())) { error_listener()->semanticError(expr->start, "Expression must be constant"); @@ -778,17 +778,17 @@ } } -void InstructionSetVisitor::VisitConstAndDefaultDecls(ConstAndDefaultCtx *ctx, - Slot *slot) { +void InstructionSetVisitor::VisitConstAndDefaultDecls(ConstAndDefaultCtx* ctx, + Slot* slot) { if (ctx == nullptr) return; // A constant declaration. - auto *const_def = ctx->constant_def(); + auto* const_def = ctx->constant_def(); if (const_def != nullptr) { // Constant declaration. std::string ident = const_def->ident()->getText(); std::string type = const_def->template_parameter_type()->getText(); context_file_map_.insert( {const_def->expression(), context_file_map_.at(ctx)}); - auto *expr = VisitExpression(const_def->expression(), slot, nullptr); + auto* expr = VisitExpression(const_def->expression(), slot, nullptr); if (expr == nullptr) { delete expr; error_listener()->semanticError(file_names_[context_file_map_.at(ctx)], @@ -812,7 +812,7 @@ } if (ctx->LATENCY() != nullptr) { // Default latency. context_file_map_.insert({ctx->expression(), context_file_map_.at(ctx)}); - auto *expr = VisitExpression(ctx->expression(), slot, nullptr); + auto* expr = VisitExpression(ctx->expression(), slot, nullptr); if (expr == nullptr) { delete expr; error_listener()->semanticError(file_names_[context_file_map_.at(ctx)], @@ -832,7 +832,7 @@ } // Add any include files to our set of includes. if (ctx->include_file_list() != nullptr) { - for (auto *include_file : ctx->include_file_list()->include_file()) { + for (auto* include_file : ctx->include_file_list()->include_file()) { // Insert the string - the call will always succeed, but the insertion // does not happen if it already exists. include_files_.insert(include_file->STRING_LITERAL()->getText()); @@ -847,11 +847,11 @@ "Multiple definitions of 'default' opcode"); return; } - auto *default_instruction = new Instruction( + auto* default_instruction = new Instruction( slot->instruction_set()->opcode_factory()->CreateDefaultOpcode(), slot); bool has_disasm = false; bool has_semfunc = false; - for (auto *attribute : ctx->opcode_attribute_list()->opcode_attribute()) { + for (auto* attribute : ctx->opcode_attribute_list()->opcode_attribute()) { // Disasm spec. if (attribute->disasm_spec() != nullptr) { if (has_disasm) { @@ -861,7 +861,7 @@ continue; } has_disasm = true; - for (auto *format_str : attribute->disasm_spec()->STRING_LITERAL()) { + for (auto* format_str : attribute->disasm_spec()->STRING_LITERAL()) { std::string format = format_str->getText(); // Trim the double quotes. format.erase(format.size() - 1, 1); @@ -924,13 +924,13 @@ // Visit the template argument recursively to create an expression tree that // can be evaluated later. No need to coalesce constant expression trees, the // savings aren't that great. -TemplateExpression *InstructionSetVisitor::VisitExpression(ExpressionCtx *ctx, - Slot *slot, - Instruction *inst) { +TemplateExpression* InstructionSetVisitor::VisitExpression(ExpressionCtx* ctx, + Slot* slot, + Instruction* inst) { if (ctx == nullptr) return nullptr; if (ctx->negop() != nullptr) { context_file_map_.insert({ctx->expr, context_file_map_.at(ctx)}); - TemplateExpression *expr = VisitExpression(ctx->expr, slot, inst); + TemplateExpression* expr = VisitExpression(ctx->expr, slot, inst); if (expr == nullptr) return nullptr; return new TemplateNegate(expr); } @@ -938,10 +938,10 @@ if (ctx->mulop() != nullptr) { std::string op = ctx->mulop()->getText(); context_file_map_.insert({ctx->lhs, context_file_map_.at(ctx)}); - TemplateExpression *lhs = VisitExpression(ctx->lhs, slot, inst); + TemplateExpression* lhs = VisitExpression(ctx->lhs, slot, inst); if (lhs == nullptr) return nullptr; context_file_map_.insert({ctx->rhs, context_file_map_.at(ctx)}); - TemplateExpression *rhs = VisitExpression(ctx->rhs, slot, inst); + TemplateExpression* rhs = VisitExpression(ctx->rhs, slot, inst); if (rhs == nullptr) { delete lhs; return nullptr; @@ -953,10 +953,10 @@ if (ctx->addop() != nullptr) { std::string op = ctx->addop()->getText(); context_file_map_.insert({ctx->lhs, context_file_map_.at(ctx)}); - TemplateExpression *lhs = VisitExpression(ctx->lhs, slot, inst); + TemplateExpression* lhs = VisitExpression(ctx->lhs, slot, inst); if (lhs == nullptr) return nullptr; context_file_map_.insert({ctx->rhs, context_file_map_.at(ctx)}); - TemplateExpression *rhs = VisitExpression(ctx->rhs, slot, inst); + TemplateExpression* rhs = VisitExpression(ctx->rhs, slot, inst); if (rhs == nullptr) { delete lhs; return nullptr; @@ -982,11 +982,11 @@ " parameters, but ", ctx->expression().size(), " were given")); } - auto *args = new TemplateInstantiationArgs; + auto* args = new TemplateInstantiationArgs; bool has_error = false; - for (auto *expr_ctx : ctx->expression()) { + for (auto* expr_ctx : ctx->expression()) { context_file_map_.insert({expr_ctx, context_file_map_.at(ctx)}); - auto *expr = VisitExpression(expr_ctx, slot, inst); + auto* expr = VisitExpression(expr_ctx, slot, inst); if (expr == nullptr) { has_error = true; break; @@ -994,7 +994,7 @@ args->push_back(expr); } if (has_error) { - for (auto *expr : *args) { + for (auto* expr : *args) { delete expr; } delete args; @@ -1009,7 +1009,7 @@ } if (ctx->NUMBER() != nullptr) { - auto *expr = + auto* expr = new TemplateConstant(std::stoi(ctx->NUMBER()->getText(), nullptr, 0)); return expr; } @@ -1019,11 +1019,11 @@ // Four possibilities. A global constant, a slot local constant, a // template formal, or a reference to a destination operand. if (slot != nullptr) { - TemplateFormal *param = slot->GetTemplateFormal(ident); + TemplateFormal* param = slot->GetTemplateFormal(ident); if (param != nullptr) return new TemplateParam(param); // Check if it's a slot const expression. - auto *expr = slot->GetConstExpression(ident); + auto* expr = slot->GetConstExpression(ident); if (expr != nullptr) return expr->DeepCopy(); } @@ -1031,7 +1031,7 @@ // destination operand with a latency. That is the value/expression that // is needed here. if (inst != nullptr) { - auto *op = inst->GetDestOp(ident); + auto* op = inst->GetDestOp(ident); if (op == nullptr) { error_listener()->semanticError( file_names_[context_file_map_.at(ctx)], ctx->start, @@ -1041,7 +1041,7 @@ return nullptr; } - auto *expr = op->expression(); + auto* expr = op->expression(); if (expr != nullptr) return expr->DeepCopy(); // expr is null, this means that the destination operand has a decode @@ -1054,7 +1054,7 @@ return nullptr; } - auto *expr = GetConstExpression(ident); + auto* expr = GetConstExpression(ident); if (expr != nullptr) return expr->DeepCopy(); error_listener()->semanticError( @@ -1066,8 +1066,8 @@ return nullptr; } -DestinationOperand *InstructionSetVisitor::FindDestinationOpInExpression( - ExpressionCtx *ctx, const Slot *slot, const Instruction *inst) { +DestinationOperand* InstructionSetVisitor::FindDestinationOpInExpression( + ExpressionCtx* ctx, const Slot* slot, const Instruction* inst) { if (ctx == nullptr) return nullptr; if (ctx->negop() != nullptr) { context_file_map_.insert({ctx->expr, context_file_map_.at(ctx)}); @@ -1076,8 +1076,8 @@ if ((ctx->mulop() != nullptr) || (ctx->addop() != nullptr)) { context_file_map_.insert({ctx->lhs, context_file_map_.at(ctx)}); context_file_map_.insert({ctx->rhs, context_file_map_.at(ctx)}); - auto *lhs = FindDestinationOpInExpression(ctx->lhs, slot, inst); - auto *rhs = FindDestinationOpInExpression(ctx->rhs, slot, inst); + auto* lhs = FindDestinationOpInExpression(ctx->lhs, slot, inst); + auto* rhs = FindDestinationOpInExpression(ctx->rhs, slot, inst); if (lhs == nullptr) return rhs; if (rhs == nullptr) return lhs; if (lhs == rhs) return lhs; @@ -1096,9 +1096,9 @@ return nullptr; } if (ctx->func != nullptr) { - DestinationOperand *dest_op = nullptr; - DestinationOperand *tmp_op; - for (auto *expr_ctx : ctx->expression()) { + DestinationOperand* dest_op = nullptr; + DestinationOperand* tmp_op; + for (auto* expr_ctx : ctx->expression()) { context_file_map_.insert({expr_ctx, context_file_map_.at(ctx)}); tmp_op = FindDestinationOpInExpression(expr_ctx, slot, inst); if (dest_op == nullptr) { @@ -1119,19 +1119,19 @@ std::string ident = ctx->IDENT()->getText(); // It is either a slot local constant, a template formal, or a reference // to a destination operand. - TemplateFormal *param = slot->GetTemplateFormal(ident); + TemplateFormal* param = slot->GetTemplateFormal(ident); if (param != nullptr) return nullptr; // Check if it's a slot const expression. - auto *expr = slot->GetConstExpression(ident); + auto* expr = slot->GetConstExpression(ident); if (expr != nullptr) return nullptr; // It should be an opcode operand term. return inst->GetDestOp(ident); } -void InstructionSetVisitor::VisitOpcodeList(OpcodeListCtx *ctx, Slot *slot) { +void InstructionSetVisitor::VisitOpcodeList(OpcodeListCtx* ctx, Slot* slot) { absl::flat_hash_set<std::string> deleted_ops_set; - absl::flat_hash_set<OpcodeSpecCtx *> overridden_ops_set; - std::vector<Instruction *> instruction_vec; + absl::flat_hash_set<OpcodeSpecCtx*> overridden_ops_set; + std::vector<Instruction*> instruction_vec; if (ctx != nullptr) { ProcessOpcodeList(ctx, slot, instruction_vec, deleted_ops_set, overridden_ops_set); @@ -1140,12 +1140,12 @@ // to the current slot. When adding the instruction, pass in any template // instantiation arguments to the base slot so that any expressions for // destination operand latencies can be evaluated. - for (auto const &base_slot : slot->base_slots()) { + for (auto const& base_slot : slot->base_slots()) { if (base_slot.base->min_instruction_size() < slot->min_instruction_size()) { slot->set_min_instruction_size(base_slot.base->min_instruction_size()); } // Copy over the instructions that were not deleted. - for (auto &[unused, inst_ptr] : base_slot.base->instruction_map()) { + for (auto& [unused, inst_ptr] : base_slot.base->instruction_map()) { if (!deleted_ops_set.contains(inst_ptr->opcode()->name())) { absl::Status status = slot->AppendInheritedInstruction(inst_ptr, base_slot.arguments); @@ -1160,7 +1160,7 @@ PerformOpcodeOverrides(overridden_ops_set, slot); } // Add the declared opcodes. - for (auto *inst : instruction_vec) { + for (auto* inst : instruction_vec) { absl::Status status = slot->AppendInstruction(inst); if (!status.ok()) { error_listener()->semanticError(file_names_[context_file_map_.at(ctx)], @@ -1170,17 +1170,17 @@ } void InstructionSetVisitor::PerformOpcodeOverrides( - absl::flat_hash_set<OpcodeSpecCtx *> overridden_ops_set, Slot *slot) { - for (auto *override_ctx : overridden_ops_set) { + absl::flat_hash_set<OpcodeSpecCtx*> overridden_ops_set, Slot* slot) { + for (auto* override_ctx : overridden_ops_set) { std::string name = override_ctx->name->getText(); - auto *inst = slot->instruction_map().at(name); + auto* inst = slot->instruction_map().at(name); VisitOpcodeAttributes(override_ctx->opcode_attribute_list(), inst, slot); } } -void InstructionSetVisitor::VisitOpcodeAttributes(OpcodeAttributeListCtx *ctx, - Instruction *inst, - Slot *slot) { +void InstructionSetVisitor::VisitOpcodeAttributes(OpcodeAttributeListCtx* ctx, + Instruction* inst, + Slot* slot) { if (ctx == nullptr) return; // These flags are used to detect multiple instances of each attribute. bool has_disasm = false; @@ -1188,7 +1188,7 @@ bool has_resources = false; bool has_attributes = false; // Visit the opcode attributes. - for (auto *attribute_ctx : ctx->opcode_attribute()) { + for (auto* attribute_ctx : ctx->opcode_attribute()) { // Process any disassembly specifications. if (attribute_ctx->disasm_spec() != nullptr) { // In case of override, need to clear any disasm info in instruction. @@ -1201,7 +1201,7 @@ continue; } has_disasm = true; - for (auto *disasm_fmt : attribute_ctx->disasm_spec()->STRING_LITERAL()) { + for (auto* disasm_fmt : attribute_ctx->disasm_spec()->STRING_LITERAL()) { std::string format = disasm_fmt->getText(); // Trim the double quotes. format.erase(format.size() - 1, 1); @@ -1277,9 +1277,9 @@ } void InstructionSetVisitor::VisitInstructionAttributeList( - InstructionAttributeListCtx *ctx, Slot *slot, Instruction *inst) { - absl::flat_hash_map<std::string, TemplateExpression *> attributes; - for (auto *attribute : ctx->instruction_attribute()) { + InstructionAttributeListCtx* ctx, Slot* slot, Instruction* inst) { + absl::flat_hash_map<std::string, TemplateExpression*> attributes; + for (auto* attribute : ctx->instruction_attribute()) { std::string name = attribute->IDENT()->getText(); if (attributes.find(name) != attributes.end()) { error_listener()->semanticError( @@ -1291,7 +1291,7 @@ if (attribute->expression() != nullptr) { context_file_map_.insert( {attribute->expression(), context_file_map_.at(slot->ctx())}); - auto *expr = VisitExpression(attribute->expression(), slot, inst); + auto* expr = VisitExpression(attribute->expression(), slot, inst); attributes.emplace(name, expr); continue; } @@ -1299,8 +1299,8 @@ } // Are we parsing attributes for an instruction? if (inst != nullptr) { - for (auto *child = inst; child != nullptr; child = child->child()) { - for (auto &[name, expr] : attributes) { + for (auto* child = inst; child != nullptr; child = child->child()) { + for (auto& [name, expr] : attributes) { child->AddInstructionAttribute(name, expr); } } @@ -1309,18 +1309,18 @@ return; } // Attributes are default attributes for the current slot. - for (auto &[name, expr] : attributes) { + for (auto& [name, expr] : attributes) { slot->AddInstructionAttribute(name, expr); } attributes.clear(); } -void InstructionSetVisitor::VisitSemfuncSpec(SemfuncSpecCtx *semfunc_spec, - Instruction *inst) { - auto *child = inst; +void InstructionSetVisitor::VisitSemfuncSpec(SemfuncSpecCtx* semfunc_spec, + Instruction* inst) { + auto* child = inst; // Parse each string in the list of semantic function specifications. There // should be one the opcode and one for each child opcode. - for (auto *sem_func : semfunc_spec->STRING_LITERAL()) { + for (auto* sem_func : semfunc_spec->STRING_LITERAL()) { if (child == nullptr) { error_listener()->semanticWarning( file_names_[context_file_map_.at(inst->slot()->ctx())], @@ -1342,9 +1342,9 @@ } } -void InstructionSetVisitor::VisitResourceDetails(ResourceDetailsCtx *ctx, - Instruction *inst, - Slot *slot) { +void InstructionSetVisitor::VisitResourceDetails(ResourceDetailsCtx* ctx, + Instruction* inst, + Slot* slot) { if (ctx->ident() != nullptr) { // This is a reference to a resource spec defined earlier. std::string name = ctx->ident()->getText(); @@ -1361,22 +1361,22 @@ } ResourceSpec spec; VisitResourceDetailsLists(ctx, slot, inst, &spec); - for (auto *use : spec.use_vec) { + for (auto* use : spec.use_vec) { inst->AppendResourceUse(use); } - for (auto *acquire : spec.acquire_vec) { + for (auto* acquire : spec.acquire_vec) { inst->AppendResourceAcquire(acquire); } } -std::optional<ResourceReference *> +std::optional<ResourceReference*> InstructionSetVisitor::ProcessResourceReference( - Slot *slot, Instruction *inst, ResourceItemCtx *resource_item) { + Slot* slot, Instruction* inst, ResourceItemCtx* resource_item) { // Empty optional object. - std::optional<ResourceReference *> return_value; + std::optional<ResourceReference*> return_value; - auto *factory = slot->instruction_set()->resource_factory(); - DestinationOperand *dest_op = nullptr; + auto* factory = slot->instruction_set()->resource_factory(); + DestinationOperand* dest_op = nullptr; // Extract the text from the resource reference. std::string ident_text; bool is_array; @@ -1390,12 +1390,12 @@ is_array = true; } dest_op = inst->GetDestOp(ident_text); - auto *resource = factory->GetOrInsertResource(ident_text); + auto* resource = factory->GetOrInsertResource(ident_text); resource->set_is_array(is_array); // Compute begin and end values. - TemplateExpression *begin_expr; - TemplateExpression *end_expr; - DestinationOperand *tmp_op; + TemplateExpression* begin_expr; + TemplateExpression* end_expr; + DestinationOperand* tmp_op; if (resource_item->begin_cycle == nullptr) { begin_expr = new TemplateConstant(0); } else { @@ -1450,15 +1450,15 @@ {resource_item->end_cycle, context_file_map_.at(slot->ctx())}); end_expr = VisitExpression(resource_item->end_cycle, slot, inst); } - auto *ref = + auto* ref = new ResourceReference(resource, is_array, dest_op, begin_expr, end_expr); - return std::optional<ResourceReference *>(ref); + return std::optional<ResourceReference*>(ref); } -void InstructionSetVisitor::VisitResourceDetailsLists(ResourceDetailsCtx *ctx, - Slot *slot, - Instruction *inst, - ResourceSpec *spec) { +void InstructionSetVisitor::VisitResourceDetailsLists(ResourceDetailsCtx* ctx, + Slot* slot, + Instruction* inst, + ResourceSpec* spec) { if (ctx == nullptr) return; if ((ctx->use_list == nullptr) && (ctx->acquire_list == nullptr) && @@ -1474,9 +1474,9 @@ // set of cycles specified. // Use list. - auto *use_list = ctx->use_list; + auto* use_list = ctx->use_list; if (use_list != nullptr) { - for (auto *resource_item : use_list->resource_item()) { + for (auto* resource_item : use_list->resource_item()) { auto ref_optional = ProcessResourceReference(slot, inst, resource_item); if (!ref_optional) continue; spec->use_vec.push_back(ref_optional.value()); @@ -1484,14 +1484,14 @@ } // Reserve list. - auto *acquire_list = ctx->acquire_list; + auto* acquire_list = ctx->acquire_list; if (acquire_list != nullptr) { - for (auto *resource_item : acquire_list->resource_item()) { + for (auto* resource_item : acquire_list->resource_item()) { auto ref_optional = ProcessResourceReference(slot, inst, resource_item); if (!ref_optional) continue; // Only add to use_vec if it isn't already there. bool found = false; - for (auto *ref : spec->use_vec) { + for (auto* ref : spec->use_vec) { if (ref->resource->name() == ref_optional.value()->resource->name()) { found = true; break; @@ -1505,9 +1505,9 @@ } // Hold list. - auto *hold_list = ctx->hold_list; + auto* hold_list = ctx->hold_list; if (hold_list != nullptr) { - for (auto *resource_item : hold_list->resource_item()) { + for (auto* resource_item : hold_list->resource_item()) { auto ref_optional = ProcessResourceReference(slot, inst, resource_item); if (!ref_optional) continue; spec->acquire_vec.push_back(ref_optional.value()); @@ -1516,23 +1516,23 @@ } void InstructionSetVisitor::ProcessOpcodeList( - OpcodeListCtx *ctx, Slot *slot, std::vector<Instruction *> &instruction_vec, - absl::flat_hash_set<std::string> &deleted_ops_set, - absl::flat_hash_set<OpcodeSpecCtx *> &overridden_ops_set) { + OpcodeListCtx* ctx, Slot* slot, std::vector<Instruction*>& instruction_vec, + absl::flat_hash_set<std::string>& deleted_ops_set, + absl::flat_hash_set<OpcodeSpecCtx*>& overridden_ops_set) { // Obtain the list of opcodes specifications. auto opcode_spec = ctx->opcode_spec(); - for (auto *opcode_ctx : opcode_spec) { + for (auto* opcode_ctx : opcode_spec) { ProcessOpcodeSpec(opcode_ctx, slot, instruction_vec, deleted_ops_set, overridden_ops_set); } } void InstructionSetVisitor::ProcessOpcodeSpec( - OpcodeSpecCtx *opcode_ctx, Slot *slot, - std::vector<Instruction *> &instruction_vec, - absl::flat_hash_set<std::string> &deleted_ops_set, - absl::flat_hash_set<OpcodeSpecCtx *> &overridden_ops_set) { - auto *opcode_factory = slot->instruction_set()->opcode_factory(); + OpcodeSpecCtx* opcode_ctx, Slot* slot, + std::vector<Instruction*>& instruction_vec, + absl::flat_hash_set<std::string>& deleted_ops_set, + absl::flat_hash_set<OpcodeSpecCtx*>& overridden_ops_set) { + auto* opcode_factory = slot->instruction_set()->opcode_factory(); if (opcode_ctx->generate != nullptr) { auto status = ProcessOpcodeGenerator(opcode_ctx, slot, instruction_vec, deleted_ops_set, overridden_ops_set); @@ -1556,7 +1556,7 @@ } bool found = false; // Check to see if one of the base slots has this opcode. - for (auto const &base_slot : slot->base_slots()) { + for (auto const& base_slot : slot->base_slots()) { found |= base_slot.base->HasInstruction(opcode_name); if (found) break; } @@ -1576,7 +1576,7 @@ // "attributes" (semantic function, disasm, etc.) are changed. if (opcode_ctx->overridden != nullptr) { int found = 0; - for (auto const &base_slot : slot->base_slots()) { + for (auto const& base_slot : slot->base_slots()) { found += base_slot.base->HasInstruction(opcode_name); } // Check that the opcode is indeed inherited from one base class only. @@ -1599,7 +1599,7 @@ } // This is a new opcode, so let's create it. Signal failure if error. - absl::StatusOr<Opcode *> result = opcode_factory->CreateOpcode(opcode_name); + absl::StatusOr<Opcode*> result = opcode_factory->CreateOpcode(opcode_name); if (!result.ok()) { error_listener()->semanticError( file_names_[context_file_map_.at(slot->ctx())], opcode_ctx->name, @@ -1607,7 +1607,7 @@ return; } - Opcode *top = result.value(); + Opcode* top = result.value(); auto inst = new Instruction(top, slot); slot->instruction_set()->AddInstruction(inst); @@ -1626,7 +1626,7 @@ int op_spec_number = 0; auto op_spec = opcode_ctx->operand_spec(); // Process the top instruction. - for (auto &[name, expr] : slot->attribute_map()) { + for (auto& [name, expr] : slot->attribute_map()) { inst->AddInstructionAttribute(name, expr->DeepCopy()); } @@ -1642,19 +1642,19 @@ // If there are child instructions process them. if (opcode_ctx->operand_spec()->opcode_operands_list() != nullptr) { - Opcode *parent = top; + Opcode* parent = top; auto opcode_operands = op_spec->opcode_operands_list()->opcode_operands(); - Instruction *child_inst = nullptr; + Instruction* child_inst = nullptr; // Process child instructions. for (size_t i = 1; i < opcode_operands.size(); ++i) { // Create child opcode. - auto *op = opcode_factory->CreateChildOpcode(parent); + auto* op = opcode_factory->CreateChildOpcode(parent); // Create child instruction. child_inst = new Instruction(op, slot); inst->AppendChild(child_inst); // Add default attributes. - for (auto &[name, expr] : slot->attribute_map()) { + for (auto& [name, expr] : slot->attribute_map()) { child_inst->AddInstructionAttribute(name, expr->DeepCopy()); } VisitOpcodeOperands(opcode_operands[i], op_spec_number, inst, child_inst, @@ -1666,11 +1666,11 @@ VisitOpcodeAttributes(opcode_ctx->opcode_attribute_list(), inst, slot); } -void InstructionSetVisitor::VisitOpcodeOperands(OpcodeOperandsCtx *ctx, +void InstructionSetVisitor::VisitOpcodeOperands(OpcodeOperandsCtx* ctx, int op_spec_number, - Instruction *parent, - Instruction *child, - Slot *slot) { + Instruction* parent, + Instruction* child, + Slot* slot) { if (ctx == nullptr) return; if (ctx->pred != nullptr) { std::string name = ctx->pred->getText(); @@ -1681,7 +1681,7 @@ } if (ctx->source != nullptr) { int instance = 0; - for (auto *source_op : ctx->source->source_operand()) { + for (auto* source_op : ctx->source->source_operand()) { std::string name; bool is_array = false; bool is_reloc = false; @@ -1711,7 +1711,7 @@ } if (ctx->dest_list() != nullptr) { int instance = 0; - for (auto *dest_op : ctx->dest_list()->dest_operand()) { + for (auto* dest_op : ctx->dest_list()->dest_operand()) { std::string ident; bool is_array = false; bool is_reloc = false; @@ -1759,20 +1759,20 @@ } absl::Status InstructionSetVisitor::ProcessOpcodeGenerator( - OpcodeSpecCtx *ctx, Slot *slot, std::vector<Instruction *> &instruction_vec, - absl::flat_hash_set<std::string> &deleted_ops_set, - absl::flat_hash_set<OpcodeSpecCtx *> &overridden_ops_set) { + OpcodeSpecCtx* ctx, Slot* slot, std::vector<Instruction*>& instruction_vec, + absl::flat_hash_set<std::string>& deleted_ops_set, + absl::flat_hash_set<OpcodeSpecCtx*>& overridden_ops_set) { if (ctx == nullptr) return absl::InternalError("OpcodeSpecCtx is null"); absl::flat_hash_set<std::string> range_variable_names; - std::vector<RangeAssignmentInfo *> range_info_vec; + std::vector<RangeAssignmentInfo*> range_info_vec; // Process range assignment lists. The range assignment is either a single // value or a structured binding assignment. If it's a binding assignment we // need to make sure each tuple has the same number of values as there are // idents to assign them to. - for (auto *assign_ctx : ctx->range_assignment()) { - auto *range_info = new RangeAssignmentInfo(); + for (auto* assign_ctx : ctx->range_assignment()) { + auto* range_info = new RangeAssignmentInfo(); range_info_vec.push_back(range_info); - for (auto *ident_ctx : assign_ctx->IDENT()) { + for (auto* ident_ctx : assign_ctx->IDENT()) { std::string name = ident_ctx->getText(); if (range_variable_names.contains(name)) { error_listener()->semanticError( @@ -1795,7 +1795,7 @@ } // See if it's a list of simple values. if (!assign_ctx->gen_value().empty()) { - for (auto *gen_value_ctx : assign_ctx->gen_value()) { + for (auto* gen_value_ctx : assign_ctx->gen_value()) { if (gen_value_ctx->simple != nullptr) { range_info->range_values[0].push_back( gen_value_ctx->simple->getText()); @@ -1809,9 +1809,9 @@ continue; } // It's a list of tuples with a structured binding assignment. - for (auto *tuple_ctx : assign_ctx->tuple()) { + for (auto* tuple_ctx : assign_ctx->tuple()) { if (tuple_ctx->gen_value().size() != range_info->range_names.size()) { - for (auto *info : range_info_vec) delete info; + for (auto* info : range_info_vec) delete info; return absl::InternalError( "Number of values differs from number of identifiers"); } @@ -1848,7 +1848,7 @@ pos = input_text.find_first_of('$', start_pos); } if (error_listener()->HasError()) { - for (auto *info : range_info_vec) delete info; + for (auto* info : range_info_vec) delete info; return absl::InternalError("Found undefined binding variable name(s)"); } // Now we need to iterate over the range_info instances and substitution @@ -1856,25 +1856,25 @@ std::string generated_text = GenerateOpcodeSpec(range_info_vec, 0, input_text); // Parse and process the generated text. - auto *parser = new IsaAntlrParserWrapper(generated_text); + auto* parser = new IsaAntlrParserWrapper(generated_text); antlr_parser_wrappers_.push_back(parser); // Parse the text starting at the opcode_spec_list rule. auto opcode_spec_vec = parser->parser()->opcode_spec_list()->opcode_spec(); // Process the opcode spec. - for (auto *opcode_spec : opcode_spec_vec) { + for (auto* opcode_spec : opcode_spec_vec) { ProcessOpcodeSpec(opcode_spec, slot, instruction_vec, deleted_ops_set, overridden_ops_set); } // Clean up. - for (auto *info : range_info_vec) delete info; + for (auto* info : range_info_vec) delete info; return absl::OkStatus(); } // Helper function to recursively generate the text for the GENERATE opcode // spec. std::string InstructionSetVisitor::GenerateOpcodeSpec( - const std::vector<RangeAssignmentInfo *> &range_info_vec, int index, - const std::string &template_str_in) const { + const std::vector<RangeAssignmentInfo*>& range_info_vec, int index, + const std::string& template_str_in) const { std::string generated; // Iterate for the number of values. for (int i = 0; i < range_info_vec[index]->range_values[0].size(); ++i) { @@ -1884,7 +1884,7 @@ // current set of values. int var_index = 0; int replace_count = 0; - for (auto &re : range_info_vec[index]->range_regexes) { + for (auto& re : range_info_vec[index]->range_regexes) { replace_count += RE2::GlobalReplace( &template_str, re, range_info_vec[index]->range_values[var_index++][i]); @@ -1928,18 +1928,18 @@ } // This method parses the disasm format string. absl::Status InstructionSetVisitor::ParseDisasmFormat(std::string format, - Instruction *inst) { + Instruction* inst) { std::string::size_type pos = 0; std::string::size_type prev = 0; std::string::size_type length = format.size(); - FormatInfo *format_info = nullptr; + FormatInfo* format_info = nullptr; // Extract raw text without (between) the '%' specifiers. - DisasmFormat *disasm_fmt = new DisasmFormat(); + DisasmFormat* disasm_fmt = new DisasmFormat(); while ((pos != std::string::npos) && ((pos = format.find_first_of('%', pos)) != std::string::npos)) { std::string text = format.substr(prev, pos - prev); std::string new_text; - for (auto &c : text) { + for (auto& c : text) { if (c == '\\') continue; new_text.push_back(c); } @@ -2022,7 +2022,7 @@ return absl::InternalError(absl::StrCat( "Invalid operand '", op_name, "' used in format '", format, "'")); } - auto *format_info = new FormatInfo(); + auto* format_info = new FormatInfo(); format_info->op_name = op_name; format_info->is_formatted = false; if ((pos != std::string::npos) && (format[pos] == '?')) { @@ -2047,14 +2047,14 @@ if (prev != std::string::npos) { std::string text = format.substr(prev); std::string new_text; - for (auto &c : text) { + for (auto& c : text) { if (c == '\\') continue; new_text.push_back(c); } disasm_fmt->format_fragment_vec.push_back(new_text); } std::string str; - for (auto &s : disasm_fmt->format_fragment_vec) { + for (auto& s : disasm_fmt->format_fragment_vec) { absl::StrAppend(&str, s, ":"); } int width = 0; @@ -2062,7 +2062,7 @@ if (count < disasm_field_widths_.size()) { auto result = disasm_field_widths_[count]->GetValue(); if (result.ok()) { - auto *value_ptr = std::get_if<int>(&result.value()); + auto* value_ptr = std::get_if<int>(&result.value()); width = *value_ptr; } } @@ -2071,7 +2071,7 @@ return absl::OkStatus(); } -static std::string::size_type skip_space(const std::string &str, +static std::string::size_type skip_space(const std::string& str, std::string::size_type pos) { if (pos == std::string::npos) return pos; if (pos >= str.size()) { @@ -2084,15 +2084,15 @@ return pos; } -absl::StatusOr<FormatInfo *> InstructionSetVisitor::ParseFormatExpression( - std::string expr, Opcode *op) { +absl::StatusOr<FormatInfo*> InstructionSetVisitor::ParseFormatExpression( + std::string expr, Opcode* op) { // The format expression is very simple. It is of the form: // [@+/-] ident | '(' ident <</>> number ')' // where @ signifies the current instruction address. // In short, the value of the field can be shifted left or right, then added // to, or subtracted from, the instruction address. - FormatInfo *format_info = new FormatInfo(); + FormatInfo* format_info = new FormatInfo(); std::string::size_type pos = 0; pos = skip_space(expr, pos); @@ -2262,7 +2262,7 @@ std::string InstructionSetVisitor::GenerateHdrFileProlog( absl::string_view file_name, absl::string_view opcode_file_name, absl::string_view guard_name, absl::string_view encoding_base_name, - const std::vector<std::string> &namespaces) { + const std::vector<std::string>& namespaces) { std::string output; absl::StrAppend(&output, "#ifndef ", guard_name, "\n" @@ -2282,7 +2282,7 @@ "\"\n" "\n"); - for (const auto &namespace_name : namespaces) { + for (const auto& namespace_name : namespaces) { absl::StrAppend(&output, "namespace ", namespace_name, " {\n"); } absl::StrAppend( @@ -2404,7 +2404,7 @@ InstructionSetVisitor::GenerateEncFilePrologs( absl::string_view file_name, absl::string_view guard_name, absl::string_view opcode_file_name, absl::string_view encoding_type_name, - const std::vector<std::string> &namespaces) { + const std::vector<std::string>& namespaces) { std::string h_output; std::string cc_output; absl::StrAppend(&h_output, "#ifndef ", guard_name, @@ -2451,7 +2451,7 @@ "\"\n" "\n"); - for (const auto &namespace_name : namespaces) { + for (const auto& namespace_name : namespaces) { absl::StrAppend(&h_output, "namespace ", namespace_name, " {\n"); absl::StrAppend(&cc_output, "namespace ", namespace_name, " {\n"); } @@ -2461,7 +2461,7 @@ } std::string InstructionSetVisitor::GenerateHdrFileEpilog( - absl::string_view guard_name, const std::vector<std::string> &namespaces) { + absl::string_view guard_name, const std::vector<std::string>& namespaces) { std::string output; absl::StrAppend(&output, GenerateNamespaceEpilog(namespaces)); absl::StrAppend(&output, "\n#endif // ", guard_name, "\n"); @@ -2470,7 +2470,7 @@ std::string InstructionSetVisitor::GenerateCcFileProlog( absl::string_view hdr_file_name, bool use_includes, - const std::vector<std::string> &namespaces) { + const std::vector<std::string>& namespaces) { std::string output; // Include files. absl::StrAppend(&output, "#include \"", hdr_file_name, "\"\n"); @@ -2478,13 +2478,13 @@ "\n#include <array>\n\n" "#include \"absl/strings/str_format.h\"\n\n"); if (use_includes) { - for (auto &include_file : include_files_) { + for (auto& include_file : include_files_) { absl::StrAppend(&output, "#include ", include_file, "\n"); } } absl::StrAppend(&output, "\n"); // Namespaces. - for (const auto &namespace_name : namespaces) { + for (const auto& namespace_name : namespaces) { absl::StrAppend(&output, "namespace ", namespace_name, " {\n"); } absl::StrAppend(&output, "\n"); @@ -2492,12 +2492,12 @@ } std::string InstructionSetVisitor::GenerateSimpleHdrProlog( - absl::string_view guard_name, const std::vector<std::string> &namespaces) { + absl::string_view guard_name, const std::vector<std::string>& namespaces) { std::string output; absl::StrAppend(&output, "#ifndef ", guard_name, "\n#define ", guard_name, "\n\n"); - for (const auto &namespace_name : namespaces) { + for (const auto& namespace_name : namespaces) { absl::StrAppend(&output, "namespace ", namespace_name, " {\n"); } absl::StrAppend(&output, "\n"); @@ -2505,7 +2505,7 @@ } std::string InstructionSetVisitor::GenerateNamespaceEpilog( - const std::vector<std::string> &namespaces) { + const std::vector<std::string>& namespaces) { std::string output; // Close up namespaces. absl::StrAppend(&output, "\n"); @@ -2518,7 +2518,7 @@ absl::Status InstructionSetVisitor::AddConstant(absl::string_view name, absl::string_view, - TemplateExpression *expr) { + TemplateExpression* expr) { if (constant_map_.contains(name)) { return absl::AlreadyExistsError( absl::StrCat("Constant redefinition of '", name, "'")); @@ -2527,7 +2527,7 @@ return absl::OkStatus(); } -TemplateExpression *InstructionSetVisitor::GetConstExpression( +TemplateExpression* InstructionSetVisitor::GetConstExpression( absl::string_view name) const { auto iter = constant_map_.find(name); if (iter == constant_map_.end()) return nullptr;
diff --git a/mpact/sim/decoder/instruction_set_visitor.h b/mpact/sim/decoder/instruction_set_visitor.h index 0ae5408..83fa3ba 100644 --- a/mpact/sim/decoder/instruction_set_visitor.h +++ b/mpact/sim/decoder/instruction_set_visitor.h
@@ -80,17 +80,17 @@ // Entry point for processing a source_stream input, generating any output // files in the given directory. Returns OK if no errors were encountered. - absl::Status Process(const std::vector<std::string> &file_names, - const std::string &prefix, const std::string &isa_name, - const std::vector<std::string> &include_roots, + absl::Status Process(const std::vector<std::string>& file_names, + const std::string& prefix, const std::string& isa_name, + const std::vector<std::string>& include_roots, absl::string_view directory); // Global const expressions. absl::Status AddConstant(absl::string_view name, absl::string_view type, - TemplateExpression *expr); - TemplateExpression *GetConstExpression(absl::string_view name) const; + TemplateExpression* expr); + TemplateExpression* GetConstExpression(absl::string_view name) const; // The current isa name. - const std::string &isa_name() const { return isa_name_; } + const std::string& isa_name() const { return isa_name_; } private: struct TemplateFunctionEvaluator { @@ -103,99 +103,99 @@ // Checks that any references to slots or bundles within a bundle // declaration are to valid slots/bundles. - void PerformBundleReferenceChecks(InstructionSet *instruction_set, - Bundle *bundle); + void PerformBundleReferenceChecks(InstructionSet* instruction_set, + Bundle* bundle); // The following methods visits the parts of the parse tree indicated by // the method name and builds up the internal representation used for // decoder generation. - void VisitTopLevel(TopLevelCtx *ctx); + void VisitTopLevel(TopLevelCtx* ctx); - std::unique_ptr<InstructionSet> VisitIsaDeclaration(IsaDeclCtx *ctx); - void VisitConstantDef(ConstantDefCtx *ctx); - void VisitBundleList(BundleListCtx *ctx, Bundle *bundle); - void VisitOpcodeList(OpcodeListCtx *ctx, Slot *slot); - void VisitOpcodeOperands(OpcodeOperandsCtx *ctx, int op_spec_number, - Instruction *parent, Instruction *child, Slot *slot); - void VisitSlotList(SlotListCtx *ctx, Bundle *); - void VisitIncludeFile(IncludeFileCtx *ctx); - void VisitSlotDeclaration(SlotDeclCtx *ctx, InstructionSet *instruction_set); - void VisitConstAndDefaultDecls(ConstAndDefaultCtx *ctx, Slot *slot); - TemplateExpression *VisitExpression(ExpressionCtx *ctx, Slot *slot, - Instruction *inst); - std::vector<int> VisitArraySpec(ArraySpecCtx *ctx); - void VisitNamespaceDecl(NamespaceDeclCtx *ctx, InstructionSet *isa); - void VisitBundleDeclaration(BundleDeclCtx *ctx, - InstructionSet *instruction_set); - void VisitDisasmWidthsDecl(DisasmWidthsCtx *ctx); - void VisitInstructionAttributeList(InstructionAttributeListCtx *ctx, - Slot *slot, Instruction *inst); - void VisitOpcodeAttributes(OpcodeAttributeListCtx *ctx, Instruction *inst, - Slot *slot); - void VisitSemfuncSpec(SemfuncSpecCtx *semfunc_spec, Instruction *inst); - void VisitResourceDetails(ResourceDetailsCtx *ctx, Instruction *inst, - Slot *slot); - std::optional<ResourceReference *> ProcessResourceReference( - Slot *slot, Instruction *inst, ResourceItemCtx *resource_item); - void VisitResourceDetailsLists(ResourceDetailsCtx *ctx, Slot *slot, - Instruction *inst, ResourceSpec *spec); + std::unique_ptr<InstructionSet> VisitIsaDeclaration(IsaDeclCtx* ctx); + void VisitConstantDef(ConstantDefCtx* ctx); + void VisitBundleList(BundleListCtx* ctx, Bundle* bundle); + void VisitOpcodeList(OpcodeListCtx* ctx, Slot* slot); + void VisitOpcodeOperands(OpcodeOperandsCtx* ctx, int op_spec_number, + Instruction* parent, Instruction* child, Slot* slot); + void VisitSlotList(SlotListCtx* ctx, Bundle*); + void VisitIncludeFile(IncludeFileCtx* ctx); + void VisitSlotDeclaration(SlotDeclCtx* ctx, InstructionSet* instruction_set); + void VisitConstAndDefaultDecls(ConstAndDefaultCtx* ctx, Slot* slot); + TemplateExpression* VisitExpression(ExpressionCtx* ctx, Slot* slot, + Instruction* inst); + std::vector<int> VisitArraySpec(ArraySpecCtx* ctx); + void VisitNamespaceDecl(NamespaceDeclCtx* ctx, InstructionSet* isa); + void VisitBundleDeclaration(BundleDeclCtx* ctx, + InstructionSet* instruction_set); + void VisitDisasmWidthsDecl(DisasmWidthsCtx* ctx); + void VisitInstructionAttributeList(InstructionAttributeListCtx* ctx, + Slot* slot, Instruction* inst); + void VisitOpcodeAttributes(OpcodeAttributeListCtx* ctx, Instruction* inst, + Slot* slot); + void VisitSemfuncSpec(SemfuncSpecCtx* semfunc_spec, Instruction* inst); + void VisitResourceDetails(ResourceDetailsCtx* ctx, Instruction* inst, + Slot* slot); + std::optional<ResourceReference*> ProcessResourceReference( + Slot* slot, Instruction* inst, ResourceItemCtx* resource_item); + void VisitResourceDetailsLists(ResourceDetailsCtx* ctx, Slot* slot, + Instruction* inst, ResourceSpec* spec); std::unique_ptr<InstructionSet> ProcessTopLevel(absl::string_view isa_name); - void ParseIncludeFile(antlr4::ParserRuleContext *ctx, - const std::string &file_name, - const std::vector<std::string> &dirs); - DestinationOperand *FindDestinationOpInExpression(ExpressionCtx *ctx, - const Slot *slot, - const Instruction *inst); + void ParseIncludeFile(antlr4::ParserRuleContext* ctx, + const std::string& file_name, + const std::vector<std::string>& dirs); + DestinationOperand* FindDestinationOpInExpression(ExpressionCtx* ctx, + const Slot* slot, + const Instruction* inst); void PerformOpcodeOverrides( - absl::flat_hash_set<OpcodeSpecCtx *> overridden_ops_set, Slot *slot); - void PreProcessDeclarations(const std::vector<DeclarationCtx *> &ctx_vec); + absl::flat_hash_set<OpcodeSpecCtx*> overridden_ops_set, Slot* slot); + void PreProcessDeclarations(const std::vector<DeclarationCtx*>& ctx_vec); void ProcessOpcodeList( - OpcodeListCtx *ctx, Slot *slot, - std::vector<Instruction *> &instruction_vec, - absl::flat_hash_set<std::string> &deleted_ops_set, - absl::flat_hash_set<OpcodeSpecCtx *> &overridden_ops_set); + OpcodeListCtx* ctx, Slot* slot, + std::vector<Instruction*>& instruction_vec, + absl::flat_hash_set<std::string>& deleted_ops_set, + absl::flat_hash_set<OpcodeSpecCtx*>& overridden_ops_set); void ProcessOpcodeSpec( - OpcodeSpecCtx *opcode_ctx, Slot *slot, - std::vector<Instruction *> &instruction_vec, - absl::flat_hash_set<std::string> &deleted_ops_set, - absl::flat_hash_set<OpcodeSpecCtx *> &overridden_ops_set); + OpcodeSpecCtx* opcode_ctx, Slot* slot, + std::vector<Instruction*>& instruction_vec, + absl::flat_hash_set<std::string>& deleted_ops_set, + absl::flat_hash_set<OpcodeSpecCtx*>& overridden_ops_set); // Process the GENERATE() directive. absl::Status ProcessOpcodeGenerator( - OpcodeSpecCtx *ctx, Slot *slot, - std::vector<Instruction *> &instruction_vec, - absl::flat_hash_set<std::string> &deleted_ops_set, - absl::flat_hash_set<OpcodeSpecCtx *> &overridden_ops_set); + OpcodeSpecCtx* ctx, Slot* slot, + std::vector<Instruction*>& instruction_vec, + absl::flat_hash_set<std::string>& deleted_ops_set, + absl::flat_hash_set<OpcodeSpecCtx*>& overridden_ops_set); // Helper function fused by ProcessOpcodeGenerator. std::string GenerateOpcodeSpec( - const std::vector<RangeAssignmentInfo *> &range_info_vec, int index, - const std::string &template_str_in) const; + const std::vector<RangeAssignmentInfo*>& range_info_vec, int index, + const std::string& template_str_in) const; // These methods parses the disassembly format string. - absl::Status ParseDisasmFormat(std::string format, Instruction *inst); + absl::Status ParseDisasmFormat(std::string format, Instruction* inst); absl::StatusOr<std::string> ParseNumberFormat(std::string format); - absl::StatusOr<FormatInfo *> ParseFormatExpression(std::string expr, - Opcode *op); + absl::StatusOr<FormatInfo*> ParseFormatExpression(std::string expr, + Opcode* op); // Generate file prologues/epilogues. std::string GenerateHdrFileProlog(absl::string_view file_name, absl::string_view opcode_file_name, absl::string_view guard_name, absl::string_view encoding_base_name, - const std::vector<std::string> &namespaces); + const std::vector<std::string>& namespaces); std::tuple<std::string, std::string> GenerateEncFilePrologs( absl::string_view file_name, absl::string_view guard_name, absl::string_view opcode_file_name, absl::string_view encoding_type_name, - const std::vector<std::string> &namespaces); + const std::vector<std::string>& namespaces); std::string GenerateHdrFileEpilog(absl::string_view guard_name, - const std::vector<std::string> &namespaces); + const std::vector<std::string>& namespaces); std::string GenerateCcFileProlog(absl::string_view hdr_file_name, bool use_includes, - const std::vector<std::string> &namespaces); + const std::vector<std::string>& namespaces); std::string GenerateNamespaceEpilog( - const std::vector<std::string> &namespaces); + const std::vector<std::string>& namespaces); std::string GenerateSimpleHdrProlog( - absl::string_view guard_name, const std::vector<std::string> &namespaces); + absl::string_view guard_name, const std::vector<std::string>& namespaces); // Error handler. - decoder::DecoderErrorListener *error_listener() const { + decoder::DecoderErrorListener* error_listener() const { return error_listener_.get(); } void set_error_listener( @@ -207,12 +207,12 @@ // Slot and bundle maps - these point to the contexts for every slot and // bundle that have been declared. - absl::flat_hash_map<std::string, SlotDeclCtx *> slot_decl_map_; - absl::flat_hash_map<std::string, BundleDeclCtx *> bundle_decl_map_; - absl::flat_hash_map<std::string, IsaDeclCtx *> isa_decl_map_; + absl::flat_hash_map<std::string, SlotDeclCtx*> slot_decl_map_; + absl::flat_hash_map<std::string, BundleDeclCtx*> bundle_decl_map_; + absl::flat_hash_map<std::string, IsaDeclCtx*> isa_decl_map_; // Constant map - absl::flat_hash_map<std::string, TemplateExpression *> constant_map_; + absl::flat_hash_map<std::string, TemplateExpression*> constant_map_; // Include file strings. absl::btree_set<std::string> include_files_; @@ -221,7 +221,7 @@ // Vector of file names. std::vector<std::string> file_names_; // Map from context pointer to file index. - absl::flat_hash_map<antlr4::ParserRuleContext *, int> context_file_map_; + absl::flat_hash_map<antlr4::ParserRuleContext*, int> context_file_map_; // Include file roots. std::vector<std::string> include_dir_vec_; // Keep track of files that are included in case there is recursive includes. @@ -232,9 +232,9 @@ absl::flat_hash_map<std::string, TemplateFunctionEvaluator> template_function_evaluators_; // Disassembler field widths. - std::vector<TemplateExpression *> disasm_field_widths_; + std::vector<TemplateExpression*> disasm_field_widths_; // AntlrParserWrapper vector. - std::vector<IsaAntlrParserWrapper *> antlr_parser_wrappers_; + std::vector<IsaAntlrParserWrapper*> antlr_parser_wrappers_; }; } // namespace instruction_set
diff --git a/mpact/sim/decoder/opcode.cc b/mpact/sim/decoder/opcode.cc index a4a3d30..a5e7e2e 100644 --- a/mpact/sim/decoder/opcode.cc +++ b/mpact/sim/decoder/opcode.cc
@@ -37,7 +37,7 @@ : name_(name), pascal_name_(ToPascalCase(name)), value_(value) {} Opcode::~Opcode() { - for (auto *dest_op : dest_op_vec_) { + for (auto* dest_op : dest_op_vec_) { delete dest_op; } dest_op_vec_.clear(); @@ -51,20 +51,20 @@ void Opcode::AppendDestOp(absl::string_view op_name, bool is_array, bool is_reloc) { - auto *op = new DestinationOperand(std::string(op_name), is_array, is_reloc); + auto* op = new DestinationOperand(std::string(op_name), is_array, is_reloc); dest_op_vec_.push_back(op); dest_op_map_.insert(std::make_pair(std::string(op_name), op)); } void Opcode::AppendDestOp(absl::string_view op_name, bool is_array, - bool is_reloc, TemplateExpression *expression) { - auto *op = new DestinationOperand(std::string(op_name), is_array, is_reloc, + bool is_reloc, TemplateExpression* expression) { + auto* op = new DestinationOperand(std::string(op_name), is_array, is_reloc, expression); dest_op_vec_.push_back(op); dest_op_map_.insert(std::make_pair(std::string(op_name), op)); } -DestinationOperand *Opcode::GetDestOp(absl::string_view op_name) { +DestinationOperand* Opcode::GetDestOp(absl::string_view op_name) { auto iter = dest_op_map_.find(op_name); if (iter != dest_op_map_.end()) return iter->second; @@ -72,8 +72,8 @@ } bool Opcode::ValidateDestLatencies( - const std::function<bool(int)> &validator) const { - for (auto const *dest_op : dest_op_vec_) { + const std::function<bool(int)>& validator) const { + for (auto const* dest_op : dest_op_vec_) { if (dest_op->expression() != nullptr) { auto result = dest_op->GetLatency(); if (!result.ok()) return false; @@ -83,9 +83,9 @@ return true; } -Opcode *OpcodeFactory::CreateDefaultOpcode() { return new Opcode("", -1); } +Opcode* OpcodeFactory::CreateDefaultOpcode() { return new Opcode("", -1); } -absl::StatusOr<Opcode *> OpcodeFactory::CreateOpcode(absl::string_view name) { +absl::StatusOr<Opcode*> OpcodeFactory::CreateOpcode(absl::string_view name) { if (opcode_names_.contains(name)) { return absl::InternalError( absl::StrCat("Opcode '", name, "' already declared")); @@ -97,26 +97,26 @@ return opcode; } -Opcode *OpcodeFactory::CreateChildOpcode(Opcode *opcode) const { +Opcode* OpcodeFactory::CreateChildOpcode(Opcode* opcode) const { if (opcode == nullptr) return nullptr; - auto *child = new Opcode(opcode->name(), -1); + auto* child = new Opcode(opcode->name(), -1); return child; } -absl::StatusOr<Opcode *> OpcodeFactory::CreateDerivedOpcode( - const Opcode *opcode, TemplateInstantiationArgs *args) { +absl::StatusOr<Opcode*> OpcodeFactory::CreateDerivedOpcode( + const Opcode* opcode, TemplateInstantiationArgs* args) { // Allocate a new opcode. Copy the basic information. auto new_opcode = new Opcode(opcode->name(), opcode->value()); new_opcode->set_instruction_size(opcode->instruction_size()); new_opcode->predicate_op_name_ = opcode->predicate_op_name(); new_opcode->op_locator_map_ = opcode->op_locator_map(); - for (auto const &src_op : opcode->source_op_vec()) { + for (auto const& src_op : opcode->source_op_vec()) { new_opcode->AppendSourceOp(src_op.name, src_op.is_array, src_op.is_reloc); } // Copy destination operands, but evaluate any latencies using the template // instantiation arguments, in case those expressions use them. - for (auto const *dest_op : opcode->dest_op_vec()) { + for (auto const* dest_op : opcode->dest_op_vec()) { if (dest_op->expression() == nullptr) { new_opcode->AppendDestOp(dest_op->name(), dest_op->is_array(), dest_op->is_reloc());
diff --git a/mpact/sim/decoder/opcode.h b/mpact/sim/decoder/opcode.h index e616a96..ca04563 100644 --- a/mpact/sim/decoder/opcode.h +++ b/mpact/sim/decoder/opcode.h
@@ -53,7 +53,7 @@ public: // Operand latency is defined by the expression. DestinationOperand(std::string name, bool is_array, bool is_reloc, - TemplateExpression *expression) + TemplateExpression* expression) : name_(std::move(name)), pascal_case_name_(ToPascalCase(name_)), expression_(expression), @@ -80,9 +80,9 @@ expression_ = nullptr; } - const std::string &name() const { return name_; } - const std::string &pascal_case_name() const { return pascal_case_name_; } - TemplateExpression *expression() const { return expression_; } + const std::string& name() const { return name_; } + const std::string& pascal_case_name() const { return pascal_case_name_; } + TemplateExpression* expression() const { return expression_; } bool is_array() const { return is_array_; } bool is_reloc() const { return is_reloc_; } bool HasLatency() const { return expression_ != nullptr; } @@ -94,7 +94,7 @@ "Template expression evaluation error", res.status().message())); } auto variant_value = res.value(); - auto *value_ptr = std::get_if<int>(&variant_value); + auto* value_ptr = std::get_if<int>(&variant_value); if (value_ptr == nullptr) { return absl::InternalError("Template expression type error"); } @@ -104,7 +104,7 @@ private: std::string name_; std::string pascal_case_name_; - TemplateExpression *expression_; + TemplateExpression* expression_; bool is_array_ = false; bool is_reloc_ = false; }; @@ -144,7 +144,7 @@ struct FormatInfo { FormatInfo() = default; // Use default copy constructor. - FormatInfo(const FormatInfo &) = default; + FormatInfo(const FormatInfo&) = default; std::string op_name; bool is_formatted = true; bool is_optional = false; @@ -158,18 +158,18 @@ struct DisasmFormat { DisasmFormat() = default; // Copy constructor. - DisasmFormat(const DisasmFormat &df) { + DisasmFormat(const DisasmFormat& df) { width = df.width; - for (auto const &frag : df.format_fragment_vec) { + for (auto const& frag : df.format_fragment_vec) { format_fragment_vec.push_back(frag); } - for (auto const *info : df.format_info_vec) { + for (auto const* info : df.format_info_vec) { format_info_vec.push_back(new FormatInfo(*info)); } } // Destructor. ~DisasmFormat() { - for (auto *info : format_info_vec) { + for (auto* info : format_info_vec) { delete info; } format_info_vec.clear(); @@ -177,25 +177,25 @@ int width = 0; int num_optional = 0; std::vector<std::string> format_fragment_vec; - std::vector<FormatInfo *> format_info_vec; + std::vector<FormatInfo*> format_info_vec; }; struct ResourceReference { - Resource *resource; + Resource* resource; bool is_array; - DestinationOperand *dest_op; - TemplateExpression *begin_expression; - TemplateExpression *end_expression; - ResourceReference(Resource *resource_, bool is_array_, - DestinationOperand *dest_op_, - TemplateExpression *begin_expr_, - TemplateExpression *end_expr_) + DestinationOperand* dest_op; + TemplateExpression* begin_expression; + TemplateExpression* end_expression; + ResourceReference(Resource* resource_, bool is_array_, + DestinationOperand* dest_op_, + TemplateExpression* begin_expr_, + TemplateExpression* end_expr_) : resource(resource_), is_array(is_array_), dest_op(dest_op_), begin_expression(begin_expr_), end_expression(end_expr_) {} - ResourceReference(const ResourceReference &rhs) { + ResourceReference(const ResourceReference& rhs) { resource = rhs.resource; is_array = rhs.is_array; dest_op = rhs.dest_op; @@ -230,47 +230,47 @@ // methods will be left to the user of this generator tool. void AppendSourceOp(absl::string_view op_name, bool is_array, bool is_reloc); void AppendDestOp(absl::string_view op_name, bool is_array, bool is_reloc, - TemplateExpression *expression); + TemplateExpression* expression); void AppendDestOp(absl::string_view op_name, bool is_array, bool is_reloc); - DestinationOperand *GetDestOp(absl::string_view op_name); + DestinationOperand* GetDestOp(absl::string_view op_name); // Append child opcode specification. - void AppendChild(Opcode *op) { child_ = op; } + void AppendChild(Opcode* op) { child_ = op; } // Checks destination latencies with the given function. Returns true if all // comply. - bool ValidateDestLatencies(const std::function<bool(int)> &validator) const; + bool ValidateDestLatencies(const std::function<bool(int)>& validator) const; int instruction_size() const { return instruction_size_; } void set_instruction_size(int val) { instruction_size_ = val; } - Opcode *child() const { return child_; } - Opcode *parent() const { return parent_; } - const std::string &name() const { return name_; } - const std::string &pascal_name() const { return pascal_name_; } + Opcode* child() const { return child_; } + Opcode* parent() const { return parent_; } + const std::string& name() const { return name_; } + const std::string& pascal_name() const { return pascal_name_; } // Each opcode is assigned a unique value that is used in the slot class // enum definition. int value() const { return value_; } // Predicate, source and destination operand names. - const std::string &predicate_op_name() const { return predicate_op_name_; } + const std::string& predicate_op_name() const { return predicate_op_name_; } void set_predicate_op_name(absl::string_view op_name) { predicate_op_name_ = op_name; } - const std::vector<SourceOperand> &source_op_vec() const { + const std::vector<SourceOperand>& source_op_vec() const { return source_op_vec_; } - const std::vector<DestinationOperand *> &dest_op_vec() const { + const std::vector<DestinationOperand*>& dest_op_vec() const { return dest_op_vec_; } - OpLocatorMap &op_locator_map() { return op_locator_map_; } // not const. - const OpLocatorMap &op_locator_map() const { return op_locator_map_; } + OpLocatorMap& op_locator_map() { return op_locator_map_; } // not const. + const OpLocatorMap& op_locator_map() const { return op_locator_map_; } private: Opcode(absl::string_view name, int value); int instruction_size_; - Opcode *child_ = nullptr; - Opcode *parent_ = nullptr; + Opcode* child_ = nullptr; + Opcode* parent_ = nullptr; std::string predicate_op_name_; std::vector<SourceOperand> source_op_vec_; - std::vector<DestinationOperand *> dest_op_vec_; - absl::flat_hash_map<std::string, DestinationOperand *> dest_op_map_; + std::vector<DestinationOperand*> dest_op_vec_; + absl::flat_hash_map<std::string, DestinationOperand*> dest_op_map_; std::string name_; std::string pascal_name_; std::string semfunc_code_string_; @@ -285,18 +285,18 @@ // If the opcode doesn't yet exist, create a new opcode and return the // pointer, otherwise return an error code. - absl::StatusOr<Opcode *> CreateOpcode(absl::string_view name); - Opcode *CreateDefaultOpcode(); - Opcode *CreateChildOpcode(Opcode *opcode) const; + absl::StatusOr<Opcode*> CreateOpcode(absl::string_view name); + Opcode* CreateDefaultOpcode(); + Opcode* CreateChildOpcode(Opcode* opcode) const; // Duplicate the opcode, but evaluate the destination latency expressions // with the template argument expression vector. - absl::StatusOr<Opcode *> CreateDerivedOpcode(const Opcode *opcode, - TemplateInstantiationArgs *args); - const std::vector<Opcode *> &opcode_vec() const { return opcode_vec_; } + absl::StatusOr<Opcode*> CreateDerivedOpcode(const Opcode* opcode, + TemplateInstantiationArgs* args); + const std::vector<Opcode*>& opcode_vec() const { return opcode_vec_; } private: absl::btree_set<std::string> opcode_names_; - std::vector<Opcode *> opcode_vec_; + std::vector<Opcode*> opcode_vec_; int opcode_value_ = 1; };
diff --git a/mpact/sim/decoder/overlay.cc b/mpact/sim/decoder/overlay.cc index cdc1f0c..71e9f89 100644 --- a/mpact/sim/decoder/overlay.cc +++ b/mpact/sim/decoder/overlay.cc
@@ -36,7 +36,7 @@ using ::mpact::sim::machine_description::instruction_set::ToPascalCase; using ::mpact::sim::machine_description::instruction_set::ToSnakeCase; -BitsOrField::BitsOrField(Field *field, int high, int low, int width) +BitsOrField::BitsOrField(Field* field, int high, int low, int width) : field_(field), high_(high), low_(low), width_(width), position_(-1) {} BitsOrField::BitsOrField(BinaryNum bin_num, int width) @@ -44,14 +44,14 @@ width_ = bin_num_.width; } -Overlay::Overlay(std::string name, bool is_signed, int width, Format *format) +Overlay::Overlay(std::string name, bool is_signed, int width, Format* format) : name_(name), is_signed_(is_signed), declared_width_(width), format_(format) {} Overlay::~Overlay() { - for (auto *item : component_vec_) { + for (auto* item : component_vec_) { delete item; } component_vec_.clear(); @@ -83,7 +83,7 @@ // Adds a series of bit references to a field. absl::Status Overlay::AddFieldReference(std::string field_name, - const std::vector<BitRange> &ranges) { + const std::vector<BitRange>& ranges) { // Verify that the fields is valid. auto field = format_->GetField(field_name); if (field == nullptr) { @@ -92,7 +92,7 @@ "' does not name a field in '", format_->name(), "'")); } // Scan the ranges. - for (auto &range : ranges) { + for (auto& range : ranges) { // Verify that the ranges don't refer to bits that don't exist. if (range.first < 0 || range.first >= field->width) { return absl::InternalError(absl::StrCat("bit index '", range.first, @@ -117,8 +117,8 @@ return absl::OkStatus(); } -absl::Status Overlay::AddFormatReference(const std::vector<BitRange> &ranges) { - for (auto &range : ranges) { +absl::Status Overlay::AddFormatReference(const std::vector<BitRange>& ranges) { + for (auto& range : ranges) { // Check that the range is legal for the format. if (range.first < 0 || range.first >= format_->declared_width()) { return absl::InternalError(absl::StrCat("bit index '", range.first, @@ -151,7 +151,7 @@ high_low_computed_ = true; int position = declared_width_ - 1; - for (auto *component : component_vec_) { + for (auto* component : component_vec_) { component->set_position(position); if (component->high() >= 0) { // Field or format reference. @@ -174,7 +174,7 @@ "Overlay definition incomplete: declared width != computed width"); uint64_t value = 0; - for (auto *component : component_vec_) { + for (auto* component : component_vec_) { if (component->high() < 0) { BinaryNum bin_num = component->bin_num(); // If value == 0, nothing to or in - it just takes space. @@ -194,7 +194,7 @@ absl::StatusOr<uint64_t> Overlay::GetBitField(uint64_t input) { uint64_t bitfield = 0; - for (auto *component : component_vec_) { + for (auto* component : component_vec_) { // Constant bits do not map to the instruction word. if (component->high() < 0) continue; uint64_t mask = ((1ULL << component->width()) - 1); @@ -205,7 +205,7 @@ return bitfield; } -bool Overlay::operator==(const Overlay &rhs) const { +bool Overlay::operator==(const Overlay& rhs) const { if (declared_width_ > 64) { return WriteComplexValueExtractor("value", "result", "") == rhs.WriteComplexValueExtractor("value", "result", ""); @@ -215,7 +215,7 @@ } } -bool Overlay::operator!=(const Overlay &rhs) const { return !(*this == rhs); } +bool Overlay::operator!=(const Overlay& rhs) const { return !(*this == rhs); } // Return a string with the code (not counting function definition, variable // definition or return statement) for extracting the value of the overlay from @@ -225,7 +225,7 @@ absl::string_view result) const { std::string output; std::string assign = " = "; - for (auto *component : component_vec_) { + for (auto* component : component_vec_) { if (component->high() < 0) { // Binary literals are added. BinaryNum bin_num = component->bin_num(); @@ -289,7 +289,7 @@ union_type, "*>(", format_->declared_width() > 64 ? "value);\n" : "&value);\n"); std::string result_type = GetUIntType(declared_width_); - for (auto *component : component_vec_) { + for (auto* component : component_vec_) { if (component->high() < 0) { // Binary literals are added. BinaryNum bin_num = component->bin_num(); @@ -323,7 +323,7 @@ absl::string_view return_type) const { std::string output; std::string assign = " = "; - for (auto *component : component_vec_) { + for (auto* component : component_vec_) { if (component->high() < 0) { BinaryNum bin_num = component->bin_num(); // If the value is 0, no need to 'or' it in.
diff --git a/mpact/sim/decoder/overlay.h b/mpact/sim/decoder/overlay.h index cd05ed7..ebd638b 100644 --- a/mpact/sim/decoder/overlay.h +++ b/mpact/sim/decoder/overlay.h
@@ -47,10 +47,10 @@ // Helper class to store an individual component in an overlay. class BitsOrField { public: - BitsOrField(Field *field, int high, int low, int width); + BitsOrField(Field* field, int high, int low, int width); BitsOrField(BinaryNum bin_num, int width); - Field *field() const { return field_; } + Field* field() const { return field_; } // If != >= 0, this is the high bit position of the format that this component // refers to. int high() const { return high_; } @@ -70,7 +70,7 @@ BinaryNum bin_num() const { return bin_num_; } private: - Field *field_; + Field* field_; int high_ = -1; int low_ = -1; int width_ = -1; @@ -82,7 +82,7 @@ // format. class Overlay { public: - Overlay(std::string name, bool is_signed, int width, Format *format); + Overlay(std::string name, bool is_signed, int width, Format* format); ~Overlay(); // The following methods add components to the overlay. Components are added @@ -95,10 +95,10 @@ // Add only the bit ranges from the given field to the overlay (in order of // appearance in the vector). absl::Status AddFieldReference(std::string field_name, - const std::vector<BitRange> &ranges); + const std::vector<BitRange>& ranges); // Add the bit ranges from the format to the overlay (in order of appearance // in the vector). - absl::Status AddFormatReference(const std::vector<BitRange> &ranges); + absl::Status AddFormatReference(const std::vector<BitRange>& ranges); // Adjusts high/low of each field reference. absl::Status ComputeHighLow(); @@ -109,26 +109,26 @@ absl::string_view result) const; std::string WritePackedStructValueExtractor(absl::string_view value, absl::string_view result) const; - absl::StatusOr<uint64_t> GetValue(uint8_t *input); + absl::StatusOr<uint64_t> GetValue(uint8_t* input); std::string WriteComplexValueExtractor(absl::string_view value, absl::string_view result, absl::string_view return_type) const; absl::StatusOr<uint64_t> GetBitField(uint64_t input); - bool operator==(const Overlay &rhs) const; - bool operator!=(const Overlay &rhs) const; + bool operator==(const Overlay& rhs) const; + bool operator!=(const Overlay& rhs) const; // Accessors. - const std::string &name() const { return name_; } + const std::string& name() const { return name_; } bool is_signed() const { return is_signed_; } int declared_width() const { return declared_width_; } int computed_width() const { return computed_width_; } uint64_t mask() const { return mask_; } - const std::vector<BitsOrField *> &component_vec() const { + const std::vector<BitsOrField*>& component_vec() const { return component_vec_; } bool must_be_extracted() const { return must_be_extracted_; } - Format *format() const { return format_; } + Format* format() const { return format_; } private: std::string name_; @@ -138,8 +138,8 @@ int computed_width_ = 0; uint64_t mask_ = 0; bool must_be_extracted_ = false; - Format *format_ = nullptr; - std::vector<BitsOrField *> component_vec_; + Format* format_ = nullptr; + std::vector<BitsOrField*> component_vec_; }; } // namespace bin_format
diff --git a/mpact/sim/decoder/proto_constraint_expression.cc b/mpact/sim/decoder/proto_constraint_expression.cc index 36ba220..40ae973 100644 --- a/mpact/sim/decoder/proto_constraint_expression.cc +++ b/mpact/sim/decoder/proto_constraint_expression.cc
@@ -56,7 +56,7 @@ } // Operator to implement negation. -absl::StatusOr<ProtoValue> operator-(const ProtoValue &value) { +absl::StatusOr<ProtoValue> operator-(const ProtoValue& value) { switch (value.index()) { case *ProtoValueIndex::kInt32: return -std::get<int32_t>(value);
diff --git a/mpact/sim/decoder/proto_constraint_expression.h b/mpact/sim/decoder/proto_constraint_expression.h index b293cde..794ea6b 100644 --- a/mpact/sim/decoder/proto_constraint_expression.h +++ b/mpact/sim/decoder/proto_constraint_expression.h
@@ -138,7 +138,7 @@ if (!res.ok() || !std::holds_alternative<T>(res.value())) return T(); return std::get<T>(res.value()); } - virtual ProtoConstraintExpression *Clone() const = 0; + virtual ProtoConstraintExpression* Clone() const = 0; virtual google::protobuf::FieldDescriptor::CppType cpp_type() const = 0; virtual int variant_type() const = 0; }; @@ -146,11 +146,11 @@ // Unary negate expression. class ProtoConstraintNegateExpression : public ProtoConstraintExpression { public: - explicit ProtoConstraintNegateExpression(ProtoConstraintExpression *expr) + explicit ProtoConstraintNegateExpression(ProtoConstraintExpression* expr) : expr_(expr) {} ~ProtoConstraintNegateExpression() override; absl::StatusOr<ProtoValue> GetValue() const override; - ProtoConstraintExpression *Clone() const override { + ProtoConstraintExpression* Clone() const override { return new ProtoConstraintNegateExpression(expr_->Clone()); } google::protobuf::FieldDescriptor::CppType cpp_type() const override { @@ -159,18 +159,18 @@ int variant_type() const override { return expr_->variant_type(); } private: - ProtoConstraintExpression *expr_; + ProtoConstraintExpression* expr_; }; // Enumeration value expression. class ProtoConstraintEnumExpression : public ProtoConstraintExpression { public: explicit ProtoConstraintEnumExpression( - const google::protobuf::EnumValueDescriptor *enum_value) + const google::protobuf::EnumValueDescriptor* enum_value) : enum_value_(enum_value) {} ~ProtoConstraintEnumExpression() override = default; absl::StatusOr<ProtoValue> GetValue() const override; - ProtoConstraintExpression *Clone() const override { + ProtoConstraintExpression* Clone() const override { return new ProtoConstraintEnumExpression(enum_value_); } google::protobuf::FieldDescriptor::CppType cpp_type() const override { @@ -179,20 +179,20 @@ int variant_type() const override { return *ProtoValueIndex::kInt32; } private: - const google::protobuf::EnumValueDescriptor *enum_value_ = nullptr; + const google::protobuf::EnumValueDescriptor* enum_value_ = nullptr; }; // Constant value expression. class ProtoConstraintValueExpression : public ProtoConstraintExpression { public: - explicit ProtoConstraintValueExpression(const ProtoValue &value) + explicit ProtoConstraintValueExpression(const ProtoValue& value) : value_(value) {} template <typename T> - explicit ProtoConstraintValueExpression(const T &value) : value_(value) {} + explicit ProtoConstraintValueExpression(const T& value) : value_(value) {} ~ProtoConstraintValueExpression() override = default; absl::StatusOr<ProtoValue> GetValue() const override { return value_; } - ProtoConstraintExpression *Clone() const override { + ProtoConstraintExpression* Clone() const override { return new ProtoConstraintValueExpression(value_); } google::protobuf::FieldDescriptor::CppType cpp_type() const override {
diff --git a/mpact/sim/decoder/proto_constraint_value_set.cc b/mpact/sim/decoder/proto_constraint_value_set.cc index 7a42ebb..27e1910 100644 --- a/mpact/sim/decoder/proto_constraint_value_set.cc +++ b/mpact/sim/decoder/proto_constraint_value_set.cc
@@ -32,8 +32,8 @@ // Local helper function used to get the minimum value for a given constraint // expression based on its type. -static ProtoConstraintExpression *MinValueExpr( - const ProtoConstraintExpression *expr) { +static ProtoConstraintExpression* MinValueExpr( + const ProtoConstraintExpression* expr) { auto res = expr->GetValue(); if (!res.ok()) return nullptr; auto value = res.value(); @@ -65,8 +65,8 @@ // Local helper function used to get the minimum value for a given constraint // expression based on its type. -static ProtoConstraintExpression *MaxValueExpr( - const ProtoConstraintExpression *expr) { +static ProtoConstraintExpression* MaxValueExpr( + const ProtoConstraintExpression* expr) { auto res = expr->GetValue(); if (!res.ok()) return nullptr; auto value = res.value(); @@ -98,8 +98,8 @@ // Basic constructor taking explicit arguments for the data members. ProtoConstraintValueSet::ProtoConstraintValueSet( - const ProtoConstraintExpression *min, bool min_included, - const ProtoConstraintExpression *max, bool max_included) { + const ProtoConstraintExpression* min, bool min_included, + const ProtoConstraintExpression* max, bool max_included) { // If either expression is nullptr, the range is malformed and treated as // empty. if ((min == nullptr || max == nullptr)) return; @@ -113,9 +113,9 @@ // Constructor that initializes the value set based on the expression that is // part of the constraint. ProtoConstraintValueSet::ProtoConstraintValueSet( - const ProtoConstraint *constraint) { + const ProtoConstraint* constraint) { field_descriptor_ = constraint->field_descriptor; - auto *expr = constraint->expr; + auto* expr = constraint->expr; switch (constraint->op) { case ConstraintType::kEq: subranges_.emplace_back(expr->Clone(), true, expr->Clone(), true); @@ -138,15 +138,15 @@ break; case ConstraintType::kHas: { int32_t value = -1; - auto *field = constraint->field_descriptor; - auto *one_of = constraint->field_descriptor->containing_oneof(); + auto* field = constraint->field_descriptor; + auto* one_of = constraint->field_descriptor->containing_oneof(); for (int32_t i = 0; i < one_of->field_count(); ++i) { if (one_of->field(i)->name() == field->name()) { value = i; break; } } - ProtoConstraintExpression *expr = + ProtoConstraintExpression* expr = new ProtoConstraintValueExpression(value); subranges_.emplace_back(expr, true, expr->Clone(), true); break; @@ -158,9 +158,9 @@ // Copy constructor. ProtoConstraintValueSet::ProtoConstraintValueSet( - const ProtoConstraintValueSet &other) { + const ProtoConstraintValueSet& other) { field_descriptor_ = other.field_descriptor_; - for (auto const &subrange : other.subranges_) { + for (auto const& subrange : other.subranges_) { subranges_.emplace_back( subrange.min == nullptr ? nullptr : subrange.min->Clone(), subrange.min_included, @@ -170,7 +170,7 @@ } ProtoConstraintValueSet::~ProtoConstraintValueSet() { - for (auto &subrange : subranges_) { + for (auto& subrange : subranges_) { delete subrange.min; delete subrange.max; } @@ -181,7 +181,7 @@ // sets. template <typename T> ProtoConstraintValueSet::SubRange ProtoConstraintValueSet::IntersectSubrange( - const SubRange &lhs_subrange, const SubRange &rhs_subrange) const { + const SubRange& lhs_subrange, const SubRange& rhs_subrange) const { // If both min and max are nullptr, then lhs is already a null set. if ((lhs_subrange.min == nullptr) && (rhs_subrange.min == nullptr)) { return {nullptr, false, nullptr, false}; @@ -260,11 +260,11 @@ // Iterate over the subranges to perform subrange by subrange intersection. template <typename T> void ProtoConstraintValueSet::IntersectSubranges( - const std::vector<SubRange> &lhs_subranges, - const std::vector<SubRange> &rhs_subranges, - std::vector<SubRange> &new_subranges) const { - for (auto const &lhs_subrange : lhs_subranges) { - for (auto const &rhs_subrange : rhs_subranges) { + const std::vector<SubRange>& lhs_subranges, + const std::vector<SubRange>& rhs_subranges, + std::vector<SubRange>& new_subranges) const { + for (auto const& lhs_subrange : lhs_subranges) { + for (auto const& rhs_subrange : rhs_subranges) { auto subrange = IntersectSubrange<T>(lhs_subrange, rhs_subrange); // Ignore empty sets. if ((subrange.min != nullptr) && (subrange.max != nullptr)) { @@ -275,11 +275,11 @@ } absl::Status ProtoConstraintValueSet::IntersectWith( - const ProtoConstraintValueSet &rhs) { + const ProtoConstraintValueSet& rhs) { std::vector<SubRange> new_subranges; // If either set is empty, the result is empty. if (IsEmpty() || rhs.IsEmpty()) { - for (auto &subrange : subranges_) { + for (auto& subrange : subranges_) { delete subrange.min; delete subrange.max; } @@ -288,9 +288,9 @@ } // Get expressions to check on type compatibility. Signal error if types // don't match. - auto const *lhs_expr = + auto const* lhs_expr = subranges_[0].min != nullptr ? subranges_[0].min : subranges_[0].max; - auto const *rhs_expr = rhs.subranges_[0].min != nullptr + auto const* rhs_expr = rhs.subranges_[0].min != nullptr ? rhs.subranges_[0].min : rhs.subranges_[0].max; if ((lhs_expr != nullptr) && (rhs_expr != nullptr) && @@ -326,7 +326,7 @@ absl::StrCat("Unsupported type in range")); } // Clean up the old subranges and replace with the new subranges. - for (auto &subrange : subranges_) { + for (auto& subrange : subranges_) { delete subrange.min; delete subrange.max; } @@ -336,10 +336,10 @@ } absl::Status ProtoConstraintValueSet::UnionWith( - const ProtoConstraintValueSet &rhs) { + const ProtoConstraintValueSet& rhs) { if (rhs.IsEmpty()) return absl::OkStatus(); // Copy the rhs subranges. - for (auto &subrange : rhs.subranges_) { + for (auto& subrange : rhs.subranges_) { SubRange new_subrange; new_subrange.min = subrange.min != nullptr ? subrange.min->Clone() : nullptr;
diff --git a/mpact/sim/decoder/proto_constraint_value_set.h b/mpact/sim/decoder/proto_constraint_value_set.h index 0c2052d..1986a13 100644 --- a/mpact/sim/decoder/proto_constraint_value_set.h +++ b/mpact/sim/decoder/proto_constraint_value_set.h
@@ -39,13 +39,13 @@ class ProtoConstraintValueSet { public: struct SubRange { - const ProtoConstraintExpression *min = nullptr; + const ProtoConstraintExpression* min = nullptr; bool min_included; - const ProtoConstraintExpression *max = nullptr; + const ProtoConstraintExpression* max = nullptr; bool max_included; SubRange() = default; - SubRange(const ProtoConstraintExpression *min, bool min_included, - const ProtoConstraintExpression *max, bool max_included) + SubRange(const ProtoConstraintExpression* min, bool min_included, + const ProtoConstraintExpression* max, bool max_included) : min(min), min_included(min_included), max(max), @@ -53,26 +53,26 @@ }; ProtoConstraintValueSet() = default; - ProtoConstraintValueSet(const ProtoConstraintExpression *min, + ProtoConstraintValueSet(const ProtoConstraintExpression* min, bool min_included, - const ProtoConstraintExpression *max, + const ProtoConstraintExpression* max, bool max_included); - explicit ProtoConstraintValueSet(const ProtoConstraint *constraint); - explicit ProtoConstraintValueSet(const ProtoConstraint &constraint) + explicit ProtoConstraintValueSet(const ProtoConstraint* constraint); + explicit ProtoConstraintValueSet(const ProtoConstraint& constraint) : ProtoConstraintValueSet(&constraint) {} - ProtoConstraintValueSet(const ProtoConstraintValueSet &other); + ProtoConstraintValueSet(const ProtoConstraintValueSet& other); ~ProtoConstraintValueSet(); // Intersect rhs with this, modifying this value set. - absl::Status IntersectWith(const ProtoConstraintValueSet &rhs); + absl::Status IntersectWith(const ProtoConstraintValueSet& rhs); // Simply add the sub ranges associated with rhs to this. - absl::Status UnionWith(const ProtoConstraintValueSet &rhs); + absl::Status UnionWith(const ProtoConstraintValueSet& rhs); bool IsEmpty() const; // Accessors. - const std::vector<SubRange> &subranges() const { return subranges_; } - const google::protobuf::FieldDescriptor *field_descriptor() const { + const std::vector<SubRange>& subranges() const { return subranges_; } + const google::protobuf::FieldDescriptor* field_descriptor() const { return field_descriptor_; } @@ -80,15 +80,15 @@ // Private templated helper methods for intersection. The definitions are in // the .cc file. template <typename T> - SubRange IntersectSubrange(const SubRange &lhs_subrange, - const SubRange &rhs_subrange) const; + SubRange IntersectSubrange(const SubRange& lhs_subrange, + const SubRange& rhs_subrange) const; template <typename T> - void IntersectSubranges(const std::vector<SubRange> &lhs_subranges, - const std::vector<SubRange> &rhs_subranges, - std::vector<SubRange> &new_subranges) const; + void IntersectSubranges(const std::vector<SubRange>& lhs_subranges, + const std::vector<SubRange>& rhs_subranges, + std::vector<SubRange>& new_subranges) const; // The range consists of a union of a number of subranges. std::vector<SubRange> subranges_; - const google::protobuf::FieldDescriptor *field_descriptor_ = nullptr; + const google::protobuf::FieldDescriptor* field_descriptor_ = nullptr; }; } // namespace proto_fmt
diff --git a/mpact/sim/decoder/proto_encoding_group.cc b/mpact/sim/decoder/proto_encoding_group.cc index 93be8e8..f311316 100644 --- a/mpact/sim/decoder/proto_encoding_group.cc +++ b/mpact/sim/decoder/proto_encoding_group.cc
@@ -45,10 +45,10 @@ using ::mpact::sim::machine_description::instruction_set::ToSnakeCase; struct FieldInfo { - const google::protobuf::FieldDescriptor *field; - const google::protobuf::OneofDescriptor *oneof; - QualifiedIdentCtx *ctx; - absl::btree_multimap<int64_t, const ProtoInstructionEncoding *> value_map; + const google::protobuf::FieldDescriptor* field; + const google::protobuf::OneofDescriptor* oneof; + QualifiedIdentCtx* ctx; + absl::btree_multimap<int64_t, const ProtoInstructionEncoding*> value_map; int64_t min_value = 0; int64_t max_value = 0; size_t unique_values = 0; @@ -57,48 +57,48 @@ using ConstraintValueRange = ProtoConstraintValueSet::SubRange; -ProtoEncodingGroup::ProtoEncodingGroup(ProtoInstructionGroup *inst_group, +ProtoEncodingGroup::ProtoEncodingGroup(ProtoInstructionGroup* inst_group, int level, - DecoderErrorListener *error_listener) + DecoderErrorListener* error_listener) : ProtoEncodingGroup(nullptr, inst_group, level, error_listener) {} -ProtoEncodingGroup::ProtoEncodingGroup(ProtoEncodingGroup *parent, - ProtoInstructionGroup *inst_group, +ProtoEncodingGroup::ProtoEncodingGroup(ProtoEncodingGroup* parent, + ProtoInstructionGroup* inst_group, int level, - DecoderErrorListener *error_listener) + DecoderErrorListener* error_listener) : inst_group_(inst_group), parent_(parent), error_listener_(error_listener), level_(level) {} ProtoEncodingGroup::~ProtoEncodingGroup() { - for (auto const &[unused, field_info] : field_map_) { + for (auto const& [unused, field_info] : field_map_) { delete field_info; } field_map_.clear(); - for (auto const *enc : encoding_vec_) { + for (auto const* enc : encoding_vec_) { delete enc; } encoding_vec_.clear(); inst_group_ = nullptr; - for (auto const *enc_group : encoding_group_vec_) { + for (auto const* enc_group : encoding_group_vec_) { delete enc_group; } encoding_group_vec_.clear(); } -void ProtoEncodingGroup::AddEncoding(ProtoInstructionEncoding *enc) { +void ProtoEncodingGroup::AddEncoding(ProtoInstructionEncoding* enc) { // All constraints in equal_constraints are kEq constraints on integer // fields, or are kHas constraints which are kEq constraints on the // '_value()' function of the one_of field (which is an int value). // The first step is to determine which constraints differentiate the most // instructions in the encoding group. - for (auto *eq_constraint : enc->equal_constraints()) { - auto const *field = eq_constraint->field_descriptor; - auto const *oneof = field->containing_oneof(); - auto const *expr = eq_constraint->expr; + for (auto* eq_constraint : enc->equal_constraints()) { + auto const* field = eq_constraint->field_descriptor; + auto const* oneof = field->containing_oneof(); + auto const* expr = eq_constraint->expr; auto op = eq_constraint->op; - auto *qualifed_ident_ctx = eq_constraint->ctx->qualified_ident(); + auto* qualifed_ident_ctx = eq_constraint->ctx->qualified_ident(); int64_t value; // Store the value in an int64_t. if (op == ConstraintType::kEq) { switch (expr->variant_type()) { @@ -149,7 +149,7 @@ // If the field_info doesn't exist, add a new field_info. auto name = field != nullptr ? field->name() : oneof->name(); auto iter = field_map_.find(name); - FieldInfo *field_info = nullptr; + FieldInfo* field_info = nullptr; if (iter == field_map_.end()) { field_info = new FieldInfo{field, oneof}; field_info->min_value = std::numeric_limits<int64_t>::max(); @@ -168,9 +168,9 @@ encoding_vec_.push_back(enc); // Populate the other_* sets. These are used later to ensure that sub groups // aren't added with differentiators that are also used in other constraints. - for (auto *constraint : enc->other_constraints()) { - auto const *field = constraint->field_descriptor; - auto const *oneof = field->containing_oneof(); + for (auto* constraint : enc->other_constraints()) { + auto const* field = constraint->field_descriptor; + auto const* oneof = field->containing_oneof(); if (oneof != nullptr) { other_oneof_set_.insert(oneof); continue; @@ -187,12 +187,12 @@ // the number of total values in its interval. // To start with just pick the one with the largest number of unique values, // as that should create a shallower decoding tree. - FieldInfo *best_field = nullptr; - absl::flat_hash_set<ProtoInstructionEncoding *> encodings; + FieldInfo* best_field = nullptr; + absl::flat_hash_set<ProtoInstructionEncoding*> encodings; for (auto enc : encoding_vec_) { encodings.insert(enc); } - for (auto &[unused, field_info] : field_map_) { + for (auto& [unused, field_info] : field_map_) { // First check if the field is used in any other constraints, e.g., '>' or // '!='. If so, it is not a candidate for a direct lookup of the value. if (other_field_set_.contains(field_info->field)) continue; @@ -221,7 +221,7 @@ for (auto iter = best_field->value_map.begin(); iter != best_field->value_map.end(); /*empty*/) { - auto *enc_group = + auto* enc_group = new ProtoEncodingGroup(this, inst_group_, level_ + 1, error_listener_); int64_t value = iter->first; enc_group->set_value(value); @@ -229,11 +229,11 @@ // First create a copy of the encoding and remove the constraint // that corresponds with the field info, so it will not be considered // below. - ProtoInstructionEncoding *enc = + ProtoInstructionEncoding* enc = new ProtoInstructionEncoding(*(iter->second)); // Remove the best_field constraint from the new encoding object. auto v_iter = enc->equal_constraints().begin(); - ProtoConstraint *constraint = nullptr; + ProtoConstraint* constraint = nullptr; while (v_iter != enc->equal_constraints().end()) { constraint = *v_iter; if (constraint->op == ConstraintType::kEq) { @@ -265,14 +265,14 @@ // Any encodings remaining in the map have to be added to each of the sub // groups, as they weren't selected by value. for (auto enc : encodings) { - for (auto *enc_group : encoding_group_vec_) { + for (auto* enc_group : encoding_group_vec_) { auto enc_copy = new ProtoInstructionEncoding(*enc); enc_group->AddEncoding(enc_copy); } } encodings.clear(); // Recursively try to split the child encoding groups. - for (auto *enc_group : encoding_group_vec_) { + for (auto* enc_group : encoding_group_vec_) { enc_group->AddSubGroups(); } } @@ -284,11 +284,11 @@ // Encodings have to have additional constraints to differentiate between each // other, so check to see if any of them have none, and if so, signal an // error. - for (auto *enc : encoding_vec_) { + for (auto* enc : encoding_vec_) { if (enc->equal_constraints().empty() && enc->other_constraints().empty()) { std::string msg = absl::StrCat("Decoding ambiguity between '", enc->name(), "' and :"); - for (auto *other_enc : encoding_vec_) { + for (auto* other_enc : encoding_vec_) { if (enc == other_enc) continue; absl::StrAppend(&msg, " '", other_enc->name(), "'"); } @@ -300,36 +300,36 @@ // Check for identical or overlapping constraints. // First sort the constraints in each vector. - std::vector<std::vector<ProtoConstraint *>> constraints; + std::vector<std::vector<ProtoConstraint*>> constraints; constraints.reserve(encoding_vec_.size()); - for (auto *enc : encoding_vec_) { + for (auto* enc : encoding_vec_) { constraints.push_back({}); - for (auto *constraint : enc->equal_constraints()) { + for (auto* constraint : enc->equal_constraints()) { constraints.back().push_back(constraint); } - for (auto *constraint : enc->other_constraints()) { + for (auto* constraint : enc->other_constraints()) { constraints.back().push_back(constraint); } } for (int i = 0; i < constraints.size(); ++i) { std::sort( constraints[i].begin(), constraints[i].end(), - [](const ProtoConstraint *lhs, const ProtoConstraint *rhs) -> bool { + [](const ProtoConstraint* lhs, const ProtoConstraint* rhs) -> bool { return lhs->field_descriptor->full_name() < rhs->field_descriptor->full_name(); }); } // Now create value value sets for each field descriptor, combining multiple // constraints on the same field descriptor into a single set of values. - std::vector<std::vector<ProtoConstraintValueSet *>> value_sets; + std::vector<std::vector<ProtoConstraintValueSet*>> value_sets; value_sets.reserve(encoding_vec_.size()); - for (auto const &constraint_vec : constraints) { - const google::protobuf::FieldDescriptor *previous = nullptr; + for (auto const& constraint_vec : constraints) { + const google::protobuf::FieldDescriptor* previous = nullptr; value_sets.push_back({}); - for (auto const *constraint : constraint_vec) { + for (auto const* constraint : constraint_vec) { // If it's the first occurance of a field descriptor, create a new // range on this constraint. - ProtoConstraintValueSet *value_set = nullptr; + ProtoConstraintValueSet* value_set = nullptr; if (previous != constraint->field_descriptor) { previous = constraint->field_descriptor; value_set = new ProtoConstraintValueSet(constraint); @@ -343,8 +343,8 @@ // Check for error. if (!status.ok()) { // Clean up. - for (auto &value_set_list : value_sets) { - for (auto *value_set : value_set_list) delete value_set; + for (auto& value_set_list : value_sets) { + for (auto* value_set : value_set_list) delete value_set; } value_sets.clear(); // Signal error. @@ -365,16 +365,16 @@ } } // Clean up. - for (auto &value_set_list : value_sets) { - for (auto *value_set : value_set_list) delete value_set; + for (auto& value_set_list : value_sets) { + for (auto* value_set : value_set_list) delete value_set; } } // Determine if the constraints overlap for two encodings lhs and rhs based on // the value sets. bool ProtoEncodingGroup::DoConstraintsOverlap( - const std::vector<ProtoConstraintValueSet *> &lhs, - const std::vector<ProtoConstraintValueSet *> &rhs) { + const std::vector<ProtoConstraintValueSet*>& lhs, + const std::vector<ProtoConstraintValueSet*>& rhs) { auto iter_lhs = lhs.begin(); auto iter_rhs = rhs.begin(); while ((iter_lhs != lhs.end()) && (iter_rhs != rhs.end())) { @@ -433,7 +433,7 @@ // Helper lambda. auto generate_condition = - [](const ProtoConstraint *constraint) -> std::string { + [](const ProtoConstraint* constraint) -> std::string { std::string output; if (constraint->op == ConstraintType::kHas) { std::string ident = constraint->ctx->qualified_ident()->getText(); @@ -466,15 +466,15 @@ // Generate a chained if-else if-else-statement for the encodings in the // encoding vector. std::string indent_body(indent_width + 2, ' '); - for (auto *enc : encoding_vec_) { + for (auto* enc : encoding_vec_) { // Generate the if statement conditions. absl::StrAppend(&output, indent, if_sep, "if ("); std::string cond_sep; - for (auto const *constraint : enc->equal_constraints()) { + for (auto const* constraint : enc->equal_constraints()) { absl::StrAppend(&output, cond_sep, generate_condition(constraint)); cond_sep = " && "; } - for (auto const *constraint : enc->other_constraints()) { + for (auto const* constraint : enc->other_constraints()) { absl::StrAppend(&output, cond_sep, generate_condition(constraint)); cond_sep = " && "; } @@ -498,7 +498,7 @@ namespace { -bool LessThan(ProtoEncodingGroup *lhs, ProtoEncodingGroup *rhs) { +bool LessThan(ProtoEncodingGroup* lhs, ProtoEncodingGroup* rhs) { return lhs->value() < rhs->value(); } @@ -527,7 +527,7 @@ "absl::NoDestructor<absl::flat_hash_map<int32_t, std::function<", opcode_enum, "(", message_type_name, ", ", decoder_class, "*)>>> ", map_name, "({\n"); - for (auto *enc_group : encoding_group_vec_) { + for (auto* enc_group : encoding_group_vec_) { auto enc_value = enc_group->value(); absl::StrAppend(&output, " {", enc_value, ", ", fcn_name, "_", enc_value, "},\n"); @@ -582,7 +582,7 @@ absl::string_view message_type_name) { std::string output; // Emit decoders for subordinate groups (lower in the hierarchy). - for (auto *enc_group : encoding_group_vec_) { + for (auto* enc_group : encoding_group_vec_) { absl::StrAppend( &output, enc_group->EmitDecoders(absl::StrCat(fcn_name, "_", enc_group->value()),
diff --git a/mpact/sim/decoder/proto_encoding_group.h b/mpact/sim/decoder/proto_encoding_group.h index ceace1b..200cd7f 100644 --- a/mpact/sim/decoder/proto_encoding_group.h +++ b/mpact/sim/decoder/proto_encoding_group.h
@@ -47,21 +47,21 @@ class ProtoEncodingGroup { public: // Constructor for a top level encoding group with no field differentiator. - ProtoEncodingGroup(ProtoInstructionGroup *inst_group, int level, - DecoderErrorListener *error_listener); + ProtoEncodingGroup(ProtoInstructionGroup* inst_group, int level, + DecoderErrorListener* error_listener); // Constructor for a child encoding group. - ProtoEncodingGroup(ProtoEncodingGroup *parent, - ProtoInstructionGroup *inst_group, int level, - DecoderErrorListener *error_listener); + ProtoEncodingGroup(ProtoEncodingGroup* parent, + ProtoInstructionGroup* inst_group, int level, + DecoderErrorListener* error_listener); // Deleted constructors. ProtoEncodingGroup() = delete; - ProtoEncodingGroup(const ProtoEncodingGroup &) = delete; - ProtoEncodingGroup &operator=(const ProtoEncodingGroup &) = delete; + ProtoEncodingGroup(const ProtoEncodingGroup&) = delete; + ProtoEncodingGroup& operator=(const ProtoEncodingGroup&) = delete; // Destructor. ~ProtoEncodingGroup(); // Add encoding to the current group. - void AddEncoding(ProtoInstructionEncoding *encoding); + void AddEncoding(ProtoInstructionEncoding* encoding); // Process the encodings in this group and divide them into subgroups based // on their constraint value for the differentiating field. void AddSubGroups(); @@ -71,7 +71,7 @@ absl::string_view message_type_name); // Getters/Setters. - DecoderErrorListener *error_listener() const { return error_listener_; } + DecoderErrorListener* error_listener() const { return error_listener_; } int64_t value() const { return value_; } void set_value(int64_t value) { value_ = value; } int level() const { return level_; } @@ -81,8 +81,8 @@ // there are no encoding ambiguities, such as multiple opcodes with the same // encoding, etc. void CheckEncodings(); - bool DoConstraintsOverlap(const std::vector<ProtoConstraintValueSet *> &lhs, - const std::vector<ProtoConstraintValueSet *> &rhs); + bool DoConstraintsOverlap(const std::vector<ProtoConstraintValueSet*>& lhs, + const std::vector<ProtoConstraintValueSet*>& rhs); // Create C++ code for leaf (encoding group) instruction decoder. std::string EmitLeafDecoder(absl::string_view fcn_name, absl::string_view opcode_enum, @@ -93,18 +93,18 @@ absl::string_view opcode_enum, absl::string_view message_type_name); - ProtoInstructionGroup *inst_group_ = nullptr; - ProtoEncodingGroup *parent_ = nullptr; - DecoderErrorListener *error_listener_ = nullptr; - FieldInfo *differentiator_ = nullptr; + ProtoInstructionGroup* inst_group_ = nullptr; + ProtoEncodingGroup* parent_ = nullptr; + DecoderErrorListener* error_listener_ = nullptr; + FieldInfo* differentiator_ = nullptr; int64_t value_; int level_; - std::vector<ProtoInstructionEncoding *> encoding_vec_; - std::vector<ProtoEncodingGroup *> encoding_group_vec_; - absl::btree_map<std::string, FieldInfo *> field_map_; - absl::flat_hash_set<const google::protobuf::FieldDescriptor *> + std::vector<ProtoInstructionEncoding*> encoding_vec_; + std::vector<ProtoEncodingGroup*> encoding_group_vec_; + absl::btree_map<std::string, FieldInfo*> field_map_; + absl::flat_hash_set<const google::protobuf::FieldDescriptor*> other_field_set_; - absl::flat_hash_set<const google::protobuf::OneofDescriptor *> + absl::flat_hash_set<const google::protobuf::OneofDescriptor*> other_oneof_set_; };
diff --git a/mpact/sim/decoder/proto_encoding_info.cc b/mpact/sim/decoder/proto_encoding_info.cc index 1ced0e7..1c01936 100644 --- a/mpact/sim/decoder/proto_encoding_info.cc +++ b/mpact/sim/decoder/proto_encoding_info.cc
@@ -41,8 +41,8 @@ using ::mpact::sim::machine_description::instruction_set::ToSnakeCase; ProtoEncodingInfo::ProtoEncodingInfo( - const std::string &opcode_enum, - decoder::DecoderErrorListener *error_listener) + const std::string& opcode_enum, + decoder::DecoderErrorListener* error_listener) : opcode_enum_(opcode_enum), error_listener_(error_listener) {} ProtoEncodingInfo::~ProtoEncodingInfo() { delete decoder_; } @@ -51,20 +51,20 @@ include_files_.emplace(include_file); } -ProtoInstructionDecoder *ProtoEncodingInfo::SetProtoDecoder(std::string name) { +ProtoInstructionDecoder* ProtoEncodingInfo::SetProtoDecoder(std::string name) { if (decoder_ != nullptr) { error_listener_->semanticError(nullptr, "Can only select one decoder"); return nullptr; } - auto *proto_decoder = + auto* proto_decoder = new ProtoInstructionDecoder(name, this, error_listener()); decoder_ = proto_decoder; return proto_decoder; } -absl::StatusOr<ProtoInstructionGroup *> ProtoEncodingInfo::AddInstructionGroup( - const std::string &group_name, - const google::protobuf::Descriptor *descriptor) { +absl::StatusOr<ProtoInstructionGroup*> ProtoEncodingInfo::AddInstructionGroup( + const std::string& group_name, + const google::protobuf::Descriptor* descriptor) { // Make sure that the instruction group hasn't been added before. if (instruction_group_map_.contains(group_name)) { return absl::AlreadyExistsError(absl::StrCat( @@ -78,7 +78,7 @@ absl::Status ProtoEncodingInfo::CheckSetterType( absl::string_view name, - const google::protobuf::FieldDescriptor *field_desc) { + const google::protobuf::FieldDescriptor* field_desc) { // Is it a new setter, if so, just insert it. auto iter = setter_types_.find(name); auto cpp_type = field_desc->cpp_type(); @@ -188,7 +188,7 @@ std::string decoder_def; std::string type_aliases; // Add type aliases for protobuf messages used in decoders. - for (auto *inst_group : decoder_->instruction_groups()) { + for (auto* inst_group : decoder_->instruction_groups()) { std::string qualified_message_type = absl::StrReplaceAll( inst_group->message_type()->full_name(), {{".", "::"}}); absl::StrAppend(&type_aliases, "using ", ToPascalCase(inst_group->name()), @@ -208,7 +208,7 @@ } // Include files. absl::StrAppend(&h_output, "#include <cstdint>\n\n"); - for (auto &include_file : include_files_) { + for (auto& include_file : include_files_) { absl::StrAppend(&h_output, "#include ", include_file, "\n"); } absl::StrAppend(&h_output, "\n"); @@ -217,7 +217,7 @@ "#include \"absl/container/flat_hash_map.h\"\n\n"); // Open namespaces. std::string name_space_ref = absl::StrJoin(decoder_->namespaces(), "::"); - for (auto &name_space : decoder_->namespaces()) { + for (auto& name_space : decoder_->namespaces()) { absl::StrAppend(&h_output, "namespace ", name_space, " {\n"); absl::StrAppend(&cc_output, "namespace ", name_space, " {\n"); } @@ -226,7 +226,7 @@ " public:\n", " ", class_name, "() = default;\n\n"); absl::StrAppend(&h_output, " // Decode method(s).\n"); std::string decoder_fcns; - for (auto *inst_group : decoder_->instruction_groups()) { + for (auto* inst_group : decoder_->instruction_groups()) { inst_group->ProcessEncodings(error_listener_); absl::StrAppend(&h_output, " ", opcode_enum_, " Decode", ToPascalCase(inst_group->name()), "(", @@ -243,7 +243,7 @@ if (error_listener_->HasError()) return {"", ""}; absl::StrAppend(&cc_output, decoder_fcns); absl::StrAppend(&h_output, "\n // Setters and getters.\n"); - for (auto const &[name, cpp_type] : setter_types_) { + for (auto const& [name, cpp_type] : setter_types_) { auto cpp_type_name = GetCppTypeName(cpp_type); // Generate method declarations. absl::StrAppend(&h_output, " void Set", ToPascalCase(name), "(",
diff --git a/mpact/sim/decoder/proto_encoding_info.h b/mpact/sim/decoder/proto_encoding_info.h index 3c1e34b..a186cf0 100644 --- a/mpact/sim/decoder/proto_encoding_info.h +++ b/mpact/sim/decoder/proto_encoding_info.h
@@ -45,47 +45,47 @@ class ProtoEncodingInfo { public: - ProtoEncodingInfo(const std::string &opcode_enum, - decoder::DecoderErrorListener *error_listener); + ProtoEncodingInfo(const std::string& opcode_enum, + decoder::DecoderErrorListener* error_listener); ProtoEncodingInfo() = delete; ~ProtoEncodingInfo(); // Add file to be included in the generated code. void AddIncludeFile(std::string include_file); // Create and return a proto instruction decoder object with the given name. - ProtoInstructionDecoder *SetProtoDecoder(std::string name); + ProtoInstructionDecoder* SetProtoDecoder(std::string name); // Create and return an instruction group object with the given name. - absl::StatusOr<ProtoInstructionGroup *> AddInstructionGroup( - const std::string &group_name, - const google::protobuf::Descriptor *descriptor); + absl::StatusOr<ProtoInstructionGroup*> AddInstructionGroup( + const std::string& group_name, + const google::protobuf::Descriptor* descriptor); // Check that the setter types are consistent. absl::Status CheckSetterType( absl::string_view name, - const google::protobuf::FieldDescriptor *field_desc); + const google::protobuf::FieldDescriptor* field_desc); // Generate the C++ .h and .cc file contents. StringPair GenerateDecoderClass(); // Accessors. - DecoderErrorListener *error_listener() { return error_listener_; } - absl::flat_hash_map<std::string, ProtoInstructionGroup *> & + DecoderErrorListener* error_listener() { return error_listener_; } + absl::flat_hash_map<std::string, ProtoInstructionGroup*>& instruction_group_map() { return instruction_group_map_; } - const absl::btree_set<std::string> &include_files() const { + const absl::btree_set<std::string>& include_files() const { return include_files_; } - ProtoInstructionDecoder *decoder() const { return decoder_; } + ProtoInstructionDecoder* decoder() const { return decoder_; } absl::string_view opcode_enum() const { return opcode_enum_; } private: std::string opcode_enum_; - DecoderErrorListener *error_listener_; + DecoderErrorListener* error_listener_; // Map of all instruction groups. - absl::flat_hash_map<std::string, ProtoInstructionGroup *> + absl::flat_hash_map<std::string, ProtoInstructionGroup*> instruction_group_map_; // The include files are stored in a btree set so they can be iterated over // in alphabetic order. absl::btree_set<std::string> include_files_; - ProtoInstructionDecoder *decoder_ = nullptr; + ProtoInstructionDecoder* decoder_ = nullptr; // Map of all setter types. absl::btree_map<std::string, google::protobuf::FieldDescriptor::CppType> setter_types_;
diff --git a/mpact/sim/decoder/proto_format_gen_main.cc b/mpact/sim/decoder/proto_format_gen_main.cc index e446a33..3b89c5e 100644 --- a/mpact/sim/decoder/proto_format_gen_main.cc +++ b/mpact/sim/decoder/proto_format_gen_main.cc
@@ -41,7 +41,7 @@ static constexpr char kRootDir[] = ""; -int main(int argc, char **argv) { +int main(int argc, char** argv) { // Process the command line options. auto arg_vec = absl::ParseCommandLine(argc, argv);
diff --git a/mpact/sim/decoder/proto_format_visitor.cc b/mpact/sim/decoder/proto_format_visitor.cc index 4d91176..c62acc5 100644 --- a/mpact/sim/decoder/proto_format_visitor.cc +++ b/mpact/sim/decoder/proto_format_visitor.cc
@@ -57,7 +57,7 @@ namespace { -std::string StripQuotes(const std::string &str) { +std::string StripQuotes(const std::string& str) { return str.substr(1, str.length() - 2); } @@ -68,8 +68,8 @@ : public google::protobuf::compiler::MultiFileErrorCollector { public: MultiFileErrorCollector() {} - MultiFileErrorCollector(const MultiFileErrorCollector &) = delete; - MultiFileErrorCollector &operator=(const MultiFileErrorCollector &) = delete; + MultiFileErrorCollector(const MultiFileErrorCollector&) = delete; + MultiFileErrorCollector& operator=(const MultiFileErrorCollector&) = delete; void RecordError(absl::string_view filename, int line, int column, absl::string_view message) override { @@ -78,7 +78,7 @@ absl::StrAppend(&error_, "Line ", line, " Column ", column, ": ", message, "\n"); } - const std::string &GetError() const { return error_; } + const std::string& GetError() const { return error_; } private: std::string error_; @@ -95,18 +95,18 @@ // proto_files: vector of .proto files to import. // directory: target directory to generate the C++ files in. absl::Status ProtoFormatVisitor::Process( - const std::vector<std::string> &file_names, const std::string &decoder_name, - std::string_view prefix, const std::vector<std::string> &include_roots, - const std::vector<std::string> &proto_dirs, - const std::vector<std::string> &proto_files, std::string_view directory) { + const std::vector<std::string>& file_names, const std::string& decoder_name, + std::string_view prefix, const std::vector<std::string>& include_roots, + const std::vector<std::string>& proto_dirs, + const std::vector<std::string>& proto_files, std::string_view directory) { decoder_name_ = decoder_name; include_dir_vec_.push_back("."); - for (const auto &root : include_roots) { + for (const auto& root : include_roots) { include_dir_vec_.push_back(root); } - std::istream *source_stream = &std::cin; + std::istream* source_stream = &std::cin; if (!file_names.empty()) { source_stream = new std::fstream(file_names[0], std::fstream::in); @@ -125,15 +125,15 @@ // proto files from. google::protobuf::compiler::DiskSourceTree source_tree; source_tree.MapPath("", "./"); - for (auto const &proto_dir : proto_dirs) { + for (auto const& proto_dir : proto_dirs) { source_tree.MapPath("", proto_dir); } // Import the proto files. MultiFileErrorCollector proto_error_collector; google::protobuf::compiler::Importer importer(&source_tree, &proto_error_collector); - for (auto const &proto_file : proto_files) { - auto *file_desc = importer.Import(proto_file); + for (auto const& proto_file : proto_files) { + auto* file_desc = importer.Import(proto_file); if (file_desc == nullptr) { error_listener()->semanticError( nullptr, absl::StrCat("Failed to import '", proto_file, "'")); @@ -162,7 +162,7 @@ &google::protobuf::DescriptorPool::FindEnumValueByName, descriptor_pool_); // Parse the file and then create the data structures. - TopLevelCtx *top_level = parser_wrapper.parser()->top_level(); + TopLevelCtx* top_level = parser_wrapper.parser()->top_level(); (void)top_level; if (!file_names.empty()) { delete source_stream; @@ -243,24 +243,24 @@ // Helper templated function used to find proto objects by name. template <typename T> -const T *ProtoFormatVisitor::FindByName( - const std::string &name, const std::string &message_name, - std::function<const T *(const std::string &)> finder) const { - auto *object = finder(Expand(message_name + "." + name)); +const T* ProtoFormatVisitor::FindByName( + const std::string& name, const std::string& message_name, + std::function<const T*(const std::string&)> finder) const { + auto* object = finder(Expand(message_name + "." + name)); if (object != nullptr) return object; object = finder(Expand(name)); return object; } -const google::protobuf::FieldDescriptor *ProtoFormatVisitor::GetField( - const std::string &field_name, - const google::protobuf::Descriptor *message_type, - std::vector<const google::protobuf::FieldDescriptor *> &one_of_fields) +const google::protobuf::FieldDescriptor* ProtoFormatVisitor::GetField( + const std::string& field_name, + const google::protobuf::Descriptor* message_type, + std::vector<const google::protobuf::FieldDescriptor*>& one_of_fields) const { auto pos = field_name.find_first_of('.'); // If this is a "leaf" field, find it and return if found. if (pos == std::string::npos) { - auto *field_desc = message_type->FindFieldByName(field_name); + auto* field_desc = message_type->FindFieldByName(field_name); if (field_desc->containing_oneof() != nullptr) { one_of_fields.push_back(field_desc); } @@ -269,18 +269,18 @@ // Recursively traverse the components of the field name. std::string field = field_name.substr(0, pos); std::string remainder = field_name.substr(pos + 1); - auto const *field_desc = message_type->FindFieldByName(field); + auto const* field_desc = message_type->FindFieldByName(field); if (field_desc == nullptr) return nullptr; if (field_desc->containing_oneof() != nullptr) { one_of_fields.push_back(field_desc); } - auto const *message_desc = field_desc->message_type(); + auto const* message_desc = field_desc->message_type(); if (message_desc == nullptr) return nullptr; return GetField(remainder, message_desc, one_of_fields); } -const google::protobuf::EnumValueDescriptor * -ProtoFormatVisitor::GetEnumValueDescriptor(const std::string &full_name) const { +const google::protobuf::EnumValueDescriptor* +ProtoFormatVisitor::GetEnumValueDescriptor(const std::string& full_name) const { std::string expanded = Expand(full_name); auto pos = expanded.find_last_of('.'); // If this is a "leaf", it fails. The enum must be qualified by enum type. @@ -290,17 +290,17 @@ std::string enum_name = expanded.substr(pos + 1); std::string enum_type_name = expanded.substr(0, pos); // Find the enum type. - auto const *enum_type_desc = + auto const* enum_type_desc = descriptor_pool_->FindEnumTypeByName(enum_type_name); if (enum_type_desc == nullptr) return nullptr; // Find the enum value in the enum type. - auto const *enum_value_desc = enum_type_desc->FindValueByName(enum_name); + auto const* enum_value_desc = enum_type_desc->FindValueByName(enum_name); return enum_value_desc; } absl::StatusOr<int> ProtoFormatVisitor::GetEnumValue( - const std::string &enum_name) const { - auto *enum_value_desc = GetEnumValueDescriptor(enum_name); + const std::string& enum_name) const { + auto* enum_value_desc = GetEnumValueDescriptor(enum_name); if (enum_value_desc == nullptr) { return absl::NotFoundError( absl::StrCat("Enum '", enum_name, "' not found")); @@ -309,9 +309,9 @@ } void ProtoFormatVisitor::PreProcessDeclarations( - const std::vector<DeclarationCtx *> &declarations) { - std::vector<IncludeFileCtx *> include_files; - for (auto *declaration : declarations) { + const std::vector<DeclarationCtx*>& declarations) { + std::vector<IncludeFileCtx*> include_files; + for (auto* declaration : declarations) { // Create map from instruction group name to instruction group ctx. That // way we can visit those that are referenced by the decoder definition // later. @@ -355,7 +355,7 @@ } // Create a map from decoder definitions to their parse contexts. if (declaration->decoder_def() != nullptr) { - auto *decoder = declaration->decoder_def(); + auto* decoder = declaration->decoder_def(); auto name = decoder->name->getText(); auto iter = decoder_decl_map_.find(name); if (iter != decoder_decl_map_.end()) { @@ -372,19 +372,19 @@ include_files.push_back(declaration->include_file()); } // Visit all the include files captured above. - for (auto *include_file_ctx : include_files) { + for (auto* include_file_ctx : include_files) { VisitIncludeFile(include_file_ctx); } } -void ProtoFormatVisitor::VisitIncludeFile(IncludeFileCtx *ctx) { +void ProtoFormatVisitor::VisitIncludeFile(IncludeFileCtx* ctx) { // The literal includes the double quotes. std::string literal = ctx->STRING_LITERAL()->getText(); // Remove the double quotes from the literal and construct the full file name. std::string file_name = literal.substr(1, literal.length() - 2); // Check for recursive include by comparing the current name to those on the // current include file stack. - for (auto const &name : include_file_stack_) { + for (auto const& name : include_file_stack_) { if (name == file_name) { error_listener()->semanticError( ctx->start, @@ -396,14 +396,14 @@ } void ProtoFormatVisitor::ParseIncludeFile( - antlr4::ParserRuleContext *ctx, const std::string &file_name, - const std::vector<std::string> &dirs) { + antlr4::ParserRuleContext* ctx, const std::string& file_name, + const std::vector<std::string>& dirs) { std::fstream include_file; // Open include file. include_file.open(file_name, std::fstream::in); if (!include_file.is_open()) { // Try each of the include file directories. - for (auto const &dir : dirs) { + for (auto const& dir : dirs) { std::string include_name = absl::StrCat(dir, "/", file_name); include_file.open(include_name, std::fstream::in); if (include_file.is_open()) break; @@ -420,7 +420,7 @@ } std::string previous_file_name = error_listener()->file_name(); error_listener()->set_file_name(std::string(file_name)); - auto *include_parser = new ProtoFmtAntlrParserWrapper(&include_file); + auto* include_parser = new ProtoFmtAntlrParserWrapper(&include_file); // We need to save the parser state so it's available for analysis after // we are done with building the parse trees. antlr_parser_wrappers_.push_back(include_parser); @@ -441,7 +441,7 @@ } std::unique_ptr<ProtoEncodingInfo> ProtoFormatVisitor::ProcessTopLevel( - const std::string &decoder_name) { + const std::string& decoder_name) { // Look up the decoder declaration that matches the decoder name for which // to generate C++ code. auto decoder_iter = decoder_decl_map_.find(decoder_name); @@ -455,14 +455,14 @@ } // Process instruction groups. -ProtoInstructionGroup *ProtoFormatVisitor::VisitInstructionGroupDef( - InstructionGroupDefCtx *ctx, ProtoEncodingInfo *encoding_info) { +ProtoInstructionGroup* ProtoFormatVisitor::VisitInstructionGroupDef( + InstructionGroupDefCtx* ctx, ProtoEncodingInfo* encoding_info) { if (ctx == nullptr) return nullptr; std::string group_name = ctx->name->getText(); // Verify that the message type exists. std::string message_name = Expand(ctx->message_name->getText()); - auto const *message_desc = + auto const* message_desc = descriptor_pool_->FindMessageTypeByName(message_name); // If the message type doesn't exist, its an error if (message_desc == nullptr) { @@ -480,22 +480,22 @@ return nullptr; } - auto *inst_group = inst_group_res.value(); + auto* inst_group = inst_group_res.value(); // First visit all the setter declarations. - for (auto *group_def : ctx->setter_group_def()) { + for (auto* group_def : ctx->setter_group_def()) { VisitSetterGroupDef(group_def, inst_group, encoding_info); } // Parse the instruction encoding definitions in the instruction group. - for (auto *inst_def : ctx->instruction_def()) { + for (auto* inst_def : ctx->instruction_def()) { VisitInstructionDef(inst_def, inst_group, encoding_info); } return inst_group; } // Process instruction definitions. -void ProtoFormatVisitor::VisitInstructionDef(InstructionDefCtx *ctx, - ProtoInstructionGroup *inst_group, - ProtoEncodingInfo *encoding_info) { +void ProtoFormatVisitor::VisitInstructionDef(InstructionDefCtx* ctx, + ProtoInstructionGroup* inst_group, + ProtoEncodingInfo* encoding_info) { if (ctx == nullptr) return; // If it is a generator, call the generator parsing function. @@ -505,17 +505,17 @@ } // Get the instruction name. std::string name = ctx->name->getText(); - auto *inst_encoding = inst_group->AddInstructionEncoding(name); + auto* inst_encoding = inst_group->AddInstructionEncoding(name); // Add Constraints to the instruction encoding. - for (auto *constraint : ctx->field_constraint_list()->field_constraint()) { + for (auto* constraint : ctx->field_constraint_list()->field_constraint()) { VisitFieldConstraint(constraint, inst_encoding, inst_group); } // Visit references to setters defined in the instruction group. - for (auto *setter : ctx->setter_ref()) { + for (auto* setter : ctx->setter_ref()) { VisitSetterRef(setter, inst_encoding, inst_group, encoding_info); } // Visit locally (to the instruction) defined setters. - for (auto *setter : ctx->setter_def()) { + for (auto* setter : ctx->setter_def()) { VisitSetterDef(setter, inst_encoding, inst_group, encoding_info); } // Generate the setter code template. @@ -523,8 +523,8 @@ } void ProtoFormatVisitor::VisitFieldConstraint( - FieldConstraintCtx *ctx, ProtoInstructionEncoding *inst_encoding, - const ProtoInstructionGroup *inst_group) { + FieldConstraintCtx* ctx, ProtoInstructionEncoding* inst_encoding, + const ProtoInstructionGroup* inst_group) { if (ctx == nullptr) return; // Constraints are based on field names ==/!=/>/>=/</<= to a value, or @@ -535,8 +535,8 @@ absl::Status status; if (ctx->HAS() != nullptr) { std::string field_name = ctx->qualified_ident()->getText(); - std::vector<const google::protobuf::FieldDescriptor *> one_of_fields; - auto *field_desc = + std::vector<const google::protobuf::FieldDescriptor*> one_of_fields; + auto* field_desc = GetField(field_name, inst_group->message_type(), one_of_fields); if (field_desc == nullptr) { error_listener()->semanticError( @@ -557,8 +557,8 @@ // The field name is relative to the message type, but may refer to fields // in sub-messages contained within that message. std::string field_name = ctx->field->getText(); - std::vector<const google::protobuf::FieldDescriptor *> one_of_fields; - auto *field_desc = + std::vector<const google::protobuf::FieldDescriptor*> one_of_fields; + auto* field_desc = GetField(field_name, inst_group->message_type(), one_of_fields); if (field_desc == nullptr) { error_listener()->semanticError( @@ -569,7 +569,7 @@ } std::string op = ctx->constraint_op()->getText(); - auto *constraint_expr = VisitConstraintExpression(ctx->constraint_expr(), + auto* constraint_expr = VisitConstraintExpression(ctx->constraint_expr(), field_desc, inst_group); // Add the constraint according to the type. @@ -598,11 +598,11 @@ } } -ProtoConstraintExpression *ProtoFormatVisitor::VisitConstraintExpression( - ConstraintExprCtx *ctx, const google::protobuf::FieldDescriptor *field_desc, - const ProtoInstructionGroup *inst_group) { +ProtoConstraintExpression* ProtoFormatVisitor::VisitConstraintExpression( + ConstraintExprCtx* ctx, const google::protobuf::FieldDescriptor* field_desc, + const ProtoInstructionGroup* inst_group) { if (ctx == nullptr) return nullptr; - ProtoConstraintExpression *constraint_expr = nullptr; + ProtoConstraintExpression* constraint_expr = nullptr; if (ctx->value() != nullptr) { constraint_expr = VisitValue(ctx->value()); } else if (ctx->qualified_ident() != nullptr) { @@ -612,7 +612,7 @@ return constraint_expr; } -ProtoConstraintExpression *ProtoFormatVisitor::VisitValue(ValueCtx *ctx) { +ProtoConstraintExpression* ProtoFormatVisitor::VisitValue(ValueCtx* ctx) { if (ctx == nullptr) return nullptr; if (ctx->number() != nullptr) { return VisitNumber(ctx->number()); @@ -630,7 +630,7 @@ return nullptr; } -ProtoConstraintExpression *ProtoFormatVisitor::VisitNumber(NumberCtx *ctx) { +ProtoConstraintExpression* ProtoFormatVisitor::VisitNumber(NumberCtx* ctx) { std::string num_str = ctx->getText(); // Convert to lower case to avoid capital chars in suffix. for (int i = 0; i < num_str.size(); ++i) num_str[i] = tolower(num_str[i]); @@ -690,9 +690,9 @@ } // Visits a qualified identifier that specifies an enumerator value. -ProtoConstraintExpression *ProtoFormatVisitor::VisitQualifiedIdent( - QualifiedIdentCtx *ctx, const google::protobuf::FieldDescriptor *field_desc, - const ProtoInstructionGroup *inst_group) { +ProtoConstraintExpression* ProtoFormatVisitor::VisitQualifiedIdent( + QualifiedIdentCtx* ctx, const google::protobuf::FieldDescriptor* field_desc, + const ProtoInstructionGroup* inst_group) { if (ctx == nullptr) return nullptr; // Verify that the field is an enum. if (field_desc->enum_type() == nullptr) { @@ -702,7 +702,7 @@ return nullptr; } // Look up the value (if it exists). - auto const *enum_value_desc = + auto const* enum_value_desc = field_desc->enum_type()->FindValueByName(ctx->getText()); if (enum_value_desc == nullptr) { error_listener()->semanticError( @@ -714,16 +714,16 @@ } // Process the instruction group setters. -void ProtoFormatVisitor::VisitSetterGroupDef(SetterGroupDefCtx *ctx, - ProtoInstructionGroup *inst_group, - ProtoEncodingInfo *encoding_info) { +void ProtoFormatVisitor::VisitSetterGroupDef(SetterGroupDefCtx* ctx, + ProtoInstructionGroup* inst_group, + ProtoEncodingInfo* encoding_info) { if (ctx == nullptr) return; auto group_name = ctx->name->getText(); - for (auto *setter_def : ctx->setter_def()) { + for (auto* setter_def : ctx->setter_def()) { std::string name = setter_def->name->getText(); std::string field_name = setter_def->qualified_ident()->getText(); - std::vector<const google::protobuf::FieldDescriptor *> one_of_fields; - auto const *field_desc = + std::vector<const google::protobuf::FieldDescriptor*> one_of_fields; + auto const* field_desc = GetField(field_name, inst_group->message_type(), one_of_fields); if (field_desc == nullptr) { error_listener()->semanticError( @@ -733,7 +733,7 @@ return; } - IfNotCtx *if_not = setter_def->if_not(); + IfNotCtx* if_not = setter_def->if_not(); auto status = encoding_info->CheckSetterType(name, field_desc); if (!status.ok()) { error_listener()->semanticError(setter_def->start, status.message()); @@ -749,15 +749,15 @@ } // Process local (to instruction) setters. -void ProtoFormatVisitor::VisitSetterDef(SetterDefCtx *ctx, - ProtoInstructionEncoding *inst_encoding, - ProtoInstructionGroup *inst_group, - ProtoEncodingInfo *encoding_info) { +void ProtoFormatVisitor::VisitSetterDef(SetterDefCtx* ctx, + ProtoInstructionEncoding* inst_encoding, + ProtoInstructionGroup* inst_group, + ProtoEncodingInfo* encoding_info) { if (ctx == nullptr) return; std::string name = ctx->name->getText(); std::string field_name = ctx->qualified_ident()->getText(); - std::vector<const google::protobuf::FieldDescriptor *> one_of_fields; - auto const *field_desc = + std::vector<const google::protobuf::FieldDescriptor*> one_of_fields; + auto const* field_desc = GetField(field_name, inst_group->message_type(), one_of_fields); if (field_desc == nullptr) { error_listener()->semanticError( @@ -767,7 +767,7 @@ return; } - IfNotCtx *if_not = ctx->if_not(); + IfNotCtx* if_not = ctx->if_not(); auto status = encoding_info->CheckSetterType(name, field_desc); if (!status.ok()) { error_listener()->semanticError(ctx->start, status.message()); @@ -782,10 +782,10 @@ } // Process references to instruction group setters. -void ProtoFormatVisitor::VisitSetterRef(SetterRefCtx *ctx, - ProtoInstructionEncoding *inst_encoding, - ProtoInstructionGroup *inst_group, - ProtoEncodingInfo *encoding_info) { +void ProtoFormatVisitor::VisitSetterRef(SetterRefCtx* ctx, + ProtoInstructionEncoding* inst_encoding, + ProtoInstructionGroup* inst_group, + ProtoEncodingInfo* encoding_info) { if (ctx == nullptr) return; auto res = inst_group->GetSetterGroup(ctx->name->getText()); if (!res.ok()) { @@ -794,7 +794,7 @@ } auto [iter, end] = res.value(); while (iter != end) { - auto *setter_info = iter->second; + auto* setter_info = iter->second; auto status = inst_encoding->AddSetter( setter_info->ctx, setter_info->name, setter_info->field_desc, setter_info->one_of_fields, setter_info->if_not); @@ -809,20 +809,20 @@ // Process the instruction definition generators. void ProtoFormatVisitor::ProcessInstructionDefGenerator( - InstructionDefCtx *ctx, ProtoInstructionGroup *inst_group, - ProtoEncodingInfo *encoding_info) { + InstructionDefCtx* ctx, ProtoInstructionGroup* inst_group, + ProtoEncodingInfo* encoding_info) { if (ctx == nullptr) return; absl::flat_hash_set<std::string> range_variable_names; - std::vector<RangeAssignmentInfo *> range_info_vec; + std::vector<RangeAssignmentInfo*> range_info_vec; // Process range assignment lists. The range assignment is either a single // value or a structured binding assignment. If it's a binding assignment we // need to make sure each tuple has the same number of values as there are // idents to assign them to. - for (auto *assign_ctx : ctx->range_assignment()) { - auto *range_info = new RangeAssignmentInfo(); + for (auto* assign_ctx : ctx->range_assignment()) { + auto* range_info = new RangeAssignmentInfo(); range_info_vec.push_back(range_info); - for (auto *ident_ctx : assign_ctx->IDENT()) { + for (auto* ident_ctx : assign_ctx->IDENT()) { std::string name = ident_ctx->getText(); if (range_variable_names.contains(name)) { error_listener()->semanticError( @@ -845,7 +845,7 @@ } // See if it's a list of simple values. if (!assign_ctx->gen_value().empty()) { - for (auto *gen_value_ctx : assign_ctx->gen_value()) { + for (auto* gen_value_ctx : assign_ctx->gen_value()) { if (gen_value_ctx->IDENT() != nullptr) { range_info->range_values[0].push_back( gen_value_ctx->IDENT()->getText()); @@ -867,10 +867,10 @@ continue; } // It's a list of tuples with a structured binding assignment. - for (auto *tuple_ctx : assign_ctx->tuple()) { + for (auto* tuple_ctx : assign_ctx->tuple()) { if (tuple_ctx->gen_value().size() != range_info->range_names.size()) { // Clean up. - for (auto *info : range_info_vec) delete info; + for (auto* info : range_info_vec) delete info; error_listener_->semanticError( assign_ctx->start, "Number of values differs from number of identifiers"); @@ -919,7 +919,7 @@ } if (error_listener()->HasError()) { // Clean up. - for (auto *info : range_info_vec) delete info; + for (auto* info : range_info_vec) delete info; return; } @@ -928,22 +928,22 @@ std::string generated_text = GenerateInstructionDefList(range_info_vec, 0, input_text); // Parse and process the generated text. - auto *parser = new ProtoFmtAntlrParserWrapper(generated_text); + auto* parser = new ProtoFmtAntlrParserWrapper(generated_text); antlr_parser_wrappers_.push_back(parser); // Parse the text starting at the opcode_spec_list rule. auto instruction_defs = parser->parser()->instruction_group_def()->instruction_def(); // Process the opcode spec. - for (auto *inst_def : instruction_defs) { + for (auto* inst_def : instruction_defs) { VisitInstructionDef(inst_def, inst_group, encoding_info); } // Clean up. - for (auto *info : range_info_vec) delete info; + for (auto* info : range_info_vec) delete info; } std::string ProtoFormatVisitor::GenerateInstructionDefList( - const std::vector<RangeAssignmentInfo *> &range_info_vec, int index, - const std::string &template_str_in) const { + const std::vector<RangeAssignmentInfo*>& range_info_vec, int index, + const std::string& template_str_in) const { std::string generated; // Iterate for the number of values. for (int i = 0; i < range_info_vec[index]->range_values[0].size(); ++i) { @@ -953,7 +953,7 @@ // current set of values. int var_index = 0; int replace_count = 0; - for (auto &re : range_info_vec[index]->range_regexes) { + for (auto& re : range_info_vec[index]->range_regexes) { replace_count += RE2::GlobalReplace( &template_str, re, range_info_vec[index]->range_values[var_index++][i]); @@ -977,13 +977,13 @@ } std::unique_ptr<ProtoEncodingInfo> ProtoFormatVisitor::VisitDecoderDef( - DecoderDefCtx *ctx) { + DecoderDefCtx* ctx) { if (ctx == nullptr) return nullptr; // First get the opcode enum. int opcode_count = 0; std::string opcode_enum; - for (auto *attr_ctx : ctx->decoder_attribute()) { + for (auto* attr_ctx : ctx->decoder_attribute()) { if (attr_ctx->opcode_enum_decl() != nullptr) { auto opcode_enum_literal = attr_ctx->opcode_enum_decl()->STRING_LITERAL()->getText(); @@ -1005,15 +1005,15 @@ std::string name = ctx->name->getText(); auto encoding_info = std::make_unique<ProtoEncodingInfo>(opcode_enum, error_listener_.get()); - auto *decoder = encoding_info->SetProtoDecoder(name); + auto* decoder = encoding_info->SetProtoDecoder(name); if (decoder == nullptr) return nullptr; absl::flat_hash_set<std::string> group_name_set; int namespace_count = 0; // Iterate over the decoder attributes. - for (auto *attr_ctx : ctx->decoder_attribute()) { + for (auto* attr_ctx : ctx->decoder_attribute()) { // Include files. if (attr_ctx->include_files() != nullptr) { - for (auto *file_ctx : attr_ctx->include_files()->include_file()) { + for (auto* file_ctx : attr_ctx->include_files()->include_file()) { auto include_text = file_ctx->STRING_LITERAL()->getText(); encoding_info->AddIncludeFile(include_text); } @@ -1022,7 +1022,7 @@ // Namespace declaration. if (attr_ctx->namespace_decl() != nullptr) { auto decl = attr_ctx->namespace_decl(); - for (auto *namespace_name : decl->namespace_ident()) { + for (auto* namespace_name : decl->namespace_ident()) { decoder->namespaces().push_back(namespace_name->getText()); } if (namespace_count > 0) { @@ -1058,8 +1058,8 @@ } void ProtoFormatVisitor::ProcessSingleGroup( - DecoderAttributeCtx *attr_ctx, ProtoEncodingInfo *encoding_info, - absl::flat_hash_set<std::string> &group_name_set) { + DecoderAttributeCtx* attr_ctx, ProtoEncodingInfo* encoding_info, + absl::flat_hash_set<std::string>& group_name_set) { if (attr_ctx == nullptr) return; std::string group_name = attr_ctx->group_name()->IDENT()->getText(); @@ -1072,7 +1072,7 @@ } auto map_iter = encoding_info->instruction_group_map().find(group_name); - ProtoInstructionGroup *inst_group = nullptr; + ProtoInstructionGroup* inst_group = nullptr; // Check if the group has been visited before. If so, no need to visit. if (map_iter != encoding_info->instruction_group_map().end()) { @@ -1097,8 +1097,8 @@ } void ProtoFormatVisitor::ProcessParentGroup( - DecoderAttributeCtx *attr_ctx, ProtoEncodingInfo *encoding_info, - absl::flat_hash_set<std::string> &group_name_set) { + DecoderAttributeCtx* attr_ctx, ProtoEncodingInfo* encoding_info, + absl::flat_hash_set<std::string>& group_name_set) { if (attr_ctx == nullptr) return; // Check each of the child groups. Visit any that hasn't been visited // yet, and make sure all use the same encoding proto message. @@ -1110,10 +1110,10 @@ "' listed twice - ignored")); return; } - std::vector<ProtoInstructionGroup *> child_groups; + std::vector<ProtoInstructionGroup*> child_groups; std::string group_format_name; // Iterate through the list of named "child" groups to combine. - for (auto *ident : attr_ctx->group_name()->ident_list()->IDENT()) { + for (auto* ident : attr_ctx->group_name()->ident_list()->IDENT()) { auto child_name = ident->getText(); // Make sure the child group hasn't been listed already. if (group_name_set.contains(child_name)) { @@ -1122,14 +1122,14 @@ child_name, "' - ignored")); return; } - ProtoInstructionGroup *child_group = nullptr; + ProtoInstructionGroup* child_group = nullptr; auto map_iter = encoding_info->instruction_group_map().find(child_name); if (map_iter != encoding_info->instruction_group_map().end()) { // The instruction group has been visited already. Make sure it // hasn't bin listed twice in the list of child groups. child_group = map_iter->second; bool exists = false; - for (auto const *group : child_groups) { + for (auto const* group : child_groups) { if (child_name == group->name()) { exists = true; break; @@ -1140,7 +1140,7 @@ attr_ctx->start, absl::StrCat("Instruction group '", child_name, "' listed twice")); // Clean up. - for (auto *child_group : child_groups) delete child_group; + for (auto* child_group : child_groups) delete child_group; return; } } else { @@ -1155,7 +1155,7 @@ attr_ctx->start, absl::StrCat("Instruction group '", child_name, "' not found")); // Clean up. - for (auto *child_group : child_groups) delete child_group; + for (auto* child_group : child_groups) delete child_group; continue; } } @@ -1172,7 +1172,7 @@ group_format_name, ", to be merged into group '", group_name, "'")); // Clean up. - for (auto *child_group : child_groups) delete child_group; + for (auto* child_group : child_groups) delete child_group; return; } child_groups.push_back(child_group); @@ -1181,11 +1181,11 @@ if (child_groups.empty()) { error_listener_->semanticError(attr_ctx->start, "No child groups"); // Clean up. - for (auto *child_group : child_groups) delete child_group; + for (auto* child_group : child_groups) delete child_group; return; } // Create the "parent" instruction group. - const google::protobuf::Descriptor *group_format = + const google::protobuf::Descriptor* group_format = message_finder_(Expand(group_format_name)); if (group_format == nullptr) { error_listener_->semanticError( @@ -1193,20 +1193,20 @@ absl::StrCat("Could not find proto message type '", group_format_name, "' in proto descriptor pool")); // Clean up. - for (auto *child_group : child_groups) delete child_group; + for (auto* child_group : child_groups) delete child_group; return; } auto res = encoding_info->AddInstructionGroup(group_name, group_format); if (!res.ok()) { error_listener_->semanticError(attr_ctx->start, res.status().message()); // Clean up. - for (auto *child_group : child_groups) delete child_group; + for (auto* child_group : child_groups) delete child_group; return; } auto parent_group = res.value(); // For each child group, add all of it's encodings to the parent group. - for (auto *child_group : child_groups) { - for (auto *encoding : child_group->encodings()) { + for (auto* child_group : child_groups) { + for (auto* encoding : child_group->encodings()) { parent_group->CopyInstructionEncoding( new ProtoInstructionEncoding(*encoding)); } @@ -1217,7 +1217,7 @@ encoding_info->decoder()->AddInstructionGroup(parent_group); } -StringPair ProtoFormatVisitor::EmitCode(ProtoEncodingInfo *encoding_info) { +StringPair ProtoFormatVisitor::EmitCode(ProtoEncodingInfo* encoding_info) { return encoding_info->GenerateDecoderClass(); }
diff --git a/mpact/sim/decoder/proto_format_visitor.h b/mpact/sim/decoder/proto_format_visitor.h index c8d5d1d..c57730d 100644 --- a/mpact/sim/decoder/proto_format_visitor.h +++ b/mpact/sim/decoder/proto_format_visitor.h
@@ -71,15 +71,15 @@ // proto_dirs: vector of directories from which to resolve proto files. // proto_files: vector of .proto files to import. // directory: target directory to generate the C++ files in. - absl::Status Process(const std::vector<std::string> &file_names, - const std::string &decoder_name, std::string_view prefix, - const std::vector<std::string> &include_roots, - const std::vector<std::string> &proto_dirs, - const std::vector<std::string> &proto_files, + absl::Status Process(const std::vector<std::string>& file_names, + const std::string& decoder_name, std::string_view prefix, + const std::vector<std::string>& include_roots, + const std::vector<std::string>& proto_dirs, + const std::vector<std::string>& proto_files, std::string_view directory); // Accessors for the error listener. - decoder::DecoderErrorListener *error_listener() const { + decoder::DecoderErrorListener* error_listener() const { return error_listener_.get(); } void set_error_listener( @@ -101,94 +101,92 @@ // Get the field descriptor for the named field from the message type while // building up a vector of one_of_fields that are on the path from the top // level message to the field. - const google::protobuf::FieldDescriptor *GetField( - const std::string &field_name, - const google::protobuf::Descriptor *message_type, - std::vector<const google::protobuf::FieldDescriptor *> &one_of_fields) + const google::protobuf::FieldDescriptor* GetField( + const std::string& field_name, + const google::protobuf::Descriptor* message_type, + std::vector<const google::protobuf::FieldDescriptor*>& one_of_fields) const; // Get the descriptor for the named enumeration member. - const google::protobuf::EnumValueDescriptor *GetEnumValueDescriptor( - const std::string &full_name) const; + const google::protobuf::EnumValueDescriptor* GetEnumValueDescriptor( + const std::string& full_name) const; // Get the numeric value of the named enumeration member. - absl::StatusOr<int> GetEnumValue(const std::string &enum_name) const; + absl::StatusOr<int> GetEnumValue(const std::string& enum_name) const; // Helpful template function used to find a descriptor by name. template <typename T> - const T *FindByName( - const std::string &message_name, const std::string &name, - std::function<const T *(const std::string &)> finder) const; + const T* FindByName(const std::string& message_name, const std::string& name, + std::function<const T*(const std::string&)> finder) const; // Visit the parse tree to catalog the different declarations. - void PreProcessDeclarations( - const std::vector<DeclarationCtx *> &declarations); + void PreProcessDeclarations(const std::vector<DeclarationCtx*>& declarations); // Process an include file declaration. - void VisitIncludeFile(IncludeFileCtx *ctx); + void VisitIncludeFile(IncludeFileCtx* ctx); // Parse an included file. - void ParseIncludeFile(antlr4::ParserRuleContext *ctx, - const std::string &file_name, - const std::vector<std::string> &dirs); + void ParseIncludeFile(antlr4::ParserRuleContext* ctx, + const std::string& file_name, + const std::vector<std::string>& dirs); // Creates the top level data structures and visits the declarations that // are necessary to generate the instruction decoder. std::unique_ptr<ProtoEncodingInfo> ProcessTopLevel( - const std::string &decoder_name); + const std::string& decoder_name); // The following methods visit specific nodes in the parse tree. - ProtoInstructionGroup *VisitInstructionGroupDef( - InstructionGroupDefCtx *ctx, ProtoEncodingInfo *encoding_info); - void VisitInstructionDef(InstructionDefCtx *ctx, - ProtoInstructionGroup *inst_group, - ProtoEncodingInfo *encoding_info); - void VisitFieldConstraint(FieldConstraintCtx *ctx, - ProtoInstructionEncoding *inst_encoding, - const ProtoInstructionGroup *inst_group); - ProtoConstraintExpression *VisitConstraintExpression( - ConstraintExprCtx *ctx, - const google::protobuf::FieldDescriptor *field_desc, - const ProtoInstructionGroup *inst_group); - ProtoConstraintExpression *VisitValue(ValueCtx *ctx); - ProtoConstraintExpression *VisitNumber(NumberCtx *ctx); - ProtoConstraintExpression *VisitQualifiedIdent( - QualifiedIdentCtx *ctx, - const google::protobuf::FieldDescriptor *field_desc, - const ProtoInstructionGroup *inst_group); - void VisitSetterGroupDef(SetterGroupDefCtx *ctx, - ProtoInstructionGroup *inst_group, - ProtoEncodingInfo *encoding_info); - void VisitSetterDef(SetterDefCtx *ctx, - ProtoInstructionEncoding *inst_encoding, - ProtoInstructionGroup *inst_group, - ProtoEncodingInfo *encoding_info); - void VisitSetterRef(SetterRefCtx *ctx, - ProtoInstructionEncoding *inst_encoding, - ProtoInstructionGroup *inst_group, - ProtoEncodingInfo *encoding_info); - std::unique_ptr<ProtoEncodingInfo> VisitDecoderDef(DecoderDefCtx *ctx); + ProtoInstructionGroup* VisitInstructionGroupDef( + InstructionGroupDefCtx* ctx, ProtoEncodingInfo* encoding_info); + void VisitInstructionDef(InstructionDefCtx* ctx, + ProtoInstructionGroup* inst_group, + ProtoEncodingInfo* encoding_info); + void VisitFieldConstraint(FieldConstraintCtx* ctx, + ProtoInstructionEncoding* inst_encoding, + const ProtoInstructionGroup* inst_group); + ProtoConstraintExpression* VisitConstraintExpression( + ConstraintExprCtx* ctx, + const google::protobuf::FieldDescriptor* field_desc, + const ProtoInstructionGroup* inst_group); + ProtoConstraintExpression* VisitValue(ValueCtx* ctx); + ProtoConstraintExpression* VisitNumber(NumberCtx* ctx); + ProtoConstraintExpression* VisitQualifiedIdent( + QualifiedIdentCtx* ctx, + const google::protobuf::FieldDescriptor* field_desc, + const ProtoInstructionGroup* inst_group); + void VisitSetterGroupDef(SetterGroupDefCtx* ctx, + ProtoInstructionGroup* inst_group, + ProtoEncodingInfo* encoding_info); + void VisitSetterDef(SetterDefCtx* ctx, + ProtoInstructionEncoding* inst_encoding, + ProtoInstructionGroup* inst_group, + ProtoEncodingInfo* encoding_info); + void VisitSetterRef(SetterRefCtx* ctx, + ProtoInstructionEncoding* inst_encoding, + ProtoInstructionGroup* inst_group, + ProtoEncodingInfo* encoding_info); + std::unique_ptr<ProtoEncodingInfo> VisitDecoderDef(DecoderDefCtx* ctx); // Process and generate instruction definitions from a generate statement. - void ProcessInstructionDefGenerator(InstructionDefCtx *ctx, - ProtoInstructionGroup *inst_group, - ProtoEncodingInfo *encoding_info); + void ProcessInstructionDefGenerator(InstructionDefCtx* ctx, + ProtoInstructionGroup* inst_group, + ProtoEncodingInfo* encoding_info); std::string GenerateInstructionDefList( - const std::vector<RangeAssignmentInfo *> &range_info_vec, int index, - const std::string &template_str_in) const; + const std::vector<RangeAssignmentInfo*>& range_info_vec, int index, + const std::string& template_str_in) const; // Process instruction groups. - void ProcessSingleGroup(DecoderAttributeCtx *attr_ctx, - ProtoEncodingInfo *encoding_info, - absl::flat_hash_set<std::string> &group_name_set); - void ProcessParentGroup(DecoderAttributeCtx *attr_ctx, - ProtoEncodingInfo *encoding_info, - absl::flat_hash_set<std::string> &group_name_set); + void ProcessSingleGroup(DecoderAttributeCtx* attr_ctx, + ProtoEncodingInfo* encoding_info, + absl::flat_hash_set<std::string>& group_name_set); + void ProcessParentGroup(DecoderAttributeCtx* attr_ctx, + ProtoEncodingInfo* encoding_info, + absl::flat_hash_set<std::string>& group_name_set); // Called to generate and emit code for the decoder according to the parsed // input file. - StringPair EmitCode(ProtoEncodingInfo *encoding_info); + StringPair EmitCode(ProtoEncodingInfo* encoding_info); // Finders used to find specific object types from the proto2 pool. - using FieldFinder = std::function<const google::protobuf::FieldDescriptor *( - const std::string &)>; + using FieldFinder = std::function<const google::protobuf::FieldDescriptor*( + const std::string&)>; using MessageFinder = - std::function<const google::protobuf::Descriptor *(const std::string &)>; - using EnumTypeFinder = std::function<const google::protobuf::EnumDescriptor *( - const std::string &)>; + std::function<const google::protobuf::Descriptor*(const std::string&)>; + using EnumTypeFinder = std::function<const google::protobuf::EnumDescriptor*( + const std::string&)>; using EnumValueFinder = - std::function<const google::protobuf::EnumValueDescriptor *( - const std::string &)>; + std::function<const google::protobuf::EnumValueDescriptor*( + const std::string&)>; FieldFinder field_finder_; MessageFinder message_finder_; @@ -203,16 +201,16 @@ std::unique_ptr<decoder::DecoderErrorListener> error_listener_ = nullptr; std::string decoder_name_; // Descriptor pool. - const google::protobuf::DescriptorPool *descriptor_pool_; - absl::flat_hash_map<std::string, const google::protobuf::FileDescriptor *> + const google::protobuf::DescriptorPool* descriptor_pool_; + absl::flat_hash_map<std::string, const google::protobuf::FileDescriptor*> file_descriptor_map_; // Using decl map. absl::flat_hash_map<std::string, std::string> using_decl_map_; // Maps from identifiers to declaration contexts. - absl::flat_hash_map<std::string, InstructionGroupDefCtx *> group_decl_map_; - absl::flat_hash_map<std::string, DecoderDefCtx *> decoder_decl_map_; + absl::flat_hash_map<std::string, InstructionGroupDefCtx*> group_decl_map_; + absl::flat_hash_map<std::string, DecoderDefCtx*> decoder_decl_map_; // AntlrParserWrapper vector. - std::vector<ProtoFmtAntlrParserWrapper *> antlr_parser_wrappers_; + std::vector<ProtoFmtAntlrParserWrapper*> antlr_parser_wrappers_; }; } // namespace proto_fmt
diff --git a/mpact/sim/decoder/proto_instruction_decoder.cc b/mpact/sim/decoder/proto_instruction_decoder.cc index 59fba2d..945d617 100644 --- a/mpact/sim/decoder/proto_instruction_decoder.cc +++ b/mpact/sim/decoder/proto_instruction_decoder.cc
@@ -24,19 +24,19 @@ namespace proto_fmt { ProtoInstructionDecoder::ProtoInstructionDecoder( - std::string name, ProtoEncodingInfo *encoding_info, - DecoderErrorListener *error_listener) + std::string name, ProtoEncodingInfo* encoding_info, + DecoderErrorListener* error_listener) : name_(name), encoding_info_(encoding_info), error_listener_(error_listener) {} ProtoInstructionDecoder::~ProtoInstructionDecoder() { - for (auto *group : instruction_groups_) delete group; + for (auto* group : instruction_groups_) delete group; instruction_groups_.clear(); } void ProtoInstructionDecoder::AddInstructionGroup( - ProtoInstructionGroup *inst_group) { + ProtoInstructionGroup* inst_group) { instruction_groups_.push_back(inst_group); }
diff --git a/mpact/sim/decoder/proto_instruction_decoder.h b/mpact/sim/decoder/proto_instruction_decoder.h index 28ed1c8..900e366 100644 --- a/mpact/sim/decoder/proto_instruction_decoder.h +++ b/mpact/sim/decoder/proto_instruction_decoder.h
@@ -36,33 +36,33 @@ class ProtoInstructionDecoder { public: - ProtoInstructionDecoder(std::string name, ProtoEncodingInfo *encoding_info, - DecoderErrorListener *error_listener); + ProtoInstructionDecoder(std::string name, ProtoEncodingInfo* encoding_info, + DecoderErrorListener* error_listener); ~ProtoInstructionDecoder(); // Add an instruction group that will be part of this decoder. - void AddInstructionGroup(ProtoInstructionGroup *inst_group); + void AddInstructionGroup(ProtoInstructionGroup* inst_group); // Getters/Setters. - const std::string &name() const { return name_; } - DecoderErrorListener *error_listener() const { return error_listener_; } - ProtoEncodingInfo *encoding_info() const { return encoding_info_; } - std::vector<ProtoInstructionGroup *> instruction_groups() const { + const std::string& name() const { return name_; } + DecoderErrorListener* error_listener() const { return error_listener_; } + ProtoEncodingInfo* encoding_info() const { return encoding_info_; } + std::vector<ProtoInstructionGroup*> instruction_groups() const { return instruction_groups_; } - std::deque<std::string> &namespaces() { return namespaces_; } + std::deque<std::string>& namespaces() { return namespaces_; } private: // Decoder name. std::string name_; // The global encoding structure. - ProtoEncodingInfo *encoding_info_; + ProtoEncodingInfo* encoding_info_; // Error handler. - DecoderErrorListener *error_listener_; + DecoderErrorListener* error_listener_; // Namespace container. std::deque<std::string> namespaces_; // Instruction groups. - std::vector<ProtoInstructionGroup *> instruction_groups_; + std::vector<ProtoInstructionGroup*> instruction_groups_; }; } // namespace proto_fmt
diff --git a/mpact/sim/decoder/proto_instruction_encoding.cc b/mpact/sim/decoder/proto_instruction_encoding.cc index 5b725b9..bbd16b2 100644 --- a/mpact/sim/decoder/proto_instruction_encoding.cc +++ b/mpact/sim/decoder/proto_instruction_encoding.cc
@@ -38,55 +38,55 @@ using mpact::sim::machine_description::instruction_set::ToPascalCase; ProtoInstructionEncoding::ProtoInstructionEncoding( - std::string name, ProtoInstructionGroup *parent) + std::string name, ProtoInstructionGroup* parent) : name_(name), instruction_group_(parent) {} // Copy constructor. ProtoInstructionEncoding::ProtoInstructionEncoding( - const ProtoInstructionEncoding &rhs) { + const ProtoInstructionEncoding& rhs) { name_ = rhs.name_; instruction_group_ = rhs.instruction_group_; setter_code_ = rhs.setter_code_; - for (const auto &[name, setter_ptr] : rhs.setter_map_) { + for (const auto& [name, setter_ptr] : rhs.setter_map_) { setter_map_.insert({name, new ProtoSetter(*setter_ptr)}); } - for (const auto *constraint : rhs.equal_constraints_) { + for (const auto* constraint : rhs.equal_constraints_) { equal_constraints_.push_back(new ProtoConstraint(*constraint)); } - for (const auto *constraint : rhs.other_constraints_) { + for (const auto* constraint : rhs.other_constraints_) { other_constraints_.push_back(new ProtoConstraint(*constraint)); } - for (const auto &[name, constraint_ptr] : rhs.has_constraints_) { + for (const auto& [name, constraint_ptr] : rhs.has_constraints_) { has_constraints_.insert({name, new ProtoConstraint(*constraint_ptr)}); } } ProtoInstructionEncoding::~ProtoInstructionEncoding() { - for (const auto *constraint : equal_constraints_) { + for (const auto* constraint : equal_constraints_) { delete constraint->expr; delete constraint; } equal_constraints_.clear(); - for (const auto *constraint : other_constraints_) { + for (const auto* constraint : other_constraints_) { delete constraint->expr; delete constraint; } other_constraints_.clear(); - for (const auto &[unused, constraint] : has_constraints_) { + for (const auto& [unused, constraint] : has_constraints_) { delete constraint; } has_constraints_.clear(); - for (const auto &[unused, setter] : setter_map_) { + for (const auto& [unused, setter] : setter_map_) { delete setter; } setter_map_.clear(); } absl::Status ProtoInstructionEncoding::AddSetter( - SetterDefCtx *ctx, const std::string &name, - const google::protobuf::FieldDescriptor *field_descriptor, - const std::vector<const google::protobuf::FieldDescriptor *> &one_of_fields, - IfNotCtx *if_not) { + SetterDefCtx* ctx, const std::string& name, + const google::protobuf::FieldDescriptor* field_descriptor, + const std::vector<const google::protobuf::FieldDescriptor*>& one_of_fields, + IfNotCtx* if_not) { if (ctx == nullptr) return absl::InvalidArgumentError("Context is null"); // If there is a setter already for that name, return an error. @@ -100,8 +100,8 @@ // one_of_fields vector, as it is guaranteed to be satisfied if the // instruction is successfully decoded. If it contradicts an existing // constraint, signal an error. - ProtoConstraint *depends_on = nullptr; - for (auto const *desc : one_of_fields) { + ProtoConstraint* depends_on = nullptr; + for (auto const* desc : one_of_fields) { auto iter = oneof_field_map_.find(desc->containing_oneof()); if (iter != oneof_field_map_.end()) { // Duplicate of an encoding constraint. @@ -121,16 +121,16 @@ } absl::Status ProtoInstructionEncoding::AddConstraint( - FieldConstraintCtx *ctx, ConstraintType op, - const google::protobuf::FieldDescriptor *field_descriptor, - const std::vector<const google::protobuf::FieldDescriptor *> &one_of_fields, - const ProtoConstraintExpression *expr) { + FieldConstraintCtx* ctx, ConstraintType op, + const google::protobuf::FieldDescriptor* field_descriptor, + const std::vector<const google::protobuf::FieldDescriptor*>& one_of_fields, + const ProtoConstraintExpression* expr) { // One_of_fields is a list of fields that have 'kHas' constraints that are // prerequisites for the constraint being added. The variable depends_on // points to the end of the dependence chain, or nullptr if there are no or // duplicate one_of field constraints. - ProtoConstraint *depends_on = nullptr; - for (auto const *desc : one_of_fields) { + ProtoConstraint* depends_on = nullptr; + for (auto const* desc : one_of_fields) { auto iter = oneof_field_map_.find(desc->containing_oneof()); if (iter != oneof_field_map_.end()) { if (iter->second == field_descriptor) { @@ -186,7 +186,7 @@ (field_descriptor->containing_oneof() != nullptr)) { // If it's a kHas constraint on an one_of field, first make sure that it // does not contradict or duplicate any previous one_of kHas constraints. - auto *oneof_desc = field_descriptor->containing_oneof(); + auto* oneof_desc = field_descriptor->containing_oneof(); auto iter = oneof_field_map_.find(oneof_desc); if (iter != oneof_field_map_.end()) { // There is already a constraint on this oneof. Either it's the same @@ -214,9 +214,9 @@ return absl::OkStatus(); } -ProtoConstraint *ProtoInstructionEncoding::AddHasConstraint( - const google::protobuf::FieldDescriptor *field_descriptor, - ProtoConstraint *depends_on) { +ProtoConstraint* ProtoInstructionEncoding::AddHasConstraint( + const google::protobuf::FieldDescriptor* field_descriptor, + ProtoConstraint* depends_on) { if (depends_on != nullptr) { if (!has_constraints_.contains(depends_on->field_descriptor->full_name())) { return nullptr; @@ -225,7 +225,7 @@ auto iter = has_constraints_.find(field_descriptor->full_name()); if (iter != has_constraints_.end()) return iter->second; - ProtoConstraint *constraint = new ProtoConstraint{ + ProtoConstraint* constraint = new ProtoConstraint{ nullptr, field_descriptor, ConstraintType::kHas, nullptr, 0, depends_on}; has_constraints_.emplace(field_descriptor->full_name(), constraint); return constraint; @@ -241,28 +241,28 @@ // with if_not and those without (except for those with no depends_on.). // Also need to group constraints by their dependencies. Use multimap that // maps from a constraint to those that depend on it. - absl::btree_multimap<const ProtoConstraint *, const ProtoConstraint *> + absl::btree_multimap<const ProtoConstraint*, const ProtoConstraint*> grouped_constraints; // Maintain a set of inserted constraints, so that the multimap has no // duplicate key-value pairs. - absl::flat_hash_set<const ProtoConstraint *> inserted_constraints; + absl::flat_hash_set<const ProtoConstraint*> inserted_constraints; // This set contains the top level constraints that do not depend on any // other constraints, and thus are the beginning of the 'dependence chains'. - absl::flat_hash_set<const ProtoConstraint *> constraint_tops; + absl::flat_hash_set<const ProtoConstraint*> constraint_tops; // These multimaps map from a constraint to the set of setters dependent on // that constraint. - absl::btree_multimap<const ProtoConstraint *, const ProtoSetter *> + absl::btree_multimap<const ProtoConstraint*, const ProtoSetter*> grouped_setters; - absl::btree_multimap<const ProtoConstraint *, const ProtoSetter *> + absl::btree_multimap<const ProtoConstraint*, const ProtoSetter*> grouped_if_not_setters; // Lambda used to determine if a constraint is already satisfied by // an identical constraint used in the decoding of the instruction. - auto is_in_eq_constraints = [&](const ProtoConstraint *constraint) { - auto *field_descriptor = constraint->field_descriptor; + auto is_in_eq_constraints = [&](const ProtoConstraint* constraint) { + auto* field_descriptor = constraint->field_descriptor; auto iter = std::find_if( equal_constraints_.begin(), equal_constraints_.end(), - [&field_descriptor](const ProtoConstraint *constraint) { + [&field_descriptor](const ProtoConstraint* constraint) { return (constraint->op == ConstraintType::kHas) && (constraint->field_descriptor == field_descriptor); }); @@ -271,9 +271,9 @@ // First build up the data structures. // Iterate over the setters for this instruction. - for (auto &[name, setter_ptr] : setter_map_) { + for (auto& [name, setter_ptr] : setter_map_) { // Get any one_of dependency that the setter depends on. - auto *depends = setter_ptr->depends_on; + auto* depends = setter_ptr->depends_on; // If the dependency matches one in the equal constraints for decoding the // instruction, it will be true for the setters, and does not have to be // tested for again. @@ -313,7 +313,7 @@ // Helper lambda functions used in the loop nest below. // This generates the assignment. - auto assign = [&](int indent, const ProtoSetter *setter) { + auto assign = [&](int indent, const ProtoSetter* setter) { absl::StrAppend(&setter_code_, std::string(indent, ' '), "decoder->Set", ToPascalCase(setter->name), "($."); auto field_name = setter->ctx->qualified_ident()->getText(); @@ -346,9 +346,9 @@ // Helper lambda function to generate the if statement to guard individual // setters. auto generate_if_statement = [&](int indent, - const ProtoConstraint *constraint) { - auto *desc = constraint->field_descriptor; - auto *oneof = desc->containing_oneof(); + const ProtoConstraint* constraint) { + auto* desc = constraint->field_descriptor; + auto* oneof = desc->containing_oneof(); absl::StrAppend(&setter_code_, std::string(indent, ' '), "if ($."); if (oneof != nullptr) { absl::StrAppend(&setter_code_, oneof->name(), @@ -361,8 +361,8 @@ // Recursive lambda for generating nested if statements around groups of // setters with the same constraint. - std::function<void(int, const ProtoConstraint *)> generate_nested_ifs = - [&](int indent, const ProtoConstraint *constraint) { + std::function<void(int, const ProtoConstraint*)> generate_nested_ifs = + [&](int indent, const ProtoConstraint* constraint) { // Generate if statement for 'constraint'. generate_if_statement(indent, constraint); indent += 2; @@ -384,24 +384,24 @@ }; // Process the setters with no if_not's. - for (auto *constraint : constraint_tops) { + for (auto* constraint : constraint_tops) { generate_nested_ifs(kIndent, constraint); } // Recursive lambda for generating the conditions of the if statements used // by setters with 'if_not' constructs. - std::function<void(const ProtoConstraint *, std::string &)> + std::function<void(const ProtoConstraint*, std::string&)> recursive_if_conditions = - [&](const ProtoConstraint *constraint, std::string &if_conditions) { - auto *desc = constraint->field_descriptor; - auto *depends_on = constraint->depends_on; + [&](const ProtoConstraint* constraint, std::string& if_conditions) { + auto* desc = constraint->field_descriptor; + auto* depends_on = constraint->depends_on; std::string sep = ""; // Generate the conditions in reverse order of the depends_on list. if (depends_on != nullptr) { recursive_if_conditions(depends_on, if_conditions); if (!if_conditions.empty()) sep = " && "; } - auto *oneof = desc->containing_oneof(); + auto* oneof = desc->containing_oneof(); std::string ident = constraint->ctx->qualified_ident()->getText(); auto pos = ident.find_last_of('.'); std::string prefix;
diff --git a/mpact/sim/decoder/proto_instruction_encoding.h b/mpact/sim/decoder/proto_instruction_encoding.h index 1349d05..2a96456 100644 --- a/mpact/sim/decoder/proto_instruction_encoding.h +++ b/mpact/sim/decoder/proto_instruction_encoding.h
@@ -60,36 +60,36 @@ // Struct to store information about an encoding constraint for an instruction. struct ProtoConstraint { // Parsing context. - FieldConstraintCtx *ctx; + FieldConstraintCtx* ctx; // The proto field descriptor for which the constraint applies. - const google::protobuf::FieldDescriptor *field_descriptor; + const google::protobuf::FieldDescriptor* field_descriptor; // The constraint type. ConstraintType op; // If non-null, the expression that applies to the constraint. - const ProtoConstraintExpression *expr; + const ProtoConstraintExpression* expr; // If the value is compatible with int64_t, the value of the expression. This // is filled in later when the expression is evaluated for decoding purposes. int64_t value; // If non-null, points to a constraint that has to be true before one can // evaluate this constraint. - ProtoConstraint *depends_on; + ProtoConstraint* depends_on; // Constructors. - ProtoConstraint(FieldConstraintCtx *ctx, - const google::protobuf::FieldDescriptor *field_descriptor, - ConstraintType op, const ProtoConstraintExpression *expr, - int64_t value, ProtoConstraint *depends_on) + ProtoConstraint(FieldConstraintCtx* ctx, + const google::protobuf::FieldDescriptor* field_descriptor, + ConstraintType op, const ProtoConstraintExpression* expr, + int64_t value, ProtoConstraint* depends_on) : ctx(ctx), field_descriptor(field_descriptor), op(op), expr(expr), value(value), depends_on(depends_on) {} - ProtoConstraint(FieldConstraintCtx *ctx, - const google::protobuf::FieldDescriptor *field_descriptor, + ProtoConstraint(FieldConstraintCtx* ctx, + const google::protobuf::FieldDescriptor* field_descriptor, ConstraintType op) : ProtoConstraint(ctx, field_descriptor, op, nullptr, 0, nullptr) {} // Copy constructor. - ProtoConstraint(const ProtoConstraint &rhs) { + ProtoConstraint(const ProtoConstraint& rhs) { this->ctx = rhs.ctx; this->field_descriptor = rhs.field_descriptor; this->op = rhs.op; @@ -102,16 +102,16 @@ // Struct to store information about a setter for an instruction encoding. struct ProtoSetter { // Proto setter context. - SetterDefCtx *ctx; + SetterDefCtx* ctx; // The name of the object that is set. std::string name; // The field that will provide the type and value of the object. - const google::protobuf::FieldDescriptor *field_descriptor; + const google::protobuf::FieldDescriptor* field_descriptor; // Default value of the object if the field descriptor is not valid. - IfNotCtx *if_not; + IfNotCtx* if_not; // If non-null, points to constraint that has to be true in order to access // the value of the field described by field_descriptor. - ProtoConstraint *depends_on; + ProtoConstraint* depends_on; }; class ProtoInstructionGroup; @@ -120,11 +120,11 @@ // instruction in an instruction group. class ProtoInstructionEncoding { public: - ProtoInstructionEncoding(std::string name, ProtoInstructionGroup *parent); - ProtoInstructionEncoding(const ProtoInstructionEncoding &rhs); + ProtoInstructionEncoding(std::string name, ProtoInstructionGroup* parent); + ProtoInstructionEncoding(const ProtoInstructionEncoding& rhs); ProtoInstructionEncoding() = delete; - ProtoInstructionEncoding &operator=( - const ProtoInstructionEncoding &encoding) = delete; + ProtoInstructionEncoding& operator=( + const ProtoInstructionEncoding& encoding) = delete; ~ProtoInstructionEncoding(); // Adds a value setter that is executed when the instruction is successfully @@ -132,20 +132,20 @@ // values, etc., that could be stored in a nested one_of submessage, available // at known names. absl::Status AddSetter( - SetterDefCtx *ctx, const std::string &name, - const google::protobuf::FieldDescriptor *field_descriptor, - const std::vector<const google::protobuf::FieldDescriptor *> - &one_of_fields, - IfNotCtx *if_not); + SetterDefCtx* ctx, const std::string& name, + const google::protobuf::FieldDescriptor* field_descriptor, + const std::vector<const google::protobuf::FieldDescriptor*>& + one_of_fields, + IfNotCtx* if_not); // Adds an encoding constraint for the current instruction. Encoding // constraints provide constraints on values of proto message fields that // have to be satisfied in order for the instruction to match. absl::Status AddConstraint( - FieldConstraintCtx *ctx, ConstraintType op, - const google::protobuf::FieldDescriptor *field_descriptor, - const std::vector<const google::protobuf::FieldDescriptor *> - &one_of_fields, - const ProtoConstraintExpression *expr); + FieldConstraintCtx* ctx, ConstraintType op, + const google::protobuf::FieldDescriptor* field_descriptor, + const std::vector<const google::protobuf::FieldDescriptor*>& + one_of_fields, + const ProtoConstraintExpression* expr); // Call when the setters and constraints have been added in order to generate // the setter code into the setter_code_ variable. @@ -153,17 +153,17 @@ // Get setter code, substituting 'message_name' for '$' in the text. std::string GetSetterCode(absl::string_view message_name, int indent) const; // Getters. - const std::string &name() const { return name_; } - ProtoInstructionGroup *instruction_group() const { + const std::string& name() const { return name_; } + ProtoInstructionGroup* instruction_group() const { return instruction_group_; } - std::vector<ProtoConstraint *> &equal_constraints() { + std::vector<ProtoConstraint*>& equal_constraints() { return equal_constraints_; } - std::vector<ProtoConstraint *> &other_constraints() { + std::vector<ProtoConstraint*>& other_constraints() { return other_constraints_; } - absl::flat_hash_map<std::string, ProtoConstraint *> &has_constraints() { + absl::flat_hash_map<std::string, ProtoConstraint*>& has_constraints() { return has_constraints_; } @@ -176,29 +176,29 @@ // then it is required that the depends_on constraint exists in the // has_constraints_ map. This is checked by searching for the full_name of // the field_descriptor in the depends_on constraint. - ProtoConstraint *AddHasConstraint( - const google::protobuf::FieldDescriptor *field_descriptor, - ProtoConstraint *depends_on); + ProtoConstraint* AddHasConstraint( + const google::protobuf::FieldDescriptor* field_descriptor, + ProtoConstraint* depends_on); // Instruction name. std::string name_; // Parent instruction group. - ProtoInstructionGroup *instruction_group_ = nullptr; + ProtoInstructionGroup* instruction_group_ = nullptr; // Setter code for this encoding. std::string setter_code_; // Map from setter names to the setter structs. - absl::btree_map<std::string, ProtoSetter *> setter_map_; + absl::btree_map<std::string, ProtoSetter*> setter_map_; // Map from one_of descriptor to field. - absl::flat_hash_map<const google::protobuf::OneofDescriptor *, - const google::protobuf::FieldDescriptor *> + absl::flat_hash_map<const google::protobuf::OneofDescriptor*, + const google::protobuf::FieldDescriptor*> oneof_field_map_; // "equal-to" field constraints. - std::vector<ProtoConstraint *> equal_constraints_; + std::vector<ProtoConstraint*> equal_constraints_; // All other constraints. - std::vector<ProtoConstraint *> other_constraints_; + std::vector<ProtoConstraint*> other_constraints_; // Has Constraints, these are required one_of members that other constraints // may depend on. - absl::flat_hash_map<std::string, ProtoConstraint *> has_constraints_; + absl::flat_hash_map<std::string, ProtoConstraint*> has_constraints_; }; } // namespace proto_fmt
diff --git a/mpact/sim/decoder/proto_instruction_group.cc b/mpact/sim/decoder/proto_instruction_group.cc index 32d0277..d253d43 100644 --- a/mpact/sim/decoder/proto_instruction_group.cc +++ b/mpact/sim/decoder/proto_instruction_group.cc
@@ -40,22 +40,22 @@ using ::mpact::sim::machine_description::instruction_set::ToPascalCase; ProtoInstructionGroup::ProtoInstructionGroup( - std::string group_name, const google::protobuf::Descriptor *message_type, - std::string opcode_enum, ProtoEncodingInfo *encoding_info) + std::string group_name, const google::protobuf::Descriptor* message_type, + std::string opcode_enum, ProtoEncodingInfo* encoding_info) : name_(group_name), message_type_(message_type), opcode_enum_(opcode_enum), encoding_info_(encoding_info) {} ProtoInstructionGroup::~ProtoInstructionGroup() { - for (auto *encoding : encodings_) { + for (auto* encoding : encodings_) { delete encoding; } encodings_.clear(); delete encoding_group_; encoding_group_ = nullptr; - for (auto &[unused, setter_map] : setter_groups_) { - for (auto &[unused, setter_info] : setter_map) { + for (auto& [unused, setter_map] : setter_groups_) { + for (auto& [unused, setter_info] : setter_map) { delete setter_info; } setter_map.clear(); @@ -63,33 +63,33 @@ setter_groups_.clear(); } -ProtoInstructionEncoding *ProtoInstructionGroup::AddInstructionEncoding( +ProtoInstructionEncoding* ProtoInstructionGroup::AddInstructionEncoding( std::string name) { - auto *encoding = new ProtoInstructionEncoding(name, this); + auto* encoding = new ProtoInstructionEncoding(name, this); encodings_.push_back(encoding); return encoding; } absl::StatusOr< - std::pair<absl::btree_map<std::string, SetterInfo *>::const_iterator, - absl::btree_map<std::string, SetterInfo *>::const_iterator>> + std::pair<absl::btree_map<std::string, SetterInfo*>::const_iterator, + absl::btree_map<std::string, SetterInfo*>::const_iterator>> ProtoInstructionGroup::GetSetterGroup(absl::string_view group) const { auto map_iter = setter_groups_.find(group); if (map_iter == setter_groups_.end()) { return absl::NotFoundError(absl::StrCat("No setter group '", group, "'.")); } - return std::pair<absl::btree_map<std::string, SetterInfo *>::const_iterator, - absl::btree_map<std::string, SetterInfo *>::const_iterator>{ + return std::pair<absl::btree_map<std::string, SetterInfo*>::const_iterator, + absl::btree_map<std::string, SetterInfo*>::const_iterator>{ map_iter->second.begin(), map_iter->second.end()}; } // Add a group level setter. absl::Status ProtoInstructionGroup::AddSetter( - const std::string &group_name, SetterDefCtx *ctx, - const std::string &setter_name, - const google::protobuf::FieldDescriptor *field_desc, - std::vector<const google::protobuf::FieldDescriptor *> one_of_fields, - IfNotCtx *if_not) { + const std::string& group_name, SetterDefCtx* ctx, + const std::string& setter_name, + const google::protobuf::FieldDescriptor* field_desc, + std::vector<const google::protobuf::FieldDescriptor*> one_of_fields, + IfNotCtx* if_not) { auto map_iter = setter_groups_.find(group_name); if (map_iter == setter_groups_.end()) { auto [iter, unused] = setter_groups_.insert({group_name, {}}); @@ -100,14 +100,14 @@ absl::StrCat("Duplicate setter name '", setter_name, "' in setter group '", group_name, "'.")); } - auto *setter_info = + auto* setter_info = new SetterInfo({ctx, setter_name, field_desc, one_of_fields, if_not}); map_iter->second.insert({setter_name, setter_info}); return absl::OkStatus(); } void ProtoInstructionGroup::CopyInstructionEncoding( - ProtoInstructionEncoding *encoding) { + ProtoInstructionEncoding* encoding) { if (encoding_name_set_.contains(encoding->name())) { encoding_info_->error_listener()->semanticWarning( nullptr, absl::StrCat("Duplicate instruction opcode name '", @@ -118,11 +118,11 @@ } void ProtoInstructionGroup::ProcessEncodings( - DecoderErrorListener *error_listener) { + DecoderErrorListener* error_listener) { // Create a new encoding group for this instruction group and add all the // encodings to it. encoding_group_ = new ProtoEncodingGroup(this, 0, error_listener); - for (auto *encoding : encodings_) { + for (auto* encoding : encodings_) { encoding_group_->AddEncoding(new ProtoInstructionEncoding(*encoding)); } // Call the encoding group to break it into a proper decoding hierarchy.
diff --git a/mpact/sim/decoder/proto_instruction_group.h b/mpact/sim/decoder/proto_instruction_group.h index 8440af9..d178553 100644 --- a/mpact/sim/decoder/proto_instruction_group.h +++ b/mpact/sim/decoder/proto_instruction_group.h
@@ -39,71 +39,71 @@ class ProtoEncodingGroup; struct SetterInfo { - SetterDefCtx *ctx; + SetterDefCtx* ctx; std::string name; - const google::protobuf::FieldDescriptor *field_desc; - std::vector<const google::protobuf::FieldDescriptor *> one_of_fields; - IfNotCtx *if_not; + const google::protobuf::FieldDescriptor* field_desc; + std::vector<const google::protobuf::FieldDescriptor*> one_of_fields; + IfNotCtx* if_not; }; // This class represents an instruction group from the .proto_fmt file. class ProtoInstructionGroup { public: ProtoInstructionGroup(std::string group_name, - const google::protobuf::Descriptor *message_type, + const google::protobuf::Descriptor* message_type, std::string opcode_enum, - ProtoEncodingInfo *encoding_info); + ProtoEncodingInfo* encoding_info); ProtoInstructionGroup() = delete; ~ProtoInstructionGroup(); // Add group level setter. absl::Status AddSetter( - const std::string &group_name, SetterDefCtx *ctx, - const std::string &setter_name, - const google::protobuf::FieldDescriptor *field_desc, - std::vector<const google::protobuf::FieldDescriptor *> one_of_fields, - IfNotCtx *if_not); + const std::string& group_name, SetterDefCtx* ctx, + const std::string& setter_name, + const google::protobuf::FieldDescriptor* field_desc, + std::vector<const google::protobuf::FieldDescriptor*> one_of_fields, + IfNotCtx* if_not); // Look up the setters in the named setter group. If found, return the begin // and end iterators for those setters. absl::StatusOr< - std::pair<absl::btree_map<std::string, SetterInfo *>::const_iterator, - absl::btree_map<std::string, SetterInfo *>::const_iterator>> + std::pair<absl::btree_map<std::string, SetterInfo*>::const_iterator, + absl::btree_map<std::string, SetterInfo*>::const_iterator>> GetSetterGroup(absl::string_view group) const; // Create and return an instruction encoding with the given name. - ProtoInstructionEncoding *AddInstructionEncoding(std::string name); + ProtoInstructionEncoding* AddInstructionEncoding(std::string name); // Create a copy of the given instruction encoding. - void CopyInstructionEncoding(ProtoInstructionEncoding *encoding); + void CopyInstructionEncoding(ProtoInstructionEncoding* encoding); // Create an encoding group for this instruction group and then subdivide // it in a hierarchy as necessary. - void ProcessEncodings(DecoderErrorListener *error_listener); + void ProcessEncodings(DecoderErrorListener* error_listener); // Generate the decoder for this instruction group. std::string GenerateDecoder() const; // Accessors. - const std::string &name() const { return name_; } - const google::protobuf::Descriptor *message_type() const { + const std::string& name() const { return name_; } + const google::protobuf::Descriptor* message_type() const { return message_type_; } - const std::vector<ProtoInstructionEncoding *> &encodings() const { + const std::vector<ProtoInstructionEncoding*>& encodings() const { return encodings_; } - const ProtoEncodingInfo *encoding_info() const { return encoding_info_; } + const ProtoEncodingInfo* encoding_info() const { return encoding_info_; } private: std::string name_; - const google::protobuf::Descriptor *message_type_; + const google::protobuf::Descriptor* message_type_; std::string opcode_enum_; - ProtoEncodingInfo *encoding_info_; + ProtoEncodingInfo* encoding_info_; absl::flat_hash_set<std::string> encoding_name_set_; - std::vector<ProtoInstructionEncoding *> encodings_; + std::vector<ProtoInstructionEncoding*> encodings_; // Encoding group. - ProtoEncodingGroup *encoding_group_ = nullptr; + ProtoEncodingGroup* encoding_group_ = nullptr; // Setter names and types. absl::btree_map<std::string, int> setter_name_to_type_; // Setter group map. Maps from setter group name to a map from setter name // to setter info. - absl::btree_map<std::string, absl::btree_map<std::string, SetterInfo *>> + absl::btree_map<std::string, absl::btree_map<std::string, SetterInfo*>> setter_groups_; };
diff --git a/mpact/sim/decoder/resource.cc b/mpact/sim/decoder/resource.cc index 0cafa1a..77ecea8 100644 --- a/mpact/sim/decoder/resource.cc +++ b/mpact/sim/decoder/resource.cc
@@ -17,6 +17,10 @@ #include <string> #include <utility> +#include "absl/status/status.h" +#include "absl/status/statusor.h" +#include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "mpact/sim/decoder/format_name.h" namespace mpact { @@ -29,24 +33,24 @@ } ResourceFactory::~ResourceFactory() { - for (auto &[unused, resource_ptr] : resource_map_) { + for (auto& [unused, resource_ptr] : resource_map_) { delete resource_ptr; } resource_map_.clear(); } -absl::StatusOr<Resource *> ResourceFactory::CreateResource( +absl::StatusOr<Resource*> ResourceFactory::CreateResource( absl::string_view name) { if (resource_map_.contains(name)) { return absl::AlreadyExistsError( absl::StrCat("Resource '", name, "' already exists")); } - auto *resource = new Resource(std::string(name)); + auto* resource = new Resource(std::string(name)); resource_map_.insert(std::make_pair(resource->name(), resource)); return resource; } -Resource *ResourceFactory::GetOrInsertResource(absl::string_view name) { +Resource* ResourceFactory::GetOrInsertResource(absl::string_view name) { auto iter = resource_map_.find(name); if (iter != resource_map_.end()) return iter->second; auto result = CreateResource(name);
diff --git a/mpact/sim/decoder/resource.h b/mpact/sim/decoder/resource.h index 6567b15..25867e2 100644 --- a/mpact/sim/decoder/resource.h +++ b/mpact/sim/decoder/resource.h
@@ -50,8 +50,8 @@ bool is_array() const { return is_array_; } void set_is_array(bool value) { is_array_ = value; } - const std::string &name() const { return name_; } - const std::string &pascal_name() const { return pascal_name_; } + const std::string& name() const { return name_; } + const std::string& pascal_name() const { return pascal_name_; } private: explicit Resource(std::string name); @@ -66,7 +66,7 @@ // resources. class ResourceFactory { public: - using ResourceMap = absl::btree_map<std::string, Resource *>; + using ResourceMap = absl::btree_map<std::string, Resource*>; using ArgumentSet = absl::btree_set<std::string>; ResourceFactory() = default; @@ -74,11 +74,11 @@ // If the resource doesn't yet exist, create a new resource and return the // pointer, otherwise return an error code. - absl::StatusOr<Resource *> CreateResource(absl::string_view name); + absl::StatusOr<Resource*> CreateResource(absl::string_view name); // Return the named resource, or if it does not exist, create it, and return // a pointer to the newly created resource. - Resource *GetOrInsertResource(absl::string_view name); - const ResourceMap &resource_map() const { return resource_map_; } + Resource* GetOrInsertResource(absl::string_view name); + const ResourceMap& resource_map() const { return resource_map_; } private: ResourceMap resource_map_;
diff --git a/mpact/sim/decoder/slot.cc b/mpact/sim/decoder/slot.cc index 641972e..e7cf436 100644 --- a/mpact/sim/decoder/slot.cc +++ b/mpact/sim/decoder/slot.cc
@@ -60,7 +60,7 @@ // This function translates the location specification into a set of '->' // references starting with 'inst->' to get to the operand that is implied. static absl::StatusOr<std::string> TranslateLocator( - const OperandLocator &locator) { + const OperandLocator& locator) { std::string code; absl::StrAppend(&code, "inst->"); if (locator.op_spec_number > 0) { @@ -85,7 +85,7 @@ // This is a helper function that generates the code snippet to extract the // right sized value based on the length specifier in the print format // specification. E.g., %08x, %04d, etc. -static std::string GetExtractor(const std::string &format) { +static std::string GetExtractor(const std::string& format) { int size = 0; int pos = 0; int len = 1; @@ -105,8 +105,8 @@ // Small helper function to just expand the expression specified by the // FormatInfo from parsing the disassembly specifier. -static std::string ExpandExpression(const FormatInfo &format, - const std::string &locator) { +static std::string ExpandExpression(const FormatInfo& format, + const std::string& locator) { // Handle the case when it's just an '@' - i.e., just the address. if (format.use_address && format.operation.empty()) { return absl::StrCat("(inst->address())"); @@ -133,8 +133,8 @@ : "))"); } -Slot::Slot(absl::string_view name, InstructionSet *instruction_set, - bool is_templated, SlotDeclCtx *ctx, unsigned generator_version) +Slot::Slot(absl::string_view name, InstructionSet* instruction_set, + bool is_templated, SlotDeclCtx* ctx, unsigned generator_version) : instruction_set_(instruction_set), ctx_(ctx), generator_version_(generator_version), @@ -147,37 +147,37 @@ default_latency_ = nullptr; delete default_instruction_; default_instruction_ = nullptr; - for (auto *param : template_parameters_) { + for (auto* param : template_parameters_) { delete param; } template_parameters_.clear(); - for (auto &base : base_slots_) { + for (auto& base : base_slots_) { if (base.arguments != nullptr) { - for (auto *expr : *(base.arguments)) { + for (auto* expr : *(base.arguments)) { delete expr; } delete base.arguments; } } base_slots_.clear(); - for (auto &[unused, inst_ptr] : instruction_map_) { + for (auto& [unused, inst_ptr] : instruction_map_) { delete inst_ptr; } instruction_map_.clear(); - for (auto &[unused, element_ptr] : constant_map_) { + for (auto& [unused, element_ptr] : constant_map_) { delete element_ptr; } constant_map_.clear(); // The ctx objects stored in resource_spec_map_ are owned by the Antlr4 // parser, so just clear the map (don't delete those objects). resource_spec_map_.clear(); - for (auto &[ignored, expr] : attribute_map_) { + for (auto& [ignored, expr] : attribute_map_) { delete expr; } attribute_map_.clear(); } -absl::Status Slot::AppendInstruction(Instruction *inst) { +absl::Status Slot::AppendInstruction(Instruction* inst) { if (!is_templated()) { bool valid = inst->opcode()->ValidateDestLatencies( [](int l) -> bool { return l >= 0; }); @@ -195,8 +195,8 @@ "Opcode '", name, "' already added to slot '", this->name(), "'")); } -absl::Status Slot::AppendInheritedInstruction(Instruction *inst, - TemplateInstantiationArgs *args) { +absl::Status Slot::AppendInheritedInstruction(Instruction* inst, + TemplateInstantiationArgs* args) { std::string name = inst->opcode()->name(); if (!instruction_map_.contains(name)) { auto derived = inst->CreateDerivedInstruction(args); @@ -219,7 +219,7 @@ absl::StrCat("instruction already added: ", inst->opcode()->name())); } -bool Slot::HasInstruction(const std::string &opcode_name) const { +bool Slot::HasInstruction(const std::string& opcode_name) const { return instruction_map_.contains(opcode_name); } @@ -227,16 +227,16 @@ // Generates a string that is a unique key for the attributes to determine which // instructions can share attribute setter functions. -std::string Slot::CreateAttributeLookupKey(const Instruction *inst) const { +std::string Slot::CreateAttributeLookupKey(const Instruction* inst) const { std::string key; - for (auto const &[name, expr] : inst->attribute_map()) { + for (auto const& [name, expr] : inst->attribute_map()) { std::string value; auto result = expr->GetValue(); if (!result.ok()) { absl::StrAppend(&key, name, "[e1]:"); continue; } - auto *value_ptr = std::get_if<int>(&result.value()); + auto* value_ptr = std::get_if<int>(&result.value()); if (value_ptr == nullptr) { absl::StrAppend(&key, name, "[e2]:"); continue; @@ -249,7 +249,7 @@ // Generate the attribute setter function that matches the "key" of the given // instruction. std::string Slot::GenerateAttributeSetterFcn(absl::string_view name, - const Instruction *inst) const { + const Instruction* inst) const { std::string output; absl::StrAppend(&output, "void ", name, "(Instruction *inst) {\n"); if (!attribute_map_.empty()) { @@ -258,14 +258,14 @@ "];\n" " attrs = {"); std::string sep = ""; - for (auto const &[name, expr] : inst->attribute_map()) { + for (auto const& [name, expr] : inst->attribute_map()) { auto result = expr->GetValue(); if (!result.ok()) { absl::StrAppend(&output, " #error Expression for '", name, "' has no constant value\n"); continue; } - int *value = std::get_if<int>(&result.value()); + int* value = std::get_if<int>(&result.value()); if (value == nullptr) { absl::StrAppend(&output, " #error Expression for '", name, "' does not have type int\n"); @@ -284,7 +284,7 @@ // Return a function call string that will set the attributes for the given // instruction. If no such appropriate function exists, create one. -std::string Slot::GenerateAttributeSetter(const Instruction *inst) { +std::string Slot::GenerateAttributeSetter(const Instruction* inst) { auto key = CreateAttributeLookupKey(inst); auto iter = attribute_setter_name_map_->find(key); if (iter == attribute_setter_name_map_->end()) { @@ -300,7 +300,7 @@ namespace { -std::string EscapeRegexCharacters(const std::string &str) { +std::string EscapeRegexCharacters(const std::string& str) { std::string output; if (str.empty()) return output; auto pos = str.find_last_not_of(' '); @@ -381,13 +381,13 @@ } // namespace std::tuple<std::string, std::vector<OperandLocator>> Slot::GenerateRegEx( - const Instruction *inst, std::vector<std::string> &formats) const { + const Instruction* inst, std::vector<std::string>& formats) const { std::string output = "R\"("; std::string sep = "^\\s*"; std::vector<OperandLocator> opnd_locators; // Iterate over the vector of disasm formats. These will end up concatenated // with \s+ separators. - for (auto const *disasm_fmt : inst->disasm_format_vec()) { + for (auto const* disasm_fmt : inst->disasm_format_vec()) { absl::StrAppend(&output, sep); sep = "\\s+"; // The fragments are the text part (not part of operands), that occur @@ -451,7 +451,7 @@ return {output, opnd_locators}; } -std::string GenerateEncodingFunctions(const std::string &encoder, +std::string GenerateEncodingFunctions(const std::string& encoder, InstructionSet instruction_set) { std::string output; absl::StrAppend(&output, "namespace {\n\n"); @@ -525,7 +525,7 @@ " if (index == -1) return absl::InternalError(error);\n" " regex_vec_.push_back(new RE2(\"^$\"));\n"); std::vector<std::string> formats; - for (auto const &[name, inst_ptr] : instruction_map_) { + for (auto const& [name, inst_ptr] : instruction_map_) { auto [regex, opnd_locators] = GenerateRegEx(inst_ptr, formats); max_args = std::max(max_args, opnd_locators.size()); std::string opcode_name = @@ -625,7 +625,7 @@ // Generate a function that will set the disassembly string for the given // instruction. std::string Slot::GenerateDisasmSetterFcn(absl::string_view name, - const Instruction *inst) const { + const Instruction* inst) const { std::string output; std::string class_name = pascal_name() + "Slot"; absl::StrAppend(&output, "void ", name, "(Instruction *inst) {\n"); @@ -640,7 +640,7 @@ in_strcat.push(true); outer_paren = true; std::string outer_sep; - for (auto const *disasm_fmt : inst->disasm_format_vec()) { + for (auto const* disasm_fmt : inst->disasm_format_vec()) { int inner_paren = 0; size_t index = 0; std::string inner_sep; @@ -667,14 +667,14 @@ } // Generate the strings from the format fragments and the format info. std::string next_sep; - for (auto const &frag : disasm_fmt->format_fragment_vec) { + for (auto const& frag : disasm_fmt->format_fragment_vec) { if (!frag.empty()) { absl::StrAppend(&output, inner_sep, indent_string(indent), "\"", frag, "\""); next_sep = ", "; } if (index < disasm_fmt->format_info_vec.size()) { - auto *format_info = disasm_fmt->format_info_vec[index]; + auto* format_info = disasm_fmt->format_info_vec[index]; if (format_info->op_name.empty()) { if (!format_info->is_formatted) { absl::StrAppend(&output, "\n#error Missing locator information"); @@ -737,11 +737,11 @@ // Generate a signature for the disassembly setter function required for the // given instruction. If a matching one does not exist, call to create such a // function. -std::string Slot::GenerateDisassemblySetter(const Instruction *inst) { +std::string Slot::GenerateDisassemblySetter(const Instruction* inst) { std::string key; // First combine the disassembly fragments. - for (auto const *format : inst->disasm_format_vec()) { - for (auto const &frag : format->format_fragment_vec) { + for (auto const* format : inst->disasm_format_vec()) { + for (auto const& frag : format->format_fragment_vec) { absl::StrAppend(&key, frag); } } @@ -759,7 +759,7 @@ } // Generate the assembler function for the given instruction. -std::string Slot::GenerateAssemblerFcn(const Instruction *inst, +std::string Slot::GenerateAssemblerFcn(const Instruction* inst, absl::string_view encoder_type) const { std::string output; int num_values = inst->opcode()->source_op_vec().size() + @@ -778,7 +778,7 @@ "auto [inst_word, num_bits] = enc->GetOpEncoding(opcode, slot, " "entry);\n", " absl::Status status;\n"); - auto const &source_op_vec = inst->opcode()->source_op_vec(); + auto const& source_op_vec = inst->opcode()->source_op_vec(); for (int i = 0; i < source_op_vec.size(); ++i) { std::string op_name = ToPascalCase(source_op_vec[i].name); absl::StrAppend(&output, " status = enc->SetSrcEncoding(values.at(", i, @@ -788,7 +788,7 @@ ", opcode);\n" " if (!stats.ok()) return status;\n"); } - auto const &dest_op_vec = inst->opcode()->dest_op_vec(); + auto const& dest_op_vec = inst->opcode()->dest_op_vec(); for (int i = 0; i < dest_op_vec.size(); ++i) { absl::StrAppend(&output, " status = enc->SetDestEncoding(values.at(", i, "), slot, entry,\n" @@ -811,13 +811,13 @@ // Generate a string that is a unique identifier from the resources to // determine which instructions can share resource setter functions. std::string Slot::CreateResourceKey( - const std::vector<const ResourceReference *> &refs) const { + const std::vector<const ResourceReference*>& refs) const { std::string key; - std::vector<const ResourceReference *> complex_refs; - std::vector<const ResourceReference *> simple_refs; + std::vector<const ResourceReference*> complex_refs; + std::vector<const ResourceReference*> simple_refs; absl::btree_set<std::string> names; // Iterate over use resources. - for (auto const *ref : refs) { + for (auto const* ref : refs) { if (!ref->resource->is_simple()) { complex_refs.push_back(ref); } else { @@ -825,7 +825,7 @@ } } // Simple use resources. - for (auto const *ref : simple_refs) { + for (auto const* ref : simple_refs) { std::string name = "S$"; if (ref->is_array) { absl::StrAppend(&name, "[", ref->resource->pascal_name(), "]"); @@ -835,7 +835,7 @@ names.insert(name); } std::string sep = ""; - for (auto const &name : names) { + for (auto const& name : names) { absl::StrAppend(&key, sep, name); sep = "/"; } @@ -843,7 +843,7 @@ absl::StrAppend(&key, ":"); // Complex use resources. - for (auto const *ref : complex_refs) { + for (auto const* ref : complex_refs) { std::string name = "C$"; if (ref->is_array) { absl::StrAppend(&name, "[", ref->resource->pascal_name(), "]"); @@ -865,7 +865,7 @@ names.insert(name); } sep = ""; - for (auto const &name : names) { + for (auto const& name : names) { absl::StrAppend(&key, sep, name); sep = "/"; } @@ -875,7 +875,7 @@ // Generate a resource setter function call for the resource "key" of the // given instruction. If a matching one does not exist, call to create such a // function. -std::string Slot::GenerateResourceSetter(const Instruction *inst, +std::string Slot::GenerateResourceSetter(const Instruction* inst, absl::string_view encoding_type) { std::string key = CreateResourceKey(inst->resource_use_vec()); absl::StrAppend(&key, ":", CreateResourceKey(inst->resource_acquire_vec())); @@ -894,7 +894,7 @@ // Create a resource setter function for the resource "key" of the given // instruction. std::string Slot::GenerateResourceSetterFcn( - absl::string_view name, const Instruction *inst, + absl::string_view name, const Instruction* inst, absl::string_view encoding_type) const { std::string output; absl::StrAppend(&output, "void ", name, "(Instruction *inst, ", encoding_type, @@ -911,9 +911,9 @@ } // Get all the simple resources that need to be free, then all the complex // resources that need to be free in order to issue the instruction. - std::vector<const ResourceReference *> complex_refs; - std::vector<const ResourceReference *> simple_refs; - for (auto const *ref : inst->resource_use_vec()) { + std::vector<const ResourceReference*> complex_refs; + std::vector<const ResourceReference*> simple_refs; + for (auto const* ref : inst->resource_use_vec()) { // Do the complex refs last. if (!ref->resource->is_simple()) { complex_refs.push_back(ref); @@ -926,7 +926,7 @@ // First gather the resource references into a single vector, then request // the resource operands for all the resource references in that vector. absl::StrAppend(&output, " std::vector<SimpleResourceEnum> hold_vec = {"); - for (auto const *simple : simple_refs) { + for (auto const* simple : simple_refs) { std::string resource_name; if (simple->is_array) { resource_name = absl::StrCat("SimpleResourceEnum::k", @@ -947,7 +947,7 @@ " }\n"); } // Complex resources. - for (auto const *complex : complex_refs) { + for (auto const* complex : complex_refs) { // Get the expression values for the begin and end expressions. auto begin_value = complex->begin_expression->GetValue(); auto end_value = complex->end_expression->GetValue(); @@ -957,8 +957,8 @@ continue; } // Get the integer values from the begin and end expression values. - int *begin = std::get_if<int>(&begin_value.value()); - int *end = std::get_if<int>(&end_value.value()); + int* begin = std::get_if<int>(&begin_value.value()); + int* end = std::get_if<int>(&end_value.value()); if ((begin == nullptr) || (end == nullptr)) { absl::StrAppend( &output, "#error Unable to get value of begin or end expression\n"); @@ -991,7 +991,7 @@ // complex resources that need to be reserved when issuing this instruction. complex_refs.clear(); simple_refs.clear(); - for (auto const *ref : inst->resource_acquire_vec()) { + for (auto const* ref : inst->resource_acquire_vec()) { // Do the complex refs last. if (!ref->resource->is_simple()) { complex_refs.push_back(ref); @@ -1003,9 +1003,9 @@ if (!simple_refs.empty()) { // Compute the set of latencies. Insert each reference into a multi-map // keyed by the latency. - std::multimap<int, const ResourceReference *> latency_map; + std::multimap<int, const ResourceReference*> latency_map; absl::flat_hash_set<int> latencies; - for (auto const *simple : simple_refs) { + for (auto const* simple : simple_refs) { if (simple->end_expression == nullptr) { continue; } @@ -1014,7 +1014,7 @@ absl::StrAppend(&output, "#error Unable to evaluate end expression\n"); continue; } - int *end = std::get_if<int>(&end_value.value()); + int* end = std::get_if<int>(&end_value.value()); if (end == nullptr) { absl::StrAppend(&output, "#error Unable to get value of end expression\n"); @@ -1031,7 +1031,7 @@ latency, " = {"); for (auto iter = latency_map.lower_bound(latency); iter != latency_map.upper_bound(latency); ++iter) { - auto *simple = iter->second; + auto* simple = iter->second; std::string resource_name; if (simple->is_array) { resource_name = absl::StrCat("SimpleResourceEnum::k", @@ -1056,7 +1056,7 @@ // Complex resources. if (!complex_refs.empty()) { - for (auto const *complex : complex_refs) { + for (auto const* complex : complex_refs) { // Get the expression values for the begin and end expressions. if (complex->begin_expression == nullptr) continue; if (complex->end_expression == nullptr) continue; @@ -1068,8 +1068,8 @@ continue; } // Get the integer values from the begin and end expression values. - int *begin = std::get_if<int>(&begin_value.value()); - int *end = std::get_if<int>(&end_value.value()); + int* begin = std::get_if<int>(&begin_value.value()); + int* end = std::get_if<int>(&end_value.value()); if (complex->is_array) { absl::StrAppend(&output, " auto res_op_vec = " @@ -1101,16 +1101,16 @@ // Generates a string that is a unique identifier from the operands to // determine which instructions can share operand getter functions. -std::string Slot::CreateOperandLookupKey(const Opcode *opcode) const { +std::string Slot::CreateOperandLookupKey(const Opcode* opcode) const { std::string key; // Generate identifier for the predicate operand, if the opcode has one. - const std::string &op_name = opcode->predicate_op_name(); + const std::string& op_name = opcode->predicate_op_name(); if (!op_name.empty()) { absl::StrAppend(&key, op_name, ":"); } // Generate key for the source operands. std::string sep = ""; - for (const auto &src_op : opcode->source_op_vec()) { + for (const auto& src_op : opcode->source_op_vec()) { if (src_op.is_array) { absl::StrAppend(&key, sep, "[", src_op.name, "]"); } else { @@ -1121,7 +1121,7 @@ absl::StrAppend(&key, ":"); // Append identifier for destination operands. sep.clear(); - for (auto const *dst_op : opcode->dest_op_vec()) { + for (auto const* dst_op : opcode->dest_op_vec()) { std::string dest_op_enum; if (dst_op->is_array()) { absl::StrAppend(&key, sep, "[", dst_op->name(), "]"); @@ -1157,7 +1157,7 @@ // given opcode. std::string Slot::GenerateOperandSetterFcn(absl::string_view getter_name, absl::string_view encoding_type, - const Opcode *opcode) const { + const Opcode* opcode) const { std::string output; std::string optional_inst; if (generator_version_ == 2) { @@ -1167,7 +1167,7 @@ encoding_type, " *enc, OpcodeEnum opcode, SlotEnum slot, int entry) {\n"); // Generate code to set predicate operand, if the opcode has one. - const std::string &op_name = opcode->predicate_op_name(); + const std::string& op_name = opcode->predicate_op_name(); if (!op_name.empty()) { std::string pred_op_enum = absl::StrCat("PredOpEnum::k", ToPascalCase(op_name)); @@ -1177,7 +1177,7 @@ } // Generate code to set the instruction's source operands. int source_no = 0; - for (const auto &src_op : opcode->source_op_vec()) { + for (const auto& src_op : opcode->source_op_vec()) { // If the source operand is an array, then we need to iterate over the // vector of operands that GetSources returns. if (src_op.is_array) { @@ -1201,7 +1201,7 @@ } // Generate code to set the instruction's destination operands. int dest_no = 0; - for (auto const *dst_op : opcode->dest_op_vec()) { + for (auto const* dst_op : opcode->dest_op_vec()) { std::string dest_op_enum; if (dst_op->is_array()) { dest_op_enum = @@ -1276,8 +1276,8 @@ " ", GenerateAttributeSetter(default_instruction_), ",\n", " SemFuncSetter{", default_instruction_->semfunc_code_string(), "}, ", default_instruction_->opcode()->instruction_size(), "}},\n"); - for (auto const &[unused, inst_ptr] : instruction_map_) { - auto *instruction = inst_ptr; + for (auto const& [unused, inst_ptr] : instruction_map_) { + auto* instruction = inst_ptr; std::string opcode_name = instruction->opcode()->pascal_name(); std::string opcode_enum = absl::StrCat("OpcodeEnum::k", opcode_name); absl::StrAppend(&output, "\n // *** k", opcode_name, " ***\n"); @@ -1286,7 +1286,7 @@ std::string code_str; std::string sep = ""; std::string operands_str; - for (auto const *inst = instruction; inst != nullptr; + for (auto const* inst = instruction; inst != nullptr; inst = inst->child()) { // Construct operand getter lookup key. std::string key = CreateOperandLookupKey(inst->opcode()); @@ -1402,23 +1402,23 @@ return combined_output; } -absl::Status Slot::CheckPredecessors(const Slot *base) const { +absl::Status Slot::CheckPredecessors(const Slot* base) const { if (predecessor_set_.contains(base)) return absl::AlreadyExistsError( absl::StrCat("'", base->name(), "' is already in the predecessor set of '", name(), "'")); - for (auto const *pred : predecessor_set_) { + for (auto const* pred : predecessor_set_) { auto status = pred->CheckPredecessors(base); if (!status.ok()) return status; } - for (auto const *base_pred : base->predecessor_set_) { + for (auto const* base_pred : base->predecessor_set_) { auto status = CheckPredecessors(base_pred); if (!status.ok()) return status; } return absl::OkStatus(); } -absl::Status Slot::AddBase(const Slot *base) { +absl::Status Slot::AddBase(const Slot* base) { // First need to check if the current slot already inherits from base, or // any of base's predecessors. Only tree-like inheritance is supported. auto status = CheckPredecessors(base); @@ -1428,8 +1428,8 @@ return absl::OkStatus(); } -absl::Status Slot::AddBase(const Slot *base, - TemplateInstantiationArgs *arguments) { +absl::Status Slot::AddBase(const Slot* base, + TemplateInstantiationArgs* arguments) { auto status = CheckPredecessors(base); if (!status.ok()) return status; predecessor_set_.insert(base); @@ -1437,9 +1437,9 @@ return absl::OkStatus(); } -absl::Status Slot::AddConstant(const std::string &ident, - const std::string &type, - TemplateExpression *expression) { +absl::Status Slot::AddConstant(const std::string& ident, + const std::string& type, + TemplateExpression* expression) { // Ignore the type for now - there is only int. (void)type; // Check if the name already exists or matches a template formal parameter. @@ -1456,13 +1456,13 @@ return absl::OkStatus(); } -TemplateExpression *Slot::GetConstExpression(const std::string &ident) const { +TemplateExpression* Slot::GetConstExpression(const std::string& ident) const { auto iter = constant_map_.find(ident); if (iter == constant_map_.end()) return nullptr; return iter->second; } -absl::Status Slot::AddTemplateFormal(const std::string &par_name) { +absl::Status Slot::AddTemplateFormal(const std::string& par_name) { if (template_parameter_map_.contains(par_name)) { // Push it into the vector, but not the map. Have the formal name refer to // the previous index. Signal error. This allows us to properly match the @@ -1479,14 +1479,14 @@ return absl::OkStatus(); } -TemplateFormal *Slot::GetTemplateFormal(const std::string &name) const { +TemplateFormal* Slot::GetTemplateFormal(const std::string& name) const { auto iter = template_parameter_map_.find(name); if (iter == template_parameter_map_.end()) return nullptr; return template_parameters_[iter->second]; } -void Slot::AddInstructionAttribute(const std::string &name, - TemplateExpression *expr) { +void Slot::AddInstructionAttribute(const std::string& name, + TemplateExpression* expr) { attribute_map_.emplace(name, expr); }
diff --git a/mpact/sim/decoder/slot.h b/mpact/sim/decoder/slot.h index d6a9367..9065874 100644 --- a/mpact/sim/decoder/slot.h +++ b/mpact/sim/decoder/slot.h
@@ -44,8 +44,8 @@ // A structure that holds the resources specified by a named resource specifier. struct ResourceSpec { std::string name; - std::vector<ResourceReference *> use_vec; - std::vector<ResourceReference *> acquire_vec; + std::vector<ResourceReference*> use_vec; + std::vector<ResourceReference*> acquire_vec; }; // A slot class instance represents one or more identical instruction slots @@ -61,71 +61,71 @@ generated::InstructionSetParser::Resource_detailsContext; // Constructor and destructor. - Slot(absl::string_view name, InstructionSet *instruction_set, - bool is_templated, SlotDeclCtx *ctx, unsigned generator_version); - Slot(absl::string_view name, InstructionSet *instruction_set, - bool is_templated, SlotDeclCtx *ctx) + Slot(absl::string_view name, InstructionSet* instruction_set, + bool is_templated, SlotDeclCtx* ctx, unsigned generator_version); + Slot(absl::string_view name, InstructionSet* instruction_set, + bool is_templated, SlotDeclCtx* ctx) : Slot(name, instruction_set, is_templated, ctx, 1) {} ~Slot(); // Add declared opcode to the current slot. - absl::Status AppendInstruction(Instruction *inst); + absl::Status AppendInstruction(Instruction* inst); // Add an opcode inherited from a base slot to the current slot. - absl::Status AppendInheritedInstruction(Instruction *inst, - TemplateInstantiationArgs *args); + absl::Status AppendInheritedInstruction(Instruction* inst, + TemplateInstantiationArgs* args); // Add default instruction attribute. - void AddInstructionAttribute(const std::string &name, - TemplateExpression *expr); - bool HasInstruction(const std::string &opcode_name) const; + void AddInstructionAttribute(const std::string& name, + TemplateExpression* expr); + bool HasInstruction(const std::string& opcode_name) const; // Return string for the header file declarations for this class. std::string GenerateClassDeclaration(absl::string_view encoding_type) const; // Return string for the .cc file definitions for this class. std::string GenerateClassDefinition(absl::string_view encoding_type); // Add a non-templated slot as a base. - absl::Status AddBase(const Slot *base); + absl::Status AddBase(const Slot* base); // Add a templated slot as a base with the vector of expressions as the // template parameter values. - absl::Status AddBase(const Slot *base, TemplateInstantiationArgs *arguments); + absl::Status AddBase(const Slot* base, TemplateInstantiationArgs* arguments); // Add a declared constant (scoped to the slot). - absl::Status AddConstant(const std::string &ident, const std::string &type, - TemplateExpression *expression); - TemplateExpression *GetConstExpression(const std::string &ident) const; + absl::Status AddConstant(const std::string& ident, const std::string& type, + TemplateExpression* expression); + TemplateExpression* GetConstExpression(const std::string& ident) const; // When the current slot is templated, adds an identifier as a template // formal parameter. - absl::Status AddTemplateFormal(const std::string &name); - TemplateFormal *GetTemplateFormal(const std::string &name) const; + absl::Status AddTemplateFormal(const std::string& name); + TemplateFormal* GetTemplateFormal(const std::string& name) const; // Generate the calls to encode the given operand. std::string GenerateOperandEncoder(int position, absl::string_view op_name, - const OperandLocator &locator, - const Opcode *opcode) const; + const OperandLocator& locator, + const Opcode* opcode) const; // Generate regex for a given instruction. std::tuple<std::string, std::vector<OperandLocator>> GenerateRegEx( - const Instruction *inst, std::vector<std::string> &formats) const; + const Instruction* inst, std::vector<std::string>& formats) const; // Generate regexes to match the assembly string for the instructions. std::tuple<std::string, std::string> GenerateAsmRegexMatcher() const; // Generate assembler function for the given instruction. - std::string GenerateAssemblerFcn(const Instruction *inst, + std::string GenerateAssemblerFcn(const Instruction* inst, absl::string_view encoder_type) const; // Resources - Resource *GetOrInsertResource(const std::string &name); + Resource* GetOrInsertResource(const std::string& name); // Getters and setters. - InstructionSet *instruction_set() const { return instruction_set_; } - const SlotDeclCtx *ctx() const { return ctx_; } + InstructionSet* instruction_set() const { return instruction_set_; } + const SlotDeclCtx* ctx() const { return ctx_; } int default_instruction_size() const { return default_instruction_size_; } void set_default_instruction_size(int val) { default_instruction_size_ = val; } - TemplateExpression *default_latency() const { return default_latency_; } - void set_default_latency(TemplateExpression *latency_expr) { + TemplateExpression* default_latency() const { return default_latency_; } + void set_default_latency(TemplateExpression* latency_expr) { if (default_latency_ != nullptr) delete default_latency_; default_latency_ = latency_expr; } - Instruction *default_instruction() const { return default_instruction_; } - void set_default_instruction(Instruction *inst) { + Instruction* default_instruction() const { return default_instruction_; } + void set_default_instruction(Instruction* inst) { default_instruction_ = inst; } int size() const { return size_; } @@ -137,55 +137,55 @@ void set_is_marked(bool value) { is_marked_ = value; } void set_is_referenced(bool value) { is_referenced_ = value; } bool is_referenced() const { return is_referenced_; } - const std::string &name() const { return name_; } - const std::string &pascal_name() const { return pascal_name_; } - const std::vector<BaseSlot> &base_slots() const { return base_slots_; } - const absl::btree_map<std::string, Instruction *> &instruction_map() const { + const std::string& name() const { return name_; } + const std::string& pascal_name() const { return pascal_name_; } + const std::vector<BaseSlot>& base_slots() const { return base_slots_; } + const absl::btree_map<std::string, Instruction*>& instruction_map() const { return instruction_map_; } - const std::vector<TemplateFormal *> &template_parameters() const { + const std::vector<TemplateFormal*>& template_parameters() const { return template_parameters_; } - const absl::flat_hash_map<std::string, int> &template_parameter_map() const { + const absl::flat_hash_map<std::string, int>& template_parameter_map() const { return template_parameter_map_; } - absl::btree_map<std::string, ResourceDetailsCtx *> &resource_spec_map() { + absl::btree_map<std::string, ResourceDetailsCtx*>& resource_spec_map() { return resource_spec_map_; } - absl::btree_map<std::string, IdentListCtx *> &resource_array_ref_map() { + absl::btree_map<std::string, IdentListCtx*>& resource_array_ref_map() { return resource_array_ref_map_; } - const absl::btree_map<std::string, TemplateExpression *> &attribute_map() { + const absl::btree_map<std::string, TemplateExpression*>& attribute_map() { return attribute_map_; } private: // These functions generate the functions that are called by the decoder to // set the instruction operands. - std::string CreateOperandLookupKey(const Opcode *opcode) const; + std::string CreateOperandLookupKey(const Opcode* opcode) const; std::string GenerateOperandSetterFcn(absl::string_view getter_name, absl::string_view encoding_type, - const Opcode *opcode) const; + const Opcode* opcode) const; // These functions generate the functions that are called by the decoder to // set the instruction resources. std::string CreateResourceKey( - const std::vector<const ResourceReference *> &refs) const; - std::string GenerateResourceSetter(const Instruction *inst, + const std::vector<const ResourceReference*>& refs) const; + std::string GenerateResourceSetter(const Instruction* inst, absl::string_view encoding_type); std::string GenerateResourceSetterFcn(absl::string_view name, - const Instruction *inst, + const Instruction* inst, absl::string_view encoding_type) const; // These functions generate the functions that are called by the decoder to // set the instruction disassembly string. - std::string GenerateDisassemblySetter(const Instruction *inst); + std::string GenerateDisassemblySetter(const Instruction* inst); std::string GenerateDisasmSetterFcn(absl::string_view name, - const Instruction *inst) const; + const Instruction* inst) const; // These functions generate the functions that are called by the decoder to // set the instruction attributes. - std::string GenerateAttributeSetter(const Instruction *inst); + std::string GenerateAttributeSetter(const Instruction* inst); std::string GenerateAttributeSetterFcn(absl::string_view name, - const Instruction *inst) const; - std::string CreateAttributeLookupKey(const Instruction *inst) const; + const Instruction* inst) const; + std::string CreateAttributeLookupKey(const Instruction* inst) const; // Generates a string that is a unique key for the operands to determine which // instructions can share operand getter functions. // Build up a string containing the function getter initializers that are @@ -197,18 +197,18 @@ // slot or any of its inheritance predecessors. Returns AlreadyExistsError // if the current slot or its predecessors already inherit from base or its // predecessors. - absl::Status CheckPredecessors(const Slot *base) const; + absl::Status CheckPredecessors(const Slot* base) const; // Parent instruction_set class. - InstructionSet *instruction_set_; + InstructionSet* instruction_set_; // Parser context. - SlotDeclCtx *ctx_ = nullptr; + SlotDeclCtx* ctx_ = nullptr; // The default and minimum opcode size specified for the slot. int default_instruction_size_ = 1; int min_instruction_size_ = std::numeric_limits<int>::max(); // Default latency for destination operands. - TemplateExpression *default_latency_ = nullptr; + TemplateExpression* default_latency_ = nullptr; // Fallback opcode for failed decodes. - Instruction *default_instruction_ = nullptr; + Instruction* default_instruction_ = nullptr; // Number of instances of this slot in the instruction_set instruction word. int size_ = 1; unsigned generator_version_; @@ -223,7 +223,7 @@ std::string pascal_name_; // Pointer to slot it inherits from. std::vector<BaseSlot> base_slots_; - absl::flat_hash_set<const Slot *> predecessor_set_; + absl::flat_hash_set<const Slot*> predecessor_set_; // Map from operand getter key to operand getter function name. These are // static so that they can be shared across different slots. static absl::NoDestructor<absl::flat_hash_map<std::string, std::string>> @@ -240,17 +240,17 @@ absl::flat_hash_set<std::string> src_operand_getters_; absl::flat_hash_set<std::string> dst_operand_getters_; // Map of instructions defined in this slot or inherited. - absl::btree_map<std::string, Instruction *> instruction_map_; + absl::btree_map<std::string, Instruction*> instruction_map_; absl::flat_hash_set<std::string> operand_setters_; // Template parameter names. - std::vector<TemplateFormal *> template_parameters_; + std::vector<TemplateFormal*> template_parameters_; absl::flat_hash_map<std::string, int> template_parameter_map_; - absl::flat_hash_map<std::string, TemplateExpression *> constant_map_; + absl::flat_hash_map<std::string, TemplateExpression*> constant_map_; // Named resource specifiers. - absl::btree_map<std::string, ResourceDetailsCtx *> resource_spec_map_; - absl::btree_map<std::string, IdentListCtx *> resource_array_ref_map_; + absl::btree_map<std::string, ResourceDetailsCtx*> resource_spec_map_; + absl::btree_map<std::string, IdentListCtx*> resource_array_ref_map_; // Default instruction attributes. - absl::btree_map<std::string, TemplateExpression *> attribute_map_; + absl::btree_map<std::string, TemplateExpression*> attribute_map_; }; } // namespace instruction_set
diff --git a/mpact/sim/decoder/template_expression.cc b/mpact/sim/decoder/template_expression.cc index 5b651d9..8d88e7c 100644 --- a/mpact/sim/decoder/template_expression.cc +++ b/mpact/sim/decoder/template_expression.cc
@@ -29,10 +29,10 @@ // nodes. If there is an error in the expression evaluation the error is // propagated to the top. static absl::StatusOr<TemplateValue> operator-( - const absl::StatusOr<TemplateValue> &lhs) { + const absl::StatusOr<TemplateValue>& lhs) { if (lhs.ok()) { auto variant_value = lhs.value(); - int *value_ptr = std::get_if<int>(&variant_value); + int* value_ptr = std::get_if<int>(&variant_value); if (value_ptr != nullptr) { return -*value_ptr; } else { @@ -46,16 +46,16 @@ // that is member of the TemplateValue variant. template <typename T> static absl::StatusOr<TemplateValue> OperatorHelper( - const absl::StatusOr<TemplateValue> &lhs, - const absl::StatusOr<TemplateValue> &rhs, + const absl::StatusOr<TemplateValue>& lhs, + const absl::StatusOr<TemplateValue>& rhs, std::function<absl::StatusOr<TemplateValue>(T, T)> func) { if (!lhs.ok()) return lhs.status(); if (!rhs.ok()) return rhs.status(); auto lhs_variant = lhs.value(); auto rhs_variant = rhs.value(); - int *lhs_value = std::get_if<T>(&lhs_variant); - int *rhs_value = std::get_if<T>(&rhs_variant); + int* lhs_value = std::get_if<T>(&lhs_variant); + int* rhs_value = std::get_if<T>(&rhs_variant); if (lhs_value == nullptr) return absl::InternalError("int type expected"); if (rhs_value == nullptr) return absl::InternalError("int type expected"); @@ -64,8 +64,8 @@ } static absl::StatusOr<TemplateValue> operator+( - const absl::StatusOr<TemplateValue> &lhs, - const absl::StatusOr<TemplateValue> &rhs) { + const absl::StatusOr<TemplateValue>& lhs, + const absl::StatusOr<TemplateValue>& rhs) { return OperatorHelper<int>( lhs, rhs, [](int lhs_value, int rhs_value) -> absl::StatusOr<TemplateValue> { @@ -74,8 +74,8 @@ } static absl::StatusOr<TemplateValue> operator-( - const absl::StatusOr<TemplateValue> &lhs, - const absl::StatusOr<TemplateValue> &rhs) { + const absl::StatusOr<TemplateValue>& lhs, + const absl::StatusOr<TemplateValue>& rhs) { return OperatorHelper<int>( lhs, rhs, [](int lhs_value, int rhs_value) -> absl::StatusOr<TemplateValue> { @@ -84,8 +84,8 @@ } static absl::StatusOr<TemplateValue> operator*( - const absl::StatusOr<TemplateValue> &lhs, - const absl::StatusOr<TemplateValue> &rhs) { + const absl::StatusOr<TemplateValue>& lhs, + const absl::StatusOr<TemplateValue>& rhs) { return OperatorHelper<int>( lhs, rhs, [](int lhs_value, int rhs_value) -> absl::StatusOr<TemplateValue> { @@ -94,8 +94,8 @@ } static absl::StatusOr<TemplateValue> operator/( - const absl::StatusOr<TemplateValue> &lhs, - const absl::StatusOr<TemplateValue> &rhs) { + const absl::StatusOr<TemplateValue>& lhs, + const absl::StatusOr<TemplateValue>& rhs) { return OperatorHelper<int>( lhs, rhs, [](int lhs_value, int rhs_value) -> absl::StatusOr<TemplateValue> { @@ -105,12 +105,12 @@ } // Evaluate of constant only returns a copy. -absl::StatusOr<TemplateExpression *> TemplateConstant::Evaluate( - TemplateInstantiationArgs *) { +absl::StatusOr<TemplateExpression*> TemplateConstant::Evaluate( + TemplateInstantiationArgs*) { return new TemplateConstant(value_); } -TemplateExpression *TemplateConstant::DeepCopy() const { +TemplateExpression* TemplateConstant::DeepCopy() const { return new TemplateConstant(value_); } @@ -120,12 +120,12 @@ return expr_->GetValue(); } -absl::StatusOr<TemplateExpression *> SlotConstant::Evaluate( - TemplateInstantiationArgs *args) { +absl::StatusOr<TemplateExpression*> SlotConstant::Evaluate( + TemplateInstantiationArgs* args) { return expr_->Evaluate(args); } -TemplateExpression *SlotConstant::DeepCopy() const { return expr_->DeepCopy(); } +TemplateExpression* SlotConstant::DeepCopy() const { return expr_->DeepCopy(); } // A template parameter has no value in the expression unless replaced by // the actual argument expression tree. @@ -134,8 +134,8 @@ } // Returns an evaluated copy of the corresponding argument expression tree. -absl::StatusOr<TemplateExpression *> TemplateParam::Evaluate( - TemplateInstantiationArgs *args) { +absl::StatusOr<TemplateExpression*> TemplateParam::Evaluate( + TemplateInstantiationArgs* args) { // No template arguments available, so just return the template parameter. if (args == nullptr) { return new TemplateParam(param_); @@ -143,7 +143,7 @@ if (param_->position() >= args->size()) { return absl::InternalError("Template parameter position out of range"); } - TemplateExpression *expr = (*args)[param_->position()]; + TemplateExpression* expr = (*args)[param_->position()]; if (expr->IsConstant()) { auto result = expr->GetValue(); if (result.ok()) return new TemplateConstant(result.value()); @@ -155,7 +155,7 @@ return (*args)[param_->position()]->Evaluate(nullptr); } -TemplateExpression *TemplateParam::DeepCopy() const { +TemplateExpression* TemplateParam::DeepCopy() const { return new TemplateParam(param_); } @@ -169,8 +169,8 @@ return -expr_->GetValue(); } -absl::StatusOr<TemplateExpression *> TemplateNegate::Evaluate( - TemplateInstantiationArgs *args) { +absl::StatusOr<TemplateExpression*> TemplateNegate::Evaluate( + TemplateInstantiationArgs* args) { auto expr = expr_->Evaluate(args); if (!expr.ok()) return expr.status(); // If expression is constant then can return a constant node. @@ -187,36 +187,36 @@ } } -TemplateExpression *TemplateNegate::DeepCopy() const { +TemplateExpression* TemplateNegate::DeepCopy() const { return new TemplateNegate(expr_->DeepCopy()); } absl::StatusOr<TemplateValue> TemplateMultiply::Operator( - const absl::StatusOr<TemplateValue> &lhs, - const absl::StatusOr<TemplateValue> &rhs) { + const absl::StatusOr<TemplateValue>& lhs, + const absl::StatusOr<TemplateValue>& rhs) { return lhs * rhs; } absl::StatusOr<TemplateValue> TemplateDivide::Operator( - const absl::StatusOr<TemplateValue> &lhs, - const absl::StatusOr<TemplateValue> &rhs) { + const absl::StatusOr<TemplateValue>& lhs, + const absl::StatusOr<TemplateValue>& rhs) { return lhs / rhs; } absl::StatusOr<TemplateValue> TemplateAdd::Operator( - const absl::StatusOr<TemplateValue> &lhs, - const absl::StatusOr<TemplateValue> &rhs) { + const absl::StatusOr<TemplateValue>& lhs, + const absl::StatusOr<TemplateValue>& rhs) { return lhs + rhs; } absl::StatusOr<TemplateValue> TemplateSubtract::Operator( - const absl::StatusOr<TemplateValue> &lhs, - const absl::StatusOr<TemplateValue> &rhs) { + const absl::StatusOr<TemplateValue>& lhs, + const absl::StatusOr<TemplateValue>& rhs) { return lhs - rhs; } TemplateFunction::~TemplateFunction() { - for (auto *arg : *args_) { + for (auto* arg : *args_) { delete arg; } delete args_; @@ -229,13 +229,13 @@ return absl::InternalError("Cannot evaluate function with unbound arguments"); } -absl::StatusOr<TemplateExpression *> TemplateFunction::Evaluate( - TemplateInstantiationArgs *args) { +absl::StatusOr<TemplateExpression*> TemplateFunction::Evaluate( + TemplateInstantiationArgs* args) { auto new_arguments = new TemplateInstantiationArgs; - for (auto *arg : *args_) { + for (auto* arg : *args_) { auto result = arg->Evaluate(args); if (!result.ok()) { - for (auto *tmp : *new_arguments) { + for (auto* tmp : *new_arguments) { delete tmp; } delete new_arguments; @@ -247,15 +247,15 @@ } bool TemplateFunction::IsConstant() const { - for (auto *arg : *args_) { + for (auto* arg : *args_) { if (!arg->IsConstant()) return false; } return true; } -TemplateExpression *TemplateFunction::DeepCopy() const { - auto *args = new TemplateInstantiationArgs; - for (auto *arg : *args_) { +TemplateExpression* TemplateFunction::DeepCopy() const { + auto* args = new TemplateInstantiationArgs; + for (auto* arg : *args_) { args->push_back(arg->DeepCopy()); } return new TemplateFunction(evaluator_, args);
diff --git a/mpact/sim/decoder/template_expression.h b/mpact/sim/decoder/template_expression.h index f9a604d..0ba9bc9 100644 --- a/mpact/sim/decoder/template_expression.h +++ b/mpact/sim/decoder/template_expression.h
@@ -46,7 +46,7 @@ TemplateFormal(std::string name, int position) : name_(std::move(name)), position_(position) {} - const std::string &name() const { return name_; } + const std::string& name() const { return name_; } size_t position() const { return position_; } private: @@ -59,7 +59,7 @@ // parameters. class TemplateExpression; -using TemplateInstantiationArgs = std::vector<TemplateExpression *>; +using TemplateInstantiationArgs = std::vector<TemplateExpression*>; // Virtual base class for template expressions. class TemplateExpression { @@ -74,11 +74,11 @@ // subexpressions are collapsed into constant nodes wherever possible. Note // that the argument expressions may themselves contain template parameters // for the "surrounding" template, so it may not resolve to a constant value. - virtual absl::StatusOr<TemplateExpression *> Evaluate( - TemplateInstantiationArgs *) = 0; + virtual absl::StatusOr<TemplateExpression*> Evaluate( + TemplateInstantiationArgs*) = 0; // Returns true if the expression can be evaluated to a constant. virtual bool IsConstant() const = 0; - virtual TemplateExpression *DeepCopy() const = 0; + virtual TemplateExpression* DeepCopy() const = 0; }; // Constant value expression node. @@ -87,10 +87,10 @@ explicit TemplateConstant(int val) : value_(val) {} explicit TemplateConstant(TemplateValue val) : value_(val) {} absl::StatusOr<TemplateValue> GetValue() const override { return value_; } - absl::StatusOr<TemplateExpression *> Evaluate( - TemplateInstantiationArgs *) override; + absl::StatusOr<TemplateExpression*> Evaluate( + TemplateInstantiationArgs*) override; bool IsConstant() const override { return true; } - TemplateExpression *DeepCopy() const override; + TemplateExpression* DeepCopy() const override; private: TemplateValue value_; @@ -102,11 +102,11 @@ template <typename T> class BinaryTemplateExpression : public TemplateExpression { public: - TemplateExpression *DeepCopy() const final { + TemplateExpression* DeepCopy() const final { return new T(lhs_->DeepCopy(), rhs_->DeepCopy()); } - absl::StatusOr<TemplateExpression *> Evaluate( - TemplateInstantiationArgs *args) final { + absl::StatusOr<TemplateExpression*> Evaluate( + TemplateInstantiationArgs* args) final { auto lhs = lhs_->Evaluate(args); if (!lhs.ok()) return lhs.status(); @@ -141,7 +141,7 @@ protected: BinaryTemplateExpression() = delete; - BinaryTemplateExpression(TemplateExpression *lhs, TemplateExpression *rhs) + BinaryTemplateExpression(TemplateExpression* lhs, TemplateExpression* rhs) : lhs_(lhs), rhs_(rhs) {} ~BinaryTemplateExpression() override { delete lhs_; @@ -151,111 +151,111 @@ } private: - TemplateExpression *lhs_; - TemplateExpression *rhs_; + TemplateExpression* lhs_; + TemplateExpression* rhs_; }; // Slot constant. class SlotConstant : public TemplateExpression { public: - explicit SlotConstant(TemplateExpression *expr) : expr_(expr) {} + explicit SlotConstant(TemplateExpression* expr) : expr_(expr) {} ~SlotConstant() override; absl::StatusOr<TemplateValue> GetValue() const override; - absl::StatusOr<TemplateExpression *> Evaluate( - TemplateInstantiationArgs *args) override; + absl::StatusOr<TemplateExpression*> Evaluate( + TemplateInstantiationArgs* args) override; bool IsConstant() const override { return expr_->IsConstant(); } - TemplateExpression *DeepCopy() const override; + TemplateExpression* DeepCopy() const override; private: - TemplateExpression *expr_ = nullptr; + TemplateExpression* expr_ = nullptr; }; // Template formal parameter reference expression node. class TemplateParam : public TemplateExpression { public: - explicit TemplateParam(TemplateFormal *param) : param_(param) {} + explicit TemplateParam(TemplateFormal* param) : param_(param) {} absl::StatusOr<TemplateValue> GetValue() const override; - absl::StatusOr<TemplateExpression *> Evaluate( - TemplateInstantiationArgs *args) override; + absl::StatusOr<TemplateExpression*> Evaluate( + TemplateInstantiationArgs* args) override; bool IsConstant() const override { return false; } - TemplateExpression *DeepCopy() const override; + TemplateExpression* DeepCopy() const override; private: - TemplateFormal *param_; + TemplateFormal* param_; }; // Negate expression node. class TemplateNegate : public TemplateExpression { public: - explicit TemplateNegate(TemplateExpression *expr) : expr_(expr) {} + explicit TemplateNegate(TemplateExpression* expr) : expr_(expr) {} ~TemplateNegate() override; absl::StatusOr<TemplateValue> GetValue() const override; - absl::StatusOr<TemplateExpression *> Evaluate( - TemplateInstantiationArgs *args) override; + absl::StatusOr<TemplateExpression*> Evaluate( + TemplateInstantiationArgs* args) override; bool IsConstant() const override { return expr_->IsConstant(); } - TemplateExpression *DeepCopy() const override; + TemplateExpression* DeepCopy() const override; private: - TemplateExpression *expr_; + TemplateExpression* expr_; }; // Multiply expression node. class TemplateMultiply : public BinaryTemplateExpression<TemplateMultiply> { public: - TemplateMultiply(TemplateExpression *lhs, TemplateExpression *rhs) + TemplateMultiply(TemplateExpression* lhs, TemplateExpression* rhs) : BinaryTemplateExpression(lhs, rhs) {} static absl::StatusOr<TemplateValue> Operator( - const absl::StatusOr<TemplateValue> &lhs, - const absl::StatusOr<TemplateValue> &rhs); + const absl::StatusOr<TemplateValue>& lhs, + const absl::StatusOr<TemplateValue>& rhs); }; // Divide expression node. class TemplateDivide : public BinaryTemplateExpression<TemplateDivide> { public: - TemplateDivide(TemplateExpression *lhs, TemplateExpression *rhs) + TemplateDivide(TemplateExpression* lhs, TemplateExpression* rhs) : BinaryTemplateExpression(lhs, rhs) {} static absl::StatusOr<TemplateValue> Operator( - const absl::StatusOr<TemplateValue> &lhs, - const absl::StatusOr<TemplateValue> &rhs); + const absl::StatusOr<TemplateValue>& lhs, + const absl::StatusOr<TemplateValue>& rhs); }; // Add expression node. class TemplateAdd : public BinaryTemplateExpression<TemplateAdd> { public: - TemplateAdd(TemplateExpression *lhs, TemplateExpression *rhs) + TemplateAdd(TemplateExpression* lhs, TemplateExpression* rhs) : BinaryTemplateExpression(lhs, rhs) {} static absl::StatusOr<TemplateValue> Operator( - const absl::StatusOr<TemplateValue> &lhs, - const absl::StatusOr<TemplateValue> &rhs); + const absl::StatusOr<TemplateValue>& lhs, + const absl::StatusOr<TemplateValue>& rhs); }; // Subtract expression node. class TemplateSubtract : public BinaryTemplateExpression<TemplateSubtract> { public: - TemplateSubtract(TemplateExpression *lhs, TemplateExpression *rhs) + TemplateSubtract(TemplateExpression* lhs, TemplateExpression* rhs) : BinaryTemplateExpression(lhs, rhs) {} static absl::StatusOr<TemplateValue> Operator( - const absl::StatusOr<TemplateValue> &lhs, - const absl::StatusOr<TemplateValue> &rhs); + const absl::StatusOr<TemplateValue>& lhs, + const absl::StatusOr<TemplateValue>& rhs); }; // Function expression node. class TemplateFunction : public TemplateExpression { public: using Evaluator = - std::function<absl::StatusOr<TemplateValue>(TemplateInstantiationArgs *)>; - TemplateFunction(Evaluator evaluator, TemplateInstantiationArgs *args) + std::function<absl::StatusOr<TemplateValue>(TemplateInstantiationArgs*)>; + TemplateFunction(Evaluator evaluator, TemplateInstantiationArgs* args) : evaluator_(std::move(evaluator)), args_(args) {} ~TemplateFunction() override; absl::StatusOr<TemplateValue> GetValue() const override; - absl::StatusOr<TemplateExpression *> Evaluate( - TemplateInstantiationArgs *args) override; + absl::StatusOr<TemplateExpression*> Evaluate( + TemplateInstantiationArgs* args) override; bool IsConstant() const override; - TemplateExpression *DeepCopy() const override; + TemplateExpression* DeepCopy() const override; private: Evaluator evaluator_; - TemplateInstantiationArgs *args_; + TemplateInstantiationArgs* args_; }; } // namespace instruction_set
diff --git a/mpact/sim/decoder/test/array_operand_test.cc b/mpact/sim/decoder/test/array_operand_test.cc index c0bdb3f..36dc54e 100644 --- a/mpact/sim/decoder/test/array_operand_test.cc +++ b/mpact/sim/decoder/test/array_operand_test.cc
@@ -61,7 +61,7 @@ } // Write instructions to memory - 16 each of pushes and pops. The first // 4 of each are illegal instructions since rlist < 4. - DataBuffer *db = state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* db = state_->db_factory()->Allocate<uint16_t>(1); for (int i = 0; i < 16; i++) { db->Set<uint16_t>(0, GeneratePushInstruction(i, i & 0x3)); memory_->Store(kBase + i * db->size<uint8_t>(), db); @@ -82,7 +82,7 @@ // Verify that the push instructions are decoded correctly. TEST_F(ArrayOperandTest, PushInstructionDecoding) { for (int i = 0; i < 16; i++) { - auto *inst = decoder_->DecodeInstruction(kBase + i * 2); + auto* inst = decoder_->DecodeInstruction(kBase + i * 2); CHECK_NE(inst, nullptr); if (i < 4) { EXPECT_EQ(inst->opcode(), *OpcodeEnum::kNone); @@ -96,7 +96,7 @@ // Verify that the pop instructions are decoded correctly. TEST_F(ArrayOperandTest, PopInstructionDecoding) { for (int i = 0; i < 16; i++) { - auto *inst = decoder_->DecodeInstruction(kBase + 16 * 2 + i * 2); + auto* inst = decoder_->DecodeInstruction(kBase + 16 * 2 + i * 2); CHECK_NE(inst, nullptr); if (i < 4) { EXPECT_EQ(inst->opcode(), *OpcodeEnum::kNone); @@ -111,7 +111,7 @@ // destination operands. TEST_F(ArrayOperandTest, PushOperands) { for (int i = 4; i < 16; i++) { - auto *inst = decoder_->DecodeInstruction(kBase + i * 2); + auto* inst = decoder_->DecodeInstruction(kBase + i * 2); CHECK_NE(inst, nullptr); EXPECT_EQ(inst->opcode(), *OpcodeEnum::kPush) << inst->AsString() << " for instruction " << i; @@ -130,7 +130,7 @@ // destination operands. TEST_F(ArrayOperandTest, PopOperands) { for (int i = 4; i < 16; i++) { - auto *inst = decoder_->DecodeInstruction(kBase + 16 * 2 + i * 2); + auto* inst = decoder_->DecodeInstruction(kBase + 16 * 2 + i * 2); CHECK_NE(inst, nullptr); EXPECT_EQ(inst->opcode(), *OpcodeEnum::kPop) << inst->AsString() << " for instruction " << i;
diff --git a/mpact/sim/decoder/test/bin_encoding_info_test.cc b/mpact/sim/decoder/test/bin_encoding_info_test.cc index 1cc5117..79c8f91 100644 --- a/mpact/sim/decoder/test/bin_encoding_info_test.cc +++ b/mpact/sim/decoder/test/bin_encoding_info_test.cc
@@ -19,7 +19,7 @@ constexpr char kIncludeFile0[] = "IncludeFile0"; constexpr char kIncludeFile1[] = "IncludeFile1"; constexpr char kIncludeFile2[] = "IncludeFile2"; -constexpr const char *kIncludeFiles[] = {kIncludeFile0, kIncludeFile1, +constexpr const char* kIncludeFiles[] = {kIncludeFile0, kIncludeFile1, kIncludeFile2}; constexpr char kFormat0[] = "Format0"; constexpr char kFormat1[] = "Format1"; @@ -40,8 +40,8 @@ delete error_listener_; } - DecoderErrorListener *error_listener_ = nullptr; - BinEncodingInfo *bin_encoding_info_ = nullptr; + DecoderErrorListener* error_listener_ = nullptr; + BinEncodingInfo* bin_encoding_info_ = nullptr; }; // Test for proper initialization of object. @@ -57,11 +57,11 @@ // Test that include files are properly added/kept. TEST_F(BinEncodingInfoTest, AddIncludeFile) { EXPECT_TRUE(bin_encoding_info_->include_files().empty()); - for (auto const &include_file : kIncludeFiles) { + for (auto const& include_file : kIncludeFiles) { bin_encoding_info_->AddIncludeFile(include_file); } EXPECT_FALSE(bin_encoding_info_->include_files().empty()); - for (auto const &include_file : kIncludeFiles) { + for (auto const& include_file : kIncludeFiles) { EXPECT_TRUE(bin_encoding_info_->include_files().contains(include_file)); } EXPECT_FALSE(bin_encoding_info_->include_files().contains("NoIncludeFile")); @@ -72,12 +72,12 @@ // Adding a new format should work. auto res0 = bin_encoding_info_->AddFormat(kFormat0, kFormatWidth32); EXPECT_TRUE(res0.status().ok()); - auto *format = res0.value(); + auto* format = res0.value(); EXPECT_EQ(format->name(), kFormat0); EXPECT_EQ(format->declared_width(), kFormatWidth32); // Make sure we get the format back when calling GetFormat. - auto *get_format = bin_encoding_info_->GetFormat(kFormat0); + auto* get_format = bin_encoding_info_->GetFormat(kFormat0); EXPECT_EQ(get_format, format); // Adding the same format again should fail. res0 = bin_encoding_info_->AddFormat(kFormat0, kFormatWidth32); @@ -102,7 +102,7 @@ EXPECT_EQ(absl::StatusCode::kAlreadyExists, res2.status().code()); // Format map. Verify that the formats are in the map. - auto &format_map = bin_encoding_info_->format_map(); + auto& format_map = bin_encoding_info_->format_map(); EXPECT_EQ(format_map.size(), 3); EXPECT_NE(format_map.find(kFormat0), format_map.end()); EXPECT_NE(format_map.find(kFormat1), format_map.end()); @@ -117,7 +117,7 @@ auto res = bin_encoding_info_->AddInstructionGroup(kGroup0, kFormatWidth32, kFormat0); EXPECT_TRUE(res.status().ok()); - auto *instruction_group = res.value(); + auto* instruction_group = res.value(); EXPECT_EQ(instruction_group->name(), kGroup0); EXPECT_EQ(instruction_group->width(), kFormatWidth32); EXPECT_EQ(instruction_group->format_name(), kFormat0); @@ -132,7 +132,7 @@ // Bin decoder. TEST_F(BinEncodingInfoTest, AddDecoder) { // Add BinDecoder. - auto *bin_dec = bin_encoding_info_->AddBinDecoder(kBinDecoder); + auto* bin_dec = bin_encoding_info_->AddBinDecoder(kBinDecoder); EXPECT_NE(bin_dec, nullptr); EXPECT_FALSE(error_listener_->HasError()); // Try adding it again.
diff --git a/mpact/sim/decoder/test/bin_format_visitor_test.cc b/mpact/sim/decoder/test/bin_format_visitor_test.cc index 4080b13..b1da3ed 100644 --- a/mpact/sim/decoder/test/bin_format_visitor_test.cc +++ b/mpact/sim/decoder/test/bin_format_visitor_test.cc
@@ -96,7 +96,7 @@ std::string OutputDir() { return "./"; } -static bool FileExists(const std::string &name) { +static bool FileExists(const std::string& name) { std::ifstream file(name); return file.good(); } @@ -591,7 +591,7 @@ // Verify that decoder entries use the different constraint types. std::string decoder_str((std::istreambuf_iterator<char>(decoder_file)), (std::istreambuf_iterator<char>())); - for (auto const &fragment : + for (auto const& fragment : {"field1_value != 0x1", "field2_value > 0x2", "field3_value >= 0x3", "field4_value < 0x4", "field5_value <= 0x5"}) { RE2 re(fragment);
diff --git a/mpact/sim/decoder/test/bundle_test.cc b/mpact/sim/decoder/test/bundle_test.cc index 6a9123c..723ace5 100644 --- a/mpact/sim/decoder/test/bundle_test.cc +++ b/mpact/sim/decoder/test/bundle_test.cc
@@ -34,12 +34,12 @@ constexpr char kSubBundleName0[] = "TestSubBundle0"; constexpr char kSubBundleName1[] = "TestSubBundle1"; constexpr char kSubBundleName2[] = "TestSubBundle2"; -const char *kSubBundleNames[3] = {kSubBundleName0, kSubBundleName1, +const char* kSubBundleNames[3] = {kSubBundleName0, kSubBundleName1, kSubBundleName2}; constexpr char kSlotName0[] = "TestSlot0"; constexpr char kSlotName1[] = "TestSlot1"; constexpr char kSlotName2[] = "TestSlot2"; -const char *kSlotNames[3] = {kSlotName0, kSlotName1, kSlotName2}; +const char* kSlotNames[3] = {kSlotName0, kSlotName1, kSlotName2}; class BundleTest : public testing::Test { protected:
diff --git a/mpact/sim/decoder/test/extract_bits_test.cc b/mpact/sim/decoder/test/extract_bits_test.cc index 2e5beaa..d26f6a9 100644 --- a/mpact/sim/decoder/test/extract_bits_test.cc +++ b/mpact/sim/decoder/test/extract_bits_test.cc
@@ -16,7 +16,7 @@ #include <ios> #include "absl/numeric/bits.h" -#include "googlemock/include/gmock/gmock.h" +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" namespace { @@ -26,7 +26,7 @@ // out to a source file as part of a code generator, so it is not included. template <typename T> -static inline T ExtractBits(const uint8_t *data, int data_size, int msb, +static inline T ExtractBits(const uint8_t* data, int data_size, int msb, int width) { if (width == 0) return 0;
diff --git a/mpact/sim/decoder/test/format_test.cc b/mpact/sim/decoder/test/format_test.cc index cfb322d..986e258 100644 --- a/mpact/sim/decoder/test/format_test.cc +++ b/mpact/sim/decoder/test/format_test.cc
@@ -15,7 +15,7 @@ #include "mpact/sim/decoder/format.h" #include "absl/status/status.h" -#include "googlemock/include/gmock/gmock.h" +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" #include "mpact/sim/decoder/bin_encoding_info.h" #include "mpact/sim/decoder/decoder_error_listener.h" @@ -52,12 +52,12 @@ delete encoding_info_; } - DecoderErrorListener *error_listener_; - BinEncodingInfo *encoding_info_; + DecoderErrorListener* error_listener_; + BinEncodingInfo* encoding_info_; }; TEST_F(FormatTest, Constructor) { - auto *format = new Format("format_name", 16, encoding_info_); + auto* format = new Format("format_name", 16, encoding_info_); EXPECT_EQ(format->name(), "format_name"); EXPECT_EQ(format->declared_width(), 16); EXPECT_EQ(format->computed_width(), 0); @@ -77,7 +77,7 @@ } TEST_F(FormatTest, AddFields) { - auto *format = new Format("format", 16, encoding_info_); + auto* format = new Format("format", 16, encoding_info_); ASSERT_TRUE(format->AddField("func3", /*is_signed=*/false, 3).ok()); ASSERT_TRUE(format->AddField("imm3", /*is_signed=*/false, 3).ok()); ASSERT_TRUE(format->AddField("rs1p", /*is_signed=*/false, 3).ok()); @@ -86,8 +86,8 @@ ASSERT_TRUE(format->AddField("op", /*is_signed=*/false, 2).ok()); ASSERT_TRUE(format->ComputeAndCheckFormatWidth().ok()); EXPECT_EQ(format->declared_width(), format->computed_width()); - for (auto &name : {"func3", "imm3", "rs1p", "imm2", "rdp", "op"}) { - auto *field = format->GetField(name); + for (auto& name : {"func3", "imm3", "rs1p", "imm2", "rdp", "op"}) { + auto* field = format->GetField(name); ASSERT_NE(field, nullptr); EXPECT_EQ(field->name, name); } @@ -96,7 +96,7 @@ } TEST_F(FormatTest, AddOverlay) { - auto *format = new Format("format", 16, encoding_info_); + auto* format = new Format("format", 16, encoding_info_); ASSERT_TRUE(format->AddField("func3", /*is_signed=*/false, 3).ok()); ASSERT_TRUE(format->AddField("imm3", /*is_signed=*/false, 3).ok()); ASSERT_TRUE(format->AddField("rs1p", /*is_signed=*/false, 3).ok());
diff --git a/mpact/sim/decoder/test/instruction_encoding_test.cc b/mpact/sim/decoder/test/instruction_encoding_test.cc index 21e1a59..42d935c 100644 --- a/mpact/sim/decoder/test/instruction_encoding_test.cc +++ b/mpact/sim/decoder/test/instruction_encoding_test.cc
@@ -17,7 +17,7 @@ #include <string> #include "absl/status/status.h" -#include "googlemock/include/gmock/gmock.h" +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" #include "mpact/sim/decoder/bin_encoding_info.h" #include "mpact/sim/decoder/bin_format_visitor.h" @@ -52,7 +52,7 @@ (void)i_type_fmt_->AddField("rd", /*is_signed*/ false, 5); (void)i_type_fmt_->AddField("opcode", /*is_signed*/ false, 7); (void)i_type_fmt_->AddFieldOverlay("uspecial", /*is_signed*/ false, 10); - auto *overlay = i_type_fmt_->GetOverlay("uspecial"); + auto* overlay = i_type_fmt_->GetOverlay("uspecial"); (void)overlay->AddFieldReference("rs1"); (void)overlay->AddFieldReference("rd"); (void)i_type_fmt_->AddFieldOverlay("sspecial", /*is_signed*/ true, 10); @@ -75,10 +75,10 @@ delete i_type_; } - DecoderErrorListener *error_listener_; - BinEncodingInfo *encoding_info_; - Format *i_type_fmt_; - InstructionEncoding *i_type_; + DecoderErrorListener* error_listener_; + BinEncodingInfo* encoding_info_; + Format* i_type_fmt_; + InstructionEncoding* i_type_; }; TEST_F(InstructionEncodingTest, Basic) { @@ -191,7 +191,7 @@ EXPECT_EQ(i_type_->GetMask(), kFunc3Mask); EXPECT_EQ(i_type_->GetCombinedMask(), kFunc3Mask); EXPECT_EQ(i_type_->equal_constraints().size(), 1); - auto *constraint = i_type_->equal_constraints()[0]; + auto* constraint = i_type_->equal_constraints()[0]; EXPECT_EQ(constraint->type, ConstraintType::kEq); EXPECT_EQ(constraint->field, i_type_fmt_->GetField("func3")); EXPECT_EQ(constraint->value, kFunc3Value); @@ -210,7 +210,7 @@ EXPECT_EQ(i_type_->GetMask(), 0); EXPECT_EQ(i_type_->GetCombinedMask(), 0); EXPECT_EQ(i_type_->equal_extracted_constraints().size(), 1); - auto *constraint = i_type_->equal_extracted_constraints()[0]; + auto* constraint = i_type_->equal_extracted_constraints()[0]; EXPECT_EQ(constraint->type, ConstraintType::kEq); EXPECT_EQ(constraint->field, i_type_fmt_->GetField("extract")); EXPECT_EQ(constraint->value, 0b11011'11'00100); @@ -226,7 +226,7 @@ EXPECT_EQ(i_type_->GetMask(), 0); EXPECT_EQ(i_type_->GetCombinedMask(), kFunc3Mask); EXPECT_EQ(i_type_->other_constraints().size(), 1); - auto *constraint = i_type_->other_constraints()[0]; + auto* constraint = i_type_->other_constraints()[0]; EXPECT_EQ(constraint->type, ConstraintType::kGe); EXPECT_EQ(constraint->field, i_type_fmt_->GetField("func3")); EXPECT_EQ(constraint->value, kFunc3Value);
diff --git a/mpact/sim/decoder/test/instruction_set_test.cc b/mpact/sim/decoder/test/instruction_set_test.cc index 1d70b48..4df5175 100644 --- a/mpact/sim/decoder/test/instruction_set_test.cc +++ b/mpact/sim/decoder/test/instruction_set_test.cc
@@ -45,7 +45,7 @@ TEST_F(InstructionSetTest, Basic) { EXPECT_STREQ(instruction_set_->name().c_str(), kInstructionSetName); EXPECT_EQ(nullptr, instruction_set_->bundle()); - Bundle *bundle = new Bundle(kBundleName, instruction_set_.get(), nullptr); + Bundle* bundle = new Bundle(kBundleName, instruction_set_.get(), nullptr); instruction_set_->set_bundle(bundle); EXPECT_EQ(instruction_set_->bundle(), bundle); } @@ -54,7 +54,7 @@ // name. TEST_F(InstructionSetTest, SingleBundle) { EXPECT_EQ(nullptr, instruction_set_->GetBundle(kBundleName)); - Bundle *bundle = new Bundle(kBundleName, instruction_set_.get(), nullptr); + Bundle* bundle = new Bundle(kBundleName, instruction_set_.get(), nullptr); instruction_set_->AddBundle(bundle); EXPECT_EQ(bundle, instruction_set_->GetBundle(kBundleName)); EXPECT_EQ(nullptr, instruction_set_->GetBundle(kSlotName)); @@ -65,7 +65,7 @@ // name. TEST_F(InstructionSetTest, SingleSlot) { EXPECT_EQ(nullptr, instruction_set_->GetSlot(kSlotName)); - Slot *slot = new Slot(kSlotName, instruction_set_.get(), + Slot* slot = new Slot(kSlotName, instruction_set_.get(), /* is_templated */ false, nullptr); instruction_set_->AddSlot(slot); EXPECT_EQ(slot, instruction_set_->GetSlot(kSlotName));
diff --git a/mpact/sim/decoder/test/instruction_set_visitor_test.cc b/mpact/sim/decoder/test/instruction_set_visitor_test.cc index 6e0342f..d7c338d 100644 --- a/mpact/sim/decoder/test/instruction_set_visitor_test.cc +++ b/mpact/sim/decoder/test/instruction_set_visitor_test.cc
@@ -83,7 +83,7 @@ std::string OutputDir() { return "./"; } -static bool FileExists(const std::string &name) { +static bool FileExists(const std::string& name) { std::ifstream file(name); return file.good(); } @@ -576,7 +576,7 @@ std::string opcodes; RE2 opcodes_re("(?msU:\\s*OpcodeEnum[\\s\\n]*\\{([^\\}]*)\\})"); EXPECT_TRUE(RE2::PartialMatch(enum_str, opcodes_re, &opcodes)); - for (auto &name : {"kInst0", "kInst1"}) { + for (auto& name : {"kInst0", "kInst1"}) { RE2 re(name); EXPECT_TRUE(RE2::PartialMatch(opcodes, re)) << name; EXPECT_TRUE(RE2::PartialMatch(decoder_str, re)) << name;
diff --git a/mpact/sim/decoder/test/log_sink.h b/mpact/sim/decoder/test/log_sink.h index c148dce..0fabecc 100644 --- a/mpact/sim/decoder/test/log_sink.h +++ b/mpact/sim/decoder/test/log_sink.h
@@ -18,7 +18,7 @@ LogSink() = default; ~LogSink() override = default; // Method called for each log message. - void Send(const absl::LogEntry &entry) override { + void Send(const absl::LogEntry& entry) override { switch (entry.log_severity()) { case absl::LogSeverity::kInfo: absl::StrAppend(&info_log_, entry.text_message());
diff --git a/mpact/sim/decoder/test/opcode_test.cc b/mpact/sim/decoder/test/opcode_test.cc index 8dba3f0..d8884e0 100644 --- a/mpact/sim/decoder/test/opcode_test.cc +++ b/mpact/sim/decoder/test/opcode_test.cc
@@ -36,7 +36,7 @@ constexpr char kOpcodeName2[] = "opcode_2"; constexpr char kPredicateOpName[] = "pred"; -const char *kOpcodeNames[] = {kOpcodeName0, kOpcodeName1, kOpcodeName2}; +const char* kOpcodeNames[] = {kOpcodeName0, kOpcodeName1, kOpcodeName2}; // Test fixture for opcode test. class OpcodeTest : public testing::Test { @@ -44,7 +44,7 @@ OpcodeTest() { instruction_set_ = std::make_unique<InstructionSet>(kInstructionSetName); - absl::StatusOr<Opcode *> result = + absl::StatusOr<Opcode*> result = instruction_set_->opcode_factory()->CreateOpcode(kOpcodeName0); opcode_ = result.ok() ? result.value() : nullptr; } @@ -52,7 +52,7 @@ ~OpcodeTest() override { delete opcode_; } std::unique_ptr<InstructionSet> instruction_set_; - Opcode *opcode_; // Does not have to be deleted, as OpcodeFactory handles it. + Opcode* opcode_; // Does not have to be deleted, as OpcodeFactory handles it. }; TEST_F(OpcodeTest, Basic) { @@ -66,7 +66,7 @@ // Verify that values of opcodes increment as you create new ones. TEST_F(OpcodeTest, Multiple) { // Creating a duplicate opcode should fail. - absl::StatusOr<Opcode *> result = + absl::StatusOr<Opcode*> result = instruction_set_->opcode_factory()->CreateOpcode(kOpcodeNames[0]); EXPECT_TRUE(absl::IsInternal(result.status())); for (int indx = 1; indx < 3; indx++) { @@ -74,7 +74,7 @@ instruction_set_->opcode_factory()->CreateOpcode(kOpcodeNames[indx]); // Since one opcode is created in fixture, these opcode values start at 2. ASSERT_TRUE(result.ok()); - Opcode *opcode = result.value(); + Opcode* opcode = result.value(); EXPECT_EQ(opcode->value(), indx + 1); delete opcode; }
diff --git a/mpact/sim/decoder/test/overlay_test.cc b/mpact/sim/decoder/test/overlay_test.cc index 565307f..ec19de8 100644 --- a/mpact/sim/decoder/test/overlay_test.cc +++ b/mpact/sim/decoder/test/overlay_test.cc
@@ -70,12 +70,12 @@ ~OverlayTest() override { delete format_; } - Format *format_; + Format* format_; }; // Test construction and initial state of an overlay. TEST_F(OverlayTest, Constructor) { - auto *overlay = + auto* overlay = new Overlay(kOverlayName, /*is_signed=*/false, kOverlayWidth, format_); EXPECT_EQ(overlay->name(), kOverlayName); EXPECT_FALSE(overlay->is_signed()); @@ -89,7 +89,7 @@ // Add a full field reference. TEST_F(OverlayTest, AddFieldReference) { - auto *overlay = + auto* overlay = new Overlay(kOverlayName, /*is_signed=*/false, kOverlayWidth, format_); // Fail to add a reference to an unknown field. EXPECT_EQ(overlay->AddFieldReference("immXYZ").code(), @@ -105,7 +105,7 @@ // Add a field range reference. TEST_F(OverlayTest, AddFieldRangeReference) { - auto *overlay = + auto* overlay = new Overlay(kOverlayName, /*is_signed=*/false, kOverlayWidth, format_); // Fail to add a reference to an unknown field. EXPECT_EQ( @@ -143,7 +143,7 @@ // Add a format range reference. TEST_F(OverlayTest, AddFormatReference) { - auto *overlay = + auto* overlay = new Overlay(kOverlayName, /*is_signed=*/false, kOverlayWidth, format_); // Fail to add a reference to an unknown field. EXPECT_EQ(overlay->AddFormatReference(std::vector<BitRange>{BitRange{18, 16}}) @@ -169,7 +169,7 @@ // Add a bit constant. TEST_F(OverlayTest, AddBitConstant) { - auto *overlay = + auto* overlay = new Overlay(kOverlayName, /*is_signed=*/false, kOverlayWidth, format_); overlay->AddBitConstant(BinaryNum{0b00, 2}); ASSERT_TRUE(overlay->ComputeHighLow().ok()); @@ -182,7 +182,7 @@ // Full overlay test with value extraction. TEST_F(OverlayTest, FullOverlay) { - auto *overlay = + auto* overlay = new Overlay(kOverlayName, /*is_signed=*/false, kOverlayWidth, format_); ASSERT_TRUE( overlay @@ -210,7 +210,7 @@ // Extraction code. TEST_F(OverlayTest, WriteSimpleExtractor) { - auto *overlay = + auto* overlay = new Overlay(kOverlayName, /*is_signed=*/false, kOverlayWidth, format_); ASSERT_TRUE( overlay @@ -236,7 +236,7 @@ } TEST_F(OverlayTest, WriteComplexExtractor) { - auto *overlay = + auto* overlay = new Overlay(kOverlayName, /*is_signed=*/false, kOverlayWidth, format_); overlay->AddBitConstant(BinaryNum{0b11, 2}); ASSERT_TRUE(
diff --git a/mpact/sim/decoder/test/proto_constraint_expression_test.cc b/mpact/sim/decoder/test/proto_constraint_expression_test.cc index f6454ed..65b7951 100644 --- a/mpact/sim/decoder/test/proto_constraint_expression_test.cc +++ b/mpact/sim/decoder/test/proto_constraint_expression_test.cc
@@ -31,8 +31,8 @@ : public google::protobuf::compiler::MultiFileErrorCollector { public: MultiFileErrorCollector() {} - MultiFileErrorCollector(const MultiFileErrorCollector &) = delete; - MultiFileErrorCollector &operator=(const MultiFileErrorCollector &) = delete; + MultiFileErrorCollector(const MultiFileErrorCollector&) = delete; + MultiFileErrorCollector& operator=(const MultiFileErrorCollector&) = delete; void RecordError(absl::string_view filename, int line, int column, absl::string_view message) override { @@ -41,7 +41,7 @@ absl::StrAppend(&error_, "Line ", line, " Column ", column, ": ", message, "\n"); } - const std::string &GetError() const { return error_; } + const std::string& GetError() const { return error_; } private: std::string error_; @@ -79,12 +79,12 @@ google::protobuf::compiler::DiskSourceTree source_tree; source_tree.MapPath("", ""); google::protobuf::compiler::Importer importer(&source_tree, &error_collector); - auto const *isa_descriptor = importer.Import(kIsaProto); + auto const* isa_descriptor = importer.Import(kIsaProto); CHECK_NE(isa_descriptor, nullptr); - auto const *pool = importer.pool(); + auto const* pool = importer.pool(); CHECK_NE(pool, nullptr); // Get the enum value descriptor. - auto const *enum_value_desc = + auto const* enum_value_desc = pool->FindEnumValueByName("mpact_sim.decoder.test.OPCODE_ADD"); CHECK_NE(enum_value_desc, nullptr); int enum_value = enum_value_desc->number(); @@ -100,7 +100,7 @@ // Verify that the type is as expected. EXPECT_EQ(expr_value.index(), *ProtoValueIndex::kInt32); // Get the typed value. - auto const *value = std::get_if<int32_t>(&expr_value); + auto const* value = std::get_if<int32_t>(&expr_value); CHECK_NE(value, nullptr); // Match the value against that obtained from the enum value descriptor. EXPECT_EQ(*value, enum_value); @@ -159,7 +159,7 @@ // Test the negate expression. TEST_F(ProtoConstraintExpressionTest, NegateExpression) { // int32_t - auto *val_expr = + auto* val_expr = new ProtoConstraintValueExpression(ProtoValue(static_cast<int32_t>(-1))); ProtoConstraintNegateExpression neg_expr(val_expr); EXPECT_EQ(CppType<int32_t>::value, neg_expr.cpp_type()); @@ -194,7 +194,7 @@ TEST_F(ProtoConstraintExpressionTest, CloneValueExpr) { ProtoConstraintValueExpression expr(ProtoValue(static_cast<int32_t>(-1))); - auto *clone = expr.Clone(); + auto* clone = expr.Clone(); EXPECT_NE(clone, nullptr); EXPECT_EQ(clone->cpp_type(), expr.cpp_type()); EXPECT_EQ(clone->GetValueAs<int32_t>(), -1); @@ -207,18 +207,18 @@ google::protobuf::compiler::DiskSourceTree source_tree; source_tree.MapPath("", ""); google::protobuf::compiler::Importer importer(&source_tree, &error_collector); - auto const *isa_descriptor = importer.Import(kIsaProto); + auto const* isa_descriptor = importer.Import(kIsaProto); CHECK_NE(isa_descriptor, nullptr); - auto const *pool = importer.pool(); + auto const* pool = importer.pool(); CHECK_NE(pool, nullptr); // Get the enum value descriptor. - auto const *enum_value_desc = + auto const* enum_value_desc = pool->FindEnumValueByName("mpact_sim.decoder.test.OPCODE_ADD"); CHECK_NE(enum_value_desc, nullptr); int enum_value = enum_value_desc->number(); // Create a constraint enum expression using the enum value descriptor. ProtoConstraintEnumExpression enum_expr(enum_value_desc); - auto *clone = enum_expr.Clone(); + auto* clone = enum_expr.Clone(); EXPECT_NE(clone, nullptr); EXPECT_EQ(clone->cpp_type(), enum_expr.cpp_type()); EXPECT_EQ(clone->GetValueAs<int32_t>(), enum_value); @@ -227,10 +227,10 @@ TEST_F(ProtoConstraintExpressionTest, CloneNegateExpr) { // int32_t - auto *val_expr = + auto* val_expr = new ProtoConstraintValueExpression(ProtoValue(static_cast<int32_t>(-1))); ProtoConstraintNegateExpression neg_expr(val_expr); - auto *clone = neg_expr.Clone(); + auto* clone = neg_expr.Clone(); EXPECT_NE(clone, nullptr); EXPECT_EQ(clone->cpp_type(), neg_expr.cpp_type()); EXPECT_EQ(clone->GetValueAs<int32_t>(), neg_expr.GetValueAs<int32_t>());
diff --git a/mpact/sim/decoder/test/proto_format_visitor_test.cc b/mpact/sim/decoder/test/proto_format_visitor_test.cc index 03ced68..3cd40f0 100644 --- a/mpact/sim/decoder/test/proto_format_visitor_test.cc +++ b/mpact/sim/decoder/test/proto_format_visitor_test.cc
@@ -42,7 +42,7 @@ // The depot path to the test directory. constexpr char kDepotPath[] = "mpact/sim/decoder/test"; -static bool FileExists(const std::string &name) { +static bool FileExists(const std::string& name) { std::ifstream file(name); return file.good(); }
diff --git a/mpact/sim/decoder/test/push_pop.cc b/mpact/sim/decoder/test/push_pop.cc index b7ac9f7..824779c 100644 --- a/mpact/sim/decoder/test/push_pop.cc +++ b/mpact/sim/decoder/test/push_pop.cc
@@ -23,9 +23,9 @@ using ::mpact::sim::generic::Instruction; -void Illegal(const Instruction *inst) { /*empty*/ } -void Push(const Instruction *inst) { /*empty*/ } -void Pop(const Instruction *inst) { /*empty*/ } +void Illegal(const Instruction* inst) { /*empty*/ } +void Push(const Instruction* inst) { /*empty*/ } +void Pop(const Instruction* inst) { /*empty*/ } } // namespace test } // namespace decoder
diff --git a/mpact/sim/decoder/test/push_pop.h b/mpact/sim/decoder/test/push_pop.h index 01523d1..0bd48b5 100644 --- a/mpact/sim/decoder/test/push_pop.h +++ b/mpact/sim/decoder/test/push_pop.h
@@ -24,9 +24,9 @@ using ::mpact::sim::generic::Instruction; -void Illegal(const Instruction *inst); -void Push(const Instruction *inst); -void Pop(const Instruction *inst); +void Illegal(const Instruction* inst); +void Push(const Instruction* inst); +void Pop(const Instruction* inst); } // namespace test } // namespace decoder
diff --git a/mpact/sim/decoder/test/push_pop_decoder.cc b/mpact/sim/decoder/test/push_pop_decoder.cc index d2b3596..356d61c 100644 --- a/mpact/sim/decoder/test/push_pop_decoder.cc +++ b/mpact/sim/decoder/test/push_pop_decoder.cc
@@ -29,7 +29,7 @@ using ::mpact::sim::generic::Instruction; using ::mpact::sim::util::MemoryInterface; -PushPopDecoder::PushPopDecoder(ArchState *state, MemoryInterface *memory) +PushPopDecoder::PushPopDecoder(ArchState* state, MemoryInterface* memory) : state_(state), memory_(memory) { push_pop_isa_factory_ = new PushPopIsaFactory(); push_pop_isa_ = new PushPopInstInstructionSet(state, push_pop_isa_factory_); @@ -44,11 +44,11 @@ delete push_pop_isa_factory_; } -Instruction *PushPopDecoder::DecodeInstruction(uint64_t address) { +Instruction* PushPopDecoder::DecodeInstruction(uint64_t address) { memory_->Load(address, inst_db_, nullptr, nullptr); uint16_t iword = inst_db_->Get<uint16_t>(0); push_pop_encoding_->ParseInstruction(iword); - auto *instruction = push_pop_isa_->Decode(address, push_pop_encoding_); + auto* instruction = push_pop_isa_->Decode(address, push_pop_encoding_); instruction->set_opcode( *push_pop_encoding_->GetOpcode(SlotEnum::kPushPopInst, 0)); return instruction;
diff --git a/mpact/sim/decoder/test/push_pop_decoder.h b/mpact/sim/decoder/test/push_pop_decoder.h index 821d362..ca0c2f1 100644 --- a/mpact/sim/decoder/test/push_pop_decoder.h +++ b/mpact/sim/decoder/test/push_pop_decoder.h
@@ -40,32 +40,32 @@ class PushPopIsaFactory : public PushPopInstInstructionSetFactory { public: std::unique_ptr<PushPopInstSlot> CreatePushPopInstSlot( - ArchState *state) override { + ArchState* state) override { return std::make_unique<PushPopInstSlot>(state); } }; class PushPopDecoder : public generic::DecoderInterface { public: - PushPopDecoder(ArchState *state, MemoryInterface *memory); + PushPopDecoder(ArchState* state, MemoryInterface* memory); PushPopDecoder() = delete; ~PushPopDecoder() override; - generic::Instruction *DecodeInstruction(uint64_t address) override; + generic::Instruction* DecodeInstruction(uint64_t address) override; int GetNumOpcodes() const override { return *OpcodeEnum::kPastMaxValue; } - const char *GetOpcodeName(int index) const override { + const char* GetOpcodeName(int index) const override { return kOpcodeNames[index]; } - PushPopEncoding *push_pop_encoding() const { return push_pop_encoding_; } + PushPopEncoding* push_pop_encoding() const { return push_pop_encoding_; } private: - ArchState *state_; - MemoryInterface *memory_; - PushPopEncoding *push_pop_encoding_; - PushPopIsaFactory *push_pop_isa_factory_; - PushPopInstInstructionSet *push_pop_isa_; - DataBuffer *inst_db_; + ArchState* state_; + MemoryInterface* memory_; + PushPopEncoding* push_pop_encoding_; + PushPopIsaFactory* push_pop_isa_factory_; + PushPopInstInstructionSet* push_pop_isa_; + DataBuffer* inst_db_; }; } // namespace mpact::sim::decoder::test
diff --git a/mpact/sim/decoder/test/push_pop_encoding.cc b/mpact/sim/decoder/test/push_pop_encoding.cc index 142df85..eb58b2c 100644 --- a/mpact/sim/decoder/test/push_pop_encoding.cc +++ b/mpact/sim/decoder/test/push_pop_encoding.cc
@@ -37,69 +37,69 @@ using TestRegister = ::mpact::sim::generic::Register<uint32_t>; template <typename RegType> -inline RegType *GetRegister(ArchState *state, std::string name) { +inline RegType* GetRegister(ArchState* state, std::string name) { auto iter = state->registers()->find(name); if (iter == state->registers()->end()) { return nullptr; } - return static_cast<RegType *>(iter->second); + return static_cast<RegType*>(iter->second); } // Generic helper functions to create register operands. template <typename RegType> -inline DestinationOperandInterface *GetRegisterDestinationOp(ArchState *state, +inline DestinationOperandInterface* GetRegisterDestinationOp(ArchState* state, std::string name, int latency) { - auto *reg = GetRegister<RegType>(state, name); + auto* reg = GetRegister<RegType>(state, name); return reg->CreateDestinationOperand(latency); } template <typename RegType> -inline DestinationOperandInterface *GetRegisterDestinationOp( - ArchState *state, std::string name, int latency, std::string op_name) { - auto *reg = GetRegister<RegType>(state, name); +inline DestinationOperandInterface* GetRegisterDestinationOp( + ArchState* state, std::string name, int latency, std::string op_name) { + auto* reg = GetRegister<RegType>(state, name); return reg->CreateDestinationOperand(latency, op_name); } template <typename RegType> -inline SourceOperandInterface *GetRegisterSourceOp(ArchState *state, +inline SourceOperandInterface* GetRegisterSourceOp(ArchState* state, std::string name) { - auto *reg = GetRegister<RegType>(state, name); - auto *op = reg->CreateSourceOperand(); + auto* reg = GetRegister<RegType>(state, name); + auto* op = reg->CreateSourceOperand(); return op; } template <typename RegType> -inline SourceOperandInterface *GetRegisterSourceOp(ArchState *state, +inline SourceOperandInterface* GetRegisterSourceOp(ArchState* state, std::string name, std::string op_name) { - auto *reg = GetRegister<RegType>(state, name); - auto *op = reg->CreateSourceOperand(op_name); + auto* reg = GetRegister<RegType>(state, name); + auto* op = reg->CreateSourceOperand(op_name); return op; } -PushPopEncoding::PushPopEncoding(ArchState *state) : state_(state) { +PushPopEncoding::PushPopEncoding(ArchState* state) : state_(state) { source_op_getters_.insert(std::make_pair( - *SourceOpEnum::kRlist, [this]() -> SourceOperandInterface * { + *SourceOpEnum::kRlist, [this]() -> SourceOperandInterface* { return new generic::ImmediateOperand<uint32_t>( p_type::ExtractRlist(inst_word_)); })); source_op_getters_.insert(std::make_pair( - *SourceOpEnum::kSpimm6, [this]() -> SourceOperandInterface * { + *SourceOpEnum::kSpimm6, [this]() -> SourceOperandInterface* { return new generic::ImmediateOperand<uint32_t>( p_type::ExtractSpimm6(inst_word_)); })); source_op_getters_.insert( - std::make_pair(*SourceOpEnum::kX2, [this]() -> SourceOperandInterface * { + std::make_pair(*SourceOpEnum::kX2, [this]() -> SourceOperandInterface* { return GetRegisterSourceOp<TestRegister>(state_, "x2"); })); list_source_op_getters_.insert(std::make_pair( *ListSourceOpEnum::kRlist, - [this]() -> std::vector<SourceOperandInterface *> { - std::vector<SourceOperandInterface *> result; + [this]() -> std::vector<SourceOperandInterface*> { + std::vector<SourceOperandInterface*> result; auto rlist = p_type::ExtractRlist(inst_word_); // Get the value of 'rlist', and add source operands accordingly. if (rlist < 4) return result; @@ -131,15 +131,15 @@ })); dest_op_getters_.insert(std::make_pair( - *DestOpEnum::kX2, [this](int latency) -> DestinationOperandInterface * { + *DestOpEnum::kX2, [this](int latency) -> DestinationOperandInterface* { return GetRegisterDestinationOp<TestRegister>(state_, "x2", latency); })); list_dest_op_getters_.insert( std::make_pair(*ListDestOpEnum::kRlist, - [this](const std::vector<int> &latency) - -> std::vector<DestinationOperandInterface *> { - std::vector<DestinationOperandInterface *> result; + [this](const std::vector<int>& latency) + -> std::vector<DestinationOperandInterface*> { + std::vector<DestinationOperandInterface*> result; // Get the value of 'rlist', and add destination operands // accordingly. auto rlist = p_type::ExtractRlist(inst_word_); @@ -191,7 +191,7 @@ opcode_ = DecodePushPop(inst_word_); } -SourceOperandInterface *PushPopEncoding::GetSource(SlotEnum, int, OpcodeEnum, +SourceOperandInterface* PushPopEncoding::GetSource(SlotEnum, int, OpcodeEnum, SourceOpEnum op, int source_no) { auto iter = source_op_getters_.find(*op); @@ -201,7 +201,7 @@ return iter->second(); } -std::vector<SourceOperandInterface *> PushPopEncoding::GetSources( +std::vector<SourceOperandInterface*> PushPopEncoding::GetSources( SlotEnum, int, OpcodeEnum, ListSourceOpEnum op, int source_no) { auto iter = list_source_op_getters_.find(*op); if (iter == list_source_op_getters_.end()) { @@ -210,7 +210,7 @@ return iter->second(); } -DestinationOperandInterface *PushPopEncoding::GetDestination( +DestinationOperandInterface* PushPopEncoding::GetDestination( SlotEnum, int, OpcodeEnum, DestOpEnum op, int dest_no, int latency) { auto iter = dest_op_getters_.find(*op); if (iter == dest_op_getters_.end()) { @@ -219,9 +219,9 @@ return iter->second(latency); } -std::vector<DestinationOperandInterface *> PushPopEncoding::GetDestinations( +std::vector<DestinationOperandInterface*> PushPopEncoding::GetDestinations( SlotEnum, int, OpcodeEnum, ListDestOpEnum op, int dest_no, - const std::vector<int> &latency) { + const std::vector<int>& latency) { auto iter = list_dest_op_getters_.find(*op); if (iter == list_dest_op_getters_.end()) { return {};
diff --git a/mpact/sim/decoder/test/push_pop_encoding.h b/mpact/sim/decoder/test/push_pop_encoding.h index 4dec95e..02a93ce 100644 --- a/mpact/sim/decoder/test/push_pop_encoding.h +++ b/mpact/sim/decoder/test/push_pop_encoding.h
@@ -34,7 +34,7 @@ class PushPopEncoding : public PushPopInstEncodingBase { public: - explicit PushPopEncoding(ArchState *state); + explicit PushPopEncoding(ArchState* state); ~PushPopEncoding() override = default; void ParseInstruction(uint16_t inst_word); @@ -42,34 +42,34 @@ OpcodeEnum opcode() const { return opcode_; } // Return a single source operand for the given slot, entry, opcode, and // source operand enum. - SourceOperandInterface *GetSource(SlotEnum, int, OpcodeEnum, SourceOpEnum op, + SourceOperandInterface* GetSource(SlotEnum, int, OpcodeEnum, SourceOpEnum op, int source_no) override; // Expand the ListSourceOpEnum into a vector of source operands. - std::vector<SourceOperandInterface *> GetSources(SlotEnum, int, OpcodeEnum, - ListSourceOpEnum op, - int source_no) override; + std::vector<SourceOperandInterface*> GetSources(SlotEnum, int, OpcodeEnum, + ListSourceOpEnum op, + int source_no) override; // Return a single destination operand for the given slot, entry, opcode, // destination operand enum, and latency. - DestinationOperandInterface *GetDestination(SlotEnum, int, OpcodeEnum, + DestinationOperandInterface* GetDestination(SlotEnum, int, OpcodeEnum, DestOpEnum op, int dest_no, int latency) override; // Expand the ListDestOpEnum into a vector of destination operands. - std::vector<DestinationOperandInterface *> GetDestinations( + std::vector<DestinationOperandInterface*> GetDestinations( SlotEnum, int, OpcodeEnum, ListDestOpEnum op, int dest_no, - const std::vector<int> &latency) override; + const std::vector<int>& latency) override; private: using SourceOpGetterMap = - absl::flat_hash_map<int, absl::AnyInvocable<SourceOperandInterface *()>>; + absl::flat_hash_map<int, absl::AnyInvocable<SourceOperandInterface*()>>; using DestOpGetterMap = absl::flat_hash_map< - int, absl::AnyInvocable<DestinationOperandInterface *(int)>>; + int, absl::AnyInvocable<DestinationOperandInterface*(int)>>; using ListSourceOpGetterMap = absl::flat_hash_map< - int, absl::AnyInvocable<std::vector<SourceOperandInterface *>()>>; + int, absl::AnyInvocable<std::vector<SourceOperandInterface*>()>>; using ListDestOpGetterMap = absl::flat_hash_map< - int, absl::AnyInvocable<std::vector<DestinationOperandInterface *>( - const std::vector<int> &)>>; + int, absl::AnyInvocable<std::vector<DestinationOperandInterface*>( + const std::vector<int>&)>>; - ArchState *state_; + ArchState* state_; OpcodeEnum opcode_; uint16_t inst_word_;
diff --git a/mpact/sim/decoder/test/resource_test.cc b/mpact/sim/decoder/test/resource_test.cc index a8c8159..efef72c 100644 --- a/mpact/sim/decoder/test/resource_test.cc +++ b/mpact/sim/decoder/test/resource_test.cc
@@ -28,9 +28,9 @@ EXPECT_TRUE(result.status().ok()); auto result2 = factory_.CreateResource(kResource1Name); EXPECT_TRUE(absl::IsAlreadyExists(result2.status())); - auto *resource1 = factory_.GetOrInsertResource(kResource1Name); + auto* resource1 = factory_.GetOrInsertResource(kResource1Name); EXPECT_EQ(result.value(), resource1); - auto *resource2 = factory_.GetOrInsertResource(kResource2Name); + auto* resource2 = factory_.GetOrInsertResource(kResource2Name); EXPECT_NE(resource2, nullptr); EXPECT_NE(resource2, resource1); auto result3 = factory_.CreateResource(kResource2Name); @@ -42,7 +42,7 @@ // Test initial state of a new resource. TEST_F(ResourceTest, ResourceInitial) { - auto *resource = factory_.GetOrInsertResource(kResource1Name); + auto* resource = factory_.GetOrInsertResource(kResource1Name); EXPECT_TRUE(resource->is_simple()); EXPECT_FALSE(resource->is_multi_valued()); EXPECT_EQ(resource->name(), kResource1Name); @@ -51,7 +51,7 @@ // Test resource setters. TEST_F(ResourceTest, ResourceSetters) { - auto *resource = factory_.GetOrInsertResource(kResource1Name); + auto* resource = factory_.GetOrInsertResource(kResource1Name); resource->set_is_simple(false); resource->set_is_multi_valued(true); EXPECT_FALSE(resource->is_simple());
diff --git a/mpact/sim/decoder/test/riscv_i_instructions.h b/mpact/sim/decoder/test/riscv_i_instructions.h index a4eaf9e..c371804 100644 --- a/mpact/sim/decoder/test/riscv_i_instructions.h +++ b/mpact/sim/decoder/test/riscv_i_instructions.h
@@ -15,6 +15,8 @@ #ifndef THIRD_PARTY_MPACT_RISCV_RISCV_RISCV_I_INSTRUCTIONS_H_ #define THIRD_PARTY_MPACT_RISCV_RISCV_RISCV_I_INSTRUCTIONS_H_ +#include <cstdint> + #include "mpact/sim/generic/instruction.h" // This file contains the declarations of the instruction semantic functions @@ -29,51 +31,51 @@ using ::mpact::sim::generic::Instruction; -void RiscVIllegalInstruction(const Instruction *inst); +void RiscVIllegalInstruction(const Instruction* inst); // No operands necessary for Nop. For now, all hint instructions should be // decoded as Nop. -void RiscVINop(const Instruction *instruction); +void RiscVINop(const Instruction* instruction); namespace RV32 { // For the following, source operand 0 refers to the register specified in rs1, // and source operand 1 refers to either the register specified in rs2, or the // immediate. Destination operand 0 refers to the register specified in rd. -void RiscVIAdd(const Instruction *instruction); -void RiscVISub(const Instruction *instruction); -void RiscVISlt(const Instruction *instruction); -void RiscVISltu(const Instruction *instruction); -void RiscVIAnd(const Instruction *instruction); -void RiscVIOr(const Instruction *instruction); -void RiscVIXor(const Instruction *instruction); -void RiscVISll(const Instruction *instruction); -void RiscVISrl(const Instruction *instruction); -void RiscVISra(const Instruction *instruction); +void RiscVIAdd(const Instruction* instruction); +void RiscVISub(const Instruction* instruction); +void RiscVISlt(const Instruction* instruction); +void RiscVISltu(const Instruction* instruction); +void RiscVIAnd(const Instruction* instruction); +void RiscVIOr(const Instruction* instruction); +void RiscVIXor(const Instruction* instruction); +void RiscVISll(const Instruction* instruction); +void RiscVISrl(const Instruction* instruction); +void RiscVISra(const Instruction* instruction); // For the following two semantic functions, source operand 0 refers to the // immediate value, and destination 0 the register specified in rd. Note, the // value of the immediate shall be properly shifted. -void RiscVILui(const Instruction *instruction); -void RiscVIAuipc(const Instruction *instruction); +void RiscVILui(const Instruction* instruction); +void RiscVIAuipc(const Instruction* instruction); // Source operand 0 contains the immediate value. Destination operand 0 refers // to the pc destination operand, wheras destination operand 1 refers to the // link register specified in rd. -void RiscVIJal(const Instruction *instruction); +void RiscVIJal(const Instruction* instruction); // Source operand 0 refers to the base registers specified by rs1, source // operand 1 contains the immediate value. Destination operand 0 refers to the // pc destination operand, wheras destination operand 1 refers to the // link register specified in rd. -void RiscVIJalr(const Instruction *instruction); +void RiscVIJalr(const Instruction* instruction); // For the following branch instructions. Source operand 0 refers to the // register specified by rs1, source operand 2 refers to the register specified // by rs2, and source operand 3 refers to the immediate offset. Destination // operand 0 refers to the pc destination operand. -void RiscVIBeq(const Instruction *instruction); -void RiscVIBne(const Instruction *instruction); -void RiscVIBlt(const Instruction *instruction); -void RiscVIBltu(const Instruction *instruction); -void RiscVIBge(const Instruction *instruction); -void RiscVIBgeu(const Instruction *instruction); +void RiscVIBeq(const Instruction* instruction); +void RiscVIBne(const Instruction* instruction); +void RiscVIBlt(const Instruction* instruction); +void RiscVIBltu(const Instruction* instruction); +void RiscVIBge(const Instruction* instruction); +void RiscVIBgeu(const Instruction* instruction); // Each of the load instructions are modeled by a pair of semantic instruction // functions. The "main" function computes the effective address and initiates // the load, the "child" function processes the load result and writes it back @@ -82,24 +84,24 @@ // source operand 1 the offset. Destination operand 0 is the register specified // by rd. The "child" semantic function will get a copy of the destination // operand. -void RiscVILd(const Instruction *instruction); -void RiscVILw(const Instruction *instruction); -void RiscVILwChild(const Instruction *instruction); -void RiscVILh(const Instruction *instruction); -void RiscVILhChild(const Instruction *instruction); -void RiscVILhu(const Instruction *instruction); -void RiscVILhuChild(const Instruction *instruction); -void RiscVILb(const Instruction *instruction); -void RiscVILbChild(const Instruction *instruction); -void RiscVILbu(const Instruction *instruction); -void RiscVILbuChild(const Instruction *instruction); +void RiscVILd(const Instruction* instruction); +void RiscVILw(const Instruction* instruction); +void RiscVILwChild(const Instruction* instruction); +void RiscVILh(const Instruction* instruction); +void RiscVILhChild(const Instruction* instruction); +void RiscVILhu(const Instruction* instruction); +void RiscVILhuChild(const Instruction* instruction); +void RiscVILb(const Instruction* instruction); +void RiscVILbChild(const Instruction* instruction); +void RiscVILbu(const Instruction* instruction); +void RiscVILbuChild(const Instruction* instruction); // For each store instruction semantic function, source operand 0 is the base // register, source operand 1 is the offset, while source operand 2 is the value // to be stored referred to by rs2. -void RiscVISd(const Instruction *instruction); -void RiscVISw(const Instruction *instruction); -void RiscVISh(const Instruction *instruction); -void RiscVISb(const Instruction *instruction); +void RiscVISd(const Instruction* instruction); +void RiscVISw(const Instruction* instruction); +void RiscVISh(const Instruction* instruction); +void RiscVISb(const Instruction* instruction); } // namespace RV32 @@ -108,48 +110,48 @@ // For the following, source operand 0 refers to the register specified in rs1, // and source operand 1 refers to either the register specified in rs2, or the // immediate. Destination operand 0 refers to the register specified in rd. -void RiscVIAdd(const Instruction *instruction); -void RiscVIAddw(const Instruction *instruction); -void RiscVISub(const Instruction *instruction); -void RiscVISubw(const Instruction *instruction); -void RiscVISlt(const Instruction *instruction); -void RiscVISltu(const Instruction *instruction); -void RiscVIAnd(const Instruction *instruction); -void RiscVIOr(const Instruction *instruction); -void RiscVIXor(const Instruction *instruction); -void RiscVISll(const Instruction *instruction); -void RiscVISrl(const Instruction *instruction); -void RiscVISra(const Instruction *instruction); -void RiscVISllw(const Instruction *instruction); -void RiscVISrlw(const Instruction *instruction); -void RiscVISraw(const Instruction *instruction); +void RiscVIAdd(const Instruction* instruction); +void RiscVIAddw(const Instruction* instruction); +void RiscVISub(const Instruction* instruction); +void RiscVISubw(const Instruction* instruction); +void RiscVISlt(const Instruction* instruction); +void RiscVISltu(const Instruction* instruction); +void RiscVIAnd(const Instruction* instruction); +void RiscVIOr(const Instruction* instruction); +void RiscVIXor(const Instruction* instruction); +void RiscVISll(const Instruction* instruction); +void RiscVISrl(const Instruction* instruction); +void RiscVISra(const Instruction* instruction); +void RiscVISllw(const Instruction* instruction); +void RiscVISrlw(const Instruction* instruction); +void RiscVISraw(const Instruction* instruction); // For the following two semantic functions, source operand 0 refers to the // immediate value, and destination 0 the register specified in rd. Note, the // value of the immediate shall be properly shifted. -void RiscVILui(const Instruction *instruction); -void RiscVIAuipc(const Instruction *instruction); +void RiscVILui(const Instruction* instruction); +void RiscVIAuipc(const Instruction* instruction); // No operands necessary for Nop. For now, all hint instructions should be // decoded as Nop. -void RiscVINop(const Instruction *instruction); +void RiscVINop(const Instruction* instruction); // Source operand 0 contains the immediate value. Destination operand 0 refers // to the pc destination operand, wheras destination operand 1 refers to the // link register specified in rd. -void RiscVIJal(const Instruction *instruction); +void RiscVIJal(const Instruction* instruction); // Source operand 0 refers to the base registers specified by rs1, source // operand 1 contains the immediate value. Destination operand 0 refers to the // pc destination operand, wheras destination operand 1 refers to the // link register specified in rd. -void RiscVIJalr(const Instruction *instruction); +void RiscVIJalr(const Instruction* instruction); // For the following branch instructions. Source operand 0 refers to the // register specified by rs1, source operand 2 refers to the register specified // by rs2, and source operand 3 refers to the immediate offset. Destination // operand 0 refers to the pc destination operand. -void RiscVIBeq(const Instruction *instruction); -void RiscVIBne(const Instruction *instruction); -void RiscVIBlt(const Instruction *instruction); -void RiscVIBltu(const Instruction *instruction); -void RiscVIBge(const Instruction *instruction); -void RiscVIBgeu(const Instruction *instruction); +void RiscVIBeq(const Instruction* instruction); +void RiscVIBne(const Instruction* instruction); +void RiscVIBlt(const Instruction* instruction); +void RiscVIBltu(const Instruction* instruction); +void RiscVIBge(const Instruction* instruction); +void RiscVIBgeu(const Instruction* instruction); // Each of the load instructions are modeled by a pair of semantic instruction // functions. The "main" function computes the effective address and initiates // the load, the "child" function processes the load result and writes it back @@ -158,40 +160,40 @@ // source operand 1 the offset. Destination operand 0 is the register specified // by rd. The "child" semantic function will get a copy of the destination // operand. -void RiscVILd(const Instruction *instruction); -void RiscVILdChild(const Instruction *instruction); -void RiscVILw(const Instruction *instruction); -void RiscVILwChild(const Instruction *instruction); -void RiscVILwu(const Instruction *instruction); -void RiscVILwuChild(const Instruction *instruction); -void RiscVILh(const Instruction *instruction); -void RiscVILhChild(const Instruction *instruction); -void RiscVILhu(const Instruction *instruction); -void RiscVILhuChild(const Instruction *instruction); -void RiscVILb(const Instruction *instruction); -void RiscVILbChild(const Instruction *instruction); -void RiscVILbu(const Instruction *instruction); -void RiscVILbuChild(const Instruction *instruction); +void RiscVILd(const Instruction* instruction); +void RiscVILdChild(const Instruction* instruction); +void RiscVILw(const Instruction* instruction); +void RiscVILwChild(const Instruction* instruction); +void RiscVILwu(const Instruction* instruction); +void RiscVILwuChild(const Instruction* instruction); +void RiscVILh(const Instruction* instruction); +void RiscVILhChild(const Instruction* instruction); +void RiscVILhu(const Instruction* instruction); +void RiscVILhuChild(const Instruction* instruction); +void RiscVILb(const Instruction* instruction); +void RiscVILbChild(const Instruction* instruction); +void RiscVILbu(const Instruction* instruction); +void RiscVILbuChild(const Instruction* instruction); // For each store instruction semantic function, source operand 0 is the base // register, source operand 1 is the offset, while source operand 2 is the value // to be stored referred to by rs2. -void RiscVISd(const Instruction *instruction); -void RiscVISw(const Instruction *instruction); -void RiscVISh(const Instruction *instruction); -void RiscVISb(const Instruction *instruction); +void RiscVISd(const Instruction* instruction); +void RiscVISw(const Instruction* instruction); +void RiscVISh(const Instruction* instruction); +void RiscVISb(const Instruction* instruction); } // namespace RV64 // The Fence instruction takes a single source operand (index 0) which consists // of an immediate value containing the right justified concatenation of the FM, // predecessor, and successor bit fields of the instruction. -void RiscVIFence(const Instruction *instruction); +void RiscVIFence(const Instruction* instruction); // Ecall and EBreak take no source or destination operands. -void RiscVIEcall(const Instruction *instruction); -void RiscVIEbreak(const Instruction *instruction); +void RiscVIEcall(const Instruction* instruction); +void RiscVIEbreak(const Instruction* instruction); // Trap doesn't implement any specific instruction, but can be called as an // instruction, for instance for unknown instructions. -void RiscVITrap(bool is_interrupt, uint32_t cause, Instruction *instruction); +void RiscVITrap(bool is_interrupt, uint32_t cause, Instruction* instruction); } // namespace riscv } // namespace sim
diff --git a/mpact/sim/decoder/test/slot_test.cc b/mpact/sim/decoder/test/slot_test.cc index 8a4c516..4aff4f8 100644 --- a/mpact/sim/decoder/test/slot_test.cc +++ b/mpact/sim/decoder/test/slot_test.cc
@@ -18,7 +18,7 @@ #include <string> #include "absl/strings/str_cat.h" -#include "googlemock/include/gmock/gmock.h" +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" #include "mpact/sim/decoder/instruction.h" #include "mpact/sim/decoder/instruction_set.h" @@ -91,7 +91,7 @@ std::string opcode_name = absl::StrCat("opcode_", inst_indx); auto res = instruction_set_->opcode_factory()->CreateOpcode(opcode_name); ASSERT_TRUE(res.status().ok()); - auto *inst = new Instruction(res.value(), slot_.get()); + auto* inst = new Instruction(res.value(), slot_.get()); EXPECT_TRUE(slot_->AppendInstruction(inst).ok()); EXPECT_EQ(slot_->instruction_map().size(), inst_indx + 1); EXPECT_EQ(slot_->instruction_map().at(opcode_name), inst);
diff --git a/mpact/sim/decoder/test/template_expression_test.cc b/mpact/sim/decoder/test/template_expression_test.cc index 64ea168..35c0173 100644 --- a/mpact/sim/decoder/test/template_expression_test.cc +++ b/mpact/sim/decoder/test/template_expression_test.cc
@@ -19,7 +19,6 @@ #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" -#include "absl/types/variant.h" #include "googletest/include/gtest/gtest.h" namespace mpact { @@ -34,7 +33,7 @@ constexpr int kIntConst0 = 0; static absl::StatusOr<TemplateValue> Add3TemplateFunc( - TemplateInstantiationArgs *args) { + TemplateInstantiationArgs* args) { if (args->size() != 1) { return absl::InternalError(absl::StrCat( "Wrong number of arguments, expected 1, was given ", args->size())); @@ -42,7 +41,7 @@ auto result = (*args)[0]->GetValue(); if (!result.ok()) return result.status(); - auto *value_ptr = std::get_if<int>(&result.value()); + auto* value_ptr = std::get_if<int>(&result.value()); if (value_ptr == nullptr) { return absl::InternalError("Type mismatch - int expected"); } @@ -57,23 +56,23 @@ ASSERT_TRUE(result.status().ok()); ASSERT_TRUE(five->IsConstant()); auto template_value = result.value(); - int *value_ptr = std::get_if<int>(&template_value); + int* value_ptr = std::get_if<int>(&template_value); EXPECT_EQ(*value_ptr, kIntConst5); delete five; } TEST(TemplateExpressionTest, Negate) { - auto *five = new TemplateConstant(kIntConst5); - auto *negate_expr = new TemplateNegate(five); + auto* five = new TemplateConstant(kIntConst5); + auto* negate_expr = new TemplateNegate(five); auto result = negate_expr->GetValue(); ASSERT_TRUE(result.status().ok()); auto template_value = result.value(); - int *value_ptr = std::get_if<int>(&template_value); + int* value_ptr = std::get_if<int>(&template_value); EXPECT_EQ(*value_ptr, -kIntConst5); // Call Evaluate and check that the value is the same. auto eval_res = negate_expr->Evaluate(nullptr); EXPECT_TRUE(eval_res.status().ok()); - auto *eval_expr = eval_res.value(); + auto* eval_expr = eval_res.value(); result = eval_expr->GetValue(); ASSERT_TRUE(result.status().ok()); template_value = result.value(); @@ -91,7 +90,7 @@ auto result = add_expr->GetValue(); ASSERT_TRUE(result.status().ok()); auto template_value = result.value(); - int *value_ptr = std::get_if<int>(&template_value); + int* value_ptr = std::get_if<int>(&template_value); EXPECT_EQ(*value_ptr, kIntConst2 + kIntConst3); delete add_expr; } @@ -104,7 +103,7 @@ auto result = subtract_expr->GetValue(); ASSERT_TRUE(result.status().ok()); auto template_value = result.value(); - int *value_ptr = std::get_if<int>(&template_value); + int* value_ptr = std::get_if<int>(&template_value); EXPECT_EQ(*value_ptr, kIntConst2 - kIntConst3); delete subtract_expr; } @@ -117,7 +116,7 @@ auto result = mult_expr->GetValue(); ASSERT_TRUE(result.status().ok()); auto template_value = result.value(); - int *value_ptr = std::get_if<int>(&template_value); + int* value_ptr = std::get_if<int>(&template_value); EXPECT_EQ(*value_ptr, kIntConst2 * kIntConst3); delete mult_expr; } @@ -130,7 +129,7 @@ auto result = div_expr->GetValue(); ASSERT_TRUE(result.status().ok()); auto template_value = result.value(); - int *value_ptr = std::get_if<int>(&template_value); + int* value_ptr = std::get_if<int>(&template_value); EXPECT_EQ(*value_ptr, kIntConst5 / kIntConst2); delete div_expr; } @@ -148,43 +147,43 @@ } TEST(TemplateExpressionTest, TemplateFunctionAdd3) { - auto *two = new TemplateConstant(kIntConst2); - auto *args = new TemplateInstantiationArgs{two}; - auto *func = new TemplateFunction(Add3TemplateFunc, args); + auto* two = new TemplateConstant(kIntConst2); + auto* args = new TemplateInstantiationArgs{two}; + auto* func = new TemplateFunction(Add3TemplateFunc, args); EXPECT_TRUE(func->IsConstant()); auto expr_value = func->GetValue(); ASSERT_TRUE(expr_value.status().ok()); - auto *value_ptr = std::get_if<int>(&expr_value.value()); + auto* value_ptr = std::get_if<int>(&expr_value.value()); ASSERT_NE(value_ptr, nullptr); EXPECT_EQ(*value_ptr, kIntConst2 + kIntConst3); delete func; } TEST(TemplateExpressionTest, TemplateFunctionAdd3Evaluate) { - TemplateFormal *formal_b = new TemplateFormal("b", 0); - auto *b_plus_two = new TemplateAdd(new TemplateParam(formal_b), + TemplateFormal* formal_b = new TemplateFormal("b", 0); + auto* b_plus_two = new TemplateAdd(new TemplateParam(formal_b), new TemplateConstant(kIntConst2)); - auto *args = new TemplateInstantiationArgs{b_plus_two}; - auto *func = new TemplateFunction(Add3TemplateFunc, args); + auto* args = new TemplateInstantiationArgs{b_plus_two}; + auto* func = new TemplateFunction(Add3TemplateFunc, args); // First attempt at evaluating function should fail, due to the template // formal b. auto result = func->GetValue(); EXPECT_FALSE(result.status().ok()); // Create a deep copy of func. - auto *deep_func = func->DeepCopy(); + auto* deep_func = func->DeepCopy(); // Specialize based on b = 3. - auto *three = new TemplateConstant(kIntConst3); + auto* three = new TemplateConstant(kIntConst3); TemplateInstantiationArgs instance_b{three}; auto eval_result = func->Evaluate(&instance_b); ASSERT_TRUE(eval_result.status().ok()); - auto *eval_func = eval_result.value(); + auto* eval_func = eval_result.value(); // Specialize the deep copy too. auto deep_eval_result = deep_func->Evaluate(&instance_b); ASSERT_TRUE(deep_eval_result.status().ok()); - auto *deep_eval_func = deep_eval_result.value(); + auto* deep_eval_func = deep_eval_result.value(); // Now get the value. result = eval_func->GetValue(); - auto *value_ptr = std::get_if<int>(&result.value()); + auto* value_ptr = std::get_if<int>(&result.value()); ASSERT_NE(value_ptr, nullptr); EXPECT_EQ(*value_ptr, kIntConst2 + kIntConst3 + kIntConst3); // Get the value from the deep copy too. @@ -205,16 +204,16 @@ // template <int b> B where the expression b + 2 is used in B. // Compute b + 2 given instantiation argument of B<3> TEST(TemplateExpressionTest, TemplateParameter) { - auto *three = new TemplateConstant(kIntConst3); - TemplateFormal *formal_b = new TemplateFormal("b", 0); - auto *b_plus_two = new TemplateAdd(new TemplateParam(formal_b), + auto* three = new TemplateConstant(kIntConst3); + TemplateFormal* formal_b = new TemplateFormal("b", 0); + auto* b_plus_two = new TemplateAdd(new TemplateParam(formal_b), new TemplateConstant(kIntConst2)); TemplateInstantiationArgs instance_b{three}; auto result = b_plus_two->Evaluate(&instance_b); ASSERT_TRUE(result.status().ok()); auto expr_value = result.value()->GetValue(); ASSERT_TRUE(expr_value.status().ok()); - int *value_ptr = std::get_if<int>(&expr_value.value()); + int* value_ptr = std::get_if<int>(&expr_value.value()); ASSERT_NE(value_ptr, nullptr); EXPECT_EQ(*value_ptr, kIntConst2 + kIntConst3); delete formal_b;
diff --git a/mpact/sim/decoder/test/testfiles/riscv32i.h b/mpact/sim/decoder/test/testfiles/riscv32i.h index 372c7f8..20f168e 100644 --- a/mpact/sim/decoder/test/testfiles/riscv32i.h +++ b/mpact/sim/decoder/test/testfiles/riscv32i.h
@@ -24,8 +24,8 @@ using ::mpact::sim::generic::Instruction; -void SomeFunction(Instruction *inst); -void SomeOtherFunction(Instruction *inst); +void SomeFunction(Instruction* inst); +void SomeOtherFunction(Instruction* inst); } // namespace rv32 } // namespace riscv
diff --git a/mpact/sim/generic/action_point_manager_base.cc b/mpact/sim/generic/action_point_manager_base.cc index 21f9999..ea53a81 100644 --- a/mpact/sim/generic/action_point_manager_base.cc +++ b/mpact/sim/generic/action_point_manager_base.cc
@@ -25,12 +25,12 @@ namespace mpact::sim::generic { ActionPointManagerBase::ActionPointManagerBase( - ActionPointMemoryInterface *ap_mem_interface) + ActionPointMemoryInterface* ap_mem_interface) : ap_memory_interface_(ap_mem_interface) {} ActionPointManagerBase::~ActionPointManagerBase() { - for (auto &[unused, ap_ptr] : action_point_map_) { - for (auto &[unused, ai_ptr] : ap_ptr->action_map) { + for (auto& [unused, ap_ptr] : action_point_map_) { + for (auto& [unused, ai_ptr] : ap_ptr->action_map) { ai_ptr->action_fcn = nullptr; delete ai_ptr; } @@ -47,7 +47,7 @@ absl::StatusOr<int> ActionPointManagerBase::SetAction(uint64_t address, ActionFcn action_fcn) { auto it = action_point_map_.find(address); - ActionPointInfo *ap = nullptr; + ActionPointInfo* ap = nullptr; if (it == action_point_map_.end()) { // If the action point doesn't exist, create a new one. // First set the breakpoint instruction. @@ -65,7 +65,7 @@ } // Add the function as an enabled action. int id = ap->next_id++; - auto *action_info = + auto* action_info = new ActionInfo(std::move(action_fcn), /*is_enabled=*/true); ap->action_map.insert(std::make_pair(id, action_info)); ap->num_active++; @@ -80,14 +80,14 @@ absl::StrCat("No action point found at: ", absl::Hex(address))); } // Find the action. - auto *ap = it->second; + auto* ap = it->second; auto action_it = ap->action_map.find(id); if (action_it == ap->action_map.end()) { return absl::NotFoundError( absl::StrCat("No action ", id, "found at: ", absl::Hex(address))); } // Remove the action. - auto *action_info = action_it->second; + auto* action_info = action_it->second; ap->action_map.erase(action_it); ap->num_active -= action_info->is_enabled ? 1 : 0; delete action_info; @@ -106,7 +106,7 @@ return absl::NotFoundError( absl::StrCat("No action point found at: ", absl::Hex(address))); } - auto *ap = it->second; + auto* ap = it->second; // Find the action. auto action_it = ap->action_map.find(id); if (action_it == ap->action_map.end()) { @@ -133,7 +133,7 @@ absl::StrCat("No action point found at: ", absl::Hex(address))); } // Find the action. - auto *ap = it->second; + auto* ap = it->second; auto action_it = ap->action_map.find(id); if (action_it == ap->action_map.end()) { return absl::NotFoundError( @@ -157,7 +157,7 @@ auto it = action_point_map_.find(address); if (it == action_point_map_.end()) return false; - auto *ap = it->second; + auto* ap = it->second; return ap->num_active > 0; } @@ -166,7 +166,7 @@ auto it = action_point_map_.find(address); if (it == action_point_map_.end()) return false; - auto *ap = it->second; + auto* ap = it->second; // Find the action. auto action_it = ap->action_map.find(id); if (action_it == ap->action_map.end()) return false; @@ -174,8 +174,8 @@ } void ActionPointManagerBase::ClearAllActionPoints() { - for (auto &[address, ap_ptr] : action_point_map_) { - for (auto &[unused, action_ptr] : ap_ptr->action_map) { + for (auto& [address, ap_ptr] : action_point_map_) { + for (auto& [unused, action_ptr] : ap_ptr->action_map) { delete action_ptr; } ap_ptr->action_map.clear(); @@ -192,7 +192,7 @@ absl::Hex(address)); } - for (auto &[id, action_ptr] : it->second->action_map) { + for (auto& [id, action_ptr] : it->second->action_map) { if (action_ptr->is_enabled) action_ptr->action_fcn(address, id); } }
diff --git a/mpact/sim/generic/action_point_manager_base.h b/mpact/sim/generic/action_point_manager_base.h index abb8d4e..798c461 100644 --- a/mpact/sim/generic/action_point_manager_base.h +++ b/mpact/sim/generic/action_point_manager_base.h
@@ -64,7 +64,7 @@ using ActionFcn = absl::AnyInvocable<void(uint64_t address, int id)>; // The constructor takes an instance of the ActionPointMemoryInterface class. - ActionPointManagerBase(ActionPointMemoryInterface *ap_mem_interface); + ActionPointManagerBase(ActionPointMemoryInterface* ap_mem_interface); virtual ~ActionPointManagerBase(); // Returns true if the given address has an action point, regardless of @@ -90,7 +90,7 @@ void PerformActions(uint64_t address); // Accessor. - ActionPointMemoryInterface *ap_memory_interface() const { + ActionPointMemoryInterface* ap_memory_interface() const { return ap_memory_interface_; } @@ -112,14 +112,14 @@ // Number of 'actions' that are enabled. int num_active = 0; // Map from id to action function struct. - absl::btree_map<int, ActionInfo *> action_map; + absl::btree_map<int, ActionInfo*> action_map; ActionPointInfo(uint64_t address) : address(address) {} }; // Interface to program memory. - ActionPointMemoryInterface *ap_memory_interface_; + ActionPointMemoryInterface* ap_memory_interface_; // Map from address to action info struct. - absl::btree_map<uint64_t, ActionPointInfo *> action_point_map_; + absl::btree_map<uint64_t, ActionPointInfo*> action_point_map_; }; } // namespace mpact::sim::generic
diff --git a/mpact/sim/generic/arch_state.h b/mpact/sim/generic/arch_state.h index 30316ac..674795b 100644 --- a/mpact/sim/generic/arch_state.h +++ b/mpact/sim/generic/arch_state.h
@@ -51,24 +51,24 @@ protected: ArchState() = delete; explicit ArchState(absl::string_view id) : ArchState(nullptr, id, nullptr) {} - ArchState(absl::string_view id, SourceOperandInterface *pc_operand) + ArchState(absl::string_view id, SourceOperandInterface* pc_operand) : ArchState(nullptr, id, pc_operand) {} - ArchState(Component *parent, absl::string_view id, - SourceOperandInterface *pc_operand); + ArchState(Component* parent, absl::string_view id, + SourceOperandInterface* pc_operand); public: ~ArchState() override; public: - using RegisterMap = absl::flat_hash_map<std::string, RegisterBase *>; - using FifoMap = absl::flat_hash_map<std::string, FifoBase *>; + using RegisterMap = absl::flat_hash_map<std::string, RegisterBase*>; + using FifoMap = absl::flat_hash_map<std::string, FifoBase*>; // Adds the given register to the register table. - void AddRegister(RegisterBase *reg); + void AddRegister(RegisterBase* reg); // Adds the given register to the register table but using name as key. This // is useful when a register object may be accessible using more than one // name, or a name that differs from that stored in the register object. - void AddRegister(absl::string_view name, RegisterBase *reg); + void AddRegister(absl::string_view name, RegisterBase* reg); // Remove the named register from the register table. No action occurs if // there is no such register. If multiple names map to the same register // object, only the single mapping from the given name is removed. @@ -76,18 +76,18 @@ // Creates a register of the given type and adds it to the register table. template <typename RegisterType, typename... Ps> - RegisterType *AddRegister(absl::string_view name, Ps... pargs) { + RegisterType* AddRegister(absl::string_view name, Ps... pargs) { auto reg = new RegisterType(this, name, pargs...); AddRegister(reg); return reg; } // Adds the given fifo to the fifo table. - void AddFifo(FifoBase *fifo); + void AddFifo(FifoBase* fifo); // Adds the given fifo to the fifo table but using name as key. This is useful // when a fifo object may be accessed using more than one name, or a name that // differs from that stored in the fifo object. - void AddFifo(absl::string_view name, FifoBase *fifo); + void AddFifo(absl::string_view name, FifoBase* fifo); // Remove the named fifo from the fifo table. No action occurs if there is no // such fifo. If multiple names map to the same fifo object, only the single // mapping from the given name is removed. @@ -95,7 +95,7 @@ // Creates a fifo of the given type and adds it to the fifo table. template <typename FifoType, typename... Ps> - FifoType *AddFifo(absl::string_view name, Ps... pargs) { + FifoType* AddFifo(absl::string_view name, Ps... pargs) { auto fifo = new FifoType(this, name, pargs...); AddFifo(fifo); return fifo; @@ -116,11 +116,11 @@ // delay lines outside of ArchState instances. Delay lines managed by the // ArchState instance will be deleted when the ArchState is deleted. template <typename DelayLineType, typename... Ps> - DelayLineType *CreateAndAddDelayLine(Ps... pargs) { + DelayLineType* CreateAndAddDelayLine(Ps... pargs) { static_assert( - std::is_convertible<DelayLineType *, DelayLineInterface *>::value); - DelayLineType *delay_line = new DelayLineType(pargs...); - delay_lines_.push_back(static_cast<DelayLineInterface *>(delay_line)); + std::is_convertible<DelayLineType*, DelayLineInterface*>::value); + DelayLineType* delay_line = new DelayLineType(pargs...); + delay_lines_.push_back(static_cast<DelayLineInterface*>(delay_line)); return delay_line; } // This function is called after any event that may have caused an interrupt @@ -130,46 +130,46 @@ virtual void CheckForInterrupt() { /*empty*/ } // Accessors for data members - const std::string &id() const { return component_name(); } + const std::string& id() const { return component_name(); } // The DataBufferFactory associated with this architecture instance. - DataBufferFactory *db_factory() const { return db_factory_; } + DataBufferFactory* db_factory() const { return db_factory_; } // The table of registers. - RegisterMap *registers() { return ®isters_; } + RegisterMap* registers() { return ®isters_; } // The table of fifos. - FifoMap *fifos() { return &fifos_; } + FifoMap* fifos() { return &fifos_; } // The DataBuffer instance delay line. - DataBufferDelayLine *data_buffer_delay_line() const { + DataBufferDelayLine* data_buffer_delay_line() const { return data_buffer_delay_line_; } // The void() function delay line - FunctionDelayLine *function_delay_line() const { + FunctionDelayLine* function_delay_line() const { return function_delay_line_; } // Returns the PC operand interface (read only) - SourceOperandInterface *pc_operand() const { return pc_operand_; } + SourceOperandInterface* pc_operand() const { return pc_operand_; } // Used to report program error (or even internal simulator errors). - ProgramErrorController *program_error_controller() const { + ProgramErrorController* program_error_controller() const { return program_error_controller_; } uint64_t cycle() const { return cycle_; } protected: - void set_pc_operand(SourceOperandInterface *pc_operand) { + void set_pc_operand(SourceOperandInterface* pc_operand) { pc_operand_ = pc_operand; } void set_cycle(uint64_t value) { cycle_ = value; } private: uint64_t cycle_ = 0; - SourceOperandInterface *pc_operand_; - DataBufferFactory *db_factory_; + SourceOperandInterface* pc_operand_; + DataBufferFactory* db_factory_; RegisterMap registers_; FifoMap fifos_; - DataBufferDelayLine *data_buffer_delay_line_; - FunctionDelayLine *function_delay_line_; - std::vector<DelayLineInterface *> delay_lines_; - ProgramErrorController *program_error_controller_; + DataBufferDelayLine* data_buffer_delay_line_; + FunctionDelayLine* function_delay_line_; + std::vector<DelayLineInterface*> delay_lines_; + ProgramErrorController* program_error_controller_; }; } // namespace generic
diff --git a/mpact/sim/generic/breakpoint_manager.cc b/mpact/sim/generic/breakpoint_manager.cc index 9043231..7967d47 100644 --- a/mpact/sim/generic/breakpoint_manager.cc +++ b/mpact/sim/generic/breakpoint_manager.cc
@@ -29,13 +29,13 @@ namespace generic { BreakpointManager::BreakpointManager( - ActionPointManagerBase *action_point_manager, + ActionPointManagerBase* action_point_manager, RequestHaltFunction req_halt_function) : req_halt_function_(std::move(req_halt_function)), action_point_manager_(action_point_manager) {} BreakpointManager::~BreakpointManager() { - for (auto const &[unused, bp_ptr] : breakpoint_map_) { + for (auto const& [unused, bp_ptr] : breakpoint_map_) { delete bp_ptr; } req_halt_function_ = nullptr; @@ -57,7 +57,7 @@ if (!result.ok()) return result.status(); auto id = result.value(); - auto *bp = new BreakpointInfo{address, id, /*is_active=*/true}; + auto* bp = new BreakpointInfo{address, id, /*is_active=*/true}; breakpoint_map_.insert(std::make_pair(address, bp)); return absl::OkStatus(); @@ -75,7 +75,7 @@ auto status = action_point_manager_->ClearAction(address, iter->second->id); if (!status.ok()) return status; - auto *bp = iter->second; + auto* bp = iter->second; breakpoint_map_.erase(iter); delete bp; return absl::OkStatus(); @@ -106,7 +106,7 @@ } void BreakpointManager::ClearAllBreakpoints() { - for (auto const &[unused, bp_ptr] : breakpoint_map_) { + for (auto const& [unused, bp_ptr] : breakpoint_map_) { (void)action_point_manager_->ClearAction(bp_ptr->address, bp_ptr->id); delete bp_ptr; }
diff --git a/mpact/sim/generic/breakpoint_manager.h b/mpact/sim/generic/breakpoint_manager.h index bd77982..f0dca00 100644 --- a/mpact/sim/generic/breakpoint_manager.h +++ b/mpact/sim/generic/breakpoint_manager.h
@@ -37,7 +37,7 @@ // Define a function type to use for the breakpoint action to call for a halt. using RequestHaltFunction = absl::AnyInvocable<void()>; - BreakpointManager(ActionPointManagerBase *action_point_manager, + BreakpointManager(ActionPointManagerBase* action_point_manager, RequestHaltFunction req_halt_function); ~BreakpointManager(); @@ -55,7 +55,7 @@ bool IsBreakpoint(uint64_t address) const; // Accessor. - ActionPointManagerBase *action_point_manager() const { + ActionPointManagerBase* action_point_manager() const { return action_point_manager_; } @@ -71,8 +71,8 @@ RequestHaltFunction req_halt_function_; void DoBreakpointAction(uint64_t, int); - ActionPointManagerBase *action_point_manager_; - absl::btree_map<uint64_t, BreakpointInfo *> breakpoint_map_; + ActionPointManagerBase* action_point_manager_; + absl::btree_map<uint64_t, BreakpointInfo*> breakpoint_map_; }; } // namespace generic
diff --git a/mpact/sim/generic/complex_resource.cc b/mpact/sim/generic/complex_resource.cc index fcf54e9..bcefed9 100644 --- a/mpact/sim/generic/complex_resource.cc +++ b/mpact/sim/generic/complex_resource.cc
@@ -15,9 +15,13 @@ #include "mpact/sim/generic/complex_resource.h" #include <algorithm> +#include <cstddef> +#include <cstdint> +#include <cstring> #include <string> -#include "absl/status/status.h" +#include "absl/types/span.h" +#include "mpact/sim/generic/arch_state.h" namespace mpact { namespace sim { @@ -26,7 +30,7 @@ constexpr size_t kNumBitsPerWord = sizeof(uint64_t) * 8; constexpr size_t kLowBitMask = kNumBitsPerWord - 1; -ComplexResource::ComplexResource(ArchState *state, std::string name, +ComplexResource::ComplexResource(ArchState* state, std::string name, size_t cycle_depth) : state_(state), name_(name), cycle_depth_(cycle_depth) { array_size_ = (cycle_depth_ + kNumBitsPerWord - 1) / kNumBitsPerWord;
diff --git a/mpact/sim/generic/complex_resource.h b/mpact/sim/generic/complex_resource.h index 3e9a476..1d3b12d 100644 --- a/mpact/sim/generic/complex_resource.h +++ b/mpact/sim/generic/complex_resource.h
@@ -15,9 +15,10 @@ #ifndef MPACT_SIM_GENERIC_COMPLEX_RESOURCE_H_ #define MPACT_SIM_GENERIC_COMPLEX_RESOURCE_H_ +#include <cstddef> +#include <cstdint> #include <string> -#include "absl/status/status.h" #include "absl/types/span.h" #include "mpact/sim/generic/arch_state.h" @@ -44,7 +45,7 @@ public: static inline const int kMaxDepth = 512; - ComplexResource(ArchState *state, std::string name, size_t cycle_depth); + ComplexResource(ArchState* state, std::string name, size_t cycle_depth); ComplexResource() = delete; ~ComplexResource(); @@ -58,8 +59,8 @@ // Return printable representation. std::string AsString() const { return name(); } // Accessors. - const std::string &name() const { return name_; } - const absl::Span<uint64_t> bit_array() const { + const std::string& name() const { return name_; } + absl::Span<uint64_t> bit_array() const { return absl::MakeSpan(bit_array_, array_size_); } size_t cycle_depth() const { return cycle_depth_; } @@ -68,7 +69,7 @@ // Advance the cycle vector to current time. void Advance(); // Pointer to the arch state. This is needed to obtain current time. - ArchState *state_; + ArchState* state_; // Name of resource. std::string name_; // Last time the cycle vector was shifted. @@ -78,8 +79,8 @@ // How many uint64_t elements in the array. size_t array_size_; // Pointer to the arrays. - uint64_t *bit_array_ = nullptr; - uint64_t *mask_array_ = nullptr; + uint64_t* bit_array_ = nullptr; + uint64_t* mask_array_ = nullptr; }; } // namespace generic
diff --git a/mpact/sim/generic/complex_resource_operand.cc b/mpact/sim/generic/complex_resource_operand.cc index f5fb474..a2413e4 100644 --- a/mpact/sim/generic/complex_resource_operand.cc +++ b/mpact/sim/generic/complex_resource_operand.cc
@@ -14,7 +14,13 @@ #include "mpact/sim/generic/complex_resource_operand.h" +#include <cstddef> +#include <cstdint> +#include <cstring> + #include "absl/status/status.h" +#include "absl/strings/str_cat.h" +#include "absl/types/span.h" namespace mpact { namespace sim {
diff --git a/mpact/sim/generic/complex_resource_operand.h b/mpact/sim/generic/complex_resource_operand.h index 57ef0d8..7fda90d 100644 --- a/mpact/sim/generic/complex_resource_operand.h +++ b/mpact/sim/generic/complex_resource_operand.h
@@ -15,6 +15,8 @@ #ifndef MPACT_SIM_GENERIC_COMPLEX_RESOURCE_OPERAND_H_ #define MPACT_SIM_GENERIC_COMPLEX_RESOURCE_OPERAND_H_ +#include <cstddef> +#include <cstdint> #include <string> #include "absl/status/status.h" @@ -32,7 +34,7 @@ class ComplexResourceOperand : public ResourceOperandInterface { public: ComplexResourceOperand() = delete; - explicit ComplexResourceOperand(ComplexResource *resource) + explicit ComplexResourceOperand(ComplexResource* resource) : resource_(resource) {} ~ComplexResourceOperand() override { delete[] bit_array_; } @@ -62,8 +64,8 @@ } private: - ComplexResource *resource_ = nullptr; - uint64_t *bit_array_ = nullptr; + ComplexResource* resource_ = nullptr; + uint64_t* bit_array_ = nullptr; int span_size_ = 0; };
diff --git a/mpact/sim/generic/component.cc b/mpact/sim/generic/component.cc index 08b63bb..a4aa0f7 100644 --- a/mpact/sim/generic/component.cc +++ b/mpact/sim/generic/component.cc
@@ -35,7 +35,7 @@ // for the element data type. This template static function factors out the // commonalities. template <typename M, typename T> -static T *GetMapEntry(const M &map, absl::string_view name) { +static T* GetMapEntry(const M& map, absl::string_view name) { auto ptr = map.find(name); return (ptr == map.end()) ? nullptr : ptr->second; } @@ -44,7 +44,7 @@ // for the element data type. This template static function factors out the // commonalities. template <typename M, typename T> -static absl::Status AddMapEntry(absl::string_view name, T *entry, M *map) { +static absl::Status AddMapEntry(absl::string_view name, T* entry, M* map) { if (entry == nullptr) return absl::InvalidArgumentError("entry is nullptr"); auto ptr = map->find(name); if (ptr != map->end()) { @@ -58,7 +58,7 @@ // Constructors. Component::Component(std::string name) : component_name_(std::move(name)) {} -Component::Component(std::string name, Component *parent) +Component::Component(std::string name, Component* parent) : component_name_(std::move(name)) { if (parent != nullptr) { auto status = parent->AddChildComponent(*this); @@ -71,24 +71,24 @@ } // Call the generic static function to Add the element. -absl::Status Component::AddChildComponent(Component &child) { +absl::Status Component::AddChildComponent(Component& child) { auto status = AddMapEntry(child.component_name(), &child, &child_map_); if (!status.ok()) return status; child.SetParent(this); return absl::OkStatus(); } -absl::Status Component::AddCounter(CounterBaseInterface *counter) { +absl::Status Component::AddCounter(CounterBaseInterface* counter) { if (!counter->IsInitialized()) { return absl::InvalidArgumentError("Counter has not been initialized"); } return AddMapEntry(counter->GetName(), counter, &counter_map_); } -absl::Status Component::AddConfig(ConfigBase *config) { +absl::Status Component::AddConfig(ConfigBase* config) { return AddMapEntry(config->name(), config, &config_map_); } // Call the generic static function to Get the element. -Component *Component::GetChildComponent(absl::string_view name) const { +Component* Component::GetChildComponent(absl::string_view name) const { return GetMapEntry<ComponentMap, Component>(child_map_, name); } absl::Status Component::RemoveChildComponent(absl::string_view name) { @@ -99,15 +99,15 @@ child_map_.erase(iter); return absl::OkStatus(); } -CounterBaseInterface *Component::GetCounter(absl::string_view name) const { +CounterBaseInterface* Component::GetCounter(absl::string_view name) const { return GetMapEntry<CounterMap, CounterBaseInterface>(counter_map_, name); } -ConfigBase *Component::GetConfig(absl::string_view name) const { +ConfigBase* Component::GetConfig(absl::string_view name) const { return GetMapEntry<ConfigMap, ConfigBase>(config_map_, name); } // Import information from the component data proto. -absl::Status Component::Import(const ComponentData &component_data) { +absl::Status Component::Import(const ComponentData& component_data) { // Checking that the proto name matches. Recursive calls will not generate // this error, but need to check at the top level. if (!component_data.has_name() || @@ -126,13 +126,13 @@ return absl::OkStatus(); } -absl::Status Component::ImportSelf(const ComponentData &component_data) { - for (auto const &entry : component_data.configuration()) { +absl::Status Component::ImportSelf(const ComponentData& component_data) { + for (auto const& entry : component_data.configuration()) { if (!entry.has_name()) { // The proto is malformed. return absl::InternalError("Missing name in component value"); } - ConfigBase *config = GetConfig(entry.name()); + ConfigBase* config = GetConfig(entry.name()); // It's not an error if there are proto values for config entries that // aren't registered. Just skip and continue. if (config == nullptr) continue; @@ -143,12 +143,12 @@ return absl::OkStatus(); } -absl::Status Component::ImportChildren(const ComponentData &component_data) { - for (auto const &child_data : component_data.component_data()) { +absl::Status Component::ImportChildren(const ComponentData& component_data) { + for (auto const& child_data : component_data.component_data()) { if (!child_data.has_name()) { return absl::InternalError("Unnamed child component"); } - Component *child = GetChildComponent(child_data.name()); + Component* child = GetChildComponent(child_data.name()); if (child == nullptr) continue; auto status = child->Import(child_data); if (!status.ok()) return status; @@ -158,37 +158,37 @@ void Component::ImportDone() const { // Propagate down the component hierarchy. - for (auto const &[unused, child] : child_map_) { + for (auto const& [unused, child] : child_map_) { child->ImportDone(); } // Notify through callbacks. - for (auto const &callback : callback_vec_) { + for (auto const& callback : callback_vec_) { callback(); } } // Export the information reachable from this component to the mutable // component data proto. -absl::Status Component::Export(ComponentData *component_data) { +absl::Status Component::Export(ComponentData* component_data) { if (component_data == nullptr) { return absl::InvalidArgumentError("Component data is null"); } component_data->set_name(component_name()); // Export the configuration values. - for (auto const &[unused, config_pair] : config_map_) { - ComponentValueEntry *entry = component_data->add_configuration(); + for (auto const& [unused, config_pair] : config_map_) { + ComponentValueEntry* entry = component_data->add_configuration(); auto status = config_pair->Export(entry); if (!status.ok()) return status; } // Export the counter values. - for (auto const &[unused, counter_pair] : counter_map_) { - ComponentValueEntry *entry = component_data->add_statistics(); + for (auto const& [unused, counter_pair] : counter_map_) { + ComponentValueEntry* entry = component_data->add_statistics(); auto status = counter_pair->Export(entry); if (!status.ok()) return status; } // Recursively export child component data. - for (auto const &[unused, child_pair] : child_map_) { - ComponentData *child_data = component_data->add_component_data(); + for (auto const& [unused, child_pair] : child_map_) { + ComponentData* child_data = component_data->add_component_data(); auto status = child_pair->Export(child_data); if (!status.ok()) return status; }
diff --git a/mpact/sim/generic/component.h b/mpact/sim/generic/component.h index 7dcc52b..253edbe 100644 --- a/mpact/sim/generic/component.h +++ b/mpact/sim/generic/component.h
@@ -40,73 +40,73 @@ class Component { public: // Using btree_map to ensure proto exports are done in name order. - using ComponentMap = absl::btree_map<std::string, Component *>; - using CounterMap = absl::btree_map<std::string, CounterBaseInterface *>; - using ConfigMap = absl::btree_map<std::string, ConfigBase *>; + using ComponentMap = absl::btree_map<std::string, Component*>; + using CounterMap = absl::btree_map<std::string, CounterBaseInterface*>; + using ConfigMap = absl::btree_map<std::string, ConfigBase*>; // Type alias for import done callback function. using CallbackFunction = std::function<void()>; // Create a Component with no parent. explicit Component(std::string name); // Create a Component under the given parent. Adds the component to the // parent's child components. - Component(std::string name, Component *parent); + Component(std::string name, Component* parent); Component() = delete; - Component(const Component &) = delete; - Component operator=(const Component &) = delete; + Component(const Component&) = delete; + Component operator=(const Component&) = delete; virtual ~Component() = default; // Methods to add and access child components, counters and config entries. - absl::Status AddChildComponent(Component &child); - absl::Status AddCounter(CounterBaseInterface *counter); - absl::Status AddConfig(ConfigBase *config); - Component *GetChildComponent(absl::string_view name) const; + absl::Status AddChildComponent(Component& child); + absl::Status AddCounter(CounterBaseInterface* counter); + absl::Status AddConfig(ConfigBase* config); + Component* GetChildComponent(absl::string_view name) const; absl::Status RemoveChildComponent(absl::string_view name); - CounterBaseInterface *GetCounter(absl::string_view name) const; - ConfigBase *GetConfig(absl::string_view name) const; + CounterBaseInterface* GetCounter(absl::string_view name) const; + ConfigBase* GetConfig(absl::string_view name) const; // Imports the ComponentData proto into the current Component, registered // child component instances, and registered ConfigBase instances. No values // are imported into counters. This method may be overridden. virtual absl::Status Import( - const mpact::sim::proto::ComponentData &component_data); + const mpact::sim::proto::ComponentData& component_data); // This method is called when all imports are done. Can be overridden. virtual void ImportDone() const; // Register a callback function to be called when import is done. template <typename F> - void AddImportDoneCallback(const F &callback) { + void AddImportDoneCallback(const F& callback) { callback_vec_.push_back(callback); } // Exports the data from the current Component instance, its' registered child // components, registered ConfigBase instances, and registered CounterBase // instances. - absl::Status Export(proto::ComponentData *component_data); + absl::Status Export(proto::ComponentData* component_data); // Accessors. - const std::string &component_name() const { return component_name_; } - Component *parent() const { return parent_; } + const std::string& component_name() const { return component_name_; } + Component* parent() const { return parent_; } // Map accessors. - const ComponentMap &child_map() const { return child_map_; } - const CounterMap &counter_map() const { return counter_map_; } - const ConfigMap &config_map() const { return config_map_; } + const ComponentMap& child_map() const { return child_map_; } + const CounterMap& counter_map() const { return counter_map_; } + const ConfigMap& config_map() const { return config_map_; } protected: // The Import method is divided into import self and import children. Each // can be individually overridden. virtual absl::Status ImportSelf( - const mpact::sim::proto::ComponentData &component_data); + const mpact::sim::proto::ComponentData& component_data); virtual absl::Status ImportChildren( - const mpact::sim::proto::ComponentData &component_data); + const mpact::sim::proto::ComponentData& component_data); private: // Private accessor. - void SetParent(Component *parent) { parent_ = parent; } + void SetParent(Component* parent) { parent_ = parent; } std::string component_name_; - Component *parent_ = nullptr; + Component* parent_ = nullptr; // None of the objects pointed to by these maps are owned by this object. ComponentMap child_map_;
diff --git a/mpact/sim/generic/config.h b/mpact/sim/generic/config.h index 68aaf24..346804b 100644 --- a/mpact/sim/generic/config.h +++ b/mpact/sim/generic/config.h
@@ -72,20 +72,20 @@ public: explicit ConfigBase(absl::string_view name) : name_(name) {} ConfigBase() = delete; - ConfigBase(const ConfigBase &) = delete; - ConfigBase &operator=(const ConfigBase &) = delete; + ConfigBase(const ConfigBase&) = delete; + ConfigBase& operator=(const ConfigBase&) = delete; virtual ~ConfigBase() = default; // Return true if the config value has been set since construction. virtual bool HasConfigValue() const = 0; // Variant value accessors provide type agnostic access to config value. virtual ConfigValue GetConfigValue() const = 0; - virtual absl::Status SetConfigValue(const ConfigValue &) = 0; + virtual absl::Status SetConfigValue(const ConfigValue&) = 0; // Exports the Config (name and value) to the proto message. - virtual absl::Status Export(proto::ComponentValueEntry *entry) const = 0; - virtual absl::Status Import(const proto::ComponentValueEntry *entry) = 0; + virtual absl::Status Export(proto::ComponentValueEntry* entry) const = 0; + virtual absl::Status Import(const proto::ComponentValueEntry* entry) = 0; - const std::string &name() const { return name_; } + const std::string& name() const { return name_; } private: std::string name_; @@ -118,7 +118,7 @@ ConfigValue GetConfigValue() const override { return ConfigValue(GetValue()); } - absl::Status SetConfigValue(const ConfigValue &config_value) override { + absl::Status SetConfigValue(const ConfigValue& config_value) override { if (!std::holds_alternative<T>(config_value)) { return absl::InvalidArgumentError("Invalid type in ConfigValue argument"); } @@ -135,7 +135,7 @@ void SetValue(T value) { has_value_ = true; value_ = value; - for (auto const &callback : value_written_callback_vector_) { + for (auto const& callback : value_written_callback_vector_) { callback(); } } @@ -149,7 +149,7 @@ value_written_callback_vector_.push_back(ValueWrittenCallback(callback)); } // Exports the configuration entry name and value to the proto message. - absl::Status Export(proto::ComponentValueEntry *entry) const override { + absl::Status Export(proto::ComponentValueEntry* entry) const override { if (entry == nullptr) return absl::InvalidArgumentError("Entry is null"); entry->set_name(name()); ExportValue(entry); @@ -157,7 +157,7 @@ } // Imports the configuration entry value in the proto. Returns an error if the // name doesn't match or the entry is nullptr. - absl::Status Import(const proto::ComponentValueEntry *entry) override { + absl::Status Import(const proto::ComponentValueEntry* entry) override { if (entry == nullptr) return absl::InvalidArgumentError("Entry is null"); if (!entry->has_name() || (entry->name() != name())) return absl::InternalError( @@ -173,9 +173,9 @@ // in specializations outside the class, as each specialization requires // writing to a different field in the proto message. // Exports the value to the proto message. - void ExportValue(proto::ComponentValueEntry *entry) const; + void ExportValue(proto::ComponentValueEntry* entry) const; // Imports the value from the proto message. - absl::Status ImportValue(const proto::ComponentValueEntry *entry); + absl::Status ImportValue(const proto::ComponentValueEntry* entry); bool has_value_ = false; T value_; std::vector<ValueWrittenCallback> value_written_callback_vector_; @@ -187,34 +187,34 @@ // ExportValue() specializations for the types in the ConfigValue variant. // NOTE: add a specialization for every new type added to the variant. template <> -inline void Config<bool>::ExportValue(proto::ComponentValueEntry *entry) const { +inline void Config<bool>::ExportValue(proto::ComponentValueEntry* entry) const { entry->set_bool_value(GetValue()); } template <> inline void Config<int64_t>::ExportValue( - proto::ComponentValueEntry *entry) const { + proto::ComponentValueEntry* entry) const { entry->set_sint64_value(GetValue()); } template <> inline void Config<uint64_t>::ExportValue( - proto::ComponentValueEntry *entry) const { + proto::ComponentValueEntry* entry) const { entry->set_uint64_value(GetValue()); } template <> inline void Config<double>::ExportValue( - proto::ComponentValueEntry *entry) const { + proto::ComponentValueEntry* entry) const { entry->set_double_value(GetValue()); } template <> inline void Config<std::string>::ExportValue( - proto::ComponentValueEntry *entry) const { + proto::ComponentValueEntry* entry) const { entry->set_string_value(GetValue()); } template <> inline void Config<PhysicalValue>::ExportValue( - proto::ComponentValueEntry *entry) const { - auto *pvalue = entry->mutable_physical_value(); - const PhysicalValue &value = GetValue(); + proto::ComponentValueEntry* entry) const { + auto* pvalue = entry->mutable_physical_value(); + const PhysicalValue& value = GetValue(); pvalue->set_value(value.value); pvalue->set_si_prefix(value.si_prefix); pvalue->set_si_unit(value.si_unit); @@ -223,35 +223,35 @@ // NOTE: add a specialization for every new type added to the variant. template <> inline absl::Status Config<bool>::ImportValue( - const proto::ComponentValueEntry *entry) { + const proto::ComponentValueEntry* entry) { if (!entry->has_bool_value()) return absl::InternalError("No valid value"); SetValue(entry->bool_value()); return absl::OkStatus(); } template <> inline absl::Status Config<int64_t>::ImportValue( - const proto::ComponentValueEntry *entry) { + const proto::ComponentValueEntry* entry) { if (!entry->has_sint64_value()) return absl::InternalError("No valid value"); SetValue(entry->sint64_value()); return absl::OkStatus(); } template <> inline absl::Status Config<uint64_t>::ImportValue( - const proto::ComponentValueEntry *entry) { + const proto::ComponentValueEntry* entry) { if (!entry->has_uint64_value()) return absl::InternalError("No valid value"); SetValue(entry->uint64_value()); return absl::OkStatus(); } template <> inline absl::Status Config<double>::ImportValue( - const proto::ComponentValueEntry *entry) { + const proto::ComponentValueEntry* entry) { if (!entry->has_double_value()) return absl::InternalError("No valid value"); SetValue(entry->double_value()); return absl::OkStatus(); } template <> inline absl::Status Config<std::string>::ImportValue( - const proto::ComponentValueEntry *entry) { + const proto::ComponentValueEntry* entry) { if (!entry->has_string_value()) return absl::InternalError("No valid value"); SetValue(entry->string_value()); return absl::OkStatus(); @@ -259,7 +259,7 @@ template <> inline absl::Status Config<PhysicalValue>::ImportValue( - const proto::ComponentValueEntry *entry) { + const proto::ComponentValueEntry* entry) { if (!entry->has_physical_value()) return absl::InternalError("No valid value"); SetValue(PhysicalValue(entry->physical_value().value(),
diff --git a/mpact/sim/generic/control_register.cc b/mpact/sim/generic/control_register.cc index 05c8791..4be0937 100644 --- a/mpact/sim/generic/control_register.cc +++ b/mpact/sim/generic/control_register.cc
@@ -16,13 +16,17 @@ #include <vector> +#include "absl/strings/string_view.h" +#include "mpact/sim/generic/data_buffer.h" +#include "mpact/sim/generic/register.h" + namespace mpact { namespace sim { namespace generic { ControlRegisterBase::ControlRegisterBase( - ArchState *arch_state, absl::string_view name, - const std::vector<int> &shape, int element_size, + ArchState* arch_state, absl::string_view name, + const std::vector<int>& shape, int element_size, UpdateCallbackFunction on_update_callback) : RegisterBase(arch_state, name, shape, element_size), on_update_callback_(on_update_callback) {} @@ -37,7 +41,7 @@ // register->RegisterBase::SetDataBuffer(db); // } // -void ControlRegisterBase::SetDataBuffer(DataBuffer *db) { +void ControlRegisterBase::SetDataBuffer(DataBuffer* db) { on_update_callback_(this, db); }
diff --git a/mpact/sim/generic/control_register.h b/mpact/sim/generic/control_register.h index 6e6e3fb..010ccd2 100644 --- a/mpact/sim/generic/control_register.h +++ b/mpact/sim/generic/control_register.h
@@ -34,10 +34,7 @@ // method is called from the update callback function, as that is the only way // the register object's data pointer is updated. -#include <cstdint> #include <functional> -#include <map> -#include <string> #include <vector> #include "absl/strings/string_view.h" @@ -59,17 +56,17 @@ public: // Type alias for the update callback function type (set in the constructor). using UpdateCallbackFunction = - std::function<void(ControlRegisterBase *, DataBuffer *)>; + std::function<void(ControlRegisterBase*, DataBuffer*)>; ControlRegisterBase() = delete; - ControlRegisterBase(const ControlRegisterBase &) = delete; + ControlRegisterBase(const ControlRegisterBase&) = delete; ~ControlRegisterBase() override = default; // Calls the update callback function. - void SetDataBuffer(DataBuffer *db) override; + void SetDataBuffer(DataBuffer* db) override; protected: - ControlRegisterBase(ArchState *arch_state, absl::string_view name, - const std::vector<int> &shape, int element_size, + ControlRegisterBase(ArchState* arch_state, absl::string_view name, + const std::vector<int>& shape, int element_size, UpdateCallbackFunction on_update_callback); private:
diff --git a/mpact/sim/generic/core_debug_interface.h b/mpact/sim/generic/core_debug_interface.h index 6402696..81d3762 100644 --- a/mpact/sim/generic/core_debug_interface.h +++ b/mpact/sim/generic/core_debug_interface.h
@@ -91,8 +91,8 @@ virtual absl::StatusOr<HaltReasonValueType> GetLastHaltReason() = 0; // Read/write the named registers. - virtual absl::StatusOr<uint64_t> ReadRegister(const std::string &name) = 0; - virtual absl::Status WriteRegister(const std::string &name, + virtual absl::StatusOr<uint64_t> ReadRegister(const std::string& name) = 0; + virtual absl::Status WriteRegister(const std::string& name, uint64_t value) = 0; // Some registers, including vector registers, have values that exceed the @@ -105,13 +105,13 @@ // Note (2): In some cases, a register write may replace the DataBuffer // instance within a register so that any stored references to it become // stale. - virtual absl::StatusOr<DataBuffer *> GetRegisterDataBuffer( - const std::string &name) = 0; + virtual absl::StatusOr<DataBuffer*> GetRegisterDataBuffer( + const std::string& name) = 0; // Read/write the buffers to memory. - virtual absl::StatusOr<size_t> ReadMemory(uint64_t address, void *buf, + virtual absl::StatusOr<size_t> ReadMemory(uint64_t address, void* buf, size_t length) = 0; - virtual absl::StatusOr<size_t> WriteMemory(uint64_t address, const void *buf, + virtual absl::StatusOr<size_t> WriteMemory(uint64_t address, const void* buf, size_t length) = 0; // Test to see if there's a breakpoint at the given address. @@ -123,7 +123,7 @@ virtual absl::Status ClearAllSwBreakpoints() = 0; // Return the instruction object for the instruction at the given address. - virtual absl::StatusOr<Instruction *> GetInstruction(uint64_t address) = 0; + virtual absl::StatusOr<Instruction*> GetInstruction(uint64_t address) = 0; // Return the string representation for the instruction at the given address. virtual absl::StatusOr<std::string> GetDisassembly(uint64_t address) = 0; };
diff --git a/mpact/sim/generic/counters.h b/mpact/sim/generic/counters.h index 1c086cb..a544201 100644 --- a/mpact/sim/generic/counters.h +++ b/mpact/sim/generic/counters.h
@@ -104,7 +104,7 @@ // to be added a a listener, which means that its SetValue() method will be // called whenever value of the counter is updated. The caller retains // ownership of the listener. - void AddListener(CounterValueSetInterface<T> *listener) { + void AddListener(CounterValueSetInterface<T>* listener) { listeners_.push_back(listener); } // Implementation of the pure virtual method from CounterBaseInterface to @@ -120,7 +120,7 @@ // for the type specific export, as each different type needs to set // a different field in the proto message. absl::Status Export( - mpact::sim::proto::ComponentValueEntry *entry) const override { + mpact::sim::proto::ComponentValueEntry* entry) const override { if (entry == nullptr) return absl::InvalidArgumentError("Entry is null"); entry->set_name(GetName()); if (!GetAbout().empty()) { @@ -154,7 +154,7 @@ // of registered listener objects with the new value. void UpdateValue(T value) { value_ = std::move(value); - for (auto *listener : listeners_) { + for (auto* listener : listeners_) { listener->SetValue(value_); } } @@ -163,10 +163,10 @@ // This method exports the typed value of the counter to the appropriate // field in the proto message. Note, this method is defined at the bottom of // this file. - void ExportValue(mpact::sim::proto::ComponentValueEntry *entry) const; + void ExportValue(mpact::sim::proto::ComponentValueEntry* entry) const; // Objects pointed to are owned elsewhere. Their lifetimes must exceed the // lifetime of the counter, or at least beyond the last call to UpdateValue. - std::vector<CounterValueSetInterface<T> *> listeners_; + std::vector<CounterValueSetInterface<T>*> listeners_; std::string name_; std::string about_; bool is_enabled_; @@ -204,27 +204,27 @@ // Constructor and destructor. SimpleCounter() : CounterValueOutputBase<T>() {} - SimpleCounter(std::string name, std::string about, const T &initial) + SimpleCounter(std::string name, std::string about, const T& initial) : CounterValueOutputBase<T>(std::move(name), std::move(about), initial) {} - SimpleCounter(std::string name, const T &initial) + SimpleCounter(std::string name, const T& initial) : CounterValueOutputBase<T>(std::move(name), initial) {} SimpleCounter(std::string name, std::string about) : SimpleCounter(std::move(name), std::move(about), T()) {} explicit SimpleCounter(std::string name) : SimpleCounter(std::move(name), T()) {} - SimpleCounter &operator=(const SimpleCounter &) = delete; + SimpleCounter& operator=(const SimpleCounter&) = delete; ~SimpleCounter() override = default; // Implementing the methods from the CounterValueIncrementInterface<T>. Note // that the methods are declared final to enable de-virtualization // optimizations in the compiler. - void Increment(const T &val) final { + void Increment(const T& val) final { if (IsEnabled()) UpdateValue(GetValue() + val); } - void Decrement(const T &val) final { + void Decrement(const T& val) final { if (IsEnabled()) UpdateValue(GetValue() - val); } - void SetValue(const T &val) final { + void SetValue(const T& val) final { if (IsEnabled()) UpdateValue(val); } @@ -259,7 +259,7 @@ "Template argument type Out is not in CounterValue variant."); public: - using ProcessingFunction = std::function<bool(const In &, Out *)>; + using ProcessingFunction = std::function<bool(const In&, Out*)>; // Since this class derives from templated classes, calls to the base class // methods must be qualified or use this->. Electing to do the former with the // following using declarations. @@ -273,7 +273,7 @@ // If not passed in to the constructor it defaults to a function that always // returns false and thus never updates the counter value. template <typename F> - FunctionCounter(std::string name, const Out &initial, F processing_function) + FunctionCounter(std::string name, const Out& initial, F processing_function) : CounterValueOutputBase<Out>(std::move(name), initial), processing_function_( std::move(ProcessingFunction(processing_function))) {} @@ -281,12 +281,12 @@ FunctionCounter(std::string name, F processing_function) : FunctionCounter(std::move(name), Out(), std::move(processing_function)) {} - FunctionCounter(std::string name, const Out &initial) + FunctionCounter(std::string name, const Out& initial) : FunctionCounter(std::move(name), initial, - [](const In &, Out *) -> bool { return false; }) {} + [](const In&, Out*) -> bool { return false; }) {} explicit FunctionCounter(std::string name) : FunctionCounter(std::move(name), Out()) {} - FunctionCounter &operator=(const FunctionCounter &) = delete; + FunctionCounter& operator=(const FunctionCounter&) = delete; ~FunctionCounter() override = default; // Set the value processing function. @@ -298,7 +298,7 @@ // The following method is defined final to enable devirtualization // optimization in the compiler. // Process the input value and update the counter if indicated. - void SetValue(const In &in_value) final { + void SetValue(const In& in_value) final { if (IsEnabled()) { Out out_value; if (processing_function_(in_value, &out_value)) UpdateValue(out_value); @@ -319,17 +319,17 @@ // NOTE: add a specialization for every new type added to the variant. template <> inline void CounterValueOutputBase<uint64_t>::ExportValue( - mpact::sim::proto::ComponentValueEntry *entry) const { + mpact::sim::proto::ComponentValueEntry* entry) const { entry->set_uint64_value(GetValue()); } template <> inline void CounterValueOutputBase<int64_t>::ExportValue( - mpact::sim::proto::ComponentValueEntry *entry) const { + mpact::sim::proto::ComponentValueEntry* entry) const { entry->set_sint64_value(GetValue()); } template <> inline void CounterValueOutputBase<double>::ExportValue( - mpact::sim::proto::ComponentValueEntry *entry) const { + mpact::sim::proto::ComponentValueEntry* entry) const { entry->set_double_value(GetValue()); }
diff --git a/mpact/sim/generic/counters_base.h b/mpact/sim/generic/counters_base.h index 4468afa..5a80391 100644 --- a/mpact/sim/generic/counters_base.h +++ b/mpact/sim/generic/counters_base.h
@@ -20,8 +20,6 @@ #include <variant> #include "absl/status/status.h" -#include "absl/strings/string_view.h" -#include "absl/types/variant.h" #include "mpact/sim/proto/component_data.pb.h" namespace mpact { @@ -55,7 +53,7 @@ // Exports the counter values to the proto message. virtual absl::Status Export( - mpact::sim::proto::ComponentValueEntry *entry) const = 0; + mpact::sim::proto::ComponentValueEntry* entry) const = 0; // Access name and set/get about string. virtual std::string GetName() const = 0; @@ -72,7 +70,7 @@ class CounterValueSetInterface { public: virtual ~CounterValueSetInterface() = default; - virtual void SetValue(const T &val) = 0; + virtual void SetValue(const T& val) = 0; }; // Extended input interface of a counter. Adds methods to increment and @@ -81,8 +79,8 @@ class CounterValueIncrementInterface : public CounterValueSetInterface<T> { public: ~CounterValueIncrementInterface() override = default; - virtual void Increment(const T &val) = 0; - virtual void Decrement(const T &val) = 0; + virtual void Increment(const T& val) = 0; + virtual void Decrement(const T& val) = 0; }; } // namespace generic
diff --git a/mpact/sim/generic/data_buffer.cc b/mpact/sim/generic/data_buffer.cc index 58cd2f5..5482a56 100644 --- a/mpact/sim/generic/data_buffer.cc +++ b/mpact/sim/generic/data_buffer.cc
@@ -40,8 +40,8 @@ // Allocate a DataBuffer and then copy the value of the source DB into // the newly allocated buffer. -DataBuffer *DataBufferFactory::MakeCopyOf(const DataBuffer *src_db) { - DataBuffer *db = Allocate(src_db->size<uint8_t>()); +DataBuffer* DataBufferFactory::MakeCopyOf(const DataBuffer* src_db) { + DataBuffer* db = Allocate(src_db->size<uint8_t>()); db->CopyFrom(src_db); return db; } @@ -49,10 +49,10 @@ DataBuffer::DataBuffer(unsigned size) : size_(size) { // Allocate using unsigned char to guarantee appropriate alignment according // to C++ standard 5.3.4 (11). - raw_ptr_ = static_cast<void *>(new unsigned char[size_]); + raw_ptr_ = static_cast<void*>(new unsigned char[size_]); } -DataBuffer::~DataBuffer() { delete[] static_cast<unsigned char *>(raw_ptr_); } +DataBuffer::~DataBuffer() { delete[] static_cast<unsigned char*>(raw_ptr_); } void DataBuffer::Submit(int latency) { if (destination_ == nullptr) {
diff --git a/mpact/sim/generic/data_buffer.h b/mpact/sim/generic/data_buffer.h index a2c70ae..e06dcf4 100644 --- a/mpact/sim/generic/data_buffer.h +++ b/mpact/sim/generic/data_buffer.h
@@ -62,19 +62,19 @@ // Allocates a DataBuffer instance with a buffer size of num instances of T. // The free list is searched before falling back on using new. template <typename T> - DataBuffer *Allocate(int num) { + DataBuffer* Allocate(int num) { return Allocate(sizeof(T) * num); } // Allocates a DataBuffer instance with a buffer of size bytes. The free // list is searched before falling back on using new. - inline DataBuffer *Allocate(int size); + inline DataBuffer* Allocate(int size); // Allocates a new DataBuffer instance with the same size as db and // initializes the contents of the internal buffer to the value of that of // db - without changing db. Except for the memcpy this method acts just like // Allocate() - DataBuffer *MakeCopyOf(const DataBuffer *src_db); + DataBuffer* MakeCopyOf(const DataBuffer* src_db); // Clears and frees up all the objects contained in the DBStore that holds // the recycled DataBuffers. @@ -83,15 +83,15 @@ private: // Moves the DataBuffer instance on to a free list based on the size of the // internal buffer. This method is only called by DataBuffere instances. - inline void Recycle(DataBuffer *db); + inline void Recycle(DataBuffer* db); // The DBStore keeps free DataBuffer instances in free lists by size of // the data_ store. That way runtime overhead is reduced, since DataBuffer // objects are allocated very frequently. // // map <size of data buffer data_, list of free data buffers > - using DataBufferFreeList = absl::btree_map<int, std::vector<DataBuffer *>>; + using DataBufferFreeList = absl::btree_map<int, std::vector<DataBuffer*>>; - std::vector<DataBuffer *> short_free_list_[kShortSize + 1]; + std::vector<DataBuffer*> short_free_list_[kShortSize + 1]; DataBufferFreeList free_list_; }; @@ -103,7 +103,7 @@ class DataBufferDestination { public: - virtual void SetDataBuffer(DataBuffer *db) = 0; + virtual void SetDataBuffer(DataBuffer* db) = 0; virtual ~DataBufferDestination() = default; }; @@ -153,15 +153,15 @@ template <typename ElementType> inline void Set(int index, ElementType value) { ABSL_HARDENING_ASSERT((index + 1) * sizeof(ElementType) <= size_); - reinterpret_cast<ElementType *>(raw_ptr_)[index] = value; + reinterpret_cast<ElementType*>(raw_ptr_)[index] = value; } // Set entry using a span. template <typename ElementType> inline void Set(absl::Span<const ElementType> values) { ABSL_HARDENING_ASSERT(values.size() * sizeof(ElementType) <= size_); - auto *data_ptr = reinterpret_cast<ElementType *>(raw_ptr_); - for (auto const &value : values) { + auto* data_ptr = reinterpret_cast<ElementType*>(raw_ptr_); + for (auto const& value : values) { *data_ptr++ = value; } } @@ -170,7 +170,7 @@ template <typename ElementType> inline void SetSubmit(int index, ElementType value) { ABSL_HARDENING_ASSERT((index + 1) * sizeof(ElementType) <= size_); - reinterpret_cast<ElementType *>(raw_ptr_)[index] = value; + reinterpret_cast<ElementType*>(raw_ptr_)[index] = value; Submit(latency_); } @@ -178,8 +178,8 @@ template <typename ElementType> inline void SetSubmit(absl::Span<const ElementType> values) { ABSL_HARDENING_ASSERT(values.size() * sizeof(ElementType) <= size_); - auto *data_ptr = reinterpret_cast<ElementType *>(raw_ptr_); - for (auto const &value : values) { + auto* data_ptr = reinterpret_cast<ElementType*>(raw_ptr_); + for (auto const& value : values) { *data_ptr++ = value; } Submit(latency_); @@ -190,7 +190,7 @@ template <typename ElementType> inline ElementType Get(unsigned index) const { ABSL_HARDENING_ASSERT((index + 1) * sizeof(ElementType) <= size_); - return reinterpret_cast<ElementType *>(raw_ptr_)[index]; + return reinterpret_cast<ElementType*>(raw_ptr_)[index]; } template <int N> @@ -202,27 +202,27 @@ // Return the data buffer as a span of elements of type ElementType. template <typename ElementType> inline absl::Span<ElementType> Get() const { - return absl::MakeSpan(reinterpret_cast<ElementType *>(raw_ptr_), + return absl::MakeSpan(reinterpret_cast<ElementType*>(raw_ptr_), size<ElementType>()); } // Copies the content of the data buffer to the buffer stored at the // given location. The caller is responsible for ensuring that the // target buffer is of sufficient size. - inline void CopyTo(uint8_t *data) const { + inline void CopyTo(uint8_t* data) const { std::memcpy(data, raw_ptr_, size_); } // Copies the content of the data stored at the given location into // the data buffer. The caller is responsible for ensuring that the // source buffer is of sufficient size. - inline void CopyFrom(const uint8_t *data) { + inline void CopyFrom(const uint8_t* data) { std::memcpy(raw_ptr_, data, size_); } // Copies the data from the given data buffer. The sizes have to be // identical. - inline void CopyFrom(const DataBuffer *src_db) { + inline void CopyFrom(const DataBuffer* src_db) { ABSL_HARDENING_ASSERT(size_ == src_db->size_); std::memcpy(raw_ptr_, src_db->raw_ptr_, size_); } @@ -255,26 +255,26 @@ // Sets the destination state object that will receive the data buffer upon // Submit(0)/0 latency, or after latency cycles from a "delay line". - inline void set_destination(DataBufferDestination *dest) { + inline void set_destination(DataBufferDestination* dest) { destination_ = dest; } // Sets the delay line to use for this data buffer when it's submitted with // a non-zero latency. - inline void set_delay_line(DataBufferDelayLine *delay_line) { + inline void set_delay_line(DataBufferDelayLine* delay_line) { delay_line_ = delay_line; } // Returns the raw byte pointer to the data buffer storage. - void *raw_ptr() const { return raw_ptr_; } + void* raw_ptr() const { return raw_ptr_; } private: explicit DataBuffer(unsigned size); - DataBufferFactory *db_factory_; - DataBufferDelayLine *delay_line_; - DataBufferDestination *destination_; + DataBufferFactory* db_factory_; + DataBufferDelayLine* delay_line_; + DataBufferDestination* destination_; int latency_; unsigned size_; - void *raw_ptr_; + void* raw_ptr_; }; // DataBufferDelayRecord is used as the parameter for the DelayLine for @@ -283,12 +283,12 @@ class DataBufferDelayRecord { public: DataBufferDelayRecord() = delete; - DataBufferDelayRecord(const DataBufferDelayRecord &rhs) { + DataBufferDelayRecord(const DataBufferDelayRecord& rhs) { dest_ = rhs.dest_; data_buffer_ = rhs.data_buffer_; data_buffer_->IncRef(); } - DataBufferDelayRecord(DataBuffer *data_buffer, DataBufferDestination *dest) + DataBufferDelayRecord(DataBuffer* data_buffer, DataBufferDestination* dest) : data_buffer_(data_buffer), dest_(dest) {} ~DataBufferDelayRecord() { if (data_buffer_ != nullptr) { @@ -299,14 +299,14 @@ void Apply() { dest_->SetDataBuffer(data_buffer_); } private: - DataBuffer *data_buffer_; - DataBufferDestination *dest_; + DataBuffer* data_buffer_; + DataBufferDestination* dest_; }; // Put the DataBuffer into the db_store based on size of the data it can hold. // This method is only call from DataBuffer instance, so no need to check for // db == nullptr. -inline void DataBufferFactory::Recycle(DataBuffer *db) { +inline void DataBufferFactory::Recycle(DataBuffer* db) { int size = db->size<uint8_t>(); if (size <= kShortSize) { short_free_list_[size].push_back(db); @@ -316,17 +316,17 @@ ptr->second.push_back(db); return; } - free_list_.emplace(size, std::vector<DataBuffer *>{db}); + free_list_.emplace(size, std::vector<DataBuffer*>{db}); } } // Search through the DataBuffer recycled store to see if there is a buffer // of the appropriate size. If not, allocate a new one. -inline DataBuffer *DataBufferFactory::Allocate(int size) { - DataBuffer *db = nullptr; +inline DataBuffer* DataBufferFactory::Allocate(int size) { + DataBuffer* db = nullptr; { if (size <= kShortSize) { - auto &free_list = short_free_list_[size]; + auto& free_list = short_free_list_[size]; if (!free_list.empty()) { db = free_list.back(); free_list.pop_back();
diff --git a/mpact/sim/generic/debug_command_shell_interface.h b/mpact/sim/generic/debug_command_shell_interface.h index 46689c0..528d6bd 100644 --- a/mpact/sim/generic/debug_command_shell_interface.h +++ b/mpact/sim/generic/debug_command_shell_interface.h
@@ -30,9 +30,9 @@ // Each core must provide the debug interface and the elf loader. struct CoreAccess { - CoreDebugInterface *debug_interface = nullptr; - std::function<util::ElfProgramLoader *()> loader_getter; - ArchState *state = nullptr; + CoreDebugInterface* debug_interface = nullptr; + std::function<util::ElfProgramLoader*()> loader_getter; + ArchState* state = nullptr; absl::btree_map<int, uint64_t> breakpoint_map; int breakpoint_index = 0; absl::btree_map<int, WatchpointInfo> watchpoint_map; @@ -48,11 +48,11 @@ // any error while executing the command, in which case the output string // should be set to an appropriate error message. using CommandFunction = absl::AnyInvocable<bool( - absl::string_view, const CoreAccess &, std::string &)>; + absl::string_view, const CoreAccess&, std::string&)>; // Add core access to the system. - virtual void AddCore(const CoreAccess &core_access) = 0; - virtual void AddCores(const std::vector<CoreAccess> &core_access) = 0; + virtual void AddCore(const CoreAccess& core_access) = 0; + virtual void AddCores(const std::vector<CoreAccess>& core_access) = 0; // This adds a custom command to the command interpreter. Usage will be added // to the standard command usage. The callable will be called before the @@ -62,7 +62,7 @@ // The run method is the command interpreter. It parses the command strings, // executes the corresponding commands, displays results and error messages. - virtual void Run(std::istream &is, std::ostream &os) = 0; + virtual void Run(std::istream& is, std::ostream& os) = 0; }; } // namespace mpact::sim::generic
diff --git a/mpact/sim/generic/decode_cache.cc b/mpact/sim/generic/decode_cache.cc index b452b3c..bbb9a6e 100644 --- a/mpact/sim/generic/decode_cache.cc +++ b/mpact/sim/generic/decode_cache.cc
@@ -17,13 +17,15 @@ #include <cstdint> #include "absl/numeric/bits.h" +#include "mpact/sim/generic/decoder_interface.h" +#include "mpact/sim/generic/instruction.h" namespace mpact { namespace sim { namespace generic { -DecodeCache::DecodeCache(const DecodeCacheProperties &props, - DecoderInterface *decoder) +DecodeCache::DecodeCache(const DecodeCacheProperties& props, + DecoderInterface* decoder) : decoder_(decoder), instruction_cache_(nullptr) { num_entries_ = absl::bit_ceil(props.num_entries); address_shift_ = @@ -36,7 +38,7 @@ } address_mask_ = (num_entries_ - 1) << address_shift_; - instruction_cache_ = new Instruction *[num_entries_]; + instruction_cache_ = new Instruction*[num_entries_]; if (nullptr == instruction_cache_) { // memory allocation failed return; @@ -53,9 +55,9 @@ instruction_cache_ = nullptr; } -DecodeCache *DecodeCache::Create(const DecodeCacheProperties &props, - DecoderInterface *decoder) { - DecodeCache *dc = new DecodeCache(props, decoder); +DecodeCache* DecodeCache::Create(const DecodeCacheProperties& props, + DecoderInterface* decoder) { + DecodeCache* dc = new DecodeCache(props, decoder); if (nullptr == dc->instruction_cache_) { delete dc; return nullptr; @@ -63,20 +65,20 @@ return dc; } -Instruction *DecodeCache::GetDecodedInstruction(uint64_t address) { +Instruction* DecodeCache::GetDecodedInstruction(uint64_t address) { // Verify that the instruction_cache_ was allocated if (nullptr == instruction_cache_) { return nullptr; } uint64_t indx = (address & address_mask_) >> address_shift_; - Instruction *inst = instruction_cache_[indx]; + Instruction* inst = instruction_cache_[indx]; if ((nullptr != inst) && (inst->address() == address)) { return inst; } - Instruction *new_inst = decoder_->DecodeInstruction(address); + Instruction* new_inst = decoder_->DecodeInstruction(address); if (nullptr == new_inst) { return nullptr; @@ -93,7 +95,7 @@ void DecodeCache::Invalidate(uint64_t address) { uint64_t entry = (address & address_mask_) >> address_shift_; - Instruction *inst = instruction_cache_[entry]; + Instruction* inst = instruction_cache_[entry]; if ((nullptr != inst) && (inst->address() == address)) { instruction_cache_[entry]->DecRef(); instruction_cache_[entry] = nullptr;
diff --git a/mpact/sim/generic/decode_cache.h b/mpact/sim/generic/decode_cache.h index 7fd1189..d87cd6a 100644 --- a/mpact/sim/generic/decode_cache.h +++ b/mpact/sim/generic/decode_cache.h
@@ -57,7 +57,7 @@ class DecodeCache { private: // Constructed using static factory method. - DecodeCache(const DecodeCacheProperties &props, DecoderInterface *decoder); + DecodeCache(const DecodeCacheProperties& props, DecoderInterface* decoder); public: DecodeCache() = delete; @@ -65,12 +65,12 @@ // The DecodeCache factory method takes the property struct and the interface // to a decoder that will supply an instruction internal representation for // a given address. If memory allocation fails it returns nullptr. - static DecodeCache *Create(const DecodeCacheProperties &props, - DecoderInterface *decoder); + static DecodeCache* Create(const DecodeCacheProperties& props, + DecoderInterface* decoder); // Returns the decoded instruction associated with the given address. If there // is not an instruction with that address in the decode cache, the decoder // will be called and the newly decoded instruction will be cached. - Instruction *GetDecodedInstruction(uint64_t address); + Instruction* GetDecodedInstruction(uint64_t address); // Invalidation operations // These methods cases the removal from the cache of the instruction // internal represenations that match the address, address range [start, end), @@ -87,12 +87,12 @@ int address_inc() const { return address_inc_; } private: - DecoderInterface *decoder_; + DecoderInterface* decoder_; int num_entries_; int address_shift_; uint32_t address_inc_; uint64_t address_mask_; - Instruction **instruction_cache_; + Instruction** instruction_cache_; }; } // namespace generic
diff --git a/mpact/sim/generic/decoder_interface.h b/mpact/sim/generic/decoder_interface.h index 86173eb..23eecae 100644 --- a/mpact/sim/generic/decoder_interface.h +++ b/mpact/sim/generic/decoder_interface.h
@@ -30,9 +30,9 @@ // in the instruction decoding, the decoder should still produce an // instruction that can be executed, but its semantic action function should // set an error condition in the simulation when executed. - virtual Instruction *DecodeInstruction(uint64_t address) = 0; + virtual Instruction* DecodeInstruction(uint64_t address) = 0; virtual int GetNumOpcodes() const = 0; - virtual const char *GetOpcodeName(int index) const = 0; + virtual const char* GetOpcodeName(int index) const = 0; virtual ~DecoderInterface() = default; };
diff --git a/mpact/sim/generic/delay_line.h b/mpact/sim/generic/delay_line.h index f8cfa9d..ceaf6d7 100644 --- a/mpact/sim/generic/delay_line.h +++ b/mpact/sim/generic/delay_line.h
@@ -15,6 +15,7 @@ #ifndef MPACT_SIM_GENERIC_DELAY_LINE_H_ #define MPACT_SIM_GENERIC_DELAY_LINE_H_ +#include <cstdint> #include <vector> /* Commented out for now. Not currently using threads. @@ -101,7 +102,7 @@ int Advance() override /*ABSL_LOCKS_EXCLUDED(delay_line_lock_)*/ { // absl::MutexLock dl(&delay_line_lock_); current_ = (current_ + 1) & mask_; - for (auto &rec : delay_line_[current_]) { + for (auto& rec : delay_line_[current_]) { rec.Apply(); num_entries_--; }
diff --git a/mpact/sim/generic/devnull_operand.h b/mpact/sim/generic/devnull_operand.h index 4cd43eb..e61b9f9 100644 --- a/mpact/sim/generic/devnull_operand.h +++ b/mpact/sim/generic/devnull_operand.h
@@ -39,7 +39,7 @@ public: // Constructor requires machine state to access data buffer factory, and // shape to allocate the correct size. - DevNullOperand(ArchState *state, const std::vector<int> &shape, + DevNullOperand(ArchState* state, const std::vector<int>& shape, absl::string_view string_value) : db_factory_(state->db_factory()), shape_(shape), @@ -49,24 +49,24 @@ size_ *= sz; } } - DevNullOperand(ArchState *state, const std::vector<int> &shape) + DevNullOperand(ArchState* state, const std::vector<int>& shape) : DevNullOperand(state, shape, "") {} DevNullOperand() = delete; // Allocates a data buffer of the correct size, but initializes it with a // null destination. - DataBuffer *AllocateDataBuffer() override { - DataBuffer *db = db_factory_->Allocate(size_); + DataBuffer* AllocateDataBuffer() override { + DataBuffer* db = db_factory_->Allocate(size_); InitializeDataBuffer(db); return db; } // Initializes the data buffer with null attributes. - void InitializeDataBuffer(DataBuffer *db) override { + void InitializeDataBuffer(DataBuffer* db) override { db->set_destination(nullptr); db->set_latency(0); db->set_delay_line(nullptr); } // Just call AllocateDataBuffer, as there is no underlying state item. - DataBuffer *CopyDataBuffer() override { return AllocateDataBuffer(); } + DataBuffer* CopyDataBuffer() override { return AllocateDataBuffer(); } // Zero latency always. int latency() const override { return 0; } // No object to return. @@ -77,7 +77,7 @@ std::string AsString() const override { return string_value_; } private: - DataBufferFactory *db_factory_; + DataBufferFactory* db_factory_; std::vector<int> shape_; int size_; std::string string_value_;
diff --git a/mpact/sim/generic/fifo.cc b/mpact/sim/generic/fifo.cc index ee22930..b0e5d39 100644 --- a/mpact/sim/generic/fifo.cc +++ b/mpact/sim/generic/fifo.cc
@@ -28,8 +28,8 @@ namespace sim { namespace generic { -FifoBase::FifoBase(class ArchState *arch_state, absl::string_view name, - const std::vector<int> &shape, int element_size, +FifoBase::FifoBase(class ArchState* arch_state, absl::string_view name, + const std::vector<int>& shape, int element_size, int default_capacity) : StateItemBase(arch_state, name, shape, element_size), Component(std::string(name), arch_state), @@ -58,7 +58,7 @@ void FifoBase::Reserve(int count) { reserved_ += count; } -bool FifoBase::Push(DataBuffer *db) { +bool FifoBase::Push(DataBuffer* db) { // If any slots are reserved, decrement first before checking for full. if (reserved_ > 0) { reserved_--; @@ -86,7 +86,7 @@ fifo_.pop_front(); } -DataBuffer *FifoBase::Front() const { +DataBuffer* FifoBase::Front() const { if (fifo_.empty()) { if (nullptr != underflow_program_error_) { underflow_program_error_->Raise("Underflow in fifo " + name_); @@ -99,10 +99,10 @@ unsigned FifoBase::Available() const { return fifo_.size(); } -void FifoBase::SetDataBuffer(DataBuffer *db) { Push(db); } +void FifoBase::SetDataBuffer(DataBuffer* db) { Push(db); } absl::Status FifoBase::ImportSelf( - const mpact::sim::proto::ComponentData &component_data) { + const mpact::sim::proto::ComponentData& component_data) { auto status = Component::ImportSelf(component_data); if (!status.ok()) return status; capacity_ = depth_.GetValue();
diff --git a/mpact/sim/generic/fifo.h b/mpact/sim/generic/fifo.h index 35cd9a8..963b356 100644 --- a/mpact/sim/generic/fifo.h +++ b/mpact/sim/generic/fifo.h
@@ -49,8 +49,8 @@ class FifoSourceOperand : public SourceOperandInterface { public: // Constructor. Note, default constructor deleted. - explicit FifoSourceOperand(FifoBase *fifo); - FifoSourceOperand(FifoBase *fifo, const std::string op_name); + explicit FifoSourceOperand(FifoBase* fifo); + FifoSourceOperand(FifoBase* fifo, const std::string op_name); FifoSourceOperand() = delete; // These accessor methods are defined to satisfy the interface. However, @@ -80,7 +80,7 @@ std::string AsString() const override { return op_name_; } private: - FifoBase *fifo_; + FifoBase* fifo_; std::string op_name_; }; @@ -91,22 +91,22 @@ class FifoDestinationOperand : public DestinationOperandInterface { public: // Constructors - FifoDestinationOperand(FifoBase *fifo, int latency, std::string op_name); - FifoDestinationOperand(FifoBase *fifo, int latency); + FifoDestinationOperand(FifoBase* fifo, int latency, std::string op_name); + FifoDestinationOperand(FifoBase* fifo, int latency); FifoDestinationOperand() = delete; // Initializes the DataBuffer instance so that when Submit is called, it can // be entered into the correct delay line, with the correct latency, targeting // the correct fifo. - void InitializeDataBuffer(DataBuffer *db) override; + void InitializeDataBuffer(DataBuffer* db) override; // Since a fifo stores multiple values, this method will return a nullptr // as it does not make sense to copy the value from a fifo into a destination // DataBuffer instance that is destined for that fifo. - DataBuffer *CopyDataBuffer() override { return nullptr; } + DataBuffer* CopyDataBuffer() override { return nullptr; } // Allocates and returns an initialized DataBuffer instance. - DataBuffer *AllocateDataBuffer() override; + DataBuffer* AllocateDataBuffer() override; // Returns the FifoBase object wrapped in absl::any. std::any GetObject() const override { return std::any(fifo_); } @@ -122,10 +122,10 @@ std::string AsString() const override { return op_name_; } private: - FifoBase *fifo_; - DataBufferFactory *db_factory_; + FifoBase* fifo_; + DataBufferFactory* db_factory_; int latency_; - DataBufferDelayLine *delay_line_; + DataBufferDelayLine* delay_line_; std::string op_name_; }; @@ -141,18 +141,18 @@ class FifoBase : public StateItemBase, public Component { // Only constructed from derived classes. protected: - FifoBase(class ArchState *arch_state, absl::string_view name, - const std::vector<int> &shape, int element_size, + FifoBase(class ArchState* arch_state, absl::string_view name, + const std::vector<int>& shape, int element_size, int default_capacity); FifoBase() = delete; - FifoBase(const FifoBase &) = delete; + FifoBase(const FifoBase&) = delete; public: ~FifoBase() override; public: // Pushes the DataBuffer to the fifo provided there is space available. - void SetDataBuffer(DataBuffer *db) override; + void SetDataBuffer(DataBuffer* db) override; // Returns true if the count of reserved and full slots equals or exceeds // fifo capacity. @@ -177,12 +177,12 @@ // is greater than zero it will decrement the reserved count. If the push // would overflow the fifo it returns false, and raises the overflow program // error if set. - virtual bool Push(DataBuffer *db); + virtual bool Push(DataBuffer* db); // Returns a pointer to the DataBuffer at the front of the fifo. If the fifo // is empty, the nullptr is returned and the underflow program error, if set, // is raised. - DataBuffer *Front() const; + DataBuffer* Front() const; // Removes the front element of the fifo and decrements its reference count. // If the fifo is empty, the underflow program error, if set, is raised. @@ -198,23 +198,23 @@ unsigned Reserved() const { return reserved_; } // Setters for ProgramErrors - void SetOverflowProgramError(std::unique_ptr<ProgramError> *program_error) { + void SetOverflowProgramError(std::unique_ptr<ProgramError>* program_error) { overflow_program_error_ = std::move(*program_error); } - void SetUnderflowProgramError(std::unique_ptr<ProgramError> *program_error) { + void SetUnderflowProgramError(std::unique_ptr<ProgramError>* program_error) { underflow_program_error_ = std::move(*program_error); } protected: // Configuration import. absl::Status ImportSelf( - const mpact::sim::proto::ComponentData &component_data) override; + const mpact::sim::proto::ComponentData& component_data) override; - ProgramError *overflow_program_error() { + ProgramError* overflow_program_error() { return overflow_program_error_.get(); } - ProgramError *underflow_program_error() { + ProgramError* underflow_program_error() { return underflow_program_error_.get(); } @@ -225,7 +225,7 @@ std::string name_; unsigned capacity_; unsigned reserved_; - std::deque<DataBuffer *> fifo_; + std::deque<DataBuffer*> fifo_; }; // Scalar valued fifo with value type ElementType. @@ -260,11 +260,10 @@ typename std::enable_if<!std::is_integral<T>::value, void>::type; // Helper function used in the partial specialization below. -template < - typename F, typename T, - typename std::enable_if<std::is_signed<T>::value, T>::type * = nullptr> -inline T HelperAs(const FifoBase *fifo, int i) { - DataBuffer *db = fifo->Front(); +template <typename F, typename T, + typename std::enable_if<std::is_signed<T>::value, T>::type* = nullptr> +inline T HelperAs(const FifoBase* fifo, int i) { + DataBuffer* db = fifo->Front(); if (nullptr == db) { return static_cast<T>(0); } @@ -274,9 +273,9 @@ template < typename F, typename T, - typename std::enable_if<std::is_unsigned<T>::value, T>::type * = nullptr> -inline T HelperAs(const FifoBase *fifo, int i) { - DataBuffer *db = fifo->Front(); + typename std::enable_if<std::is_unsigned<T>::value, T>::type* = nullptr> +inline T HelperAs(const FifoBase* fifo, int i) { + DataBuffer* db = fifo->Front(); if (nullptr == db) { return static_cast<T>(0); } @@ -285,12 +284,12 @@ } template <typename T, typename Enable> -FifoSourceOperand<T, Enable>::FifoSourceOperand(FifoBase *fifo, +FifoSourceOperand<T, Enable>::FifoSourceOperand(FifoBase* fifo, const std::string op_name) : fifo_(fifo), op_name_(op_name) {} template <typename T, typename Enable> -FifoSourceOperand<T, Enable>::FifoSourceOperand(FifoBase *fifo) +FifoSourceOperand<T, Enable>::FifoSourceOperand(FifoBase* fifo) : FifoSourceOperand(fifo, fifo->name()) {} template <typename T> @@ -298,9 +297,9 @@ : public SourceOperandInterface { public: // Constructors. Note, default constructor deleted. - FifoSourceOperand(FifoBase *fifo, const std::string op_name) + FifoSourceOperand(FifoBase* fifo, const std::string op_name) : fifo_(fifo), op_name_(op_name) {} - explicit FifoSourceOperand(FifoBase *fifo) + explicit FifoSourceOperand(FifoBase* fifo) : FifoSourceOperand(fifo, fifo->name()) {} FifoSourceOperand() = delete; @@ -331,7 +330,7 @@ std::string AsString() const override { return op_name_; } private: - FifoBase *fifo_; + FifoBase* fifo_; std::string op_name_; }; @@ -347,9 +346,9 @@ : public SourceOperandInterface { public: // Constructors. Note, default constructor deleted. - FifoSourceOperand(FifoBase *fifo, const std::string op_name) + FifoSourceOperand(FifoBase* fifo, const std::string op_name) : fifo_(fifo), op_name_(op_name) {} - explicit FifoSourceOperand(FifoBase *fifo) + explicit FifoSourceOperand(FifoBase* fifo) : FifoSourceOperand(fifo, fifo->name()) {} FifoSourceOperand() = delete; @@ -373,12 +372,12 @@ std::vector<int> shape() const override { return fifo_->shape(); } private: - FifoBase *fifo_; + FifoBase* fifo_; std::string op_name_; }; template <typename T> -FifoDestinationOperand<T>::FifoDestinationOperand(FifoBase *fifo, int latency, +FifoDestinationOperand<T>::FifoDestinationOperand(FifoBase* fifo, int latency, std::string op_name) : fifo_(fifo), db_factory_(fifo->arch_state()->db_factory()), @@ -387,19 +386,19 @@ op_name_(op_name) {} template <typename T> -FifoDestinationOperand<T>::FifoDestinationOperand(FifoBase *fifo, int latency) +FifoDestinationOperand<T>::FifoDestinationOperand(FifoBase* fifo, int latency) : FifoDestinationOperand(fifo, latency, fifo->name()) {} template <typename T> -void FifoDestinationOperand<T>::InitializeDataBuffer(DataBuffer *db) { +void FifoDestinationOperand<T>::InitializeDataBuffer(DataBuffer* db) { db->set_destination(fifo_); db->set_latency(latency_); db->set_delay_line(delay_line_); } template <typename T> -DataBuffer *FifoDestinationOperand<T>::AllocateDataBuffer() { - DataBuffer *db = db_factory_->Allocate(fifo_->size()); +DataBuffer* FifoDestinationOperand<T>::AllocateDataBuffer() { + DataBuffer* db = db_factory_->Allocate(fifo_->size()); InitializeDataBuffer(db); return db; }
diff --git a/mpact/sim/generic/fifo_with_notify.cc b/mpact/sim/generic/fifo_with_notify.cc index 1493da2..a4e1db6 100644 --- a/mpact/sim/generic/fifo_with_notify.cc +++ b/mpact/sim/generic/fifo_with_notify.cc
@@ -16,13 +16,16 @@ #include <utility> +#include "mpact/sim/generic/data_buffer.h" +#include "mpact/sim/generic/fifo.h" + namespace mpact { namespace sim { namespace generic { // Call base class Push. Only call the on_not_empty callback if the fifo is // empty prior to pushing. -bool FifoWithNotifyBase::Push(DataBuffer *db) { +bool FifoWithNotifyBase::Push(DataBuffer* db) { if (!IsEmpty()) return FifoBase::Push(db); auto res = FifoBase::Push(db);
diff --git a/mpact/sim/generic/fifo_with_notify.h b/mpact/sim/generic/fifo_with_notify.h index fb3b27d..ef683c7 100644 --- a/mpact/sim/generic/fifo_with_notify.h +++ b/mpact/sim/generic/fifo_with_notify.h
@@ -36,21 +36,21 @@ class FifoWithNotifyBase : public FifoBase { protected: // Constructed from derived class (StateItem). - FifoWithNotifyBase(ArchState *arch_state, absl::string_view name, - const std::vector<int> &shape, int element_size, + FifoWithNotifyBase(ArchState* arch_state, absl::string_view name, + const std::vector<int>& shape, int element_size, int default_capacity) : FifoBase(arch_state, name, shape, element_size, default_capacity) {} FifoWithNotifyBase() = delete; - FifoWithNotifyBase(const FifoWithNotifyBase &) = delete; + FifoWithNotifyBase(const FifoWithNotifyBase&) = delete; public: - using OnEventCallback = absl::AnyInvocable<void(FifoWithNotifyBase *)>; + using OnEventCallback = absl::AnyInvocable<void(FifoWithNotifyBase*)>; // SetDataBuffer and Pop are overridden to detect when the fifo transitions // from/to empty. The reason Push is not overrided is that Push moves the // data buffer into a delay line with a possible non-zero latency. That means // that the write doesn't actually occur into until SetDataBuffer is called. - bool Push(DataBuffer *) override; + bool Push(DataBuffer*) override; void Pop() override; // Set the transition callbacks functions. Pass in nullptr to clear an already
diff --git a/mpact/sim/generic/immediate_operand.h b/mpact/sim/generic/immediate_operand.h index 4cb5f2b..55aa40b 100644 --- a/mpact/sim/generic/immediate_operand.h +++ b/mpact/sim/generic/immediate_operand.h
@@ -20,6 +20,7 @@ #include <string> #include <vector> +#include "absl/base/macros.h" #include "mpact/sim/generic/operand_interface.h" namespace mpact { @@ -36,9 +37,9 @@ : value_(val), shape_({1}), as_string_(absl::StrCat(val)) {} ImmediateOperand(T val, std::string as_string) : value_(val), shape_({1}), as_string_(as_string) {} - ImmediateOperand(T val, const std::vector<int> &shape) + ImmediateOperand(T val, const std::vector<int>& shape) : value_(val), shape_(shape), as_string_(absl::StrCat(val)) {} - ImmediateOperand(T val, const std::vector<int> &shape, std::string as_string) + ImmediateOperand(T val, const std::vector<int>& shape, std::string as_string) : value_(val), shape_(shape), as_string_(as_string) {} // Methods for accessing the immediate value. Always returns the same @@ -83,7 +84,7 @@ explicit VectorImmediateOperand(std::vector<T> val) : value_(val) { shape_.push_back(value_.size()); } - VectorImmediateOperand(std::vector<T> val, const std::vector<int> &shape) + VectorImmediateOperand(std::vector<T> val, const std::vector<int>& shape) : value_(val), shape_(shape) { ABSL_HARDENING_ASSERT((shape.size() == 1) && (shape[0] == val.size())); }
diff --git a/mpact/sim/generic/instruction.cc b/mpact/sim/generic/instruction.cc index 79af44b..6ba87f4 100644 --- a/mpact/sim/generic/instruction.cc +++ b/mpact/sim/generic/instruction.cc
@@ -18,13 +18,16 @@ #include <cstring> #include <string> -#include "mpact/sim/generic/resource_operand_interface.h" +#include "absl/types/span.h" +#include "mpact/sim/generic/arch_state.h" +#include "mpact/sim/generic/operand_interface.h" +#include "mpact/sim/generic/resource_operand_interface.h" // IWYU pragma: keep namespace mpact { namespace sim { namespace generic { -void Instruction::AppendChild(Instruction *inst) { +void Instruction::AppendChild(Instruction* inst) { if (nullptr == inst) return; inst->parent_ = this; if (nullptr == child_) { @@ -35,7 +38,7 @@ } } -void Instruction::Append(Instruction *inst) { +void Instruction::Append(Instruction* inst) { if (nullptr == inst) return; if (nullptr == next_) { inst->IncRef(); @@ -45,23 +48,23 @@ } } -void Instruction::SetPredicate(PredicateOperandInterface *predicate) { +void Instruction::SetPredicate(PredicateOperandInterface* predicate) { predicate_ = predicate; } -void Instruction::AppendSource(SourceOperandInterface *op) { +void Instruction::AppendSource(SourceOperandInterface* op) { sources_.push_back(op); } int Instruction::SourcesSize() const { return sources_.size(); } -void Instruction::AppendDestination(DestinationOperandInterface *op) { +void Instruction::AppendDestination(DestinationOperandInterface* op) { dests_.push_back(op); } int Instruction::DestinationsSize() const { return dests_.size(); } -Instruction::Instruction(uint64_t address, ArchState *state) +Instruction::Instruction(uint64_t address, ArchState* state) : predicate_(nullptr), address_(address), state_(state), @@ -70,24 +73,24 @@ parent_(nullptr), next_(nullptr) {} -Instruction::Instruction(ArchState *state) : Instruction(0, state) {} +Instruction::Instruction(ArchState* state) : Instruction(0, state) {} Instruction::~Instruction() { delete[] attribute_array_; delete predicate_; - for (auto *op : sources_) { + for (auto* op : sources_) { delete op; } sources_.clear(); - for (auto *op : dests_) { + for (auto* op : dests_) { delete op; } dests_.clear(); - for (auto *op : resource_hold_) { + for (auto* op : resource_hold_) { delete op; } resource_hold_.clear(); - for (auto *op : resource_acquire_) { + for (auto* op : resource_acquire_) { delete op; } resource_acquire_.clear();
diff --git a/mpact/sim/generic/instruction.h b/mpact/sim/generic/instruction.h index 8a553e7..b8606dc 100644 --- a/mpact/sim/generic/instruction.h +++ b/mpact/sim/generic/instruction.h
@@ -87,22 +87,22 @@ class Instruction : public ReferenceCount { public: // Type Alias for the semantic function. - using SemanticFunction = std::function<void(Instruction *)>; + using SemanticFunction = std::function<void(Instruction*)>; // Constructors and Destructors. - explicit Instruction(ArchState *state); - Instruction(uint64_t address, ArchState *state); + explicit Instruction(ArchState* state); + Instruction(uint64_t address, ArchState* state); ~Instruction() override; // Appends the instruction to the "next" list of instructions. - void Append(Instruction *inst); + void Append(Instruction* inst); // Appends the instruction the "child" list of instructions. - void AppendChild(Instruction *inst); + void AppendChild(Instruction* inst); // Methods used for navigating instruction hierarchy. - Instruction *child() const { return child_; } - Instruction *parent() const { return parent_; } - Instruction *next() const { return next_; } + Instruction* child() const { return child_; } + Instruction* parent() const { return parent_; } + Instruction* next() const { return next_; } // Execute the instruction with the given context // Note: The context is stored into the instruction instance instead of @@ -113,7 +113,7 @@ // only a handle to the Instruction instance as that is available during // instruction decode, and accessing the context otherwise would require // modifying the interface for all operands. - void Execute(ReferenceCount *context) { + void Execute(ReferenceCount* context) { context_ = context; semantic_fcn_(this); context_ = nullptr; @@ -122,8 +122,8 @@ void Execute() { semantic_fcn_(this); } // Accessors (getters/setters). - ReferenceCount *context() const { return context_; } - ArchState *state() const { return state_; } + ReferenceCount* context() const { return context_; } + ArchState* state() const { return state_; } // Returns the pc value for the instruction. uint64_t address() const { return address_; } // The address should seldom be set outside the constructor. @@ -144,32 +144,32 @@ // PredicateOperand interface used for those ISAs that implement // instruction predicates. - PredicateOperandInterface *Predicate() const { return predicate_; } - void SetPredicate(PredicateOperandInterface *predicate); + PredicateOperandInterface* Predicate() const { return predicate_; } + void SetPredicate(PredicateOperandInterface* predicate); // SourceOperand interfaces for the instruction. - SourceOperandInterface *Source(int i) const { return sources_[i]; } - void AppendSource(SourceOperandInterface *op); + SourceOperandInterface* Source(int i) const { return sources_[i]; } + void AppendSource(SourceOperandInterface* op); int SourcesSize() const; // DestinationOperand interfaces for the instruction. - DestinationOperandInterface *Destination(int i) const { return dests_[i]; } - void AppendDestination(DestinationOperandInterface *op); + DestinationOperandInterface* Destination(int i) const { return dests_[i]; } + void AppendDestination(DestinationOperandInterface* op); int DestinationsSize() const; // Hold ResourceOperand interfaces for the instruction. - inline std::vector<ResourceOperandInterface *> &ResourceHold() { + inline std::vector<ResourceOperandInterface*>& ResourceHold() { return resource_hold_; } - inline void AppendResourceHold(ResourceOperandInterface *op) { + inline void AppendResourceHold(ResourceOperandInterface* op) { resource_hold_.push_back(op); } // Acquire ResourceOperand interfaces for the instruction. - inline std::vector<ResourceOperandInterface *> &ResourceAcquire() { + inline std::vector<ResourceOperandInterface*>& ResourceAcquire() { return resource_acquire_; } - inline void AppendResourceAcquire(ResourceOperandInterface *op) { + inline void AppendResourceAcquire(ResourceOperandInterface* op) { resource_acquire_.push_back(op); } @@ -186,19 +186,19 @@ private: // Instruction operands. - PredicateOperandInterface *predicate_ = nullptr; - std::vector<SourceOperandInterface *> sources_; - std::vector<DestinationOperandInterface *> dests_; + PredicateOperandInterface* predicate_ = nullptr; + std::vector<SourceOperandInterface*> sources_; + std::vector<DestinationOperandInterface*> dests_; // The resources that must be available in order to issue the instruction. // This includes any registers that are read. - std::vector<ResourceOperandInterface *> resource_hold_; + std::vector<ResourceOperandInterface*> resource_hold_; // The resources that must be reserved/acquired by the instruction. Each // vector element is a set of resources that are acquired when the instruction // issues. The method Acquire() should be called on each element of the // vector. The operands should contain all registers and other resources that // that need to be reserved for writing. - std::vector<ResourceOperandInterface *> resource_acquire_; + std::vector<ResourceOperandInterface*> resource_acquire_; // Simulated instruction size. int size_; // Simulated instruction address. @@ -214,24 +214,24 @@ // privilege level, or whether the instruction is a branch or not. // The attribute array is owned by the Instruction object. The attributes are // accessed as a const span, so the attributes are read only. - int *attribute_array_ = nullptr; + int* attribute_array_ = nullptr; absl::Span<const int> attributes_ = - absl::MakeConstSpan(static_cast<int *>(nullptr), 0); + absl::MakeConstSpan(static_cast<int*>(nullptr), 0); // Architecture state object. - ArchState *state_; + ArchState* state_; // Instruction execution context (this is usuall nullptr). - ReferenceCount *context_; + ReferenceCount* context_; // Semantic function that implements the instruction semantics. SemanticFunction semantic_fcn_; // Pointer to the child (or sub) instruction. Used to break an instruction // up into multiple semantic actions, such as a VLIW instruction. - Instruction *child_; + Instruction* child_; // Parent instruction pointer from child instruction. - Instruction *parent_; + Instruction* parent_; // Pointer to the "next" instruction (instructions can be linked into a list // of instructions), such as those instances that make up the instructions in // a VLIW instruction word. - Instruction *next_; + Instruction* next_; }; // Templated inline helper functions for operand access. These are intended to @@ -240,75 +240,75 @@ // The base case shouldn't be matched. No return statement is provided. template <typename T> -inline T GetInstructionSource(const Instruction *inst, int index) { /*empty */ } +inline T GetInstructionSource(const Instruction* inst, int index) { /*empty */ } // The following provide specializations for each of the integral types of // operand values, both signed and unsigned. template <> -inline bool GetInstructionSource<bool>(const Instruction *inst, int index) { +inline bool GetInstructionSource<bool>(const Instruction* inst, int index) { return inst->Source(index)->AsBool(0); } template <> -inline uint8_t GetInstructionSource<uint8_t>(const Instruction *inst, +inline uint8_t GetInstructionSource<uint8_t>(const Instruction* inst, int index) { return inst->Source(index)->AsUint8(0); } template <> -inline int8_t GetInstructionSource<int8_t>(const Instruction *inst, int index) { +inline int8_t GetInstructionSource<int8_t>(const Instruction* inst, int index) { return inst->Source(index)->AsInt8(0); } template <> -inline uint16_t GetInstructionSource<uint16_t>(const Instruction *inst, +inline uint16_t GetInstructionSource<uint16_t>(const Instruction* inst, int index) { return inst->Source(index)->AsUint16(0); } template <> -inline int16_t GetInstructionSource<int16_t>(const Instruction *inst, +inline int16_t GetInstructionSource<int16_t>(const Instruction* inst, int index) { return inst->Source(index)->AsInt16(0); } template <> -inline HalfFP GetInstructionSource<HalfFP>(const Instruction *inst, int index) { +inline HalfFP GetInstructionSource<HalfFP>(const Instruction* inst, int index) { auto value = inst->Source(index)->AsUint16(0); return HalfFP{.value = value}; } template <> -inline uint32_t GetInstructionSource<uint32_t>(const Instruction *inst, +inline uint32_t GetInstructionSource<uint32_t>(const Instruction* inst, int index) { return inst->Source(index)->AsUint32(0); } template <> -inline int32_t GetInstructionSource<int32_t>(const Instruction *inst, +inline int32_t GetInstructionSource<int32_t>(const Instruction* inst, int index) { return inst->Source(index)->AsInt32(0); } template <> -inline float GetInstructionSource<float>(const Instruction *inst, int index) { +inline float GetInstructionSource<float>(const Instruction* inst, int index) { auto value = inst->Source(index)->AsUint32(0); - return *reinterpret_cast<float *>(&value); + return *reinterpret_cast<float*>(&value); } template <> -inline uint64_t GetInstructionSource<uint64_t>(const Instruction *inst, +inline uint64_t GetInstructionSource<uint64_t>(const Instruction* inst, int index) { return inst->Source(index)->AsUint64(0); } template <> -inline int64_t GetInstructionSource<int64_t>(const Instruction *inst, +inline int64_t GetInstructionSource<int64_t>(const Instruction* inst, int index) { return inst->Source(index)->AsInt64(0); } template <> -inline double GetInstructionSource<double>(const Instruction *inst, int index) { +inline double GetInstructionSource<double>(const Instruction* inst, int index) { auto value = inst->Source(index)->AsUint64(0); - return *reinterpret_cast<double *>(&value); + return *reinterpret_cast<double*>(&value); } template <> inline absl::uint128 GetInstructionSource<absl::uint128>( - const Instruction *inst, int index) { + const Instruction* inst, int index) { return static_cast<absl::uint128>(inst->Source(index)->AsUint64(0)); } template <> -inline absl::int128 GetInstructionSource<absl::int128>(const Instruction *inst, +inline absl::int128 GetInstructionSource<absl::int128>(const Instruction* inst, int index) { return static_cast<absl::int128>(inst->Source(index)->AsInt64(0)); } @@ -316,66 +316,66 @@ // The base case shouldn't be matched. No return statement is provided, so it // will generate a compile time error if no other case is matched. template <typename T> -inline T GetInstructionSource(const Instruction *inst, int index, +inline T GetInstructionSource(const Instruction* inst, int index, int element) { /*empty */ } // The following provide specializations for each of the integral types of // operand values, both signed and unsigned. template <> -inline bool GetInstructionSource<bool>(const Instruction *inst, int index, +inline bool GetInstructionSource<bool>(const Instruction* inst, int index, int element) { return inst->Source(index)->AsBool(element); } template <> -inline uint8_t GetInstructionSource<uint8_t>(const Instruction *inst, int index, +inline uint8_t GetInstructionSource<uint8_t>(const Instruction* inst, int index, int element) { return inst->Source(index)->AsUint8(element); } template <> -inline int8_t GetInstructionSource<int8_t>(const Instruction *inst, int index, +inline int8_t GetInstructionSource<int8_t>(const Instruction* inst, int index, int element) { return inst->Source(index)->AsInt8(element); } template <> -inline uint16_t GetInstructionSource<uint16_t>(const Instruction *inst, +inline uint16_t GetInstructionSource<uint16_t>(const Instruction* inst, int index, int element) { return inst->Source(index)->AsUint16(element); } template <> -inline int16_t GetInstructionSource<int16_t>(const Instruction *inst, int index, +inline int16_t GetInstructionSource<int16_t>(const Instruction* inst, int index, int element) { return inst->Source(index)->AsInt16(element); } template <> -inline uint32_t GetInstructionSource<uint32_t>(const Instruction *inst, +inline uint32_t GetInstructionSource<uint32_t>(const Instruction* inst, int index, int element) { return inst->Source(index)->AsUint32(element); } template <> -inline int32_t GetInstructionSource<int32_t>(const Instruction *inst, int index, +inline int32_t GetInstructionSource<int32_t>(const Instruction* inst, int index, int element) { return inst->Source(index)->AsInt32(element); } template <> -inline float GetInstructionSource<float>(const Instruction *inst, int index, +inline float GetInstructionSource<float>(const Instruction* inst, int index, int element) { auto value = inst->Source(index)->AsUint32(element); - return *reinterpret_cast<float *>(&value); + return *reinterpret_cast<float*>(&value); } template <> -inline uint64_t GetInstructionSource<uint64_t>(const Instruction *inst, +inline uint64_t GetInstructionSource<uint64_t>(const Instruction* inst, int index, int element) { return inst->Source(index)->AsUint64(element); } template <> -inline int64_t GetInstructionSource<int64_t>(const Instruction *inst, int index, +inline int64_t GetInstructionSource<int64_t>(const Instruction* inst, int index, int element) { return inst->Source(index)->AsInt64(element); } template <> -inline double GetInstructionSource<double>(const Instruction *inst, int index, +inline double GetInstructionSource<double>(const Instruction* inst, int index, int element) { auto value = inst->Source(index)->AsUint64(element); - return *reinterpret_cast<double *>(&value); + return *reinterpret_cast<double*>(&value); } } // namespace generic
diff --git a/mpact/sim/generic/instruction_helpers.h b/mpact/sim/generic/instruction_helpers.h index b3d3b31..a86a46d 100644 --- a/mpact/sim/generic/instruction_helpers.h +++ b/mpact/sim/generic/instruction_helpers.h
@@ -34,12 +34,12 @@ // destination operand. This version supports different types for the result and // each of the two source operands. template <typename Result, typename Argument1, typename Argument2> -inline void BinaryOp(const Instruction *instruction, +inline void BinaryOp(const Instruction* instruction, std::function<Result(Argument1, Argument2)> operation) { Argument1 lhs = generic::GetInstructionSource<Argument1>(instruction, 0); Argument2 rhs = generic::GetInstructionSource<Argument2>(instruction, 1); Result dest_value = operation(lhs, rhs); - auto *db = instruction->Destination(0)->AllocateDataBuffer(); + auto* db = instruction->Destination(0)->AllocateDataBuffer(); db->SetSubmit<Result>(0, dest_value); } @@ -49,12 +49,12 @@ // destination operand. This version supports different types for the result // and the operands, but the two source operands must have the same type. template <typename Result, typename Argument> -inline void BinaryOp(const Instruction *instruction, +inline void BinaryOp(const Instruction* instruction, std::function<Result(Argument, Argument)> operation) { Argument lhs = generic::GetInstructionSource<Argument>(instruction, 0); Argument rhs = generic::GetInstructionSource<Argument>(instruction, 1); Result dest_value = operation(lhs, rhs); - auto *db = instruction->Destination(0)->AllocateDataBuffer(); + auto* db = instruction->Destination(0)->AllocateDataBuffer(); db->SetSubmit<Result>(0, dest_value); } @@ -64,12 +64,12 @@ // destination operand. This version requires both result and source operands // to have the same type. template <typename Result> -inline void BinaryOp(const Instruction *instruction, +inline void BinaryOp(const Instruction* instruction, std::function<Result(Result, Result)> operation) { Result lhs = generic::GetInstructionSource<Result>(instruction, 0); Result rhs = generic::GetInstructionSource<Result>(instruction, 1); Result dest_value = operation(lhs, rhs); - auto *db = instruction->Destination(0)->AllocateDataBuffer(); + auto* db = instruction->Destination(0)->AllocateDataBuffer(); db->SetSubmit<Result>(0, dest_value); } @@ -79,11 +79,11 @@ // destination operand. This version supports the result and argument having // different types. template <typename Result, typename Argument> -inline void UnaryOp(const Instruction *instruction, +inline void UnaryOp(const Instruction* instruction, std::function<Result(Argument)> operation) { Argument lhs = generic::GetInstructionSource<Argument>(instruction, 0); Result dest_value = operation(lhs); - auto *db = instruction->Destination(0)->AllocateDataBuffer(); + auto* db = instruction->Destination(0)->AllocateDataBuffer(); db->SetSubmit<Result>(0, dest_value); } @@ -93,11 +93,11 @@ // destination operand. This version requires that the result and argument have // the same type. template <typename Result> -inline void UnaryOp(const Instruction *instruction, +inline void UnaryOp(const Instruction* instruction, std::function<Result(Result)> operation) { Result lhs = generic::GetInstructionSource<Result>(instruction, 0); Result dest_value = operation(lhs); - auto *db = instruction->Destination(0)->AllocateDataBuffer(); + auto* db = instruction->Destination(0)->AllocateDataBuffer(); db->SetSubmit<Result>(0, dest_value); } @@ -107,10 +107,10 @@ template <typename Result, typename Argument1, typename Argument2, typename Argument3> inline void TernaryVectorOp( - const Instruction *instruction, + const Instruction* instruction, std::function<Result(Argument1, Argument2, Argument3)> operation) { - auto *dst = instruction->Destination(0); - auto *db = dst->AllocateDataBuffer(); + auto* dst = instruction->Destination(0); + auto* db = dst->AllocateDataBuffer(); int size = dst->shape()[0]; for (int i = 0; i < size; i++) { Argument1 x_val = @@ -131,10 +131,10 @@ // the arguments have to all have the same type. template <typename Result, typename Argument> inline void TernaryVectorOp( - const Instruction *instruction, + const Instruction* instruction, std::function<Result(Argument, Argument, Argument)> operation) { - auto *dst = instruction->Destination(0); - auto *db = dst->AllocateDataBuffer(); + auto* dst = instruction->Destination(0); + auto* db = dst->AllocateDataBuffer(); int size = dst->shape()[0]; for (int i = 0; i < size; i++) { Argument x_val = generic::GetInstructionSource<Argument>(instruction, 0, i); @@ -151,10 +151,10 @@ // requires the result and arguments to have the same type. template <typename Result> inline void TernaryVectorOp( - const Instruction *instruction, + const Instruction* instruction, std::function<Result(Result, Result, Result)> operation) { - auto *dst = instruction->Destination(0); - auto *db = dst->AllocateDataBuffer(); + auto* dst = instruction->Destination(0); + auto* db = dst->AllocateDataBuffer(); int size = dst->shape()[0]; for (int i = 0; i < size; i++) { Result x_val = generic::GetInstructionSource<Result>(instruction, 0, i); @@ -171,10 +171,10 @@ // allows for different types for the result and each argument. template <typename Result, typename Argument1, typename Argument2> inline void BinaryVectorOp( - const Instruction *instruction, + const Instruction* instruction, std::function<Result(Argument1, Argument2)> operation) { - auto *dst = instruction->Destination(0); - auto *db = dst->AllocateDataBuffer(); + auto* dst = instruction->Destination(0); + auto* db = dst->AllocateDataBuffer(); int size = dst->shape()[0]; for (int i = 0; i < size; i++) { Argument1 lhs = generic::GetInstructionSource<Argument1>(instruction, 0, i); @@ -191,10 +191,10 @@ // the arguments have to have the same type. template <typename Result, typename Argument> inline void BinaryVectorOp( - const Instruction *instruction, + const Instruction* instruction, std::function<Result(Argument, Argument)> operation) { - auto *dst = instruction->Destination(0); - auto *db = dst->AllocateDataBuffer(); + auto* dst = instruction->Destination(0); + auto* db = dst->AllocateDataBuffer(); int size = dst->shape()[0]; for (int i = 0; i < size; i++) { Argument lhs = generic::GetInstructionSource<Argument>(instruction, 0, i); @@ -209,10 +209,10 @@ // two operand vector instruction semantic functions. This version // requires the result and arguments to have the same type. template <typename Result> -inline void BinaryVectorOp(const Instruction *instruction, +inline void BinaryVectorOp(const Instruction* instruction, std::function<Result(Result, Result)> operation) { - auto *dst = instruction->Destination(0); - auto *db = dst->AllocateDataBuffer(); + auto* dst = instruction->Destination(0); + auto* db = dst->AllocateDataBuffer(); int size = dst->shape()[0]; for (int i = 0; i < size; i++) { Result lhs = generic::GetInstructionSource<Result>(instruction, 0, i); @@ -227,10 +227,10 @@ // single operand vector instruction semantic functions. This version // allows the result and argument to have different types. template <typename Result, typename Argument> -inline void UnaryVectorOp(const Instruction *instruction, +inline void UnaryVectorOp(const Instruction* instruction, std::function<Result(Argument)> operation) { - auto *dst = instruction->Destination(0); - auto *db = dst->AllocateDataBuffer(); + auto* dst = instruction->Destination(0); + auto* db = dst->AllocateDataBuffer(); int size = dst->shape()[0]; for (int i = 0; i < size; i++) { Argument lhs = generic::GetInstructionSource<Argument>(instruction, 0, i); @@ -244,10 +244,10 @@ // single operand vector instruction semantic functions. This version // requires the result and argument to have the same type. template <typename Result> -inline void UnaryVectorOp(const Instruction *instruction, +inline void UnaryVectorOp(const Instruction* instruction, std::function<Result(Result)> operation) { - auto *dst = instruction->Destination(0); - auto *db = dst->AllocateDataBuffer(); + auto* dst = instruction->Destination(0); + auto* db = dst->AllocateDataBuffer(); int size = dst->shape()[0]; for (int i = 0; i < size; i++) { Result lhs = generic::GetInstructionSource<Result>(instruction, 0, i);
diff --git a/mpact/sim/generic/literal_operand.h b/mpact/sim/generic/literal_operand.h index c74cba2..1f47377 100644 --- a/mpact/sim/generic/literal_operand.h +++ b/mpact/sim/generic/literal_operand.h
@@ -56,9 +56,9 @@ public: BoolLiteralOperand() : as_string_(absl::StrCat(literal)) {} BoolLiteralOperand(absl::string_view as_string) : as_string_(as_string) {} - BoolLiteralOperand(const std::vector<int> &shape, absl::string_view as_string) + BoolLiteralOperand(const std::vector<int>& shape, absl::string_view as_string) : shape_(shape), as_string_(as_string) {} - explicit BoolLiteralOperand(const std::vector<int> &shape) + explicit BoolLiteralOperand(const std::vector<int>& shape) : BoolLiteralOperand(shape, absl::StrCat(literal)) {} // Methods for accessing the literal value. Always returns the same @@ -95,9 +95,9 @@ public: IntLiteralOperand() : as_string_(absl::StrCat(literal)) {}; IntLiteralOperand(absl::string_view as_string) : as_string_(as_string) {} - IntLiteralOperand(const std::vector<int> &shape, absl::string_view as_string) + IntLiteralOperand(const std::vector<int>& shape, absl::string_view as_string) : shape_(shape), as_string_(as_string) {} - explicit IntLiteralOperand(const std::vector<int> &shape) + explicit IntLiteralOperand(const std::vector<int>& shape) : IntLiteralOperand(shape, absl::StrCat(literal)) {} // Methods for accessing the immediate value. Always returns the same
diff --git a/mpact/sim/generic/operand_interface.h b/mpact/sim/generic/operand_interface.h index e39adc5..21ee4b2 100644 --- a/mpact/sim/generic/operand_interface.h +++ b/mpact/sim/generic/operand_interface.h
@@ -88,14 +88,14 @@ public: virtual ~DestinationOperandInterface() = default; // Allocates a data buffer with ownership, latency and delay line set up. - virtual DataBuffer *AllocateDataBuffer() = 0; + virtual DataBuffer* AllocateDataBuffer() = 0; // Takes an existing data buffer, and initializes it for the destination // as if AllocateDataBuffer had been called. - virtual void InitializeDataBuffer(DataBuffer *db) = 0; + virtual void InitializeDataBuffer(DataBuffer* db) = 0; // Allocates and initializes data buffer as if AllocateDataBuffer had been // called, but also copies in the value from the current value of the // destination. - virtual DataBuffer *CopyDataBuffer() = 0; + virtual DataBuffer* CopyDataBuffer() = 0; // Returns the latency associated with the destination operand. virtual int latency() const = 0; // Return a pointer to the object instance that implements the state in
diff --git a/mpact/sim/generic/program_error.cc b/mpact/sim/generic/program_error.cc index daf4589..a566108 100644 --- a/mpact/sim/generic/program_error.cc +++ b/mpact/sim/generic/program_error.cc
@@ -83,7 +83,7 @@ } void ProgramErrorController::ClearAll() { - for (auto &entry : program_error_info_) { + for (auto& entry : program_error_info_) { entry.error_messages.clear(); } unmasked_program_errors_.clear(); @@ -167,7 +167,7 @@ return names; } -const std::vector<std::string> &ProgramErrorController::GetErrorMessages( +const std::vector<std::string>& ProgramErrorController::GetErrorMessages( absl::string_view program_error_name) { auto entry = program_error_map_.find(program_error_name); if (program_error_map_.end() != entry) { @@ -202,7 +202,7 @@ // Constructor and method for class ProgramError. ProgramError::ProgramError(absl::string_view name, - ProgramErrorController *controller) + ProgramErrorController* controller) : name_(name), controller_(controller) {} void ProgramError::Raise(absl::string_view error_message) {
diff --git a/mpact/sim/generic/program_error.h b/mpact/sim/generic/program_error.h index 0e80581..d9a2635 100644 --- a/mpact/sim/generic/program_error.h +++ b/mpact/sim/generic/program_error.h
@@ -92,7 +92,7 @@ // named program error. If there is no such program_error_name the internal // error is raised (see kInternalErrorName), and the error messages for that // are returned. - const std::vector<std::string> &GetErrorMessages( + const std::vector<std::string>& GetErrorMessages( absl::string_view program_error_name); // Raises the named program error and adds the error message to its message @@ -142,7 +142,7 @@ private: // The constructor is private, as the handle is obtained from a // ProgramErrorController instance. - ProgramError(absl::string_view name, ProgramErrorController *controller); + ProgramError(absl::string_view name, ProgramErrorController* controller); public: // Raise the error to the ProgramErrorController with the given additional @@ -153,7 +153,7 @@ private: std::string name_; - ProgramErrorController *controller_; + ProgramErrorController* controller_; }; } // namespace generic
diff --git a/mpact/sim/generic/register.cc b/mpact/sim/generic/register.cc index 99c976e..bf7c79a 100644 --- a/mpact/sim/generic/register.cc +++ b/mpact/sim/generic/register.cc
@@ -27,12 +27,12 @@ namespace sim { namespace generic { -RegisterBase::RegisterBase(ArchState *state, absl::string_view name, - const std::vector<int> &shape, int unit_size) +RegisterBase::RegisterBase(ArchState* state, absl::string_view name, + const std::vector<int>& shape, int unit_size) : StateItemBase(state, name, shape, unit_size), data_buffer_(nullptr) { // Initialize register with a data buffer set to 0. if (state != nullptr) { - auto *db = state->db_factory()->Allocate<uint8_t>(size()); + auto* db = state->db_factory()->Allocate<uint8_t>(size()); std::memset(db->raw_ptr(), 0, size()); SetDataBuffer(db); db->DecRef(); @@ -46,7 +46,7 @@ } } -void RegisterBase::SetDataBuffer(DataBuffer *db) { +void RegisterBase::SetDataBuffer(DataBuffer* db) { // For now, ignore if the sizes don't match. // ABSL_HARDENING_ASSERT(db->size<uint8_t>() == size()); if (nullptr != data_buffer_) { @@ -56,14 +56,14 @@ data_buffer_ = db; } -ReservedRegisterBase::ReservedRegisterBase(ArchState *state, +ReservedRegisterBase::ReservedRegisterBase(ArchState* state, absl::string_view name, - const std::vector<int> &shape, + const std::vector<int>& shape, int unit_size, - SimpleResource *resource) + SimpleResource* resource) : RegisterBase(state, name, shape, unit_size), resource_(resource) {} -void ReservedRegisterBase::SetDataBuffer(DataBuffer *db) { +void ReservedRegisterBase::SetDataBuffer(DataBuffer* db) { // Use the base class to update the data buffer. RegisterBase::SetDataBuffer(db); // Release the resource if set.
diff --git a/mpact/sim/generic/register.h b/mpact/sim/generic/register.h index b25861b..36c042b 100644 --- a/mpact/sim/generic/register.h +++ b/mpact/sim/generic/register.h
@@ -48,8 +48,8 @@ class RegisterSourceOperand : public SourceOperandInterface { public: // Constructor. Note, default constructor deleted. - RegisterSourceOperand(RegisterBase *reg, std::string op_name); - explicit RegisterSourceOperand(RegisterBase *reg); + RegisterSourceOperand(RegisterBase* reg, std::string op_name); + explicit RegisterSourceOperand(RegisterBase* reg); RegisterSourceOperand() = delete; @@ -72,14 +72,14 @@ // Returns the RegisterBase object wrapped in absl::any. std::any GetObject() const override { return std::any(register_); } // Non-inherited method to get the register object. - RegisterBase *GetRegister() const { return register_; } + RegisterBase* GetRegister() const { return register_; } // Returns the shape of the register. std::vector<int> shape() const override; std::string AsString() const override { return op_name_; } private: - RegisterBase *register_; + RegisterBase* register_; std::string op_name_; }; @@ -89,23 +89,23 @@ class RegisterDestinationOperand : public DestinationOperandInterface { public: // Constructor and Destructor - RegisterDestinationOperand(RegisterBase *reg, int latency); - RegisterDestinationOperand(RegisterBase *reg, int latency, + RegisterDestinationOperand(RegisterBase* reg, int latency); + RegisterDestinationOperand(RegisterBase* reg, int latency, std::string op_name); RegisterDestinationOperand() = delete; // Initializes the DataBuffer instance so that when Submit is called, it can // be entered into the correct delay line, with the correct latency, targeting // the correct register. - void InitializeDataBuffer(DataBuffer *db) override; + void InitializeDataBuffer(DataBuffer* db) override; // Allocates and returns an initialized DataBuffer instance that contains a // copy of the current value of the register. This is useful when only part // of the destination register will be modified. - DataBuffer *CopyDataBuffer() override; + DataBuffer* CopyDataBuffer() override; // Allocates and returns an initialized DataBuffer instance. - DataBuffer *AllocateDataBuffer() final; + DataBuffer* AllocateDataBuffer() final; // Returns the latency associated with writes to this register operand. int latency() const override { return latency_; } @@ -113,7 +113,7 @@ // Returns the RegisterBase object wrapped in absl::any. std::any GetObject() const override { return std::any(register_); } // Non-inherited method to get the register object. - RegisterBase *GetRegister() const { return register_; } + RegisterBase* GetRegister() const { return register_; } // Returns the shape of the underlying register (the number of elements in // each dimension). For instance {0} indicates a scalar quantity, whereas @@ -123,10 +123,10 @@ std::string AsString() const override { return op_name_; } private: - RegisterBase *register_; - DataBufferFactory *db_factory_; + RegisterBase* register_; + DataBufferFactory* db_factory_; int latency_; - DataBufferDelayLine *delay_line_; + DataBufferDelayLine* delay_line_; std::string op_name_; }; @@ -141,21 +141,21 @@ // protected section below. ~RegisterBase() override; RegisterBase() = delete; - RegisterBase(const RegisterBase &) = delete; - RegisterBase &operator=(const RegisterBase &) = delete; + RegisterBase(const RegisterBase&) = delete; + RegisterBase& operator=(const RegisterBase&) = delete; // DecRef's the current data buffer and replaces it with a new one. - void SetDataBuffer(DataBuffer *db) override; + void SetDataBuffer(DataBuffer* db) override; // Returns a pointer to the DataBuffer that contains the current value of // the register. - DataBuffer *data_buffer() const { return data_buffer_; } + DataBuffer* data_buffer() const { return data_buffer_; } protected: - RegisterBase(ArchState *state, absl::string_view name, - const std::vector<int> &shape, int unit_size); + RegisterBase(ArchState* state, absl::string_view name, + const std::vector<int>& shape, int unit_size); private: - DataBuffer *data_buffer_; + DataBuffer* data_buffer_; std::vector<UpdateCallbackFunction> next_update_callbacks_; }; @@ -165,24 +165,24 @@ class ReservedRegisterBase : public RegisterBase { public: ReservedRegisterBase() = delete; - ReservedRegisterBase(const ReservedRegisterBase &) = delete; - ReservedRegisterBase &operator=(const ReservedRegisterBase &) = delete; + ReservedRegisterBase(const ReservedRegisterBase&) = delete; + ReservedRegisterBase& operator=(const ReservedRegisterBase&) = delete; // Override the SetDataBuffer to release the SimpleResource instance when // called. - void SetDataBuffer(DataBuffer *db) override; + void SetDataBuffer(DataBuffer* db) override; // Accessor. - SimpleResource *resource() const { return resource_; } + SimpleResource* resource() const { return resource_; } protected: - ReservedRegisterBase(ArchState *state, absl::string_view name, - const std::vector<int> &shape, int unit_size, - SimpleResource *resource); + ReservedRegisterBase(ArchState* state, absl::string_view name, + const std::vector<int>& shape, int unit_size, + SimpleResource* resource); private: // SimpleResource instance associated with the register. - SimpleResource *resource_; + SimpleResource* resource_; }; // Scalar register type with value type ElementType. @@ -224,12 +224,12 @@ RegisterDestinationOperand<ElementType>, M, N>; template <typename T> -RegisterSourceOperand<T>::RegisterSourceOperand(RegisterBase *reg, +RegisterSourceOperand<T>::RegisterSourceOperand(RegisterBase* reg, const std::string op_name) : register_(reg), op_name_(op_name) {} template <typename T> -RegisterSourceOperand<T>::RegisterSourceOperand(RegisterBase *reg) +RegisterSourceOperand<T>::RegisterSourceOperand(RegisterBase* reg) : RegisterSourceOperand(reg, reg->name()) {} template <typename T> @@ -279,7 +279,7 @@ } template <typename T> -RegisterDestinationOperand<T>::RegisterDestinationOperand(RegisterBase *reg, +RegisterDestinationOperand<T>::RegisterDestinationOperand(RegisterBase* reg, int latency, std::string op_name) : register_(reg), @@ -289,27 +289,27 @@ op_name_(op_name) {} template <typename T> -RegisterDestinationOperand<T>::RegisterDestinationOperand(RegisterBase *reg, +RegisterDestinationOperand<T>::RegisterDestinationOperand(RegisterBase* reg, int latency) : RegisterDestinationOperand(reg, latency, reg->name()) {} template <typename T> -void RegisterDestinationOperand<T>::InitializeDataBuffer(DataBuffer *db) { +void RegisterDestinationOperand<T>::InitializeDataBuffer(DataBuffer* db) { db->set_destination(register_); db->set_latency(latency_); db->set_delay_line(delay_line_); } template <typename T> -DataBuffer *RegisterDestinationOperand<T>::CopyDataBuffer() { - DataBuffer *db = db_factory_->MakeCopyOf(register_->data_buffer()); +DataBuffer* RegisterDestinationOperand<T>::CopyDataBuffer() { + DataBuffer* db = db_factory_->MakeCopyOf(register_->data_buffer()); InitializeDataBuffer(db); return db; } template <typename T> -DataBuffer *RegisterDestinationOperand<T>::AllocateDataBuffer() { - DataBuffer *db = db_factory_->Allocate(register_->size()); +DataBuffer* RegisterDestinationOperand<T>::AllocateDataBuffer() { + DataBuffer* db = db_factory_->Allocate(register_->size()); InitializeDataBuffer(db); return db; }
diff --git a/mpact/sim/generic/resource_bitset.h b/mpact/sim/generic/resource_bitset.h index c9773ac..5d0f848 100644 --- a/mpact/sim/generic/resource_bitset.h +++ b/mpact/sim/generic/resource_bitset.h
@@ -28,9 +28,9 @@ class ResourceBitSet { public: ResourceBitSet() = default; - ResourceBitSet(const ResourceBitSet &rhs); - ResourceBitSet(ResourceBitSet &&rhs); - ResourceBitSet &operator=(const ResourceBitSet &rhs); + ResourceBitSet(const ResourceBitSet& rhs); + ResourceBitSet(ResourceBitSet&& rhs); + ResourceBitSet& operator=(const ResourceBitSet& rhs); explicit ResourceBitSet(int bit_size); ~ResourceBitSet(); @@ -39,22 +39,22 @@ // Add rhs bitset content to this. If the size of rhs is greater than this, // resize this to match. If the size of this is larger than rhs, the bits not // in rhs are assumed to be zero. - void Or(const ResourceBitSet &rhs); + void Or(const ResourceBitSet& rhs); // Remove rhs bitset content from this. If the size of rhs is greater than // this, the additional bits are ignored. If this is larger than rhs, the // missing rhs bits are assumed to be zero. - void AndNot(const ResourceBitSet &rhs); + void AndNot(const ResourceBitSet& rhs); // Return true if the bitsets have a non-empty intersection. If either is // larger than the other, the "missing" bits are assumed to be zero. - bool IsIntersectionNonEmpty(const ResourceBitSet &rhs) const; + bool IsIntersectionNonEmpty(const ResourceBitSet& rhs) const; // Locate the first bit set. If there is no such bit // return false, otherwise, return true and set *position to the position of // that bit. - bool FindFirstSetBit(int *position) const; + bool FindFirstSetBit(int* position) const; // Locate the first bit set at or after *position. If there is no such bit // return false, otherwise, return true and set *position to the position of // that bit. - bool FindNextSetBit(int *position) const; + bool FindNextSetBit(int* position) const; // Return the number of set bits. int GetOnesCount() const; // Make the bitsize at least size bits long. @@ -63,7 +63,7 @@ private: using UInt = uint64_t; static constexpr int kBitsInUint = sizeof(UInt) * 8; - UInt *bits_ = nullptr; + UInt* bits_ = nullptr; int size_ = 0; };
diff --git a/mpact/sim/generic/simple_resource.cc b/mpact/sim/generic/simple_resource.cc index 3b9a9d7..5602305 100644 --- a/mpact/sim/generic/simple_resource.cc +++ b/mpact/sim/generic/simple_resource.cc
@@ -18,7 +18,9 @@ #include "absl/log/log.h" #include "absl/status/status.h" +#include "absl/status/statusor.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" namespace mpact { namespace sim { @@ -26,7 +28,7 @@ // Initialize the bitmap and set the bit specified by index. SimpleResource::SimpleResource(absl::string_view name, int index, - SimpleResourcePool *pool) + SimpleResourcePool* pool) : name_(name), index_(index), pool_(pool) { resource_bit_.Resize(pool_->width()); resource_bit_.Set(index); @@ -39,13 +41,13 @@ bool SimpleResource::IsFree() const { return pool_->IsFree(this); } -SimpleResourceSet::SimpleResourceSet(SimpleResourcePool *pool) : pool_(pool) { +SimpleResourceSet::SimpleResourceSet(SimpleResourcePool* pool) : pool_(pool) { resource_vector_.Resize(pool_->width()); } // Verify that the resource comes from the same pool. If so, add it (union with) // the bitmap. Return appropriate status. -absl::Status SimpleResourceSet::AddResource(SimpleResource *resource) { +absl::Status SimpleResourceSet::AddResource(SimpleResource* resource) { // If the resource is nullptr, just return ok status. if (resource == nullptr) return absl::OkStatus(); // Make sure it belongs to the same pool as the resource set. @@ -61,7 +63,7 @@ // If the resource doesn't exist, add it to the resource pool, before adding it // to the resource set. absl::Status SimpleResourceSet::AddResource(absl::string_view name) { - SimpleResource *resource = pool_->GetResource(name); + SimpleResource* resource = pool_->GetResource(name); if (nullptr == resource) { auto status = pool_->AddResource(name); if (!status.ok()) return status; @@ -83,7 +85,7 @@ std::string out = "["; std::string sep; for (int index = 0; resource_vector_.FindNextSetBit(&index); ++index) { - auto *resource = pool_->GetResource(index); + auto* resource = pool_->GetResource(index); if (resource == nullptr) { LOG(ERROR) << absl::StrCat("Cannot find resource (", index, ") in pool '", pool_->name(), "'"); @@ -102,7 +104,7 @@ } SimpleResourcePool::~SimpleResourcePool() { - for (const auto &entry : resource_name_map_) { + for (const auto& entry : resource_name_map_) { delete entry.second; } resource_name_map_.clear(); @@ -114,7 +116,7 @@ // Add named resource to the pool. If the pool has reached maximum size, return // an error. -absl::StatusOr<SimpleResource *> SimpleResourcePool::AddResourceInternal( +absl::StatusOr<SimpleResource*> SimpleResourcePool::AddResourceInternal( absl::string_view name) { if (resource_name_map_.size() == width_) { return absl::InternalError(absl::StrCat( @@ -127,7 +129,7 @@ "' already exists in pool '", name_, "'")); } int index = resource_name_map_.size(); - SimpleResource *resource = new SimpleResource(name, index, this); + SimpleResource* resource = new SimpleResource(name, index, this); resource_name_map_.emplace(name, resource); resources_.push_back(resource); return resource; @@ -140,19 +142,19 @@ return result.status(); } -SimpleResource *SimpleResourcePool::GetResource(unsigned index) const { +SimpleResource* SimpleResourcePool::GetResource(unsigned index) const { if ((index < 0) || (index >= resources_.size())) return nullptr; return resources_[index]; } -SimpleResource *SimpleResourcePool::GetResource(absl::string_view name) const { +SimpleResource* SimpleResourcePool::GetResource(absl::string_view name) const { auto ptr = resource_name_map_.find(name); if (ptr == resource_name_map_.end()) return nullptr; return ptr->second; } -SimpleResource *SimpleResourcePool::GetOrAddResource(absl::string_view name) { - auto *resource = GetResource(name); +SimpleResource* SimpleResourcePool::GetOrAddResource(absl::string_view name) { + auto* resource = GetResource(name); if (resource != nullptr) return resource; auto result = AddResourceInternal(name); @@ -165,7 +167,7 @@ return result.value(); } -SimpleResourceSet *SimpleResourcePool::CreateResourceSet() { +SimpleResourceSet* SimpleResourcePool::CreateResourceSet() { resource_sets_.push_front(new SimpleResourceSet(this)); return resource_sets_.front(); } @@ -173,28 +175,28 @@ // Bitmap operations to reserve, free and check resources. Union with a bitmap // from a resource or resource set to reserve (set), difference to free (clear), // and non-empty intersection (non-zero and) to check. -bool SimpleResourcePool::IsFree(const SimpleResourceSet *resource_set) const { +bool SimpleResourcePool::IsFree(const SimpleResourceSet* resource_set) const { return !resource_vector_.IsIntersectionNonEmpty( resource_set->resource_vector()); } -bool SimpleResourcePool::IsFree(const SimpleResource *resource) const { +bool SimpleResourcePool::IsFree(const SimpleResource* resource) const { return !resource_vector_.IsIntersectionNonEmpty(resource->resource_bit()); } -void SimpleResourcePool::Acquire(const SimpleResourceSet *resource_set) { +void SimpleResourcePool::Acquire(const SimpleResourceSet* resource_set) { resource_vector_.Or(resource_set->resource_vector()); } -void SimpleResourcePool::Acquire(const SimpleResource *resource) { +void SimpleResourcePool::Acquire(const SimpleResource* resource) { resource_vector_.Or(resource->resource_bit()); } -void SimpleResourcePool::Release(const SimpleResourceSet *resource_set) { +void SimpleResourcePool::Release(const SimpleResourceSet* resource_set) { resource_vector_.AndNot(resource_set->resource_vector()); } -void SimpleResourcePool::Release(const SimpleResource *resource) { +void SimpleResourcePool::Release(const SimpleResource* resource) { resource_vector_.AndNot(resource->resource_bit()); } @@ -202,7 +204,7 @@ std::string out = "["; std::string sep; for (int index = 0; resource_vector_.FindNextSetBit(&index); ++index) { - auto *resource = resources_[index]; + auto* resource = resources_[index]; if (resource == nullptr) { LOG(ERROR) << absl::StrCat("Cannot find resource (", index, ") in pool '", name(), "'");
diff --git a/mpact/sim/generic/simple_resource.h b/mpact/sim/generic/simple_resource.h index cba7234..1883f07 100644 --- a/mpact/sim/generic/simple_resource.h +++ b/mpact/sim/generic/simple_resource.h
@@ -22,6 +22,7 @@ #include "absl/container/flat_hash_map.h" #include "absl/status/status.h" #include "absl/status/statusor.h" +#include "absl/strings/string_view.h" #include "mpact/sim/generic/resource_bitset.h" namespace mpact { @@ -59,7 +60,7 @@ private: // The constructor is private. It is called from a SimpleResourcePool // instance in which the resource belongs. - SimpleResource(absl::string_view name, int index, SimpleResourcePool *pool); + SimpleResource(absl::string_view name, int index, SimpleResourcePool* pool); SimpleResource() = delete; virtual ~SimpleResource() = default; @@ -73,20 +74,20 @@ bool IsFree() const; // Returns the "one hot" bitvector for the resource. - const ResourceBitSet &resource_bit() const { return resource_bit_; } + const ResourceBitSet& resource_bit() const { return resource_bit_; } // The bit index of the resource in the bitvector. int index() const { return index_; } // Other accessors. - const std::string &name() const { return name_; } - const SimpleResourcePool *pool() const { return pool_; } + const std::string& name() const { return name_; } + const SimpleResourcePool* pool() const { return pool_; } private: ResourceBitSet resource_bit_; std::string name_; int index_; - SimpleResourcePool *pool_; + SimpleResourcePool* pool_; }; // The SimpleResourceSet models a set of individual SimpleResources that are @@ -95,14 +96,14 @@ friend class SimpleResourcePool; private: - explicit SimpleResourceSet(SimpleResourcePool *); + explicit SimpleResourceSet(SimpleResourcePool*); SimpleResourceSet() = delete; virtual ~SimpleResourceSet() = default; public: // Adds the resource to the resource set. Return error if the resource // belongs to a different pool. - absl::Status AddResource(SimpleResource *resource); + absl::Status AddResource(SimpleResource* resource); absl::Status AddResource(absl::string_view name); // Mark the resources in the set reserved in the associated resource pool. @@ -118,11 +119,11 @@ std::string AsString() const; // Return the bit vector for the resources in this set. - const ResourceBitSet &resource_vector() const { return resource_vector_; } + const ResourceBitSet& resource_vector() const { return resource_vector_; } private: ResourceBitSet resource_vector_; - SimpleResourcePool *pool_; + SimpleResourcePool* pool_; }; // The SimpleResourcePool is a class for managing a group of SimpleResource @@ -141,45 +142,45 @@ // Return the SimpleResource pointer of the named resource, or nullptr if it // hasn't been added. - SimpleResource *GetResource(absl::string_view name) const; + SimpleResource* GetResource(absl::string_view name) const; // Return the SimpleResource pointer of resource with bit index 'index', or // nullptr if it hasn't been added. - SimpleResource *GetResource(unsigned index) const; + SimpleResource* GetResource(unsigned index) const; // If the resource does not exisit, add it. Return a pointer to the named // resource. - SimpleResource *GetOrAddResource(absl::string_view name); + SimpleResource* GetOrAddResource(absl::string_view name); // Create an resource set for the current resource pool. - SimpleResourceSet *CreateResourceSet(); + SimpleResourceSet* CreateResourceSet(); // Return true if the resources in the resource/resource set are not reserved // in the resource pool. - bool IsFree(const SimpleResourceSet *resource_set) const; - bool IsFree(const SimpleResource *resource) const; + bool IsFree(const SimpleResourceSet* resource_set) const; + bool IsFree(const SimpleResource* resource) const; // Mark the resource/resource set reserved in the resource pool. - void Acquire(const SimpleResourceSet *resource_set); - void Acquire(const SimpleResource *resource); + void Acquire(const SimpleResourceSet* resource_set); + void Acquire(const SimpleResource* resource); // Mark the resource/resource set unreserved in the resource pool. - void Release(const SimpleResourceSet *resource_set); - void Release(const SimpleResource *resource); + void Release(const SimpleResourceSet* resource_set); + void Release(const SimpleResource* resource); // List reserved resources as string. std::string ReservedAsString() const; // Accessors. - const std::string &name() const { return name_; } - const ResourceBitSet &resource_vector() const { return resource_vector_; } + const std::string& name() const { return name_; } + const ResourceBitSet& resource_vector() const { return resource_vector_; } // The width is the max number of resources (i.e., bitwidth of the resource // vector). unsigned width() const { return width_; } private: - absl::StatusOr<SimpleResource *> AddResourceInternal(absl::string_view name); - absl::flat_hash_map<std::string, SimpleResource *> resource_name_map_; - std::vector<SimpleResource *> resources_; - std::list<SimpleResourceSet *> resource_sets_; + absl::StatusOr<SimpleResource*> AddResourceInternal(absl::string_view name); + absl::flat_hash_map<std::string, SimpleResource*> resource_name_map_; + std::vector<SimpleResource*> resources_; + std::list<SimpleResourceSet*> resource_sets_; ResourceBitSet resource_vector_; std::string name_; unsigned width_;
diff --git a/mpact/sim/generic/simple_resource_operand.h b/mpact/sim/generic/simple_resource_operand.h index 32a3547..9b6f9b9 100644 --- a/mpact/sim/generic/simple_resource_operand.h +++ b/mpact/sim/generic/simple_resource_operand.h
@@ -30,7 +30,7 @@ class SimpleResourceDelayRecord { public: SimpleResourceDelayRecord() = delete; - explicit SimpleResourceDelayRecord(SimpleResourceSet *resource_set) + explicit SimpleResourceDelayRecord(SimpleResourceSet* resource_set) : resource_set_(resource_set) {} ~SimpleResourceDelayRecord() = default; @@ -38,7 +38,7 @@ void Apply() { resource_set_->Release(); } private: - SimpleResourceSet *resource_set_; + SimpleResourceSet* resource_set_; }; // Type def for the SimpleResourceDelayLine. @@ -53,12 +53,12 @@ class SimpleResourceOperand : public ResourceOperandInterface { public: // Constructors and Destructors. Default constructor deleted. - SimpleResourceOperand(SimpleResourceSet *resource_set, int latency, - SimpleResourceDelayLine *delay_line) + SimpleResourceOperand(SimpleResourceSet* resource_set, int latency, + SimpleResourceDelayLine* delay_line) : resource_set_(resource_set), latency_(latency), delay_line_(delay_line) {} - SimpleResourceOperand(SimpleResourceSet *resource_set, int latency) + SimpleResourceOperand(SimpleResourceSet* resource_set, int latency) : SimpleResourceOperand(resource_set, latency, nullptr) {} SimpleResourceOperand() = delete; ~SimpleResourceOperand() override = default; @@ -87,20 +87,20 @@ std::string AsString() const override { return resource_set_->AsString(); } // Accessor. - void set_delay_line(SimpleResourceDelayLine *delay_line) { + void set_delay_line(SimpleResourceDelayLine* delay_line) { delay_line_ = delay_line; } - SimpleResourceSet *resource_set() const { return resource_set_; } + SimpleResourceSet* resource_set() const { return resource_set_; } int latency() const { return latency_; } private: // Pointer to the resource set that will be released. - SimpleResourceSet *resource_set_ = nullptr; + SimpleResourceSet* resource_set_ = nullptr; // Latency of the release. 0 = immediate, 1 = before next cycle, etc. int latency_; // Pointer to the delay line to be used. - SimpleResourceDelayLine *delay_line_; + SimpleResourceDelayLine* delay_line_; }; } // namespace generic
diff --git a/mpact/sim/generic/state_item.h b/mpact/sim/generic/state_item.h index 1df112c..6abe682 100644 --- a/mpact/sim/generic/state_item.h +++ b/mpact/sim/generic/state_item.h
@@ -67,18 +67,18 @@ public: using ValueType = ElementType; template <typename... Ps> - explicit StateItem(ArchState *arch_state, absl::string_view name, Ps... pargs) + explicit StateItem(ArchState* arch_state, absl::string_view name, Ps... pargs) : BaseType(arch_state, name, {1}, sizeof(ElementType), pargs...) {} - virtual SourceOperandInterface *CreateSourceOperand() { + virtual SourceOperandInterface* CreateSourceOperand() { return new SourceOperandType(this); } - virtual DestinationOperandInterface *CreateDestinationOperand(int latency) { + virtual DestinationOperandInterface* CreateDestinationOperand(int latency) { return new DestinationOperandType(this, latency); } - virtual SourceOperandInterface *CreateSourceOperand(std::string op_name) { + virtual SourceOperandInterface* CreateSourceOperand(std::string op_name) { return new SourceOperandType(this, op_name); } - virtual DestinationOperandInterface *CreateDestinationOperand( + virtual DestinationOperandInterface* CreateDestinationOperand( int latency, std::string op_name) { return new DestinationOperandType(this, latency, op_name); } @@ -88,28 +88,28 @@ // element type. The element type should be uint8_t (so it is a byte array). template <typename BaseType, typename ElementType, typename SourceOperandType, typename DestinationOperandType> -class StateItem<BaseType, ElementType *, SourceOperandType, +class StateItem<BaseType, ElementType*, SourceOperandType, DestinationOperandType> : public BaseType { public: using ValueType = ElementType; template <typename... Ps> - explicit StateItem(ArchState *arch_state, absl::string_view name, int width, + explicit StateItem(ArchState* arch_state, absl::string_view name, int width, Ps... pargs) : BaseType(arch_state, name, {width}, sizeof(ElementType), pargs...) { static_assert(std::is_same<ElementType, uint8_t>::value, "Element type must be 'uint8_t'"); } - virtual SourceOperandInterface *CreateSourceOperand() { + virtual SourceOperandInterface* CreateSourceOperand() { return new SourceOperandType(this); } - virtual SourceOperandInterface *CreateSourceOperand(std::string op_name) { + virtual SourceOperandInterface* CreateSourceOperand(std::string op_name) { return new SourceOperandType(this, op_name); } - virtual DestinationOperandInterface *CreateDestinationOperand( + virtual DestinationOperandInterface* CreateDestinationOperand( int latency, std::string op_name) { return new DestinationOperandType(this, latency, op_name); } - virtual DestinationOperandInterface *CreateDestinationOperand(int latency) { + virtual DestinationOperandInterface* CreateDestinationOperand(int latency) { return new DestinationOperandType(this, latency); } }; @@ -122,12 +122,12 @@ public: using ValueType = ElementType; template <typename... Ps> - explicit StateItem(ArchState *arch_state, absl::string_view name, Ps... pargs) + explicit StateItem(ArchState* arch_state, absl::string_view name, Ps... pargs) : BaseType(arch_state, name, {1}, sizeof(ElementType), pargs...) {} - virtual SourceOperandInterface *CreateSourceOperand() { + virtual SourceOperandInterface* CreateSourceOperand() { return new SourceOperandType(this); } - virtual SourceOperandInterface *CreateSourceOperand(std::string op_name) { + virtual SourceOperandInterface* CreateSourceOperand(std::string op_name) { return new SourceOperandType(this, op_name); } }; @@ -142,19 +142,19 @@ static constexpr int kNumDimensions = 1; static constexpr int kShape[] = {N}; template <typename... Ps> - explicit StateItem(ArchState *arch_state, absl::string_view name, Ps... pargs) + explicit StateItem(ArchState* arch_state, absl::string_view name, Ps... pargs) : BaseType(arch_state, name, {N}, sizeof(ElementType), pargs...) {} // Source/destination operand creation interface. - virtual SourceOperandInterface *CreateSourceOperand() { + virtual SourceOperandInterface* CreateSourceOperand() { return new SourceOperandType(this); } - virtual DestinationOperandInterface *CreateDestinationOperand(int latency) { + virtual DestinationOperandInterface* CreateDestinationOperand(int latency) { return new DestinationOperandType(this, latency); } - virtual SourceOperandInterface *CreateSourceOperand(std::string op_name) { + virtual SourceOperandInterface* CreateSourceOperand(std::string op_name) { return new SourceOperandType(this, op_name); } - virtual DestinationOperandInterface *CreateDestinationOperand( + virtual DestinationOperandInterface* CreateDestinationOperand( int latency, std::string op_name) { return new DestinationOperandType(this, latency, op_name); } @@ -170,18 +170,18 @@ static constexpr int kNumDimensions = 2; static constexpr int kShape[] = {M, N}; template <typename... Ps> - explicit StateItem(ArchState *arch_state, absl::string_view name, Ps... pargs) + explicit StateItem(ArchState* arch_state, absl::string_view name, Ps... pargs) : BaseType(arch_state, name, {M, N}, sizeof(ElementType), pargs...) {} - virtual SourceOperandInterface *CreateSourceOperand() { + virtual SourceOperandInterface* CreateSourceOperand() { return new SourceOperandType(this); } - virtual DestinationOperandInterface *CreateDestinationOperand(int latency) { + virtual DestinationOperandInterface* CreateDestinationOperand(int latency) { return new DestinationOperandType(this, latency); } - virtual SourceOperandInterface *CreateSourceOperand(std::string op_name) { + virtual SourceOperandInterface* CreateSourceOperand(std::string op_name) { return new SourceOperandType(this, op_name); } - virtual DestinationOperandInterface *CreateDestinationOperand( + virtual DestinationOperandInterface* CreateDestinationOperand( int latency, std::string op_name) { return new DestinationOperandType(this, latency, op_name); }
diff --git a/mpact/sim/generic/state_item_base.cc b/mpact/sim/generic/state_item_base.cc index 896a27b..a43809b 100644 --- a/mpact/sim/generic/state_item_base.cc +++ b/mpact/sim/generic/state_item_base.cc
@@ -22,9 +22,9 @@ namespace sim { namespace generic { -StateItemBase::StateItemBase(class ArchState *arch_state, +StateItemBase::StateItemBase(class ArchState* arch_state, absl::string_view name, - const std::vector<int> &shape, int element_size) + const std::vector<int>& shape, int element_size) : arch_state_(arch_state), name_(name), shape_(shape),
diff --git a/mpact/sim/generic/state_item_base.h b/mpact/sim/generic/state_item_base.h index 6ca3df4..455dd3a 100644 --- a/mpact/sim/generic/state_item_base.h +++ b/mpact/sim/generic/state_item_base.h
@@ -36,14 +36,14 @@ class StateItemBase : public DataBufferDestination { protected: // Only constructed from derived classes - StateItemBase(ArchState *arch_state, absl::string_view name, - const std::vector<int> &shape, int element_size); + StateItemBase(ArchState* arch_state, absl::string_view name, + const std::vector<int>& shape, int element_size); StateItemBase() = delete; - StateItemBase(const StateItemBase &) = delete; + StateItemBase(const StateItemBase&) = delete; public: // Name() returns the state item's name. - const std::string &name() const { return name_; } + const std::string& name() const { return name_; } // Returns the size vector of the state item. A scalar element has size // vector {1}, an N element vector item has size vector {N}, and @@ -58,10 +58,10 @@ // Returns the architecture state object that this simulated state is // associated with. - ArchState *arch_state() const { return arch_state_; } + ArchState* arch_state() const { return arch_state_; } private: - ArchState *arch_state_; + ArchState* arch_state_; std::string name_; std::vector<int> shape_; int element_size_;
diff --git a/mpact/sim/generic/status_register.h b/mpact/sim/generic/status_register.h index b8f0416..e607e95 100644 --- a/mpact/sim/generic/status_register.h +++ b/mpact/sim/generic/status_register.h
@@ -16,12 +16,14 @@ #define MPACT_SIM_GENERIC_STATUS_REGISTER_H_ #include <any> +#include <cstdint> #include <string> #include <type_traits> #include <utility> #include <vector> #include "absl/functional/any_invocable.h" +#include "absl/strings/string_view.h" #include "mpact/sim/generic/data_buffer.h" #include "mpact/sim/generic/operand_interface.h" #include "mpact/sim/generic/state_item.h" @@ -51,13 +53,13 @@ using Evaluate = absl::AnyInvocable<bool()>; // The constructor is in the protected section below. Others are deleted. StatusRegisterBase() = delete; - StatusRegisterBase(const StatusRegisterBase &) = delete; - StatusRegisterBase &operator=(const StatusRegisterBase &) = delete; + StatusRegisterBase(const StatusRegisterBase&) = delete; + StatusRegisterBase& operator=(const StatusRegisterBase&) = delete; T Read(); T Read(T mask); - void SetDataBuffer(DataBuffer *db) override { + void SetDataBuffer(DataBuffer* db) override { // Read only state item, so just decrement the ref count and ignore. db->DecRef(); } @@ -68,8 +70,8 @@ protected: // The constructor is called from StateItem<> - StatusRegisterBase(ArchState *state, absl::string_view name, - const std::vector<int> &shape, int unit_size); + StatusRegisterBase(ArchState* state, absl::string_view name, + const std::vector<int>& shape, int unit_size); private: std::vector<Evaluate> evaluate_; @@ -77,9 +79,9 @@ }; template <typename T> -StatusRegisterBase<T>::StatusRegisterBase(ArchState *state, +StatusRegisterBase<T>::StatusRegisterBase(ArchState* state, absl::string_view name, - const std::vector<int> &shape, + const std::vector<int>& shape, int unit_size) : StateItemBase(state, name, shape, unit_size), size_(sizeof(T) * 8) { // Initialize the evaluate functions to lambdas that return false. @@ -119,10 +121,10 @@ class StatusRegisterSourceOperand : public SourceOperandInterface { public: // Construtor. Note, default constructor deleted. - StatusRegisterSourceOperand(StatusRegisterBase<T> *status_reg, + StatusRegisterSourceOperand(StatusRegisterBase<T>* status_reg, std::string op_name) : status_register_(status_reg), op_name_(op_name) {} - explicit StatusRegisterSourceOperand(StatusRegisterBase<T> *status_reg) + explicit StatusRegisterSourceOperand(StatusRegisterBase<T>* status_reg) : StatusRegisterSourceOperand(status_reg, status_reg->name()) {} StatusRegisterSourceOperand() = delete; @@ -164,7 +166,7 @@ std::string AsString() const override { return op_name_; } private: - StatusRegisterBase<T> *status_register_; + StatusRegisterBase<T>* status_register_; std::string op_name_; }; @@ -172,7 +174,7 @@ // used without template arguments, deducing the type from the constructor // argument instead. template <typename T> -StatusRegisterSourceOperand(StatusRegisterBase<T> *) +StatusRegisterSourceOperand(StatusRegisterBase<T>*) -> StatusRegisterSourceOperand<T>; template <typename ElementType>
diff --git a/mpact/sim/generic/test/BUILD b/mpact/sim/generic/test/BUILD index 55063dd..6225cf3 100644 --- a/mpact/sim/generic/test/BUILD +++ b/mpact/sim/generic/test/BUILD
@@ -73,7 +73,6 @@ deps = [ "//mpact/sim/generic:arch_state", "//mpact/sim/generic:core", - "@com_google_absl//absl/memory", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -86,7 +85,6 @@ deps = [ "//mpact/sim/generic:arch_state", "//mpact/sim/generic:core", - "@com_google_absl//absl/memory", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -109,11 +107,9 @@ srcs = ["fifo_test.cc"], deps = [ "//mpact/sim/generic:arch_state", - "//mpact/sim/generic:config", "//mpact/sim/generic:core", "//mpact/sim/generic:program_error", "//mpact/sim/proto:component_data_cc_proto", - "@com_google_absl//absl/memory", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", "@com_google_protobuf//:protobuf", @@ -127,8 +123,6 @@ deps = [ "//mpact/sim/generic:arch_state", "//mpact/sim/generic:core", - "//mpact/sim/generic:program_error", - "@com_google_absl//absl/memory", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -142,7 +136,6 @@ "//mpact/sim/generic:arch_state", "//mpact/sim/generic:core", "//mpact/sim/generic:program_error", - "@com_google_absl//absl/memory", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -154,7 +147,6 @@ srcs = ["immediate_operand_test.cc"], deps = [ "//mpact/sim/generic:core", - "@com_google_absl//absl/memory", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -179,7 +171,7 @@ deps = [ "//mpact/sim/generic:arch_state", "//mpact/sim/generic:core", - "@com_google_absl//absl/memory", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -244,6 +236,7 @@ deps = [ "//mpact/sim/generic:core", "//mpact/sim/generic:instruction", + "@com_google_absl//absl/types:span", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -291,6 +284,8 @@ deps = [ "//mpact/sim/generic:arch_state", "//mpact/sim/generic:core", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/types:span", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -302,7 +297,10 @@ srcs = ["complex_resource_operand_test.cc"], deps = [ "//mpact/sim/generic:arch_state", + "//mpact/sim/generic:core", "@com_google_absl//absl/status", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/types:span", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -316,7 +314,6 @@ "//mpact/sim/generic:config", "//mpact/sim/proto:component_data_cc_proto", "@com_google_absl//absl/container:btree", - "@com_google_absl//absl/memory", "@com_google_absl//absl/status", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", @@ -333,6 +330,7 @@ "//mpact/sim/generic:config", "//mpact/sim/generic:counters", "//mpact/sim/proto:component_data_cc_proto", + "@com_google_absl//absl/status", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", "@com_google_protobuf//:protobuf", @@ -349,8 +347,6 @@ "//mpact/sim/generic:counters", "//mpact/sim/proto:component_data_cc_proto", "@com_google_absl//absl/strings", - "@com_google_absl//absl/types:optional", - "@com_google_absl//absl/types:variant", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", "@com_google_protobuf//:protobuf",
diff --git a/mpact/sim/generic/test/arch_state_test.cc b/mpact/sim/generic/test/arch_state_test.cc index c56a31e..2bb9a9e 100644 --- a/mpact/sim/generic/test/arch_state_test.cc +++ b/mpact/sim/generic/test/arch_state_test.cc
@@ -19,11 +19,11 @@ #include <string> #include <vector> +#include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "googlemock/include/gmock/gmock.h" #include "googletest/include/gtest/gtest.h" #include "mpact/sim/generic/delay_line.h" -#include "mpact/sim/generic/delay_line_interface.h" #include "mpact/sim/generic/fifo.h" #include "mpact/sim/generic/operand_interface.h" #include "mpact/sim/generic/register.h" @@ -49,11 +49,11 @@ // Define a new delay line type. struct IntDelayRecord { - int *destination; + int* destination; int value; void Apply() { *destination = value; } IntDelayRecord() = delete; - IntDelayRecord(int *dest, int val) : destination(dest), value(val) {} + IntDelayRecord(int* dest, int val) : destination(dest), value(val) {} }; using IntDelayLine = DelayLine<IntDelayRecord>; @@ -98,7 +98,7 @@ // protected. class MyArchState : public ArchState { public: - MyArchState(absl::string_view id, SourceOperandInterface *pc_op) + MyArchState(absl::string_view id, SourceOperandInterface* pc_op) : ArchState(id, pc_op) {} explicit MyArchState(absl::string_view id) : MyArchState(id, nullptr) {} }; @@ -121,7 +121,7 @@ ~ArchStateTest() override { delete arch_state_; } MyProgramCounter my_pc_; - ArchState *arch_state_; + ArchState* arch_state_; }; // Test that the ArchState instance is properly initialized. @@ -131,7 +131,7 @@ EXPECT_THAT(arch_state_->program_error_controller()->name(), StrEq("TestArchitectureErrors")); EXPECT_EQ(arch_state_->pc_operand(), - static_cast<SourceOperandInterface *>(&my_pc_)); + static_cast<SourceOperandInterface*>(&my_pc_)); for (int reg_no = 0; reg_no < 16; reg_no++) { EXPECT_THAT(arch_state_->registers()->find(absl::StrCat("R", reg_no)), Ne(arch_state_->registers()->end())); @@ -163,7 +163,7 @@ // Test creation of a new delay line and that it gets advanced by ArchState. TEST_F(ArchStateTest, AddDelayLine) { - IntDelayLine *int_delay_line = + IntDelayLine* int_delay_line = arch_state_->CreateAndAddDelayLine<IntDelayLine>(); int my_value = 0; int_delay_line->Add(1, &my_value, 1); @@ -185,15 +185,15 @@ // Test alternate ways to add registers. TEST_F(ArchStateTest, AddRegister) { - auto *reg = new ScalarRegister(arch_state_, kRegName1); + auto* reg = new ScalarRegister(arch_state_, kRegName1); arch_state_->AddRegister(reg); // Also add the register with an alias. arch_state_->AddRegister(kRegName2, reg); auto iter = arch_state_->registers()->find(kRegName1); - auto *reg1 = + auto* reg1 = (iter == arch_state_->registers()->end()) ? nullptr : iter->second; iter = arch_state_->registers()->find(kRegName2); - auto *reg2 = + auto* reg2 = (iter == arch_state_->registers()->end()) ? nullptr : iter->second; EXPECT_EQ(reg1, reg); EXPECT_EQ(reg2, reg); @@ -208,14 +208,14 @@ // Test alternate ways to add registers. TEST_F(ArchStateTest, AddFifo) { - auto *fifo = new ScalarFifo(arch_state_, kFifoName1, 8); + auto* fifo = new ScalarFifo(arch_state_, kFifoName1, 8); arch_state_->AddFifo(fifo); // Add fifo with an alias. arch_state_->AddFifo(kFifoName2, fifo); auto iter = arch_state_->fifos()->find(kFifoName1); - auto *fifo1 = (iter == arch_state_->fifos()->end()) ? nullptr : iter->second; + auto* fifo1 = (iter == arch_state_->fifos()->end()) ? nullptr : iter->second; iter = arch_state_->fifos()->find(kFifoName2); - auto *fifo2 = (iter == arch_state_->fifos()->end()) ? nullptr : iter->second; + auto* fifo2 = (iter == arch_state_->fifos()->end()) ? nullptr : iter->second; EXPECT_EQ(fifo1, fifo); EXPECT_EQ(fifo2, fifo); arch_state_->RemoveFifo(kFifoName2);
diff --git a/mpact/sim/generic/test/complex_resource_operand_test.cc b/mpact/sim/generic/test/complex_resource_operand_test.cc index 3532c6f..d603c67 100644 --- a/mpact/sim/generic/test/complex_resource_operand_test.cc +++ b/mpact/sim/generic/test/complex_resource_operand_test.cc
@@ -14,9 +14,17 @@ #include "mpact/sim/generic/complex_resource_operand.h" +#include <cstddef> +#include <cstdint> + #include "absl/status/status.h" +#include "absl/strings/string_view.h" +#include "absl/types/span.h" #include "googlemock/include/gmock/gmock.h" #include "googletest/include/gtest/gtest.h" +#include "mpact/sim/generic/arch_state.h" +#include "mpact/sim/generic/complex_resource.h" +#include "mpact/sim/generic/operand_interface.h" namespace { @@ -51,7 +59,7 @@ // access the clock. class MockArchState : public ArchState { public: - MockArchState(absl::string_view id, SourceOperandInterface *pc_op) + MockArchState(absl::string_view id, SourceOperandInterface* pc_op) : ArchState(id, pc_op) {} explicit MockArchState(absl::string_view id) : MockArchState(id, nullptr) {} void set_cycle(uint64_t value) { ArchState::set_cycle(value); } @@ -73,9 +81,9 @@ delete arch_state_; } - MockArchState *arch_state_; - ComplexResource *resource_; - ComplexResourceOperand *operand_; + MockArchState* arch_state_; + ComplexResource* resource_; + ComplexResourceOperand* operand_; }; // Create and check name. @@ -85,7 +93,7 @@ // Check error status from setting the cycle mask. TEST_F(ComplexResourceOperandTest, CycleMask) { - auto *op = new ComplexResourceOperand(nullptr); + auto* op = new ComplexResourceOperand(nullptr); EXPECT_TRUE(absl::IsInternal(op->SetCycleMask(kLow, kHigh))); EXPECT_TRUE(absl::IsInvalidArgument(operand_->SetCycleMask(kHigh, kLow))); EXPECT_TRUE(
diff --git a/mpact/sim/generic/test/complex_resource_test.cc b/mpact/sim/generic/test/complex_resource_test.cc index ef400ef..62eaa5c 100644 --- a/mpact/sim/generic/test/complex_resource_test.cc +++ b/mpact/sim/generic/test/complex_resource_test.cc
@@ -14,9 +14,14 @@ #include "mpact/sim/generic/complex_resource.h" +#include <cstddef> +#include <cstdint> #include <ostream> -#include "googlemock/include/gmock/gmock.h" +#include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" +#include "absl/types/span.h" +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" #include "mpact/sim/generic/arch_state.h" #include "mpact/sim/generic/operand_interface.h" @@ -41,7 +46,7 @@ class MockArchState : public ArchState { public: - MockArchState(absl::string_view id, SourceOperandInterface *pc_op) + MockArchState(absl::string_view id, SourceOperandInterface* pc_op) : ArchState(id, pc_op) {} explicit MockArchState(absl::string_view id) : MockArchState(id, nullptr) {} void set_cycle(uint64_t value) { ArchState::set_cycle(value); } @@ -53,11 +58,11 @@ ~ComplexResourceTest() override { delete arch_state_; } - MockArchState *arch_state_; + MockArchState* arch_state_; }; TEST_F(ComplexResourceTest, Construct) { - auto *resource = new ComplexResource(arch_state_, kResourceName, kCycleDepth); + auto* resource = new ComplexResource(arch_state_, kResourceName, kCycleDepth); EXPECT_EQ(resource->bit_array().size(), (kCycleDepth + 63) / 64); EXPECT_EQ(resource->name(), kResourceName); EXPECT_EQ(resource->AsString(), kResourceName); @@ -66,7 +71,7 @@ // Verify that all bits are free to start out with. TEST_F(ComplexResourceTest, IsFreeMarchingOne) { - auto *resource = new ComplexResource(arch_state_, kResourceName, kCycleDepth); + auto* resource = new ComplexResource(arch_state_, kResourceName, kCycleDepth); uint64_t marching_one[4] = {0x8000'0000'0000'0000, 0, 0, 0}; for (size_t i = 0; i < kCycleDepth; i++) { EXPECT_TRUE(resource->IsFree(marching_one)) << i; @@ -83,7 +88,7 @@ // Reserve all bits, verify that they are set. TEST_F(ComplexResourceTest, IsBusyMarchingOne) { - auto *resource = new ComplexResource(arch_state_, kResourceName, kCycleDepth); + auto* resource = new ComplexResource(arch_state_, kResourceName, kCycleDepth); resource->Acquire(kAllOnes234); uint64_t marching_one[4] = {0x8000'0000'0000'0000, 0, 0, 0}; for (size_t i = 0; i < kCycleDepth; i++) { @@ -102,7 +107,7 @@ // Acquire the resource for all the cycles. Then check if it is available and // try to acquire it. Release the resource for that cycle, then try again. TEST_F(ComplexResourceTest, AcquireRelease) { - auto *resource = new ComplexResource(arch_state_, kResourceName, kCycleDepth); + auto* resource = new ComplexResource(arch_state_, kResourceName, kCycleDepth); resource->Acquire(kAllOnes234); uint64_t marching_one[4] = {0x8000'0000'0000'0000, 0, 0, 0}; for (size_t i = 0; i < kCycleDepth; i++) { @@ -125,7 +130,7 @@ // Acquires the resource for all cycles. Then advances the clock and checks if // the resource is free in the last cycle, next to last cycle, etc. TEST_F(ComplexResourceTest, SingleWordBy1) { - auto *resource = new ComplexResource(arch_state_, kResourceName, 64); + auto* resource = new ComplexResource(arch_state_, kResourceName, 64); EXPECT_TRUE(resource->IsFree(kAllOnes234)); resource->Acquire(kAllOnes234); EXPECT_FALSE(resource->IsFree(kAllOnes234)); @@ -154,7 +159,7 @@ // Same as above, but advanced the clock by 3. TEST_F(ComplexResourceTest, SingleWordBy3) { - auto *resource = new ComplexResource(arch_state_, kResourceName, 64); + auto* resource = new ComplexResource(arch_state_, kResourceName, 64); EXPECT_TRUE(resource->IsFree(kAllOnes234)); resource->Acquire(kAllOnes234); EXPECT_FALSE(resource->IsFree(kAllOnes234)); @@ -185,7 +190,7 @@ // Acquires the resource for all cycles. Then advances the clock and checks if // the resource is free in the last cycle, next to last cycle, etc. TEST_F(ComplexResourceTest, QuadWordBy1) { - auto *resource = new ComplexResource(arch_state_, kResourceName, 256); + auto* resource = new ComplexResource(arch_state_, kResourceName, 256); EXPECT_TRUE(resource->IsFree(kAllOnes256)); resource->Acquire(kAllOnes256); EXPECT_FALSE(resource->IsFree(kAllOnes256)); @@ -219,7 +224,7 @@ // Same as above, but advances the clock by 7 cycles at a time. TEST_F(ComplexResourceTest, QuadWordBy5) { - auto *resource = new ComplexResource(arch_state_, kResourceName, 256); + auto* resource = new ComplexResource(arch_state_, kResourceName, 256); EXPECT_TRUE(resource->IsFree(kAllOnes256)); resource->Acquire(kAllOnes256); EXPECT_FALSE(resource->IsFree(kAllOnes256)); @@ -253,7 +258,7 @@ // Check that advancing clock by more than 256 yields free resource. TEST_F(ComplexResourceTest, ShiftGreaterThan256) { - auto *resource = new ComplexResource(arch_state_, kResourceName, 256); + auto* resource = new ComplexResource(arch_state_, kResourceName, 256); EXPECT_TRUE(resource->IsFree(kAllOnes256)); resource->Acquire(kAllOnes256); EXPECT_FALSE(resource->IsFree(kAllOnes256)); @@ -264,7 +269,7 @@ // Verify that shifts over 64 bits work. TEST_F(ComplexResourceTest, ShiftGreaterThan64) { - auto *resource = new ComplexResource(arch_state_, kResourceName, 256); + auto* resource = new ComplexResource(arch_state_, kResourceName, 256); EXPECT_TRUE(resource->IsFree(kAllOnes256)); resource->Acquire(kAllOnes256); EXPECT_FALSE(resource->IsFree(kAllOnes64));
diff --git a/mpact/sim/generic/test/component_test.cc b/mpact/sim/generic/test/component_test.cc index 7ed65fc..299fa8f 100644 --- a/mpact/sim/generic/test/component_test.cc +++ b/mpact/sim/generic/test/component_test.cc
@@ -17,7 +17,8 @@ #include <cstdint> #include <memory> -#include "googlemock/include/gmock/gmock.h" +#include "absl/status/status.h" +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" #include "mpact/sim/generic/config.h" #include "mpact/sim/generic/counters.h" @@ -116,15 +117,15 @@ int64_config_(kInt64ConfigName, kInt64ConfigValue), uint64_config_(kUint64ConfigName, kUint64ConfigValue) {} - Component &top() { return top_; } - Component &child() { return child_; } - SimpleCounter<int64_t> &int64_counter() { return int64_counter_; } - SimpleCounter<uint64_t> &uint64_counter() { return uint64_counter_; } - SimpleCounter<uint64_t> &uninitialized_counter() { + Component& top() { return top_; } + Component& child() { return child_; } + SimpleCounter<int64_t>& int64_counter() { return int64_counter_; } + SimpleCounter<uint64_t>& uint64_counter() { return uint64_counter_; } + SimpleCounter<uint64_t>& uninitialized_counter() { return uninitialized_counter_; } - Config<int64_t> &int64_config() { return int64_config_; } - Config<uint64_t> &uint64_config() { return uint64_config_; } + Config<int64_t>& int64_config() { return int64_config_; } + Config<uint64_t>& uint64_config() { return uint64_config_; } private: Component top_; @@ -157,9 +158,9 @@ // Add counter objects to the two components. Ensure that the counters are // found in the expected component. TEST_F(ComponentTest, ComponentsWithCounters) { - auto *top_counter = &int64_counter(); - auto *child_counter = &uint64_counter(); - auto *uninit_counter = &uninitialized_counter(); + auto* top_counter = &int64_counter(); + auto* child_counter = &uint64_counter(); + auto* uninit_counter = &uninitialized_counter(); EXPECT_TRUE(top().AddCounter(top_counter).ok()); EXPECT_TRUE(child().AddCounter(child_counter).ok()); @@ -174,8 +175,8 @@ // Add config objects to the two components. Ensure that the config objects // are found in the expected component. TEST_F(ComponentTest, ComponentsWithConfigs) { - auto *top_config = &int64_config(); - auto *child_config = &uint64_config(); + auto* top_config = &int64_config(); + auto* child_config = &uint64_config(); EXPECT_TRUE(top().AddConfig(top_config).ok()); EXPECT_TRUE(child().AddConfig(child_config).ok()); @@ -201,13 +202,13 @@ // then export the components to a proto, and verify the proto against the // expected value. TEST_F(ComponentTest, ExportTest) { - auto *top_config = &int64_config(); - auto *child_config = &uint64_config(); + auto* top_config = &int64_config(); + auto* child_config = &uint64_config(); EXPECT_TRUE(top().AddConfig(top_config).ok()); EXPECT_TRUE(child().AddConfig(child_config).ok()); - auto *top_counter = &int64_counter(); - auto *child_counter = &uint64_counter(); + auto* top_counter = &int64_counter(); + auto* child_counter = &uint64_counter(); EXPECT_TRUE(top().AddCounter(top_counter).ok()); EXPECT_TRUE(child().AddCounter(child_counter).ok()); @@ -219,13 +220,13 @@ // Failed import due to missing top-level name. TEST_F(ComponentTest, ImportTestNameMissing) { - auto *top_config = &int64_config(); - auto *child_config = &uint64_config(); + auto* top_config = &int64_config(); + auto* child_config = &uint64_config(); EXPECT_TRUE(top().AddConfig(top_config).ok()); EXPECT_TRUE(child().AddConfig(child_config).ok()); - auto *top_counter = &int64_counter(); - auto *child_counter = &uint64_counter(); + auto* top_counter = &int64_counter(); + auto* child_counter = &uint64_counter(); EXPECT_TRUE(top().AddCounter(top_counter).ok()); EXPECT_TRUE(child().AddCounter(child_counter).ok()); @@ -238,13 +239,13 @@ // Failed import due to malformed component data. TEST_F(ComponentTest, ImportTestMalformed) { - auto *top_config = &int64_config(); - auto *child_config = &uint64_config(); + auto* top_config = &int64_config(); + auto* child_config = &uint64_config(); EXPECT_TRUE(top().AddConfig(top_config).ok()); EXPECT_TRUE(child().AddConfig(child_config).ok()); - auto *top_counter = &int64_counter(); - auto *child_counter = &uint64_counter(); + auto* top_counter = &int64_counter(); + auto* child_counter = &uint64_counter(); EXPECT_TRUE(top().AddCounter(top_counter).ok()); EXPECT_TRUE(child().AddCounter(child_counter).ok()); @@ -257,13 +258,13 @@ // Failed import due to missing child name. TEST_F(ComponentTest, ImportTestChildNameMissing) { - auto *top_config = &int64_config(); - auto *child_config = &uint64_config(); + auto* top_config = &int64_config(); + auto* child_config = &uint64_config(); EXPECT_TRUE(top().AddConfig(top_config).ok()); EXPECT_TRUE(child().AddConfig(child_config).ok()); - auto *top_counter = &int64_counter(); - auto *child_counter = &uint64_counter(); + auto* top_counter = &int64_counter(); + auto* child_counter = &uint64_counter(); EXPECT_TRUE(top().AddCounter(top_counter).ok()); EXPECT_TRUE(child().AddCounter(child_counter).ok()); @@ -276,13 +277,13 @@ // Failed import due to top level name mismatch. TEST_F(ComponentTest, ImportTestNameMismatch) { - auto *top_config = &int64_config(); - auto *child_config = &uint64_config(); + auto* top_config = &int64_config(); + auto* child_config = &uint64_config(); EXPECT_TRUE(top().AddConfig(top_config).ok()); EXPECT_TRUE(child().AddConfig(child_config).ok()); - auto *top_counter = &int64_counter(); - auto *child_counter = &uint64_counter(); + auto* top_counter = &int64_counter(); + auto* child_counter = &uint64_counter(); EXPECT_TRUE(top().AddCounter(top_counter).ok()); EXPECT_TRUE(child().AddCounter(child_counter).ok()); @@ -296,13 +297,13 @@ // Import a proto into the components. Verify that the value of config entries // are updated, but the counters are not. TEST_F(ComponentTest, ImportTest) { - auto *top_config = &int64_config(); - auto *child_config = &uint64_config(); + auto* top_config = &int64_config(); + auto* child_config = &uint64_config(); EXPECT_TRUE(top().AddConfig(top_config).ok()); EXPECT_TRUE(child().AddConfig(child_config).ok()); - auto *top_counter = &int64_counter(); - auto *child_counter = &uint64_counter(); + auto* top_counter = &int64_counter(); + auto* child_counter = &uint64_counter(); EXPECT_TRUE(top().AddCounter(top_counter).ok()); EXPECT_TRUE(child().AddCounter(child_counter).ok());
diff --git a/mpact/sim/generic/test/config_test.cc b/mpact/sim/generic/test/config_test.cc index 47ae18a..45f061f 100644 --- a/mpact/sim/generic/test/config_test.cc +++ b/mpact/sim/generic/test/config_test.cc
@@ -196,7 +196,7 @@ // and exporting it to a proto. Saving the configuration after a simulation // is useful in post analysis to be able to tie together the configuration // information and the collected statistics. - std::vector<ConfigBase *> config_vector; + std::vector<ConfigBase*> config_vector; config_vector.push_back(&bool_config); config_vector.push_back(&int64_config); config_vector.push_back(&uint64_config); @@ -204,8 +204,8 @@ config_vector.push_back(&string_config); auto exported_proto = std::make_unique<ComponentData>(); - ComponentValueEntry *entry; - for (auto const &config : config_vector) { + ComponentValueEntry* entry; + for (auto const& config : config_vector) { entry = exported_proto->add_configuration(); EXPECT_TRUE(config->Export(entry).ok()); } @@ -231,7 +231,7 @@ // Add the configuration entries to a map from name to ConfigBase. This is to // mimic a use case where a proto is read in for a software component and the // values are imported into its configuration entries (stored in a registry). - absl::btree_map<std::string, ConfigBase *> config_map; + absl::btree_map<std::string, ConfigBase*> config_map; config_map.insert(std::make_pair(bool_config.name(), &bool_config)); config_map.insert(std::make_pair(int64_config.name(), &int64_config)); config_map.insert(std::make_pair(uint64_config.name(), &uint64_config)); @@ -245,9 +245,9 @@ // For each configuration entry, look up a config entry with a matching name // and import the proto value to the config. for (int index = 0; index < fromText.configuration_size(); index++) { - const ComponentValueEntry &entry = fromText.configuration(index); + const ComponentValueEntry& entry = fromText.configuration(index); if (entry.has_name() && config_map.contains(entry.name())) { - ConfigBase *config = config_map.at(entry.name()); + ConfigBase* config = config_map.at(entry.name()); EXPECT_TRUE(config->Import(&entry).ok()); } } @@ -268,7 +268,7 @@ Config<double> double_config(kDoubleConfigName); Config<std::string> string_config(kStringConfigName); - std::vector<ConfigBase *> config_vector; + std::vector<ConfigBase*> config_vector; config_vector.push_back(&bool_config); config_vector.push_back(&int64_config); config_vector.push_back(&uint64_config); @@ -276,7 +276,7 @@ config_vector.push_back(&string_config); // Expect each import to fail with invalid argument. - for (auto *config : config_vector) { + for (auto* config : config_vector) { EXPECT_TRUE(absl::IsInvalidArgument(config->Import(nullptr))); } } @@ -289,7 +289,7 @@ Config<double> double_config(kDoubleConfigName); Config<std::string> string_config(kStringConfigName); - std::vector<ConfigBase *> config_vector; + std::vector<ConfigBase*> config_vector; config_vector.push_back(&bool_config); config_vector.push_back(&int64_config); config_vector.push_back(&uint64_config); @@ -301,7 +301,7 @@ EXPECT_TRUE( google::protobuf::TextFormat::ParseFromString(kProtoNoName, &fromText)); // Expect each import to fail with internal error. - const ComponentValueEntry &entry = fromText.configuration(0); + const ComponentValueEntry& entry = fromText.configuration(0); for (int index = 0; index < fromText.configuration_size(); index++) { EXPECT_TRUE(absl::IsInternal(config_vector[index]->Import(&entry))); } @@ -315,7 +315,7 @@ Config<double> double_config(kDoubleConfigName); Config<std::string> string_config(kStringConfigName); - std::vector<ConfigBase *> config_vector; + std::vector<ConfigBase*> config_vector; config_vector.push_back(&bool_config); config_vector.push_back(&int64_config); config_vector.push_back(&uint64_config); @@ -329,7 +329,7 @@ // Expect each import to fail with internal error, as the proto message // passed in has a name that doesn't match the configuration entry. for (int index = 0; index < fromText.configuration_size(); index++) { - const ComponentValueEntry &entry = fromText.configuration(index); + const ComponentValueEntry& entry = fromText.configuration(index); EXPECT_TRUE(absl::IsInternal(config_vector[index]->Import(&entry))); } } @@ -345,7 +345,7 @@ // Add the configuration entries to a map from name to ConfigBase. This is to // mimic a use case where a proto is read in for a software component and the // values are imported into its configuration entries (stored in a registry). - absl::btree_map<std::string, ConfigBase *> config_map; + absl::btree_map<std::string, ConfigBase*> config_map; config_map.insert(std::make_pair(bool_config.name(), &bool_config)); config_map.insert(std::make_pair(int64_config.name(), &int64_config)); config_map.insert(std::make_pair(uint64_config.name(), &uint64_config)); @@ -361,9 +361,9 @@ // mismatches to the type of the config entry they should all fail with // internal errors. for (int index = 0; index < fromText.configuration_size(); index++) { - const ComponentValueEntry &entry = fromText.configuration(index); + const ComponentValueEntry& entry = fromText.configuration(index); if (entry.has_name() && config_map.contains(entry.name())) { - ConfigBase *config = config_map.at(entry.name()); + ConfigBase* config = config_map.at(entry.name()); EXPECT_TRUE(absl::IsInternal(config->Import(&entry))); } }
diff --git a/mpact/sim/generic/test/control_register_test.cc b/mpact/sim/generic/test/control_register_test.cc index bc77f6e..1a72675 100644 --- a/mpact/sim/generic/test/control_register_test.cc +++ b/mpact/sim/generic/test/control_register_test.cc
@@ -17,10 +17,10 @@ #include <cstdint> #include <memory> -#include "absl/memory/memory.h" #include "googlemock/include/gmock/gmock.h" #include "googletest/include/gtest/gtest.h" #include "mpact/sim/generic/data_buffer.h" +#include "mpact/sim/generic/register.h" namespace { @@ -36,13 +36,13 @@ ~ControlRegisterTest() override { delete db_factory_; } - DataBufferFactory *db_factory_; + DataBufferFactory* db_factory_; }; // Create scalar register and verify attributes. TEST_F(ControlRegisterTest, Create) { auto scalar_reg = std::make_unique<TestRegister>( - nullptr, "R0", [](ControlRegisterBase *, DataBuffer *) {}); + nullptr, "R0", [](ControlRegisterBase*, DataBuffer*) {}); EXPECT_THAT(scalar_reg->name(), StrEq("R0")); EXPECT_EQ(scalar_reg->shape().size(), 1); EXPECT_EQ(scalar_reg->size(), sizeof(uint32_t)); @@ -53,14 +53,14 @@ bool works = false; // Allocate register and make sure data_buffer is nullptr. auto reg = std::make_unique<TestRegister>( - nullptr, "R0", [&works](ControlRegisterBase *creg, DataBuffer *db) { + nullptr, "R0", [&works](ControlRegisterBase* creg, DataBuffer* db) { works = true; creg->RegisterBase::SetDataBuffer(db); }); EXPECT_EQ(reg->data_buffer(), nullptr); // Allocate a data buffer of the right byte size and bind it to the register. - DataBuffer *db = db_factory_->Allocate(reg->size()); + DataBuffer* db = db_factory_->Allocate(reg->size()); reg->SetDataBuffer(db); EXPECT_TRUE(works);
diff --git a/mpact/sim/generic/test/counters_test.cc b/mpact/sim/generic/test/counters_test.cc index 045fe8d..00d4726 100644 --- a/mpact/sim/generic/test/counters_test.cc +++ b/mpact/sim/generic/test/counters_test.cc
@@ -24,10 +24,9 @@ #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" -#include "absl/types/variant.h" -#include "googlemock/include/gmock/gmock.h" +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" +#include "mpact/sim/generic/counters_base.h" #include "mpact/sim/proto/component_data.pb.h" #include "src/google/protobuf/text_format.h" @@ -65,7 +64,7 @@ template <typename T> class Max { public: - bool operator()(const T &in, T *out) { + bool operator()(const T& in, T* out) { if (value_.has_value() && (in <= *value_)) return false; value_ = in; *out = in; @@ -83,7 +82,7 @@ class Count { public: template <typename T> - bool operator()(const T &in, int64_t *out) { + bool operator()(const T& in, int64_t* out) { *out = ++value_; return true; } @@ -157,7 +156,7 @@ CounterValue cv = int64_counter.GetCounterValue(); EXPECT_EQ(std::get<int64_t>(cv), kMinusFive); EXPECT_EQ(int64_counter.ToString(), absl::StrCat(kMinusFive)); - EXPECT_EQ(static_cast<mpact::sim::generic::CounterValueOutputBase<int64_t> *>( + EXPECT_EQ(static_cast<mpact::sim::generic::CounterValueOutputBase<int64_t>*>( &int64_counter) ->ToString(), absl::StrCat(kMinusFive)); @@ -210,7 +209,7 @@ std::vector<double> values = {1.1, 5.2, 3.3, 9.4, 2.5, 0.6}; // Pass in default constructed instance of Max<double>. FunctionCounter<double> max("max", Max<double>()); - for (auto const &val : values) { + for (auto const& val : values) { max.SetValue(val); } // Verify that the computed max is the same as that computed by max_element. @@ -222,7 +221,7 @@ std::vector<double> values = {1.1, 5.2, 3.3, 9.4, 2.5, 0.6}; // Pass in default constructed instance of Count<double>. FunctionCounter<double, int64_t> count("count", Count()); - for (auto const &val : values) { + for (auto const& val : values) { count.SetValue(val); } // Verify that the element count is the same as the vector size. @@ -241,14 +240,14 @@ // is an intended use case for reading out the values of the counters and // exporting it to a proto in order to save the simulation results at the end // of a run. - std::vector<CounterBaseInterface *> counter_vector; + std::vector<CounterBaseInterface*> counter_vector; counter_vector.push_back(&int64_counter); counter_vector.push_back(&uint64_counter); counter_vector.push_back(&double_counter); auto exported_proto = std::make_unique<ComponentData>(); - ComponentValueEntry *entry; - for (auto const &counter : counter_vector) { + ComponentValueEntry* entry; + for (auto const& counter : counter_vector) { entry = exported_proto->add_statistics(); EXPECT_TRUE(counter->Export(entry).ok()); }
diff --git a/mpact/sim/generic/test/data_buffer_test.cc b/mpact/sim/generic/test/data_buffer_test.cc index e2d464b..2bb00ba 100644 --- a/mpact/sim/generic/test/data_buffer_test.cc +++ b/mpact/sim/generic/test/data_buffer_test.cc
@@ -14,6 +14,7 @@ #include "mpact/sim/generic/data_buffer.h" +#include <cstddef> #include <cstdint> #include <vector> @@ -32,17 +33,17 @@ ~DataBufferTest() override { delete db_factory_; } - DataBufferFactory *db_factory_; + DataBufferFactory* db_factory_; }; // Test that DataBufferFactory allocates the right sizes. TEST_F(DataBufferTest, DataBufferFactoryAllocate) { - DataBuffer *db8_1 = db_factory_->Allocate<uint32_t>(8); + DataBuffer* db8_1 = db_factory_->Allocate<uint32_t>(8); EXPECT_EQ(db8_1->size<uint32_t>(), 8); EXPECT_EQ(db8_1->size<uint8_t>(), 32); EXPECT_EQ(db8_1->ref_count(), 1); - DataBuffer *db4_1 = db_factory_->Allocate<uint32_t>(4); + DataBuffer* db4_1 = db_factory_->Allocate<uint32_t>(4); EXPECT_EQ(db4_1->size<uint32_t>(), 4); EXPECT_EQ(db4_1->size<uint8_t>(), 16); EXPECT_EQ(db4_1->ref_count(), 1); @@ -53,17 +54,17 @@ // Test that DataBuffers are allocated and recycled. TEST_F(DataBufferTest, DataBufferFactoryAllocateRecycleAllocate) { - DataBuffer *db8_1 = db_factory_->Allocate<uint32_t>(8); + DataBuffer* db8_1 = db_factory_->Allocate<uint32_t>(8); db8_1->DecRef(); - DataBuffer *db4_1 = db_factory_->Allocate<uint32_t>(4); + DataBuffer* db4_1 = db_factory_->Allocate<uint32_t>(4); EXPECT_NE(db8_1, db4_1); db4_1->DecRef(); - DataBuffer *db8_2 = db_factory_->Allocate<uint32_t>(8); - DataBuffer *db4_2 = db_factory_->Allocate<uint32_t>(4); + DataBuffer* db8_2 = db_factory_->Allocate<uint32_t>(8); + DataBuffer* db4_2 = db_factory_->Allocate<uint32_t>(4); EXPECT_EQ(db8_1, db8_2); EXPECT_EQ(db4_1, db4_2); @@ -79,13 +80,13 @@ const uint32_t kValues[] = {0x01020304, 0xDEADBEEF, 0xA5A55A5A, 0xF0F00F0F}; const int kSize = 4; - DataBuffer *db_source = db_factory_->Allocate<uint32_t>(kSize); + DataBuffer* db_source = db_factory_->Allocate<uint32_t>(kSize); for (int index = 0; index < kSize; index++) { db_source->Set<uint32_t>(index, kValues[index]); } - DataBuffer *db_dest = db_factory_->MakeCopyOf(db_source); + DataBuffer* db_dest = db_factory_->MakeCopyOf(db_source); EXPECT_NE(db_source, db_dest); EXPECT_EQ(db_source->size<uint32_t>(), db_dest->size<uint32_t>()); @@ -104,7 +105,7 @@ const std::vector<uint32_t> kValueVec{0x01020304, 0xDEADBEEF, 0xA5A55A5A, 0xF0F00F0F}; - DataBuffer *db = db_factory_->Allocate<uint32_t>(kValueVec.size()); + DataBuffer* db = db_factory_->Allocate<uint32_t>(kValueVec.size()); db->Set<uint32_t>(kValueVec); for (size_t index = 0; index < kValueVec.size(); index++) { @@ -136,9 +137,9 @@ double y; }; - DataBuffer *db = db_factory_->Allocate(sizeof(MyTest)); + DataBuffer* db = db_factory_->Allocate(sizeof(MyTest)); EXPECT_EQ(sizeof(MyTest), db->size<unsigned char>()); - MyTest *my_test = reinterpret_cast<MyTest *>(db->raw_ptr()); + MyTest* my_test = reinterpret_cast<MyTest*>(db->raw_ptr()); my_test->y = 3.14; db->DecRef(); }
diff --git a/mpact/sim/generic/test/decode_cache_test.cc b/mpact/sim/generic/test/decode_cache_test.cc index 7c71ddd..20f40d1 100644 --- a/mpact/sim/generic/test/decode_cache_test.cc +++ b/mpact/sim/generic/test/decode_cache_test.cc
@@ -31,13 +31,13 @@ public: MockDecoder() : num_decoded_(0) {} ~MockDecoder() override {} - Instruction *DecodeInstruction(uint64_t address) override { + Instruction* DecodeInstruction(uint64_t address) override { num_decoded_++; - Instruction *inst = new Instruction(address, nullptr); + Instruction* inst = new Instruction(address, nullptr); return inst; } int GetNumOpcodes() const override { return 0; } - const char *GetOpcodeName(int index) const override { return ""; } + const char* GetOpcodeName(int index) const override { return ""; } void set_num_decoded(int val) { num_decoded_ = val; } int num_decoded() const { return num_decoded_; } @@ -52,7 +52,7 @@ ~DecodeCacheTest() override { delete decoder_; } - MockDecoder *decoder_; + MockDecoder* decoder_; }; // Test creation and verify basic properties. @@ -61,7 +61,7 @@ props.num_entries = 1000; props.minimum_pc_increment = 4; - DecodeCache *dc = DecodeCache::Create(props, decoder_); + DecodeCache* dc = DecodeCache::Create(props, decoder_); EXPECT_EQ(dc->num_entries(), 1024); EXPECT_EQ(dc->address_mask(), 0xFFC); EXPECT_EQ(dc->address_shift(), 2); @@ -83,9 +83,9 @@ DecodeCacheProperties props; props.num_entries = 1000; props.minimum_pc_increment = 4; - DecodeCache *dc = DecodeCache::Create(props, decoder_); + DecodeCache* dc = DecodeCache::Create(props, decoder_); - Instruction *inst; + Instruction* inst; EXPECT_EQ(decoder_->num_decoded(), 0); // Not in cache, decoder will be called. inst = dc->GetDecodedInstruction(0x1000); @@ -116,9 +116,9 @@ DecodeCacheProperties props; props.num_entries = 1000; props.minimum_pc_increment = 4; - DecodeCache *dc = DecodeCache::Create(props, decoder_); + DecodeCache* dc = DecodeCache::Create(props, decoder_); - Instruction *inst; + Instruction* inst; inst = dc->GetDecodedInstruction(0x1000); inst = dc->GetDecodedInstruction(0x1004); inst = dc->GetDecodedInstruction(0x1008); @@ -139,9 +139,9 @@ DecodeCacheProperties props; props.num_entries = 1000; props.minimum_pc_increment = 4; - DecodeCache *dc = DecodeCache::Create(props, decoder_); + DecodeCache* dc = DecodeCache::Create(props, decoder_); - Instruction *inst; + Instruction* inst; inst = dc->GetDecodedInstruction(0x1000); inst = dc->GetDecodedInstruction(0x1004); inst = dc->GetDecodedInstruction(0x1008); @@ -162,9 +162,9 @@ DecodeCacheProperties props; props.num_entries = 1000; props.minimum_pc_increment = 4; - DecodeCache *dc = DecodeCache::Create(props, decoder_); + DecodeCache* dc = DecodeCache::Create(props, decoder_); - Instruction *inst; + Instruction* inst; inst = dc->GetDecodedInstruction(0x1000); inst = dc->GetDecodedInstruction(0x1004); inst = dc->GetDecodedInstruction(0x1008);
diff --git a/mpact/sim/generic/test/delay_line_test.cc b/mpact/sim/generic/test/delay_line_test.cc index 960ba59..cf58445 100644 --- a/mpact/sim/generic/test/delay_line_test.cc +++ b/mpact/sim/generic/test/delay_line_test.cc
@@ -14,7 +14,7 @@ #include "mpact/sim/generic/delay_line.h" -#include "googlemock/include/gmock/gmock.h" +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" namespace mpact { @@ -28,11 +28,11 @@ class TestRecord { public: void Apply() { *dest_ = value_; } - TestRecord(int value, int *dest) : value_(value), dest_(dest) {} + TestRecord(int value, int* dest) : value_(value), dest_(dest) {} private: int value_; - int *dest_; + int* dest_; }; // Delay Line is 8 entries deep. @@ -40,7 +40,7 @@ ~DelayLineTest() override { delete delay_line_; } - DelayLine<TestRecord> *delay_line_; + DelayLine<TestRecord>* delay_line_; }; // Test that the value changes after two calls to Advance.
diff --git a/mpact/sim/generic/test/devnull_operand_test.cc b/mpact/sim/generic/test/devnull_operand_test.cc index 5cbed05..22dff8b 100644 --- a/mpact/sim/generic/test/devnull_operand_test.cc +++ b/mpact/sim/generic/test/devnull_operand_test.cc
@@ -17,8 +17,8 @@ #include <cstdint> #include <memory> -#include "absl/memory/memory.h" -#include "googlemock/include/gmock/gmock.h" +#include "absl/strings/string_view.h" +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" #include "mpact/sim/generic/arch_state.h" #include "mpact/sim/generic/data_buffer.h" @@ -32,7 +32,7 @@ class MockArchState : public ArchState { public: - MockArchState(absl::string_view id, SourceOperandInterface *pc_op) + MockArchState(absl::string_view id, SourceOperandInterface* pc_op) : ArchState(id, pc_op) {} explicit MockArchState(absl::string_view id) : MockArchState(id, nullptr) {} }; @@ -42,7 +42,7 @@ DevNullOperandTest() { arch_state_ = new MockArchState("MockArchState"); } ~DevNullOperandTest() override { delete arch_state_; } - MockArchState *arch_state_; + MockArchState* arch_state_; }; // Testing that the operand behaves like a normal destination, that the
diff --git a/mpact/sim/generic/test/fifo_operand_test.cc b/mpact/sim/generic/test/fifo_operand_test.cc index 839560c..6f852bc 100644 --- a/mpact/sim/generic/test/fifo_operand_test.cc +++ b/mpact/sim/generic/test/fifo_operand_test.cc
@@ -18,11 +18,10 @@ #include "absl/strings/string_view.h" #include "absl/types/any.h" -#include "googlemock/include/gmock/gmock.h" +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" #include "mpact/sim/generic/arch_state.h" #include "mpact/sim/generic/data_buffer.h" -#include "mpact/sim/generic/delay_line.h" #include "mpact/sim/generic/fifo.h" #include "mpact/sim/generic/operand_interface.h" @@ -42,7 +41,7 @@ // protected. class MockArchState : public ArchState { public: - MockArchState(absl::string_view id, SourceOperandInterface *pc_op) + MockArchState(absl::string_view id, SourceOperandInterface* pc_op) : ArchState(id, pc_op) {} explicit MockArchState(absl::string_view id) : MockArchState(id, nullptr) {} }; @@ -63,16 +62,16 @@ delete arch_state_; } - MockArchState *arch_state_; - ScalarFifo *sfifo_; - Vector8Fifo *vfifo_; + MockArchState* arch_state_; + ScalarFifo* sfifo_; + Vector8Fifo* vfifo_; }; // Tests that the fifo source operands are initialized correctly. TEST_F(FifoOperandTest, SourceOperandInitialization) { auto s_src_op = std::make_unique<FifoSourceOperand<uint32_t>>(sfifo_); - EXPECT_EQ(std::any_cast<FifoBase *>(s_src_op->GetObject()), - static_cast<FifoBase *>(sfifo_)); + EXPECT_EQ(std::any_cast<FifoBase*>(s_src_op->GetObject()), + static_cast<FifoBase*>(sfifo_)); EXPECT_EQ(s_src_op->shape(), sfifo_->shape()); EXPECT_EQ(s_src_op->AsString(), kScalarFifoName); @@ -80,8 +79,8 @@ EXPECT_EQ(s_src_op->AsString(), "Fifo"); auto v_src_op = std::make_unique<FifoSourceOperand<uint32_t>>(vfifo_); - EXPECT_EQ(std::any_cast<FifoBase *>(v_src_op->GetObject()), - static_cast<FifoBase *>(vfifo_)); + EXPECT_EQ(std::any_cast<FifoBase*>(v_src_op->GetObject()), + static_cast<FifoBase*>(vfifo_)); EXPECT_EQ(v_src_op->shape(), vfifo_->shape()); EXPECT_EQ(v_src_op->AsString(), kVectorFifoName); @@ -95,8 +94,8 @@ EXPECT_EQ(s_dst_op->latency(), 1); EXPECT_EQ(s_dst_op->shape(), sfifo_->shape()); EXPECT_EQ(s_dst_op->CopyDataBuffer(), nullptr); - EXPECT_EQ(std::any_cast<FifoBase *>(s_dst_op->GetObject()), - static_cast<FifoBase *>(sfifo_)); + EXPECT_EQ(std::any_cast<FifoBase*>(s_dst_op->GetObject()), + static_cast<FifoBase*>(sfifo_)); EXPECT_EQ(s_dst_op->AsString(), kScalarFifoName); s_dst_op = @@ -107,8 +106,8 @@ EXPECT_EQ(v_dst_op->latency(), 4); EXPECT_EQ(v_dst_op->shape(), vfifo_->shape()); EXPECT_EQ(v_dst_op->CopyDataBuffer(), nullptr); - EXPECT_EQ(std::any_cast<FifoBase *>(v_dst_op->GetObject()), - static_cast<FifoBase *>(vfifo_)); + EXPECT_EQ(std::any_cast<FifoBase*>(v_dst_op->GetObject()), + static_cast<FifoBase*>(vfifo_)); EXPECT_EQ(v_dst_op->AsString(), kVectorFifoName); v_dst_op = @@ -123,7 +122,7 @@ auto src_op = sfifo_->CreateSourceOperand(); // Get DataBuffer from destination operand and initialize the value. - DataBuffer *db = dst_op->AllocateDataBuffer(); + DataBuffer* db = dst_op->AllocateDataBuffer(); db->Set<uint32_t>(0, 0xDEADBEEF); // Submit data buffer and advance the delay line by the 1 cycle latency. @@ -142,7 +141,7 @@ EXPECT_EQ(src_op->AsUint64(0), 0xDEADBEEF); // Get a new data buffer and initialize it to a new value. - DataBuffer *db2 = dst_op->AllocateDataBuffer(); + DataBuffer* db2 = dst_op->AllocateDataBuffer(); db2->Set<uint32_t>(0, 0xA5A55A5A); // Submit the data buffer and advance the delay line 1 cycle. @@ -153,11 +152,11 @@ EXPECT_EQ(src_op->AsUint32(0), 0xDEADBEEF); // Pop the fifo and verify the new value is there. - std::any_cast<FifoBase *>(src_op->GetObject())->Pop(); + std::any_cast<FifoBase*>(src_op->GetObject())->Pop(); EXPECT_EQ(src_op->AsUint32(0), 0xA5A55A5A); // Pop the fifo. It is now empty, so attempting to get a value will return 0. - std::any_cast<FifoBase *>(src_op->GetObject())->Pop(); + std::any_cast<FifoBase*>(src_op->GetObject())->Pop(); EXPECT_EQ(src_op->AsUint32(0), 0); EXPECT_EQ(src_op->AsInt32(0), 0); @@ -172,7 +171,7 @@ auto src_op = vfifo_->CreateSourceOperand(); // Get DataBuffer from destination operand and initialize the value. - DataBuffer *db = dst_op->AllocateDataBuffer(); + DataBuffer* db = dst_op->AllocateDataBuffer(); for (int index = 0; index < vfifo_->shape()[0]; index++) { db->Set<uint32_t>(index, 0xDEAD0000 | index); } @@ -188,7 +187,7 @@ } // Get another DataBuffer from destination operand and initialize to zeros. - DataBuffer *db2 = dst_op->AllocateDataBuffer(); + DataBuffer* db2 = dst_op->AllocateDataBuffer(); for (int index = 0; index < vfifo_->shape()[0]; index++) { db2->Set<uint32_t>(index, 0); } @@ -204,7 +203,7 @@ } // Pop the fifo and verify that the value has been updated. - std::any_cast<FifoBase *>(src_op->GetObject())->Pop(); + std::any_cast<FifoBase*>(src_op->GetObject())->Pop(); for (int index = 0; index < vfifo_->shape()[0]; index++) { EXPECT_EQ(src_op->AsUint32(index), 0); }
diff --git a/mpact/sim/generic/test/fifo_test.cc b/mpact/sim/generic/test/fifo_test.cc index 5deed7b..57b7062 100644 --- a/mpact/sim/generic/test/fifo_test.cc +++ b/mpact/sim/generic/test/fifo_test.cc
@@ -17,15 +17,12 @@ #include <cstdint> #include <memory> -#include "absl/memory/memory.h" -#include "googlemock/include/gmock/gmock.h" +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" -#include "mpact/sim/generic/config.h" #include "mpact/sim/generic/data_buffer.h" #include "mpact/sim/generic/program_error.h" #include "mpact/sim/proto/component_data.pb.h" #include "src/google/protobuf/text_format.h" -#include "src/google/protobuf/util/message_differencer.h" namespace mpact { namespace sim { @@ -107,7 +104,7 @@ EXPECT_EQ(scalar_fifo->Front(), nullptr); // Allocate a data buffer of the right byte size and bind it to the fifo. - DataBuffer *db = db_factory_->Allocate(scalar_fifo->size()); + DataBuffer* db = db_factory_->Allocate(scalar_fifo->size()); scalar_fifo->SetDataBuffer(db); EXPECT_EQ(scalar_fifo->Available(), 1); EXPECT_FALSE(scalar_fifo->IsFull()); @@ -126,7 +123,7 @@ EXPECT_EQ(vector_fifo->Front(), nullptr); // Allocate a data buffer of the right byte size and bind it to the fifo. - DataBuffer *db = db_factory_->Allocate(vector_fifo->size()); + DataBuffer* db = db_factory_->Allocate(vector_fifo->size()); vector_fifo->SetDataBuffer(db); EXPECT_EQ(vector_fifo->Available(), 1); EXPECT_FALSE(vector_fifo->IsFull()); @@ -146,7 +143,7 @@ EXPECT_EQ(matrix_fifo->Front(), nullptr); // Allocate a data buffer of the right byte size and bind it to the fifo. - DataBuffer *db = db_factory_->Allocate(matrix_fifo->size()); + DataBuffer* db = db_factory_->Allocate(matrix_fifo->size()); matrix_fifo->SetDataBuffer(db); EXPECT_EQ(matrix_fifo->Available(), 1); EXPECT_FALSE(matrix_fifo->IsFull()); @@ -162,7 +159,7 @@ TEST_F(FifoTest, EmptyFullEmpty) { auto fifo = std::make_unique<ScalarFifo>(nullptr, "S0", kFifoDepth); - DataBuffer *db[kFifoDepth + 1]; + DataBuffer* db[kFifoDepth + 1]; for (int db_num = 0; db_num < kFifoDepth + 1; db_num++) { db[db_num] = db_factory_->Allocate(fifo->size()); } @@ -212,7 +209,7 @@ EXPECT_TRUE(fifo->IsFull()); EXPECT_FALSE(fifo->IsOverSubscribed()); - DataBuffer *db[kFifoDepth]; + DataBuffer* db[kFifoDepth]; for (int db_num = 0; db_num < kFifoDepth; db_num++) { db[db_num] = db_factory_->Allocate(fifo->size()); fifo->Push(db[db_num]); @@ -267,7 +264,7 @@ fifo->SetOverflowProgramError(&overflow); EXPECT_FALSE(controller_->HasError()); - DataBuffer *db[kFifoDepth + 1]; + DataBuffer* db[kFifoDepth + 1]; for (int db_num = 0; db_num < kFifoDepth + 1; db_num++) { db[db_num] = db_factory_->Allocate(fifo->size()); fifo->Push(db[db_num]);
diff --git a/mpact/sim/generic/test/fifo_with_notify_test.cc b/mpact/sim/generic/test/fifo_with_notify_test.cc index 09953e2..98d9f58 100644 --- a/mpact/sim/generic/test/fifo_with_notify_test.cc +++ b/mpact/sim/generic/test/fifo_with_notify_test.cc
@@ -14,13 +14,12 @@ #include "mpact/sim/generic/fifo_with_notify.h" +#include <cstdint> #include <memory> -#include "absl/memory/memory.h" -#include "googlemock/include/gmock/gmock.h" +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" #include "mpact/sim/generic/data_buffer.h" -#include "mpact/sim/generic/program_error.h" namespace { @@ -48,7 +47,7 @@ TEST_F(FifoWithNotifyTest, NoCallbacks) { EXPECT_TRUE(fifo_->IsEmpty()); - auto *db = db_factory_->Allocate(sizeof(uint32_t)); + auto* db = db_factory_->Allocate(sizeof(uint32_t)); fifo_->Push(db); EXPECT_TRUE(!fifo_->IsEmpty()); fifo_->Pop(); @@ -59,10 +58,10 @@ int on_empty_count = 0; int on_not_empty_count = 0; fifo_->SetOnEmpty( - [&on_empty_count](FifoWithNotifyBase *) { on_empty_count++; }); + [&on_empty_count](FifoWithNotifyBase*) { on_empty_count++; }); fifo_->SetOnNotEmpty( - [&on_not_empty_count](FifoWithNotifyBase *) { on_not_empty_count++; }); - auto *db = db_factory_->Allocate(sizeof(uint32_t)); + [&on_not_empty_count](FifoWithNotifyBase*) { on_not_empty_count++; }); + auto* db = db_factory_->Allocate(sizeof(uint32_t)); EXPECT_EQ(on_empty_count, 0); EXPECT_EQ(on_not_empty_count, 0); (void)fifo_->Push(db);
diff --git a/mpact/sim/generic/test/immediate_operand_test.cc b/mpact/sim/generic/test/immediate_operand_test.cc index 9c69eef..441f3af 100644 --- a/mpact/sim/generic/test/immediate_operand_test.cc +++ b/mpact/sim/generic/test/immediate_operand_test.cc
@@ -14,13 +14,13 @@ #include "mpact/sim/generic/immediate_operand.h" +#include <cstddef> #include <cstdint> #include <limits> #include <memory> #include <vector> -#include "absl/memory/memory.h" -#include "googlemock/include/gmock/gmock.h" +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" namespace mpact {
diff --git a/mpact/sim/generic/test/instruction_test.cc b/mpact/sim/generic/test/instruction_test.cc index 3c29e09..d1d3b63 100644 --- a/mpact/sim/generic/test/instruction_test.cc +++ b/mpact/sim/generic/test/instruction_test.cc
@@ -16,6 +16,7 @@ #include <memory> +#include "absl/types/span.h" #include "googlemock/include/gmock/gmock.h" #include "googletest/include/gtest/gtest.h" #include "mpact/sim/generic/ref_count.h" @@ -27,7 +28,7 @@ struct InstructionContext : public ReferenceCount { public: - int *value; + int* value; }; // Tests values of the instruction properties. @@ -54,10 +55,10 @@ auto my_context = std::make_unique<InstructionContext>(); my_context->value = &context_value; - inst->set_semantic_function([&](Instruction *inst) { - EXPECT_EQ(inst->context(), static_cast<ReferenceCount *>(my_context.get())); + inst->set_semantic_function([&](Instruction* inst) { + EXPECT_EQ(inst->context(), static_cast<ReferenceCount*>(my_context.get())); my_value = 1; - auto context = static_cast<InstructionContext *>(inst->context()); + auto context = static_cast<InstructionContext*>(inst->context()); ++(*context->value); }); @@ -70,8 +71,8 @@ TEST(InstructionTest, ChildBundle) { auto inst = std::make_unique<Instruction>(0x1000, nullptr); - Instruction *child0 = new Instruction(nullptr); - Instruction *child1 = new Instruction(nullptr); + Instruction* child0 = new Instruction(nullptr); + Instruction* child1 = new Instruction(nullptr); inst->AppendChild(nullptr); EXPECT_EQ(inst->child(), nullptr); @@ -93,8 +94,8 @@ TEST(InstructionTest, InstructionList) { auto inst = std::make_unique<Instruction>(0x1000, nullptr); - Instruction *next0 = new Instruction(nullptr); - Instruction *next1 = new Instruction(nullptr); + Instruction* next0 = new Instruction(nullptr); + Instruction* next1 = new Instruction(nullptr); inst->Append(nullptr); EXPECT_EQ(inst->next(), nullptr);
diff --git a/mpact/sim/generic/test/program_error_test.cc b/mpact/sim/generic/test/program_error_test.cc index dc32e61..c93af64 100644 --- a/mpact/sim/generic/test/program_error_test.cc +++ b/mpact/sim/generic/test/program_error_test.cc
@@ -36,7 +36,7 @@ ~ProgramErrorTest() override { delete controller_; } - ProgramErrorController *controller_; + ProgramErrorController* controller_; }; TEST_F(ProgramErrorTest, ControllerInstantiation) {
diff --git a/mpact/sim/generic/test/ref_count_test.cc b/mpact/sim/generic/test/ref_count_test.cc index 3622d6a..03dff6a 100644 --- a/mpact/sim/generic/test/ref_count_test.cc +++ b/mpact/sim/generic/test/ref_count_test.cc
@@ -14,7 +14,7 @@ #include "mpact/sim/generic/ref_count.h" -#include "googlemock/include/gmock/gmock.h" +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" namespace mpact { @@ -25,7 +25,7 @@ // Test class that counts calls to the destructor and OnRefCountIsZero. class TestRefCount : public ReferenceCount { public: - TestRefCount(int *destructor_call_count, int *refcount_zero_call_count) + TestRefCount(int* destructor_call_count, int* refcount_zero_call_count) : destructor_call_count_(destructor_call_count), refcount_zero_call_count_(refcount_zero_call_count) {} @@ -45,20 +45,20 @@ } private: - int *destructor_call_count_; - int *refcount_zero_call_count_; + int* destructor_call_count_; + int* refcount_zero_call_count_; }; // Call constructor and ensure that the refcount is initialized to 1. TEST(RefCount, Create) { - ReferenceCount *ref_count = new ReferenceCount(); + ReferenceCount* ref_count = new ReferenceCount(); EXPECT_EQ(ref_count->ref_count(), 1); ref_count->DecRef(); } // Test that ref count increases when Inc is called. TEST(RefCount, IncRef) { - ReferenceCount *ref_count = new ReferenceCount(); + ReferenceCount* ref_count = new ReferenceCount(); EXPECT_EQ(ref_count->ref_count(), 1); ref_count->IncRef(); EXPECT_EQ(ref_count->ref_count(), 2); @@ -73,7 +73,7 @@ TEST(RefCount, OnRefCountIsZero) { int destructor_call_count = 0; int refcount_zero_call_count = 0; - TestRefCount *test_ref_count = + TestRefCount* test_ref_count = new TestRefCount(&destructor_call_count, &refcount_zero_call_count); EXPECT_EQ(test_ref_count->ref_count(), 1);
diff --git a/mpact/sim/generic/test/register_operand_test.cc b/mpact/sim/generic/test/register_operand_test.cc index 8dcaac2..bd8b91c 100644 --- a/mpact/sim/generic/test/register_operand_test.cc +++ b/mpact/sim/generic/test/register_operand_test.cc
@@ -17,11 +17,10 @@ #include "absl/strings/string_view.h" #include "absl/types/any.h" -#include "googlemock/include/gmock/gmock.h" +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" #include "mpact/sim/generic/arch_state.h" #include "mpact/sim/generic/data_buffer.h" -#include "mpact/sim/generic/delay_line.h" #include "mpact/sim/generic/operand_interface.h" #include "mpact/sim/generic/register.h" #include "mpact/sim/generic/simple_resource.h" @@ -42,7 +41,7 @@ // protected. class MockArchState : public ArchState { public: - MockArchState(absl::string_view id, SourceOperandInterface *pc_op) + MockArchState(absl::string_view id, SourceOperandInterface* pc_op) : ArchState(id, pc_op) {} explicit MockArchState(absl::string_view id) : MockArchState(id, nullptr) {} }; @@ -70,30 +69,30 @@ delete arch_state_; } - MockArchState *arch_state_; - ScalarRegister *sreg_; - Vector8Register *vreg_; - ScalarReservedRegister *rreg_ = nullptr; - SimpleResourcePool *pool_; + MockArchState* arch_state_; + ScalarRegister* sreg_; + Vector8Register* vreg_; + ScalarReservedRegister* rreg_ = nullptr; + SimpleResourcePool* pool_; }; // Tests that the register source operands are initialized correctly. TEST_F(RegisterOperandTest, SourceOperandInitialization) { auto s_src_op = sreg_->CreateSourceOperand(); - EXPECT_EQ(std::any_cast<RegisterBase *>(s_src_op->GetObject()), - static_cast<RegisterBase *>(sreg_)); + EXPECT_EQ(std::any_cast<RegisterBase*>(s_src_op->GetObject()), + static_cast<RegisterBase*>(sreg_)); EXPECT_EQ(s_src_op->shape(), sreg_->shape()); delete s_src_op; auto v_src_op = vreg_->CreateSourceOperand(); - EXPECT_EQ(std::any_cast<RegisterBase *>(v_src_op->GetObject()), - static_cast<RegisterBase *>(vreg_)); + EXPECT_EQ(std::any_cast<RegisterBase*>(v_src_op->GetObject()), + static_cast<RegisterBase*>(vreg_)); EXPECT_EQ(v_src_op->shape(), vreg_->shape()); delete v_src_op; auto r_src_op = rreg_->CreateSourceOperand(); - EXPECT_EQ(std::any_cast<RegisterBase *>(r_src_op->GetObject()), - static_cast<RegisterBase *>(rreg_)); + EXPECT_EQ(std::any_cast<RegisterBase*>(r_src_op->GetObject()), + static_cast<RegisterBase*>(rreg_)); EXPECT_EQ(r_src_op->shape(), rreg_->shape()); delete r_src_op; } @@ -103,22 +102,22 @@ auto s_dst_op = sreg_->CreateDestinationOperand(1); EXPECT_EQ(s_dst_op->latency(), 1); EXPECT_EQ(s_dst_op->shape(), sreg_->shape()); - EXPECT_EQ(std::any_cast<RegisterBase *>(s_dst_op->GetObject()), - static_cast<RegisterBase *>(sreg_)); + EXPECT_EQ(std::any_cast<RegisterBase*>(s_dst_op->GetObject()), + static_cast<RegisterBase*>(sreg_)); delete s_dst_op; auto v_dst_op = vreg_->CreateDestinationOperand(4); EXPECT_EQ(v_dst_op->latency(), 4); EXPECT_EQ(v_dst_op->shape(), vreg_->shape()); - EXPECT_EQ(std::any_cast<RegisterBase *>(v_dst_op->GetObject()), - static_cast<RegisterBase *>(vreg_)); + EXPECT_EQ(std::any_cast<RegisterBase*>(v_dst_op->GetObject()), + static_cast<RegisterBase*>(vreg_)); delete v_dst_op; auto r_dst_op = rreg_->CreateDestinationOperand(3); EXPECT_EQ(r_dst_op->latency(), 3); EXPECT_EQ(r_dst_op->shape(), rreg_->shape()); - EXPECT_EQ(std::any_cast<RegisterBase *>(r_dst_op->GetObject()), - static_cast<RegisterBase *>(rreg_)); + EXPECT_EQ(std::any_cast<RegisterBase*>(r_dst_op->GetObject()), + static_cast<RegisterBase*>(rreg_)); delete r_dst_op; } @@ -129,7 +128,7 @@ auto src_op = sreg_->CreateSourceOperand(); // Get DataBuffer from destination operand and initialize the value. - DataBuffer *db = dst_op->AllocateDataBuffer(); + DataBuffer* db = dst_op->AllocateDataBuffer(); db->Set<uint32_t>(0, 0xDEADBEEF); // Submit data buffer and advance the delay line by the 1 cycle latency. db->Submit(); @@ -140,7 +139,7 @@ // Get a new data buffer with copy of the current value and verify value is // correct. - DataBuffer *db2 = dst_op->CopyDataBuffer(); + DataBuffer* db2 = dst_op->CopyDataBuffer(); EXPECT_EQ(db2->Get<uint32_t>(0), 0xDEADBEEF); // Change value, submit the data buffer and advance the delay line 1 cycle. @@ -162,7 +161,7 @@ auto src_op = vreg_->CreateSourceOperand(); // Get DataBuffer from destination operand and initialize the value. - DataBuffer *db = dst_op->AllocateDataBuffer(); + DataBuffer* db = dst_op->AllocateDataBuffer(); for (int index = 0; index < vreg_->shape()[0]; index++) { db->Set<uint32_t>(index, 0xDEAD0000 | index); } @@ -178,7 +177,7 @@ } // Get DataBuffer from destination operand with copy of the current value. - DataBuffer *db2 = dst_op->CopyDataBuffer(); + DataBuffer* db2 = dst_op->CopyDataBuffer(); // Verify that the value is the same as before. for (int index = 0; index < vreg_->shape()[0]; index++) { @@ -210,7 +209,7 @@ rreg_->resource()->Acquire(); // Get DataBuffer from destination operand and initialize the value. - DataBuffer *db = dst_op->AllocateDataBuffer(); + DataBuffer* db = dst_op->AllocateDataBuffer(); db->Set<uint32_t>(0, 0xDEAD0000); @@ -225,7 +224,7 @@ EXPECT_EQ(src_op->AsUint32(0), 0xDEAD0000); // Get DataBuffer from destination operand with copy of the current value. - DataBuffer *db2 = dst_op->CopyDataBuffer(); + DataBuffer* db2 = dst_op->CopyDataBuffer(); EXPECT_TRUE(rreg_->resource()->IsFree()); rreg_->resource()->Acquire();
diff --git a/mpact/sim/generic/test/register_test.cc b/mpact/sim/generic/test/register_test.cc index 8badee8..4b00d2b 100644 --- a/mpact/sim/generic/test/register_test.cc +++ b/mpact/sim/generic/test/register_test.cc
@@ -17,9 +17,9 @@ #include <cstdint> #include <memory> -#include "absl/memory/memory.h" -#include "googlemock/include/gmock/gmock.h" +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" +#include "mpact/sim/generic/data_buffer.h" #include "mpact/sim/generic/simple_resource.h" namespace mpact { @@ -54,8 +54,8 @@ delete pool_; } - DataBufferFactory *db_factory_; - SimpleResourcePool *pool_; + DataBufferFactory* db_factory_; + SimpleResourcePool* pool_; }; // Create scalar register and verify attributes. @@ -91,7 +91,7 @@ nullptr, "S0", pool_->GetResource("S0")); pool_->GetResource("S0")->Acquire(); EXPECT_FALSE(pool_->GetResource("S0")->IsFree()); - auto *db = db_factory_->Allocate(scalar_reserved_reg->size()); + auto* db = db_factory_->Allocate(scalar_reserved_reg->size()); scalar_reserved_reg->SetDataBuffer(db); EXPECT_TRUE(pool_->GetResource("S0")->IsFree()); db->DecRef(); @@ -104,7 +104,7 @@ EXPECT_EQ(scalar_reg->data_buffer(), nullptr); // Allocate a data buffer of the right byte size and bind it to the register. - DataBuffer *db = db_factory_->Allocate(scalar_reg->size()); + DataBuffer* db = db_factory_->Allocate(scalar_reg->size()); scalar_reg->SetDataBuffer(db); // Verify reference count is 2, then DecRef. @@ -120,7 +120,7 @@ EXPECT_EQ(vector_reg->data_buffer(), nullptr); // Allocate a data buffer of the right byte size and bind it to the register. - DataBuffer *db = db_factory_->Allocate(vector_reg->size()); + DataBuffer* db = db_factory_->Allocate(vector_reg->size()); vector_reg->SetDataBuffer(db); // Verify reference count is 2, then DecRef. @@ -136,7 +136,7 @@ EXPECT_EQ(matrix_reg->data_buffer(), nullptr); // Allocate a data buffer of the right byte size and bind it to the register. - DataBuffer *db = db_factory_->Allocate(matrix_reg->size()); + DataBuffer* db = db_factory_->Allocate(matrix_reg->size()); matrix_reg->SetDataBuffer(db); // Verify reference count is 2, then DecRef.
diff --git a/mpact/sim/generic/test/simple_resource_test.cc b/mpact/sim/generic/test/simple_resource_test.cc index b9c7578..51b929d 100644 --- a/mpact/sim/generic/test/simple_resource_test.cc +++ b/mpact/sim/generic/test/simple_resource_test.cc
@@ -33,7 +33,7 @@ static constexpr char kTestResource0[] = "Resource0"; static constexpr char kTestResource1[] = "Resource1"; static constexpr char kTestResource2[] = "Resource2"; -static constexpr char const *kTestResources[] = {kTestResource0, kTestResource1, +static constexpr char const* kTestResources[] = {kTestResource0, kTestResource1, kTestResource2}; class SimpleResourceTest : public testing::Test { @@ -53,9 +53,9 @@ } TEST_F(SimpleResourceTest, Resources) { - SimpleResource *resources[kNumResources]; + SimpleResource* resources[kNumResources]; for (int num = 0; num < kNumResources; num++) { - const char *name = kTestResources[num]; + const char* name = kTestResources[num]; // Creat resource. EXPECT_TRUE(pool_->AddResource(name).ok()); resources[num] = pool_->GetResource(name); @@ -83,16 +83,16 @@ } TEST_F(SimpleResourceTest, ResourceSets) { - SimpleResource *resources[kNumResources]; + SimpleResource* resources[kNumResources]; for (int num = 0; num < kNumResources; num++) { - const char *name = kTestResources[num]; + const char* name = kTestResources[num]; // Creat resource. EXPECT_TRUE(pool_->AddResource(name).ok()); resources[num] = pool_->GetResource(name); } // Create a resource set and add resource 0 and 1 to it. - SimpleResourceSet *resource_set = pool_->CreateResourceSet(); + SimpleResourceSet* resource_set = pool_->CreateResourceSet(); EXPECT_TRUE(resource_set->AddResource(kTestResource0).ok()); EXPECT_TRUE(resource_set->AddResource(resources[1]).ok());
diff --git a/mpact/sim/generic/test/state_item_base_test.cc b/mpact/sim/generic/test/state_item_base_test.cc index 2927161..07a7fc2 100644 --- a/mpact/sim/generic/test/state_item_base_test.cc +++ b/mpact/sim/generic/test/state_item_base_test.cc
@@ -33,8 +33,8 @@ class TestStateItemBase : public StateItemBase { public: - void SetDataBuffer(DataBuffer *db) override {} - TestStateItemBase(ArchState *state, absl::string_view nm, + void SetDataBuffer(DataBuffer* db) override {} + TestStateItemBase(ArchState* state, absl::string_view nm, const std::vector<int> sz, int unit_size) : StateItemBase(state, nm, sz, unit_size) {} ~TestStateItemBase() override {}
diff --git a/mpact/sim/generic/test/status_register_test.cc b/mpact/sim/generic/test/status_register_test.cc index 6e53b82..34643db 100644 --- a/mpact/sim/generic/test/status_register_test.cc +++ b/mpact/sim/generic/test/status_register_test.cc
@@ -55,14 +55,14 @@ delete src_op_64_; } - StatusRegister<uint8_t> *status_8_; - StatusRegister<uint16_t> *status_16_; - StatusRegister<uint32_t> *status_32_; - StatusRegister<uint64_t> *status_64_; - StatusRegisterSourceOperand<uint8_t> *src_op_8_; - StatusRegisterSourceOperand<uint16_t> *src_op_16_; - StatusRegisterSourceOperand<uint32_t> *src_op_32_; - StatusRegisterSourceOperand<uint64_t> *src_op_64_; + StatusRegister<uint8_t>* status_8_; + StatusRegister<uint16_t>* status_16_; + StatusRegister<uint32_t>* status_32_; + StatusRegister<uint64_t>* status_64_; + StatusRegisterSourceOperand<uint8_t>* src_op_8_; + StatusRegisterSourceOperand<uint16_t>* src_op_16_; + StatusRegisterSourceOperand<uint32_t>* src_op_32_; + StatusRegisterSourceOperand<uint64_t>* src_op_64_; }; // Test that initial values are all 0.
diff --git a/mpact/sim/generic/test/token_fifo_test.cc b/mpact/sim/generic/test/token_fifo_test.cc index c925082..752983d 100644 --- a/mpact/sim/generic/test/token_fifo_test.cc +++ b/mpact/sim/generic/test/token_fifo_test.cc
@@ -14,10 +14,10 @@ #include "mpact/sim/generic/token_fifo.h" +#include <algorithm> #include <cstdint> #include <memory> -#include "absl/memory/memory.h" #include "googlemock/include/gmock/gmock.h" #include "googletest/include/gtest/gtest.h" #include "mpact/sim/generic/data_buffer.h" @@ -73,7 +73,7 @@ EXPECT_EQ(scalar_fifo->Front(), nullptr); // Allocate a data buffer of the right byte size and bind it to the fifo. - DataBuffer *db = db_factory_->Allocate(scalar_fifo->size()); + DataBuffer* db = db_factory_->Allocate(scalar_fifo->size()); scalar_fifo->SetDataBuffer(db); EXPECT_EQ(scalar_fifo->Available(), 1); EXPECT_FALSE(scalar_fifo->IsFull()); @@ -90,7 +90,7 @@ auto fifo = std::make_unique<ScalarTokenFifo>(nullptr, "S0", kFifoDepth, &token_store_); - DataBuffer *db[kNumTokens + 1]; + DataBuffer* db[kNumTokens + 1]; for (int db_num = 0; db_num < kNumTokens + 1; db_num++) { db[db_num] = db_factory_->Allocate(fifo->size()); } @@ -142,7 +142,7 @@ EXPECT_TRUE(fifo->IsFull()); EXPECT_FALSE(fifo->IsOverSubscribed()); - DataBuffer *db[kNumTokens]; + DataBuffer* db[kNumTokens]; for (int db_num = 0; db_num < kNumTokens; db_num++) { db[db_num] = db_factory_->Allocate(fifo->size()); fifo->Push(db[db_num]); @@ -200,7 +200,7 @@ fifo->SetOverflowProgramError(&overflow); EXPECT_FALSE(controller_->HasError()); - DataBuffer *db[kNumTokens + 1]; + DataBuffer* db[kNumTokens + 1]; for (int db_num = 0; db_num < kNumTokens + 1; db_num++) { db[db_num] = db_factory_->Allocate(fifo->size()); fifo->Push(db[db_num]);
diff --git a/mpact/sim/generic/token_fifo.cc b/mpact/sim/generic/token_fifo.cc index b2452f6..978d62d 100644 --- a/mpact/sim/generic/token_fifo.cc +++ b/mpact/sim/generic/token_fifo.cc
@@ -16,6 +16,12 @@ #include <vector> +#include "absl/status/status.h" +#include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" +#include "mpact/sim/generic/arch_state.h" +#include "mpact/sim/generic/data_buffer.h" + namespace mpact { namespace sim { namespace generic { @@ -38,9 +44,9 @@ } // Token fifo base method definitions. -TokenFifoBase::TokenFifoBase(ArchState *arch_state, absl::string_view name, - const std::vector<int> &shape, int element_size, - unsigned capacity, FifoTokenStore *tokens) +TokenFifoBase::TokenFifoBase(ArchState* arch_state, absl::string_view name, + const std::vector<int>& shape, int element_size, + unsigned capacity, FifoTokenStore* tokens) : FifoBase(arch_state, name, shape, element_size, capacity), token_store_(tokens) {} @@ -54,7 +60,7 @@ return Reserved() > token_store_->available(); } -bool TokenFifoBase::Push(DataBuffer *db) { +bool TokenFifoBase::Push(DataBuffer* db) { if (token_store_->available() == 0) { if (nullptr != overflow_program_error()) { overflow_program_error()->Raise("Overflow in fifo " + name());
diff --git a/mpact/sim/generic/token_fifo.h b/mpact/sim/generic/token_fifo.h index f1aeaad..b583ca6 100644 --- a/mpact/sim/generic/token_fifo.h +++ b/mpact/sim/generic/token_fifo.h
@@ -22,7 +22,6 @@ #include "mpact/sim/generic/arch_state.h" #include "mpact/sim/generic/data_buffer.h" #include "mpact/sim/generic/fifo.h" -#include "mpact/sim/generic/program_error.h" #include "mpact/sim/generic/state_item.h" #include "mpact/sim/generic/state_item_base.h" @@ -55,20 +54,20 @@ class TokenFifoBase : public FifoBase { protected: - TokenFifoBase(ArchState *arch_state, absl::string_view name, - const std::vector<int> &shape, int element_size, - unsigned capacity, FifoTokenStore *tokens); + TokenFifoBase(ArchState* arch_state, absl::string_view name, + const std::vector<int>& shape, int element_size, + unsigned capacity, FifoTokenStore* tokens); TokenFifoBase() = delete; - TokenFifoBase(const TokenFifoBase &) = delete; + TokenFifoBase(const TokenFifoBase&) = delete; public: bool IsOverSubscribed() const override; bool IsFull() const override; - bool Push(DataBuffer *db) override; + bool Push(DataBuffer* db) override; void Pop() override; private: - FifoTokenStore *token_store_; + FifoTokenStore* token_store_; }; template <typename ElementType>
diff --git a/mpact/sim/generic/type_helpers.h b/mpact/sim/generic/type_helpers.h index 4816ed1..bd5ec36 100644 --- a/mpact/sim/generic/type_helpers.h +++ b/mpact/sim/generic/type_helpers.h
@@ -151,23 +151,23 @@ static constexpr UIntType kPosInf = kExpMask; static constexpr UIntType kNegInf = kExpMask | (1ULL << (kBitSize - 1)); static inline bool IsInf(T value) { - UIntType uint_val = *reinterpret_cast<UIntType *>(&value); + UIntType uint_val = *reinterpret_cast<UIntType*>(&value); return (uint_val & kInfMask) == kPosInf; } static inline bool IsNaN(T value) { - UIntType uint_val = *reinterpret_cast<UIntType *>(&value); + UIntType uint_val = *reinterpret_cast<UIntType*>(&value); return ((uint_val & kExpMask) == kExpMask) && ((uint_val & kSigMask) != 0); } static inline bool IsSNaN(T value) { - UIntType uint_val = *reinterpret_cast<UIntType *>(&value); + UIntType uint_val = *reinterpret_cast<UIntType*>(&value); return IsNaN(value) && (((1 << (kSigSize - 1)) & uint_val) == 0); } static inline bool IsQNaN(T value) { - UIntType uint_val = *reinterpret_cast<UIntType *>(&value); + UIntType uint_val = *reinterpret_cast<UIntType*>(&value); return IsNaN(value) && (((1 << (kSigSize - 1)) & uint_val) != 0); } static inline bool SignBit(T value) { - UIntType uint_val = *reinterpret_cast<UIntType *>(&value); + UIntType uint_val = *reinterpret_cast<UIntType*>(&value); return 1 == (uint_val >> (kBitSize - 1)); } }; @@ -189,23 +189,23 @@ static constexpr UIntType kPosInf = kExpMask; static constexpr UIntType kNegInf = kExpMask | (1ULL << (kBitSize - 1)); static inline bool IsInf(T value) { - UIntType uint_val = *reinterpret_cast<UIntType *>(&value); + UIntType uint_val = *reinterpret_cast<UIntType*>(&value); return (uint_val & kInfMask) == kPosInf; } static inline bool IsNaN(T value) { - UIntType uint_val = *reinterpret_cast<UIntType *>(&value); + UIntType uint_val = *reinterpret_cast<UIntType*>(&value); return ((uint_val & kExpMask) == kExpMask) && ((uint_val & kSigMask) != 0); } static inline bool IsSNaN(T value) { - UIntType uint_val = *reinterpret_cast<UIntType *>(&value); + UIntType uint_val = *reinterpret_cast<UIntType*>(&value); return IsNaN(value) && (((1 << (kSigSize - 1)) & uint_val) == 0); } static inline bool IsQNaN(T value) { - UIntType uint_val = *reinterpret_cast<UIntType *>(&value); + UIntType uint_val = *reinterpret_cast<UIntType*>(&value); return IsNaN(value) && (((1 << (kSigSize - 1)) & uint_val) != 0); } static inline bool SignBit(T value) { - UIntType uint_val = *reinterpret_cast<UIntType *>(&value); + UIntType uint_val = *reinterpret_cast<UIntType*>(&value); return 1 == (uint_val >> (kBitSize - 1)); } }; @@ -227,23 +227,23 @@ static constexpr UIntType kPosInf = kExpMask; static constexpr UIntType kNegInf = kExpMask | (1ULL << (kBitSize - 1)); static inline bool IsInf(T value) { - UIntType uint_val = *reinterpret_cast<UIntType *>(&value); + UIntType uint_val = *reinterpret_cast<UIntType*>(&value); return (uint_val & kInfMask) == kPosInf; } static inline bool IsNaN(T value) { - UIntType uint_val = *reinterpret_cast<UIntType *>(&value); + UIntType uint_val = *reinterpret_cast<UIntType*>(&value); return ((uint_val & kExpMask) == kExpMask) && ((uint_val & kSigMask) != 0); } static inline bool IsSNaN(T value) { - UIntType uint_val = *reinterpret_cast<UIntType *>(&value); + UIntType uint_val = *reinterpret_cast<UIntType*>(&value); return IsNaN(value) && (((1ULL << (kSigSize - 1)) & uint_val) == 0); } static inline bool IsQNaN(T value) { - UIntType uint_val = *reinterpret_cast<UIntType *>(&value); + UIntType uint_val = *reinterpret_cast<UIntType*>(&value); return IsNaN(value) && (((1ULL << (kSigSize - 1)) & uint_val) != 0); } static inline bool SignBit(T value) { - UIntType uint_val = *reinterpret_cast<UIntType *>(&value); + UIntType uint_val = *reinterpret_cast<UIntType*>(&value); return 1 == (uint_val >> (kBitSize - 1)); } }; @@ -426,28 +426,28 @@ if (half.value == FPTypeInfo<HalfFP>::kPosInf) { float_uint = FPTypeInfo<float>::kPosInf; - return *reinterpret_cast<float *>(&float_uint); + return *reinterpret_cast<float*>(&float_uint); } if (half.value == FPTypeInfo<HalfFP>::kNegInf) { float_uint = FPTypeInfo<float>::kNegInf; - return *reinterpret_cast<float *>(&float_uint); + return *reinterpret_cast<float*>(&float_uint); } if (FPTypeInfo<HalfFP>::IsNaN(half)) { float_uint = FPTypeInfo<float>::kCanonicalNaN; float_uint |= sign << (FPTypeInfo<float>::kBitSize - 1); - return *reinterpret_cast<float *>(&float_uint); + return *reinterpret_cast<float*>(&float_uint); } if (half.value == 0) { float_uint = 0; - return *reinterpret_cast<float *>(&float_uint); + return *reinterpret_cast<float*>(&float_uint); } if (half.value == 1 << (FPTypeInfo<HalfFP>::kBitSize - 1)) { float_uint = 1 << (FPTypeInfo<float>::kBitSize - 1); - return *reinterpret_cast<float *>(&float_uint); + return *reinterpret_cast<float*>(&float_uint); } uint32_t exp = (half.value & FPTypeInfo<HalfFP>::kExpMask) >> @@ -467,7 +467,7 @@ sig <<= FPTypeInfo<float>::kSigSize - FPTypeInfo<HalfFP>::kSigSize; float_uint = (exp << FPTypeInfo<float>::kSigSize) | sig; float_uint |= sign << (FPTypeInfo<float>::kBitSize - 1); - return *reinterpret_cast<float *>(&float_uint); + return *reinterpret_cast<float*>(&float_uint); } // A replacement for std::is_floating_point that works for half precision.
diff --git a/mpact/sim/generic/wrapper_operand.h b/mpact/sim/generic/wrapper_operand.h index f5954ed..daf9e00 100644 --- a/mpact/sim/generic/wrapper_operand.h +++ b/mpact/sim/generic/wrapper_operand.h
@@ -34,11 +34,11 @@ template <typename T> class WrapperSourceOperand : public SourceOperandInterface { public: - WrapperSourceOperand(T *value, const std::vector<int> &shape) + WrapperSourceOperand(T* value, const std::vector<int>& shape) : value_(value), shape_(shape) {} WrapperSourceOperand() = delete; - WrapperSourceOperand(const WrapperSourceOperand &) = delete; - WrapperSourceOperand &operator=(const WrapperSourceOperand &) = delete; + WrapperSourceOperand(const WrapperSourceOperand&) = delete; + WrapperSourceOperand& operator=(const WrapperSourceOperand&) = delete; bool AsBool(int index) override { return false; } int8_t AsInt8(int index) override { return 0; } uint8_t AsUint8(int index) override { return 0; } @@ -57,7 +57,7 @@ std::string AsString() const override { return value_->AsString(); } private: - T *value_; + T* value_; std::vector<int> shape_; }; @@ -67,17 +67,17 @@ template <typename T> class WrapperDestinationOperand : public DestinationOperandInterface { public: - WrapperDestinationOperand(T *value, const std::vector<int> &shape) + WrapperDestinationOperand(T* value, const std::vector<int>& shape) : value_(value), shape_(shape) {} WrapperDestinationOperand() = delete; - WrapperDestinationOperand(const WrapperDestinationOperand &) = delete; - WrapperDestinationOperand &operator=(const WrapperDestinationOperand &) = + WrapperDestinationOperand(const WrapperDestinationOperand&) = delete; + WrapperDestinationOperand& operator=(const WrapperDestinationOperand&) = delete; ~WrapperDestinationOperand() override = default; - DataBuffer *AllocateDataBuffer() override { return nullptr; } - void InitializeDataBuffer(DataBuffer *db) override { /* Do nothing. */ } - DataBuffer *CopyDataBuffer() override { return nullptr; } + DataBuffer* AllocateDataBuffer() override { return nullptr; } + void InitializeDataBuffer(DataBuffer* db) override { /* Do nothing. */ } + DataBuffer* CopyDataBuffer() override { return nullptr; } int latency() const override { return 0; } // Return a pointer to the MR object. std::any GetObject() const override { return std::any(value_); } @@ -87,7 +87,7 @@ std::string AsString() const override { return value_->AsString(); } private: - T *value_; + T* value_; std::vector<int> shape_; };
diff --git a/mpact/sim/util/asm/opcode_assembler_interface.h b/mpact/sim/util/asm/opcode_assembler_interface.h index 1663787..2894626 100644 --- a/mpact/sim/util/asm/opcode_assembler_interface.h +++ b/mpact/sim/util/asm/opcode_assembler_interface.h
@@ -42,7 +42,7 @@ uint32_t type; uint64_t addend; uint16_t section_index; - RelocationInfo(uint64_t offset, const std::string &symbol, uint32_t type, + RelocationInfo(uint64_t offset, const std::string& symbol, uint32_t type, uint64_t addend, uint16_t section_index) : offset(offset), symbol(symbol), @@ -55,7 +55,7 @@ public: virtual ~OpcodeAssemblerInterface() = default; using AddSymbolCallback = absl::AnyInvocable<absl::Status( - const std::string &, ELFIO::Elf64_Addr /*value*/, + const std::string&, ELFIO::Elf64_Addr /*value*/, ELFIO::Elf_Xword /*size*/, uint8_t /*type*/, uint8_t /*binding*/, uint8_t /*other*/)>; // Takes the current address, the text for the assembly instruction (including @@ -65,9 +65,9 @@ // the increment to the address after the instruction is encoded. virtual absl::StatusOr<size_t> Encode( uint64_t address, absl::string_view text, - AddSymbolCallback add_symbol_callback, ResolverInterface *resolver, - std::vector<uint8_t> &bytes, - std::vector<RelocationInfo> &relocations) = 0; + AddSymbolCallback add_symbol_callback, ResolverInterface* resolver, + std::vector<uint8_t>& bytes, + std::vector<RelocationInfo>& relocations) = 0; }; } // namespace assembler
diff --git a/mpact/sim/util/asm/resolver.cc b/mpact/sim/util/asm/resolver.cc index f8ec781..e82087d 100644 --- a/mpact/sim/util/asm/resolver.cc +++ b/mpact/sim/util/asm/resolver.cc
@@ -26,8 +26,8 @@ } SymbolResolver::SymbolResolver( - int elf_file_class, ELFIO::section *symtab, - const absl::flat_hash_map<std::string, ELFIO::Elf_Word> &symbol_indices) + int elf_file_class, ELFIO::section* symtab, + const absl::flat_hash_map<std::string, ELFIO::Elf_Word>& symbol_indices) : elf_file_class_(elf_file_class), symtab_(symtab), symbol_indices_(symbol_indices) {} @@ -40,10 +40,10 @@ } auto index = iter->second; if (elf_file_class_ == ELFCLASS64) { - auto *sym = reinterpret_cast<const ELFIO::Elf64_Sym *>(symtab_->get_data()); + auto* sym = reinterpret_cast<const ELFIO::Elf64_Sym*>(symtab_->get_data()); return sym[index].st_value; } else if (elf_file_class_ == ELFCLASS32) { - auto *sym = reinterpret_cast<const ELFIO::Elf32_Sym *>(symtab_->get_data()); + auto* sym = reinterpret_cast<const ELFIO::Elf32_Sym*>(symtab_->get_data()); return sym[index].st_value; } return absl::InternalError("Unsupported ELF file class");
diff --git a/mpact/sim/util/asm/resolver.h b/mpact/sim/util/asm/resolver.h index 3adb3ff..8d81b50 100644 --- a/mpact/sim/util/asm/resolver.h +++ b/mpact/sim/util/asm/resolver.h
@@ -49,17 +49,17 @@ class SymbolResolver : public ResolverInterface { public: SymbolResolver( - int elf_file_class, ELFIO::section *symtab, - const absl::flat_hash_map<std::string, ELFIO::Elf_Word> &symbol_indices); + int elf_file_class, ELFIO::section* symtab, + const absl::flat_hash_map<std::string, ELFIO::Elf_Word>& symbol_indices); absl::StatusOr<uint64_t> Resolve(absl::string_view text) override; private: // Elf file class. int elf_file_class_ = 0; // The symbol table ELF section. - ELFIO::section *symtab_; + ELFIO::section* symtab_; // Map from symbol name to symbol index in the symbol table. - const absl::flat_hash_map<std::string, ELFIO::Elf_Word> &symbol_indices_; + const absl::flat_hash_map<std::string, ELFIO::Elf_Word>& symbol_indices_; }; } // namespace mpact::sim::util::assembler
diff --git a/mpact/sim/util/asm/simple_assembler.cc b/mpact/sim/util/asm/simple_assembler.cc index aff0218..afb2c13 100644 --- a/mpact/sim/util/asm/simple_assembler.cc +++ b/mpact/sim/util/asm/simple_assembler.cc
@@ -91,7 +91,7 @@ // then it returns an error. template <typename T> absl::StatusOr<T> SimpleTextToInt(absl::string_view text, - ResolverInterface *resolver = nullptr) { + ResolverInterface* resolver = nullptr) { T value; if (text.substr(0, 2) == "0x") { if (absl::SimpleHexAtoi(text.substr(2), &value)) return value; @@ -174,7 +174,7 @@ // interface is optional and is used to resolve any symbol names in the text. template <typename T> absl::StatusOr<std::vector<T>> GetValues( - absl::string_view remainder, ResolverInterface *resolver = nullptr) { + absl::string_view remainder, ResolverInterface* resolver = nullptr) { std::vector<T> values; static RE2 value_re("\\s*(0x[0-9a-fA-F]+|-?[0-9]+)\\s*(?:,|$)"); std::string match; @@ -190,7 +190,7 @@ // Specialization of the above that handles char values. template <> absl::StatusOr<std::vector<char>> GetValues<char>(absl::string_view remainder, - ResolverInterface *resolver) { + ResolverInterface* resolver) { std::vector<char> values; static RE2 value_re("\\s*'(.{1,2})'\\s*(?:,|$)"); std::string match; @@ -207,7 +207,7 @@ // Specialization of the above that handles double quoted string values. template <> absl::StatusOr<std::vector<std::string>> GetValues<std::string>( - absl::string_view remainder, ResolverInterface *resolver) { + absl::string_view remainder, ResolverInterface* resolver) { std::vector<std::string> values; std::string match; static RE2 value_re("\\s*\"([^\"]*)\"\\s*(?:,|$)"); @@ -232,8 +232,8 @@ // Helper that converts a vector of integer values to a vector of bytes. template <typename T> -inline void ConvertToBytes(const std::vector<T> &values, - std::vector<uint8_t> &bytes) { +inline void ConvertToBytes(const std::vector<T>& values, + std::vector<uint8_t>& bytes) { union { T i; uint8_t b[sizeof(T)]; @@ -249,7 +249,7 @@ } // namespace SimpleAssembler::SimpleAssembler(absl::string_view comment, int elf_file_class, - OpcodeAssemblerInterface *opcode_assembler_if) + OpcodeAssemblerInterface* opcode_assembler_if) : elf_file_class_(elf_file_class), opcode_assembler_if_(opcode_assembler_if), comment_re_(absl::StrCat("^(.*?)(?:", comment, ".*?)?(\\\\)?$")), @@ -298,8 +298,8 @@ string_accessor_ = nullptr; } -absl::Status SimpleAssembler::Parse(std::istream &is, - ResolverInterface *zero_resolver) { +absl::Status SimpleAssembler::Parse(std::istream& is, + ResolverInterface* zero_resolver) { // A trivial symbol resolver that always returns 0. bool own_zero_resolver = false; std::function<void()> cleanup = []() {}; @@ -347,7 +347,7 @@ if (RE2::FullMatch(line, asm_line_re_, &label, &statement)) { std::vector<uint8_t> byte_vector; std::vector<RelocationInfo> relo_vector; - auto *section = current_section_; + auto* section = current_section_; uint64_t address = (section == nullptr) ? 0 : section_address_map_[section]; if (!statement.empty()) { @@ -389,7 +389,7 @@ } // Add undefined symbols to the symbol table. - for (auto const &symbol : undefined_symbols_) { + for (auto const& symbol : undefined_symbols_) { auto status = AddSymbol(symbol, 0, 0, STT_NOTYPE, 0, 0, nullptr); if (!status.ok()) { cleanup(); @@ -408,7 +408,7 @@ absl::Status SimpleAssembler::CreateExecutable( uint64_t base_address, uint64_t entry_point, - ResolverInterface *symbol_resolver) { + ResolverInterface* symbol_resolver) { return CreateExecutable(base_address, absl::StrCat(entry_point), symbol_resolver); } @@ -420,10 +420,10 @@ uint64_t bss_segment_start) { auto num_symbols = symtab_->get_size() / sizeof(SymbolType); auto size = num_symbols * sizeof(SymbolType); - auto *symbols = new SymbolType[num_symbols]; + auto* symbols = new SymbolType[num_symbols]; std::memcpy(symbols, symtab_->get_data(), size); for (int i = 0; i < num_symbols; ++i) { - auto &sym = symbols[i]; + auto& sym = symbols[i]; auto shndx = sym.st_shndx; std::string name = string_accessor_->get_string(sym.st_name); if (global_symbols_.contains(name)) { @@ -439,7 +439,7 @@ sym.st_value += bss_segment_start; } } - symtab_->set_data(reinterpret_cast<char *>(symbols), size); + symtab_->set_data(reinterpret_cast<char*>(symbols), size); delete[] symbols; } @@ -447,28 +447,28 @@ void SimpleAssembler::UpdateSymbolsForRelocatable() { auto num_symbols = symtab_->get_size() / sizeof(SymbolType); auto size = num_symbols * sizeof(SymbolType); - auto *symbols = new SymbolType[num_symbols]; + auto* symbols = new SymbolType[num_symbols]; std::memcpy(symbols, symtab_->get_data(), size); for (int i = 0; i < num_symbols; ++i) { - auto &sym = symbols[i]; + auto& sym = symbols[i]; std::string name = string_accessor_->get_string(sym.st_name); if (global_symbols_.contains(name)) { sym.st_info = ELF_ST_INFO(STB_GLOBAL, ELF_ST_TYPE(sym.st_info)); } } - symtab_->set_data(reinterpret_cast<char *>(symbols), size); + symtab_->set_data(reinterpret_cast<char*>(symbols), size); delete[] symbols; } absl::Status SimpleAssembler::CreateExecutable( - uint64_t base_address, const std::string &entry_point, - ResolverInterface *symbol_resolver) { + uint64_t base_address, const std::string& entry_point, + ResolverInterface* symbol_resolver) { if (!undefined_symbols_.empty()) { std::string message; absl::StrAppend( &message, "Cannot create executable with the following undefined symbols: "); - for (auto const &symbol : undefined_symbols_) { + for (auto const& symbol : undefined_symbols_) { absl::StrAppend(&message, " ", symbol, "\n"); } return absl::InvalidArgumentError(message); @@ -481,7 +481,7 @@ // data segment starting at the end of the text segment + any alignment. // The bss section is added to the end of the data segment + any alignment. - ELFIO::segment *text_segment = nullptr; + ELFIO::segment* text_segment = nullptr; uint64_t text_segment_start = 0; if (text_section_ != nullptr) { text_segment_start = base_address & ~4095ULL; @@ -496,7 +496,7 @@ text_segment->set_align(4096); } - ELFIO::segment *data_segment = nullptr; + ELFIO::segment* data_segment = nullptr; uint64_t data_segment_start = 0; uint64_t bss_segment_start = 0; if ((data_section_ != nullptr) || (bss_section_ != nullptr)) { @@ -588,10 +588,10 @@ // Helper function to add a relocation entry to a relocation section. template <typename RelocaType> absl::Status AddRelocationEntries( - const std::vector<RelocationInfo> &relo_vector, - absl::flat_hash_map<std::string, ELFIO::Elf_Word> &symbol_indices, - ELFIO::section *reloca_section) { - for (auto const &relo : relo_vector) { + const std::vector<RelocationInfo>& relo_vector, + absl::flat_hash_map<std::string, ELFIO::Elf_Word>& symbol_indices, + ELFIO::section* reloca_section) { + for (auto const& relo : relo_vector) { RelocaType rela; rela.r_offset = relo.offset; rela.r_addend = relo.addend; @@ -605,7 +605,7 @@ } else { rela.r_info = ELF32_R_INFO(iter->second, relo.type); } - reloca_section->append_data(reinterpret_cast<const char *>(&rela), + reloca_section->append_data(reinterpret_cast<const char*>(&rela), sizeof(RelocaType)); } return absl::OkStatus(); @@ -617,7 +617,7 @@ void SimpleAssembler::UpdateSymtabHeaderInfo() { int last_local = 0; auto syms = - absl::MakeSpan(reinterpret_cast<const SymbolType *>(symtab_->get_data()), + absl::MakeSpan(reinterpret_cast<const SymbolType*>(symtab_->get_data()), symtab_->get_size() / sizeof(SymbolType)); for (int i = 0; i < syms.size(); ++i) { auto name = string_accessor_->get_string(syms[i].st_name); @@ -628,7 +628,7 @@ } absl::Status SimpleAssembler::CreateRelocatable( - ResolverInterface *symbol_resolver) { + ResolverInterface* symbol_resolver) { writer_.set_type(ET_REL); // Reset the section address map to zero since we are creating a relocatable // file. @@ -678,10 +678,10 @@ // First scan through the entries relocation vector and group them by // the section in which the relocation is to be applied. absl::flat_hash_map<uint16_t, std::vector<RelocationInfo>> relo_map; - for (auto const &relo : relo_vector) { + for (auto const& relo : relo_vector) { relo_map[relo.section_index].push_back(relo); } - for (auto const &[section_index, relo_vec] : relo_map) { + for (auto const& [section_index, relo_vec] : relo_map) { if (section_index == 0) { cleanup(); return absl::InternalError( @@ -695,7 +695,7 @@ // Now, create a relocation section for each key in the map. std::string name = absl::StrCat(".rela", section_index_map_[section_index]->get_name()); - auto *rela_section = writer_.sections.add(name); + auto* rela_section = writer_.sections.add(name); rela_section->set_type(SHT_RELA); rela_section->set_flags(SHF_INFO_LINK); rela_section->set_entry_size(elf_file_class_ == ELFCLASS64 @@ -728,14 +728,14 @@ } absl::Status SimpleAssembler::ParsePassTwo( - std::vector<RelocationInfo> &relo_vector, - ResolverInterface *symbol_resolver) { + std::vector<RelocationInfo>& relo_vector, + ResolverInterface* symbol_resolver) { // Now fill in the sections. Parse each of the lines saved in the first // pass. - for (auto const &line : lines_) { + for (auto const& line : lines_) { std::vector<uint8_t> byte_vector; absl::Status status; - auto *section = current_section_; + auto* section = current_section_; auto relo_size = relo_vector.size(); auto address = section_address_map_[section]; if (line[0] == '.') { @@ -758,7 +758,7 @@ if (section == nullptr) { return absl::InternalError("Data is added to a null section"); } - section->append_data(reinterpret_cast<const char *>(byte_vector.data()), + section->append_data(reinterpret_cast<const char*>(byte_vector.data()), byte_vector.size()); } } @@ -766,7 +766,7 @@ } // Top level function that writes the ELF file out to disk. -absl::Status SimpleAssembler::Write(std::ostream &os) { +absl::Status SimpleAssembler::Write(std::ostream& os) { writer_.save(os); return absl::OkStatus(); } @@ -777,12 +777,12 @@ // tokens separated by spaces. The argument is parsed using regular // expressions. The byte values are appended to the given vector. absl::Status SimpleAssembler::ParseAsmDirective( - absl::string_view line, uint64_t address, ResolverInterface *resolver, - std::vector<uint8_t> &byte_values, - std::vector<RelocationInfo> &relocations) { + absl::string_view line, uint64_t address, ResolverInterface* resolver, + std::vector<uint8_t>& byte_values, + std::vector<RelocationInfo>& relocations) { std::string match; std::string remainder; - ELFIO::section *section = current_section_; + ELFIO::section* section = current_section_; uint64_t size = 0; std::string directive; std::string label; @@ -819,22 +819,22 @@ if (!res.ok()) return res.status(); auto values = res.value(); size = values.size(); - for (auto const &value : values) byte_values.push_back(value); + for (auto const& value : values) byte_values.push_back(value); } else if (match == "char") { // .char auto res = GetValues<char>(remainder, resolver); if (!res.ok()) return res.status(); auto values = res.value(); size = values.size(); - for (auto const &value : values) byte_values.push_back(value); + for (auto const& value : values) byte_values.push_back(value); } else if (match == "cstring") { // .cstring auto res = GetValues<std::string>(remainder, resolver); if (!res.ok()) return res.status(); auto values = res.value(); size = 0; - for (auto const &value : values) { - for (auto const &c : value) byte_values.push_back(c); + for (auto const& value : values) { + for (auto const& c : value) byte_values.push_back(c); byte_values.push_back('\0'); size += value.size() + 1; } @@ -846,7 +846,7 @@ auto res = GetLabels(remainder); if (!res.ok()) return res.status(); auto values = res.value(); - for (auto const &value : values) { + for (auto const& value : values) { global_symbols_.insert(value); } } else if (match == "long") { @@ -878,8 +878,8 @@ if (!res.ok()) return res.status(); auto values = res.value(); size = 0; - for (auto const &value : values) { - for (auto const &c : value) byte_values.push_back(c); + for (auto const& value : values) { + for (auto const& c : value) byte_values.push_back(c); size += value.size(); } } else if (match == "text") { @@ -891,7 +891,7 @@ if (!res.ok()) return res.status(); auto values = res.value(); size = values.size(); - for (auto const &value : values) byte_values.push_back(value); + for (auto const& value : values) byte_values.push_back(value); } else if (match == "ulong") { // .ulong auto res = GetValues<uint64_t>(remainder); @@ -949,9 +949,9 @@ // expected to be a single line of text. The byte values are appended to the // given vector. absl::Status SimpleAssembler::ParseAsmStatement( - absl::string_view line, uint64_t address, ResolverInterface *resolver, - std::vector<uint8_t> &byte_values, - std::vector<RelocationInfo> &relocations) { + absl::string_view line, uint64_t address, ResolverInterface* resolver, + std::vector<uint8_t>& byte_values, + std::vector<RelocationInfo>& relocations) { // Call the target specific assembler to encode the statement. auto result = opcode_assembler_if_->Encode( address, line, @@ -962,9 +962,9 @@ return absl::OkStatus(); } -void SimpleAssembler::SetTextSection(const std::string &name) { +void SimpleAssembler::SetTextSection(const std::string& name) { // First check if the section already exists. - auto *section = writer_.sections[name]; + auto* section = writer_.sections[name]; if (section != nullptr) { current_section_ = section; return; @@ -983,9 +983,9 @@ section_index_map_.insert({section->get_index(), text_section_}); } -void SimpleAssembler::SetDataSection(const std::string &name) { +void SimpleAssembler::SetDataSection(const std::string& name) { // First check if the section already exists. - auto *section = writer_.sections[name]; + auto* section = writer_.sections[name]; if (section != nullptr) { current_section_ = section; return; @@ -1004,9 +1004,9 @@ section_index_map_.insert({section->get_index(), data_section_}); } -void SimpleAssembler::SetBssSection(const std::string &name) { +void SimpleAssembler::SetBssSection(const std::string& name) { // First check if the section already exists. - auto *section = writer_.sections[name]; + auto* section = writer_.sections[name]; if (section != nullptr) { current_section_ = section; return; @@ -1025,17 +1025,17 @@ section_index_map_.insert({section->get_index(), bss_section_}); } absl::Status SimpleAssembler::AddSymbolToCurrentSection( - const std::string &name, ELFIO::Elf64_Addr value, ELFIO::Elf_Xword size, + const std::string& name, ELFIO::Elf64_Addr value, ELFIO::Elf_Xword size, uint8_t type, uint8_t binding, uint8_t other) { return AddSymbol(name, value, size, type, binding, other, current_section_); } -absl::Status SimpleAssembler::AddSymbol(const std::string &name, +absl::Status SimpleAssembler::AddSymbol(const std::string& name, ELFIO::Elf64_Addr value, ELFIO::Elf_Xword size, uint8_t type, uint8_t binding, uint8_t other, - const std::string §ion_name) { - ELFIO::section *section = nullptr; + const std::string& section_name) { + ELFIO::section* section = nullptr; if (!section_name.empty()) { section = writer_.sections[section_name]; if (section == nullptr) { @@ -1046,11 +1046,11 @@ return AddSymbol(name, value, size, type, binding, other, section); } -absl::Status SimpleAssembler::AddSymbol(const std::string &name, +absl::Status SimpleAssembler::AddSymbol(const std::string& name, ELFIO::Elf64_Addr value, ELFIO::Elf_Xword size, uint8_t type, uint8_t binding, uint8_t other, - ELFIO::section *section) { + ELFIO::section* section) { auto iter = symbol_indices_.find(name); if (iter != symbol_indices_.end()) { return absl::AlreadyExistsError( @@ -1079,7 +1079,7 @@ undefined_symbols_.insert(name_str); } -absl::Status SimpleAssembler::AppendData(const char *data, size_t size) { +absl::Status SimpleAssembler::AppendData(const char* data, size_t size) { if (current_section_ == nullptr) { return absl::FailedPreconditionError("No current section"); }
diff --git a/mpact/sim/util/asm/simple_assembler.h b/mpact/sim/util/asm/simple_assembler.h index 1f705c5..c684685 100644 --- a/mpact/sim/util/asm/simple_assembler.h +++ b/mpact/sim/util/asm/simple_assembler.h
@@ -68,48 +68,48 @@ // opcode_assembler_if: The opcode assembler interface to use for parsing // and encoding assembly statements. SimpleAssembler(absl::string_view comment, int elf_file_class, - OpcodeAssemblerInterface *opcode_assembler_if); - SimpleAssembler(const SimpleAssembler &) = delete; - SimpleAssembler &operator=(const SimpleAssembler &) = delete; + OpcodeAssemblerInterface* opcode_assembler_if); + SimpleAssembler(const SimpleAssembler&) = delete; + SimpleAssembler& operator=(const SimpleAssembler&) = delete; virtual ~SimpleAssembler(); // Parse the input stream as assembly. - absl::Status Parse(std::istream &is, - ResolverInterface *zero_resolver = nullptr); + absl::Status Parse(std::istream& is, + ResolverInterface* zero_resolver = nullptr); // Add the symbol to the symbol table for the current section. See ELFIO // documentation for details of the meaning of the parameters. - absl::Status AddSymbolToCurrentSection(const std::string &name, + absl::Status AddSymbolToCurrentSection(const std::string& name, ELFIO::Elf64_Addr value, ELFIO::Elf_Xword size, uint8_t type, uint8_t binding, uint8_t other); // Add the symbol to the symbol table for the named section. See ELFIO // documentation for details of the meaning of the parameters. - absl::Status AddSymbol(const std::string &name, ELFIO::Elf64_Addr value, + absl::Status AddSymbol(const std::string& name, ELFIO::Elf64_Addr value, ELFIO::Elf_Xword size, uint8_t type, uint8_t binding, - uint8_t other, const std::string §ion_name); + uint8_t other, const std::string& section_name); // Create executable ELF file with the given value as the entry point. // The text segment will be laid out starting at base address, followed by // the data segment. absl::Status CreateExecutable(uint64_t base_address, - const std::string &entry_point, - ResolverInterface *symbol_resolver = nullptr); + const std::string& entry_point, + ResolverInterface* symbol_resolver = nullptr); absl::Status CreateExecutable(uint64_t base_address, uint64_t entry_point, - ResolverInterface *symbol_resolver = nullptr); + ResolverInterface* symbol_resolver = nullptr); // Create a relocatable ELF file. - absl::Status CreateRelocatable(ResolverInterface *symbol_resolver = nullptr); + absl::Status CreateRelocatable(ResolverInterface* symbol_resolver = nullptr); // Write the ELF file to the given output stream. - absl::Status Write(std::ostream &os); + absl::Status Write(std::ostream& os); // Access the ELF writer. - ELFIO::elfio &writer() { return writer_; } + ELFIO::elfio& writer() { return writer_; } // Add a symbol reference to the symbol table if it is not already defined. void SimpleAddSymbol(absl::string_view name); // Getters and setters. - absl::flat_hash_map<std::string, ELFIO::Elf_Word> &symbol_indices() { + absl::flat_hash_map<std::string, ELFIO::Elf_Word>& symbol_indices() { return symbol_indices_; } - ELFIO::section *symtab() { return symtab_; } + ELFIO::section* symtab() { return symtab_; } unsigned data_address_unit() { return data_address_unit_; } void set_data_address_unit(unsigned data_address_unit) { data_address_unit_ = data_address_unit; @@ -126,57 +126,57 @@ template <typename SymbolType> void UpdateSymtabHeaderInfo(); // Perform second pass of parsing. - absl::Status ParsePassTwo(std::vector<RelocationInfo> &relo_vector, - ResolverInterface *symbol_resolver); + absl::Status ParsePassTwo(std::vector<RelocationInfo>& relo_vector, + ResolverInterface* symbol_resolver); // Parse and process an assembly directive. absl::Status ParseAsmDirective(absl::string_view line, uint64_t address, - ResolverInterface *resolver, - std::vector<uint8_t> &byte_values, - std::vector<RelocationInfo> &relocations); + ResolverInterface* resolver, + std::vector<uint8_t>& byte_values, + std::vector<RelocationInfo>& relocations); // Parse and process and assembly statement. absl::Status ParseAsmStatement(absl::string_view line, uint64_t address, - ResolverInterface *resolver, - std::vector<uint8_t> &byte_values, - std::vector<RelocationInfo> &relocations); + ResolverInterface* resolver, + std::vector<uint8_t>& byte_values, + std::vector<RelocationInfo>& relocations); // Add the symbol to the symbol table. - absl::Status AddSymbol(const std::string &name, ELFIO::Elf64_Addr value, + absl::Status AddSymbol(const std::string& name, ELFIO::Elf64_Addr value, ELFIO::Elf_Xword size, uint8_t type, uint8_t binding, - uint8_t other, ELFIO::section *section); + uint8_t other, ELFIO::section* section); // Append the data to the current section. - absl::Status AppendData(const char *data, size_t size); + absl::Status AppendData(const char* data, size_t size); // Set the the given section as the current section. Create if it has not // already been created. - void SetTextSection(const std::string &name); - void SetDataSection(const std::string &name); - void SetBssSection(const std::string &name); + void SetTextSection(const std::string& name); + void SetDataSection(const std::string& name); + void SetBssSection(const std::string& name); // ELF file class. int elf_file_class_ = 0; // Elf file top level object. ELFIO::elfio writer_; // The current section being processed. - ELFIO::section *current_section_ = nullptr; + ELFIO::section* current_section_ = nullptr; // Map from section index to section pointer. - absl::flat_hash_map<uint16_t, ELFIO::section *> section_index_map_; + absl::flat_hash_map<uint16_t, ELFIO::section*> section_index_map_; // Interface used to parse and encode assembly statements. - OpcodeAssemblerInterface *opcode_assembler_if_ = nullptr; + OpcodeAssemblerInterface* opcode_assembler_if_ = nullptr; // Interface used to access strings in the string table. - ELFIO::string_section_accessor *string_accessor_ = nullptr; + ELFIO::string_section_accessor* string_accessor_ = nullptr; // Interface used to access symbols in the symbol table. - ELFIO::symbol_section_accessor *symbol_accessor_ = nullptr; + ELFIO::symbol_section_accessor* symbol_accessor_ = nullptr; // ELF symbol table section. - ELFIO::section *symtab_ = nullptr; + ELFIO::section* symtab_ = nullptr; // Elf string table section. - ELFIO::section *strtab_ = nullptr; + ELFIO::section* strtab_ = nullptr; // Map that tracks the current address of each section. - absl::flat_hash_map<ELFIO::section *, uint64_t> section_address_map_; + absl::flat_hash_map<ELFIO::section*, uint64_t> section_address_map_; std::vector<std::string> lines_; // Section pointers. - ELFIO::section *text_section_ = nullptr; - ELFIO::section *data_section_ = nullptr; - ELFIO::section *bss_section_ = nullptr; + ELFIO::section* text_section_ = nullptr; + ELFIO::section* data_section_ = nullptr; + ELFIO::section* bss_section_ = nullptr; // Regular expressions used to parse the assembly source. RE2 comment_re_; RE2 asm_line_re_;
diff --git a/mpact/sim/util/asm/test/riscv64x_bin_encoder_interface.cc b/mpact/sim/util/asm/test/riscv64x_bin_encoder_interface.cc index 9f45dbf..7c2edba 100644 --- a/mpact/sim/util/asm/test/riscv64x_bin_encoder_interface.cc +++ b/mpact/sim/util/asm/test/riscv64x_bin_encoder_interface.cc
@@ -49,14 +49,14 @@ absl::StatusOr<std::tuple<uint64_t, int>> RiscV64XBinEncoderInterface::GetOpcodeEncoding(SlotEnum slot, int entry, OpcodeEnum opcode, - ResolverInterface *resolver) { + ResolverInterface* resolver) { return encoding64::kOpcodeEncodings->at(opcode); } absl::StatusOr<uint64_t> RiscV64XBinEncoderInterface::GetSrcOpEncoding( uint64_t address, absl::string_view text, SlotEnum slot, int entry, OpcodeEnum opcode, SourceOpEnum source_op, int source_num, - ResolverInterface *resolver) { + ResolverInterface* resolver) { auto iter = source_op_map_.find(*source_op); if (iter == source_op_map_.end()) { return absl::NotFoundError(absl::StrCat( @@ -68,7 +68,7 @@ absl::Status RiscV64XBinEncoderInterface::AppendSrcOpRelocation( uint64_t address, absl::string_view text, SlotEnum slot, int entry, OpcodeEnum opcode, SourceOpEnum source_op, int source_num, - ResolverInterface *resolver, std::vector<RelocationInfo> &relocations) { + ResolverInterface* resolver, std::vector<RelocationInfo>& relocations) { auto iter = relocation_source_op_map_.find(std::tie(opcode, source_op)); if (iter == relocation_source_op_map_.end()) return absl::OkStatus(); return iter->second(address, text, resolver, relocations); @@ -77,7 +77,7 @@ absl::StatusOr<uint64_t> RiscV64XBinEncoderInterface::GetDestOpEncoding( uint64_t address, absl::string_view text, SlotEnum slot, int entry, OpcodeEnum opcode, DestOpEnum dest_op, int dest_num, - ResolverInterface *resolver) { + ResolverInterface* resolver) { auto iter = dest_op_map_.find(*dest_op); if (iter == dest_op_map_.end()) { return absl::NotFoundError( @@ -89,7 +89,7 @@ absl::Status RiscV64XBinEncoderInterface::AppendDestOpRelocation( uint64_t address, absl::string_view text, SlotEnum slot, int entry, OpcodeEnum opcode, DestOpEnum dest_op, int dest_num, - ResolverInterface *resolver, std::vector<RelocationInfo> &relocations) { + ResolverInterface* resolver, std::vector<RelocationInfo>& relocations) { // There are no destination operands that require relocation. return absl::OkStatus(); } @@ -97,7 +97,7 @@ absl::StatusOr<uint64_t> RiscV64XBinEncoderInterface::GetListDestOpEncoding( uint64_t address, absl::string_view text, SlotEnum slot, int entry, OpcodeEnum opcode, ListDestOpEnum dest_op, int dest_num, - ResolverInterface *resolver) { + ResolverInterface* resolver) { auto iter = list_dest_op_map_.find(*dest_op); if (iter == list_dest_op_map_.end()) { return absl::NotFoundError(absl::StrCat( @@ -109,7 +109,7 @@ absl::StatusOr<uint64_t> RiscV64XBinEncoderInterface::GetListSrcOpEncoding( uint64_t address, absl::string_view text, SlotEnum slot, int entry, OpcodeEnum opcode, ListSourceOpEnum source_op, int source_num, - ResolverInterface *resolver) { + ResolverInterface* resolver) { auto iter = list_source_op_map_.find(*source_op); if (iter == list_source_op_map_.end()) { return absl::NotFoundError(absl::StrCat( @@ -120,7 +120,7 @@ absl::StatusOr<uint64_t> RiscV64XBinEncoderInterface::GetPredOpEncoding( uint64_t address, absl::string_view text, SlotEnum slot, int entry, - OpcodeEnum opcode, PredOpEnum pred_op, ResolverInterface *resolver) { + OpcodeEnum opcode, PredOpEnum pred_op, ResolverInterface* resolver) { auto iter = pred_op_map_.find(*pred_op); if (iter == pred_op_map_.end()) { return absl::NotFoundError(absl::StrCat(
diff --git a/mpact/sim/util/asm/test/riscv64x_bin_encoder_interface.h b/mpact/sim/util/asm/test/riscv64x_bin_encoder_interface.h index 4c1d341..96b4912 100644 --- a/mpact/sim/util/asm/test/riscv64x_bin_encoder_interface.h +++ b/mpact/sim/util/asm/test/riscv64x_bin_encoder_interface.h
@@ -38,54 +38,54 @@ class RiscV64XBinEncoderInterface : public RiscV64XEncoderInterfaceBase { public: RiscV64XBinEncoderInterface(); - RiscV64XBinEncoderInterface(const RiscV64XBinEncoderInterface &) = delete; - RiscV64XBinEncoderInterface &operator=(const RiscV64XBinEncoderInterface &) = + RiscV64XBinEncoderInterface(const RiscV64XBinEncoderInterface&) = delete; + RiscV64XBinEncoderInterface& operator=(const RiscV64XBinEncoderInterface&) = delete; ~RiscV64XBinEncoderInterface() override = default; absl::StatusOr<std::tuple<uint64_t, int>> GetOpcodeEncoding( SlotEnum slot, int entry, OpcodeEnum opcode, - ResolverInterface *resolver) override; + ResolverInterface* resolver) override; absl::StatusOr<uint64_t> GetSrcOpEncoding( uint64_t address, absl::string_view text, SlotEnum slot, int entry, OpcodeEnum opcode, SourceOpEnum source_op, int source_num, - ResolverInterface *resolver) override; + ResolverInterface* resolver) override; absl::Status AppendSrcOpRelocation( uint64_t address, absl::string_view text, SlotEnum slot, int entry, OpcodeEnum opcode, SourceOpEnum source_op, int source_num, - ResolverInterface *resolver, - std::vector<RelocationInfo> &relocations) override; + ResolverInterface* resolver, + std::vector<RelocationInfo>& relocations) override; absl::StatusOr<uint64_t> GetDestOpEncoding( uint64_t address, absl::string_view text, SlotEnum slot, int entry, OpcodeEnum opcode, DestOpEnum dest_op, int dest_num, - ResolverInterface *resolver) override; + ResolverInterface* resolver) override; absl::Status AppendDestOpRelocation( uint64_t address, absl::string_view text, SlotEnum slot, int entry, OpcodeEnum opcode, DestOpEnum dest_op, int dest_num, - ResolverInterface *resolver, - std::vector<RelocationInfo> &relocations) override; + ResolverInterface* resolver, + std::vector<RelocationInfo>& relocations) override; absl::StatusOr<uint64_t> GetListDestOpEncoding( uint64_t address, absl::string_view text, SlotEnum slot, int entry, OpcodeEnum opcode, ListDestOpEnum dest_op, int dest_num, - ResolverInterface *resolver) override; + ResolverInterface* resolver) override; absl::StatusOr<uint64_t> GetListSrcOpEncoding( uint64_t address, absl::string_view text, SlotEnum slot, int entry, OpcodeEnum opcode, ListSourceOpEnum source_op, int source_num, - ResolverInterface *resolver) override; + ResolverInterface* resolver) override; absl::StatusOr<uint64_t> GetPredOpEncoding( uint64_t address, absl::string_view text, SlotEnum slot, int entry, OpcodeEnum opcode, PredOpEnum pred_op, - ResolverInterface *resolver) override; + ResolverInterface* resolver) override; private: using OpMap = absl::flat_hash_map< int, std::function<absl::StatusOr<uint64_t>(uint64_t, absl::string_view, - ResolverInterface *)>>; + ResolverInterface*)>>; using RelocationMap = absl::flat_hash_map<std::tuple<OpcodeEnum, SourceOpEnum>, std::function<absl::Status( - uint64_t, absl::string_view, ResolverInterface *, - std::vector<RelocationInfo> &)>>; + uint64_t, absl::string_view, ResolverInterface*, + std::vector<RelocationInfo>&)>>; OpMap source_op_map_; RelocationMap relocation_source_op_map_;
diff --git a/mpact/sim/util/asm/test/riscv64x_instructions.cc b/mpact/sim/util/asm/test/riscv64x_instructions.cc index 44990e6..9829c4d 100644 --- a/mpact/sim/util/asm/test/riscv64x_instructions.cc +++ b/mpact/sim/util/asm/test/riscv64x_instructions.cc
@@ -20,7 +20,7 @@ namespace mpact::sim::riscv { -void RiscVIllegalInstruction(const generic::Instruction *inst) { +void RiscVIllegalInstruction(const generic::Instruction* inst) { std::cerr << "Illegal instruction\n"; }
diff --git a/mpact/sim/util/asm/test/riscv64x_instructions.h b/mpact/sim/util/asm/test/riscv64x_instructions.h index 9dc1c42..2807440 100644 --- a/mpact/sim/util/asm/test/riscv64x_instructions.h +++ b/mpact/sim/util/asm/test/riscv64x_instructions.h
@@ -21,7 +21,7 @@ using ::mpact::sim::generic::Instruction; -void RiscVIllegalInstruction(const generic::Instruction *inst); +void RiscVIllegalInstruction(const generic::Instruction* inst); } // namespace mpact::sim::riscv
diff --git a/mpact/sim/util/asm/test/riscv_bin_setters.cc b/mpact/sim/util/asm/test/riscv_bin_setters.cc index 165b407..a411e87 100644 --- a/mpact/sim/util/asm/test/riscv_bin_setters.cc +++ b/mpact/sim/util/asm/test/riscv_bin_setters.cc
@@ -48,8 +48,8 @@ absl::NoDestructor<RE2> kSymRe("^\\s*(%[a-zA-Z0-9_]+)\\s*\\(?([^)]+)\\)?\\s*$"); absl::Status RelocateAddiIImm12(uint64_t address, absl::string_view text, - ResolverInterface *resolver, - std::vector<RelocationInfo> &relocations) { + ResolverInterface* resolver, + std::vector<RelocationInfo>& relocations) { std::string relo; std::string sym; if (!RE2::FullMatch(text, *kSymRe, &relo, &sym)) return absl::OkStatus(); @@ -69,8 +69,8 @@ } absl::Status RelocateJJImm20(uint64_t address, absl::string_view text, - ResolverInterface *resolver, - std::vector<RelocationInfo> &relocations) { + ResolverInterface* resolver, + std::vector<RelocationInfo>& relocations) { std::string relo; std::string sym; if (!RE2::FullMatch(text, *kSymRe, &relo, &sym)) return absl::OkStatus(); @@ -80,14 +80,14 @@ } absl::Status RelocateJrJImm12(uint64_t address, absl::string_view text, - ResolverInterface *resolver, - std::vector<RelocationInfo> &relocations) { + ResolverInterface* resolver, + std::vector<RelocationInfo>& relocations) { return absl::OkStatus(); } absl::Status RelocateLuiUImm20(uint64_t address, absl::string_view text, - ResolverInterface *resolver, - std::vector<RelocationInfo> &relocations) { + ResolverInterface* resolver, + std::vector<RelocationInfo>& relocations) { std::string relo; std::string sym; if (!RE2::FullMatch(text, *kSymRe, &relo, &sym)) return absl::OkStatus(); @@ -96,8 +96,8 @@ } absl::Status RelocateSdSImm12(uint64_t address, absl::string_view text, - ResolverInterface *resolver, - std::vector<RelocationInfo> &relocations) { + ResolverInterface* resolver, + std::vector<RelocationInfo>& relocations) { std::string relo; std::string sym; if (!RE2::FullMatch(text, *kSymRe, &relo, &sym)) return absl::OkStatus();
diff --git a/mpact/sim/util/asm/test/riscv_bin_setters.h b/mpact/sim/util/asm/test/riscv_bin_setters.h index d461381..83a435b 100644 --- a/mpact/sim/util/asm/test/riscv_bin_setters.h +++ b/mpact/sim/util/asm/test/riscv_bin_setters.h
@@ -57,7 +57,7 @@ template <typename T> absl::StatusOr<T> SimpleTextToInt(absl::string_view op_text, - ResolverInterface *resolver) { + ResolverInterface* resolver) { T value; static RE2 hex_re("^\\s*0x([0-9a-fA-F]+)\\s*$"); static RE2 dec_re("^\\s*(-?[0-9]+)\\s*$"); @@ -98,31 +98,31 @@ using ValueMap = absl::flat_hash_map<absl::string_view, uint64_t>; template <typename Enum, typename Map, typename Encoder> -void AddRiscvSourceOpBinSetters(Map &map) { +void AddRiscvSourceOpBinSetters(Map& map) { Insert(map, *Enum::kIImm12, [](uint64_t address, absl::string_view text, - ResolverInterface *resolver) -> absl::StatusOr<uint64_t> { + ResolverInterface* resolver) -> absl::StatusOr<uint64_t> { auto res = SimpleTextToInt<int32_t>(text, resolver); if (!res.ok()) return res.status(); return Encoder::IType::InsertImm12(res.value(), 0ULL); }); Insert(map, *Enum::kIUimm6, [](uint64_t address, absl::string_view text, - ResolverInterface *resolver) -> absl::StatusOr<uint64_t> { + ResolverInterface* resolver) -> absl::StatusOr<uint64_t> { auto res = SimpleTextToInt<uint32_t>(text, resolver); if (!res.ok()) return res.status(); return Encoder::RSType::InsertRUimm6(res.value(), 0ULL); }); Insert(map, *Enum::kJImm12, [](uint64_t address, absl::string_view text, - ResolverInterface *resolver) -> absl::StatusOr<uint64_t> { + ResolverInterface* resolver) -> absl::StatusOr<uint64_t> { auto res = SimpleTextToInt<int32_t>(text, resolver); if (!res.ok()) return res.status(); return Encoder::IType::InsertImm12(res.value(), 0ULL); }); Insert(map, *Enum::kJImm20, [](uint64_t address, absl::string_view text, - ResolverInterface *resolver) -> absl::StatusOr<uint64_t> { + ResolverInterface* resolver) -> absl::StatusOr<uint64_t> { auto res = SimpleTextToInt<int32_t>(text, resolver); if (!res.ok()) return res.status(); uint32_t delta = res.value() - address; @@ -131,7 +131,7 @@ }); Insert(map, *Enum::kRs1, [](uint64_t address, absl::string_view text, - ResolverInterface *resolver) -> absl::StatusOr<uint64_t> { + ResolverInterface* resolver) -> absl::StatusOr<uint64_t> { static ValueMap map(kRegisterList); auto iter = map.find(text); if (iter == map.end()) { @@ -142,7 +142,7 @@ }); Insert(map, *Enum::kRs2, [](uint64_t address, absl::string_view text, - ResolverInterface *resolver) -> absl::StatusOr<uint64_t> { + ResolverInterface* resolver) -> absl::StatusOr<uint64_t> { static ValueMap map(kRegisterList); auto iter = map.find(text); if (iter == map.end()) { @@ -153,14 +153,14 @@ }); Insert(map, *Enum::kSImm12, [](uint64_t address, absl::string_view text, - ResolverInterface *resolver) -> absl::StatusOr<uint64_t> { + ResolverInterface* resolver) -> absl::StatusOr<uint64_t> { auto res = SimpleTextToInt<uint32_t>(text, resolver); if (!res.ok()) return res.status(); return Encoder::SType::InsertSImm(res.value(), 0ULL); }); Insert(map, *Enum::kUImm20, [](uint64_t address, absl::string_view text, - ResolverInterface *resolver) -> absl::StatusOr<uint64_t> { + ResolverInterface* resolver) -> absl::StatusOr<uint64_t> { auto res = SimpleTextToInt<uint32_t>(text, resolver); if (!res.ok()) return res.status(); return Encoder::UType::InsertUImm(res.value(), 0ULL); @@ -168,10 +168,10 @@ } template <typename Enum, typename Map, typename Encoder> -void AddRiscvDestOpBinSetters(Map &map) { +void AddRiscvDestOpBinSetters(Map& map) { Insert(map, *Enum::kRd, [](uint64_t address, absl::string_view text, - ResolverInterface *resolver) -> absl::StatusOr<uint64_t> { + ResolverInterface* resolver) -> absl::StatusOr<uint64_t> { static ValueMap map(kRegisterList); auto iter = map.find(text); if (iter == map.end()) { @@ -185,25 +185,25 @@ namespace internal { absl::Status RelocateAddiIImm12(uint64_t address, absl::string_view text, - ResolverInterface *resolver, - std::vector<RelocationInfo> &relocations); + ResolverInterface* resolver, + std::vector<RelocationInfo>& relocations); absl::Status RelocateJJImm20(uint64_t address, absl::string_view text, - ResolverInterface *resolver, - std::vector<RelocationInfo> &relocations); + ResolverInterface* resolver, + std::vector<RelocationInfo>& relocations); absl::Status RelocateJrJImm12(uint64_t address, absl::string_view text, - ResolverInterface *resolver, - std::vector<RelocationInfo> &relocations); + ResolverInterface* resolver, + std::vector<RelocationInfo>& relocations); absl::Status RelocateLuiUImm20(uint64_t address, absl::string_view text, - ResolverInterface *resolver, - std::vector<RelocationInfo> &relocations); + ResolverInterface* resolver, + std::vector<RelocationInfo>& relocations); absl::Status RelocateSdSImm12(uint64_t address, absl::string_view text, - ResolverInterface *resolver, - std::vector<RelocationInfo> &relocations); + ResolverInterface* resolver, + std::vector<RelocationInfo>& relocations); } // namespace internal template <typename OpcodeEnum, typename SourceOpEnum, typename Map> -void AddRiscvSourceOpRelocationSetters(Map &map) { +void AddRiscvSourceOpRelocationSetters(Map& map) { Insert(map, OpcodeEnum::kAddi, SourceOpEnum::kIImm12, internal::RelocateAddiIImm12); Insert(map, OpcodeEnum::kJal, SourceOpEnum::kJImm20,
diff --git a/mpact/sim/util/asm/test/riscv_getter_helpers.h b/mpact/sim/util/asm/test/riscv_getter_helpers.h index 5c37128..1ddde27 100644 --- a/mpact/sim/util/asm/test/riscv_getter_helpers.h +++ b/mpact/sim/util/asm/test/riscv_getter_helpers.h
@@ -27,7 +27,7 @@ // Helper function to insert and entry into a "getter" map. This is used in // the riscv_*_getter.h files. template <typename M, typename E, typename G> -inline void Insert(M &map, E entry, G getter) { +inline void Insert(M& map, E entry, G getter) { if (!map.contains(static_cast<int>(entry))) { map.insert(std::make_pair(static_cast<int>(entry), getter)); } else { @@ -36,7 +36,7 @@ } template <typename M, typename E1, typename E2, typename G> -inline void Insert(M &map, E1 entry1, E2 entry2, G getter) { +inline void Insert(M& map, E1 entry1, E2 entry2, G getter) { auto key = std::tie(entry1, entry2); if (!map.contains(key)) { map.insert(std::make_pair(key, getter));
diff --git a/mpact/sim/util/memory/atomic_memory.cc b/mpact/sim/util/memory/atomic_memory.cc index 1e2c589..b121477 100644 --- a/mpact/sim/util/memory/atomic_memory.cc +++ b/mpact/sim/util/memory/atomic_memory.cc
@@ -14,10 +14,14 @@ #include "mpact/sim/util/memory/atomic_memory.h" -#include <cstring> +#include <cstdint> +#include <type_traits> +#include <utility> #include "absl/log/log.h" #include "absl/status/status.h" +#include "absl/strings/str_cat.h" +#include "mpact/sim/util/memory/memory_interface.h" namespace mpact { namespace sim { @@ -25,7 +29,7 @@ // Helper function that writes the value to the data buffer. template <typename I> -static absl::Status WriteDb(DataBuffer *db, I value) { +static absl::Status WriteDb(DataBuffer* db, I value) { switch (db->size<uint8_t>()) { case 1: db->Set<uint8_t>(0, static_cast<uint8_t>(value)); @@ -50,8 +54,8 @@ // buffers. template <typename T> static void PerformOp(AtomicMemoryOpInterface::Operation op, - const DataBuffer *db_lhs, const DataBuffer *db_rhs, - DataBuffer *db_res) { + const DataBuffer* db_lhs, const DataBuffer* db_rhs, + DataBuffer* db_res) { using UT = typename std::make_unsigned<T>::type; using ST = typename std::make_signed<T>::type; switch (op) { @@ -89,7 +93,7 @@ } // Constructor. -AtomicMemory::AtomicMemory(MemoryInterface *memory) : memory_(memory) { +AtomicMemory::AtomicMemory(MemoryInterface* memory) : memory_(memory) { // Construct and initialize the local data buffers. db1_ = db_factory_.Allocate<uint8_t>(1); db1_->set_latency(0); @@ -114,20 +118,20 @@ } // Forward the load call. -void AtomicMemory::Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void AtomicMemory::Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) { memory_->Load(address, db, inst, context); } // Forward the load call. -void AtomicMemory::Load(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void AtomicMemory::Load(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db, Instruction* inst, + ReferenceCount* context) { memory_->Load(address_db, mask_db, el_size, db, inst, context); } // Store the value to memory, but remove any matching tag from the tag set. -void AtomicMemory::Store(uint64_t address, DataBuffer *db) { +void AtomicMemory::Store(uint64_t address, DataBuffer* db) { // If the address matches a tag, remove the tag. auto ptr = ll_tag_set_.find(address >> kTagShift); if (ptr != ll_tag_set_.end()) { @@ -137,8 +141,8 @@ } // Store the value to memory, but remove any matching tag from the tag set. -void AtomicMemory::Store(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db) { +void AtomicMemory::Store(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db) { // If the address matches a tag, remove the tag. for (uint64_t address : address_db->Get<uint64_t>()) { auto ptr = ll_tag_set_.find(address >> kTagShift); @@ -151,8 +155,8 @@ // Perform the atomic memory operation. absl::Status AtomicMemory::PerformMemoryOp(uint64_t address, Operation op, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) { + DataBuffer* db, Instruction* inst, + ReferenceCount* context) { int el_size = db->size<uint8_t>(); db->set_latency(0); // Load-linked. @@ -182,7 +186,7 @@ } // Load the data from memory. - auto *tmp_db = GetDb(el_size); + auto* tmp_db = GetDb(el_size); if (tmp_db == nullptr) return absl::InternalError( absl::StrCat("Illegal element size (", el_size, ")")); @@ -238,8 +242,8 @@ return absl::OkStatus(); } -void AtomicMemory::WriteBack(Instruction *inst, ReferenceCount *context, - DataBuffer *db) { +void AtomicMemory::WriteBack(Instruction* inst, ReferenceCount* context, + DataBuffer* db) { if (inst != nullptr) { if (db->latency() > 0) { inst->IncRef(); @@ -257,7 +261,7 @@ } } -DataBuffer *AtomicMemory::GetDb(int size) const { +DataBuffer* AtomicMemory::GetDb(int size) const { switch (size) { case 1: return db1_;
diff --git a/mpact/sim/util/memory/atomic_memory.h b/mpact/sim/util/memory/atomic_memory.h index 28d927d..1864787 100644 --- a/mpact/sim/util/memory/atomic_memory.h +++ b/mpact/sim/util/memory/atomic_memory.h
@@ -15,7 +15,10 @@ #ifndef MPACT_SIM_UTIL_MEMORY_ATOMIC_MEMORY_H_ #define MPACT_SIM_UTIL_MEMORY_ATOMIC_MEMORY_H_ +#include <cstdint> + #include "absl/container/flat_hash_set.h" +#include "absl/status/status.h" #include "mpact/sim/generic/data_buffer.h" #include "mpact/sim/generic/instruction.h" #include "mpact/sim/generic/ref_count.h" @@ -37,14 +40,14 @@ using Operation = AtomicMemoryOpInterface::Operation; AtomicMemory() = delete; - explicit AtomicMemory(MemoryInterface *memory); + explicit AtomicMemory(MemoryInterface* memory); ~AtomicMemory() override; // Load data from address into the DataBuffer, then schedule the Instruction // inst (if not nullptr) to be executed (using the function delay line) with // context. The size of the data access is based on size of the data buffer. - void Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; + void Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; // Load data from N addresses stored in address_db (uint64), using mask_db // (bool) to mask out the corresponding loads from taking place (if false). // Each access is el_size bytes long, and is stored into the DataBuffer. @@ -52,30 +55,30 @@ // executed (using the function delay line) with context. It's the // responsibility of the caller to ensure that all DataBuffer instances passed // in are appropriately sized. - void Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; + void Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; // Stores data from the DataBuffer instance to memory starting at address. - void Store(uint64_t address, DataBuffer *db) override; + void Store(uint64_t address, DataBuffer* db) override; // Stores data starting at each of the N addresses stored in address_db, // (uint64) using mask_db (bool) to mask out stores from taking place (if // false). Each store is el_size bytes long. It's the responsibility of the // caller to ensure that all DataBuffer instances that are passed in are // appropriately sized. - void Store(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db) override; + void Store(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db) override; - absl::Status PerformMemoryOp(uint64_t address, Operation op, DataBuffer *db, - Instruction *inst, - ReferenceCount *context) override; + absl::Status PerformMemoryOp(uint64_t address, Operation op, DataBuffer* db, + Instruction* inst, + ReferenceCount* context) override; private: static constexpr int kTagShift = 3; // Write back the result. - void WriteBack(Instruction *inst, ReferenceCount *context, DataBuffer *db); + void WriteBack(Instruction* inst, ReferenceCount* context, DataBuffer* db); // Returns the db of the given size. - DataBuffer *GetDb(int size) const; - MemoryInterface *memory_ = nullptr; + DataBuffer* GetDb(int size) const; + MemoryInterface* memory_ = nullptr; // Tag store for load linked operations. This is used to track if there is an // intervening store between the ll and the sc instruction. The addresses used // are the memory address shifted right by three. For byte addressable @@ -83,10 +86,10 @@ // and that the ll/sc tracking granule is 8 bytes. absl::flat_hash_set<uint64_t> ll_tag_set_; // Support accesses of 1 through 8 byte integer types. - DataBuffer *db1_; - DataBuffer *db2_; - DataBuffer *db4_; - DataBuffer *db8_; + DataBuffer* db1_; + DataBuffer* db2_; + DataBuffer* db4_; + DataBuffer* db8_; DataBufferFactory db_factory_; };
diff --git a/mpact/sim/util/memory/atomic_tagged_memory.cc b/mpact/sim/util/memory/atomic_tagged_memory.cc index 6c649bb..9d43890 100644 --- a/mpact/sim/util/memory/atomic_tagged_memory.cc +++ b/mpact/sim/util/memory/atomic_tagged_memory.cc
@@ -30,7 +30,7 @@ // Helper function that writes the value to the data buffer. template <typename I> -static absl::Status WriteDb(DataBuffer *db, I value) { +static absl::Status WriteDb(DataBuffer* db, I value) { switch (db->size<uint8_t>()) { case 1: db->Set<uint8_t>(0, static_cast<uint8_t>(value)); @@ -55,8 +55,8 @@ // buffers. template <typename T> static void PerformOp(AtomicMemoryOpInterface::Operation op, - const DataBuffer *db_lhs, const DataBuffer *db_rhs, - DataBuffer *db_res) { + const DataBuffer* db_lhs, const DataBuffer* db_rhs, + DataBuffer* db_res) { using UT = typename std::make_unsigned<T>::type; using ST = typename std::make_signed<T>::type; switch (op) { @@ -94,7 +94,7 @@ } // Constructor. -AtomicTaggedMemory::AtomicTaggedMemory(TaggedMemoryInterface *tagged_memory) +AtomicTaggedMemory::AtomicTaggedMemory(TaggedMemoryInterface* tagged_memory) : tagged_memory_(tagged_memory) { // Construct and initialize the local data buffers. db1_ = db_factory_.Allocate<uint8_t>(1); @@ -120,27 +120,27 @@ } // Forward the load call. -void AtomicTaggedMemory::Load(uint64_t address, DataBuffer *db, - DataBuffer *tag_db, Instruction *inst, - ReferenceCount *context) { +void AtomicTaggedMemory::Load(uint64_t address, DataBuffer* db, + DataBuffer* tag_db, Instruction* inst, + ReferenceCount* context) { tagged_memory_->Load(address, db, tag_db, inst, context); } -void AtomicTaggedMemory::Load(uint64_t address, DataBuffer *db, - Instruction *inst, ReferenceCount *context) { +void AtomicTaggedMemory::Load(uint64_t address, DataBuffer* db, + Instruction* inst, ReferenceCount* context) { tagged_memory_->Load(address, db, inst, context); } // Forward the load call. -void AtomicTaggedMemory::Load(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void AtomicTaggedMemory::Load(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db, Instruction* inst, + ReferenceCount* context) { tagged_memory_->Load(address_db, mask_db, el_size, db, inst, context); } // Store the value to memory, but remove any matching tag from the tag set. -void AtomicTaggedMemory::Store(uint64_t address, DataBuffer *db, - DataBuffer *tag_db) { +void AtomicTaggedMemory::Store(uint64_t address, DataBuffer* db, + DataBuffer* tag_db) { // If the address matches a tag, remove the tag. auto ptr = ll_tag_set_.find(address >> kTagShift); if (ptr != ll_tag_set_.end()) { @@ -150,7 +150,7 @@ } // Store the value to memory, but remove any matching tag from the tag set. -void AtomicTaggedMemory::Store(uint64_t address, DataBuffer *db) { +void AtomicTaggedMemory::Store(uint64_t address, DataBuffer* db) { // If the address matches a tag, remove the tag. auto ptr = ll_tag_set_.find(address >> kTagShift); if (ptr != ll_tag_set_.end()) { @@ -160,8 +160,8 @@ } // Store the value to memory, but remove any matching tag from the tag set. -void AtomicTaggedMemory::Store(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db) { +void AtomicTaggedMemory::Store(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db) { // If the address matches a tag, remove the tag. for (uint64_t address : address_db->Get<uint64_t>()) { auto ptr = ll_tag_set_.find(address >> kTagShift); @@ -174,9 +174,9 @@ // Perform the atomic memory operation. absl::Status AtomicTaggedMemory::PerformMemoryOp(uint64_t address, Operation op, - DataBuffer *db, - Instruction *inst, - ReferenceCount *context) { + DataBuffer* db, + Instruction* inst, + ReferenceCount* context) { int el_size = db->size<uint8_t>(); db->set_latency(0); // Load-linked. @@ -206,7 +206,7 @@ } // Load the data from memory. - auto *tmp_db = GetDb(el_size); + auto* tmp_db = GetDb(el_size); if (tmp_db == nullptr) return absl::InternalError( absl::StrCat("Illegal element size (", el_size, ")")); @@ -262,8 +262,8 @@ return absl::OkStatus(); } -void AtomicTaggedMemory::WriteBack(Instruction *inst, ReferenceCount *context, - DataBuffer *db) { +void AtomicTaggedMemory::WriteBack(Instruction* inst, ReferenceCount* context, + DataBuffer* db) { if (inst != nullptr) { if (db->latency() > 0) { inst->IncRef(); @@ -281,7 +281,7 @@ } } -DataBuffer *AtomicTaggedMemory::GetDb(int size) const { +DataBuffer* AtomicTaggedMemory::GetDb(int size) const { switch (size) { case 1: return db1_;
diff --git a/mpact/sim/util/memory/atomic_tagged_memory.h b/mpact/sim/util/memory/atomic_tagged_memory.h index 455d1fd..5090bf2 100644 --- a/mpact/sim/util/memory/atomic_tagged_memory.h +++ b/mpact/sim/util/memory/atomic_tagged_memory.h
@@ -42,16 +42,16 @@ using Operation = AtomicMemoryOpInterface::Operation; AtomicTaggedMemory() = delete; - explicit AtomicTaggedMemory(TaggedMemoryInterface *tagged_memory); + explicit AtomicTaggedMemory(TaggedMemoryInterface* tagged_memory); ~AtomicTaggedMemory() override; // Load data from address into the DataBuffer, then schedule the Instruction // inst (if not nullptr) to be executed (using the function delay line) with // context. The size of the data access is based on size of the data buffer. - void Load(uint64_t address, DataBuffer *db, DataBuffer *tag_db, - Instruction *inst, ReferenceCount *context) override; - void Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; + void Load(uint64_t address, DataBuffer* db, DataBuffer* tag_db, + Instruction* inst, ReferenceCount* context) override; + void Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; // Load data from N addresses stored in address_db (uint64), using mask_db // (bool) to mask out the corresponding loads from taking place (if false). // Each access is el_size bytes long, and is stored into the DataBuffer. @@ -59,32 +59,32 @@ // executed (using the function delay line) with context. It's the // responsibility of the caller to ensure that all DataBuffer instances passed // in are appropriately sized. - void Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; + void Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; // Stores data from the DataBuffer instance to memory starting at address. - void Store(uint64_t address, DataBuffer *db, DataBuffer *tag_db) override; + void Store(uint64_t address, DataBuffer* db, DataBuffer* tag_db) override; // Stores data from the DataBuffer instance to memory starting at address. - void Store(uint64_t address, DataBuffer *db) override; + void Store(uint64_t address, DataBuffer* db) override; // Stores data starting at each of the N addresses stored in address_db, // (uint64) using mask_db (bool) to mask out stores from taking place (if // false). Each store is el_size bytes long. It's the responsibility of the // caller to ensure that all DataBuffer instances that are passed in are // appropriately sized. - void Store(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db) override; + void Store(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db) override; - absl::Status PerformMemoryOp(uint64_t address, Operation op, DataBuffer *db, - Instruction *inst, - ReferenceCount *context) override; + absl::Status PerformMemoryOp(uint64_t address, Operation op, DataBuffer* db, + Instruction* inst, + ReferenceCount* context) override; private: static constexpr int kTagShift = 3; // Write back the result. - void WriteBack(Instruction *inst, ReferenceCount *context, DataBuffer *db); + void WriteBack(Instruction* inst, ReferenceCount* context, DataBuffer* db); // Returns the db of the given size. - DataBuffer *GetDb(int size) const; - TaggedMemoryInterface *tagged_memory_ = nullptr; + DataBuffer* GetDb(int size) const; + TaggedMemoryInterface* tagged_memory_ = nullptr; // Tag store for load linked operations. This is used to track if there is an // intervening store between the ll and the sc instruction. The addresses used // are the memory address shifted right by three. For byte addressable @@ -92,10 +92,10 @@ // and that the ll/sc tracking granule is 8 bytes. absl::flat_hash_set<uint64_t> ll_tag_set_; // Support accesses of 1 through 8 byte integer types. - DataBuffer *db1_; - DataBuffer *db2_; - DataBuffer *db4_; - DataBuffer *db8_; + DataBuffer* db1_; + DataBuffer* db2_; + DataBuffer* db4_; + DataBuffer* db8_; DataBufferFactory db_factory_; };
diff --git a/mpact/sim/util/memory/cache.cc b/mpact/sim/util/memory/cache.cc index defa1b3..8f36b63 100644 --- a/mpact/sim/util/memory/cache.cc +++ b/mpact/sim/util/memory/cache.cc
@@ -39,7 +39,7 @@ using ::mpact::sim::generic::Component; // Constructors. -Cache::Cache(std::string name, Component *parent, MemoryInterface *memory) +Cache::Cache(std::string name, Component* parent, MemoryInterface* memory) : Component(name, parent), read_hit_counter_("read_hit", 0ULL), read_miss_counter_("read_miss", 0ULL), @@ -66,8 +66,8 @@ cache_inst_->set_semantic_function(absl::bind_front(&Cache::LoadChild, this)); } -Cache::Cache(std::string name, Component *parent, - TaggedMemoryInterface *tagged_memory) +Cache::Cache(std::string name, Component* parent, + TaggedMemoryInterface* tagged_memory) : Component(name, parent), read_hit_counter_("read_hit", 0ULL), read_miss_counter_("read_miss", 0ULL), @@ -93,25 +93,25 @@ } // The simple constructors just call the main constructors. -Cache::Cache(std::string name, MemoryInterface *memory) +Cache::Cache(std::string name, MemoryInterface* memory) : Cache(name, nullptr, memory) {} -Cache::Cache(std::string name, TaggedMemoryInterface *tagged_memory) +Cache::Cache(std::string name, TaggedMemoryInterface* tagged_memory) : Cache(name, nullptr, tagged_memory) {} -Cache::Cache(std::string name, Component *parent) - : Cache(name, parent, static_cast<MemoryInterface *>(nullptr)) {} +Cache::Cache(std::string name, Component* parent) + : Cache(name, parent, static_cast<MemoryInterface*>(nullptr)) {} Cache::Cache(std::string name) - : Cache(name, static_cast<Component *>(nullptr)) {} + : Cache(name, static_cast<Component*>(nullptr)) {} Cache::~Cache() { delete[] cache_lines_; cache_inst_->DecRef(); } -absl::Status Cache::Configure(const std::string &config, - CounterValueOutputBase<uint64_t> *cycle_counter) { +absl::Status Cache::Configure(const std::string& config, + CounterValueOutputBase<uint64_t>* cycle_counter) { if (cycle_counter == nullptr) { return absl::InvalidArgumentError("Cycle counter is null"); } @@ -239,13 +239,13 @@ // the method will call the ReplaceBlock method to replace the block in the // cache. The memory request itself will be forwarded to the memory interface // provided to the constructor (if not nullptr). -void Cache::Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void Cache::Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) { (void)CacheLookup(address, db->size<uint8_t>(), /*is_read=*/true); if (memory_ == nullptr) return; - auto *cache_context = new CacheContext(context, db, inst, db->latency()); + auto* cache_context = new CacheContext(context, db, inst, db->latency()); if (context) context->IncRef(); if (inst) inst->IncRef(); db->IncRef(); @@ -254,8 +254,8 @@ cache_context->DecRef(); } -void Cache::Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, ReferenceCount *context) { +void Cache::Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, ReferenceCount* context) { auto address_span = address_db->Get<uint64_t>(); auto mask_span = mask_db->Get<bool>(); for (int i = 0; i < address_db->size<uint64_t>(); i++) { @@ -265,7 +265,7 @@ } if (memory_ == nullptr) return; - auto *cache_context = new CacheContext(context, db, inst, db->latency()); + auto* cache_context = new CacheContext(context, db, inst, db->latency()); if (context) context->IncRef(); if (inst) inst->IncRef(); db->IncRef(); @@ -274,8 +274,8 @@ cache_context->DecRef(); } -void Cache::Load(uint64_t address, DataBuffer *db, DataBuffer *tags, - Instruction *inst, ReferenceCount *context) { +void Cache::Load(uint64_t address, DataBuffer* db, DataBuffer* tags, + Instruction* inst, ReferenceCount* context) { // Since db can be nullptr (for a tag only load), the size and latency may // have to be computed differently. For size, base it on the number of tags // that are being loaded. For latency, use 0. @@ -296,7 +296,7 @@ return; } - auto *cache_context = new CacheContext(context, db, inst, latency); + auto* cache_context = new CacheContext(context, db, inst, latency); if (context) context->IncRef(); if (inst) inst->IncRef(); if (db) { @@ -307,15 +307,15 @@ cache_context->DecRef(); } -void Cache::Store(uint64_t address, DataBuffer *db) { +void Cache::Store(uint64_t address, DataBuffer* db) { (void)CacheLookup(address, db->size<uint8_t>(), /*is_read=*/false); if (memory_ == nullptr) return; memory_->Store(address, db); } -void Cache::Store(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db) { +void Cache::Store(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db) { auto address_span = address_db->Get<uint64_t>(); auto mask_span = mask_db->Get<bool>(); for (int i = 0; i < address_db->size<uint64_t>(); i++) { @@ -328,7 +328,7 @@ memory_->Store(address_db, mask_db, el_size, db); } -void Cache::Store(uint64_t address, DataBuffer *db, DataBuffer *tags) { +void Cache::Store(uint64_t address, DataBuffer* db, DataBuffer* tags) { (void)CacheLookup(address, db->size<uint8_t>(), /*is_read=*/false); if (tagged_memory_ == nullptr) return; @@ -338,11 +338,11 @@ // This is the semantic function that is bound to the cache_inst_ instruction // and is used to perform the writeback to the processor of the data that was // read. -void Cache::LoadChild(const Instruction *inst) { - auto *cache_context = static_cast<CacheContext *>(inst->context()); - auto *og_context = cache_context->context; - auto *db = cache_context->db; - auto *og_inst = cache_context->inst; +void Cache::LoadChild(const Instruction* inst) { + auto* cache_context = static_cast<CacheContext*>(inst->context()); + auto* og_context = cache_context->context; + auto* db = cache_context->db; + auto* og_inst = cache_context->inst; // Reset the db latency to the original value. if (nullptr != og_inst) { if (cache_context->latency > 0) { @@ -393,7 +393,7 @@ bool hit = false; // Iterate over the number of sets in the cache. for (int set = 0; set < num_sets_; set++) { - CacheLine &line = cache_lines_[index + set]; + CacheLine& line = cache_lines_[index + set]; if (line.valid && line.tag == block) { hit = true; line.lru = cycle_counter_->GetValue(); @@ -432,7 +432,7 @@ int victim = -1; uint64_t victim_lru = std::numeric_limits<uint64_t>::max(); for (int set = 0; set < num_sets_; set++) { - CacheLine &line = cache_lines_[index + set]; + CacheLine& line = cache_lines_[index + set]; // If the line is invalid, use it as the victim. if (!line.valid) { victim = index + set; @@ -458,7 +458,7 @@ return; } // Perform the replacement on the victim. - CacheLine &line = cache_lines_[victim]; + CacheLine& line = cache_lines_[victim]; // If the line is dirty (and valid), count the writeback. if (line.valid && line.dirty) { dirty_line_writeback_counter_.Increment(1ULL);
diff --git a/mpact/sim/util/memory/cache.h b/mpact/sim/util/memory/cache.h index af2e11b..711a844 100644 --- a/mpact/sim/util/memory/cache.h +++ b/mpact/sim/util/memory/cache.h
@@ -67,16 +67,16 @@ // the memory request when it's forwarded on to the memory interface. struct CacheContext : public ReferenceCount { // The context of the original memory reference. - ReferenceCount *context; + ReferenceCount* context; // Original data buffer. - DataBuffer *db; + DataBuffer* db; // Instruction to be executed upon memory access completion. - Instruction *inst; + Instruction* inst; // Latency of the memory access. int latency; // Two constructors depending on whether the cache is used with a tagged // memory interface or not. - CacheContext(ReferenceCount *context_, DataBuffer *db_, Instruction *inst_, + CacheContext(ReferenceCount* context_, DataBuffer* db_, Instruction* inst_, int latency_) : context(context_), db(db_), inst(inst_), latency(latency_) {} }; @@ -86,17 +86,17 @@ // to use for the cache, a pointer to the parent component (used to register // and provide access to the performance counters), and a memory interface // used to forward memory requests to. - Cache(std::string name, Component *parent, MemoryInterface *memory); - Cache(std::string name, Component *parent, - TaggedMemoryInterface *tagged_memory); + Cache(std::string name, Component* parent, MemoryInterface* memory); + Cache(std::string name, Component* parent, + TaggedMemoryInterface* tagged_memory); // Shorthand constructors that omit some parameters. - Cache(std::string name, MemoryInterface *memory); - Cache(std::string name, TaggedMemoryInterface *tagged_memory); - Cache(std::string name, Component *parent); + Cache(std::string name, MemoryInterface* memory); + Cache(std::string name, TaggedMemoryInterface* tagged_memory); + Cache(std::string name, Component* parent); explicit Cache(std::string name); Cache() = delete; - Cache(const Cache &) = delete; - Cache operator=(const Cache &) = delete; + Cache(const Cache&) = delete; + Cache operator=(const Cache&) = delete; ~Cache() override; // Configure the cache. The configuration string is expected to be in the @@ -114,29 +114,29 @@ // // cycle_counter is a pointer to a counter that counts cycles in the // simulation. - absl::Status Configure(const std::string &config, - CounterValueOutputBase<uint64_t> *cycle_counter); + absl::Status Configure(const std::string& config, + CounterValueOutputBase<uint64_t>* cycle_counter); // MemoryInterface and TaggedMemoryInterfacemethods. - void Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; - void Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; - void Load(uint64_t address, DataBuffer *db, DataBuffer *tags, - Instruction *inst, ReferenceCount *context) override; - void Store(uint64_t address, DataBuffer *db) override; - void Store(DataBuffer *address, DataBuffer *mask, int el_size, - DataBuffer *db) override; - void Store(uint64_t address, DataBuffer *db, DataBuffer *tags) override; + void Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; + void Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; + void Load(uint64_t address, DataBuffer* db, DataBuffer* tags, + Instruction* inst, ReferenceCount* context) override; + void Store(uint64_t address, DataBuffer* db) override; + void Store(DataBuffer* address, DataBuffer* mask, int el_size, + DataBuffer* db) override; + void Store(uint64_t address, DataBuffer* db, DataBuffer* tags) override; // Setters for the memory interfaces. - void set_memory(MemoryInterface *memory) { + void set_memory(MemoryInterface* memory) { memory_ = memory; tagged_memory_ = nullptr; } - void set_tagged_memory(TaggedMemoryInterface *tagged_memory) { + void set_tagged_memory(TaggedMemoryInterface* tagged_memory) { tagged_memory_ = tagged_memory; - memory_ = static_cast<MemoryInterface *>(tagged_memory); + memory_ = static_cast<MemoryInterface*>(tagged_memory); } private: @@ -155,8 +155,8 @@ // of the second. Thus if neither is less than the other, they overlap in // in some way. struct AddressRangeLess { - constexpr bool operator()(const AddressRange &lhs, - const AddressRange &rhs) const { + constexpr bool operator()(const AddressRange& lhs, + const AddressRange& rhs) const { return lhs.end < rhs.start; } }; @@ -178,12 +178,12 @@ // This is a semantic function that is bound to a local instruction instance // and is used to perform the writeback to the processor of the data that was // read. - void LoadChild(const Instruction *inst); + void LoadChild(const Instruction* inst); // Cache read/write function. Returns the number of cache misses. int CacheLookup(uint64_t address, int size, bool is_read); void ReplaceBlock(uint64_t block, bool is_read); // The cache. - CacheLine *cache_lines_ = nullptr; + CacheLine* cache_lines_ = nullptr; // Shift amounts and mask used to compute the index from the address. int block_shift_ = 0; int set_shift_ = 0; @@ -197,8 +197,8 @@ bool has_non_cacheable_ = false; bool has_cacheable_ = false; // Instruction object used to perform the writeback to the processor. - Instruction *cache_inst_; - CounterValueOutputBase<uint64_t> *cycle_counter_; + Instruction* cache_inst_; + CounterValueOutputBase<uint64_t>* cycle_counter_; // Performance counters. SimpleCounter<uint64_t> read_hit_counter_; SimpleCounter<uint64_t> read_miss_counter_; @@ -210,8 +210,8 @@ SimpleCounter<uint64_t> read_non_cacheable_counter_; SimpleCounter<uint64_t> write_non_cacheable_counter_; // Memory interface pointers. - MemoryInterface *memory_; - TaggedMemoryInterface *tagged_memory_; + MemoryInterface* memory_; + TaggedMemoryInterface* tagged_memory_; }; } // namespace mpact::sim::util
diff --git a/mpact/sim/util/memory/flat_demand_memory.cc b/mpact/sim/util/memory/flat_demand_memory.cc index 8107668..e026de7 100644 --- a/mpact/sim/util/memory/flat_demand_memory.cc +++ b/mpact/sim/util/memory/flat_demand_memory.cc
@@ -43,13 +43,13 @@ // Delete all the allocated blocks. FlatDemandMemory::~FlatDemandMemory() { Clear(); } -void FlatDemandMemory::Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void FlatDemandMemory::Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) { int size_in_units = db->size<uint8_t>() >> addressable_unit_shift_; uint64_t high = address + size_in_units; ABSL_HARDENING_ASSERT((address >= base_address_) && (high <= max_address_)); ABSL_HARDENING_ASSERT(size_in_units > 0); - uint8_t *byte_ptr = static_cast<uint8_t *>(db->raw_ptr()); + uint8_t* byte_ptr = static_cast<uint8_t*>(db->raw_ptr()); // Load the data into the data buffer. LoadStoreHelper(address, byte_ptr, size_in_units, true); // Execute the instruction to process and write back the load data. @@ -70,12 +70,12 @@ } } -void FlatDemandMemory::Load(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void FlatDemandMemory::Load(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db, Instruction* inst, + ReferenceCount* context) { auto mask_span = mask_db->Get<bool>(); auto address_span = address_db->Get<uint64_t>(); - uint8_t *byte_ptr = static_cast<uint8_t *>(db->raw_ptr()); + uint8_t* byte_ptr = static_cast<uint8_t*>(db->raw_ptr()); int size_in_units = el_size >> addressable_unit_shift_; ABSL_HARDENING_ASSERT(size_in_units > 0); // This is either a gather load, or a unit stride load depending on size of @@ -106,20 +106,20 @@ } } -void FlatDemandMemory::Store(uint64_t address, DataBuffer *db) { +void FlatDemandMemory::Store(uint64_t address, DataBuffer* db) { int size_in_units = db->size<uint8_t>() >> addressable_unit_shift_; uint64_t high = address + size_in_units; ABSL_HARDENING_ASSERT((address >= base_address_) && (high <= max_address_)); ABSL_HARDENING_ASSERT(size_in_units > 0); - uint8_t *byte_ptr = static_cast<uint8_t *>(db->raw_ptr()); + uint8_t* byte_ptr = static_cast<uint8_t*>(db->raw_ptr()); LoadStoreHelper(address, byte_ptr, size_in_units, /*is_load*/ false); } -void FlatDemandMemory::Store(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db) { +void FlatDemandMemory::Store(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db) { auto mask_span = mask_db->Get<bool>(); auto address_span = address_db->Get<uint64_t>(); - uint8_t *byte_ptr = static_cast<uint8_t *>(db->raw_ptr()); + uint8_t* byte_ptr = static_cast<uint8_t*>(db->raw_ptr()); int size_in_units = el_size >> addressable_unit_shift_; ABSL_HARDENING_ASSERT(size_in_units > 0); // If the address_span.size() > 1, then this is a scatter store, otherwise @@ -136,7 +136,7 @@ } } -void FlatDemandMemory::LoadStoreHelper(uint64_t address, uint8_t *data_ptr, +void FlatDemandMemory::LoadStoreHelper(uint64_t address, uint8_t* data_ptr, int size_in_units, bool is_load) { // Repeat the following while there is data to copy. If it's a big chunk of // data it may span across more than one block. @@ -145,7 +145,7 @@ uint64_t block_address = address >> kAllocationShift; auto iter = block_map_.find(block_address); - uint8_t *block; + uint8_t* block; if (iter == block_map_.end()) { block = new uint8_t[allocation_byte_size_]; block_map_.insert(std::make_pair(block_address, block)); @@ -180,7 +180,7 @@ } void FlatDemandMemory::Clear() { - for (auto &[unused, block_ptr] : block_map_) { + for (auto& [unused, block_ptr] : block_map_) { delete[] block_ptr; } block_map_.clear();
diff --git a/mpact/sim/util/memory/flat_demand_memory.h b/mpact/sim/util/memory/flat_demand_memory.h index f583a2f..982e908 100644 --- a/mpact/sim/util/memory/flat_demand_memory.h +++ b/mpact/sim/util/memory/flat_demand_memory.h
@@ -51,8 +51,8 @@ // Load data from address into the DataBuffer, then schedule the Instruction // inst (if not nullptr) to be executed (using the function delay line) with // context. The size of the data access is based on size of the data buffer. - void Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; + void Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; // Load data from N addresses stored in address_db (uint64), using mask_db // (bool) to mask out the corresponding loads from taking place (if false). // Each access is el_size bytes long, and is stored into the DataBuffer. @@ -60,29 +60,29 @@ // executed (using the function delay line) with context. It's the // responsibility of the caller to ensure that all DataBuffer instances passed // in are appropriately sized. - void Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; + void Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; // Convenience template function that calls the above function with the // element size as the sizeof() the template parameter type. template <typename T> - void Load(DataBuffer *address_db, DataBuffer *mask_db, DataBuffer *db, - Instruction *inst, ReferenceCount *context) { + void Load(DataBuffer* address_db, DataBuffer* mask_db, DataBuffer* db, + Instruction* inst, ReferenceCount* context) { Load(address_db, mask_db, sizeof(T), db, inst, context); } // Stores data from the DataBuffer instance to memory starting at address. - void Store(uint64_t address, DataBuffer *db) override; + void Store(uint64_t address, DataBuffer* db) override; // Stores data starting at each of the N addresses stored in address_db, // (uint64) using mask_db (bool) to mask out stores from taking place (if // false). Each store is el_size bytes long. It's the responsibility of the // caller to ensure that all DataBuffer instances that are passed in are // appropriately sized. - void Store(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db) override; + void Store(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db) override; // Convenience template function that calls the above function with the // element size as the sizeof() the template parameter type. template <typename T> - void Store(DataBuffer *address_db, DataBuffer *mask_db, DataBuffer *db) { + void Store(DataBuffer* address_db, DataBuffer* mask_db, DataBuffer* db) { Store(address_db, mask_db, sizeof(T), db); } static constexpr int kAllocationSize = 16 * 1024; // Power of two. @@ -91,7 +91,7 @@ void Clear(); private: - void LoadStoreHelper(uint64_t address, uint8_t *data_ptr, int size_in_units, + void LoadStoreHelper(uint64_t address, uint8_t* data_ptr, int size_in_units, bool is_load); static constexpr int kAllocationShift = 14; @@ -101,7 +101,7 @@ uint8_t fill_value_; int addressable_unit_shift_; int allocation_byte_size_; - absl::flat_hash_map<uint64_t, uint8_t *> block_map_; + absl::flat_hash_map<uint64_t, uint8_t*> block_map_; }; } // namespace util
diff --git a/mpact/sim/util/memory/flat_memory.cc b/mpact/sim/util/memory/flat_memory.cc index 95cfd19..a3ceee6 100644 --- a/mpact/sim/util/memory/flat_memory.cc +++ b/mpact/sim/util/memory/flat_memory.cc
@@ -15,7 +15,7 @@ #include "mpact/sim/util/memory/flat_memory.h" #include <cstdint> -#include <functional> +#include <cstring> #include "absl/base/macros.h" #include "absl/numeric/bits.h" @@ -24,12 +24,12 @@ namespace sim { namespace util { -void FlatMemory::Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void FlatMemory::Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) { ABSL_HARDENING_ASSERT(address >= base_); uint64_t offset = (address - base_) << shift_; ABSL_HARDENING_ASSERT(offset + db->size<uint8_t>() <= size_); - uint8_t *ptr = &memory_buffer_[offset]; + uint8_t* ptr = &memory_buffer_[offset]; db->CopyFrom(ptr); if (nullptr != inst) { if (db->latency() > 0) { @@ -48,9 +48,9 @@ } } -void FlatMemory::Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void FlatMemory::Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) { int max = mask_db->size<bool>(); switch (el_size) { case 1: @@ -87,16 +87,16 @@ } } -void FlatMemory::Store(uint64_t address, DataBuffer *db) { +void FlatMemory::Store(uint64_t address, DataBuffer* db) { ABSL_HARDENING_ASSERT(address >= base_); uint64_t offset = (address - base_) << shift_; ABSL_HARDENING_ASSERT(offset + db->size<uint8_t>() <= size_); - uint8_t *ptr = &memory_buffer_[offset]; + uint8_t* ptr = &memory_buffer_[offset]; db->CopyTo(ptr); } -void FlatMemory::Store(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db) { +void FlatMemory::Store(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db) { int max = mask_db->size<bool>(); switch (el_size) {
diff --git a/mpact/sim/util/memory/flat_memory.h b/mpact/sim/util/memory/flat_memory.h index b6b48de..b51c3d8 100644 --- a/mpact/sim/util/memory/flat_memory.h +++ b/mpact/sim/util/memory/flat_memory.h
@@ -54,8 +54,8 @@ // Load a DataBuffer instance db from a single address, calling the Execute // method of inst (if inst is not equal to nullptr) with context when the data // has been written to db. - void Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; + void Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; // Load a DataBuffer instance db with el_size sized memory accesses using the // addresses stored in the address_db DataBuffer instance subject to the // masking of the boolean masks stored in the mask_db DataBuffer instance. @@ -64,20 +64,20 @@ // sizeof(uint64), mask_db sizeof(bool), and db is el_size. Once the data has // been written to db, the Execute method of inst is called (if inst is not // equal to nullptr) with the given context. - void Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; + void Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; // Convenience template function that calls the above function with the // element size as the sizeof() the template parameter type. template <typename T> - void Load(DataBuffer *address_db, DataBuffer *mask_db, DataBuffer *db, - Instruction *inst, ReferenceCount *context) { + void Load(DataBuffer* address_db, DataBuffer* mask_db, DataBuffer* db, + Instruction* inst, ReferenceCount* context) { Load(address_db, mask_db, sizeof(T), db, inst, context); } // Store the contents of the DataBuffer instance db to memory starting at the // given address. - void Store(uint64_t address, DataBuffer *db) override; + void Store(uint64_t address, DataBuffer* db) override; // Store the contents of the DataBuffer instance db to memory with el_size // sized accesses based using the addresses stored in the address_db // DataBuffer instance subject to the masking of the boolean masks stored in @@ -86,12 +86,12 @@ // the element sizes vary (thus the overall byte size of the DataBuffer // instances vary). The elements sizes are: address_db sizeof(uint64), mask_db // sizeof(bool), and db is el_size. - void Store(DataBuffer *address, DataBuffer *mask, int el_size, - DataBuffer *db) override; + void Store(DataBuffer* address, DataBuffer* mask, int el_size, + DataBuffer* db) override; // Convenience template function that calls the above function with the // element size as the sizeof() the template parameter type. template <typename T> - void Store(DataBuffer *address_db, DataBuffer *mask_db, DataBuffer *db) { + void Store(DataBuffer* address_db, DataBuffer* mask_db, DataBuffer* db) { Store(address_db, mask_db, sizeof(T), db); } @@ -104,8 +104,8 @@ // Private helper function used for copying data from memory to the // databuffer for the vector gather load. template <typename T> - void LoadData(const DataBuffer *address_db, const DataBuffer *mask_db, - int max, DataBuffer *db) { + void LoadData(const DataBuffer* address_db, const DataBuffer* mask_db, + int max, DataBuffer* db) { auto masks = mask_db->Get<bool>(); auto addresses = address_db->Get<uint64_t>(); bool gather = addresses.size() > 1; @@ -116,7 +116,7 @@ ABSL_HARDENING_ASSERT(address >= base_); uint64_t offset = (address - base_) << shift_; ABSL_HARDENING_ASSERT(offset + sizeof(T) <= size_); - db->Set<T>(entry, *reinterpret_cast<T *>(&memory_buffer_[offset])); + db->Set<T>(entry, *reinterpret_cast<T*>(&memory_buffer_[offset])); } } } @@ -124,8 +124,8 @@ // Private helper function used for copying data from the databuffer to // memory for the vector scatter store. template <typename T> - void StoreData(const DataBuffer *address_db, const DataBuffer *mask_db, - int max, const DataBuffer *db) { + void StoreData(const DataBuffer* address_db, const DataBuffer* mask_db, + int max, const DataBuffer* db) { auto masks = mask_db->Get<bool>(); auto addresses = address_db->Get<uint64_t>(); bool gather = addresses.size() > 1; @@ -136,14 +136,14 @@ ABSL_HARDENING_ASSERT(address >= base_); uint64_t offset = (address - base_) << shift_; ABSL_HARDENING_ASSERT(offset + sizeof(T) <= size_); - *reinterpret_cast<T *>(&memory_buffer_[offset]) = db->Get<T>(entry); + *reinterpret_cast<T*>(&memory_buffer_[offset]) = db->Get<T>(entry); } } } int64_t size_; uint64_t base_; int shift_; - uint8_t *memory_buffer_; + uint8_t* memory_buffer_; }; } // namespace util
diff --git a/mpact/sim/util/memory/memory_interface.h b/mpact/sim/util/memory/memory_interface.h index 6d75548..028f20a 100644 --- a/mpact/sim/util/memory/memory_interface.h +++ b/mpact/sim/util/memory/memory_interface.h
@@ -49,8 +49,8 @@ // Load data from address into the DataBuffer, then schedule the Instruction // inst (if not nullptr) to be executed (using the function delay line) with // context. The size of the data access is based on size of the data buffer. - virtual void Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) = 0; + virtual void Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) = 0; // Load data from 1 or N addresses stored in address_db (uint64), using // mask_db (bool) to mask out the corresponding loads from taking place (if // false). Each access is el_size bytes long, and is stored into the @@ -60,19 +60,19 @@ // in are appropriately sized. Use the DataBuffer size<uint64_t> to determine // the number of addresses availalble. The following summarizes the parameter // requirements: - virtual void Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) = 0; + virtual void Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) = 0; // Convenience template function that calls the above function with the // element size as the sizeof() the template parameter type. template <typename T> - void Load(DataBuffer *address_db, DataBuffer *mask_db, DataBuffer *db, - Instruction *inst, ReferenceCount *context) { + void Load(DataBuffer* address_db, DataBuffer* mask_db, DataBuffer* db, + Instruction* inst, ReferenceCount* context) { Load(address_db, mask_db, sizeof(T), db, inst, context); } // Stores data from the DataBuffer instance to memory starting at address. - virtual void Store(uint64_t address, DataBuffer *db) = 0; + virtual void Store(uint64_t address, DataBuffer* db) = 0; // Stores data starting at each of the 1 or N addresses stored in address_db, // (uint64) using mask_db (bool) to mask out stores from taking place (if // false). Each store is el_size bytes long. It's the responsibility of the @@ -82,12 +82,12 @@ // address_db->size<uint64_t>)() is either 1 or N // mask_db->size<bool>() is N // db->size<uint8_t>()/el_size = N. - virtual void Store(DataBuffer *address, DataBuffer *mask, int el_size, - DataBuffer *db) = 0; + virtual void Store(DataBuffer* address, DataBuffer* mask, int el_size, + DataBuffer* db) = 0; // Convenience template function that calls the above function with the // element size as the sizeof() the template parameter type. template <typename T> - void Store(DataBuffer *address_db, DataBuffer *mask_db, DataBuffer *db) { + void Store(DataBuffer* address_db, DataBuffer* mask_db, DataBuffer* db) { Store(address_db, mask_db, sizeof(T), db); } }; @@ -137,8 +137,8 @@ // db->size<uint8_t>() must be equal to sizeof(T) for some integer type, i.e., // 1, 2, 4, or 8. virtual absl::Status PerformMemoryOp(uint64_t address, Operation op, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) = 0; + DataBuffer* db, Instruction* inst, + ReferenceCount* context) = 0; }; } // namespace util
diff --git a/mpact/sim/util/memory/memory_router.cc b/mpact/sim/util/memory/memory_router.cc index 2474952..7c86cf5 100644 --- a/mpact/sim/util/memory/memory_router.cc +++ b/mpact/sim/util/memory/memory_router.cc
@@ -33,7 +33,7 @@ MemoryRouter::MemoryRouter() {} MemoryRouter::~MemoryRouter() { - for (auto &[unused, initiator] : initiators_) delete initiator; + for (auto& [unused, initiator] : initiators_) delete initiator; initiators_.clear(); } @@ -41,29 +41,29 @@ // Templated helper method used in implementing the three methods to add named // initiators to the router (one for each type of initiator interface). template <typename Interface> -Interface *AddInitiator(MemoryRouter::InitiatorMap &initiators, - const std::string &name) { +Interface* AddInitiator(MemoryRouter::InitiatorMap& initiators, + const std::string& name) { // See if it already exists. auto it = initiators.find(name); if (it != initiators.end()) { - return static_cast<Interface *>(it->second); + return static_cast<Interface*>(it->second); } auto initiator = new SingleInitiatorRouter(name); initiators.emplace(std::string(name), initiator); - return static_cast<Interface *>(initiator); + return static_cast<Interface*>(initiator); } -MemoryInterface *MemoryRouter::AddMemoryInitiator(const std::string &name) { +MemoryInterface* MemoryRouter::AddMemoryInitiator(const std::string& name) { return AddInitiator<MemoryInterface>(initiators_, name); } -TaggedMemoryInterface *MemoryRouter::AddTaggedInitiator( - const std::string &name) { +TaggedMemoryInterface* MemoryRouter::AddTaggedInitiator( + const std::string& name) { return AddInitiator<TaggedMemoryInterface>(initiators_, name); } -AtomicMemoryOpInterface *MemoryRouter::AddAtomicInitiator( - const std::string &name) { +AtomicMemoryOpInterface* MemoryRouter::AddAtomicInitiator( + const std::string& name) { return AddInitiator<AtomicMemoryOpInterface>(initiators_, name); } @@ -73,9 +73,9 @@ // add named targets to the router (one for each type of target interface). template <typename Interface> absl::Status AddTargetPrivate( - MemoryRouter::TargetMap<Interface> &target_interface_map, - absl::flat_hash_set<std::string> &target_names, const std::string &name, - Interface *memory) { + MemoryRouter::TargetMap<Interface>& target_interface_map, + absl::flat_hash_set<std::string>& target_names, const std::string& name, + Interface* memory) { // Only one instance of each target name can exist. if (target_names.contains(name)) { return absl::AlreadyExistsError( @@ -88,28 +88,28 @@ } // namespace internal -absl::Status MemoryRouter::AddTarget(const std::string &name, - MemoryInterface *memory) { +absl::Status MemoryRouter::AddTarget(const std::string& name, + MemoryInterface* memory) { return internal::AddTargetPrivate<MemoryInterface>( memory_targets_, target_names_, name, memory); } -absl::Status MemoryRouter::AddTarget(const std::string &name, - TaggedMemoryInterface *tagged_memory) { +absl::Status MemoryRouter::AddTarget(const std::string& name, + TaggedMemoryInterface* tagged_memory) { return internal::AddTargetPrivate<TaggedMemoryInterface>( tagged_targets_, target_names_, name, tagged_memory); } -absl::Status MemoryRouter::AddTarget(const std::string &name, - AtomicMemoryOpInterface *atomic_memory) { +absl::Status MemoryRouter::AddTarget(const std::string& name, + AtomicMemoryOpInterface* atomic_memory) { return internal::AddTargetPrivate<AtomicMemoryOpInterface>( atomic_targets_, target_names_, name, atomic_memory); } // Add a mapping between 'initiator_name' and 'target_name' for the given // address range (inclusive). -absl::Status MemoryRouter::AddMapping(const std::string &initiator_name, - const std::string &target_name, +absl::Status MemoryRouter::AddMapping(const std::string& initiator_name, + const std::string& target_name, uint64_t base, uint64_t top) { // Return error if the initiator doesn't exist. auto it = initiators_.find(initiator_name); @@ -117,7 +117,7 @@ return absl::NotFoundError( absl::StrCat("Initiator: ", initiator_name, " not found")); } - auto *initiator = it->second; + auto* initiator = it->second; // Check each type of target and add the one found to the initiator with the // given address range.
diff --git a/mpact/sim/util/memory/memory_router.h b/mpact/sim/util/memory/memory_router.h index a578ccb..f2c7cac 100644 --- a/mpact/sim/util/memory/memory_router.h +++ b/mpact/sim/util/memory/memory_router.h
@@ -45,14 +45,13 @@ class MemoryRouter { public: // Convenient map types shorthand. - using InitiatorMap = - absl::flat_hash_map<std::string, SingleInitiatorRouter *>; + using InitiatorMap = absl::flat_hash_map<std::string, SingleInitiatorRouter*>; template <typename Interface> - using TargetMap = absl::flat_hash_map<std::string, Interface *>; + using TargetMap = absl::flat_hash_map<std::string, Interface*>; MemoryRouter(); - MemoryRouter(const MemoryRouter &) = delete; - MemoryRouter &operator=(const MemoryRouter &) = delete; + MemoryRouter(const MemoryRouter&) = delete; + MemoryRouter& operator=(const MemoryRouter&) = delete; ~MemoryRouter(); // The following three methods add initiators with a given name. Depending @@ -62,28 +61,28 @@ // SingleInitiatorRouter, but the returned interfaces differ. // Add an initiator with name 'name', returning pointer to MemoryInterface. - MemoryInterface *AddMemoryInitiator(const std::string &name); + MemoryInterface* AddMemoryInitiator(const std::string& name); // Add an initiator with name 'name', returning pointer to // TaggedMemoryInterface. - TaggedMemoryInterface *AddTaggedInitiator(const std::string &name); + TaggedMemoryInterface* AddTaggedInitiator(const std::string& name); // Add an initiator with name 'name', returning pointer to MemoryInterface. - AtomicMemoryOpInterface *AddAtomicInitiator(const std::string &name); + AtomicMemoryOpInterface* AddAtomicInitiator(const std::string& name); // The following three methods add target memory interfaces with the given // name and type. Two different interfaces may not use the same name. // Add 'memory' interface with name 'name'. - absl::Status AddTarget(const std::string &name, MemoryInterface *memory); + absl::Status AddTarget(const std::string& name, MemoryInterface* memory); // Add 'tagged_memory' interface with name 'name'. - absl::Status AddTarget(const std::string &name, - TaggedMemoryInterface *tagged_memory); + absl::Status AddTarget(const std::string& name, + TaggedMemoryInterface* tagged_memory); // Add 'atomic_memory' interface with name 'name'. - absl::Status AddTarget(const std::string &name, - AtomicMemoryOpInterface *atomic_memory); + absl::Status AddTarget(const std::string& name, + AtomicMemoryOpInterface* atomic_memory); // Map a target to an initiator for the given address range (inclusive). - absl::Status AddMapping(const std::string &initiator_name, - const std::string &target_name, uint64_t base, + absl::Status AddMapping(const std::string& initiator_name, + const std::string& target_name, uint64_t base, uint64_t top); private:
diff --git a/mpact/sim/util/memory/memory_use_profiler.cc b/mpact/sim/util/memory/memory_use_profiler.cc index ea04787..35ef4ed 100644 --- a/mpact/sim/util/memory/memory_use_profiler.cc +++ b/mpact/sim/util/memory/memory_use_profiler.cc
@@ -33,14 +33,14 @@ namespace internal { MemoryUseTracker::~MemoryUseTracker() { - for (auto &[unused, bits] : memory_use_map_) { + for (auto& [unused, bits] : memory_use_map_) { delete[] bits; } memory_use_map_.clear(); } // Static helper function. -static inline void MarkUsedBits(uint64_t byte_offset, int mask, uint8_t *bits) { +static inline void MarkUsedBits(uint64_t byte_offset, int mask, uint8_t* bits) { // Shift right by two, so that every byte offset becomes a word offset. uint64_t word_offset = byte_offset >> 2; // Byte offs @@ -68,7 +68,7 @@ // Compute new base and top addresses. uint64_t start = address & ~kBaseMask; uint64_t end = start + kSegmentSize - 1; - auto *bits = new uint8_t[kBitsSize]; + auto* bits = new uint8_t[kBitsSize]; std::memset(bits, 0, kBitsSize); it = memory_use_map_ @@ -83,12 +83,12 @@ } // Write out ranges of words that have been used. -void MemoryUseTracker::WriteUseProfile(std::ostream &os) const { +void MemoryUseTracker::WriteUseProfile(std::ostream& os) const { // Current range info. uint64_t range_start = 0; uint64_t range_end = 0; bool range_started = false; - for (auto const &[range, bits] : memory_use_map_) { + for (auto const& [range, bits] : memory_use_map_) { auto base = range.start; int byte_index = 0; uint8_t byte = bits[byte_index]; @@ -134,18 +134,18 @@ MemoryUseProfiler::MemoryUseProfiler() : MemoryUseProfiler(nullptr) {} -MemoryUseProfiler::MemoryUseProfiler(MemoryInterface *memory) +MemoryUseProfiler::MemoryUseProfiler(MemoryInterface* memory) : memory_(memory) {} -void MemoryUseProfiler::Load(uint64_t address, DataBuffer *db, - Instruction *inst, ReferenceCount *context) { +void MemoryUseProfiler::Load(uint64_t address, DataBuffer* db, + Instruction* inst, ReferenceCount* context) { if (is_enabled_) tracker_.MarkUsed(address, db->size<uint8_t>()); if (memory_) memory_->Load(address, db, inst, context); } -void MemoryUseProfiler::Load(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void MemoryUseProfiler::Load(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db, Instruction* inst, + ReferenceCount* context) { if (is_enabled_) { for (int i = 0; i < address_db->size<uint64_t>(); ++i) { if (mask_db->Get<uint8_t>(i)) { @@ -156,13 +156,13 @@ if (memory_) memory_->Load(address_db, mask_db, el_size, db, inst, context); } -void MemoryUseProfiler::Store(uint64_t address, DataBuffer *db) { +void MemoryUseProfiler::Store(uint64_t address, DataBuffer* db) { if (is_enabled_) tracker_.MarkUsed(address, db->size<uint8_t>()); if (memory_) memory_->Store(address, db); } -void MemoryUseProfiler::Store(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db) { +void MemoryUseProfiler::Store(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db) { if (is_enabled_) { for (int i = 0; i < address_db->size<uint64_t>(); ++i) { if (mask_db->Get<uint8_t>(i)) { @@ -177,18 +177,18 @@ : TaggedMemoryUseProfiler(nullptr) {} TaggedMemoryUseProfiler::TaggedMemoryUseProfiler( - TaggedMemoryInterface *tagged_memory) + TaggedMemoryInterface* tagged_memory) : tagged_memory_(tagged_memory) {} -void TaggedMemoryUseProfiler::Load(uint64_t address, DataBuffer *db, - Instruction *inst, ReferenceCount *context) { +void TaggedMemoryUseProfiler::Load(uint64_t address, DataBuffer* db, + Instruction* inst, ReferenceCount* context) { if (is_enabled_) tracker_.MarkUsed(address, db->size<uint8_t>()); if (tagged_memory_) tagged_memory_->Load(address, db, inst, context); } -void TaggedMemoryUseProfiler::Load(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db, - Instruction *inst, ReferenceCount *context) { +void TaggedMemoryUseProfiler::Load(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db, + Instruction* inst, ReferenceCount* context) { if (is_enabled_) { for (int i = 0; i < address_db->size<uint64_t>(); ++i) { if (mask_db->Get<uint8_t>(i)) { @@ -200,21 +200,21 @@ tagged_memory_->Load(address_db, mask_db, el_size, db, inst, context); } -void TaggedMemoryUseProfiler::Load(uint64_t address, DataBuffer *db, - DataBuffer *tags, Instruction *inst, - ReferenceCount *context) { +void TaggedMemoryUseProfiler::Load(uint64_t address, DataBuffer* db, + DataBuffer* tags, Instruction* inst, + ReferenceCount* context) { if ((db != nullptr) && is_enabled_) tracker_.MarkUsed(address, db->size<uint8_t>()); if (tagged_memory_) tagged_memory_->Load(address, db, tags, inst, context); } -void TaggedMemoryUseProfiler::Store(uint64_t address, DataBuffer *db) { +void TaggedMemoryUseProfiler::Store(uint64_t address, DataBuffer* db) { if (is_enabled_) tracker_.MarkUsed(address, db->size<uint8_t>()); if (tagged_memory_) tagged_memory_->Store(address, db); } -void TaggedMemoryUseProfiler::Store(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db) { +void TaggedMemoryUseProfiler::Store(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db) { if (is_enabled_) { for (int i = 0; i < address_db->size<uint64_t>(); ++i) { if (mask_db->Get<uint8_t>(i)) { @@ -225,8 +225,8 @@ if (tagged_memory_) tagged_memory_->Store(address_db, mask_db, el_size, db); } -void TaggedMemoryUseProfiler::Store(uint64_t address, DataBuffer *db, - DataBuffer *tags) { +void TaggedMemoryUseProfiler::Store(uint64_t address, DataBuffer* db, + DataBuffer* tags) { if ((db != nullptr) && is_enabled_) tracker_.MarkUsed(address, db->size<uint8_t>()); if (tagged_memory_) tagged_memory_->Store(address, db, tags);
diff --git a/mpact/sim/util/memory/memory_use_profiler.h b/mpact/sim/util/memory/memory_use_profiler.h index b5785f6..bd24ae1 100644 --- a/mpact/sim/util/memory/memory_use_profiler.h +++ b/mpact/sim/util/memory/memory_use_profiler.h
@@ -54,13 +54,13 @@ // Size of each 'use' bit store. static constexpr int kBitsSize = kSegmentSize / (kGranularity * 8); void MarkUsed(uint64_t address, int size); - void WriteUseProfile(std::ostream &os) const; + void WriteUseProfile(std::ostream& os) const; private: uint64_t last_start_ = 0; uint64_t last_end_ = 0; - uint8_t *last_used_ = nullptr; - absl::btree_map<MemoryWatcher::AddressRange, uint8_t *, + uint8_t* last_used_ = nullptr; + absl::btree_map<MemoryWatcher::AddressRange, uint8_t*, MemoryWatcher::AddressRangeLess> memory_use_map_; }; @@ -72,20 +72,20 @@ public: // The default constructor does not set up memory forwarding. MemoryUseProfiler(); - explicit MemoryUseProfiler(MemoryInterface *memory); + explicit MemoryUseProfiler(MemoryInterface* memory); ~MemoryUseProfiler() override = default; // Inherited from memory interfaces. - void Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; - void Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; - void Store(uint64_t address, DataBuffer *db) override; - void Store(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db) override; + void Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; + void Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; + void Store(uint64_t address, DataBuffer* db) override; + void Store(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db) override; - void WriteProfile(std::ostream &os) const { tracker_.WriteUseProfile(os); } + void WriteProfile(std::ostream& os) const { tracker_.WriteUseProfile(os); } // Accessor. void set_is_enabled(bool is_enabled) { is_enabled_ = is_enabled; } @@ -93,7 +93,7 @@ private: bool is_enabled_ = false; - MemoryInterface *memory_; + MemoryInterface* memory_; internal::MemoryUseTracker tracker_; }; @@ -102,30 +102,30 @@ public: // The default constructor does not set up memory forwarding. TaggedMemoryUseProfiler(); - explicit TaggedMemoryUseProfiler(TaggedMemoryInterface *tagged_memory); + explicit TaggedMemoryUseProfiler(TaggedMemoryInterface* tagged_memory); ~TaggedMemoryUseProfiler() override = default; // Inherited from memory interfaces. - void Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; - void Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; - void Load(uint64_t address, DataBuffer *db, DataBuffer *tags, - Instruction *inst, ReferenceCount *context) override; - void Store(uint64_t address, DataBuffer *db) override; - void Store(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db) override; - void Store(uint64_t address, DataBuffer *db, DataBuffer *tags) override; + void Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; + void Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; + void Load(uint64_t address, DataBuffer* db, DataBuffer* tags, + Instruction* inst, ReferenceCount* context) override; + void Store(uint64_t address, DataBuffer* db) override; + void Store(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db) override; + void Store(uint64_t address, DataBuffer* db, DataBuffer* tags) override; - void WriteProfile(std::ostream &os) const { tracker_.WriteUseProfile(os); } + void WriteProfile(std::ostream& os) const { tracker_.WriteUseProfile(os); } // Accessor. void set_is_enabled(bool is_enabled) { is_enabled_ = is_enabled; } private: bool is_enabled_ = false; - TaggedMemoryInterface *tagged_memory_; + TaggedMemoryInterface* tagged_memory_; internal::MemoryUseTracker tracker_; };
diff --git a/mpact/sim/util/memory/memory_watcher.cc b/mpact/sim/util/memory/memory_watcher.cc index 5da7f72..34b7fe5 100644 --- a/mpact/sim/util/memory/memory_watcher.cc +++ b/mpact/sim/util/memory/memory_watcher.cc
@@ -19,18 +19,19 @@ #include "absl/status/status.h" #include "absl/strings/str_cat.h" +#include "mpact/sim/util/memory/memory_interface.h" namespace mpact { namespace sim { namespace util { -MemoryWatcher::MemoryWatcher(MemoryInterface *memory) : memory_(memory) {} +MemoryWatcher::MemoryWatcher(MemoryInterface* memory) : memory_(memory) {} // Methods to insert store and load watch callbacks. The methods check that // the address range is well formed (start <= end), and that there is no // overlapping range in the btree map. -absl::Status MemoryWatcher::SetStoreWatchCallback(const AddressRange &range, +absl::Status MemoryWatcher::SetStoreWatchCallback(const AddressRange& range, Callback callback) { if (range.start > range.end) { return absl::InternalError(absl::StrCat("Illegal store watch range: start ", @@ -57,7 +58,7 @@ return absl::OkStatus(); } -absl::Status MemoryWatcher::SetLoadWatchCallback(const AddressRange &range, +absl::Status MemoryWatcher::SetLoadWatchCallback(const AddressRange& range, Callback callback) { if (range.start > range.end) { return absl::InternalError(absl::StrCat("Illegal store watch range: start ", @@ -89,8 +90,8 @@ // is called before/after the load/store is forwarded to the interface. // Single address. -void MemoryWatcher::Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void MemoryWatcher::Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) { if (!ld_watch_actions_.empty()) { auto [first_match, last] = ld_watch_actions_.equal_range( AddressRange(address, address + db->size<uint8_t>() - 1)); @@ -103,9 +104,9 @@ } // Gather load (multiple addresses and a mask vector). -void MemoryWatcher::Load(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void MemoryWatcher::Load(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db, Instruction* inst, + ReferenceCount* context) { if (!ld_watch_actions_.empty()) { int num_entries = mask_db->size<bool>(); auto addresses = address_db->Get<uint64_t>(); @@ -126,7 +127,7 @@ } // Single address store. -void MemoryWatcher::Store(uint64_t address, DataBuffer *db) { +void MemoryWatcher::Store(uint64_t address, DataBuffer* db) { memory_->Store(address, db); if (!st_watch_actions_.empty()) { auto [first_match, last] = st_watch_actions_.equal_range( @@ -139,8 +140,8 @@ } // Scatter store (multiple addresses and a mask vector). -void MemoryWatcher::Store(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db) { +void MemoryWatcher::Store(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db) { memory_->Store(address_db, mask_db, el_size, db); if (!st_watch_actions_.empty()) { int num_entries = mask_db->size<bool>();
diff --git a/mpact/sim/util/memory/memory_watcher.h b/mpact/sim/util/memory/memory_watcher.h index d9acfa7..b332ad1 100644 --- a/mpact/sim/util/memory/memory_watcher.h +++ b/mpact/sim/util/memory/memory_watcher.h
@@ -51,8 +51,8 @@ // if they do (a) not overlap and (b) the addresses of the first are less than // the other. struct AddressRangeLess { - constexpr bool operator()(const AddressRange &lhs, - const AddressRange &rhs) const { + constexpr bool operator()(const AddressRange& lhs, + const AddressRange& rhs) const { return lhs.end < rhs.start; } }; @@ -63,10 +63,10 @@ using Callback = absl::AnyInvocable<void(uint64_t, int)>; // Constructor - default constructor is disabled. Use default destructor. - explicit MemoryWatcher(MemoryInterface *memory); + explicit MemoryWatcher(MemoryInterface* memory); MemoryWatcher() = delete; - MemoryWatcher(const MemoryWatcher &) = delete; // no copy constructor. - MemoryWatcher &operator=(const MemoryWatcher &) = delete; // no assignment. + MemoryWatcher(const MemoryWatcher&) = delete; // no copy constructor. + MemoryWatcher& operator=(const MemoryWatcher&) = delete; // no assignment. ~MemoryWatcher() override = default; // Methods to set/clear watch ranges. No new store (load) range can overlap an @@ -74,26 +74,26 @@ // Since there cannot be any overlapping ranges, it is only necessary to // specify a single address for the clear call, as it will map to the range // that contains it. - absl::Status SetStoreWatchCallback(const AddressRange &range, + absl::Status SetStoreWatchCallback(const AddressRange& range, Callback callback); absl::Status ClearStoreWatchCallback(uint64_t address); - absl::Status SetLoadWatchCallback(const AddressRange &range, + absl::Status SetLoadWatchCallback(const AddressRange& range, Callback callback); absl::Status ClearLoadWatchCallback(uint64_t address); // The memory interface methods. - void Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; - void Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; - void Store(uint64_t address, DataBuffer *db) override; - void Store(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db) override; + void Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; + void Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; + void Store(uint64_t address, DataBuffer* db) override; + void Store(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db) override; private: // The memory interface to forward the loads/stores to. - MemoryInterface *memory_; + MemoryInterface* memory_; absl::btree_multimap<AddressRange, Callback, AddressRangeLess> ld_watch_actions_; absl::btree_multimap<AddressRange, Callback, AddressRangeLess>
diff --git a/mpact/sim/util/memory/single_initiator_router.cc b/mpact/sim/util/memory/single_initiator_router.cc index b4d1094..d07b461 100644 --- a/mpact/sim/util/memory/single_initiator_router.cc +++ b/mpact/sim/util/memory/single_initiator_router.cc
@@ -40,7 +40,7 @@ // memory interface, base address, and address space size. template <typename Interface> static absl::Status AddTargetPrivate( - SingleInitiatorRouter::InterfaceMap<Interface> &map, Interface *interface, + SingleInitiatorRouter::InterfaceMap<Interface>& map, Interface* interface, uint64_t base, uint64_t top) { // Make sure the range is valid and makes sense. if (base > top) { @@ -69,20 +69,20 @@ // Template specializations of the AddTarget method. template <> absl::Status SingleInitiatorRouter::AddTarget<MemoryInterface>( - MemoryInterface *memory, uint64_t base, uint64_t top) { + MemoryInterface* memory, uint64_t base, uint64_t top) { return AddTargetPrivate<MemoryInterface>(memory_targets_, memory, base, top); } template <> absl::Status SingleInitiatorRouter::AddTarget<TaggedMemoryInterface>( - TaggedMemoryInterface *tagged_memory, uint64_t base, uint64_t top) { + TaggedMemoryInterface* tagged_memory, uint64_t base, uint64_t top) { return AddTargetPrivate<TaggedMemoryInterface>(tagged_targets_, tagged_memory, base, top); } template <> absl::Status SingleInitiatorRouter::AddTarget<AtomicMemoryOpInterface>( - AtomicMemoryOpInterface *atomic_memory, uint64_t base, uint64_t top) { + AtomicMemoryOpInterface* atomic_memory, uint64_t base, uint64_t top) { return AddTargetPrivate<AtomicMemoryOpInterface>(atomic_targets_, atomic_memory, base, top); } @@ -90,7 +90,7 @@ // Template specializations of the AddDefaultTarget method. template <> absl::Status SingleInitiatorRouter::AddDefaultTarget<MemoryInterface>( - MemoryInterface *memory) { + MemoryInterface* memory) { if ((memory != nullptr) && (default_memory_target_ != nullptr)) { return absl::AlreadyExistsError("Default memory target already exists"); } @@ -100,7 +100,7 @@ template <> absl::Status SingleInitiatorRouter::AddDefaultTarget<TaggedMemoryInterface>( - TaggedMemoryInterface *tagged_memory) { + TaggedMemoryInterface* tagged_memory) { if ((tagged_memory != nullptr) && (default_tagged_target_ != nullptr)) { return absl::AlreadyExistsError( "Default tagged memory target already exists"); @@ -111,7 +111,7 @@ template <> absl::Status SingleInitiatorRouter::AddDefaultTarget<AtomicMemoryOpInterface>( - AtomicMemoryOpInterface *atomic_memory) { + AtomicMemoryOpInterface* atomic_memory) { if ((atomic_memory != nullptr) && (default_atomic_target_ != nullptr)) { return absl::AlreadyExistsError( "Default atomic memory target already exists"); @@ -125,12 +125,12 @@ // they log an error and return. // Plain memory load. -void SingleInitiatorRouter::Load(uint64_t address, DataBuffer *db, - Instruction *inst, ReferenceCount *context) { +void SingleInitiatorRouter::Load(uint64_t address, DataBuffer* db, + Instruction* inst, ReferenceCount* context) { int size = db->size<uint8_t>(); auto it = memory_targets_.find({address, address + size - 1}); if (it != memory_targets_.end()) { - auto &range = it->first; + auto& range = it->first; if ((range.base <= address) && (range.top >= address + size - 1)) { return it->second->Load(address, db, inst, context); } @@ -144,7 +144,7 @@ // too. auto tagged_it = tagged_targets_.find({address, address}); if (tagged_it != tagged_targets_.end()) { - auto &range = tagged_it->first; + auto& range = tagged_it->first; if ((range.base <= address) && (range.top >= address + size - 1)) { return tagged_it->second->Load(address, db, inst, context); } @@ -159,25 +159,25 @@ } // Vector memory load. -void SingleInitiatorRouter::Load(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void SingleInitiatorRouter::Load(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db, Instruction* inst, + ReferenceCount* context) { // This is a vector load, so check each address that is not masked off. // Vector memory loads will not be split across multiple targets. int count = address_db->size<uint64_t>(); - MemoryInterface *memory = nullptr; + MemoryInterface* memory = nullptr; for (int i = 0; i < count; i++) { // If the mask is true, check this address. if (mask_db->Get<uint8_t>(i)) { auto address = address_db->Get<uint64_t>(i); auto it = memory_targets_.find({address, address + el_size - 1}); - MemoryInterface *tmp_memory = nullptr; + MemoryInterface* tmp_memory = nullptr; if (it == memory_targets_.end()) { // If there are no overlapping targets, use the default, if it is set. if (default_memory_target_ == nullptr) break; tmp_memory = default_memory_target_; } else { - auto &range = it->first; + auto& range = it->first; // If there is no proper overlap, just break out of the loop. We are // not splitting the memory access across multiple targets. if ((range.base > address) || (range.top < address + el_size - 1)) @@ -200,18 +200,18 @@ // Since the vector memory load can occur in both MemoryInterface and // TaggedMemoryInterface, we need to check the tagged memory interface map // too. - TaggedMemoryInterface *tagged_memory = nullptr; + TaggedMemoryInterface* tagged_memory = nullptr; for (int i = 0; i < count; i++) { if (mask_db->Get<uint8_t>(i)) { auto address = address_db->Get<uint64_t>(i); auto it = tagged_targets_.find({address, address + el_size - 1}); - TaggedMemoryInterface *tmp_memory = nullptr; + TaggedMemoryInterface* tmp_memory = nullptr; if (it == tagged_targets_.end()) { // If there are no overlapping targets, use the default, if it is set. if (default_tagged_target_ == nullptr) break; tmp_memory = default_tagged_target_; } else { - auto &range = it->first; + auto& range = it->first; // If there is no proper overlap, just break out of the loop. We are // not splitting the memory access across multiple targets. if ((range.base > address) || (range.top < address + el_size - 1)) @@ -235,9 +235,9 @@ } // Tagged memory load. -void SingleInitiatorRouter::Load(uint64_t address, DataBuffer *db, - DataBuffer *tags, Instruction *inst, - ReferenceCount *context) { +void SingleInitiatorRouter::Load(uint64_t address, DataBuffer* db, + DataBuffer* tags, Instruction* inst, + ReferenceCount* context) { int size; // If db is null, then this is a tag load. The size for routing purposes is // the size of tags * 8. @@ -248,7 +248,7 @@ } auto tagged_it = tagged_targets_.find({address, address + size - 1}); if (tagged_it != tagged_targets_.end()) { - auto &range = tagged_it->first; + auto& range = tagged_it->first; if ((range.base <= address) && (range.top >= address + size - 1)) { return tagged_it->second->Load(address, db, tags, inst, context); } @@ -263,11 +263,11 @@ } // Plain memory store. -void SingleInitiatorRouter::Store(uint64_t address, DataBuffer *db) { +void SingleInitiatorRouter::Store(uint64_t address, DataBuffer* db) { int size = db->size<uint8_t>(); auto it = memory_targets_.find({address, address + size}); if (it != memory_targets_.end()) { - auto &range = it->first; + auto& range = it->first; if ((range.base <= address) && (range.top >= address + size - 1)) { return it->second->Store(address, db); } @@ -281,7 +281,7 @@ // too. auto tagged_it = tagged_targets_.find({address, address}); if (tagged_it != tagged_targets_.end()) { - auto &range = tagged_it->first; + auto& range = tagged_it->first; if ((range.base <= address) && (range.top >= address + size - 1)) { return tagged_it->second->Store(address, db); } @@ -296,24 +296,24 @@ } // Vector memory store. -void SingleInitiatorRouter::Store(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db) { +void SingleInitiatorRouter::Store(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db) { // This is a vector store, so check each address that is not masked off. // Vector memory stores will not be split across multiple targets. int count = address_db->size<uint64_t>(); - MemoryInterface *memory = nullptr; + MemoryInterface* memory = nullptr; for (int i = 0; i < count; i++) { // If the mask is true, check this address. if (mask_db->Get<uint8_t>(i)) { auto address = address_db->Get<uint64_t>(i); auto it = memory_targets_.find({address, address + el_size - 1}); - MemoryInterface *tmp_memory = nullptr; + MemoryInterface* tmp_memory = nullptr; if (it == memory_targets_.end()) { // If there are no overlapping targets, use the default, if it is set. if (default_memory_target_ == nullptr) break; tmp_memory = default_memory_target_; } else { - auto &range = it->first; + auto& range = it->first; // If there is no proper overlap, just break out of the loop. We are // not splitting the memory access across multiple targets. if ((range.base > address) || (range.top < address + el_size - 1)) @@ -336,18 +336,18 @@ // Since the vector memory store can occur in both MemoryInterface and // TaggedMemoryInterface, we need to check the tagged memory interface map // too. - TaggedMemoryInterface *tagged_memory = nullptr; + TaggedMemoryInterface* tagged_memory = nullptr; for (int i = 0; i < count; i++) { if (mask_db->Get<uint8_t>(i)) { auto address = address_db->Get<uint64_t>(i); auto it = tagged_targets_.find({address, address + el_size}); - TaggedMemoryInterface *tmp_memory = nullptr; + TaggedMemoryInterface* tmp_memory = nullptr; if (it == tagged_targets_.end()) { // If there are no overlapping targets, use the default, if it is set. if (default_tagged_target_ == nullptr) break; tmp_memory = default_tagged_target_; } else { - auto &range = it->first; + auto& range = it->first; // If there is no proper overlap, just break out of the loop. We are // not splitting the memory access across multiple targets. if ((range.base > address) || (range.top < address + el_size)) break; @@ -370,12 +370,12 @@ } // Simple tagged memory store. -void SingleInitiatorRouter::Store(uint64_t address, DataBuffer *db, - DataBuffer *tags) { +void SingleInitiatorRouter::Store(uint64_t address, DataBuffer* db, + DataBuffer* tags) { int size = db->size<uint8_t>(); auto tagged_it = tagged_targets_.find({address, address + size - 1}); if (tagged_it != tagged_targets_.end()) { - auto &range = tagged_it->first; + auto& range = tagged_it->first; if ((range.base <= address) && (range.top >= address + size - 1)) { return tagged_it->second->Store(address, db, tags); } else { @@ -395,13 +395,13 @@ // Atomic memory operation. absl::Status SingleInitiatorRouter::PerformMemoryOp(uint64_t address, Operation op, - DataBuffer *db, - Instruction *inst, - ReferenceCount *context) { + DataBuffer* db, + Instruction* inst, + ReferenceCount* context) { int size = db->size<uint8_t>(); auto atomic_it = atomic_targets_.find({address, address + size - 1}); if (atomic_it != atomic_targets_.end()) { - auto &range = atomic_it->first; + auto& range = atomic_it->first; if ((range.base <= address) && (range.top >= address + size - 1)) { return atomic_it->second->PerformMemoryOp(address, op, db, inst, context); }
diff --git a/mpact/sim/util/memory/single_initiator_router.h b/mpact/sim/util/memory/single_initiator_router.h index 39a7d77..27e5785 100644 --- a/mpact/sim/util/memory/single_initiator_router.h +++ b/mpact/sim/util/memory/single_initiator_router.h
@@ -50,57 +50,57 @@ }; // Comparator for address ranges. struct AddressRangeLess { - bool operator()(const AddressRange &lhs, const AddressRange &rhs) const { + bool operator()(const AddressRange& lhs, const AddressRange& rhs) const { return (lhs.top < rhs.base); } }; // Map type convenience template. template <typename Interface> using InterfaceMap = - absl::btree_map<SingleInitiatorRouter::AddressRange, Interface *, + absl::btree_map<SingleInitiatorRouter::AddressRange, Interface*, SingleInitiatorRouter::AddressRangeLess>; // Constructor and destructor. explicit SingleInitiatorRouter(std::string name); - SingleInitiatorRouter(const SingleInitiatorRouter &) = delete; - SingleInitiatorRouter &operator=(const SingleInitiatorRouter &) = delete; + SingleInitiatorRouter(const SingleInitiatorRouter&) = delete; + SingleInitiatorRouter& operator=(const SingleInitiatorRouter&) = delete; ~SingleInitiatorRouter(); // Add 'memory' target interface with given range. Only three interface types // are supported: MemoryInterface, TaggedMemoryInterface, and // AtomicMemoryOpInterface. template <typename Interface> - absl::Status AddTarget(Interface *memory, uint64_t base, uint64_t top); + absl::Status AddTarget(Interface* memory, uint64_t base, uint64_t top); // Add 'memory' target interface as default target, that is, if no other // interface matches, it is the fallback interface. Only three interface types // are supported: MemoryInterface, TaggedMemoryInterface, and // AtomicMemoryOpInterface. template <typename Interface> - absl::Status AddDefaultTarget(Interface *memory); + absl::Status AddDefaultTarget(Interface* memory); // Memory interface methods. // Plain load. - void Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; + void Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; // Vector load. - void Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; + void Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; // Tagged load. - void Load(uint64_t address, DataBuffer *db, DataBuffer *tags, - Instruction *inst, ReferenceCount *context) override; + void Load(uint64_t address, DataBuffer* db, DataBuffer* tags, + Instruction* inst, ReferenceCount* context) override; // Plain store. - void Store(uint64_t address, DataBuffer *db) override; + void Store(uint64_t address, DataBuffer* db) override; // Vector store. - void Store(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db) override; + void Store(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db) override; // Tagged store. - void Store(uint64_t address, DataBuffer *db, DataBuffer *tags) override; + void Store(uint64_t address, DataBuffer* db, DataBuffer* tags) override; // Atomic memory operation. - absl::Status PerformMemoryOp(uint64_t address, Operation op, DataBuffer *db, - Instruction *inst, - ReferenceCount *context) override; + absl::Status PerformMemoryOp(uint64_t address, Operation op, DataBuffer* db, + Instruction* inst, + ReferenceCount* context) override; // Accessors. std::string_view name() const { return name_; } @@ -109,11 +109,11 @@ std::string name_; // These maps are used to look up target interfaces based on addresses. InterfaceMap<MemoryInterface> memory_targets_; - MemoryInterface *default_memory_target_ = nullptr; + MemoryInterface* default_memory_target_ = nullptr; InterfaceMap<TaggedMemoryInterface> tagged_targets_; - TaggedMemoryInterface *default_tagged_target_ = nullptr; + TaggedMemoryInterface* default_tagged_target_ = nullptr; InterfaceMap<AtomicMemoryOpInterface> atomic_targets_; - AtomicMemoryOpInterface *default_atomic_target_ = nullptr; + AtomicMemoryOpInterface* default_atomic_target_ = nullptr; }; } // namespace util
diff --git a/mpact/sim/util/memory/tagged_flat_demand_memory.cc b/mpact/sim/util/memory/tagged_flat_demand_memory.cc index 73b8593..2537544 100644 --- a/mpact/sim/util/memory/tagged_flat_demand_memory.cc +++ b/mpact/sim/util/memory/tagged_flat_demand_memory.cc
@@ -60,9 +60,9 @@ db_factory_ = nullptr; } -void TaggedFlatDemandMemory::Load(uint64_t address, DataBuffer *db, - DataBuffer *tags, Instruction *inst, - ReferenceCount *context) { +void TaggedFlatDemandMemory::Load(uint64_t address, DataBuffer* db, + DataBuffer* tags, Instruction* inst, + ReferenceCount* context) { if (!CheckRequest(address, db, tags)) return; // Load data with no latency. If db is null, then skip the load, but load the @@ -75,8 +75,8 @@ FinishLoad(latency, inst, context); } -void TaggedFlatDemandMemory::Store(uint64_t address, DataBuffer *db, - DataBuffer *tags) { +void TaggedFlatDemandMemory::Store(uint64_t address, DataBuffer* db, + DataBuffer* tags) { if (!CheckRequest(address, db, tags)) return; // Store data and tags. data_memory_->Store(address, db); @@ -84,28 +84,28 @@ } // Untagged load is passed directly to the data memory. -void TaggedFlatDemandMemory::Load(uint64_t address, DataBuffer *db, - Instruction *inst, ReferenceCount *context) { +void TaggedFlatDemandMemory::Load(uint64_t address, DataBuffer* db, + Instruction* inst, ReferenceCount* context) { data_memory_->Load(address, db, inst, context); } // Untagged vector load is passed directly to the data memory. -void TaggedFlatDemandMemory::Load(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db, - Instruction *inst, ReferenceCount *context) { +void TaggedFlatDemandMemory::Load(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db, + Instruction* inst, ReferenceCount* context) { data_memory_->Load(address_db, mask_db, el_size, db, inst, context); } // Untagged store. -void TaggedFlatDemandMemory::Store(uint64_t address, DataBuffer *db) { +void TaggedFlatDemandMemory::Store(uint64_t address, DataBuffer* db) { data_memory_->Store(address, db); // Clear any affected tags. ClearTags(address, db->size<uint8_t>()); } // Untagged vector store. -void TaggedFlatDemandMemory::Store(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db) { +void TaggedFlatDemandMemory::Store(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db) { unsigned num_stores = address_db->size<uint64_t>(); if (num_stores == 0) return; unsigned store_size = db->size<uint8_t>() / num_stores; @@ -123,8 +123,8 @@ } bool TaggedFlatDemandMemory::CheckRequest(uint64_t address, - const DataBuffer *db, - const DataBuffer *tags) { + const DataBuffer* db, + const DataBuffer* tags) { uint64_t mask = (1ULL << tag_granule_shift_) - 1; if (address & mask) { LOG(ERROR) << absl::StrCat( @@ -150,8 +150,8 @@ return true; } -void TaggedFlatDemandMemory::FinishLoad(int latency, Instruction *inst, - ReferenceCount *context) { +void TaggedFlatDemandMemory::FinishLoad(int latency, Instruction* inst, + ReferenceCount* context) { if (inst == nullptr) return; // If the latency is 0, execute the instruction immediately. if (latency == 0) { @@ -176,7 +176,7 @@ uint64_t lo = address >> tag_granule_shift_; uint64_t hi = (address + size - 1) >> tag_granule_shift_; int num_tags = hi - lo + 1; - auto *tag_db = db_factory_->Allocate(num_tags); + auto* tag_db = db_factory_->Allocate(num_tags); std::memset(tag_db->raw_ptr(), 0, num_tags); tag_memory_->Store(lo, tag_db); tag_db->DecRef();
diff --git a/mpact/sim/util/memory/tagged_flat_demand_memory.h b/mpact/sim/util/memory/tagged_flat_demand_memory.h index 58e4234..1c7bbf1 100644 --- a/mpact/sim/util/memory/tagged_flat_demand_memory.h +++ b/mpact/sim/util/memory/tagged_flat_demand_memory.h
@@ -72,8 +72,8 @@ ~TaggedFlatDemandMemory() override; // Disabled constructors and operator. TaggedFlatDemandMemory() = delete; - TaggedFlatDemandMemory(const TaggedFlatDemandMemory &) = delete; - TaggedFlatDemandMemory &operator=(const TaggedFlatDemandMemory &) = delete; + TaggedFlatDemandMemory(const TaggedFlatDemandMemory&) = delete; + TaggedFlatDemandMemory& operator=(const TaggedFlatDemandMemory&) = delete; // Methods inherited directly from TaggedMemoryInterface. // Single address load. Loads the data into data buffer 'db', and accompanying @@ -81,54 +81,54 @@ // the size and the address have to be aligned to the tag granule for the // memory. Upon completion, and timed according to the latency of 'db', if // non-null, 'inst' is executed with context 'context'. - void Load(uint64_t address, generic::DataBuffer *db, - generic::DataBuffer *tags, generic::Instruction *inst, - generic::ReferenceCount *context) override; - void Store(uint64_t address, generic::DataBuffer *db, - generic::DataBuffer *tags) override; + void Load(uint64_t address, generic::DataBuffer* db, + generic::DataBuffer* tags, generic::Instruction* inst, + generic::ReferenceCount* context) override; + void Store(uint64_t address, generic::DataBuffer* db, + generic::DataBuffer* tags) override; // Methods inherited from MemoryInterface. These methods do not handle tags. // Loads are identical to FlatDemandMemory loads. - void Load(uint64_t address, generic::DataBuffer *db, - generic::Instruction *inst, - generic::ReferenceCount *context) override; - void Load(generic::DataBuffer *address_db, generic::DataBuffer *mask_db, - int el_size, generic::DataBuffer *db, Instruction *inst, - generic::ReferenceCount *context) override; + void Load(uint64_t address, generic::DataBuffer* db, + generic::Instruction* inst, + generic::ReferenceCount* context) override; + void Load(generic::DataBuffer* address_db, generic::DataBuffer* mask_db, + int el_size, generic::DataBuffer* db, Instruction* inst, + generic::ReferenceCount* context) override; // Convenience template function that calls the above function with the // element size as the sizeof() the template parameter type. template <typename T> - void Load(DataBuffer *address_db, DataBuffer *mask_db, DataBuffer *db, - Instruction *inst, ReferenceCount *context) { + void Load(DataBuffer* address_db, DataBuffer* mask_db, DataBuffer* db, + Instruction* inst, ReferenceCount* context) { Load(address_db, mask_db, sizeof(T), db, inst, context); } // Store methods inherited from MemoryInterface. These methods do not handle // tags. Instead, tags are cleared for any part of memory that is written to. - void Store(uint64_t address, DataBuffer *db) override; - void Store(generic::DataBuffer *address_db, generic::DataBuffer *mask_db, - int el_size, generic::DataBuffer *db) override; + void Store(uint64_t address, DataBuffer* db) override; + void Store(generic::DataBuffer* address_db, generic::DataBuffer* mask_db, + int el_size, generic::DataBuffer* db) override; // Convenience template function that calls the above function with the // element size as the sizeof() the template parameter type. template <typename T> - void Store(DataBuffer *address_db, DataBuffer *mask_db, DataBuffer *db) { + void Store(DataBuffer* address_db, DataBuffer* mask_db, DataBuffer* db) { Store(address_db, mask_db, sizeof(T), db); } private: // Check that the tagged load or store is properly aligned to the tag // granule, and that the number of tags provided is correct. - bool CheckRequest(uint64_t address, const generic::DataBuffer *db, - const generic::DataBuffer *tags); + bool CheckRequest(uint64_t address, const generic::DataBuffer* db, + const generic::DataBuffer* tags); // Complete the load - void FinishLoad(int latency, generic::Instruction *inst, - generic::ReferenceCount *context); + void FinishLoad(int latency, generic::Instruction* inst, + generic::ReferenceCount* context); // Clear the tags for the specified range of memory. void ClearTags(uint64_t address, unsigned size); unsigned tag_granule_; unsigned tag_granule_shift_; - FlatDemandMemory *data_memory_ = nullptr; - FlatDemandMemory *tag_memory_ = nullptr; - generic::DataBufferFactory *db_factory_ = nullptr; + FlatDemandMemory* data_memory_ = nullptr; + FlatDemandMemory* tag_memory_ = nullptr; + generic::DataBufferFactory* db_factory_ = nullptr; }; } // namespace util
diff --git a/mpact/sim/util/memory/tagged_memory_interface.h b/mpact/sim/util/memory/tagged_memory_interface.h index 43a6f36..8eac44b 100644 --- a/mpact/sim/util/memory/tagged_memory_interface.h +++ b/mpact/sim/util/memory/tagged_memory_interface.h
@@ -38,9 +38,9 @@ using MemoryInterface::Store; virtual ~TaggedMemoryInterface() = default; // For now, only support non-vector loads and stores with tags. - virtual void Load(uint64_t address, DataBuffer *db, DataBuffer *tags, - Instruction *inst, ReferenceCount *context) = 0; - virtual void Store(uint64_t address, DataBuffer *db, DataBuffer *tags) = 0; + virtual void Load(uint64_t address, DataBuffer* db, DataBuffer* tags, + Instruction* inst, ReferenceCount* context) = 0; + virtual void Store(uint64_t address, DataBuffer* db, DataBuffer* tags) = 0; }; } // namespace util
diff --git a/mpact/sim/util/memory/tagged_memory_watcher.cc b/mpact/sim/util/memory/tagged_memory_watcher.cc index ecc5966..2e72efd 100644 --- a/mpact/sim/util/memory/tagged_memory_watcher.cc +++ b/mpact/sim/util/memory/tagged_memory_watcher.cc
@@ -25,7 +25,7 @@ namespace sim { namespace util { -TaggedMemoryWatcher::TaggedMemoryWatcher(TaggedMemoryInterface *memory) +TaggedMemoryWatcher::TaggedMemoryWatcher(TaggedMemoryInterface* memory) : memory_(memory) {} // Methods to insert store and load watch callbacks. The methods check that @@ -33,7 +33,7 @@ // overlapping range in the btree map. absl::Status TaggedMemoryWatcher::SetStoreWatchCallback( - const AddressRange &range, Callback callback) { + const AddressRange& range, Callback callback) { if (range.start > range.end) { return absl::InternalError(absl::StrCat("Illegal store watch range: start ", absl::Hex(range.start), " > end ", @@ -60,7 +60,7 @@ } absl::Status TaggedMemoryWatcher::SetLoadWatchCallback( - const AddressRange &range, Callback callback) { + const AddressRange& range, Callback callback) { if (range.start > range.end) { return absl::InternalError(absl::StrCat("Illegal store watch range: start ", absl::Hex(range.start), " > end ", @@ -91,8 +91,8 @@ // is called before/after the load/store is forwarded to the interface. // Single address. -void TaggedMemoryWatcher::Load(uint64_t address, DataBuffer *db, - Instruction *inst, ReferenceCount *context) { +void TaggedMemoryWatcher::Load(uint64_t address, DataBuffer* db, + Instruction* inst, ReferenceCount* context) { if (!ld_watch_actions_.empty()) { auto [first_match, last] = ld_watch_actions_.equal_range( AddressRange(address, address + db->size<uint8_t>() - 1)); @@ -105,9 +105,9 @@ } // Gather load (multiple addresses and a mask vector). -void TaggedMemoryWatcher::Load(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void TaggedMemoryWatcher::Load(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db, Instruction* inst, + ReferenceCount* context) { if (!ld_watch_actions_.empty()) { int num_entries = mask_db->size<bool>(); auto addresses = address_db->Get<uint64_t>(); @@ -128,9 +128,9 @@ } // Tagged memory load. -void TaggedMemoryWatcher::Load(uint64_t address, DataBuffer *db, - DataBuffer *tags, Instruction *inst, - ReferenceCount *context) { +void TaggedMemoryWatcher::Load(uint64_t address, DataBuffer* db, + DataBuffer* tags, Instruction* inst, + ReferenceCount* context) { if (db != nullptr && !ld_watch_actions_.empty()) { auto [first_match, last] = ld_watch_actions_.equal_range( AddressRange(address, address + db->size<uint8_t>() - 1)); @@ -143,7 +143,7 @@ } // Single address store. -void TaggedMemoryWatcher::Store(uint64_t address, DataBuffer *db) { +void TaggedMemoryWatcher::Store(uint64_t address, DataBuffer* db) { memory_->Store(address, db); if (!st_watch_actions_.empty()) { auto [first_match, last] = st_watch_actions_.equal_range( @@ -156,8 +156,8 @@ } // Scatter store (multiple addresses and a mask vector). -void TaggedMemoryWatcher::Store(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db) { +void TaggedMemoryWatcher::Store(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db) { memory_->Store(address_db, mask_db, el_size, db); if (!st_watch_actions_.empty()) { int num_entries = mask_db->size<bool>(); @@ -178,8 +178,8 @@ } // Tagged memory store. -void TaggedMemoryWatcher::Store(uint64_t address, DataBuffer *db, - DataBuffer *tags) { +void TaggedMemoryWatcher::Store(uint64_t address, DataBuffer* db, + DataBuffer* tags) { memory_->Store(address, db, tags); if (!st_watch_actions_.empty()) { auto [first_match, last] = st_watch_actions_.equal_range(
diff --git a/mpact/sim/util/memory/tagged_memory_watcher.h b/mpact/sim/util/memory/tagged_memory_watcher.h index a4f4174..5045b09 100644 --- a/mpact/sim/util/memory/tagged_memory_watcher.h +++ b/mpact/sim/util/memory/tagged_memory_watcher.h
@@ -54,11 +54,11 @@ using Callback = absl::AnyInvocable<void(uint64_t, int)>; // Constructor - default constructor is disabled. Use default destructor. - explicit TaggedMemoryWatcher(TaggedMemoryInterface *memory); + explicit TaggedMemoryWatcher(TaggedMemoryInterface* memory); TaggedMemoryWatcher() = delete; - TaggedMemoryWatcher(const TaggedMemoryWatcher &) = + TaggedMemoryWatcher(const TaggedMemoryWatcher&) = delete; // no copy constructor. - TaggedMemoryWatcher &operator=(const TaggedMemoryWatcher &) = + TaggedMemoryWatcher& operator=(const TaggedMemoryWatcher&) = delete; // no assignment. ~TaggedMemoryWatcher() override = default; @@ -67,38 +67,38 @@ // Since there cannot be any overlapping ranges, it is only necessary to // specify a single address for the clear call, as it will map to the range // that contains it. - absl::Status SetStoreWatchCallback(const AddressRange &range, + absl::Status SetStoreWatchCallback(const AddressRange& range, Callback callback); absl::Status ClearStoreWatchCallback(uint64_t address); - absl::Status SetLoadWatchCallback(const AddressRange &range, + absl::Status SetLoadWatchCallback(const AddressRange& range, Callback callback); absl::Status ClearLoadWatchCallback(uint64_t address); // The memory interface methods. - void Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; - void Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; - void Store(uint64_t address, DataBuffer *db) override; - void Store(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db) override; - void Load(uint64_t address, DataBuffer *db, DataBuffer *tags, - Instruction *inst, ReferenceCount *context) override; - void Store(uint64_t address, DataBuffer *db, DataBuffer *tags) override; + void Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; + void Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; + void Store(uint64_t address, DataBuffer* db) override; + void Store(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db) override; + void Load(uint64_t address, DataBuffer* db, DataBuffer* tags, + Instruction* inst, ReferenceCount* context) override; + void Store(uint64_t address, DataBuffer* db, DataBuffer* tags) override; private: // Comparator used to compare two address ranges. A range is less than another // if they do (a) not overlap and (b) the addresses of the first are less than // the other. struct AddressRangeLess { - constexpr bool operator()(const AddressRange &lhs, - const AddressRange &rhs) const { + constexpr bool operator()(const AddressRange& lhs, + const AddressRange& rhs) const { return lhs.end < rhs.start; } }; // The memory interface to forward the loads/stores to. - TaggedMemoryInterface *memory_; + TaggedMemoryInterface* memory_; absl::btree_multimap<AddressRange, Callback, AddressRangeLess> ld_watch_actions_; absl::btree_multimap<AddressRange, Callback, AddressRangeLess>
diff --git a/mpact/sim/util/memory/tagged_to_untagged_memory_transactor.cc b/mpact/sim/util/memory/tagged_to_untagged_memory_transactor.cc index d732706..ed08831 100644 --- a/mpact/sim/util/memory/tagged_to_untagged_memory_transactor.cc +++ b/mpact/sim/util/memory/tagged_to_untagged_memory_transactor.cc
@@ -33,41 +33,41 @@ using ::mpact::sim::generic::ReferenceCount; // These methods simply forward the call to the target mem interface. -void TaggedToUntaggedMemoryTransactor::Load(uint64_t address, DataBuffer *db, - Instruction *inst, - ReferenceCount *context) { +void TaggedToUntaggedMemoryTransactor::Load(uint64_t address, DataBuffer* db, + Instruction* inst, + ReferenceCount* context) { target_mem_->Load(address, db, inst, context); } -void TaggedToUntaggedMemoryTransactor::Load(DataBuffer *address_db, - DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void TaggedToUntaggedMemoryTransactor::Load(DataBuffer* address_db, + DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) { target_mem_->Load(address_db, mask_db, el_size, db, inst, context); } -void TaggedToUntaggedMemoryTransactor::Store(uint64_t address, DataBuffer *db) { +void TaggedToUntaggedMemoryTransactor::Store(uint64_t address, DataBuffer* db) { target_mem_->Store(address, db); } -void TaggedToUntaggedMemoryTransactor::Store(DataBuffer *address, - DataBuffer *mask, int el_size, - DataBuffer *db) { +void TaggedToUntaggedMemoryTransactor::Store(DataBuffer* address, + DataBuffer* mask, int el_size, + DataBuffer* db) { target_mem_->Store(address, mask, el_size, db); } // For tagged loads, zero the tags, and then forward to the target mem // interface. -void TaggedToUntaggedMemoryTransactor::Load(uint64_t address, DataBuffer *db, - DataBuffer *tags, Instruction *inst, - ReferenceCount *context) { +void TaggedToUntaggedMemoryTransactor::Load(uint64_t address, DataBuffer* db, + DataBuffer* tags, Instruction* inst, + ReferenceCount* context) { std::memset(tags->raw_ptr(), 0, tags->size<uint8_t>()); if (db == nullptr) return; target_mem_->Load(address, db, inst, context); } // For tagged stores, ignore the tags. just forward to the target mem interface. -void TaggedToUntaggedMemoryTransactor::Store(uint64_t address, DataBuffer *db, - DataBuffer *tags) { +void TaggedToUntaggedMemoryTransactor::Store(uint64_t address, DataBuffer* db, + DataBuffer* tags) { if (tags != nullptr) { for (auto tag : tags->Get<uint8_t>()) { if (tag != 0)
diff --git a/mpact/sim/util/memory/tagged_to_untagged_memory_transactor.h b/mpact/sim/util/memory/tagged_to_untagged_memory_transactor.h index 45586ee..e9d439c 100644 --- a/mpact/sim/util/memory/tagged_to_untagged_memory_transactor.h +++ b/mpact/sim/util/memory/tagged_to_untagged_memory_transactor.h
@@ -39,23 +39,23 @@ // on loads. class TaggedToUntaggedMemoryTransactor : public util::TaggedMemoryInterface { public: - explicit TaggedToUntaggedMemoryTransactor(MemoryInterface *target_mem) + explicit TaggedToUntaggedMemoryTransactor(MemoryInterface* target_mem) : target_mem_(target_mem) {} - void Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; - void Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; - void Store(uint64_t address, DataBuffer *db) override; - void Store(DataBuffer *address, DataBuffer *mask, int el_size, - DataBuffer *db) override; - void Load(uint64_t address, DataBuffer *db, DataBuffer *tags, - Instruction *inst, ReferenceCount *context) override; - void Store(uint64_t address, DataBuffer *db, DataBuffer *tags) override; + void Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; + void Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; + void Store(uint64_t address, DataBuffer* db) override; + void Store(DataBuffer* address, DataBuffer* mask, int el_size, + DataBuffer* db) override; + void Load(uint64_t address, DataBuffer* db, DataBuffer* tags, + Instruction* inst, ReferenceCount* context) override; + void Store(uint64_t address, DataBuffer* db, DataBuffer* tags) override; private: - MemoryInterface *target_mem_; + MemoryInterface* target_mem_; }; } // namespace util
diff --git a/mpact/sim/util/memory/test/BUILD b/mpact/sim/util/memory/test/BUILD index 4d88893..dd4ef95 100644 --- a/mpact/sim/util/memory/test/BUILD +++ b/mpact/sim/util/memory/test/BUILD
@@ -40,6 +40,7 @@ deps = [ "//mpact/sim/generic:arch_state", "//mpact/sim/generic:core", + "//mpact/sim/generic:instruction", "//mpact/sim/util/memory", "@com_google_absl//absl/strings", "@com_google_googletest//:gtest",
diff --git a/mpact/sim/util/memory/test/atomic_memory_test.cc b/mpact/sim/util/memory/test/atomic_memory_test.cc index d1b0fea..d9acefa 100644 --- a/mpact/sim/util/memory/test/atomic_memory_test.cc +++ b/mpact/sim/util/memory/test/atomic_memory_test.cc
@@ -14,7 +14,10 @@ #include "mpact/sim/util/memory/atomic_memory.h" -#include "googlemock/include/gmock/gmock.h" +#include <algorithm> +#include <cstdint> + +#include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep #include "googletest/include/gtest/gtest.h" #include "mpact/sim/generic/data_buffer.h" #include "mpact/sim/util/memory/flat_demand_memory.h" @@ -46,19 +49,19 @@ delete flat_memory_; } - AtomicMemory *memory_; - FlatDemandMemory *flat_memory_; + AtomicMemory* memory_; + FlatDemandMemory* flat_memory_; DataBufferFactory db_factory_; - DataBuffer *db_; + DataBuffer* db_; }; // Test that loads and stores are passed through to the FlatDemandMemory // for simple loads and stores. TEST_F(AtomicMemoryTest, PassThroughLoadsStores) { - DataBuffer *st_db1 = db_factory_.Allocate<uint8_t>(1); - DataBuffer *st_db2 = db_factory_.Allocate<uint16_t>(1); - DataBuffer *st_db4 = db_factory_.Allocate<uint32_t>(1); - DataBuffer *st_db8 = db_factory_.Allocate<uint64_t>(1); + DataBuffer* st_db1 = db_factory_.Allocate<uint8_t>(1); + DataBuffer* st_db2 = db_factory_.Allocate<uint16_t>(1); + DataBuffer* st_db4 = db_factory_.Allocate<uint32_t>(1); + DataBuffer* st_db8 = db_factory_.Allocate<uint64_t>(1); st_db1->Set<uint8_t>(0, 0x0F); st_db2->Set<uint16_t>(0, 0xA5A5); @@ -70,10 +73,10 @@ memory_->Store(0x1004, st_db4); memory_->Store(0x1008, st_db8); - DataBuffer *ld_db1 = db_factory_.Allocate<uint8_t>(1); - DataBuffer *ld_db2 = db_factory_.Allocate<uint16_t>(1); - DataBuffer *ld_db4 = db_factory_.Allocate<uint32_t>(1); - DataBuffer *ld_db8 = db_factory_.Allocate<uint64_t>(1); + DataBuffer* ld_db1 = db_factory_.Allocate<uint8_t>(1); + DataBuffer* ld_db2 = db_factory_.Allocate<uint16_t>(1); + DataBuffer* ld_db4 = db_factory_.Allocate<uint32_t>(1); + DataBuffer* ld_db8 = db_factory_.Allocate<uint64_t>(1); flat_memory_->Load(0x1000, ld_db1, nullptr, nullptr); flat_memory_->Load(0x1002, ld_db2, nullptr, nullptr); @@ -108,7 +111,7 @@ // Test load-linked, store-conditional. TEST_F(AtomicMemoryTest, TestLlSc) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -142,8 +145,8 @@ // Test load-linked, store-conditional. TEST_F(AtomicMemoryTest, TestLlScFailure) { - auto *db = db_factory_.Allocate<uint32_t>(1); - auto *db2 = db_factory_.Allocate<uint16_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); + auto* db2 = db_factory_.Allocate<uint16_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); memory_->Store(kBaseAddr, db); @@ -178,7 +181,7 @@ // Swap TEST_F(AtomicMemoryTest, Swap) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -195,7 +198,7 @@ // Add TEST_F(AtomicMemoryTest, Add) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -212,7 +215,7 @@ // Subtract TEST_F(AtomicMemoryTest, Sub) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -229,7 +232,7 @@ // And TEST_F(AtomicMemoryTest, And) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -246,7 +249,7 @@ // Or TEST_F(AtomicMemoryTest, Or) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -263,7 +266,7 @@ // Xor TEST_F(AtomicMemoryTest, Xor) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -280,7 +283,7 @@ // Max TEST_F(AtomicMemoryTest, Max) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -298,7 +301,7 @@ // Maxu TEST_F(AtomicMemoryTest, Maxu) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -317,7 +320,7 @@ // Min TEST_F(AtomicMemoryTest, Min) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -335,7 +338,7 @@ // Minu TEST_F(AtomicMemoryTest, Minu) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db);
diff --git a/mpact/sim/util/memory/test/atomic_tagged_memory_test.cc b/mpact/sim/util/memory/test/atomic_tagged_memory_test.cc index 0193a9f..f4fbde9 100644 --- a/mpact/sim/util/memory/test/atomic_tagged_memory_test.cc +++ b/mpact/sim/util/memory/test/atomic_tagged_memory_test.cc
@@ -14,6 +14,7 @@ #include "mpact/sim/util/memory/atomic_tagged_memory.h" +#include <algorithm> #include <cstdint> #include "googlemock/include/gmock/gmock.h" // IWYU pragma: keep @@ -49,19 +50,19 @@ delete flat_memory_; } - AtomicTaggedMemory *memory_; - TaggedFlatDemandMemory *flat_memory_; + AtomicTaggedMemory* memory_; + TaggedFlatDemandMemory* flat_memory_; DataBufferFactory db_factory_; - DataBuffer *db_; + DataBuffer* db_; }; // Test that loads and stores are passed through to the FlatDemandMemory // for simple loads and stores. TEST_F(AtomicTaggedMemoryTest, PassThroughLoadsStores) { - DataBuffer *st_db1 = db_factory_.Allocate<uint8_t>(1); - DataBuffer *st_db2 = db_factory_.Allocate<uint16_t>(1); - DataBuffer *st_db4 = db_factory_.Allocate<uint32_t>(1); - DataBuffer *st_db8 = db_factory_.Allocate<uint64_t>(1); + DataBuffer* st_db1 = db_factory_.Allocate<uint8_t>(1); + DataBuffer* st_db2 = db_factory_.Allocate<uint16_t>(1); + DataBuffer* st_db4 = db_factory_.Allocate<uint32_t>(1); + DataBuffer* st_db8 = db_factory_.Allocate<uint64_t>(1); st_db1->Set<uint8_t>(0, 0x0F); st_db2->Set<uint16_t>(0, 0xA5A5); @@ -73,10 +74,10 @@ memory_->Store(0x1004, st_db4); memory_->Store(0x1008, st_db8); - DataBuffer *ld_db1 = db_factory_.Allocate<uint8_t>(1); - DataBuffer *ld_db2 = db_factory_.Allocate<uint16_t>(1); - DataBuffer *ld_db4 = db_factory_.Allocate<uint32_t>(1); - DataBuffer *ld_db8 = db_factory_.Allocate<uint64_t>(1); + DataBuffer* ld_db1 = db_factory_.Allocate<uint8_t>(1); + DataBuffer* ld_db2 = db_factory_.Allocate<uint16_t>(1); + DataBuffer* ld_db4 = db_factory_.Allocate<uint32_t>(1); + DataBuffer* ld_db8 = db_factory_.Allocate<uint64_t>(1); flat_memory_->Load(0x1000, ld_db1, nullptr, nullptr); flat_memory_->Load(0x1002, ld_db2, nullptr, nullptr); @@ -111,7 +112,7 @@ // Test load-linked, store-conditional. TEST_F(AtomicTaggedMemoryTest, TestLlSc) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -145,8 +146,8 @@ // Test load-linked, store-conditional. TEST_F(AtomicTaggedMemoryTest, TestLlScFailure) { - auto *db = db_factory_.Allocate<uint32_t>(1); - auto *db2 = db_factory_.Allocate<uint16_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); + auto* db2 = db_factory_.Allocate<uint16_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); memory_->Store(kBaseAddr, db); @@ -181,7 +182,7 @@ // Swap TEST_F(AtomicTaggedMemoryTest, Swap) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -198,7 +199,7 @@ // Add TEST_F(AtomicTaggedMemoryTest, Add) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -215,7 +216,7 @@ // Subtract TEST_F(AtomicTaggedMemoryTest, Sub) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -232,7 +233,7 @@ // And TEST_F(AtomicTaggedMemoryTest, And) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -249,7 +250,7 @@ // Or TEST_F(AtomicTaggedMemoryTest, Or) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -266,7 +267,7 @@ // Xor TEST_F(AtomicTaggedMemoryTest, Xor) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -283,7 +284,7 @@ // Max TEST_F(AtomicTaggedMemoryTest, Max) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -301,7 +302,7 @@ // Maxu TEST_F(AtomicTaggedMemoryTest, Maxu) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -320,7 +321,7 @@ // Min TEST_F(AtomicTaggedMemoryTest, Min) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db); @@ -338,7 +339,7 @@ // Minu TEST_F(AtomicTaggedMemoryTest, Minu) { - auto *db = db_factory_.Allocate<uint32_t>(1); + auto* db = db_factory_.Allocate<uint32_t>(1); // Store a known value to kBaseAddr. db->Set<uint32_t>(0, kBaseValue); flat_memory_->Store(kBaseAddr, db);
diff --git a/mpact/sim/util/memory/test/cache_test.cc b/mpact/sim/util/memory/test/cache_test.cc index f6067a1..49468dd 100644 --- a/mpact/sim/util/memory/test/cache_test.cc +++ b/mpact/sim/util/memory/test/cache_test.cc
@@ -43,23 +43,23 @@ cache_ = new Cache("cache"); db_ = db_factory_.Allocate<uint32_t>(1); db_->set_latency(0); - read_hits_ = reinterpret_cast<SimpleCounter<uint64_t> *>( + read_hits_ = reinterpret_cast<SimpleCounter<uint64_t>*>( cache_->GetCounter("read_hit")); - read_misses_ = reinterpret_cast<SimpleCounter<uint64_t> *>( + read_misses_ = reinterpret_cast<SimpleCounter<uint64_t>*>( cache_->GetCounter("read_miss")); - write_hits_ = reinterpret_cast<SimpleCounter<uint64_t> *>( + write_hits_ = reinterpret_cast<SimpleCounter<uint64_t>*>( cache_->GetCounter("write_hit")); - write_misses_ = reinterpret_cast<SimpleCounter<uint64_t> *>( + write_misses_ = reinterpret_cast<SimpleCounter<uint64_t>*>( cache_->GetCounter("write_miss")); - dirty_line_writebacks_ = reinterpret_cast<SimpleCounter<uint64_t> *>( + dirty_line_writebacks_ = reinterpret_cast<SimpleCounter<uint64_t>*>( cache_->GetCounter("dirty_line_writeback")); - read_arounds_ = reinterpret_cast<SimpleCounter<uint64_t> *>( + read_arounds_ = reinterpret_cast<SimpleCounter<uint64_t>*>( cache_->GetCounter("read_around")); - write_arounds_ = reinterpret_cast<SimpleCounter<uint64_t> *>( + write_arounds_ = reinterpret_cast<SimpleCounter<uint64_t>*>( cache_->GetCounter("write_around")); - read_non_cacheable_ = reinterpret_cast<SimpleCounter<uint64_t> *>( + read_non_cacheable_ = reinterpret_cast<SimpleCounter<uint64_t>*>( cache_->GetCounter("read_non_cacheable")); - write_non_cacheable_ = reinterpret_cast<SimpleCounter<uint64_t> *>( + write_non_cacheable_ = reinterpret_cast<SimpleCounter<uint64_t>*>( cache_->GetCounter("write_non_cacheable")); } @@ -69,17 +69,17 @@ } DataBufferFactory db_factory_; - DataBuffer *db_; - Cache *cache_; - SimpleCounter<uint64_t> *read_hits_; - SimpleCounter<uint64_t> *read_misses_; - SimpleCounter<uint64_t> *write_hits_; - SimpleCounter<uint64_t> *write_misses_; - SimpleCounter<uint64_t> *dirty_line_writebacks_; - SimpleCounter<uint64_t> *read_arounds_; - SimpleCounter<uint64_t> *write_arounds_; - SimpleCounter<uint64_t> *read_non_cacheable_; - SimpleCounter<uint64_t> *write_non_cacheable_; + DataBuffer* db_; + Cache* cache_; + SimpleCounter<uint64_t>* read_hits_; + SimpleCounter<uint64_t>* read_misses_; + SimpleCounter<uint64_t>* write_hits_; + SimpleCounter<uint64_t>* write_misses_; + SimpleCounter<uint64_t>* dirty_line_writebacks_; + SimpleCounter<uint64_t>* read_arounds_; + SimpleCounter<uint64_t>* write_arounds_; + SimpleCounter<uint64_t>* read_non_cacheable_; + SimpleCounter<uint64_t>* write_non_cacheable_; SimpleCounter<uint64_t> cycle_counter_; }; @@ -196,10 +196,10 @@ cache_->set_memory(&memory); CHECK_OK(cache_->Configure("1k,16,1,true", &cycle_counter_)); - DataBuffer *st_db1 = db_factory_.Allocate<uint8_t>(1); - DataBuffer *st_db2 = db_factory_.Allocate<uint16_t>(1); - DataBuffer *st_db4 = db_factory_.Allocate<uint32_t>(1); - DataBuffer *st_db8 = db_factory_.Allocate<uint64_t>(1); + DataBuffer* st_db1 = db_factory_.Allocate<uint8_t>(1); + DataBuffer* st_db2 = db_factory_.Allocate<uint16_t>(1); + DataBuffer* st_db4 = db_factory_.Allocate<uint32_t>(1); + DataBuffer* st_db8 = db_factory_.Allocate<uint64_t>(1); st_db1->Set<uint8_t>(0, 0x0F); st_db2->Set<uint16_t>(0, 0xA5A5); @@ -211,10 +211,10 @@ cache_->Store(0x1004, st_db4); cache_->Store(0x1008, st_db8); - DataBuffer *ld_db1 = db_factory_.Allocate<uint8_t>(1); - DataBuffer *ld_db2 = db_factory_.Allocate<uint16_t>(1); - DataBuffer *ld_db4 = db_factory_.Allocate<uint32_t>(1); - DataBuffer *ld_db8 = db_factory_.Allocate<uint64_t>(1); + DataBuffer* ld_db1 = db_factory_.Allocate<uint8_t>(1); + DataBuffer* ld_db2 = db_factory_.Allocate<uint16_t>(1); + DataBuffer* ld_db4 = db_factory_.Allocate<uint32_t>(1); + DataBuffer* ld_db8 = db_factory_.Allocate<uint64_t>(1); ld_db1->set_latency(0); ld_db2->set_latency(0); @@ -247,10 +247,10 @@ cache_->set_tagged_memory(&memory); CHECK_OK(cache_->Configure("1k,16,1,true", &cycle_counter_)); - DataBuffer *ld_data_db = db_factory_.Allocate<uint8_t>(kTagGranule * 16); - DataBuffer *ld_tag_db = db_factory_.Allocate<uint8_t>(16); - DataBuffer *st_data_db = db_factory_.Allocate<uint8_t>(kTagGranule * 16); - DataBuffer *st_tag_db = db_factory_.Allocate<uint8_t>(16); + DataBuffer* ld_data_db = db_factory_.Allocate<uint8_t>(kTagGranule * 16); + DataBuffer* ld_tag_db = db_factory_.Allocate<uint8_t>(16); + DataBuffer* st_data_db = db_factory_.Allocate<uint8_t>(kTagGranule * 16); + DataBuffer* st_tag_db = db_factory_.Allocate<uint8_t>(16); ld_data_db->set_latency(0); ld_tag_db->set_latency(0);
diff --git a/mpact/sim/util/memory/test/dummy_memory.h b/mpact/sim/util/memory/test/dummy_memory.h index b74c901..c43fe6f 100644 --- a/mpact/sim/util/memory/test/dummy_memory.h +++ b/mpact/sim/util/memory/test/dummy_memory.h
@@ -30,38 +30,38 @@ // Memory interface methods. // Plain load. - void Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) override { + void Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) override { load_address_ = address; } // Vector load. - void Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) override { + void Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) override { vector_load_address_ = address_db->Get<uint64_t>(0); } // Tagged load. - void Load(uint64_t address, DataBuffer *db, DataBuffer *tags, - Instruction *inst, ReferenceCount *context) override { + void Load(uint64_t address, DataBuffer* db, DataBuffer* tags, + Instruction* inst, ReferenceCount* context) override { tagged_load_address_ = address; } // Plain store. - void Store(uint64_t address, DataBuffer *db) override { + void Store(uint64_t address, DataBuffer* db) override { store_address_ = address; } // Vector store. - void Store(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db) override { + void Store(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db) override { vector_store_address_ = address_db->Get<uint64_t>(0); } // Tagged store. - void Store(uint64_t address, DataBuffer *db, DataBuffer *tags) override { + void Store(uint64_t address, DataBuffer* db, DataBuffer* tags) override { tagged_store_address_ = address; } // Atomic memory operation. - absl::Status PerformMemoryOp(uint64_t address, Operation op, DataBuffer *db, - Instruction *inst, - ReferenceCount *context) override { + absl::Status PerformMemoryOp(uint64_t address, Operation op, DataBuffer* db, + Instruction* inst, + ReferenceCount* context) override { memory_op_address_ = address; return absl::OkStatus(); }
diff --git a/mpact/sim/util/memory/test/flat_demand_memory_test.cc b/mpact/sim/util/memory/test/flat_demand_memory_test.cc index c432cf9..b68c040 100644 --- a/mpact/sim/util/memory/test/flat_demand_memory_test.cc +++ b/mpact/sim/util/memory/test/flat_demand_memory_test.cc
@@ -42,15 +42,15 @@ FlatDemandMemoryTest() { arch_state_ = new MyArchState("TestArchitecture"); } ~FlatDemandMemoryTest() override { delete arch_state_; } - MyArchState *arch_state_; + MyArchState* arch_state_; }; TEST_F(FlatDemandMemoryTest, BasicLoadStore) { auto mem = std::make_unique<FlatDemandMemory>(); - DataBuffer *st_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); - DataBuffer *st_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); - DataBuffer *st_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); - DataBuffer *st_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* st_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); + DataBuffer* st_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* st_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* st_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); st_db1->Set<uint8_t>(0, 0x0F); st_db2->Set<uint16_t>(0, 0xA5A5); @@ -62,10 +62,10 @@ mem->Store(0x1004, st_db4); mem->Store(0x1008, st_db8); - DataBuffer *ld_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); - DataBuffer *ld_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); - DataBuffer *ld_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); - DataBuffer *ld_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* ld_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); + DataBuffer* ld_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* ld_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* ld_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); ld_db1->set_latency(0); ld_db2->set_latency(0); ld_db4->set_latency(0); @@ -95,15 +95,15 @@ TEST_F(FlatDemandMemoryTest, SpanningLoadStore) { auto mem = std::make_unique<FlatDemandMemory>(); - DataBuffer *st_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); - DataBuffer *st_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); - DataBuffer *st_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); - DataBuffer *st_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* st_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); + DataBuffer* st_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* st_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* st_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); - DataBuffer *ld_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); - DataBuffer *ld_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); - DataBuffer *ld_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); - DataBuffer *ld_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* ld_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); + DataBuffer* ld_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* ld_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* ld_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); ld_db1->set_latency(0); ld_db2->set_latency(0); ld_db4->set_latency(0); @@ -142,11 +142,11 @@ TEST_F(FlatDemandMemoryTest, MultiLoadUnitStride) { auto mem = std::make_unique<FlatDemandMemory>(1024, 0x1000, 1, 0); - DataBuffer *address_db = arch_state_->db_factory()->Allocate<uint64_t>(1); - DataBuffer *mask_db = arch_state_->db_factory()->Allocate<bool>(4); - DataBuffer *ld_db = arch_state_->db_factory()->Allocate<uint32_t>(4); + DataBuffer* address_db = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* mask_db = arch_state_->db_factory()->Allocate<bool>(4); + DataBuffer* ld_db = arch_state_->db_factory()->Allocate<uint32_t>(4); ld_db->set_latency(0); - DataBuffer *st_db = arch_state_->db_factory()->Allocate<uint32_t>(4); + DataBuffer* st_db = arch_state_->db_factory()->Allocate<uint32_t>(4); auto ld_span = ld_db->Get<uint32_t>(); auto st_span = st_db->Get<uint32_t>(); auto mask_span = mask_db->Get<bool>(); @@ -166,9 +166,9 @@ TEST_F(FlatDemandMemoryTest, HalfWordAddressable) { auto mem = std::make_unique<FlatDemandMemory>(0x4000, 0x1000, 2, 0); - DataBuffer *st_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); - DataBuffer *st_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); - DataBuffer *st_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* st_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* st_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* st_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); st_db2->Set<uint16_t>(0, 0xA5A5); st_db4->Set<uint32_t>(0, 0xDEADBEEF); @@ -178,9 +178,9 @@ mem->Store(0x1001, st_db4); mem->Store(0x1003, st_db8); - DataBuffer *ld_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); - DataBuffer *ld_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); - DataBuffer *ld_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* ld_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* ld_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* ld_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); ld_db2->set_latency(0); ld_db4->set_latency(0); ld_db8->set_latency(0); @@ -204,10 +204,10 @@ TEST_F(FlatDemandMemoryTest, LargeBlockOfMemory) { auto mem = std::make_unique<FlatDemandMemory>(); - DataBuffer *ld_db = arch_state_->db_factory()->Allocate<uint8_t>( + DataBuffer* ld_db = arch_state_->db_factory()->Allocate<uint8_t>( FlatDemandMemory::kAllocationSize * 2); ld_db->set_latency(0); - DataBuffer *st_db = arch_state_->db_factory()->Allocate<uint8_t>( + DataBuffer* st_db = arch_state_->db_factory()->Allocate<uint8_t>( FlatDemandMemory::kAllocationSize * 2); // Set the store data to known value. std::memset(st_db->raw_ptr(), 0xbe, FlatDemandMemory::kAllocationSize * 2);
diff --git a/mpact/sim/util/memory/test/flat_memory_test.cc b/mpact/sim/util/memory/test/flat_memory_test.cc index 7e248b2..d4d5251 100644 --- a/mpact/sim/util/memory/test/flat_memory_test.cc +++ b/mpact/sim/util/memory/test/flat_memory_test.cc
@@ -22,6 +22,9 @@ #include "googletest/include/gtest/gtest.h" #include "mpact/sim/generic/arch_state.h" #include "mpact/sim/generic/data_buffer.h" +#include "mpact/sim/generic/instruction.h" +#include "mpact/sim/generic/operand_interface.h" +#include "mpact/sim/generic/ref_count.h" namespace mpact { namespace sim { @@ -32,14 +35,14 @@ struct InstructionContext : public generic::ReferenceCount { public: - uint32_t *value; + uint32_t* value; }; // Define a class that derives from ArchState since constructors are // protected. class MyArchState : public generic::ArchState { public: - MyArchState(absl::string_view id, generic::SourceOperandInterface *pc_op) + MyArchState(absl::string_view id, generic::SourceOperandInterface* pc_op) : ArchState(id, pc_op) {} explicit MyArchState(absl::string_view id) : MyArchState(id, nullptr) {} }; @@ -50,7 +53,7 @@ FlatMemoryTest() { arch_state_ = new MyArchState("TestArchitecture"); } ~FlatMemoryTest() override { delete arch_state_; } - MyArchState *arch_state_; + MyArchState* arch_state_; }; // Verify that size and base address are correct when created. @@ -71,10 +74,10 @@ TEST_F(FlatMemoryTest, SimpleStoreLoad) { auto mem = std::make_unique<FlatMemory>(1024, 0x1000, 1, 0); - DataBuffer *st_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); - DataBuffer *st_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); - DataBuffer *st_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); - DataBuffer *st_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* st_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); + DataBuffer* st_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* st_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* st_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); st_db1->Set<uint8_t>(0, 0x0F); st_db2->Set<uint16_t>(0, 0xA5A5); @@ -86,10 +89,10 @@ mem->Store(0x1004, st_db4); mem->Store(0x1008, st_db8); - DataBuffer *ld_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); - DataBuffer *ld_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); - DataBuffer *ld_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); - DataBuffer *ld_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* ld_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); + DataBuffer* ld_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* ld_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* ld_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); mem->Load(0x1000, ld_db1, nullptr, nullptr); mem->Load(0x1002, ld_db2, nullptr, nullptr); @@ -117,11 +120,11 @@ TEST_F(FlatMemoryTest, MultiAddressLoadStore) { auto mem = std::make_unique<FlatMemory>(1024, 0x1000, 1, 0); - DataBuffer *address_db = arch_state_->db_factory()->Allocate<uint64_t>(4); - DataBuffer *mask_db = arch_state_->db_factory()->Allocate<bool>(4); - DataBuffer *store_data_db = arch_state_->db_factory()->Allocate<uint32_t>(4); - DataBuffer *load_data_db = arch_state_->db_factory()->Allocate<uint32_t>(4); - DataBuffer *load_data2_db = arch_state_->db_factory()->Allocate<uint32_t>(8); + DataBuffer* address_db = arch_state_->db_factory()->Allocate<uint64_t>(4); + DataBuffer* mask_db = arch_state_->db_factory()->Allocate<bool>(4); + DataBuffer* store_data_db = arch_state_->db_factory()->Allocate<uint32_t>(4); + DataBuffer* load_data_db = arch_state_->db_factory()->Allocate<uint32_t>(4); + DataBuffer* load_data2_db = arch_state_->db_factory()->Allocate<uint32_t>(8); // Should load zeros's into load_data_db mem->Load(0x1000, load_data_db, nullptr, nullptr); @@ -188,14 +191,14 @@ auto context = new InstructionContext(); auto inst = std::make_unique<Instruction>(arch_state_); int data = 0; - inst->set_semantic_function([&](Instruction *instruction) { + inst->set_semantic_function([&](Instruction* instruction) { EXPECT_EQ(inst.get(), instruction); - EXPECT_EQ(instruction->context(), static_cast<ReferenceCount *>(context)); + EXPECT_EQ(instruction->context(), static_cast<ReferenceCount*>(context)); data++; }); auto mem = std::make_unique<FlatMemory>(1024, 0x1000, 1, 0); - DataBuffer *ld_db = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* ld_db = arch_state_->db_factory()->Allocate<uint32_t>(1); // Set latency to zero so that the instruction semantic function in inst is // executed immediately. @@ -222,16 +225,16 @@ auto context = new InstructionContext(); auto inst = std::make_unique<Instruction>(arch_state_); int data = 0; - inst->set_semantic_function([&](Instruction *instruction) { + inst->set_semantic_function([&](Instruction* instruction) { EXPECT_EQ(inst.get(), instruction); - EXPECT_EQ(instruction->context(), static_cast<ReferenceCount *>(context)); + EXPECT_EQ(instruction->context(), static_cast<ReferenceCount*>(context)); data++; }); auto mem = std::make_unique<FlatMemory>(1024, 0x1000, 1, 0); - DataBuffer *address_db = arch_state_->db_factory()->Allocate<uint64_t>(4); - DataBuffer *mask_db = arch_state_->db_factory()->Allocate<bool>(4); - DataBuffer *ld_db = arch_state_->db_factory()->Allocate<uint32_t>(4); + DataBuffer* address_db = arch_state_->db_factory()->Allocate<uint64_t>(4); + DataBuffer* mask_db = arch_state_->db_factory()->Allocate<bool>(4); + DataBuffer* ld_db = arch_state_->db_factory()->Allocate<uint32_t>(4); // Set up addresses and mask values. for (int index = 0; index < 4; index++) { @@ -264,10 +267,10 @@ TEST_F(FlatMemoryTest, MultiLoadUnitStride) { auto mem = std::make_unique<FlatMemory>(1024, 0x1000, 1, 0); - DataBuffer *address_db = arch_state_->db_factory()->Allocate<uint64_t>(1); - DataBuffer *mask_db = arch_state_->db_factory()->Allocate<bool>(4); - DataBuffer *ld_db = arch_state_->db_factory()->Allocate<uint32_t>(4); - DataBuffer *st_db = arch_state_->db_factory()->Allocate<uint32_t>(4); + DataBuffer* address_db = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* mask_db = arch_state_->db_factory()->Allocate<bool>(4); + DataBuffer* ld_db = arch_state_->db_factory()->Allocate<uint32_t>(4); + DataBuffer* st_db = arch_state_->db_factory()->Allocate<uint32_t>(4); auto ld_span = ld_db->Get<uint32_t>(); auto st_span = st_db->Get<uint32_t>(); auto mask_span = mask_db->Get<bool>(); @@ -288,10 +291,10 @@ TEST_F(FlatMemoryTest, WordAddressableMemory) { auto mem = std::make_unique<FlatMemory>(1024, 0x1000, 4, 0); // Allocate data buffers for store data. - DataBuffer *st_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); - DataBuffer *st_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); - DataBuffer *st_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); - DataBuffer *st_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* st_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); + DataBuffer* st_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* st_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* st_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); // Initialize values to be stored. st_db1->Set<uint8_t>(0, 0x0F); st_db2->Set<uint16_t>(0, 0xA5A5); @@ -303,10 +306,10 @@ mem->Store(0x1002, st_db4); mem->Store(0x1003, st_db8); // Allocate data buffers for load data. - DataBuffer *ld_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); - DataBuffer *ld_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); - DataBuffer *ld_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); - DataBuffer *ld_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* ld_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); + DataBuffer* ld_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* ld_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* ld_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); // Perform loads from the adjacent addresses in memory. mem->Load(0x1000, ld_db1, nullptr, nullptr); mem->Load(0x1001, ld_db2, nullptr, nullptr);
diff --git a/mpact/sim/util/memory/test/memory_router_test.cc b/mpact/sim/util/memory/test/memory_router_test.cc index 5878e7f..b3c6c26 100644 --- a/mpact/sim/util/memory/test/memory_router_test.cc +++ b/mpact/sim/util/memory/test/memory_router_test.cc
@@ -40,14 +40,14 @@ TEST(MemoryRouterTest, AddInitiator) { auto memory_router = std::make_unique<MemoryRouter>(); // Add initiator. - auto *memory_initiator0 = memory_router->AddMemoryInitiator("initiator0"); + auto* memory_initiator0 = memory_router->AddMemoryInitiator("initiator0"); // Try to add a second initiator with the same name. - auto *memory_initiator1 = memory_router->AddMemoryInitiator("initiator0"); + auto* memory_initiator1 = memory_router->AddMemoryInitiator("initiator0"); // They should be the same object. EXPECT_EQ(memory_initiator0, memory_initiator1); // Add tagged initiator by the same name - it should also be the same object. - auto *tagged_initiator = memory_router->AddTaggedInitiator("initiator0"); + auto* tagged_initiator = memory_router->AddTaggedInitiator("initiator0"); // Since the types are different, make sure that the pointers point to the // same area within the size of SingleInitiatorRouter. uint64_t p0 = reinterpret_cast<uint64_t>(memory_initiator0); @@ -56,7 +56,7 @@ ((p1 >= p0) && (p1 < p0 + sizeof(SingleInitiatorRouter)))); // Add atomic initiator by the same name - it should also be the same object. - auto *atomic_initiator = memory_router->AddAtomicInitiator("initiator0"); + auto* atomic_initiator = memory_router->AddAtomicInitiator("initiator0"); // Since the types are different, make sure that the pointers point to the // same area within the size of SingleInitiatorRouter. p0 = reinterpret_cast<uint64_t>(tagged_initiator); @@ -71,37 +71,36 @@ // Add memory target. EXPECT_TRUE(memory_router ->AddTarget("memory_target", - static_cast<MemoryInterface *>(memory.get())) + static_cast<MemoryInterface*>(memory.get())) .ok()); // Try adding it again, for each interface. It should fail. EXPECT_FALSE(memory_router ->AddTarget("memory_target", - static_cast<MemoryInterface *>(memory.get())) + static_cast<MemoryInterface*>(memory.get())) .ok()); EXPECT_FALSE( memory_router ->AddTarget("memory_target", - static_cast<TaggedMemoryInterface *>(memory.get())) + static_cast<TaggedMemoryInterface*>(memory.get())) .ok()); EXPECT_FALSE( memory_router ->AddTarget("memory_target", - static_cast<AtomicMemoryOpInterface *>(memory.get())) + static_cast<AtomicMemoryOpInterface*>(memory.get())) .ok()); // Add the memory target with different names. This should work. EXPECT_TRUE(memory_router ->AddTarget("memory_target_2", - static_cast<MemoryInterface *>(memory.get())) + static_cast<MemoryInterface*>(memory.get())) + .ok()); + EXPECT_TRUE(memory_router + ->AddTarget("tagged_target", + static_cast<TaggedMemoryInterface*>(memory.get())) .ok()); EXPECT_TRUE( memory_router - ->AddTarget("tagged_target", - static_cast<TaggedMemoryInterface *>(memory.get())) - .ok()); - EXPECT_TRUE( - memory_router ->AddTarget("atomic_target", - static_cast<AtomicMemoryOpInterface *>(memory.get())) + static_cast<AtomicMemoryOpInterface*>(memory.get())) .ok()); } @@ -112,7 +111,7 @@ (void)memory_router->AddMemoryInitiator("initiator"); EXPECT_TRUE( memory_router - ->AddTarget("mem", static_cast<MemoryInterface *>(memory.get())) + ->AddTarget("mem", static_cast<MemoryInterface*>(memory.get())) .ok()); EXPECT_TRUE( memory_router->AddMapping("initiator", "mem", 0x1000, 0x1fff).ok()); @@ -131,19 +130,19 @@ // Create a router with 2 initiators and 2 memory targets. With different // mappings for each initiator. DataBufferFactory factory; - auto *db = factory.Allocate<uint32_t>(1); + auto* db = factory.Allocate<uint32_t>(1); auto memory_router = std::make_unique<MemoryRouter>(); auto memory0 = std::make_unique<DummyMemory>(); auto memory1 = std::make_unique<DummyMemory>(); - auto *initiator0 = memory_router->AddMemoryInitiator("initiator0"); - auto *initiator1 = memory_router->AddMemoryInitiator("initiator1"); + auto* initiator0 = memory_router->AddMemoryInitiator("initiator0"); + auto* initiator1 = memory_router->AddMemoryInitiator("initiator1"); EXPECT_TRUE( memory_router - ->AddTarget("mem0", static_cast<MemoryInterface *>(memory0.get())) + ->AddTarget("mem0", static_cast<MemoryInterface*>(memory0.get())) .ok()); EXPECT_TRUE( memory_router - ->AddTarget("mem1", static_cast<MemoryInterface *>(memory1.get())) + ->AddTarget("mem1", static_cast<MemoryInterface*>(memory1.get())) .ok()); EXPECT_TRUE( memory_router->AddMapping("initiator0", "mem0", 0x1000, 0x1fff).ok());
diff --git a/mpact/sim/util/memory/test/memory_watcher_test.cc b/mpact/sim/util/memory/test/memory_watcher_test.cc index d4d9850..5c4c175 100644 --- a/mpact/sim/util/memory/test/memory_watcher_test.cc +++ b/mpact/sim/util/memory/test/memory_watcher_test.cc
@@ -42,8 +42,8 @@ } DataBufferFactory db_factory_; - MemoryWatcher *watcher_; - FlatDemandMemory *memory_; + MemoryWatcher* watcher_; + FlatDemandMemory* memory_; }; // This tests if status is ok when setting non overlapping ranges. @@ -161,10 +161,10 @@ }) .ok()); - DataBuffer *db1 = db_factory_.Allocate<uint8_t>(1); - DataBuffer *db2 = db_factory_.Allocate<uint16_t>(1); - DataBuffer *db4 = db_factory_.Allocate<uint32_t>(1); - DataBuffer *db8 = db_factory_.Allocate<uint64_t>(1); + DataBuffer* db1 = db_factory_.Allocate<uint8_t>(1); + DataBuffer* db2 = db_factory_.Allocate<uint16_t>(1); + DataBuffer* db4 = db_factory_.Allocate<uint32_t>(1); + DataBuffer* db8 = db_factory_.Allocate<uint64_t>(1); // First ensure that the store doesn't trigger a callback. watcher_->Store(0x1000, db8); @@ -232,9 +232,9 @@ }) .ok()); - DataBuffer *address_db = db_factory_.Allocate<uint64_t>(4); - DataBuffer *mask_db = db_factory_.Allocate<bool>(4); - DataBuffer *data_db = db_factory_.Allocate<uint32_t>(4); + DataBuffer* address_db = db_factory_.Allocate<uint64_t>(4); + DataBuffer* mask_db = db_factory_.Allocate<bool>(4); + DataBuffer* data_db = db_factory_.Allocate<uint32_t>(4); auto address_span = address_db->Get<uint64_t>(); auto mask_span = mask_db->Get<bool>(); @@ -302,10 +302,10 @@ }) .ok()); - DataBuffer *db1 = db_factory_.Allocate<uint8_t>(1); - DataBuffer *db2 = db_factory_.Allocate<uint16_t>(1); - DataBuffer *db4 = db_factory_.Allocate<uint32_t>(1); - DataBuffer *db8 = db_factory_.Allocate<uint64_t>(1); + DataBuffer* db1 = db_factory_.Allocate<uint8_t>(1); + DataBuffer* db2 = db_factory_.Allocate<uint16_t>(1); + DataBuffer* db4 = db_factory_.Allocate<uint32_t>(1); + DataBuffer* db8 = db_factory_.Allocate<uint64_t>(1); // No callbacks for a load. watcher_->Load(0x1000, db8, nullptr, nullptr); @@ -372,9 +372,9 @@ }) .ok()); - DataBuffer *address_db = db_factory_.Allocate<uint64_t>(4); - DataBuffer *mask_db = db_factory_.Allocate<bool>(4); - DataBuffer *data_db = db_factory_.Allocate<uint32_t>(4); + DataBuffer* address_db = db_factory_.Allocate<uint64_t>(4); + DataBuffer* mask_db = db_factory_.Allocate<bool>(4); + DataBuffer* data_db = db_factory_.Allocate<uint32_t>(4); auto address_span = address_db->Get<uint64_t>(); auto mask_span = mask_db->Get<bool>();
diff --git a/mpact/sim/util/memory/test/single_initiator_router_test.cc b/mpact/sim/util/memory/test/single_initiator_router_test.cc index 30ec9cb..3cac2b3 100644 --- a/mpact/sim/util/memory/test/single_initiator_router_test.cc +++ b/mpact/sim/util/memory/test/single_initiator_router_test.cc
@@ -40,11 +40,11 @@ DataBufferFactory db_factory; auto router = std::make_unique<SingleInitiatorRouter>("test"); auto memory = std::make_unique<DummyMemory>(); - auto *memory_target = static_cast<MemoryInterface *>(memory.get()); + auto* memory_target = static_cast<MemoryInterface*>(memory.get()); EXPECT_TRUE(router->AddTarget(memory_target, 0, 0xffff'ffff'ffff'ffff).ok()); - auto *db = db_factory.Allocate<uint32_t>(1); - auto *tag_db = db_factory.Allocate<uint8_t>(1); + auto* db = db_factory.Allocate<uint32_t>(1); + auto* tag_db = db_factory.Allocate<uint8_t>(1); // Verify that only the access on the correct interface call go through. router->Load(0x1000, db, nullptr, nullptr); @@ -73,12 +73,12 @@ DataBufferFactory db_factory; auto router = std::make_unique<SingleInitiatorRouter>("test"); auto memory = std::make_unique<DummyMemory>(); - auto *memory_target = static_cast<MemoryInterface *>(memory.get()); + auto* memory_target = static_cast<MemoryInterface*>(memory.get()); EXPECT_TRUE(router->AddTarget(memory_target, 0, 0xffff'ffff'ffff'ffff).ok()); - auto *db = db_factory.Allocate<uint32_t>(2); - auto *address_db = db_factory.Allocate<uint64_t>(2); - auto *mask_db = db_factory.Allocate<uint8_t>(2); + auto* db = db_factory.Allocate<uint32_t>(2); + auto* address_db = db_factory.Allocate<uint64_t>(2); + auto* mask_db = db_factory.Allocate<uint8_t>(2); address_db->Set<uint64_t>(0, 0x1000); address_db->Set<uint64_t>(1, 0x2000); mask_db->Set<uint8_t>(0, 1); @@ -101,11 +101,11 @@ DataBufferFactory db_factory; auto router = std::make_unique<SingleInitiatorRouter>("test"); auto tagged = std::make_unique<DummyMemory>(); - auto *tagged_target = static_cast<TaggedMemoryInterface *>(tagged.get()); + auto* tagged_target = static_cast<TaggedMemoryInterface*>(tagged.get()); EXPECT_TRUE(router->AddTarget(tagged_target, 0, 0xffff'ffff'ffff'ffff).ok()); - auto *db = db_factory.Allocate<uint32_t>(1); - auto *tag_db = db_factory.Allocate<uint8_t>(1); + auto* db = db_factory.Allocate<uint32_t>(1); + auto* tag_db = db_factory.Allocate<uint8_t>(1); // Verify that only the access on the correct interface call go through. router->Load(0x1000, db, nullptr, nullptr); EXPECT_EQ(tagged->load_address(), 0x1000); @@ -135,12 +135,12 @@ DataBufferFactory db_factory; auto router = std::make_unique<SingleInitiatorRouter>("test"); auto tagged = std::make_unique<DummyMemory>(); - auto *tagged_target = static_cast<TaggedMemoryInterface *>(tagged.get()); + auto* tagged_target = static_cast<TaggedMemoryInterface*>(tagged.get()); EXPECT_TRUE(router->AddTarget(tagged_target, 0, 0xffff'ffff'ffff'ffff).ok()); - auto *db = db_factory.Allocate<uint32_t>(2); - auto *address_db = db_factory.Allocate<uint64_t>(2); - auto *mask_db = db_factory.Allocate<uint8_t>(2); + auto* db = db_factory.Allocate<uint32_t>(2); + auto* address_db = db_factory.Allocate<uint64_t>(2); + auto* mask_db = db_factory.Allocate<uint8_t>(2); address_db->Set<uint64_t>(0, 0x1000); address_db->Set<uint64_t>(1, 0x2000); mask_db->Set<uint8_t>(0, 1); @@ -163,10 +163,10 @@ DataBufferFactory db_factory; auto router = std::make_unique<SingleInitiatorRouter>("test"); auto atomic = std::make_unique<DummyMemory>(); - auto *atomic_target = static_cast<AtomicMemoryOpInterface *>(atomic.get()); + auto* atomic_target = static_cast<AtomicMemoryOpInterface*>(atomic.get()); EXPECT_TRUE(router->AddTarget(atomic_target, 0, 0xffff'ffff'ffff'ffff).ok()); - auto *db = db_factory.Allocate<uint32_t>(1); - auto *tag_db = db_factory.Allocate<uint8_t>(1); + auto* db = db_factory.Allocate<uint32_t>(1); + auto* tag_db = db_factory.Allocate<uint8_t>(1); // These should not update the address. router->Load(0x1000, db, nullptr, nullptr); EXPECT_EQ(atomic->load_address(), 0); @@ -195,11 +195,11 @@ auto memory1 = std::make_unique<DummyMemory>(); auto memory2 = std::make_unique<DummyMemory>(); auto default_memory = std::make_unique<DummyMemory>(); - auto *memory_target0 = static_cast<MemoryInterface *>(memory0.get()); - auto *memory_target1 = static_cast<MemoryInterface *>(memory1.get()); - auto *memory_target2 = static_cast<MemoryInterface *>(memory2.get()); - auto *default_target = static_cast<MemoryInterface *>(default_memory.get()); - auto *db = db_factory.Allocate<uint32_t>(1); + auto* memory_target0 = static_cast<MemoryInterface*>(memory0.get()); + auto* memory_target1 = static_cast<MemoryInterface*>(memory1.get()); + auto* memory_target2 = static_cast<MemoryInterface*>(memory2.get()); + auto* default_target = static_cast<MemoryInterface*>(default_memory.get()); + auto* db = db_factory.Allocate<uint32_t>(1); // Add 3 targets at different areas in the memory map. EXPECT_TRUE( @@ -268,13 +268,13 @@ auto memory1 = std::make_unique<DummyMemory>(); auto memory2 = std::make_unique<DummyMemory>(); auto default_memory = std::make_unique<DummyMemory>(); - auto *memory_target0 = static_cast<TaggedMemoryInterface *>(memory0.get()); - auto *memory_target1 = static_cast<TaggedMemoryInterface *>(memory1.get()); - auto *memory_target2 = static_cast<TaggedMemoryInterface *>(memory2.get()); - auto *default_target = - static_cast<TaggedMemoryInterface *>(default_memory.get()); - auto *db = db_factory.Allocate<uint32_t>(1); - auto *tag_db = db_factory.Allocate<uint8_t>(1); + auto* memory_target0 = static_cast<TaggedMemoryInterface*>(memory0.get()); + auto* memory_target1 = static_cast<TaggedMemoryInterface*>(memory1.get()); + auto* memory_target2 = static_cast<TaggedMemoryInterface*>(memory2.get()); + auto* default_target = + static_cast<TaggedMemoryInterface*>(default_memory.get()); + auto* db = db_factory.Allocate<uint32_t>(1); + auto* tag_db = db_factory.Allocate<uint8_t>(1); // Add 3 targets at different areas in the memory map. EXPECT_TRUE( @@ -344,12 +344,12 @@ auto memory0 = std::make_unique<DummyMemory>(); auto memory1 = std::make_unique<DummyMemory>(); auto memory2 = std::make_unique<DummyMemory>(); - auto *memory_target0 = static_cast<MemoryInterface *>(memory0.get()); - auto *memory_target1 = static_cast<MemoryInterface *>(memory1.get()); - auto *memory_target2 = static_cast<MemoryInterface *>(memory2.get()); - auto *address_db = db_factory.Allocate<uint64_t>(2); - auto *mask_db = db_factory.Allocate<uint8_t>(2); - auto *db = db_factory.Allocate<uint32_t>(2); + auto* memory_target0 = static_cast<MemoryInterface*>(memory0.get()); + auto* memory_target1 = static_cast<MemoryInterface*>(memory1.get()); + auto* memory_target2 = static_cast<MemoryInterface*>(memory2.get()); + auto* address_db = db_factory.Allocate<uint64_t>(2); + auto* mask_db = db_factory.Allocate<uint8_t>(2); + auto* db = db_factory.Allocate<uint32_t>(2); mask_db->Set<uint8_t>(0, 1); mask_db->Set<uint8_t>(1, 1); @@ -431,12 +431,12 @@ auto memory0 = std::make_unique<DummyMemory>(); auto memory1 = std::make_unique<DummyMemory>(); auto memory2 = std::make_unique<DummyMemory>(); - auto *tagged_target0 = static_cast<TaggedMemoryInterface *>(memory0.get()); - auto *tagged_target1 = static_cast<TaggedMemoryInterface *>(memory1.get()); - auto *tagged_target2 = static_cast<TaggedMemoryInterface *>(memory2.get()); - auto *address_db = db_factory.Allocate<uint64_t>(2); - auto *mask_db = db_factory.Allocate<uint8_t>(2); - auto *db = db_factory.Allocate<uint32_t>(2); + auto* tagged_target0 = static_cast<TaggedMemoryInterface*>(memory0.get()); + auto* tagged_target1 = static_cast<TaggedMemoryInterface*>(memory1.get()); + auto* tagged_target2 = static_cast<TaggedMemoryInterface*>(memory2.get()); + auto* address_db = db_factory.Allocate<uint64_t>(2); + auto* mask_db = db_factory.Allocate<uint8_t>(2); + auto* db = db_factory.Allocate<uint32_t>(2); mask_db->Set<uint8_t>(0, 1); mask_db->Set<uint8_t>(1, 1); @@ -519,12 +519,12 @@ auto memory1 = std::make_unique<DummyMemory>(); auto memory2 = std::make_unique<DummyMemory>(); auto default_memory = std::make_unique<DummyMemory>(); - auto *atomic_target0 = static_cast<AtomicMemoryOpInterface *>(memory0.get()); - auto *atomic_target1 = static_cast<AtomicMemoryOpInterface *>(memory1.get()); - auto *atomic_target2 = static_cast<AtomicMemoryOpInterface *>(memory2.get()); - auto *default_target = - static_cast<AtomicMemoryOpInterface *>(default_memory.get()); - auto *db = db_factory.Allocate<uint32_t>(1); + auto* atomic_target0 = static_cast<AtomicMemoryOpInterface*>(memory0.get()); + auto* atomic_target1 = static_cast<AtomicMemoryOpInterface*>(memory1.get()); + auto* atomic_target2 = static_cast<AtomicMemoryOpInterface*>(memory2.get()); + auto* default_target = + static_cast<AtomicMemoryOpInterface*>(default_memory.get()); + auto* db = db_factory.Allocate<uint32_t>(1); // Add 3 targets at different areas in the memory map. EXPECT_TRUE(
diff --git a/mpact/sim/util/memory/test/tagged_flat_demand_memory_test.cc b/mpact/sim/util/memory/test/tagged_flat_demand_memory_test.cc index 5a40ba9..4e6d912 100644 --- a/mpact/sim/util/memory/test/tagged_flat_demand_memory_test.cc +++ b/mpact/sim/util/memory/test/tagged_flat_demand_memory_test.cc
@@ -50,7 +50,7 @@ } ~TaggedFlatDemandMemoryTest() override { delete arch_state_; } - MyArchState *arch_state_; + MyArchState* arch_state_; }; // The first set of tests verify that the tagged flat demand memory works just @@ -58,10 +58,10 @@ TEST_F(TaggedFlatDemandMemoryTest, BasicLoadStore) { auto mem = std::make_unique<TaggedFlatDemandMemory>(kTagGranule); - DataBuffer *st_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); - DataBuffer *st_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); - DataBuffer *st_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); - DataBuffer *st_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* st_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); + DataBuffer* st_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* st_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* st_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); st_db1->Set<uint8_t>(0, 0x0F); st_db2->Set<uint16_t>(0, 0xA5A5); @@ -73,10 +73,10 @@ mem->Store(0x1004, st_db4); mem->Store(0x1008, st_db8); - DataBuffer *ld_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); - DataBuffer *ld_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); - DataBuffer *ld_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); - DataBuffer *ld_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* ld_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); + DataBuffer* ld_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* ld_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* ld_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); ld_db1->set_latency(0); ld_db2->set_latency(0); ld_db4->set_latency(0); @@ -106,15 +106,15 @@ TEST_F(TaggedFlatDemandMemoryTest, SpanningLoadStore) { auto mem = std::make_unique<TaggedFlatDemandMemory>(kTagGranule); - DataBuffer *st_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); - DataBuffer *st_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); - DataBuffer *st_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); - DataBuffer *st_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* st_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); + DataBuffer* st_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* st_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* st_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); - DataBuffer *ld_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); - DataBuffer *ld_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); - DataBuffer *ld_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); - DataBuffer *ld_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* ld_db1 = arch_state_->db_factory()->Allocate<uint8_t>(1); + DataBuffer* ld_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* ld_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* ld_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); ld_db1->set_latency(0); ld_db2->set_latency(0); ld_db4->set_latency(0); @@ -158,11 +158,11 @@ auto mem = std::make_unique<TaggedFlatDemandMemory>(1024, 0x1000, 1, 0, kTagGranule); - DataBuffer *address_db = arch_state_->db_factory()->Allocate<uint64_t>(1); - DataBuffer *mask_db = arch_state_->db_factory()->Allocate<bool>(4); - DataBuffer *ld_db = arch_state_->db_factory()->Allocate<uint32_t>(4); + DataBuffer* address_db = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* mask_db = arch_state_->db_factory()->Allocate<bool>(4); + DataBuffer* ld_db = arch_state_->db_factory()->Allocate<uint32_t>(4); ld_db->set_latency(0); - DataBuffer *st_db = arch_state_->db_factory()->Allocate<uint32_t>(4); + DataBuffer* st_db = arch_state_->db_factory()->Allocate<uint32_t>(4); auto ld_span = ld_db->Get<uint32_t>(); auto st_span = st_db->Get<uint32_t>(); auto mask_span = mask_db->Get<bool>(); @@ -183,9 +183,9 @@ TEST_F(TaggedFlatDemandMemoryTest, HalfWordAddressable) { auto mem = std::make_unique<TaggedFlatDemandMemory>(0x4000, 0x1000, 2, 0, kTagGranule); - DataBuffer *st_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); - DataBuffer *st_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); - DataBuffer *st_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* st_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* st_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* st_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); st_db2->Set<uint16_t>(0, 0xA5A5); st_db4->Set<uint32_t>(0, 0xDEADBEEF); @@ -195,9 +195,9 @@ mem->Store(0x1001, st_db4); mem->Store(0x1003, st_db8); - DataBuffer *ld_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); - DataBuffer *ld_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); - DataBuffer *ld_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); + DataBuffer* ld_db2 = arch_state_->db_factory()->Allocate<uint16_t>(1); + DataBuffer* ld_db4 = arch_state_->db_factory()->Allocate<uint32_t>(1); + DataBuffer* ld_db8 = arch_state_->db_factory()->Allocate<uint64_t>(1); ld_db2->set_latency(0); ld_db4->set_latency(0); ld_db8->set_latency(0); @@ -221,9 +221,9 @@ TEST_F(TaggedFlatDemandMemoryTest, LargeBlockOfMemory) { auto mem = std::make_unique<TaggedFlatDemandMemory>(kTagGranule); - DataBuffer *ld_db = arch_state_->db_factory()->Allocate<uint8_t>( + DataBuffer* ld_db = arch_state_->db_factory()->Allocate<uint8_t>( TaggedFlatDemandMemory::kAllocationSize * 2); - DataBuffer *st_db = arch_state_->db_factory()->Allocate<uint8_t>( + DataBuffer* st_db = arch_state_->db_factory()->Allocate<uint8_t>( TaggedFlatDemandMemory::kAllocationSize * 2); // Set the store data to known value. std::memset(st_db->raw_ptr(), 0xbe, @@ -246,9 +246,9 @@ LogSink log_sink; absl::AddLogSink(&log_sink); auto mem = std::make_unique<TaggedFlatDemandMemory>(kTagGranule); - DataBuffer *data_db = + DataBuffer* data_db = arch_state_->db_factory()->Allocate<uint8_t>(kTagGranule * 16); - DataBuffer *tag_db = arch_state_->db_factory()->Allocate<uint8_t>(16); + DataBuffer* tag_db = arch_state_->db_factory()->Allocate<uint8_t>(16); data_db->set_latency(0); tag_db->set_latency(0); int expected_err_count = 0; @@ -270,12 +270,12 @@ LogSink log_sink; absl::AddLogSink(&log_sink); auto mem = std::make_unique<TaggedFlatDemandMemory>(kTagGranule); - DataBuffer *data_db = + DataBuffer* data_db = arch_state_->db_factory()->Allocate<uint8_t>(kTagGranule * 16); - DataBuffer *tag_db = arch_state_->db_factory()->Allocate<uint8_t>(16); - DataBuffer *short_data_db = + DataBuffer* tag_db = arch_state_->db_factory()->Allocate<uint8_t>(16); + DataBuffer* short_data_db = arch_state_->db_factory()->Allocate<uint8_t>(kTagGranule * 16 - 1); - DataBuffer *long_data_db = + DataBuffer* long_data_db = arch_state_->db_factory()->Allocate<uint8_t>(kTagGranule * 16 + 1); data_db->set_latency(0); tag_db->set_latency(0); @@ -303,11 +303,11 @@ LogSink log_sink; absl::AddLogSink(&log_sink); auto mem = std::make_unique<TaggedFlatDemandMemory>(kTagGranule); - DataBuffer *data_db = + DataBuffer* data_db = arch_state_->db_factory()->Allocate<uint8_t>(kTagGranule * 16); - DataBuffer *tag_db = arch_state_->db_factory()->Allocate<uint8_t>(16); - DataBuffer *short_tag_db = arch_state_->db_factory()->Allocate<uint8_t>(8); - DataBuffer *long_tag_db = arch_state_->db_factory()->Allocate<uint8_t>(18); + DataBuffer* tag_db = arch_state_->db_factory()->Allocate<uint8_t>(16); + DataBuffer* short_tag_db = arch_state_->db_factory()->Allocate<uint8_t>(8); + DataBuffer* long_tag_db = arch_state_->db_factory()->Allocate<uint8_t>(18); data_db->set_latency(0); tag_db->set_latency(0); short_tag_db->set_latency(0); @@ -332,14 +332,14 @@ TEST_F(TaggedFlatDemandMemoryTest, TaggedLoadStore) { auto mem = std::make_unique<TaggedFlatDemandMemory>(kTagGranule); - DataBuffer *ld_data_db = + DataBuffer* ld_data_db = arch_state_->db_factory()->Allocate<uint8_t>(kTagGranule * 16); - DataBuffer *ld_tag_db = arch_state_->db_factory()->Allocate<uint8_t>(16); + DataBuffer* ld_tag_db = arch_state_->db_factory()->Allocate<uint8_t>(16); ld_data_db->set_latency(0); ld_tag_db->set_latency(0); - DataBuffer *st_data_db = + DataBuffer* st_data_db = arch_state_->db_factory()->Allocate<uint8_t>(kTagGranule * 16); - DataBuffer *st_tag_db = arch_state_->db_factory()->Allocate<uint8_t>(16); + DataBuffer* st_tag_db = arch_state_->db_factory()->Allocate<uint8_t>(16); mem->Load(0x1000, ld_data_db, ld_tag_db, nullptr, nullptr); // The loaded data should be all zeros. for (int i = 0; i < 16; i++) { @@ -387,14 +387,14 @@ LogSink log_sink; absl::AddLogSink(&log_sink); auto mem = std::make_unique<TaggedFlatDemandMemory>(kTagGranule); - DataBuffer *ld_data_db = + DataBuffer* ld_data_db = arch_state_->db_factory()->Allocate<uint8_t>(kTagGranule * 16); - DataBuffer *ld_tag_db = arch_state_->db_factory()->Allocate<uint8_t>(16); + DataBuffer* ld_tag_db = arch_state_->db_factory()->Allocate<uint8_t>(16); ld_data_db->set_latency(0); ld_tag_db->set_latency(0); - DataBuffer *st_data_db = + DataBuffer* st_data_db = arch_state_->db_factory()->Allocate<uint8_t>(kTagGranule * 16); - DataBuffer *st_tag_db = arch_state_->db_factory()->Allocate<uint8_t>(16); + DataBuffer* st_tag_db = arch_state_->db_factory()->Allocate<uint8_t>(16); // Write tagged data to memory. for (int i = 0; i < st_data_db->size<uint8_t>(); i++) { st_data_db->Set<uint8_t>(i, i); @@ -409,7 +409,7 @@ EXPECT_EQ(ld_tag_db->Get<uint8_t>(i), 1); } // Clear tags with non-tagged stores. - DataBuffer *st_untagged_db = arch_state_->db_factory()->Allocate<uint8_t>(1); + DataBuffer* st_untagged_db = arch_state_->db_factory()->Allocate<uint8_t>(1); for (int i = 0; i < st_data_db->size<uint8_t>(); i++) { st_untagged_db->Set<uint8_t>(0, st_data_db->size<uint8_t>() - i); mem->Store(0x1000 + i, st_untagged_db);
diff --git a/mpact/sim/util/other/instruction_profiler.cc b/mpact/sim/util/other/instruction_profiler.cc index ab0947e..85941fa 100644 --- a/mpact/sim/util/other/instruction_profiler.cc +++ b/mpact/sim/util/other/instruction_profiler.cc
@@ -29,7 +29,7 @@ namespace mpact::sim::util { -InstructionProfiler::InstructionProfiler(ElfProgramLoader &elf_loader, +InstructionProfiler::InstructionProfiler(ElfProgramLoader& elf_loader, unsigned granularity) : elf_loader_(&elf_loader) { if (!absl::has_single_bit(granularity)) { @@ -50,7 +50,7 @@ } InstructionProfiler::~InstructionProfiler() { - for (auto const &[unused, counters] : profile_ranges_) { + for (auto const& [unused, counters] : profile_ranges_) { delete[] counters; } profile_ranges_.clear(); @@ -72,9 +72,9 @@ last_profile_range_[sample - last_start_]++; } -void InstructionProfiler::WriteProfile(std::ostream &os) { +void InstructionProfiler::WriteProfile(std::ostream& os) { os << "Address,Count" << "\n"; - for (auto const &[range, counters] : profile_ranges_) { + for (auto const& [range, counters] : profile_ranges_) { uint64_t size = range.end - range.start; for (auto i = 0; i < size; ++i) { if (counters[i] == 0) continue; @@ -84,7 +84,7 @@ } } -void InstructionProfiler::SetElfLoader(ElfProgramLoader *elf_loader) { +void InstructionProfiler::SetElfLoader(ElfProgramLoader* elf_loader) { elf_loader_ = elf_loader; uint64_t begin = 0; uint64_t end = 0; @@ -92,7 +92,7 @@ // coalesces ranges that are spaced by less than 0x1'000 units of granularity. // This reduces the number of ranges in the map and improves performance // during simulation. - for (auto const &segment : elf_loader_->elf_reader()->segments) { + for (auto const& segment : elf_loader_->elf_reader()->segments) { // Only consider segments that are loaded, executable, and with size > 0. if (segment->get_type() != PT_LOAD) continue; if ((segment->get_flags() & PF_X) == 0) continue; @@ -115,7 +115,7 @@ // Otherwise, create a entry from the previously accumulated ranges, and // start a new range. size = end - begin - 1; - uint64_t *counters = new uint64_t[size]; + uint64_t* counters = new uint64_t[size]; ::memset(counters, 0, size * sizeof(uint64_t)); profile_ranges_.insert( std::make_pair(MemoryWatcher::AddressRange{begin, end}, counters)); @@ -125,7 +125,7 @@ // Make the last entry. if (begin != 0 || end != 0) { uint64_t size = end - begin - 1; - uint64_t *counters = new uint64_t[size]; + uint64_t* counters = new uint64_t[size]; ::memset(counters, 0, size * sizeof(uint64_t)); profile_ranges_.insert( std::make_pair(MemoryWatcher::AddressRange{begin, end - 1}, counters));
diff --git a/mpact/sim/util/other/instruction_profiler.h b/mpact/sim/util/other/instruction_profiler.h index 058770b..35fbf35 100644 --- a/mpact/sim/util/other/instruction_profiler.h +++ b/mpact/sim/util/other/instruction_profiler.h
@@ -43,14 +43,14 @@ // The granularity is a power of two and determines the value difference // between two adjacent sample buckets. For instruction profiling this is // the smallest instruction size in bytes. - InstructionProfiler(ElfProgramLoader &elf_loader, unsigned granularity); + InstructionProfiler(ElfProgramLoader& elf_loader, unsigned granularity); explicit InstructionProfiler(unsigned granularity); ~InstructionProfiler() override; // Inherited from CounterValueSetInterface. This will connect to a counter // that is assigned the value to profile. The most recently used range is // cached for performance. If it doesn't match, call AddSampleInternal(). - void SetValue(const uint64_t &value) override { + void SetValue(const uint64_t& value) override { // See if the previously referenced range applies. uint64_t sample = value >> shift_; if ((sample >= last_start_) && (sample <= last_end_)) { @@ -61,22 +61,22 @@ } // Write the profile to the given stream in csv format. - void WriteProfile(std::ostream &os); + void WriteProfile(std::ostream& os); // If the elf loader wasn't set in the constructor, use this method to set // it once the elf file is available. - void SetElfLoader(ElfProgramLoader *elf_loader); + void SetElfLoader(ElfProgramLoader* elf_loader); private: void AddSampleInternal(uint64_t sample); int shift_ = 0; - ElfProgramLoader *elf_loader_ = nullptr; - absl::btree_map<MemoryWatcher::AddressRange, uint64_t *, + ElfProgramLoader* elf_loader_ = nullptr; + absl::btree_map<MemoryWatcher::AddressRange, uint64_t*, MemoryWatcher::AddressRangeLess> profile_ranges_; uint64_t last_start_ = 0xffff'ffff'ffff'ffffULL; uint64_t last_end_ = 0xffff'ffff'ffff'ffffULL; - uint64_t *last_profile_range_ = nullptr; + uint64_t* last_profile_range_ = nullptr; }; } // namespace mpact::sim::util
diff --git a/mpact/sim/util/other/simple_uart.cc b/mpact/sim/util/other/simple_uart.cc index ffbe3bb..949f911 100644 --- a/mpact/sim/util/other/simple_uart.cc +++ b/mpact/sim/util/other/simple_uart.cc
@@ -10,13 +10,13 @@ namespace mpact::sim::util { // Constructors. -SimpleUart::SimpleUart(ArchState *state, std::ostream &output) +SimpleUart::SimpleUart(ArchState* state, std::ostream& output) : output_(&output) {} -SimpleUart::SimpleUart(ArchState *state) : SimpleUart(state, std::cerr) {} +SimpleUart::SimpleUart(ArchState* state) : SimpleUart(state, std::cerr) {} -void SimpleUart::Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void SimpleUart::Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) { // If the address is unaligned, or the size is not a multiple of 4, it should // really be handled before it gets this far. Set the db to zero and finish // the load. @@ -47,13 +47,13 @@ } // No support for vector loads. -void SimpleUart::Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void SimpleUart::Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) { LOG(FATAL) << "SimpleUart does not support vector loads"; } -void SimpleUart::Store(uint64_t address, DataBuffer *db) { +void SimpleUart::Store(uint64_t address, DataBuffer* db) { // If the address is unaligned, or the size is not a multiple of 4, it should // really be handled before it gets this far. Set the db to zero and finish // the load. @@ -156,8 +156,8 @@ } // No support for vector stores. -void SimpleUart::Store(DataBuffer *address, DataBuffer *mask_db, int el_size, - DataBuffer *db) { +void SimpleUart::Store(DataBuffer* address, DataBuffer* mask_db, int el_size, + DataBuffer* db) { LOG(FATAL) << "SimpleUart does not support vector stores"; }
diff --git a/mpact/sim/util/other/simple_uart.h b/mpact/sim/util/other/simple_uart.h index 6142440..3cff450 100644 --- a/mpact/sim/util/other/simple_uart.h +++ b/mpact/sim/util/other/simple_uart.h
@@ -38,19 +38,19 @@ public: // Constructors. // Instantiate the uart and set the output to std::cerr. - explicit SimpleUart(ArchState *state); + explicit SimpleUart(ArchState* state); // Instantiate the uart and set the output to the given ostream. - SimpleUart(ArchState *state, std::ostream &output); + SimpleUart(ArchState* state, std::ostream& output); // Memory interface methods used to write to the memory mapped registers. - void Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; - void Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; - void Store(uint64_t address, DataBuffer *db) override; - void Store(DataBuffer *address, DataBuffer *mask_db, int el_size, - DataBuffer *db) override; + void Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; + void Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; + void Store(uint64_t address, DataBuffer* db) override; + void Store(DataBuffer* address, DataBuffer* mask_db, int el_size, + DataBuffer* db) override; private: // Helper methods. @@ -65,7 +65,7 @@ uint32_t divisor_low_byte_ = 0; uint32_t interrupt_enable_ = 0; uint32_t scratch_; - std::ostream *output_; + std::ostream* output_; }; } // namespace mpact::sim::util
diff --git a/mpact/sim/util/program_loader/elf_program_loader.cc b/mpact/sim/util/program_loader/elf_program_loader.cc index 8371a9c..4c7e5a6 100644 --- a/mpact/sim/util/program_loader/elf_program_loader.cc +++ b/mpact/sim/util/program_loader/elf_program_loader.cc
@@ -37,18 +37,18 @@ constexpr uint64_t kPtGnuStack = 0x6474e551; -ElfProgramLoader::ElfProgramLoader(util::MemoryInterface *code_memory, - util::MemoryInterface *data_memory) +ElfProgramLoader::ElfProgramLoader(util::MemoryInterface* code_memory, + util::MemoryInterface* data_memory) : code_memory_(code_memory), data_memory_(data_memory) {} -ElfProgramLoader::ElfProgramLoader(util::MemoryInterface *memory) +ElfProgramLoader::ElfProgramLoader(util::MemoryInterface* memory) : code_memory_(memory), data_memory_(memory) {} -ElfProgramLoader::ElfProgramLoader(generic::CoreDebugInterface *dbg_if) +ElfProgramLoader::ElfProgramLoader(generic::CoreDebugInterface* dbg_if) : dbg_if_(dbg_if) {} ElfProgramLoader::~ElfProgramLoader() { - for (auto *symtab : symbol_accessors_) { + for (auto* symtab : symbol_accessors_) { delete symtab; } symbol_accessors_.clear(); @@ -56,7 +56,7 @@ // Only load the program into the elf reader so that symbols can be looked up. absl::StatusOr<uint64_t> ElfProgramLoader::LoadSymbols( - const std::string &file_name) { + const std::string& file_name) { struct stat buffer; auto result = stat(file_name.c_str(), &buffer); if (result == -1) { @@ -74,7 +74,7 @@ } loaded_ = true; // Now look up any symbol sections. - for (auto const §ion : elf_reader_.sections) { + for (auto const& section : elf_reader_.sections) { if (section->get_type() == SHT_SYMTAB) { symbol_accessors_.push_back( new ELFIO::symbol_section_accessor(elf_reader_, section)); @@ -87,7 +87,7 @@ ELFIO::Elf_Half section_index; unsigned char other; // Scan symbol table. Place function names in a map for easy lookup. - for (auto *symtab : symbol_accessors_) { + for (auto* symtab : symbol_accessors_) { ELFIO::Elf64_Addr value; for (unsigned i = 0; i < symtab->get_symbols_num(); i++) { symtab->get_symbol(i, name, value, size, bind, type, section_index, @@ -106,13 +106,13 @@ // and iterates over the segments. For each segment it writes it to the // appropriate location in the given memories. absl::StatusOr<uint64_t> ElfProgramLoader::LoadProgram( - const std::string &file_name) { + const std::string& file_name) { auto load_symbols_res = LoadSymbols(file_name); if (!load_symbols_res.ok()) return load_symbols_res.status(); generic::DataBufferFactory db_factory; - for (auto const &segment : elf_reader_.segments) { + for (auto const& segment : elf_reader_.segments) { if (segment->get_type() == kPtGnuStack) { stack_size_ = segment->get_memory_size(); has_stack_size_ = (stack_size_ > 0); @@ -123,7 +123,7 @@ if (segment->get_file_size() == 0) continue; // Read the data from the elf file. if (dbg_if_ == nullptr) { // Use memory interfaces. - auto *db = db_factory.Allocate(segment->get_file_size()); + auto* db = db_factory.Allocate(segment->get_file_size()); std::memcpy(db->raw_ptr(), segment->get_data(), segment->get_file_size()); if (segment->get_flags() & @@ -148,7 +148,7 @@ } absl::StatusOr<std::pair<uint64_t, uint64_t>> ElfProgramLoader::GetSymbol( - const std::string &name) const { + const std::string& name) const { if (!loaded_) return absl::InternalError("No program loaded"); if (symbol_accessors_.empty()) return absl::NotFoundError("Symbol table not found"); @@ -159,7 +159,7 @@ unsigned char type; ELFIO::Elf_Half section_index; unsigned char other; - for (auto *symtab : symbol_accessors_) { + for (auto* symtab : symbol_accessors_) { if (symtab->get_symbol(name, value, size, bind, type, section_index, other)) { return std::make_pair(static_cast<uint64_t>(value),
diff --git a/mpact/sim/util/program_loader/elf_program_loader.h b/mpact/sim/util/program_loader/elf_program_loader.h index f023bfb..760f11b 100644 --- a/mpact/sim/util/program_loader/elf_program_loader.h +++ b/mpact/sim/util/program_loader/elf_program_loader.h
@@ -43,7 +43,7 @@ }; struct AddressRangeComp { - bool operator()(const AddressRange &lhs, const AddressRange &rhs) const { + bool operator()(const AddressRange& lhs, const AddressRange& rhs) const { if (lhs.end <= rhs.start) { return true; } @@ -61,19 +61,19 @@ // memory. class ElfProgramLoader : public ProgramLoaderInterface { public: - ElfProgramLoader(util::MemoryInterface *code_memory, - util::MemoryInterface *data_memory); - explicit ElfProgramLoader(util::MemoryInterface *memory); - explicit ElfProgramLoader(generic::CoreDebugInterface *dbg_if); + ElfProgramLoader(util::MemoryInterface* code_memory, + util::MemoryInterface* data_memory); + explicit ElfProgramLoader(util::MemoryInterface* memory); + explicit ElfProgramLoader(generic::CoreDebugInterface* dbg_if); ElfProgramLoader() = delete; ~ElfProgramLoader() override; - absl::StatusOr<uint64_t> LoadSymbols(const std::string &file_name) override; - absl::StatusOr<uint64_t> LoadProgram(const std::string &file_name) override; + absl::StatusOr<uint64_t> LoadSymbols(const std::string& file_name) override; + absl::StatusOr<uint64_t> LoadProgram(const std::string& file_name) override; // Return the value and size of the symbol 'name' if it exists in the symbol // table. absl::StatusOr<std::pair<uint64_t, uint64_t>> GetSymbol( - const std::string &name) const; + const std::string& name) const; // If there is a function with symbol table value 'address' return its name. absl::StatusOr<std::string> GetFcnSymbolName(uint64_t address) const; // Looks up to see if the address is in the range of a function symbol, and @@ -82,15 +82,15 @@ // If the GNU stack size program header exists, return the memory size. absl::StatusOr<uint64_t> GetStackSize() const; - const ELFIO::elfio *elf_reader() const { return &elf_reader_; } + const ELFIO::elfio* elf_reader() const { return &elf_reader_; } private: bool loaded_ = false; ELFIO::elfio elf_reader_; - util::MemoryInterface *code_memory_ = nullptr; - util::MemoryInterface *data_memory_ = nullptr; - generic::CoreDebugInterface *dbg_if_ = nullptr; - std::vector<const ELFIO::symbol_section_accessor *> symbol_accessors_; + util::MemoryInterface* code_memory_ = nullptr; + util::MemoryInterface* data_memory_ = nullptr; + generic::CoreDebugInterface* dbg_if_ = nullptr; + std::vector<const ELFIO::symbol_section_accessor*> symbol_accessors_; absl::flat_hash_map<uint64_t, std::string> fcn_symbol_map_; std::map<AddressRange, std::string, AddressRangeComp> function_range_map_; uint64_t has_stack_size_ = false;
diff --git a/mpact/sim/util/program_loader/program_loader_interface.h b/mpact/sim/util/program_loader/program_loader_interface.h index ab88564..f6b5118 100644 --- a/mpact/sim/util/program_loader/program_loader_interface.h +++ b/mpact/sim/util/program_loader/program_loader_interface.h
@@ -30,10 +30,10 @@ // Load the executable into the program loader, but don't write segments to // memory. Return the entry point. virtual absl::StatusOr<uint64_t> LoadSymbols( - const std::string &file_name) = 0; + const std::string& file_name) = 0; // Write program segments to memories and return the entry point. virtual absl::StatusOr<uint64_t> LoadProgram( - const std::string &file_name) = 0; + const std::string& file_name) = 0; }; } // namespace util
diff --git a/mpact/sim/util/program_loader/test/elf_program_loader_test.cc b/mpact/sim/util/program_loader/test/elf_program_loader_test.cc index 0682961..6ef8f6e 100644 --- a/mpact/sim/util/program_loader/test/elf_program_loader_test.cc +++ b/mpact/sim/util/program_loader/test/elf_program_loader_test.cc
@@ -77,12 +77,12 @@ ASSERT_THAT(elf_reader_.validate(), testing::StrEq("")); auto result = loader_.LoadProgram(input_file); ASSERT_TRUE(result.status().ok()); - for (auto const &segment : elf_reader_.segments) { + for (auto const& segment : elf_reader_.segments) { if (segment->get_type() != PT_LOAD) continue; if (segment->get_file_size() == 0) continue; int size = segment->get_file_size(); - auto *db = db_factory_.Allocate(size); + auto* db = db_factory_.Allocate(size); memory_.Load(segment->get_virtual_address(), db, nullptr, nullptr); EXPECT_EQ(memcmp(db->raw_ptr(), segment->get_data(), size), 0); db->DecRef();
diff --git a/mpact/sim/util/renode/cli_forwarder.cc b/mpact/sim/util/renode/cli_forwarder.cc index dffe1c8..3a05645 100644 --- a/mpact/sim/util/renode/cli_forwarder.cc +++ b/mpact/sim/util/renode/cli_forwarder.cc
@@ -34,7 +34,7 @@ using HaltReasonValueType = ::mpact::sim::generic::CoreDebugInterface::HaltReasonValueType; -CLIForwarder::CLIForwarder(RenodeCLITop *top) : top_(top) {} +CLIForwarder::CLIForwarder(RenodeCLITop* top) : top_(top) {} // Forward the calls to the CheriotRenodeCLITop class - CLI methods. @@ -54,27 +54,27 @@ return top_->CLIGetLastHaltReason(); } -absl::StatusOr<uint64_t> CLIForwarder::ReadRegister(const std::string &name) { +absl::StatusOr<uint64_t> CLIForwarder::ReadRegister(const std::string& name) { return top_->CLIReadRegister(name); } -absl::Status CLIForwarder::WriteRegister(const std::string &name, +absl::Status CLIForwarder::WriteRegister(const std::string& name, uint64_t value) { return top_->CLIWriteRegister(name, value); } -absl::StatusOr<DataBuffer *> CLIForwarder::GetRegisterDataBuffer( - const std::string &name) { +absl::StatusOr<DataBuffer*> CLIForwarder::GetRegisterDataBuffer( + const std::string& name) { return top_->CLIGetRegisterDataBuffer(name); } -absl::StatusOr<size_t> CLIForwarder::ReadMemory(uint64_t address, void *buf, +absl::StatusOr<size_t> CLIForwarder::ReadMemory(uint64_t address, void* buf, size_t length) { return top_->CLIReadMemory(address, buf, length); } absl::StatusOr<size_t> CLIForwarder::WriteMemory(uint64_t address, - const void *buf, + const void* buf, size_t length) { return top_->CLIWriteMemory(address, buf, length); } @@ -95,7 +95,7 @@ return top_->CLIClearAllSwBreakpoints(); } -absl::StatusOr<Instruction *> CLIForwarder::GetInstruction(uint64_t address) { +absl::StatusOr<Instruction*> CLIForwarder::GetInstruction(uint64_t address) { return top_->CLIGetInstruction(address); }
diff --git a/mpact/sim/util/renode/cli_forwarder.h b/mpact/sim/util/renode/cli_forwarder.h index 139bee5..f253c4b 100644 --- a/mpact/sim/util/renode/cli_forwarder.h +++ b/mpact/sim/util/renode/cli_forwarder.h
@@ -37,10 +37,10 @@ class CLIForwarder : public CoreDebugInterface { public: - explicit CLIForwarder(RenodeCLITop *top); + explicit CLIForwarder(RenodeCLITop* top); CLIForwarder() = delete; - CLIForwarder(const CLIForwarder &) = delete; - CLIForwarder &operator=(const CLIForwarder &) = delete; + CLIForwarder(const CLIForwarder&) = delete; + CLIForwarder& operator=(const CLIForwarder&) = delete; ~CLIForwarder() override = default; @@ -62,8 +62,8 @@ absl::StatusOr<HaltReasonValueType> GetLastHaltReason() override; // Read/write the named registers. - absl::StatusOr<uint64_t> ReadRegister(const std::string &name) override; - absl::Status WriteRegister(const std::string &name, uint64_t value) override; + absl::StatusOr<uint64_t> ReadRegister(const std::string& name) override; + absl::Status WriteRegister(const std::string& name, uint64_t value) override; // Some registers, including vector registers, have values that exceed the // 64 bits supported in the Read/Write register API calls. This function @@ -75,13 +75,13 @@ // Note (2): In some cases, a register write may replace the DataBuffer // instance within a register so that any stored references to it become // stale. - absl::StatusOr<DataBuffer *> GetRegisterDataBuffer( - const std::string &name) override; + absl::StatusOr<DataBuffer*> GetRegisterDataBuffer( + const std::string& name) override; // Read/write the buffers to memory. - absl::StatusOr<size_t> ReadMemory(uint64_t address, void *buf, + absl::StatusOr<size_t> ReadMemory(uint64_t address, void* buf, size_t length) override; - absl::StatusOr<size_t> WriteMemory(uint64_t address, const void *buf, + absl::StatusOr<size_t> WriteMemory(uint64_t address, const void* buf, size_t length) override; // Test to see if there's a breakpoint at the given address. @@ -93,12 +93,12 @@ absl::Status ClearAllSwBreakpoints() override; // Return the instruction object for the instruction at the given address. - absl::StatusOr<Instruction *> GetInstruction(uint64_t address) override; + absl::StatusOr<Instruction*> GetInstruction(uint64_t address) override; // Return the string representation for the instruction at the given address. absl::StatusOr<std::string> GetDisassembly(uint64_t address) override; private: - RenodeCLITop *top_; + RenodeCLITop* top_; }; } // namespace renode
diff --git a/mpact/sim/util/renode/renode_cli_top.cc b/mpact/sim/util/renode/renode_cli_top.cc index 2c0947e..6292c2b 100644 --- a/mpact/sim/util/renode/renode_cli_top.cc +++ b/mpact/sim/util/renode/renode_cli_top.cc
@@ -36,7 +36,7 @@ using ::mpact::sim::generic::CoreDebugInterface; using ::mpact::sim::generic::operator*; // NOLINT: used below (clang error). -RenodeCLITop::RenodeCLITop(CoreDebugInterface *top, bool wait_for_cli) +RenodeCLITop::RenodeCLITop(CoreDebugInterface* top, bool wait_for_cli) : top_(top), wait_for_cli_(wait_for_cli) { absl::MutexLock lock(&run_control_mutex_); cli_status_ = wait_for_cli_ ? RunStatus::kHalted : RunStatus::kRunning; @@ -117,23 +117,23 @@ } absl::StatusOr<uint64_t> RenodeCLITop::RenodeReadRegister( - const std::string &name) { + const std::string& name) { return top_->ReadRegister(name); } -absl::Status RenodeCLITop::RenodeWriteRegister(const std::string &name, +absl::Status RenodeCLITop::RenodeWriteRegister(const std::string& name, uint64_t value) { return top_->WriteRegister(name, value); } absl::StatusOr<size_t> RenodeCLITop::RenodeReadMemory(uint64_t address, - void *buf, + void* buf, size_t length) { return top_->ReadMemory(address, buf, length); } absl::StatusOr<size_t> RenodeCLITop::RenodeWriteMemory(uint64_t address, - const void *buf, + const void* buf, size_t length) { return top_->WriteMemory(address, buf, length); } @@ -243,24 +243,24 @@ } absl::StatusOr<uint64_t> RenodeCLITop::CLIReadRegister( - const std::string &name) { + const std::string& name) { return DoWhenInControl<absl::StatusOr<uint64_t>>( [this, &name]() { return top_->ReadRegister(name); }); } -absl::Status RenodeCLITop::CLIWriteRegister(const std::string &name, +absl::Status RenodeCLITop::CLIWriteRegister(const std::string& name, uint64_t value) { return DoWhenInControl<absl::Status>( [this, &name, &value]() { return top_->WriteRegister(name, value); }); } -absl::StatusOr<generic::DataBuffer *> RenodeCLITop::CLIGetRegisterDataBuffer( - const std::string &name) { - return DoWhenInControl<absl::StatusOr<generic::DataBuffer *>>( +absl::StatusOr<generic::DataBuffer*> RenodeCLITop::CLIGetRegisterDataBuffer( + const std::string& name) { + return DoWhenInControl<absl::StatusOr<generic::DataBuffer*>>( [this, &name]() { return top_->GetRegisterDataBuffer(name); }); } -absl::StatusOr<size_t> RenodeCLITop::CLIReadMemory(uint64_t address, void *buf, +absl::StatusOr<size_t> RenodeCLITop::CLIReadMemory(uint64_t address, void* buf, size_t length) { return DoWhenInControl<absl::StatusOr<size_t>>( [this, &address, &buf, &length]() { @@ -269,7 +269,7 @@ } absl::StatusOr<size_t> RenodeCLITop::CLIWriteMemory(uint64_t address, - const void *buf, + const void* buf, size_t length) { return DoWhenInControl<absl::StatusOr<size_t>>( [this, &address, &buf, &length]() { @@ -297,9 +297,8 @@ [this]() { return top_->ClearAllSwBreakpoints(); }); } -absl::StatusOr<Instruction *> RenodeCLITop::CLIGetInstruction( - uint64_t address) { - return DoWhenInControl<absl::StatusOr<Instruction *>>( +absl::StatusOr<Instruction*> RenodeCLITop::CLIGetInstruction(uint64_t address) { + return DoWhenInControl<absl::StatusOr<Instruction*>>( [this, &address]() { return top_->GetInstruction(address); }); } @@ -309,12 +308,12 @@ } void RenodeCLITop::CLIRequestHalt(HaltReason halt_reason, - const Instruction *inst) { + const Instruction* inst) { (void)top_->Halt(halt_reason); } void RenodeCLITop::CLIRequestHalt(HaltReasonValueType halt_reason, - const Instruction *inst) { + const Instruction* inst) { (void)top_->Halt(halt_reason); }
diff --git a/mpact/sim/util/renode/renode_cli_top.h b/mpact/sim/util/renode/renode_cli_top.h index 5945565..7059421 100644 --- a/mpact/sim/util/renode/renode_cli_top.h +++ b/mpact/sim/util/renode/renode_cli_top.h
@@ -45,7 +45,7 @@ // line interface and forwards them to the top simulator control interface. class RenodeCLITop { public: - RenodeCLITop(CoreDebugInterface *top, bool wait_for_cli); + RenodeCLITop(CoreDebugInterface* top, bool wait_for_cli); virtual ~RenodeCLITop() = default; // Set the connected status of the command line interface. @@ -58,14 +58,14 @@ // Get the reason for the last halt. virtual absl::StatusOr<HaltReasonValueType> RenodeGetLastHaltReason(); // Register access by register name. - virtual absl::StatusOr<uint64_t> RenodeReadRegister(const std::string &name); - virtual absl::Status RenodeWriteRegister(const std::string &name, + virtual absl::StatusOr<uint64_t> RenodeReadRegister(const std::string& name); + virtual absl::Status RenodeWriteRegister(const std::string& name, uint64_t value); // Read and Write memory methods bypass any semihosting. - virtual absl::StatusOr<size_t> RenodeReadMemory(uint64_t address, void *buf, + virtual absl::StatusOr<size_t> RenodeReadMemory(uint64_t address, void* buf, size_t length); virtual absl::StatusOr<size_t> RenodeWriteMemory(uint64_t address, - const void *buf, + const void* buf, size_t length); // Methods that handle requests from Command Line Interface. @@ -79,28 +79,28 @@ // Wait for free run to complete. virtual absl::Status CLIWait(); virtual absl::StatusOr<RunStatus> CLIGetRunStatus(); - virtual void CLIRequestHalt(HaltReason halt_reason, const Instruction *inst); + virtual void CLIRequestHalt(HaltReason halt_reason, const Instruction* inst); virtual void CLIRequestHalt(HaltReasonValueType halt_reason, - const Instruction *inst); + const Instruction* inst); virtual absl::StatusOr<HaltReasonValueType> CLIGetLastHaltReason(); // Register access by register name. - virtual absl::StatusOr<uint64_t> CLIReadRegister(const std::string &name); - virtual absl::Status CLIWriteRegister(const std::string &name, + virtual absl::StatusOr<uint64_t> CLIReadRegister(const std::string& name); + virtual absl::Status CLIWriteRegister(const std::string& name, uint64_t value); - virtual absl::StatusOr<DataBuffer *> CLIGetRegisterDataBuffer( - const std::string &name); + virtual absl::StatusOr<DataBuffer*> CLIGetRegisterDataBuffer( + const std::string& name); // Read and Write memory methods bypass any semihosting. - virtual absl::StatusOr<size_t> CLIReadMemory(uint64_t address, void *buf, + virtual absl::StatusOr<size_t> CLIReadMemory(uint64_t address, void* buf, size_t length); virtual absl::StatusOr<size_t> CLIWriteMemory(uint64_t address, - const void *buf, size_t length); + const void* buf, size_t length); // Breakpoint and watchpoint management. virtual bool CLIHasBreakpoint(uint64_t address); virtual absl::Status CLISetSwBreakpoint(uint64_t address); virtual absl::Status CLIClearSwBreakpoint(uint64_t address); virtual absl::Status CLIClearAllSwBreakpoints(); - virtual absl::StatusOr<Instruction *> CLIGetInstruction(uint64_t address); + virtual absl::StatusOr<Instruction*> CLIGetInstruction(uint64_t address); virtual absl::StatusOr<std::string> CLIGetDisassembly(uint64_t address); protected: @@ -109,11 +109,11 @@ template <typename T> T DoWhenInControl(absl::AnyInvocable<T(void)> action); // Accessor. - CoreDebugInterface *top() const { return top_; } + CoreDebugInterface* top() const { return top_; } private: bool IsCLIInControl() const; - CoreDebugInterface *top_ = nullptr; + CoreDebugInterface* top_ = nullptr; // Mutex that determines which of ReNode and the command line interface has // control over the simulator control interface. absl::Mutex run_control_mutex_;
diff --git a/mpact/sim/util/renode/renode_debug_interface.h b/mpact/sim/util/renode/renode_debug_interface.h index 401da5b..3d8ea55 100644 --- a/mpact/sim/util/renode/renode_debug_interface.h +++ b/mpact/sim/util/renode/renode_debug_interface.h
@@ -49,7 +49,7 @@ using generic::CoreDebugInterface::WriteRegister; // Load executable or load symbols from executable. - virtual absl::StatusOr<uint64_t> LoadExecutable(const char *elf_file_name, + virtual absl::StatusOr<uint64_t> LoadExecutable(const char* elf_file_name, bool for_symbols_only) = 0; // Read/write the numeric id registers. @@ -58,11 +58,11 @@ // Get register information. virtual int32_t GetRenodeRegisterInfoSize() const = 0; virtual absl::Status GetRenodeRegisterInfo(int32_t index, int32_t max_len, - char *name, - RenodeCpuRegister &info) = 0; + char* name, + RenodeCpuRegister& info) = 0; // Set configuration item. - virtual absl::Status SetConfig(const char *config_names[], - const char *config_values[], int size) = 0; + virtual absl::Status SetConfig(const char* config_names[], + const char* config_values[], int size) = 0; // Set IRQ. virtual absl::Status SetIrqValue(int32_t irq_num, bool irq_value) = 0; @@ -89,14 +89,14 @@ absl::StatusOr<RunStatus> GetRunStatus() final { return absl::InternalError("GetRunStatus: Not implemented"); } - absl::StatusOr<uint64_t> ReadRegister(const std::string &name) final { + absl::StatusOr<uint64_t> ReadRegister(const std::string& name) final { return absl::InternalError("ReadRegister: Not implemented"); } - absl::Status WriteRegister(const std::string &name, uint64_t value) final { + absl::Status WriteRegister(const std::string& name, uint64_t value) final { return absl::InternalError("WriteRegister: Not implemented"); } - absl::StatusOr<mpact::sim::generic::DataBuffer *> GetRegisterDataBuffer( - const std::string &) final { + absl::StatusOr<mpact::sim::generic::DataBuffer*> GetRegisterDataBuffer( + const std::string&) final { return absl::InternalError("GetRegisterDataBuffer: Not implemented"); } bool HasBreakpoint(uint64_t address) final { return false; } @@ -109,7 +109,7 @@ absl::Status ClearAllSwBreakpoints() final { return absl::InternalError("ClearAllSwBreakpoints: Not implemented"); } - absl::StatusOr<mpact::sim::generic::Instruction *> GetInstruction( + absl::StatusOr<mpact::sim::generic::Instruction*> GetInstruction( uint64_t address) final { return absl::InternalError("GetInstruction: Not implemented"); }
diff --git a/mpact/sim/util/renode/renode_memory_access.cc b/mpact/sim/util/renode/renode_memory_access.cc index 919e37f..6b9b39a 100644 --- a/mpact/sim/util/renode/renode_memory_access.cc +++ b/mpact/sim/util/renode/renode_memory_access.cc
@@ -29,8 +29,8 @@ using ::mpact::sim::generic::ReferenceCount; // Process the load using the interface to the ReNode system bus to fetch data. -void RenodeMemoryAccess::Load(uint64_t address, DataBuffer *db, - Instruction *inst, ReferenceCount *context) { +void RenodeMemoryAccess::Load(uint64_t address, DataBuffer* db, + Instruction* inst, ReferenceCount* context) { if (read_fcn_ == nullptr) { LOG(WARNING) << "RenodeMemoryAccess: read_fcn_ is null"; std::memset(db->raw_ptr(), 0, db->size<uint8_t>()); @@ -39,8 +39,7 @@ } int32_t size = db->size<uint8_t>(); // Call the C# function delegate. - auto bytes_read = - read_fcn_(address, static_cast<char *>(db->raw_ptr()), size); + auto bytes_read = read_fcn_(address, static_cast<char*>(db->raw_ptr()), size); if (size != bytes_read) { LOG(ERROR) << "Failed to read " << size - bytes_read << " bytes of " << size; @@ -49,16 +48,16 @@ } // TODO(torerik): add vector load functionality. -void RenodeMemoryAccess::Load(DataBuffer *address_db, DataBuffer *mask_db, - int el_size, DataBuffer *db, Instruction *inst, - ReferenceCount *context) { +void RenodeMemoryAccess::Load(DataBuffer* address_db, DataBuffer* mask_db, + int el_size, DataBuffer* db, Instruction* inst, + ReferenceCount* context) { LOG(ERROR) << "RenodeMemoryAccess: Vector loads are not supported"; } // Complete the load by writing back (or scheduling the write back of) the // fetched data. -void RenodeMemoryAccess::FinishLoad(int latency, Instruction *inst, - ReferenceCount *context) { +void RenodeMemoryAccess::FinishLoad(int latency, Instruction* inst, + ReferenceCount* context) { if (inst == nullptr) return; // If the latency is 0, execute the instruction immediately. if (latency == 0) { @@ -79,7 +78,7 @@ } // Process the store using the interface to the ReNode system bus to store data. -void RenodeMemoryAccess::Store(uint64_t address, DataBuffer *db) { +void RenodeMemoryAccess::Store(uint64_t address, DataBuffer* db) { if (write_fcn_ == nullptr) { LOG(WARNING) << "RenodeMemoryAccess: write_fcn_ is null"; return; @@ -87,7 +86,7 @@ int32_t size = db->size<uint8_t>(); // Call the C# function delegate. auto bytes_written = - write_fcn_(address, static_cast<char *>(db->raw_ptr()), size); + write_fcn_(address, static_cast<char*>(db->raw_ptr()), size); if (size != bytes_written) { LOG(ERROR) << "Failed to write " << size - bytes_written << " bytes of " << size; @@ -95,8 +94,8 @@ } // TODO(torerik): add vector store functionality. -void RenodeMemoryAccess::Store(DataBuffer *address, DataBuffer *mask, - int el_size, DataBuffer *db) { +void RenodeMemoryAccess::Store(DataBuffer* address, DataBuffer* mask, + int el_size, DataBuffer* db) { LOG(ERROR) << "RenodeMemoryAccess: Vector stores are not supported"; }
diff --git a/mpact/sim/util/renode/renode_memory_access.h b/mpact/sim/util/renode/renode_memory_access.h index fbded36..5a0c10a 100644 --- a/mpact/sim/util/renode/renode_memory_access.h +++ b/mpact/sim/util/renode/renode_memory_access.h
@@ -38,7 +38,7 @@ public: // Function call signature for the sysbus read/write methods. using RenodeMemoryFunction = - absl::AnyInvocable<int32_t(uint64_t, char *, int32_t)>; + absl::AnyInvocable<int32_t(uint64_t, char*, int32_t)>; RenodeMemoryAccess(RenodeMemoryFunction read_fcn, RenodeMemoryFunction write_fcn) @@ -46,17 +46,17 @@ // MemoryInterface methods. // Single item load. - void Load(uint64_t address, DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; + void Load(uint64_t address, DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; // Vector load. - void Load(DataBuffer *address_db, DataBuffer *mask_db, int el_size, - DataBuffer *db, Instruction *inst, - ReferenceCount *context) override; + void Load(DataBuffer* address_db, DataBuffer* mask_db, int el_size, + DataBuffer* db, Instruction* inst, + ReferenceCount* context) override; // Single item store. - void Store(uint64_t address, DataBuffer *db) override; + void Store(uint64_t address, DataBuffer* db) override; // Vector store. - void Store(DataBuffer *address, DataBuffer *mask, int el_size, - DataBuffer *db) override; + void Store(DataBuffer* address, DataBuffer* mask, int el_size, + DataBuffer* db) override; bool has_read_fcn() const { return read_fcn_ != nullptr; } bool has_write_fcn() const { return write_fcn_ != nullptr; } @@ -70,7 +70,7 @@ private: // Method that is responsible to write back the load data to the appropriate // destination. - void FinishLoad(int latency, Instruction *inst, ReferenceCount *context); + void FinishLoad(int latency, Instruction* inst, ReferenceCount* context); // System bus read/write function pointers (point to C# delegates). RenodeMemoryFunction read_fcn_;
diff --git a/mpact/sim/util/renode/renode_mpact.cc b/mpact/sim/util/renode/renode_mpact.cc index b43487b..0b96319 100644 --- a/mpact/sim/util/renode/renode_mpact.cc +++ b/mpact/sim/util/renode/renode_mpact.cc
@@ -35,36 +35,36 @@ using ::mpact::sim::util::MemoryInterface; // This function must be defined in the library. -extern ::mpact::sim::util::renode::RenodeDebugInterface *CreateMpactSim( - std::string name, std::string cpu_type, MemoryInterface *); +extern ::mpact::sim::util::renode::RenodeDebugInterface* CreateMpactSim( + std::string name, std::string cpu_type, MemoryInterface*); using ::mpact::sim::util::renode::RenodeAgent; using ::mpact::sim::util::renode::RenodeCpuRegister; // Implementation of the C interface functions. They each forward the call to // the corresponding method in RenodeAgent. -int32_t construct(char *cpu_type, int32_t max_name_length) { +int32_t construct(char* cpu_type, int32_t max_name_length) { return RenodeAgent::Instance()->Construct(cpu_type, max_name_length, nullptr, nullptr); } -int32_t construct_with_sysbus(char *cpu_type, int32_t max_name_length, - int32_t (*read_callback)(uint64_t, char *, +int32_t construct_with_sysbus(char* cpu_type, int32_t max_name_length, + int32_t (*read_callback)(uint64_t, char*, int32_t), - int32_t (*write_callback)(uint64_t, char *, + int32_t (*write_callback)(uint64_t, char*, int32_t)) { return RenodeAgent::Instance()->Construct(cpu_type, max_name_length, read_callback, write_callback); } -int32_t connect(char *cpu_type, int32_t id, int32_t max_name_length) { +int32_t connect(char* cpu_type, int32_t id, int32_t max_name_length) { return RenodeAgent::Instance()->Connect(cpu_type, id, max_name_length, nullptr, nullptr); } -int32_t connect_with_sysbus(char *cpu_type, int32_t id, int32_t max_name_length, - int32_t (*read_callback)(uint64_t, char *, int32_t), - int32_t (*write_callback)(uint64_t, char *, +int32_t connect_with_sysbus(char* cpu_type, int32_t id, int32_t max_name_length, + int32_t (*read_callback)(uint64_t, char*, int32_t), + int32_t (*write_callback)(uint64_t, char*, int32_t)) { return RenodeAgent::Instance()->Connect(cpu_type, id, max_name_length, read_callback, write_callback); @@ -78,23 +78,23 @@ return RenodeAgent::Instance()->GetRegisterInfoSize(id); } -int32_t get_reg_info(int32_t id, int32_t index, char *name, void *info) { +int32_t get_reg_info(int32_t id, int32_t index, char* name, void* info) { if (info == nullptr) return -1; return RenodeAgent::Instance()->GetRegisterInfo( - id, index, name, static_cast<RenodeCpuRegister *>(info)); + id, index, name, static_cast<RenodeCpuRegister*>(info)); } -uint64_t load_elf(int32_t id, const char *elf_file_name, bool for_symbols_only, - int32_t *status) { +uint64_t load_elf(int32_t id, const char* elf_file_name, bool for_symbols_only, + int32_t* status) { return RenodeAgent::Instance()->LoadExecutable(id, elf_file_name, for_symbols_only, status); } -int32_t load_image(int32_t id, const char *file_name, uint64_t address) { +int32_t load_image(int32_t id, const char* file_name, uint64_t address) { return RenodeAgent::Instance()->LoadImage(id, file_name, address); } -int32_t read_register(int32_t id, uint32_t reg_id, uint64_t *value) { +int32_t read_register(int32_t id, uint32_t reg_id, uint64_t* value) { return RenodeAgent::Instance()->ReadRegister(id, reg_id, value); } @@ -102,22 +102,22 @@ return RenodeAgent::Instance()->WriteRegister(id, reg_id, value); } -uint64_t read_memory(int32_t id, uint64_t address, char *buffer, +uint64_t read_memory(int32_t id, uint64_t address, char* buffer, uint64_t length) { return RenodeAgent::Instance()->ReadMemory(id, address, buffer, length); } -uint64_t write_memory(int32_t id, uint64_t address, const char *buffer, +uint64_t write_memory(int32_t id, uint64_t address, const char* buffer, uint64_t length) { return RenodeAgent::Instance()->WriteMemory(id, address, buffer, length); } -uint64_t step(int32_t id, uint64_t num_to_step, int32_t *status) { +uint64_t step(int32_t id, uint64_t num_to_step, int32_t* status) { return RenodeAgent::Instance()->Step(id, num_to_step, status); } -int32_t set_config(int32_t id, const char *config_names[], - const char *config_values[], int32_t size) { +int32_t set_config(int32_t id, const char* config_names[], + const char* config_values[], int32_t size) { return RenodeAgent::Instance()->SetConfig(id, config_names, config_values, size); } @@ -133,18 +133,18 @@ using HaltReason = ::mpact::sim::generic::CoreDebugInterface::HaltReason; -RenodeAgent *RenodeAgent::instance_ = nullptr; +RenodeAgent* RenodeAgent::instance_ = nullptr; int32_t RenodeAgent::count_ = 0; // Create the debug instance by calling the factory function. -int32_t RenodeAgent::Construct(char *cpu_type, int32_t max_name_length, - int32_t (*read_callback)(uint64_t, char *, +int32_t RenodeAgent::Construct(char* cpu_type, int32_t max_name_length, + int32_t (*read_callback)(uint64_t, char*, int32_t), - int32_t (*write_callback)(uint64_t, char *, + int32_t (*write_callback)(uint64_t, char*, int32_t)) { std::string name = absl::StrCat("renode", count_); - auto *memory_access = new RenodeMemoryAccess(read_callback, write_callback); - auto *dbg = CreateMpactSim(name, cpu_type, memory_access); + auto* memory_access = new RenodeMemoryAccess(read_callback, write_callback); + auto* dbg = CreateMpactSim(name, cpu_type, memory_access); if (dbg == nullptr) { delete memory_access; return -1; @@ -160,16 +160,17 @@ return RenodeAgent::count_++; } -int32_t RenodeAgent::Connect( - char *cpu_type, int32_t id, int32_t max_name_length, - int32_t (*read_callback)(uint64_t, char *, int32_t), - int32_t (*write_callback)(uint64_t, char *, int32_t)) { +int32_t RenodeAgent::Connect(char* cpu_type, int32_t id, + int32_t max_name_length, + int32_t (*read_callback)(uint64_t, char*, int32_t), + int32_t (*write_callback)(uint64_t, char*, + int32_t)) { // First check if the instance already exists. auto iter = core_dbg_instances_.find(id); if (iter != core_dbg_instances_.end()) { // If memory callbacks are provided, don't overwrite any previous non-null // callbacks. - auto *mem_access = renode_memory_access_.at(id); + auto* mem_access = renode_memory_access_.at(id); // Replace any null callbacks. if (!mem_access->has_read_fcn()) { mem_access->set_read_fcn(read_callback); @@ -182,8 +183,8 @@ // The instance does not exist, so create a new debug instance. std::string name = absl::StrCat("renode", id); - auto *memory_access = new RenodeMemoryAccess(read_callback, write_callback); - auto *dbg = CreateMpactSim(name, cpu_type, memory_access); + auto* memory_access = new RenodeMemoryAccess(read_callback, write_callback); + auto* dbg = CreateMpactSim(name, cpu_type, memory_access); if (dbg == nullptr) { delete memory_access; return -1; @@ -224,17 +225,17 @@ // Check for valid instance. auto dbg_iter = core_dbg_instances_.find(id); if (dbg_iter == core_dbg_instances_.end()) return -1; - auto *dbg = dbg_iter->second; + auto* dbg = dbg_iter->second; return dbg->GetRenodeRegisterInfoSize(); } -int32_t RenodeAgent::GetRegisterInfo(int32_t id, int32_t index, char *name, - RenodeCpuRegister *info) { +int32_t RenodeAgent::GetRegisterInfo(int32_t id, int32_t index, char* name, + RenodeCpuRegister* info) { // Check for valid instance. if (info == nullptr) return -1; auto dbg_iter = core_dbg_instances_.find(id); if (dbg_iter == core_dbg_instances_.end()) return -1; - auto *dbg = dbg_iter->second; + auto* dbg = dbg_iter->second; int32_t max_len = name_length_map_.at(id); auto result = dbg->GetRenodeRegisterInfo(index, max_len, name, *info); if (!result.ok()) return -1; @@ -243,13 +244,13 @@ // Read the register given by the id. int32_t RenodeAgent::ReadRegister(int32_t id, uint32_t reg_id, - uint64_t *value) { + uint64_t* value) { // Check for valid instance. if (value == nullptr) return -1; auto dbg_iter = core_dbg_instances_.find(id); if (dbg_iter == core_dbg_instances_.end()) return -1; // Read register. - auto *dbg = dbg_iter->second; + auto* dbg = dbg_iter->second; auto result = dbg->ReadRegister(reg_id); if (!result.ok()) return -1; *value = result.value(); @@ -262,13 +263,13 @@ auto dbg_iter = core_dbg_instances_.find(id); if (dbg_iter == core_dbg_instances_.end()) return -1; // Write register. - auto *dbg = dbg_iter->second; + auto* dbg = dbg_iter->second; auto result = dbg->WriteRegister(reg_id, value); if (!result.ok()) return -1; return 0; } -uint64_t RenodeAgent::ReadMemory(int32_t id, uint64_t address, char *buffer, +uint64_t RenodeAgent::ReadMemory(int32_t id, uint64_t address, char* buffer, uint64_t length) { // Get the debug interface. auto dbg_iter = core_dbg_instances_.find(id); @@ -276,28 +277,28 @@ LOG(ERROR) << "No such core dbg instance: " << id; return 0; } - auto *dbg = dbg_iter->second; + auto* dbg = dbg_iter->second; auto res = dbg->ReadMemory(address, buffer, length); if (!res.ok()) return 0; return res.value(); } uint64_t RenodeAgent::WriteMemory(int32_t id, uint64_t address, - const char *buffer, uint64_t length) { + const char* buffer, uint64_t length) { // Get the debug interface. auto dbg_iter = core_dbg_instances_.find(id); if (dbg_iter == core_dbg_instances_.end()) { LOG(ERROR) << "No such core dbg instance: " << id; return 0; } - auto *dbg = dbg_iter->second; + auto* dbg = dbg_iter->second; auto res = dbg->WriteMemory(address, buffer, length); if (!res.ok()) return 0; return res.value(); } -uint64_t RenodeAgent::LoadExecutable(int32_t id, const char *file_name, - bool for_symbols_only, int32_t *status) { +uint64_t RenodeAgent::LoadExecutable(int32_t id, const char* file_name, + bool for_symbols_only, int32_t* status) { // Get the debug interface. auto dbg_iter = core_dbg_instances_.find(id); if (dbg_iter == core_dbg_instances_.end()) { @@ -306,7 +307,7 @@ return 0; } // Instantiate loader. - auto *dbg = dbg_iter->second; + auto* dbg = dbg_iter->second; auto res = dbg->LoadExecutable(file_name, for_symbols_only); if (!res.ok()) { LOG(ERROR) << "Failed to load executable: " << res.status().message(); @@ -318,7 +319,7 @@ return entry; } -int32_t RenodeAgent::LoadImage(int32_t id, const char *file_name, +int32_t RenodeAgent::LoadImage(int32_t id, const char* file_name, uint64_t address) { // Get the debug interface. auto dbg_iter = core_dbg_instances_.find(id); @@ -326,7 +327,7 @@ LOG(ERROR) << "No such core dbg instance: " << id; return -1; } - auto *dbg = dbg_iter->second; + auto* dbg = dbg_iter->second; // Open up the image file. std::ifstream image_file; image_file.open(file_name, std::ios::in | std::ios::binary); @@ -358,9 +359,9 @@ return 0; } -uint64_t RenodeAgent::Step(int32_t id, uint64_t num_to_step, int32_t *status) { +uint64_t RenodeAgent::Step(int32_t id, uint64_t num_to_step, int32_t* status) { // Get the core debug if object. - auto *dbg = RenodeAgent::Instance()->core_dbg(id); + auto* dbg = RenodeAgent::Instance()->core_dbg(id); // Is the debug interface valid? if (dbg == nullptr) { if (status != nullptr) { @@ -457,10 +458,10 @@ } // Set configuration item. -int32_t RenodeAgent::SetConfig(int32_t id, const char *config_names[], - const char *config_values[], int size) { +int32_t RenodeAgent::SetConfig(int32_t id, const char* config_names[], + const char* config_values[], int size) { // Get the core debug interface object. - auto *dbg = RenodeAgent::Instance()->core_dbg(id); + auto* dbg = RenodeAgent::Instance()->core_dbg(id); // Is the debug interface valid? if (dbg == nullptr) { return -1; @@ -476,7 +477,7 @@ // Set irq value. int32_t RenodeAgent::SetIrqValue(int32_t id, int32_t irq_num, bool irq_value) { // Get the core debug interface object. - auto *dbg = RenodeAgent::Instance()->core_dbg(id); + auto* dbg = RenodeAgent::Instance()->core_dbg(id); // Is the debug interface valid? if (dbg == nullptr) { return -1;
diff --git a/mpact/sim/util/renode/renode_mpact.h b/mpact/sim/util/renode/renode_mpact.h index 533cc81..ba0ec68 100644 --- a/mpact/sim/util/renode/renode_mpact.h +++ b/mpact/sim/util/renode/renode_mpact.h
@@ -38,20 +38,20 @@ // Create a debug instance, returning its id. A return value of zero indicates // and error. The sysbus variant of the call provides methods to perform loads // and stores from a memory space managed by the caller. -int32_t construct(char *cpu_type, int32_t max_name_length); -int32_t construct_with_sysbus(char *cpu_type, int32_t max_name_length, - int32_t (*read_callback)(uint64_t, char *, +int32_t construct(char* cpu_type, int32_t max_name_length); +int32_t construct_with_sysbus(char* cpu_type, int32_t max_name_length, + int32_t (*read_callback)(uint64_t, char*, int32_t), - int32_t (*write_callback)(uint64_t, char *, + int32_t (*write_callback)(uint64_t, char*, int32_t)); // Connect with, or construct, a debug instance connected to a simulator with // the given id. A return value of zero indicates an error. The sysbus variant // of the call provides methods to perform loads and stores from a memory space // managed by the caller. -int32_t connect(char *cpu_type, int32_t id, int32_t max_name_length); -int32_t connect_with_sysbus(char *cpu_type, int32_t id, int32_t max_name_length, - int32_t (*read_callback)(uint64_t, char *, int32_t), - int32_t (*write_callback)(uint64_t, char *, +int32_t connect(char* cpu_type, int32_t id, int32_t max_name_length); +int32_t connect_with_sysbus(char* cpu_type, int32_t id, int32_t max_name_length, + int32_t (*read_callback)(uint64_t, char*, int32_t), + int32_t (*write_callback)(uint64_t, char*, int32_t)); // Destruct the given debug instance. A negative return value indicates an // error. @@ -60,37 +60,37 @@ int32_t get_reg_info_size(int32_t id); // Return the register entry with the given index. The info pointer should // store an object of type RenodeCpuRegister. -int32_t get_reg_info(int32_t id, int32_t index, char *name, void *info); +int32_t get_reg_info(int32_t id, int32_t index, char* name, void* info); // Use the loader to read in the given ELF executable. If the for_symbols_only // is true, do not write it to memory or set the PC to the entry point. The // memory and register initialization will be performed by ReNode. In this case // the file is loaded only to provide symbol lookup. -uint64_t load_elf(int32_t id, const char *elf_file_name, bool for_symbols_only, - int32_t *status); +uint64_t load_elf(int32_t id, const char* elf_file_name, bool for_symbols_only, + int32_t* status); // Load the content of the given file into memory, starting at the given // address. -int32_t load_image(int32_t id, const char *file_name, uint64_t address); +int32_t load_image(int32_t id, const char* file_name, uint64_t address); // Read register reg_id in the instance id, store the value in the pointer // given. A return value < 0 is an error. -int32_t read_register(int32_t id, uint32_t reg_id, uint64_t *value); +int32_t read_register(int32_t id, uint32_t reg_id, uint64_t* value); // Write register reg_id in the instance id. A return value < 0 is an error. int32_t write_register(int32_t id, uint32_t reg_id, uint64_t value); // Read/Write memory. -uint64_t read_memory(int32_t id, uint64_t address, char *buffer, +uint64_t read_memory(int32_t id, uint64_t address, char* buffer, uint64_t length); -uint64_t write_memory(int32_t id, uint64_t address, const char *buffer, +uint64_t write_memory(int32_t id, uint64_t address, const char* buffer, uint64_t length); // Reset the instance. A return value < 0 is an error. int32_t reset(int32_t id); // Step the instance id by num_to_step instructions. Return the number of // instructions stepped. The status is written to the pointer *status. -uint64_t step(int32_t id, uint64_t num_to_step, int32_t *status); +uint64_t step(int32_t id, uint64_t num_to_step, int32_t* status); // Set configuration items. This passes in the id, two arrays of strings (names // and values), and the size of the two arrays. Depending on the name of the // configuration item, the string will be interpreted according to the expected // type. -int32_t set_config(int32_t id, const char *config_name[], - const char *config_value[], int32_t size); +int32_t set_config(int32_t id, const char* config_name[], + const char* config_value[], int32_t size); // Set the given irq number (if valid) to the provided value. int32_t set_irq_value(int32_t id, int32_t irq_number, bool irq_value); } // extern "C" @@ -117,7 +117,7 @@ public: constexpr static size_t kBufferSize = 64 * 1024; // This is a singleton class, so need a static Instance method. - static RenodeAgent *Instance() { + static RenodeAgent* Instance() { if (instance_ != nullptr) return instance_; instance_ = new RenodeAgent(); @@ -125,51 +125,50 @@ } // These methods correspond to the C methods defined above. - int32_t Construct(char *cpu_type, int32_t max_name_length, - int32_t (*read_callback)(uint64_t, char *, int32_t), - int32_t (*write_callback)(uint64_t, char *, int32_t)); - int32_t Connect(char *cpu_type, int32_t id, int32_t max_name_length, - int32_t (*read_callback)(uint64_t, char *, int32_t), - int32_t (*write_callback)(uint64_t, char *, int32_t)); + int32_t Construct(char* cpu_type, int32_t max_name_length, + int32_t (*read_callback)(uint64_t, char*, int32_t), + int32_t (*write_callback)(uint64_t, char*, int32_t)); + int32_t Connect(char* cpu_type, int32_t id, int32_t max_name_length, + int32_t (*read_callback)(uint64_t, char*, int32_t), + int32_t (*write_callback)(uint64_t, char*, int32_t)); void Destroy(int32_t id); int32_t Reset(int32_t id); int32_t GetRegisterInfoSize(int32_t id) const; - int32_t GetRegisterInfo(int32_t id, int32_t index, char *name, - RenodeCpuRegister *info); - int32_t ReadRegister(int32_t id, uint32_t reg_id, uint64_t *value); + int32_t GetRegisterInfo(int32_t id, int32_t index, char* name, + RenodeCpuRegister* info); + int32_t ReadRegister(int32_t id, uint32_t reg_id, uint64_t* value); int32_t WriteRegister(int32_t id, uint32_t reg_id, uint64_t value); - uint64_t ReadMemory(int32_t id, uint64_t address, char *buffer, + uint64_t ReadMemory(int32_t id, uint64_t address, char* buffer, uint64_t length); - uint64_t WriteMemory(int32_t id, uint64_t address, const char *buffer, + uint64_t WriteMemory(int32_t id, uint64_t address, const char* buffer, uint64_t length); - uint64_t LoadExecutable(int32_t id, const char *elf_file_name, - bool for_symbols_only, int32_t *status); - int32_t LoadImage(int32_t id, const char *file_name, uint64_t address); - uint64_t Step(int32_t id, uint64_t num_to_step, int32_t *status); - int32_t SetConfig(int32_t id, const char *config_names[], - const char *config_values[], int32_t size); + uint64_t LoadExecutable(int32_t id, const char* elf_file_name, + bool for_symbols_only, int32_t* status); + int32_t LoadImage(int32_t id, const char* file_name, uint64_t address); + uint64_t Step(int32_t id, uint64_t num_to_step, int32_t* status); + int32_t SetConfig(int32_t id, const char* config_names[], + const char* config_values[], int32_t size); int32_t SetIrqValue(int32_t id, int32_t irq_number, bool irq_value); // Accessor. - RenodeDebugInterface *core_dbg(int32_t id) const { + RenodeDebugInterface* core_dbg(int32_t id) const { auto ptr = core_dbg_instances_.find(id); if (ptr != core_dbg_instances_.end()) return ptr->second; return nullptr; } private: - using RenodeMemoryFcn = - absl::AnyInvocable<int32_t(uint64_t, char *, int32_t)>; + using RenodeMemoryFcn = absl::AnyInvocable<int32_t(uint64_t, char*, int32_t)>; // Private constructor. RenodeAgent() = default; - static RenodeAgent *instance_; + static RenodeAgent* instance_; static int32_t count_; // Map of renode memory access interfaces used to access devices and memory // off the system bus. - absl::flat_hash_map<int32_t, RenodeMemoryAccess *> renode_memory_access_; + absl::flat_hash_map<int32_t, RenodeMemoryAccess*> renode_memory_access_; // Map of debug instances. - absl::flat_hash_map<int32_t, RenodeDebugInterface *> core_dbg_instances_; + absl::flat_hash_map<int32_t, RenodeDebugInterface*> core_dbg_instances_; absl::flat_hash_map<int32_t, int32_t> name_length_map_; absl::flat_hash_map<int32_t, uint64_t> memory_bases_; absl::flat_hash_map<int32_t, uint64_t> memory_sizes_;
diff --git a/mpact/sim/util/renode/socket_cli.cc b/mpact/sim/util/renode/socket_cli.cc index a03efdc..17a158b 100644 --- a/mpact/sim/util/renode/socket_cli.cc +++ b/mpact/sim/util/renode/socket_cli.cc
@@ -39,7 +39,7 @@ using ::mpact::sim::generic::DebugCommandShellInterface; -SocketCLI::SocketCLI(int port, DebugCommandShellInterface &dbg_shell, +SocketCLI::SocketCLI(int port, DebugCommandShellInterface& dbg_shell, absl::AnyInvocable<void(bool)> is_connected_cb) : dbg_shell_(dbg_shell), is_connected_cb_(std::move(is_connected_cb)) { // Set initial status as not connected. @@ -68,7 +68,7 @@ std::memset(&server_address_int.sin_zero, 0, sizeof(server_address_int.sin_zero)); int res = bind(server_socket_, - reinterpret_cast<const sockaddr *>(&server_address_int), + reinterpret_cast<const sockaddr*>(&server_address_int), sizeof(server_address_int)); if (res != 0) { good_ = false;
diff --git a/mpact/sim/util/renode/socket_cli.h b/mpact/sim/util/renode/socket_cli.h index 6c13822..56d4807 100644 --- a/mpact/sim/util/renode/socket_cli.h +++ b/mpact/sim/util/renode/socket_cli.h
@@ -29,14 +29,14 @@ // Constructor takes the port number to listen to, the top level CherIoT // simulator interface, and a callback to notify when the connection status // of the port/cli changes. - SocketCLI(int port, DebugCommandShellInterface &dbg_shell, + SocketCLI(int port, DebugCommandShellInterface& dbg_shell, absl::AnyInvocable<void(bool)> is_connected_cb); ~SocketCLI(); bool good() const { return good_; } private: - DebugCommandShellInterface &dbg_shell_; + DebugCommandShellInterface& dbg_shell_; std::thread cli_thread_; bool good_ = false; int server_socket_ = -1;