Move private header into private directory
[oota-llvm.git] / tools / llc / LLCOptions.cpp
1 // $Id$
2 //**************************************************************************/
3 // File:
4 //      LLCOptions.cpp
5 // 
6 // Purpose:
7 //      Options for the llc compiler.
8 // 
9 // History:
10 //      7/15/01  -  Vikram Adve  -  Created
11 // 
12 //**************************************************************************/
13
14 //************************** System Include Files **************************/
15
16 #include <iostream.h>
17 #include <unistd.h>
18
19
20 //*************************** User Include Files ***************************/
21
22 #include "llvm/Support/ProgramOptions.h"
23 #include "llvm/Support/ProgramOption.h"
24 #include "llvm/LLC/LLCOptions.h"
25
26
27 //---------------------------------------------------------------------------
28 // class LLCOptions
29 //---------------------------------------------------------------------------
30
31 /*ctor*/
32 LLCOptions::LLCOptions (int _argc,
33                         const char* _argv[],
34                         const char* _envp[]) 
35   : ProgramOptions(_argc, _argv, _envp)
36 {
37   InitializeOptions();
38   ParseArgs(argc, argv, envp);
39   CheckParse();
40 }
41
42 /*dtor*/
43 LLCOptions::~LLCOptions()
44 {}
45
46 //--------------------------------------------------------------------
47 // Initialize all our compiler options
48 //--------------------------------------------------------------------
49
50 void
51 LLCOptions::InitializeOptions()
52 {
53   Register(new FlagOption(HELP_OPT,
54                           "print usage message",
55                           false /*initValue*/));
56   
57   Register(new FlagOption(DEBUG_OPT,
58                           "turn on default debugging options",
59                           false /*initValue*/));
60   
61   Register(new FlagOption(DEBUG_OPT,
62                           "turn off all diagnostic messages",
63                           false /*initValue*/));
64   
65   Register(new StringOption(OUTFILENAME_OPT,
66                             "output file name",
67                             "" /*initValue*/));
68   
69   Register(new IntegerValuedOption(DEBUG_INSTR_SELECT_OPT,
70        "control amount of debugging information for instruction selection",
71                                    0 /*initValue*/));
72 }
73
74
75 void
76 LLCOptions::ParseExtraArgs()
77 {
78   if (argsConsumed != argc-1)
79     Usage();
80   
81   // input file name should be the last argument
82   inputFileName = argv[argc-1];
83   
84   // output file name may be specified with -o option;
85   // otherwise create it from the input file name by replace ".ll" with ".o"
86   const string &outfilenameOpt = StringOptionValue(OUTFILENAME_OPT);
87   if (outfilenameOpt.length())
88     {// "-o" option was used
89       outputFileName = outfilenameOpt; 
90     }
91   else
92     {
93       outputFileName = inputFileName;
94       unsigned int suffixPos = outputFileName.rfind(".bc");
95       
96       if (suffixPos >= outputFileName.length())
97         suffixPos = outputFileName.rfind(".ll");
98       
99       if (suffixPos >= outputFileName.length())
100         {
101           cerr << "Unrecognized suffix in file name " << inputFileName << endl;
102           Usage();
103         }
104       
105       outputFileName.replace(suffixPos, 3, ".o"); 
106     }
107 }
108
109 //--------------------------------------------------------------------
110 // Functions that must be overridden in subclass of ProgramOptions
111 //--------------------------------------------------------------------
112
113 void
114 LLCOptions::CheckParse()
115 {}
116
117 void
118 LLCOptions::PrintUsage(ostream& stream) const
119 {
120   stream << "\nUSAGE:\n\t" << ProgramName() << " [options] " 
121          << "llvm-file" << endl << endl;
122   PrintOptions(stream); 
123 }
124
125