diff --git a/src/rv32iinterpreter.cpp b/src/rv32iinterpreter.cpp index af3079d..a09ff0b 100644 --- a/src/rv32iinterpreter.cpp +++ b/src/rv32iinterpreter.cpp @@ -9,6 +9,11 @@ #include #include #include +#ifdef DEBUG +#define DEBUG_CERR std::cerr +#else +#define DEBUG_CERR if(0) std::cerr +#endif inline uint8_t ReadBit(uint32_t data, int pos) { return (data >> pos) & 1; } inline void WriteBit(uint32_t &data, int pos, uint8_t bit) { data &= ~(1 << pos); @@ -75,7 +80,7 @@ ExecuteFunc Decode(uint32_t instr) { funct7 = 0; } uint8_t second_key = funct3 | (funct7 << 3); - std::cerr << "Decoding, opcode=" << std::hex << (int)opcode << " second_key=" << std::dec << (int)second_key + DEBUG_CERR << "Decoding, opcode=" << std::hex << (int)opcode << " second_key=" << std::dec << (int)second_key << std::endl; if (ExecuteFuncMap.find({opcode, second_key}) == ExecuteFuncMap.end()) { throw std::runtime_error("Unsupported instruction"); @@ -130,7 +135,7 @@ class RV32IInterpreter { void PrintRegisters() { for (int i = 0; i < 32; i++) { - std::cerr << "x" << i << "=" << std::hex << std::uppercase << std::setw(8) << std::setfill('0') << reg[i] + DEBUG_CERR << "x" << i << "=" << std::hex << std::uppercase << std::setw(8) << std::setfill('0') << reg[i] << std::endl; } } @@ -150,7 +155,7 @@ class RV32IInterpreter { int addr, tmp; std::vector buf; fin >> addr; - // std::cerr << "begin:" << std::hex << addr << std::endl; + // DEBUG_CERR << "begin:" << std::hex << addr << std::endl; while (fin >> tmp) { buf.push_back(tmp); } @@ -159,7 +164,7 @@ class RV32IInterpreter { } for (int i = 0; i < buf.size(); i++) { dat[addr + i] = buf[i]; - // std::cerr << std::hex << addr + i << ' ' << std::uppercase << std::setw(2) << std::setfill('0') << std::hex + // DEBUG_CERR << std::hex << addr + i << ' ' << std::uppercase << std::setw(2) << std::setfill('0') << std::hex // << (int)buf[i] << std::endl; } fin.clear(); @@ -168,10 +173,10 @@ class RV32IInterpreter { memset(reg, 0, sizeof(reg)); } bool Fetch() { - std::cerr<<"Fetching PC: "<(&dat[PC]); if (IR == 0x0FF00513) { - // std::cerr<<"ready to exit"<