|
|
@ -1,3 +1,4 @@
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include "IRBuilder.h"
|
|
|
|
#include "IRBuilder.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace SysYF
|
|
|
|
namespace SysYF
|
|
|
@ -81,17 +82,17 @@ void IRBuilder::visit(SyntaxTree::FuncParam &node) {
|
|
|
|
if (!node.array_index.empty()) {
|
|
|
|
if (!node.array_index.empty()) {
|
|
|
|
// TODO: high dim array
|
|
|
|
// TODO: high dim array
|
|
|
|
funcFParam.push_back(INT32PTR_T);
|
|
|
|
funcFParam.push_back(INT32PTR_T);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else
|
|
|
|
|
|
|
|
funcFParam.push_back(INT32_T);
|
|
|
|
funcFParam.push_back(INT32_T);
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case SyntaxTree::Type::FLOAT:
|
|
|
|
case SyntaxTree::Type::FLOAT:
|
|
|
|
if (!node.array_index.empty()) {
|
|
|
|
if (!node.array_index.empty()) {
|
|
|
|
// TODO: high dim array (not now)
|
|
|
|
// TODO: high dim array (not now)
|
|
|
|
funcFParam.push_back(FLOATPTR_T);
|
|
|
|
funcFParam.push_back(FLOATPTR_T);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else
|
|
|
|
|
|
|
|
funcFParam.push_back(FLOAT_T);
|
|
|
|
funcFParam.push_back(FLOAT_T);
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
funcFParam.push_back(INT32_T);
|
|
|
|
funcFParam.push_back(INT32_T);
|
|
|
@ -100,7 +101,66 @@ void IRBuilder::visit(SyntaxTree::FuncParam &node) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IRBuilder::visit(SyntaxTree::VarDef &node) {
|
|
|
|
void IRBuilder::visit(SyntaxTree::VarDef &node) {
|
|
|
|
;
|
|
|
|
// TODO: high dim array (not now)
|
|
|
|
|
|
|
|
Ptr<Value> arrayLength;
|
|
|
|
|
|
|
|
Ptr<Value> 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) {
|
|
|
|
void IRBuilder::visit(SyntaxTree::LVal &node) {
|
|
|
|