src/irgenerator/StdFunctionManager.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "StdFunctionManager.h" | ||
| 4 | |||
| 5 | #include <SourceFile.h> | ||
| 6 | #include <driver/Driver.h> | ||
| 7 | #include <global/GlobalResourceManager.h> | ||
| 8 | #include <irgenerator/NameMangling.h> | ||
| 9 | #include <model/Function.h> | ||
| 10 | |||
| 11 | #include <llvm/IR/Module.h> | ||
| 12 | |||
| 13 | namespace spice::compiler { | ||
| 14 | |||
| 15 | 5561 | StdFunctionManager::StdFunctionManager(SourceFile *sourceFile, GlobalResourceManager &resourceManager, llvm::Module *module) | |
| 16 |
2/2✓ Branch 2 → 3 taken 4 times.
✓ Branch 2 → 4 taken 5557 times.
|
5561 | : sourceFile(sourceFile), context(resourceManager.cliOptions.useLTO ? resourceManager.ltoContext : sourceFile->context), |
| 17 | 5561 | builder(sourceFile->builder), module(module) {} | |
| 18 | |||
| 19 | 13544 | llvm::Function *StdFunctionManager::getPrintfFct() const { | |
| 20 |
3/6✓ Branch 2 → 3 taken 13544 times.
✗ Branch 2 → 17 not taken.
✓ Branch 4 → 5 taken 13544 times.
✗ Branch 4 → 17 not taken.
✓ Branch 5 → 6 taken 13544 times.
✗ Branch 5 → 17 not taken.
|
13544 | llvm::Function *printfFct = getFunction("printf", builder.getInt32Ty(), builder.getPtrTy(), true); |
| 21 | // Set attributes | ||
| 22 | 13544 | printfFct->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Local); | |
| 23 | 13544 | printfFct->addFnAttr(llvm::Attribute::NoFree); | |
| 24 | 13544 | printfFct->addFnAttr(llvm::Attribute::NoUnwind); | |
| 25 | 13544 | printfFct->addParamAttr(0, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none())); | |
| 26 | 13544 | printfFct->addParamAttr(0, llvm::Attribute::NoUndef); | |
| 27 | 13544 | printfFct->addParamAttr(0, llvm::Attribute::ReadOnly); | |
| 28 | 13544 | printfFct->addRetAttr(llvm::Attribute::NoUndef); | |
| 29 | 13544 | return printfFct; | |
| 30 | } | ||
| 31 | |||
| 32 | 4979 | llvm::Function *StdFunctionManager::getFPrintfFct() const { | |
| 33 |
4/8✓ Branch 2 → 3 taken 4979 times.
✗ Branch 2 → 21 not taken.
✓ Branch 3 → 4 taken 4979 times.
✗ Branch 3 → 21 not taken.
✓ Branch 5 → 6 taken 4979 times.
✗ Branch 5 → 21 not taken.
✓ Branch 6 → 7 taken 4979 times.
✗ Branch 6 → 21 not taken.
|
4979 | llvm::Function *fprintfFct = getFunction("fprintf", builder.getInt32Ty(), {builder.getPtrTy(), builder.getPtrTy()}, true); |
| 34 | // Set attributes | ||
| 35 | 4979 | fprintfFct->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Local); | |
| 36 | 4979 | fprintfFct->addFnAttr(llvm::Attribute::NoFree); | |
| 37 | 4979 | fprintfFct->addParamAttr(0, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none())); | |
| 38 | 4979 | fprintfFct->addParamAttr(0, llvm::Attribute::NoUndef); | |
| 39 | 4979 | fprintfFct->addParamAttr(1, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none())); | |
| 40 | 4979 | fprintfFct->addParamAttr(1, llvm::Attribute::NoUndef); | |
| 41 | 4979 | fprintfFct->addParamAttr(1, llvm::Attribute::ReadOnly); | |
| 42 | 4979 | fprintfFct->addRetAttr(llvm::Attribute::NoUndef); | |
| 43 | 4979 | return fprintfFct; | |
| 44 | } | ||
| 45 | |||
| 46 | 15988 | llvm::Function *StdFunctionManager::getExitFct() const { | |
| 47 |
2/4✓ Branch 2 → 3 taken 15988 times.
✗ Branch 2 → 10 not taken.
✓ Branch 4 → 5 taken 15988 times.
✗ Branch 4 → 10 not taken.
|
15988 | llvm::Function *exitFct = getProcedure("exit", builder.getInt32Ty()); |
| 48 | // Set attributes | ||
| 49 | 15988 | exitFct->addFnAttr(llvm::Attribute::Cold); | |
| 50 | 15988 | exitFct->addFnAttr(llvm::Attribute::NoReturn); | |
| 51 | 15988 | exitFct->addFnAttr(llvm::Attribute::NoUnwind); | |
| 52 | 15988 | return exitFct; | |
| 53 | } | ||
| 54 | |||
| 55 | ✗ | llvm::Function *StdFunctionManager::getFreeFct() const { | |
| 56 | ✗ | llvm::Function *freeFct = getProcedure("free", builder.getPtrTy()); | |
| 57 | // Set attributes | ||
| 58 | ✗ | freeFct->addFnAttr(llvm::Attribute::NoUnwind); | |
| 59 | ✗ | freeFct->addParamAttr(0, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none())); | |
| 60 | ✗ | freeFct->addParamAttr(0, llvm::Attribute::NoUndef); | |
| 61 | ✗ | freeFct->addParamAttr(0, llvm::Attribute::ReadOnly); | |
| 62 | ✗ | return freeFct; | |
| 63 | } | ||
| 64 | |||
| 65 | 592 | llvm::Function *StdFunctionManager::getMemcmpFct() const { | |
| 66 | 592 | llvm::Type *ptrTy = builder.getPtrTy(); | |
| 67 |
3/6✓ Branch 3 → 4 taken 592 times.
✗ Branch 3 → 22 not taken.
✓ Branch 5 → 6 taken 592 times.
✗ Branch 5 → 22 not taken.
✓ Branch 6 → 7 taken 592 times.
✗ Branch 6 → 22 not taken.
|
592 | llvm::Function *memcmpFct = getFunction("memcmp", builder.getInt32Ty(), {ptrTy, ptrTy, builder.getInt64Ty()}); |
| 68 | // Set attributes | ||
| 69 | 592 | memcmpFct->addFnAttr(llvm::Attribute::NoUnwind); | |
| 70 | 592 | memcmpFct->addParamAttr(0, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none())); | |
| 71 | 592 | memcmpFct->addParamAttr(0, llvm::Attribute::NoUndef); | |
| 72 | 592 | memcmpFct->addParamAttr(0, llvm::Attribute::ReadOnly); | |
| 73 | 592 | memcmpFct->addParamAttr(1, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none())); | |
| 74 | 592 | memcmpFct->addParamAttr(1, llvm::Attribute::NoUndef); | |
| 75 | 592 | memcmpFct->addParamAttr(1, llvm::Attribute::ReadOnly); | |
| 76 | 592 | memcmpFct->addParamAttr(2, llvm::Attribute::NoUndef); | |
| 77 | 592 | memcmpFct->addRetAttr(llvm::Attribute::NoUndef); | |
| 78 | 592 | return memcmpFct; | |
| 79 | } | ||
| 80 | |||
| 81 | 6253 | llvm::Function *StdFunctionManager::getMemcpyIntrinsic() const { | |
| 82 | 6253 | llvm::Type *ptrTy = builder.getPtrTy(); | |
| 83 |
3/6✓ Branch 3 → 4 taken 6253 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 6253 times.
✗ Branch 4 → 13 not taken.
✓ Branch 6 → 7 taken 6253 times.
✗ Branch 6 → 13 not taken.
|
6253 | llvm::Function *memcpyFct = getProcedure("llvm.memcpy.p0.p0.i64", {ptrTy, ptrTy, builder.getInt64Ty(), builder.getInt1Ty()}); |
| 84 | // Set attributes | ||
| 85 | 6253 | memcpyFct->addFnAttr(llvm::Attribute::NoCallback); | |
| 86 | 6253 | memcpyFct->addFnAttr(llvm::Attribute::NoFree); | |
| 87 | 6253 | memcpyFct->addFnAttr(llvm::Attribute::NoUnwind); | |
| 88 | 6253 | memcpyFct->addFnAttr(llvm::Attribute::WillReturn); | |
| 89 | 6253 | return memcpyFct; | |
| 90 | } | ||
| 91 | |||
| 92 | 156 | llvm::Function *StdFunctionManager::getStringGetRawLengthStringFct() const { | |
| 93 |
2/4✓ Branch 2 → 3 taken 156 times.
✗ Branch 2 → 34 not taken.
✓ Branch 5 → 6 taken 156 times.
✗ Branch 5 → 31 not taken.
|
312 | const ParamList paramLst = {{QualType(TY_STRING), false}}; |
| 94 |
5/10✓ Branch 8 → 9 taken 156 times.
✗ Branch 8 → 45 not taken.
✓ Branch 9 → 10 taken 156 times.
✗ Branch 9 → 42 not taken.
✓ Branch 10 → 11 taken 156 times.
✗ Branch 10 → 41 not taken.
✓ Branch 13 → 14 taken 156 times.
✗ Branch 13 → 37 not taken.
✓ Branch 14 → 15 taken 156 times.
✗ Branch 14 → 35 not taken.
|
468 | const Function function("getRawLength", nullptr, QualType(TY_DYN), QualType(TY_LONG), paramLst, {}, nullptr); |
| 95 |
1/2✓ Branch 19 → 20 taken 156 times.
✗ Branch 19 → 53 not taken.
|
156 | const std::string mangledName = NameMangling::mangleFunction(function); |
| 96 |
3/6✓ Branch 20 → 21 taken 156 times.
✗ Branch 20 → 49 not taken.
✓ Branch 22 → 23 taken 156 times.
✗ Branch 22 → 49 not taken.
✓ Branch 24 → 25 taken 156 times.
✗ Branch 24 → 49 not taken.
|
312 | return getFunction(mangledName.c_str(), builder.getInt64Ty(), {builder.getPtrTy()}); |
| 97 | 156 | } | |
| 98 | |||
| 99 | 845 | llvm::Function *StdFunctionManager::getStringIsRawEqualStringStringFct() const { | |
| 100 |
3/6✓ Branch 2 → 3 taken 845 times.
✗ Branch 2 → 36 not taken.
✓ Branch 3 → 4 taken 845 times.
✗ Branch 3 → 36 not taken.
✓ Branch 6 → 7 taken 845 times.
✗ Branch 6 → 33 not taken.
|
1690 | const ParamList paramLst = {{QualType(TY_STRING), false}, {QualType(TY_STRING), false}}; |
| 101 |
5/10✓ Branch 9 → 10 taken 845 times.
✗ Branch 9 → 47 not taken.
✓ Branch 10 → 11 taken 845 times.
✗ Branch 10 → 44 not taken.
✓ Branch 11 → 12 taken 845 times.
✗ Branch 11 → 43 not taken.
✓ Branch 14 → 15 taken 845 times.
✗ Branch 14 → 39 not taken.
✓ Branch 15 → 16 taken 845 times.
✗ Branch 15 → 37 not taken.
|
2535 | const Function function("isRawEqual", nullptr, QualType(TY_DYN), QualType(TY_BOOL), paramLst, {}, nullptr); |
| 102 |
1/2✓ Branch 20 → 21 taken 845 times.
✗ Branch 20 → 55 not taken.
|
845 | const std::string mangledName = NameMangling::mangleFunction(function); |
| 103 |
4/8✓ Branch 21 → 22 taken 845 times.
✗ Branch 21 → 51 not taken.
✓ Branch 22 → 23 taken 845 times.
✗ Branch 22 → 51 not taken.
✓ Branch 24 → 25 taken 845 times.
✗ Branch 24 → 51 not taken.
✓ Branch 26 → 27 taken 845 times.
✗ Branch 26 → 51 not taken.
|
1690 | return getFunction(mangledName.c_str(), builder.getInt1Ty(), {builder.getPtrTy(), builder.getPtrTy()}); |
| 104 | 845 | } | |
| 105 | |||
| 106 | 489 | llvm::Function *StdFunctionManager::getAllocUnsafeLongFct() const { | |
| 107 |
1/2✓ Branch 2 → 3 taken 489 times.
✗ Branch 2 → 60 not taken.
|
489 | QualType unsignedLong(TY_LONG); |
| 108 |
1/2✓ Branch 3 → 4 taken 489 times.
✗ Branch 3 → 60 not taken.
|
489 | unsignedLong.makeUnsigned(); |
| 109 |
1/2✓ Branch 6 → 7 taken 489 times.
✗ Branch 6 → 33 not taken.
|
978 | const ParamList paramLst = {{unsignedLong, false}}; |
| 110 |
6/12✓ Branch 9 → 10 taken 489 times.
✗ Branch 9 → 48 not taken.
✓ Branch 10 → 11 taken 489 times.
✗ Branch 10 → 44 not taken.
✓ Branch 11 → 12 taken 489 times.
✗ Branch 11 → 44 not taken.
✓ Branch 12 → 13 taken 489 times.
✗ Branch 12 → 43 not taken.
✓ Branch 15 → 16 taken 489 times.
✗ Branch 15 → 39 not taken.
✓ Branch 16 → 17 taken 489 times.
✗ Branch 16 → 37 not taken.
|
1467 | const Function function("sAllocUnsafe", nullptr, QualType(TY_DYN), QualType(TY_BYTE).toPtr(nullptr), paramLst, {}, nullptr); |
| 111 |
1/2✓ Branch 21 → 22 taken 489 times.
✗ Branch 21 → 56 not taken.
|
489 | const std::string mangledName = NameMangling::mangleFunction(function); |
| 112 |
3/6✓ Branch 22 → 23 taken 489 times.
✗ Branch 22 → 52 not taken.
✓ Branch 24 → 25 taken 489 times.
✗ Branch 24 → 52 not taken.
✓ Branch 26 → 27 taken 489 times.
✗ Branch 26 → 52 not taken.
|
978 | return getFunction(mangledName.c_str(), builder.getPtrTy(), {builder.getInt64Ty()}); |
| 113 | 489 | } | |
| 114 | |||
| 115 | 685 | llvm::Function *StdFunctionManager::getDeallocBytePtrRefFct() const { | |
| 116 |
2/4✓ Branch 2 → 3 taken 685 times.
✗ Branch 2 → 33 not taken.
✓ Branch 3 → 4 taken 685 times.
✗ Branch 3 → 33 not taken.
|
685 | QualType heapBytePtrType = QualType(TY_BYTE).toPtr(nullptr); |
| 117 |
1/2✓ Branch 4 → 5 taken 685 times.
✗ Branch 4 → 60 not taken.
|
685 | heapBytePtrType.makeHeap(); |
| 118 |
2/4✓ Branch 5 → 6 taken 685 times.
✗ Branch 5 → 37 not taken.
✓ Branch 8 → 9 taken 685 times.
✗ Branch 8 → 34 not taken.
|
1370 | const ParamList paramLst = {{heapBytePtrType.toRef(nullptr), false}}; |
| 119 |
5/10✓ Branch 11 → 12 taken 685 times.
✗ Branch 11 → 48 not taken.
✓ Branch 12 → 13 taken 685 times.
✗ Branch 12 → 45 not taken.
✓ Branch 13 → 14 taken 685 times.
✗ Branch 13 → 44 not taken.
✓ Branch 16 → 17 taken 685 times.
✗ Branch 16 → 40 not taken.
✓ Branch 17 → 18 taken 685 times.
✗ Branch 17 → 38 not taken.
|
2055 | const Function function("sDealloc", nullptr, QualType(TY_DYN), QualType(TY_DYN), paramLst, {}, nullptr); |
| 120 |
1/2✓ Branch 22 → 23 taken 685 times.
✗ Branch 22 → 56 not taken.
|
685 | const std::string mangledName = NameMangling::mangleFunction(function); |
| 121 |
2/4✓ Branch 23 → 24 taken 685 times.
✗ Branch 23 → 52 not taken.
✓ Branch 26 → 27 taken 685 times.
✗ Branch 26 → 52 not taken.
|
1370 | return getProcedure(mangledName.c_str(), {builder.getPtrTy()}); |
| 122 | 685 | } | |
| 123 | |||
| 124 | 36 | llvm::Function *StdFunctionManager::getIterateFct(const Function *spiceFunc) const { | |
| 125 |
1/2✓ Branch 2 → 3 taken 36 times.
✗ Branch 2 → 17 not taken.
|
36 | const std::string functionName = NameMangling::mangleFunction(*spiceFunc); |
| 126 |
1/2✓ Branch 3 → 4 taken 36 times.
✗ Branch 3 → 15 not taken.
|
36 | llvm::Type *iteratorType = spiceFunc->returnType.toLLVMType(sourceFile); |
| 127 |
3/6✓ Branch 4 → 5 taken 36 times.
✗ Branch 4 → 13 not taken.
✓ Branch 5 → 6 taken 36 times.
✗ Branch 5 → 13 not taken.
✓ Branch 8 → 9 taken 36 times.
✗ Branch 8 → 13 not taken.
|
72 | return getFunction(functionName.c_str(), iteratorType, {builder.getPtrTy(), builder.getInt64Ty()}); |
| 128 | 36 | } | |
| 129 | |||
| 130 | 862 | llvm::Function *StdFunctionManager::getIteratorFct(const Function *spiceFunc) const { | |
| 131 |
1/2✓ Branch 2 → 3 taken 862 times.
✗ Branch 2 → 16 not taken.
|
862 | const std::string functionName = NameMangling::mangleFunction(*spiceFunc); |
| 132 |
1/2✓ Branch 3 → 4 taken 862 times.
✗ Branch 3 → 14 not taken.
|
862 | llvm::Type *iteratorType = spiceFunc->returnType.toLLVMType(sourceFile); |
| 133 |
2/4✓ Branch 4 → 5 taken 862 times.
✗ Branch 4 → 12 not taken.
✓ Branch 7 → 8 taken 862 times.
✗ Branch 7 → 12 not taken.
|
1724 | return getFunction(functionName.c_str(), iteratorType, builder.getPtrTy()); |
| 134 | 862 | } | |
| 135 | |||
| 136 | 730 | llvm::Function *StdFunctionManager::getIteratorGetFct(const Function *spiceFunc) const { | |
| 137 |
1/2✓ Branch 2 → 3 taken 730 times.
✗ Branch 2 → 16 not taken.
|
730 | const std::string functionName = NameMangling::mangleFunction(*spiceFunc); |
| 138 |
3/6✓ Branch 3 → 4 taken 730 times.
✗ Branch 3 → 12 not taken.
✓ Branch 5 → 6 taken 730 times.
✗ Branch 5 → 12 not taken.
✓ Branch 7 → 8 taken 730 times.
✗ Branch 7 → 12 not taken.
|
1460 | return getFunction(functionName.c_str(), builder.getPtrTy(), builder.getPtrTy()); |
| 139 | 730 | } | |
| 140 | |||
| 141 | 234 | llvm::Function *StdFunctionManager::getIteratorGetIdxFct(const Function *spiceFunc) const { | |
| 142 |
1/2✓ Branch 2 → 3 taken 234 times.
✗ Branch 2 → 16 not taken.
|
234 | const std::string functionName = NameMangling::mangleFunction(*spiceFunc); |
| 143 |
1/2✓ Branch 3 → 4 taken 234 times.
✗ Branch 3 → 14 not taken.
|
234 | llvm::Type *pairTy = spiceFunc->returnType.toLLVMType(sourceFile); |
| 144 |
2/4✓ Branch 4 → 5 taken 234 times.
✗ Branch 4 → 12 not taken.
✓ Branch 7 → 8 taken 234 times.
✗ Branch 7 → 12 not taken.
|
468 | return getFunction(functionName.c_str(), pairTy, builder.getPtrTy()); |
| 145 | 234 | } | |
| 146 | |||
| 147 | 964 | llvm::Function *StdFunctionManager::getIteratorIsValidFct(const Function *spiceFunc) const { | |
| 148 |
1/2✓ Branch 2 → 3 taken 964 times.
✗ Branch 2 → 16 not taken.
|
964 | const std::string functionName = NameMangling::mangleFunction(*spiceFunc); |
| 149 |
3/6✓ Branch 3 → 4 taken 964 times.
✗ Branch 3 → 12 not taken.
✓ Branch 5 → 6 taken 964 times.
✗ Branch 5 → 12 not taken.
✓ Branch 7 → 8 taken 964 times.
✗ Branch 7 → 12 not taken.
|
1928 | return getFunction(functionName.c_str(), builder.getInt1Ty(), builder.getPtrTy()); |
| 150 | 964 | } | |
| 151 | |||
| 152 | 964 | llvm::Function *StdFunctionManager::getIteratorNextFct(const Function *spiceFunc) const { | |
| 153 |
1/2✓ Branch 2 → 3 taken 964 times.
✗ Branch 2 → 15 not taken.
|
964 | const std::string functionName = NameMangling::mangleFunction(*spiceFunc); |
| 154 |
2/4✓ Branch 3 → 4 taken 964 times.
✗ Branch 3 → 11 not taken.
✓ Branch 6 → 7 taken 964 times.
✗ Branch 6 → 11 not taken.
|
1928 | return getProcedure(functionName.c_str(), builder.getPtrTy()); |
| 155 | 964 | } | |
| 156 | |||
| 157 | 120 | llvm::Function *StdFunctionManager::getResultIsErrFct(const Function *spiceFunc) const { | |
| 158 |
1/2✓ Branch 2 → 3 taken 120 times.
✗ Branch 2 → 16 not taken.
|
120 | const std::string functionName = NameMangling::mangleFunction(*spiceFunc); |
| 159 |
3/6✓ Branch 3 → 4 taken 120 times.
✗ Branch 3 → 12 not taken.
✓ Branch 5 → 6 taken 120 times.
✗ Branch 5 → 12 not taken.
✓ Branch 7 → 8 taken 120 times.
✗ Branch 7 → 12 not taken.
|
240 | return getFunction(functionName.c_str(), builder.getInt1Ty(), builder.getPtrTy()); |
| 160 | 120 | } | |
| 161 | |||
| 162 | 120 | llvm::Function *StdFunctionManager::getResultUnwrapFct(const Function *spiceFunc) const { | |
| 163 |
1/2✓ Branch 2 → 3 taken 120 times.
✗ Branch 2 → 16 not taken.
|
120 | const std::string functionName = NameMangling::mangleFunction(*spiceFunc); |
| 164 |
3/6✓ Branch 3 → 4 taken 120 times.
✗ Branch 3 → 12 not taken.
✓ Branch 5 → 6 taken 120 times.
✗ Branch 5 → 12 not taken.
✓ Branch 7 → 8 taken 120 times.
✗ Branch 7 → 12 not taken.
|
240 | return getFunction(functionName.c_str(), builder.getPtrTy(), builder.getPtrTy()); |
| 165 | 120 | } | |
| 166 | |||
| 167 | 120 | llvm::Function *StdFunctionManager::getResultGetErrFct(const Function *spiceFunc) const { | |
| 168 |
1/2✓ Branch 2 → 3 taken 120 times.
✗ Branch 2 → 16 not taken.
|
120 | const std::string functionName = NameMangling::mangleFunction(*spiceFunc); |
| 169 |
3/6✓ Branch 3 → 4 taken 120 times.
✗ Branch 3 → 12 not taken.
✓ Branch 5 → 6 taken 120 times.
✗ Branch 5 → 12 not taken.
✓ Branch 7 → 8 taken 120 times.
✗ Branch 7 → 12 not taken.
|
240 | return getFunction(functionName.c_str(), builder.getPtrTy(), builder.getPtrTy()); |
| 170 | 120 | } | |
| 171 | |||
| 172 | 120 | llvm::Function *StdFunctionManager::getResultErrCtorFct(const Function *spiceFunc) const { | |
| 173 |
1/2✓ Branch 2 → 3 taken 120 times.
✗ Branch 2 → 16 not taken.
|
120 | const std::string functionName = NameMangling::mangleFunction(*spiceFunc); |
| 174 |
1/2✓ Branch 3 → 4 taken 120 times.
✗ Branch 3 → 14 not taken.
|
120 | llvm::Type *resultType = spiceFunc->returnType.toLLVMType(sourceFile); |
| 175 |
2/4✓ Branch 4 → 5 taken 120 times.
✗ Branch 4 → 12 not taken.
✓ Branch 7 → 8 taken 120 times.
✗ Branch 7 → 12 not taken.
|
240 | return getFunction(functionName.c_str(), resultType, builder.getPtrTy()); |
| 176 | 120 | } | |
| 177 | |||
| 178 | 10 | llvm::Function *StdFunctionManager::getErrTraceResetFct() const { | |
| 179 |
1/2✓ Branch 2 → 3 taken 10 times.
✗ Branch 2 → 62 not taken.
|
10 | QualType unsignedInt(TY_INT); |
| 180 |
1/2✓ Branch 3 → 4 taken 10 times.
✗ Branch 3 → 62 not taken.
|
10 | unsignedInt.makeUnsigned(); |
| 181 | 10 | const ParamList paramLst = { | |
| 182 |
3/6✓ Branch 4 → 5 taken 10 times.
✗ Branch 4 → 39 not taken.
✓ Branch 5 → 6 taken 10 times.
✗ Branch 5 → 39 not taken.
✓ Branch 8 → 9 taken 10 times.
✗ Branch 8 → 36 not taken.
|
20 | {QualType(TY_STRING), false}, {QualType(TY_STRING), false}, {unsignedInt, false}, {unsignedInt, false}}; |
| 183 |
5/10✓ Branch 11 → 12 taken 10 times.
✗ Branch 11 → 50 not taken.
✓ Branch 12 → 13 taken 10 times.
✗ Branch 12 → 47 not taken.
✓ Branch 13 → 14 taken 10 times.
✗ Branch 13 → 46 not taken.
✓ Branch 16 → 17 taken 10 times.
✗ Branch 16 → 42 not taken.
✓ Branch 17 → 18 taken 10 times.
✗ Branch 17 → 40 not taken.
|
30 | const Function function("sErrTraceReset", nullptr, QualType(TY_DYN), QualType(TY_DYN), paramLst, {}, nullptr); |
| 184 |
1/2✓ Branch 22 → 23 taken 10 times.
✗ Branch 22 → 58 not taken.
|
10 | const std::string mangledName = NameMangling::mangleFunction(function); |
| 185 |
1/2✓ Branch 29 → 30 taken 10 times.
✗ Branch 29 → 54 not taken.
|
10 | return getProcedure(mangledName.c_str(), |
| 186 |
4/8✓ Branch 23 → 24 taken 10 times.
✗ Branch 23 → 54 not taken.
✓ Branch 24 → 25 taken 10 times.
✗ Branch 24 → 54 not taken.
✓ Branch 25 → 26 taken 10 times.
✗ Branch 25 → 54 not taken.
✓ Branch 26 → 27 taken 10 times.
✗ Branch 26 → 54 not taken.
|
30 | {builder.getPtrTy(), builder.getPtrTy(), builder.getInt32Ty(), builder.getInt32Ty()}); |
| 187 | 10 | } | |
| 188 | |||
| 189 | 6 | llvm::Function *StdFunctionManager::getErrTracePushFct() const { | |
| 190 |
1/2✓ Branch 2 → 3 taken 6 times.
✗ Branch 2 → 62 not taken.
|
6 | QualType unsignedInt(TY_INT); |
| 191 |
1/2✓ Branch 3 → 4 taken 6 times.
✗ Branch 3 → 62 not taken.
|
6 | unsignedInt.makeUnsigned(); |
| 192 | 6 | const ParamList paramLst = { | |
| 193 |
3/6✓ Branch 4 → 5 taken 6 times.
✗ Branch 4 → 39 not taken.
✓ Branch 5 → 6 taken 6 times.
✗ Branch 5 → 39 not taken.
✓ Branch 8 → 9 taken 6 times.
✗ Branch 8 → 36 not taken.
|
12 | {QualType(TY_STRING), false}, {QualType(TY_STRING), false}, {unsignedInt, false}, {unsignedInt, false}}; |
| 194 |
5/10✓ Branch 11 → 12 taken 6 times.
✗ Branch 11 → 50 not taken.
✓ Branch 12 → 13 taken 6 times.
✗ Branch 12 → 47 not taken.
✓ Branch 13 → 14 taken 6 times.
✗ Branch 13 → 46 not taken.
✓ Branch 16 → 17 taken 6 times.
✗ Branch 16 → 42 not taken.
✓ Branch 17 → 18 taken 6 times.
✗ Branch 17 → 40 not taken.
|
18 | const Function function("sErrTracePush", nullptr, QualType(TY_DYN), QualType(TY_DYN), paramLst, {}, nullptr); |
| 195 |
1/2✓ Branch 22 → 23 taken 6 times.
✗ Branch 22 → 58 not taken.
|
6 | const std::string mangledName = NameMangling::mangleFunction(function); |
| 196 |
1/2✓ Branch 29 → 30 taken 6 times.
✗ Branch 29 → 54 not taken.
|
6 | return getProcedure(mangledName.c_str(), |
| 197 |
4/8✓ Branch 23 → 24 taken 6 times.
✗ Branch 23 → 54 not taken.
✓ Branch 24 → 25 taken 6 times.
✗ Branch 24 → 54 not taken.
✓ Branch 25 → 26 taken 6 times.
✗ Branch 25 → 54 not taken.
✓ Branch 26 → 27 taken 6 times.
✗ Branch 26 → 54 not taken.
|
18 | {builder.getPtrTy(), builder.getPtrTy(), builder.getInt32Ty(), builder.getInt32Ty()}); |
| 198 | 6 | } | |
| 199 | |||
| 200 | 4979 | llvm::Function *StdFunctionManager::getErrTraceDumpFct() const { | |
| 201 |
4/8✓ Branch 4 → 5 taken 4979 times.
✗ Branch 4 → 30 not taken.
✓ Branch 5 → 6 taken 4979 times.
✗ Branch 5 → 29 not taken.
✓ Branch 8 → 9 taken 4979 times.
✗ Branch 8 → 25 not taken.
✓ Branch 9 → 10 taken 4979 times.
✗ Branch 9 → 23 not taken.
|
14937 | const Function function("sErrTraceDump", nullptr, QualType(TY_DYN), QualType(TY_DYN), {}, {}, nullptr); |
| 202 |
1/2✓ Branch 14 → 15 taken 4979 times.
✗ Branch 14 → 40 not taken.
|
4979 | const std::string mangledName = NameMangling::mangleFunction(function); |
| 203 |
1/2✓ Branch 17 → 18 taken 4979 times.
✗ Branch 17 → 37 not taken.
|
9958 | return getProcedure(mangledName.c_str(), {}); |
| 204 | 4979 | } | |
| 205 | |||
| 206 | 26 | llvm::Function *StdFunctionManager::getAcrtIOFuncFct() const { | |
| 207 |
3/6✓ Branch 2 → 3 taken 26 times.
✗ Branch 2 → 12 not taken.
✓ Branch 4 → 5 taken 26 times.
✗ Branch 4 → 12 not taken.
✓ Branch 5 → 6 taken 26 times.
✗ Branch 5 → 12 not taken.
|
26 | llvm::Function *stdErrPFct = getFunction("__acrt_iob_func", builder.getPtrTy(), builder.getInt32Ty()); |
| 208 | 26 | stdErrPFct->setDSOLocal(true); | |
| 209 | // Set attributes | ||
| 210 | 26 | stdErrPFct->addFnAttr(llvm::Attribute::NoUnwind); | |
| 211 | 26 | stdErrPFct->addParamAttr(0, llvm::Attribute::NoUndef); | |
| 212 | 26 | stdErrPFct->addRetAttr(llvm::Attribute::NoUndef); | |
| 213 | 26 | return stdErrPFct; | |
| 214 | } | ||
| 215 | |||
| 216 | 52822 | llvm::Function *StdFunctionManager::getFunction(const char *funcName, llvm::Type *returnType, llvm::ArrayRef<llvm::Type *> args, | |
| 217 | bool varArg /*=false*/) const { | ||
| 218 | // Check if function already exists in the current module | ||
| 219 |
2/4✓ Branch 2 → 3 taken 52822 times.
✗ Branch 2 → 14 not taken.
✓ Branch 3 → 4 taken 52822 times.
✗ Branch 3 → 14 not taken.
|
52822 | llvm::Function *opFct = module->getFunction(funcName); |
| 220 |
2/2✓ Branch 4 → 5 taken 41788 times.
✓ Branch 4 → 6 taken 11034 times.
|
52822 | if (opFct != nullptr) |
| 221 | 41788 | return opFct; | |
| 222 | |||
| 223 | // Add function to the current module | ||
| 224 | 11034 | llvm::FunctionType *opFctTy = llvm::FunctionType::get(returnType, args, varArg); | |
| 225 |
2/4✓ Branch 7 → 8 taken 11034 times.
✗ Branch 7 → 15 not taken.
✓ Branch 8 → 9 taken 11034 times.
✗ Branch 8 → 15 not taken.
|
11034 | module->getOrInsertFunction(funcName, opFctTy); |
| 226 |
2/4✓ Branch 9 → 10 taken 11034 times.
✗ Branch 9 → 16 not taken.
✓ Branch 10 → 11 taken 11034 times.
✗ Branch 10 → 16 not taken.
|
11034 | return module->getFunction(funcName); |
| 227 | } | ||
| 228 | |||
| 229 | 28885 | llvm::Function *StdFunctionManager::getProcedure(const char *procName, llvm::ArrayRef<llvm::Type *> args) const { | |
| 230 | 28885 | return getFunction(procName, builder.getVoidTy(), args, false); | |
| 231 | } | ||
| 232 | |||
| 233 | } // namespace spice::compiler | ||
| 234 |