mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-24 01:12:42 +00:00
Form a side table with constant values for each instruction. Evaluation is only supported for a few very simple kinds of instruction for now. This is not observable outside of the SemIR output, because nothing depends on expressions having a constant value phase yet.
64 lines
2.3 KiB
Plaintext
64 lines
2.3 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
|
|
|
|
fn A() -> i32 { return 1; }
|
|
fn B() -> i32 { return 2; }
|
|
|
|
fn F(b: bool) -> i32 {
|
|
return if b then A() else B();
|
|
}
|
|
|
|
// CHECK:STDOUT: --- control_flow.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %.loc7: i32 = int_literal 1, const
|
|
// CHECK:STDOUT: %.loc8: i32 = int_literal 2, const
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace package, {.A = %A, .B = %B, .F = %F}
|
|
// CHECK:STDOUT: %A: <function> = fn_decl @A, const
|
|
// CHECK:STDOUT: %B: <function> = fn_decl @B, const
|
|
// CHECK:STDOUT: %F: <function> = fn_decl @F, const
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @A() -> i32 {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %.loc7: i32 = int_literal 1, const = constants.%.loc7
|
|
// CHECK:STDOUT: return %.loc7
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @B() -> i32 {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %.loc8: i32 = int_literal 2, const = constants.%.loc8
|
|
// CHECK:STDOUT: return %.loc8
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @F(%b: bool) -> i32 {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %b.ref: bool = name_ref b, %b
|
|
// CHECK:STDOUT: if %b.ref br !if.expr.then else br !if.expr.else
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !if.expr.then:
|
|
// CHECK:STDOUT: %A.ref: <function> = name_ref A, file.%A, const = file.%A
|
|
// CHECK:STDOUT: %.loc11_21.1: init i32 = call %A.ref()
|
|
// CHECK:STDOUT: %.loc11_21.2: i32 = value_of_initializer %.loc11_21.1
|
|
// CHECK:STDOUT: %.loc11_21.3: i32 = converted %.loc11_21.1, %.loc11_21.2
|
|
// CHECK:STDOUT: br !if.expr.result(%.loc11_21.3)
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !if.expr.else:
|
|
// CHECK:STDOUT: %B.ref: <function> = name_ref B, file.%B, const = file.%B
|
|
// CHECK:STDOUT: %.loc11_30: init i32 = call %B.ref()
|
|
// CHECK:STDOUT: %.loc11_24.1: i32 = value_of_initializer %.loc11_30
|
|
// CHECK:STDOUT: %.loc11_24.2: i32 = converted %.loc11_30, %.loc11_24.1
|
|
// CHECK:STDOUT: br !if.expr.result(%.loc11_24.2)
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !if.expr.result:
|
|
// CHECK:STDOUT: %.loc11_10: i32 = block_arg !if.expr.result
|
|
// CHECK:STDOUT: return %.loc11_10
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|