<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Jul 8, 2013, at 12:46 PM, Daniel Albuschat <<a href="mailto:d.albuschat@gmail.com">d.albuschat@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Am Montag, 8. Juli 2013 schrieb Douglas Gregor :<br><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;"><br><div><div>On Jul 5, 2013, at 3:28 PM, Daniel Albuschat <<a target="_blank">d.albuschat@gmail.com</a>> wrote:</div><br><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div dir="ltr">Hi there,<div><br></div><div>I recently started looking into the Clang project and have to admit that I would never have expected it to be that mature. And I really appreciate the design decisions that lead to Clang being that re-usable and flexible. I think you're doing each and every C++ programmer a great favor and Clang will spawn an immense number of awesome tools in the future that we previously might not have imagined being possible to implement.</div><div><br></div><div>Enough praising, here is my actual question:</div><div>Is there any tool that reads an AST, saves it to some file or database, and later is able to *restore* that AST completely (e.g. to be able to create LLVM IR from it)? I'm trying to do something similar, so it'd be nice to know whether someone did that before.</div><div>The precompiled header implementations should do something like this, shouldn't they? Is their AST representation complete, or are they missing things like control-flow?<br></div></div></div></blockquote><br></div><div>Yes to everything. The precompiled header implementation serializes the entire AST. You can use clang -cc1’s ‘-emit-ast’ option to emit the serialized AST into a “.ast” file, which can then be used to generate LLVM IR. It hasn’t been extensively tested, and to my knowledge nobody is doing this in a production environment, but the test file test/Frontend/ast-codegen.c illustrates how to do it and that it isn’t *completely* broken.</div></div></blockquote><div><br></div><div><br></div><div>Thank you for your reply, Doug.</div><div><br></div><div>The reason I am interested in restoring and/or building an AST is because I am thinking about using Clang as the backend for a programming language. It will obviously be a subset of C++. It would be awesome to use libraries written in C++ in it. This means, at a minimum,  instantiating "simple" classes and calling functions. Think of "C++ light" with less baggage from C and more straightforward Syntax. I am going to evaluate whether building my own, simpler AST and translating it into the Clang AST might work.</div><div><br></div><div>Do you think that this is feasible, or is it doomed to fail for some obvious reasons?<span></span></div></div></blockquote><br></div><div dir="auto">Generating correct Clang ASTs from anything but parsed C++ code is going to be extremely complicated. I think you’re better off generating C++ directly, or simply keeping your language front end separate from Clang.</div><div dir="auto"><br></div><div dir="auto"><span class="Apple-tab-span" style="white-space:pre">     </span>- Doug</div><div dir="auto"><br></div><br></body></html>