This is an archive of the discontinued LLVM Phabricator instance.

TableGen backend to generate an index in ctags(1) format.
Needs ReviewPublic

Authored by kpschoedel on Mar 15 2013, 11:49 AM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

TableGen backend to generate an index in ctags(1) format.

Example use:

$ cd $SRCDIR/lib/Target/$TARGET
$ llvm-tblgen -I=../../../include --gen-ctags $TGT.td >tags

To use this in conjunction with exuberant ctags to generate a single
combined tags file, run tblgen first and then

$ ctags --append [...]

Since some identifiers have corresponding definitions in C++ code,
it can be useful (if using vim) to also use cscope, and

:set cscopetagorder=1

so that

:tag X

will preferentially select the tablegen symbol, while

:cscope find g X

will always find the C++ symbol.

Diff Detail

Event Timeline

I doesn't seem reasonable to be invoking this by hand. Maybe also add a utility script or something that will index all the tablegen files in the project?

kpschoedel updated this revision to Unknown Object (????).Mar 18 2013, 11:45 AM

Thanks for the feedback.

There doesn't seem to be a good way to identify which files to run llvm-tblgen on without involving the build system (or replicating information from it); that is not done for normal C++ tags, so I didn't want to do it here. (This is not a problem from ctags(1), which merely scans individual source files and does not require them to be buildable.) The added script tries to guess reasonably well, and can be told to shut tblgen up in the cases it gets wrong.

Tested on Linux and OS X.

ping?

I've played with this and it works really well.

silvas added inline comments.Mar 19 2013, 8:45 AM
utils/TableGen/CTagsEmitter.cpp
11

Cross-reference the helper script here.

utils/TableGen/tdtags
1–18 ↗(On Diff #1308)

TBQH this is probably the best example of shell scripting I've ever seen (i.e. it's very readable and organized). I honestly wish I could code shell like this.

Despite that, as far as maintainability is concerned, I really don't think that shell is the best language for this script. Pragmatically, I wouldn't trust myself to maintain this file and uphold the same code quality that you have set forth here. Are you familiar enough with Python to write this in Python? For these kinds of scripts, Python seems to be the de facto choice for LLVM. Additionally, Python is, broadly speaking, more portable than shell (for example, Python's platform abstraction extends to Windows as well, while shell is not a "first class citizen" there).

I'd like to emphasize that this script is masterfully written. My concern is that writing correct and robust shell is somewhat of a black art, which hampers the maintainability. I would be glad to point you in the right direction (which API's are best to use, etc.) for a Python script if you aren't familiar.

@silvas
I know this has been discussed before (e.g. in this bug report: http://llvm.org/bugs/show_bug.cgi?id=12900) but python is still not being very "portably used" and I still have to manually link which python to which python2 to get the build system to work on my Archlinux where which python is linked to which python3 by default (and I am sure this problem exists on other distros like archbang etc.).

Yeah, I'm stuck in the '90s, where ‘script’ automatically means ‘shell’. I'm not a Python expert, but I expect I can manage. Are there specific Python scripts in the tree that are particularly good examples of the ideal style?

Does the script functionality seem reasonable? We have been using tblgen tags so far only to navigate our back end, so I'm not so sure about other uses (e.g. in clang).

sdt added a comment.Mar 19 2013, 11:08 AM

If the script works today, rewriting it in Python now seems unnecessary. Sounds like Kevin will use Python for future scripts, but since this is just a little utility, I think it's fine.

(I have to say I giggled when I saw the size and quality of this script given that it was in response to a one-liner request for improvement :))

I'm certainly willing to redo the script, and it should be easy (a language with arrays?!? Luxury!), but I might not get to it for a week or two. I'm happy to entertain comments on the current or desired functionality in the interim.

silvas added inline comments.Mar 19 2013, 7:30 PM
utils/TableGen/tdtags
2 ↗(On Diff #1308)

typo: s/tdtabs/tdtags/

kpschoedel updated this revision to Unknown Object (????).Mar 20 2013, 9:39 AM

Addressed review comments:

  • Reference the helper script here in the tblgen backend.
  • Fix typo in tblgen backend.
kpschoedel updated this revision to Unknown Object (????).Mar 21 2013, 8:45 AM

Rebased against r177639.

Committed as r177682. Please keep an eye on the bots and the commit email in case any issues come up. If possible be on IRC to reduce response latency.