39 lines
1.4 KiB
C++
39 lines
1.4 KiB
C++
/**
|
||
* @file Codegen.h
|
||
* @brief 寄存器码生成(12.8,切片 1:MOVE / LOADK / RET)
|
||
* @author
|
||
* @date 2026-08-21
|
||
*
|
||
* @details 代码生成:输入 Project + Unit(AST)+ LinkResult,输出 .stb 映像字节。
|
||
* 寄存器分配:r0 结果、r1..r7 参数、r8+ 变量/临时;跳转偏移相对下一条。
|
||
*/
|
||
|
||
#pragma once
|
||
|
||
#include <cstdint>
|
||
#include <string>
|
||
#include <vector>
|
||
|
||
#include "compiler/Linker.h"
|
||
#include "compiler/MachineConfig.h"
|
||
#include "compiler/Parser.h"
|
||
#include "compiler/Project.h"
|
||
|
||
namespace compiler {
|
||
|
||
/**
|
||
* @brief 编译工程为 .stb 映像字节(在链接 + 类型检查成功后调用)。
|
||
* @param proj 工程定义(cycle_limit / dt_ms / 哈希)
|
||
* @param units 全部源文件的 AST
|
||
* @param link 链接结果(POU 顺序 / 全局符号 / FB 布局)
|
||
* @param cfg 机器定义(machine.toml;指令 opcode / 类型 tag / FB 布局)
|
||
* @param image 输出映像字节
|
||
* @param err 错误输出;可为 nullptr(静默)
|
||
* @return true 成功;false 失败(err 前缀 "codegen error")
|
||
* @details 指令 opcode / 类型 tag / FB 布局全部来自 machine.toml(cfg)。
|
||
*/
|
||
bool codegen_project(const Project& proj, const std::vector<SourceUnit>& units,
|
||
const LinkResult& link, const MachineConfig& cfg,
|
||
std::vector<uint8_t>* image, std::string* err);
|
||
}
|