Init and store var
This commit is contained in:
@@ -23,6 +23,9 @@ void ModuleBuilder::buildStatement(shared_ptr<Statement> statement) {
|
|||||||
case StatementKind::FUNCTION_DECLARATION:
|
case StatementKind::FUNCTION_DECLARATION:
|
||||||
buildFunctionDeclaration(dynamic_pointer_cast<StatementFunctionDeclaration>(statement));
|
buildFunctionDeclaration(dynamic_pointer_cast<StatementFunctionDeclaration>(statement));
|
||||||
break;
|
break;
|
||||||
|
case StatementKind::VAR_DECLARATION:
|
||||||
|
buildVarDeclaration(dynamic_pointer_cast<StatementVarDeclaration>(statement));
|
||||||
|
break;
|
||||||
case StatementKind::BLOCK:
|
case StatementKind::BLOCK:
|
||||||
buildBlock(dynamic_pointer_cast<StatementBlock>(statement));
|
buildBlock(dynamic_pointer_cast<StatementBlock>(statement));
|
||||||
break;
|
break;
|
||||||
@@ -45,6 +48,12 @@ void ModuleBuilder::buildFunctionDeclaration(shared_ptr<StatementFunctionDeclara
|
|||||||
buildStatement(statement->getStatementBlock());
|
buildStatement(statement->getStatementBlock());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModuleBuilder::buildVarDeclaration(shared_ptr<StatementVarDeclaration> statement) {
|
||||||
|
llvm::Value *value = valueForExpression(statement->getExpression());
|
||||||
|
llvm::AllocaInst *alloca = builder->CreateAlloca(typeForValueType(statement->getValueType()), nullptr, statement->getName());
|
||||||
|
builder->CreateStore(value, alloca);
|
||||||
|
}
|
||||||
|
|
||||||
void ModuleBuilder::buildBlock(shared_ptr<StatementBlock> statement) {
|
void ModuleBuilder::buildBlock(shared_ptr<StatementBlock> statement) {
|
||||||
for (shared_ptr<Statement> &innerStatement : statement->getStatements()) {
|
for (shared_ptr<Statement> &innerStatement : statement->getStatements()) {
|
||||||
buildStatement(innerStatement);
|
buildStatement(innerStatement);
|
||||||
@@ -99,7 +108,7 @@ llvm::Value *ModuleBuilder::valueForGrouping(shared_ptr<ExpressionGrouping> expr
|
|||||||
}
|
}
|
||||||
|
|
||||||
llvm::Value *ModuleBuilder::valueForBinary(shared_ptr<ExpressionBinary> expression) {
|
llvm::Value *ModuleBuilder::valueForBinary(shared_ptr<ExpressionBinary> expression) {
|
||||||
switch (expression->getValueType()) {
|
switch (expression->getLeft()->getValueType()) {
|
||||||
case ValueType::BOOL:
|
case ValueType::BOOL:
|
||||||
return valueForBinaryBool(expression);
|
return valueForBinaryBool(expression);
|
||||||
case ValueType::SINT32:
|
case ValueType::SINT32:
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ private:
|
|||||||
|
|
||||||
void buildStatement(shared_ptr<Statement> statement);
|
void buildStatement(shared_ptr<Statement> statement);
|
||||||
void buildFunctionDeclaration(shared_ptr<StatementFunctionDeclaration> statement);
|
void buildFunctionDeclaration(shared_ptr<StatementFunctionDeclaration> statement);
|
||||||
|
void buildVarDeclaration(shared_ptr<StatementVarDeclaration> statement);
|
||||||
void buildBlock(shared_ptr<StatementBlock> statement);
|
void buildBlock(shared_ptr<StatementBlock> statement);
|
||||||
void buildReturn(shared_ptr<StatementReturn> statement);
|
void buildReturn(shared_ptr<StatementReturn> statement);
|
||||||
void buildExpression(shared_ptr<StatementExpression> statement);
|
void buildExpression(shared_ptr<StatementExpression> statement);
|
||||||
|
|||||||
@@ -333,7 +333,7 @@ shared_ptr<Expression> Parser::matchExpressionIfElse() {
|
|||||||
else if (!thenBlock->isValid())
|
else if (!thenBlock->isValid())
|
||||||
return matchExpressionInvalid(); // FIXME
|
return matchExpressionInvalid(); // FIXME
|
||||||
|
|
||||||
// Match else blcok
|
// Match else block
|
||||||
shared_ptr<Statement> elseBlock;
|
shared_ptr<Statement> elseBlock;
|
||||||
|
|
||||||
if (tokens.at(currentIndex)->getKind() == TokenKind::COLON) {
|
if (tokens.at(currentIndex)->getKind() == TokenKind::COLON) {
|
||||||
|
|||||||
@@ -51,9 +51,9 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
cout << endl << endl;
|
cout << endl << endl;
|
||||||
|
|
||||||
//ModuleBuilder moduleBuilder(statements);
|
ModuleBuilder moduleBuilder(statements);
|
||||||
//shared_ptr<llvm::Module> module = moduleBuilder.getModule();
|
shared_ptr<llvm::Module> module = moduleBuilder.getModule();
|
||||||
//module->print(llvm::outs(), nullptr);
|
module->print(llvm::outs(), nullptr);
|
||||||
|
|
||||||
//CodeGenerator codeGenerator(module);
|
//CodeGenerator codeGenerator(module);
|
||||||
//codeGenerator.generateObjectFile("dummy.s");
|
//codeGenerator.generateObjectFile("dummy.s");
|
||||||
|
|||||||
Reference in New Issue
Block a user