-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd22d43
commit 5ab23aa
Showing
13 changed files
with
605 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Test | ||
on: | ||
push: | ||
branches: | ||
- master | ||
tags: | ||
- v[0-9]+.[0-9] | ||
|
||
jobs: | ||
BuildAndTestUbuntu: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
submodules: recursive | ||
|
||
- name: release name | ||
id: release | ||
run: | | ||
branch=$(echo ${{github.ref}} | sed 's/refs\/\(heads\|tags\)\///g') && \ | ||
release=$([[ "$branch" =~ v[0-9.]+ ]] && echo $branch || echo $branch) && \ | ||
echo "release_name=$release" && \ | ||
printf "::set-output name=release::%s\n" "$release" | ||
- name: install clang | ||
run: | | ||
wget https://apt.llvm.org/llvm.sh && \ | ||
chmod +x llvm.sh && \ | ||
sudo ./llvm.sh 17 && \ | ||
sudo apt install clang-tidy && \ | ||
echo "clang-17: $(which clang-17), clang-tidy: $(which clang-tidy-17)" | ||
- name: Release Build | ||
run: | | ||
export CC=$(which clang-17) && export CXX=$(which clang++-17) && \ | ||
mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DCXX_VERSION=17 && make | ||
- name: Test | ||
run: | | ||
cd build && ctest | ||
- name: release | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
allowUpdates: true | ||
artifacts: "./build/example/SimpleCalculator/scalc" | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
tag: ${{ steps.release.outputs.release }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "ast.h" | ||
#include <map> | ||
#include <string> | ||
#include <memory> | ||
#include <variant> | ||
#include <llvm/IR/IRBuilder.h> | ||
#include <llvm/IR/LLVMContext.h> | ||
#include <llvm/IR/Module.h> | ||
#include <llvm/ADT/APFloat.h> | ||
|
||
|
||
class ASTNodeVisitorLLVMGen: public ASTNodeVisitor { | ||
private: | ||
std::unique_ptr<llvm::LLVMContext> m_context; | ||
std::unique_ptr<llvm::Module> m_module; | ||
std::unique_ptr<llvm::IRBuilder<>> m_builder; | ||
std::vector<std::map<std::string, std::variant<llvm::AllocaInst*,llvm::GlobalVariable*>>> m_namedValues; | ||
llvm::Value* m_prevValue; | ||
bool m_globalscope; | ||
|
||
llvm::Value* lookup_var(const std::string& name) | ||
{ | ||
for (size_t i=m_namedValues.size();i>0;i--) { | ||
auto& k = m_namedValues.at(i - 1); | ||
if (k.count(name)) { | ||
if (std::holds_alternative<llvm::AllocaInst*>(k.at(name))) { | ||
return std::get<0>(k.at(name)); | ||
} else { | ||
return std::get<1>(k.at(name)); | ||
} | ||
} | ||
} | ||
return nullptr; | ||
} | ||
|
||
public: | ||
ASTNodeVisitorLLVMGen(const std::string& filename); | ||
|
||
void visitExpr(const ASTNodeExpr&) override; | ||
void visitExprStat(const ASTNodeExprList&) override; | ||
void visitBlockStat(const ASTNodeStatList&) override; | ||
void visitStatList(const std::vector<std::shared_ptr<ASTNodeStat>>&) override; | ||
void visitForStat(const ASTNodeExprList*, const ASTNodeExpr*, const ASTNodeExprList*, const ASTNodeStat&) override; | ||
void visitIfStat(const ASTNodeExpr&, const ASTNodeStat&, const ASTNodeStat*) override; | ||
void visitReturnStat(const ASTNodeExpr&) override; | ||
void visitFuncDef(const std::string&, const std::vector<std::string>&, const ASTNodeBlockStat&) override; | ||
void visitFuncDecl(const std::string&, const std::vector<std::string>&) override; | ||
void visitCalcUnit(const std::vector<UnitItem>&) override; | ||
|
||
std::string codegen() const; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.