Skip to content

Commit a8dbbc2

Browse files
authored
Merge pull request #2417 from Shaikh-Ubaid/remove_redundant_code
Remove redundant code
2 parents 03d54d2 + 2591cb8 commit a8dbbc2

File tree

6 files changed

+10
-406
lines changed

6 files changed

+10
-406
lines changed

src/bin/lpython.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#define CLI11_HAS_FILESYSTEM 0
77
#include <bin/CLI11.hpp>
88

9-
#include <libasr/stacktrace.h>
109
#include <lpython/pickle.h>
10+
#include <libasr/pickle.h>
11+
#include <libasr/stacktrace.h>
1112
#include <lpython/semantics/python_ast_to_asr.h>
1213
#include <libasr/codegen/asr_to_llvm.h>
1314
#include <libasr/codegen/asr_to_cpp.h>
@@ -221,15 +222,15 @@ int emit_asr(const std::string &infile,
221222
pass_manager.apply_passes(al, asr, compiler_options.po, diagnostics);
222223

223224
if (compiler_options.po.tree) {
224-
std::cout << LCompilers::LPython::pickle_tree(*asr,
225+
std::cout << LCompilers::pickle_tree(*asr,
225226
compiler_options.use_colors, with_intrinsic_modules) << std::endl;
226227
} else if (compiler_options.po.json) {
227-
std::cout << LCompilers::LPython::pickle_json(*asr, lm, with_intrinsic_modules) << std::endl;
228+
std::cout << LCompilers::pickle_json(*asr, lm, false, with_intrinsic_modules) << std::endl;
228229
} else if (compiler_options.po.visualize) {
229-
std::string astr_data_json = LCompilers::LPython::pickle_json(*asr, lm, with_intrinsic_modules);
230+
std::string astr_data_json = LCompilers::pickle_json(*asr, lm, false, with_intrinsic_modules);
230231
return visualize_json(astr_data_json, compiler_options.platform);
231232
} else {
232-
std::cout << LCompilers::LPython::pickle(*asr, compiler_options.use_colors,
233+
std::cout << LCompilers::pickle(*asr, compiler_options.use_colors,
233234
compiler_options.indent, with_intrinsic_modules) << std::endl;
234235
}
235236
return 0;
@@ -1361,7 +1362,7 @@ EMSCRIPTEN_KEEPALIVE char* emit_asr_from_source(char *input) {
13611362
asr = LCompilers::LPython::python_ast_to_asr(al, lm, nullptr, *casted_ast, diagnostics, compiler_options, true, "__main__", "input");
13621363
out = diagnostics.render(lm, compiler_options);
13631364
if (asr.ok) {
1364-
out += LCompilers::LPython::pickle(*asr.result, compiler_options.use_colors, compiler_options.indent,
1365+
out += LCompilers::pickle(*asr.result, compiler_options.use_colors, compiler_options.indent,
13651366
false /* with_intrinsic_modules */);
13661367
}
13671368
}

src/libasr/pickle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ class ASRPickleVisitor :
5252
}
5353
void visit_Module(const ASR::Module_t &x) {
5454
if (!show_intrinsic_modules &&
55-
startswith(x.m_name, "lfortran_intrinsic_")) {
55+
(x.m_intrinsic || startswith(x.m_name, "lfortran_intrinsic_") || startswith(x.m_name, "numpy"))) {
5656
s.append("(");
5757
if (use_colors) {
5858
s.append(color(style::bold));
5959
s.append(color(fg::magenta));
6060
}
61-
s.append("IntrinsicModule");
61+
s.append(x.m_intrinsic ? "IntrinsicModule" : "Module");
6262
if (use_colors) {
6363
s.append(color(fg::reset));
6464
s.append(color(style::reset));

src/lpython/pickle.cpp

Lines changed: 0 additions & 232 deletions
Original file line numberDiff line numberDiff line change
@@ -28,129 +28,6 @@ std::string pickle_python(AST::ast_t &ast, bool colors, bool indent) {
2828
return v.get_str();
2929
}
3030

31-
/********************** ASR Pickle *******************/
32-
class ASRPickleVisitor :
33-
public ASR::PickleBaseVisitor<ASRPickleVisitor>
34-
{
35-
public:
36-
bool show_intrinsic_modules;
37-
38-
std::string get_str() {
39-
return s;
40-
}
41-
void visit_symbol(const ASR::symbol_t &x) {
42-
s.append(ASRUtils::symbol_parent_symtab(&x)->get_counter());
43-
s.append(" ");
44-
if (use_colors) {
45-
s.append(color(fg::yellow));
46-
}
47-
s.append(ASRUtils::symbol_name(&x));
48-
if (use_colors) {
49-
s.append(color(fg::reset));
50-
}
51-
}
52-
void visit_IntegerConstant(const ASR::IntegerConstant_t &x) {
53-
s.append("(");
54-
if (use_colors) {
55-
s.append(color(style::bold));
56-
s.append(color(fg::magenta));
57-
}
58-
s.append("IntegerConstant");
59-
if (use_colors) {
60-
s.append(color(fg::reset));
61-
s.append(color(style::reset));
62-
}
63-
s.append(" ");
64-
if (use_colors) {
65-
s.append(color(fg::cyan));
66-
}
67-
s.append(std::to_string(x.m_n));
68-
if (use_colors) {
69-
s.append(color(fg::reset));
70-
}
71-
s.append(" ");
72-
this->visit_ttype(*x.m_type);
73-
s.append(")");
74-
}
75-
void visit_Module(const ASR::Module_t &x) {
76-
// hide intrinsic modules and numpy module by default
77-
if (!show_intrinsic_modules &&
78-
(x.m_intrinsic || startswith(x.m_name, "numpy"))) {
79-
s.append("(");
80-
if (use_colors) {
81-
s.append(color(style::bold));
82-
s.append(color(fg::magenta));
83-
}
84-
s.append(x.m_intrinsic ? "IntrinsicModule" : "Module");
85-
if (use_colors) {
86-
s.append(color(fg::reset));
87-
s.append(color(style::reset));
88-
}
89-
s.append(" ");
90-
s.append(x.m_name);
91-
s.append(")");
92-
} else {
93-
ASR::PickleBaseVisitor<ASRPickleVisitor>::visit_Module(x);
94-
};
95-
}
96-
97-
std::string convert_intrinsic_id(int x) {
98-
std::string s;
99-
if (use_colors) {
100-
s.append(color(style::bold));
101-
s.append(color(fg::green));
102-
}
103-
s.append(ASRUtils::get_intrinsic_name(x));
104-
if (use_colors) {
105-
s.append(color(fg::reset));
106-
s.append(color(style::reset));
107-
}
108-
return s;
109-
}
110-
111-
std::string convert_impure_intrinsic_id(int x) {
112-
std::string s;
113-
if (use_colors) {
114-
s.append(color(style::bold));
115-
s.append(color(fg::green));
116-
}
117-
s.append(ASRUtils::get_impure_intrinsic_name(x));
118-
if (use_colors) {
119-
s.append(color(fg::reset));
120-
s.append(color(style::reset));
121-
}
122-
return s;
123-
}
124-
125-
std::string convert_array_intrinsic_id(int x) {
126-
std::string s;
127-
if (use_colors) {
128-
s.append(color(style::bold));
129-
s.append(color(fg::green));
130-
}
131-
s.append(ASRUtils::get_array_intrinsic_name(x));
132-
if (use_colors) {
133-
s.append(color(fg::reset));
134-
s.append(color(style::reset));
135-
}
136-
return s;
137-
}
138-
};
139-
140-
std::string pickle(ASR::asr_t &asr, bool colors, bool indent,
141-
bool show_intrinsic_modules) {
142-
ASRPickleVisitor v;
143-
v.use_colors = colors;
144-
v.indent = indent;
145-
v.show_intrinsic_modules = show_intrinsic_modules;
146-
v.visit_asr(asr);
147-
return v.get_str();
148-
}
149-
150-
std::string pickle(ASR::TranslationUnit_t &asr, bool colors, bool indent, bool show_intrinsic_modules) {
151-
return pickle((ASR::asr_t &)asr, colors, indent, show_intrinsic_modules);
152-
}
153-
15431
/********************** AST Pickle Tree *******************/
15532
class ASTTreeVisitor : public AST::TreeBaseVisitor<ASTTreeVisitor>
15633
{
@@ -167,31 +44,6 @@ std::string pickle_tree_python(AST::ast_t &ast, bool colors) {
16744
return v.get_str();
16845
}
16946

170-
/********************** ASR Pickle Tree *******************/
171-
class ASRTreeVisitor :
172-
public ASR::TreeBaseVisitor<ASRTreeVisitor>
173-
{
174-
public:
175-
bool show_intrinsic_modules;
176-
177-
std::string get_str() {
178-
return s;
179-
}
180-
181-
};
182-
183-
std::string pickle_tree(ASR::asr_t &asr, bool colors, bool show_intrinsic_modules) {
184-
ASRTreeVisitor v;
185-
v.use_colors = colors;
186-
v.show_intrinsic_modules = show_intrinsic_modules;
187-
v.visit_asr(asr);
188-
return v.get_str();
189-
}
190-
191-
std::string pickle_tree(ASR::TranslationUnit_t &asr, bool colors, bool show_intrinsic_modules) {
192-
return pickle_tree((ASR::asr_t &)asr, colors, show_intrinsic_modules);
193-
}
194-
19547
/********************** AST Pickle Json *******************/
19648
class ASTJsonVisitor :
19749
public LPython::AST::JsonBaseVisitor<ASTJsonVisitor>
@@ -210,88 +62,4 @@ std::string pickle_json(LPython::AST::ast_t &ast, LocationManager &lm) {
21062
return v.get_str();
21163
}
21264

213-
/********************** ASR Pickle Json *******************/
214-
class ASRJsonVisitor :
215-
public ASR::JsonBaseVisitor<ASRJsonVisitor>
216-
{
217-
public:
218-
bool show_intrinsic_modules;
219-
220-
using ASR::JsonBaseVisitor<ASRJsonVisitor>::JsonBaseVisitor;
221-
222-
std::string get_str() {
223-
return s;
224-
}
225-
226-
void visit_symbol(const ASR::symbol_t &x) {
227-
s.append("\"");
228-
s.append(ASRUtils::symbol_name(&x));
229-
s.append(" (SymbolTable");
230-
s.append(ASRUtils::symbol_parent_symtab(&x)->get_counter());
231-
s.append(")\"");
232-
}
233-
234-
void visit_Module(const ASR::Module_t &x) {
235-
// hide intrinsic modules and numpy module by default
236-
if (!show_intrinsic_modules &&
237-
(x.m_intrinsic || startswith(x.m_name, "numpy"))) {
238-
s.append("{");
239-
inc_indent(); s.append("\n" + indtd);
240-
s.append("\"node\": \"Module\"");
241-
s.append(",\n" + indtd);
242-
s.append("\"fields\": {");
243-
inc_indent(); s.append("\n" + indtd);
244-
s.append("\"name\": ");
245-
s.append("\"" + std::string(x.m_name) + "\"");
246-
s.append(",\n" + indtd);
247-
s.append("\"dependencies\": ");
248-
s.append("[");
249-
if (x.n_dependencies > 0) {
250-
inc_indent(); s.append("\n" + indtd);
251-
for (size_t i=0; i<x.n_dependencies; i++) {
252-
s.append("\"" + std::string(x.m_dependencies[i]) + "\"");
253-
if (i < x.n_dependencies-1) {
254-
s.append(",\n" + indtd);
255-
};
256-
}
257-
dec_indent(); s.append("\n" + indtd);
258-
}
259-
s.append("]");
260-
s.append(",\n" + indtd);
261-
s.append("\"loaded_from_mod\": ");
262-
if (x.m_loaded_from_mod) {
263-
s.append("true");
264-
} else {
265-
s.append("false");
266-
}
267-
s.append(",\n" + indtd);
268-
s.append("\"intrinsic\": ");
269-
if (x.m_intrinsic) {
270-
s.append("true");
271-
} else {
272-
s.append("false");
273-
}
274-
dec_indent(); s.append("\n" + indtd);
275-
s.append("}");
276-
s.append(",\n" + indtd);
277-
append_location(s, x.base.base.loc.first, x.base.base.loc.last);
278-
dec_indent(); s.append("\n" + indtd);
279-
s.append("}");
280-
} else {
281-
ASR::JsonBaseVisitor<ASRJsonVisitor>::visit_Module(x);
282-
}
283-
}
284-
};
285-
286-
std::string pickle_json(ASR::asr_t &asr, LocationManager &lm, bool show_intrinsic_modules) {
287-
ASRJsonVisitor v(lm);
288-
v.show_intrinsic_modules = show_intrinsic_modules;
289-
v.visit_asr(asr);
290-
return v.get_str();
291-
}
292-
293-
std::string pickle_json(ASR::TranslationUnit_t &asr, LocationManager &lm, bool show_intrinsic_modules) {
294-
return pickle_json((ASR::asr_t &)asr, lm, show_intrinsic_modules);
295-
}
296-
29765
}

src/lpython/pickle.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,12 @@ namespace LCompilers::LPython {
99

1010
// Pickle an ASR node
1111
std::string pickle_python(AST::ast_t &ast, bool colors=false, bool indent=false);
12-
std::string pickle(ASR::asr_t &asr, bool colors=false, bool indent=false,
13-
bool show_intrinsic_modules=false);
14-
std::string pickle(ASR::TranslationUnit_t &asr, bool colors=false,
15-
bool indent=false, bool show_intrinsic_modules=false);
1612

1713
// Print the tree structure
1814
std::string pickle_tree_python(AST::ast_t &ast, bool colors=true);
19-
std::string pickle_tree(ASR::asr_t &asr, bool colors, bool show_intrinsic_modules);
20-
std::string pickle_tree(ASR::TranslationUnit_t &asr, bool colors, bool show_intrinsic_modules);
2115

16+
// Print the ASR in json format
2217
std::string pickle_json(AST::ast_t &ast, LocationManager &lm);
23-
std::string pickle_json(ASR::asr_t &asr, LocationManager &lm, bool show_intrinsic_modules);
24-
std::string pickle_json(ASR::TranslationUnit_t &asr, LocationManager &lm, bool show_intrinsic_modules);
25-
2618
}
2719

2820
#endif // LFORTRAN_PICKLE_H

0 commit comments

Comments
 (0)