Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions src/bin/lpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#endif

extern std::string lcompilers_unique_ID;

namespace {

using LCompilers::endswith;
Expand All @@ -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;
Expand Down Expand Up @@ -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 ) {
Expand Down
2 changes: 2 additions & 0 deletions src/libasr/asr_scopes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <libasr/asr_scopes.h>
#include <libasr/asr_utils.h>

std::string lcompilers_unique_ID;

namespace LCompilers {

template< typename T >
Expand Down
2 changes: 2 additions & 0 deletions src/libasr/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::filesystem::path> include_dirs;
Expand Down
15 changes: 15 additions & 0 deletions src/libasr/utils2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,28 @@
#endif

#include <fstream>
#include <filesystem>
#include <random>

#include <libasr/exception.h>
#include <libasr/utils.h>
#include <libasr/string_utils.h>

namespace LCompilers {

std::string get_unique_ID() {
static std::random_device dev;
static std::mt19937 rng(dev());
std::uniform_int_distribution<int> 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
Expand Down