assembling first version
This commit is contained in:
parent
9e9039af05
commit
d3e08abd30
7 changed files with 896 additions and 1 deletions
|
|
@ -6,6 +6,8 @@
|
|||
#include "../../include/opcode.h"
|
||||
#include "../../include/constants.h"
|
||||
#include "../../include/loader.h"
|
||||
#include "../../include/parser.h"
|
||||
#include "../../include/code.h"
|
||||
|
||||
#include <QIntValidator>
|
||||
#include <QLineEdit>
|
||||
|
|
@ -20,6 +22,9 @@
|
|||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QScrollBar>
|
||||
#include <QDir>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
class Loader;
|
||||
|
||||
|
|
@ -102,6 +107,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
|
||||
// Connect menu actions
|
||||
connect(ui->actionLoad_Object_File, &QAction::triggered, this, &MainWindow::loadObjectFile);
|
||||
connect(ui->actionLoad_Asm_file, &QAction::triggered, this, &MainWindow::loadAsmFile);
|
||||
connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::showAboutDialog);
|
||||
connect(ui->actionFrequency, &QAction::triggered, this, &MainWindow::showFrequencyDialog);
|
||||
|
||||
|
|
@ -981,6 +987,100 @@ void MainWindow::loadObjectFile()
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadAsmFile()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this,
|
||||
tr("Load Assembly File"),
|
||||
QString(),
|
||||
tr("Assembly Files (*.asm);;All Files (*)"));
|
||||
|
||||
if (fileName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Stop execution if running
|
||||
m_controller->stop();
|
||||
|
||||
// Reset machine state
|
||||
m_machine->reset();
|
||||
|
||||
// Read assembly file
|
||||
std::ifstream file(fileName.toStdString());
|
||||
if (!file.is_open()) {
|
||||
throw std::runtime_error("Could not open file: " + fileName.toStdString());
|
||||
}
|
||||
|
||||
std::string source((std::istreambuf_iterator<char>(file)),
|
||||
std::istreambuf_iterator<char>());
|
||||
file.close();
|
||||
|
||||
// Parse and assemble
|
||||
Parser parser;
|
||||
Code code = parser.parse(source);
|
||||
code.assemble();
|
||||
|
||||
// Generate object code
|
||||
std::string objCode = code.emitText();
|
||||
|
||||
// Create resources directory if it doesn't exist
|
||||
QDir dir;
|
||||
if (!dir.exists("resources")) {
|
||||
dir.mkpath("resources");
|
||||
}
|
||||
|
||||
// Save object file to resources directory
|
||||
QFileInfo fileInfo(fileName);
|
||||
QString objFileName = "resources/" + fileInfo.completeBaseName() + ".obj";
|
||||
|
||||
std::ofstream objFile(objFileName.toStdString());
|
||||
if (!objFile.is_open()) {
|
||||
throw std::runtime_error("Could not create object file: " + objFileName.toStdString());
|
||||
}
|
||||
objFile << objCode;
|
||||
objFile.close();
|
||||
|
||||
// Generate and save log file
|
||||
QString logFileName = "resources/" + fileInfo.completeBaseName() + ".log";
|
||||
std::ofstream logFile(logFileName.toStdString());
|
||||
if (!logFile.is_open()) {
|
||||
throw std::runtime_error("Could not create log file: " + logFileName.toStdString());
|
||||
}
|
||||
|
||||
logFile << "=== SIC/XE Assembler Log ===\n\n";
|
||||
logFile << "Source file: " << fileName.toStdString() << "\n";
|
||||
logFile << "Object file: " << objFileName.toStdString() << "\n\n";
|
||||
|
||||
logFile << "=== Symbols ===\n";
|
||||
logFile << code.dumpSymbols() << "\n\n";
|
||||
|
||||
logFile << "=== Code ===\n";
|
||||
logFile << code.dumpCode() << "\n\n";
|
||||
|
||||
logFile << "=== Object Code ===\n";
|
||||
logFile << objCode << "\n";
|
||||
|
||||
logFile.close();
|
||||
|
||||
// Load the generated object file
|
||||
Loader loader(m_machine, objFileName.toStdString());
|
||||
loader.load();
|
||||
|
||||
// Update displays
|
||||
updateRegisterDisplays();
|
||||
updateMemoryDisplay();
|
||||
updateDisassemblyDisplay();
|
||||
|
||||
QMessageBox::information(this, tr("Success"),
|
||||
tr("Assembly successful!\nObject file: %1\nLog file: %2")
|
||||
.arg(objFileName).arg(logFileName));
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("Failed to assemble file: %1").arg(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::showAboutDialog()
|
||||
{
|
||||
QMessageBox::about(this, tr("About SIC/XE Simulator"),
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ private slots:
|
|||
void onDisassemblyGoToStart();
|
||||
void onDisassemblyGoToEnd();
|
||||
void loadObjectFile();
|
||||
void loadAsmFile();
|
||||
void showAboutDialog();
|
||||
void showFrequencyDialog();
|
||||
|
||||
|
|
|
|||
|
|
@ -892,6 +892,7 @@
|
|||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="actionLoad_Object_File"/>
|
||||
<addaction name="actionLoad_Asm_file"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuMachine">
|
||||
<property name="title">
|
||||
|
|
@ -924,6 +925,11 @@
|
|||
<string>About</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLoad_Asm_file">
|
||||
<property name="text">
|
||||
<string>Load Asm file</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue