| 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 | |
| 5 | module ssa |
| 6 | |
| 7 | pub type ValueID = int |
| 8 | |
| 9 | pub fn (id ValueID) str() string { |
| 10 | return int(id).str() |
| 11 | } |
| 12 | |
| 13 | pub 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. |
| 26 | pub 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 | |
| 40 | pub struct Value { |
| 41 | pub: |
| 42 | id ValueID |
| 43 | typ TypeID |
| 44 | // Index into the specific arena (instrs, blocks, globals) |
| 45 | index int |
| 46 | pub mut: |
| 47 | kind ValueKind |
| 48 | name string |
| 49 | uses []ValueID |
| 50 | } |
| 51 | |
| 52 | pub struct ConstantData { |
| 53 | pub: |
| 54 | int_val i64 |
| 55 | float_val f64 |
| 56 | str_val string |
| 57 | } |
| 58 | |
| 59 | pub struct GlobalVar { |
| 60 | pub 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 | |