Files
carbon-lang/toolchain/semantics/testdata/function/call/params_two.carbon
T
Jon Ross-Perkins 32e8fee4ad Add initial lowering of a trivial function (#2640)
This is starting to build out actual lowering logic, for a really simple `fn Main() -> i32 { return 0; }`

Notes for achieving this:

- In semantics, currently function names are bound separate from the signature. When emitting IR, this turns out to be inconvenient because we want to know the name when we process the declaration and the definition. This change addresses that by merging the name into the FunctionDeclaration node, which is also accessible from the definition. It removes the separate BindName. This should be the cause of all the test changes in semantics, because the IR generated changes.

- Add a "Lowering" class which I'm using to hold the llvm builder state. This class now has minimal support for the SemanticsIR generated by the above example.

- In the "Lowering", values from expressions are stored in a DenseMap. I'll keep thinking about whether there's a cleaner way to achieve this, and I'd call it a temporary solution for now. However, this is how the `0` in `return 0` gets properly associated across SemanticsIR instructions, and it'll frequently be an issue in less trivial cases.
2023-02-28 11:30:20 -08:00

84 lines
3.0 KiB
Plaintext

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// RUN: %{carbon-run-semantics}
// CHECK:STDOUT: cross_reference_irs_size: 1
// CHECK:STDOUT: calls: [
// CHECK:STDOUT: {arg_ir: block4, arg_refs: block5},
// CHECK:STDOUT: ]
// CHECK:STDOUT: callables: [
// CHECK:STDOUT: {param_ir: block1, param_refs: block2},
// CHECK:STDOUT: {param_ir: block0, param_refs: block0},
// CHECK:STDOUT: ]
// CHECK:STDOUT: integer_literals: [
// CHECK:STDOUT: 1,
// CHECK:STDOUT: 2,
// CHECK:STDOUT: ]
// CHECK:STDOUT: real_literals: [
// CHECK:STDOUT: ]
// CHECK:STDOUT: strings: [
// CHECK:STDOUT: a,
// CHECK:STDOUT: b,
// CHECK:STDOUT: Foo,
// CHECK:STDOUT: Main,
// CHECK:STDOUT: ]
// CHECK:STDOUT: nodes: [
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: node0, type: node0},
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: node1, type: node1},
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: node2, type: node0},
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: node3, type: node0},
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: node4, type: node0},
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: node5, type: node0},
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: node6, type: node5},
// CHECK:STDOUT: {kind: VarStorage, type: node2},
// CHECK:STDOUT: {kind: BindName, arg0: str0, arg1: node7, type: node2},
// CHECK:STDOUT: {kind: VarStorage, type: node2},
// CHECK:STDOUT: {kind: BindName, arg0: str1, arg1: node9, type: node2},
// CHECK:STDOUT: {kind: FunctionDeclaration, arg0: str2, arg1: callable0},
// CHECK:STDOUT: {kind: FunctionDefinition, arg0: node11, arg1: block0},
// CHECK:STDOUT: {kind: FunctionDeclaration, arg0: str3, arg1: callable1},
// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int0, type: node2},
// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int1, type: node2},
// CHECK:STDOUT: {kind: Call, arg0: call0, arg1: callable0, type: node6},
// CHECK:STDOUT: {kind: FunctionDefinition, arg0: node13, arg1: block6},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node7,
// CHECK:STDOUT: node8,
// CHECK:STDOUT: node9,
// CHECK:STDOUT: node10,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node8,
// CHECK:STDOUT: node10,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node11,
// CHECK:STDOUT: node12,
// CHECK:STDOUT: node13,
// CHECK:STDOUT: node17,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node14,
// CHECK:STDOUT: node15,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node14,
// CHECK:STDOUT: node15,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node16,
// CHECK:STDOUT: ],
// CHECK:STDOUT: ]
fn Foo(a: i32, b: i32) {}
fn Main() {
Foo(1, 2);
}