summaryrefslogtreecommitdiffstats
path: root/llvm/support/lib/Support/ProgramOption.cpp
diff options
context:
space:
mode:
authorVikram S. Adve <vadve@cs.uiuc.edu>2001-07-21 12:43:07 +0000
committerVikram S. Adve <vadve@cs.uiuc.edu>2001-07-21 12:43:07 +0000
commit4d709951bba758bd9d88b158b8bf447c7959d3ef (patch)
tree4e34b0732939536056e8b978ad26d0b848615122 /llvm/support/lib/Support/ProgramOption.cpp
parent2d94a344f0b0394da5a5c94f0931fb822d6312ee (diff)
downloadbcm5719-llvm-4d709951bba758bd9d88b158b8bf447c7959d3ef.tar.gz
bcm5719-llvm-4d709951bba758bd9d88b158b8bf447c7959d3ef.zip
Program options class.
llvm-svn: 235
Diffstat (limited to 'llvm/support/lib/Support/ProgramOption.cpp')
-rw-r--r--llvm/support/lib/Support/ProgramOption.cpp138
1 files changed, 138 insertions, 0 deletions
diff --git a/llvm/support/lib/Support/ProgramOption.cpp b/llvm/support/lib/Support/ProgramOption.cpp
new file mode 100644
index 00000000000..2fa987941be
--- /dev/null
+++ b/llvm/support/lib/Support/ProgramOption.cpp
@@ -0,0 +1,138 @@
+// $Id$
+//***************************************************************************
+//
+// File:
+// ProgramOption.C
+//
+// Purpose:
+// General representations for a program option.
+//
+// History:
+// 08/08/95 - adve - created in the dHPF compiler
+// 11/26/96 - adve - EvalOpt now returns #args consumed, or -1 for error
+// 07/15/01 - vadve - Copied to LLVM system and modified
+//
+//**************************************************************************/
+
+//************************** System Include Files **************************/
+
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string>
+
+//*************************** User Include Files ***************************/
+
+#include "llvm/Support/ProgramOption.h"
+
+//********************** Local Variable Definitions ************************/
+
+//************************ Class Implementations ***************************/
+
+
+//**************************************************************************/
+
+StringOption::StringOption(const char* _argString,
+ const char* _helpMesg,
+ const char* _initValue,
+ bool _append)
+ : ProgramOption(_argString, _helpMesg),
+ value(_initValue),
+ append(_append)
+{}
+
+int
+StringOption::EvalOpt(const char* optarg)
+{
+ if (optarg == (char*) NULL)
+ return -1; // flag the error
+
+ if (this->append)
+ value += optarg;
+ else
+ value = optarg;
+
+ optionSpecified = true;
+ return 1; // one additional argument consumed
+}
+
+
+//**************************************************************************/
+
+FlagOption::FlagOption(const char* _argString,
+ const char* _helpMesg,
+ bool _initValue)
+ : ProgramOption(_argString, _helpMesg, 0),
+ value(_initValue)
+{}
+
+int
+FlagOption::EvalOpt(const char* optarg)
+{
+ if (strcmp(optarg, "0") == 0) {
+ value = false;
+ return 1; // one additional argument consumed
+ }
+ else {
+ value = true;
+ return 0; // zero ... consumed
+ }
+}
+
+//**************************************************************************/
+
+RealValuedOption::RealValuedOption(const char* _argString,
+ const char* _helpMesg,
+ double _initValue)
+ : ProgramOption(_argString, _helpMesg),
+ value(_initValue)
+{}
+
+int
+RealValuedOption::EvalOpt(const char* optarg)
+{
+ if (optarg == (char*) NULL)
+ return -1;
+
+ char* lastCharScanned = NULL;
+ value = strtod(optarg, &lastCharScanned);
+ if (! (*lastCharScanned == '\0')) // look for incorrect or partially
+ return -1; // correct numerical argument
+
+ optionSpecified = true;
+ return 1;
+}
+
+char*
+RealValuedOption::GetTextValue() const
+{
+ char buffer[40];
+ sprintf(buffer, "%f", value);
+ return strdup(buffer);
+}
+
+//**************************************************************************/
+
+IntegerValuedOption::IntegerValuedOption(const char* _argString,
+ const char* _helpMesg,
+ int _initValue)
+ : RealValuedOption(_argString, _helpMesg, (double) _initValue)
+{}
+
+int
+IntegerValuedOption::Value() const
+{
+ double realValue = RealValuedOption::Value();
+ assert(realValue == (int) realValue);
+ return (int) realValue;
+}
+
+char*
+IntegerValuedOption::GetTextValue() const
+{
+ char buffer[40];
+ sprintf(buffer, "%d", Value());
+ return strdup(buffer);
+}
+
+//**************************************************************************/
OpenPOWER on IntegriCloud