Skip to content

Commit

Permalink
修复代码生成BUG & 改进诊断输出 (#40)
Browse files Browse the repository at this point in the history
* 修复Error不应该是panic

* 限制并行数量避免占用过高

* 更改原生字符串为string view

* 改进代码生成

* update llvm backend

* 修复codegen的bug

* 改进诊断输出

* 更新子模块
  • Loading branch information
heckerpowered authored Oct 14, 2024
1 parent e82e306 commit e0c4eb6
Show file tree
Hide file tree
Showing 12 changed files with 422 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"label": "CMake Build",
"type": "shell",
"command": "cmake --build build -j",
"command": "cmake --build build -j$nproc",
"options": {
"cwd": "${workspaceFolder}"
},
Expand Down
17 changes: 17 additions & 0 deletions Mamba/src/Code Analysis/Binding/ControlFlow/BasicBlock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <memory>

#include "BoundStatement.h"
#include "MambaCore.h"

namespace Mamba
{
struct BasicBlock
{
std::span<const BoundStatement*> Statements;

std::unique_ptr<Nullable<BasicBlock>> Successor;
std::unique_ptr<Nullable<BasicBlock>> Predecessor;
};
} // namespace Mamba
12 changes: 12 additions & 0 deletions Mamba/src/Code Analysis/Binding/ControlFlow/BasicBlockBranch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "BasicBlock.h"
#include "BoundExpression.h"

namespace Mamba
{
struct BasicBlockBranch : public BasicBlock
{
const BoundExpression* Condition;
};
} // namespace Mamba
12 changes: 12 additions & 0 deletions Mamba/src/Code Analysis/Binding/ControlFlow/ControlFlowGraph.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "BasicBlock.h"

namespace Mamba
{
struct ControlFlowGraph
{
BasicBlock Entry;
BasicBlock Exit;
};
} // namespace Mamba
12 changes: 12 additions & 0 deletions Mamba/src/Code Generation/LLVM/CompareKind.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

namespace Mamba
{
enum class CompareKind
{
Ordered,
Unordered,
Signed,
Unsigned
};
} // namespace Mamba
7 changes: 7 additions & 0 deletions Mamba/src/Code Generation/LLVM/GenerationContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@ namespace Mamba
llvm::IRBuilder<>& Builder;

std::unordered_map<StringView, llvm::AllocaInst*> NamedValues;

llvm::AllocaInst* ReturnValue;
llvm::BasicBlock* ReturnBlock;

// Indicates that an unconditional jump instruction has been generated,
// and subsequent code is considered DEAD code and should be excised
bool IsTerminating;
};
} // namespace Mamba
Loading

0 comments on commit e0c4eb6

Please sign in to comment.