This is an archive of the discontinued LLVM Phabricator instance.

[libclang] Expose some target information via the C API.
ClosedPublic

Authored by emilio on Apr 22 2017, 8:42 AM.

Details

Summary

This allows users to query the target triple and target pointer width, which
would make me able to fix https://github.com/servo/rust-bindgen/issues/593 and
other related bugs in an elegant way (without having to manually parse the
target triple in the command line arguments).

Diff Detail

Repository
rL LLVM

Event Timeline

emilio created this revision.Apr 22 2017, 8:42 AM

I'd appreciate if anyone could point me to an appropriate reviewer for this.

Thanks in advance! :)

Maybe it would be better to introduce a CXTargetInfo type, and change the API to be:

clang_getTranslationUnitTargetInfo
clang_TargetInfo_getTriple
clang_TargetInfo_getPointerWidth

?
This way the TargetInfo functions will be cleanly separated, so we can extend the API easier in the future.

Sounds good to me, will do :)

emilio updated this revision to Diff 96652.Apr 25 2017, 5:12 PM

Updated per comments, I used clang_TargetInfo_dispose following recent APIs instead of clang_disposeTargetInfo, let me know if I should change that.

Also, didn't add a new header for CXTargetInfo, since it's rather small, but can definitely do if needed.

It looks good, I have a couple of comments:

clang/include/clang-c/Index.h
1573 ↗(On Diff #96652)

Please capitalize Info here and in the other parameter lists.

1584 ↗(On Diff #96652)

You could mention that the function returns the width in bits.

clang/test/Index/target-info.c
4 ↗(On Diff #96652)

NIT: Please put both RUN lines at the top of the file.

clang/tools/libclang/CIndex.cpp
4035 ↗(On Diff #96652)

Please add a message to the assert (e.g. && "message").

4048 ↗(On Diff #96652)

Please add an assertion message here as well.

emilio updated this revision to Diff 96834.Apr 26 2017, 3:14 PM

Updated per review comments, thanks :)

arphaman accepted this revision.Apr 28 2017, 7:49 AM

Thanks, LGTM

This revision is now accepted and ready to land.Apr 28 2017, 7:49 AM
This revision was automatically updated to reflect the committed changes.