MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
dbg.h File Reference
#include <absl/container/flat_hash_map.h>
#include <absl/container/flat_hash_set.h>
#include <fe/loc.h>
#include <fe/sym.h>
#include <rang.hpp>
#include "mim/util/print.h"
Include dependency graph for dbg.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  mim::Error
 
struct  mim::Error::Msg
 
struct  mim::Dbg
 

Namespaces

namespace  mim
 

Functions

Formatted Output

Provides a printf-like interface to format s with args and puts it into os.

Use {} as a placeholder within your format string s.

  • By default, os << t will be used to stream the appropriate argument:
    print(os, "int: {}, float: {}", 23, 42.f);
    std::ostream & print(std::ostream &os, const char *s)
    Base case.
    Definition print.cpp:5
  • You can also place a function as argument to inject arbitrary code:
    print(os, "int: {}, fun: {}, float: {}", 23, [&]() { os << "hey :)"}, 42.f);
  • There is also a variant to pass os to the function, if you don't have easy access to it:
    print(os, "int: {}, fun: {}, float: {}", 23, [&](auto& os) { os << "hey :)"}, 42.f);
  • You can put a std::ranges::range as argument. This will output a list - using the given specifier as separator. Each element elem of the range will be output via os << elem:
    std::vector<int> v = {0, 1, 2, 3};
    print(os, "v: {, }", v);
  • If you have a std::ranges::range that needs to be formatted in a more complicated way, bundle it with an Elem:
    std::vector<int> v = {3, 2, 1, 0};
    size_t i = 0;
    print(os, "v: {, }", Elem(v, [&](auto elem) { print(os, "{}: {}", i++, elem); }));
  • You again have the option to pass os to the bundled function:
    std::vector<int> v = {3, 2, 1, 0};
    size_t i = 0;
    print(os, "v: {, }", Elem(v, [&](auto& os, auto elem) { print(os, "{}: {}", i++, elem); }));
    * Use `{{` or `}}` to literally output `{` or `{`:
    print(os, "{{{}}}", 23); // "{23}"
    See also
    Tab
template<class... Args>
void mim::error (Loc loc, const char *f, Args &&... args)