[llvm-commits] Use "LLVMBool" instead of "int" for booleans in llvm-c API
James Y Knight
foom at fuhm.net
Mon Dec 21 15:54:11 PST 2009
In order to ease automatic bindings generation, it would be helpful if
boolean values were distinguishable from integers. The attached patch
introduces "typedef int LLVMBool;", and uses LLVMBool instead of int
throughout the C API, wherever a boolean value is called for.
This should have no impact, but it allows me to put the following:
%typemap(cin) LLVMBool ":boolean";
%typemap(cout) LLVMBool ":boolean";
in my swig .i file, and have it map LLVMBool to a boolean type in the
bindings, instead of treating it as an integer.
The attached patch also includes the following two tangentially
related changes:
1) The following change seems trivially correct, but I'm not sure why
it was not originally done like this. It makes the autogenerated
wrapper nicer.
-enum { LLVMBigEndian, LLVMLittleEndian };
-typedef int LLVMByteOrdering;
+enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
...Although, I don't know why this API uses an enum in any case. The
obvious wrapper would have been:
LLVMBool LLVMIsLittleEndian(LLVMTargetDataRef TD) {
return unwrap(TD)->isLittleEndian();
}
...I suppose someone had a reason to not do that? *shrug*
2) While making these changes, I noticed that the function declaration
for LLVMConstInlineAsm didn't match the function definition, and fixed
it:
-LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
+LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
const char *AsmString, const char
*Constraints,
- int HasSideEffects);
+ LLVMBool HasSideEffects, LLVMBool
IsAlignStack);
But i'm not sure if was correct procedure to fix the prototype, or if
the function body should be adjusted to match the prototype instead...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LLVM-Bool.patch
Type: application/octet-stream
Size: 34682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20091221/7139d1c1/attachment.obj>
-------------- next part --------------
PS:
The bindings I'm creating are for Common-Lisp, and are available here: http://repo.or.cz/w/cl-llvm.git/
James
More information about the llvm-commits
mailing list