brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.4 KiB · 6d62fb1 Raw
201 lines · plain
1/// These are automatically generated checked C++ bindings for isl.2///3/// isl is a library for computing with integer sets and maps described by4/// Presburger formulas. On top of this, isl provides various tools for5/// polyhedral compilation, ranging from dependence analysis over scheduling6/// to AST generation.7 8#ifndef ISL_CPP_CHECKED9#define ISL_CPP_CHECKED10 11#include <stdio.h>12#include <stdlib.h>13 14#include <functional>15#include <memory>16#include <ostream>17#include <string>18#include <type_traits>19 20#if __cplusplus >= 201703L21#include <any>22#include <optional>23#endif24 25namespace isl {26namespace checked {27 28#define ISLPP_STRINGIZE_(X) #X29#define ISLPP_STRINGIZE(X) ISLPP_STRINGIZE_(X)30 31#define ISLPP_ASSERT(test, message)                          \32  do {                                                       \33    if (test)                                                \34      break;                                                 \35    fputs("Assertion \"" #test "\" failed at " __FILE__      \36      ":" ISLPP_STRINGIZE(__LINE__) "\n  " message "\n",     \37      stderr);                                               \38    abort();                                                 \39  } while (0)40 41/* Class used to check that isl::checked::boolean,42 * isl::checked::stat and isl::checked::size values are checked for errors.43 */44struct checker {45	bool checked = false;46	~checker() {47		ISLPP_ASSERT(checked, "IMPLEMENTATION ERROR: Unchecked state");48	}49};50 51class boolean {52private:53  mutable std::shared_ptr<checker> check = std::make_shared<checker>();54  isl_bool val;55 56  friend boolean manage(isl_bool val);57  boolean(isl_bool val): val(val) {}58public:59  static boolean error() {60    return boolean(isl_bool_error);61  }62  boolean()63      : val(isl_bool_error) {}64 65  /* implicit */ boolean(bool val)66      : val(val ? isl_bool_true : isl_bool_false) {}67 68  isl_bool release() {69    auto tmp = val;70    val = isl_bool_error;71    check->checked = true;72    return tmp;73  }74 75  bool is_error() const { check->checked = true; return val == isl_bool_error; }76  bool is_false() const { check->checked = true; return val == isl_bool_false; }77  bool is_true() const { check->checked = true; return val == isl_bool_true; }78 79  explicit operator bool() const {80    ISLPP_ASSERT(check->checked, "IMPLEMENTATION ERROR: Unchecked error state");81    ISLPP_ASSERT(!is_error(), "IMPLEMENTATION ERROR: Unhandled error state");82    return is_true();83  }84 85  boolean negate() {86    if (val == isl_bool_true)87      val = isl_bool_false;88    else if (val == isl_bool_false)89      val = isl_bool_true;90    return *this;91  }92 93  boolean operator!() const {94    return boolean(*this).negate();95  }96};97 98inline boolean manage(isl_bool val) {99  return boolean(val);100}101 102class ctx {103	isl_ctx *ptr;104public:105	/* implicit */ ctx(isl_ctx *ctx) : ptr(ctx) {}106	isl_ctx *release() {107		auto tmp = ptr;108		ptr = nullptr;109		return tmp;110	}111	isl_ctx *get() {112		return ptr;113	}114#if __cplusplus >= 201703L115	static void free_user(void *user) {116		std::any *p = static_cast<std::any *>(user);117		delete p;118	}119#endif120};121 122/* Class encapsulating an isl_stat value.123 */124class stat {125private:126	mutable std::shared_ptr<checker> check = std::make_shared<checker>();127	isl_stat val;128 129	friend stat manage(isl_stat val);130	stat(isl_stat val) : val(val) {}131public:132	static stat ok() {133		return stat(isl_stat_ok);134	}135	static stat error() {136		return stat(isl_stat_error);137	}138	stat() : val(isl_stat_error) {}139 140	isl_stat release() {141		check->checked = true;142		return val;143	}144 145	bool is_error() const {146		check->checked = true;147		return val == isl_stat_error;148	}149	bool is_ok() const {150		check->checked = true;151		return val == isl_stat_ok;152	}153};154 155inline stat manage(isl_stat val)156{157	return stat(val);158}159 160/* Class encapsulating an isl_size value.161 */162class size {163private:164	mutable std::shared_ptr<checker> check = std::make_shared<checker>();165	isl_size val;166 167	friend size manage(isl_size val);168	size(isl_size val) : val(val) {}169public:170	size() : val(isl_size_error) {}171 172	isl_size release() {173		auto tmp = val;174		val = isl_size_error;175		check->checked = true;176		return tmp;177	}178 179	bool is_error() const {180		check->checked = true;181		return val == isl_size_error;182	}183 184	explicit operator unsigned() const {185		ISLPP_ASSERT(check->checked,186			    "IMPLEMENTATION ERROR: Unchecked error state");187		ISLPP_ASSERT(!is_error(),188			    "IMPLEMENTATION ERROR: Unhandled error state");189		return val;190	}191};192 193inline size manage(isl_size val)194{195	return size(val);196}197 198}199} // namespace isl200 201