diff options
author | 2016-11-03 17:24:15 -0700 | |
---|---|---|
committer | 2016-11-04 09:11:35 -0700 | |
commit | 2e965aca73bacf84123b5c53bb0904b13b48e428 (patch) | |
tree | edad34a00b358ca613b7e18781b91c4473e916fb /compiler/utils/assembler_test_base.h | |
parent | 2b64cccce7e3697e4ccca44fb95a6cc12c6441aa (diff) |
ART: Use references in assembler tests
Move parameters to const references.
Bug: 32619234
Test: m
Change-Id: Ib68bdc313b91fee1e9e4e1e794eeca630837b005
Diffstat (limited to 'compiler/utils/assembler_test_base.h')
-rw-r--r-- | compiler/utils/assembler_test_base.h | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/compiler/utils/assembler_test_base.h b/compiler/utils/assembler_test_base.h index 8c71292465..ac24ee95eb 100644 --- a/compiler/utils/assembler_test_base.h +++ b/compiler/utils/assembler_test_base.h @@ -106,7 +106,9 @@ class AssemblerTestInfrastructure { // Driver() assembles and compares the results. If the results are not equal and we have a // disassembler, disassemble both and check whether they have the same mnemonics (in which case // we just warn). - void Driver(const std::vector<uint8_t>& data, std::string assembly_text, std::string test_name) { + void Driver(const std::vector<uint8_t>& data, + const std::string& assembly_text, + const std::string& test_name) { EXPECT_NE(assembly_text.length(), 0U) << "Empty assembly"; NativeAssemblerResult res; @@ -229,7 +231,7 @@ class AssemblerTestInfrastructure { bool success = Exec(args, error_msg); if (!success) { LOG(ERROR) << "Assembler command line:"; - for (std::string arg : args) { + for (const std::string& arg : args) { LOG(ERROR) << arg; } } @@ -238,7 +240,7 @@ class AssemblerTestInfrastructure { // Runs objdump -h on the binary file and extracts the first line with .text. // Returns "" on failure. - std::string Objdump(std::string file) { + std::string Objdump(const std::string& file) { bool have_objdump = FileExists(FindTool(objdump_cmd_name_)); EXPECT_TRUE(have_objdump) << "Cannot find objdump: " << GetObjdumpCommand(); if (!have_objdump) { @@ -287,8 +289,9 @@ class AssemblerTestInfrastructure { } // Disassemble both binaries and compare the text. - bool DisassembleBinaries(const std::vector<uint8_t>& data, const std::vector<uint8_t>& as, - std::string test_name) { + bool DisassembleBinaries(const std::vector<uint8_t>& data, + const std::vector<uint8_t>& as, + const std::string& test_name) { std::string disassembler = GetDisassembleCommand(); if (disassembler.length() == 0) { LOG(WARNING) << "No dissassembler command."; @@ -324,7 +327,7 @@ class AssemblerTestInfrastructure { return result; } - bool DisassembleBinary(std::string file, std::string* error_msg) { + bool DisassembleBinary(const std::string& file, std::string* error_msg) { std::vector<std::string> args; // Encaspulate the whole command line in a single string passed to @@ -345,7 +348,7 @@ class AssemblerTestInfrastructure { return Exec(args, error_msg); } - std::string WriteToFile(const std::vector<uint8_t>& buffer, std::string test_name) { + std::string WriteToFile(const std::vector<uint8_t>& buffer, const std::string& test_name) { std::string file_name = GetTmpnam() + std::string("---") + test_name; const char* data = reinterpret_cast<const char*>(buffer.data()); std::ofstream s_out(file_name + ".o"); @@ -354,7 +357,7 @@ class AssemblerTestInfrastructure { return file_name + ".o"; } - bool CompareFiles(std::string f1, std::string f2) { + bool CompareFiles(const std::string& f1, const std::string& f2) { std::ifstream f1_in(f1); std::ifstream f2_in(f2); @@ -369,7 +372,9 @@ class AssemblerTestInfrastructure { } // Compile the given assembly code and extract the binary, if possible. Put result into res. - bool Compile(std::string assembly_code, NativeAssemblerResult* res, std::string test_name) { + bool Compile(const std::string& assembly_code, + NativeAssemblerResult* res, + const std::string& test_name) { res->ok = false; res->code.reset(nullptr); @@ -438,7 +443,7 @@ class AssemblerTestInfrastructure { // Check whether file exists. Is used for commands, so strips off any parameters: anything after // the first space. We skip to the last slash for this, so it should work with directories with // spaces. - static bool FileExists(std::string file) { + static bool FileExists(const std::string& file) { if (file.length() == 0) { return false; } @@ -478,7 +483,7 @@ class AssemblerTestInfrastructure { return getcwd(temp, 1024) ? std::string(temp) + "/" : std::string(""); } - std::string FindTool(std::string tool_name) { + std::string FindTool(const std::string& tool_name) { // Find the current tool. Wild-card pattern is "arch-string*tool-name". std::string gcc_path = GetRootPath() + GetGCCRootPath(); std::vector<std::string> args; @@ -522,7 +527,8 @@ class AssemblerTestInfrastructure { // Helper for below. If name_predicate is empty, search for all files, otherwise use it for the // "-name" option. - static void FindToolDumpPrintout(std::string name_predicate, std::string tmp_file) { + static void FindToolDumpPrintout(const std::string& name_predicate, + const std::string& tmp_file) { std::string gcc_path = GetRootPath() + GetGCCRootPath(); std::vector<std::string> args; args.push_back("find"); @@ -562,7 +568,7 @@ class AssemblerTestInfrastructure { } // For debug purposes. - void FindToolDump(std::string tool_name) { + void FindToolDump(const std::string& tool_name) { // Check with the tool name. FindToolDumpPrintout(architecture_string_ + "*" + tool_name, GetTmpnam()); FindToolDumpPrintout("", GetTmpnam()); |