Skip to content

Commit bc9042a

Browse files
committed
RISCV: compressed insn treats the uncompressed version as an alias
1 parent 25c4796 commit bc9042a

1 file changed

Lines changed: 43 additions & 19 deletions

File tree

arch/RISCV/RISCVInstPrinter.c

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -400,28 +400,52 @@ void RISCV_LLVM_printInstruction(MCInst *MI, SStream *O,
400400
(is_uncompressed &&
401401
MI->csh->syntax & CS_OPT_SYNTAX_NO_ALIAS_TEXT_COMPRESSED);
402402
if (print_exact_text) {
403+
// while we always print real operands for NO_ALIAS_TEXT, set this explicitly
404+
MI->flat_insn->usesAliasDetails = false;
403405
printInstruction(MI, MI->address, O);
404-
} else {
405406
// side-effectful check for alias instructions that prints to the SStream if true
406-
if (printAliasInstr(McInstr, MI->address, O)) {
407-
MCInst_setIsAlias(MI, true);
408-
// do we still want the exact details even if the text is alias ?
409-
if (!usesAliasDetails && detail_is_set(MI)) {
410-
// disable actual printing
411-
SStream_Close(O);
412-
// discard the alias operands
413-
memset(MI->flat_insn->detail->riscv.operands, 0,
414-
sizeof(MI->flat_insn->detail->riscv
415-
.operands));
416-
MI->flat_insn->detail->riscv.op_count = 0;
417-
// re-disassemble again with no printing in order to obtain the full details
418-
// including the whole operands array
419-
printInstruction(MI, MI->address, O);
420-
// re-open the stream to restore the usual state
421-
SStream_Open(O);
407+
} else if (printAliasInstr(McInstr, MI->address, O)) {
408+
MCInst_setIsAlias(MI, true);
409+
// do we still want the exact details even if the text is alias ?
410+
if (!usesAliasDetails && detail_is_set(MI)) {
411+
// disable actual printing
412+
SStream_Close(O);
413+
// discard the alias operands
414+
memset(MI->flat_insn->detail->riscv.operands, 0,
415+
sizeof(MI->flat_insn->detail->riscv.operands));
416+
MI->flat_insn->detail->riscv.op_count = 0;
417+
// re-disassemble again with no printing in order to obtain the full details
418+
// including the whole operands array
419+
printInstruction(MI, MI->address, O);
420+
// re-open the stream to restore the usual state
421+
SStream_Open(O);
422+
}
423+
// the instruction is not an ISA alias, but it still can be an uncompressed "alias"
424+
} else {
425+
if (is_uncompressed) {
426+
unsigned int i = find_cs_id(MCInst_getOpcode(&Uncompressed),
427+
RISCV_insns, RISCV_insn_count);
428+
if (i != -1) {
429+
Uncompressed.flat_insn->alias_id = RISCV_insns[i].mapid;
430+
MCInst_setIsAlias(&Uncompressed, true);
422431
}
423-
} else // the instruction is not an alias
424-
printInstruction(McInstr, MI->address, O);
432+
}
433+
printInstruction(McInstr, MI->address, O);
434+
435+
// do we still want the exact details even if the text is alias ?
436+
if (!usesAliasDetails && detail_is_set(MI)) {
437+
// disable actual printing
438+
SStream_Close(O);
439+
// discard the alias operands
440+
memset(MI->flat_insn->detail->riscv.operands, 0,
441+
sizeof(MI->flat_insn->detail->riscv.operands));
442+
MI->flat_insn->detail->riscv.op_count = 0;
443+
// re-disassemble again with no printing in order to obtain the full details
444+
// including the whole operands array
445+
printInstruction(MI, MI->address, O);
446+
// re-open the stream to restore the usual state
447+
SStream_Open(O);
448+
}
425449
}
426450
RISCV_add_groups(MI);
427451
RISCV_add_missing_write_access(MI);

0 commit comments

Comments
 (0)