#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"
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);
/* 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]);
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;
+}
}
+LLVMValueRef
+lp_build_const_string(struct gallivm_state *gallivm,
+ const char *str);
#endif /* !LP_BLD_CONST_H */
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.
*
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++) {
#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,