v / vlib / v2 / ssa / value.v
68 lines · 60 sloc · 1.44 KB · 726559c029ba7e9171e3f7cb5dcfd204ee42f7e3
Raw
1// Copyright (c) 2026 Alexander Medvednikov. All rights reserved.
2// Use of this source code is governed by an MIT license
3// that can be found in the LICENSE file.
4
5module ssa
6
7pub type ValueID = int
8
9pub fn (id ValueID) str() string {
10 return int(id).str()
11}
12
13pub enum ValueKind {
14 unknown
15 constant
16 argument
17 global
18 instruction
19 basic_block
20 string_literal // V string struct literal (by value)
21 c_string_literal // C string literal (raw char pointer)
22 func_ref // Function pointer reference (for map hash/eq/clone/free functions)
23}
24
25// str returns the symbolic name for an SSA value kind.
26pub fn (k ValueKind) str() string {
27 return match k {
28 .unknown { 'unknown' }
29 .constant { 'constant' }
30 .argument { 'argument' }
31 .global { 'global' }
32 .instruction { 'instruction' }
33 .basic_block { 'basic_block' }
34 .string_literal { 'string_literal' }
35 .c_string_literal { 'c_string_literal' }
36 .func_ref { 'func_ref' }
37 }
38}
39
40pub struct Value {
41pub:
42 id ValueID
43 typ TypeID
44 // Index into the specific arena (instrs, blocks, globals)
45 index int
46pub mut:
47 kind ValueKind
48 name string
49 uses []ValueID
50}
51
52pub struct ConstantData {
53pub:
54 int_val i64
55 float_val f64
56 str_val string
57}
58
59pub struct GlobalVar {
60pub mut:
61 name string
62 typ TypeID
63 linkage Linkage
64 alignment int
65 is_constant bool
66 initial_value i64 // For constants/enums, the initial integer value
67 initial_data []u8 // For constant arrays: serialized element data
68}
69