irgenerator/llvm-expr-result.spice
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | // Std imports | ||
| 4 | import "std/bindings/llvm/llvm" as llvm; | ||
| 5 | |||
| 6 | // Own imports | ||
| 7 | import "@/ast/ast-nodes"; | ||
| 8 | import "@/symboltablebuilder/symbol-table-entry"; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * For routing through multiple LLVM values at once | ||
| 12 | */ | ||
| 13 | public type LLVMExprResult struct { | ||
| 14 | public llvm::Value value | ||
| 15 | public llvm::Value constant | ||
| 16 | public llvm::Value ptr | ||
| 17 | public llvm::Value refPtr | ||
| 18 | 555383 | public const SymbolTableEntry* entry = nil<const SymbolTableEntry*> | |
| 19 | 555383 | public IVisitable* node = nil<IVisitable*> | |
| 20 | } | ||
| 21 | |||
| 22 | 555383 | public p LLVMExprResult.ctor() { | |
| 23 | 555383 | this.value = llvm::Value(); | |
| 24 | 555383 | this.constant = llvm::Value(); | |
| 25 | 555383 | this.ptr = llvm::Value(); | |
| 26 | 555383 | this.refPtr = llvm::Value(); | |
| 27 | 555383 | this.entry = nil<const SymbolTableEntry*>; | |
| 28 | 555383 | this.node = nil<IVisitable*>; | |
| 29 | 555383 | } | |
| 30 | |||
| 31 | 10179 | public f<bool> LLVMExprResult.isTemporary() { | |
| 32 | 10179 | return this.entry == nil<const SymbolTableEntry*> || this.entry.anonymous; | |
| 33 | } | ||
| 34 | |||
| 35 | // Shorthands for creating an expression result with a single member set | ||
| 36 | |||
| 37 | 96960 | public f<LLVMExprResult> exprResultWithValue(llvm::Value value) { | |
| 38 | 96960 | LLVMExprResult exprResult; | |
| 39 | 96960 | exprResult.value = value; | |
| 40 | 96960 | return exprResult; | |
| 41 | } | ||
| 42 | |||
| 43 | 86638 | public f<LLVMExprResult> exprResultWithConstant(llvm::Value constant) { | |
| 44 | 86638 | LLVMExprResult exprResult; | |
| 45 | 86638 | exprResult.constant = constant; | |
| 46 | 86638 | return exprResult; | |
| 47 | } | ||
| 48 | |||
| 49 | 2459 | public f<LLVMExprResult> exprResultWithPtr(llvm::Value ptr) { | |
| 50 | 2459 | LLVMExprResult exprResult; | |
| 51 | 2459 | exprResult.ptr = ptr; | |
| 52 | 2459 | return exprResult; | |
| 53 | } | ||
| 54 |