#include "pttc.h"
#include "pt_cpu.h"
#include "pt_version.h"
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
static void help(const char *prog)
{
printf("usage: %s [<options>] <pttfile>\n\n"
"options:\n"
" --help|-h this text.\n"
" --version display version information and exit.\n"
" --cpu none|auto|f/m[/s] set cpu to the given value and encode according to:\n"
" none spec (default)\n"
" auto current cpu\n"
" f/m[/s] family/model[/stepping]\n"
" <pttfile> the annotated yasm input file.\n",
prog);
}
int main(int argc, char *argv[])
{
struct pttc_options options;
const char *prog;
int errcode, i;
prog = argv[0];
memset(&options, 0, sizeof(options));
for (i = 1; i < argc;) {
const char *arg;
arg = argv[i++];
if (strcmp(arg, "--help") == 0 || strcmp(arg, "-h") == 0) {
help(prog);
return 0;
}
if (strcmp(arg, "--version") == 0) {
pt_print_tool_version(prog);
return 0;
}
if (strcmp(arg, "--cpu") == 0) {
arg = argv[i++];
if (strcmp(arg, "auto") == 0) {
errcode = pt_cpu_read(&options.cpu);
if (errcode < 0) {
fprintf(stderr,
"%s: error reading cpu: %s.\n",
prog,
pt_errstr(pt_errcode(errcode)));
return 1;
}
continue;
}
if (strcmp(arg, "none") == 0) {
memset(&options.cpu, 0, sizeof(options.cpu));
continue;
}
errcode = pt_cpu_parse(&options.cpu, arg);
if (errcode < 0) {
fprintf(stderr,
"%s: cpu must be specified as f/m[/s].\n",
prog);
return 1;
}
continue;
}
if (arg[0] == '-') {
fprintf(stderr, "%s: unrecognized option '%s'.\n",
prog, arg);
return 1;
}
if (options.pttfile) {
fprintf(stderr,
"%s: only one pttfile can be specified.\n",
prog);
return 1;
}
options.pttfile = arg;
}
if (!options.pttfile) {
fprintf(stderr, "%s: no pttfile specified.\n", prog);
fprintf(stderr, "Try '%s -h' for more information.\n", prog);
return 1;
}
return pttc_main(&options);
}