From c1c64d86db3b0b57df2c9c055857b871ab84b029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Sun, 9 Jul 2023 22:50:28 -0600 Subject: [PATCH] Implement lcompilers_unique_ID global variable This is initialized to a unique number for each run. --- src/bin/lpython.cpp | 7 +++++++ src/libasr/asr_scopes.cpp | 2 ++ src/libasr/utils.h | 2 ++ src/libasr/utils2.cpp | 15 +++++++++++++++ 4 files changed, 26 insertions(+) diff --git a/src/bin/lpython.cpp b/src/bin/lpython.cpp index 4eca2b4da3..013c89e04f 100644 --- a/src/bin/lpython.cpp +++ b/src/bin/lpython.cpp @@ -44,6 +44,9 @@ #include #include #endif + +extern std::string lcompilers_unique_ID; + namespace { using LCompilers::endswith; @@ -54,6 +57,7 @@ enum class Backend { llvm, cpp, c, x86, wasm, wasm_x86, wasm_x64 }; + std::string remove_extension(const std::string& filename) { size_t lastdot = filename.find_last_of("."); if (lastdot == std::string::npos) return filename; @@ -1610,6 +1614,9 @@ int main(int argc, char *argv[]) app.require_subcommand(0, 1); CLI11_PARSE(app, argc, argv); + lcompilers_unique_ID = LCompilers::get_unique_ID(); + + if( compiler_options.fast && compiler_options.enable_bounds_checking ) { // ReleaseSafe Mode } else if ( compiler_options.fast ) { diff --git a/src/libasr/asr_scopes.cpp b/src/libasr/asr_scopes.cpp index acbb50d9c6..ebd3b7c476 100644 --- a/src/libasr/asr_scopes.cpp +++ b/src/libasr/asr_scopes.cpp @@ -4,6 +4,8 @@ #include #include +std::string lcompilers_unique_ID; + namespace LCompilers { template< typename T > diff --git a/src/libasr/utils.h b/src/libasr/utils.h index a0b0c00451..e19e0e3ae4 100644 --- a/src/libasr/utils.h +++ b/src/libasr/utils.h @@ -20,6 +20,8 @@ enum Platform { std::string pf2s(Platform); Platform get_platform(); +std::string get_unique_ID(); + struct CompilerOptions { std::filesystem::path mod_files_dir; std::vector include_dirs; diff --git a/src/libasr/utils2.cpp b/src/libasr/utils2.cpp index 62cabe162d..51a2a3c5f4 100644 --- a/src/libasr/utils2.cpp +++ b/src/libasr/utils2.cpp @@ -4,6 +4,8 @@ #endif #include +#include +#include #include #include @@ -11,6 +13,19 @@ namespace LCompilers { +std::string get_unique_ID() { + static std::random_device dev; + static std::mt19937 rng(dev()); + std::uniform_int_distribution dist(0, 61); + const std::string v = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + std::string res; + for (int i = 0; i < 22; i++) { + res += v[dist(rng)]; + } + return res; +} + bool read_file(const std::string &filename, std::string &text) { std::ifstream ifs(filename.c_str(), std::ios::in | std::ios::binary