From 0e256196e605abe216d05ca4e269356a04472b2b Mon Sep 17 00:00:00 2001 From: Odeinjul Date: Wed, 13 Dec 2023 14:58:19 +0800 Subject: [PATCH] Modify VarDef --- src/SysYFIRBuilder/IRBuilder.cpp | 70 +++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 5 deletions(-) diff --git a/src/SysYFIRBuilder/IRBuilder.cpp b/src/SysYFIRBuilder/IRBuilder.cpp index 219b882..8237206 100644 --- a/src/SysYFIRBuilder/IRBuilder.cpp +++ b/src/SysYFIRBuilder/IRBuilder.cpp @@ -1,3 +1,4 @@ +#include #include "IRBuilder.h" namespace SysYF @@ -81,17 +82,17 @@ void IRBuilder::visit(SyntaxTree::FuncParam &node) { if (!node.array_index.empty()) { // TODO: high dim array funcFParam.push_back(INT32PTR_T); - } - else + } else { funcFParam.push_back(INT32_T); + } break; case SyntaxTree::Type::FLOAT: if (!node.array_index.empty()) { // TODO: high dim array (not now) funcFParam.push_back(FLOATPTR_T); - } - else + } else { funcFParam.push_back(FLOAT_T); + } break; default: funcFParam.push_back(INT32_T); @@ -100,7 +101,66 @@ void IRBuilder::visit(SyntaxTree::FuncParam &node) { } void IRBuilder::visit(SyntaxTree::VarDef &node) { - ; + // TODO: high dim array (not now) + Ptr arrayLength; + Ptr initVal; + if (node.is_constant) { + assert(node.is_inited); + switch (node.btype) { + case (SyntaxTree::Type::INT): + if (!node.array_length.empty()) { + + } else { + + } + break; + case (SyntaxTree::Type::FLOAT): + if (!node.array_length.empty()) { + + } else { + + } + break; + default: + break; + } + } else { + switch (node.btype) { + case (SyntaxTree::Type::INT): + if (!node.array_length.empty()) { + + } else { + auto alloca = builder->create_alloca(INT32_T); + if (node.is_inited) { + + + builder->create_store(initVal, alloca); + } else { + builder->create_store(CONST_INT(0), alloca); + scope.push(node.name, alloca); + } + } + break; + case (SyntaxTree::Type::FLOAT): + if (!node.array_length.empty()) { + + } else { + auto alloca = builder->create_alloca(FLOAT_T); + if (node.is_inited) { + + + builder->create_store(initVal, alloca); + } else { + builder->create_store(CONST_FLOAT(0), alloca); + scope.push(node.name, alloca); + } + } + break; + default: + break; + } + } + } void IRBuilder::visit(SyntaxTree::LVal &node) {