ubuntu 22.04 LTS 在 llvm release/17.x 分支上编译 cookbook llvm example Chapter 02

不错的资料:

LLVM+Clang+编译器+链接器--保值【进阶之路二】 - 掘金

——————————————————————————————————————

下载 llvm-cookbook example:

$ git clone https://github.com/elongbug/llvm-cookbook.git

也可以参照llvm-projec中的官方代码,一样的差不多:

https://github.com/llvm/llvm-project/tree/main/llvm/examples/Kaleidoscope

开发环境:

 从apt source 安装llvm、clang和lldb:

$ apt install llvm
$ apt install llvm-dev
$ apt install clang
$ apt install lldb
$ cd llvm-cookbook/Chapter_2
$ make
$ ./toy example1

 运行效果:

事隔十个版本,llvm的接口如故,还是让人惊讶与当时接口定义的周到;

具体代码如下:

Makefile:

CC = clang++
SOURCE = ch2_toy.cpp
TARGET = toy$(TARGET) : $(SOURCE)$(CC) $(SOURCE) -o  $(TARGET) -g -O3 `llvm-config --cxxflags --ldflags --system-libs --libs core mcjit native`clean :rm $(TARGET)

ch2_toy.cpp:

#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h"
#include <cctype>
#include <cstdio>
#include <map>
#include <string>
#include <vector>
using namespace llvm;enum Token_Type { EOF_TOKEN = 0, DEF_TOKEN, IDENTIFIER_TOKEN, NUMERIC_TOKEN };FILE *file;
static std::string Identifier_string;
static int Numeric_Val;static int get_token() {static int LastChar = ' ';while (isspace(LastChar))LastChar = fgetc(file);if (isalpha(LastChar)) {Identifier_string = LastChar;while (isalnum((LastChar = fgetc(file))))Identifier_string += LastChar;if (Identifier_string == "def")return DEF_TOKEN;return IDENTIFIER_TOKEN;}if (isdigit(LastChar)) {std::string NumStr;do {NumStr += LastChar;LastChar = fgetc(file);} while (isdigit(LastChar));Numeric_Val = strtod(NumStr.c_str(), 0);return NUMERIC_TOKEN;}if (LastChar == '#') {doLastChar = fgetc(file);while (LastChar != EOF && LastChar != '\n' && LastChar != '\r');if (LastChar != EOF)return get_token();}if (LastChar == EOF)return EOF_TOKEN;int ThisChar = LastChar;LastChar = fgetc(file);return ThisChar;
}namespace {class BaseAST {
public:virtual ~BaseAST() {}virtual Value *Codegen() = 0;
};class NumericAST : public BaseAST {int numeric_val;public:NumericAST(int val) : numeric_val(val) {}virtual Value *Codegen();
};class VariableAST : public BaseAST {std::string Var_Name;public:VariableAST(const std::string &name) : Var_Name(name) {}virtual Value *Codegen();
};class BinaryAST : public BaseAST {std::string Bin_Operator;BaseAST *LHS, *RHS;public:BinaryAST(std::string op, BaseAST *lhs, BaseAST *rhs): Bin_Operator(op), LHS(lhs), RHS(rhs) {}virtual Value *Codegen();
};class FunctionCallAST : public BaseAST {std::string Function_Callee;std::vector<BaseAST *> Function_Arguments;public:FunctionCallAST(const std::string &callee, std::vector<BaseAST *> &args): Function_Callee(callee), Function_Arguments(args) {}virtual Value *Codegen();
};class FunctionDeclAST {std::string Func_Name;std::vector<std::string> Arguments;public:FunctionDeclAST(const std::string &name, const std::vector<std::string> &args): Func_Name(name), Arguments(args){};Function *Codegen();
};class FunctionDefnAST {FunctionDeclAST *Func_Decl;BaseAST *Body;public:FunctionDefnAST(FunctionDeclAST *proto, BaseAST *body): Func_Decl(proto), Body(body) {}Function *Codegen();
};
} // namespacestatic int Current_token;
static int next_token() { return Current_token = get_token(); }static std::map<char, int> Operator_Precedence;static int getBinOpPrecedence() {if (!isascii(Current_token))return -1;int TokPrec = Operator_Precedence[Current_token];if (TokPrec <= 0)return -1;return TokPrec;
}static BaseAST *expression_parser();static BaseAST *identifier_parser() {std::string IdName = Identifier_string;next_token();if (Current_token != '(')return new VariableAST(IdName);next_token();std::vector<BaseAST *> Args;if (Current_token != ')') {while (1) {BaseAST *Arg = expression_parser();if (!Arg)return 0;Args.push_back(Arg);if (Current_token == ')')break;if (Current_token != ',')return 0;next_token();}}next_token();return new FunctionCallAST(IdName, Args);
}static BaseAST *numeric_parser() {BaseAST *Result = new NumericAST(Numeric_Val);next_token();return Result;
}static BaseAST *paran_parser() {next_token();BaseAST *V = expression_parser();if (!V)return 0;if (Current_token != ')')return 0;return V;
}static BaseAST *Base_Parser() {switch (Current_token) {default:return 0;case IDENTIFIER_TOKEN:return identifier_parser();case NUMERIC_TOKEN:return numeric_parser();case '(':return paran_parser();}
}static BaseAST *binary_op_parser(int Old_Prec, BaseAST *LHS) {while (1) {int Operator_Prec = getBinOpPrecedence();if (Operator_Prec < Old_Prec)return LHS;int BinOp = Current_token;next_token();BaseAST *RHS = Base_Parser();if (!RHS)return 0;int Next_Prec = getBinOpPrecedence();if (Operator_Prec < Next_Prec) {RHS = binary_op_parser(Operator_Prec + 1, RHS);if (RHS == 0)return 0;}LHS = new BinaryAST(std::to_string(BinOp), LHS, RHS);}
}static BaseAST *expression_parser() {BaseAST *LHS = Base_Parser();if (!LHS)return 0;return binary_op_parser(0, LHS);
}static FunctionDeclAST *func_decl_parser() {if (Current_token != IDENTIFIER_TOKEN)return 0;std::string FnName = Identifier_string;next_token();if (Current_token != '(')return 0;std::vector<std::string> Function_Argument_Names;while (next_token() == IDENTIFIER_TOKEN)Function_Argument_Names.push_back(Identifier_string);if (Current_token != ')')return 0;next_token();return new FunctionDeclAST(FnName, Function_Argument_Names);
}static FunctionDefnAST *func_defn_parser() {next_token();FunctionDeclAST *Decl = func_decl_parser();if (Decl == 0)return 0;if (BaseAST *Body = expression_parser())return new FunctionDefnAST(Decl, Body);return 0;
}static FunctionDefnAST *top_level_parser() {if (BaseAST *E = expression_parser()) {FunctionDeclAST *Func_Decl =new FunctionDeclAST("", std::vector<std::string>());return new FunctionDefnAST(Func_Decl, E);}return 0;
}static void init_precedence() {Operator_Precedence['-'] = 1;Operator_Precedence['+'] = 2;Operator_Precedence['/'] = 3;Operator_Precedence['*'] = 4;
}static Module *Module_Ob;
static LLVMContext MyGlobalContext;
static IRBuilder<> Builder(MyGlobalContext);
static std::map<std::string, Value *> Named_Values;Value *NumericAST::Codegen() {return ConstantInt::get(Type::getInt32Ty(MyGlobalContext), numeric_val);
}Value *VariableAST::Codegen() {Value *V = Named_Values[Var_Name];return V ? V : 0;
}Value *BinaryAST::Codegen() {Value *L = LHS->Codegen();Value *R = RHS->Codegen();if (L == 0 || R == 0)return 0;switch (atoi(Bin_Operator.c_str())) {case '+':return Builder.CreateAdd(L, R, "addtmp");case '-':return Builder.CreateSub(L, R, "subtmp");case '*':return Builder.CreateMul(L, R, "multmp");case '/':return Builder.CreateUDiv(L, R, "divtmp");default:return 0;}
}Value *FunctionCallAST::Codegen() {Function *CalleeF = Module_Ob->getFunction(Function_Callee);std::vector<Value *> ArgsV;for (unsigned i = 0, e = Function_Arguments.size(); i != e; ++i) {ArgsV.push_back(Function_Arguments[i]->Codegen());if (ArgsV.back() == 0)return 0;}return Builder.CreateCall(CalleeF, ArgsV, "calltmp");
}Function *FunctionDeclAST::Codegen() {std::vector<Type *> Integers(Arguments.size(),Type::getInt32Ty(MyGlobalContext));FunctionType *FT =FunctionType::get(Type::getInt32Ty(MyGlobalContext), Integers, false);Function *F =Function::Create(FT, Function::ExternalLinkage, Func_Name, Module_Ob);if (F->getName() != Func_Name) {F->eraseFromParent();F = Module_Ob->getFunction(Func_Name);if (!F->empty())return 0;if (F->arg_size() != Arguments.size())return 0;}unsigned Idx = 0;for (Function::arg_iterator Arg_It = F->arg_begin(); Idx != Arguments.size();++Arg_It, ++Idx) {Arg_It->setName(Arguments[Idx]);Named_Values[Arguments[Idx]] = Arg_It;}return F;
}Function *FunctionDefnAST::Codegen() {Named_Values.clear();Function *TheFunction = Func_Decl->Codegen();if (TheFunction == 0)return 0;BasicBlock *BB = BasicBlock::Create(MyGlobalContext, "entry", TheFunction);Builder.SetInsertPoint(BB);if (Value *RetVal = Body->Codegen()) {Builder.CreateRet(RetVal);verifyFunction(*TheFunction);return TheFunction;}TheFunction->eraseFromParent();return 0;
}static void HandleDefn() {if (FunctionDefnAST *F = func_defn_parser()) {if (Function *LF = F->Codegen()) {}} else {next_token();}
}static void HandleTopExpression() {if (FunctionDefnAST *F = top_level_parser()) {if (Function *LF = F->Codegen()) {}} else {next_token();}
}static void Driver() {while (1) {switch (Current_token) {case EOF_TOKEN:return;case ';':next_token();break;case DEF_TOKEN:HandleDefn();break;default:HandleTopExpression();break;}}
}extern "C" double putchard(double X) {putchar((char)X);return 0;
}int main(int argc, char *argv[]) {LLVMContext &Context = MyGlobalContext;init_precedence();file = fopen(argv[1], "r");if (file == 0) {printf("Could not open file\n");}next_token();Module_Ob = new Module("my compiler", Context);Driver();Module_Ob->print(llvm::outs(), nullptr);return 0;
}

 ————————————————————————————————————————

