summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-c-test
diff options
context:
space:
mode:
authorAmaury Sechet <deadalnix@gmail.com>2016-02-16 07:08:49 +0000
committerAmaury Sechet <deadalnix@gmail.com>2016-02-16 07:08:49 +0000
commitf64e834f63fdf1a4a4f316dcef73a7acd14c4e38 (patch)
tree7caad19a76262ad63d3a995c7efdf43cafbf3e1e /llvm/tools/llvm-c-test
parent6ebdc14cf1b240bbd28c46564d50b7ea1f33ecb3 (diff)
downloadbcm5719-llvm-f64e834f63fdf1a4a4f316dcef73a7acd14c4e38.tar.gz
bcm5719-llvm-f64e834f63fdf1a4a4f316dcef73a7acd14c4e38.zip
Generate functions in 2 steps in the C API echo test. NFC
llvm-svn: 260939
Diffstat (limited to 'llvm/tools/llvm-c-test')
-rw-r--r--llvm/tools/llvm-c-test/echo.cpp38
1 files changed, 32 insertions, 6 deletions
diff --git a/llvm/tools/llvm-c-test/echo.cpp b/llvm/tools/llvm-c-test/echo.cpp
index 774e339879d..9dd9b105407 100644
--- a/llvm/tools/llvm-c-test/echo.cpp
+++ b/llvm/tools/llvm-c-test/echo.cpp
@@ -585,27 +585,53 @@ struct FunCloner {
}
};
-static LLVMValueRef clone_function(LLVMValueRef Src, LLVMModuleRef M) {
+static void clone_function(LLVMValueRef Src, LLVMModuleRef M) {
const char *Name = LLVMGetValueName(Src);
LLVMValueRef Fun = LLVMGetNamedFunction(M, Name);
- if (Fun != nullptr)
- return Fun;
+ if (!Fun)
+ report_fatal_error("Function must have been declared already");
- LLVMTypeRef FunTy = LLVMGetElementType(TypeCloner(M).Clone(Src));
- Fun = LLVMAddFunction(M, Name, FunTy);
FunCloner FC(Src, Fun);
FC.CloneBBs(Src);
+}
+
+static void declare_function(LLVMValueRef Src, LLVMModuleRef M) {
+ const char *Name = LLVMGetValueName(Src);
+ LLVMValueRef Fun = LLVMGetNamedFunction(M, Name);
+ if (Fun != nullptr)
+ report_fatal_error("Function already cloned");
- return Fun;
+ LLVMTypeRef FunTy = LLVMGetElementType(TypeCloner(M).Clone(Src));
+ LLVMAddFunction(M, Name, FunTy);
}
static void clone_functions(LLVMModuleRef Src, LLVMModuleRef Dst) {
LLVMValueRef Begin = LLVMGetFirstFunction(Src);
LLVMValueRef End = LLVMGetLastFunction(Src);
+ // First pass, we declare all function
LLVMValueRef Cur = Begin;
LLVMValueRef Next = nullptr;
while (true) {
+ declare_function(Cur, Dst);
+ Next = LLVMGetNextFunction(Cur);
+ if (Next == nullptr) {
+ if (Cur != End)
+ report_fatal_error("Last function does not match End");
+ break;
+ }
+
+ LLVMValueRef Prev = LLVMGetPreviousFunction(Next);
+ if (Prev != Cur)
+ report_fatal_error("Next.Previous function is not Current");
+
+ Cur = Next;
+ }
+
+ // Second pass, we define them
+ Cur = Begin;
+ Next = nullptr;
+ while (true) {
clone_function(Cur, Dst);
Next = LLVMGetNextFunction(Cur);
if (Next == nullptr) {
OpenPOWER on IntegriCloud