lambdaclass / concrete

Concrete is a simple programming language specifically crafted for creating highly scalable systems that are reliable, efficient, and easy to maintain.
Apache License 2.0
123 stars 11 forks source link

Add output flags to CLI #112

Closed JulianGCalderon closed 4 months ago

JulianGCalderon commented 4 months ago

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",
    },
}
github-actions[bot] commented 4 months ago

Benchmarking factorial

codecov-commenter commented 4 months ago

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 :warning:
Additional details and impacted files ```diff @@ 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 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

juanbono commented 4 months ago

can you paste sample outputs here?