A small proposal for extraction of inline assembly block information

Hello Clang,

This is Xiang and I am investigating the option to enhance libclang and its clang-c interface, so that one can extract essential information such as assembly template, register constraints and clobber specification from the Clang AST.

The idea is that given a CXCursor pointing at an InlineAssembly node, clang-c can also answer basic questions on how the corresponding LLVM IR asm template would be like, the number of inputs, outputs, clobbers and how would the constraints be formatted in the LLVM IR.

The idea is that it would allow one to inspect the assembly template and perform analysis and translation on a fully expanded and parsed C AST, which in turn enables further integration. I am striving for minimal exposure of Clang’s internal and focus mostly on the maximally common denominator according to the Clang and GCC documentation, given that this is mostly still an language extension.

My questions is the following: in view of the Clang team and libclang maintainer, is the proposed interface in the appendix reasonable?

I am looking forward to your feedback. Cheers!

Appendix

/**
 * Given a CXCursor_GCCAsmStmt cursor, return the assembly template string.
 */

CINDEX_LINKAGE CXString clang_Cursor_getGCCAssemblyTemplate(CXCursor);

/**
 * Given a CXCursor_GCCAsmStmt cursor, check if the assembly block has goto
 * labels.
 */

CINDEX_LINKAGE unsigned clang_Cursor_isGCCAssemblyHasGoto(CXCursor);

/**
 * Given a CXCursor_GCCAsmStmt cursor, count the number of outputs
 */

CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyNumOutputs(CXCursor);

/**
 * Given a CXCursor_GCCAsmStmt cursor, count the number of inputs
 */

CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyNumInputs(CXCursor);

/**
 * Given a CXCursor_GCCAsmStmt cursor, get the constraint and expression cursor
 * to the Index-th input.
 */

CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyInput(CXCursor Cursor,
                                                         unsigned Index,
                                                         CXString *Constraint,
                                                         CXCursor *Expr);

/**
 * Given a CXCursor_GCCAsmStmt cursor, get the constraint and expression cursor
 * to the Index-th output.
 */

CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyOutput(CXCursor Cursor,
                                                          unsigned Index,
                                                          CXString *Constraint,
                                                          CXCursor *Expr);

/**
 * Given a CXCursor_GCCAsmStmt cursor, count the clobbers in it.
 */

unsigned clang_Cursor_getGCCAssemblyNumClobbers(CXCursor Cursor);

/**
 * Given a CXCursor_GCCAsmStmt cursor, get the Index-th clobber of it.
 */

CXString clang_Cursor_getGCCAssemblyClobber(CXCursor Cursor, unsigned Index);