// between 0 and SPLIT_INSTANTIATIONS_COUNT-1 to get the instantiations of that
// particular chunk.
static unsigned int counter = 0;
- std::cout << "#if !defined(SPLIT_INSTANTIATIONS_COUNT) || ("
+ std::cout << "#if (SPLIT_INSTANTIATIONS_CHECK("
<< counter++
- << " % SPLIT_INSTANTIATIONS_COUNT == SPLIT_INSTANTIATIONS_INDEX)" << std::endl;
+ << "))" << std::endl;
std::cout << substitute_tokens (text, name, *expansion)
<< std::endl;
std::cout << "#endif" << std::endl;
for (int i=1; i<argc; ++i)
read_expansion_lists (argv[i]);
+ // write header:
+ std::cout << "// This file is automatically generated from corresponding .inst.in, do not edit."
+ << std::endl << std::endl;
+
+ // Make sure SPLIT_INSTANTIATIONS_* is working correctly if the user doesn't
+ // use it. The defaults will not split the instantiations. This logic is
+ // somewhat tricky to get right for two reasons: 1. icc 14 will not allow an
+ // expressition like "#if !defined(B) || (A % B == C)" 2. we have .cc files
+ // where more than one .inst is included and splitting is only required in
+ // one of them. So we need to handle the case where _COUNT is undefined but
+ // _INDEX is defined, which might be needed later.
+ std::cout << "#ifdef SPLIT_INSTANTIATIONS_COUNT" << std::endl
+ << " #define SPLIT_INSTANTIATIONS_CHECK(C) (((C) % SPLIT_INSTANTIATIONS_COUNT) == SPLIT_INSTANTIATIONS_INDEX)" << std::endl
+ << "#else" << std::endl
+ << " #define SPLIT_INSTANTIATIONS_CHECK(C) (1)" << std::endl
+ << "#endif" << std::endl << std::endl;
+
process_instantiations ();
+
+ // undefine the macro to avoid issues when more than one .inst file is
+ // included in a single .cc
+ std::cout << std::endl
+ << "#undef SPLIT_INSTANTIATIONS_CHECK" << std::endl;
}