| 1 |
// Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 2 |
|
| 3 |
// This file is part of GCC. |
| 4 |
|
| 5 |
// GCC is free software; you can redistribute it and/or modify it under |
| 6 |
// the terms of the GNU General Public License as published by the Free |
| 7 |
// Software Foundation; either version 3, or (at your option) any later |
| 8 |
// version. |
| 9 |
|
| 10 |
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 |
// for more details. |
| 14 |
|
| 15 |
// You should have received a copy of the GNU General Public License |
| 16 |
// along with GCC; see the file COPYING3. If not see |
| 17 |
// <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
#ifndef RUST_BIR_DUMP_H |
| 20 |
#define RUST_BIR_DUMP_H |
| 21 |
|
| 22 |
#include "rust-system.h" |
| 23 |
#include "rust-bir-place.h" |
| 24 |
#include "rust-bir-visitor.h" |
| 25 |
#include "rust-bir.h" |
| 26 |
|
| 27 |
namespace Rust { |
| 28 |
namespace BIR { |
| 29 |
|
| 30 |
/** Prints the BIR to a stream in a format resembling rustc's MIR. */ |
| 31 |
class Dump : public Visitor |
| 32 |
{ |
| 33 |
std::ostream &stream; |
| 34 |
Function &func; |
| 35 |
const std::string &name; |
| 36 |
|
| 37 |
IndexVec<BasicBlockId, BasicBlockId> bb_fold_map; |
| 38 |
IndexVec<PlaceId, PlaceId> place_map; |
| 39 |
|
| 40 |
PlaceId statement_place = INVALID_PLACE; |
| 41 |
BasicBlockId statement_bb = INVALID_BB; |
| 42 |
bool bb_terminated = false; |
| 43 |
|
| 44 |
public: |
| 45 |
Dump (std::ostream &os, Function &func, const std::string &name) |
| 46 |
: stream (os), func (func), name (name), |
| 47 |
bb_fold_map (func.basic_blocks.size ()), place_map (func.place_db.size ()) |
| 48 |
{} |
| 49 |
void go (bool enable_simplify_cfg = false); |
| 50 |
|
| 51 |
protected: |
| 52 |
void visit (const Statement &stmt) override; |
| 53 |
void visit_place (PlaceId place_id); |
| 54 |
void visit_move_place (PlaceId place_id); |
| 55 |
void visit (const BorrowExpr &expr) override; |
| 56 |
void visit_lifetime (PlaceId place_id); |
| 57 |
void visit (const InitializerExpr &expr) override; |
| 58 |
void visit (const CallExpr &expr) override; |
| 59 |
void visit (const Operator<1> &expr) override; |
| 60 |
void visit (const Operator<2> &expr) override; |
| 61 |
void visit (const Assignment &expr) override; |
| 62 |
void visit_scope (ScopeId id, size_t depth = 1); |
| 63 |
|
| 64 |
std::ostream &indent (size_t depth); |
| 65 |
}; |
| 66 |
|
| 67 |
} // namespace BIR |
| 68 |
} // namespace Rust |
| 69 |
|
| 70 |
#endif // RUST_BIR_DUMP_H |