From e18997dbec2532fa7479a3afb1d39c3d18628343 Mon Sep 17 00:00:00 2001 From: advik Date: Wed, 6 Mar 2024 06:28:36 +0530 Subject: [PATCH] Refactored initial setup --- src/libasr/codegen/asr_to_llvm.cpp | 8 ++++---- src/libasr/runtime/lfortran_intrinsics.c | 7 +++++++ src/libasr/runtime/lfortran_intrinsics.h | 1 + tests/reference/llvm-assert1-8df4f31.json | 2 +- tests/reference/llvm-assert1-8df4f31.stdout | 4 ++-- tests/reference/llvm-bindc_01-c984f09.json | 2 +- tests/reference/llvm-bindc_01-c984f09.stdout | 4 ++-- tests/reference/llvm-bool1-af4376b.json | 2 +- tests/reference/llvm-bool1-af4376b.stdout | 4 ++-- tests/reference/llvm-expr14-b96b5b1.json | 2 +- tests/reference/llvm-expr14-b96b5b1.stdout | 4 ++-- tests/reference/llvm-expr_01-54467c1.json | 2 +- tests/reference/llvm-expr_01-54467c1.stdout | 4 ++-- tests/reference/llvm-func_inline_01-2d4583a.json | 2 +- tests/reference/llvm-func_inline_01-2d4583a.stdout | 4 ++-- tests/reference/llvm-lpython1-23c5987.json | 2 +- tests/reference/llvm-lpython1-23c5987.stdout | 4 ++-- tests/reference/llvm-print_04-443a8d8.json | 2 +- tests/reference/llvm-print_04-443a8d8.stdout | 4 ++-- tests/reference/llvm-structs_11-09fea6a.json | 2 +- tests/reference/llvm-structs_11-09fea6a.stdout | 4 ++-- tests/reference/llvm-test_issue_518-cdb641a.json | 2 +- tests/reference/llvm-test_issue_518-cdb641a.stdout | 4 ++-- tests/reference/llvm-test_unary_op_03-046fb86.json | 2 +- tests/reference/llvm-test_unary_op_03-046fb86.stdout | 4 ++-- tests/reference/llvm_dbg-expr_01-9fc5f30.json | 2 +- tests/reference/llvm_dbg-expr_01-9fc5f30.stdout | 4 ++-- 27 files changed, 48 insertions(+), 40 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index d5af2946f7..b347fcf865 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -3026,11 +3026,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } builder->SetInsertPoint(BB); - // Call the `_lpython_set_argv` function to assign command line argument - // values to `argc` and `argv`. + // Call the `_lpython_call_initial_functions` function to assign command line argument + // values to `argc` and `argv`, and set the random seed to the system clock. { if (compiler_options.emit_debug_info) debug_emit_loc(x); - llvm::Function *fn = module->getFunction("_lpython_set_argv"); + llvm::Function *fn = module->getFunction("_lpython_call_initial_functions"); if(!fn) { llvm::FunctionType *function_type = llvm::FunctionType::get( llvm::Type::getVoidTy(context), { @@ -3038,7 +3038,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor character_type->getPointerTo() }, false); fn = llvm::Function::Create(function_type, - llvm::Function::ExternalLinkage, "_lpython_set_argv", *module); + llvm::Function::ExternalLinkage, "_lpython_call_initial_functions", *module); } std::vector args; for (llvm::Argument &llvm_arg : F->args()) { diff --git a/src/libasr/runtime/lfortran_intrinsics.c b/src/libasr/runtime/lfortran_intrinsics.c index a5c506edb3..06f7bc20f1 100644 --- a/src/libasr/runtime/lfortran_intrinsics.c +++ b/src/libasr/runtime/lfortran_intrinsics.c @@ -2545,6 +2545,13 @@ LFORTRAN_API char *_lpython_get_argv(int32_t index) { // << Command line arguments << ------------------------------------------------ +// Initial setup +LFORTRAN_API void _lpython_call_initial_functions(int32_t argc_1, char *argv_1[]) { + _lpython_set_argv(argc_1, argv_1); + _lfortran_init_random_clock(); +} +// << Initial setup << --------------------------------------------------------- + // >> Runtime Stacktrace >> ---------------------------------------------------- #ifdef HAVE_RUNTIME_STACKTRACE #ifdef HAVE_LFORTRAN_UNWIND diff --git a/src/libasr/runtime/lfortran_intrinsics.h b/src/libasr/runtime/lfortran_intrinsics.h index 7efaa10b85..7d25667eab 100644 --- a/src/libasr/runtime/lfortran_intrinsics.h +++ b/src/libasr/runtime/lfortran_intrinsics.h @@ -277,6 +277,7 @@ LFORTRAN_API int32_t _lfortran_all(bool *mask, int32_t n); LFORTRAN_API void _lpython_set_argv(int32_t argc_1, char *argv_1[]); LFORTRAN_API int32_t _lpython_get_argc(); LFORTRAN_API char *_lpython_get_argv(int32_t index); +LFORTRAN_API void _lpython_call_initial_functions(int32_t argc_1, char *argv_1[]); LFORTRAN_API void print_stacktrace_addresses(char *filename, bool use_colors); LFORTRAN_API char *_lfortran_get_env_variable(char *name); LFORTRAN_API int _lfortran_exec_command(char *cmd); diff --git a/tests/reference/llvm-assert1-8df4f31.json b/tests/reference/llvm-assert1-8df4f31.json index f7af1f27c3..d280f55589 100644 --- a/tests/reference/llvm-assert1-8df4f31.json +++ b/tests/reference/llvm-assert1-8df4f31.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-assert1-8df4f31.stdout", - "stdout_hash": "15764832892f7e0cd2a438b247a148564f5f83b3a00ca929bd9cc625", + "stdout_hash": "de8886bdb5b86970a042b8ee00f309cf6bcf9e3e192cb4875ab3b2b0", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-assert1-8df4f31.stdout b/tests/reference/llvm-assert1-8df4f31.stdout index 084a225695..494dc5c091 100644 --- a/tests/reference/llvm-assert1-8df4f31.stdout +++ b/tests/reference/llvm-assert1-8df4f31.stdout @@ -3,8 +3,8 @@ source_filename = "LFortran" define i32 @main(i32 %0, i8** %1) { .entry: - call void @_lpython_set_argv(i32 %0, i8** %1) + call void @_lpython_call_initial_functions(i32 %0, i8** %1) ret i32 0 } -declare void @_lpython_set_argv(i32, i8**) +declare void @_lpython_call_initial_functions(i32, i8**) diff --git a/tests/reference/llvm-bindc_01-c984f09.json b/tests/reference/llvm-bindc_01-c984f09.json index b8bf60feb9..d49cc35592 100644 --- a/tests/reference/llvm-bindc_01-c984f09.json +++ b/tests/reference/llvm-bindc_01-c984f09.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-bindc_01-c984f09.stdout", - "stdout_hash": "36302aceabcf2682f3e954ab4bc56dd960fe532dc7799cb58baa19a3", + "stdout_hash": "054106835033c19d6d0b10c264d915a4d4b11fee2a70abd6d66bade3", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-bindc_01-c984f09.stdout b/tests/reference/llvm-bindc_01-c984f09.stdout index 16f056eec7..f5c2dbbbe4 100644 --- a/tests/reference/llvm-bindc_01-c984f09.stdout +++ b/tests/reference/llvm-bindc_01-c984f09.stdout @@ -73,9 +73,9 @@ declare void @exit(i32) define i32 @main(i32 %0, i8** %1) { .entry: - call void @_lpython_set_argv(i32 %0, i8** %1) + call void @_lpython_call_initial_functions(i32 %0, i8** %1) call void @__module___main_____main__global_stmts() ret i32 0 } -declare void @_lpython_set_argv(i32, i8**) +declare void @_lpython_call_initial_functions(i32, i8**) diff --git a/tests/reference/llvm-bool1-af4376b.json b/tests/reference/llvm-bool1-af4376b.json index 8a924e4972..446f579e9f 100644 --- a/tests/reference/llvm-bool1-af4376b.json +++ b/tests/reference/llvm-bool1-af4376b.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-bool1-af4376b.stdout", - "stdout_hash": "cb60cdc2beb220bbe693b54079b5ebc7efcdc2cdc830c3cc0e213c39", + "stdout_hash": "7c68133cc3f970d6eddca6cf982fb405b5a1c8014ef5aa916ea38cf6", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-bool1-af4376b.stdout b/tests/reference/llvm-bool1-af4376b.stdout index 67423eab3e..630d17250f 100644 --- a/tests/reference/llvm-bool1-af4376b.stdout +++ b/tests/reference/llvm-bool1-af4376b.stdout @@ -56,9 +56,9 @@ declare void @_lfortran_printf(i8*, ...) define i32 @main(i32 %0, i8** %1) { .entry: - call void @_lpython_set_argv(i32 %0, i8** %1) + call void @_lpython_call_initial_functions(i32 %0, i8** %1) call void @__module___main_____main__global_stmts() ret i32 0 } -declare void @_lpython_set_argv(i32, i8**) +declare void @_lpython_call_initial_functions(i32, i8**) diff --git a/tests/reference/llvm-expr14-b96b5b1.json b/tests/reference/llvm-expr14-b96b5b1.json index a3c6d2f1be..f94838f361 100644 --- a/tests/reference/llvm-expr14-b96b5b1.json +++ b/tests/reference/llvm-expr14-b96b5b1.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-expr14-b96b5b1.stdout", - "stdout_hash": "15764832892f7e0cd2a438b247a148564f5f83b3a00ca929bd9cc625", + "stdout_hash": "de8886bdb5b86970a042b8ee00f309cf6bcf9e3e192cb4875ab3b2b0", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-expr14-b96b5b1.stdout b/tests/reference/llvm-expr14-b96b5b1.stdout index 084a225695..494dc5c091 100644 --- a/tests/reference/llvm-expr14-b96b5b1.stdout +++ b/tests/reference/llvm-expr14-b96b5b1.stdout @@ -3,8 +3,8 @@ source_filename = "LFortran" define i32 @main(i32 %0, i8** %1) { .entry: - call void @_lpython_set_argv(i32 %0, i8** %1) + call void @_lpython_call_initial_functions(i32 %0, i8** %1) ret i32 0 } -declare void @_lpython_set_argv(i32, i8**) +declare void @_lpython_call_initial_functions(i32, i8**) diff --git a/tests/reference/llvm-expr_01-54467c1.json b/tests/reference/llvm-expr_01-54467c1.json index f3c32d129d..2c12ec9785 100644 --- a/tests/reference/llvm-expr_01-54467c1.json +++ b/tests/reference/llvm-expr_01-54467c1.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-expr_01-54467c1.stdout", - "stdout_hash": "8018bddb16bb05f28f77e84b0c4bb63a5515c75d5fee087543a243b5", + "stdout_hash": "951a792984bf209b37aafc95435eb319906b5c9cb22a62a018556f06", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-expr_01-54467c1.stdout b/tests/reference/llvm-expr_01-54467c1.stdout index 1eb63578bf..e4b4598e72 100644 --- a/tests/reference/llvm-expr_01-54467c1.stdout +++ b/tests/reference/llvm-expr_01-54467c1.stdout @@ -33,9 +33,9 @@ declare void @_lfortran_printf(i8*, ...) define i32 @main(i32 %0, i8** %1) { .entry: - call void @_lpython_set_argv(i32 %0, i8** %1) + call void @_lpython_call_initial_functions(i32 %0, i8** %1) call void @__module___main_____main__global_stmts() ret i32 0 } -declare void @_lpython_set_argv(i32, i8**) +declare void @_lpython_call_initial_functions(i32, i8**) diff --git a/tests/reference/llvm-func_inline_01-2d4583a.json b/tests/reference/llvm-func_inline_01-2d4583a.json index 075a1dfc5f..60381a81be 100644 --- a/tests/reference/llvm-func_inline_01-2d4583a.json +++ b/tests/reference/llvm-func_inline_01-2d4583a.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-func_inline_01-2d4583a.stdout", - "stdout_hash": "a91f2155136dbc019a41e5b1006d9b4a9e1f7def08086e307aafd15c", + "stdout_hash": "3d0670fb3a5502d046ad0acaa0b5d0f06cd05285df45bef0eca0b626", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-func_inline_01-2d4583a.stdout b/tests/reference/llvm-func_inline_01-2d4583a.stdout index ec43646d47..9c38b8e90a 100644 --- a/tests/reference/llvm-func_inline_01-2d4583a.stdout +++ b/tests/reference/llvm-func_inline_01-2d4583a.stdout @@ -92,9 +92,9 @@ declare void @exit(i32) define i32 @main(i32 %0, i8** %1) { .entry: - call void @_lpython_set_argv(i32 %0, i8** %1) + call void @_lpython_call_initial_functions(i32 %0, i8** %1) call void @__module___main_____main__global_stmts() ret i32 0 } -declare void @_lpython_set_argv(i32, i8**) +declare void @_lpython_call_initial_functions(i32, i8**) diff --git a/tests/reference/llvm-lpython1-23c5987.json b/tests/reference/llvm-lpython1-23c5987.json index 326c58af5a..f1aa41324a 100644 --- a/tests/reference/llvm-lpython1-23c5987.json +++ b/tests/reference/llvm-lpython1-23c5987.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-lpython1-23c5987.stdout", - "stdout_hash": "15764832892f7e0cd2a438b247a148564f5f83b3a00ca929bd9cc625", + "stdout_hash": "de8886bdb5b86970a042b8ee00f309cf6bcf9e3e192cb4875ab3b2b0", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-lpython1-23c5987.stdout b/tests/reference/llvm-lpython1-23c5987.stdout index 084a225695..494dc5c091 100644 --- a/tests/reference/llvm-lpython1-23c5987.stdout +++ b/tests/reference/llvm-lpython1-23c5987.stdout @@ -3,8 +3,8 @@ source_filename = "LFortran" define i32 @main(i32 %0, i8** %1) { .entry: - call void @_lpython_set_argv(i32 %0, i8** %1) + call void @_lpython_call_initial_functions(i32 %0, i8** %1) ret i32 0 } -declare void @_lpython_set_argv(i32, i8**) +declare void @_lpython_call_initial_functions(i32, i8**) diff --git a/tests/reference/llvm-print_04-443a8d8.json b/tests/reference/llvm-print_04-443a8d8.json index 6edad74b2a..d2d3439fea 100644 --- a/tests/reference/llvm-print_04-443a8d8.json +++ b/tests/reference/llvm-print_04-443a8d8.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-print_04-443a8d8.stdout", - "stdout_hash": "5fd7d7df606b54cd4d8304825a94448d366762055fdc5de73c61738c", + "stdout_hash": "95087a18862e89fbe34c93a49eef3683bc027bf02c47d41c27b9bc46", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-print_04-443a8d8.stdout b/tests/reference/llvm-print_04-443a8d8.stdout index 520f8a3d65..b56c7c7bdd 100644 --- a/tests/reference/llvm-print_04-443a8d8.stdout +++ b/tests/reference/llvm-print_04-443a8d8.stdout @@ -38,9 +38,9 @@ declare void @_lfortran_printf(i8*, ...) define i32 @main(i32 %0, i8** %1) { .entry: - call void @_lpython_set_argv(i32 %0, i8** %1) + call void @_lpython_call_initial_functions(i32 %0, i8** %1) call void @__module___main_____main__global_stmts() ret i32 0 } -declare void @_lpython_set_argv(i32, i8**) +declare void @_lpython_call_initial_functions(i32, i8**) diff --git a/tests/reference/llvm-structs_11-09fea6a.json b/tests/reference/llvm-structs_11-09fea6a.json index 861941353b..88e4e9adba 100644 --- a/tests/reference/llvm-structs_11-09fea6a.json +++ b/tests/reference/llvm-structs_11-09fea6a.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-structs_11-09fea6a.stdout", - "stdout_hash": "c6cdeacf6cdb7b9a5e68d2263a28585e68ec51e11f544fd366eac428", + "stdout_hash": "b1de8efeefa8bb2d76ce4fcb13e049cd550cb2242189bec5d0003b80", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-structs_11-09fea6a.stdout b/tests/reference/llvm-structs_11-09fea6a.stdout index c72ba9709d..bc78d40bab 100644 --- a/tests/reference/llvm-structs_11-09fea6a.stdout +++ b/tests/reference/llvm-structs_11-09fea6a.stdout @@ -36,10 +36,10 @@ declare void @_lfortran_printf(i8*, ...) define i32 @main(i32 %0, i8** %1) { .entry: - call void @_lpython_set_argv(i32 %0, i8** %1) + call void @_lpython_call_initial_functions(i32 %0, i8** %1) call void @__module___main_____main__global_init() call void @__module___main_____main__global_stmts() ret i32 0 } -declare void @_lpython_set_argv(i32, i8**) +declare void @_lpython_call_initial_functions(i32, i8**) diff --git a/tests/reference/llvm-test_issue_518-cdb641a.json b/tests/reference/llvm-test_issue_518-cdb641a.json index e11cc83f6d..574d643253 100644 --- a/tests/reference/llvm-test_issue_518-cdb641a.json +++ b/tests/reference/llvm-test_issue_518-cdb641a.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-test_issue_518-cdb641a.stdout", - "stdout_hash": "61bea2762ce630ed6295649a1653e608a77cc1165f7575d28fdfefd1", + "stdout_hash": "923730d85df2dd4d88987ee03b085cc9035929493898dc8c99409dc6", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-test_issue_518-cdb641a.stdout b/tests/reference/llvm-test_issue_518-cdb641a.stdout index 00236ee26f..699d365c17 100644 --- a/tests/reference/llvm-test_issue_518-cdb641a.stdout +++ b/tests/reference/llvm-test_issue_518-cdb641a.stdout @@ -113,9 +113,9 @@ declare void @exit(i32) define i32 @main(i32 %0, i8** %1) { .entry: - call void @_lpython_set_argv(i32 %0, i8** %1) + call void @_lpython_call_initial_functions(i32 %0, i8** %1) call void @__module___main_____main__global_stmts() ret i32 0 } -declare void @_lpython_set_argv(i32, i8**) +declare void @_lpython_call_initial_functions(i32, i8**) diff --git a/tests/reference/llvm-test_unary_op_03-046fb86.json b/tests/reference/llvm-test_unary_op_03-046fb86.json index d6390dde20..800d513680 100644 --- a/tests/reference/llvm-test_unary_op_03-046fb86.json +++ b/tests/reference/llvm-test_unary_op_03-046fb86.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-test_unary_op_03-046fb86.stdout", - "stdout_hash": "1e9e596b5383d76430007e2e89893f64e5b07c21d46edeea5bd5acba", + "stdout_hash": "8ae64ade26bcceb59c961b87142054ab443d47b4467569b01d9d24f9", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-test_unary_op_03-046fb86.stdout b/tests/reference/llvm-test_unary_op_03-046fb86.stdout index f460174a28..7774aa0a9a 100644 --- a/tests/reference/llvm-test_unary_op_03-046fb86.stdout +++ b/tests/reference/llvm-test_unary_op_03-046fb86.stdout @@ -61,9 +61,9 @@ declare void @exit(i32) define i32 @main(i32 %0, i8** %1) { .entry: - call void @_lpython_set_argv(i32 %0, i8** %1) + call void @_lpython_call_initial_functions(i32 %0, i8** %1) call void @__module___main_____main__global_stmts() ret i32 0 } -declare void @_lpython_set_argv(i32, i8**) +declare void @_lpython_call_initial_functions(i32, i8**) diff --git a/tests/reference/llvm_dbg-expr_01-9fc5f30.json b/tests/reference/llvm_dbg-expr_01-9fc5f30.json index c139101c1d..649301a2b9 100644 --- a/tests/reference/llvm_dbg-expr_01-9fc5f30.json +++ b/tests/reference/llvm_dbg-expr_01-9fc5f30.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm_dbg-expr_01-9fc5f30.stdout", - "stdout_hash": "f5424d14e2553fd4ea59a66c0d1560e435f0871cdfc5250f6a5df57d", + "stdout_hash": "70643017f0ad204393988f111369cdd921c1c297149078182707cb54", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm_dbg-expr_01-9fc5f30.stdout b/tests/reference/llvm_dbg-expr_01-9fc5f30.stdout index c942af4f3a..405da5aad9 100644 --- a/tests/reference/llvm_dbg-expr_01-9fc5f30.stdout +++ b/tests/reference/llvm_dbg-expr_01-9fc5f30.stdout @@ -40,12 +40,12 @@ declare void @_lfortran_printf(i8*, ...) define i32 @main(i32 %0, i8** %1) !dbg !22 { .entry: - call void @_lpython_set_argv(i32 %0, i8** %1), !dbg !25 + call void @_lpython_call_initial_functions(i32 %0, i8** %1), !dbg !25 call void @__module___main_____main__global_stmts(), !dbg !25 ret i32 0, !dbg !25 } -declare void @_lpython_set_argv(i32, i8**) +declare void @_lpython_call_initial_functions(i32, i8**) attributes #0 = { nounwind readnone speculatable willreturn }