summaryrefslogtreecommitdiff
path: root/tools/llc/LLCOptions.cpp
blob: 1f367a2d18382afcbd4bd8ebcc8b47659655a00d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// $Id$
//**************************************************************************/
// File:
//	LLCOptions.cpp
// 
// Purpose:
//	Options for the llc compiler.
// 
// History:
//	7/15/01	 -  Vikram Adve  -  Created
// 
//**************************************************************************/

//************************** System Include Files **************************/

#include <iostream.h>
#include <unistd.h>


//*************************** User Include Files ***************************/

#include "llvm/Support/ProgramOptions.h"
#include "llvm/Support/ProgramOption.h"
#include "LLCOptions.h"


//---------------------------------------------------------------------------
// class LLCOptions
//---------------------------------------------------------------------------

/*ctor*/
LLCOptions::LLCOptions (int _argc,
			const char* _argv[],
			const char* _envp[]) 
  : ProgramOptions(_argc, _argv, _envp)
{
  InitializeOptions();
  ParseArgs(argc, argv, envp);
  CheckParse();
}

/*dtor*/
LLCOptions::~LLCOptions()
{}

//--------------------------------------------------------------------
// Initialize all our compiler options
//--------------------------------------------------------------------

void
LLCOptions::InitializeOptions()
{
  Register(new FlagOption(HELP_OPT,
			  "print usage message",
			  false /*initValue*/));
  
  Register(new FlagOption(DEBUG_OPT,
			  "turn on default debugging options",
			  false /*initValue*/));
  
  Register(new FlagOption(DEBUG_OPT,
			  "turn off all diagnostic messages",
			  false /*initValue*/));
  
  Register(new StringOption(OUTFILENAME_OPT,
			    "output file name",
			    "" /*initValue*/));
  
  Register(new IntegerValuedOption(DEBUG_INSTR_SELECT_OPT,
       "control amount of debugging information for instruction selection",
				   0 /*initValue*/));
}


void
LLCOptions::ParseExtraArgs()
{
  if (argsConsumed != argc-1)
    Usage();
  
  // input file name should be the last argument
  inputFileName = argv[argc-1];
  
  // output file name may be specified with -o option;
  // otherwise create it from the input file name by replace ".ll" with ".o"
  const string &outfilenameOpt = StringOptionValue(OUTFILENAME_OPT);
  if (outfilenameOpt.length())
    {// "-o" option was used
      outputFileName = outfilenameOpt; 
    }
  else
    {
      outputFileName = inputFileName;
      unsigned int suffixPos = outputFileName.rfind(".bc");
      
      if (suffixPos >= outputFileName.length())
	suffixPos = outputFileName.rfind(".ll");
      
      if (suffixPos >= outputFileName.length())
	{
	  cerr << "Unrecognized suffix in file name " << inputFileName << endl;
	  Usage();
	}
      
      outputFileName.replace(suffixPos, 3, ".o"); 
    }
}

//--------------------------------------------------------------------
// Functions that must be overridden in subclass of ProgramOptions
//--------------------------------------------------------------------

void
LLCOptions::CheckParse()
{}

void
LLCOptions::PrintUsage(ostream& stream) const
{
  stream << "\nUSAGE:\n\t" << ProgramName() << " [options] " 
	 << "llvm-file" << endl << endl;
  PrintOptions(stream); 
}