blob: dd4324ee11c28dd6cba4910add4d78cd488bedc6 [file] [log] [blame]
Chris Lattner9e493cf2006-03-03 02:32:46 +00001//===- IntrinsicEmitter.cpp - Generate intrinsic information --------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This tablegen backend emits information about intrinsic functions.
11//
12//===----------------------------------------------------------------------===//
13
14#include "IntrinsicEmitter.h"
15#include "Record.h"
16using namespace llvm;
17
18//===----------------------------------------------------------------------===//
19// CodeGenIntrinsic Implementation
20//===----------------------------------------------------------------------===//
21
22std::vector<CodeGenIntrinsic> llvm::LoadIntrinsics(const RecordKeeper &RC) {
23 std::vector<Record*> I = RC.getAllDerivedDefinitions("Intrinsic");
24 return std::vector<CodeGenIntrinsic>(I.begin(), I.end());
25}
26
27CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
28 std::string DefName = R->getName();
29
30 if (DefName.size() <= 4 ||
31 std::string(DefName.begin(), DefName.begin()+4) != "int_")
32 throw "Intrinsic '" + DefName + "' does not start with 'int_'!";
33 EnumName = std::string(DefName.begin()+4, DefName.end());
34
35 Name = R->getValueAsString("LLVMName");
36 if (Name == "") {
37 // If an explicit name isn't specified, derive one from the DefName.
38 Name = "llvm.";
39 for (unsigned i = 0, e = EnumName.size(); i != e; ++i)
40 if (EnumName[i] == '_')
41 Name += '.';
42 else
43 Name += EnumName[i];
44 }
45}
46
47//===----------------------------------------------------------------------===//
48// IntrinsicEmitter Implementation
49//===----------------------------------------------------------------------===//
50
51void IntrinsicEmitter::run(std::ostream &OS) {
52 EmitSourceFileHeader("Intrinsic Function Source Fragment", OS);
53
54 std::vector<CodeGenIntrinsic> Ints = LoadIntrinsics(Records);
55
56 // Emit the enum information.
57 EmitEnumInfo(Ints, OS);
58}
59
60void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
61 std::ostream &OS) {
62 OS << "#ifdef GET_INTRINSIC_ENUM_VALUES\n";
63 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
64 OS << " " << Ints[i].EnumName;
65 OS << ((i != e-1) ? ", " : " ");
66 OS << std::string(40-Ints[i].EnumName.size(), ' ')
67 << "// " << Ints[i].Name << "\n";
68 }
69 OS << "#endif\n\n";
70}