[AMDGPU] Test codegen'ing True16 additions.
[llvm-project.git] / polly / lib / External / isl / interface / cpp_conversion.cc
blob58294d54800b06fe5e77055e53bc0e0bda218125
1 /*
2 * Copyright 2018 Sven Verdoolaege
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege.
7 */
9 #include <stdio.h>
10 #include <map>
11 #include <string>
13 #include "cpp.h"
14 #include "cpp_conversion.h"
16 /* If "clazz" describes a subclass of a C type, then print code
17 * for converting an object of the class derived from the C type
18 * to the subclass. Do this by first converting this class
19 * to the immediate superclass of the subclass and then converting
20 * from this superclass to the subclass.
22 void cpp_conversion_generator::cast(const isl_class &clazz, const char *to)
24 string name = cpp_generator::type2cpp(clazz);
26 if (!clazz.is_type_subclass())
27 return;
29 cast(classes[clazz.superclass_name], to);
30 printf(".as<%s%s>()", to, name.c_str());
33 /* Print a function called "function" for converting objects of
34 * "clazz" from the "from" bindings to the "to" bindings.
35 * If "clazz" describes a subclass of a C type, then the result
36 * of the conversion between bindings is derived from the C type and
37 * needs to be converted back to the subclass.
39 void cpp_conversion_generator::convert(const isl_class &clazz,
40 const char *from, const char *to, const char *function)
42 string name = cpp_generator::type2cpp(clazz);
44 printf("%s%s %s(%s%s obj) {\n",
45 to, name.c_str(), function, from, name.c_str());
46 printf("\t""return %s""manage(obj.copy())", to);
47 cast(clazz, to);
48 printf(";\n");
49 printf("}\n");
50 printf("\n");
53 /* Print functions for converting objects of "clazz"
54 * between the default and the checked C++ bindings.
56 * The conversion from default to checked is called "check".
57 * The inverse conversion is called "uncheck".
58 * For example, to "set", the following two functions are generated:
60 * checked::set check(set obj) {
61 * return checked::manage(obj.copy());
62 * }
64 * set uncheck(checked::set obj) {
65 * return manage(obj.copy());
66 * }
68 void cpp_conversion_generator::print(const isl_class &clazz)
70 convert(clazz, "", "checked::", "check");
71 convert(clazz, "checked::", "", "uncheck");
74 /* Generate conversion functions for converting objects between
75 * the default and the checked C++ bindings.
76 * Do this for each exported class.
78 void cpp_conversion_generator::generate()
80 map<string, isl_class>::iterator ci;
82 printf("namespace isl {\n\n");
83 for (ci = classes.begin(); ci != classes.end(); ++ci)
84 print(ci->second);
85 printf("} // namespace isl\n");