Skip to content

Commit 865949e

Browse files
committed
Add gen_pass.py
1 parent de44dbf commit 865949e

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

src/libasr/gen_pass.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
passes = [
2+
# name, optional prefix (pass_PREFIX_name())
3+
("arr_slice", "replace"),
4+
("array_op", "replace"),
5+
("class_constructor", "replace"),
6+
("dead_code_removal", ""),
7+
("div_to_mul", "replace"),
8+
("do_loops", "replace"),
9+
("flip_sign", "replace"),
10+
("fma", "replace"),
11+
("for_all", "replace"),
12+
("global_stmts", "wrap"),
13+
("global_stmts_program", "wrap"),
14+
("global_symbols", "wrap"),
15+
("implied_do_loops", "replace"),
16+
("init_expr", "replace"),
17+
("inline_function_calls", ""),
18+
("instantiate_template", ""),
19+
("intrinsic_function", "replace"),
20+
("loop_unroll", ""),
21+
("loop_vectorise", ""),
22+
("nested_vars", ""),
23+
("param_to_const", "replace"),
24+
("pass_array_by_data", ""),
25+
("pass_compare", ""),
26+
("pass_list_expr", ""),
27+
("print_arr", "replace"),
28+
("print_list_tuple", "replace"),
29+
("print_struct_type", "replace"),
30+
("select_case", "replace"),
31+
("sign_from_value", "replace"),
32+
("subroutine_from_function", "create"),
33+
("transform_optional_argument_functions", ""),
34+
("unused_functions", ""),
35+
("update_array_dim_intrinsic_calls", ""),
36+
("where", "replace"),
37+
]
38+
39+
40+
41+
for pass_name, prefix in passes:
42+
print(f"Processing: {pass_name}")
43+
name = pass_name
44+
if name.startswith("pass"):
45+
name = name[5:]
46+
name_up = name.upper()
47+
if prefix != "":
48+
prefix += "_"
49+
arguments = r"""Allocator &al, ASR::TranslationUnit_t &unit,
50+
const PassOptions &pass_options"""
51+
return_type = "void"
52+
if pass_name == "instantiate_template":
53+
arguments = r"""Allocator &al,
54+
std::map<std::string, ASR::ttype_t*> subs, std::map<std::string, ASR::symbol_t*> rt_subs,
55+
SymbolTable *current_scope, SymbolTable *template_scope,
56+
std::string new_func_name, ASR::symbol_t *sym"""
57+
return_type = "ASR::symbol_t*"
58+
59+
60+
61+
header = rf"""#ifndef LIBASR_PASS_{name_up}_H
62+
#define LIBASR_PASS_{name_up}_H
63+
64+
#include <libasr/asr.h>
65+
#include <libasr/utils.h>
66+
67+
namespace LCompilers {{
68+
69+
{return_type} pass_{prefix}{name}({arguments});
70+
71+
}} // namespace LCompilers
72+
73+
#endif // LIBASR_PASS_{name_up}_H
74+
"""
75+
header_filename = f"pass/{pass_name}.h"
76+
f = open(header_filename, "w")
77+
f.write(header)

0 commit comments

Comments
 (0)