Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial pass infrastructure #2112

Merged
merged 4 commits into from
Jul 5, 2023
Merged
Changes from 1 commit
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
Next Next commit
Add gen_pass.py
  • Loading branch information
certik committed Jul 5, 2023
commit 865949e663da04f86313e7731551623a09798747
77 changes: 77 additions & 0 deletions src/libasr/gen_pass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
passes = [
# name, optional prefix (pass_PREFIX_name())
("arr_slice", "replace"),
("array_op", "replace"),
("class_constructor", "replace"),
("dead_code_removal", ""),
("div_to_mul", "replace"),
("do_loops", "replace"),
("flip_sign", "replace"),
("fma", "replace"),
("for_all", "replace"),
("global_stmts", "wrap"),
("global_stmts_program", "wrap"),
("global_symbols", "wrap"),
("implied_do_loops", "replace"),
("init_expr", "replace"),
("inline_function_calls", ""),
("instantiate_template", ""),
("intrinsic_function", "replace"),
("loop_unroll", ""),
("loop_vectorise", ""),
("nested_vars", ""),
("param_to_const", "replace"),
("pass_array_by_data", ""),
("pass_compare", ""),
("pass_list_expr", ""),
("print_arr", "replace"),
("print_list_tuple", "replace"),
("print_struct_type", "replace"),
("select_case", "replace"),
("sign_from_value", "replace"),
("subroutine_from_function", "create"),
("transform_optional_argument_functions", ""),
("unused_functions", ""),
("update_array_dim_intrinsic_calls", ""),
("where", "replace"),
]



for pass_name, prefix in passes:
print(f"Processing: {pass_name}")
name = pass_name
if name.startswith("pass"):
name = name[5:]
name_up = name.upper()
if prefix != "":
prefix += "_"
arguments = r"""Allocator &al, ASR::TranslationUnit_t &unit,
const PassOptions &pass_options"""
return_type = "void"
if pass_name == "instantiate_template":
arguments = r"""Allocator &al,
std::map<std::string, ASR::ttype_t*> subs, std::map<std::string, ASR::symbol_t*> rt_subs,
SymbolTable *current_scope, SymbolTable *template_scope,
std::string new_func_name, ASR::symbol_t *sym"""
return_type = "ASR::symbol_t*"



header = rf"""#ifndef LIBASR_PASS_{name_up}_H
#define LIBASR_PASS_{name_up}_H

#include <libasr/asr.h>
#include <libasr/utils.h>

namespace LCompilers {{

{return_type} pass_{prefix}{name}({arguments});

}} // namespace LCompilers

#endif // LIBASR_PASS_{name_up}_H
"""
header_filename = f"pass/{pass_name}.h"
f = open(header_filename, "w")
f.write(header)