Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
language: c

compiler:
- clang
- gcc

os:
- linux
# - osx

osx_image: xcode9

dist: trusty

before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install gmp ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install --with-clang --with-lld --with-python llvm ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install libgmp-dev libedit-dev ; fi
- export PATH=/usr/local/opt/llvm/bin:$PATH
- git submodule init
- git submodule update
env:
- INT=gmp
- INT=imath
- INT=imath-32

script:
- ./autogen.sh && ./configure --with-int=$INT --with-clang=system && make && make check
22 changes: 12 additions & 10 deletions include/isl/aff.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ __isl_give isl_aff *isl_aff_set_dim_id(__isl_take isl_aff *aff,
int isl_aff_find_dim_by_name(__isl_keep isl_aff *aff, enum isl_dim_type type,
const char *name);

__isl_export
isl_bool isl_aff_plain_is_equal(__isl_keep isl_aff *aff1,
__isl_keep isl_aff *aff2);
isl_bool isl_aff_plain_is_zero(__isl_keep isl_aff *aff);
isl_bool isl_aff_is_nan(__isl_keep isl_aff *aff);

__isl_give isl_aff *isl_aff_get_div(__isl_keep isl_aff *aff, int pos);

__isl_export
__isl_operator
__isl_give isl_aff *isl_aff_neg(__isl_take isl_aff *aff);
__isl_export
__isl_give isl_aff *isl_aff_ceil(__isl_take isl_aff *aff);
Expand All @@ -90,16 +91,16 @@ __isl_overload
__isl_give isl_aff *isl_aff_mod_val(__isl_take isl_aff *aff,
__isl_take isl_val *mod);

__isl_export
__isl_operator
__isl_give isl_aff *isl_aff_mul(__isl_take isl_aff *aff1,
__isl_take isl_aff *aff2);
__isl_export
__isl_operator
__isl_give isl_aff *isl_aff_div(__isl_take isl_aff *aff1,
__isl_take isl_aff *aff2);
__isl_export
__isl_operator
__isl_give isl_aff *isl_aff_add(__isl_take isl_aff *aff1,
__isl_take isl_aff *aff2);
__isl_export
__isl_operator
__isl_give isl_aff *isl_aff_sub(__isl_take isl_aff *aff1,
__isl_take isl_aff *aff2);

Expand Down Expand Up @@ -201,6 +202,7 @@ isl_bool isl_pw_aff_is_empty(__isl_keep isl_pw_aff *pwaff);
isl_bool isl_pw_aff_involves_nan(__isl_keep isl_pw_aff *pa);
int isl_pw_aff_plain_cmp(__isl_keep isl_pw_aff *pa1,
__isl_keep isl_pw_aff *pa2);
__isl_export
isl_bool isl_pw_aff_plain_is_equal(__isl_keep isl_pw_aff *pwaff1,
__isl_keep isl_pw_aff *pwaff2);
isl_bool isl_pw_aff_is_equal(__isl_keep isl_pw_aff *pa1,
Expand Down Expand Up @@ -249,19 +251,19 @@ __isl_give isl_pw_aff *isl_pw_aff_min(__isl_take isl_pw_aff *pwaff1,
__isl_export
__isl_give isl_pw_aff *isl_pw_aff_max(__isl_take isl_pw_aff *pwaff1,
__isl_take isl_pw_aff *pwaff2);
__isl_export
__isl_operator
__isl_give isl_pw_aff *isl_pw_aff_mul(__isl_take isl_pw_aff *pwaff1,
__isl_take isl_pw_aff *pwaff2);
__isl_export
__isl_operator
__isl_give isl_pw_aff *isl_pw_aff_div(__isl_take isl_pw_aff *pa1,
__isl_take isl_pw_aff *pa2);
__isl_export
__isl_operator
__isl_give isl_pw_aff *isl_pw_aff_add(__isl_take isl_pw_aff *pwaff1,
__isl_take isl_pw_aff *pwaff2);
__isl_export
__isl_operator
__isl_give isl_pw_aff *isl_pw_aff_sub(__isl_take isl_pw_aff *pwaff1,
__isl_take isl_pw_aff *pwaff2);
__isl_export
__isl_operator
__isl_give isl_pw_aff *isl_pw_aff_neg(__isl_take isl_pw_aff *pwaff);
__isl_export
__isl_give isl_pw_aff *isl_pw_aff_ceil(__isl_take isl_pw_aff *pwaff);
Expand Down
3 changes: 3 additions & 0 deletions include/isl/ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#ifndef __isl_overload
#define __isl_overload
#endif
#ifndef __isl_operator
#define __isl_operator
#endif
#ifndef __isl_constructor
#define __isl_constructor
#endif
Expand Down
22 changes: 11 additions & 11 deletions include/isl/val.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ __isl_give isl_val *isl_val_set_si(__isl_take isl_val *v, long i);

__isl_export
__isl_give isl_val *isl_val_abs(__isl_take isl_val *v);
__isl_export
__isl_operator
__isl_give isl_val *isl_val_neg(__isl_take isl_val *v);
__isl_export
__isl_give isl_val *isl_val_inv(__isl_take isl_val *v);
Expand All @@ -73,16 +73,16 @@ __isl_export
__isl_give isl_val *isl_val_min(__isl_take isl_val *v1, __isl_take isl_val *v2);
__isl_export
__isl_give isl_val *isl_val_max(__isl_take isl_val *v1, __isl_take isl_val *v2);
__isl_export
__isl_operator
__isl_give isl_val *isl_val_add(__isl_take isl_val *v1, __isl_take isl_val *v2);
__isl_give isl_val *isl_val_add_ui(__isl_take isl_val *v1, unsigned long v2);
__isl_export
__isl_operator
__isl_give isl_val *isl_val_sub(__isl_take isl_val *v1, __isl_take isl_val *v2);
__isl_give isl_val *isl_val_sub_ui(__isl_take isl_val *v1, unsigned long v2);
__isl_export
__isl_operator
__isl_give isl_val *isl_val_mul(__isl_take isl_val *v1, __isl_take isl_val *v2);
__isl_give isl_val *isl_val_mul_ui(__isl_take isl_val *v1, unsigned long v2);
__isl_export
__isl_operator
__isl_give isl_val *isl_val_div(__isl_take isl_val *v1, __isl_take isl_val *v2);
__isl_give isl_val *isl_val_div_ui(__isl_take isl_val *v1, unsigned long v2);
__isl_export
Expand Down Expand Up @@ -122,17 +122,17 @@ isl_bool isl_val_is_neginfty(__isl_keep isl_val *v);
__isl_export
int isl_val_cmp_si(__isl_keep isl_val *v, long i);

__isl_export
__isl_operator
isl_bool isl_val_lt(__isl_keep isl_val *v1, __isl_keep isl_val *v2);
__isl_export
__isl_operator
isl_bool isl_val_le(__isl_keep isl_val *v1, __isl_keep isl_val *v2);
__isl_export
__isl_operator
isl_bool isl_val_gt(__isl_keep isl_val *v1, __isl_keep isl_val *v2);
__isl_export
__isl_operator
isl_bool isl_val_ge(__isl_keep isl_val *v1, __isl_keep isl_val *v2);
__isl_export
__isl_operator
isl_bool isl_val_eq(__isl_keep isl_val *v1, __isl_keep isl_val *v2);
__isl_export
__isl_operator
isl_bool isl_val_ne(__isl_keep isl_val *v1, __isl_keep isl_val *v2);
__isl_export
isl_bool isl_val_abs_eq(__isl_keep isl_val *v1, __isl_keep isl_val *v2);
Expand Down
50 changes: 49 additions & 1 deletion interface/cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -553,13 +553,42 @@ void cpp_generator::print_methods_impl(ostream &os, const isl_class &clazz)
}
}

/* Map isl function names to C++ operators.
*/
static const char *op_map[][2] = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered an unordered_map instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sven prefers to not use C++11 in the generator yet (but the generated code is C++11). Hence, I use now a std::map, instead.

{ "neg", "-" },
{ "add", "+" },
{ "sub", "-" },
{ "mul", "*" },
{ "div", "/" },
{ "lt", "<" },
{ "le", "<=" },
{ "gt", ">" },
{ "ge", ">=" },
{ "eq", "==" },
{ "ne", "!=" },
};

