Appearance
| 1 | namespace IR is | |
| 2 | use IO.Std | |
| 3 | ||
| 4 | use Semantic.Types.Type | |
| 5 | use Values.Value | |
| 6 | ||
| 7 | class TEMP is | |
| 8 | _block: IR.Values.BLOCK | |
| 9 | _next_id: int static | |
| 10 | _name: string => | |
| 11 | if suffix > 0 then | |
| 12 | ".{prefix}.{id}.{suffix}" | |
| 13 | else | |
| 14 | ".{prefix}.{id}" | |
| 15 | fi | |
| 16 | ||
| 17 | local: LOCAL | |
| 18 | ||
| 19 | id: int | |
| 20 | prefix: string | |
| 21 | suffix: int | |
| 22 | type: Type | |
| 23 | ||
| 24 | init(block: IR.Values.BLOCK, prefix: string, suffix: int, type: Type) is | |
| 25 | _block = block | |
| 26 | self.prefix = prefix | |
| 27 | self.suffix = suffix | |
| 28 | ||
| 29 | self.id = get_next_id() | |
| 30 | self.type = type | |
| 31 | ||
| 32 | local = LOCAL(_name, type) | |
| 33 | ||
| 34 | declare() | |
| 35 | si | |
| 36 | ||
| 37 | init(block: IR.Values.BLOCK, prefix: string, value: Value) is | |
| 38 | init(block, prefix, 0, value) | |
| 39 | si | |
| 40 | ||
| 41 | init(block: IR.Values.BLOCK, prefix: string, suffix: int, value: Value) is | |
| 42 | init(block, prefix, suffix, value.type!) | |
| 43 | ||
| 44 | store(value) | |
| 45 | si | |
| 46 | ||
| 47 | init(block: IR.Values.BLOCK, prefix: string, type: Type) is | |
| 48 | init(block, prefix, 0, type) | |
| 49 | si | |
| 50 | ||
| 51 | reset_id() static is | |
| 52 | _next_id = 0 | |
| 53 | si | |
| 54 | ||
| 55 | get_next_id() -> int static is | |
| 56 | let result = _next_id | |
| 57 | _next_id = _next_id + 1 | |
| 58 | return result | |
| 59 | si | |
| 60 | ||
| 61 | declare() is | |
| 62 | _block.add(Values.DECLARE_LOCAL(local)) | |
| 63 | si | |
| 64 | ||
| 65 | load() -> Values.Load.TEMP => Values.Load.TEMP(local) | |
| 66 | ||
| 67 | store(value: Value) is | |
| 68 | _block.add(value) | |
| 69 | ||
| 70 | _block.add(Values.STORE_TEMP(local)) | |
| 71 | si | |
| 72 | si | |
| 73 | si |