/** * @brief Fusion two osl_body into a third one. * The two osl_body must have the same iterators or the program will fail. * * @param body1 The first osl_body. * @param body2 The second osl_body. * * @return An osl_body with the same iteratar as the parameters, but with * their "code" fusionned. */ struct osl_body * substrate_osl_body_fusion( struct osl_body * body1, struct osl_body * body2) { struct osl_body * res = NULL; size_t body1_size = 0, body2_size = 0; body1_size = osl_strings_size(body1->iterators); body2_size = osl_strings_size(body2->iterators); res = osl_body_malloc(); if((osl_strings_equal(body1->iterators, body2->iterators)) || (body1_size==0) || (body2_size==0)) { res->iterators = osl_strings_clone(body1->iterators); substrate_osl_strings_concat( &res->expression, body1->expression, body2->expression); } else { //TODO Maybe fuse when iterators don't match ? (I'm not really sure). OSL_error("Can't fusion body"); } return res; }
/** * osl_scatnames_equal function: * this function returns true if the two scatnames structures are the same * (content-wise), false otherwise. * \param[in] s1 The first scatnames structure. * \param[in] s2 The second scatnames structure. * \return 1 if s1 and s2 are the same (content-wise), 0 otherwise. */ int osl_scatnames_equal(osl_scatnames_p s1, osl_scatnames_p s2) { if (s1 == s2) return 1; if (((s1 == NULL) && (s2 != NULL)) || ((s1 != NULL) && (s2 == NULL))) return 0; if (!osl_strings_equal(s1->names, s2->names)) return 0; return 1; }
/** * osl_body_equal function: * this function returns true if the two bodies are the same, false * otherwise (the usr field is not tested). However, let us * recall here that non-string elements are untouched by the OpenScop Library. * \param[in] b1 The first body. * \param[in] b2 The second body. * \return 1 if b1 and b2 are the same (content-wise), 0 otherwise. */ int osl_body_equal(osl_body_p b1, osl_body_p b2) { if (b1 == b2) return 1; if (((b1 != NULL) && (b2 == NULL)) || ((b1 == NULL) && (b2 != NULL))) { OSL_info("bodies are not the same"); return 0; } if (!osl_strings_equal(b1->iterators, b2->iterators)) { OSL_info("body iterators are not the same"); return 0; } if (!osl_strings_equal(b1->expression, b2->expression)) { OSL_info("body expressions are not the same"); return 0; } return 1; }