[clang-repl] [codegen] Reduce the state in TBAA. NFC for static compilation. (#98138)
[llvm-project.git] / polly / lib / External / isl / libisl-gdb.py
blobbf01bc583d15d8c06791f25a68a3b07f994b5357
1 import gdb
2 import re
4 # GDB Pretty Printers for most isl objects
5 class IslObjectPrinter:
6 """Print an isl object"""
8 def __init__(self, val, type):
9 self.val = val
10 self.type = type
12 def to_string(self):
13 # Cast val to a void pointer to stop gdb using this pretty
14 # printer for the pointer which would lead to an infinite loop.
15 void_ptr = gdb.lookup_type("void").pointer()
16 value = str(self.val.cast(void_ptr))
17 printer = gdb.parse_and_eval(
18 "isl_printer_to_str(isl_" + str(self.type) + "_get_ctx(" + value + "))"
20 printer = gdb.parse_and_eval(
21 "isl_printer_print_"
22 + str(self.type)
23 + "("
24 + str(printer)
25 + ", "
26 + value
27 + ")"
29 string = gdb.parse_and_eval("(char*)isl_printer_get_str(" + str(printer) + ")")
30 gdb.parse_and_eval("isl_printer_free(" + str(printer) + ")")
31 return string
33 def display_hint(self):
34 return "string"
37 class IslIntPrinter:
38 """Print an isl_int"""
40 def __init__(self, val):
41 self.val = val
43 def to_string(self):
44 # Cast val to a void pointer to stop gdb using this pretty
45 # printer for the pointer which would lead to an infinite loop.
46 void_ptr = gdb.lookup_type("void").pointer()
47 value = str(self.val.cast(void_ptr))
49 context = gdb.parse_and_eval("isl_ctx_alloc()")
50 printer = gdb.parse_and_eval("isl_printer_to_str(" + str(context) + ")")
51 printer = gdb.parse_and_eval(
52 "isl_printer_print_isl_int(" + str(printer) + ", " + value + ")"
54 string = gdb.parse_and_eval("(char*)isl_printer_get_str(" + str(printer) + ")")
55 gdb.parse_and_eval("isl_printer_free(" + str(printer) + ")")
56 gdb.parse_and_eval("isl_ctx_free(" + str(context) + ")")
57 return string
59 def display_hint(self):
60 return "string"
63 class IslPrintCommand(gdb.Command):
64 """Print an isl value."""
66 def __init__(self):
67 super(IslPrintCommand, self).__init__("islprint", gdb.COMMAND_OBSCURE)
69 def invoke(self, arg, from_tty):
70 arg = gdb.parse_and_eval(arg)
71 printer = str_lookup_function(arg)
73 if printer == None:
74 print("No isl printer for this type")
75 return
77 print(printer.to_string())
80 IslPrintCommand()
83 def str_lookup_function(val):
84 if val.type.code != gdb.TYPE_CODE_PTR:
85 if str(val.type) == "isl_int":
86 return IslIntPrinter(val)
87 else:
88 return None
90 lookup_tag = val.type.target()
91 regex = re.compile("^isl_(.*)$")
93 if lookup_tag == None:
94 return None
96 m = regex.match(str(lookup_tag))
98 if m:
99 # Those types of printers defined in isl.
100 if m.group(1) in [
101 "basic_set",
102 "set",
103 "union_set",
104 "basic_map",
105 "map",
106 "union_map",
107 "qpolynomial",
108 "pw_qpolynomial",
109 "pw_qpolynomial_fold",
110 "union_pw_qpolynomial",
111 "union_pw_qpolynomial_fold",
113 return IslObjectPrinter(val, m.group(1))
114 return None
117 # Do not register the pretty printer.
118 # gdb.current_objfile().pretty_printers.append(str_lookup_function)