//===- NeonEmitter.cpp - Generate arm_neon.h for use with clang -*- C++ -*-===//
//
// 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 arm_neon.h, which includes
// a declaration and definition of each function specified by the ARM NEON
// compiler interface. See ARM document DUI0348B.
//
//===----------------------------------------------------------------------===//
#include "NeonEmitter.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include <string>
using namespace llvm;
static void ParseTypes(Record *r, std::string &s,
SmallVectorImpl<StringRef> &TV) {
const char *data = s.data();
int len = 0;
for (unsigned i = 0, e = s.size(); i != e; ++i, ++len) {
if (data[len] == 'P' || data[len] == 'Q' || data[len] == 'U')
continue;
switch (data[len]) {
case 'c':
case 's':
case 'i':
case 'l':
case 'h':
case 'f':
break;
default:
throw TGError(r->getLoc(),
"Unexpected letter: " + std::string(data + len, 1));
break;
}
TV.push_back(StringRef(data, len + 1));
data += len + 1;
len = -1;
}
}
static char Widen(const char t) {
switch (t) {
case 'c':
return 's';
case 's':
return 'i';
case 'i':
return 'l';
default: throw "unhandled type in widen!";
}
return '\0';
}
static char Narrow(const char t) {
switch (t) {
case 's':
return 'c';
case 'i':
return 's';
case 'l':
return 'i';
case 'f':
return 'h';
default: throw "unhandled type in widen!";
}
return '\0';
}
static char ClassifyType(StringRef ty, bool &quad, bool &poly, bool &usgn) {
unsigned off = 0;
// remember quad.
if (ty[off] == 'Q') {
quad = true;
++off;
}
// remember poly.
if (ty[off] == 'P') {
poly = true;
++off;
}
// remember unsigned.
if (ty[off] == 'U') {
usgn = true;
++off;
}
// base type to get the type string for.
return ty[off];
}
static char ModType(const char mod, char type, bool &quad, bool &poly,
bool &usgn, bool &scal, bool &cnst, bool &pntr) {
switch (mod) {
case 't':
if (poly) {
poly = false;
usgn = true;
}
break;
case 'u':
usgn = true;
case 'x':
poly = false;
if (type == 'f')
type = 'i';
break;
case 'f':
if (type == 'h')
quad = true;
type = 'f';
usgn = false;
break;
case 'w':
type = Widen(type);
quad = true;
break;
case 'n':
type = Widen(type);
break;
case 'l':
type = 'l';
scal = true;
usgn = true;
break;
case 's':
scal = true;
break;
case 'k':
quad = true;
break;
case 'c':
cnst = true;
case 'p':
usgn = false;
poly = false;
pntr = true;
scal = true;
break;
case 'h':
type = Narrow(type);
if (type == 'h')
quad = false;
break;
case 'e':
type = Narrow(type);
usgn = true;
break;
default:
break;
}
return type;
}
static std::string TypeString(const char mod, StringRef typestr,
bool