/** * Print the given basic block. * * @param block the basic block */ void JVMWriter::printBasicBlock(const BasicBlock *block) { printLabel(getLabelName(block)); if (trace) { if (block->hasName()) { std::string n = block->getName(); printTrc(n + ":"); } } for(BasicBlock::const_iterator i = block->begin(), e = block->end(); i != e; i++) { instNum++; if (trace) printSimpleInstruction(".line", utostr(trcLineNum+1)); else if(debug >= 1) printSimpleInstruction(".line", utostr(instNum)); if(debug >= 3 || trace) { // print current instruction as comment // note that this block of code significantly increases // code generation time std::string str; raw_string_ostream ss(str); ss << *i; ss.flush(); if (trace) printTrc(str); if (debug >= 3) { std::string::size_type pos = 0; while((pos = str.find("\n", pos)) != std::string::npos) str.replace(pos++, 1, "\n;"); out << ';' << str << '\n'; } } if(i->getOpcode() == Instruction::PHI) // don't handle phi instruction in current block continue; printInstruction(i); if(i->getType() != Type::getVoidTy(block->getContext()) && i->getOpcode() != Instruction::Invoke) // instruction doesn't return anything, or is an invoke instruction // which handles storing the return value itself printValueStore(i); } }
//----------------------------- FUNCTION -------------------------------------* /*static*/ void hexDump(BYTE* pby, int nBytes, int nShowBytes) /*>>>> print trace string to output device I pby: ptr to byte array to dump I nBytes: number of bytes in byte array I nShowBytes show max. N bytes before truncating Result void <<<<*/ { int nRow = 0; TCHAR szBuffer[50]; while (nBytes--) { if (nRow == 0) { wsprintf(szBuffer, _T("<%02X"), *pby++); } else { wsprintf(szBuffer, _T(" %02X"), *pby++); } printTrc(szBuffer); if (++nRow >= nShowBytes) { wsprintf(szBuffer, _T(" ...(trunc. by %d bytes)"), nBytes); printTrc(szBuffer); // nRow = 0; break; } } if (nRow != 0) { printTrc(_T(">\n")); s_bNewLine = TRUE; } }
//-------------------------- GLOBAL FUNCTION ---------------------------------* int TrcPrint(WORD wLevel, LPCTSTR pszFormat, ...) /*>>>> print trace line with current time I wLevel: trace level I pszFormat: format string for wsprintf() Result E_TRC_OK E_TRC_NOT_INITIALIZED E_TRC_BAD_LEVEL E_TRC_NO_RESOURCE <<<<*/ { if (!s_bInitialized) { return E_TRC_NOT_INITIALIZED; } if (s_traceMode == noTrace) { // trace mode is disabled return E_TRC_OK; } if ((wLevel & s_wLevel) == 0) { // this level is not activated return E_TRC_OK; } if (pszFormat == NULL) { return E_TRC_NO_RESOURCE; } // print time and level... SYSTEMTIME tm; GetLocalTime(&tm); TCHAR szBuffer[512]; EnterCriticalSection(&s_csTrcFile); if (s_bNewLine) { // insert date and time if start of new line: if (s_wCurrDay != tm.wDay) { printTrc(_T("--------------------------------------------------------------\n")); _stprintf(szBuffer, _T("Current date: %s %04d-%02d-%02d\n"), GetDayOfWeek(tm.wDayOfWeek), (int) tm.wYear, (int) tm.wMonth, (int) tm.wDay); printTrc(szBuffer); s_wCurrDay = tm.wDay; } _stprintf(szBuffer, _T("%02d:%02d:%02d.%03d(%03d)|"), (int) tm.wHour, (int) tm.wMinute, (int) tm.wSecond, (int) tm.wMilliseconds, ::GetCurrentThreadId()); printTrc(szBuffer); printTrc(GetTrcLevelString(wLevel)); printTrc(_T("|")); s_bNewLine = FALSE; } // ... and actual message: va_list args; va_start(args, pszFormat); int nBuf; nBuf = _vstprintf(szBuffer, pszFormat, args); assert(nBuf < _countof(szBuffer)); va_end(args); printTrc(szBuffer); int len = _tcslen(szBuffer); if (len > 0) { if ( (szBuffer[len - 1] == _T('\n')) || (szBuffer[len - 1] == _T('\r'))) { s_bNewLine = TRUE; } } // check if max file size was reached: if ((s_hfTrc != NULL) && s_bNewLine && (s_uFileSize > 0)) { if ((UINT)(ftell(s_hfTrc) / 1000) > s_uFileSize) { fclose(s_hfTrc); _tremove(s_pszOldTrcFile); _trename(s_pszTraceFile, s_pszOldTrcFile); s_hfTrc = NULL; s_wCurrDay = 0; // force date line as first line in new file } } LeaveCriticalSection(&s_csTrcFile); return E_TRC_OK; }