修复bug

This commit is contained in:
rain2133
2025-06-21 14:33:22 +08:00
parent c1583e447d
commit 2b038e671b
2 changed files with 7 additions and 22 deletions

View File

@ -188,24 +188,6 @@ class Use {
void setValue(Value *newValue) { value = newValue; } ///< 将被使用的值设置为newValue void setValue(Value *newValue) { value = newValue; } ///< 将被使用的值设置为newValue
}; };
template <typename T>
inline std::enable_if_t<std::is_base_of_v<Value, T>, bool>
isa(const Value *value) {
return T::classof(value);
}
template <typename T>
inline std::enable_if_t<std::is_base_of_v<Value, T>, T *>
dyncast(Value *value) {
return isa<T>(value) ? static_cast<T *>(value) : nullptr;
}
template <typename T>
inline std::enable_if_t<std::is_base_of_v<Value, T>, const T *>
dyncast(const Value *value) {
return isa<T>(value) ? static_cast<const T *>(value) : nullptr;
}
//! The base class of all value types //! The base class of all value types
class Value { class Value {
@ -1001,7 +983,7 @@ protected:
} }
public: public:
BasicBlock *getBlock() const { return dyncast<BasicBlock>(getOperand(0)); } BasicBlock *getBlock() const { return dynamic_cast<BasicBlock *>(getOperand(0)); }
auto getArguments() const { auto getArguments() const {
return make_range(std::next(operand_begin()), operand_end()); return make_range(std::next(operand_begin()), operand_end());
} }
@ -1029,10 +1011,10 @@ protected:
public: public:
Value *getCondition() const { return getOperand(0); } Value *getCondition() const { return getOperand(0); }
BasicBlock *getThenBlock() const { BasicBlock *getThenBlock() const {
return dyncast<BasicBlock>(getOperand(1)); return dynamic_cast<BasicBlock *>(getOperand(1));
} }
BasicBlock *getElseBlock() const { BasicBlock *getElseBlock() const {
return dyncast<BasicBlock>(getOperand(2)); return dynamic_cast<BasicBlock *>(getOperand(2));
} }
auto getThenArguments() const { auto getThenArguments() const {
auto begin = std::next(operand_begin(), 3); auto begin = std::next(operand_begin(), 3);
@ -1213,6 +1195,8 @@ public:
}; };
class GlobalValue;
// 循环类 // 循环类
class Loop { class Loop {
public: public:
@ -1658,6 +1642,7 @@ class Module {
} }
return result.first->second.get(); return result.first->second.get();
} ///< 创建外部函数 } ///< 创建外部函数
///< 变量创建伴随着符号表的更新
auto createGlobalValue(const std::string &name, Type *type, const std::vector<Value *> &dims = {}, auto createGlobalValue(const std::string &name, Type *type, const std::vector<Value *> &dims = {},
const ValueCounter &init = {}) -> GlobalValue * { const ValueCounter &init = {}) -> GlobalValue * {
bool isFinished = variableTable.isCurNodeNull(); bool isFinished = variableTable.isCurNodeNull();

View File

@ -71,7 +71,7 @@ public:
std::any visitGlobalConstDecl(SysYParser::GlobalConstDeclContext *ctx) override; std::any visitGlobalConstDecl(SysYParser::GlobalConstDeclContext *ctx) override;
std::any visitGlobalVarDecl(SysYParser::GlobalVarDeclContext *ctx) override; std::any visitGlobalVarDecl(SysYParser::GlobalVarDeclContext *ctx) override;
std::any visitDecl(SysYParser::DeclContext *ctx) override ; // std::any visitDecl(SysYParser::DeclContext *ctx) override;
std::any visitConstDecl(SysYParser::ConstDeclContext *ctx) override; std::any visitConstDecl(SysYParser::ConstDeclContext *ctx) override;
std::any visitVarDecl(SysYParser::VarDeclContext *ctx) override; std::any visitVarDecl(SysYParser::VarDeclContext *ctx) override;