@@ -143,6 +143,9 @@ AsmHighlighter::AsmHighlighter(QTextDocument *parent) : QSyntaxHighlighter(paren
143143
144144 mnemonicFormat.setForeground (QColor (darkMode ? " darkorange" : " darkblue" ));
145145
146+ controlFlowFormat.setForeground (QColor (" crimson" ));
147+ controlFlowTargetFormat.setForeground (QColor (" #dc795d" ));
148+
146149 symbolFormat.setFontWeight (disasm.bold_sym ? QFont::DemiBold : QFont::Normal);
147150 rule.pattern = QRegularExpression (" \\ b\\ w+\\ b" );
148151 rule.format = symbolFormat;
@@ -187,6 +190,14 @@ void AsmHighlighter::highlightBlock(const QString &text) {
187190 setFormat (match.capturedStart (4 ), match.capturedLength (4 ), breakPFormat);
188191 setFormat (match.capturedStart (5 ), match.capturedLength (5 ), bytesFormat);
189192 setFormat (match.capturedStart (6 ), match.capturedLength (6 ), mnemonicFormat);
193+
194+ const QString fullMnemonic = match.captured (6 );
195+ const QString primary = fullMnemonic.section (' .' , 0 , 0 ).toUpper ();
196+ const bool isControlFlow = std::find (controlFlowMnemonics.begin (), controlFlowMnemonics.end (), primary) != controlFlowMnemonics.end ();
197+ if (isControlFlow) {
198+ setFormat (match.capturedStart (6 ), match.capturedLength (6 ), controlFlowFormat);
199+ }
200+
190201 foreach (const HighlightingRule &rule, highlightingRules) {
191202 QRegularExpressionMatchIterator iter = rule.pattern .globalMatch (text, match.capturedEnd ());
192203 while (iter.hasNext ()) {
@@ -196,5 +207,45 @@ void AsmHighlighter::highlightBlock(const QString &text) {
196207 }
197208 }
198209 }
210+
211+ if (!isControlFlow) {
212+ return ;
213+ }
214+
215+ if (std::find (noTargetMnemonics.begin (), noTargetMnemonics.end (), primary) != noTargetMnemonics.end ()) {
216+ return ;
217+ }
218+
219+ const int operandStart = match.capturedEnd ();
220+ const QString operands = text.mid (operandStart);
221+
222+ // hex address patterns allowing optional +/ - after '$' for relative forms like $+5
223+ const QRegularExpression hexTargetRe (QStringLiteral (" \\ $[+\\ -]?[0-9A-Fa-f]+\\ b" ));
224+ QRegularExpressionMatchIterator hIt = hexTargetRe.globalMatch (operands);
225+ while (hIt.hasNext ()) {
226+ const auto m2 = hIt.next ();
227+ if (m2.hasMatch ()) {
228+ const int s = operandStart + m2.capturedStart ();
229+ const int l = m2.capturedLength ();
230+ setFormat (s, l, controlFlowTargetFormat);
231+ }
232+ }
233+
234+ // equate/label tokens (exclude registers and condition codes)
235+ const QRegularExpression labelRe (QStringLiteral (" \\ b[._A-Za-z][._A-Za-z0-9]*\\ b" ));
236+
237+ QRegularExpressionMatchIterator lIt = labelRe.globalMatch (operands);
238+ while (lIt.hasNext ()) {
239+ const auto m3 = lIt.next ();
240+ if (m3.hasMatch ()) {
241+ const QString tok = m3.captured ().toUpper ();
242+ if (std::find (reservedTokens.begin (), reservedTokens.end (), tok) != reservedTokens.end ()) {
243+ continue ;
244+ }
245+ const int start = operandStart + m3.capturedStart ();
246+ const int len = m3.capturedLength ();
247+ setFormat (start, len, controlFlowTargetFormat);
248+ }
249+ }
199250 }
200251}
0 commit comments