llvmpipe: remove misleading debug string
[mesa.git] / src / gallium / drivers / llvmpipe / lp_test_printf.c
1 /**************************************************************************
2 *
3 * Copyright 2010 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include <stdlib.h>
30 #include <stdio.h>
31
32 #include "util/u_pointer.h"
33 #include "gallivm/lp_bld.h"
34 #include "gallivm/lp_bld_init.h"
35 #include "gallivm/lp_bld_assert.h"
36 #include "gallivm/lp_bld_printf.h"
37
38 #include <llvm-c/Analysis.h>
39 #include <llvm-c/ExecutionEngine.h>
40 #include <llvm-c/Target.h>
41 #include <llvm-c/Transforms/Scalar.h>
42
43 #include "lp_test.h"
44
45
46 struct printf_test_case {
47 int foo;
48 };
49
50 void
51 write_tsv_header(FILE *fp)
52 {
53 fprintf(fp,
54 "result\t"
55 "format\n");
56
57 fflush(fp);
58 }
59
60
61
62 typedef void (*test_printf_t)(int i);
63
64
65 static LLVMValueRef
66 add_printf_test(LLVMModuleRef module)
67 {
68 LLVMTypeRef args[1] = { LLVMIntType(32) };
69 LLVMValueRef func = LLVMAddFunction(module, "test_printf", LLVMFunctionType(LLVMVoidType(), args, 1, 0));
70 LLVMBuilderRef builder = LLVMCreateBuilder();
71 LLVMBasicBlockRef block = LLVMAppendBasicBlock(func, "entry");
72
73 LLVMSetFunctionCallConv(func, LLVMCCallConv);
74
75 LLVMPositionBuilderAtEnd(builder, block);
76 lp_build_printf(builder, "hello, world\n");
77 lp_build_printf(builder, "print 5 6: %d %d\n", LLVMConstInt(LLVMInt32Type(), 5, 0),
78 LLVMConstInt(LLVMInt32Type(), 6, 0));
79
80 /* Also test lp_build_assert(). This should not fail. */
81 lp_build_assert(builder, LLVMConstInt(LLVMInt32Type(), 1, 0), "assert(1)");
82
83 LLVMBuildRetVoid(builder);
84 LLVMDisposeBuilder(builder);
85 return func;
86 }
87
88
89 PIPE_ALIGN_STACK
90 static boolean
91 test_printf(unsigned verbose, FILE *fp, const struct printf_test_case *testcase)
92 {
93 LLVMModuleRef module = NULL;
94 LLVMValueRef test = NULL;
95 LLVMExecutionEngineRef engine = NULL;
96 LLVMModuleProviderRef provider = NULL;
97 LLVMPassManagerRef pass = NULL;
98 char *error = NULL;
99 test_printf_t test_printf;
100 float unpacked[4];
101 unsigned packed;
102 boolean success = TRUE;
103 void *code;
104
105 module = LLVMModuleCreateWithName("test");
106
107 test = add_printf_test(module);
108
109 if(LLVMVerifyModule(module, LLVMPrintMessageAction, &error)) {
110 LLVMDumpModule(module);
111 abort();
112 }
113 LLVMDisposeMessage(error);
114
115 provider = LLVMCreateModuleProviderForExistingModule(module);
116 #if 0
117 if (LLVMCreateJITCompiler(&engine, provider, 1, &error)) {
118 fprintf(stderr, "%s\n", error);
119 LLVMDisposeMessage(error);
120 abort();
121 }
122 #else
123 (void) provider;
124 engine = lp_build_engine;
125 #endif
126
127 #if 0
128 pass = LLVMCreatePassManager();
129 LLVMAddTargetData(LLVMGetExecutionEngineTargetData(engine), pass);
130 /* These are the passes currently listed in llvm-c/Transforms/Scalar.h,
131 * but there are more on SVN. */
132 LLVMAddConstantPropagationPass(pass);
133 LLVMAddInstructionCombiningPass(pass);
134 LLVMAddPromoteMemoryToRegisterPass(pass);
135 LLVMAddGVNPass(pass);
136 LLVMAddCFGSimplificationPass(pass);
137 LLVMRunPassManager(pass, module);
138 #else
139 (void)pass;
140 #endif
141
142 code = LLVMGetPointerToGlobal(engine, test);
143 test_printf = (test_printf_t)pointer_to_func(code);
144
145 memset(unpacked, 0, sizeof unpacked);
146 packed = 0;
147
148
149 // LLVMDumpModule(module);
150
151 test_printf(0);
152
153 LLVMFreeMachineCodeForFunction(engine, test);
154
155 LLVMDisposeExecutionEngine(engine);
156 if(pass)
157 LLVMDisposePassManager(pass);
158
159 return success;
160 }
161
162
163 boolean
164 test_all(unsigned verbose, FILE *fp)
165 {
166 boolean success = TRUE;
167
168 test_printf(verbose, fp, NULL);
169
170 return success;
171 }
172
173
174 boolean
175 test_some(unsigned verbose, FILE *fp, unsigned long n)
176 {
177 return test_all(verbose, fp);
178 }
179
180
181 boolean
182 test_single(unsigned verbose, FILE *fp)
183 {
184 printf("no test_single()");
185 return TRUE;
186 }