Skip to content

Commit fd05990

Browse files
committed
draft
1 parent 5e1ee99 commit fd05990

File tree

8 files changed

+47
-6
lines changed

8 files changed

+47
-6
lines changed

src/assembler/simpleasm.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,9 @@ bool SimpleAsm::process_line(
520520
return false;
521521
}
522522
uint32_t *p = inst;
523+
printf("address: {%x} -> start_line: {%d}, size: {%d}", address, line_number, size);
523524
for (size_t l = 0; l < size; l += 4) {
525+
addressToLine.insert(address, line_number);
524526
if (!fatal_occured) { mem->write_u32(address, *(p++), ae::INTERNAL); }
525527
address += 4;
526528
}

src/assembler/simpleasm.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ class SimpleAsm : public QObject {
4848
~SimpleAsm() override;
4949

5050
public:
51-
static uint64_t
52-
string_to_uint64(const QString &str, int base, int *chars_taken = nullptr);
51+
static uint64_t string_to_uint64(const QString &str, int base, int *chars_taken = nullptr);
5352
void clear();
5453
void setup(
5554
machine::FrontendMemory *mem,
@@ -61,8 +60,7 @@ class SimpleAsm : public QObject {
6160
const QString &filename = "",
6261
int line_number = 0,
6362
QString *error_ptr = nullptr);
64-
virtual bool
65-
process_file(const QString &filename, QString *error_ptr = nullptr);
63+
virtual bool process_file(const QString &filename, QString *error_ptr = nullptr);
6664
bool finish(QString *error_ptr = nullptr);
6765

6866
protected:
@@ -76,6 +74,9 @@ class SimpleAsm : public QObject {
7674
SymbolTableDb *symtab {};
7775
machine::Address address {};
7876

77+
public:
78+
QMap<machine::Address, int> addressToLine = {};
79+
7980
private:
8081
QStringList include_stack;
8182
machine::FrontendMemory *mem {};

src/gui/mainwindow/mainwindow.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ void MainWindow::create_core(
300300
connect(machine.data(), &machine::Machine::status_change, this, &MainWindow::machine_status);
301301
connect(machine.data(), &machine::Machine::program_exit, this, &MainWindow::machine_exit);
302302
connect(machine.data(), &machine::Machine::program_trap, this, &MainWindow::machine_trap);
303+
connect(
304+
machine.data()->core(), &machine::Core::highlight_editor, this,
305+
&MainWindow::hightlightByAddress);
303306
// Connect signal from break to machine pause
304307
connect(
305308
machine->core(), &machine::Core::stop_on_exception_reached, machine.data(),
@@ -334,6 +337,12 @@ void MainWindow::new_machine() {
334337
ndialog->show();
335338
}
336339

340+
void MainWindow::hightlightByAddress(machine::Address addr) {
341+
auto lineNum = lineToAddress.value(addr);
342+
printf("hightlightByAddress addr: %x, block: %d\n", addr, lineNum);
343+
editor_tabs->get_current_editor()->highlightBlock(lineNum);
344+
}
345+
337346
void MainWindow::machine_reload(bool force_memory_reset, bool force_elf_load) {
338347
if (machine == nullptr) { return new_machine(); }
339348
bool load_executable = force_elf_load || machine->executable_loaded();
@@ -414,7 +423,7 @@ void MainWindow::reset_state_##NAME() {
414423

415424
SHOW_HANDLER(registers, Qt::TopDockWidgetArea, true)
416425
SHOW_HANDLER(program, Qt::LeftDockWidgetArea, true)
417-
SHOW_HANDLER(memory, Qt::RightDockWidgetArea, true )
426+
SHOW_HANDLER(memory, Qt::RightDockWidgetArea, true)
418427
SHOW_HANDLER(cache_program, Qt::RightDockWidgetArea, false)
419428
SHOW_HANDLER(cache_data, Qt::RightDockWidgetArea, false)
420429
SHOW_HANDLER(cache_level2, Qt::RightDockWidgetArea, false)
@@ -632,7 +641,7 @@ void MainWindow::message_selected(
632641
}
633642

634643
bool SimpleAsmWithEditorCheck::process_file(const QString &filename, QString *error_ptr) {
635-
EditorTab* tab = mainwindow->editor_tabs->find_tab_by_filename(filename);
644+
EditorTab *tab = mainwindow->editor_tabs->find_tab_by_filename(filename);
636645
if (tab == nullptr) { return Super::process_file(filename, error_ptr); }
637646
SrcEditor *editor = tab->get_editor();
638647
QTextDocument *doc = editor->document();
@@ -759,6 +768,8 @@ void MainWindow::compile_source() {
759768
}
760769
if (!sasm.finish()) { error_occured = true; }
761770

771+
lineToAddress = sasm.addressToLine;
772+
762773
if (error_occured) { show_messages(); }
763774
}
764775

src/gui/mainwindow/mainwindow.h

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class MainWindow : public QMainWindow {
6060

6161
public slots:
6262
// Actions signals
63+
void hightlightByAddress(machine::Address addr);
6364
void new_machine();
6465
void machine_reload(bool force_memory_reset = false, bool force_elf_load = false);
6566
void print_action();
@@ -115,6 +116,9 @@ public slots:
115116
protected:
116117
void closeEvent(QCloseEvent *cancel) override;
117118

119+
public:
120+
QMap<machine::Address, int> lineToAddress = {};
121+
118122
private:
119123
Box<Ui::MainWindow> ui {};
120124

src/gui/windows/editor/srceditor.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,22 @@ void SrcEditor::insertFromMimeData(const QMimeData *source) {
289289
bool SrcEditor::canInsertFromMimeData(const QMimeData *source) const {
290290
return source->hasText();
291291
}
292+
293+
void SrcEditor::highlightBlock(int blockNum) {
294+
QList<QTextEdit::ExtraSelection> extraSelections;
295+
296+
if (!isReadOnly()) {
297+
QTextEdit::ExtraSelection selection;
298+
299+
QColor lineColor = QColor(Qt::yellow).lighter(160);
300+
selection.format.setBackground(lineColor);
301+
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
302+
QTextBlock block = document()->findBlockByLineNumber(blockNum - 1);
303+
selection.cursor = QTextCursor(block);
304+
selection.cursor.movePosition(
305+
QTextCursor::EndOfBlock, QTextCursor::KeepAnchor, block.length());
306+
extraSelections.append(selection);
307+
}
308+
309+
setExtraSelections(extraSelections);
310+
}

src/gui/windows/editor/srceditor.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class SrcEditor : public QPlainTextEdit {
4242

4343
public slots:
4444
void setShowLineNumbers(bool visible);
45+
void highlightBlock(int line_num);
4546

4647
private slots:
4748
void updateMargins(int newBlockCount);

src/machine/core.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Core::Core(Registers *regs,
4949
}
5050

5151
void Core::step(bool skip_break) {
52+
emit highlight_editor(regs->read_pc());
53+
5254
state.cycle_count++;
5355
do_step(skip_break);
5456
emit step_done(state);

src/machine/core.h

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class Core : public QObject {
9393
signals:
9494
void stop_on_exception_reached();
9595
void step_done(const CoreState &);
96+
void highlight_editor(Address addr);
9697

9798
protected:
9899
virtual void do_step(bool skip_break) = 0;

0 commit comments

Comments
 (0)