Commit 686f35e5 by Jim Stichnoth

Subzero: Fix -build-atts option.

If the default --target option is not actually included in the Subzero build (via llvm/Config/SZTargets.def), then "pnacl-sz --build-atts" will fail. This is because the attribute printing is done after the GlobalContext is created, which does some amount of Target initialization. The fix is to move the attribute printing to a point after the flags are parsed and the output streams are created, but before the GlobalContext is created. This basically disables --build-atts in the browser build, but that should be OK. BUG= none R=kschimpf@google.com Review URL: https://codereview.chromium.org/1584923002 .
parent b0051dfa
......@@ -127,6 +127,30 @@ void reportFatalErrorThenExitSuccess(void *UserData, const std::string &Reason,
exit(0);
}
struct {
const char *FlagName;
bool FlagValue;
} ConditionalBuildAttributes[] = {
{"dump", BuildDefs::dump()},
{"llvm_cl", BuildDefs::llvmCl()},
{"llvm_ir", BuildDefs::llvmIr()},
{"llvm_ir_as_input", BuildDefs::llvmIrAsInput()},
{"minimal_build", BuildDefs::minimal()},
{"browser_mode", BuildDefs::browser()}};
/// Dumps values of build attributes to Stream if Stream is non-null.
void dumpBuildAttributes(Ostream &Str) {
// List the supported targets.
#define SUBZERO_TARGET(TARGET) Str << "target_" #TARGET << "\n";
#include "llvm/Config/SZTargets.def"
const char *Prefix[2] = {"no", "allow"};
for (size_t i = 0; i < llvm::array_lengthof(ConditionalBuildAttributes);
++i) {
const auto &A = ConditionalBuildAttributes[i];
Str << Prefix[A.FlagValue] << "_" << A.FlagName << "\n";
}
}
} // end of anonymous namespace
void CLCompileServer::run() {
......@@ -198,6 +222,11 @@ void CLCompileServer::run() {
return transferErrorCode(getReturnValue(ExtraFlags, Ice::EC_Bitcode));
}
if (ExtraFlags.getGenerateBuildAtts()) {
dumpBuildAttributes(*Os.get());
return transferErrorCode(getReturnValue(ExtraFlags, Ice::EC_None));
}
Ctx.reset(
new GlobalContext(Ls.get(), Os.get(), Ls.get(), ELFStr.get(), Flags));
if (Ctx->getFlags().getNumTranslationThreads() != 0) {
......
......@@ -50,29 +50,6 @@ namespace Ice {
namespace {
struct {
const char *FlagName;
bool FlagValue;
} ConditionalBuildAttributes[] = {
{"dump", BuildDefs::dump()},
{"llvm_cl", BuildDefs::llvmCl()},
{"llvm_ir", BuildDefs::llvmIr()},
{"llvm_ir_as_input", BuildDefs::llvmIrAsInput()},
{"minimal_build", BuildDefs::minimal()},
{"browser_mode", BuildDefs::browser()}};
/// Dumps values of build attributes to Stream if Stream is non-null.
void dumpBuildAttributes(Ostream &Str) {
// List the supported targets.
#define SUBZERO_TARGET(TARGET) Str << "target_" #TARGET << "\n";
#include "llvm/Config/SZTargets.def"
const char *Prefix[2] = {"no", "allow"};
for (size_t i = 0; i < llvm::array_lengthof(ConditionalBuildAttributes);
++i) {
const auto &A = ConditionalBuildAttributes[i];
Str << Prefix[A.FlagValue] << "_" << A.FlagName << "\n";
}
}
bool llvmIRInput(const IceString &Filename) {
return BuildDefs::llvmIrAsInput() &&
std::regex_match(Filename, std::regex(".*\\.ll"));
......@@ -82,11 +59,6 @@ bool llvmIRInput(const IceString &Filename) {
void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx,
std::unique_ptr<llvm::DataStreamer> &&InputStream) {
if (ExtraFlags.getGenerateBuildAtts()) {
dumpBuildAttributes(Ctx.getStrDump());
Ctx.getErrorStatus()->assign(EC_None);
return;
}
// The Minimal build (specifically, when dump()/emit() are not implemented)
// allows only --filetype=obj. Check here to avoid cryptic error messages
// downstream.
......@@ -106,7 +78,8 @@ void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx,
std::unique_ptr<Translator> Translator;
const IceString &IRFilename = ExtraFlags.getIRFilename();
bool BuildOnRead = ExtraFlags.getBuildOnRead() && !llvmIRInput(IRFilename);
const bool BuildOnRead =
ExtraFlags.getBuildOnRead() && !llvmIRInput(IRFilename);
if (BuildOnRead) {
std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx));
std::unique_ptr<llvm::StreamingMemoryObject> MemObj(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment