main.cxx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include <stdio.h>
  2. /*
  3. Define GENERATED_HEADER macro to allow c++ files to include headers
  4. generated based on different configuration types.
  5. */
  6. /* clang-format off */
  7. #define GENERATED_HEADER(x) GENERATED_HEADER0(CONFIG_TYPE/x)
  8. /* clang-format on */
  9. #define GENERATED_HEADER0(x) GENERATED_HEADER1(x)
  10. #define GENERATED_HEADER1(x) <x>
  11. #include GENERATED_HEADER(path_to_objs.h)
  12. #include <vector>
  13. std::vector<std::string> expandList(std::string const& arg)
  14. {
  15. std::vector<std::string> output;
  16. // If argument is empty or no `;` just copy the current string
  17. if (arg.empty() || arg.find(';') == std::string::npos) {
  18. output.emplace_back(arg);
  19. return output;
  20. }
  21. std::string newArg;
  22. // Break the string at non-escaped semicolons not nested in [].
  23. int squareNesting = 0;
  24. auto last = arg.begin();
  25. auto const cend = arg.end();
  26. for (auto c = last; c != cend; ++c) {
  27. switch (*c) {
  28. case '\\': {
  29. // We only want to allow escaping of semicolons. Other
  30. // escapes should not be processed here.
  31. auto cnext = c + 1;
  32. if ((cnext != cend) && *cnext == ';') {
  33. newArg.append(last, c);
  34. // Skip over the escape character
  35. last = cnext;
  36. c = cnext;
  37. }
  38. } break;
  39. case '[': {
  40. ++squareNesting;
  41. } break;
  42. case ']': {
  43. --squareNesting;
  44. } break;
  45. case ';': {
  46. // Break the string here if we are not nested inside square
  47. // brackets.
  48. if (squareNesting == 0) {
  49. newArg.append(last, c);
  50. // Skip over the semicolon
  51. last = c + 1;
  52. if (!newArg.empty()) {
  53. // Add the last argument if the string is not empty.
  54. output.push_back(newArg);
  55. newArg.clear();
  56. }
  57. }
  58. } break;
  59. default: {
  60. // Just append this character.
  61. } break;
  62. }
  63. }
  64. newArg.append(last, cend);
  65. if (!newArg.empty()) {
  66. // Add the last argument if the string is not empty.
  67. output.push_back(std::move(newArg));
  68. }
  69. return output;
  70. }
  71. int main()
  72. {
  73. // determine that the number of object files specified in obj_paths
  74. // is equal to the number of arch's
  75. std::vector<std::string> paths = expandList(obj_paths);
  76. const bool correctSize = (paths.size() == ExpectedISPCObjects);
  77. return (correctSize) ? 0 : 1;
  78. }