一,从源码编译 llvm

下载源码:

$ git clone https://github.com/llvm/llvm-project.git

创建 对应 commit id分支:

$ cd llvm-project
$ git checkout  5b78868661f42a70fa30  -b  17.x.greater

源码成功编译 llvm-project commit id:

    ~/ex/llvm-project$ git log -1commit 5b78868661f42a70fa3006b1db41f78a6178d596 (HEAD -> main)

 生成构建:

cmake -G "Unix Makefiles" ../llvm    \
-DLLVM_ENABLE_PROJECTS=all           \
-DLLVM_BUILD_EXAMPLES=ON             \
-DLLVM_TARGETS_TO_BUILD="host"       \
-DCMAKE_BUILD_TYPE=Release           \
-DLLVM_ENABLE_ASSERTIONS=ON          \
-DLLVM_ENABLE_RUNTIMES=all           \
-DLLVM_BUILD_LLVM_DYLIB=ON           \  
-DCMAKE_INSTALL_PREFIX=../inst_clanglld_rtall_5b78868661

make -j8

(i9 9900k 8物理core 16logic core, 64GB mem, 64GB swap)

make install

二,编译Chapter2 example

可行的 Makefile:

CC = /home/kleenelan/ex/cookbook_llvm/inst_clanglld_rtall_5b78868661/bin/clang++
SOURCE = ch2_toy.cpp
TARGET = toy$(TARGET) : $(SOURCE)$(CC) $(SOURCE) -o  $(TARGET) -g  `/home/kleenelan/ex/cookbook_llvm/inst_clanglld_rtall_5b78868661/bin/llvm-config --cxxflags --ldflags --system-libs --libs core mcjit native` -I/home/kleenelan/ex/cookbook_llvm/inst_clanglld_rtall_5b78868661/include/c++/v1   -I/home/kleenelan/ex/cookbook_llvm/inst_clanglld_rtall_5b78868661/include/x86_64-unknown-linux-gnu/c++/v1  -L/usr/lib/gcc/x86_64-linux-gnu/11/  -L/home/kleenelan/ex/cookbook_llvm/inst_clanglld_rtall_5b78868661/lib/x86_64-unknown-linux-gnu -lc++clean :rm $(TARGET)