/* Translate a function name "name" into the corresponding C++ operator.
*/
std::string cpp_generator::get_op_name(std::string name) {
for (size_t i = 0; i < sizeof(op_map) / sizeof(op_map[0]); i++)
if (name.compare(op_map[i][0]) == 0)
return op_map[i][1];

die("No operator name found");
};

/* Print definitions for methods "methods" of name "fullname" in class "clazz"
* to "os".
*
* "fullname" is the name of the generated C++ method. It commonly corresponds
* to the isl name, with the object type prefix dropped.
* In case of overloaded methods, the result type suffix has also been removed.
*
* In case the function is marked as operator function, an additional variant
* as C++ operator is printed.
*
* "kind" specifies the kind of method that should be generated.
*/
void cpp_generator::print_method_group_impl(ostream &os, const isl_class &clazz,
Expand All @@ -576,6 +605,13 @@ void cpp_generator::print_method_group_impl(ostream &os, const isl_class &clazz,
osprintf(os, "\n");
kind = get_method_kind(clazz, *it);
print_method_impl(os, clazz, fullname, *it, kind);

if (is_operator(*it)) {
osprintf(os, "\n");
print_method_impl(os, clazz, fullname, *it,
function_kind_operator);
}

}
}

Expand Down Expand Up @@ -658,6 +694,9 @@ void cpp_generator::print_method_param_use(ostream &os, ParmVarDecl *param,
* do not return a value, but instead update the pointer stored inside the
* newly created object.
*
* When printing a method as C++ operator, the function name is replaced by
* the corresponding C++ operator as defined by "get_op_name".
*
* If the method has a callback argument, we reduce the number of parameters
* that are exposed by one to hide the user pointer from the interface. On
* the C++ side no user pointer is needed, as arguments can be forwarded
Expand All @@ -673,6 +712,9 @@ void cpp_generator::print_method_impl(ostream &os, const isl_class &clazz,
string rettype_str = type2cpp(return_type);
bool has_callback = false;

if (kind == function_kind_operator)
cname = get_op_name(cname);

print_method_header(os, clazz, method, fullname, false, kind);

for (int i = 0; i < num_params; ++i) {
Expand Down Expand Up @@ -754,6 +796,9 @@ void cpp_generator::print_method_impl(ostream &os, const isl_class &clazz,
* as const reference, which allows the compiler to optimize the parameter
* transfer.
*
* When printing a method as C++ operator, the function name is replaced by
* the corresponding C++ operator as defined by "get_op_name".
*
* Constructors are marked as explicit using the C++ keyword 'explicit' or as
* implicit using a comment in place of the explicit keyword. By annotating
* implicit constructors with a comment, users of the interface are made
Expand All @@ -771,6 +816,9 @@ void cpp_generator::print_method_header(ostream &os, const isl_class &clazz,
int num_params = method->getNumParams();
int first_param = 0;

if (kind == function_kind_operator)
cname = "operator" + get_op_name(cname);

cname = rename_method(cname);
if (kind == function_kind_member_method)
first_param = 1;
Expand All @@ -794,7 +842,7 @@ void cpp_generator::print_method_header(ostream &os, const isl_class &clazz,
if (kind != function_kind_constructor)
osprintf(os, "%s ", rettype_str.c_str());

if (!is_declaration)
if (!is_declaration && kind != function_kind_operator)
osprintf(os, "%s::", classname.c_str());

if (kind != function_kind_constructor)
Expand Down
2 changes: 2 additions & 0 deletions interface/cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class cpp_generator : public generator {
function_kind_static_method,
function_kind_member_method,
function_kind_constructor,
function_kind_operator,
};

virtual void generate();
Expand Down Expand Up @@ -71,4 +72,5 @@ class cpp_generator : public generator {
bool is_subclass(QualType subclass_type, const isl_class &class_type);
function_kind get_method_kind(const isl_class &clazz,
FunctionDecl *method);
std::string get_op_name(std::string name);
};
3 changes: 3 additions & 0 deletions interface/extract_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ int main(int argc, char *argv[])
PO.addMacroDef("__isl_overload="
"__attribute__((annotate(\"isl_overload\"))) "
"__attribute__((annotate(\"isl_export\")))");
PO.addMacroDef("__isl_operator="
"__attribute__((annotate(\"isl_operator\"))) "
"__attribute__((annotate(\"isl_export\")))");
PO.addMacroDef("__isl_constructor=__attribute__((annotate(\"isl_constructor\"))) __attribute__((annotate(\"isl_export\")))");
PO.addMacroDef("__isl_subclass(super)=__attribute__((annotate(\"isl_subclass(\" #super \")\"))) __attribute__((annotate(\"isl_export\")))");

Expand Down
7 changes: 7 additions & 0 deletions interface/generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ std::vector<string> generator::find_superclasses(RecordDecl *decl)
return super;
}

/* Is decl marked as operator?
*/
bool generator::is_operator(Decl *decl)
{
return has_annotation(decl, "isl_operator");
}

/* Is decl marked as being part of an overloaded method?
*/
bool generator::is_overload(Decl *decl)
Expand Down
1 change: 1 addition & 0 deletions interface/generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class generator {
void die(string msg) __attribute__((noreturn));
vector<string> find_superclasses(RecordDecl *decl);
bool is_overload(Decl *decl);
bool is_operator(Decl *decl);
bool is_constructor(Decl *decl);
bool takes(Decl *decl);
bool keeps(Decl *decl);
Expand Down
Loading