feroldi / cci

DEPRECATED PROJECT, see README
MIT License
37 stars 5 forks source link

`-dump-ast` command-line option #4

Closed feroldi closed 7 years ago

feroldi commented 7 years ago

-dump-ast makes the compiler dump the generated AST from translation units to stderr.

The AST would be broken down to entity and display:

Syntax could be similar to libclang's:

int main()
{
    int i = 42;
    return i;
}

Would generate:

- FunctionDefinition(int(), main)
    - Operator(=)
        - VarDeclaration(int, i)
        - Constant(42)
    - Return(i)

This is just an illustration, and it can/will change.

edit-1:

Stick to the current general AST. Example:

$ cat src.c
int main(int argc, char** argv)
{
  return 0;
}

$ ccompiler -dump-ast src.c
compilation unit:
  function definition:
    declaration specifiers:
      type specifier(int)
    direct declarator:
      identifier(main)
      parameter list:
        parameter declaration:
          declaration specifiers:
            type specifier(int)
          identifier(argc)
        parameter declaration:
          declaration specifiers:
            type specifier(char)
          declarator:
            pointer declarator(*):
              pointer declarator(*)
            identifier(argv)
    compound statement({):
      jump statement(return):
        integer constant(0)

There will be another compiler option to emit the intermediate language (IR).

feroldi commented 7 years ago

Maybe use ipr for the syntax?

feroldi commented 7 years ago

Make it dump the AST produced from semantics analyses instead of the generic one.