ch2_toy.cpp

#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h"
#include <cctype>
#include <cstdio>
#include <map>
#include <string>
#include <vector>
using namespace llvm;enum Token_Type { EOF_TOKEN = 0, DEF_TOKEN, IDENTIFIER_TOKEN, NUMERIC_TOKEN };FILE *file;
static std::string Identifier_string;
static int Numeric_Val;static int get_token() {static int LastChar = ' ';while (isspace(LastChar))LastChar = fgetc(file);if (isalpha(LastChar)) {Identifier_string = LastChar;while (isalnum((LastChar = fgetc(file))))Identifier_string += LastChar;if (Identifier_string == "def")return DEF_TOKEN;return IDENTIFIER_TOKEN;}if (isdigit(LastChar)) {std::string NumStr;do {NumStr += LastChar;LastChar = fgetc(file);} while (isdigit(LastChar));Numeric_Val = strtod(NumStr.c_str(), 0);return NUMERIC_TOKEN;}if (LastChar == '#') {doLastChar = fgetc(file);while (LastChar != EOF && LastChar != '\n' && LastChar != '\r');if (LastChar != EOF)return get_token();}if (LastChar == EOF)return EOF_TOKEN;int ThisChar = LastChar;LastChar = fgetc(file);return ThisChar;
}namespace {class BaseAST {
public:virtual ~BaseAST() {}virtual Value *Codegen() = 0;
};class NumericAST : public BaseAST {int numeric_val;public:NumericAST(int val) : numeric_val(val) {}virtual Value *Codegen();
};class VariableAST : public BaseAST {std::string Var_Name;public:VariableAST(const std::string &name) : Var_Name(name) {}virtual Value *Codegen();
};class BinaryAST : public BaseAST {std::string Bin_Operator;BaseAST *LHS, *RHS;public:BinaryAST(std::string op, BaseAST *lhs, BaseAST *rhs): Bin_Operator(op), LHS(lhs), RHS(rhs) {}virtual Value *Codegen();
};class FunctionCallAST : public BaseAST {std::string Function_Callee;std::vector<BaseAST *> Function_Arguments;public:FunctionCallAST(const std::string &callee, std::vector<BaseAST *> &args): Function_Callee(callee), Function_Arguments(args) {}virtual Value *Codegen();
};class FunctionDeclAST {std::string Func_Name;std::vector<std::string> Arguments;public:FunctionDeclAST(const std::string &name, const std::vector<std::string> &args): Func_Name(name), Arguments(args){};Function *Codegen();
};class FunctionDefnAST {FunctionDeclAST *Func_Decl;BaseAST *Body;public:FunctionDefnAST(FunctionDeclAST *proto, BaseAST *body): Func_Decl(proto), Body(body) {}Function *Codegen();
};
} // namespacestatic int Current_token;
static int next_token() { return Current_token = get_token(); }static std::map<char, int> Operator_Precedence;static int getBinOpPrecedence() {if (!isascii(Current_token))return -1;int TokPrec = Operator_Precedence[Current_token];if (TokPrec <= 0)return -1;return TokPrec;
}static BaseAST *expression_parser();static BaseAST *identifier_parser() {std::string IdName = Identifier_string;next_token();if (Current_token != '(')return new VariableAST(IdName);next_token();std::vector<BaseAST *> Args;if (Current_token != ')') {while (1) {BaseAST *Arg = expression_parser();if (!Arg)return 0;Args.push_back(Arg);if (Current_token == ')')break;if (Current_token != ',')return 0;next_token();}}next_token();return new FunctionCallAST(IdName, Args);
}static BaseAST *numeric_parser() {BaseAST *Result = new NumericAST(Numeric_Val);next_token();return Result;
}static BaseAST *paran_parser() {next_token();BaseAST *V = expression_parser();if (!V)return 0;if (Current_token != ')')return 0;return V;
}static BaseAST *Base_Parser() {switch (Current_token) {default:return 0;case IDENTIFIER_TOKEN:return identifier_parser();case NUMERIC_TOKEN:return numeric_parser();case '(':return paran_parser();}
}static BaseAST *binary_op_parser(int Old_Prec, BaseAST *LHS) {while (1) {int Operator_Prec = getBinOpPrecedence();if (Operator_Prec < Old_Prec)return LHS;int BinOp = Current_token;next_token();BaseAST *RHS = Base_Parser();if (!RHS)return 0;int Next_Prec = getBinOpPrecedence();if (Operator_Prec < Next_Prec) {RHS = binary_op_parser(Operator_Prec + 1, RHS);if (RHS == 0)return 0;}LHS = new BinaryAST(std::to_string(BinOp), LHS, RHS);}
}static BaseAST *expression_parser() {BaseAST *LHS = Base_Parser();if (!LHS)return 0;return binary_op_parser(0, LHS);
}static FunctionDeclAST *func_decl_parser() {if (Current_token != IDENTIFIER_TOKEN)return 0;std::string FnName = Identifier_string;next_token();if (Current_token != '(')return 0;std::vector<std::string> Function_Argument_Names;while (next_token() == IDENTIFIER_TOKEN)Function_Argument_Names.push_back(Identifier_string);if (Current_token != ')')return 0;next_token();return new FunctionDeclAST(FnName, Function_Argument_Names);
}static FunctionDefnAST *func_defn_parser() {next_token();FunctionDeclAST *Decl = func_decl_parser();if (Decl == 0)return 0;if (BaseAST *Body = expression_parser())return new FunctionDefnAST(Decl, Body);return 0;
}static FunctionDefnAST *top_level_parser() {if (BaseAST *E = expression_parser()) {FunctionDeclAST *Func_Decl =new FunctionDeclAST("", std::vector<std::string>());return new FunctionDefnAST(Func_Decl, E);}return 0;
}static void init_precedence() {Operator_Precedence['-'] = 1;Operator_Precedence['+'] = 2;Operator_Precedence['/'] = 3;Operator_Precedence['*'] = 4;
}static Module *Module_Ob;
static LLVMContext MyGlobalContext;
static IRBuilder<> Builder(MyGlobalContext);
static std::map<std::string, Value *> Named_Values;Value *NumericAST::Codegen() {return ConstantInt::get(Type::getInt32Ty(MyGlobalContext), numeric_val);
}Value *VariableAST::Codegen() {Value *V = Named_Values[Var_Name];return V ? V : 0;
}Value *BinaryAST::Codegen() {Value *L = LHS->Codegen();Value *R = RHS->Codegen();if (L == 0 || R == 0)return 0;switch (atoi(Bin_Operator.c_str())) {case '+':return Builder.CreateAdd(L, R, "addtmp");case '-':return Builder.CreateSub(L, R, "subtmp");case '*':return Builder.CreateMul(L, R, "multmp");case '/':return Builder.CreateUDiv(L, R, "divtmp");default:return 0;}
}Value *FunctionCallAST::Codegen() {Function *CalleeF = Module_Ob->getFunction(Function_Callee);std::vector<Value *> ArgsV;for (unsigned i = 0, e = Function_Arguments.size(); i != e; ++i) {ArgsV.push_back(Function_Arguments[i]->Codegen());if (ArgsV.back() == 0)return 0;}return Builder.CreateCall(CalleeF, ArgsV, "calltmp");
}Function *FunctionDeclAST::Codegen() {std::vector<Type *> Integers(Arguments.size(),Type::getInt32Ty(MyGlobalContext));FunctionType *FT =FunctionType::get(Type::getInt32Ty(MyGlobalContext), Integers, false);Function *F =Function::Create(FT, Function::ExternalLinkage, Func_Name, Module_Ob);if (F->getName() != Func_Name) {F->eraseFromParent();F = Module_Ob->getFunction(Func_Name);if (!F->empty())return 0;if (F->arg_size() != Arguments.size())return 0;}unsigned Idx = 0;for (Function::arg_iterator Arg_It = F->arg_begin(); Idx != Arguments.size();++Arg_It, ++Idx) {Arg_It->setName(Arguments[Idx]);Named_Values[Arguments[Idx]] = Arg_It;}return F;
}Function *FunctionDefnAST::Codegen() {Named_Values.clear();Function *TheFunction = Func_Decl->Codegen();if (TheFunction == 0)return 0;BasicBlock *BB = BasicBlock::Create(MyGlobalContext, "entry", TheFunction);Builder.SetInsertPoint(BB);if (Value *RetVal = Body->Codegen()) {Builder.CreateRet(RetVal);verifyFunction(*TheFunction);return TheFunction;}TheFunction->eraseFromParent();return 0;
}static void HandleDefn() {if (FunctionDefnAST *F = func_defn_parser()) {if (Function *LF = F->Codegen()) {}} else {next_token();}
}static void HandleTopExpression() {if (FunctionDefnAST *F = top_level_parser()) {if (Function *LF = F->Codegen()) {}} else {next_token();}
}static void Driver() {while (1) {switch (Current_token) {case EOF_TOKEN:return;case ';':next_token();break;case DEF_TOKEN:HandleDefn();break;default:HandleTopExpression();break;}}
}extern "C" double putchard(double X) {putchar((char)X);return 0;
}int main(int argc, char *argv[]) {LLVMContext &Context = MyGlobalContext;init_precedence();file = fopen(argv[1], "r");if (file == 0) {printf("Could not open file\n");}next_token();Module_Ob = new Module("my compiler", Context);Driver();Module_Ob->print(llvm::outs(), nullptr);return 0;
}

