2013-05-31 10:12:34 +08:00
|
|
|
//===- lld/unittest/DriverTest.h ------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lld/Driver/Driver.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2014-10-18 13:33:55 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include <stdarg.h>
|
2013-05-31 10:12:34 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace lld;
|
|
|
|
|
2013-07-17 02:45:57 +08:00
|
|
|
template<typename D, typename T>
|
2013-05-31 10:12:34 +08:00
|
|
|
class ParserTest : public testing::Test {
|
|
|
|
protected:
|
2013-07-17 02:45:57 +08:00
|
|
|
|
2013-08-07 06:31:59 +08:00
|
|
|
virtual const LinkingContext *linkingContext() = 0;
|
2013-07-27 01:08:12 +08:00
|
|
|
|
2013-07-17 02:45:57 +08:00
|
|
|
std::string &errorMessage() { return _errorMessage; }
|
2013-07-27 01:08:12 +08:00
|
|
|
|
2013-07-17 02:45:57 +08:00
|
|
|
// Convenience method for getting number of input files.
|
2014-04-04 08:14:04 +08:00
|
|
|
int inputFileCount() { return linkingContext()->getInputGraph().size(); }
|
2013-05-31 10:12:34 +08:00
|
|
|
|
2013-07-17 02:45:57 +08:00
|
|
|
// Convenience method for getting i'th input files name.
|
2013-12-05 21:07:49 +08:00
|
|
|
std::string inputFile(int index) {
|
2014-05-06 08:50:46 +08:00
|
|
|
const InputElement &inputElement =
|
|
|
|
*linkingContext()->getInputGraph().inputElements()[index];
|
2013-08-22 06:57:10 +08:00
|
|
|
if (inputElement.kind() == InputElement::Kind::File)
|
2014-04-02 02:04:56 +08:00
|
|
|
return *cast<FileNode>(&inputElement)->getPath(*linkingContext());
|
2013-08-22 23:23:54 +08:00
|
|
|
llvm_unreachable("not handling other types of input files");
|
2013-07-17 02:45:57 +08:00
|
|
|
}
|
2013-05-31 10:12:34 +08:00
|
|
|
|
2013-07-17 02:45:57 +08:00
|
|
|
// For unit tests to call driver with various command lines.
|
|
|
|
bool parse(const char *args, ...) {
|
2013-05-31 10:12:34 +08:00
|
|
|
// Construct command line options from varargs.
|
|
|
|
std::vector<const char *> vec;
|
|
|
|
vec.push_back(args);
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, args);
|
|
|
|
while (const char *arg = va_arg(ap, const char *))
|
|
|
|
vec.push_back(arg);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
// Call the parser.
|
2013-07-17 02:45:57 +08:00
|
|
|
raw_string_ostream os(_errorMessage);
|
2013-08-07 06:31:59 +08:00
|
|
|
return D::parse(vec.size(), &vec[0], _context, os);
|
2013-05-31 10:12:34 +08:00
|
|
|
}
|
|
|
|
|
2013-08-07 06:31:59 +08:00
|
|
|
T _context;
|
2013-07-17 02:45:57 +08:00
|
|
|
std::string _errorMessage;
|
2013-05-31 10:12:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|