mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Very basic support for constant evaluation of expressions. (#3581)
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.
This commit is contained in:
+15
-9
@@ -15,14 +15,20 @@ fn G() -> i32 {
|
||||
// CHECK:STDOUT: --- function_param.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %.loc7: type = ptr_type [i32; 3]
|
||||
// CHECK:STDOUT: %.loc12: type = tuple_type (i32, i32, i32)
|
||||
// CHECK:STDOUT: %.loc7_17: i32 = int_literal 3, const
|
||||
// CHECK:STDOUT: %.loc7_18.1: type = array_type %.loc7_17, i32, const
|
||||
// CHECK:STDOUT: %.loc7_18.2: type = ptr_type [i32; 3], const
|
||||
// CHECK:STDOUT: %.loc12_13: i32 = int_literal 1, const
|
||||
// CHECK:STDOUT: %.loc12_16: i32 = int_literal 2, const
|
||||
// CHECK:STDOUT: %.loc12_19: i32 = int_literal 3, const
|
||||
// CHECK:STDOUT: %.loc12_20: type = tuple_type (i32, i32, i32), const
|
||||
// CHECK:STDOUT: %.loc12_23: i32 = int_literal 1, const
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace package, {.F = %F, .G = %G}
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F
|
||||
// CHECK:STDOUT: %G: <function> = fn_decl @G
|
||||
// CHECK:STDOUT: %F: <function> = fn_decl @F, const
|
||||
// CHECK:STDOUT: %G: <function> = fn_decl @G, const
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @F(%arr: [i32; 3], %i: i32) -> i32 {
|
||||
@@ -37,12 +43,12 @@ fn G() -> i32 {
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @G() -> i32 {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: %F.ref: <function> = name_ref F, file.%F
|
||||
// CHECK:STDOUT: %.loc12_13: i32 = int_literal 1
|
||||
// CHECK:STDOUT: %.loc12_16: i32 = int_literal 2
|
||||
// CHECK:STDOUT: %.loc12_19: i32 = int_literal 3
|
||||
// CHECK:STDOUT: %F.ref: <function> = name_ref F, file.%F, const = file.%F
|
||||
// CHECK:STDOUT: %.loc12_13: i32 = int_literal 1, const = constants.%.loc12_13
|
||||
// CHECK:STDOUT: %.loc12_16: i32 = int_literal 2, const = constants.%.loc12_16
|
||||
// CHECK:STDOUT: %.loc12_19: i32 = int_literal 3, const = constants.%.loc12_19
|
||||
// CHECK:STDOUT: %.loc12_20.1: (i32, i32, i32) = tuple_literal (%.loc12_13, %.loc12_16, %.loc12_19)
|
||||
// CHECK:STDOUT: %.loc12_23: i32 = int_literal 1
|
||||
// CHECK:STDOUT: %.loc12_23: i32 = int_literal 1, const = constants.%.loc12_23
|
||||
// CHECK:STDOUT: %.loc12_20.2: ref [i32; 3] = temporary_storage
|
||||
// CHECK:STDOUT: %.loc12_20.3: i32 = int_literal 0
|
||||
// CHECK:STDOUT: %.loc12_20.4: ref i32 = array_index %.loc12_20.2, %.loc12_20.3
|
||||
|
||||
Reference in New Issue
Block a user