<commit_before>/* Capstone Disassembly Engine */
/* TMS320C64x Backend by <NAME> <<EMAIL>> 2016 */

#ifdef CAPSTONE_HAS_TMS320C64X

#include <ctype.h>
#include <string.h>

#include "TMS320C64xInstPrinter.h"
#include "../../MCInst.h"
#include "../../utils.h"
#include "../../SStream.h"
#include "../../MCRegisterInfo.h"
#include "../../MathExtras.h"
#include "TMS320C64xMapping.h"

#include "capstone/tms320c64x.h"

static char *getRegisterName(unsigned RegNo);
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O);
static void printMemOperand(MCInst *MI, unsigned OpNo, SStream *O);
static void printMemOperand2(MCInst *MI, unsigned OpNo, SStream *O);
static void printRegPair(MCInst *MI, unsigned OpNo, SStream *O);

void TMS320C64x_post_printer(csh ud, cs_insn *insn, char *insn_asm, MCInst *mci)
{
	SStream ss;
	char *p, *p2, tmp[8];
	unsigned int unit = 0;
	int i;
	cs_tms320c64x *tms320c64x;

	if (mci->csh->detail) {
		tms320c64x = &mci->flat_insn->detail->tms320c64x;

		for (i = 0; i < insn->detail->groups_count; i++) {
			switch(insn->detail->groups[i]) {
				case TMS320C64X_GRP_FUNIT_D:
					unit = TMS320C64X_FUNIT_D;
					break;
				case TMS320C64X_GRP_FUNIT_L:
					unit = TMS320C64X_FUNIT_L;
					break;
				case TMS320C64X_GRP_FUNIT_M:
					unit = TMS320C64X_FUNIT_M;
					break;
				case TMS320C64X_GRP_FUNIT_S:
					unit = TMS320C64X_FUNIT_S;
					break;
				case TMS320C64X_GRP_FUNIT_NO:
					unit = TMS320C64X_FUNIT_NO;
					break;
			}
			if (unit != 0)
				break;
		}
		tms320c64x->funit.unit = unit;

		SStream_Init(&ss);
		if (tms320c64x->condition.reg != TMS320C64X_REG_INVALID)
			SStream_concat(&ss, "[%c%s]|", (tms320c64x->condition.zero == 1) ? '!' : '|', cs_reg_name(ud, tms320c64x->condition.reg));
		else
			SStream_concat0(&ss, "||||||");

		p = strchr(insn_asm, '\t');
		if (p != NULL)
			*p++ = '\0';

		SStream_concat0(&ss, insn_asm);
		if ((p != NULL) && (((p2 = strchr(p, '[')) != NULL) || ((p2 = strchr(p, '(')) != NULL))) {
			while ((p2 > p) && ((*p2 != 'A') && (*p2 != 'B')))
				p2--;
			if (p2 == p) {
				strcpy(insn_asm, "Invalid!");
				return;
			}
			if (*p2 == 'A')
				strcpy(tmp, "1T");
			else
				strcpy(tmp, "2T");
		} else {
			tmp[0] = '\0';
		}
		switch(tms320c64x->funit.unit) {
			case TMS320C64X_FUNIT_D:
				SStream_concat(&ss, ".D%s%u", tmp, tms320c64x->funit.side);
				break;
			case TMS320C64X_FUNIT_L:
				SStream_concat(&ss, ".L%s%u", tmp, tms320c64x->funit.side);
				break;
			case TMS320C64X_FUNIT_M:
				SStream_concat(&ss, ".M%s%u", tmp, tms320c64x->funit.side);
				break;
			case TMS320C64X_FUNIT_S:
				SStream_concat(&ss, ".S%s%u", tmp, tms320c64x->funit.side);
				break;<commit_msg>Fixed TMS320C64x failed to print instructions (#1367)<commit_after>/* Capstone Disassembly Engine */
/* TMS320C64x Backend by <NAME> <<EMAIL>> 2016 */

#ifdef CAPSTONE_HAS_TMS320C64X

#include <ctype.h>
#include <string.h>

#include "TMS320C64xInstPrinter.h"
#include "../../MCInst.h"
#include "../../utils.h"
#include "../../SStream.h"
#include "../../MCRegisterInfo.h"
#include "../../MathExtras.h"
#include "TMS320C64xMapping.h"

#include "capstone/tms320c64x.h"

static char *getRegisterName(unsigned RegNo);
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O);
static void printMemOperand(MCInst *MI, unsigned OpNo, SStream *O);
static void printMemOperand2(MCInst *MI, unsigned OpNo, SStream *O);
static void printRegPair(MCInst *MI, unsigned OpNo, SStream *O);

void TMS320C64x_post_printer(csh ud, cs_insn *insn, char *insn_asm, MCInst *mci)
{
	SStream ss;
	char *p, *p2, tmp[8];
	unsigned int unit = 0;
	int i;
	cs_tms320c64x *tms320c64x;

	if (mci->csh->detail) {
		tms320c64x = &mci->flat_insn->detail->tms320c64x;

		for (i = 0; i < insn->detail->groups_count; i++) {
			switch(insn->detail->groups[i]) {
				case TMS320C64X_GRP_FUNIT_D:
					unit = TMS320C64X_FUNIT_D;
					break;
				case TMS320C64X_GRP_FUNIT_L:
					unit = TMS320C64X_FUNIT_L;
					break;
				case TMS320C64X_GRP_FUNIT_M:
					unit = TMS320C64X_FUNIT_M;
					break;
				case TMS320C64X_GRP_FUNIT_S:
					unit = TMS320C64X_FUNIT_S;
					break;
				case TMS320C64X_GRP_FUNIT_NO:
					unit = TMS320C64X_FUNIT_NO;
					break;
			}
			if (unit != 0)
				break;
		}
		tms320c64x->funit.unit = unit;

		SStream_Init(&ss);
		if (tms320c64x->condition.reg != TMS320C64X_REG_INVALID)
			SStream_concat(&ss, "[%c%s]|", (tms320c64x->condition.zero == 1) ? '!' : '|', cs_reg_name(ud, tms320c64x->condition.reg));
		else
			SStream_concat0(&ss, "||||||");

		p = strchr(insn_asm, '\t');
		if (p != NULL)
			*p++ = '\0';

		SStream_concat0(&ss, insn_asm);
		if ((p != NULL) && (((p2 = strchr(p, '[')) != NULL) || ((p2 = strchr(p, '(')) != NULL))) {
			while ((p2 > p) && ((*p2 != 'a') && (*p2 != 'b')))
				p2--;
			if (p2 == p) {
				strcpy(insn_asm, "Invalid!");
				return;
			}
			if (*p2 == 'a')
				strcpy(tmp, "1T");
			else
				strcpy(tmp, "2T");
		} else {
			tmp[0] = '\0';
		}
		switch(tms320c64x->funit.unit) {
			case TMS320C64X_FUNIT_D:
				SStream_concat(&ss, ".D%s%u", tmp, tms320c64x->funit.side);
				break;
			case TMS320C64X_FUNIT_L:
				SStream_concat(&ss, ".L%s%u", tmp, tms320c64x->funit.side);
				break;
			case TMS320C64X_FUNIT_M:
				SStream_concat(&ss, ".M%s%u", tmp, tms320c64x->funit.side);
				break;
			case TMS320C64X_FUNIT_S:
				SStream_concat(&ss, ".S%s%u", tmp, tms320c64x->funit.side);
				break;
{'fraction_non_alphanumeric': 0.17916821388785742, 'fraction_numerical': 0.07445228369847753, 'mean_word_length': 3.688424717145344, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '116747', 'n_tokens_mistral': 2883, 'n_tokens_neox': 2378, 'n_words': 441}