enhance llvm-mc -show-inst to print the enum of an instruction, like so:
[oota-llvm.git] / lib / Target / Blackfin / BlackfinIntrinsicInfo.cpp
1 //===- BlackfinIntrinsicInfo.cpp - Intrinsic Information --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the Blackfin implementation of TargetIntrinsicInfo.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "BlackfinIntrinsicInfo.h"
15 #include "llvm/DerivedTypes.h"
16 #include "llvm/Function.h"
17 #include "llvm/Intrinsics.h"
18 #include "llvm/Module.h"
19 #include "llvm/Type.h"
20 #include "llvm/Support/raw_ostream.h"
21 #include <cstring>
22
23 using namespace llvm;
24
25 namespace bfinIntrinsic {
26
27   enum ID {
28     last_non_bfin_intrinsic = Intrinsic::num_intrinsics-1,
29 #define GET_INTRINSIC_ENUM_VALUES
30 #include "BlackfinGenIntrinsics.inc"
31 #undef GET_INTRINSIC_ENUM_VALUES
32     , num_bfin_intrinsics
33   };
34
35 }
36
37 std::string BlackfinIntrinsicInfo::getName(unsigned IntrID, const Type **Tys,
38                                            unsigned numTys) const {
39   static const char *const names[] = {
40 #define GET_INTRINSIC_NAME_TABLE
41 #include "BlackfinGenIntrinsics.inc"
42 #undef GET_INTRINSIC_NAME_TABLE
43   };
44
45   assert(!isOverloaded(IntrID) && "Blackfin intrinsics are not overloaded");
46   if (IntrID < Intrinsic::num_intrinsics)
47     return 0;
48   assert(IntrID < bfinIntrinsic::num_bfin_intrinsics && "Invalid intrinsic ID");
49
50   std::string Result(names[IntrID - Intrinsic::num_intrinsics]);
51   return Result;
52 }
53
54 unsigned
55 BlackfinIntrinsicInfo::lookupName(const char *Name, unsigned Len) const {
56 #define GET_FUNCTION_RECOGNIZER
57 #include "BlackfinGenIntrinsics.inc"
58 #undef GET_FUNCTION_RECOGNIZER
59   return 0;
60 }
61
62 bool BlackfinIntrinsicInfo::isOverloaded(unsigned IntrID) const {
63   // Overload Table
64   const bool OTable[] = {
65 #define GET_INTRINSIC_OVERLOAD_TABLE
66 #include "BlackfinGenIntrinsics.inc"
67 #undef GET_INTRINSIC_OVERLOAD_TABLE
68   };
69   if (IntrID == 0)
70     return false;
71   else
72     return OTable[IntrID - Intrinsic::num_intrinsics];
73 }
74
75 /// This defines the "getAttributes(ID id)" method.
76 #define GET_INTRINSIC_ATTRIBUTES
77 #include "BlackfinGenIntrinsics.inc"
78 #undef GET_INTRINSIC_ATTRIBUTES
79
80 static const FunctionType *getType(LLVMContext &Context, unsigned id) {
81   const Type *ResultTy = NULL;
82   std::vector<const Type*> ArgTys;
83   bool IsVarArg = false;
84   
85 #define GET_INTRINSIC_GENERATOR
86 #include "BlackfinGenIntrinsics.inc"
87 #undef GET_INTRINSIC_GENERATOR
88
89   return FunctionType::get(ResultTy, ArgTys, IsVarArg); 
90 }
91
92 Function *BlackfinIntrinsicInfo::getDeclaration(Module *M, unsigned IntrID,
93                                                 const Type **Tys,
94                                                 unsigned numTy) const {
95   assert(!isOverloaded(IntrID) && "Blackfin intrinsics are not overloaded");
96   AttrListPtr AList = getAttributes((bfinIntrinsic::ID) IntrID);
97   return cast<Function>(M->getOrInsertFunction(getName(IntrID),
98                                                getType(M->getContext(), IntrID),
99                                                AList));
100 }