summaryrefslogtreecommitdiff
path: root/utils/TableGen/IntrinsicEmitter.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-03-03 02:32:46 +0000
committerChris Lattner <sabre@nondot.org>2006-03-03 02:32:46 +0000
commit9e493cfcc32aee58e6750ce1efa52d5c3bc3f893 (patch)
tree041552b29e7c173fa470ea821de2601ef1d46167 /utils/TableGen/IntrinsicEmitter.cpp
parent86d064d44caf81e03b4233863747aebb3d0fba9a (diff)
downloadllvm-9e493cfcc32aee58e6750ce1efa52d5c3bc3f893.tar.gz
llvm-9e493cfcc32aee58e6750ce1efa52d5c3bc3f893.tar.bz2
llvm-9e493cfcc32aee58e6750ce1efa52d5c3bc3f893.tar.xz
initial implementation of intrinsic parsing
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26495 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/IntrinsicEmitter.cpp')
-rw-r--r--utils/TableGen/IntrinsicEmitter.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/utils/TableGen/IntrinsicEmitter.cpp b/utils/TableGen/IntrinsicEmitter.cpp
new file mode 100644
index 0000000000..dd4324ee11
--- /dev/null
+++ b/utils/TableGen/IntrinsicEmitter.cpp
@@ -0,0 +1,70 @@
+//===- IntrinsicEmitter.cpp - Generate intrinsic information --------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This tablegen backend emits information about intrinsic functions.
+//
+//===----------------------------------------------------------------------===//
+
+#include "IntrinsicEmitter.h"
+#include "Record.h"
+using namespace llvm;
+
+//===----------------------------------------------------------------------===//
+// CodeGenIntrinsic Implementation
+//===----------------------------------------------------------------------===//
+
+std::vector<CodeGenIntrinsic> llvm::LoadIntrinsics(const RecordKeeper &RC) {
+ std::vector<Record*> I = RC.getAllDerivedDefinitions("Intrinsic");
+ return std::vector<CodeGenIntrinsic>(I.begin(), I.end());
+}
+
+CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
+ std::string DefName = R->getName();
+
+ if (DefName.size() <= 4 ||
+ std::string(DefName.begin(), DefName.begin()+4) != "int_")
+ throw "Intrinsic '" + DefName + "' does not start with 'int_'!";
+ EnumName = std::string(DefName.begin()+4, DefName.end());
+
+ Name = R->getValueAsString("LLVMName");
+ if (Name == "") {
+ // If an explicit name isn't specified, derive one from the DefName.
+ Name = "llvm.";
+ for (unsigned i = 0, e = EnumName.size(); i != e; ++i)
+ if (EnumName[i] == '_')
+ Name += '.';
+ else
+ Name += EnumName[i];
+ }
+}
+
+//===----------------------------------------------------------------------===//
+// IntrinsicEmitter Implementation
+//===----------------------------------------------------------------------===//
+
+void IntrinsicEmitter::run(std::ostream &OS) {
+ EmitSourceFileHeader("Intrinsic Function Source Fragment", OS);
+
+ std::vector<CodeGenIntrinsic> Ints = LoadIntrinsics(Records);
+
+ // Emit the enum information.
+ EmitEnumInfo(Ints, OS);
+}
+
+void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
+ std::ostream &OS) {
+ OS << "#ifdef GET_INTRINSIC_ENUM_VALUES\n";
+ for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
+ OS << " " << Ints[i].EnumName;
+ OS << ((i != e-1) ? ", " : " ");
+ OS << std::string(40-Ints[i].EnumName.size(), ' ')
+ << "// " << Ints[i].Name << "\n";
+ }
+ OS << "#endif\n\n";
+}