Advertisement
Guest User

Untitled

a guest
May 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. //instruction.cpp
  2. #include "Instruction.h"
  3.  
  4. #include <iostream>
  5. #include <cassert>
  6.  
  7. using namespace std;
  8.  
  9. /* Format the assembly instruction string by adding sources and destinations
  10. * to specified locations in the asm string (replacing `s and `d)
  11. */
  12. static std::string format(const Instruction& inst);
  13.  
  14.  
  15. std::string Instruction::toString() const
  16. {
  17. return format(*this);
  18. }
  19.  
  20.  
  21. static std::string format(const Instruction& inst)
  22. {
  23. list<Reg>::const_iterator srci, dsti;
  24. char c; // current character in asm string
  25. int i; // current index of a characted in a string
  26. string formattedString = "";
  27.  
  28. if (!inst.getSrc().empty())
  29. srci = inst.getSrc().begin();
  30.  
  31. if (!inst.getDst().empty())
  32. dsti = inst.getDst().begin();
  33.  
  34. i = 0;
  35. while (i != inst.getAsmString().size())
  36. {
  37. c = inst.getAsmString()[i];
  38.  
  39. if (c == '`')
  40. {
  41. switch (inst.getAsmString()[i+1])
  42. {
  43. case 's':
  44. formattedString += getRegName(*srci);
  45. srci++;
  46. i++;
  47. break;
  48.  
  49. case 'd':
  50. formattedString += getRegName(*dsti);
  51. dsti++;
  52. i++;
  53. break;
  54.  
  55. default:
  56. assert(0);
  57. }
  58. }
  59. else
  60. {
  61. formattedString += c;
  62. }
  63. i++;
  64. }
  65.  
  66. return formattedString;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement