diff --git a/ispc.cpp b/ispc.cpp index 1b076352..8e62191a 100644 --- a/ispc.cpp +++ b/ispc.cpp @@ -418,7 +418,7 @@ public: }; -Target::Target(const char *arch, const char *cpu, const char *isa, bool pic, std::string genericAsSmth) : +Target::Target(const char *arch, const char *cpu, const char *isa, bool pic, bool printTarget, std::string genericAsSmth) : m_target(NULL), m_targetMachine(NULL), m_dataLayout(NULL), @@ -1049,6 +1049,12 @@ Target::Target(const char *arch, const char *cpu, const char *isa, bool pic, std m_valid = !error; + if (printTarget) { + printf("Target Triple: %s\n", m_targetMachine->getTargetTriple().str().c_str()); + printf("Target CPU: %s\n", m_targetMachine->getTargetCPU().str().c_str()); + printf("Target Feature String: %s\n", m_targetMachine->getTargetFeatureString().str().c_str()); + } + return; } @@ -1379,6 +1385,7 @@ Globals::Globals() { includeStdlib = true; runCPP = true; debugPrint = false; + printTarget = false; debugIR = -1; disableWarnings = false; warningsAsErrors = false; diff --git a/ispc.h b/ispc.h index a19bdb27..cec6e4d6 100644 --- a/ispc.h +++ b/ispc.h @@ -207,7 +207,7 @@ public: /** Initializes the given Target pointer for a target of the given name, if the name is a known target. Returns true if the target was initialized and false if the name is unknown. */ - Target(const char *arch, const char *cpu, const char *isa, bool pic, std::string genenricAsSmth = ""); + Target(const char *arch, const char *cpu, const char *isa, bool pic, bool printTarget, std::string genenricAsSmth = ""); /** Returns a comma-delimited string giving the names of the currently supported compilation targets. */ @@ -559,6 +559,9 @@ struct Globals { ispc's execution. */ bool debugPrint; + /** When \c true, target ISA will be printed during ispc's execution. */ + bool printTarget; + /** Indicates which stages of optimization we want to dump. */ std::set debug_stages; diff --git a/main.cpp b/main.cpp index bf78cb90..ea0d8e74 100644 --- a/main.cpp +++ b/main.cpp @@ -153,6 +153,7 @@ devUsage(int ret) { lPrintVersion(); printf("\nusage (developer options): ispc\n"); printf(" [--debug]\t\t\t\tPrint information useful for debugging ispc\n"); + printf(" [--print-target]\t\t\tPrint target's information\n"); printf(" [--dllexport]\t\t\tMake non-static functions DLL exported. Windows only.\n"); printf(" [--fuzz-test]\t\t\tRandomly perturb program input to test error conditions\n"); printf(" [--fuzz-seed=]\t\tSeed value for RNG for fuzz testing\n"); @@ -382,6 +383,8 @@ int main(int Argc, char *Argv[]) { g->debugPrint = true; else if (!strcmp(argv[i], "--dllexport")) g->dllExport = true; + else if (!strcmp(argv[i], "--print-target")) + g->printTarget = true; else if (!strcmp(argv[i], "--instrument")) g->emitInstrumentation = true; else if (!strcmp(argv[i], "-g")) { diff --git a/module.cpp b/module.cpp index 5ed3c4d0..6dc80747 100644 --- a/module.cpp +++ b/module.cpp @@ -3055,7 +3055,7 @@ Module::CompileAndOutput(const char *srcFile, { if (target == NULL || strchr(target, ',') == NULL) { // We're only compiling to a single target - g->target = new Target(arch, cpu, target, generatePIC); + g->target = new Target(arch, cpu, target, generatePIC, g->printTarget); if (!g->target->isValid()) return 1; @@ -3198,7 +3198,7 @@ Module::CompileAndOutput(const char *srcFile, std::string treatGenericAsSmth = ""; for (unsigned int i = 0; i < targets.size(); ++i) { - g->target = new Target(arch, cpu, targets[i].c_str(), generatePIC); + g->target = new Target(arch, cpu, targets[i].c_str(), generatePIC, g->printTarget); if (!g->target->isValid()) return 1; @@ -3293,7 +3293,7 @@ Module::CompileAndOutput(const char *srcFile, } Assert(firstTargetMachine != NULL); - g->target = new Target(arch, cpu, firstISA, generatePIC, treatGenericAsSmth); + g->target = new Target(arch, cpu, firstISA, generatePIC, false, treatGenericAsSmth); if (!g->target->isValid()) { return 1; }