$ make

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/101584.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【BASH】回顾与知识点梳理(三十九)

【BASH】回顾与知识点梳理 三十九 三十九. make、tarball、函数库及软件校验39.1 用 make 进行宏编译为什么要用 makemakefile 的基本语法与变量 39.2 Tarball 的管理与建议使用原始码管理软件所需要的基础软件Tarball 安装的基本步骤一般 Tarball 软件安装的建议事项 (如何移除…

【vue3+ts项目】配置eslint校验代码工具,eslint+prettier+stylelint

1、运行好后自动打开浏览器 package.json中 vite后面加上 --open 2、安装eslint npm i eslint -D3、运行 eslint --init 之后&#xff0c;回答一些问题&#xff0c; 自动创建 .eslintrc 配置文件。 npx eslint --init回答问题如下&#xff1a; 使用eslint仅检查语法&…

6-模板初步使用

官网: 中文版: 介绍-Jinja2中文文档 英文版: Template Designer Documentation — Jinja Documentation (2.11.x) 模板语法 1. 模板渲染 (1) app.py 准备数据 import jsonfrom flask import Flask,render_templateimport settingsapp Flask(__name__) app.config.from_obj…

VB.NET通过VB6 ActiveX DLL调用PowerBasic及FreeBasic动态库

前面说的Delphi通过Activex DLL同时调用PowerBasic和FreeBasic写的DLL&#xff0c;是在WINDOWS基础平台上完成的。 而 .NET平台是架在WINDOWS基础平台之上的&#xff0c;它的上面VB.NET或C#等开发的APP程序&#xff0c;下面写一下用VB.NET&#xff0c;通过VB6注册的Activex DLL…

SOA通信中间件常用的通信协议

摘要&#xff1a; SOA&#xff08;面向服务的架构&#xff09;的软件设计原则之一是模块化。 前言 SOA&#xff08;面向服务的架构&#xff09;的软件设计原则之一是模块化。模块化可以提高软件系统的可维护性和代码重用性&#xff0c;并且能够隔离故障。举例来说&#xff0c;…

(一)idea连接GitHub的全部流程(注册GitHub、idea集成GitHub、增加合作伙伴、跨团队合作、分支操作)

&#xff08;二&#xff09;Git在公司中团队内合作和跨团队合作和分支操作的全部流程&#xff08;一篇就够&#xff09;https://blog.csdn.net/m0_65992672/article/details/132336481 4.1、简介 Git是一个免费的、开源的*分布式**版本控制**系统*&#xff0c;可以快速高效地…

滑动窗口介绍

1.基本概念 利用单调性&#xff0c;使用同向双指针&#xff0c;两个指针之间形成一个窗口 子串与子数组都是连续的一段子序列时不连续的 2.为什么可以用滑动窗口&#xff1f; 暴力解决时发现两个指针不需要回退&#xff08;没必要回退&#xff0c;一定不会符合结果&#xf…

sentinel的基本使用

在一些互联网项目中高并发的场景很多&#xff0c;瞬间流量很大&#xff0c;会导致我们服务不可用。 sentinel则可以保证我们服务的正常运行&#xff0c;提供限流、熔断、降级等方法来实现 一.限流&#xff1a; 1.导入坐标 <dependency><groupId>com.alibaba.c…

ansible(2)-- ansible常用模块

部署ansible&#xff1a;ansible&#xff08;1&#xff09;-- 部署ansible连接被控端_luo_guibin的博客-CSDN博客 目录 一、ansible常用模块 1.1 ping 1.2 command 1.3 raw 1.4 shell 1.5 script 1.6 copy 1.7 template 1.8 yum 11.0.1.13 主控端(ansible)11.0.1.12 被控端(k8s…

【Java 高阶】一文精通 Spring MVC - 基础概念(一)

&#x1f449;博主介绍&#xff1a; 博主从事应用安全和大数据领域&#xff0c;有8年研发经验&#xff0c;5年面试官经验&#xff0c;Java技术专家&#xff0c;WEB架构师&#xff0c;阿里云专家博主&#xff0c;华为云云享专家&#xff0c;51CTO 专家博主 ⛪️ 个人社区&#x…

Redis的基本操作

文章目录 1.Redis简介2.Redis的常用数据类型3.Redis的常用命令1.字符串操作命令2.哈希操作命令3.列表操作命令4.集合操作命令5.有序集合操作命令6.通用操作命令 4.Springboot配置Redis1.导入SpringDataRedis的Maven坐标2.配置Redis的数据源3.编写配置类&#xff0c;创还能Redis…

k8s-ingress-context deadline exceeded

报错&#xff1a; rancher-rke-01:~/rke # helm install rancher rancher-latest/rancher --namespace cattle-system --set hostnamewww.rancher.local Error: INSTALLATION FAILED: Internal error occurred: failed calling webhook "validate.nginx.ingress.kube…

Java后端开发面试题——微服务篇总结

Spring Cloud 5大组件有哪些&#xff1f; 随着SpringCloudAlibba在国内兴起 , 我们项目中使用了一些阿里巴巴的组件 注册中心/配置中心 Nacos 负载均衡 Ribbon 服务调用 Feign 服务保护 sentinel 服务网关 Gateway Ribbon负载均衡策略有哪些 ? RoundRobinRule&…

Docker容器与虚拟化技术:Docker consul 实现服务注册与发现

目录 一、理论 1.Docker consul 二、实验 1.consul部署 2. consul-template部署 三、总结 一、理论 1.Docker consul &#xff08;1&#xff09;服务注册与发现 服务注册与发现是微服务架构中不可或缺的重要组件。起初服务都是单节点的&#xff0c;不保障高可用性&…

Python功能制作之简单的音乐播放器

需要导入的库&#xff1a; pip install PyQt5 源码&#xff1a; import os from PyQt5.QtCore import Qt, QUrl from PyQt5.QtGui import QIcon, QPixmap from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent from PyQt5.QtWidgets import QApplication, QMainWind…

RNN+LSTM正弦sin信号预测 完整代码数据视频教程

视频讲解:RNN+LSTM正弦sin信号预测_哔哩哔哩_bilibili 效果演示: 数据展示: 完整代码: import torch import torch.nn as nn import torch.optim as optim import numpy as np import matplotlib.pyplot as plt import pandas as pd from sklearn.preprocessing import…

基于web的鲜花商城系统java jsp网上购物超市mysql源代码

本项目为前几天收费帮学妹做的一个项目&#xff0c;Java EE JSP项目&#xff0c;在工作环境中基本使用不到&#xff0c;但是很多学校把这个当作编程入门的项目来做&#xff0c;故分享出本项目供初学者参考。 一、项目描述 基于web的鲜花商城系统 系统有2权限&#xff1a;前台…

【数据结构与算法】迪杰斯特拉算法

迪杰斯特拉算法 介绍 迪杰斯特拉&#xff08;Dijkstra&#xff09;算法是典型最短路径算法&#xff0c;用于计算一个节点到其他节点的最短路径。它的主要特点是以中心向外层层扩展&#xff08;广度优先搜索思想&#xff09;&#xff0c;直到扩展到终点为止。 算法过程 设置…

thinkphp6.0 配合shell 脚本 定时任务

1. 执行命令&#xff0c;生成自定义命令 php think make:command Custom<?php declare (strict_types 1);namespace app\command;use app\facade\AdmUser; use think\console\Command; use think\console\Input; use think\console\input\Argument; use think\console\i…

Microsoft正在将Python引入Excel

Excel和Python这两个世界正在碰撞&#xff0c;这要归功于Microsoft的新集成&#xff0c;以促进数据分析和可视化 Microsoft正在将流行的编程语言Python引入Excel。该功能的公共预览版现已推出&#xff0c;允许Excel用户操作和分析来自Python的数据。 “您可以使用 Python 绘图…