parent
77bee889d7
commit
e941cced9b
@ -1,4 +1,3 @@
|
||||
// AST 节点定义与实现:
|
||||
// - 表达式、语句、声明、函数、类型等节点
|
||||
// - 支持后续阶段在节点上附加信息(类型、符号绑定、常量值等)
|
||||
// AST 节点简单实现:仅需包含头文件即可,析构函数默认生成。
|
||||
|
||||
#include "ast/AstNodes.h"
|
||||
|
||||
@ -0,0 +1,70 @@
|
||||
// Minimal AST definitions for the SysY subset used in this toy compiler.
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ast {
|
||||
|
||||
enum class BinaryOp { Add, Sub, Mul, Div };
|
||||
|
||||
struct Expr {
|
||||
virtual ~Expr() = default;
|
||||
};
|
||||
|
||||
struct NumberExpr : Expr {
|
||||
int value{};
|
||||
explicit NumberExpr(int v) : value(v) {}
|
||||
};
|
||||
|
||||
struct VarExpr : Expr {
|
||||
std::string name;
|
||||
explicit VarExpr(std::string n) : name(std::move(n)) {}
|
||||
};
|
||||
|
||||
struct BinaryExpr : Expr {
|
||||
BinaryOp op;
|
||||
std::shared_ptr<Expr> lhs;
|
||||
std::shared_ptr<Expr> rhs;
|
||||
BinaryExpr(BinaryOp op, std::shared_ptr<Expr> lhs, std::shared_ptr<Expr> rhs)
|
||||
: op(op), lhs(std::move(lhs)), rhs(std::move(rhs)) {}
|
||||
};
|
||||
|
||||
struct Stmt {
|
||||
virtual ~Stmt() = default;
|
||||
};
|
||||
|
||||
struct ReturnStmt : Stmt {
|
||||
std::shared_ptr<Expr> value;
|
||||
explicit ReturnStmt(std::shared_ptr<Expr> v) : value(std::move(v)) {}
|
||||
};
|
||||
|
||||
struct VarDecl {
|
||||
std::string name;
|
||||
std::shared_ptr<Expr> init; // nullptr if no initializer
|
||||
VarDecl(std::string n, std::shared_ptr<Expr> i)
|
||||
: name(std::move(n)), init(std::move(i)) {}
|
||||
};
|
||||
|
||||
struct Block {
|
||||
std::vector<std::shared_ptr<VarDecl>> varDecls;
|
||||
std::vector<std::shared_ptr<Stmt>> stmts;
|
||||
};
|
||||
|
||||
struct FuncDef {
|
||||
std::string name;
|
||||
std::shared_ptr<Block> body;
|
||||
FuncDef(std::string n, std::shared_ptr<Block> b)
|
||||
: name(std::move(n)), body(std::move(b)) {}
|
||||
};
|
||||
|
||||
struct CompUnit {
|
||||
std::shared_ptr<FuncDef> func;
|
||||
explicit CompUnit(std::shared_ptr<FuncDef> f) : func(std::move(f)) {}
|
||||
};
|
||||
|
||||
// 调试打印
|
||||
void PrintAST(const CompUnit& cu);
|
||||
|
||||
} // namespace ast
|
||||
@ -1,4 +1,72 @@
|
||||
// AST 调试打印:
|
||||
// - 以可读形式打印 AST 结构
|
||||
// - 用于验证 AST 构建与语义分析结果,便于定位问题
|
||||
// 简单 AST 调试打印,便于前端验证。
|
||||
|
||||
#include "ast/AstNodes.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace ast {
|
||||
|
||||
static void PrintExpr(const Expr* expr);
|
||||
|
||||
static void PrintIndent(int depth) {
|
||||
for (int i = 0; i < depth; ++i) std::cout << " ";
|
||||
}
|
||||
|
||||
static void PrintExpr(const Expr* expr) {
|
||||
if (auto num = dynamic_cast<const NumberExpr*>(expr)) {
|
||||
std::cout << num->value;
|
||||
} else if (auto var = dynamic_cast<const VarExpr*>(expr)) {
|
||||
std::cout << var->name;
|
||||
} else if (auto bin = dynamic_cast<const BinaryExpr*>(expr)) {
|
||||
std::cout << "(";
|
||||
PrintExpr(bin->lhs.get());
|
||||
const char* op = "?";
|
||||
switch (bin->op) {
|
||||
case BinaryOp::Add:
|
||||
op = "+";
|
||||
break;
|
||||
case BinaryOp::Sub:
|
||||
op = "-";
|
||||
break;
|
||||
case BinaryOp::Mul:
|
||||
op = "*";
|
||||
break;
|
||||
case BinaryOp::Div:
|
||||
op = "/";
|
||||
break;
|
||||
}
|
||||
std::cout << " " << op << " ";
|
||||
PrintExpr(bin->rhs.get());
|
||||
std::cout << ")";
|
||||
}
|
||||
}
|
||||
|
||||
void PrintAST(const CompUnit& cu) {
|
||||
if (!cu.func) return;
|
||||
std::cout << "func " << cu.func->name << " () {\n";
|
||||
const auto& body = cu.func->body;
|
||||
if (!body) {
|
||||
std::cout << "}\n";
|
||||
return;
|
||||
}
|
||||
for (const auto& decl : body->varDecls) {
|
||||
PrintIndent(1);
|
||||
std::cout << "var " << decl->name;
|
||||
if (decl->init) {
|
||||
std::cout << " = ";
|
||||
PrintExpr(decl->init.get());
|
||||
}
|
||||
std::cout << ";\n";
|
||||
}
|
||||
for (const auto& stmt : body->stmts) {
|
||||
if (auto ret = dynamic_cast<ReturnStmt*>(stmt.get())) {
|
||||
PrintIndent(1);
|
||||
std::cout << "return ";
|
||||
PrintExpr(ret->value.get());
|
||||
std::cout << ";\n";
|
||||
}
|
||||
}
|
||||
std::cout << "}\n";
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
// 将 ANTLR parse tree 转换为内部 AST。
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace antlr4 {
|
||||
namespace tree {
|
||||
class ParseTree;
|
||||
}
|
||||
} // namespace antlr4
|
||||
|
||||
namespace ast {
|
||||
struct CompUnit;
|
||||
}
|
||||
|
||||
std::shared_ptr<ast::CompUnit> BuildAst(antlr4::tree::ParseTree* tree);
|
||||
@ -1,4 +1 @@
|
||||
// IR 基本块:
|
||||
// - 保存指令序列
|
||||
// - 维护或可计算前驱/后继关系,用于 CFG 分析与优化
|
||||
|
||||
#include "ir/IR.h"
|
||||
|
||||
@ -1,4 +1 @@
|
||||
// IR 上下文:
|
||||
// - 管理类型与常量的创建/复用
|
||||
// - 保存字符串常量、符号等公共资源(按需要扩展)
|
||||
|
||||
#include "ir/IR.h"
|
||||
|
||||
@ -0,0 +1,144 @@
|
||||
// 极简 IR 定义:足以表示 int 返回 a+b。
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace ir {
|
||||
|
||||
class Type {
|
||||
public:
|
||||
enum class Kind { Void, Int32 };
|
||||
explicit Type(Kind k) : kind_(k) {}
|
||||
Kind kind() const { return kind_; }
|
||||
static std::shared_ptr<Type> Void();
|
||||
static std::shared_ptr<Type> Int32();
|
||||
|
||||
private:
|
||||
Kind kind_;
|
||||
};
|
||||
|
||||
class Value {
|
||||
public:
|
||||
Value(std::shared_ptr<Type> ty, std::string name)
|
||||
: type_(std::move(ty)), name_(std::move(name)) {}
|
||||
virtual ~Value() = default;
|
||||
const std::shared_ptr<Type>& type() const { return type_; }
|
||||
const std::string& name() const { return name_; }
|
||||
void set_name(std::string n) { name_ = std::move(n); }
|
||||
|
||||
protected:
|
||||
std::shared_ptr<Type> type_;
|
||||
std::string name_;
|
||||
};
|
||||
|
||||
class ConstantInt : public Value {
|
||||
public:
|
||||
explicit ConstantInt(int v);
|
||||
int value() const { return value_; }
|
||||
|
||||
private:
|
||||
int value_{};
|
||||
};
|
||||
|
||||
enum class Opcode { Add, Sub, Mul, Div, Ret };
|
||||
|
||||
class Instruction : public Value {
|
||||
public:
|
||||
Instruction(Opcode op, std::shared_ptr<Type> ty, std::string name = "")
|
||||
: Value(std::move(ty), std::move(name)), opcode_(op) {}
|
||||
Opcode opcode() const { return opcode_; }
|
||||
|
||||
private:
|
||||
Opcode opcode_;
|
||||
};
|
||||
|
||||
class BinaryInst : public Instruction {
|
||||
public:
|
||||
BinaryInst(Opcode op, std::shared_ptr<Type> ty, Value* lhs, Value* rhs,
|
||||
std::string name);
|
||||
Value* lhs() const { return lhs_; }
|
||||
Value* rhs() const { return rhs_; }
|
||||
|
||||
private:
|
||||
Value* lhs_;
|
||||
Value* rhs_;
|
||||
};
|
||||
|
||||
class ReturnInst : public Instruction {
|
||||
public:
|
||||
explicit ReturnInst(Value* val);
|
||||
Value* value() const { return value_; }
|
||||
|
||||
private:
|
||||
Value* value_;
|
||||
};
|
||||
|
||||
class BasicBlock {
|
||||
public:
|
||||
explicit BasicBlock(std::string name) : name_(std::move(name)) {}
|
||||
const std::string& name() const { return name_; }
|
||||
const std::vector<std::unique_ptr<Instruction>>& instructions() const {
|
||||
return instructions_;
|
||||
}
|
||||
template <typename T, typename... Args>
|
||||
T* Append(Args&&... args) {
|
||||
auto inst = std::make_unique<T>(std::forward<Args>(args)...);
|
||||
auto* ptr = inst.get();
|
||||
instructions_.push_back(std::move(inst));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
std::vector<std::unique_ptr<Instruction>> instructions_;
|
||||
};
|
||||
|
||||
class Function : public Value {
|
||||
public:
|
||||
explicit Function(std::string name);
|
||||
BasicBlock* entry() { return entry_.get(); }
|
||||
const BasicBlock* entry() const { return entry_.get(); }
|
||||
void EnsureEntry();
|
||||
|
||||
private:
|
||||
std::unique_ptr<BasicBlock> entry_;
|
||||
};
|
||||
|
||||
class Module {
|
||||
public:
|
||||
Function* CreateFunction(const std::string& name);
|
||||
const std::vector<std::unique_ptr<Function>>& functions() const {
|
||||
return functions_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<Function>> functions_;
|
||||
};
|
||||
|
||||
class IRBuilder {
|
||||
public:
|
||||
explicit IRBuilder(BasicBlock* bb) : insertBlock_(bb) {}
|
||||
void SetInsertPoint(BasicBlock* bb) { insertBlock_ = bb; }
|
||||
BasicBlock* GetInsertBlock() const { return insertBlock_; }
|
||||
|
||||
ConstantInt* CreateConstInt(int v);
|
||||
BinaryInst* CreateBinary(Opcode op, Value* lhs, Value* rhs,
|
||||
const std::string& name);
|
||||
BinaryInst* CreateAdd(Value* lhs, Value* rhs, const std::string& name) {
|
||||
return CreateBinary(Opcode::Add, lhs, rhs, name);
|
||||
}
|
||||
ReturnInst* CreateRet(Value* v);
|
||||
|
||||
private:
|
||||
BasicBlock* insertBlock_;
|
||||
};
|
||||
|
||||
class IRPrinter {
|
||||
public:
|
||||
void Print(const Module& module);
|
||||
};
|
||||
|
||||
} // namespace ir
|
||||
@ -1,4 +1,19 @@
|
||||
// IR 构建工具:
|
||||
// - 管理插入点(当前基本块/位置)
|
||||
// - 提供创建各类指令的便捷接口,降低 IRGen 复杂度
|
||||
#include "ir/IR.h"
|
||||
|
||||
namespace ir {
|
||||
|
||||
ConstantInt* IRBuilder::CreateConstInt(int v) {
|
||||
// 常量不需要挂在基本块里,直接返回局部对象指针。
|
||||
return new ConstantInt(v);
|
||||
}
|
||||
|
||||
BinaryInst* IRBuilder::CreateBinary(Opcode op, Value* lhs, Value* rhs,
|
||||
const std::string& name) {
|
||||
return insertBlock_->Append<BinaryInst>(op, Type::Int32(), lhs, rhs, name);
|
||||
}
|
||||
|
||||
ReturnInst* IRBuilder::CreateRet(Value* v) {
|
||||
return insertBlock_->Append<ReturnInst>(v);
|
||||
}
|
||||
|
||||
} // namespace ir
|
||||
|
||||
@ -1,4 +1,12 @@
|
||||
// IR 指令体系:
|
||||
// - 二元运算/比较、load/store、call、br/condbr、ret、phi、alloca 等
|
||||
// - 指令操作数与结果类型管理,支持打印与优化
|
||||
#include "ir/IR.h"
|
||||
|
||||
namespace ir {
|
||||
|
||||
BinaryInst::BinaryInst(Opcode op, std::shared_ptr<Type> ty, Value* lhs,
|
||||
Value* rhs, std::string name)
|
||||
: Instruction(op, std::move(ty), std::move(name)), lhs_(lhs), rhs_(rhs) {}
|
||||
|
||||
ReturnInst::ReturnInst(Value* val)
|
||||
: Instruction(Opcode::Ret, Type::Void(), ""), value_(val) {}
|
||||
|
||||
} // namespace ir
|
||||
|
||||
@ -1,4 +1,16 @@
|
||||
// IR 类型系统:
|
||||
// - i32/f32/void、指针、数组、函数类型等
|
||||
// - 按 SysY 支持范围裁剪并逐步补齐
|
||||
// 极简类型系统:仅支持 void 与 i32。
|
||||
#include "ir/IR.h"
|
||||
|
||||
namespace ir {
|
||||
|
||||
std::shared_ptr<Type> Type::Void() {
|
||||
static auto ty = std::make_shared<Type>(Kind::Void);
|
||||
return ty;
|
||||
}
|
||||
|
||||
std::shared_ptr<Type> Type::Int32() {
|
||||
static auto ty = std::make_shared<Type>(Kind::Int32);
|
||||
return ty;
|
||||
}
|
||||
|
||||
} // namespace ir
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
// SSA 值体系抽象:
|
||||
// - 常量、参数、指令结果等统一为 Value
|
||||
// - 提供类型信息与使用/被使用关系(按需要实现)
|
||||
#include "ir/IR.h"
|
||||
|
||||
namespace ir {
|
||||
|
||||
ConstantInt::ConstantInt(int v) : Value(Type::Int32(), ""), value_(v) {
|
||||
set_name(std::to_string(v));
|
||||
}
|
||||
|
||||
} // namespace ir
|
||||
|
||||
@ -1,4 +1 @@
|
||||
// 支配树分析:
|
||||
// - 构建/查询 Dominator Tree 及相关关系
|
||||
// - 为 mem2reg、CFG 优化与循环分析提供基础能力
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -1,4 +1 @@
|
||||
// 循环分析:
|
||||
// - 识别循环结构与层级关系
|
||||
// - 为后续优化(可选)提供循环信息
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -1,4 +1 @@
|
||||
// CFG 简化:
|
||||
// - 删除不可达块、合并空块、简化分支等
|
||||
// - 改善 IR 结构,便于后续优化与后端生成
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -1,4 +1 @@
|
||||
// IR 常量折叠:
|
||||
// - 折叠可判定的常量表达式
|
||||
// - 简化常量控制流分支(按实现范围裁剪)
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
// 将 AST 翻译为极简 IR。
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace ast {
|
||||
struct CompUnit;
|
||||
}
|
||||
|
||||
namespace ir {
|
||||
class Module;
|
||||
}
|
||||
|
||||
std::unique_ptr<ir::Module> GenerateIR(const ast::CompUnit& ast);
|
||||
@ -1,4 +1 @@
|
||||
// 声明翻译模块:
|
||||
// - 处理全局变量与局部变量声明
|
||||
// - 处理数组初始化、空间分配与初值生成等
|
||||
|
||||
#include "irgen/IRGen.h"
|
||||
|
||||
@ -1,4 +1 @@
|
||||
// 表达式翻译模块:
|
||||
// - 处理算术运算、比较、逻辑运算、函数调用等表达式
|
||||
// - 生成对应的 IR 指令并返回 SSA 值
|
||||
|
||||
#include "irgen/IRGen.h"
|
||||
|
||||
@ -1,4 +1 @@
|
||||
// 函数翻译模块:
|
||||
// - 处理函数定义、参数列表与返回值翻译
|
||||
// - 创建并填充对应的 IR Function 对象
|
||||
|
||||
#include "irgen/IRGen.h"
|
||||
|
||||
@ -1,4 +1 @@
|
||||
// 语句翻译模块:
|
||||
// - 处理 if/while/return 等控制流构造
|
||||
// - 负责基本块创建、分支跳转与控制流收束
|
||||
|
||||
#include "irgen/IRGen.h"
|
||||
|
||||
@ -1,30 +1,29 @@
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
static void PrintUsage(const char* argv0) {
|
||||
std::cerr << "用法: " << (argv0 ? argv0 : "compiler") << " <input.sy> [options]\n";
|
||||
std::cerr << "说明: 当前为工程骨架阶段,暂不执行完整编译流程,仅用于验证可编译/可链接。\n";
|
||||
}
|
||||
#include "frontend/AntlrDriver.h"
|
||||
#include "frontend/AstBuilder.h"
|
||||
#include "ir/IR.h"
|
||||
#include "irgen/IRGen.h"
|
||||
#include "sem/Sema.h"
|
||||
#include "utils/CLI.h"
|
||||
#include "utils/Log.h"
|
||||
#include "ast/AstNodes.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc <= 1) {
|
||||
PrintUsage(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
auto opts = ParseCLI(argc, argv);
|
||||
auto antlr = ParseFileWithAntlr(opts.input);
|
||||
auto ast = BuildAst(antlr.tree);
|
||||
ast::PrintAST(*ast); // 调试 AST
|
||||
ast = RunSema(std::move(ast));
|
||||
auto module = GenerateIR(*ast);
|
||||
|
||||
std::string input_path = argv[1];
|
||||
if (input_path == "-h" || input_path == "--help") {
|
||||
PrintUsage(argv[0]);
|
||||
return 0;
|
||||
ir::IRPrinter printer;
|
||||
printer.Print(*module);
|
||||
} catch (const std::exception& ex) {
|
||||
LOG_ERROR(ex.what());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// TODO: 后续在此接入完整流水线:
|
||||
// 1) frontend: ANTLR 解析 + AST 构建
|
||||
// 2) sem: 语义分析
|
||||
// 3) irgen: AST -> IR
|
||||
// 4) ir passes: 可选优化
|
||||
// 5) mir/backend: AArch64 指令选择、寄存器分配、栈帧、汇编输出
|
||||
(void)input_path;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1,4 +1 @@
|
||||
// 常量求值:
|
||||
// - 处理数组维度、全局初始化、const 表达式等编译期可计算场景
|
||||
// - 为语义分析与 IR 生成提供常量折叠/常量值信息
|
||||
|
||||
#include <optional>
|
||||
|
||||
@ -1,5 +1,52 @@
|
||||
// 语义分析主流程:
|
||||
// - 符号解析与绑定、类型检查、控制流规则检查
|
||||
// - 记录/插入必要的隐式转换(或在节点上标注)
|
||||
// - 输出为“带类型 / 符号 / 常量信息”的 AST
|
||||
// 极简语义分析:只检查变量是否先声明再使用。
|
||||
#include "sem/Sema.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "ast/AstNodes.h"
|
||||
#include "sem/SymbolTable.h"
|
||||
|
||||
namespace {
|
||||
|
||||
class SemaVisitor {
|
||||
public:
|
||||
explicit SemaVisitor(SymbolTable& table) : table_(table) {}
|
||||
|
||||
void CheckBlock(const ast::Block& block) {
|
||||
for (const auto& decl : block.varDecls) {
|
||||
table_.Add(decl->name);
|
||||
if (decl->init) CheckExpr(*decl->init);
|
||||
}
|
||||
for (const auto& stmt : block.stmts) {
|
||||
if (auto ret = dynamic_cast<ast::ReturnStmt*>(stmt.get())) {
|
||||
CheckExpr(*ret->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckExpr(const ast::Expr& expr) {
|
||||
if (auto var = dynamic_cast<const ast::VarExpr*>(&expr)) {
|
||||
if (!table_.Contains(var->name)) {
|
||||
throw std::runtime_error("使用了未定义的变量: " + var->name);
|
||||
}
|
||||
} else if (auto bin = dynamic_cast<const ast::BinaryExpr*>(&expr)) {
|
||||
CheckExpr(*bin->lhs);
|
||||
CheckExpr(*bin->rhs);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
SymbolTable& table_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::shared_ptr<ast::CompUnit> RunSema(std::shared_ptr<ast::CompUnit> ast) {
|
||||
if (!ast || !ast->func || !ast->func->body) return ast;
|
||||
SymbolTable table;
|
||||
SemaVisitor visitor(table);
|
||||
visitor.CheckBlock(*ast->func->body);
|
||||
return ast;
|
||||
}
|
||||
|
||||
@ -1,4 +1 @@
|
||||
// 符号表与作用域管理:
|
||||
// - 支持嵌套作用域(块/函数/全局)
|
||||
// - 变量/函数/参数/常量的注册、查找与遮蔽规则
|
||||
|
||||
#include "sem/SymbolTable.h"
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
// 极简符号表:记录局部变量是否定义。
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class SymbolTable {
|
||||
public:
|
||||
void Add(const std::string& name) { table_[name] = true; }
|
||||
bool Contains(const std::string& name) const {
|
||||
return table_.find(name) != table_.end();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, bool> table_;
|
||||
};
|
||||
@ -0,0 +1,10 @@
|
||||
// 简易命令行解析:仅支持输入文件路径。
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
struct CLIOptions {
|
||||
std::string input;
|
||||
};
|
||||
|
||||
CLIOptions ParseCLI(int argc, char** argv);
|
||||
@ -1,4 +1 @@
|
||||
// 日志模块:
|
||||
// - 统一输出调试信息、阶段信息与错误信息
|
||||
// - 提供可配置的日志级别与输出位置(按需要实现)
|
||||
|
||||
#include "utils/Log.h"
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
// 轻量日志接口。
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#define LOG_INFO(msg) std::cerr << "[info] " << msg << "\n"
|
||||
#define LOG_ERROR(msg) std::cerr << "[error] " << msg << "\n"
|
||||
@ -0,0 +1,5 @@
|
||||
int main() {
|
||||
int a = 1;
|
||||
int b = 2;
|
||||
return a + b;
|
||||
}
|
||||
Loading…
Reference in new issue