[2019-12] [threads] Add back mono_threads_attach_tools_thread as a public API (#18074)
[mono-project.git] / mono / tests / split-tailcall-interface-conservestack.cpp
blob10e38b73c93af0b9e4f711c46fea2adae65c63da
1 // This program is used to split tailcall-interface-conservestack.il into separate tests.
2 //
3 // Algorithm is just to split on special inserted markers.
4 //
5 // mkdir tailcall/interface-conservestack
6 // rm tailcall-interface-conservestack-*
7 // git rm tailcall-interface-conservestack-*
8 // g++ split-tailcall-interface-conservestack.cpp && ./a.out < tailcall-interface-conservestack.il
9 // git add tailcall/interface-conservestack/*.il
11 // Note This is valid C++98 for use with older compilers, where C++11 would be desirable.
12 #include <stdlib.h>
13 #include <iostream>
14 #include <fstream>
15 #include <vector>
16 #include <string>
17 #include <assert.h>
18 using namespace std;
19 #include <sys/stat.h>
20 #ifdef _WIN32
21 #include <direct.h>
22 #endif
24 typedef vector<string> strings_t;
25 struct test_t
27 strings_t content;
29 typedef vector<test_t> tests_t;
31 static void
32 CreateDir (const char *a)
34 #ifdef _WIN32
35 _mkdir (a);
36 #else
37 mkdir (a, 0777);
38 #endif
41 int main()
43 string line;
44 strings_t prefix;
45 tests_t tests;
46 test_t test_dummy;
47 test_t *test = &test_dummy;
48 strings_t suffix;
50 while (getline(cin, line) && line != "// test-split-prefix do not remove or edit this line")
51 prefix.push_back(line);
53 while (getline (cin, line))
55 if (!line.length()) // tests are delimited by empty lines
57 tests.resize(tests.size() + 1);
58 test = &tests.back();
59 assert(getline(cin, line));
60 if (line == "// test-split-suffix do not remove or edit this line")
61 break;
63 test->content.push_back(line);
65 while (getline (cin, line))
66 suffix.push_back(line);
68 int i = 0;
70 CreateDir ("tailcall");
71 CreateDir ("tailcall/interface-conservestack");
73 for (tests_t::iterator test = tests.begin(); test != tests.end(); ++test)
75 char buffer[99];
76 sprintf(buffer, "%d", ++i);
77 //printf("%s\n", buffer);
78 FILE* output = fopen((string("tailcall/interface-conservestack/") + buffer + ".il").c_str(), "w");
79 for (strings_t::const_iterator s = prefix.begin(); s != prefix.end(); ++s)
80 fprintf(output, "%s\n", s->c_str());
81 fputs("\n", output);
82 for (strings_t::const_iterator s = test->content.begin(); s != test->content.end(); ++s)
83 fprintf(output, "%s\n", s->c_str());
84 fputs("\n", output);
85 for (strings_t::const_iterator s = suffix.begin(); s != suffix.end(); ++s)
86 fprintf(output, "%s\n", s->c_str());
87 fclose(output);