From d823a2453473618b29b34109c06caf7fcf0f6c97 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 16 Sep 2022 00:30:29 +0200 Subject: [PATCH] Dummy tokenization of asm operands. --- server/TracySourceTokenizer.cpp | 22 ++++++++++++++++++++++ server/TracySourceTokenizer.hpp | 9 +++++++++ server/TracySourceView.cpp | 2 ++ server/TracySourceView.hpp | 1 + 4 files changed, 34 insertions(+) diff --git a/server/TracySourceTokenizer.cpp b/server/TracySourceTokenizer.cpp index f741b8fa..cbf975d1 100644 --- a/server/TracySourceTokenizer.cpp +++ b/server/TracySourceTokenizer.cpp @@ -351,4 +351,26 @@ out: return TokenColor::Default; } +std::vector Tokenizer::TokenizeAsm( const char* begin, const char* end ) +{ + std::vector ret; + while( begin != end ) + { + while( begin != end && isspace( (uint8_t)*begin ) ) begin++; + const auto pos = begin; + const auto col = IdentifyAsmToken( begin, end ); + ret.emplace_back( AsmToken { pos, begin, col } ); + } + return ret; +} + +Tokenizer::AsmTokenColor Tokenizer::IdentifyAsmToken( const char*& begin, const char* end ) +{ + static const auto s_regs = GetAsmRegs(); + static const auto s_sizes = GetAsmSizeDirectives(); + + begin = end; + return AsmTokenColor::Default; +} + } diff --git a/server/TracySourceTokenizer.hpp b/server/TracySourceTokenizer.hpp index 3ab76946..038f1f12 100644 --- a/server/TracySourceTokenizer.hpp +++ b/server/TracySourceTokenizer.hpp @@ -47,12 +47,21 @@ public: Literal, // 0x04, etc }; + struct AsmToken + { + const char* begin; + const char* end; + AsmTokenColor color; + }; + Tokenizer(); std::vector Tokenize( const char* begin, const char* end ); + std::vector TokenizeAsm( const char* begin, const char* end ); private: TokenColor IdentifyToken( const char*& begin, const char* end ); + AsmTokenColor IdentifyAsmToken( const char*& begin, const char* end ); bool m_isInComment; bool m_isInPreprocessor; diff --git a/server/TracySourceView.cpp b/server/TracySourceView.cpp index 2b343c9a..f342c943 100644 --- a/server/TracySourceView.cpp +++ b/server/TracySourceView.cpp @@ -891,6 +891,8 @@ bool SourceView::Disassemble( uint64_t symAddr, const Worker& worker ) } } m_asm.emplace_back( AsmLine { op.address, jumpAddr, op.mnemonic, op.op_str, (uint8_t)op.size, leaData, opType, jumpConditional, std::move( params ) } ); + const auto& operands = m_asm.back().operands; + m_asm.back().opTokens = m_tokenizer.TokenizeAsm( operands.c_str(), operands.c_str() + operands.size() ); #if CS_API_MAJOR >= 4 auto& entry = m_asm.back(); diff --git a/server/TracySourceView.hpp b/server/TracySourceView.hpp index 120a188d..ef514ecd 100644 --- a/server/TracySourceView.hpp +++ b/server/TracySourceView.hpp @@ -98,6 +98,7 @@ private: OpType opType; bool jumpConditional; std::vector params; + std::vector opTokens; union { RegsX86 readX86[12];