Skip to content

Шурыгин Сергей. Лабораторная работа 3: Backend. Вариант 4. #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8797851
Update readme (#1)
Kuznetsov-Artyom Feb 14, 2025
080632e
Update README.md (#2)
Kuznetsov-Artyom Feb 20, 2025
1600352
Update readme and add label `docs` (#3)
Kuznetsov-Artyom Feb 21, 2025
58509a0
Add deadline lab1 (#4)
Kuznetsov-Artyom Feb 27, 2025
6eb53f4
Шурыгин Сергей. Задание №1. Вариант №4. (#5)
PutinVVV Mar 4, 2025
435ec1f
Lopatin Ilya. Lab 1: Clang AST. Option 1. (#6)
ascannel Mar 5, 2025
62d577d
Бесхмельнова Ксения. Лабораторная работа 1: Clang AST. Вариант 3. (#8)
KseniyaBeskhmelnova Mar 9, 2025
8c3ef28
Kurakin Matvey. FIIT1. Lab 1. Clang AST (#10)
MatveyKurakin Mar 11, 2025
687a39b
Чистов Алексей. Лабораторная работа 1. Clang AST. Вариант 1. (#11)
wabka22 Mar 11, 2025
823c5e4
[CI] Fix clang-format job
aobolensk Mar 13, 2025
3b62a16
Холин Кирилл. Лабораторная работа 1: Clang AST. Вариант 4. (#9)
Kirius257 Mar 13, 2025
000ed03
Кудряшова Ирина. Лабораторная работа 1: Clang AST. Вариант 3. (#7)
Irina2004-tech Mar 14, 2025
bb696cd
Дрождинов Дмитрий. Лабораторная работа 1. Clang AST. Вариант 3. (#13)
dima-dimka04 Mar 15, 2025
a44724b
Revert "Кудряшова Ирина. Лабораторная работа 1: Clang AST. Вариант 3.…
aobolensk Mar 15, 2025
b23eb5a
Шкуринская Елена. Лабораторная работа 1. Clang AST. Вариант 4. (#18)
sudo-technoir Mar 15, 2025
3828bab
Ионова Екатерина. Лабораторная работа 1: Clang AST. Вариант 1. (#15)
IonovvA Mar 15, 2025
b3e051a
Комшина Дарья.Лабораторная работа 1.Clang AST. Вариант 3 (#30)
MikasaAkc Mar 16, 2025
0cb240f
Фролова Елизавета. Лабораторная работа 1. Clang AST. Вариант 3. (#21)
ElizavetaFrolova Mar 18, 2025
12fec08
Колодкин Григорий. Лабораторная работа №1: ClangAST. Вариант 1. (#12)
KolodkinGrigorii Mar 18, 2025
f3bde0c
Резанцева Анастасия. Лабораторная работа 1: Clang AST. Вариант 4. (#14)
AnastasiaRezantseva Mar 18, 2025
1d3993c
Грудзин Константин. Лабораторная работа 1. Clang AST. Вариант 2 (#17)
Konstantin-Grudzin Mar 18, 2025
0dc49fa
Баранов Алексей. Лабораторная работа 1.Clang AST. Вариант 1. (#19)
Torcna Mar 18, 2025
0af8b45
Миронов Арсений. 3822Б1ФИ1. Лабораторная работа 1. Вариант 3. (#31)
Napkin-AI Mar 18, 2025
c6312a9
Revert "Кудряшова Ирина. Лабораторная работа 1: Clang AST. Вариант 3.…
Irina2004-tech Mar 19, 2025
bc5f22e
[CI] Fix workflow stop on new commit (#49)
m1likus Mar 19, 2025
68a3fb6
[CI] Normalize cache (#48)
aobolensk Mar 19, 2025
b7c6fe0
Соловьев Алексей. Лабораторная работа 1: Clang AST. Вариант 4. (#32)
Alexey-Solovev Mar 20, 2025
388e5c9
Козлова Екатерина. Лабораторная работа 1. Clang AST. Вариант 4. (#33)
KatyaKozlova Mar 20, 2025
c58b192
Суворов Дмитрий. Лабораторная работа 1. Clang AST. Вариант 4. (#37)
suvorovDm-1 Mar 20, 2025
fbcec98
Кабалова Валерия. Лабораторная работа 1. Вариант 2. (#38)
m1likus Mar 20, 2025
44b9d82
Соловьев Данила. Лабораторная работа 1: Clang AST. Вариант 2. (#16)
DSolo03 Mar 20, 2025
bc5bd36
Созонов Илья. Лабораторная работа 1. Clang AST. Вариант 1. (#40)
sozozzya Mar 21, 2025
6d88488
Плеханов Даниил. Лабораторная работа 1. Clang AST. Вариант 2 (#39)
Dxppi Mar 22, 2025
0ee90b4
Иванов Михаил. Лабораторная работа 1. Clang AST. Вариант 4. (#54)
misha-ivanov Mar 23, 2025
49fafeb
Савченко Максим. Лабораторная работа 1. Clang AST. Вариант 2. (#51)
MaxikGuy Mar 25, 2025
f6b95a3
Add deadline lab 2 (#61)
Kuznetsov-Artyom Mar 25, 2025
3f2edc5
N1
sergo199536 Mar 26, 2025
a067461
delete coments
sergo199536 Mar 26, 2025
83ca8fd
small fix
PutinVVV Mar 27, 2025
d308f80
add small fix
PutinVVV Mar 27, 2025
c01340f
clang fix-_-
PutinVVV Mar 27, 2025
d44fc2b
delete space XD
PutinVVV Mar 27, 2025
d31d485
1/2 fix
PutinVVV Mar 31, 2025
0421611
fix 2/3
sergo199536 Mar 31, 2025
40b6f91
fix 4/5
sergo199536 Mar 31, 2025
74dd00d
fix 5/5 mb
sergo199536 Mar 31, 2025
84ce4ae
N1
sergo199536 Apr 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/deadline.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def main():
moscow_tz = ZoneInfo("Europe/Moscow")
current_date = datetime.now(moscow_tz)
deadline_date = {
"lab:clang": datetime(2025, 6, 1, hour=19, tzinfo=moscow_tz),
"lab:llvm ir": datetime(2025, 6, 1, hour=19, tzinfo=moscow_tz),
"lab:clang": datetime(2025, 3, 19, hour=19, tzinfo=moscow_tz),
"lab:llvm ir": datetime(2025, 4, 9, hour=19, tzinfo=moscow_tz),
"lab:backend": datetime(2025, 6, 1, hour=19, tzinfo=moscow_tz),
"lab:mlir": datetime(2025, 6, 1, hour=19, tzinfo=moscow_tz),
}
Expand Down
3 changes: 3 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ tests:
- "llvm/test/compiler-course/**"
- "mlir/test/compiler-course/**"

docs:
- "README.md"

ci:
- ".github/**"
14 changes: 10 additions & 4 deletions .github/workflows/compiler-course-build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Build LLVM
on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: ${{ github.ref != 'refs/heads/course-spring-2025' && github.event_name != 'merge_group' && !startsWith(github.ref, 'refs/heads/gh-readonly-queue') }}

jobs:
ubuntu-gcc-build:
runs-on: ubuntu-latest
Expand All @@ -19,8 +23,9 @@ jobs:
- name: Setup ccache
uses: hendrikmuhs/[email protected]
with:
max-size: 500M
key: ccache-${{ github.job }}
key: ${{ runner.os }}
create-symlink: true
max-size: 1.5G
- name: Build
run: |
cmake -S llvm -B build \
Expand Down Expand Up @@ -54,8 +59,9 @@ jobs:
- name: Setup ccache
uses: hendrikmuhs/[email protected]
with:
max-size: 500M
key: ccache-${{ github.job }}
key: ${{ runner.os }}
create-symlink: true
max-size: 1.5G
- name: Build
run: |
cmake -S llvm -B build \
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/compiler-course-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install clang-format
run: |
sudo apt-get install -y clang-format
- name: Run clang-format
run: |
git-clang-format --diff `git merge-base ${GITHUB_SHA} ${GITHUB_BASE_REF}`
git-clang-format --diff `git merge-base ${GITHUB_SHA} origin/${GITHUB_BASE_REF}` ${GITHUB_SHA} 2>&1 | tee log.txt
exit `grep -c diff log.txt`
clang-tidy:
runs-on: ubuntu-latest
steps:
Expand All @@ -20,10 +23,13 @@ jobs:
submodules: recursive
- name: Update submodules
run: git submodule update --init --recursive
- name: ccache

- name: Setup ccache
uses: hendrikmuhs/[email protected]
with:
key: ${{ github.job }}
key: ${{ runner.os }}
create-symlink: true
max-size: 1.5G
- uses: aobolensk/[email protected]
id: review
with:
Expand Down
59 changes: 31 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
# Compiler course 2025

[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/llvm/llvm-project/badge)](https://securityscorecards.dev/viewer/?uri=github.com/llvm/llvm-project)
[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/8273/badge)](https://www.bestpractices.dev/projects/8273)
[![libc++](https://github.com/llvm/llvm-project/actions/workflows/libcxx-build-and-test.yaml/badge.svg?branch=main&event=schedule)](https://github.com/llvm/llvm-project/actions/workflows/libcxx-build-and-test.yaml?query=event%3Aschedule)
[![Build LLVM](https://github.com/NN-complr-tech/compiler-course-2025/actions/workflows/compiler-course-build.yml/badge.svg)](https://github.com/NN-complr-tech/compiler-course-2025/actions/workflows/compiler-course-build.yml)

# Resources
- [Telegram сhat][chat]
- [Telegram сhannel][channel]
- [Tasks and results][results]
- Materials
- [Lecture recordings][recording]
- [Lecture presentations][lecture]
- [LLVM][llvm]
- [MLIR][mlir]
- [Clang][clang]
- [FileCheck][filecheck]
- [Official YouTube channel LLVM][youtube_llvm]

<!-- LINKS -->
<!-- Tasks and results -->
[results]: https://docs.google.com/spreadsheets/d/1LiZ5FMd5t61yoGdnpANTFpzqtKD_ejtvLl1cHKZxvXQ/edit?usp=sharing
<!-- Contacts -->
[channel]: https://t.me/+TPntKPD8z0E3OWJi
[chat]: https://t.me/+JG3n1jeSAiIxZjMy
<!-- Materials -->
[recording]: https://disk.yandex.ru/d/52gu5vJTSt1VFg
[lecture]: https://github.com/NN-complr-tech/Complr-course-lectures
[llvm]: https://llvm.org/
[mlir]: https://mlir.llvm.org/
[clang]: https://clang.llvm.org/
[filecheck]: https://llvm.org/docs/CommandGuide/FileCheck.html
[youtube_llvm]: https://www.youtube.com/@LLVMPROJ

# What is LLVM?
LLLVM is a set of compiler and toolchain technologies that can be used to develop a frontend for any programming language and a backend for any instruction set architecture. LLVM is designed around a language-independent intermediate representation (IR) that serves as a portable, high-level assembly language that can be optimized with a variety of transformations over multiple passes. The name LLVM originally stood for Low Level Virtual Machine, though the project has expanded and the name is no longer officially an initialism.
Expand All @@ -27,8 +53,8 @@ Recommended OS - Linux (WSL).
1. Create fork this repository
2. Clone local fork
```bash
git clone https://github.com/<your-github-name>/llvm.git
cd llvm/
git clone https://github.com/<your-github-name>/compiler-course-2025.git
cd compiler-course-2025/
git checkout -b <name-your-branch>
```

Expand Down Expand Up @@ -105,26 +131,3 @@ For one test
```bash
./build/bin/llvm-lit -v /path/to/test_file
```
# 6. Resources
- [Telegram сhat][chat]
- [Telegram сhannel][channel]
- [Tasks and results][results]
- Materials
- [Lectures][lecture]
- [LLVM][llvm]
- [MLIR][mlir]
- [Clang][clang]
- [Official YouTube channel LLVM][youtube_llvm]

<!-- LINKS -->
<!-- Tasks and results -->
[results]: https://docs.google.com/spreadsheets/d/1LiZ5FMd5t61yoGdnpANTFpzqtKD_ejtvLl1cHKZxvXQ/edit?usp=sharing
<!-- Contacts -->
[channel]: https://t.me/+TPntKPD8z0E3OWJi
[chat]: https://t.me/+JG3n1jeSAiIxZjMy
<!-- Materials -->
[lecture]: https://github.com/NN-complr-tech/Complr-course-lectures
[llvm]: https://llvm.org/
[mlir]: https://mlir.llvm.org/
[clang]: https://clang.llvm.org/
[youtube_llvm]: https://www.youtube.com/@LLVMPROJ
18 changes: 18 additions & 0 deletions clang/compiler-course/Kholin_K_prefixes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(Title "PrefixesPlugin")
set(Student "KholinKirill")
set(Group "FIIT3")
set(TARGET_NAME "${Title}_${Student}_${Group}_ClangAST")

file(GLOB_RECURSE SOURCES *.cpp *.h *.hpp)
add_llvm_library(${TARGET_NAME} MODULE ${SOURCES} PLUGIN_TOOL clang)

if(WIN32 OR CYGWIN)
set(LLVM_LINK_COMPONENTS Support)
clang_target_link_libraries(${TARGET_NAME} PRIVATE
clangAST
clangBasic
clangFrontend
)
endif()

set(CLANG_TEST_DEPS "${TARGET_NAME}" ${CLANG_TEST_DEPS} PARENT_SCOPE)
105 changes: 105 additions & 0 deletions clang/compiler-course/Kholin_K_prefixes/Kholin_K_prefixes_plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendPluginRegistry.h"
#include "clang/Rewrite/Core/Rewriter.h"
#include "llvm/Support/raw_ostream.h"
#include <fstream>
#include <optional>
#include <set>

using namespace clang;

class FindNamedClassVisitor
: public RecursiveASTVisitor<FindNamedClassVisitor> {
public:
explicit FindNamedClassVisitor(ASTContext *Context, Rewriter &R)
: Context(Context), Rewrite(R) {}

std::optional<std::string> getVarPrefix(const VarDecl *Decl) {
if (Decl->isStaticLocal()) {
return "static_";
} else if (Decl->isFileVarDecl()) {
return "global_";
} else if (isa<ParmVarDecl>(Decl)) {
return "param_";
} else if (Decl->isLocalVarDecl()) {
return "local_";
}
return std::nullopt;
}

void renameVariable(Decl *Decl, SourceLocation StartLocation) {
if (!Decl) return;

std::optional<std::string> VarPrefix = getVarPrefix(cast<VarDecl>(Decl));
if (!VarPrefix.has_value()) return;

std::string NewID = VarPrefix.value() + cast<VarDecl>(Decl)->getNameAsString();
SourceLocation EndLocation =
StartLocation.getLocWithOffset(cast<VarDecl>(Decl)->getNameAsString().length());
Rewrite.ReplaceText(SourceRange(StartLocation, EndLocation), NewID);

FullSourceLoc FullLocation = Context->getFullLoc(StartLocation);
if (FullLocation.isValid()) {
llvm::outs() << "Found variable: " << cast<VarDecl>(Decl)->getNameAsString() << " -> "
<< NewID << " at " << FullLocation.getSpellingLineNumber() << ":"
<< FullLocation.getSpellingColumnNumber() << "\n";
}
}

bool VisitVarDecl(VarDecl *Decl) {
if (!Decl) return false;
renameVariable(Decl, Decl->getLocation());
return true;
}

bool VisitDeclRefExpr(DeclRefExpr *Expr) {
if (!Expr) return false;

VarDecl *Decl = dyn_cast<VarDecl>(Expr->getDecl());

renameVariable(Decl, Expr->getLocation());
return true;
}

private:
ASTContext *Context;
Rewriter &Rewrite;
};

class FindNamedClassConsumer : public clang::ASTConsumer {
public:
explicit FindNamedClassConsumer(ASTContext *Context, Rewriter &R)
: Visitor(Context, R) {}

void HandleTranslationUnit(ASTContext &Context) override {
Visitor.TraverseDecl(Context.getTranslationUnitDecl());
}

private:
FindNamedClassVisitor Visitor;
};

class FindNamedClassAction : public clang::PluginASTAction {
public:
std::unique_ptr<clang::ASTConsumer>
CreateASTConsumer(CompilerInstance &Compiler,
llvm::StringRef InFile) override {
m_rewriter.setSourceMgr(Compiler.getSourceManager(),
Compiler.getLangOpts());
return std::make_unique<FindNamedClassConsumer>(&Compiler.getASTContext(),
m_rewriter);
}

bool ParseArgs(const CompilerInstance &CI,
const std::vector<std::string> &Args) override {
return true;
}

private:
Rewriter m_rewriter;
};

static clang::FrontendPluginRegistry::Add<FindNamedClassAction>
X("PrefixesPlugin_KholinKirill_FIIT3_ClangAST", "set prefixes variables");
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(Title "ClangAST_1")
set(Student "ShuriginS")
set(Group "FIIT1")
set(TARGET_NAME "${Title}_${Student}_${Group}_ClangAST")

file(GLOB_RECURSE SOURCES *.cpp *.h *.hpp)
add_llvm_library(${TARGET_NAME} MODULE ${SOURCES} PLUGIN_TOOL clang)

if(WIN32 OR CYGWIN)
set(LLVM_LINK_COMPONENTS Support)
clang_target_link_libraries(${TARGET_NAME} PRIVATE
clangAST
clangBasic
clangFrontend
)
endif()

set(CLANG_TEST_DEPS "${TARGET_NAME}" ${CLANG_TEST_DEPS} PARENT_SCOPE)
Loading