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

How to get AST with pretty dump before simplify #574

Open
CanftIn opened this issue Aug 4, 2024 · 0 comments
Open

How to get AST with pretty dump before simplify #574

CanftIn opened this issue Aug 4, 2024 · 0 comments

Comments

@CanftIn
Copy link

CanftIn commented Aug 4, 2024

When i debug for frontend infra of codon, i found there is no existing api to dump the raw AST like that SimplifyVisitor can dump a S-expr string. The api like this code comment, or is a better method to dump to a "_dump_ast.sexp"? So there will be intuitively to diff raw ast with simplify ast.

ast::StmtPtr codeStmt = isCode
                            ? ast::parseCode(cache.get(), abspath, code, startLine)
                            : ast::parseFile(cache.get(), abspath);

///
// api like: codeStmt->dump();
// or:       ast::SomeVisitor::apply(std::move(codeStmt));
///


cache->module0 = file;

Timer t2("simplify");
t2.logged = true;
auto transformed =
    ast::SimplifyVisitor::apply(cache.get(), std::move(codeStmt), abspath, defines,
                                getEarlyDefines(), (testFlags > 1));
LOG_TIME("[T] parse = {:.1f}", totalPeg);
LOG_TIME("[T] simplify = {:.1f}", t2.elapsed() - totalPeg);

if (codon::getLogger().flags & codon::Logger::FLAG_USER) {
  auto fo = fopen("_dump_simplify.sexp", "w");
  fmt::print(fo, "{}\n", transformed->toString(0));
  fclose(fo);
}

And i noticed if i dump a test python file to codon simplify sexp or cir, it would load all sexpr/cir produced by stdlib, and it would cause to produce a large ir file with more information that does not need attention for the moment. Is there a way to avoid this? thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant