Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit C code from user-defined AST? #87

Open
SamuelMarks opened this issue Apr 4, 2022 · 1 comment
Open

Emit C code from user-defined AST? #87

SamuelMarks opened this issue Apr 4, 2022 · 1 comment

Comments

@SamuelMarks
Copy link

In Python I can do this:

class_reduction_v2 = ClassDef(
    name="ReductionV2",
    bases=[],
    keywords=[],
    body=[
        Expr(value=set_value("foo")),
        Assign(targets=[Name(id="AUTO", ctx=Store())], value=set_value("auto")),
        Assign(targets=[Name(id="NONE", ctx=Store())], value=set_value("none")),
        Assign(targets=[Name(id="SUM", ctx=Store())], value=set_value("sum")),
        Assign(
            targets=[Name(id="SUM_OVER_BATCH_SIZE", ctx=Store())],
            value=set_value("sum_over_batch_size"),
        ),
    ],
    decorator_list=[],
)

Which produces:

class ReductionV2:
    """ foo """
    AUTO = 'auto'
    NONE = 'none'
    SUM = 'sum'
    SUM_OVER_BATCH_SIZE = 'sum_over_batch_size'

Looks like neither LLVM LibTooling nor LLVM libclang have support for this:
https://discourse.llvm.org/t/create-and-emit-ast-for-struct-clang-recorddecl/61383

Is this something you would consider adding to Psyche-C? 🥇

@ltcmelo
Copy link
Owner

ltcmelo commented Apr 5, 2022

Hi @SamuelMarks . I wouldn't implement such a feature myself, but I'd be willing to accept it as a contribution (if the implementation doesn't cause side effects for the main use of psyche-c's AST).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants