[PATCH v1 2/4] Target: Convert to C++

Ryan Long ryan.long at oarcorp.com
Wed Dec 8 15:15:50 UTC 2021


---
 tester/covoar/TargetBase.cc     | 35 ++++++++++++++++++-----------------
 tester/covoar/TargetBase.h      | 18 +++++++++---------
 tester/covoar/Target_aarch64.cc | 18 ++++++++++--------
 tester/covoar/Target_aarch64.h  |  6 +++---
 tester/covoar/Target_arm.cc     | 16 +++++++++-------
 tester/covoar/Target_arm.h      |  6 +++---
 tester/covoar/Target_i386.cc    | 22 ++++++++++++----------
 tester/covoar/Target_i386.h     |  4 ++--
 tester/covoar/Target_lm32.cc    |  6 +++---
 tester/covoar/Target_lm32.h     |  4 ++--
 tester/covoar/Target_m68k.cc    | 12 +++++++-----
 tester/covoar/Target_m68k.h     |  6 +++---
 tester/covoar/Target_powerpc.cc |  8 ++++----
 tester/covoar/Target_powerpc.h  |  4 ++--
 tester/covoar/Target_riscv.cc   |  6 +++---
 tester/covoar/Target_riscv.h    |  6 +++---
 tester/covoar/Target_sparc.cc   | 12 +++++++-----
 tester/covoar/Target_sparc.h    |  6 +++---
 18 files changed, 103 insertions(+), 92 deletions(-)

diff --git a/tester/covoar/TargetBase.cc b/tester/covoar/TargetBase.cc
index 7ee45b5..a62e90f 100644
--- a/tester/covoar/TargetBase.cc
+++ b/tester/covoar/TargetBase.cc
@@ -40,24 +40,24 @@ namespace Target {
   {
   }
 
-  const char* TargetBase::getAddr2line() const
+  const std::string& TargetBase::getAddr2line() const
   {
-    return addr2line_m.c_str();
+    return addr2line_m;
   }
 
-  const char* TargetBase::getCPU( void ) const
+  const std::string& TargetBase::getCPU() const
   {
-    return cpu_m.c_str();
+    return cpu_m;
   }
 
-  const char* TargetBase::getObjdump() const
+  const std::string& TargetBase::getObjdump() const
   {
-    return objdump_m.c_str();
+    return objdump_m;
   }
 
-  const char* TargetBase::getTarget( void ) const
+  const std::string& TargetBase::getTarget() const
   {
-    return targetName_m.c_str();
+    return targetName_m;
   }
 
   bool TargetBase::isBranch( const std::string& instruction )
@@ -83,12 +83,13 @@ namespace Target {
   }
 
   bool TargetBase::isBranchLine(
-    const char* const line
+    const std::string& line
   )
   {
-    #define WARNING \
-        "WARNING: TargetBase::isBranchLine - (%d) " \
-        "Unable to find instruction in: %s\n"
+    #define WARNING_PT1 \
+        "WARNING: TargetBase::isBranchLine - ("
+    #define WARNING_PT2 \
+        ") Unable to find instruction in: "
     const char *ch;
     char instruction[120];
     int  result;
@@ -101,7 +102,7 @@ namespace Target {
       ch++;
     }
     if (*ch != '\t') {
-      fprintf( stderr, WARNING, 1, line );
+      std::cerr << WARNING_PT1 << 1 << WARNING_PT2 << line << std::endl;
       return false;
     }
     ch++;
@@ -110,7 +111,7 @@ namespace Target {
     while ((*ch != '\t') && (*ch != '\0'))
       ch++;
     if (*ch != '\t') {
-      fprintf( stderr, WARNING, 2, line) ;
+      std::cerr << WARNING_PT1 << 2 << WARNING_PT2 << line << std::endl;
       return false;
     }
     ch++;
@@ -119,19 +120,19 @@ namespace Target {
     // after the second tab.
     result = sscanf( ch, "%s", instruction );
     if (result != 1) {
-        fprintf( stderr, WARNING, 3, line );
+        std::cerr << WARNING_PT1 << 3 << WARNING_PT2 << line << std::endl;
         return false;
     }
 
     return isBranch( instruction );
   }
 
-  uint8_t TargetBase::qemuTakenBit(void)
+  uint8_t TargetBase::qemuTakenBit()
   {
     return TRACE_OP_BR0;
   }
 
-  uint8_t TargetBase::qemuNotTakenBit(void)
+  uint8_t TargetBase::qemuNotTakenBit()
   {
     return TRACE_OP_BR1;
   }
diff --git a/tester/covoar/TargetBase.h b/tester/covoar/TargetBase.h
index e5c143e..0a75c85 100644
--- a/tester/covoar/TargetBase.h
+++ b/tester/covoar/TargetBase.h
@@ -42,28 +42,28 @@ namespace Target {
      *
      *  @return Returns the target specific addr2line program name
      */
-    const char* getAddr2line( void ) const;
+    const std::string& getAddr2line() const;
 
     /*!
      *  This method returns the CPU name.
      *
      *  @return Returns the target cpu name
      */
-    const char* getCPU( void ) const;
+    const std::string& getCPU() const;
 
     /*!
      *  This method returns the program name for objdump.
      *
      *  @return Returns the target specific objdump program name
      */
-    const char* getObjdump( void ) const;
+    const std::string& getObjdump() const;
 
     /*!
      *  This method returns the target name.
      *
      *  @return Returns the target name
      */
-    const char* getTarget( void ) const;
+    const std::string& getTarget() const;
 
     /*!
      *  This method determines whether the specified line from a
@@ -75,8 +75,8 @@ namespace Target {
      *  @return Returns TRUE if the instruction is a nop, FALSE otherwise.
      */
     virtual bool isNopLine(
-      const char* const line,
-      int&              size
+      const std::string& line,
+      int&               size
     ) = 0;
 
 
@@ -90,7 +90,7 @@ namespace Target {
      *  @return Returns TRUE if the instruction is a branch, FALSE otherwise.
      */
     bool isBranchLine(
-      const char* const line
+      const std::string& line
     );
 
 
@@ -104,13 +104,13 @@ namespace Target {
      *  This method returns the bit set by Qemu in the trace record
      *  when a branch is taken.
      */
-    virtual uint8_t qemuTakenBit(void);
+    virtual uint8_t qemuTakenBit();
 
     /*!
      *  This method returns the bit set by Qemu in the trace record
      *  when a branch is taken.
      */
-    virtual uint8_t qemuNotTakenBit(void);
+    virtual uint8_t qemuNotTakenBit();
 
   protected:
 
diff --git a/tester/covoar/Target_aarch64.cc b/tester/covoar/Target_aarch64.cc
index 4d16456..139f5fe 100644
--- a/tester/covoar/Target_aarch64.cc
+++ b/tester/covoar/Target_aarch64.cc
@@ -49,31 +49,33 @@ namespace Target {
   }
 
   bool Target_aarch64::isNopLine(
-    const char* const line,
-    int&              size
+    const std::string& line,
+    int&               size
   )
   {
-    if (!strcmp( &line[strlen(line)-3], "nop")) {
+    size_t stringLen = line.length();
+
+    if ( line.substr( stringLen - 3 ) == "nop" ) {
       size = 4;
       return true;
     }
 
-    if (!strncmp( &line[strlen(line)-6], "udf", 3)) {
+    if ( line.substr( stringLen - 6, 3 ) == "udf" ) {
       size = 4;
       return true;
     }
 
     // On ARM, there are literal tables at the end of methods.
     // We need to avoid them.
-    if (!strncmp( &line[strlen(line)-10], ".byte", 5)) {
+    if ( line.substr( stringLen - 10, 5 ) == ".byte" ) {
       size = 1;
       return true;
     }
-    if (!strncmp( &line[strlen(line)-13], ".short", 6)) {
+    if ( line.substr( stringLen - 13, 6 ) == ".short" ) {
       size = 2;
       return true;
     }
-    if (!strncmp( &line[strlen(line)-16], ".word", 5)) {
+    if ( line.substr( stringLen - 16, 5 ) == ".word" ) {
       size = 4;
       return true;
     }
@@ -82,7 +84,7 @@ namespace Target {
   }
 
   bool Target_aarch64::isBranch(
-      const char* instruction
+      const std::string& instruction
   )
   {
     throw rld::error(
diff --git a/tester/covoar/Target_aarch64.h b/tester/covoar/Target_aarch64.h
index fb011e8..42353e5 100644
--- a/tester/covoar/Target_aarch64.h
+++ b/tester/covoar/Target_aarch64.h
@@ -42,8 +42,8 @@ namespace Target {
      *  @return Returns TRUE if the instruction is a nop, FALSE otherwise.
      */
     virtual bool isNopLine(
-      const char* const line,
-      int&              size
+      const std::string& line,
+      int&               size
     ) override;
 
     /*!
@@ -51,7 +51,7 @@ namespace Target {
      *  objdump file is a branch instruction.
      */
     bool isBranch(
-      const char* const instruction
+      const std::string& instruction
     );
 
     /* Documentation inherited from base class */
diff --git a/tester/covoar/Target_arm.cc b/tester/covoar/Target_arm.cc
index 94d50bb..50c9ce3 100644
--- a/tester/covoar/Target_arm.cc
+++ b/tester/covoar/Target_arm.cc
@@ -82,26 +82,28 @@ namespace Target {
   }
 
   bool Target_arm::isNopLine(
-    const char* const line,
-    int&              size
+    const std::string& line,
+    int&               size
   )
   {
-    if (!strcmp( &line[strlen(line)-3], "nop")) {
+    size_t stringLen = line.length();
+
+    if ( line.substr( stringLen - 3 ) == "nop" ) {
       size = 4;
       return true;
     }
 
     // On ARM, there are literal tables at the end of methods.
     // We need to avoid them.
-    if (!strncmp( &line[strlen(line)-10], ".byte", 5)) {
+    if ( line.substr( stringLen - 10, 5 ) == ".byte" ) {
       size = 1;
       return true;
     }
-    if (!strncmp( &line[strlen(line)-13], ".short", 6)) {
+    if ( line.substr( stringLen - 13, 6 ) == ".short" ) {
       size = 2;
       return true;
     }
-    if (!strncmp( &line[strlen(line)-16], ".word", 5)) {
+    if ( line.substr( stringLen - 16, 5 ) == ".word" ) {
       size = 4;
       return true;
     }
@@ -111,7 +113,7 @@ namespace Target {
   }
 
   bool Target_arm::isBranch(
-      const char* instruction
+      const std::string& instruction
   )
   {
     throw rld::error(
diff --git a/tester/covoar/Target_arm.h b/tester/covoar/Target_arm.h
index 80b68af..3ff9b6f 100644
--- a/tester/covoar/Target_arm.h
+++ b/tester/covoar/Target_arm.h
@@ -42,8 +42,8 @@ namespace Target {
      *  @return Returns TRUE if the instruction is a nop, FALSE otherwise.
      */
     bool isNopLine(
-      const char* const line,
-      int&              size
+      const std::string& line,
+      int&               size
     );
 
     /*!
@@ -51,7 +51,7 @@ namespace Target {
      *  objdump file is a branch instruction.
      */
     bool isBranch(
-      const char* const instruction
+      const std::string& instruction
     );
 
   private:
diff --git a/tester/covoar/Target_i386.cc b/tester/covoar/Target_i386.cc
index 2990273..cb8e64d 100644
--- a/tester/covoar/Target_i386.cc
+++ b/tester/covoar/Target_i386.cc
@@ -57,39 +57,41 @@ namespace Target {
   }
 
   bool Target_i386::isNopLine(
-    const char* const line,
-    int&              size
+    const std::string& line,
+    int&               size
   )
   {
-    if (!strcmp( &line[strlen(line)-3], "nop")) {
+    size_t stringLen = line.length();
+
+    if ( line.substr( stringLen - 3 ) == "nop" ) {
       size = 1;
       return true;
     }
 
     // i386 has some two and three byte nops
-    if (!strncmp( &line[strlen(line)-14], "xchg   %ax,%ax", 14)) {
+    if ( line.substr( stringLen - 14 ) == "xchg   %ax,%ax" ) {
       size = 2;
       return true;
     }
-    if (!strncmp( &line[strlen(line)-16], "xor    %eax,%eax", 16)) {
+    if ( line.substr( stringLen - 16 ) == "xor    %eax,%eax" ) {
       size = 2;
       return true;
     }
-    if (!strncmp( &line[strlen(line)-16], "xor    %ebx,%ebx", 16)) {
+    if ( line.substr( stringLen - 16 ) == "xor    %ebx,%ebx" ) {
       size = 2;
       return true;
     }
-    if (!strncmp( &line[strlen(line)-16], "xor    %esi,%esi", 16)) {
+    if ( line.substr( stringLen - 16 ) == "xor    %esi,%esi" ) {
       size = 2;
       return true;
     }
-    if (!strncmp( &line[strlen(line)-21], "lea    0x0(%esi),%esi", 21)) {
+    if ( line.substr( stringLen - 21 ) == "lea    0x0(%esi),%esi" ) {
       size = 3;
       return true;
     }
-    if (!strncmp( &line[strlen(line)-28], "lea    0x0(%esi,%eiz,1),%esi", 28)) {
+    if ( line.substr( stringLen - 28 ) == "lea    0x0(%esi,%eiz,1),%esi" ) {
       // Could be 4 or 7 bytes of padding.
-      if (!strncmp( &line[strlen(line)-32], "00", 2)) {
+      if ( line.substr( stringLen - 32, 2 ) == "00" ) {
         size = 7;
       } else {
         size = 4;
diff --git a/tester/covoar/Target_i386.h b/tester/covoar/Target_i386.h
index 3641de7..c9a79cd 100644
--- a/tester/covoar/Target_i386.h
+++ b/tester/covoar/Target_i386.h
@@ -43,8 +43,8 @@ namespace Target {
      *  @return Returns TRUE if the instruction is a nop, FALSE otherwise.
      */
     bool isNopLine(
-      const char* const line,
-      int&              size
+      const std::string& line,
+      int&               size
     );
 
     /* Documentation inherited from base class */
diff --git a/tester/covoar/Target_lm32.cc b/tester/covoar/Target_lm32.cc
index 18e7191..7babbd2 100644
--- a/tester/covoar/Target_lm32.cc
+++ b/tester/covoar/Target_lm32.cc
@@ -30,11 +30,11 @@ namespace Target {
   }
 
   bool Target_lm32::isNopLine(
-    const char* const line,
-    int&              size
+    const std::string& line,
+    int&               size
   )
   {
-    if (!strcmp( &line[strlen(line)-3], "nop")) {
+    if ( line.substr( line.length() - 3 ) == "nop" ) {
       size = 4;
       return true;
     }
diff --git a/tester/covoar/Target_lm32.h b/tester/covoar/Target_lm32.h
index 5d23db5..d21776e 100644
--- a/tester/covoar/Target_lm32.h
+++ b/tester/covoar/Target_lm32.h
@@ -43,8 +43,8 @@ namespace Target {
      *  @return Returns TRUE if the instruction is a nop, FALSE otherwise.
      */
     bool isNopLine(
-      const char* const line,
-      int&              size
+      const std::string& line,
+      int&               size
     );
 
   private:
diff --git a/tester/covoar/Target_m68k.cc b/tester/covoar/Target_m68k.cc
index 536ae80..7c761be 100644
--- a/tester/covoar/Target_m68k.cc
+++ b/tester/covoar/Target_m68k.cc
@@ -77,11 +77,13 @@ namespace Target {
   }
 
   bool Target_m68k::isNopLine(
-    const char* const line,
-    int&              size
+    const std::string& line,
+    int&               size
   )
   {
-    if (!strcmp( &line[strlen(line)-3], "nop")) {
+    size_t stringLen = line.length();
+
+    if ( line.substr( stringLen - 3 ) == "nop" ) {
       size = 2;
       return true;
     }
@@ -89,7 +91,7 @@ namespace Target {
     #define GNU_LD_FILLS_ALIGNMENT_WITH_RTS
     #if defined(GNU_LD_FILLS_ALIGNMENT_WITH_RTS)
       // Until binutils 2.20, binutils would fill with rts not nop
-      if (!strcmp( &line[strlen(line)-3], "rts")) {
+      if ( line.substr( stringLen - 3 ) == "rts" ) {
         size = 4;
         return true;
       }
@@ -99,7 +101,7 @@ namespace Target {
   }
 
   bool Target_m68k::isBranch(
-      const char* const instruction
+      const std::string& instruction
   )
   {
     throw rld::error(
diff --git a/tester/covoar/Target_m68k.h b/tester/covoar/Target_m68k.h
index 5ed7933..13a6030 100644
--- a/tester/covoar/Target_m68k.h
+++ b/tester/covoar/Target_m68k.h
@@ -43,8 +43,8 @@ namespace Target {
      *  @return Returns TRUE if the instruction is a nop, FALSE otherwise.
      */
     bool isNopLine(
-      const char* const line,
-      int&              size
+      const std::string& line,
+      int&               size
     );
 
     /*!
@@ -52,7 +52,7 @@ namespace Target {
      *  objdump file is a branch instruction.
      */
     bool isBranch(
-      const char* const instruction
+      const std::string& instruction
     );
 
     /* Documentation inherited from base class */
diff --git a/tester/covoar/Target_powerpc.cc b/tester/covoar/Target_powerpc.cc
index c62feb0..6cc541d 100644
--- a/tester/covoar/Target_powerpc.cc
+++ b/tester/covoar/Target_powerpc.cc
@@ -58,11 +58,11 @@ namespace Target {
   }
 
   bool Target_powerpc::isNopLine(
-    const char* const line,
-    int&              size
+    const std::string& line,
+    int&               size
   )
   {
-    if (!strcmp( &line[strlen(line)-3], "nop")) {
+    if ( line.substr( line.length() - 3 ) == "nop" ) {
       size = 4;
       return true;
     }
@@ -71,7 +71,7 @@ namespace Target {
   }
 
   bool Target_powerpc::isBranch(
-      const char* const instruction
+      const std::string& instruction
   )
   {
     throw rld::error(
diff --git a/tester/covoar/Target_powerpc.h b/tester/covoar/Target_powerpc.h
index 3008d4c..b446918 100644
--- a/tester/covoar/Target_powerpc.h
+++ b/tester/covoar/Target_powerpc.h
@@ -43,7 +43,7 @@ namespace Target {
      *  @return Returns TRUE if the instruction is a nop, FALSE otherwise.
      */
     bool isNopLine(
-      const char* const line,
+      const std::string& line,
       int&              size
     );
 
@@ -52,7 +52,7 @@ namespace Target {
      *  objdump file is a branch instruction.
      */
     bool isBranch(
-      const char* const instruction
+      const std::string& instruction
     );
 
   private:
diff --git a/tester/covoar/Target_riscv.cc b/tester/covoar/Target_riscv.cc
index 13c81c5..d0b5a8e 100644
--- a/tester/covoar/Target_riscv.cc
+++ b/tester/covoar/Target_riscv.cc
@@ -62,11 +62,11 @@ namespace Target {
   }
 
   bool Target_riscv::isNopLine(
-    const char* const line,
-    int&              size
+    const std::string& line,
+    int&               size
     )
   {
-    if (!strcmp( &line[strlen(line)-3], "nop")){
+    if ( line.substr( line.length() - 3 ) == "nop" ) {
         size = 4;
         return true;
     }
diff --git a/tester/covoar/Target_riscv.h b/tester/covoar/Target_riscv.h
index 64a63d4..1442f69 100644
--- a/tester/covoar/Target_riscv.h
+++ b/tester/covoar/Target_riscv.h
@@ -67,8 +67,8 @@ namespace Target {
    *  @return Returns True if the instruction is nop, False otherwise.
    */
   bool isNopLine(
-    const char* const line,
-    int&              size
+    const std::string& line,
+    int&               size
   );
 
   /*!
@@ -80,7 +80,7 @@ namespace Target {
    */
 
   bool isBranch(
-    const char* const instruction
+    const std::string& instruction
   );
 
   private:
diff --git a/tester/covoar/Target_sparc.cc b/tester/covoar/Target_sparc.cc
index fbdcd1e..a9435cb 100644
--- a/tester/covoar/Target_sparc.cc
+++ b/tester/covoar/Target_sparc.cc
@@ -56,23 +56,25 @@ namespace Target {
   }
 
   bool Target_sparc::isNopLine(
-    const char* const line,
-    int&              size
+    const std::string& line,
+    int&               size
   )
   {
-    if (!strcmp( &line[strlen(line)-3], "nop")) {
+    size_t stringLen = line.length();
+
+    if ( line.substr( stringLen - 3 ) == "nop" ) {
       size = 4;
       return true;
     }
 
-    if (!strcmp( &line[strlen(line)-7], "unknown")) {
+    if ( line.substr( stringLen - 7 ) == "unknown" ) {
       size = 4;
       return true;
     }
     #define GNU_LD_FILLS_ALIGNMENT_WITH_RTS
     #if defined(GNU_LD_FILLS_ALIGNMENT_WITH_RTS)
       // Until binutils 2.20, binutils would fill with rts not nop
-      if (!strcmp( &line[strlen(line)-3], "rts")) {
+    if ( line.substr( stringLen - 3 ) == "rts" ) {
         size = 4;
         return true;
       }
diff --git a/tester/covoar/Target_sparc.h b/tester/covoar/Target_sparc.h
index 0e38859..cbe2faf 100644
--- a/tester/covoar/Target_sparc.h
+++ b/tester/covoar/Target_sparc.h
@@ -43,8 +43,8 @@ namespace Target {
      *  @return Returns TRUE if the instruction is a nop, FALSE otherwise.
      */
     bool isNopLine(
-      const char* const line,
-      int&              size
+      const std::string& line,
+      int&               size
     );
 
     /*!
@@ -52,7 +52,7 @@ namespace Target {
      *  objdump file is a branch instruction.
      */
     bool isBranch(
-      const char* const instruction
+      const std::string& instruction
     );
 
   private:
-- 
1.8.3.1



More information about the devel mailing list