2025-11-27 21:03:34 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
2025-12-12 18:54:13 +08:00
|
|
|
|
#include <QProcess>
|
|
|
|
|
|
#include <QString>
|
2025-11-27 21:03:34 +08:00
|
|
|
|
|
|
|
|
|
|
class CompileProcessManager : public QObject
|
|
|
|
|
|
{
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
public:
|
|
|
|
|
|
explicit CompileProcessManager(QObject *parent = nullptr);
|
|
|
|
|
|
|
2025-12-12 18:54:13 +08:00
|
|
|
|
// 设置 mini_c 可执行文件路径,如:"/Users/xxx/mini_c_build/mini_c"
|
|
|
|
|
|
void setBackendProgram(const QString &programPath);
|
2025-11-27 21:03:34 +08:00
|
|
|
|
|
2025-12-12 18:54:13 +08:00
|
|
|
|
// 设置项目根目录,用来拼接 "test.c"、"test.s" 这样的相对路径
|
|
|
|
|
|
// 比如:"/Users/haolixin/Desktop/Compiler_Project"
|
|
|
|
|
|
void setProjectRoot(const QString &rootPath);
|
|
|
|
|
|
|
|
|
|
|
|
// 异步生成汇编:
|
|
|
|
|
|
// inputFileName 比如 "test.c"(在项目根目录下)
|
|
|
|
|
|
// outputFileName 比如 "test.s"(希望输出的文件名,同样在项目根目录下)
|
|
|
|
|
|
//
|
|
|
|
|
|
// 调用后立刻返回,编译结束后,通过 asmGenerated 信号把结果发给前端。
|
|
|
|
|
|
void generateAsm(const QString &inputFileName,
|
|
|
|
|
|
const QString &outputFileName);
|
|
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
// asmText: 读出来的汇编文本(通常就是 outputFileName 的内容)
|
|
|
|
|
|
// outputFilePath: 实际写出的汇编文件完整路径(项目根目录下)
|
|
|
|
|
|
// stdoutText / stderrText: mini_c 的标准输出 / 错误输出(原样传递,不做处理)
|
|
|
|
|
|
// exitCode: mini_c 的返回码(0 正常,非 0 表示错误)
|
|
|
|
|
|
void asmGenerated(const QString &asmText,
|
|
|
|
|
|
const QString &outputFilePath,
|
|
|
|
|
|
const QString &stdoutText,
|
|
|
|
|
|
const QString &stderrText,
|
|
|
|
|
|
int exitCode);
|
|
|
|
|
|
|
|
|
|
|
|
// 出现明显错误(比如 mini_c 路径没设、源文件不存在等)
|
|
|
|
|
|
void processError(const QString &message);
|
2025-11-27 21:03:34 +08:00
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
|
void onProcessFinished(int exitCode, QProcess::ExitStatus status);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
QProcess *m_process = nullptr;
|
|
|
|
|
|
|
2025-12-12 18:54:13 +08:00
|
|
|
|
QString m_backendProgram; // mini_c 路径
|
|
|
|
|
|
QString m_projectRoot; // 项目根目录
|
|
|
|
|
|
|
|
|
|
|
|
// 当前这次 generateAsm 的输入/输出信息,用来在 finished 时读文件
|
|
|
|
|
|
QString m_pendingInputFile; // 完整路径:root + inputFileName
|
|
|
|
|
|
QString m_pendingOutputFile; // 仅文件名,如 "test.s"
|
|
|
|
|
|
bool m_isAsmOperation = false;
|
2025-11-27 21:03:34 +08:00
|
|
|
|
};
|