[cfe-dev] Clang Python Bindings - Reading AST file dumped by clang
Jason Haslam via cfe-dev
cfe-dev at lists.llvm.org
Thu Dec 10 11:47:20 PST 2015
> On Dec 10, 2015, at 11:43 AM, Daniel Kats <dbkats at cs.toronto.edu> wrote:
> Hi Jason,
> The benefit of clang-cl is it sets up all the include headers for libclang on Windows, which I am having trouble specifying to libclang directly.
clang-cl is mostly for parsing cl.exe command line arguments. You can get windows search paths (and other windows behaviors) by setting an appropriate target in the command line arguments you use to initialize the translation unit (e.g -target x86_64-pc-windows).
> Also, in the Python bindings documentation for clang, it says that the index.read function:
> """Load a TranslationUnit from the given AST file."""
> Maybe I misunderstand what that means, but is it not meant to load AST files generated by -emit-ast or -ast-dump?
-ast-dump doesn’t write an AST file. It prints out a textual representation of the AST for human consumption. There are command line options for writing a serialized AST file (e.g. the ones related to PCH and modules), and they can probably be loaded by libclang, but I would recommend writing the files with libclang in the first place.
> On Thu, 10 Dec 2015 at 13:00 Jason Haslam via cfe-dev <cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>> wrote:
> Hi Daniel,
> The AST dump is a debugging tool. It’s not the same thing as the serialized representation of a translation unit. Use libclang to parse and serialize your header instead of doing from the command line with clang-cl.
> > On Dec 7, 2015, at 2:54 PM, Daniel Kats via cfe-dev <cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>> wrote:
> > Hi,
> > I am have generated a clang AST by running these commands on Windows on the Visual Studio command-line:
> > clang-cl <header-name> -Xclang -ast-dump -fsyntax-only -fno-color-diagnostics -w
> > And saved it in a file f.ast
> > I now want to take that file as input into a Python script, so I wrote this code:
> > Config.set_library_fie(libclang_path)
> > index = Index.create()
> > logging.debug( "Reading AST file...")
> > tu = index.read("f.ast")
> > logging.debug( "done parsing AST" )
> > # other stuff below
> > When I run this, I see command-line output:
> > "Reading AST file..."
> > And I get a popup indicating a C/C++ error in libclang.dll:
> > "Expression: ((End-Start) & 3) == 0 && "Bitcode stream not a multiple of 4 bytes""
> > Do you know why this happens, and how to fix?
> > - Daniel
> > _______________________________________________
> > cfe-dev mailing list
> > cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
> cfe-dev mailing list
> cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev