if (cmd.size() == 5)
throw std::string("$ENV invocation: empty argument list!");
- ret += "std::getenv(\"";
+ ret += "checkCString(std::getenv(\"";
ret += std::string(cmd.begin() + 5, cmd.begin() + cparen);
- ret += "\")";
+ ret += "\"))";
}
else {
throw "Unknown special command: " + cmd;
<< "static llvmc::RegisterPlugin<Plugin> RP;\n\n}\n\n";
}
-/// EmitInclude - Emit necessary #include directives.
+/// EmitIncludes - Emit necessary #include directives and some
+/// additional declarations.
void EmitIncludes(std::ostream& O) {
O << "#include \"llvm/CompilerDriver/CompilationGraph.h\"\n"
<< "#include \"llvm/CompilerDriver/Plugin.h\"\n"
<< "using namespace llvm;\n"
<< "using namespace llvmc;\n\n"
- << "extern cl::opt<std::string> OutputFilename;\n\n";
+ << "extern cl::opt<std::string> OutputFilename;\n\n"
+
+ << "inline const char* checkCString(const char* s)\n"
+ << "{ return s == NULL ? \"\" : s; }\n\n";
}
// End of anonymous namespace