diff options
author | Bartosz Taudul <wolf@nereid.pl> | 2022-09-16 00:34:39 +0300 |
---|---|---|
committer | Bartosz Taudul <wolf@nereid.pl> | 2022-09-16 00:36:31 +0300 |
commit | 4913f0e1e63164552e4d263e3f456310de535602 (patch) | |
tree | efdf82caa7563ead350db1131d49ca47bd450060 /server | |
parent | a45293d6ff0f0f5f8d4c8f23799e7b6ffabd26b0 (diff) |
Greatly simplify asm line text drawing.
This change also colors asm mnemonics and jump labels. Asm operands are not
yet colored.
Diffstat (limited to 'server')
-rw-r--r-- | server/TracySourceView.cpp | 98 |
1 files changed, 46 insertions, 52 deletions
diff --git a/server/TracySourceView.cpp b/server/TracySourceView.cpp index e9cb65d8..2b343c9a 100644 --- a/server/TracySourceView.cpp +++ b/server/TracySourceView.cpp @@ -3319,6 +3319,30 @@ void SourceView::RenderLine( const Tokenizer::Line& line, int lineNum, const Add DrawLine( draw, dpos + ImVec2( 0, ty ), dpos + ImVec2( w, ty ), 0x08FFFFFF ); } +static tracy_force_inline uint32_t AsmColor( uint32_t base, bool inContext, int isSelected ) +{ + if( inContext ) + { + switch( isSelected ) + { + case 0: return base; + case 1: return 0xFF3F3FFF; + case 2: return 0xFFFF88FF; + default: assert( false ); return 0; + } + } + else + { + switch( isSelected ) + { + case 0: return ( base & 0xFFFFFF ) | 0x88000000; + case 1: return 0x883F3FFF; + case 2: return 0x88FF88FF; + default: assert( false ); return 0; + } + } +} + void SourceView::RenderAsmLine( AsmLine& line, const AddrStat& ipcnt, const AddrStatData& as, Worker& worker, uint64_t& jumpOut, int maxAddrLen, View& view ) { const auto scale = GetScale(); @@ -3854,72 +3878,42 @@ void SourceView::RenderAsmLine( AsmLine& line, const AddrStat& ipcnt, const Addr } } - const auto msz = line.mnemonic.size(); - memcpy( buf, line.mnemonic.c_str(), msz ); - memset( buf+msz, ' ', m_maxMnemonicLen-msz ); - bool hasJump = false; - if( line.jumpAddr != 0 ) - { - auto lit = m_locMap.find( line.jumpAddr ); - if( lit != m_locMap.end() ) - { - char tmp[64]; - sprintf( tmp, ".L%" PRIu32, lit->second ); - strcpy( buf+m_maxMnemonicLen, tmp ); - hasJump = true; - } - } - if( !hasJump ) - { - memcpy( buf+m_maxMnemonicLen, line.operands.c_str(), line.operands.size() + 1 ); - } - - const bool isInContext = IsInContext( worker, line.addr ); - if( asmIdx == m_asmSelected ) - { - TextColoredUnformatted( ImVec4( 1, 0.25f, 0.25f, isInContext ? 1.f : 0.5f ), buf ); - } - else if( line.regData[0] != 0 ) + const bool inContext = IsInContext( worker, line.addr ); + int isSelected = asmIdx == m_asmSelected; + if( !isSelected && line.regData[0] != 0 ) { - bool hasDepencency = false; int idx = 0; - for(;;) + while( line.regData[idx] != 0 ) { - if( line.regData[idx] == 0 ) break; if( line.regData[idx] & ( WriteBit | ReadBit ) ) { - hasDepencency = true; + isSelected = 2; break; } idx++; } - if( hasDepencency ) - { - TextColoredUnformatted( ImVec4( 1, 0.5f, 1, isInContext ? 1.f : 0.5f ), buf ); - } - else - { - if( isInContext ) - { - ImGui::TextUnformatted( buf ); - } - else - { - TextDisabledUnformatted( buf ); - } - } } - else + + ImGui::BeginGroup(); + TextColoredUnformatted( AsmColor( AsmOpTypeColors[(int)line.opType], inContext, isSelected ), line.mnemonic.c_str() ); + ImGui::SameLine( 0, ImGui::CalcTextSize( " " ).x * ( m_maxMnemonicLen - line.mnemonic.size() ) ); + bool hasJump = false; + if( line.jumpAddr != 0 ) { - if( isInContext ) - { - ImGui::TextUnformatted( buf ); - } - else + auto lit = m_locMap.find( line.jumpAddr ); + if( lit != m_locMap.end() ) { - TextDisabledUnformatted( buf ); + ImGui::PushStyleColor( ImGuiCol_Text, AsmColor( AsmSyntaxColors[(int)Tokenizer::AsmTokenColor::Label], inContext, isSelected ) ); + ImGui::Text( ".L%" PRIu32, lit->second ); + ImGui::PopStyleColor(); + hasJump = true; } } + if( !hasJump ) + { + TextColoredUnformatted( AsmColor( 0xFFFFFFFF, inContext, isSelected ), line.operands.c_str() ); + } + ImGui::EndGroup(); uint32_t jumpOffset; uint64_t jumpBase; |