@@ -374,39 +374,51 @@ void RISCV_LLVM_printInstruction(MCInst *MI, SStream *O,
374374 MI -> MRI = (MCRegisterInfo * )info ;
375375
376376 MCInst_setIsAlias (MI , false);
377+
378+ /* check for a non-compressed instruction */
379+ MCInst Uncompressed ;
380+ MCInst_Init (& Uncompressed , MI -> csh -> arch );
381+
382+ MCInst * McInstr = MI ;
383+ bool is_uncompressed = false;
384+ // side-effectful check for compressed instructions that creates the equivalent uncompressed instruction in case of true
385+ // (LLVM doesn't generate an API for doing a pure check)
386+ if (uncompressInst (& Uncompressed , MI )) {
387+ McInstr = & Uncompressed ;
388+ Uncompressed .address = MI -> address ;
389+ Uncompressed .MRI = MI -> MRI ;
390+ Uncompressed .csh = MI -> csh ;
391+ Uncompressed .flat_insn = MI -> flat_insn ;
392+ is_uncompressed = true;
393+ }
394+
377395 // print the exact instruction text and done
378- if (MI -> csh -> syntax & CS_OPT_SYNTAX_NO_ALIAS_TEXT ) {
396+ bool print_exact_text =
397+ (MI -> csh -> syntax & CS_OPT_SYNTAX_NO_ALIAS_TEXT ) ||
398+ (is_uncompressed &&
399+ MI -> csh -> syntax & CS_OPT_SYNTAX_NO_ALIAS_TEXT_COMPRESSED );
400+ if (print_exact_text ) {
379401 printInstruction (MI , MI -> address , O );
380402 } else {
381- /* the instruction might be an alias, including in the case of a compressed instruction */
382- MCInst Uncompressed ;
383- MCInst_Init (& Uncompressed , MI -> csh -> arch );
384-
385- MCInst * McInstr = MI ;
386- if (uncompressInst (& Uncompressed , MI )) {
387- McInstr = & Uncompressed ;
388- Uncompressed .address = MI -> address ;
389- Uncompressed .MRI = MI -> MRI ;
390- Uncompressed .csh = MI -> csh ;
391- Uncompressed .flat_insn = MI -> flat_insn ;
392- }
393-
403+ // side-effectful check for alias instructions that prints to the SStream if true
394404 if (printAliasInstr (McInstr , MI -> address , O )) {
395405 MCInst_setIsAlias (MI , true);
406+ // do we still want the exact details even if the text is alias ?
396407 if (!map_use_alias_details (MI ) && detail_is_set (MI )) {
397408 // disable actual printing
398409 SStream_Close (O );
410+ // discard the alias operands
399411 memset (MI -> flat_insn -> detail -> riscv .operands , 0 ,
400412 sizeof (MI -> flat_insn -> detail -> riscv
401413 .operands ));
402414 MI -> flat_insn -> detail -> riscv .op_count = 0 ;
403- // re-disassemble again in order to obtain the full details
415+ // re-disassemble again with no printing in order to obtain the full details
404416 // including the whole operands array
405417 printInstruction (MI , MI -> address , O );
406418 // re-open the stream to restore the usual state
407419 SStream_Open (O );
408420 }
409- } else
421+ } else // the instruction is not an alias
410422 printInstruction (McInstr , MI -> address , O );
411423 }
412424 RISCV_add_groups (MI );
0 commit comments