<commit_before>//
//  riscv-test-emulate.cc
//

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cinttypes>
#include <cstdarg>
#include <cerrno>
#include <cmath>
#include <cfenv>
#include <algorithm>
#include <memory>
#include <random>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <map>

#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>

#include "riscv-endian.h"
#include "riscv-types.h"
#include "riscv-bits.h"
#include "riscv-format.h"
#include "riscv-meta.h"
#include "riscv-util.h"
#include "riscv-host.h"
#include "riscv-cmdline.h"
#include "riscv-codec.h"
#include "riscv-elf.h"
#include "riscv-elf-file.h"
#include "riscv-elf-format.h"
#include "riscv-strings.h"
#include "riscv-disasm.h"
#include "riscv-processor.h"
#include "riscv-alu.h"
#include "riscv-fpu.h"
#include "riscv-pte.h"
#include "riscv-pma.h"
#include "riscv-memory.h"
#include "riscv-cache.h"
#include "riscv-mmu.h"
#include "riscv-interp.h"
#include "riscv-machine.h"
#include "riscv-unknown-abi.h"

#if defined (ENABLE_GPERFTOOL)
#include "gperftools/profiler.h"
#endif

using namespace riscv;

/*
 * Processor base template
 */

template<typename T, typename P, typename M>
struct processor_base : P
{
	typedef T decode_type;
	typedef P processor_type;
	typedef M mmu_type;

	bool log_registers;
	bool log_instructions;
	mmu_type mmu;

	processor_base() :
		P(),
		log_registers(false),
		log_instructions(false)
	{}

	std::string format_inst(uintptr_t pc)
	{
		char buf[20];
		uintptr_t length;
		uint64_t inst = inst_fetch(pc, &length);
		switch (length) {
			case 2:  snprintf(buf, sizeof(buf), "0x%08tx", inst); break;
			case 4:  snprintf(buf, sizeof(buf), "0x%08tx", inst); break;
			case 6:  snprintf(buf, sizeof(buf), "0x%012tx", inst); break;
			case 8:  snprintf(buf, sizeof(buf), "0x%016tx", inst); break;
			default: snprintf(buf, sizeof(buf), "(invalid)"); break;
		}
		return buf;
	}

	void print_disassembly(T &dec)
	{<commit_msg>Distinguish RVC instruction width in emulator dissassembly output<commit_after>//
//  riscv-test-emulate.cc
//

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cinttypes>
#include <cstdarg>
#include <cerrno>
#include <cmath>
#include <cfenv>
#include <algorithm>
#include <memory>
#include <random>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <map>

#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>

#include "riscv-endian.h"
#include "riscv-types.h"
#include "riscv-bits.h"
#include "riscv-format.h"
#include "riscv-meta.h"
#include "riscv-util.h"
#include "riscv-host.h"
#include "riscv-cmdline.h"
#include "riscv-codec.h"
#include "riscv-elf.h"
#include "riscv-elf-file.h"
#include "riscv-elf-format.h"
#include "riscv-strings.h"
#include "riscv-disasm.h"
#include "riscv-processor.h"
#include "riscv-alu.h"
#include "riscv-fpu.h"
#include "riscv-pte.h"
#include "riscv-pma.h"
#include "riscv-memory.h"
#include "riscv-cache.h"
#include "riscv-mmu.h"
#include "riscv-interp.h"
#include "riscv-machine.h"
#include "riscv-unknown-abi.h"

#if defined (ENABLE_GPERFTOOL)
#include "gperftools/profiler.h"
#endif

using namespace riscv;

/*
 * Processor base template
 */

template<typename T, typename P, typename M>
struct processor_base : P
{
	typedef T decode_type;
	typedef P processor_type;
	typedef M mmu_type;

	bool log_registers;
	bool log_instructions;
	mmu_type mmu;

	processor_base() :
		P(),
		log_registers(false),
		log_instructions(false)
	{}

	std::string format_inst(uintptr_t pc)
	{
		char buf[20];
		uintptr_t length;
		uint64_t inst = inst_fetch(pc, &length);
		switch (length) {
			case 2:  snprintf(buf, sizeof(buf), "    0x%04tx", inst); break;
			case 4:  snprintf(buf, sizeof(buf), "0x%08tx", inst); break;
			case 6:  snprintf(buf, sizeof(buf), "0x%012tx", inst); break;
			case 8:  snprintf(buf, sizeof(buf), "0x%016tx", inst); break;
			default: snprintf(buf, sizeof(buf), "(invalid)"); break;
		}
		return buf;
	}

	void print_disassembly(T &dec)
	{
{'fraction_non_alphanumeric': 0.16478666012751347, 'fraction_numerical': 0.010789602746444336, 'mean_word_length': 5.01622418879056, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, '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': '3077034', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1714, 'n_words': 373}