1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

Make the Stacker compiler handle -O1 .. -O5 options so it is compliant with

the compiler driver interface as an optimizing translator. Also clean up
error message handling.

llvm-svn: 16165
This commit is contained in:
Reid Spencer 2004-09-04 19:05:53 +00:00
parent 56a134d07a
commit 3d69a86cef
2 changed files with 97 additions and 70 deletions

View File

@ -9,7 +9,10 @@ LEVEL=../../../..
# Give the name of a library. This will build a dynamic version.
#
TOOLNAME=stkrc
USEDLIBS=stkr_compiler asmparser bcwriter vmcore support.a LLVMsystem.a
USEDLIBS=stkr_compiler asmparser bcwriter transforms ipo.a ipa.a \
scalaropts analysis.a target.a transformutils \
vmcore support.a LLVMsystem.a
ifdef PARSE_DEBUG
CPPFLAGS = -DPARSE_DEBUG=1

View File

@ -59,11 +59,34 @@ FlexDebug("x", cl::desc("Turn on Flex Debugging"), cl::Hidden);
static cl::opt<bool>
EchoSource("e", cl::desc("Print Stacker Source as parsed"), cl::Hidden);
enum OptLev {
None = 0,
One = 1,
Two = 2,
Three = 3,
Four = 4,
Five = 5
};
static cl::opt<OptLev> OptLevel(
cl::desc("Choose optimization level to apply:"),
cl::init(One),
cl::values(
clEnumValN(None,"O0","An alias for the -O1 option"),
clEnumValN(One,"O1","Optimize for compilation speed"),
clEnumValN(Two,"O2","Perform simple optimizations to reduce code size"),
clEnumValN(Three,"O3","More aggressive optimizations"),
clEnumValN(Four,"O4","High level of optimization"),
clEnumValN(Five,"O5","An alias for the -O4 option"),
clEnumValEnd
));
int main(int argc, char **argv)
{
cl::ParseCommandLineOptions(argc, argv, " stacker .st -> .bc compiler\n");
std::ostream *Out = 0;
try {
StackerCompiler compiler;
try
{
@ -82,27 +105,25 @@ int main(int argc, char **argv)
// Parse the file now...
std::auto_ptr<Module> M (
compiler.compile(InputFilename,EchoSource, StackSize) );
compiler.compile(InputFilename,EchoSource,OptLevel,StackSize));
if (M.get() == 0) {
std::cerr << argv[0] << ": assembly didn't read correctly.\n";
return 1;
throw std::string("program didn't parse correctly.");
}
if (verifyModule(*M.get())) {
std::cerr << argv[0]
<< ": assembly parsed, but does not verify as correct!\n";
return 1;
throw std::string("program parsed, but does not verify as correct!");
}
if (DumpAsm) std::cerr << "Here's the assembly:\n" << M.get();
if (DumpAsm)
std::cerr << "Here's the assembly:" << M.get();
if (OutputFilename != "") { // Specified an output filename?
if (OutputFilename != "-") { // Not stdout?
if (!Force && std::ifstream(OutputFilename.c_str())) {
// If force is not specified, make sure not to overwrite a file!
std::cerr << argv[0] << ": error opening '" << OutputFilename
<< "': file exists!\n"
<< "Use -f command line argument to force output\n";
throw std::string("error opening '") + OutputFilename +
"': file exists!\n" +
"Use -f command line argument to force output";
return 1;
}
Out = new std::ofstream(OutputFilename.c_str());
@ -126,10 +147,9 @@ int main(int argc, char **argv)
if (!Force && std::ifstream(OutputFilename.c_str())) {
// If force is not specified, make sure not to overwrite a file!
std::cerr << argv[0] << ": error opening '" << OutputFilename
<< "': file exists!\n"
<< "Use -f command line argument to force output\n";
return 1;
throw std::string("error opening '") + OutputFilename +
"': file exists!\n" +
"Use -f command line argument to force output\n";
}
Out = new std::ofstream(OutputFilename.c_str());
@ -140,8 +160,7 @@ int main(int argc, char **argv)
}
if (!Out->good()) {
std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
return 1;
throw std::string("error opening ") + OutputFilename + "!";
}
WriteBytecodeToFile(M.get(), *Out);
@ -149,6 +168,11 @@ int main(int argc, char **argv)
std::cerr << argv[0] << ": " << E.getMessage() << "\n";
return 1;
}
}
catch (const std::string& msg ) {
std::cerr << argv[0] << ": " << msg << "\n";
return 1;
}
if (Out != &std::cout) delete Out;
return 0;