1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "span.h"
#include <array>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <string_view>
using std::cerr;
using std::cout;
using std::endl;
using std::ios;
using std::ofstream;
using std::ostream;
using std::setbase;
using std::setfill;
using std::setw;
using std::string;
using std::string_view;
using namespace std::string_view_literals;
void gen_intrinsic_table(
ofstream& o, const tcb::span<const string_view>& table) {
o << "<intrinsics>" << endl;
for (size_t i = 0; i < table.size(); i++) {
o << "\t<0x" << setw(2) << i << "> " << table[i];
if (table[i] == "UNKNOWN") {
o << '_' << setw(2) << i;
}
o << " </>" << endl;
}
o << "</>" << endl;
}
void bg_out(const string& fname) {
ofstream o;
o.open(fname.c_str());
if (o.fail()) {
cerr << "error: could not open `" << fname << "` for writing" << endl;
exit(1);
}
o << setfill('0') << setbase(16);
o.setf(ios::uppercase);
#define USECODE_INTRINSIC_PTR(NAME) #NAME##sv
constexpr static const std::array bgut{
#include "bgintrinsics.h"
};
#undef USECODE_INTRINSIC_PTR
gen_intrinsic_table(o, bgut);
o.close();
}
void si_out(const string& fname) {
ofstream o;
o.open(fname.c_str());
if (o.fail()) {
cerr << "error: could not open `" << fname << "` for writing" << endl;
exit(1);
}
o << setfill('0') << setbase(16);
o.setf(ios::uppercase);
#define USECODE_INTRINSIC_PTR(NAME) #NAME##sv
constexpr static const std::array siut{
#include "siintrinsics.h"
};
#undef USECODE_INTRINSIC_PTR
gen_intrinsic_table(o, siut);
o.close();
}
void sibeta_out(const string& fname) {
ofstream o;
o.open(fname.c_str());
if (o.fail()) {
cerr << "error: could not open `" << fname << "` for writing" << endl;
exit(1);
}
o << setfill('0') << setbase(16);
o.setf(ios::uppercase);
#define USECODE_INTRINSIC_PTR(NAME) #NAME##sv
constexpr static const std::array sibut{
#include "sibetaintrinsics.h"
};
#undef USECODE_INTRINSIC_PTR
gen_intrinsic_table(o, sibut);
o.close();
}
int main(int argc, char** argv) {
if (argc != 4) {
cout << "usage:" << endl
<< "\thead2data <bg outputfile> <si outputfile> <si beta "
"outputfile>"
<< endl
<< endl
<< "\tWhere the output files are the relative pathnames to the "
"datafiles"
<< endl
<< "\tto be output." << endl
<< "\teg. head2data data/u7bgintrinsics.data "
"data/u7siintrinsics.data data/u7sibetaintrinsics.data"
<< endl;
return 1;
}
bg_out(string(argv[1]));
si_out(string(argv[2]));
sibeta_out(string(argv[3]));
return 0;
}
|