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

Add output flags to CLI #112

Merged
merged 4 commits into from
Apr 25, 2024
Merged

Add output flags to CLI #112

merged 4 commits into from
Apr 25, 2024

Conversation

JulianGCalderon
Copy link
Contributor

@JulianGCalderon JulianGCalderon commented Apr 19, 2024

This PR adds flags for writing either ast, ir, llvm, ast, object, mlir to a file.

Code Example:

mod Example {
    fn main() -> i32 {
        return 5 + 5;
    }
}

AST Example:

[
    Program {
        file_path: Some(
            "examples/simple.con",
        ),
        modules: [
            Module {
                doc_string: None,
                imports: [],
                name: Ident {
                    name: "Example",
                    span: Span {
                        from: 4,
                        to: 11,
                    },
                },
                contents: [
                    Function(
                        FunctionDef {
                            decl: FunctionDecl {
                                doc_string: None,
                                generic_params: [],
                                name: Ident {
                                    name: "main",
                                    span: Span {
                                        from: 21,
                                        to: 25,
                                    },
                                },
                                params: [],
                                ret_type: Some(
                                    Simple {
                                        name: Ident {
                                            name: "i32",
                                            span: Span {
                                                from: 31,
                                                to: 34,
                                            },
                                        },
                                        qualifiers: [],
                                        span: Span {
                                            from: 31,
                                            to: 34,
                                        },
                                    },
                                ),
                                is_extern: false,
                                is_pub: false,
                                span: Span {
                                    from: 18,
                                    to: 34,
                                },
                            },
                            body: [
                                Return(
                                    ReturnStmt {
                                        value: Some(
                                            BinaryOp(
                                                Value(
                                                    ConstInt(
                                                        5,
                                                        Span {
                                                            from: 52,
                                                            to: 53,
                                                        },
                                                    ),
                                                    Span {
                                                        from: 52,
                                                        to: 53,
                                                    },
                                                ),
                                                Arith(
                                                    Add,
                                                ),
                                                Value(
                                                    ConstInt(
                                                        5,
                                                        Span {
                                                            from: 56,
                                                            to: 57,
                                                        },
                                                    ),
                                                    Span {
                                                        from: 56,
                                                        to: 57,
                                                    },
                                                ),
                                            ),
                                        ),
                                        span: Span {
                                            from: 45,
                                            to: 57,
                                        },
                                    },
                                ),
                            ],
                            span: Span {
                                from: 18,
                                to: 64,
                            },
                        },
                    ),
                ],
                span: Span {
                    from: 0,
                    to: 66,
                },
            },
        ],
    },
]

IR Example:

ProgramBody {
    top_level_module_names: {
        "Example": DefId {
            program_id: 0,
            id: 1,
        },
    },
    top_level_modules: [
        DefId {
            program_id: 0,
            id: 1,
        },
    ],
    modules: {
        DefId {
            program_id: 0,
            id: 1,
        }: ModuleBody {
            id: DefId {
                program_id: 0,
                id: 1,
            },
            parent_ids: [],
            symbols: SymbolTable {
                symbols: {},
                modules: {},
                functions: {
                    "main": DefId {
                        program_id: 0,
                        id: 2,
                    },
                },
                constants: {},
                structs: {},
                types: {},
            },
            functions: {
                DefId {
                    program_id: 0,
                    id: 2,
                },
            },
            structs: {},
            types: {},
            constants: {},
            modules: {},
            imports: {},
        },
    },
    functions: {
        DefId {
            program_id: 0,
            id: 2,
        }: FnBody {
            id: DefId {
                program_id: 0,
                id: 2,
            },
            name: "main",
            is_extern: false,
            basic_blocks: [
                BasicBlock {
                    statements: [
                        Statement {
                            span: None,
                            kind: StorageLive(
                                1,
                            ),
                        },
                        Statement {
                            span: None,
                            kind: Assign(
                                Place {
                                    local: 1,
                                    projection: [],
                                },
                                Use(
                                    Const(
                                        ConstData {
                                            ty: Ty {
                                                span: Some(
                                                    Span {
                                                        from: 31,
                                                        to: 34,
                                                    },
                                                ),
                                                kind: Int(
                                                    I32,
                                                ),
                                            },
                                            data: Value(
                                                Leaf(
                                                    I32(
                                                        5,
                                                    ),
                                                ),
                                            ),
                                        },
                                    ),
                                ),
                            ),
                        },
                        Statement {
                            span: None,
                            kind: StorageLive(
                                2,
                            ),
                        },
                        Statement {
                            span: None,
                            kind: Assign(
                                Place {
                                    local: 2,
                                    projection: [],
                                },
                                Use(
                                    Const(
                                        ConstData {
                                            ty: Ty {
                                                span: Some(
                                                    Span {
                                                        from: 31,
                                                        to: 34,
                                                    },
                                                ),
                                                kind: Int(
                                                    I32,
                                                ),
                                            },
                                            data: Value(
                                                Leaf(
                                                    I32(
                                                        5,
                                                    ),
                                                ),
                                            ),
                                        },
                                    ),
                                ),
                            ),
                        },
                        Statement {
                            span: None,
                            kind: Assign(
                                Place {
                                    local: 0,
                                    projection: [],
                                },
                                BinaryOp(
                                    Add,
                                    (
                                        Place(
                                            Place {
                                                local: 1,
                                                projection: [],
                                            },
                                        ),
                                        Place(
                                            Place {
                                                local: 2,
                                                projection: [],
                                            },
                                        ),
                                    ),
                                ),
                            ),
                        },
                    ],
                    terminator: Terminator {
                        span: None,
                        kind: Return,
                    },
                },
                BasicBlock {
                    statements: [],
                    terminator: Terminator {
                        span: None,
                        kind: Return,
                    },
                },
            ],
            locals: [
                Local {
                    span: None,
                    debug_name: None,
                    ty: Ty {
                        span: Some(
                            Span {
                                from: 31,
                                to: 34,
                            },
                        ),
                        kind: Int(
                            I32,
                        ),
                    },
                    kind: ReturnPointer,
                },
                Local {
                    span: None,
                    debug_name: None,
                    ty: Ty {
                        span: Some(
                            Span {
                                from: 31,
                                to: 34,
                            },
                        ),
                        kind: Int(
                            I32,
                        ),
                    },
                    kind: Temp,
                },
                Local {
                    span: None,
                    debug_name: None,
                    ty: Ty {
                        span: Some(
                            Span {
                                from: 31,
                                to: 34,
                            },
                        ),
                        kind: Int(
                            I32,
                        ),
                    },
                    kind: Temp,
                },
            ],
        },
    },
    structs: {},
    function_signatures: {
        DefId {
            program_id: 0,
            id: 2,
        }: (
            [],
            Ty {
                span: Some(
                    Span {
                        from: 31,
                        to: 34,
                    },
                ),
                kind: Int(
                    I32,
                ),
            },
        ),
    },
    file_paths: {
        0: "examples/simple.con",
    },
}

Copy link

Benchmarking factorial

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 0% with 158 lines in your changes are missing coverage. Please review.

Project coverage is 58.15%. Comparing base (802b249) to head (882ab24).

Files Patch % Lines
crates/concrete_driver/src/lib.rs 0.00% 158 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #112      +/-   ##
==========================================
- Coverage   58.42%   58.15%   -0.28%     
==========================================
  Files          34       34              
  Lines        4058     4077      +19     
==========================================
  Hits         2371     2371              
- Misses       1687     1706      +19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JulianGCalderon JulianGCalderon marked this pull request as ready for review April 19, 2024 18:34
@juanbono
Copy link
Collaborator

can you paste sample outputs here?

@igaray igaray added this pull request to the merge queue Apr 25, 2024
Merged via the queue into main with commit 383c46e Apr 25, 2024
5 checks passed
@edg-l edg-l deleted the improve-cli branch May 8, 2024 10:08
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

Successfully merging this pull request may close these issues.

4 participants