summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary
diff options
context:
space:
mode:
authorJosé Fonseca <[email protected]>2012-02-23 09:44:41 +0000
committerJosé Fonseca <[email protected]>2012-05-02 10:24:34 +0100
commit0005bd9da2b343accad423708eba36a00035c7ee (patch)
tree4f081d9646bf90724a1e845ad7051f9e4c77ecdf /src/gallium/auxiliary
parentc23fd547c060c4137eab0f878a1028c5903384eb (diff)
gallivm: Cleanup/simplify lp_build_const_string_variable.
- Move to lp_bld_const where it belongs - Rename to lp_build_const_string - take the length from the argument (and don't count the zero terminator twice) - bitcast the constant to generic i8 *
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_assert.c6
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_const.c18
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_const.h3
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_printf.c22
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_printf.h9
5 files changed, 29 insertions, 29 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_assert.c b/src/gallium/auxiliary/gallivm/lp_bld_assert.c
index 9de5e8e7b51..449d0a7c014 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_assert.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_assert.c
@@ -29,6 +29,7 @@
#include "util/u_memory.h"
#include "lp_bld_assert.h"
#include "lp_bld_init.h"
+#include "lp_bld_const.h"
#include "lp_bld_printf.h"
@@ -66,8 +67,7 @@ lp_build_assert(struct gallivm_state *gallivm,
LLVMTypeRef arg_types[2];
LLVMValueRef msg_string, assert_func, params[2], r;
- msg_string = lp_build_const_string_variable(module, context,
- msg, strlen(msg) + 1);
+ msg_string = lp_build_const_string(gallivm, msg);
arg_types[0] = LLVMInt32TypeInContext(context);
arg_types[1] = LLVMPointerType(LLVMInt8TypeInContext(context), 0);
@@ -90,7 +90,7 @@ lp_build_assert(struct gallivm_state *gallivm,
/* build function call param list */
params[0] = LLVMBuildZExt(builder, condition, arg_types[0], "");
- params[1] = LLVMBuildBitCast(builder, msg_string, arg_types[1], "");
+ params[1] = msg_string;
/* check arg types */
assert(LLVMTypeOf(params[0]) == arg_types[0]);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.c b/src/gallium/auxiliary/gallivm/lp_bld_const.c
index 77ec1a70860..9e9dc442733 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_const.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_const.c
@@ -428,3 +428,21 @@ lp_build_const_mask_aos_swizzled(struct gallivm_state *gallivm,
return lp_build_const_mask_aos(gallivm, type, mask);
}
+
+
+/**
+ * Build a zero-terminated constant string.
+ */
+LLVMValueRef
+lp_build_const_string(struct gallivm_state *gallivm,
+ const char *str)
+{
+ unsigned len = strlen(str) + 1;
+ LLVMTypeRef i8 = LLVMInt8TypeInContext(gallivm->context);
+ LLVMValueRef string = LLVMAddGlobal(gallivm->module, LLVMArrayType(i8, len), "");
+ LLVMSetGlobalConstant(string, TRUE);
+ LLVMSetLinkage(string, LLVMInternalLinkage);
+ LLVMSetInitializer(string, LLVMConstStringInContext(gallivm->context, str, len, TRUE));
+ string = LLVMConstBitCast(string, LLVMPointerType(i8, 0));
+ return string;
+}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.h b/src/gallium/auxiliary/gallivm/lp_bld_const.h
index fd398516952..34c3c691377 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_const.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_const.h
@@ -149,5 +149,8 @@ lp_build_const_int_pointer(struct gallivm_state *gallivm, const void *ptr)
}
+LLVMValueRef
+lp_build_const_string(struct gallivm_state *gallivm,
+ const char *str);
#endif /* !LP_BLD_CONST_H */
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.c b/src/gallium/auxiliary/gallivm/lp_bld_printf.c
index 5aa802d9670..806b8e0d085 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_printf.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.c
@@ -66,19 +66,6 @@ lp_get_printf_arg_count(const char *fmt)
return count;
}
-LLVMValueRef
-lp_build_const_string_variable(LLVMModuleRef module,
- LLVMContextRef context,
- const char *str, int len)
-{
- LLVMValueRef string = LLVMAddGlobal(module, LLVMArrayType(LLVMInt8TypeInContext(context), len + 1), "");
- LLVMSetGlobalConstant(string, TRUE);
- LLVMSetLinkage(string, LLVMInternalLinkage);
- LLVMSetInitializer(string, LLVMConstStringInContext(context, str, len + 1, TRUE));
- return string;
-}
-
-
/**
* lp_build_printf.
*
@@ -96,22 +83,17 @@ lp_build_printf(struct gallivm_state *gallivm, const char *fmt, ...)
LLVMContextRef context = gallivm->context;
LLVMModuleRef module = gallivm->module;
LLVMValueRef params[50];
- LLVMValueRef fmtarg = lp_build_const_string_variable(module, context,
- fmt, strlen(fmt) + 1);
- LLVMValueRef int0 = lp_build_const_int32(gallivm, 0);
- LLVMValueRef index[2];
+ LLVMValueRef fmtarg = lp_build_const_string(gallivm, fmt);
LLVMValueRef func_printf = LLVMGetNamedFunction(module, "printf");
assert(Elements(params) >= argcount + 1);
- index[0] = index[1] = int0;
-
if (!func_printf) {
LLVMTypeRef printf_type = LLVMFunctionType(LLVMIntTypeInContext(context, 32), NULL, 0, 1);
func_printf = LLVMAddFunction(module, "printf", printf_type);
}
- params[0] = LLVMBuildGEP(builder, fmtarg, index, 2, "");
+ params[0] = fmtarg;
va_start(arglist, fmt);
for (i = 1; i <= argcount; i++) {
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.h b/src/gallium/auxiliary/gallivm/lp_bld_printf.h
index ec087fd4015..7a2b26d41f4 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_printf.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.h
@@ -34,12 +34,9 @@
#include "lp_bld_init.h"
-LLVMValueRef lp_build_const_string_variable(LLVMModuleRef module,
- LLVMContextRef context,
- const char *str, int len);
-
-LLVMValueRef lp_build_printf(struct gallivm_state *gallivm,
- const char *fmt, ...);
+LLVMValueRef
+lp_build_printf(struct gallivm_state *gallivm,
+ const char *fmt, ...);
LLVMValueRef
lp_build_print_vec4(struct gallivm_state *gallivm,