1 /**************************************************************************
3 * Copyright 2010 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
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"
41 struct printf_test_case
{
46 write_tsv_header(FILE *fp
)
57 typedef void (*test_printf_t
)(int i
);
61 add_printf_test(struct gallivm_state
*gallivm
)
63 LLVMModuleRef module
= gallivm
->module
;
64 LLVMTypeRef args
[1] = { LLVMIntTypeInContext(gallivm
->context
, 32) };
65 LLVMValueRef func
= LLVMAddFunction(module
, "test_printf", LLVMFunctionType(LLVMVoidTypeInContext(gallivm
->context
), args
, 1, 0));
66 LLVMBuilderRef builder
= gallivm
->builder
;
67 LLVMBasicBlockRef block
= LLVMAppendBasicBlockInContext(gallivm
->context
, func
, "entry");
69 LLVMSetFunctionCallConv(func
, LLVMCCallConv
);
71 LLVMPositionBuilderAtEnd(builder
, block
);
72 lp_build_printf(gallivm
, "hello, world\n");
73 lp_build_printf(gallivm
, "print 5 6: %d %d\n", LLVMConstInt(LLVMInt32TypeInContext(gallivm
->context
), 5, 0),
74 LLVMConstInt(LLVMInt32TypeInContext(gallivm
->context
), 6, 0));
76 /* Also test lp_build_assert(). This should not fail. */
77 lp_build_assert(gallivm
, LLVMConstInt(LLVMInt32TypeInContext(gallivm
->context
), 1, 0), "assert(1)");
79 LLVMBuildRetVoid(builder
);
81 gallivm_verify_function(gallivm
, func
);
89 test_printf(unsigned verbose
, FILE *fp
,
90 const struct printf_test_case
*testcase
)
92 struct gallivm_state
*gallivm
;
94 test_printf_t test_printf_func
;
95 boolean success
= TRUE
;
97 gallivm
= gallivm_create("test_module", LLVMGetGlobalContext());
99 test
= add_printf_test(gallivm
);
101 gallivm_compile_module(gallivm
);
103 test_printf_func
= (test_printf_t
) gallivm_jit_function(gallivm
, test
);
105 gallivm_free_ir(gallivm
);
109 gallivm_destroy(gallivm
);
116 test_all(unsigned verbose
, FILE *fp
)
118 boolean success
= TRUE
;
120 test_printf(verbose
, fp
, NULL
);
127 test_some(unsigned verbose
, FILE *fp
,
130 return test_all(verbose
, fp
);
135 test_single(unsigned verbose
, FILE *fp
)
137 printf("no test_single()");