src/irgenerator/GenExpressions.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "IRGenerator.h" | ||
| 4 | |||
| 5 | #include <ast/ASTNodes.h> | ||
| 6 | |||
| 7 | #include <llvm/IR/Module.h> | ||
| 8 | |||
| 9 | namespace spice::compiler { | ||
| 10 | |||
| 11 | 12435 | std::any IRGenerator::visitAssignExpr(const AssignExprNode *node) { | |
| 12 | 12435 | diGenerator.setSourceLocation(node); | |
| 13 | |||
| 14 | // Visit ternary expression | ||
| 15 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 12435 times.
|
12435 | if (node->ternaryExpr) |
| 16 | ✗ | return visit(node->ternaryExpr); | |
| 17 | |||
| 18 | // Assign or compound assign operation | ||
| 19 |
1/2✓ Branch 5 → 6 taken 12435 times.
✗ Branch 5 → 60 not taken.
|
12435 | if (node->op != AssignExprNode::AssignOp::OP_NONE) { |
| 20 | 12435 | const ExprNode *lhsNode = node->lhs; | |
| 21 | 12435 | const ExprNode *rhsNode = node->rhs; | |
| 22 | |||
| 23 | // Normal assignment | ||
| 24 |
2/2✓ Branch 6 → 7 taken 10610 times.
✓ Branch 6 → 11 taken 1825 times.
|
12435 | if (node->op == AssignExprNode::AssignOp::OP_ASSIGN) |
| 25 |
2/4✓ Branch 7 → 8 taken 10610 times.
✗ Branch 7 → 69 not taken.
✓ Branch 8 → 9 taken 10610 times.
✗ Branch 8 → 69 not taken.
|
21220 | return doAssignment(lhsNode, rhsNode, node); |
| 26 | |||
| 27 | // Compound assignment | ||
| 28 | // Get symbol types of left and right side | ||
| 29 |
1/2✓ Branch 11 → 12 taken 1825 times.
✗ Branch 11 → 85 not taken.
|
1825 | const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx); |
| 30 |
1/2✓ Branch 12 → 13 taken 1825 times.
✗ Branch 12 → 85 not taken.
|
1825 | const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx); |
| 31 | |||
| 32 | // Retrieve rhs | ||
| 33 |
2/4✓ Branch 13 → 14 taken 1825 times.
✗ Branch 13 → 72 not taken.
✓ Branch 14 → 15 taken 1825 times.
✗ Branch 14 → 70 not taken.
|
1825 | auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode)); |
| 34 | // Retrieve lhs | ||
| 35 |
2/4✓ Branch 16 → 17 taken 1825 times.
✗ Branch 16 → 75 not taken.
✓ Branch 17 → 18 taken 1825 times.
✗ Branch 17 → 73 not taken.
|
1825 | auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode)); |
| 36 | |||
| 37 | 1825 | LLVMExprResult result; | |
| 38 |
10/11✓ Branch 19 → 20 taken 910 times.
✓ Branch 19 → 22 taken 75 times.
✓ Branch 19 → 24 taken 136 times.
✓ Branch 19 → 26 taken 96 times.
✓ Branch 19 → 28 taken 40 times.
✓ Branch 19 → 30 taken 11 times.
✓ Branch 19 → 32 taken 12 times.
✓ Branch 19 → 34 taken 17 times.
✓ Branch 19 → 36 taken 13 times.
✓ Branch 19 → 38 taken 515 times.
✗ Branch 19 → 40 not taken.
|
1825 | switch (node->op) { |
| 39 | 910 | case AssignExprNode::AssignOp::OP_PLUS_EQUAL: | |
| 40 |
1/2✓ Branch 20 → 21 taken 910 times.
✗ Branch 20 → 85 not taken.
|
910 | result = conversionManager.getPlusEqualInst(node, lhs, lhsSTy, rhs, rhsSTy); |
| 41 | 910 | break; | |
| 42 | 75 | case AssignExprNode::AssignOp::OP_MINUS_EQUAL: | |
| 43 |
1/2✓ Branch 22 → 23 taken 75 times.
✗ Branch 22 → 85 not taken.
|
75 | result = conversionManager.getMinusEqualInst(node, lhs, lhsSTy, rhs, rhsSTy); |
| 44 | 75 | break; | |
| 45 | 136 | case AssignExprNode::AssignOp::OP_MUL_EQUAL: | |
| 46 |
1/2✓ Branch 24 → 25 taken 136 times.
✗ Branch 24 → 85 not taken.
|
136 | result = conversionManager.getMulEqualInst(node, lhs, lhsSTy, rhs, rhsSTy); |
| 47 | 136 | break; | |
| 48 | 96 | case AssignExprNode::AssignOp::OP_DIV_EQUAL: | |
| 49 |
1/2✓ Branch 26 → 27 taken 96 times.
✗ Branch 26 → 85 not taken.
|
96 | result = conversionManager.getDivEqualInst(node, lhs, lhsSTy, rhs, rhsSTy); |
| 50 | 96 | break; | |
| 51 | 40 | case AssignExprNode::AssignOp::OP_REM_EQUAL: | |
| 52 |
1/2✓ Branch 28 → 29 taken 40 times.
✗ Branch 28 → 85 not taken.
|
40 | result = conversionManager.getRemEqualInst(node, lhs, lhsSTy, rhs, rhsSTy); |
| 53 | 40 | break; | |
| 54 | 11 | case AssignExprNode::AssignOp::OP_SHL_EQUAL: | |
| 55 |
1/2✓ Branch 30 → 31 taken 11 times.
✗ Branch 30 → 85 not taken.
|
11 | result = conversionManager.getSHLEqualInst(node, lhs, lhsSTy, rhs, rhsSTy); |
| 56 | 11 | break; | |
| 57 | 12 | case AssignExprNode::AssignOp::OP_SHR_EQUAL: | |
| 58 |
1/2✓ Branch 32 → 33 taken 12 times.
✗ Branch 32 → 85 not taken.
|
12 | result = conversionManager.getSHREqualInst(node, lhs, lhsSTy, rhs, rhsSTy); |
| 59 | 12 | break; | |
| 60 | 17 | case AssignExprNode::AssignOp::OP_AND_EQUAL: | |
| 61 |
1/2✓ Branch 34 → 35 taken 17 times.
✗ Branch 34 → 85 not taken.
|
17 | result = conversionManager.getAndEqualInst(node, lhs, lhsSTy, rhs, rhsSTy); |
| 62 | 17 | break; | |
| 63 | 13 | case AssignExprNode::AssignOp::OP_OR_EQUAL: | |
| 64 |
1/2✓ Branch 36 → 37 taken 13 times.
✗ Branch 36 → 85 not taken.
|
13 | result = conversionManager.getOrEqualInst(node, lhs, lhsSTy, rhs, rhsSTy); |
| 65 | 13 | break; | |
| 66 | 515 | case AssignExprNode::AssignOp::OP_XOR_EQUAL: | |
| 67 |
1/2✓ Branch 38 → 39 taken 515 times.
✗ Branch 38 → 85 not taken.
|
515 | result = conversionManager.getXorEqualInst(node, lhs, lhsSTy, rhs, rhsSTy); |
| 68 | 515 | break; | |
| 69 | − | default: // GCOV_EXCL_LINE | |
| 70 | − | throw CompilerError(UNHANDLED_BRANCH, "Assign op fall-through"); // GCOV_EXCL_LINE | |
| 71 | } | ||
| 72 | |||
| 73 |
1/2✗ Branch 48 → 49 not taken.
✓ Branch 48 → 51 taken 1825 times.
|
1825 | if (result.ptr) { // The operation allocated more memory |
| 74 | ✗ | if (lhs.entry) | |
| 75 | ✗ | lhs.entry->updateAddress(result.ptr); | |
| 76 |
2/2✓ Branch 51 → 52 taken 1500 times.
✓ Branch 51 → 57 taken 325 times.
|
1825 | } else if (result.value) { // The operation only updated the value |
| 77 | // Store the result | ||
| 78 | 1500 | lhs.value = result.value; | |
| 79 |
5/6✓ Branch 52 → 53 taken 1119 times.
✓ Branch 52 → 55 taken 381 times.
✓ Branch 53 → 54 taken 1 time.
✓ Branch 53 → 55 taken 1118 times.
✓ Branch 56 → 57 taken 1500 times.
✗ Branch 56 → 85 not taken.
|
1500 | insertStore(lhs.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile); |
| 80 | } | ||
| 81 |
1/2✓ Branch 57 → 58 taken 1825 times.
✗ Branch 57 → 85 not taken.
|
1825 | return lhs; |
| 82 | } | ||
| 83 | |||
| 84 | // This is a fallthrough case -> throw an error | ||
| 85 | − | throw CompilerError(UNHANDLED_BRANCH, "AssignStmt fall-through"); // GCOV_EXCL_LINE | |
| 86 | } | ||
| 87 | |||
| 88 | 894 | std::any IRGenerator::visitTernaryExpr(const TernaryExprNode *node) { | |
| 89 | 894 | diGenerator.setSourceLocation(node); | |
| 90 | |||
| 91 | // Check if only one operand is present -> loop through | ||
| 92 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 894 times.
|
894 | if (!node->falseExpr) |
| 93 | ✗ | return visit(node->condition); | |
| 94 | |||
| 95 | // It is a ternary | ||
| 96 | // Retrieve the condition value | ||
| 97 | 894 | llvm::Value *condValue = resolveValue(node->condition); | |
| 98 |
2/2✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 8 taken 893 times.
|
894 | const ExprNode *trueNode = node->isShortened ? node->condition : node->trueExpr; |
| 99 | 894 | const ExprNode *falseNode = node->falseExpr; | |
| 100 | |||
| 101 | 894 | llvm::Value *resultValue = nullptr; | |
| 102 | 894 | llvm::Value *resultPtr = nullptr; | |
| 103 | 894 | SymbolTableEntry *anonymousSymbol = nullptr; | |
| 104 |
6/6✓ Branch 10 → 11 taken 294 times.
✓ Branch 10 → 14 taken 600 times.
✓ Branch 12 → 13 taken 276 times.
✓ Branch 12 → 14 taken 18 times.
✓ Branch 15 → 16 taken 276 times.
✓ Branch 15 → 21 taken 618 times.
|
894 | if (trueNode->hasCompileTimeValue(manIdx) && falseNode->hasCompileTimeValue(manIdx)) { |
| 105 | // If both are constants, we can simply emit a selection instruction | ||
| 106 | 276 | llvm::Value *trueValue = resolveValue(trueNode); | |
| 107 | 276 | llvm::Value *falseValue = resolveValue(falseNode); | |
| 108 |
2/4✓ Branch 18 → 19 taken 276 times.
✗ Branch 18 → 147 not taken.
✓ Branch 19 → 20 taken 276 times.
✗ Branch 19 → 147 not taken.
|
276 | resultValue = builder.CreateSelect(condValue, trueValue, falseValue); |
| 109 | } else { | ||
| 110 | // We have at least one non-constant value, use branching to not perform both sides | ||
| 111 |
1/2✓ Branch 21 → 22 taken 618 times.
✗ Branch 21 → 206 not taken.
|
618 | const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn(); |
| 112 |
2/4✓ Branch 22 → 23 taken 618 times.
✗ Branch 22 → 150 not taken.
✓ Branch 23 → 24 taken 618 times.
✗ Branch 23 → 148 not taken.
|
618 | llvm::BasicBlock *condTrue = createBlock("cond.true." + codeLoc); |
| 113 |
2/4✓ Branch 25 → 26 taken 618 times.
✗ Branch 25 → 153 not taken.
✓ Branch 26 → 27 taken 618 times.
✗ Branch 26 → 151 not taken.
|
618 | llvm::BasicBlock *condFalse = createBlock("cond.false." + codeLoc); |
| 114 |
2/4✓ Branch 28 → 29 taken 618 times.
✗ Branch 28 → 156 not taken.
✓ Branch 29 → 30 taken 618 times.
✗ Branch 29 → 154 not taken.
|
618 | llvm::BasicBlock *condExit = createBlock("cond.exit." + codeLoc); |
| 115 | |||
| 116 | // Jump from original block to true or false block, depending on condition | ||
| 117 |
1/2✓ Branch 31 → 32 taken 618 times.
✗ Branch 31 → 204 not taken.
|
618 | insertCondJump(condValue, condTrue, condFalse); |
| 118 | |||
| 119 | // Fill true block | ||
| 120 |
1/2✓ Branch 32 → 33 taken 618 times.
✗ Branch 32 → 204 not taken.
|
618 | switchToBlock(condTrue); |
| 121 |
1/2✓ Branch 33 → 34 taken 618 times.
✗ Branch 33 → 204 not taken.
|
618 | const QualType &resultType = node->getEvaluatedSymbolType(manIdx); |
| 122 | 618 | llvm::Value *trueValue = nullptr; | |
| 123 | 618 | llvm::Value *truePtr = nullptr; | |
| 124 |
7/8✓ Branch 34 → 35 taken 610 times.
✓ Branch 34 → 37 taken 8 times.
✓ Branch 35 → 36 taken 610 times.
✗ Branch 35 → 204 not taken.
✓ Branch 36 → 37 taken 12 times.
✓ Branch 36 → 38 taken 598 times.
✓ Branch 39 → 40 taken 20 times.
✓ Branch 39 → 42 taken 598 times.
|
618 | if (node->falseSideCallsCopyCtor || resultType.isRef()) { // both sides or only the false side needs copy ctor call |
| 125 |
1/2✓ Branch 40 → 41 taken 20 times.
✗ Branch 40 → 204 not taken.
|
20 | truePtr = resolveAddress(trueNode); |
| 126 |
2/2✓ Branch 42 → 43 taken 2 times.
✓ Branch 42 → 58 taken 596 times.
|
598 | } else if (node->trueSideCallsCopyCtor) { // only true side needs copy ctor call |
| 127 |
1/2✓ Branch 43 → 44 taken 2 times.
✗ Branch 43 → 204 not taken.
|
2 | llvm::Value *originalPtr = resolveAddress(trueNode); |
| 128 |
2/4✓ Branch 47 → 48 taken 2 times.
✗ Branch 47 → 157 not taken.
✓ Branch 48 → 49 taken 2 times.
✗ Branch 48 → 157 not taken.
|
2 | truePtr = insertAlloca(trueNode->getEvaluatedSymbolType(manIdx)); |
| 129 |
2/4✓ Branch 53 → 54 taken 2 times.
✗ Branch 53 → 165 not taken.
✓ Branch 54 → 55 taken 2 times.
✗ Branch 54 → 163 not taken.
|
6 | generateCtorOrDtorCall(truePtr, node->calledCopyCtor, {originalPtr}); |
| 130 | } else { // neither true nor false side need copy ctor call | ||
| 131 |
1/2✓ Branch 58 → 59 taken 596 times.
✗ Branch 58 → 204 not taken.
|
596 | trueValue = resolveValue(trueNode); |
| 132 | } | ||
| 133 | // Set the true block to the current insert point, since it could have changed in the meantime | ||
| 134 | 618 | condTrue = builder.GetInsertBlock(); | |
| 135 |
1/2✓ Branch 61 → 62 taken 618 times.
✗ Branch 61 → 204 not taken.
|
618 | insertJump(condExit); |
| 136 | |||
| 137 | // Fill false block | ||
| 138 |
1/2✓ Branch 62 → 63 taken 618 times.
✗ Branch 62 → 204 not taken.
|
618 | switchToBlock(condFalse); |
| 139 | 618 | llvm::Value *falseValue = nullptr; | |
| 140 | 618 | llvm::Value *falsePtr = nullptr; | |
| 141 |
7/8✓ Branch 63 → 64 taken 609 times.
✓ Branch 63 → 66 taken 9 times.
✓ Branch 64 → 65 taken 609 times.
✗ Branch 64 → 204 not taken.
✓ Branch 65 → 66 taken 11 times.
✓ Branch 65 → 67 taken 598 times.
✓ Branch 68 → 69 taken 20 times.
✓ Branch 68 → 71 taken 598 times.
|
618 | if (node->trueSideCallsCopyCtor || resultType.isRef()) { // both sides or only the true side needs copy ctor call |
| 142 |
1/2✓ Branch 69 → 70 taken 20 times.
✗ Branch 69 → 204 not taken.
|
20 | falsePtr = resolveAddress(falseNode); |
| 143 |
2/2✓ Branch 71 → 72 taken 2 times.
✓ Branch 71 → 87 taken 596 times.
|
598 | } else if (node->falseSideCallsCopyCtor) { // only false side needs copy ctor call |
| 144 |
1/2✓ Branch 72 → 73 taken 2 times.
✗ Branch 72 → 204 not taken.
|
2 | llvm::Value *originalPtr = resolveAddress(falseNode); |
| 145 |
2/4✓ Branch 76 → 77 taken 2 times.
✗ Branch 76 → 170 not taken.
✓ Branch 77 → 78 taken 2 times.
✗ Branch 77 → 170 not taken.
|
2 | falsePtr = insertAlloca(falseNode->getEvaluatedSymbolType(manIdx)); |
| 146 |
2/4✓ Branch 82 → 83 taken 2 times.
✗ Branch 82 → 178 not taken.
✓ Branch 83 → 84 taken 2 times.
✗ Branch 83 → 176 not taken.
|
6 | generateCtorOrDtorCall(falsePtr, node->calledCopyCtor, {originalPtr}); |
| 147 | } else { // neither true nor false side need copy ctor call | ||
| 148 |
1/2✓ Branch 87 → 88 taken 596 times.
✗ Branch 87 → 204 not taken.
|
596 | falseValue = resolveValue(falseNode); |
| 149 | } | ||
| 150 | // Set the true block to the current insert point, since it could have changed in the meantime | ||
| 151 | 618 | condFalse = builder.GetInsertBlock(); | |
| 152 |
1/2✓ Branch 90 → 91 taken 618 times.
✗ Branch 90 → 204 not taken.
|
618 | insertJump(condExit); |
| 153 | |||
| 154 | // Fill the exit block | ||
| 155 |
1/2✓ Branch 91 → 92 taken 618 times.
✗ Branch 91 → 204 not taken.
|
618 | switchToBlock(condExit); |
| 156 |
9/10✓ Branch 92 → 93 taken 609 times.
✓ Branch 92 → 96 taken 9 times.
✓ Branch 93 → 94 taken 607 times.
✓ Branch 93 → 96 taken 2 times.
✓ Branch 94 → 95 taken 607 times.
✗ Branch 94 → 204 not taken.
✓ Branch 95 → 96 taken 11 times.
✓ Branch 95 → 97 taken 596 times.
✓ Branch 98 → 99 taken 22 times.
✓ Branch 98 → 121 taken 596 times.
|
618 | if (node->trueSideCallsCopyCtor || node->falseSideCallsCopyCtor || resultType.isRef()) { // one side calls copy ctor |
| 157 |
3/6✓ Branch 99 → 100 taken 22 times.
✗ Branch 99 → 183 not taken.
✓ Branch 100 → 101 taken 22 times.
✗ Branch 100 → 183 not taken.
✓ Branch 101 → 102 taken 22 times.
✗ Branch 101 → 183 not taken.
|
22 | llvm::PHINode *phiInst = builder.CreatePHI(builder.getPtrTy(), 2, "cond.result"); |
| 158 |
1/2✓ Branch 102 → 103 taken 22 times.
✗ Branch 102 → 204 not taken.
|
22 | phiInst->addIncoming(truePtr, condTrue); |
| 159 |
1/2✓ Branch 103 → 104 taken 22 times.
✗ Branch 103 → 204 not taken.
|
22 | phiInst->addIncoming(falsePtr, condFalse); |
| 160 |
4/4✓ Branch 104 → 105 taken 9 times.
✓ Branch 104 → 119 taken 13 times.
✓ Branch 105 → 106 taken 6 times.
✓ Branch 105 → 119 taken 3 times.
|
22 | if (node->trueSideCallsCopyCtor && node->falseSideCallsCopyCtor) { // both sides need copy ctor call |
| 161 |
1/2✓ Branch 109 → 110 taken 6 times.
✗ Branch 109 → 184 not taken.
|
6 | resultPtr = insertAlloca(resultType); |
| 162 |
2/4✓ Branch 114 → 115 taken 6 times.
✗ Branch 114 → 192 not taken.
✓ Branch 115 → 116 taken 6 times.
✗ Branch 115 → 190 not taken.
|
18 | generateCtorOrDtorCall(resultPtr, node->calledCopyCtor, {phiInst}); |
| 163 | } else { | ||
| 164 | 16 | resultPtr = phiInst; | |
| 165 | } | ||
| 166 | } else { // neither true nor false side calls copy ctor | ||
| 167 |
1/2✗ Branch 121 → 122 not taken.
✓ Branch 121 → 123 taken 596 times.
|
596 | assert(trueValue != nullptr); |
| 168 |
3/6✓ Branch 123 → 124 taken 596 times.
✗ Branch 123 → 197 not taken.
✓ Branch 124 → 125 taken 596 times.
✗ Branch 124 → 197 not taken.
✓ Branch 125 → 126 taken 596 times.
✗ Branch 125 → 197 not taken.
|
596 | llvm::PHINode *phiInst = builder.CreatePHI(resultType.toLLVMType(sourceFile), 2, "cond.result"); |
| 169 |
1/2✓ Branch 126 → 127 taken 596 times.
✗ Branch 126 → 204 not taken.
|
596 | phiInst->addIncoming(trueValue, condTrue); |
| 170 |
1/2✓ Branch 127 → 128 taken 596 times.
✗ Branch 127 → 204 not taken.
|
596 | phiInst->addIncoming(falseValue, condFalse); |
| 171 | 596 | resultValue = phiInst; | |
| 172 | } | ||
| 173 | |||
| 174 | // If we have an anonymous symbol for this ternary expr, make sure that it has an address to reference. | ||
| 175 |
1/2✓ Branch 129 → 130 taken 618 times.
✗ Branch 129 → 204 not taken.
|
618 | anonymousSymbol = currentScope->symbolTable.lookupAnonymous(node); |
| 176 |
2/2✓ Branch 130 → 131 taken 6 times.
✓ Branch 130 → 141 taken 612 times.
|
618 | if (anonymousSymbol != nullptr) { |
| 177 |
1/2✗ Branch 131 → 132 not taken.
✓ Branch 131 → 140 taken 6 times.
|
6 | if (!resultPtr) { |
| 178 | ✗ | resultPtr = insertAlloca(anonymousSymbol->getQualType()); | |
| 179 | ✗ | insertStore(resultValue, resultPtr); | |
| 180 | } | ||
| 181 |
1/2✓ Branch 140 → 141 taken 6 times.
✗ Branch 140 → 204 not taken.
|
6 | anonymousSymbol->updateAddress(resultPtr); |
| 182 | } | ||
| 183 | 618 | } | |
| 184 | |||
| 185 |
1/2✓ Branch 143 → 144 taken 894 times.
✗ Branch 143 → 207 not taken.
|
1788 | return LLVMExprResult{.value = resultValue, .ptr = resultPtr, .entry = anonymousSymbol}; |
| 186 | } | ||
| 187 | |||
| 188 | 1411 | std::any IRGenerator::visitLogicalOrExpr(const LogicalOrExprNode *node) { | |
| 189 |
1/2✓ Branch 2 → 3 taken 1411 times.
✗ Branch 2 → 104 not taken.
|
1411 | diGenerator.setSourceLocation(node); |
| 190 | |||
| 191 | // Check if only one operand is present -> loop through | ||
| 192 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 1411 times.
|
1411 | if (node->operands.size() == 1) |
| 193 | ✗ | return visit(node->operands.front()); | |
| 194 | |||
| 195 | // It is a logical or expression | ||
| 196 | // Create exit block for short-circuiting | ||
| 197 |
1/2✓ Branch 8 → 9 taken 1411 times.
✗ Branch 8 → 104 not taken.
|
1411 | const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn(); |
| 198 |
2/4✓ Branch 9 → 10 taken 1411 times.
✗ Branch 9 → 81 not taken.
✓ Branch 10 → 11 taken 1411 times.
✗ Branch 10 → 79 not taken.
|
1411 | llvm::BasicBlock *bExit = createBlock("lor.exit." + codeLoc); |
| 199 | |||
| 200 | // Visit the first operand | ||
| 201 |
1/2✓ Branch 13 → 14 taken 1411 times.
✗ Branch 13 → 102 not taken.
|
1411 | llvm::Value *firstOperandValue = resolveValue(node->operands.front()); |
| 202 | |||
| 203 | // Prepare an array for value-to-block-mapping | ||
| 204 | 1411 | std::vector<std::pair<llvm::BasicBlock *, llvm::Value *>> shortCircuitBlocks; | |
| 205 |
1/2✓ Branch 15 → 16 taken 1411 times.
✗ Branch 15 → 100 not taken.
|
1411 | shortCircuitBlocks.reserve(node->operands.size()); |
| 206 | // The first element is the first operand value with the original block | ||
| 207 |
1/2✓ Branch 17 → 18 taken 1411 times.
✗ Branch 17 → 82 not taken.
|
1411 | shortCircuitBlocks.emplace_back(builder.GetInsertBlock(), firstOperandValue); |
| 208 | // Create a block for each additional operand and save it to the mapping | ||
| 209 |
2/2✓ Branch 31 → 19 taken 1899 times.
✓ Branch 31 → 32 taken 1411 times.
|
3310 | for (size_t i = 1; i < node->operands.size(); i++) |
| 210 |
6/12✓ Branch 19 → 20 taken 1899 times.
✗ Branch 19 → 91 not taken.
✓ Branch 20 → 21 taken 1899 times.
✗ Branch 20 → 89 not taken.
✓ Branch 21 → 22 taken 1899 times.
✗ Branch 21 → 87 not taken.
✓ Branch 22 → 23 taken 1899 times.
✗ Branch 22 → 85 not taken.
✓ Branch 23 → 24 taken 1899 times.
✗ Branch 23 → 83 not taken.
✓ Branch 24 → 25 taken 1899 times.
✗ Branch 24 → 83 not taken.
|
1899 | shortCircuitBlocks.emplace_back(createBlock("lor." + std::to_string(i) + "." + codeLoc), nullptr); |
| 211 | // Create conditional jump to the exit block if the first operand was true, otherwise to the next block | ||
| 212 |
2/4✓ Branch 32 → 33 taken 1411 times.
✗ Branch 32 → 100 not taken.
✓ Branch 33 → 34 taken 1411 times.
✗ Branch 33 → 100 not taken.
|
1411 | insertCondJump(firstOperandValue, bExit, shortCircuitBlocks.at(1).first); |
| 213 | |||
| 214 | // Create block for each operand | ||
| 215 |
2/2✓ Branch 50 → 35 taken 1899 times.
✓ Branch 50 → 51 taken 1411 times.
|
3310 | for (size_t i = 1; i < node->operands.size(); i++) { |
| 216 | // Switch to the next block | ||
| 217 |
2/4✓ Branch 35 → 36 taken 1899 times.
✗ Branch 35 → 100 not taken.
✓ Branch 36 → 37 taken 1899 times.
✗ Branch 36 → 100 not taken.
|
1899 | switchToBlock(shortCircuitBlocks.at(i).first); |
| 218 | // Evaluate operand and save the result in the mapping | ||
| 219 |
2/4✓ Branch 38 → 39 taken 1899 times.
✗ Branch 38 → 100 not taken.
✓ Branch 39 → 40 taken 1899 times.
✗ Branch 39 → 100 not taken.
|
1899 | shortCircuitBlocks.at(i).second = resolveValue(node->operands[i]); |
| 220 | // Replace the array entry with the current insert block, since the insert block could have changed in the meantime | ||
| 221 |
1/2✓ Branch 41 → 42 taken 1899 times.
✗ Branch 41 → 100 not taken.
|
1899 | shortCircuitBlocks.at(i).first = builder.GetInsertBlock(); |
| 222 | // Check if there are more blocks to process | ||
| 223 |
2/2✓ Branch 43 → 44 taken 1411 times.
✓ Branch 43 → 45 taken 488 times.
|
1899 | if (i == node->operands.size() - 1) { |
| 224 | // Insert a simple jump to the exit block for the last block | ||
| 225 |
1/2✓ Branch 44 → 48 taken 1411 times.
✗ Branch 44 → 100 not taken.
|
1411 | insertJump(bExit); |
| 226 | } else { | ||
| 227 | // Create conditional jump to the exit block if the first operand was true, otherwise to the next block | ||
| 228 |
3/6✓ Branch 45 → 46 taken 488 times.
✗ Branch 45 → 100 not taken.
✓ Branch 46 → 47 taken 488 times.
✗ Branch 46 → 100 not taken.
✓ Branch 47 → 48 taken 488 times.
✗ Branch 47 → 100 not taken.
|
488 | insertCondJump(shortCircuitBlocks.at(i).second, bExit, shortCircuitBlocks.at(i + 1).first); |
| 229 | } | ||
| 230 | } | ||
| 231 | |||
| 232 | // Get the result with the phi node | ||
| 233 |
1/2✓ Branch 51 → 52 taken 1411 times.
✗ Branch 51 → 100 not taken.
|
1411 | switchToBlock(bExit); |
| 234 |
2/4✓ Branch 52 → 53 taken 1411 times.
✗ Branch 52 → 97 not taken.
✓ Branch 55 → 56 taken 1411 times.
✗ Branch 55 → 97 not taken.
|
1411 | llvm::PHINode *result = builder.CreatePHI(firstOperandValue->getType(), node->operands.size(), "lor_phi"); |
| 235 |
2/2✓ Branch 72 → 58 taken 3310 times.
✓ Branch 72 → 73 taken 1411 times.
|
9442 | for (const auto &[incomingBlock, value] : shortCircuitBlocks) |
| 236 |
1/2✓ Branch 62 → 63 taken 3310 times.
✗ Branch 62 → 98 not taken.
|
3310 | result->addIncoming(value, incomingBlock); |
| 237 | |||
| 238 | // Return the result | ||
| 239 |
1/2✓ Branch 73 → 74 taken 1411 times.
✗ Branch 73 → 99 not taken.
|
1411 | return LLVMExprResult{.value = result}; |
| 240 | 1411 | } | |
| 241 | |||
| 242 | 377 | std::any IRGenerator::visitLogicalAndExpr(const LogicalAndExprNode *node) { | |
| 243 |
1/2✓ Branch 2 → 3 taken 377 times.
✗ Branch 2 → 104 not taken.
|
377 | diGenerator.setSourceLocation(node); |
| 244 | |||
| 245 | // Check if only one operand is present -> loop through | ||
| 246 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 377 times.
|
377 | if (node->operands.size() == 1) |
| 247 | ✗ | return visit(node->operands.front()); | |
| 248 | |||
| 249 | // It is a logical and expression | ||
| 250 | // Create exit block for short-circuiting | ||
| 251 |
1/2✓ Branch 8 → 9 taken 377 times.
✗ Branch 8 → 104 not taken.
|
377 | const std::string codeLoc = node->codeLoc.toPrettyLineAndColumn(); |
| 252 |
2/4✓ Branch 9 → 10 taken 377 times.
✗ Branch 9 → 81 not taken.
✓ Branch 10 → 11 taken 377 times.
✗ Branch 10 → 79 not taken.
|
377 | llvm::BasicBlock *bExit = createBlock("land.exit." + codeLoc); |
| 253 | |||
| 254 | // Visit the first operand | ||
| 255 |
1/2✓ Branch 13 → 14 taken 377 times.
✗ Branch 13 → 102 not taken.
|
377 | llvm::Value *firstOperandValue = resolveValue(node->operands.front()); |
| 256 | |||
| 257 | // Prepare an array for value-to-block-mapping | ||
| 258 | 377 | std::vector<std::pair<llvm::BasicBlock *, llvm::Value *>> shortCircuitBlocks; | |
| 259 |
1/2✓ Branch 15 → 16 taken 377 times.
✗ Branch 15 → 100 not taken.
|
377 | shortCircuitBlocks.reserve(node->operands.size()); |
| 260 | // The first element is the first operand value with the original block | ||
| 261 |
1/2✓ Branch 17 → 18 taken 377 times.
✗ Branch 17 → 82 not taken.
|
377 | shortCircuitBlocks.emplace_back(builder.GetInsertBlock(), firstOperandValue); |
| 262 | // Create a block for each additional operand and save it to the mapping | ||
| 263 |
2/2✓ Branch 31 → 19 taken 439 times.
✓ Branch 31 → 32 taken 377 times.
|
816 | for (size_t i = 1; i < node->operands.size(); i++) |
| 264 |
6/12✓ Branch 19 → 20 taken 439 times.
✗ Branch 19 → 91 not taken.
✓ Branch 20 → 21 taken 439 times.
✗ Branch 20 → 89 not taken.
✓ Branch 21 → 22 taken 439 times.
✗ Branch 21 → 87 not taken.
✓ Branch 22 → 23 taken 439 times.
✗ Branch 22 → 85 not taken.
✓ Branch 23 → 24 taken 439 times.
✗ Branch 23 → 83 not taken.
✓ Branch 24 → 25 taken 439 times.
✗ Branch 24 → 83 not taken.
|
439 | shortCircuitBlocks.emplace_back(createBlock("land." + std::to_string(i) + "." + codeLoc), nullptr); |
| 265 | // Create conditional jump to the exit block if the first operand was true, otherwise to the next block | ||
| 266 |
2/4✓ Branch 32 → 33 taken 377 times.
✗ Branch 32 → 100 not taken.
✓ Branch 33 → 34 taken 377 times.
✗ Branch 33 → 100 not taken.
|
377 | insertCondJump(firstOperandValue, shortCircuitBlocks.at(1).first, bExit); |
| 267 | |||
| 268 | // Create block for each operand | ||
| 269 |
2/2✓ Branch 50 → 35 taken 439 times.
✓ Branch 50 → 51 taken 377 times.
|
816 | for (size_t i = 1; i < node->operands.size(); i++) { |
| 270 | // Switch to the next block | ||
| 271 |
2/4✓ Branch 35 → 36 taken 439 times.
✗ Branch 35 → 100 not taken.
✓ Branch 36 → 37 taken 439 times.
✗ Branch 36 → 100 not taken.
|
439 | switchToBlock(shortCircuitBlocks.at(i).first); |
| 272 | // Evaluate operand and save the result in the mapping | ||
| 273 |
2/4✓ Branch 38 → 39 taken 439 times.
✗ Branch 38 → 100 not taken.
✓ Branch 39 → 40 taken 439 times.
✗ Branch 39 → 100 not taken.
|
439 | shortCircuitBlocks.at(i).second = resolveValue(node->operands[i]); |
| 274 | // Replace the array entry with the current insert block, since the insert block could have changed in the meantime | ||
| 275 |
1/2✓ Branch 41 → 42 taken 439 times.
✗ Branch 41 → 100 not taken.
|
439 | shortCircuitBlocks.at(i).first = builder.GetInsertBlock(); |
| 276 | // Check if there are more blocks to process | ||
| 277 |
2/2✓ Branch 43 → 44 taken 377 times.
✓ Branch 43 → 45 taken 62 times.
|
439 | if (i == node->operands.size() - 1) { |
| 278 | // Insert a simple jump to the exit block for the last block | ||
| 279 |
1/2✓ Branch 44 → 48 taken 377 times.
✗ Branch 44 → 100 not taken.
|
377 | insertJump(bExit); |
| 280 | } else { | ||
| 281 | // Create conditional jump to the exit block if the operand was true, otherwise to the next block | ||
| 282 |
3/6✓ Branch 45 → 46 taken 62 times.
✗ Branch 45 → 100 not taken.
✓ Branch 46 → 47 taken 62 times.
✗ Branch 46 → 100 not taken.
✓ Branch 47 → 48 taken 62 times.
✗ Branch 47 → 100 not taken.
|
62 | insertCondJump(shortCircuitBlocks.at(i).second, shortCircuitBlocks.at(i + 1).first, bExit); |
| 283 | } | ||
| 284 | } | ||
| 285 | |||
| 286 | // Get the result with the phi node | ||
| 287 |
1/2✓ Branch 51 → 52 taken 377 times.
✗ Branch 51 → 100 not taken.
|
377 | switchToBlock(bExit); |
| 288 |
2/4✓ Branch 52 → 53 taken 377 times.
✗ Branch 52 → 97 not taken.
✓ Branch 55 → 56 taken 377 times.
✗ Branch 55 → 97 not taken.
|
377 | llvm::PHINode *result = builder.CreatePHI(firstOperandValue->getType(), node->operands.size(), "land_phi"); |
| 289 |
2/2✓ Branch 72 → 58 taken 816 times.
✓ Branch 72 → 73 taken 377 times.
|
2386 | for (const auto &[incomingBlock, value] : shortCircuitBlocks) |
| 290 |
1/2✓ Branch 62 → 63 taken 816 times.
✗ Branch 62 → 98 not taken.
|
816 | result->addIncoming(value, incomingBlock); |
| 291 | |||
| 292 | // Return the result | ||
| 293 |
1/2✓ Branch 73 → 74 taken 377 times.
✗ Branch 73 → 99 not taken.
|
377 | return LLVMExprResult{.value = result}; |
| 294 | 377 | } | |
| 295 | |||
| 296 | 164 | std::any IRGenerator::visitBitwiseOrExpr(const BitwiseOrExprNode *node) { | |
| 297 |
1/2✓ Branch 2 → 3 taken 164 times.
✗ Branch 2 → 34 not taken.
|
164 | diGenerator.setSourceLocation(node); |
| 298 | |||
| 299 | // Check if only one operand is present -> loop through | ||
| 300 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 164 times.
|
164 | if (node->operands.size() == 1) |
| 301 | ✗ | return visit(node->operands.front()); | |
| 302 | |||
| 303 | // It is a bitwise or expression | ||
| 304 | // Evaluate first operand | ||
| 305 | 164 | const ExprNode *lhsNode = node->operands.front(); | |
| 306 |
1/2✓ Branch 9 → 10 taken 164 times.
✗ Branch 9 → 34 not taken.
|
164 | const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx); |
| 307 |
2/4✓ Branch 10 → 11 taken 164 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 164 times.
✗ Branch 11 → 27 not taken.
|
164 | auto result = std::any_cast<LLVMExprResult>(visit(lhsNode)); |
| 308 | |||
| 309 | // Evaluate all additional operands | ||
| 310 |
2/2✓ Branch 22 → 14 taken 165 times.
✓ Branch 22 → 23 taken 164 times.
|
329 | for (size_t i = 1; i < node->operands.size(); i++) { |
| 311 | // Evaluate the operand | ||
| 312 | 165 | const ExprNode *rhsNode = node->operands[i]; | |
| 313 |
1/2✓ Branch 15 → 16 taken 165 times.
✗ Branch 15 → 33 not taken.
|
165 | const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx); |
| 314 |
2/4✓ Branch 16 → 17 taken 165 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 165 times.
✗ Branch 17 → 30 not taken.
|
165 | auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode)); |
| 315 |
1/2✓ Branch 19 → 20 taken 165 times.
✗ Branch 19 → 33 not taken.
|
165 | result = conversionManager.getBitwiseOrInst(node, result, lhsSTy, rhs, rhsSTy, i - 1); |
| 316 | } | ||
| 317 | |||
| 318 | // Return result | ||
| 319 |
1/2✓ Branch 23 → 24 taken 164 times.
✗ Branch 23 → 34 not taken.
|
164 | return result; |
| 320 | } | ||
| 321 | |||
| 322 | 28 | std::any IRGenerator::visitBitwiseXorExpr(const BitwiseXorExprNode *node) { | |
| 323 |
1/2✓ Branch 2 → 3 taken 28 times.
✗ Branch 2 → 34 not taken.
|
28 | diGenerator.setSourceLocation(node); |
| 324 | |||
| 325 | // Check if only one operand is present -> loop through | ||
| 326 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 28 times.
|
28 | if (node->operands.size() == 1) |
| 327 | ✗ | return visit(node->operands.front()); | |
| 328 | |||
| 329 | // It is a bitwise xor expression | ||
| 330 | // Evaluate first operand | ||
| 331 | 28 | const ExprNode *lhsNode = node->operands.front(); | |
| 332 |
1/2✓ Branch 9 → 10 taken 28 times.
✗ Branch 9 → 34 not taken.
|
28 | const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx); |
| 333 |
2/4✓ Branch 10 → 11 taken 28 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 28 times.
✗ Branch 11 → 27 not taken.
|
28 | auto result = std::any_cast<LLVMExprResult>(visit(lhsNode)); |
| 334 | |||
| 335 | // Evaluate all additional operands | ||
| 336 |
2/2✓ Branch 22 → 14 taken 29 times.
✓ Branch 22 → 23 taken 28 times.
|
57 | for (size_t i = 1; i < node->operands.size(); i++) { |
| 337 | // Evaluate the operand | ||
| 338 | 29 | const ExprNode *rhsNode = node->operands[i]; | |
| 339 |
1/2✓ Branch 15 → 16 taken 29 times.
✗ Branch 15 → 33 not taken.
|
29 | const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx); |
| 340 |
2/4✓ Branch 16 → 17 taken 29 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 29 times.
✗ Branch 17 → 30 not taken.
|
29 | auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode)); |
| 341 |
1/2✓ Branch 19 → 20 taken 29 times.
✗ Branch 19 → 33 not taken.
|
29 | result = conversionManager.getBitwiseXorInst(node, result, lhsSTy, rhs, rhsSTy, i - 1); |
| 342 | } | ||
| 343 | |||
| 344 | // Return result | ||
| 345 |
1/2✓ Branch 23 → 24 taken 28 times.
✗ Branch 23 → 34 not taken.
|
28 | return result; |
| 346 | } | ||
| 347 | |||
| 348 | 57 | std::any IRGenerator::visitBitwiseAndExpr(const BitwiseAndExprNode *node) { | |
| 349 |
1/2✓ Branch 2 → 3 taken 57 times.
✗ Branch 2 → 34 not taken.
|
57 | diGenerator.setSourceLocation(node); |
| 350 | |||
| 351 | // Check if only one operand is present -> loop through | ||
| 352 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 57 times.
|
57 | if (node->operands.size() == 1) |
| 353 | ✗ | return visit(node->operands.front()); | |
| 354 | |||
| 355 | // It is a bitwise and expression | ||
| 356 | // Evaluate first operand | ||
| 357 | 57 | const ExprNode *lhsNode = node->operands.front(); | |
| 358 |
1/2✓ Branch 9 → 10 taken 57 times.
✗ Branch 9 → 34 not taken.
|
57 | const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx); |
| 359 |
2/4✓ Branch 10 → 11 taken 57 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 57 times.
✗ Branch 11 → 27 not taken.
|
57 | auto result = std::any_cast<LLVMExprResult>(visit(lhsNode)); |
| 360 | |||
| 361 | // Evaluate all additional operands | ||
| 362 |
2/2✓ Branch 22 → 14 taken 58 times.
✓ Branch 22 → 23 taken 57 times.
|
115 | for (size_t i = 1; i < node->operands.size(); i++) { |
| 363 | // Evaluate the operand | ||
| 364 | 58 | const ExprNode *rhsNode = node->operands[i]; | |
| 365 |
1/2✓ Branch 15 → 16 taken 58 times.
✗ Branch 15 → 33 not taken.
|
58 | const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx); |
| 366 |
2/4✓ Branch 16 → 17 taken 58 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 58 times.
✗ Branch 17 → 30 not taken.
|
58 | auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode)); |
| 367 |
1/2✓ Branch 19 → 20 taken 58 times.
✗ Branch 19 → 33 not taken.
|
58 | result = conversionManager.getBitwiseAndInst(node, result, lhsSTy, rhs, rhsSTy, i - 1); |
| 368 | } | ||
| 369 | |||
| 370 | // Return result | ||
| 371 |
1/2✓ Branch 23 → 24 taken 57 times.
✗ Branch 23 → 34 not taken.
|
57 | return result; |
| 372 | } | ||
| 373 | |||
| 374 | 10033 | std::any IRGenerator::visitEqualityExpr(const EqualityExprNode *node) { | |
| 375 |
1/2✓ Branch 2 → 3 taken 10033 times.
✗ Branch 2 → 50 not taken.
|
10033 | diGenerator.setSourceLocation(node); |
| 376 | |||
| 377 | // Check if only one operand is present -> loop through | ||
| 378 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 10033 times.
|
10033 | if (node->operands.size() == 1) |
| 379 | ✗ | return visit(node->operands.front()); | |
| 380 | |||
| 381 | // It is an equality expression | ||
| 382 | // Evaluate lhs | ||
| 383 | 10033 | const ExprNode *lhsNode = node->operands[0]; | |
| 384 |
1/2✓ Branch 9 → 10 taken 10033 times.
✗ Branch 9 → 50 not taken.
|
10033 | const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx); |
| 385 |
2/4✓ Branch 10 → 11 taken 10033 times.
✗ Branch 10 → 37 not taken.
✓ Branch 11 → 12 taken 10033 times.
✗ Branch 11 → 35 not taken.
|
10033 | auto result = std::any_cast<LLVMExprResult>(visit(lhsNode)); |
| 386 | |||
| 387 | // Evaluate rhs | ||
| 388 | 10033 | const ExprNode *rhsNode = node->operands[1]; | |
| 389 |
1/2✓ Branch 14 → 15 taken 10033 times.
✗ Branch 14 → 50 not taken.
|
10033 | const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx); |
| 390 |
2/4✓ Branch 15 → 16 taken 10033 times.
✗ Branch 15 → 40 not taken.
✓ Branch 16 → 17 taken 10033 times.
✗ Branch 16 → 38 not taken.
|
10033 | auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode)); |
| 391 | |||
| 392 | // Retrieve the result value, based on the exact operator | ||
| 393 |
2/3✓ Branch 18 → 19 taken 7666 times.
✓ Branch 18 → 21 taken 2367 times.
✗ Branch 18 → 23 not taken.
|
10033 | switch (node->op) { |
| 394 | 7666 | case EqualityExprNode::EqualityOp::OP_EQUAL: | |
| 395 |
1/2✓ Branch 19 → 20 taken 7666 times.
✗ Branch 19 → 50 not taken.
|
7666 | result = conversionManager.getEqualInst(node, result, lhsSTy, rhs, rhsSTy); |
| 396 | 7666 | break; | |
| 397 | 2367 | case EqualityExprNode::EqualityOp::OP_NOT_EQUAL: | |
| 398 |
1/2✓ Branch 21 → 22 taken 2367 times.
✗ Branch 21 → 50 not taken.
|
2367 | result = conversionManager.getNotEqualInst(node, result, lhsSTy, rhs, rhsSTy); |
| 399 | 2367 | break; | |
| 400 | − | default: // GCOV_EXCL_LINE | |
| 401 | − | throw CompilerError(UNHANDLED_BRANCH, "EqualityExpr fall-through"); // GCOV_EXCL_LINE | |
| 402 | } | ||
| 403 | |||
| 404 | // Return the result | ||
| 405 |
1/2✓ Branch 31 → 32 taken 10033 times.
✗ Branch 31 → 50 not taken.
|
10033 | return result; |
| 406 | } | ||
| 407 | |||
| 408 | 6448 | std::any IRGenerator::visitRelationalExpr(const RelationalExprNode *node) { | |
| 409 |
1/2✓ Branch 2 → 3 taken 6448 times.
✗ Branch 2 → 54 not taken.
|
6448 | diGenerator.setSourceLocation(node); |
| 410 | |||
| 411 | // Check if only one operand is present -> loop through | ||
| 412 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 6448 times.
|
6448 | if (node->operands.size() == 1) |
| 413 | ✗ | return visit(node->operands.front()); | |
| 414 | |||
| 415 | // It is a relational expression | ||
| 416 | // Evaluate lhs | ||
| 417 | 6448 | const ExprNode *lhsNode = node->operands[0]; | |
| 418 |
1/2✓ Branch 9 → 10 taken 6448 times.
✗ Branch 9 → 54 not taken.
|
6448 | const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx); |
| 419 |
2/4✓ Branch 10 → 11 taken 6448 times.
✗ Branch 10 → 41 not taken.
✓ Branch 11 → 12 taken 6448 times.
✗ Branch 11 → 39 not taken.
|
6448 | auto result = std::any_cast<LLVMExprResult>(visit(lhsNode)); |
| 420 | |||
| 421 | // Evaluate rhs | ||
| 422 | 6448 | const ExprNode *rhsNode = node->operands[1]; | |
| 423 |
1/2✓ Branch 14 → 15 taken 6448 times.
✗ Branch 14 → 54 not taken.
|
6448 | const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx); |
| 424 |
2/4✓ Branch 15 → 16 taken 6448 times.
✗ Branch 15 → 44 not taken.
✓ Branch 16 → 17 taken 6448 times.
✗ Branch 16 → 42 not taken.
|
6448 | auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode)); |
| 425 | |||
| 426 | // Retrieve the result value, based on the exact operator | ||
| 427 |
4/5✓ Branch 18 → 19 taken 3019 times.
✓ Branch 18 → 21 taken 1043 times.
✓ Branch 18 → 23 taken 761 times.
✓ Branch 18 → 25 taken 1625 times.
✗ Branch 18 → 27 not taken.
|
6448 | switch (node->op) { |
| 428 | 3019 | case RelationalExprNode::RelationalOp::OP_LESS: | |
| 429 |
1/2✓ Branch 19 → 20 taken 3019 times.
✗ Branch 19 → 54 not taken.
|
3019 | result = conversionManager.getLessInst(node, result, lhsSTy, rhs, rhsSTy); |
| 430 | 3019 | break; | |
| 431 | 1043 | case RelationalExprNode::RelationalOp::OP_GREATER: | |
| 432 |
1/2✓ Branch 21 → 22 taken 1043 times.
✗ Branch 21 → 54 not taken.
|
1043 | result = conversionManager.getGreaterInst(node, result, lhsSTy, rhs, rhsSTy); |
| 433 | 1043 | break; | |
| 434 | 761 | case RelationalExprNode::RelationalOp::OP_LESS_EQUAL: | |
| 435 |
1/2✓ Branch 23 → 24 taken 761 times.
✗ Branch 23 → 54 not taken.
|
761 | result = conversionManager.getLessEqualInst(node, result, lhsSTy, rhs, rhsSTy); |
| 436 | 761 | break; | |
| 437 | 1625 | case RelationalExprNode::RelationalOp::OP_GREATER_EQUAL: | |
| 438 |
1/2✓ Branch 25 → 26 taken 1625 times.
✗ Branch 25 → 54 not taken.
|
1625 | result = conversionManager.getGreaterEqualInst(node, result, lhsSTy, rhs, rhsSTy); |
| 439 | 1625 | break; | |
| 440 | − | default: // GCOV_EXCL_LINE | |
| 441 | − | throw CompilerError(UNHANDLED_BRANCH, "EqualityExpr fall-through"); // GCOV_EXCL_LINE | |
| 442 | } | ||
| 443 | |||
| 444 | // Return the result | ||
| 445 |
1/2✓ Branch 35 → 36 taken 6448 times.
✗ Branch 35 → 54 not taken.
|
6448 | return result; |
| 446 | } | ||
| 447 | |||
| 448 | 268 | std::any IRGenerator::visitShiftExpr(const ShiftExprNode *node) { | |
| 449 |
1/2✓ Branch 2 → 3 taken 268 times.
✗ Branch 2 → 64 not taken.
|
268 | diGenerator.setSourceLocation(node); |
| 450 | |||
| 451 | // Check if only one operand is present -> loop through | ||
| 452 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 268 times.
|
268 | if (node->operands.size() == 1) |
| 453 | ✗ | return visit(node->operands.front()); | |
| 454 | |||
| 455 | // It is a shift expression | ||
| 456 | // Evaluate first operand | ||
| 457 | 268 | const ExprNode *lhsNode = node->operands.front(); | |
| 458 |
1/2✓ Branch 9 → 10 taken 268 times.
✗ Branch 9 → 64 not taken.
|
268 | QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx); |
| 459 |
2/4✓ Branch 10 → 11 taken 268 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 268 times.
✗ Branch 11 → 46 not taken.
|
268 | auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode)); |
| 460 | |||
| 461 |
1/2✓ Branch 13 → 14 taken 268 times.
✗ Branch 13 → 64 not taken.
|
268 | auto opQueue = node->opQueue; |
| 462 | 268 | size_t operandIndex = 1; | |
| 463 |
2/2✓ Branch 40 → 15 taken 403 times.
✓ Branch 40 → 41 taken 268 times.
|
671 | while (!opQueue.empty()) { |
| 464 | 403 | const size_t operatorIndex = operandIndex - 1; | |
| 465 | // Evaluate next operand | ||
| 466 | 403 | const ExprNode *rhsNode = node->operands[operandIndex++]; | |
| 467 |
1/2✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 403 times.
|
403 | assert(rhsNode != nullptr); |
| 468 |
1/2✓ Branch 18 → 19 taken 403 times.
✗ Branch 18 → 61 not taken.
|
403 | const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx); |
| 469 |
2/4✓ Branch 19 → 20 taken 403 times.
✗ Branch 19 → 51 not taken.
✓ Branch 20 → 21 taken 403 times.
✗ Branch 20 → 49 not taken.
|
403 | auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode)); |
| 470 | |||
| 471 | // Retrieve the result, based on the exact operator | ||
| 472 |
2/3✓ Branch 23 → 24 taken 278 times.
✓ Branch 23 → 26 taken 125 times.
✗ Branch 23 → 28 not taken.
|
403 | switch (opQueue.front().first) { |
| 473 | 278 | case ShiftExprNode::ShiftOp::OP_SHIFT_LEFT: | |
| 474 |
1/2✓ Branch 24 → 25 taken 278 times.
✗ Branch 24 → 61 not taken.
|
278 | lhs = conversionManager.getShiftLeftInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex); |
| 475 | 278 | break; | |
| 476 | 125 | case ShiftExprNode::ShiftOp::OP_SHIFT_RIGHT: | |
| 477 |
1/2✓ Branch 26 → 27 taken 125 times.
✗ Branch 26 → 61 not taken.
|
125 | lhs = conversionManager.getShiftRightInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex); |
| 478 | 125 | break; | |
| 479 | − | default: // GCOV_EXCL_LINE | |
| 480 | − | throw CompilerError(UNHANDLED_BRANCH, "AdditiveExpr fall-through"); // GCOV_EXCL_LINE | |
| 481 | } | ||
| 482 | |||
| 483 | // Retrieve the new lhs symbol type | ||
| 484 | 403 | lhsSTy = opQueue.front().second; | |
| 485 | |||
| 486 | 403 | opQueue.pop(); | |
| 487 | } | ||
| 488 | |||
| 489 | // Return the result | ||
| 490 |
1/2✓ Branch 41 → 42 taken 268 times.
✗ Branch 41 → 62 not taken.
|
268 | return lhs; |
| 491 | 268 | } | |
| 492 | |||
| 493 | 6798 | std::any IRGenerator::visitAdditiveExpr(const AdditiveExprNode *node) { | |
| 494 |
1/2✓ Branch 2 → 3 taken 6798 times.
✗ Branch 2 → 64 not taken.
|
6798 | diGenerator.setSourceLocation(node); |
| 495 | |||
| 496 | // Check if only one operand is present -> loop through | ||
| 497 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 6798 times.
|
6798 | if (node->operands.size() == 1) |
| 498 | ✗ | return visit(node->operands.front()); | |
| 499 | |||
| 500 | // It is an additive expression | ||
| 501 | // Evaluate first operand | ||
| 502 | 6798 | const ExprNode *lhsNode = node->operands[0]; | |
| 503 |
1/2✓ Branch 9 → 10 taken 6798 times.
✗ Branch 9 → 64 not taken.
|
6798 | QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx); |
| 504 |
2/4✓ Branch 10 → 11 taken 6798 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 6798 times.
✗ Branch 11 → 46 not taken.
|
6798 | auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode)); |
| 505 | |||
| 506 |
1/2✓ Branch 13 → 14 taken 6798 times.
✗ Branch 13 → 64 not taken.
|
6798 | auto opQueue = node->opQueue; |
| 507 | 6798 | size_t operandIndex = 1; | |
| 508 |
2/2✓ Branch 40 → 15 taken 7702 times.
✓ Branch 40 → 41 taken 6798 times.
|
14500 | while (!opQueue.empty()) { |
| 509 | 7702 | const size_t operatorIndex = operandIndex - 1; | |
| 510 | // Evaluate next operand | ||
| 511 | 7702 | const ExprNode *rhsNode = node->operands[operandIndex++]; | |
| 512 |
1/2✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 7702 times.
|
7702 | assert(rhsNode != nullptr); |
| 513 |
1/2✓ Branch 18 → 19 taken 7702 times.
✗ Branch 18 → 61 not taken.
|
7702 | const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx); |
| 514 |
2/4✓ Branch 19 → 20 taken 7702 times.
✗ Branch 19 → 51 not taken.
✓ Branch 20 → 21 taken 7702 times.
✗ Branch 20 → 49 not taken.
|
7702 | auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode)); |
| 515 | |||
| 516 | // Retrieve the result, based on the exact operator | ||
| 517 |
2/3✓ Branch 23 → 24 taken 4920 times.
✓ Branch 23 → 26 taken 2782 times.
✗ Branch 23 → 28 not taken.
|
7702 | switch (opQueue.front().first) { |
| 518 | 4920 | case AdditiveExprNode::AdditiveOp::OP_PLUS: | |
| 519 |
1/2✓ Branch 24 → 25 taken 4920 times.
✗ Branch 24 → 61 not taken.
|
4920 | lhs = conversionManager.getPlusInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex); |
| 520 | 4920 | break; | |
| 521 | 2782 | case AdditiveExprNode::AdditiveOp::OP_MINUS: | |
| 522 |
1/2✓ Branch 26 → 27 taken 2782 times.
✗ Branch 26 → 61 not taken.
|
2782 | lhs = conversionManager.getMinusInst(node, lhs, lhsSTy, rhs, rhsSTy, operatorIndex); |
| 523 | 2782 | break; | |
| 524 | − | default: // GCOV_EXCL_LINE | |
| 525 | − | throw CompilerError(UNHANDLED_BRANCH, "AdditiveExpr fall-through"); // GCOV_EXCL_LINE | |
| 526 | } | ||
| 527 | |||
| 528 | // Retrieve the new lhs symbol type | ||
| 529 | 7702 | lhsSTy = opQueue.front().second; | |
| 530 | |||
| 531 | 7702 | opQueue.pop(); | |
| 532 | } | ||
| 533 | |||
| 534 | // Return the result | ||
| 535 |
1/2✓ Branch 41 → 42 taken 6798 times.
✗ Branch 41 → 62 not taken.
|
6798 | return lhs; |
| 536 | 6798 | } | |
| 537 | |||
| 538 | 1944 | std::any IRGenerator::visitMultiplicativeExpr(const MultiplicativeExprNode *node) { | |
| 539 |
1/2✓ Branch 2 → 3 taken 1944 times.
✗ Branch 2 → 66 not taken.
|
1944 | diGenerator.setSourceLocation(node); |
| 540 | |||
| 541 | // Check if only one operand is present -> loop through | ||
| 542 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 1944 times.
|
1944 | if (node->operands.size() == 1) |
| 543 | ✗ | return visit(node->operands.front()); | |
| 544 | |||
| 545 | // It is an additive expression | ||
| 546 | // Evaluate first operand | ||
| 547 | 1944 | const ExprNode *lhsNode = node->operands[0]; | |
| 548 |
1/2✓ Branch 9 → 10 taken 1944 times.
✗ Branch 9 → 66 not taken.
|
1944 | QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx); |
| 549 |
2/4✓ Branch 10 → 11 taken 1944 times.
✗ Branch 10 → 50 not taken.
✓ Branch 11 → 12 taken 1944 times.
✗ Branch 11 → 48 not taken.
|
1944 | auto result = std::any_cast<LLVMExprResult>(visit(lhsNode)); |
| 550 | |||
| 551 |
1/2✓ Branch 13 → 14 taken 1944 times.
✗ Branch 13 → 66 not taken.
|
1944 | auto opQueue = node->opQueue; |
| 552 | 1944 | size_t operandIndex = 1; | |
| 553 |
2/2✓ Branch 42 → 15 taken 1989 times.
✓ Branch 42 → 43 taken 1944 times.
|
3933 | while (!opQueue.empty()) { |
| 554 | 1989 | const size_t operatorIndex = operandIndex - 1; | |
| 555 | // Evaluate next operand | ||
| 556 | 1989 | const ExprNode *rhsNode = node->operands[operandIndex++]; | |
| 557 |
1/2✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 1989 times.
|
1989 | assert(rhsNode != nullptr); |
| 558 |
1/2✓ Branch 18 → 19 taken 1989 times.
✗ Branch 18 → 63 not taken.
|
1989 | const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx); |
| 559 |
2/4✓ Branch 19 → 20 taken 1989 times.
✗ Branch 19 → 53 not taken.
✓ Branch 20 → 21 taken 1989 times.
✗ Branch 20 → 51 not taken.
|
1989 | auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode)); |
| 560 | |||
| 561 | // Retrieve the result, based on the exact operator | ||
| 562 |
3/4✓ Branch 23 → 24 taken 1458 times.
✓ Branch 23 → 26 taken 430 times.
✓ Branch 23 → 28 taken 101 times.
✗ Branch 23 → 30 not taken.
|
1989 | switch (opQueue.front().first) { |
| 563 | 1458 | case MultiplicativeExprNode::MultiplicativeOp::OP_MUL: | |
| 564 |
1/2✓ Branch 24 → 25 taken 1458 times.
✗ Branch 24 → 63 not taken.
|
1458 | result = conversionManager.getMulInst(node, result, lhsSTy, rhs, rhsSTy, operatorIndex); |
| 565 | 1458 | break; | |
| 566 | 430 | case MultiplicativeExprNode::MultiplicativeOp::OP_DIV: | |
| 567 |
1/2✓ Branch 26 → 27 taken 430 times.
✗ Branch 26 → 63 not taken.
|
430 | result = conversionManager.getDivInst(node, result, lhsSTy, rhs, rhsSTy, operatorIndex); |
| 568 | 430 | break; | |
| 569 | 101 | case MultiplicativeExprNode::MultiplicativeOp::OP_REM: | |
| 570 |
1/2✓ Branch 28 → 29 taken 101 times.
✗ Branch 28 → 63 not taken.
|
101 | result = conversionManager.getRemInst(node, result, lhsSTy, rhs, rhsSTy); |
| 571 | 101 | break; | |
| 572 | − | default: // GCOV_EXCL_LINE | |
| 573 | − | throw CompilerError(UNHANDLED_BRANCH, "MultiplicativeExpr fall-through"); // GCOV_EXCL_LINE | |
| 574 | } | ||
| 575 | |||
| 576 | // Retrieve the new lhs symbol type | ||
| 577 | 1989 | lhsSTy = opQueue.front().second; | |
| 578 | 1989 | opQueue.pop(); | |
| 579 | } | ||
| 580 | |||
| 581 | // Return the result | ||
| 582 |
1/2✓ Branch 43 → 44 taken 1944 times.
✗ Branch 43 → 64 not taken.
|
1944 | return result; |
| 583 | 1944 | } | |
| 584 | |||
| 585 | 4673 | std::any IRGenerator::visitCastExpr(const CastExprNode *node) { | |
| 586 |
1/2✓ Branch 2 → 3 taken 4673 times.
✗ Branch 2 → 19 not taken.
|
4673 | diGenerator.setSourceLocation(node); |
| 587 | |||
| 588 | // Check if only one operand is present -> loop through | ||
| 589 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 4673 times.
|
4673 | if (!node->isCast) |
| 590 | ✗ | return visit(node->prefixUnaryExpr); | |
| 591 | |||
| 592 | // It is a cast expression | ||
| 593 | // Retrieve target symbol type | ||
| 594 |
1/2✓ Branch 6 → 7 taken 4673 times.
✗ Branch 6 → 19 not taken.
|
4673 | const QualType targetSTy = node->getEvaluatedSymbolType(manIdx); |
| 595 | |||
| 596 | // Evaluate rhs | ||
| 597 | 4673 | const ExprNode *rhsNode = node->assignExpr; | |
| 598 |
1/2✓ Branch 7 → 8 taken 4673 times.
✗ Branch 7 → 19 not taken.
|
4673 | const QualType rhsSTy = rhsNode->getEvaluatedSymbolType(manIdx); |
| 599 |
2/4✓ Branch 8 → 9 taken 4673 times.
✗ Branch 8 → 18 not taken.
✓ Branch 9 → 10 taken 4673 times.
✗ Branch 9 → 16 not taken.
|
4673 | auto rhs = std::any_cast<LLVMExprResult>(visit(rhsNode)); |
| 600 | |||
| 601 | // Retrieve the result value | ||
| 602 |
1/2✓ Branch 11 → 12 taken 4673 times.
✗ Branch 11 → 19 not taken.
|
4673 | const LLVMExprResult result = conversionManager.getCastInst(node, targetSTy, rhs, rhsSTy); |
| 603 | |||
| 604 | // Return the result | ||
| 605 |
1/2✓ Branch 12 → 13 taken 4673 times.
✗ Branch 12 → 19 not taken.
|
4673 | return result; |
| 606 | } | ||
| 607 | |||
| 608 | 3511 | std::any IRGenerator::visitPrefixUnaryExpr(const PrefixUnaryExprNode *node) { | |
| 609 |
1/2✓ Branch 2 → 3 taken 3511 times.
✗ Branch 2 → 117 not taken.
|
3511 | diGenerator.setSourceLocation(node); |
| 610 | |||
| 611 | // If no operator is applied, simply visit the atomic expression | ||
| 612 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 3511 times.
|
3511 | if (node->op == PrefixUnaryExprNode::PrefixUnaryOp::OP_NONE) |
| 613 | ✗ | return visit(node->postfixUnaryExpr); | |
| 614 | |||
| 615 | // Evaluate lhs | ||
| 616 | 3511 | const ExprNode *lhsNode = node->prefixUnaryExpr; | |
| 617 |
1/2✓ Branch 6 → 7 taken 3511 times.
✗ Branch 6 → 117 not taken.
|
3511 | const QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx); |
| 618 |
2/4✓ Branch 7 → 8 taken 3511 times.
✗ Branch 7 → 87 not taken.
✓ Branch 8 → 9 taken 3511 times.
✗ Branch 8 → 85 not taken.
|
3511 | auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode)); |
| 619 | |||
| 620 |
7/8✓ Branch 10 → 11 taken 991 times.
✓ Branch 10 → 21 taken 39 times.
✓ Branch 10 → 36 taken 12 times.
✓ Branch 10 → 51 taken 1731 times.
✓ Branch 10 → 53 taken 12 times.
✓ Branch 10 → 55 taken 431 times.
✓ Branch 10 → 64 taken 295 times.
✗ Branch 10 → 73 not taken.
|
3511 | switch (node->op) { |
| 621 | 991 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS: { | |
| 622 | // Execute operation | ||
| 623 |
1/2✓ Branch 11 → 12 taken 991 times.
✗ Branch 11 → 117 not taken.
|
991 | lhs = conversionManager.getPrefixMinusInst(node, lhs, lhsSTy); |
| 624 | |||
| 625 | // This operator can not work in-place, so we need additional memory | ||
| 626 |
1/2✓ Branch 16 → 17 taken 991 times.
✗ Branch 16 → 88 not taken.
|
991 | lhs.ptr = insertAlloca(lhs.value->getType()); |
| 627 | |||
| 628 | // Store the new value | ||
| 629 |
1/2✓ Branch 19 → 20 taken 991 times.
✗ Branch 19 → 117 not taken.
|
991 | insertStore(lhs.value, lhs.ptr); |
| 630 | |||
| 631 | 991 | break; | |
| 632 | } | ||
| 633 | 39 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_PLUS_PLUS: { | |
| 634 | // Execute operation | ||
| 635 |
1/2✓ Branch 21 → 22 taken 39 times.
✗ Branch 21 → 94 not taken.
|
39 | lhs.value = conversionManager.getPrefixPlusPlusInst(node, lhs, lhsSTy).value; |
| 636 | |||
| 637 | // If this operation happens on a volatile variable, store the value directly | ||
| 638 |
3/4✓ Branch 22 → 23 taken 38 times.
✓ Branch 22 → 25 taken 1 time.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 38 times.
|
39 | if (lhs.entry && lhs.entry->isVolatile) |
| 639 | ✗ | insertStore(lhs.value, lhs.ptr, true); | |
| 640 | |||
| 641 | // Save to the existing address if possible, otherwise (e.g. for literals) allocate new space | ||
| 642 |
2/2✓ Branch 25 → 26 taken 1 time.
✓ Branch 25 → 34 taken 38 times.
|
39 | if (!lhs.ptr) |
| 643 |
1/2✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 95 not taken.
|
1 | lhs.ptr = insertAlloca(lhs.value->getType()); |
| 644 | |||
| 645 | // Store the new value | ||
| 646 |
1/2✓ Branch 34 → 35 taken 39 times.
✗ Branch 34 → 117 not taken.
|
39 | insertStore(lhs.value, lhs.ptr); |
| 647 | |||
| 648 | 39 | break; | |
| 649 | } | ||
| 650 | 12 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS_MINUS: { | |
| 651 | // Execute operation | ||
| 652 |
1/2✓ Branch 36 → 37 taken 12 times.
✗ Branch 36 → 101 not taken.
|
12 | lhs.value = conversionManager.getPrefixMinusMinusInst(node, lhs, lhsSTy).value; |
| 653 | |||
| 654 | // If this operation happens on a volatile variable, store the value directly | ||
| 655 |
3/4✓ Branch 37 → 38 taken 11 times.
✓ Branch 37 → 40 taken 1 time.
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 11 times.
|
12 | if (lhs.entry && lhs.entry->isVolatile) |
| 656 | ✗ | insertStore(lhs.value, lhs.ptr, true); | |
| 657 | |||
| 658 | // Save to the existing address if possible, otherwise (e.g. for literals) allocate new space | ||
| 659 |
2/2✓ Branch 40 → 41 taken 1 time.
✓ Branch 40 → 49 taken 11 times.
|
12 | if (!lhs.ptr) |
| 660 |
1/2✓ Branch 45 → 46 taken 1 time.
✗ Branch 45 → 102 not taken.
|
1 | lhs.ptr = insertAlloca(lhs.value->getType()); |
| 661 | |||
| 662 | // Store the new value | ||
| 663 |
1/2✓ Branch 49 → 50 taken 12 times.
✗ Branch 49 → 117 not taken.
|
12 | insertStore(lhs.value, lhs.ptr); |
| 664 | |||
| 665 | 12 | break; | |
| 666 | } | ||
| 667 | 1731 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_NOT: { | |
| 668 | // Execute operation | ||
| 669 |
1/2✓ Branch 51 → 52 taken 1731 times.
✗ Branch 51 → 117 not taken.
|
1731 | lhs = conversionManager.getPrefixNotInst(node, lhs, lhsSTy); |
| 670 | 1731 | break; | |
| 671 | } | ||
| 672 | 12 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_BITWISE_NOT: { | |
| 673 | // Execute operation | ||
| 674 |
1/2✓ Branch 53 → 54 taken 12 times.
✗ Branch 53 → 117 not taken.
|
12 | lhs = conversionManager.getPrefixBitwiseNotInst(node, lhs, lhsSTy); |
| 675 | 12 | break; | |
| 676 | } | ||
| 677 | 431 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_DEREFERENCE: { | |
| 678 | // If only .refPtr is filled, we can't simply rewire the fields, but need to actually perform a load. | ||
| 679 | // For that we can use resolveValue(). | ||
| 680 |
4/4✓ Branch 55 → 56 taken 416 times.
✓ Branch 55 → 58 taken 15 times.
✓ Branch 56 → 57 taken 19 times.
✓ Branch 56 → 58 taken 397 times.
|
431 | const bool onlyRefPtrIsFilled = lhs.value == nullptr && lhs.ptr == nullptr; |
| 681 | // Rewire the fields | ||
| 682 |
3/4✓ Branch 59 → 60 taken 19 times.
✓ Branch 59 → 62 taken 412 times.
✓ Branch 60 → 61 taken 19 times.
✗ Branch 60 → 117 not taken.
|
431 | llvm::Value *newRefPtr = onlyRefPtrIsFilled ? resolveValue(lhsNode, lhs) : lhs.ptr; |
| 683 | 431 | llvm::Value *newPtr = lhs.value; | |
| 684 | 431 | lhs = {.ptr = newPtr, .refPtr = newRefPtr}; | |
| 685 | 431 | break; | |
| 686 | } | ||
| 687 | 295 | case PrefixUnaryExprNode::PrefixUnaryOp::OP_ADDRESS_OF: { | |
| 688 | // If only .value is filled, we can't simply rewire the fields, but need to actually perform alloca + store. | ||
| 689 | // For that we can use resolveAddress(). | ||
| 690 |
4/4✓ Branch 64 → 65 taken 22 times.
✓ Branch 64 → 67 taken 273 times.
✓ Branch 65 → 66 taken 2 times.
✓ Branch 65 → 67 taken 20 times.
|
295 | const bool onlyValueIsFilled = lhs.ptr == nullptr && lhs.refPtr == nullptr; |
| 691 | // Rewire the fields | ||
| 692 |
3/4✓ Branch 68 → 69 taken 2 times.
✓ Branch 68 → 71 taken 293 times.
✓ Branch 69 → 70 taken 2 times.
✗ Branch 69 → 117 not taken.
|
295 | llvm::Value *newValue = onlyValueIsFilled ? resolveAddress(lhs) : lhs.ptr; |
| 693 | 295 | llvm::Value *newPtr = lhs.refPtr; | |
| 694 | 295 | lhs = {.value = newValue, .ptr = newPtr}; | |
| 695 | 295 | break; | |
| 696 | } | ||
| 697 | − | default: // GCOV_EXCL_LINE | |
| 698 | − | throw CompilerError(UNHANDLED_BRANCH, "PrefixUnaryExpr fall-through"); // GCOV_EXCL_LINE | |
| 699 | } | ||
| 700 | |||
| 701 |
1/2✓ Branch 81 → 82 taken 3511 times.
✗ Branch 81 → 117 not taken.
|
3511 | return lhs; |
| 702 | } | ||
| 703 | |||
| 704 | 37368 | std::any IRGenerator::visitPostfixUnaryExpr(const PostfixUnaryExprNode *node) { | |
| 705 |
1/2✓ Branch 2 → 3 taken 37368 times.
✗ Branch 2 → 244 not taken.
|
37368 | diGenerator.setSourceLocation(node); |
| 706 | |||
| 707 | // If no operator is applied, simply visit the atomic expression | ||
| 708 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 37368 times.
|
37368 | if (node->op == PostfixUnaryExprNode::PostfixUnaryOp::OP_NONE) |
| 709 | ✗ | return visit(node->atomicExpr); | |
| 710 | |||
| 711 | // Evaluate lhs | ||
| 712 | 37368 | const ExprNode *lhsNode = node->postfixUnaryExpr; | |
| 713 |
1/2✓ Branch 6 → 7 taken 37368 times.
✗ Branch 6 → 244 not taken.
|
37368 | QualType lhsSTy = lhsNode->getEvaluatedSymbolType(manIdx); |
| 714 |
2/4✓ Branch 7 → 8 taken 37368 times.
✗ Branch 7 → 169 not taken.
✓ Branch 8 → 9 taken 37368 times.
✗ Branch 8 → 167 not taken.
|
37368 | auto lhs = std::any_cast<LLVMExprResult>(visit(lhsNode)); |
| 715 | |||
| 716 |
4/5✓ Branch 10 → 11 taken 4977 times.
✓ Branch 10 → 62 taken 28836 times.
✓ Branch 10 → 107 taken 2959 times.
✓ Branch 10 → 131 taken 596 times.
✗ Branch 10 → 155 not taken.
|
37368 | switch (node->op) { |
| 717 | 4977 | case PostfixUnaryExprNode::PostfixUnaryOp::OP_SUBSCRIPT: { | |
| 718 | 4977 | const ExprNode *indexExpr = node->subscriptIndexExpr; | |
| 719 | |||
| 720 | // Check if we need to generate a call to an overloaded operator function | ||
| 721 |
3/4✓ Branch 11 → 12 taken 4977 times.
✗ Branch 11 → 205 not taken.
✓ Branch 12 → 13 taken 280 times.
✓ Branch 12 → 29 taken 4697 times.
|
4977 | if (conversionManager.callsOverloadedOpFct(node, 0)) { |
| 722 |
1/2✓ Branch 13 → 14 taken 280 times.
✗ Branch 13 → 170 not taken.
|
280 | ResolverFct lhsV = [&] { return resolveValue(lhsSTy, lhs); }; |
| 723 | 560 | ResolverFct lhsP = [&] { return resolveAddress(lhs); }; | |
| 724 | 537 | ResolverFct idxV = [&] { return resolveValue(indexExpr); }; | |
| 725 | 303 | ResolverFct idxP = [&] { return resolveAddress(indexExpr); }; | |
| 726 | 280 | lhs = conversionManager.callOperatorOverloadFct<2>(node, {lhsV, lhsP, idxV, idxP}, 0); | |
| 727 | 280 | break; | |
| 728 | 280 | } | |
| 729 | |||
| 730 |
1/2✓ Branch 29 → 30 taken 4697 times.
✗ Branch 29 → 188 not taken.
|
4697 | lhsSTy = lhsSTy.removeReferenceWrapper(); |
| 731 | |||
| 732 | // Get the index value | ||
| 733 |
1/2✓ Branch 30 → 31 taken 4697 times.
✗ Branch 30 → 205 not taken.
|
4697 | llvm::Value *indexValue = resolveValue(indexExpr); |
| 734 | // Come up with the address | ||
| 735 |
8/10✓ Branch 31 → 32 taken 4697 times.
✗ Branch 31 → 205 not taken.
✓ Branch 32 → 33 taken 229 times.
✓ Branch 32 → 36 taken 4468 times.
✓ Branch 33 → 34 taken 229 times.
✗ Branch 33 → 205 not taken.
✓ Branch 34 → 35 taken 174 times.
✓ Branch 34 → 36 taken 55 times.
✓ Branch 37 → 38 taken 174 times.
✓ Branch 37 → 49 taken 4523 times.
|
4697 | if (lhsSTy.isArray() && lhsSTy.getArraySize() != ARRAY_SIZE_UNKNOWN) { // Array |
| 736 | // Make sure the address is present | ||
| 737 |
1/2✓ Branch 38 → 39 taken 174 times.
✗ Branch 38 → 196 not taken.
|
174 | resolveAddress(lhs); |
| 738 | |||
| 739 | // Calculate address of array item | ||
| 740 |
1/2✓ Branch 39 → 40 taken 174 times.
✗ Branch 39 → 196 not taken.
|
174 | llvm::Type *lhsTy = lhsSTy.toLLVMType(sourceFile); |
| 741 |
1/2✓ Branch 40 → 41 taken 174 times.
✗ Branch 40 → 196 not taken.
|
174 | llvm::Value *indices[2] = {builder.getInt64(0), indexValue}; |
| 742 |
1/2✓ Branch 45 → 46 taken 174 times.
✗ Branch 45 → 189 not taken.
|
174 | lhs.ptr = insertInBoundsGEP(lhsTy, lhs.ptr, indices); |
| 743 | } else { // Pointer | ||
| 744 | // Now the pointer is the value | ||
| 745 |
1/2✓ Branch 49 → 50 taken 4523 times.
✗ Branch 49 → 205 not taken.
|
4523 | lhs.ptr = resolveValue(lhsNode, lhs); |
| 746 | |||
| 747 |
2/4✓ Branch 50 → 51 taken 4523 times.
✗ Branch 50 → 197 not taken.
✓ Branch 51 → 52 taken 4523 times.
✗ Branch 51 → 197 not taken.
|
4523 | llvm::Type *lhsTy = lhsSTy.getContained().toLLVMType(sourceFile); |
| 748 | // Calculate address of pointer item | ||
| 749 |
1/2✓ Branch 56 → 57 taken 4523 times.
✗ Branch 56 → 198 not taken.
|
4523 | lhs.ptr = insertInBoundsGEP(lhsTy, lhs.ptr, indexValue); |
| 750 | } | ||
| 751 | |||
| 752 | // Reset value and entry | ||
| 753 | 4697 | lhs.value = nullptr; | |
| 754 | 4697 | lhs.entry = nullptr; | |
| 755 | 4697 | break; | |
| 756 | } | ||
| 757 | 28836 | case PostfixUnaryExprNode::PostfixUnaryOp::OP_MEMBER_ACCESS: { | |
| 758 | // Get the address of the struct instance | ||
| 759 |
1/2✓ Branch 62 → 63 taken 28836 times.
✗ Branch 62 → 220 not taken.
|
28836 | resolveAddress(lhs); |
| 760 |
1/2✓ Branch 63 → 64 taken 28836 times.
✗ Branch 63 → 206 not taken.
|
28836 | lhsSTy = lhsSTy.removeReferenceWrapper(); |
| 761 | |||
| 762 | // Auto de-reference pointer | ||
| 763 |
1/2✓ Branch 64 → 65 taken 28836 times.
✗ Branch 64 → 220 not taken.
|
28836 | autoDeReferencePtr(lhs.ptr, lhsSTy); |
| 764 |
2/4✓ Branch 65 → 66 taken 28836 times.
✗ Branch 65 → 220 not taken.
✗ Branch 66 → 67 not taken.
✓ Branch 66 → 68 taken 28836 times.
|
28836 | assert(lhsSTy.is(TY_STRUCT)); |
| 765 | |||
| 766 | // Retrieve struct scope | ||
| 767 | 28836 | const std::string &fieldName = node->identifier; | |
| 768 |
1/2✓ Branch 68 → 69 taken 28836 times.
✗ Branch 68 → 220 not taken.
|
28836 | Scope *structScope = lhsSTy.getBodyScope(); |
| 769 | |||
| 770 | // Retrieve field entry | ||
| 771 | 28836 | std::vector<size_t> indexPath; | |
| 772 |
1/2✓ Branch 69 → 70 taken 28836 times.
✗ Branch 69 → 218 not taken.
|
28836 | lhs.entry = structScope->symbolTable.lookupInComposedFields(fieldName, indexPath); |
| 773 |
1/2✗ Branch 70 → 71 not taken.
✓ Branch 70 → 72 taken 28836 times.
|
28836 | assert(lhs.entry != nullptr); |
| 774 |
1/2✓ Branch 72 → 73 taken 28836 times.
✗ Branch 72 → 218 not taken.
|
28836 | const QualType fieldSymbolType = lhs.entry->getQualType(); |
| 775 | |||
| 776 | // Get address of the field in the struct instance | ||
| 777 |
2/4✓ Branch 73 → 74 taken 28836 times.
✗ Branch 73 → 210 not taken.
✓ Branch 76 → 77 taken 28836 times.
✗ Branch 76 → 207 not taken.
|
57672 | std::vector<llvm::Value *> indices = {builder.getInt64(0)}; |
| 778 |
2/2✓ Branch 93 → 80 taken 28874 times.
✓ Branch 93 → 94 taken 28836 times.
|
86546 | for (const size_t index : indexPath) |
| 779 |
2/4✓ Branch 82 → 83 taken 28874 times.
✗ Branch 82 → 211 not taken.
✓ Branch 83 → 84 taken 28874 times.
✗ Branch 83 → 211 not taken.
|
28874 | indices.push_back(builder.getInt32(index)); |
| 780 |
1/2✓ Branch 94 → 95 taken 28836 times.
✗ Branch 94 → 216 not taken.
|
28836 | const std::string name = fieldName + ".addr"; |
| 781 |
2/4✓ Branch 96 → 97 taken 28836 times.
✗ Branch 96 → 213 not taken.
✓ Branch 97 → 98 taken 28836 times.
✗ Branch 97 → 213 not taken.
|
28836 | llvm::Value *memberAddr = insertInBoundsGEP(lhsSTy.toLLVMType(sourceFile), lhs.ptr, indices, name); |
| 782 | |||
| 783 | // Set as ptr or refPtr, depending on the type | ||
| 784 |
3/4✓ Branch 98 → 99 taken 28836 times.
✗ Branch 98 → 214 not taken.
✓ Branch 99 → 100 taken 436 times.
✓ Branch 99 → 101 taken 28400 times.
|
28836 | if (fieldSymbolType.isRef()) { |
| 785 | 436 | lhs.ptr = nullptr; | |
| 786 | 436 | lhs.refPtr = memberAddr; | |
| 787 | } else { | ||
| 788 | 28400 | lhs.ptr = memberAddr; | |
| 789 | 28400 | lhs.refPtr = nullptr; | |
| 790 | } | ||
| 791 | |||
| 792 | // Reset the value | ||
| 793 | 28836 | lhs.value = nullptr; | |
| 794 | 28836 | break; | |
| 795 | 28836 | } | |
| 796 | 2959 | case PostfixUnaryExprNode::PostfixUnaryOp::OP_PLUS_PLUS: { | |
| 797 | // Make sure a value is present | ||
| 798 |
1/2✓ Branch 107 → 108 taken 2959 times.
✗ Branch 107 → 227 not taken.
|
2959 | resolveValue(lhsNode, lhs); |
| 799 | |||
| 800 | // Allocate new local variable if required | ||
| 801 |
2/2✓ Branch 108 → 109 taken 2 times.
✓ Branch 108 → 119 taken 2957 times.
|
2959 | if (!lhs.ptr) { |
| 802 |
1/2✗ Branch 109 → 110 not taken.
✓ Branch 109 → 111 taken 2 times.
|
2 | assert(lhs.value != nullptr); |
| 803 |
1/2✓ Branch 115 → 116 taken 2 times.
✗ Branch 115 → 221 not taken.
|
2 | lhs.ptr = insertAlloca(lhs.value->getType()); |
| 804 | } | ||
| 805 | |||
| 806 | // Execute operation | ||
| 807 |
1/2✓ Branch 119 → 120 taken 2959 times.
✗ Branch 119 → 227 not taken.
|
2959 | const LLVMExprResult result = conversionManager.getPostfixPlusPlusInst(node, lhs, lhsSTy); |
| 808 | |||
| 809 | // Save the new value to the old address | ||
| 810 |
3/4✓ Branch 120 → 121 taken 2959 times.
✗ Branch 120 → 227 not taken.
✓ Branch 121 → 122 taken 9 times.
✓ Branch 121 → 123 taken 2950 times.
|
2959 | if (conversionManager.callsOverloadedOpFct(node, 0)) { |
| 811 | 9 | lhs.value = result.value; | |
| 812 | 9 | lhs.ptr = result.ptr; | |
| 813 | } else { | ||
| 814 |
5/6✓ Branch 123 → 124 taken 2947 times.
✓ Branch 123 → 126 taken 3 times.
✓ Branch 124 → 125 taken 3 times.
✓ Branch 124 → 126 taken 2944 times.
✓ Branch 127 → 128 taken 2950 times.
✗ Branch 127 → 227 not taken.
|
2950 | insertStore(result.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile); |
| 815 | 2950 | lhs.ptr = nullptr; | |
| 816 | } | ||
| 817 | 2959 | break; | |
| 818 | } | ||
| 819 | 596 | case PostfixUnaryExprNode::PostfixUnaryOp::OP_MINUS_MINUS: { | |
| 820 | // Make sure a value is present | ||
| 821 |
1/2✓ Branch 131 → 132 taken 596 times.
✗ Branch 131 → 234 not taken.
|
596 | resolveValue(lhsNode, lhs); |
| 822 | |||
| 823 | // Allocate new local variable if required | ||
| 824 |
2/2✓ Branch 132 → 133 taken 2 times.
✓ Branch 132 → 143 taken 594 times.
|
596 | if (!lhs.ptr) { |
| 825 |
1/2✗ Branch 133 → 134 not taken.
✓ Branch 133 → 135 taken 2 times.
|
2 | assert(lhs.value != nullptr); |
| 826 |
1/2✓ Branch 139 → 140 taken 2 times.
✗ Branch 139 → 228 not taken.
|
2 | lhs.ptr = insertAlloca(lhs.value->getType()); |
| 827 | } | ||
| 828 | |||
| 829 | // Execute operation | ||
| 830 |
1/2✓ Branch 143 → 144 taken 596 times.
✗ Branch 143 → 234 not taken.
|
596 | const LLVMExprResult result = conversionManager.getPostfixMinusMinusInst(node, lhs, lhsSTy); |
| 831 | |||
| 832 | // Save the new value to the old address | ||
| 833 |
3/4✓ Branch 144 → 145 taken 596 times.
✗ Branch 144 → 234 not taken.
✓ Branch 145 → 146 taken 7 times.
✓ Branch 145 → 147 taken 589 times.
|
596 | if (conversionManager.callsOverloadedOpFct(node, 0)) { |
| 834 | 7 | lhs.value = result.value; | |
| 835 | 7 | lhs.ptr = result.ptr; | |
| 836 | } else { | ||
| 837 |
4/6✓ Branch 147 → 148 taken 587 times.
✓ Branch 147 → 150 taken 2 times.
✗ Branch 148 → 149 not taken.
✓ Branch 148 → 150 taken 587 times.
✓ Branch 151 → 152 taken 589 times.
✗ Branch 151 → 234 not taken.
|
589 | insertStore(result.value, lhs.ptr, lhs.entry && lhs.entry->isVolatile); |
| 838 | 589 | lhs.ptr = nullptr; | |
| 839 | } | ||
| 840 | 596 | break; | |
| 841 | } | ||
| 842 | − | default: // GCOV_EXCL_LINE | |
| 843 | − | throw CompilerError(UNHANDLED_BRANCH, "PostfixUnaryExpr fall-through"); // GCOV_EXCL_LINE | |
| 844 | } | ||
| 845 | |||
| 846 |
1/2✓ Branch 163 → 164 taken 37368 times.
✗ Branch 163 → 244 not taken.
|
37368 | return lhs; |
| 847 |
5/14✓ Branch 17 → 18 taken 280 times.
✗ Branch 17 → 173 not taken.
✓ Branch 18 → 19 taken 280 times.
✗ Branch 18 → 173 not taken.
✓ Branch 19 → 20 taken 280 times.
✗ Branch 19 → 173 not taken.
✓ Branch 20 → 21 taken 280 times.
✗ Branch 20 → 173 not taken.
✓ Branch 21 → 22 taken 280 times.
✗ Branch 21 → 171 not taken.
✗ Branch 173 → 174 not taken.
✗ Branch 173 → 177 not taken.
✗ Branch 175 → 176 not taken.
✗ Branch 175 → 177 not taken.
|
280 | } |
| 848 | |||
| 849 | 165051 | std::any IRGenerator::visitAtomicExpr(const AtomicExprNode *node) { | |
| 850 |
1/2✓ Branch 2 → 3 taken 165051 times.
✗ Branch 2 → 86 not taken.
|
165051 | diGenerator.setSourceLocation(node); |
| 851 | |||
| 852 | // If constant | ||
| 853 |
2/2✓ Branch 3 → 4 taken 28469 times.
✓ Branch 3 → 10 taken 136582 times.
|
165051 | if (node->constant) { |
| 854 |
2/4✓ Branch 4 → 5 taken 28469 times.
✗ Branch 4 → 78 not taken.
✓ Branch 5 → 6 taken 28469 times.
✗ Branch 5 → 76 not taken.
|
28469 | const auto constantValue = std::any_cast<llvm::Constant *>(visit(node->constant)); |
| 855 |
1/2✓ Branch 7 → 8 taken 28469 times.
✗ Branch 7 → 79 not taken.
|
56938 | return LLVMExprResult{.constant = constantValue}; |
| 856 | } | ||
| 857 | |||
| 858 | // If value | ||
| 859 |
2/2✓ Branch 10 → 11 taken 38955 times.
✓ Branch 10 → 13 taken 97627 times.
|
136582 | if (node->value) |
| 860 |
1/2✓ Branch 11 → 12 taken 38955 times.
✗ Branch 11 → 86 not taken.
|
38955 | return visit(node->value); |
| 861 | |||
| 862 | // Is assign expression | ||
| 863 |
2/2✓ Branch 13 → 14 taken 903 times.
✓ Branch 13 → 16 taken 96724 times.
|
97627 | if (node->assignExpr) |
| 864 |
1/2✓ Branch 14 → 15 taken 903 times.
✗ Branch 14 → 86 not taken.
|
903 | return visit(node->assignExpr); |
| 865 | |||
| 866 | // Identifier (local or global variable access) | ||
| 867 |
1/2✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 96724 times.
|
96724 | assert(!node->identifierFragments.empty()); |
| 868 | |||
| 869 | // Get symbol table entry | ||
| 870 |
1/2✓ Branch 19 → 20 taken 96724 times.
✗ Branch 19 → 86 not taken.
|
96724 | const auto &[entry, accessScope, capture] = node->data.at(manIdx); |
| 871 |
1/2✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 96724 times.
|
96724 | assert(entry != nullptr); |
| 872 |
1/2✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 96724 times.
|
96724 | assert(accessScope != nullptr); |
| 873 |
1/2✓ Branch 24 → 25 taken 96724 times.
✗ Branch 24 → 86 not taken.
|
96724 | const QualType varSymbolType = entry->getQualType(); |
| 874 |
1/2✓ Branch 25 → 26 taken 96724 times.
✗ Branch 25 → 86 not taken.
|
96724 | llvm::Type *varType = varSymbolType.toLLVMType(sourceFile); |
| 875 | |||
| 876 | // Check if external global variable | ||
| 877 |
7/8✓ Branch 26 → 27 taken 2413 times.
✓ Branch 26 → 30 taken 94311 times.
✓ Branch 27 → 28 taken 2413 times.
✗ Branch 27 → 86 not taken.
✓ Branch 28 → 29 taken 174 times.
✓ Branch 28 → 30 taken 2239 times.
✓ Branch 31 → 32 taken 174 times.
✓ Branch 31 → 35 taken 96550 times.
|
96724 | if (entry->global && accessScope->isImportedBy(rootScope)) { |
| 878 | // External global variables need to be declared and allocated in the current module | ||
| 879 |
1/2✓ Branch 33 → 34 taken 174 times.
✗ Branch 33 → 80 not taken.
|
174 | llvm::Value *varAddress = module->getOrInsertGlobal(entry->name, varType); |
| 880 |
1/2✓ Branch 34 → 35 taken 174 times.
✗ Branch 34 → 86 not taken.
|
174 | entry->updateAddress(varAddress); |
| 881 | } | ||
| 882 | |||
| 883 | // Check if enum item | ||
| 884 |
2/2✓ Branch 35 → 36 taken 2049 times.
✓ Branch 35 → 47 taken 94675 times.
|
96724 | if (accessScope->type == ScopeType::ENUM) { |
| 885 |
1/2✓ Branch 36 → 37 taken 2049 times.
✗ Branch 36 → 38 not taken.
|
2049 | const auto itemNode = spice_pointer_cast<const EnumItemNode *>(entry->declNode); |
| 886 |
1/2✓ Branch 43 → 44 taken 2049 times.
✗ Branch 43 → 86 not taken.
|
2049 | llvm::Constant *constantItemValue = llvm::ConstantInt::get(varType, itemNode->itemValue); |
| 887 |
1/2✓ Branch 44 → 45 taken 2049 times.
✗ Branch 44 → 81 not taken.
|
4098 | return LLVMExprResult{.constant = constantItemValue, .entry = entry}; |
| 888 | } | ||
| 889 | |||
| 890 |
1/2✓ Branch 47 → 48 taken 94675 times.
✗ Branch 47 → 86 not taken.
|
94675 | llvm::Value *address = entry->getAddress(); |
| 891 |
1/2✗ Branch 48 → 49 not taken.
✓ Branch 48 → 50 taken 94675 times.
|
94675 | assert(address != nullptr); |
| 892 | |||
| 893 | // If this is a function/procedure reference, return it as value | ||
| 894 |
7/8✓ Branch 50 → 51 taken 2413 times.
✓ Branch 50 → 54 taken 92262 times.
✓ Branch 51 → 52 taken 2413 times.
✗ Branch 51 → 82 not taken.
✓ Branch 52 → 53 taken 15 times.
✓ Branch 52 → 54 taken 2398 times.
✓ Branch 55 → 56 taken 15 times.
✓ Branch 55 → 60 taken 94660 times.
|
94675 | if (entry->global && varSymbolType.isOneOf({TY_FUNCTION, TY_PROCEDURE})) { |
| 895 |
1/2✓ Branch 56 → 57 taken 15 times.
✗ Branch 56 → 86 not taken.
|
15 | llvm::Value *fatPtr = buildFatFctPtr(nullptr, nullptr, address); |
| 896 |
1/2✓ Branch 57 → 58 taken 15 times.
✗ Branch 57 → 83 not taken.
|
30 | return LLVMExprResult{.ptr = fatPtr, .entry = entry}; |
| 897 | } | ||
| 898 | |||
| 899 | // Load the address of the referenced variable | ||
| 900 |
10/12✓ Branch 60 → 61 taken 94660 times.
✗ Branch 60 → 86 not taken.
✓ Branch 61 → 62 taken 86816 times.
✓ Branch 61 → 65 taken 7844 times.
✓ Branch 62 → 63 taken 28 times.
✓ Branch 62 → 66 taken 86788 times.
✓ Branch 63 → 64 taken 28 times.
✗ Branch 63 → 86 not taken.
✓ Branch 64 → 65 taken 11 times.
✓ Branch 64 → 66 taken 17 times.
✓ Branch 67 → 68 taken 7855 times.
✓ Branch 67 → 71 taken 86805 times.
|
94660 | if (varSymbolType.isRef() || (capture && capture->getMode() == BY_REFERENCE)) |
| 901 |
1/2✓ Branch 68 → 69 taken 7855 times.
✗ Branch 68 → 84 not taken.
|
15710 | return LLVMExprResult{.refPtr = address, .entry = entry}; |
| 902 | |||
| 903 |
1/2✓ Branch 71 → 72 taken 86805 times.
✗ Branch 71 → 85 not taken.
|
173610 | return LLVMExprResult{.ptr = address, .entry = entry}; |
| 904 | } | ||
| 905 | |||
| 906 | } // namespace spice::compiler | ||
| 907 |