X86IntelInstPrinter.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. //===-- X86IntelInstPrinter.cpp - Intel assembly instruction printing -----===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file includes code for rendering MCInst instances as Intel-style
  10. // assembly.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "X86IntelInstPrinter.h"
  14. #include "X86BaseInfo.h"
  15. #include "X86InstComments.h"
  16. #include "llvm/MC/MCExpr.h"
  17. #include "llvm/MC/MCInst.h"
  18. #include "llvm/MC/MCInstrAnalysis.h"
  19. #include "llvm/MC/MCInstrDesc.h"
  20. #include "llvm/MC/MCInstrInfo.h"
  21. #include "llvm/MC/MCSubtargetInfo.h"
  22. #include "llvm/Support/Casting.h"
  23. #include "llvm/Support/ErrorHandling.h"
  24. #include <cassert>
  25. #include <cstdint>
  26. using namespace llvm;
  27. #define DEBUG_TYPE "asm-printer"
  28. // Include the auto-generated portion of the assembly writer.
  29. #define PRINT_ALIAS_INSTR
  30. #include "X86GenAsmWriter1.inc"
  31. void X86IntelInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
  32. OS << getRegisterName(RegNo);
  33. }
  34. void X86IntelInstPrinter::printInst(const MCInst *MI, uint64_t Address,
  35. StringRef Annot, const MCSubtargetInfo &STI,
  36. raw_ostream &OS) {
  37. printInstFlags(MI, OS);
  38. // In 16-bit mode, print data16 as data32.
  39. if (MI->getOpcode() == X86::DATA16_PREFIX &&
  40. STI.getFeatureBits()[X86::Mode16Bit]) {
  41. OS << "\tdata32";
  42. } else if (!printAliasInstr(MI, Address, OS) && !printVecCompareInstr(MI, OS))
  43. printInstruction(MI, Address, OS);
  44. // Next always print the annotation.
  45. printAnnotation(OS, Annot);
  46. // If verbose assembly is enabled, we can print some informative comments.
  47. if (CommentStream)
  48. EmitAnyX86InstComments(MI, *CommentStream, MII);
  49. }
  50. bool X86IntelInstPrinter::printVecCompareInstr(const MCInst *MI, raw_ostream &OS) {
  51. if (MI->getNumOperands() == 0 ||
  52. !MI->getOperand(MI->getNumOperands() - 1).isImm())
  53. return false;
  54. int64_t Imm = MI->getOperand(MI->getNumOperands() - 1).getImm();
  55. const MCInstrDesc &Desc = MII.get(MI->getOpcode());
  56. // Custom print the vector compare instructions to get the immediate
  57. // translated into the mnemonic.
  58. switch (MI->getOpcode()) {
  59. case X86::CMPPDrmi: case X86::CMPPDrri:
  60. case X86::CMPPSrmi: case X86::CMPPSrri:
  61. case X86::CMPSDrm: case X86::CMPSDrr:
  62. case X86::CMPSDrm_Int: case X86::CMPSDrr_Int:
  63. case X86::CMPSSrm: case X86::CMPSSrr:
  64. case X86::CMPSSrm_Int: case X86::CMPSSrr_Int:
  65. if (Imm >= 0 && Imm <= 7) {
  66. OS << '\t';
  67. printCMPMnemonic(MI, /*IsVCMP*/false, OS);
  68. printOperand(MI, 0, OS);
  69. OS << ", ";
  70. // Skip operand 1 as its tied to the dest.
  71. if ((Desc.TSFlags & X86II::FormMask) == X86II::MRMSrcMem) {
  72. if ((Desc.TSFlags & X86II::OpPrefixMask) == X86II::XS)
  73. printdwordmem(MI, 2, OS);
  74. else if ((Desc.TSFlags & X86II::OpPrefixMask) == X86II::XD)
  75. printqwordmem(MI, 2, OS);
  76. else
  77. printxmmwordmem(MI, 2, OS);
  78. } else
  79. printOperand(MI, 2, OS);
  80. return true;
  81. }
  82. break;
  83. case X86::VCMPPDrmi: case X86::VCMPPDrri:
  84. case X86::VCMPPDYrmi: case X86::VCMPPDYrri:
  85. case X86::VCMPPDZ128rmi: case X86::VCMPPDZ128rri:
  86. case X86::VCMPPDZ256rmi: case X86::VCMPPDZ256rri:
  87. case X86::VCMPPDZrmi: case X86::VCMPPDZrri:
  88. case X86::VCMPPSrmi: case X86::VCMPPSrri:
  89. case X86::VCMPPSYrmi: case X86::VCMPPSYrri:
  90. case X86::VCMPPSZ128rmi: case X86::VCMPPSZ128rri:
  91. case X86::VCMPPSZ256rmi: case X86::VCMPPSZ256rri:
  92. case X86::VCMPPSZrmi: case X86::VCMPPSZrri:
  93. case X86::VCMPSDrm: case X86::VCMPSDrr:
  94. case X86::VCMPSDZrm: case X86::VCMPSDZrr:
  95. case X86::VCMPSDrm_Int: case X86::VCMPSDrr_Int:
  96. case X86::VCMPSDZrm_Int: case X86::VCMPSDZrr_Int:
  97. case X86::VCMPSSrm: case X86::VCMPSSrr:
  98. case X86::VCMPSSZrm: case X86::VCMPSSZrr:
  99. case X86::VCMPSSrm_Int: case X86::VCMPSSrr_Int:
  100. case X86::VCMPSSZrm_Int: case X86::VCMPSSZrr_Int:
  101. case X86::VCMPPDZ128rmik: case X86::VCMPPDZ128rrik:
  102. case X86::VCMPPDZ256rmik: case X86::VCMPPDZ256rrik:
  103. case X86::VCMPPDZrmik: case X86::VCMPPDZrrik:
  104. case X86::VCMPPSZ128rmik: case X86::VCMPPSZ128rrik:
  105. case X86::VCMPPSZ256rmik: case X86::VCMPPSZ256rrik:
  106. case X86::VCMPPSZrmik: case X86::VCMPPSZrrik:
  107. case X86::VCMPSDZrm_Intk: case X86::VCMPSDZrr_Intk:
  108. case X86::VCMPSSZrm_Intk: case X86::VCMPSSZrr_Intk:
  109. case X86::VCMPPDZ128rmbi: case X86::VCMPPDZ128rmbik:
  110. case X86::VCMPPDZ256rmbi: case X86::VCMPPDZ256rmbik:
  111. case X86::VCMPPDZrmbi: case X86::VCMPPDZrmbik:
  112. case X86::VCMPPSZ128rmbi: case X86::VCMPPSZ128rmbik:
  113. case X86::VCMPPSZ256rmbi: case X86::VCMPPSZ256rmbik:
  114. case X86::VCMPPSZrmbi: case X86::VCMPPSZrmbik:
  115. case X86::VCMPPDZrrib: case X86::VCMPPDZrribk:
  116. case X86::VCMPPSZrrib: case X86::VCMPPSZrribk:
  117. case X86::VCMPSDZrrb_Int: case X86::VCMPSDZrrb_Intk:
  118. case X86::VCMPSSZrrb_Int: case X86::VCMPSSZrrb_Intk:
  119. case X86::VCMPPHZ128rmi: case X86::VCMPPHZ128rri:
  120. case X86::VCMPPHZ256rmi: case X86::VCMPPHZ256rri:
  121. case X86::VCMPPHZrmi: case X86::VCMPPHZrri:
  122. case X86::VCMPSHZrm: case X86::VCMPSHZrr:
  123. case X86::VCMPSHZrm_Int: case X86::VCMPSHZrr_Int:
  124. case X86::VCMPPHZ128rmik: case X86::VCMPPHZ128rrik:
  125. case X86::VCMPPHZ256rmik: case X86::VCMPPHZ256rrik:
  126. case X86::VCMPPHZrmik: case X86::VCMPPHZrrik:
  127. case X86::VCMPSHZrm_Intk: case X86::VCMPSHZrr_Intk:
  128. case X86::VCMPPHZ128rmbi: case X86::VCMPPHZ128rmbik:
  129. case X86::VCMPPHZ256rmbi: case X86::VCMPPHZ256rmbik:
  130. case X86::VCMPPHZrmbi: case X86::VCMPPHZrmbik:
  131. case X86::VCMPPHZrrib: case X86::VCMPPHZrribk:
  132. case X86::VCMPSHZrrb_Int: case X86::VCMPSHZrrb_Intk:
  133. if (Imm >= 0 && Imm <= 31) {
  134. OS << '\t';
  135. printCMPMnemonic(MI, /*IsVCMP*/true, OS);
  136. unsigned CurOp = 0;
  137. printOperand(MI, CurOp++, OS);
  138. if (Desc.TSFlags & X86II::EVEX_K) {
  139. // Print mask operand.
  140. OS << " {";
  141. printOperand(MI, CurOp++, OS);
  142. OS << "}";
  143. }
  144. OS << ", ";
  145. printOperand(MI, CurOp++, OS);
  146. OS << ", ";
  147. if ((Desc.TSFlags & X86II::FormMask) == X86II::MRMSrcMem) {
  148. if (Desc.TSFlags & X86II::EVEX_B) {
  149. // Broadcast form.
  150. // Load size is word for TA map. Otherwise it is based on W-bit.
  151. if ((Desc.TSFlags & X86II::OpMapMask) == X86II::TA) {
  152. assert(!(Desc.TSFlags & X86II::VEX_W) && "Unknown W-bit value!");
  153. printwordmem(MI, CurOp++, OS);
  154. } else if (Desc.TSFlags & X86II::VEX_W) {
  155. printqwordmem(MI, CurOp++, OS);
  156. } else {
  157. printdwordmem(MI, CurOp++, OS);
  158. }
  159. // Print the number of elements broadcasted.
  160. unsigned NumElts;
  161. if (Desc.TSFlags & X86II::EVEX_L2)
  162. NumElts = (Desc.TSFlags & X86II::VEX_W) ? 8 : 16;
  163. else if (Desc.TSFlags & X86II::VEX_L)
  164. NumElts = (Desc.TSFlags & X86II::VEX_W) ? 4 : 8;
  165. else
  166. NumElts = (Desc.TSFlags & X86II::VEX_W) ? 2 : 4;
  167. if ((Desc.TSFlags & X86II::OpMapMask) == X86II::TA) {
  168. assert(!(Desc.TSFlags & X86II::VEX_W) && "Unknown W-bit value!");
  169. NumElts *= 2;
  170. }
  171. OS << "{1to" << NumElts << "}";
  172. } else {
  173. if ((Desc.TSFlags & X86II::OpPrefixMask) == X86II::XS) {
  174. if ((Desc.TSFlags & X86II::OpMapMask) == X86II::TA)
  175. printwordmem(MI, CurOp++, OS);
  176. else
  177. printdwordmem(MI, CurOp++, OS);
  178. } else if ((Desc.TSFlags & X86II::OpPrefixMask) == X86II::XD) {
  179. assert((Desc.TSFlags & X86II::OpMapMask) != X86II::TA &&
  180. "Unexpected op map!");
  181. printqwordmem(MI, CurOp++, OS);
  182. } else if (Desc.TSFlags & X86II::EVEX_L2) {
  183. printzmmwordmem(MI, CurOp++, OS);
  184. } else if (Desc.TSFlags & X86II::VEX_L) {
  185. printymmwordmem(MI, CurOp++, OS);
  186. } else {
  187. printxmmwordmem(MI, CurOp++, OS);
  188. }
  189. }
  190. } else {
  191. printOperand(MI, CurOp++, OS);
  192. if (Desc.TSFlags & X86II::EVEX_B)
  193. OS << ", {sae}";
  194. }
  195. return true;
  196. }
  197. break;
  198. case X86::VPCOMBmi: case X86::VPCOMBri:
  199. case X86::VPCOMDmi: case X86::VPCOMDri:
  200. case X86::VPCOMQmi: case X86::VPCOMQri:
  201. case X86::VPCOMUBmi: case X86::VPCOMUBri:
  202. case X86::VPCOMUDmi: case X86::VPCOMUDri:
  203. case X86::VPCOMUQmi: case X86::VPCOMUQri:
  204. case X86::VPCOMUWmi: case X86::VPCOMUWri:
  205. case X86::VPCOMWmi: case X86::VPCOMWri:
  206. if (Imm >= 0 && Imm <= 7) {
  207. OS << '\t';
  208. printVPCOMMnemonic(MI, OS);
  209. printOperand(MI, 0, OS);
  210. OS << ", ";
  211. printOperand(MI, 1, OS);
  212. OS << ", ";
  213. if ((Desc.TSFlags & X86II::FormMask) == X86II::MRMSrcMem)
  214. printxmmwordmem(MI, 2, OS);
  215. else
  216. printOperand(MI, 2, OS);
  217. return true;
  218. }
  219. break;
  220. case X86::VPCMPBZ128rmi: case X86::VPCMPBZ128rri:
  221. case X86::VPCMPBZ256rmi: case X86::VPCMPBZ256rri:
  222. case X86::VPCMPBZrmi: case X86::VPCMPBZrri:
  223. case X86::VPCMPDZ128rmi: case X86::VPCMPDZ128rri:
  224. case X86::VPCMPDZ256rmi: case X86::VPCMPDZ256rri:
  225. case X86::VPCMPDZrmi: case X86::VPCMPDZrri:
  226. case X86::VPCMPQZ128rmi: case X86::VPCMPQZ128rri:
  227. case X86::VPCMPQZ256rmi: case X86::VPCMPQZ256rri:
  228. case X86::VPCMPQZrmi: case X86::VPCMPQZrri:
  229. case X86::VPCMPUBZ128rmi: case X86::VPCMPUBZ128rri:
  230. case X86::VPCMPUBZ256rmi: case X86::VPCMPUBZ256rri:
  231. case X86::VPCMPUBZrmi: case X86::VPCMPUBZrri:
  232. case X86::VPCMPUDZ128rmi: case X86::VPCMPUDZ128rri:
  233. case X86::VPCMPUDZ256rmi: case X86::VPCMPUDZ256rri:
  234. case X86::VPCMPUDZrmi: case X86::VPCMPUDZrri:
  235. case X86::VPCMPUQZ128rmi: case X86::VPCMPUQZ128rri:
  236. case X86::VPCMPUQZ256rmi: case X86::VPCMPUQZ256rri:
  237. case X86::VPCMPUQZrmi: case X86::VPCMPUQZrri:
  238. case X86::VPCMPUWZ128rmi: case X86::VPCMPUWZ128rri:
  239. case X86::VPCMPUWZ256rmi: case X86::VPCMPUWZ256rri:
  240. case X86::VPCMPUWZrmi: case X86::VPCMPUWZrri:
  241. case X86::VPCMPWZ128rmi: case X86::VPCMPWZ128rri:
  242. case X86::VPCMPWZ256rmi: case X86::VPCMPWZ256rri:
  243. case X86::VPCMPWZrmi: case X86::VPCMPWZrri:
  244. case X86::VPCMPBZ128rmik: case X86::VPCMPBZ128rrik:
  245. case X86::VPCMPBZ256rmik: case X86::VPCMPBZ256rrik:
  246. case X86::VPCMPBZrmik: case X86::VPCMPBZrrik:
  247. case X86::VPCMPDZ128rmik: case X86::VPCMPDZ128rrik:
  248. case X86::VPCMPDZ256rmik: case X86::VPCMPDZ256rrik:
  249. case X86::VPCMPDZrmik: case X86::VPCMPDZrrik:
  250. case X86::VPCMPQZ128rmik: case X86::VPCMPQZ128rrik:
  251. case X86::VPCMPQZ256rmik: case X86::VPCMPQZ256rrik:
  252. case X86::VPCMPQZrmik: case X86::VPCMPQZrrik:
  253. case X86::VPCMPUBZ128rmik: case X86::VPCMPUBZ128rrik:
  254. case X86::VPCMPUBZ256rmik: case X86::VPCMPUBZ256rrik:
  255. case X86::VPCMPUBZrmik: case X86::VPCMPUBZrrik:
  256. case X86::VPCMPUDZ128rmik: case X86::VPCMPUDZ128rrik:
  257. case X86::VPCMPUDZ256rmik: case X86::VPCMPUDZ256rrik:
  258. case X86::VPCMPUDZrmik: case X86::VPCMPUDZrrik:
  259. case X86::VPCMPUQZ128rmik: case X86::VPCMPUQZ128rrik:
  260. case X86::VPCMPUQZ256rmik: case X86::VPCMPUQZ256rrik:
  261. case X86::VPCMPUQZrmik: case X86::VPCMPUQZrrik:
  262. case X86::VPCMPUWZ128rmik: case X86::VPCMPUWZ128rrik:
  263. case X86::VPCMPUWZ256rmik: case X86::VPCMPUWZ256rrik:
  264. case X86::VPCMPUWZrmik: case X86::VPCMPUWZrrik:
  265. case X86::VPCMPWZ128rmik: case X86::VPCMPWZ128rrik:
  266. case X86::VPCMPWZ256rmik: case X86::VPCMPWZ256rrik:
  267. case X86::VPCMPWZrmik: case X86::VPCMPWZrrik:
  268. case X86::VPCMPDZ128rmib: case X86::VPCMPDZ128rmibk:
  269. case X86::VPCMPDZ256rmib: case X86::VPCMPDZ256rmibk:
  270. case X86::VPCMPDZrmib: case X86::VPCMPDZrmibk:
  271. case X86::VPCMPQZ128rmib: case X86::VPCMPQZ128rmibk:
  272. case X86::VPCMPQZ256rmib: case X86::VPCMPQZ256rmibk:
  273. case X86::VPCMPQZrmib: case X86::VPCMPQZrmibk:
  274. case X86::VPCMPUDZ128rmib: case X86::VPCMPUDZ128rmibk:
  275. case X86::VPCMPUDZ256rmib: case X86::VPCMPUDZ256rmibk:
  276. case X86::VPCMPUDZrmib: case X86::VPCMPUDZrmibk:
  277. case X86::VPCMPUQZ128rmib: case X86::VPCMPUQZ128rmibk:
  278. case X86::VPCMPUQZ256rmib: case X86::VPCMPUQZ256rmibk:
  279. case X86::VPCMPUQZrmib: case X86::VPCMPUQZrmibk:
  280. if ((Imm >= 0 && Imm <= 2) || (Imm >= 4 && Imm <= 6)) {
  281. OS << '\t';
  282. printVPCMPMnemonic(MI, OS);
  283. unsigned CurOp = 0;
  284. printOperand(MI, CurOp++, OS);
  285. if (Desc.TSFlags & X86II::EVEX_K) {
  286. // Print mask operand.
  287. OS << " {";
  288. printOperand(MI, CurOp++, OS);
  289. OS << "}";
  290. }
  291. OS << ", ";
  292. printOperand(MI, CurOp++, OS);
  293. OS << ", ";
  294. if ((Desc.TSFlags & X86II::FormMask) == X86II::MRMSrcMem) {
  295. if (Desc.TSFlags & X86II::EVEX_B) {
  296. // Broadcast form.
  297. // Load size is based on W-bit as only D and Q are supported.
  298. if (Desc.TSFlags & X86II::VEX_W)
  299. printqwordmem(MI, CurOp++, OS);
  300. else
  301. printdwordmem(MI, CurOp++, OS);
  302. // Print the number of elements broadcasted.
  303. unsigned NumElts;
  304. if (Desc.TSFlags & X86II::EVEX_L2)
  305. NumElts = (Desc.TSFlags & X86II::VEX_W) ? 8 : 16;
  306. else if (Desc.TSFlags & X86II::VEX_L)
  307. NumElts = (Desc.TSFlags & X86II::VEX_W) ? 4 : 8;
  308. else
  309. NumElts = (Desc.TSFlags & X86II::VEX_W) ? 2 : 4;
  310. OS << "{1to" << NumElts << "}";
  311. } else {
  312. if (Desc.TSFlags & X86II::EVEX_L2)
  313. printzmmwordmem(MI, CurOp++, OS);
  314. else if (Desc.TSFlags & X86II::VEX_L)
  315. printymmwordmem(MI, CurOp++, OS);
  316. else
  317. printxmmwordmem(MI, CurOp++, OS);
  318. }
  319. } else {
  320. printOperand(MI, CurOp++, OS);
  321. }
  322. return true;
  323. }
  324. break;
  325. }
  326. return false;
  327. }
  328. void X86IntelInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
  329. raw_ostream &O) {
  330. const MCOperand &Op = MI->getOperand(OpNo);
  331. if (Op.isReg()) {
  332. printRegName(O, Op.getReg());
  333. } else if (Op.isImm()) {
  334. O << formatImm((int64_t)Op.getImm());
  335. } else {
  336. assert(Op.isExpr() && "unknown operand kind in printOperand");
  337. O << "offset ";
  338. Op.getExpr()->print(O, &MAI);
  339. }
  340. }
  341. void X86IntelInstPrinter::printMemReference(const MCInst *MI, unsigned Op,
  342. raw_ostream &O) {
  343. // Do not print the exact form of the memory operand if it references a known
  344. // binary object.
  345. if (SymbolizeOperands && MIA) {
  346. uint64_t Target;
  347. if (MIA->evaluateBranch(*MI, 0, 0, Target))
  348. return;
  349. if (MIA->evaluateMemoryOperandAddress(*MI, /*STI=*/nullptr, 0, 0))
  350. return;
  351. }
  352. const MCOperand &BaseReg = MI->getOperand(Op+X86::AddrBaseReg);
  353. unsigned ScaleVal = MI->getOperand(Op+X86::AddrScaleAmt).getImm();
  354. const MCOperand &IndexReg = MI->getOperand(Op+X86::AddrIndexReg);
  355. const MCOperand &DispSpec = MI->getOperand(Op+X86::AddrDisp);
  356. // If this has a segment register, print it.
  357. printOptionalSegReg(MI, Op + X86::AddrSegmentReg, O);
  358. O << '[';
  359. bool NeedPlus = false;
  360. if (BaseReg.getReg()) {
  361. printOperand(MI, Op+X86::AddrBaseReg, O);
  362. NeedPlus = true;
  363. }
  364. if (IndexReg.getReg()) {
  365. if (NeedPlus) O << " + ";
  366. if (ScaleVal != 1)
  367. O << ScaleVal << '*';
  368. printOperand(MI, Op+X86::AddrIndexReg, O);
  369. NeedPlus = true;
  370. }
  371. if (!DispSpec.isImm()) {
  372. if (NeedPlus) O << " + ";
  373. assert(DispSpec.isExpr() && "non-immediate displacement for LEA?");
  374. DispSpec.getExpr()->print(O, &MAI);
  375. } else {
  376. int64_t DispVal = DispSpec.getImm();
  377. if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg())) {
  378. if (NeedPlus) {
  379. if (DispVal > 0)
  380. O << " + ";
  381. else {
  382. O << " - ";
  383. DispVal = -DispVal;
  384. }
  385. }
  386. O << formatImm(DispVal);
  387. }
  388. }
  389. O << ']';
  390. }
  391. void X86IntelInstPrinter::printSrcIdx(const MCInst *MI, unsigned Op,
  392. raw_ostream &O) {
  393. // If this has a segment register, print it.
  394. printOptionalSegReg(MI, Op + 1, O);
  395. O << '[';
  396. printOperand(MI, Op, O);
  397. O << ']';
  398. }
  399. void X86IntelInstPrinter::printDstIdx(const MCInst *MI, unsigned Op,
  400. raw_ostream &O) {
  401. // DI accesses are always ES-based.
  402. O << "es:[";
  403. printOperand(MI, Op, O);
  404. O << ']';
  405. }
  406. void X86IntelInstPrinter::printMemOffset(const MCInst *MI, unsigned Op,
  407. raw_ostream &O) {
  408. const MCOperand &DispSpec = MI->getOperand(Op);
  409. // If this has a segment register, print it.
  410. printOptionalSegReg(MI, Op + 1, O);
  411. O << '[';
  412. if (DispSpec.isImm()) {
  413. O << formatImm(DispSpec.getImm());
  414. } else {
  415. assert(DispSpec.isExpr() && "non-immediate displacement?");
  416. DispSpec.getExpr()->print(O, &MAI);
  417. }
  418. O << ']';
  419. }
  420. void X86IntelInstPrinter::printU8Imm(const MCInst *MI, unsigned Op,
  421. raw_ostream &O) {
  422. if (MI->getOperand(Op).isExpr())
  423. return MI->getOperand(Op).getExpr()->print(O, &MAI);
  424. O << formatImm(MI->getOperand(Op).getImm() & 0xff);
  425. }
  426. void X86IntelInstPrinter::printSTiRegOperand(const MCInst *MI, unsigned OpNo,
  427. raw_ostream &OS) {
  428. const MCOperand &Op = MI->getOperand(OpNo);
  429. unsigned Reg = Op.getReg();
  430. // Override the default printing to print st(0) instead st.
  431. if (Reg == X86::ST0)
  432. OS << "st(0)";
  433. else
  434. printRegName(OS, Reg);
  435. }