Skip to content

Commit f0284c1

Browse files
authored
Merge pull request #2138 from certik/unique_id
Implement lcompilers_unique_ID global variable
2 parents c6628be + c1c64d8 commit f0284c1

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

src/bin/lpython.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
#include <rapidjson/stringbuffer.h>
4545
#include <rapidjson/writer.h>
4646
#endif
47+
48+
extern std::string lcompilers_unique_ID;
49+
4750
namespace {
4851

4952
using LCompilers::endswith;
@@ -54,6 +57,7 @@ enum class Backend {
5457
llvm, cpp, c, x86, wasm, wasm_x86, wasm_x64
5558
};
5659

60+
5761
std::string remove_extension(const std::string& filename) {
5862
size_t lastdot = filename.find_last_of(".");
5963
if (lastdot == std::string::npos) return filename;
@@ -1610,6 +1614,9 @@ int main(int argc, char *argv[])
16101614
app.require_subcommand(0, 1);
16111615
CLI11_PARSE(app, argc, argv);
16121616

1617+
lcompilers_unique_ID = LCompilers::get_unique_ID();
1618+
1619+
16131620
if( compiler_options.fast && compiler_options.enable_bounds_checking ) {
16141621
// ReleaseSafe Mode
16151622
} else if ( compiler_options.fast ) {

src/libasr/asr_scopes.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <libasr/asr_scopes.h>
55
#include <libasr/asr_utils.h>
66

7+
std::string lcompilers_unique_ID;
8+
79
namespace LCompilers {
810

911
template< typename T >

src/libasr/utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ enum Platform {
2020
std::string pf2s(Platform);
2121
Platform get_platform();
2222

23+
std::string get_unique_ID();
24+
2325
struct CompilerOptions {
2426
std::filesystem::path mod_files_dir;
2527
std::vector<std::filesystem::path> include_dirs;

src/libasr/utils2.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,28 @@
44
#endif
55

66
#include <fstream>
7+
#include <filesystem>
8+
#include <random>
79

810
#include <libasr/exception.h>
911
#include <libasr/utils.h>
1012
#include <libasr/string_utils.h>
1113

1214
namespace LCompilers {
1315

16+
std::string get_unique_ID() {
17+
static std::random_device dev;
18+
static std::mt19937 rng(dev());
19+
std::uniform_int_distribution<int> dist(0, 61);
20+
const std::string v =
21+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
22+
std::string res;
23+
for (int i = 0; i < 22; i++) {
24+
res += v[dist(rng)];
25+
}
26+
return res;
27+
}
28+
1429
bool read_file(const std::string &filename, std::string &text)
1530
{
1631
std::ifstream ifs(filename.c_str(), std::ios::in | std::ios::binary

0 commit comments

Comments
 (0)