//===- LLVMCConfigurationEmitter.cpp - Generate LLVMC config --------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open
// Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This tablegen backend is responsible for emitting LLVMC configuration code.
//
//===----------------------------------------------------------------------===//
#include "LLVMCConfigurationEmitter.h"
#include "Record.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/Streams.h"
#include <algorithm>
#include <cassert>
#include <functional>
#include <string>
using namespace llvm;
namespace {
//===----------------------------------------------------------------------===//
/// Typedefs
typedef std::vector<Record*> RecordVector;
typedef std::vector<std::string> StrVector;
//===----------------------------------------------------------------------===//
/// Constants
// Indentation strings.
const char * Indent1 = " ";
const char * Indent2 = " ";
const char * Indent3 = " ";
const char * Indent4 = " ";
// Default help string.
const char * DefaultHelpString = "NO HELP MESSAGE PROVIDED";
// Name for the "sink" option.
const char * SinkOptionName = "AutoGeneratedSinkOption";
//===----------------------------------------------------------------------===//
/// Helper functions
std::string InitPtrToString(Init* ptr) {
StringInit& val = dynamic_cast<StringInit&>(*ptr);
return val.getValue();
}
int InitPtrToInt(Init* ptr) {
IntInit& val = dynamic_cast<IntInit&>(*ptr);
return val.getValue();
}
const DagInit& InitPtrToDagInitRef(Init* ptr) {
DagInit& val = dynamic_cast<DagInit&>(*ptr);
return val;
}
// checkNumberOfArguments - Ensure that the number of args in d is
// less than or equal to min_arguments, otherwise throw an exception .
void checkNumberOfArguments (const DagInit* d, unsigned min_arguments) {
if (d->getNumArgs() < min_arguments)
throw "Property " + d->getOperator()->getAsString()
+ " has too few arguments!";
}
//===----------------------------------------------------------------------===//
/// Back-end specific code
// A command-line option can have one of the following types:
//
// Switch - a simple switch w/o arguments, e.g. -O2
//
// Parameter - an option that takes one(and only one) argument, e.g. -o file,
// --output=file
//
// ParameterList - same as Parameter, but more than one occurence
// of the option is allowed, e.g. -lm -lpthread
//
// Prefix - argument is everything after the prefix,
// e.g. -Wa,-foo,-bar, -DNAME=VALUE
//
// PrefixList - same as Prefix, but more than one option occurence is
// allowed
namespace OptionType {
enum OptionType { Switch, Parameter, ParameterList, Prefix, PrefixList};
}
bool IsListOptionType (OptionType::OptionType t) {
return (t == OptionType::ParameterList || t == OptionType::PrefixList);
}
// Code duplication here is necessary because one option can affect
// several tools and those tools may have different actions associated
// with this option. GlobalOptionDescriptions are used to generate
// the option registration code, while ToolOptionDescriptions are used
// to generate tool-specific code.
/// OptionDescription - Base class for option descriptions.
struct OptionDescription {
OptionType::OptionType