diff --git a/.github/workflows/ci-cpp.yml b/.github/workflows/ci-cpp.yml index 0e440032b..2cc139db5 100644 --- a/.github/workflows/ci-cpp.yml +++ b/.github/workflows/ci-cpp.yml @@ -43,14 +43,14 @@ jobs: uses: actions/cache@v3 with: path: /home/runner/work/spice/llvm - key: llvm-14-0-6 + key: llvm-15.0.0-rc1-invalidate - name: Setup LLVM if: steps.cache-llvm.outputs.cache-hit != 'true' run: | cd .. rm -rf llvm - git clone --depth 1 --branch llvmorg-14.0.6 https://github.com/llvm/llvm-project llvm + git clone --depth 1 --branch llvmorg-15.0.0-rc1 https://github.com/llvm/llvm-project llvm mkdir ./llvm/build cd ./llvm/build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS_RELEASE="-O2" -GNinja ../llvm @@ -58,13 +58,8 @@ jobs: - name: Download Libs run: | - mkdir ./lib - cd ./lib - git clone --depth 1 --branch 4.10.1 https://github.com/antlr/antlr4.git - mkdir json - curl -SsL "https://github.com/nlohmann/json/releases/download/v3.10.5/json.hpp" --output json/json.hpp - mkdir cli11 - curl -SsL "https://github.com/spicelang/CLI11/releases/download/v2.2.0-spice/CLI11.hpp" --output cli11/CLI11.hpp + chmod +x setup-libs.sh + ./setup-libs.sh - name: Build Test target env: diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 52ee234a6..c11d713d8 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -43,13 +43,13 @@ jobs: uses: actions/cache@v3 with: path: /home/runner/work/spice/llvm - key: llvm-14-0-5 + key: 15.0.0-rc1 - name: Setup LLVM if: steps.cache-llvm.outputs.cache-hit != 'true' run: | cd .. - git clone --depth 1 --branch llvmorg-14.0.5 https://github.com/llvm/llvm-project llvm + git clone --depth 1 --branch llvmorg-15.0.0-rc1 https://github.com/llvm/llvm-project llvm mkdir ./llvm/build cd ./llvm/build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS_RELEASE="-O2" -GNinja ../llvm @@ -57,13 +57,8 @@ jobs: - name: Download Libs run: | - mkdir ./lib - cd ./lib - git clone --depth 1 --branch 4.10.1 https://github.com/antlr/antlr4.git - mkdir json - curl -SsL "https://github.com/nlohmann/json/releases/download/v3.10.5/json.hpp" --output json/json.hpp - mkdir cli11 - curl -SsL "https://github.com/spicelang/CLI11/releases/download/v2.2.0-spice/CLI11.hpp" --output cli11/CLI11.hpp + chmod +x setup-libs.sh + ./setup-libs.sh - name: Build Test target env: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 15c8e9c8a..2419a948e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -44,15 +44,12 @@ jobs: uses: actions/cache@v3 with: path: /home/runner/work/spice/spice/llvm - key: llvm-14-0-6-linux-x64 + key: llvm-15.0.0-rc1-linux-x64 - - name: Clone LLVM - if: steps.cache-llvm.outputs.cache-hit != 'true' - run: git clone --depth 1 --branch llvmorg-14.0.6 https://github.com/llvm/llvm-project.git llvm - - - name: Setup LLVM - Configure + - name: Setup LLVM if: steps.cache-llvm.outputs.cache-hit != 'true' run: | + git clone --depth 1 --branch llvmorg-15.0.0-rc1 https://github.com/llvm/llvm-project.git llvm mkdir ./llvm/build cd ./llvm/build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS_RELEASE="-O2" -GNinja -Wno-dev -Wattributes ../llvm @@ -65,13 +62,8 @@ jobs: - name: Download Libs run: | - mkdir -p ./lib - cd ./lib - git clone --branch 4.10.1 --depth 1 https://github.com/antlr/antlr4.git - mkdir json - curl -SsL "https://github.com/nlohmann/json/releases/download/v3.10.5/json.hpp" --output json/json.hpp - mkdir cli11 - curl -SsL "https://github.com/spicelang/CLI11/releases/download/v2.2.0-spice/CLI11.hpp" --output cli11/CLI11.hpp + chmod +x setup-libs.sh + ./setup-libs.sh - name: Configure & compile project env: @@ -132,37 +124,22 @@ jobs: uses: actions/cache@v3 with: path: D:/a/spice/spice/llvm - key: llvm-14-0-6-win-x64 + key: llvm-15.0.0-rc1-win-x64 - - name: Clone LLVM - if: steps.cache-llvm.outputs.cache-hit != 'true' - run: git clone --depth 1 --branch llvmorg-14.0.6 https://github.com/llvm/llvm-project.git llvm - - - name: Setup LLVM - Configure + - name: Setup LLVM if: steps.cache-llvm.outputs.cache-hit != 'true' run: | + git clone --depth 1 --branch llvmorg-15.0.0-rc1 https://github.com/llvm/llvm-project.git llvm setx /M PATH "%PATH%;C:\mingw64\mingw64\bin" $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") echo "Adding MinGW to path done." mkdir ./llvm/build cd ./llvm/build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS_RELEASE="-O2" -GNinja -Wno-dev -Wattributes ../llvm - - - name: Setup LLVM - Build - if: steps.cache-llvm.outputs.cache-hit != 'true' - run: | - cd ./llvm/build cmake --build . - name: Download Libs - run: | - mkdir -p ./lib - cd ./lib - git clone --branch 4.10.1 --depth 1 https://github.com/antlr/antlr4.git - mkdir json - curl -SsL "https://github.com/nlohmann/json/releases/download/v3.10.5/json.hpp" -o json/json.hpp - mkdir cli11 - curl -SsL "https://github.com/spicelang/CLI11/releases/download/v2.2.0-spice/CLI11.hpp" --output cli11/CLI11.hpp + run: .\setup-libs.bat - name: Configure & compile project env: @@ -188,7 +165,7 @@ jobs: build-artifacts: name: Build artifacts - needs: [build-compiler-linux, build-compiler-windows] + needs: [ build-compiler-linux, build-compiler-windows ] runs-on: ubuntu-latest env: DOCKER_CLI_EXPERIMENTAL: enabled @@ -245,7 +222,7 @@ jobs: - name: Run GoReleaser uses: goreleaser/goreleaser-action@v3 with: - version: v1.10.2 + version: v1.10.3 args: release --rm-dist env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -305,9 +282,9 @@ jobs: run: | curl -sSf -u "${{ secrets.NEXUS_USERNAME }}:${{ secrets.NEXUS_PASSWORD }}" -H "Content-Type: multipart/form-data" --upload-file ./spice_${{ matrix.arch }}.rpm ${{ secrets.NEXUS_URL }}/fedora/spice/${{ steps.get_version.outputs.version }}/spice-${{ matrix.arch }}.rpm -# - name: Deploy to Alpine repo -# run: | -# curl -sSf -u "${{ secrets.NEXUS_USERNAME }}:${{ secrets.NEXUS_PASSWORD }}" -H "Content-Type: multipart/form-data" --data-binary "@./spice_${{ matrix.arch }}.apk" "${{ secrets.NEXUS_URL }}/alpine/spice/${{ steps.get_version.outputs.version }}/spice-${{ matrix.arch }}.apk" +# - name: Deploy to Alpine repo +# run: | +# curl -sSf -u "${{ secrets.NEXUS_USERNAME }}:${{ secrets.NEXUS_PASSWORD }}" -H "Content-Type: multipart/form-data" --data-binary "@./spice_${{ matrix.arch }}.apk" "${{ secrets.NEXUS_URL }}/alpine/spice/${{ steps.get_version.outputs.version }}/spice-${{ matrix.arch }}.apk" build-win-installers: name: Build Windows installers @@ -317,9 +294,9 @@ jobs: matrix: config: - { - arch: amd64, - label: x64 - } + arch: amd64, + label: x64 + } steps: - name: Checkout uses: actions/checkout@v3 diff --git a/CMakeLists.txt b/CMakeLists.txt index ce167c453..a6225966c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,10 @@ add_definitions(-DANTLR4CPP_STATIC) include(ExternalAntlr4Cpp) set(ANTLR_EXECUTABLE ${CMAKE_CURRENT_SOURCE_DIR}/src/thirdparty/antlr-4.10.1-complete.jar) +# Find Google Test +add_subdirectory(lib/googletest) +include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) + # Find LLVM find_package(LLVM REQUIRED CONFIG) message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") diff --git a/dev-setup.bat b/dev-setup.bat index 1da660547..4c14a627d 100644 --- a/dev-setup.bat +++ b/dev-setup.bat @@ -27,7 +27,7 @@ echo done. REM - Clone LLVM echo [Step 2] Cloning LLVM (Could take a while) ... -git clone --depth 1 --branch llvmorg-14.0.6 https://github.com/llvm/llvm-project llvm +git clone --depth 1 --branch llvmorg-15.0.0-rc1 https://github.com/llvm/llvm-project llvm echo done. REM - Build LLVM diff --git a/dev-setup.sh b/dev-setup.sh index 1a4a39c4d..f81a5c358 100644 --- a/dev-setup.sh +++ b/dev-setup.sh @@ -16,7 +16,7 @@ colored_echo "done." # Clone LLVM colored_echo "[Step 2] Cloning LLVM (Could take a while) ... " -git clone --depth 1 --branch llvmorg-14.0.6 https://github.com/llvm/llvm-project llvm +git clone --depth 1 --branch llvmorg-15.0.0-rc1 https://github.com/llvm/llvm-project llvm colored_echo "done." # Build LLVM diff --git a/media/test-project/os-test.spice b/media/test-project/os-test.spice index eed6cc749..806ffc44f 100644 --- a/media/test-project/os-test.spice +++ b/media/test-project/os-test.spice @@ -11,9 +11,11 @@ f main() { }*/ f main() { - int value0 = 2; - int[5] intArray = { value0, 7, 4 }; - intArray[2] *= 11; - intArray[0] = 3; - printf("Item 0: %d, item 2: %d", intArray[0], intArray[2]); + int[10][10] a; + for int i = 0; i < 10; i++ { + for int j = 0; j < 10; j++ { + a[i][j] = i * j; + } + } + printf("Cell [1,3]: %d", a[1][3]); } \ No newline at end of file diff --git a/setup-libs.bat b/setup-libs.bat index c4dbd98ed..eb57c924e 100644 --- a/setup-libs.bat +++ b/setup-libs.bat @@ -5,8 +5,10 @@ pushd lib git clone --depth 1 --branch 4.10.1 https://github.com/antlr/antlr4.git +git clone --depth 1 --branch release-1.12.1 https://github.com/google/googletest.git + mkdir json -curl -SsL "https://github.com/nlohmann/json/releases/download/v3.10.5/json.hpp" --output json/json.hpp +curl -SsL "https://github.com/nlohmann/json/releases/download/v3.11.1/json.hpp" --output json/json.hpp mkdir cli11 curl -SsL "https://github.com/spicelang/CLI11/releases/download/v2.2.0-spice/CLI11.hpp" --output cli11/CLI11.hpp diff --git a/setup-libs.sh b/setup-libs.sh index d16a18301..d33e42532 100644 --- a/setup-libs.sh +++ b/setup-libs.sh @@ -5,8 +5,10 @@ cd lib || exit git clone --depth 1 --branch 4.10.1 https://github.com/antlr/antlr4.git +git clone --depth 1 --branch release-1.12.1 https://github.com/google/googletest.git + mkdir json -curl -SsL "https://github.com/nlohmann/json/releases/download/v3.10.5/json.hpp" --output json/json.hpp +curl -SsL "https://github.com/nlohmann/json/releases/download/v3.11.1/json.hpp" --output json/json.hpp mkdir cli11 curl -SsL "https://github.com/spicelang/CLI11/releases/download/v2.2.0-spice/CLI11.hpp" --output cli11/CLI11.hpp diff --git a/src/analyzer/AnalyzerVisitor.cpp b/src/analyzer/AnalyzerVisitor.cpp index 18a1a66a8..23bce8738 100644 --- a/src/analyzer/AnalyzerVisitor.cpp +++ b/src/analyzer/AnalyzerVisitor.cpp @@ -50,6 +50,9 @@ std::any AnalyzerVisitor::visitEntry(EntryNode *node) { // if (requiresMainFct && secondRun) // rootScope->purgeSubstantiationRemnants(); + // Reset the AST + node->reset(); + bool reAnalyze = reAnalyzeRequired; // Check if the visitor got a main function @@ -131,12 +134,12 @@ std::any AnalyzerVisitor::visitFctDef(FctDefNode *node) { // Get 'this' type std::vector templateTypes; SymbolType thisType = SymbolType(TY_DYN); - SymbolType thisTypePtr = thisType; + SymbolType thisPtrType = thisType; if (node->isMethod) { SymbolTableEntry *structEntry = currentScope->lookup(node->structName); assert(structEntry != nullptr); thisType = structEntry->getType(); - thisTypePtr = thisType.toPointer(err.get(), node->codeLoc); + thisPtrType = thisType.toPointer(err.get(), node->codeLoc); for (const auto &templateType : thisType.getTemplateTypes()) templateTypes.emplace_back(templateType); } @@ -177,9 +180,9 @@ std::any AnalyzerVisitor::visitFctDef(FctDefNode *node) { // Declare 'this' variable in new scope if (node->isMethod) { - SymbolSpecifiers thisTypeSpecifiers(thisTypePtr); + SymbolSpecifiers thisTypeSpecifiers(thisPtrType); thisTypeSpecifiers.setConst(true); - currentScope->insert(THIS_VARIABLE_NAME, thisTypePtr, thisTypeSpecifiers, INITIALIZED, node->codeLoc); + currentScope->insert(THIS_VARIABLE_NAME, thisPtrType, thisTypeSpecifiers, INITIALIZED, node->codeLoc); } // Declare variable for the return value in the function scope @@ -232,6 +235,9 @@ std::any AnalyzerVisitor::visitFctDef(FctDefNode *node) { if (node->isMethod) currentScope = currentScope->getParent(); + // Set the symbolTypeIndex to 0 + node->symbolTypeIndex = 0; + if (manifestations) { for (auto &[mangledName, spiceFunc] : *manifestations) { // Check if the function is substantiated @@ -253,11 +259,11 @@ std::any AnalyzerVisitor::visitFctDef(FctDefNode *node) { assert(currentScope != nullptr); // Replace this type - if (spiceFunc.isMethodFunction()) { + /*if (spiceFunc.isMethodFunction()) { SymbolTableEntry *thisVar = currentScope->lookup(THIS_VARIABLE_NAME); assert(thisVar != nullptr); thisVar->updateType(spiceFunc.getThisType(), true); - } + }*/ // Morph the generic return type SymbolTableEntry *returnVarEntry = currentScope->lookup(RETURN_VARIABLE_NAME); @@ -313,6 +319,9 @@ std::any AnalyzerVisitor::visitFctDef(FctDefNode *node) { currentScope = currentScope->getParent(); spiceFunc.setAnalyzed(); + + // Increase the symbolTypeIndex + node->symbolTypeIndex++; } } } @@ -335,11 +344,11 @@ std::any AnalyzerVisitor::visitProcDef(ProcDefNode *node) { // Get 'this' type std::vector templateTypes; SymbolType thisType = SymbolType(TY_DYN); - SymbolType thisTypePtr = thisType; + SymbolType thisPtrType = thisType; if (node->isMethod) { SymbolTableEntry *structEntry = currentScope->lookup(node->structName); thisType = structEntry->getType(); - thisTypePtr = thisType.toPointer(err.get(), node->codeLoc); + thisPtrType = thisType.toPointer(err.get(), node->codeLoc); for (const auto &templateType : thisType.getTemplateTypes()) templateTypes.emplace_back(templateType); } @@ -380,9 +389,9 @@ std::any AnalyzerVisitor::visitProcDef(ProcDefNode *node) { // Declare 'this' variable in new scope if (node->isMethod) { - auto thisSymbolSpecifiers = SymbolSpecifiers(thisTypePtr); + auto thisSymbolSpecifiers = SymbolSpecifiers(thisPtrType); thisSymbolSpecifiers.setConst(true); - currentScope->insert(THIS_VARIABLE_NAME, thisTypePtr, thisSymbolSpecifiers, INITIALIZED, node->codeLoc); + currentScope->insert(THIS_VARIABLE_NAME, thisPtrType, thisSymbolSpecifiers, INITIALIZED, node->codeLoc); } // Return to old scope @@ -427,6 +436,9 @@ std::any AnalyzerVisitor::visitProcDef(ProcDefNode *node) { if (node->isMethod) currentScope = currentScope->getParent(); + // Set the symbolTypeIndex to 0 + node->symbolTypeIndex = 0; + if (manifestations) { for (auto &[mangledName, spiceProc] : *manifestations) { // Check if the function is substantiated @@ -448,11 +460,11 @@ std::any AnalyzerVisitor::visitProcDef(ProcDefNode *node) { assert(currentScope != nullptr); // Replace this type - if (spiceProc.isMethodProcedure()) { + /*if (spiceProc.isMethodProcedure()) { SymbolTableEntry *thisVar = currentScope->lookup(THIS_VARIABLE_NAME); assert(thisVar != nullptr); thisVar->updateType(spiceProc.getThisType(), true); - } + }*/ // Get parameter types std::vector> params; @@ -494,6 +506,9 @@ std::any AnalyzerVisitor::visitProcDef(ProcDefNode *node) { currentScope = currentScope->getParent(); spiceProc.setAnalyzed(); + + // Increase the symbolTypeIndex + node->symbolTypeIndex++; } } } @@ -748,7 +763,7 @@ std::any AnalyzerVisitor::visitThreadDef(ThreadDefNode *node) { // Return to old scope currentScope = currentScope->getParent(); - return SymbolType(TY_BYTE).toPointer(err.get(), node->codeLoc); + return node->setEvaluatedSymbolType(SymbolType(TY_BYTE).toPointer(err.get(), node->codeLoc)); } std::any AnalyzerVisitor::visitUnsafeBlockDef(UnsafeBlockDefNode *node) { @@ -792,7 +807,7 @@ std::any AnalyzerVisitor::visitForLoop(ForLoopNode *node) { // Return to old scope currentScope = currentScope->getParent(); - return SymbolType(TY_BOOL); + return nullptr; } std::any AnalyzerVisitor::visitForeachLoop(ForeachLoopNode *node) { @@ -844,7 +859,7 @@ std::any AnalyzerVisitor::visitForeachLoop(ForeachLoopNode *node) { itemVarSymbol->updateType(itemType, false); // Update symbolType of the declaration data type - node->itemDecl()->dataType()->symbolType = itemType; + node->itemDecl()->dataType()->setEvaluatedSymbolType(itemType); } else { if (itemType != arrayType.getContainedTy()) throw err->get(node->itemDecl()->codeLoc, OPERATOR_WRONG_DATA_TYPE, @@ -861,7 +876,7 @@ std::any AnalyzerVisitor::visitForeachLoop(ForeachLoopNode *node) { // Return to old scope currentScope = currentScope->getParent(); - return SymbolType(TY_BOOL); + return nullptr; } std::any AnalyzerVisitor::visitWhileLoop(WhileLoopNode *node) { @@ -881,7 +896,7 @@ std::any AnalyzerVisitor::visitWhileLoop(WhileLoopNode *node) { // Return to old scope currentScope = currentScope->getParent(); - return SymbolType(TY_BOOL); + return nullptr; } std::any AnalyzerVisitor::visitIfStmt(IfStmtNode *node) { @@ -903,7 +918,7 @@ std::any AnalyzerVisitor::visitIfStmt(IfStmtNode *node) { if (node->elseStmt()) visit(node->elseStmt()); - return SymbolType(TY_BOOL); + return nullptr; } std::any AnalyzerVisitor::visitElseStmt(ElseStmtNode *node) { @@ -919,7 +934,7 @@ std::any AnalyzerVisitor::visitElseStmt(ElseStmtNode *node) { // Return to old scope currentScope = currentScope->getParent(); } - return SymbolType(TY_BOOL); + return nullptr; } std::any AnalyzerVisitor::visitAssertStmt(AssertStmtNode *node) { @@ -929,14 +944,15 @@ std::any AnalyzerVisitor::visitAssertStmt(AssertStmtNode *node) { if (!assertConditionType.is(TY_BOOL)) throw err->get(node->assignExpr()->codeLoc, ASSERTION_CONDITION_BOOL, "The asserted condition must be of type bool"); - return assertConditionType; + return nullptr; } std::any AnalyzerVisitor::visitParamLst(ParamLstNode *node) { NamedParamList namedParamList; bool metOptional = false; for (const auto ¶m : node->params()) { - auto paramType = any_cast(visit(param)); + visit(param); + SymbolType paramType = param->dataType()->getEvaluatedSymbolType(); // Check if the type could be inferred. Dyn without a default value is forbidden if (paramType.is(TY_DYN)) @@ -970,8 +986,8 @@ std::any AnalyzerVisitor::visitDeclStmt(DeclStmtNode *node) { symbolType = opRuleManager->getAssignResultType(node->codeLoc, symbolType, rhsTy); initialState = INITIALIZED; - // Update symbolType of the declaration data type - node->dataType()->symbolType = symbolType; + // Push symbolType to the declaration data type + node->dataType()->setEvaluatedSymbolType(symbolType); // If the rhs is of type array and was the array initialization, there must be a size attached if (symbolType.isArray() && symbolType.getArraySize() == 0 && currentVarName.empty()) @@ -1054,7 +1070,7 @@ std::any AnalyzerVisitor::visitReturnStmt(ReturnStmtNode *node) { for (SymbolTableEntry *varEntry : varsToDestruct) insertDestructorCall(node->codeLoc, varEntry); - return returnType; + return nullptr; } std::any AnalyzerVisitor::visitBreakStmt(BreakStmtNode *node) { @@ -1068,7 +1084,7 @@ std::any AnalyzerVisitor::visitBreakStmt(BreakStmtNode *node) { if (node->breakTimes > nestedLoopCounter) throw err->get(node->codeLoc, INVALID_BREAK_NUMBER, "We can only break " + std::to_string(nestedLoopCounter) + " time(s) here"); - return SymbolType(TY_INT); + return nullptr; } std::any AnalyzerVisitor::visitContinueStmt(ContinueStmtNode *node) { @@ -1082,7 +1098,7 @@ std::any AnalyzerVisitor::visitContinueStmt(ContinueStmtNode *node) { if (node->continueTimes > nestedLoopCounter) throw err->get(node->codeLoc, INVALID_CONTINUE_NUMBER, "We can only continue " + std::to_string(nestedLoopCounter) + " time(s) here"); - return SymbolType(TY_INT); + return nullptr; } std::any AnalyzerVisitor::visitPrintfCall(PrintfCallNode *node) { @@ -1155,7 +1171,7 @@ std::any AnalyzerVisitor::visitPrintfCall(PrintfCallNode *node) { throw err->get(node->codeLoc, PRINTF_ARG_COUNT_ERROR, "The placeholder string contains less placeholders that arguments were passed"); - return SymbolType(TY_BOOL); + return node->setEvaluatedSymbolType(SymbolType(TY_BOOL)); } std::any AnalyzerVisitor::visitSizeofCall(SizeofCallNode *node) { @@ -1164,7 +1180,7 @@ std::any AnalyzerVisitor::visitSizeofCall(SizeofCallNode *node) { } else { // Size of value any_cast(visit(node->assignExpr())); } - return SymbolType(TY_INT); + return node->setEvaluatedSymbolType(SymbolType(TY_INT)); } std::any AnalyzerVisitor::visitLenCall(LenCallNode *node) { @@ -1174,12 +1190,12 @@ std::any AnalyzerVisitor::visitLenCall(LenCallNode *node) { if (!argType.isArray()) throw err->get(node->assignExpr()->codeLoc, EXPECTED_ARRAY_TYPE, "The len builtin can only work on arrays"); - return SymbolType(TY_INT); + return node->setEvaluatedSymbolType(SymbolType(TY_INT)); } -std::any AnalyzerVisitor::visitTidCall(TidCallNode * /*node*/) { +std::any AnalyzerVisitor::visitTidCall(TidCallNode *node) { // Nothing to check here. Tid builtin has no arguments - return SymbolType(TY_INT); + return node->setEvaluatedSymbolType(SymbolType(TY_INT)); } std::any AnalyzerVisitor::visitJoinCall(JoinCallNode *node) { @@ -1192,7 +1208,7 @@ std::any AnalyzerVisitor::visitJoinCall(JoinCallNode *node) { } // Return the number of threads that were joined - return SymbolType(TY_INT); + return node->setEvaluatedSymbolType(SymbolType(TY_INT)); } std::any AnalyzerVisitor::visitAssignExpr(AssignExprNode *node) { @@ -1259,7 +1275,7 @@ std::any AnalyzerVisitor::visitAssignExpr(AssignExprNode *node) { .print(); } - return rhsTy; + return node->setEvaluatedSymbolType(rhsTy); } else if (node->ternaryExpr()) { return visit(node->ternaryExpr()); } else if (node->threadDef()) { @@ -1283,7 +1299,7 @@ std::any AnalyzerVisitor::visitTernaryExpr(TernaryExprNode *node) { // Check if trueType and falseType are matching if (trueType != falseType) throw err->get(node->codeLoc, OPERATOR_WRONG_DATA_TYPE, "True and false operands in ternary must be of same data type"); - return trueType; + return node->setEvaluatedSymbolType(trueType); } return visit(node->operands().front()); } @@ -1296,7 +1312,7 @@ std::any AnalyzerVisitor::visitLogicalOrExpr(LogicalOrExprNode *node) { auto rhsTy = any_cast(visit(node->operands()[i])); lhsTy = opRuleManager->getLogicalOrResultType(node->codeLoc, lhsTy, rhsTy); } - return lhsTy; + return node->setEvaluatedSymbolType(lhsTy); } return visit(node->operands().front()); } @@ -1309,7 +1325,7 @@ std::any AnalyzerVisitor::visitLogicalAndExpr(LogicalAndExprNode *node) { auto rhsTy = any_cast(visit(node->operands()[i])); lhsTy = opRuleManager->getLogicalAndResultType(node->codeLoc, lhsTy, rhsTy); } - return lhsTy; + return node->setEvaluatedSymbolType(lhsTy); } return visit(node->operands().front()); } @@ -1322,7 +1338,7 @@ std::any AnalyzerVisitor::visitBitwiseOrExpr(BitwiseOrExprNode *node) { auto rhsTy = any_cast(visit(node->operands()[i])); lhsTy = opRuleManager->getBitwiseOrResultType(node->codeLoc, lhsTy, rhsTy); } - return lhsTy; + return node->setEvaluatedSymbolType(lhsTy); } return visit(node->operands().front()); } @@ -1335,7 +1351,7 @@ std::any AnalyzerVisitor::visitBitwiseXorExpr(BitwiseXorExprNode *node) { auto rhsTy = any_cast(visit(node->operands()[i])); lhsTy = opRuleManager->getBitwiseXorResultType(node->codeLoc, lhsTy, rhsTy); } - return lhsTy; + return node->setEvaluatedSymbolType(lhsTy); } return visit(node->operands().front()); } @@ -1348,7 +1364,7 @@ std::any AnalyzerVisitor::visitBitwiseAndExpr(BitwiseAndExprNode *node) { auto rhsTy = any_cast(visit(node->operands()[i])); lhsTy = opRuleManager->getBitwiseAndResultType(node->codeLoc, lhsTy, rhsTy); } - return lhsTy; + return node->setEvaluatedSymbolType(lhsTy); } return visit(node->operands().front()); } @@ -1360,9 +1376,9 @@ std::any AnalyzerVisitor::visitEqualityExpr(EqualityExprNode *node) { auto rhsTy = any_cast(visit(node->operands()[1])); if (node->op == EqualityExprNode::OP_EQUAL) // Operator was equal - return opRuleManager->getEqualResultType(node->codeLoc, lhsTy, rhsTy); + return node->setEvaluatedSymbolType(opRuleManager->getEqualResultType(node->codeLoc, lhsTy, rhsTy)); else if (node->op == EqualityExprNode::OP_NOT_EQUAL) // Operator was not equal - return opRuleManager->getNotEqualResultType(node->codeLoc, lhsTy, rhsTy); + return node->setEvaluatedSymbolType(opRuleManager->getNotEqualResultType(node->codeLoc, lhsTy, rhsTy)); } return visit(node->operands().front()); } @@ -1374,13 +1390,13 @@ std::any AnalyzerVisitor::visitRelationalExpr(RelationalExprNode *node) { auto rhsTy = any_cast(visit(node->operands()[1])); if (node->op == RelationalExprNode::OP_LESS) // Operator was less - return opRuleManager->getLessResultType(node->codeLoc, lhsTy, rhsTy); + return node->setEvaluatedSymbolType(opRuleManager->getLessResultType(node->codeLoc, lhsTy, rhsTy)); else if (node->op == RelationalExprNode::OP_GREATER) // Operator was greater - return opRuleManager->getGreaterResultType(node->codeLoc, lhsTy, rhsTy); + return node->setEvaluatedSymbolType(opRuleManager->getGreaterResultType(node->codeLoc, lhsTy, rhsTy)); else if (node->op == RelationalExprNode::OP_LESS_EQUAL) // Operator was less equal - return opRuleManager->getLessEqualResultType(node->codeLoc, lhsTy, rhsTy); + return node->setEvaluatedSymbolType(opRuleManager->getLessEqualResultType(node->codeLoc, lhsTy, rhsTy)); else if (node->op == RelationalExprNode::OP_GREATER_EQUAL) // Operator was greater equal - return opRuleManager->getGreaterEqualResultType(node->codeLoc, lhsTy, rhsTy); + return node->setEvaluatedSymbolType(opRuleManager->getGreaterEqualResultType(node->codeLoc, lhsTy, rhsTy)); } return visit(node->operands().front()); } @@ -1392,9 +1408,9 @@ std::any AnalyzerVisitor::visitShiftExpr(ShiftExprNode *node) { auto rhsTy = any_cast(visit(node->operands()[1])); if (node->op == ShiftExprNode::OP_SHIFT_LEFT) // Operator was shl - return opRuleManager->getShiftLeftResultType(node->codeLoc, lhsTy, rhsTy); + return node->setEvaluatedSymbolType(opRuleManager->getShiftLeftResultType(node->codeLoc, lhsTy, rhsTy)); else if (node->op == ShiftExprNode::OP_SHIFT_RIGHT) // Operator was shr - return opRuleManager->getShiftRightResultType(node->codeLoc, lhsTy, rhsTy); + return node->setEvaluatedSymbolType(opRuleManager->getShiftRightResultType(node->codeLoc, lhsTy, rhsTy)); } return visit(node->operands().front()); } @@ -1404,14 +1420,15 @@ std::any AnalyzerVisitor::visitAdditiveExpr(AdditiveExprNode *node) { if (node->operands().size() > 1) { auto currentType = any_cast(visit(node->operands()[0])); - std::queue opQueue = node->opQueue; + auto opQueue = node->opQueue; + std::queue> newOpQueue; size_t operandIndex = 1; while (!opQueue.empty()) { MultiplicativeExprNode *operand = node->operands()[operandIndex++]; assert(operand != nullptr); auto operandType = any_cast(visit(operand)); - switch (opQueue.front()) { + switch (opQueue.front().first) { case AdditiveExprNode::OP_PLUS: currentType = opRuleManager->getPlusResultType(operand->codeLoc, currentType, operandType); break; @@ -1422,10 +1439,12 @@ std::any AnalyzerVisitor::visitAdditiveExpr(AdditiveExprNode *node) { throw std::runtime_error("Additive expr fall-through"); } + newOpQueue.emplace(opQueue.front().first, currentType); opQueue.pop(); } + node->opQueue = newOpQueue; - return currentType; + return node->setEvaluatedSymbolType(currentType); } return visit(node->operands().front()); } @@ -1435,14 +1454,15 @@ std::any AnalyzerVisitor::visitMultiplicativeExpr(MultiplicativeExprNode *node) if (node->operands().size() > 1) { auto currentType = any_cast(visit(node->operands()[0])); - std::queue opQueue = node->opQueue; + auto opQueue = node->opQueue; + std::queue> newOpQueue; size_t operandIndex = 1; while (!opQueue.empty()) { CastExprNode *operand = node->operands()[operandIndex++]; assert(operand != nullptr); auto operandType = any_cast(visit(operand)); - switch (opQueue.front()) { + switch (opQueue.front().first) { case MultiplicativeExprNode::OP_MUL: currentType = opRuleManager->getMulResultType(operand->codeLoc, currentType, operandType); break; @@ -1456,10 +1476,12 @@ std::any AnalyzerVisitor::visitMultiplicativeExpr(MultiplicativeExprNode *node) throw std::runtime_error("Multiplicative expr fall-through"); } + newOpQueue.emplace(opQueue.front().first, currentType); opQueue.pop(); } + node->opQueue = newOpQueue; - return currentType; + return node->setEvaluatedSymbolType(currentType); } return visit(node->operands().front()); } @@ -1468,8 +1490,10 @@ std::any AnalyzerVisitor::visitCastExpr(CastExprNode *node) { std::any rhs = visit(node->prefixUnaryExpr()); if (node->isCasted) { // Cast is applied + auto srcType = any_cast(rhs); auto dstType = any_cast(visit(node->dataType())); - return opRuleManager->getCastResultType(node->codeLoc, dstType, any_cast(rhs)); + SymbolType symbolType = opRuleManager->getCastResultType(node->codeLoc, dstType, any_cast(rhs)); + return node->setEvaluatedSymbolType(symbolType); } return rhs; @@ -1482,9 +1506,10 @@ std::any AnalyzerVisitor::visitPrefixUnaryExpr(PrefixUnaryExprNode *node) { auto rhs = any_cast(visit(node->postfixUnaryExpr())); - std::stack opStack = node->opStack; // Copy to not modify the stack in the AST node + auto opStack = node->opStack; + std::stack> newOpStack; while (!opStack.empty()) { - switch (opStack.top()) { + switch (opStack.top().first) { case PrefixUnaryExprNode::OP_MINUS: rhs = opRuleManager->getPrefixMinusResultType(node->postfixUnaryExpr()->codeLoc, rhs); break; @@ -1525,10 +1550,13 @@ std::any AnalyzerVisitor::visitPrefixUnaryExpr(PrefixUnaryExprNode *node) { default: throw std::runtime_error("Prefix unary fall-through"); } + + newOpStack.emplace(opStack.top().first, rhs); opStack.pop(); } + node->opStack = newOpStack; - return rhs; + return node->setEvaluatedSymbolType(rhs); } std::any AnalyzerVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { @@ -1537,9 +1565,10 @@ std::any AnalyzerVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { size_t subscriptCounter = 0; size_t memberAccessCounter = 0; - std::queue opQueue = node->opQueue; // Copy to not modify the queue in the AST node + auto opQueue = node->opQueue; + std::queue> newOpQueue; while (!opQueue.empty()) { - switch (opQueue.front()) { + switch (opQueue.front().first) { case PostfixUnaryExprNode::OP_SUBSCRIPT: { std::string arrayName = currentVarName; // Save array name SymbolTableEntry *currentEntryBackup = currentEntry; // Save current entry @@ -1612,14 +1641,17 @@ std::any AnalyzerVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { default: throw std::runtime_error("PostfixUnary fall-through"); } + + newOpQueue.emplace(opQueue.front().first, lhs); opQueue.pop(); } + node->opQueue = newOpQueue; if (lhs.is(TY_INVALID)) throw err->get(node->codeLoc, REFERENCED_UNDEFINED_VARIABLE, "Variable '" + currentVarName + "' was referenced before declared"); - return lhs; + return node->setEvaluatedSymbolType(lhs); } std::any AnalyzerVisitor::visitAtomicExpr(AtomicExprNode *node) { @@ -1687,8 +1719,9 @@ std::any AnalyzerVisitor::visitAtomicExpr(AtomicExprNode *node) { SymbolTableEntry *parentStruct = currentScope->lookup(scopePath.getLastScopeName()); assert(parentStruct != nullptr); std::string scopePrefix = CommonUtil::getPrefix(parentStruct->getType().getSubType(), "."); - return initExtStruct(accessScope, scopePrefix, entry->getType().getBaseType().getSubType(), - currentThisType.getTemplateTypes(), node->codeLoc); + SymbolType symbolType = initExtStruct(accessScope, scopePrefix, entry->getType().getBaseType().getSubType(), + currentThisType.getTemplateTypes(), node->codeLoc); + return node->setEvaluatedSymbolType(symbolType); } } else { // Check if we have seen a 'this.' prefix, because the generator needs that @@ -1701,7 +1734,7 @@ std::any AnalyzerVisitor::visitAtomicExpr(AtomicExprNode *node) { // Otherwise, push the retrieved scope to the scope path scopePath.pushFragment(currentVarName, accessScope); - return entry->getType(); + return node->setEvaluatedSymbolType(entry->getType()); } if (node->printfCall()) @@ -1744,7 +1777,7 @@ std::any AnalyzerVisitor::visitValue(ValueNode *node) { auto nilType = any_cast(visit(node->nilType())); if (nilType.is(TY_DYN)) throw err->get(node->nilType()->codeLoc, UNEXPECTED_DYN_TYPE_SA, "Nil must have an explicit type"); - return nilType; + return node->setEvaluatedSymbolType(nilType); } throw std::runtime_error("Value fall-through"); @@ -1753,21 +1786,21 @@ std::any AnalyzerVisitor::visitValue(ValueNode *node) { std::any AnalyzerVisitor::visitPrimitiveValue(PrimitiveValueNode *node) { switch (node->type) { case PrimitiveValueNode::TY_DOUBLE: - return SymbolType(TY_DOUBLE); + return node->setEvaluatedSymbolType(SymbolType(TY_DOUBLE)); case PrimitiveValueNode::TY_INT: - return SymbolType(TY_INT); + return node->setEvaluatedSymbolType(SymbolType(TY_INT)); case PrimitiveValueNode::TY_SHORT: - return SymbolType(TY_SHORT); + return node->setEvaluatedSymbolType(SymbolType(TY_SHORT)); case PrimitiveValueNode::TY_LONG: - return SymbolType(TY_LONG); + return node->setEvaluatedSymbolType(SymbolType(TY_LONG)); case PrimitiveValueNode::TY_BYTE: - return SymbolType(TY_BYTE); + return node->setEvaluatedSymbolType(SymbolType(TY_BYTE)); case PrimitiveValueNode::TY_CHAR: - return SymbolType(TY_CHAR); + return node->setEvaluatedSymbolType(SymbolType(TY_CHAR)); case PrimitiveValueNode::TY_STRING: - return SymbolType(TY_STRING); + return node->setEvaluatedSymbolType(SymbolType(TY_STRING)); case PrimitiveValueNode::TY_BOOL: - return SymbolType(TY_BOOL); + return node->setEvaluatedSymbolType(SymbolType(TY_BOOL)); } throw std::runtime_error("Primitive value fall-through"); } @@ -1851,7 +1884,7 @@ std::any AnalyzerVisitor::visitFunctionCall(FunctionCallNode *node) { SymbolSpecifiers specifiers = SymbolSpecifiers(SymbolType(TY_FUNCTION)); ArgList errArgTypes; - for (auto &argType : argTypes) + for (const auto &argType : argTypes) errArgTypes.emplace_back(argType, false); Function f(functionName, specifiers, thisType, SymbolType(TY_DYN), errArgTypes, {}, node->codeLoc); @@ -1878,21 +1911,23 @@ std::any AnalyzerVisitor::visitFunctionCall(FunctionCallNode *node) { // Return struct type on constructor call if (constructorCall) - return thisType; + return node->setEvaluatedSymbolType(thisType); // If the callee is a procedure, return type bool if (spiceFunc->isProcedure() || spiceFunc->getReturnType().is(TY_DYN)) - return SymbolType(TY_BOOL); + return node->setEvaluatedSymbolType(SymbolType(TY_BOOL)); // Retrieve the return type of the function SymbolType returnType = spiceFunc->getReturnType(); // If the return type is an external struct, initialize it - if (!scopePathBackup.isEmpty() && returnType.is(TY_STRUCT) && scopePathBackup.getCurrentScope()->isImported(currentScope)) - return initExtStruct(scopePathBackup.getCurrentScope(), scopePathBackup.getScopePrefix(true), returnType.getSubType(), - thisType.getTemplateTypes(), node->codeLoc); + if (!scopePathBackup.isEmpty() && returnType.is(TY_STRUCT) && scopePathBackup.getCurrentScope()->isImported(currentScope)) { + SymbolType symbolType = initExtStruct(scopePathBackup.getCurrentScope(), scopePathBackup.getScopePrefix(true), + returnType.getSubType(), thisType.getTemplateTypes(), node->codeLoc); + return node->setEvaluatedSymbolType(symbolType); + } - return returnType; + return node->setEvaluatedSymbolType(returnType); } std::any AnalyzerVisitor::visitArrayInitialization(ArrayInitializationNode *node) { @@ -1900,7 +1935,7 @@ std::any AnalyzerVisitor::visitArrayInitialization(ArrayInitializationNode *node int actualSize = 0; SymbolType actualItemType = SymbolType(TY_DYN); if (node->itemLst()) { - for (auto &arg : node->itemLst()->args()) { + for (const auto &arg : node->itemLst()->args()) { auto itemType = any_cast(visit(arg)); if (actualItemType.is(TY_DYN)) { actualItemType = itemType; @@ -1925,7 +1960,7 @@ std::any AnalyzerVisitor::visitArrayInitialization(ArrayInitializationNode *node actualItemType = expectedType.getContainedTy(); } - return actualItemType.toArray(err.get(), node->codeLoc, actualSize); + return node->setEvaluatedSymbolType(actualItemType.toArray(err.get(), node->codeLoc, actualSize)); } std::any AnalyzerVisitor::visitStructInstantiation(StructInstantiationNode *node) { @@ -1983,7 +2018,7 @@ std::any AnalyzerVisitor::visitStructInstantiation(StructInstantiationNode *node // Set template types to the struct std::vector genericTemplateTypes = spiceStruct->getTemplateTypes(); std::vector templateTypes; - for (auto &genericType : genericTemplateTypes) + for (const auto &genericType : genericTemplateTypes) templateTypes.emplace_back(genericType.getTypeChain()); structType.setTemplateTypes(templateTypes); @@ -2015,7 +2050,7 @@ std::any AnalyzerVisitor::visitStructInstantiation(StructInstantiationNode *node } } - return structType; + return node->setEvaluatedSymbolType(structType); } std::any AnalyzerVisitor::visitDataType(DataTypeNode *node) { @@ -2037,7 +2072,7 @@ std::any AnalyzerVisitor::visitDataType(DataTypeNode *node) { if (typeModifier.hardcodedSize <= 1) throw err->get(node->codeLoc, ARRAY_SIZE_INVALID, "The size of an array must be > 1 and explicitly stated"); } else { - auto sizeType = std::any_cast(visit(arraySizeExpr[assignExprCounter++])); + auto sizeType = any_cast(visit(arraySizeExpr[assignExprCounter++])); if (!sizeType.isOneOf({TY_INT, TY_LONG, TY_SHORT})) throw err->get(node->codeLoc, ARRAY_SIZE_INVALID, "The array size must be of type int, long or short"); } @@ -2051,31 +2086,31 @@ std::any AnalyzerVisitor::visitDataType(DataTypeNode *node) { tmQueue.pop(); } - return node->symbolType = type; + return node->setEvaluatedSymbolType(type); } std::any AnalyzerVisitor::visitBaseDataType(BaseDataTypeNode *node) { switch (node->type) { case BaseDataTypeNode::TY_DOUBLE: - return SymbolType(TY_DOUBLE); + return node->setEvaluatedSymbolType(SymbolType(TY_DOUBLE)); case BaseDataTypeNode::TY_INT: - return SymbolType(TY_INT); + return node->setEvaluatedSymbolType(SymbolType(TY_INT)); case BaseDataTypeNode::TY_SHORT: - return SymbolType(TY_SHORT); + return node->setEvaluatedSymbolType(SymbolType(TY_SHORT)); case BaseDataTypeNode::TY_LONG: - return SymbolType(TY_LONG); + return node->setEvaluatedSymbolType(SymbolType(TY_LONG)); case BaseDataTypeNode::TY_BYTE: - return SymbolType(TY_BYTE); + return node->setEvaluatedSymbolType(SymbolType(TY_BYTE)); case BaseDataTypeNode::TY_CHAR: - return SymbolType(TY_CHAR); + return node->setEvaluatedSymbolType(SymbolType(TY_CHAR)); case BaseDataTypeNode::TY_STRING: - return SymbolType(TY_STRING); + return node->setEvaluatedSymbolType(SymbolType(TY_STRING)); case BaseDataTypeNode::TY_BOOL: - return SymbolType(TY_BOOL); + return node->setEvaluatedSymbolType(SymbolType(TY_BOOL)); case BaseDataTypeNode::TY_CUSTOM: - return std::any_cast(visit(node->customDataType())); + return node->setEvaluatedSymbolType(any_cast(visit(node->customDataType()))); default: - return SymbolType(TY_DYN); + return node->setEvaluatedSymbolType(SymbolType(TY_DYN)); } } @@ -2083,8 +2118,10 @@ std::any AnalyzerVisitor::visitCustomDataType(CustomDataTypeNode *node) { // Check if it is a generic type std::string firstFragment = node->typeNameFragments.front(); SymbolTableEntry *entry = currentScope->lookup(firstFragment); - if (node->typeNameFragments.size() == 1 && !entry && currentScope->lookupGenericType(firstFragment)) - return *static_cast(currentScope->lookupGenericType(firstFragment)); + if (node->typeNameFragments.size() == 1 && !entry && currentScope->lookupGenericType(firstFragment)) { + SymbolType symbolType = *static_cast(currentScope->lookupGenericType(firstFragment)); + return node->setEvaluatedSymbolType(symbolType); + } // It is a struct type -> get the access scope SymbolTable *accessScope = scopePath.getCurrentScope() ? scopePath.getCurrentScope() : currentScope; @@ -2122,8 +2159,10 @@ std::any AnalyzerVisitor::visitCustomDataType(CustomDataTypeNode *node) { if (spiceStruct) spiceStruct->setUsed(); - if (structIsImported) // Imported struct - return initExtStruct(accessScope, accessScopePrefix, structName, concreteTemplateTypes, node->codeLoc); + if (structIsImported) { // Imported struct + SymbolType symbolType = initExtStruct(accessScope, accessScopePrefix, structName, concreteTemplateTypes, node->codeLoc); + return node->setEvaluatedSymbolType(symbolType); + } // Check if struct was declared SymbolTableEntry *structSymbol = accessScope->lookup(structName); @@ -2131,7 +2170,7 @@ std::any AnalyzerVisitor::visitCustomDataType(CustomDataTypeNode *node) { throw err->get(node->codeLoc, UNKNOWN_DATATYPE, "Unknown datatype '" + structName + "'"); structSymbol->setUsed(); - return SymbolType(TY_STRUCT, structName, concreteTemplateTypes); + return node->setEvaluatedSymbolType(SymbolType(TY_STRUCT, structName, concreteTemplateTypes)); } void AnalyzerVisitor::insertDestructorCall(const CodeLoc &codeLoc, SymbolTableEntry *varEntry) { @@ -2173,7 +2212,7 @@ SymbolType AnalyzerVisitor::initExtStruct(SymbolTable *sourceScope, const std::s SymbolTable *externalStructTable = sourceScope->lookupTable(STRUCT_SCOPE_PREFIX + structSignature); // Initialize potential structs for field types - for (auto &[_, entry] : externalStructTable->getSymbols()) { + for (const auto &[_, entry] : externalStructTable->getSymbols()) { if (entry.getType().isBaseType(TY_STRUCT)) { std::string nestedStructName = CommonUtil::getLastFragment(entry.getType().getBaseType().getSubType(), "."); std::string nestedStructPrefix = CommonUtil::getPrefix(entry.getType().getBaseType().getSubType(), "."); diff --git a/src/analyzer/PreAnalyzerVisitor.cpp b/src/analyzer/PreAnalyzerVisitor.cpp index 8683eaa6f..278edc707 100644 --- a/src/analyzer/PreAnalyzerVisitor.cpp +++ b/src/analyzer/PreAnalyzerVisitor.cpp @@ -10,8 +10,13 @@ #include std::any PreAnalyzerVisitor::visitEntry(EntryNode *node) { - for (auto &importStmt : node->importStmts()) + // Visit all import statements + for (const auto &importStmt : node->importStmts()) visit(importStmt); + + // Reset the AST + node->reset(); + return nullptr; } diff --git a/src/ast/AstNodes.h b/src/ast/AstNodes.h index c1d4d2d3f..90bc687ca 100644 --- a/src/ast/AstNodes.h +++ b/src/ast/AstNodes.h @@ -21,7 +21,7 @@ class AstNode { // Destructors virtual ~AstNode() { - for (auto child : children) + for (const auto child : children) delete child; } @@ -39,7 +39,7 @@ class AstNode { template [[nodiscard]] T *getChild(size_t i = 0) const { static_assert(std::is_base_of_v, "T must be derived from AstNode"); size_t j = 0; - for (auto &child : children) { + for (const auto &child : children) { if (auto *typedChild = dynamic_cast(child); typedChild != nullptr) { if (j++ == i) return typedChild; @@ -51,17 +51,53 @@ class AstNode { template [[nodiscard]] std::vector getChildren() const { static_assert(std::is_base_of_v, "T must be derived from AstNode"); std::vector nodes; - for (auto &child : children) { + for (const auto &child : children) { if (auto *typedChild = dynamic_cast(child); typedChild != nullptr) nodes.push_back(typedChild); } return nodes; } + [[nodiscard]] size_t getSymbolTypeIndex() const { + if (symbolTypeIndex == SIZE_MAX) { + if (parent != nullptr) + return parent->getSymbolTypeIndex(); + return 0; + } + return symbolTypeIndex; + } + + SymbolType setEvaluatedSymbolType(const SymbolType &symbolType) { + size_t index = getSymbolTypeIndex(); + // if (symbolTypes.capacity() <= index) + // symbolTypes.reserve(index + 1); + symbolTypes.insert(symbolTypes.begin() + index, symbolType); + return symbolType; + } + + SymbolType getEvaluatedSymbolType() { + size_t symbolTypeIndex = getSymbolTypeIndex(); + if (!symbolTypes.empty() && !symbolTypes[symbolTypeIndex].is(TY_INVALID)) + return symbolTypes.at(symbolTypeIndex); + if (children.size() != 1) + throw std::runtime_error("Cannot deduce evaluated symbol type"); + return children.front()->getEvaluatedSymbolType(); + } + + void reset() { + // Reset all children + for (const auto &child : children) + child->reset(); + // Reset the symbolTypeIndex counter + symbolTypeIndex = SIZE_MAX; + } + // Public members AstNode *parent; std::vector children; const CodeLoc codeLoc; + size_t symbolTypeIndex = SIZE_MAX; + std::vector symbolTypes; }; // ========================================================== EntryNode ========================================================== @@ -882,7 +918,7 @@ class AdditiveExprNode : public AstNode { [[nodiscard]] std::vector operands() const { return getChildren(); } // Public members - std::queue opQueue; + std::queue> opQueue; }; // ================================================== MultiplicativeExprNode ===================================================== @@ -906,7 +942,7 @@ class MultiplicativeExprNode : public AstNode { [[nodiscard]] std::vector operands() const { return getChildren(); } // Public members - std::queue opQueue; + std::queue> opQueue; }; // ======================================================= CastExprNode ========================================================== @@ -952,7 +988,7 @@ class PrefixUnaryExprNode : public AstNode { [[nodiscard]] PostfixUnaryExprNode *postfixUnaryExpr() const { return getChild(); } // Public members - std::stack opStack; + std::stack> opStack; }; // =================================================== PostfixUnaryExprNode ====================================================== @@ -974,7 +1010,7 @@ class PostfixUnaryExprNode : public AstNode { [[nodiscard]] std::vector postfixUnaryExpr() const { return getChildren(); } // Public members - std::queue opQueue; + std::queue> opQueue; }; // ====================================================== AtomicExprNode ========================================================= @@ -1130,7 +1166,6 @@ class DataTypeNode : public AstNode { // Public members std::queue tmQueue; - SymbolType symbolType = SymbolType(TY_INVALID); }; // ==================================================== BaseDataTypeNode ========================================================= diff --git a/src/dependency/SourceFile.cpp b/src/dependency/SourceFile.cpp index c063c69f9..c214e0913 100644 --- a/src/dependency/SourceFile.cpp +++ b/src/dependency/SourceFile.cpp @@ -68,7 +68,7 @@ void SourceFile::visualizeCST(std::string *output) { dotCode += " label=\"" + replacedFilePath + "\";\n "; // Visualize the imported source files - for (auto &[_, sourceFile] : dependencies) + for (const auto &[_, sourceFile] : dependencies) sourceFile.first->visualizeCST(output); // Generate dot code for this source file @@ -103,7 +103,7 @@ void SourceFile::visualizeCST(std::string *output) { void SourceFile::buildAST() { // Transform the imported source files - for (auto &[_, sourceFile] : dependencies) + for (const auto &[_, sourceFile] : dependencies) sourceFile.first->buildAST(); // Transform this source file @@ -123,7 +123,7 @@ void SourceFile::visualizeAST(std::string *output) { dotCode += " label=\"" + replacedFilePath + "\";\n "; // Visualize the imported source files - for (auto &[_, sourceFile] : dependencies) + for (const auto &[_, sourceFile] : dependencies) sourceFile.first->visualizeAST(output); // Generate dot code for this source file @@ -162,7 +162,7 @@ void SourceFile::preAnalyze() { antlrCtx.parser->reset(); // Analyze the imported source files - for (auto &[_, sourceFile] : dependencies) { + for (const auto &[_, sourceFile] : dependencies) { sourceFile.first->buildAST(); sourceFile.first->preAnalyze(); } @@ -171,7 +171,7 @@ void SourceFile::preAnalyze() { void SourceFile::analyze(const std::shared_ptr &context, const std::shared_ptr> &builder, const ThreadFactory &threadFactory) { // Analyze the imported source files - for (auto &[importName, sourceFile] : dependencies) { + for (const auto &[importName, sourceFile] : dependencies) { // Analyze the imported source file sourceFile.first->analyze(context, builder, threadFactory); @@ -206,7 +206,7 @@ void SourceFile::reAnalyze(const std::shared_ptr &context, co } while (repetitionRequired); // Re-analyze the imported source files - for (auto &[importName, sourceFile] : dependencies) + for (const auto &[importName, sourceFile] : dependencies) sourceFile.first->reAnalyze(context, builder, threadFactory); // Save the JSON version in the compiler output @@ -222,7 +222,7 @@ void SourceFile::reAnalyze(const std::shared_ptr &context, co void SourceFile::generate(const std::shared_ptr &context, const std::shared_ptr> &builder, ThreadFactory &threadFactory, LinkerInterface &linker) { // Generate the imported source files - for (auto &[_, sourceFile] : dependencies) + for (const auto &[_, sourceFile] : dependencies) sourceFile.first->generate(context, builder, threadFactory, linker); // Generate this source file @@ -230,7 +230,7 @@ void SourceFile::generate(const std::shared_ptr &context, con bool repetitionRequired; unsigned int generateCount = 0; do { - repetitionRequired = std::any_cast(generator->visit(ast.get())); + repetitionRequired = any_cast(generator->visit(ast.get())); antlrCtx.parser->reset(); generateCount++; if (generateCount >= 10) diff --git a/src/generator/GeneratorVisitor.cpp b/src/generator/GeneratorVisitor.cpp index 5711fe6a0..55a78492d 100644 --- a/src/generator/GeneratorVisitor.cpp +++ b/src/generator/GeneratorVisitor.cpp @@ -46,7 +46,7 @@ GeneratorVisitor::GeneratorVisitor(const std::shared_ptr &con // Create LLVM base components module = std::make_unique(FileUtil::getFileName(sourceFile.filePath), *context); - conversionsManager = std::make_unique(builder, err.get()); + conversionsManager = std::make_unique(context, builder, err.get()); // Initialize LLVM llvm::InitializeAllTargetInfos(); @@ -144,8 +144,13 @@ void GeneratorVisitor::dumpAsm() { } std::any GeneratorVisitor::visitEntry(EntryNode *node) { + // Visit children AstVisitor::visitEntry(node); + // Reset the AST + node->reset(); + + // Check if we need to re-analyze if (!secondRun) { secondRun = true; return true; @@ -201,7 +206,7 @@ std::any GeneratorVisitor::visitMainFctDef(MainFctDefNode *node) { if (cliOptions.generateDebugInfo) { // Get arg types std::vector> argTypes; - for (auto &argName : argNames) { + for (const auto &argName : argNames) { SymbolTableEntry *argEntry = currentScope->lookup(argName); assert(argEntry != nullptr); argTypes.emplace_back(argEntry->getType(), true); @@ -214,7 +219,8 @@ std::any GeneratorVisitor::visitMainFctDef(MainFctDefNode *node) { } // Create entry block - llvm::BasicBlock *bEntry = allocaInsertBlock = llvm::BasicBlock::Create(*context, "entry"); + std::string codeLine = node->codeLoc.toPrettyLine(); + llvm::BasicBlock *bEntry = allocaInsertBlock = llvm::BasicBlock::Create(*context, "entry." + codeLine); fct->getBasicBlockList().push_back(bEntry); moveInsertPointToBlock(bEntry); allocaInsertInst = nullptr; @@ -223,12 +229,11 @@ std::any GeneratorVisitor::visitMainFctDef(MainFctDefNode *node) { for (auto &arg : fct->args()) { unsigned argNo = arg.getArgNo(); std::string argName = argNames[argNo]; - llvm::Type *argType = fct->getFunctionType()->getParamType(argNo); + llvm::Type *argType = fctType->getParamType(argNo); llvm::Value *memAddress = insertAlloca(argType, argName); SymbolTableEntry *argSymbol = currentScope->lookup(argName); assert(argSymbol != nullptr); argSymbol->updateAddress(memAddress); - argSymbol->updateLLVMType(argType); builder->CreateStore(&arg, memAddress); } @@ -237,7 +242,6 @@ std::any GeneratorVisitor::visitMainFctDef(MainFctDefNode *node) { SymbolTableEntry *returnSymbol = currentScope->lookup(RETURN_VARIABLE_NAME); assert(returnSymbol != nullptr); returnSymbol->updateAddress(memAddress); - returnSymbol->updateLLVMType(returnType); builder->CreateStore(builder->getInt32(0), returnSymbol->getAddress()); // Reset stack state @@ -252,7 +256,7 @@ std::any GeneratorVisitor::visitMainFctDef(MainFctDefNode *node) { if (!varsToDestruct.empty()) { llvm::BasicBlock *predecessor = builder->GetInsertBlock(); // Generate cleanup block - llvm::BasicBlock *bCleanup = llvm::BasicBlock::Create(*context, "cleanup"); + llvm::BasicBlock *bCleanup = llvm::BasicBlock::Create(*context, "cleanup." + codeLine); moveInsertPointToBlock(bCleanup); // Generate cleanup instructions (e.g. dtor calls) @@ -276,7 +280,7 @@ std::any GeneratorVisitor::visitMainFctDef(MainFctDefNode *node) { // Create return stmt llvm::Value *result = returnSymbol->getAddress(); - builder->CreateRet(builder->CreateLoad(result->getType()->getPointerElementType(), result)); + builder->CreateRet(builder->CreateLoad(fct->getReturnType(), result)); } // Conclude debug information @@ -312,6 +316,9 @@ std::any GeneratorVisitor::visitFctDef(FctDefNode *node) { // Get all substantiated function which result from this function declaration std::map *manifestations = accessScope->getFunctionManifestations(node->codeLoc); + // Set the symbolTypeIndex to 0 + node->symbolTypeIndex = 0; + if (manifestations) { for (const auto &[mangledName, spiceFunc] : *manifestations) { // Check if the function is substantiated @@ -329,10 +336,10 @@ std::any GeneratorVisitor::visitFctDef(FctDefNode *node) { std::string structSignature = Struct::getSignature(spiceFunc.getThisType().getBaseType().getSubType(), spiceFunc.getThisType().getBaseType().getTemplateTypes()); // Get the LLVM type of the struct symbol - SymbolTableEntry *thisEntry = currentScope->lookup(structSignature); - assert(thisEntry); + SymbolType thisSymbolType = spiceFunc.getThisType(); argNames.push_back(THIS_VARIABLE_NAME); - argTypes.push_back(thisEntry->getLLVMType()->getPointerTo()); + llvm::Type *thisType = thisSymbolType.toLLVMType(*context, accessScope)->getPointerTo(); + argTypes.push_back(thisType); // Change scope to struct currentScope = currentScope->lookupTable(STRUCT_SCOPE_PREFIX + structSignature); assert(currentScope); @@ -385,7 +392,8 @@ std::any GeneratorVisitor::visitFctDef(FctDefNode *node) { generateFunctionDebugInfo(fct, &spiceFunc); // Create entry block - llvm::BasicBlock *bEntry = allocaInsertBlock = llvm::BasicBlock::Create(*context, "entry"); + std::string codeLine = node->codeLoc.toPrettyLine(); + llvm::BasicBlock *bEntry = allocaInsertBlock = llvm::BasicBlock::Create(*context, "entry." + codeLine); allocaInsertInst = nullptr; fct->getBasicBlockList().push_back(bEntry); moveInsertPointToBlock(bEntry); @@ -394,12 +402,11 @@ std::any GeneratorVisitor::visitFctDef(FctDefNode *node) { for (auto &arg : fct->args()) { unsigned int argNo = arg.getArgNo(); std::string argName = argNames[argNo]; - llvm::Type *argType = fct->getFunctionType()->getParamType(argNo); + llvm::Type *argType = fctType->getParamType(argNo); llvm::Value *memAddress = insertAlloca(argType, argName); SymbolTableEntry *argEntry = currentScope->lookup(argName); assert(argEntry != nullptr); argEntry->updateAddress(memAddress); - argEntry->updateLLVMType(argType); builder->CreateStore(&arg, memAddress); } @@ -414,7 +421,6 @@ std::any GeneratorVisitor::visitFctDef(FctDefNode *node) { SymbolTableEntry *returnSymbol = currentScope->lookup(RETURN_VARIABLE_NAME); assert(returnSymbol != nullptr); returnSymbol->updateAddress(returnMemAddress); - returnSymbol->updateLLVMType(returnType); // Reset stack state stackState = nullptr; @@ -428,7 +434,7 @@ std::any GeneratorVisitor::visitFctDef(FctDefNode *node) { if (!varsToDestruct.empty()) { llvm::BasicBlock *predecessor = builder->GetInsertBlock(); // Generate cleanup block - llvm::BasicBlock *bCleanup = llvm::BasicBlock::Create(*context, "cleanup"); + llvm::BasicBlock *bCleanup = llvm::BasicBlock::Create(*context, "cleanup." + codeLine); moveInsertPointToBlock(bCleanup); // Generate cleanup instructions (e.g. dtor calls) @@ -451,7 +457,7 @@ std::any GeneratorVisitor::visitFctDef(FctDefNode *node) { builder->CreateCall(retrieveStackRestoreFct(), {stackState}); // Create return stmt llvm::Value *result = returnSymbol->getAddress(); - builder->CreateRet(builder->CreateLoad(result->getType()->getPointerElementType(), result)); + builder->CreateRet(builder->CreateLoad(fct->getReturnType(), result)); } // Conclude debug information @@ -475,6 +481,9 @@ std::any GeneratorVisitor::visitFctDef(FctDefNode *node) { currentScope = currentScope->getParent(); assert(currentScope); } + + // Increase the symbolTypeIndex + node->symbolTypeIndex++; } } return nullptr; @@ -493,6 +502,9 @@ std::any GeneratorVisitor::visitProcDef(ProcDefNode *node) { // Get all substantiated function which result from this function declaration std::map *manifestations = accessScope->getFunctionManifestations(node->codeLoc); + // Set the symbolTypeIndex to 0 + node->symbolTypeIndex = 0; + if (manifestations) { for (const auto &[mangledName, spiceProc] : *manifestations) { // Check if the function is substantiated @@ -510,10 +522,9 @@ std::any GeneratorVisitor::visitProcDef(ProcDefNode *node) { std::string structSignature = Struct::getSignature(spiceProc.getThisType().getBaseType().getSubType(), spiceProc.getThisType().getBaseType().getTemplateTypes()); // Get the LLVM type of the struct symbol - SymbolTableEntry *thisEntry = currentScope->lookup(structSignature); - assert(thisEntry); argNames.push_back(THIS_VARIABLE_NAME); - argTypes.push_back(thisEntry->getLLVMType()->getPointerTo()); + llvm::Type *thisType = spiceProc.getThisType().toLLVMType(*context, accessScope)->getPointerTo(); + argTypes.push_back(thisType); // Change scope to struct currentScope = currentScope->lookupTable(STRUCT_SCOPE_PREFIX + structSignature); assert(currentScope); @@ -563,7 +574,8 @@ std::any GeneratorVisitor::visitProcDef(ProcDefNode *node) { generateFunctionDebugInfo(proc, &spiceProc); // Create entry block - llvm::BasicBlock *bEntry = allocaInsertBlock = llvm::BasicBlock::Create(*context, "entry"); + std::string codeLine = node->codeLoc.toPrettyLine(); + llvm::BasicBlock *bEntry = allocaInsertBlock = llvm::BasicBlock::Create(*context, "entry." + codeLine); allocaInsertInst = nullptr; proc->getBasicBlockList().push_back(bEntry); moveInsertPointToBlock(bEntry); @@ -572,12 +584,11 @@ std::any GeneratorVisitor::visitProcDef(ProcDefNode *node) { for (auto &arg : proc->args()) { unsigned int argNo = arg.getArgNo(); std::string argName = argNames[argNo]; - llvm::Type *argType = proc->getFunctionType()->getParamType(argNo); + llvm::Type *argType = procType->getParamType(argNo); llvm::Value *memAddress = insertAlloca(argType, argName); SymbolTableEntry *argSymbol = currentScope->lookup(argName); assert(argSymbol != nullptr); argSymbol->updateAddress(memAddress); - argSymbol->updateLLVMType(argType); builder->CreateStore(&arg, memAddress); } @@ -599,7 +610,7 @@ std::any GeneratorVisitor::visitProcDef(ProcDefNode *node) { if (!varsToDestruct.empty()) { llvm::BasicBlock *predecessor = builder->GetInsertBlock(); // Generate cleanup block - llvm::BasicBlock *bCleanup = llvm::BasicBlock::Create(*context, "cleanup"); + llvm::BasicBlock *bCleanup = llvm::BasicBlock::Create(*context, "cleanup." + codeLine); moveInsertPointToBlock(bCleanup); // Generate cleanup instructions (e.g. dtor calls) @@ -645,6 +656,9 @@ std::any GeneratorVisitor::visitProcDef(ProcDefNode *node) { currentScope = currentScope->getParent(); assert(currentScope); } + + // Increase the symbolTypeIndex + node->symbolTypeIndex++; } } return nullptr; @@ -674,7 +688,7 @@ std::any GeneratorVisitor::visitStructDef(StructDefNode *node) { llvm::StructType *structType = llvm::StructType::create(*context, mangledName); SymbolTableEntry *structSymbol = currentScope->lookup(spiceStruct.getSignature()); assert(structSymbol); - structSymbol->updateLLVMType(structType); + structSymbol->setStructLLVMType(structType); // Collect concrete field types std::vector fieldTypes; @@ -713,7 +727,6 @@ std::any GeneratorVisitor::visitGlobalVarDef(GlobalVarDefNode *node) { // Create correctly signed LLVM type from the data type currentConstSigned = specifiers.isSigned(); auto varType = any_cast(visit(node->dataType())); - globalVarEntry->updateLLVMType(varType); // Create global variable llvm::Value *memAddress = module->getOrInsertGlobal(node->varName, varType); @@ -797,7 +810,7 @@ std::any GeneratorVisitor::visitThreadDef(ThreadDefNode *node) { std::vector argStructFieldPointers; for (const auto &capture : currentScope->getCaptures()) { argStructFieldNames.push_back(capture.first); - argStructFieldTypes.push_back(capture.second.getEntry()->getLLVMType()->getPointerTo()); + argStructFieldTypes.push_back(capture.second.getEntry()->getType().toLLVMType(*context, currentScope)->getPointerTo()); argStructFieldPointers.push_back(capture.second.getEntry()->getAddress()); } @@ -817,7 +830,8 @@ std::any GeneratorVisitor::visitThreadDef(ThreadDefNode *node) { // Create entry block for thread function llvm::BasicBlock *allocaInsertBlockBackup = allocaInsertBlock; llvm::Instruction *allocaInsertInstBackup = allocaInsertInst; - llvm::BasicBlock *bEntry = allocaInsertBlock = llvm::BasicBlock::Create(*context, "entry"); + std::string codeLine = node->codeLoc.toPrettyLine(); + llvm::BasicBlock *bEntry = allocaInsertBlock = llvm::BasicBlock::Create(*context, "thread.entry." + codeLine); allocaInsertInst = nullptr; threadFct->getBasicBlockList().push_back(bEntry); moveInsertPointToBlock(bEntry); @@ -825,12 +839,13 @@ std::any GeneratorVisitor::visitThreadDef(ThreadDefNode *node) { // Store function args llvm::Value *recArgStructPtr = builder->CreatePointerCast(threadFct->args().begin(), argStructTy->getPointerTo()); unsigned int i = 0; - for (const auto &capture : currentScope->getCaptures()) { + for (const auto &[name, capture] : currentScope->getCaptures()) { std::string argName = argStructFieldNames[i]; llvm::Value *memAddress = builder->CreateStructGEP(argStructTy, recArgStructPtr, i); - memAddress = builder->CreateLoad(memAddress->getType()->getPointerElementType(), memAddress); + llvm::Type *loadType = capture.getEntry()->getType().toLLVMType(*context, currentScope)->getPointerTo(); + memAddress = builder->CreateLoad(loadType, memAddress); // Push address to each capture to ensure that the address is valid and known to the inner function - capture.second.getEntry()->pushAddress(memAddress); + capture.getEntry()->pushAddress(memAddress); i++; } @@ -905,10 +920,11 @@ std::any GeneratorVisitor::visitForLoop(ForLoopNode *node) { emitSourceLocation(node); // Create blocks - llvm::BasicBlock *bCond = llvm::BasicBlock::Create(*context, "for.cond"); - llvm::BasicBlock *bInc = llvm::BasicBlock::Create(*context, "for.inc"); - llvm::BasicBlock *bLoop = llvm::BasicBlock::Create(*context, "for"); - llvm::BasicBlock *bEnd = llvm::BasicBlock::Create(*context, "for.end"); + std::string codeLine = node->codeLoc.toPrettyLine(); + llvm::BasicBlock *bCond = llvm::BasicBlock::Create(*context, "for.cond." + codeLine); + llvm::BasicBlock *bInc = llvm::BasicBlock::Create(*context, "for.inc." + codeLine); + llvm::BasicBlock *bLoop = llvm::BasicBlock::Create(*context, "for." + codeLine); + llvm::BasicBlock *bEnd = llvm::BasicBlock::Create(*context, "for.end." + codeLine); // Change scope currentScope = currentScope->getChild(node->getScopeId()); @@ -967,10 +983,11 @@ std::any GeneratorVisitor::visitForeachLoop(ForeachLoopNode *node) { emitSourceLocation(node); // Create blocks - llvm::BasicBlock *bCond = llvm::BasicBlock::Create(*context, "foreach.cond"); - llvm::BasicBlock *bInc = llvm::BasicBlock::Create(*context, "foreach.inc"); - llvm::BasicBlock *bLoop = llvm::BasicBlock::Create(*context, "foreach.loop"); - llvm::BasicBlock *bEnd = llvm::BasicBlock::Create(*context, "foreach.end"); + std::string codeLine = node->codeLoc.toPrettyLine(); + llvm::BasicBlock *bCond = llvm::BasicBlock::Create(*context, "foreach.cond." + codeLine); + llvm::BasicBlock *bInc = llvm::BasicBlock::Create(*context, "foreach.inc." + codeLine); + llvm::BasicBlock *bLoop = llvm::BasicBlock::Create(*context, "foreach.loop." + codeLine); + llvm::BasicBlock *bEnd = llvm::BasicBlock::Create(*context, "foreach.end." + codeLine); // Change scope currentScope = currentScope->getChild(node->getScopeId()); @@ -986,20 +1003,21 @@ std::any GeneratorVisitor::visitForeachLoop(ForeachLoopNode *node) { // Initialize loop variables llvm::Value *idxVarPtr; + llvm::Type *idxVarType; if (node->idxVarDecl()) { auto idxVarName = any_cast(visit(node->idxVarDecl())); SymbolTableEntry *idxVarEntry = currentScope->lookup(idxVarName); assert(idxVarEntry != nullptr); idxVarPtr = idxVarEntry->getAddress(); + idxVarType = idxVarEntry->getType().toLLVMType(*context, currentScope); } else { std::string indexVariableName = FOREACH_DEFAULT_IDX_VARIABLE_NAME; // Create local variable for - llvm::Type *indexVariableType = llvm::Type::getInt32Ty(*context); - idxVarPtr = insertAlloca(indexVariableType, indexVariableName); + idxVarType = llvm::Type::getInt32Ty(*context); + idxVarPtr = insertAlloca(idxVarType, indexVariableName); SymbolTableEntry *idxVarEntry = currentScope->lookup(indexVariableName); assert(idxVarEntry != nullptr); idxVarEntry->updateAddress(idxVarPtr); - idxVarEntry->updateLLVMType(indexVariableType); idxVarEntry->setUsed(); // Initialize variable with 0 builder->CreateStore(builder->getInt32(0), idxVarPtr); @@ -1011,7 +1029,9 @@ std::any GeneratorVisitor::visitForeachLoop(ForeachLoopNode *node) { // Do loop variable initialization llvm::Value *arrayValuePtr = resolveAddress(node->arrayAssign()); - llvm::Value *arrayValue = builder->CreateLoad(arrayValuePtr->getType()->getPointerElementType(), arrayValuePtr); + SymbolType arraySymbolType = node->arrayAssign()->getEvaluatedSymbolType(); + llvm::Type *arrayValueType = arraySymbolType.toLLVMType(*context, currentScope); + llvm::Value *arrayValue = builder->CreateLoad(arrayValueType, arrayValuePtr); llvm::Value *arraySizeValue = dynamicallySized ? arrayVarEntry->getType().getDynamicArraySize() : builder->getInt32(arrayValue->getType()->getArrayNumElements()); @@ -1020,17 +1040,19 @@ std::any GeneratorVisitor::visitForeachLoop(ForeachLoopNode *node) { arraySizeValue = builder->CreateSExtOrTrunc(arraySizeValue, builder->getInt32Ty()); // Load the first item into item variable - llvm::Value *index = builder->CreateLoad(idxVarPtr->getType()->getPointerElementType(), idxVarPtr); + llvm::Value *index = builder->CreateLoad(idxVarType, idxVarPtr); llvm::Value *itemPtr; llvm::Value *indices[2] = {builder->getInt32(0), index}; if (dynamicallySized) { - arrayValuePtr = builder->CreateLoad(arrayValuePtr->getType()->getPointerElementType(), arrayValuePtr); - itemPtr = builder->CreateInBoundsGEP(arrayValuePtr->getType()->getPointerElementType(), arrayValuePtr, index); + arrayValuePtr = builder->CreateLoad(arrayValueType, arrayValuePtr); + arrayValueType = arraySymbolType.getContainedTy().toLLVMType(*context, currentScope); + itemPtr = builder->CreateInBoundsGEP(arrayValueType, arrayValuePtr, index); } else { - itemPtr = builder->CreateInBoundsGEP(arrayValuePtr->getType()->getPointerElementType(), arrayValuePtr, indices); + itemPtr = builder->CreateInBoundsGEP(arrayValueType, arrayValuePtr, indices); } - llvm::Value *newItemValue = builder->CreateLoad(itemPtr->getType()->getPointerElementType(), itemPtr); + llvm::Type *itemPtrType = arraySymbolType.getContainedTy().toLLVMType(*context, currentScope); + llvm::Value *newItemValue = builder->CreateLoad(itemPtrType, itemPtr); builder->CreateStore(newItemValue, itemVarPtr); createBr(bLoop); @@ -1050,17 +1072,17 @@ std::any GeneratorVisitor::visitForeachLoop(ForeachLoopNode *node) { parentFct->getBasicBlockList().push_back(bInc); moveInsertPointToBlock(bInc); // Increment index variable - index = builder->CreateLoad(idxVarPtr->getType()->getPointerElementType(), idxVarPtr, "idx"); + index = builder->CreateLoad(idxVarType, idxVarPtr, "idx"); index = builder->CreateAdd(index, builder->getInt32(1), "idx.inc"); builder->CreateStore(index, idxVarPtr); // Load new item into item variable indices[1] = index; if (dynamicallySized) { - itemPtr = builder->CreateInBoundsGEP(arrayValuePtr->getType()->getPointerElementType(), arrayValuePtr, index); + itemPtr = builder->CreateInBoundsGEP(arrayValueType, arrayValuePtr, index); } else { - itemPtr = builder->CreateInBoundsGEP(arrayValuePtr->getType()->getPointerElementType(), arrayValuePtr, indices); + itemPtr = builder->CreateInBoundsGEP(arrayValueType, arrayValuePtr, indices); } - newItemValue = builder->CreateLoad(itemPtr->getType()->getPointerElementType(), itemPtr); + newItemValue = builder->CreateLoad(itemPtrType, itemPtr); builder->CreateStore(newItemValue, itemVarPtr); createBr(bCond); @@ -1068,7 +1090,7 @@ std::any GeneratorVisitor::visitForeachLoop(ForeachLoopNode *node) { parentFct->getBasicBlockList().push_back(bCond); moveInsertPointToBlock(bCond); // Check condition - index = builder->CreateLoad(idxVarPtr->getType()->getPointerElementType(), idxVarPtr); + index = builder->CreateLoad(idxVarType, idxVarPtr); llvm::Value *cond = builder->CreateICmpULT(index, arraySizeValue); createCondBr(cond, bLoop, bEnd); @@ -1094,9 +1116,10 @@ std::any GeneratorVisitor::visitWhileLoop(WhileLoopNode *node) { llvm::Function *parentFct = builder->GetInsertBlock()->getParent(); // Create blocks - llvm::BasicBlock *bCond = llvm::BasicBlock::Create(*context, "while.cond"); - llvm::BasicBlock *bLoop = llvm::BasicBlock::Create(*context, "while"); - llvm::BasicBlock *bEnd = llvm::BasicBlock::Create(*context, "while.end"); + std::string codeLine = node->codeLoc.toPrettyLine(); + llvm::BasicBlock *bCond = llvm::BasicBlock::Create(*context, "while.cond." + codeLine); + llvm::BasicBlock *bLoop = llvm::BasicBlock::Create(*context, "while." + codeLine); + llvm::BasicBlock *bEnd = llvm::BasicBlock::Create(*context, "while.end." + codeLine); // Change scope currentScope = currentScope->getChild(node->getScopeId()); @@ -1160,9 +1183,10 @@ std::any GeneratorVisitor::visitIfStmt(IfStmtNode *node) { llvm::Function *parentFct = builder->GetInsertBlock()->getParent(); // Create blocks - llvm::BasicBlock *bThen = llvm::BasicBlock::Create(*context, "if.then"); - llvm::BasicBlock *bElse = llvm::BasicBlock::Create(*context, "if.else"); - llvm::BasicBlock *bEnd = llvm::BasicBlock::Create(*context, "if.end"); + std::string codeLine = node->codeLoc.toPrettyLine(); + llvm::BasicBlock *bThen = llvm::BasicBlock::Create(*context, "if.then." + codeLine); + llvm::BasicBlock *bElse = llvm::BasicBlock::Create(*context, "if.else." + codeLine); + llvm::BasicBlock *bEnd = llvm::BasicBlock::Create(*context, "if.end." + codeLine); // Check if condition is fulfilled createCondBr(condValue, bThen, node->elseStmt() ? bElse : bEnd); @@ -1224,8 +1248,9 @@ std::any GeneratorVisitor::visitAssertStmt(AssertStmtNode *node) { llvm::Function *parentFct = builder->GetInsertBlock()->getParent(); // Create blocks - llvm::BasicBlock *bThen = llvm::BasicBlock::Create(*context, "if.then"); - llvm::BasicBlock *bEnd = llvm::BasicBlock::Create(*context, "if.end"); + std::string codeLine = node->codeLoc.toPrettyLine(); + llvm::BasicBlock *bThen = llvm::BasicBlock::Create(*context, "assert.then." + codeLine); + llvm::BasicBlock *bEnd = llvm::BasicBlock::Create(*context, "assert.end." + codeLine); // Check if condition is fulfilled createCondBr(condValue, bEnd, bThen); @@ -1265,7 +1290,6 @@ std::any GeneratorVisitor::visitDeclStmt(DeclStmtNode *node) { // Get data type llvm::Type *varType = lhsType = any_cast(visit(node->dataType())); - entry->updateLLVMType(varType); entry->updateType(currentSymbolType, true); // Restore var name @@ -1274,7 +1298,6 @@ std::any GeneratorVisitor::visitDeclStmt(DeclStmtNode *node) { llvm::Value *memAddress = nullptr; if (node->assignExpr()) { // Declaration with assignment memAddress = resolveAddress(node->assignExpr()); - assert(memAddress->getType()->getPointerElementType() == varType); // Generate debug info for local variable generateDeclDebugInfo(node->codeLoc, lhsVarName, memAddress); @@ -1286,7 +1309,7 @@ std::any GeneratorVisitor::visitDeclStmt(DeclStmtNode *node) { memAddress = insertAlloca(arrayValue->getType(), lhsVarName); builder->CreateStore(arrayValue, memAddress, entry->isVolatile()); } else { - llvm::Value *defaultValue = getDefaultValueForType(varType, entry->getType().getBaseType().getSubType()); + llvm::Value *defaultValue = getDefaultValueForSymbolType(currentSymbolType); memAddress = insertAlloca(varType, lhsVarName); // Generate debug info for local variable @@ -1318,14 +1341,17 @@ std::any GeneratorVisitor::visitReturnStmt(ReturnStmtNode *node) { // Check if a value is attached to the return statement llvm::Value *returnValuePtr = nullptr; + llvm::Type *returnValueType; if (node->assignExpr()) { assert(returnVarEntry != nullptr); // Set the expected type of the value lhsType = returnVarEntry->getType().toLLVMType(*context, currentScope); // Visit return value returnValuePtr = resolveAddress(node->assignExpr()); + returnValueType = node->assignExpr()->getEvaluatedSymbolType().toLLVMType(*context, currentScope); } else if (returnVarEntry != nullptr) { // Function. Procedures do not have a return variable returnValuePtr = returnVarEntry->getAddress(); + returnValueType = returnVarEntry->getType().toLLVMType(*context, currentScope); } // Insert destructor calls to variables, going out of scope @@ -1361,7 +1387,7 @@ std::any GeneratorVisitor::visitReturnStmt(ReturnStmtNode *node) { } // Return value - llvm::Value *returnValue = builder->CreateLoad(returnValuePtr->getType()->getPointerElementType(), returnValuePtr); + llvm::Value *returnValue = builder->CreateLoad(returnValueType, returnValuePtr); builder->CreateRet(returnValue); return returnValuePtr; } @@ -1397,16 +1423,18 @@ std::any GeneratorVisitor::visitPrintfCall(PrintfCallNode *node) { std::vector printfArgs; printfArgs.push_back(builder->CreateGlobalStringPtr(node->templatedString)); for (const auto &arg : node->assignExpr()) { + SymbolType argSymbolType = arg->getEvaluatedSymbolType(); + // Visit argument - auto argValPtr = resolveAddress(arg); + llvm::Value *argValPtr = resolveAddress(arg); + llvm::Type *targetType = argSymbolType.toLLVMType(*context, currentScope); llvm::Value *argVal; - if (argValPtr->getType()->getPointerElementType()->isArrayTy()) { // Convert array type to pointer type + if (argSymbolType.isArray()) { // Convert array type to pointer type llvm::Value *indices[2] = {builder->getInt32(0), builder->getInt32(0)}; - llvm::Type *targetType = argValPtr->getType()->getPointerElementType(); argVal = builder->CreateInBoundsGEP(targetType, argValPtr, indices); } else { - argVal = builder->CreateLoad(argValPtr->getType()->getPointerElementType(), argValPtr); + argVal = builder->CreateLoad(targetType, argValPtr); } // Cast all integer types to 32 bit @@ -1417,17 +1445,19 @@ std::any GeneratorVisitor::visitPrintfCall(PrintfCallNode *node) { printfArgs.push_back(argVal); } - return static_cast(builder->CreateCall(printfFct, printfArgs)); + + llvm::Value *returnValue = builder->CreateCall(printfFct, printfArgs); + return returnValue; } std::any GeneratorVisitor::visitSizeofCall(SizeofCallNode *node) { llvm::Type *type; - if (node->assignExpr()) { // Assign expression + if (node->isType) { // Size of type + type = any_cast(visit(node->dataType())); + } else { // Size of value // Visit the argument llvm::Value *value = resolveValue(node->assignExpr()); type = value->getType(); - } else { // Type - type = any_cast(visit(node->dataType())); } // Calculate size at compile-time unsigned int size = module->getDataLayout().getTypeSizeInBits(type); @@ -1499,13 +1529,15 @@ std::any GeneratorVisitor::visitJoinCall(JoinCallNode *node) { // Check if it is an id or an array of ids auto threadIdPtr = resolveAddress(assignExpr); assert(threadIdPtr != nullptr && threadIdPtr->getType()->isPointerTy()); - llvm::Type *threadIdPtrTy = threadIdPtr->getType()->getPointerElementType(); - if (threadIdPtr->getType()->getPointerElementType()->isArrayTy()) { // Array of ids + SymbolType threadIdSymbolType = assignExpr->getEvaluatedSymbolType(); + llvm::Type *threadIdPtrTy = threadIdSymbolType.toLLVMType(*context, currentScope); + if (threadIdPtrTy->isArrayTy()) { // Array of ids for (int i = 0; i < threadIdPtrTy->getArrayNumElements(); i++) { // Get thread id that has to be joined llvm::Value *indices[2] = {builder->getInt32(0), builder->getInt32(i)}; llvm::Value *threadIdAddr = builder->CreateGEP(threadIdPtrTy, threadIdPtr, indices); - llvm::Value *threadId = builder->CreateLoad(threadIdAddr->getType()->getPointerElementType(), threadIdAddr); + llvm::Type *threadIdType = threadIdSymbolType.getContainedTy().toLLVMType(*context, currentScope); + llvm::Value *threadId = builder->CreateLoad(threadIdType, threadIdAddr); // Create call to pthread_join llvm::Value *voidPtrPtrNull = llvm::Constant::getNullValue(llvm::Type::getInt8PtrTy(*context)->getPointerTo()); @@ -1545,14 +1577,15 @@ std::any GeneratorVisitor::visitAssignExpr(AssignExprNode *node) { // Get value of right side llvm::Value *rhs = resolveValue(node->rhs()); + SymbolType rhsTy = node->rhs()->getEvaluatedSymbolType(); // Visit the left side - auto lhsPtr = resolveAddress(node->lhs()); + llvm::Value *lhsPtr = resolveAddress(node->lhs()); + SymbolType lhsTy = node->lhs()->getEvaluatedSymbolType(); lhsVarName = currentVarName; // Take a look at the operator if (node->op == AssignExprNode::OP_ASSIGN) { // Simple assign - assert(rhs->getType() == lhsPtr->getType()->getPointerElementType()); builder->CreateStore(rhs, lhsPtr); } else { // Compound assign // Get symbol table entry @@ -1564,40 +1597,40 @@ std::any GeneratorVisitor::visitAssignExpr(AssignExprNode *node) { if (variableEntry->isGlobal()) { lhs = module->getNamedGlobal(lhsVarName); } else { - lhs = builder->CreateLoad(lhsPtr->getType()->getPointerElementType(), lhsPtr); + lhs = builder->CreateLoad(lhsTy.toLLVMType(*context, currentScope), lhsPtr); } // Decide what to do, based on the operator switch (node->op) { case AssignExprNode::OP_PLUS_EQUAL: - rhs = conversionsManager->getPlusEqualInst(lhs, rhs, node->codeLoc); + rhs = conversionsManager->getPlusEqualInst(lhs, rhs, lhsTy, rhsTy, currentScope, node->codeLoc); break; case AssignExprNode::OP_MINUS_EQUAL: - rhs = conversionsManager->getMinusEqualInst(lhs, rhs); + rhs = conversionsManager->getMinusEqualInst(lhs, rhs, lhsTy, rhsTy, currentScope); break; case AssignExprNode::OP_MUL_EQUAL: - rhs = conversionsManager->getMulEqualInst(lhs, rhs); + rhs = conversionsManager->getMulEqualInst(lhs, rhs, lhsTy, rhsTy); break; case AssignExprNode::OP_DIV_EQUAL: - rhs = conversionsManager->getDivEqualInst(lhs, rhs); + rhs = conversionsManager->getDivEqualInst(lhs, rhs, lhsTy, rhsTy); break; case AssignExprNode::OP_REM_EQUAL: - rhs = conversionsManager->getRemEqualInst(lhs, rhs); + rhs = conversionsManager->getRemEqualInst(lhs, rhs, lhsTy, rhsTy); break; case AssignExprNode::OP_SHL_EQUAL: - rhs = conversionsManager->getSHLEqualInst(lhs, rhs); + rhs = conversionsManager->getSHLEqualInst(lhs, rhs, lhsTy, rhsTy); break; case AssignExprNode::OP_SHR_EQUAL: - rhs = conversionsManager->getSHREqualInst(lhs, rhs); + rhs = conversionsManager->getSHREqualInst(lhs, rhs, lhsTy, rhsTy); break; case AssignExprNode::OP_AND_EQUAL: - rhs = conversionsManager->getAndEqualInst(lhs, rhs); + rhs = conversionsManager->getAndEqualInst(lhs, rhs, lhsTy, rhsTy); break; case AssignExprNode::OP_OR_EQUAL: - rhs = conversionsManager->getOrEqualInst(lhs, rhs); + rhs = conversionsManager->getOrEqualInst(lhs, rhs, lhsTy, rhsTy); break; case AssignExprNode::OP_XOR_EQUAL: - rhs = conversionsManager->getXorEqualInst(lhs, rhs); + rhs = conversionsManager->getXorEqualInst(lhs, rhs, lhsTy, rhsTy); break; default: throw std::runtime_error("Assign op fall-through"); @@ -1631,7 +1664,8 @@ std::any GeneratorVisitor::visitTernaryExpr(TernaryExprNode *node) { auto trueValuePtr = resolveAddress(node->operands()[1]); auto falseValuePtr = resolveAddress(node->operands()[2]); - llvm::Value *condition = builder->CreateLoad(conditionPtr->getType()->getPointerElementType(), conditionPtr); + llvm::Type *conditionType = node->operands().front()->getEvaluatedSymbolType().toLLVMType(*context, currentScope); + llvm::Value *condition = builder->CreateLoad(conditionType, conditionPtr); return builder->CreateSelect(condition, trueValuePtr, falseValuePtr); } return visit(node->operands().front()); @@ -1641,9 +1675,10 @@ std::any GeneratorVisitor::visitLogicalOrExpr(LogicalOrExprNode *node) { emitSourceLocation(node); if (node->operands().size() > 1) { + std::string codeLine = node->codeLoc.toPrettyLine(); // Prepare for short-circuiting std::pair incomingBlocks[node->operands().size()]; - llvm::BasicBlock *bEnd = llvm::BasicBlock::Create(*context, "lor.end"); + llvm::BasicBlock *bEnd = llvm::BasicBlock::Create(*context, "lor.end." + codeLine); llvm::Function *parentFunction = builder->GetInsertBlock()->getParent(); // Visit the first condition @@ -1652,7 +1687,7 @@ std::any GeneratorVisitor::visitLogicalOrExpr(LogicalOrExprNode *node) { // Prepare the blocks incomingBlocks[0] = {lhs, builder->GetInsertBlock()}; for (int i = 1; i < node->operands().size(); i++) { - llvm::BasicBlock *bb = llvm::BasicBlock::Create(*context, "lor." + std::to_string(i)); + llvm::BasicBlock *bb = llvm::BasicBlock::Create(*context, "lor." + std::to_string(i) + "." + codeLine); parentFunction->getBasicBlockList().push_back(bb); incomingBlocks[i] = {nullptr, bb}; } @@ -1690,9 +1725,10 @@ std::any GeneratorVisitor::visitLogicalAndExpr(LogicalAndExprNode *node) { emitSourceLocation(node); if (node->operands().size() > 1) { + std::string codeLine = node->codeLoc.toPrettyLine(); // Prepare for short-circuiting std::pair incomingBlocks[node->operands().size()]; - llvm::BasicBlock *bEnd = llvm::BasicBlock::Create(*context, "land.end"); + llvm::BasicBlock *bEnd = llvm::BasicBlock::Create(*context, "land.end." + codeLine); llvm::Function *parentFunction = builder->GetInsertBlock()->getParent(); // Visit the first condition @@ -1701,7 +1737,7 @@ std::any GeneratorVisitor::visitLogicalAndExpr(LogicalAndExprNode *node) { // Prepare the blocks incomingBlocks[0] = {lhs, builder->GetInsertBlock()}; for (int i = 1; i < node->operands().size(); i++) { - llvm::BasicBlock *bb = llvm::BasicBlock::Create(*context, "land." + std::to_string(i)); + llvm::BasicBlock *bb = llvm::BasicBlock::Create(*context, "land." + std::to_string(i) + "." + codeLine); parentFunction->getBasicBlockList().push_back(bb); incomingBlocks[i] = {nullptr, bb}; } @@ -1739,10 +1775,13 @@ std::any GeneratorVisitor::visitBitwiseOrExpr(BitwiseOrExprNode *node) { emitSourceLocation(node); if (node->operands().size() > 1) { - llvm::Value *lhs = resolveValue(node->operands().front()); + BitwiseXorExprNode *lhsOperand = node->operands().front(); + llvm::Value *lhs = resolveValue(lhsOperand); for (int i = 1; i < node->operands().size(); i++) { - llvm::Value *rhs = resolveValue(node->operands()[i]); - lhs = conversionsManager->getBitwiseOrInst(lhs, rhs); + BitwiseXorExprNode *rhsOperand = node->operands()[i]; + llvm::Value *rhs = resolveValue(rhsOperand); + lhs = conversionsManager->getBitwiseOrInst(lhs, rhs, lhsOperand->getEvaluatedSymbolType(), + rhsOperand->getEvaluatedSymbolType()); } llvm::Value *resultPtr = insertAlloca(lhs->getType()); builder->CreateStore(lhs, resultPtr); @@ -1755,10 +1794,13 @@ std::any GeneratorVisitor::visitBitwiseXorExpr(BitwiseXorExprNode *node) { emitSourceLocation(node); if (node->operands().size() > 1) { - llvm::Value *lhs = resolveValue(node->operands().front()); + BitwiseAndExprNode *lhsOperand = node->operands().front(); + llvm::Value *lhs = resolveValue(lhsOperand); for (int i = 1; i < node->operands().size(); i++) { - llvm::Value *rhs = resolveValue(node->operands()[i]); - lhs = conversionsManager->getBitwiseXorInst(lhs, rhs); + BitwiseAndExprNode *rhsOperand = node->operands()[i]; + llvm::Value *rhs = resolveValue(rhsOperand); + lhs = conversionsManager->getBitwiseXorInst(lhs, rhs, lhsOperand->getEvaluatedSymbolType(), + rhsOperand->getEvaluatedSymbolType()); } llvm::Value *resultPtr = insertAlloca(lhs->getType()); builder->CreateStore(lhs, resultPtr); @@ -1771,10 +1813,13 @@ std::any GeneratorVisitor::visitBitwiseAndExpr(BitwiseAndExprNode *node) { emitSourceLocation(node); if (node->operands().size() > 1) { - llvm::Value *lhs = resolveValue(node->operands().front()); + EqualityExprNode *lhsOperand = node->operands().front(); + llvm::Value *lhs = resolveValue(lhsOperand); for (int i = 1; i < node->operands().size(); i++) { - llvm::Value *rhs = resolveValue(node->operands()[i]); - lhs = conversionsManager->getBitwiseAndInst(lhs, rhs); + EqualityExprNode *rhsOperand = node->operands()[i]; + llvm::Value *rhs = resolveValue(rhsOperand); + lhs = conversionsManager->getBitwiseAndInst(lhs, rhs, lhsOperand->getEvaluatedSymbolType(), + rhsOperand->getEvaluatedSymbolType()); } llvm::Value *resultPtr = insertAlloca(lhs->getType()); builder->CreateStore(lhs, resultPtr); @@ -1787,16 +1832,21 @@ std::any GeneratorVisitor::visitEqualityExpr(EqualityExprNode *node) { emitSourceLocation(node); if (node->operands().size() > 1) { - llvm::Value *lhs = resolveValue(node->operands()[0]); - llvm::Value *rhs = resolveValue(node->operands()[1]); + RelationalExprNode *lhsOperand = node->operands()[0]; + SymbolType lhsSymbolType = lhsOperand->getEvaluatedSymbolType(); + llvm::Value *lhs = resolveValue(lhsOperand); + + RelationalExprNode *rhsOperand = node->operands()[1]; + SymbolType rhsSymbolType = rhsOperand->getEvaluatedSymbolType(); + llvm::Value *rhs = resolveValue(rhsOperand); llvm::Value *result; switch (node->op) { case EqualityExprNode::OP_EQUAL: - result = conversionsManager->getEqualInst(lhs, rhs, node->codeLoc); + result = conversionsManager->getEqualInst(lhs, rhs, lhsSymbolType, rhsSymbolType, node->codeLoc); break; case EqualityExprNode::OP_NOT_EQUAL: - result = conversionsManager->getNotEqualInst(lhs, rhs, node->codeLoc); + result = conversionsManager->getNotEqualInst(lhs, rhs, lhsSymbolType, rhsSymbolType, node->codeLoc); break; default: throw std::runtime_error("Equality expr fall-through"); @@ -1812,22 +1862,27 @@ std::any GeneratorVisitor::visitRelationalExpr(RelationalExprNode *node) { emitSourceLocation(node); if (node->operands().size() > 1) { - llvm::Value *lhs = resolveValue(node->operands()[0]); - llvm::Value *rhs = resolveValue(node->operands()[1]); + ShiftExprNode *lhsOperand = node->operands()[0]; + SymbolType lhsSymbolType = lhsOperand->getEvaluatedSymbolType(); + llvm::Value *lhs = resolveValue(lhsOperand); + + ShiftExprNode *rhsOperand = node->operands()[1]; + SymbolType rhsSymbolType = rhsOperand->getEvaluatedSymbolType(); + llvm::Value *rhs = resolveValue(rhsOperand); llvm::Value *result; switch (node->op) { case RelationalExprNode::OP_LESS: - result = conversionsManager->getLessInst(lhs, rhs); + result = conversionsManager->getLessInst(lhs, rhs, lhsSymbolType, rhsSymbolType); break; case RelationalExprNode::OP_GREATER: - result = conversionsManager->getGreaterInst(lhs, rhs); + result = conversionsManager->getGreaterInst(lhs, rhs, lhsSymbolType, rhsSymbolType); break; case RelationalExprNode::OP_LESS_EQUAL: - result = conversionsManager->getLessEqualInst(lhs, rhs); + result = conversionsManager->getLessEqualInst(lhs, rhs, lhsSymbolType, rhsSymbolType); break; case RelationalExprNode::OP_GREATER_EQUAL: - result = conversionsManager->getGreaterEqualInst(lhs, rhs); + result = conversionsManager->getGreaterEqualInst(lhs, rhs, lhsSymbolType, rhsSymbolType); break; default: throw std::runtime_error("Relational expr fall-through"); @@ -1844,16 +1899,21 @@ std::any GeneratorVisitor::visitShiftExpr(ShiftExprNode *node) { // Check if there is a shift operation attached if (node->operands().size() > 1) { - llvm::Value *lhs = resolveValue(node->operands()[0]); - llvm::Value *rhs = resolveValue(node->operands()[1]); + AdditiveExprNode *lhsOperand = node->operands()[0]; + SymbolType lhsSymbolType = lhsOperand->getEvaluatedSymbolType(); + llvm::Value *lhs = resolveValue(lhsOperand); + + AdditiveExprNode *rhsOperand = node->operands()[1]; + SymbolType rhsSymbolType = rhsOperand->getEvaluatedSymbolType(); + llvm::Value *rhs = resolveValue(rhsOperand); llvm::Value *result; switch (node->op) { case ShiftExprNode::OP_SHIFT_LEFT: - result = conversionsManager->getShiftLeftInst(lhs, rhs); + result = conversionsManager->getShiftLeftInst(lhs, rhs, lhsSymbolType, rhsSymbolType); break; case ShiftExprNode::OP_SHIFT_RIGHT: - result = conversionsManager->getShiftRightInst(lhs, rhs); + result = conversionsManager->getShiftRightInst(lhs, rhs, lhsSymbolType, rhsSymbolType); break; default: throw std::runtime_error("Shift expr fall-through"); @@ -1870,26 +1930,30 @@ std::any GeneratorVisitor::visitAdditiveExpr(AdditiveExprNode *node) { // Check if at least one additive operator is applied if (!node->opQueue.empty()) { - llvm::Value *lhs = resolveValue(node->operands().front()); + MultiplicativeExprNode *lhsOperand = node->operands().front(); + SymbolType lhsSymbolType = lhsOperand->getEvaluatedSymbolType(); + llvm::Value *lhs = resolveValue(lhsOperand); - std::queue opQueue = node->opQueue; + auto opQueue = node->opQueue; size_t operandIndex = 1; while (!opQueue.empty()) { - MultiplicativeExprNode *operand = node->operands()[operandIndex++]; - assert(operand != nullptr); - llvm::Value *rhs = resolveValue(operand); + MultiplicativeExprNode *rhsOperand = node->operands()[operandIndex++]; + assert(rhsOperand != nullptr); + SymbolType rhsSymbolType = rhsOperand->getEvaluatedSymbolType(); + llvm::Value *rhs = resolveValue(rhsOperand); - switch (opQueue.front()) { + switch (opQueue.front().first) { case AdditiveExprNode::OP_PLUS: - lhs = conversionsManager->getPlusInst(lhs, rhs, node->codeLoc); + lhs = conversionsManager->getPlusInst(lhs, rhs, lhsSymbolType, rhsSymbolType, currentScope, node->codeLoc); break; case AdditiveExprNode::OP_MINUS: - lhs = conversionsManager->getMinusInst(lhs, rhs); + lhs = conversionsManager->getMinusInst(lhs, rhs, lhsSymbolType, rhsSymbolType, currentScope); break; default: throw std::runtime_error("Additive expr fall-through"); } + lhsSymbolType = opQueue.front().second; opQueue.pop(); } @@ -1905,29 +1969,33 @@ std::any GeneratorVisitor::visitMultiplicativeExpr(MultiplicativeExprNode *node) // Check if at least one multiplicative operator is applied if (!node->opQueue.empty()) { - llvm::Value *lhs = resolveValue(node->operands().front()); + CastExprNode *lhsOperand = node->operands().front(); + SymbolType lhsSymbolType = lhsOperand->getEvaluatedSymbolType(); + llvm::Value *lhs = resolveValue(lhsOperand); - std::queue opQueue = node->opQueue; + auto opQueue = node->opQueue; size_t operandIndex = 1; while (!opQueue.empty()) { - CastExprNode *operand = node->operands()[operandIndex++]; - assert(operand != nullptr); - llvm::Value *rhs = resolveValue(operand); + CastExprNode *rhsOperand = node->operands()[operandIndex++]; + assert(rhsOperand != nullptr); + SymbolType rhsSymbolType = rhsOperand->getEvaluatedSymbolType(); + llvm::Value *rhs = resolveValue(rhsOperand); - switch (opQueue.front()) { + switch (opQueue.front().first) { case MultiplicativeExprNode::OP_MUL: - lhs = conversionsManager->getMulInst(lhs, rhs, node->codeLoc); + lhs = conversionsManager->getMulInst(lhs, rhs, lhsSymbolType, rhsSymbolType, node->codeLoc); break; case MultiplicativeExprNode::OP_DIV: - lhs = conversionsManager->getDivInst(lhs, rhs); + lhs = conversionsManager->getDivInst(lhs, rhs, lhsSymbolType, rhsSymbolType); break; case MultiplicativeExprNode::OP_REM: - lhs = conversionsManager->getRemInst(lhs, rhs); + lhs = conversionsManager->getRemInst(lhs, rhs, lhsSymbolType, rhsSymbolType); break; default: throw std::runtime_error("Multiplicative expr fall-through"); } + lhsSymbolType = opQueue.front().second; opQueue.pop(); } @@ -1942,9 +2010,14 @@ std::any GeneratorVisitor::visitCastExpr(CastExprNode *node) { emitSourceLocation(node); if (node->isCasted) { // Cast operator is applied - auto dstTy = any_cast(visit(node->dataType())); - llvm::Value *rhs = resolveValue(node->prefixUnaryExpr()); - llvm::Value *result = conversionsManager->getCastInst(dstTy, rhs); + SymbolType lhsSymbolType = node->getEvaluatedSymbolType(); + + PrefixUnaryExprNode *rhsOperand = node->prefixUnaryExpr(); + SymbolType rhsSymbolType = rhsOperand->getEvaluatedSymbolType(); + llvm::Value *rhs = resolveValue(rhsOperand); + + llvm::Value *result = conversionsManager->getCastInst(rhs, lhsSymbolType, rhsSymbolType, currentScope); + llvm::Value *resultPtr = insertAlloca(result->getType()); builder->CreateStore(result, resultPtr); return resultPtr; @@ -1962,26 +2035,29 @@ std::any GeneratorVisitor::visitPrefixUnaryExpr(PrefixUnaryExprNode *node) { if (!node->opStack.empty()) { // Load the value - llvm::Value *lhsPtr = resolveAddress(node->postfixUnaryExpr()); + PostfixUnaryExprNode *lhsOperand = node->postfixUnaryExpr(); + SymbolType lhsSymbolType = lhsOperand->getEvaluatedSymbolType(); + llvm::Type *lhsTy = lhsSymbolType.toLLVMType(*context, currentScope); + llvm::Value *lhsPtr = resolveAddress(lhsOperand); llvm::Value *lhs = nullptr; bool isVolatile = false; bool storeValue = true; - std::stack opStack = node->opStack; + auto opStack = node->opStack; while (!opStack.empty()) { - switch (opStack.top()) { + switch (opStack.top().first) { case PrefixUnaryExprNode::OP_MINUS: { if (!lhs) - lhs = builder->CreateLoad(lhsPtr->getType()->getPointerElementType(), lhsPtr); - lhs = conversionsManager->getPrefixMinusInst(lhs); + lhs = builder->CreateLoad(lhsTy, lhsPtr); + lhs = conversionsManager->getPrefixMinusInst(lhs, lhsSymbolType); lhsPtr = insertAlloca(lhs->getType()); break; } case PrefixUnaryExprNode::OP_PLUS_PLUS: { if (!lhs) - lhs = builder->CreateLoad(lhsPtr->getType()->getPointerElementType(), lhsPtr); - lhs = conversionsManager->getPrefixPlusPlusInst(lhs); + lhs = builder->CreateLoad(lhsTy, lhsPtr); + lhs = conversionsManager->getPrefixPlusPlusInst(lhs, lhsSymbolType); // Store the new value volatile SymbolTableEntry *lhsVarEntry = currentScope->lookup(currentVarName); @@ -1991,8 +2067,8 @@ std::any GeneratorVisitor::visitPrefixUnaryExpr(PrefixUnaryExprNode *node) { } case PrefixUnaryExprNode::OP_MINUS_MINUS: { if (!lhs) - lhs = builder->CreateLoad(lhsPtr->getType()->getPointerElementType(), lhsPtr); - lhs = conversionsManager->getPrefixMinusMinusInst(lhs); + lhs = builder->CreateLoad(lhsTy, lhsPtr); + lhs = conversionsManager->getPrefixMinusMinusInst(lhs, lhsSymbolType); // Store the new value volatile SymbolTableEntry *lhsVarEntry = currentScope->lookup(currentVarName); @@ -2002,24 +2078,27 @@ std::any GeneratorVisitor::visitPrefixUnaryExpr(PrefixUnaryExprNode *node) { } case PrefixUnaryExprNode::OP_NOT: { if (!lhs) - lhs = builder->CreateLoad(lhsPtr->getType()->getPointerElementType(), lhsPtr); - lhs = conversionsManager->getPrefixNotInst(lhs); + lhs = builder->CreateLoad(lhsTy, lhsPtr); + lhs = conversionsManager->getPrefixNotInst(lhs, lhsSymbolType); lhsPtr = insertAlloca(lhs->getType()); break; } case PrefixUnaryExprNode::OP_BITWISE_NOT: { if (!lhs) - lhs = builder->CreateLoad(lhsPtr->getType()->getPointerElementType(), lhsPtr); - lhs = conversionsManager->getPrefixBitwiseNotInst(lhs); + lhs = builder->CreateLoad(lhsTy, lhsPtr); + lhs = conversionsManager->getPrefixBitwiseNotInst(lhs, lhsSymbolType); lhsPtr = insertAlloca(lhs->getType()); break; } case PrefixUnaryExprNode::OP_INDIRECTION: { - if (!lhs) - lhs = builder->CreateLoad(lhsPtr->getType()->getPointerElementType(), lhsPtr); + if (!lhs) { + lhs = builder->CreateLoad(lhsTy, lhsPtr); + lhsSymbolType = lhsSymbolType.getContainedTy(); + lhsTy = lhsSymbolType.toLLVMType(*context, currentScope); + } // Indirect pointer lhsPtr = lhs; - lhs = builder->CreateLoad(lhs->getType()->getPointerElementType(), lhs); + lhs = builder->CreateLoad(lhsTy, lhs); break; } case PrefixUnaryExprNode::OP_ADDRESS_OF: { @@ -2034,6 +2113,8 @@ std::any GeneratorVisitor::visitPrefixUnaryExpr(PrefixUnaryExprNode *node) { throw std::runtime_error("PrefixUnary fall-through"); } + lhsSymbolType = opStack.top().second; + lhsTy = lhsSymbolType.toLLVMType(*context, currentScope); opStack.pop(); } @@ -2055,18 +2136,23 @@ std::any GeneratorVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { if (!node->opQueue.empty()) { // Retrieve the address and the value if required - llvm::Value *lhsPtr = resolveAddress(node->atomicExpr()); - llvm::Value *lhs = lhsPtr != nullptr ? builder->CreateLoad(lhsPtr->getType()->getPointerElementType(), lhsPtr) : nullptr; + AtomicExprNode *lhsOperand = node->atomicExpr(); + SymbolType lhsSymbolType = lhsOperand->getEvaluatedSymbolType(); + llvm::Type *lhsTy = lhsSymbolType.is(TY_IMPORT) ? nullptr : lhsSymbolType.toLLVMType(*context, currentScope); + llvm::Value *lhsPtr = resolveAddress(lhsOperand); + llvm::Value *lhs = lhsPtr != nullptr ? builder->CreateLoad(lhsTy, lhsPtr) : nullptr; size_t subscriptCounter = 0; size_t memberAccessCounter = 0; - std::queue opQueue = node->opQueue; // Copy to not modify the queue in the AST node + auto opQueue = node->opQueue; while (!opQueue.empty()) { - switch (opQueue.front()) { + switch (opQueue.front().first) { case PostfixUnaryExprNode::OP_SUBSCRIPT: { - if (!lhs) - lhs = builder->CreateLoad(lhsPtr->getType()->getPointerElementType(), lhsPtr); + if (!lhs) { + lhsTy = lhsSymbolType.toLLVMType(*context, currentScope); + lhs = builder->CreateLoad(lhsTy, lhsPtr); + } assert(lhs->getType()->isArrayTy() || lhs->getType()->isPointerTy()); @@ -2074,6 +2160,7 @@ std::any GeneratorVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { std::string currentVarNameBackup = currentVarName; ScopePath scopePathBackup = scopePath; llvm::Value *structAccessAddressBackup = structAccessAddress; + llvm::Type *structAccessTypeBackup = structAccessType; // Get the index value AssignExprNode *indexExpr = node->assignExpr()[subscriptCounter++]; @@ -2083,23 +2170,33 @@ std::any GeneratorVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { currentVarName = currentVarNameBackup; scopePath = scopePathBackup; structAccessAddress = structAccessAddressBackup; + structAccessType = structAccessTypeBackup; if (lhs->getType()->isArrayTy()) { + lhsTy = lhsSymbolType.toLLVMType(*context, currentScope); // Calculate address of array item llvm::Value *indices[2] = {builder->getInt32(0), indexValue}; - lhsPtr = builder->CreateInBoundsGEP(lhsPtr->getType()->getPointerElementType(), lhsPtr, indices); + lhsPtr = builder->CreateInBoundsGEP(lhsTy, lhsPtr, indices); + structAccessType = lhsSymbolType.getContainedTy().toLLVMType(*context, currentScope); } else { + lhsTy = lhsSymbolType.getContainedTy().toLLVMType(*context, currentScope); // Calculate address of pointer offset - lhsPtr = builder->CreateInBoundsGEP(lhs->getType()->getPointerElementType(), lhs, indexValue); + lhsPtr = builder->CreateInBoundsGEP(lhsTy, lhs, indexValue); + structAccessType = lhsTy; } + structAccessAddress = lhsPtr; lhs = nullptr; break; } case PostfixUnaryExprNode::OP_MEMBER_ACCESS: { // Auto de-reference pointer - while (lhsPtr && lhsPtr->getType()->getPointerElementType()->isPointerTy()) - lhsPtr = structAccessAddress = builder->CreateLoad(lhsPtr->getType()->getPointerElementType(), lhsPtr); + while (lhsPtr && lhsSymbolType.isPointer()) { + lhsTy = lhsSymbolType.toLLVMType(*context, currentScope); + lhsPtr = structAccessAddress = builder->CreateLoad(lhsTy, lhsPtr); + lhsSymbolType = lhsSymbolType.getContainedTy(); + structAccessType = lhsSymbolType.toLLVMType(*context, currentScope); + } // Visit identifier after the dot PostfixUnaryExprNode *rhs = node->postfixUnaryExpr()[memberAccessCounter++]; @@ -2110,11 +2207,11 @@ std::any GeneratorVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { } case PostfixUnaryExprNode::OP_PLUS_PLUS: { if (!lhs) - lhs = builder->CreateLoad(lhsPtr->getType()->getPointerElementType(), lhsPtr); + lhs = builder->CreateLoad(lhsTy, lhsPtr); // Get the lhs variable entry SymbolTableEntry *lhsVarEntry = currentScope->lookup(currentVarName); // Save the new value to the old pointer - llvm::Value *newLhsValue = conversionsManager->getPostfixPlusPlusInst(lhs); + llvm::Value *newLhsValue = conversionsManager->getPostfixPlusPlusInst(lhs, lhsSymbolType); builder->CreateStore(newLhsValue, lhsPtr, lhsVarEntry && lhsVarEntry->isVolatile()); // Allocate new space and continue working with the new memory slot lhsPtr = insertAlloca(lhs->getType()); @@ -2122,11 +2219,11 @@ std::any GeneratorVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { } case PostfixUnaryExprNode::OP_MINUS_MINUS: { if (!lhs) - lhs = builder->CreateLoad(lhsPtr->getType()->getPointerElementType(), lhsPtr); + lhs = builder->CreateLoad(lhsTy, lhsPtr); // Get the lhs variable entry SymbolTableEntry *lhsVarEntry = currentScope->lookup(currentVarName); // Save the new value to the old pointer - llvm::Value *newLhsValue = conversionsManager->getPostfixMinusMinusInst(lhs); + llvm::Value *newLhsValue = conversionsManager->getPostfixMinusMinusInst(lhs, lhsSymbolType); builder->CreateStore(newLhsValue, lhsPtr, lhsVarEntry && lhsVarEntry->isVolatile()); // Allocate new space and continue working with the new memory slot lhsPtr = insertAlloca(lhs->getType()); @@ -2135,6 +2232,8 @@ std::any GeneratorVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { default: throw std::runtime_error("PostfixUnary fall-through"); } + + lhsSymbolType = opQueue.front().second; opQueue.pop(); } @@ -2186,28 +2285,7 @@ std::any GeneratorVisitor::visitAtomicExpr(AtomicExprNode *node) { return entry->getAddress(); } - // Struct without pointer - if (entry->getType().is(TY_STRUCT)) { - // Retrieve struct scope - SymbolType entryType = entry->getType(); - std::string structSignature = Struct::getSignature(entryType.getSubType(), entryType.getTemplateTypes()); - SymbolTable *structScope = accessScope->lookupTable(STRUCT_SCOPE_PREFIX + structSignature); - assert(structScope != nullptr); - scopePath.pushFragment(node->identifier, structScope); - - if (structAccessAddress == nullptr) { - // Initialize struct resolution - return structAccessAddress = entry->getAddress(); - } else { - // Add field index to indices - unsigned int fieldIndex = entry->getOrderIndex(); - llvm::Value *indices[2] = {builder->getInt32(0), builder->getInt32(fieldIndex)}; - return structAccessAddress = builder->CreateInBoundsGEP(structAccessAddress->getType()->getPointerElementType(), - structAccessAddress, indices); - } - } - - // Struct* or Struct** or ... + // Struct or Struct* or Struct** or ... if (entry->getType().isBaseType(TY_STRUCT)) { // Retrieve struct scope SymbolType entryBaseType = entry->getType().getBaseType(); @@ -2218,13 +2296,16 @@ std::any GeneratorVisitor::visitAtomicExpr(AtomicExprNode *node) { if (structAccessAddress == nullptr) { // Auto de-referencing is done by the dot operator + structAccessType = node->getEvaluatedSymbolType().toLLVMType(*context, accessScope); return structAccessAddress = entry->getAddress(); } else { unsigned int fieldIndex = entry->getOrderIndex(); llvm::Value *indices[2] = {builder->getInt32(0), builder->getInt32(fieldIndex)}; + SymbolTableEntry *structEntry = accessScope->lookup(entry->getType().getName()); // Auto de-referencing is done by the dot operator - return structAccessAddress = builder->CreateInBoundsGEP(structAccessAddress->getType()->getPointerElementType(), - structAccessAddress, indices); + llvm::Value *address = builder->CreateInBoundsGEP(structAccessType, structAccessAddress, indices); + structAccessType = node->getEvaluatedSymbolType().toLLVMType(*context, accessScope); + return structAccessAddress = address; } } @@ -2235,10 +2316,10 @@ std::any GeneratorVisitor::visitAtomicExpr(AtomicExprNode *node) { llvm::Value *indices[2] = {builder->getInt32(0), builder->getInt32(fieldIndex)}; // Calculate field address - llvm::Value *fieldAddress = - builder->CreateInBoundsGEP(structAccessAddress->getType()->getPointerElementType(), structAccessAddress, indices); + llvm::Value *fieldAddress = builder->CreateInBoundsGEP(structAccessType, structAccessAddress, indices); structAccessAddress = nullptr; + structAccessType = nullptr; return fieldAddress; } @@ -2403,6 +2484,7 @@ std::any GeneratorVisitor::visitFunctionCall(FunctionCallNode *node) { // Load the 'this' value if it is a pointer llvm::Value *thisValuePtr = nullptr; + SymbolType thisSymbolType; for (unsigned int i = 0; i < node->functionNameFragments.size(); i++) { std::string identifier = node->functionNameFragments[i]; SymbolTableEntry *symbolEntry = accessScope->lookup(identifier); @@ -2439,6 +2521,7 @@ std::any GeneratorVisitor::visitFunctionCall(FunctionCallNode *node) { } else { continue; } + thisSymbolType = symbolEntry->getType(); std::string tableName = symbolEntry->getType().is(TY_IMPORT) ? identifier : STRUCT_SCOPE_PREFIX + symbolEntry->getType().getBaseType().getName(); @@ -2448,8 +2531,10 @@ std::any GeneratorVisitor::visitFunctionCall(FunctionCallNode *node) { } // Load this value ptr if necessary - if (isMethod && thisValuePtr->getType()->getPointerElementType()->isPointerTy()) - thisValuePtr = builder->CreateLoad(thisValuePtr->getType()->getPointerElementType(), thisValuePtr); + while (isMethod && thisSymbolType.isPointer()) { + thisValuePtr = builder->CreateLoad(thisSymbolType.toLLVMType(*context, accessScope), thisValuePtr); + thisSymbolType = thisSymbolType.getContainedTy(); + } // Check if function exists in the current module bool functionFound = false; @@ -2474,8 +2559,8 @@ std::any GeneratorVisitor::visitFunctionCall(FunctionCallNode *node) { std::vector argTypes; if (isMethod) - argTypes.push_back(thisValuePtr->getType()); - for (auto &argSymbolType : argSymbolTypes) + argTypes.push_back(thisSymbolType.toLLVMType(*context, accessScope)->getPointerTo()); + for (const auto &argSymbolType : argSymbolTypes) argTypes.push_back(argSymbolType.toLLVMType(*context, accessScope)); llvm::FunctionType *fctType = llvm::FunctionType::get(returnType, argTypes, false); @@ -2497,13 +2582,15 @@ std::any GeneratorVisitor::visitFunctionCall(FunctionCallNode *node) { if (node->argLst()) { for (const auto &arg : node->argLst()->args()) { // Get expected arg type + SymbolType expectedArgSymbolType = spiceFunc->getArgTypes()[isMethod ? argIndex - 1 : argIndex]; llvm::Type *expectedArgType = fctType->getParamType(argIndex); // Get the actual arg value - auto actualArgPtr = resolveAddress(arg); - if (!compareLLVMTypes(actualArgPtr->getType()->getPointerElementType(), expectedArgType)) { - argValues.push_back(doImplicitCast(actualArgPtr, expectedArgType)); + SymbolType actualArgSymbolType = arg->getEvaluatedSymbolType(); + llvm::Value *actualArgPtr = resolveAddress(arg); + if (actualArgSymbolType != expectedArgSymbolType) { + argValues.push_back(doImplicitCast(actualArgPtr, expectedArgType, actualArgSymbolType)); } else { - argValues.push_back(builder->CreateLoad(actualArgPtr->getType()->getPointerElementType(), actualArgPtr)); + argValues.push_back(builder->CreateLoad(actualArgSymbolType.toLLVMType(*context, accessScope), actualArgPtr)); } argIndex++; } @@ -2529,7 +2616,10 @@ std::any GeneratorVisitor::visitArrayInitialization(ArrayInitializationNode *nod // Get data type size_t actualItemCount = node->itemLst() ? node->itemLst()->args().size() : 0; size_t arraySize = lhsType != nullptr && lhsType->isArrayTy() ? lhsType->getArrayNumElements() : actualItemCount; - auto arrayType = lhsType; + SymbolType arraySymbolType = node->getEvaluatedSymbolType(); + SymbolType itemSymbolType = arraySymbolType.getContainedTy(); + llvm::Type *arrayType = arraySymbolType.toLLVMType(*context, currentScope); + llvm::Type *itemType = itemSymbolType.toLLVMType(*context, currentScope); bool dynamicallySized = false; if (!lhsVarName.empty()) { @@ -2554,30 +2644,11 @@ std::any GeneratorVisitor::visitArrayInitialization(ArrayInitializationNode *nod } } - llvm::Type *itemType = nullptr; - if (arrayType) { - // Check if array type matches the item type - if (arrayType->isArrayTy()) { // Array - assert(itemConstants.empty() || !itemConstants.front() || - arrayType->getArrayElementType() == itemConstants.front()->getType()); - itemType = arrayType->getArrayElementType(); - } else { // Pointer - assert(itemConstants.empty() || !itemConstants.front() || - arrayType->getPointerElementType() == itemConstants.front()->getType()); - itemType = arrayType->getPointerElementType(); - } - } else { - // Infer type of array from the item type - assert(!itemConstants.empty()); - itemType = itemConstants.front()->getType(); - arrayType = llvm::ArrayType::get(itemType, arraySize); - } - // Decide if the array can be defined globally if (allArgsHardcoded && !dynamicallySized && !itemType->isStructTy()) { // Global array is possible // Fill up the rest of the items with default values if (itemConstants.size() < arraySize) { - llvm::Constant *constantValue = getDefaultValueForType(itemType, ""); // ToDo: Fill empty string + llvm::Constant *constantValue = getDefaultValueForSymbolType(itemSymbolType); for (size_t i = itemConstants.size(); i < arraySize; i++) itemConstants.push_back(constantValue); } @@ -2587,19 +2658,19 @@ std::any GeneratorVisitor::visitArrayInitialization(ArrayInitializationNode *nod return createGlobalArray(arrayType, itemConstants); } else { // Global array is not possible => fallback to individual indexing // Allocate array - llvm::Value *arrayAddress = nullptr; + llvm::Value *arrayAddress; if (dynamicallySized) { arrayAddress = allocateDynamicallySizedArray(itemType); - arrayType = arrayAddress->getType()->getPointerElementType(); + arrayType = arraySymbolType.getContainedTy().toLLVMType(*context, currentScope); } else { arrayAddress = insertAlloca(arrayType, lhsVarName); } // Insert all given values - llvm::Value *itemDefaultValue = getDefaultValueForType(itemType, ""); + llvm::Value *itemDefaultValue = getDefaultValueForSymbolType(itemSymbolType); for (size_t valueIndex = 0; valueIndex < arraySize; valueIndex++) { // Calculate item address - llvm::Value *itemAddress = nullptr; + llvm::Value *itemAddress; if (arrayType->isArrayTy()) { llvm::Value *indices[2] = {builder->getInt32(0), builder->getInt32(valueIndex)}; itemAddress = builder->CreateInBoundsGEP(arrayType, arrayAddress, indices); @@ -2648,7 +2719,7 @@ std::any GeneratorVisitor::visitStructInstantiation(StructInstantiationNode *nod // Check if the struct is defined SymbolTableEntry *structSymbol = structScope->lookup(spiceStruct->getSignature()); assert(structSymbol); - llvm::Type *structType = structSymbol->getLLVMType(); + llvm::Type *structType = structSymbol->getType().toLLVMType(*context, structScope); // Allocate space for the struct in memory llvm::Value *structAddress = insertAlloca(structType); @@ -2679,7 +2750,8 @@ std::any GeneratorVisitor::visitStructInstantiation(StructInstantiationNode *nod std::any GeneratorVisitor::visitDataType(DataTypeNode *node) { emitSourceLocation(node); - if (node->symbolType.is(TY_DYN)) { + SymbolType symbolType = node->getEvaluatedSymbolType(); + if (symbolType.is(TY_DYN)) { SymbolTableEntry *lhsVarEntry = currentScope->lookup(lhsVarName); assert(lhsVarEntry != nullptr); currentSymbolType = lhsVarEntry->getType(); @@ -2688,7 +2760,7 @@ std::any GeneratorVisitor::visitDataType(DataTypeNode *node) { if (!node->arraySizeExpr().empty()) { // Reset to base type because it will be rebuilt in the next step - node->symbolType = node->symbolType.getBaseType(); + symbolType = symbolType.getBaseType(); size_t assignExprCounter = 0; std::vector arraySizeExpr = node->arraySizeExpr(); @@ -2697,20 +2769,21 @@ std::any GeneratorVisitor::visitDataType(DataTypeNode *node) { DataTypeNode::TypeModifier typeModifier = tmQueue.front(); switch (typeModifier.modifierType) { case DataTypeNode::TY_POINTER: { - node->symbolType = node->symbolType.toPointer(err.get(), node->codeLoc); + symbolType = symbolType.toPointer(err.get(), node->codeLoc); break; } case DataTypeNode::TY_ARRAY: { if (!typeModifier.hasSize) { - node->symbolType = node->symbolType.toPointer(err.get(), node->codeLoc); + symbolType = symbolType.toPointer(err.get(), node->codeLoc); } else if (typeModifier.isSizeHardcoded) { - node->symbolType = node->symbolType.toArray(err.get(), node->codeLoc, typeModifier.hardcodedSize); + symbolType = symbolType.toArray(err.get(), node->codeLoc, typeModifier.hardcodedSize); } else { AssignExprNode *indexExpr = arraySizeExpr[assignExprCounter++]; assert(indexExpr != nullptr); - auto sizeValuePtr = std::any_cast(visit(indexExpr)); - dynamicArraySize = builder->CreateLoad(sizeValuePtr->getType()->getPointerElementType(), sizeValuePtr); - node->symbolType = node->symbolType.toPointer(err.get(), node->codeLoc, dynamicArraySize); + auto sizeValuePtr = any_cast(visit(indexExpr)); + llvm::Type *sizeType = indexExpr->getEvaluatedSymbolType().toLLVMType(*context, currentScope); + dynamicArraySize = builder->CreateLoad(sizeType, sizeValuePtr); + symbolType = symbolType.toPointer(err.get(), node->codeLoc, dynamicArraySize); } break; } @@ -2720,25 +2793,33 @@ std::any GeneratorVisitor::visitDataType(DataTypeNode *node) { tmQueue.pop(); } } - currentSymbolType = node->symbolType; + currentSymbolType = symbolType; return currentSymbolType.toLLVMType(*context, currentScope); } -llvm::Value *GeneratorVisitor::resolveValue(AstNode *node) { +llvm::Value *GeneratorVisitor::resolveValue(AstNode *node, SymbolTable *accessScope) { + if (!accessScope) + accessScope = currentScope; + std::any valueAny = visit(node); + if (!valueAny.has_value() && currentConstValue) return currentConstValue; + auto valueAddr = any_cast(valueAny); - return builder->CreateLoad(valueAddr->getType()->getPointerElementType(), valueAddr); + llvm::Type *dstType = node->getEvaluatedSymbolType().toLLVMType(*context, accessScope); + return builder->CreateLoad(dstType, valueAddr); } llvm::Value *GeneratorVisitor::resolveAddress(AstNode *node, bool storeVolatile) { std::any valueAny = visit(node); + if (!valueAny.has_value() && currentConstValue) { llvm::Value *valueAddr = insertAlloca(currentConstValue->getType(), lhsVarName); builder->CreateStore(currentConstValue, valueAddr, storeVolatile); return valueAddr; } + return any_cast(valueAny); } @@ -2899,74 +2980,78 @@ llvm::Function *GeneratorVisitor::retrieveStackRestoreFct() { return module->getFunction(stackRestoreFctName); } -llvm::Constant *GeneratorVisitor::getDefaultValueForType(llvm::Type *type, const std::string &subTypeName) { +llvm::Constant *GeneratorVisitor::getDefaultValueForSymbolType(const SymbolType &symbolType) { // Double - if (OpRuleConversionsManager::isDouble(type)) + if (symbolType.is(TY_DOUBLE)) return currentConstValue = llvm::ConstantFP::get(*context, llvm::APFloat(0.0)); // Int - if (OpRuleConversionsManager::isInt(type)) + if (symbolType.is(TY_INT)) return currentConstValue = builder->getInt32(0); // Short - if (OpRuleConversionsManager::isShort(type)) + if (symbolType.is(TY_SHORT)) return currentConstValue = builder->getInt16(0); // Long - if (OpRuleConversionsManager::isLong(type)) + if (symbolType.is(TY_LONG)) return currentConstValue = builder->getInt64(0); // Byte or char - if (OpRuleConversionsManager::isByteOrChar(type)) + if (symbolType.isOneOf({TY_BYTE, TY_CHAR})) return currentConstValue = builder->getInt8(0); // String - if (OpRuleConversionsManager::isString(type)) + if (symbolType.is(TY_STRING)) return currentConstValue = builder->CreateGlobalStringPtr("", "", 0, module.get()); // Bool - if (OpRuleConversionsManager::isBool(type)) + if (symbolType.is(TY_BOOL)) return currentConstValue = builder->getFalse(); // Pointer - if (type->isPointerTy()) - return currentConstValue = llvm::Constant::getNullValue(type); + if (symbolType.is(TY_PTR)) { + llvm::Type *baseType = symbolType.getContainedTy().toLLVMType(*context, currentScope); + return currentConstValue = llvm::Constant::getNullValue(baseType->getPointerTo()); + } // Array - if (type->isArrayTy()) { - size_t arraySize = type->getArrayNumElements(); + if (symbolType.is(TY_ARRAY)) { + size_t arraySize = symbolType.getArraySize(); - llvm::Type *itemType = type->getArrayElementType(); + llvm::Type *itemType = symbolType.getContainedTy().toLLVMType(*context, currentScope); llvm::ArrayType *arrayType = llvm::ArrayType::get(itemType, arraySize); - llvm::Constant *zeroItem = getDefaultValueForType(itemType, subTypeName); + llvm::Constant *zeroItem = getDefaultValueForSymbolType(symbolType.getContainedTy()); std::vector itemConstants(arraySize, zeroItem); return llvm::ConstantArray::get(arrayType, itemConstants); } // Struct - if (type->isStructTy()) { - assert(!subTypeName.empty()); - SymbolTable *childTable = currentScope->lookupTable(STRUCT_SCOPE_PREFIX + subTypeName); - assert(childTable != nullptr); + if (symbolType.is(TY_STRUCT)) { + // Get struct entry + std::string structName = symbolType.getSubType(); + SymbolTableEntry *structEntry = currentScope->lookup(structName); + assert(structEntry != nullptr); + + // Get struct table + SymbolTable *structScope = currentScope->lookupTable(STRUCT_SCOPE_PREFIX + structName); + assert(structScope != nullptr); - size_t fieldNumber = type->getStructNumElements(); - auto structType = static_cast(type); + size_t fieldCount = structScope->getFieldCount(); + auto structType = static_cast(structEntry->getType().toLLVMType(*context, structScope)); // Allocate space for the struct in memory llvm::Value *structAddress = insertAlloca(structType); - std::vector fieldTypes; std::vector fieldConstants; - fieldTypes.reserve(fieldNumber); - fieldConstants.reserve(fieldNumber); - for (int i = 0; i < fieldNumber; i++) { - SymbolTableEntry *fieldEntry = childTable->lookupByIndex(i); + fieldConstants.reserve(fieldCount); + for (int i = 0; i < fieldCount; i++) { + SymbolTableEntry *fieldEntry = structScope->lookupByIndex(i); assert(fieldEntry != nullptr); - llvm::Type *fieldType = type->getContainedType(i); - fieldEntry->updateLLVMType(fieldType); - fieldTypes.push_back(fieldType); - llvm::Constant *defaultFieldValue = getDefaultValueForType(fieldType, fieldEntry->getType().getBaseType().getSubType()); + + // Retrieve default field value + llvm::Constant *defaultFieldValue = getDefaultValueForSymbolType(fieldEntry->getType()); // Get pointer to struct element llvm::Value *fieldAddress = builder->CreateStructGEP(structType, structAddress, i); @@ -2992,46 +3077,35 @@ SymbolTableEntry *GeneratorVisitor::initExtGlobal(const std::string &globalName, return global; // Declare the global also in the current module and update the address of the symbol accordingly - llvm::Value *memAddress = module->getOrInsertGlobal(globalName, global->getLLVMType()); + llvm::Value *memAddress = module->getOrInsertGlobal(globalName, global->getType().toLLVMType(*context, currentScope)); global->updateAddress(memAddress); return global; } -bool GeneratorVisitor::compareLLVMTypes(llvm::Type *lhs, llvm::Type *rhs) { - if (lhs->getTypeID() != rhs->getTypeID()) - return false; - if (lhs->getTypeID() == llvm::Type::PointerTyID) - return compareLLVMTypes(lhs->getPointerElementType(), rhs->getPointerElementType()); - if (lhs->getTypeID() == llvm::Type::ArrayTyID) - return compareLLVMTypes(lhs->getArrayElementType(), rhs->getArrayElementType()); - return true; -} - -llvm::Value *GeneratorVisitor::doImplicitCast(llvm::Value *srcValue, llvm::Type *dstType) { +llvm::Value *GeneratorVisitor::doImplicitCast(llvm::Value *src, llvm::Type *dstTy, SymbolType srcType) { // Unpack the pointers until a pointer of another type is met unsigned int loadCounter = 0; - while (srcValue->getType()->getPointerElementType()->isPointerTy()) { - srcValue = builder->CreateLoad(srcValue->getType()->getPointerElementType(), srcValue); + while (srcType.isPointer()) { + src = builder->CreateLoad(srcType.toLLVMType(*context, currentScope), src); + srcType = srcType.getContainedTy(); loadCounter++; } // GEP or bit-cast - if (dstType->isPointerTy() && srcValue->getType()->getPointerElementType()->isArrayTy()) { + if (dstTy->isPointerTy() && srcType.isArray()) { llvm::Value *indices[2] = {builder->getInt32(0), builder->getInt32(0)}; - llvm::Type *actualArgType = srcValue->getType()->getPointerElementType(); - srcValue = builder->CreateInBoundsGEP(actualArgType, srcValue, indices); + src = builder->CreateInBoundsGEP(srcType.toLLVMType(*context, currentScope), src, indices); } else { - llvm::Type *actualArgType = srcValue->getType()->getPointerElementType(); - srcValue = builder->CreateLoad(actualArgType, srcValue); - srcValue = builder->CreateBitCast(srcValue, dstType); + src = builder->CreateLoad(srcType.toLLVMType(*context, currentScope), src); + src = builder->CreateBitCast(src, dstTy); } // Pack the pointers together again for (; loadCounter > 0; loadCounter--) { - llvm::Value *newActualArg = insertAlloca(srcValue->getType()); - builder->CreateStore(srcValue, newActualArg); - srcValue = newActualArg; + llvm::Value *newActualArg = insertAlloca(src->getType()); + builder->CreateStore(src, newActualArg); + src = newActualArg; } - return srcValue; + return src; } void GeneratorVisitor::initializeDIBuilder(const std::string &sourceFileName, const std::string &sourceFileDir) { @@ -3099,7 +3173,7 @@ void GeneratorVisitor::generateFunctionDebugInfo(llvm::Function *llvmFunction, c // Create function type std::vector argTypes; argTypes.push_back(getDITypeForSymbolType(spiceFunc->getReturnType())); // Add result type - for (auto &argType : spiceFunc->getArgTypes()) // Add arg types + for (const auto &argType : spiceFunc->getArgTypes()) // Add arg types argTypes.push_back(getDITypeForSymbolType(argType)); llvm::DISubroutineType *functionTy = diBuilder->createSubroutineType(diBuilder->getOrCreateTypeArray(argTypes)); @@ -3113,14 +3187,14 @@ void GeneratorVisitor::generateFunctionDebugInfo(llvm::Function *llvmFunction, c debugInfo.lexicalBlocks.push_back(subprogram); } -llvm::DIType *GeneratorVisitor::generateStructDebugInfo(llvm::StructType *llvmStructTy, const Struct *spiceStruct) const { +/*llvm::DIType *GeneratorVisitor::generateStructDebugInfo(llvm::StructType *llvmStructTy, const Struct *spiceStruct) const { llvm::DIFile *unit = diBuilder->createFile(debugInfo.compileUnit->getFilename(), debugInfo.compileUnit->getDirectory()); size_t lineNumber = spiceStruct->getDeclCodeLoc().line; size_t sizeInBits = module->getDataLayout().getTypeSizeInBits(llvmStructTy); llvm::DINode::DIFlags flags = spiceStruct->getSpecifiers().isPublic() ? llvm::DINode::FlagPublic : llvm::DINode::FlagPrivate; llvm::DINodeArray elements = diBuilder->getOrCreateArray({}); // ToDo: fill return diBuilder->createStructType(unit, spiceStruct->getName(), unit, lineNumber, sizeInBits, 0, flags, nullptr, elements); -} +}*/ void GeneratorVisitor::generateDeclDebugInfo(const CodeLoc &codeLoc, const std::string &varName, llvm::Value *address) { if (!cliOptions.generateDebugInfo) diff --git a/src/generator/GeneratorVisitor.h b/src/generator/GeneratorVisitor.h index 0a15866cd..18855b74f 100644 --- a/src/generator/GeneratorVisitor.h +++ b/src/generator/GeneratorVisitor.h @@ -130,6 +130,7 @@ class GeneratorVisitor : public AstVisitor { std::string lhsVarName; llvm::Type *lhsType = nullptr; llvm::Value *structAccessAddress = nullptr; + llvm::Type *structAccessType = nullptr; llvm::Value *dynamicArraySize = nullptr; llvm::Value *stackState = nullptr; bool secondRun = false; @@ -153,7 +154,7 @@ class GeneratorVisitor : public AstVisitor { } debugInfo; // Private methods - llvm::Value *resolveValue(AstNode *node); + llvm::Value *resolveValue(AstNode *node, SymbolTable *accessScope = nullptr); llvm::Value *resolveAddress(AstNode *node, bool storeVolatile = false); void moveInsertPointToBlock(llvm::BasicBlock *block); void createBr(llvm::BasicBlock *targetBlock); @@ -166,16 +167,15 @@ class GeneratorVisitor : public AstVisitor { llvm::Function *retrieveExitFct(); llvm::Function *retrieveStackSaveFct(); llvm::Function *retrieveStackRestoreFct(); - llvm::Constant *getDefaultValueForType(llvm::Type *type, const std::string &subTypeName); + llvm::Constant *getDefaultValueForSymbolType(const SymbolType &symbolType); SymbolTableEntry *initExtGlobal(const std::string &globalName, const std::string &fqGlobalName); - bool compareLLVMTypes(llvm::Type *lhs, llvm::Type *rhs); - llvm::Value *doImplicitCast(llvm::Value *lhs, llvm::Type *rhs); + llvm::Value *doImplicitCast(llvm::Value *src, llvm::Type *dstTy, SymbolType srcType); void initializeDIBuilder(const std::string &sourceFileName, const std::string &sourceFileDir); [[nodiscard]] llvm::DIType *getDITypeForSymbolType(const SymbolType &symbolType) const; void generateFunctionDebugInfo(llvm::Function *llvmFunction, const Function *spiceFunc); void generateDeclDebugInfo(const CodeLoc &codeLoc, const std::string &varName, llvm::Value *address); void generateAssignDebugInfo(const CodeLoc &codeLoc, const std::string &varName, llvm::Value *value); void emitSourceLocation(AstNode *ctx); - [[nodiscard]] llvm::DIType *generateStructDebugInfo(llvm::StructType *llvmStructTy, const Struct *spiceStruct) const; + //[[nodiscard]] llvm::DIType *generateStructDebugInfo(llvm::StructType *llvmStructTy, const Struct *spiceStruct) const; [[nodiscard]] llvm::OptimizationLevel getLLVMOptLevelFromSpiceOptLevel() const; }; \ No newline at end of file diff --git a/src/generator/OpRuleConversionsManager.cpp b/src/generator/OpRuleConversionsManager.cpp index e6d3146bc..9fd4e9eb4 100644 --- a/src/generator/OpRuleConversionsManager.cpp +++ b/src/generator/OpRuleConversionsManager.cpp @@ -7,396 +7,369 @@ #include #include -llvm::Value *OpRuleConversionsManager::getPlusEqualInst(llvm::Value *lhs, llvm::Value *rhs, const CodeLoc &codeLoc) { +llvm::Value *OpRuleConversionsManager::getPlusEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy, SymbolTable *accessScope, + const CodeLoc &codeLoc) { llvm::Type *lhsTy = lhs->getType(); - llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): return builder->CreateFAdd(lhs, rhs); - case COMB(P_TY_INT, P_TY_INT): + case COMB(TY_INT, TY_INT): return builder->CreateAdd(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): // fallthrough - case COMB(P_TY_INT, P_TY_LONG): { + case COMB(TY_INT, TY_SHORT): // fallthrough + case COMB(TY_INT, TY_LONG): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateAdd(lhs, rhsInt); } - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_SHORT, TY_INT): { llvm::Value *rhsShort = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateAdd(lhs, rhsShort); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateAdd(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): { + case COMB(TY_SHORT, TY_LONG): { llvm::Value *rhsShort = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateAdd(lhs, rhsShort); } - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateAdd(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): return builder->CreateAdd(lhs, rhs); - case COMB(P_TY_STRING, P_TY_BYTE_OR_CHAR): + case COMB(TY_STRING, TY_CHAR): // ToDo(@marcauberer): Insert call to appendChar in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '+=' operator for lhs=string and rhs=char yet"); - case COMB(P_TY_STRING, P_TY_STRING): + case COMB(TY_STRING, TY_STRING): // ToDo(@marcauberer): Insert call to concatStrings in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '+=' operator for lhs=string and rhs=string yet"); - case COMB(P_TY_PTR, P_TY_INT): // fallthrough - case COMB(P_TY_PTR, P_TY_SHORT): // fallthrough - case COMB(P_TY_PTR, P_TY_LONG): - return builder->CreateGEP(lhsTy->getPointerElementType(), lhs, rhs); + case COMB(TY_PTR, TY_INT): // fallthrough + case COMB(TY_PTR, TY_SHORT): // fallthrough + case COMB(TY_PTR, TY_LONG): + return builder->CreateGEP(lhsSTy.getContainedTy().toLLVMType(*context, accessScope), lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: +="); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getMinusEqualInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getMinusEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy, SymbolTable *accessScope) { llvm::Type *lhsTy = lhs->getType(); - llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): return builder->CreateFSub(lhs, rhs); - case COMB(P_TY_INT, P_TY_INT): + case COMB(TY_INT, TY_INT): return builder->CreateSub(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): // fallthrough - case COMB(P_TY_INT, P_TY_LONG): { + case COMB(TY_INT, TY_SHORT): // fallthrough + case COMB(TY_INT, TY_LONG): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSub(lhs, rhsInt); } - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_SHORT, TY_INT): { llvm::Value *rhsShort = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSub(lhs, rhsShort); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateSub(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): { + case COMB(TY_SHORT, TY_LONG): { llvm::Value *rhsShort = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSub(lhs, rhsShort); } - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSub(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): return builder->CreateSub(lhs, rhs); - case COMB(P_TY_PTR, P_TY_INT): // fallthrough - case COMB(P_TY_PTR, P_TY_SHORT): // fallthrough - case COMB(P_TY_PTR, P_TY_LONG): - return builder->CreateGEP(lhsTy->getPointerElementType(), lhs, rhs); + case COMB(TY_PTR, TY_INT): // fallthrough + case COMB(TY_PTR, TY_SHORT): // fallthrough + case COMB(TY_PTR, TY_LONG): + return builder->CreateGEP(lhsSTy.getContainedTy().toLLVMType(*context, accessScope), lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: -="); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getMulEqualInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getMulEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { llvm::Type *lhsTy = lhs->getType(); - llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): return builder->CreateFMul(lhs, rhs); - case COMB(P_TY_INT, P_TY_INT): + case COMB(TY_INT, TY_INT): return builder->CreateMul(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): // fallthrough - case COMB(P_TY_INT, P_TY_LONG): { + case COMB(TY_INT, TY_SHORT): // fallthrough + case COMB(TY_INT, TY_LONG): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateMul(lhs, rhsInt); } - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_SHORT, TY_INT): { llvm::Value *rhsShort = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateMul(lhs, rhsShort); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateMul(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): { + case COMB(TY_SHORT, TY_LONG): { llvm::Value *rhsShort = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateMul(lhs, rhsShort); } - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateMul(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): return builder->CreateMul(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: *="); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getDivEqualInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getDivEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { llvm::Type *lhsTy = lhs->getType(); - llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): return builder->CreateFDiv(lhs, rhs); - case COMB(P_TY_INT, P_TY_INT): + case COMB(TY_INT, TY_INT): return builder->CreateSDiv(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): // fallthrough - case COMB(P_TY_INT, P_TY_LONG): { + case COMB(TY_INT, TY_SHORT): // fallthrough + case COMB(TY_INT, TY_LONG): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSDiv(lhs, rhsInt); } - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_SHORT, TY_INT): { llvm::Value *rhsShort = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSDiv(lhs, rhsShort); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateSDiv(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): { + case COMB(TY_SHORT, TY_LONG): { llvm::Value *rhsShort = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSDiv(lhs, rhsShort); } - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSDiv(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): return builder->CreateSDiv(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: /="); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getRemEqualInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getRemEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { llvm::Type *lhsTy = lhs->getType(); - llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): return builder->CreateFRem(lhs, rhs); - case COMB(P_TY_INT, P_TY_INT): + case COMB(TY_INT, TY_INT): return builder->CreateSRem(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): // fallthrough - case COMB(P_TY_INT, P_TY_LONG): { + case COMB(TY_INT, TY_SHORT): // fallthrough + case COMB(TY_INT, TY_LONG): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSRem(lhs, rhsInt); } - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_SHORT, TY_INT): { llvm::Value *rhsShort = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSRem(lhs, rhsShort); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateSRem(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): { + case COMB(TY_SHORT, TY_LONG): { llvm::Value *rhsShort = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSRem(lhs, rhsShort); } - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSRem(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): return builder->CreateSRem(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: %="); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getSHLEqualInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getSHLEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { llvm::Type *lhsTy = lhs->getType(); - llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_INT, P_TY_INT): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_INT, TY_INT): return builder->CreateShl(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): // fallthrough - case COMB(P_TY_INT, P_TY_LONG): // fallthrough - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_INT, TY_SHORT): // fallthrough + case COMB(TY_INT, TY_LONG): // fallthrough + case COMB(TY_SHORT, TY_INT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateShl(lhs, rhsInt); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateShl(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): // fallthrough - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_SHORT, TY_LONG): // fallthrough + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateShl(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): return builder->CreateShl(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: <<="); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getSHREqualInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getSHREqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { llvm::Type *lhsTy = lhs->getType(); - llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_INT, P_TY_INT): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_INT, TY_INT): return builder->CreateLShr(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): // fallthrough - case COMB(P_TY_INT, P_TY_LONG): // fallthrough - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_INT, TY_SHORT): // fallthrough + case COMB(TY_INT, TY_LONG): // fallthrough + case COMB(TY_SHORT, TY_INT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateLShr(lhs, rhsInt); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateLShr(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): // fallthrough - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_SHORT, TY_LONG): // fallthrough + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateLShr(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): return builder->CreateLShr(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: >>="); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getAndEqualInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getAndEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { llvm::Type *lhsTy = lhs->getType(); - llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_INT, P_TY_INT): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_INT, TY_INT): return builder->CreateAnd(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): // fallthrough - case COMB(P_TY_INT, P_TY_LONG): // fallthrough - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_INT, TY_SHORT): // fallthrough + case COMB(TY_INT, TY_LONG): // fallthrough + case COMB(TY_SHORT, TY_INT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateAnd(lhs, rhsInt); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateAnd(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): // fallthrough - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_SHORT, TY_LONG): // fallthrough + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateAnd(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): return builder->CreateAnd(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: &="); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getOrEqualInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getOrEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { llvm::Type *lhsTy = lhs->getType(); - llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_INT, P_TY_INT): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_INT, TY_INT): return builder->CreateOr(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): // fallthrough - case COMB(P_TY_INT, P_TY_LONG): // fallthrough - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_INT, TY_SHORT): // fallthrough + case COMB(TY_INT, TY_LONG): // fallthrough + case COMB(TY_SHORT, TY_INT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateOr(lhs, rhsInt); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateOr(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): // fallthrough - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_SHORT, TY_LONG): // fallthrough + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateOr(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): return builder->CreateOr(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: |="); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getXorEqualInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getXorEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { llvm::Type *lhsTy = lhs->getType(); - llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_INT, P_TY_INT): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_INT, TY_INT): return builder->CreateXor(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): // fallthrough - case COMB(P_TY_INT, P_TY_LONG): // fallthrough - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_INT, TY_SHORT): // fallthrough + case COMB(TY_INT, TY_LONG): // fallthrough + case COMB(TY_SHORT, TY_INT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateXor(lhs, rhsInt); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateXor(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): // fallthrough - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_SHORT, TY_LONG): // fallthrough + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateXor(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): return builder->CreateXor(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: ^="); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getBitwiseAndInst(llvm::Value *lhs, llvm::Value *rhs) { - llvm::Type *lhsTy = lhs->getType(); - llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_INT, P_TY_INT): // fallthrough - case COMB(P_TY_SHORT, P_TY_SHORT): // fallthrough - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): +llvm::Value *OpRuleConversionsManager::getBitwiseAndInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_INT, TY_INT): // fallthrough + case COMB(TY_SHORT, TY_SHORT): // fallthrough + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): return builder->CreateAnd(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: &"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getBitwiseOrInst(llvm::Value *lhs, llvm::Value *rhs) { - llvm::Type *lhsTy = lhs->getType(); - llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_INT, P_TY_INT): // fallthrough - case COMB(P_TY_SHORT, P_TY_SHORT): // fallthrough - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): +llvm::Value *OpRuleConversionsManager::getBitwiseOrInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_INT, TY_INT): // fallthrough + case COMB(TY_SHORT, TY_SHORT): // fallthrough + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): return builder->CreateOr(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: |"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getBitwiseXorInst(llvm::Value *lhs, llvm::Value *rhs) { - llvm::Type *lhsTy = lhs->getType(); - llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_INT, P_TY_INT): // fallthrough - case COMB(P_TY_SHORT, P_TY_SHORT): // fallthrough - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): +llvm::Value *OpRuleConversionsManager::getBitwiseXorInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_INT, TY_INT): // fallthrough + case COMB(TY_SHORT, TY_SHORT): // fallthrough + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): return builder->CreateXor(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: ^"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getEqualInst(llvm::Value *lhs, llvm::Value *rhs, const CodeLoc &codeLoc) { +llvm::Value *OpRuleConversionsManager::getEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy, const CodeLoc &codeLoc) { llvm::Type *lhsTy = lhs->getType(); llvm::Type *rhsTy = rhs->getType(); @@ -411,92 +384,98 @@ llvm::Value *OpRuleConversionsManager::getEqualInst(llvm::Value *lhs, llvm::Valu } // Check for primitive type combinations - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): return builder->CreateFCmpOEQ(lhs, rhs); - case COMB(P_TY_DOUBLE, P_TY_INT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_SHORT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_LONG): { + case COMB(TY_DOUBLE, TY_INT): // fallthrough + case COMB(TY_DOUBLE, TY_SHORT): // fallthrough + case COMB(TY_DOUBLE, TY_LONG): { llvm::Value *rhsFP = builder->CreateSIToFP(rhs, lhsTy); return builder->CreateFCmpOEQ(lhs, rhsFP); } - case COMB(P_TY_INT, P_TY_DOUBLE): { + case COMB(TY_INT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpOEQ(lhsFP, rhs); } - case COMB(P_TY_INT, P_TY_INT): + case COMB(TY_INT, TY_INT): return builder->CreateICmpEQ(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): { + case COMB(TY_INT, TY_SHORT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpEQ(lhs, rhsInt); } - case COMB(P_TY_INT, P_TY_LONG): { + case COMB(TY_INT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpEQ(lhsLong, rhs); } - case COMB(P_TY_INT, P_TY_BYTE_OR_CHAR): { + case COMB(TY_INT, TY_BYTE): // fallthrough + case COMB(TY_INT, TY_CHAR): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpEQ(lhs, rhsInt); } - case COMB(P_TY_SHORT, P_TY_DOUBLE): { + case COMB(TY_SHORT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpOEQ(lhsFP, rhs); } - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_SHORT, TY_INT): { llvm::Value *lhsInt = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpEQ(lhsInt, rhs); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateICmpEQ(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): { + case COMB(TY_SHORT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpEQ(lhsLong, rhs); } - case COMB(P_TY_SHORT, P_TY_BYTE_OR_CHAR): { + case COMB(TY_SHORT, TY_BYTE): // fallthrough + case COMB(TY_SHORT, TY_CHAR): { llvm::Value *rhsShort = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpEQ(lhs, rhsShort); } - case COMB(P_TY_LONG, P_TY_DOUBLE): { + case COMB(TY_LONG, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpOEQ(lhsFP, rhs); } - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpEQ(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): + case COMB(TY_LONG, TY_LONG): return builder->CreateICmpEQ(lhs, rhs); - case COMB(P_TY_LONG, P_TY_BYTE_OR_CHAR): { + case COMB(TY_LONG, TY_BYTE): // fallthrough + case COMB(TY_LONG, TY_CHAR): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpEQ(lhs, rhsLong); } - case COMB(P_TY_BYTE_OR_CHAR, P_TY_INT): { + case COMB(TY_BYTE, TY_INT): // fallthrough + case COMB(TY_CHAR, TY_INT): { llvm::Value *lhsInt = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpEQ(lhsInt, rhs); } - case COMB(P_TY_BYTE_OR_CHAR, P_TY_SHORT): { + case COMB(TY_BYTE, TY_SHORT): // fallthrough + case COMB(TY_CHAR, TY_SHORT): { llvm::Value *lhsShort = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpEQ(lhsShort, rhs); } - case COMB(P_TY_BYTE_OR_CHAR, P_TY_LONG): { + case COMB(TY_BYTE, TY_LONG): // fallthrough + case COMB(TY_CHAR, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpEQ(lhsLong, rhs); } - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_BYTE, TY_BYTE): // fallthrough + case COMB(TY_CHAR, TY_CHAR): return builder->CreateICmpEQ(lhs, rhs); - case COMB(P_TY_STRING, P_TY_STRING): + case COMB(TY_STRING, TY_STRING): // ToDo(@marcauberer): Insert call to concatStrings in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '==' operator for lhs=string and rhs=string yet"); - case COMB(P_TY_BOOL, P_TY_BOOL): + case COMB(TY_BOOL, TY_BOOL): return builder->CreateICmpEQ(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: =="); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getNotEqualInst(llvm::Value *lhs, llvm::Value *rhs, const CodeLoc &codeLoc) { +llvm::Value *OpRuleConversionsManager::getNotEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy, const CodeLoc &codeLoc) { llvm::Type *lhsTy = lhs->getType(); llvm::Type *rhsTy = rhs->getType(); @@ -510,642 +489,642 @@ llvm::Value *OpRuleConversionsManager::getNotEqualInst(llvm::Value *lhs, llvm::V return builder->CreateICmpNE(lhsInt, rhs); } - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): return builder->CreateFCmpONE(lhs, rhs); - case COMB(P_TY_DOUBLE, P_TY_INT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_SHORT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_LONG): { + case COMB(TY_DOUBLE, TY_INT): // fallthrough + case COMB(TY_DOUBLE, TY_SHORT): // fallthrough + case COMB(TY_DOUBLE, TY_LONG): { llvm::Value *rhsFP = builder->CreateSIToFP(rhs, lhsTy); return builder->CreateFCmpONE(lhs, rhsFP); } - case COMB(P_TY_INT, P_TY_DOUBLE): { + case COMB(TY_INT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpONE(lhsFP, rhs); } - case COMB(P_TY_INT, P_TY_INT): + case COMB(TY_INT, TY_INT): return builder->CreateICmpNE(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): { + case COMB(TY_INT, TY_SHORT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpNE(lhs, rhsInt); } - case COMB(P_TY_INT, P_TY_LONG): { + case COMB(TY_INT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpNE(lhsLong, rhs); } - case COMB(P_TY_INT, P_TY_BYTE_OR_CHAR): { + case COMB(TY_INT, TY_BYTE): // fallthrough + case COMB(TY_INT, TY_CHAR): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpNE(lhs, rhsInt); } - case COMB(P_TY_SHORT, P_TY_DOUBLE): { + case COMB(TY_SHORT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpONE(lhsFP, rhs); } - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_SHORT, TY_INT): { llvm::Value *lhsInt = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpNE(lhsInt, rhs); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateICmpNE(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): { + case COMB(TY_SHORT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpNE(lhsLong, rhs); } - case COMB(P_TY_SHORT, P_TY_BYTE_OR_CHAR): { + case COMB(TY_SHORT, TY_BYTE): // fallthrough + case COMB(TY_SHORT, TY_CHAR): { llvm::Value *rhsShort = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpNE(lhs, rhsShort); } - case COMB(P_TY_LONG, P_TY_DOUBLE): { + case COMB(TY_LONG, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpONE(lhsFP, rhs); } - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpNE(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): + case COMB(TY_LONG, TY_LONG): return builder->CreateICmpNE(lhs, rhs); - case COMB(P_TY_LONG, P_TY_BYTE_OR_CHAR): { + case COMB(TY_LONG, TY_BYTE): // fallthrough + case COMB(TY_LONG, TY_CHAR): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpNE(lhs, rhsLong); } - case COMB(P_TY_BYTE_OR_CHAR, P_TY_INT): { + case COMB(TY_BYTE, TY_INT): + case COMB(TY_CHAR, TY_INT): { llvm::Value *lhsInt = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpNE(lhsInt, rhs); } - case COMB(P_TY_BYTE_OR_CHAR, P_TY_SHORT): { + case COMB(TY_BYTE, TY_SHORT): // fallthrough + case COMB(TY_CHAR, TY_SHORT): { llvm::Value *lhsShort = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpNE(lhsShort, rhs); } - case COMB(P_TY_BYTE_OR_CHAR, P_TY_LONG): { + case COMB(TY_BYTE, TY_LONG): // fallthrough + case COMB(TY_CHAR, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpNE(lhsLong, rhs); } - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_BYTE, TY_BYTE): // fallthrough + case COMB(TY_CHAR, TY_CHAR): return builder->CreateICmpNE(lhs, rhs); - case COMB(P_TY_STRING, P_TY_STRING): + case COMB(TY_STRING, TY_STRING): // ToDo(@marcauberer): Insert call to concatStrings in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '!=' operator for lhs=string and rhs=string yet"); - case COMB(P_TY_BOOL, P_TY_BOOL): + case COMB(TY_BOOL, TY_BOOL): return builder->CreateICmpNE(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: !="); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getLessInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getLessInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { llvm::Type *lhsTy = lhs->getType(); llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): return builder->CreateFCmpOLT(lhs, rhs); - case COMB(P_TY_DOUBLE, P_TY_INT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_SHORT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_LONG): { + case COMB(TY_DOUBLE, TY_INT): // fallthrough + case COMB(TY_DOUBLE, TY_SHORT): // fallthrough + case COMB(TY_DOUBLE, TY_LONG): { llvm::Value *rhsFP = builder->CreateSIToFP(rhs, lhsTy); return builder->CreateFCmpOLT(lhs, rhsFP); } - case COMB(P_TY_INT, P_TY_DOUBLE): { + case COMB(TY_INT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpOLT(lhsFP, rhs); } - case COMB(P_TY_INT, P_TY_INT): + case COMB(TY_INT, TY_INT): return builder->CreateICmpSLT(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): { + case COMB(TY_INT, TY_SHORT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpSLT(lhs, rhsInt); } - case COMB(P_TY_INT, P_TY_LONG): { + case COMB(TY_INT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpSLT(lhsLong, rhs); } - case COMB(P_TY_SHORT, P_TY_DOUBLE): { + case COMB(TY_SHORT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpOLT(lhsFP, rhs); } - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_SHORT, TY_INT): { llvm::Value *lhsInt = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpSLT(lhsInt, rhs); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateICmpSLT(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): { + case COMB(TY_SHORT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpSLT(lhsLong, rhs); } - case COMB(P_TY_LONG, P_TY_DOUBLE): { + case COMB(TY_LONG, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpOLT(lhsFP, rhs); } - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpSLT(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): // fallthrough + case COMB(TY_CHAR, TY_CHAR): return builder->CreateICmpSLT(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: <"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getGreaterInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getGreaterInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { llvm::Type *lhsTy = lhs->getType(); llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): return builder->CreateFCmpOGT(lhs, rhs); - case COMB(P_TY_DOUBLE, P_TY_INT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_SHORT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_LONG): { + case COMB(TY_DOUBLE, TY_INT): // fallthrough + case COMB(TY_DOUBLE, TY_SHORT): // fallthrough + case COMB(TY_DOUBLE, TY_LONG): { llvm::Value *rhsFP = builder->CreateSIToFP(rhs, lhsTy); return builder->CreateFCmpOGT(lhs, rhsFP); } - case COMB(P_TY_INT, P_TY_DOUBLE): { + case COMB(TY_INT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpOGT(lhsFP, rhs); } - case COMB(P_TY_INT, P_TY_INT): + case COMB(TY_INT, TY_INT): return builder->CreateICmpSGT(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): { + case COMB(TY_INT, TY_SHORT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpSGT(lhs, rhsInt); } - case COMB(P_TY_INT, P_TY_LONG): { + case COMB(TY_INT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpSGT(lhsLong, rhs); } - case COMB(P_TY_SHORT, P_TY_DOUBLE): { + case COMB(TY_SHORT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpOGT(lhsFP, rhs); } - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_SHORT, TY_INT): { llvm::Value *lhsInt = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpSGT(lhsInt, rhs); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateICmpSGT(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): { + case COMB(TY_SHORT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpSGT(lhsLong, rhs); } - case COMB(P_TY_LONG, P_TY_DOUBLE): { + case COMB(TY_LONG, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpOGT(lhsFP, rhs); } - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpSGT(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): // fallthrough + case COMB(TY_CHAR, TY_CHAR): return builder->CreateICmpSGT(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: >"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getLessEqualInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getLessEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { llvm::Type *lhsTy = lhs->getType(); llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): return builder->CreateFCmpOLE(lhs, rhs); - case COMB(P_TY_DOUBLE, P_TY_INT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_SHORT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_LONG): { + case COMB(TY_DOUBLE, TY_INT): // fallthrough + case COMB(TY_DOUBLE, TY_SHORT): // fallthrough + case COMB(TY_DOUBLE, TY_LONG): { llvm::Value *rhsFP = builder->CreateSIToFP(rhs, lhsTy); return builder->CreateFCmpOLE(lhs, rhsFP); } - case COMB(P_TY_INT, P_TY_DOUBLE): { + case COMB(TY_INT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpOLE(lhsFP, rhs); } - case COMB(P_TY_INT, P_TY_INT): + case COMB(TY_INT, TY_INT): return builder->CreateICmpSLE(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): { + case COMB(TY_INT, TY_SHORT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpSLE(lhs, rhsInt); } - case COMB(P_TY_INT, P_TY_LONG): { + case COMB(TY_INT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpSLE(lhsLong, rhs); } - case COMB(P_TY_SHORT, P_TY_DOUBLE): { + case COMB(TY_SHORT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpOLE(lhsFP, rhs); } - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_SHORT, TY_INT): { llvm::Value *lhsInt = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpSLE(lhsInt, rhs); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateICmpSLE(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): { + case COMB(TY_SHORT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpSLE(lhsLong, rhs); } - case COMB(P_TY_LONG, P_TY_DOUBLE): { + case COMB(TY_LONG, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpOLE(lhsFP, rhs); } - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpSLE(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): // fallthrough + case COMB(TY_CHAR, TY_CHAR): return builder->CreateICmpSLE(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: <="); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getGreaterEqualInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getGreaterEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { llvm::Type *lhsTy = lhs->getType(); llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): return builder->CreateFCmpOGE(lhs, rhs); - case COMB(P_TY_DOUBLE, P_TY_INT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_SHORT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_LONG): { + case COMB(TY_DOUBLE, TY_INT): // fallthrough + case COMB(TY_DOUBLE, TY_SHORT): // fallthrough + case COMB(TY_DOUBLE, TY_LONG): { llvm::Value *rhsFP = builder->CreateSIToFP(rhs, lhsTy); return builder->CreateFCmpOGE(lhs, rhsFP); } - case COMB(P_TY_INT, P_TY_DOUBLE): { + case COMB(TY_INT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpOGE(lhsFP, rhs); } - case COMB(P_TY_INT, P_TY_INT): + case COMB(TY_INT, TY_INT): return builder->CreateICmpSGE(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): { + case COMB(TY_INT, TY_SHORT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpSGE(lhs, rhsInt); } - case COMB(P_TY_INT, P_TY_LONG): { + case COMB(TY_INT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpSGE(lhsLong, rhs); } - case COMB(P_TY_SHORT, P_TY_DOUBLE): { + case COMB(TY_SHORT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpOGE(lhsFP, rhs); } - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_SHORT, TY_INT): { llvm::Value *lhsInt = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpSGE(lhsInt, rhs); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateICmpSGE(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): { + case COMB(TY_SHORT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateICmpSGE(lhsLong, rhs); } - case COMB(P_TY_LONG, P_TY_DOUBLE): { + case COMB(TY_LONG, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFCmpOGE(lhsFP, rhs); } - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateICmpSGE(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): // fallthrough + case COMB(TY_CHAR, TY_CHAR): return builder->CreateICmpSGE(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: >="); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getShiftLeftInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getShiftLeftInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { llvm::Type *lhsTy = lhs->getType(); - llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_INT, P_TY_INT): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_INT, TY_INT): return builder->CreateShl(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): // fallthrough - case COMB(P_TY_INT, P_TY_LONG): // fallthrough - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_INT, TY_SHORT): // fallthrough + case COMB(TY_INT, TY_LONG): // fallthrough + case COMB(TY_SHORT, TY_INT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateShl(lhs, rhsInt); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateShl(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): // fallthrough - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_SHORT, TY_LONG): // fallthrough + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateShl(lhs, rhsInt); } - case COMB(P_TY_LONG, P_TY_LONG): + case COMB(TY_LONG, TY_LONG): return builder->CreateShl(lhs, rhs); - case COMB(P_TY_BYTE_OR_CHAR, P_TY_INT): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_SHORT): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_LONG): { + case COMB(TY_BYTE, TY_INT): // fallthrough + case COMB(TY_BYTE, TY_SHORT): // fallthrough + case COMB(TY_BYTE, TY_LONG): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateShl(lhs, rhsInt); } - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_BYTE, TY_BYTE): return builder->CreateShl(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: <<"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getShiftRightInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getShiftRightInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { llvm::Type *lhsTy = lhs->getType(); - llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_INT, P_TY_INT): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_INT, TY_INT): return builder->CreateLShr(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): // fallthrough - case COMB(P_TY_INT, P_TY_LONG): // fallthrough - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_INT, TY_SHORT): // fallthrough + case COMB(TY_INT, TY_LONG): // fallthrough + case COMB(TY_SHORT, TY_INT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateLShr(lhs, rhsInt); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateLShr(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): // fallthrough - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_SHORT, TY_LONG): // fallthrough + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateLShr(lhs, rhsInt); } - case COMB(P_TY_LONG, P_TY_LONG): + case COMB(TY_LONG, TY_LONG): return builder->CreateLShr(lhs, rhs); - case COMB(P_TY_BYTE_OR_CHAR, P_TY_INT): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_SHORT): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_LONG): { + case COMB(TY_BYTE, TY_INT): // fallthrough + case COMB(TY_BYTE, TY_SHORT): // fallthrough + case COMB(TY_BYTE, TY_LONG): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateLShr(lhs, rhsInt); } - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_BYTE, TY_BYTE): return builder->CreateLShr(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: >>"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getPlusInst(llvm::Value *lhs, llvm::Value *rhs, const CodeLoc &codeLoc) { +llvm::Value *OpRuleConversionsManager::getPlusInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy, SymbolTable *accessScope, const CodeLoc &codeLoc) { llvm::Type *lhsTy = lhs->getType(); llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): return builder->CreateFAdd(lhs, rhs); - case COMB(P_TY_DOUBLE, P_TY_INT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_SHORT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_LONG): { + case COMB(TY_DOUBLE, TY_INT): // fallthrough + case COMB(TY_DOUBLE, TY_SHORT): // fallthrough + case COMB(TY_DOUBLE, TY_LONG): { llvm::Value *rhsFP = builder->CreateSIToFP(rhs, lhsTy); return builder->CreateFAdd(lhs, rhsFP); } - case COMB(P_TY_INT, P_TY_DOUBLE): { + case COMB(TY_INT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFAdd(lhsFP, rhs); } - case COMB(P_TY_INT, P_TY_INT): + case COMB(TY_INT, TY_INT): return builder->CreateAdd(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): { + case COMB(TY_INT, TY_SHORT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateAdd(lhs, rhsInt); } - case COMB(P_TY_INT, P_TY_LONG): { + case COMB(TY_INT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateAdd(lhsLong, rhs); } - case COMB(P_TY_INT, P_TY_PTR): - return builder->CreateGEP(rhsTy->getPointerElementType(), rhs, lhs); - case COMB(P_TY_SHORT, P_TY_DOUBLE): { + case COMB(TY_INT, TY_PTR): + return builder->CreateGEP(rhsSTy.getContainedTy().toLLVMType(*context, accessScope), rhs, lhs); + case COMB(TY_SHORT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFAdd(lhsFP, rhs); } - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_SHORT, TY_INT): { llvm::Value *lhsInt = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateAdd(lhsInt, rhs); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateAdd(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): { + case COMB(TY_SHORT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateAdd(lhsLong, rhs); } - case COMB(P_TY_SHORT, P_TY_PTR): - return builder->CreateGEP(rhsTy->getPointerElementType(), rhs, lhs); - case COMB(P_TY_LONG, P_TY_DOUBLE): { + case COMB(TY_SHORT, TY_PTR): + return builder->CreateGEP(rhsSTy.getContainedTy().toLLVMType(*context, accessScope), rhs, lhs); + case COMB(TY_LONG, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFAdd(lhsFP, rhs); } - case COMB(P_TY_LONG, P_TY_INT): { + case COMB(TY_LONG, TY_INT): { llvm::Value *lhsInt = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateAdd(lhsInt, rhs); } - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateAdd(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): + case COMB(TY_LONG, TY_LONG): return builder->CreateAdd(lhs, rhs); - case COMB(P_TY_LONG, P_TY_PTR): - return builder->CreateGEP(rhsTy->getPointerElementType(), rhs, lhs); - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_PTR): + return builder->CreateGEP(rhsSTy.getContainedTy().toLLVMType(*context, accessScope), rhs, lhs); + case COMB(TY_BYTE, TY_BYTE): // fallthrough + case COMB(TY_CHAR, TY_CHAR): return builder->CreateAdd(lhs, rhs); - case COMB(P_TY_STRING, P_TY_STRING): + case COMB(TY_STRING, TY_STRING): // ToDo(@marcauberer): Insert call to concatStrings in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '+' operator for lhs=string and rhs=string yet"); - case COMB(P_TY_PTR, P_TY_INT): // fallthrough - case COMB(P_TY_PTR, P_TY_SHORT): // fallthrough - case COMB(P_TY_PTR, P_TY_LONG): - return builder->CreateGEP(lhsTy->getPointerElementType(), lhs, rhs); + case COMB(TY_PTR, TY_INT): // fallthrough + case COMB(TY_PTR, TY_SHORT): // fallthrough + case COMB(TY_PTR, TY_LONG): + return builder->CreateGEP(lhsSTy.getContainedTy().toLLVMType(*context, accessScope), lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: +"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getMinusInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getMinusInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy, SymbolTable *accessScope) { llvm::Type *lhsTy = lhs->getType(); llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): return builder->CreateFSub(lhs, rhs); - case COMB(P_TY_DOUBLE, P_TY_INT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_SHORT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_LONG): { + case COMB(TY_DOUBLE, TY_INT): // fallthrough + case COMB(TY_DOUBLE, TY_SHORT): // fallthrough + case COMB(TY_DOUBLE, TY_LONG): { llvm::Value *rhsFP = builder->CreateSIToFP(rhs, lhsTy); return builder->CreateFSub(lhs, rhsFP); } - case COMB(P_TY_INT, P_TY_DOUBLE): { + case COMB(TY_INT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFSub(lhsFP, rhs); } - case COMB(P_TY_INT, P_TY_INT): + case COMB(TY_INT, TY_INT): return builder->CreateSub(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): { + case COMB(TY_INT, TY_SHORT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSub(lhs, rhsInt); } - case COMB(P_TY_INT, P_TY_LONG): { + case COMB(TY_INT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateSub(lhsLong, rhs); } - case COMB(P_TY_INT, P_TY_PTR): - return builder->CreateGEP(rhsTy->getPointerElementType(), rhs, lhs); - case COMB(P_TY_SHORT, P_TY_DOUBLE): { + case COMB(TY_INT, TY_PTR): + return builder->CreateGEP(rhsSTy.getContainedTy().toLLVMType(*context, accessScope), rhs, lhs); + case COMB(TY_SHORT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFSub(lhsFP, rhs); } - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_SHORT, TY_INT): { llvm::Value *lhsInt = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateSub(lhsInt, rhs); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateSub(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): { + case COMB(TY_SHORT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateSub(lhsLong, rhs); } - case COMB(P_TY_SHORT, P_TY_PTR): - return builder->CreateGEP(rhsTy->getPointerElementType(), rhs, lhs); - case COMB(P_TY_LONG, P_TY_DOUBLE): { + case COMB(TY_SHORT, TY_PTR): + return builder->CreateGEP(rhsSTy.getContainedTy().toLLVMType(*context, accessScope), rhs, lhs); + case COMB(TY_LONG, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFSub(lhsFP, rhs); } - case COMB(P_TY_LONG, P_TY_INT): { + case COMB(TY_LONG, TY_INT): { llvm::Value *lhsInt = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateSub(lhsInt, rhs); } - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSub(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): + case COMB(TY_LONG, TY_LONG): return builder->CreateSub(lhs, rhs); - case COMB(P_TY_LONG, P_TY_PTR): - return builder->CreateGEP(rhsTy->getPointerElementType(), rhs, lhs); - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_PTR): + return builder->CreateGEP(rhsSTy.getContainedTy().toLLVMType(*context, accessScope), rhs, lhs); + case COMB(TY_BYTE, TY_BYTE): // fallthrough + case COMB(TY_CHAR, TY_CHAR): return builder->CreateSub(lhs, rhs); - case COMB(P_TY_PTR, P_TY_INT): // fallthrough - case COMB(P_TY_PTR, P_TY_SHORT): // fallthrough - case COMB(P_TY_PTR, P_TY_LONG): - return builder->CreateGEP(lhsTy->getPointerElementType(), lhs, rhs); + case COMB(TY_PTR, TY_INT): // fallthrough + case COMB(TY_PTR, TY_SHORT): // fallthrough + case COMB(TY_PTR, TY_LONG): + return builder->CreateGEP(lhsSTy.getContainedTy().toLLVMType(*context, accessScope), lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: -"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getMulInst(llvm::Value *lhs, llvm::Value *rhs, const CodeLoc &codeLoc) { +llvm::Value *OpRuleConversionsManager::getMulInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy, const CodeLoc &codeLoc) { llvm::Type *lhsTy = lhs->getType(); llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): return builder->CreateFMul(lhs, rhs); - case COMB(P_TY_DOUBLE, P_TY_INT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_SHORT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_LONG): { + case COMB(TY_DOUBLE, TY_INT): // fallthrough + case COMB(TY_DOUBLE, TY_SHORT): // fallthrough + case COMB(TY_DOUBLE, TY_LONG): { llvm::Value *rhsFP = builder->CreateSIToFP(rhs, lhsTy); return builder->CreateFMul(lhs, rhsFP); } - case COMB(P_TY_INT, P_TY_DOUBLE): { + case COMB(TY_INT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFMul(lhsFP, rhs); } - case COMB(P_TY_INT, P_TY_INT): + case COMB(TY_INT, TY_INT): return builder->CreateMul(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): { + case COMB(TY_INT, TY_SHORT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateMul(lhs, rhsInt); } - case COMB(P_TY_INT, P_TY_LONG): { + case COMB(TY_INT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateMul(lhsLong, rhs); } - case COMB(P_TY_INT, P_TY_BYTE_OR_CHAR): { + case COMB(TY_INT, TY_CHAR): { // ToDo(@marcauberer): Insert call to concatStrings in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '*' operator for lhs=int and rhs=char yet"); } - case COMB(P_TY_INT, P_TY_STRING): { + case COMB(TY_INT, TY_STRING): { // ToDo(@marcauberer): Insert call to concatStrings in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '*' operator for lhs=int and rhs=string yet"); } - case COMB(P_TY_SHORT, P_TY_DOUBLE): { + case COMB(TY_SHORT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFMul(lhsFP, rhs); } - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_SHORT, TY_INT): { llvm::Value *lhsInt = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateMul(lhsInt, rhs); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateMul(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): { + case COMB(TY_SHORT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateMul(lhsLong, rhs); } - case COMB(P_TY_SHORT, P_TY_BYTE_OR_CHAR): { + case COMB(TY_SHORT, TY_CHAR): { // ToDo(@marcauberer): Insert call to concatStrings in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '*' operator for lhs=short and rhs=char yet"); } - case COMB(P_TY_SHORT, P_TY_STRING): { + case COMB(TY_SHORT, TY_STRING): { // ToDo(@marcauberer): Insert call to concatStrings in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '*' operator for lhs=short and rhs=string yet"); } - case COMB(P_TY_LONG, P_TY_DOUBLE): { + case COMB(TY_LONG, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFMul(lhsFP, rhs); } - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateMul(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): + case COMB(TY_LONG, TY_LONG): return builder->CreateMul(lhs, rhs); - case COMB(P_TY_LONG, P_TY_BYTE_OR_CHAR): { + case COMB(TY_LONG, TY_CHAR): { // ToDo(@marcauberer): Insert call to concatStrings in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '*' operator for lhs=long and rhs=char yet"); } - case COMB(P_TY_LONG, P_TY_STRING): { + case COMB(TY_LONG, TY_STRING): { // ToDo(@marcauberer): Insert call to concatStrings in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '*' operator for lhs=long and rhs=string yet"); } - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_BYTE, TY_BYTE): return builder->CreateMul(lhs, rhs); - case COMB(P_TY_BYTE_OR_CHAR, P_TY_INT): { + case COMB(TY_CHAR, TY_INT): { // ToDo(@marcauberer): Insert call to concatStrings in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '*' operator for lhs=char and rhs=int yet"); } - case COMB(P_TY_BYTE_OR_CHAR, P_TY_SHORT): { + case COMB(TY_CHAR, TY_SHORT): { // ToDo(@marcauberer): Insert call to concatStrings in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '*' operator for lhs=char and rhs=short yet"); } - case COMB(P_TY_BYTE_OR_CHAR, P_TY_LONG): { + case COMB(TY_CHAR, TY_LONG): { // ToDo(@marcauberer): Insert call to concatStrings in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '*' operator for lhs=char and rhs=long yet"); } - case COMB(P_TY_STRING, P_TY_INT): { + case COMB(TY_STRING, TY_INT): { // ToDo(@marcauberer): Insert call to concatStrings in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '*' operator for lhs=string and rhs=int yet"); } - case COMB(P_TY_STRING, P_TY_SHORT): { + case COMB(TY_STRING, TY_SHORT): { // ToDo(@marcauberer): Insert call to concatStrings in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '*' operator for lhs=string and rhs=short yet"); } - case COMB(P_TY_STRING, P_TY_LONG): { + case COMB(TY_STRING, TY_LONG): { // ToDo(@marcauberer): Insert call to concatStrings in the runtime lib throw err->get(codeLoc, COMING_SOON_IR, "The compiler does not support the '*' operator for lhs=string and rhs=long yet"); } @@ -1153,112 +1132,109 @@ llvm::Value *OpRuleConversionsManager::getMulInst(llvm::Value *lhs, llvm::Value throw std::runtime_error("Internal compiler error: Operator fallthrough: *"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getDivInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getDivInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { llvm::Type *lhsTy = lhs->getType(); llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): return builder->CreateFDiv(lhs, rhs); - case COMB(P_TY_DOUBLE, P_TY_INT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_SHORT): // fallthrough - case COMB(P_TY_DOUBLE, P_TY_LONG): { + case COMB(TY_DOUBLE, TY_INT): // fallthrough + case COMB(TY_DOUBLE, TY_SHORT): // fallthrough + case COMB(TY_DOUBLE, TY_LONG): { llvm::Value *rhsFP = builder->CreateSIToFP(rhs, lhsTy); return builder->CreateFDiv(lhs, rhsFP); } - case COMB(P_TY_INT, P_TY_DOUBLE): { + case COMB(TY_INT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFDiv(lhsFP, rhs); } - case COMB(P_TY_INT, P_TY_INT): + case COMB(TY_INT, TY_INT): return builder->CreateSDiv(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): { + case COMB(TY_INT, TY_SHORT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSDiv(lhs, rhsInt); } - case COMB(P_TY_INT, P_TY_LONG): { + case COMB(TY_INT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateSDiv(lhsLong, rhs); } - case COMB(P_TY_SHORT, P_TY_DOUBLE): { + case COMB(TY_SHORT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFDiv(lhsFP, rhs); } - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_SHORT, TY_INT): { llvm::Value *lhsInt = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateSDiv(lhsInt, rhs); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateSDiv(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): { + case COMB(TY_SHORT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateSDiv(lhsLong, rhs); } - case COMB(P_TY_LONG, P_TY_DOUBLE): { + case COMB(TY_LONG, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); return builder->CreateFDiv(lhsFP, rhs); } - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSDiv(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): + case COMB(TY_LONG, TY_LONG): // fallthrough + case COMB(TY_BYTE, TY_BYTE): // fallthrough + case COMB(TY_CHAR, TY_CHAR): return builder->CreateSDiv(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: /"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getRemInst(llvm::Value *lhs, llvm::Value *rhs) { +llvm::Value *OpRuleConversionsManager::getRemInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsSTy, + const SymbolType &rhsSTy) { llvm::Type *lhsTy = lhs->getType(); llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): return builder->CreateFRem(lhs, rhs); - case COMB(P_TY_INT, P_TY_INT): + case COMB(TY_INT, TY_INT): return builder->CreateSRem(lhs, rhs); - case COMB(P_TY_INT, P_TY_SHORT): { + case COMB(TY_INT, TY_SHORT): { llvm::Value *rhsInt = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSRem(lhs, rhsInt); } - case COMB(P_TY_INT, P_TY_LONG): { + case COMB(TY_INT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateSRem(lhsLong, rhs); } - case COMB(P_TY_SHORT, P_TY_INT): { + case COMB(TY_SHORT, TY_INT): { llvm::Value *lhsInt = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateSRem(lhsInt, rhs); } - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return builder->CreateSRem(lhs, rhs); - case COMB(P_TY_SHORT, P_TY_LONG): { + case COMB(TY_SHORT, TY_LONG): { llvm::Value *lhsLong = builder->CreateIntCast(lhs, rhsTy, true); return builder->CreateSRem(lhsLong, rhs); } - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): { + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): { llvm::Value *rhsLong = builder->CreateIntCast(rhs, lhsTy, true); return builder->CreateSRem(lhs, rhsLong); } - case COMB(P_TY_LONG, P_TY_LONG): + case COMB(TY_LONG, TY_LONG): return builder->CreateSRem(lhs, rhs); } throw std::runtime_error("Internal compiler error: Operator fallthrough: %"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getPrefixMinusInst(llvm::Value *lhs) { - llvm::Type *lhsTy = lhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - switch (lhsPTy) { - case P_TY_DOUBLE: +llvm::Value *OpRuleConversionsManager::getPrefixMinusInst(llvm::Value *lhs, const SymbolType &lhsSTy) { + switch (lhsSTy.getSuperType()) { + case TY_DOUBLE: return builder->CreateFMul(lhs, llvm::ConstantFP::get(builder->getContext(), llvm::APFloat(double(-1)))); - case P_TY_INT: // fallthrough - case P_TY_SHORT: // fallthrough - case P_TY_LONG: + case TY_INT: // fallthrough + case TY_SHORT: // fallthrough + case TY_LONG: return builder->CreateNeg(lhs); default: break; @@ -1266,15 +1242,13 @@ llvm::Value *OpRuleConversionsManager::getPrefixMinusInst(llvm::Value *lhs) { throw std::runtime_error("Internal compiler error: Operator fallthrough: +"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getPrefixPlusPlusInst(llvm::Value *lhs) { - llvm::Type *lhsTy = lhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - switch (lhsPTy) { - case P_TY_INT: +llvm::Value *OpRuleConversionsManager::getPrefixPlusPlusInst(llvm::Value *lhs, const SymbolType &lhsSTy) { + switch (lhsSTy.getSuperType()) { + case TY_INT: return builder->CreateAdd(lhs, builder->getInt32(1)); - case P_TY_SHORT: + case TY_SHORT: return builder->CreateAdd(lhs, builder->getInt16(1)); - case P_TY_LONG: + case TY_LONG: return builder->CreateAdd(lhs, builder->getInt64(1)); default: break; @@ -1282,15 +1256,13 @@ llvm::Value *OpRuleConversionsManager::getPrefixPlusPlusInst(llvm::Value *lhs) { throw std::runtime_error("Internal compiler error: Operator fallthrough: ++ (prefix)"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getPrefixMinusMinusInst(llvm::Value *lhs) { - llvm::Type *lhsTy = lhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - switch (lhsPTy) { - case P_TY_INT: +llvm::Value *OpRuleConversionsManager::getPrefixMinusMinusInst(llvm::Value *lhs, const SymbolType &lhsSTy) { + switch (lhsSTy.getSuperType()) { + case TY_INT: return builder->CreateSub(lhs, builder->getInt32(1)); - case P_TY_SHORT: + case TY_SHORT: return builder->CreateSub(lhs, builder->getInt16(1)); - case P_TY_LONG: + case TY_LONG: return builder->CreateSub(lhs, builder->getInt64(1)); default: break; @@ -1298,11 +1270,9 @@ llvm::Value *OpRuleConversionsManager::getPrefixMinusMinusInst(llvm::Value *lhs) throw std::runtime_error("Internal compiler error: Operator fallthrough: -- (prefix)"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getPrefixNotInst(llvm::Value *lhs) { - llvm::Type *lhsTy = lhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - switch (lhsPTy) { - case P_TY_BOOL: +llvm::Value *OpRuleConversionsManager::getPrefixNotInst(llvm::Value *lhs, const SymbolType &lhsSTy) { + switch (lhsSTy.getSuperType()) { + case TY_BOOL: return builder->CreateNot(lhs); default: break; @@ -1310,13 +1280,11 @@ llvm::Value *OpRuleConversionsManager::getPrefixNotInst(llvm::Value *lhs) { throw std::runtime_error("Internal compiler error: Operator fallthrough: !"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getPrefixBitwiseNotInst(llvm::Value *lhs) { - llvm::Type *lhsTy = lhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - switch (lhsPTy) { - case P_TY_INT: // fallthrough - case P_TY_SHORT: // fallthrough - case P_TY_LONG: +llvm::Value *OpRuleConversionsManager::getPrefixBitwiseNotInst(llvm::Value *lhs, const SymbolType &lhsSTy) { + switch (lhsSTy.getSuperType()) { + case TY_INT: // fallthrough + case TY_SHORT: // fallthrough + case TY_LONG: return builder->CreateNeg(lhs); default: break; @@ -1324,15 +1292,13 @@ llvm::Value *OpRuleConversionsManager::getPrefixBitwiseNotInst(llvm::Value *lhs) throw std::runtime_error("Internal compiler error: Operator fallthrough: ~"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getPostfixPlusPlusInst(llvm::Value *lhs) { - llvm::Type *lhsTy = lhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - switch (lhsPTy) { - case P_TY_INT: +llvm::Value *OpRuleConversionsManager::getPostfixPlusPlusInst(llvm::Value *lhs, const SymbolType &lhsSTy) { + switch (lhsSTy.getSuperType()) { + case TY_INT: return builder->CreateAdd(lhs, builder->getInt32(1)); - case P_TY_SHORT: + case TY_SHORT: return builder->CreateAdd(lhs, builder->getInt16(1)); - case P_TY_LONG: + case TY_LONG: return builder->CreateAdd(lhs, builder->getInt64(1)); default: break; @@ -1340,15 +1306,13 @@ llvm::Value *OpRuleConversionsManager::getPostfixPlusPlusInst(llvm::Value *lhs) throw std::runtime_error("Internal compiler error: Operator fallthrough: ++ (postfix)"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getPostfixMinusMinusInst(llvm::Value *lhs) { - llvm::Type *lhsTy = lhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - switch (lhsPTy) { - case P_TY_INT: +llvm::Value *OpRuleConversionsManager::getPostfixMinusMinusInst(llvm::Value *lhs, const SymbolType &lhsSTy) { + switch (lhsSTy.getSuperType()) { + case TY_INT: return builder->CreateSub(lhs, builder->getInt32(1)); - case P_TY_SHORT: + case TY_SHORT: return builder->CreateSub(lhs, builder->getInt16(1)); - case P_TY_LONG: + case TY_LONG: return builder->CreateSub(lhs, builder->getInt64(1)); default: break; @@ -1356,79 +1320,47 @@ llvm::Value *OpRuleConversionsManager::getPostfixMinusMinusInst(llvm::Value *lhs throw std::runtime_error("Internal compiler error: Operator fallthrough: -- (postfix)"); // GCOV_EXCL_LINE } -llvm::Value *OpRuleConversionsManager::getCastInst(llvm::Type *lhsTy, llvm::Value *rhs) { - llvm::Type *rhsTy = rhs->getType(); - OpRuleType lhsPTy = getSymbolTypeFromLLVMType(lhsTy); - OpRuleType rhsPTy = getSymbolTypeFromLLVMType(rhsTy); - switch (COMB(lhsPTy, rhsPTy)) { - case COMB(P_TY_DOUBLE, P_TY_DOUBLE): // fallthrough - case COMB(P_TY_INT, P_TY_INT): +llvm::Value *OpRuleConversionsManager::getCastInst(llvm::Value *rhs, const SymbolType &lhsSTy, const SymbolType &rhsSTy, + SymbolTable *accessScope) { + llvm::Type *lhsTy = lhsSTy.toLLVMType(*context, accessScope); + switch (COMB(lhsSTy.getSuperType(), rhsSTy.getSuperType())) { + case COMB(TY_DOUBLE, TY_DOUBLE): // fallthrough + case COMB(TY_INT, TY_INT): return rhs; - case COMB(P_TY_INT, P_TY_SHORT): // fallthrough - case COMB(P_TY_INT, P_TY_LONG): // fallthrough - case COMB(P_TY_INT, P_TY_BYTE_OR_CHAR): // fallthrough - case COMB(P_TY_SHORT, P_TY_INT): + case COMB(TY_INT, TY_SHORT): // fallthrough + case COMB(TY_INT, TY_LONG): // fallthrough + case COMB(TY_INT, TY_BYTE): // fallthrough + case COMB(TY_INT, TY_CHAR): // fallthrough + case COMB(TY_SHORT, TY_INT): return builder->CreateIntCast(rhs, lhsTy, true); - case COMB(P_TY_SHORT, P_TY_SHORT): + case COMB(TY_SHORT, TY_SHORT): return rhs; - case COMB(P_TY_SHORT, P_TY_LONG): // fallthrough - case COMB(P_TY_LONG, P_TY_INT): // fallthrough - case COMB(P_TY_LONG, P_TY_SHORT): + case COMB(TY_SHORT, TY_LONG): // fallthrough + case COMB(TY_LONG, TY_INT): // fallthrough + case COMB(TY_LONG, TY_SHORT): return builder->CreateIntCast(rhs, lhsTy, true); - case COMB(P_TY_LONG, P_TY_LONG): + case COMB(TY_LONG, TY_LONG): + return rhs; + case COMB(TY_BYTE, TY_INT): // fallthrough + case COMB(TY_BYTE, TY_SHORT): // fallthrough + case COMB(TY_BYTE, TY_LONG): + return builder->CreateIntCast(rhs, lhsTy, false); + case COMB(TY_BYTE, TY_BYTE): return rhs; - case COMB(P_TY_BYTE_OR_CHAR, P_TY_INT): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_SHORT): // fallthrough - case COMB(P_TY_BYTE_OR_CHAR, P_TY_LONG): + case COMB(TY_CHAR, TY_INT): // fallthrough + case COMB(TY_CHAR, TY_SHORT): // fallthrough + case COMB(TY_CHAR, TY_LONG): return builder->CreateIntCast(rhs, lhsTy, false); - case COMB(P_TY_BYTE_OR_CHAR, P_TY_BYTE_OR_CHAR): // fallthrough - case COMB(P_TY_STRING, P_TY_STRING): + case COMB(TY_CHAR, TY_CHAR): // fallthrough + case COMB(TY_STRING, TY_STRING): return rhs; - case COMB(P_TY_STRING, P_TY_PTR): + case COMB(TY_STRING, TY_PTR): return builder->CreatePointerCast(rhs, lhsTy); - case COMB(P_TY_BOOL, P_TY_BOOL): + case COMB(TY_BOOL, TY_BOOL): return rhs; - case COMB(P_TY_PTR, P_TY_STRING): // fallthrough (string corresponds to byte* or char*) - case COMB(P_TY_PTR, P_TY_PTR): + case COMB(TY_PTR, TY_STRING): // fallthrough (string corresponds to byte* or char*) + case COMB(TY_PTR, TY_PTR): return builder->CreatePointerCast(rhs, lhsTy); } throw std::runtime_error("Internal compiler error: Operator fallthrough: (cast)"); // GCOV_EXCL_LINE -} - -OpRuleType OpRuleConversionsManager::getSymbolTypeFromLLVMType(llvm::Type *ty) { - if (isDouble(ty)) - return P_TY_DOUBLE; - if (isInt(ty)) - return P_TY_INT; - if (isShort(ty)) - return P_TY_SHORT; - if (isLong(ty)) - return P_TY_LONG; - if (isByteOrChar(ty)) - return P_TY_BYTE_OR_CHAR; - if (isString(ty)) - return P_TY_STRING; - if (isBool(ty)) - return P_TY_BOOL; - if (isPtr(ty)) - return P_TY_PTR; - throw std::runtime_error("Internal compiler error: Cannot find primitive type of llvm type"); // GCOV_EXCL_LINE -} - -bool OpRuleConversionsManager::isDouble(llvm::Type *ty) { return ty->isDoubleTy(); } - -bool OpRuleConversionsManager::isInt(llvm::Type *ty) { return ty->isIntegerTy(32); } - -bool OpRuleConversionsManager::isShort(llvm::Type *ty) { return ty->isIntegerTy(16); } - -bool OpRuleConversionsManager::isLong(llvm::Type *ty) { return ty->isIntegerTy(64); } - -bool OpRuleConversionsManager::isByteOrChar(llvm::Type *ty) { return ty->isIntegerTy(8); } - -bool OpRuleConversionsManager::isString(llvm::Type *ty) { - return ty->isPointerTy() && ty->getPointerElementType()->isIntegerTy(8); -} - -bool OpRuleConversionsManager::isBool(llvm::Type *ty) { return ty->isIntegerTy(1); } - -bool OpRuleConversionsManager::isPtr(llvm::Type *ty) { return ty->isPointerTy(); } \ No newline at end of file +} \ No newline at end of file diff --git a/src/generator/OpRuleConversionsManager.h b/src/generator/OpRuleConversionsManager.h index 30e97ff28..138249230 100644 --- a/src/generator/OpRuleConversionsManager.h +++ b/src/generator/OpRuleConversionsManager.h @@ -4,73 +4,68 @@ #include -#include +#include -#include #include // Forward declarations class ErrorFactory; struct CodeLoc; -enum OpRuleType { P_TY_DOUBLE, P_TY_INT, P_TY_SHORT, P_TY_LONG, P_TY_BYTE_OR_CHAR, P_TY_STRING, P_TY_BOOL, P_TY_PTR }; - #define COMB(en1, en2) ((en1) | ((en2) << 16)) class OpRuleConversionsManager { public: - explicit OpRuleConversionsManager(std::shared_ptr> builder, const ErrorFactory *errorFactory) - : err(errorFactory), builder(std::move(builder)) {} + explicit OpRuleConversionsManager(const std::shared_ptr &context, std::shared_ptr> builder, + const ErrorFactory *errorFactory) + : context(context), builder(std::move(builder)), err(errorFactory) {} // Public methods - llvm::Value *getPlusEqualInst(llvm::Value *lhs, llvm::Value *rhs, const CodeLoc &codeLoc); - llvm::Value *getMinusEqualInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getMulEqualInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getDivEqualInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getRemEqualInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getSHLEqualInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getSHREqualInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getAndEqualInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getOrEqualInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getXorEqualInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getBitwiseAndInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getBitwiseOrInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getBitwiseXorInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getEqualInst(llvm::Value *lhs, llvm::Value *rhs, const CodeLoc &codeLoc); - llvm::Value *getNotEqualInst(llvm::Value *lhs, llvm::Value *rhs, const CodeLoc &codeLoc); - llvm::Value *getLessInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getGreaterInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getLessEqualInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getGreaterEqualInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getShiftLeftInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getShiftRightInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getPlusInst(llvm::Value *lhs, llvm::Value *rhs, const CodeLoc &codeLoc); - llvm::Value *getMinusInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getMulInst(llvm::Value *lhs, llvm::Value *rhs, const CodeLoc &codeLoc); - llvm::Value *getDivInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getRemInst(llvm::Value *lhs, llvm::Value *rhs); - llvm::Value *getPrefixMinusInst(llvm::Value *lhs); - llvm::Value *getPrefixPlusPlusInst(llvm::Value *lhs); - llvm::Value *getPrefixMinusMinusInst(llvm::Value *lhs); - llvm::Value *getPrefixNotInst(llvm::Value *lhs); - llvm::Value *getPrefixBitwiseNotInst(llvm::Value *lhs); - llvm::Value *getPostfixPlusPlusInst(llvm::Value *lhs); - llvm::Value *getPostfixMinusMinusInst(llvm::Value *lhs); - llvm::Value *getCastInst(llvm::Type *, llvm::Value *lhs); - static bool isDouble(llvm::Type *llvmType); - static bool isInt(llvm::Type *llvmType); - static bool isShort(llvm::Type *llvmType); - static bool isLong(llvm::Type *llvmType); - static bool isByteOrChar(llvm::Type *llvmType); - static bool isString(llvm::Type *llvmType); - static bool isBool(llvm::Type *llvmType); - static bool isPtr(llvm::Type *ty); + llvm::Value *getPlusEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy, + SymbolTable *accessScope, const CodeLoc &codeLoc); + llvm::Value *getMinusEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy, + SymbolTable *accessScope); + llvm::Value *getMulEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getDivEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getRemEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getSHLEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getSHREqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getAndEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getOrEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getXorEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getBitwiseAndInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getBitwiseOrInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getBitwiseXorInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy, + const CodeLoc &codeLoc); + llvm::Value *getNotEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy, + const CodeLoc &codeLoc); + llvm::Value *getLessInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getGreaterInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getLessEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getGreaterEqualInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getShiftLeftInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getShiftRightInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getPlusInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy, + SymbolTable *accessScope, const CodeLoc &codeLoc); + llvm::Value *getMinusInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy, + SymbolTable *accessScope); + llvm::Value *getMulInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy, + const CodeLoc &codeLoc); + llvm::Value *getDivInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getRemInst(llvm::Value *lhs, llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy); + llvm::Value *getPrefixMinusInst(llvm::Value *lhs, const SymbolType &lhsTy); + llvm::Value *getPrefixPlusPlusInst(llvm::Value *lhs, const SymbolType &lhsTy); + llvm::Value *getPrefixMinusMinusInst(llvm::Value *lhs, const SymbolType &lhsTy); + llvm::Value *getPrefixNotInst(llvm::Value *lhs, const SymbolType &lhsTy); + llvm::Value *getPrefixBitwiseNotInst(llvm::Value *lhs, const SymbolType &lhsTy); + llvm::Value *getPostfixPlusPlusInst(llvm::Value *lhs, const SymbolType &lhsTy); + llvm::Value *getPostfixMinusMinusInst(llvm::Value *lhs, const SymbolType &lhsTy); + llvm::Value *getCastInst(llvm::Value *rhs, const SymbolType &lhsTy, const SymbolType &rhsTy, SymbolTable *accessScope); private: // Members - const ErrorFactory *err; + const std::shared_ptr &context; std::shared_ptr> builder; - - // Private methods - static OpRuleType getSymbolTypeFromLLVMType(llvm::Type *ty); + const ErrorFactory *err; }; \ No newline at end of file diff --git a/src/parser/AstBuilderVisitor.cpp b/src/parser/AstBuilderVisitor.cpp index 442be074b..f26dfed89 100644 --- a/src/parser/AstBuilderVisitor.cpp +++ b/src/parser/AstBuilderVisitor.cpp @@ -9,7 +9,7 @@ std::any AstBuilderVisitor::visitEntry(SpiceParser::EntryContext *ctx) { auto entryNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { // Create child for the current node antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // MainFctDef @@ -41,7 +41,7 @@ std::any AstBuilderVisitor::visitEntry(SpiceParser::EntryContext *ctx) { std::any AstBuilderVisitor::visitMainFunctionDef(SpiceParser::MainFunctionDefContext *ctx) { auto mainFctDefNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) { // ArgLstDef currentNode = mainFctDefNode->createChild(CodeLoc(fileName, rule->start)); @@ -70,7 +70,7 @@ std::any AstBuilderVisitor::visitFunctionDef(SpiceParser::FunctionDefContext *ct fctDefNode->isMethod = true; } - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // DeclSpecifiers currentNode = fctDefNode->createChild(CodeLoc(fileName, rule->start)); @@ -106,7 +106,7 @@ std::any AstBuilderVisitor::visitProcedureDef(SpiceParser::ProcedureDefContext * procDefNode->isMethod = true; } - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // DeclSpecifiers currentNode = procDefNode->createChild(CodeLoc(fileName, rule->start)); @@ -135,7 +135,7 @@ std::any AstBuilderVisitor::visitStructDef(SpiceParser::StructDefContext *ctx) { // Extract struct name structDefNode->structName = ctx->IDENTIFIER()->getText(); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // DeclSpecifiers currentNode = structDefNode->createChild(CodeLoc(fileName, rule->start)); @@ -161,7 +161,7 @@ std::any AstBuilderVisitor::visitGenericTypeDef(SpiceParser::GenericTypeDefConte // Extract type name genericTypeDefNode->typeName = ctx->IDENTIFIER()->getText(); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // DeclSpecifiers currentNode = genericTypeDefNode->createChild(CodeLoc(fileName, rule->start)); @@ -187,7 +187,7 @@ std::any AstBuilderVisitor::visitGlobalVarDef(SpiceParser::GlobalVarDefContext * // Extract negative globalVarDefNode->negative = ctx->MINUS(); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // DeclSpecifiers currentNode = globalVarDefNode->createChild(CodeLoc(fileName, rule->start)); @@ -212,7 +212,7 @@ std::any AstBuilderVisitor::visitExtDecl(SpiceParser::ExtDeclContext *ctx) { // Extract function name extDeclNode->extFunctionName = ctx->IDENTIFIER()->getText(); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // DataType currentNode = extDeclNode->createChild(CodeLoc(fileName, rule->start)); @@ -234,7 +234,7 @@ std::any AstBuilderVisitor::visitExtDecl(SpiceParser::ExtDeclContext *ctx) { std::any AstBuilderVisitor::visitThreadDef(SpiceParser::ThreadDefContext *ctx) { auto threadDefNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // StmtLst currentNode = threadDefNode->createChild(CodeLoc(fileName, rule->start)); @@ -252,7 +252,7 @@ std::any AstBuilderVisitor::visitThreadDef(SpiceParser::ThreadDefContext *ctx) { std::any AstBuilderVisitor::visitUnsafeBlockDef(SpiceParser::UnsafeBlockDefContext *ctx) { auto unsafeBlockDefNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // StmtLst currentNode = unsafeBlockDefNode->createChild(CodeLoc(fileName, rule->start)); @@ -270,7 +270,7 @@ std::any AstBuilderVisitor::visitUnsafeBlockDef(SpiceParser::UnsafeBlockDefConte std::any AstBuilderVisitor::visitForLoop(SpiceParser::ForLoopContext *ctx) { auto forLoopNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // ForHead visit(rule); @@ -290,7 +290,7 @@ std::any AstBuilderVisitor::visitForLoop(SpiceParser::ForLoopContext *ctx) { std::any AstBuilderVisitor::visitForHead(SpiceParser::ForHeadContext *ctx) { auto forLoopNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // DeclStmt currentNode = forLoopNode->createChild(CodeLoc(fileName, rule->start)); @@ -310,7 +310,7 @@ std::any AstBuilderVisitor::visitForHead(SpiceParser::ForHeadContext *ctx) { std::any AstBuilderVisitor::visitForeachLoop(SpiceParser::ForeachLoopContext *ctx) { auto foreachLoopNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // ForeachHead visit(rule); @@ -330,7 +330,7 @@ std::any AstBuilderVisitor::visitForeachLoop(SpiceParser::ForeachLoopContext *ct std::any AstBuilderVisitor::visitForeachHead(SpiceParser::ForeachHeadContext *ctx) { auto foreachLoopNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // DeclStmt currentNode = foreachLoopNode->createChild(CodeLoc(fileName, rule->start)); @@ -350,7 +350,7 @@ std::any AstBuilderVisitor::visitForeachHead(SpiceParser::ForeachHeadContext *ct std::any AstBuilderVisitor::visitWhileLoop(SpiceParser::WhileLoopContext *ctx) { auto whileLoopNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // AssignExpr currentNode = whileLoopNode->createChild(CodeLoc(fileName, rule->start)); @@ -370,7 +370,7 @@ std::any AstBuilderVisitor::visitWhileLoop(SpiceParser::WhileLoopContext *ctx) { std::any AstBuilderVisitor::visitIfStmt(SpiceParser::IfStmtContext *ctx) { auto ifStmtNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // AssignExpr currentNode = ifStmtNode->createChild(CodeLoc(fileName, rule->start)); @@ -392,7 +392,7 @@ std::any AstBuilderVisitor::visitIfStmt(SpiceParser::IfStmtContext *ctx) { std::any AstBuilderVisitor::visitElseStmt(SpiceParser::ElseStmtContext *ctx) { auto elseStmtNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) { // IfStmt currentNode = elseStmtNode->createChild(CodeLoc(fileName, rule->start)); @@ -413,7 +413,7 @@ std::any AstBuilderVisitor::visitElseStmt(SpiceParser::ElseStmtContext *ctx) { std::any AstBuilderVisitor::visitAssertStmt(SpiceParser::AssertStmtContext *ctx) { auto assertStmtNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) { // AssignExpr currentNode = assertStmtNode->createChild(CodeLoc(fileName, rule->start)); @@ -431,7 +431,7 @@ std::any AstBuilderVisitor::visitAssertStmt(SpiceParser::AssertStmtContext *ctx) std::any AstBuilderVisitor::visitStmtLst(SpiceParser::StmtLstContext *ctx) { auto stmtLstNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // Stmt currentNode = stmtLstNode->createChild(CodeLoc(fileName, rule->start)); @@ -463,7 +463,7 @@ std::any AstBuilderVisitor::visitStmtLst(SpiceParser::StmtLstContext *ctx) { std::any AstBuilderVisitor::visitTypeLst(SpiceParser::TypeLstContext *ctx) { auto typeLstNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) { // DataType currentNode = typeLstNode->createChild(CodeLoc(fileName, rule->start)); @@ -482,7 +482,7 @@ std::any AstBuilderVisitor::visitTypeLst(SpiceParser::TypeLstContext *ctx) { std::any AstBuilderVisitor::visitTypeAltsLst(SpiceParser::TypeAltsLstContext *ctx) { auto typeAltsLstNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) { // DataType currentNode = typeAltsLstNode->createChild(CodeLoc(fileName, rule->start)); @@ -501,7 +501,7 @@ std::any AstBuilderVisitor::visitTypeAltsLst(SpiceParser::TypeAltsLstContext *ct std::any AstBuilderVisitor::visitParamLst(SpiceParser::ParamLstContext *ctx) { auto argLstDefNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // DeclStmt currentNode = argLstDefNode->createChild(CodeLoc(fileName, rule->start)); @@ -519,7 +519,7 @@ std::any AstBuilderVisitor::visitParamLst(SpiceParser::ParamLstContext *ctx) { std::any AstBuilderVisitor::visitArgLst(SpiceParser::ArgLstContext *ctx) { auto argLstNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // AssignStmt currentNode = argLstNode->createChild(CodeLoc(fileName, rule->start)); @@ -540,7 +540,7 @@ std::any AstBuilderVisitor::visitField(SpiceParser::FieldContext *ctx) { // Extract field name fieldNode->name = ctx->IDENTIFIER()->getText(); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // DeclSpecifiers currentNode = fieldNode->createChild(CodeLoc(fileName, rule->start)); @@ -560,7 +560,7 @@ std::any AstBuilderVisitor::visitField(SpiceParser::FieldContext *ctx) { std::any AstBuilderVisitor::visitStmt(SpiceParser::StmtContext *ctx) { auto stmtNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // DeclStmt currentNode = stmtNode->createChild(CodeLoc(fileName, rule->start)); @@ -589,7 +589,7 @@ std::any AstBuilderVisitor::visitDeclStmt(SpiceParser::DeclStmtContext *ctx) { // Extract var name declStmtNode->varName = ctx->IDENTIFIER()->getText(); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // DeclSpecifiers currentNode = declStmtNode->createChild(CodeLoc(fileName, rule->start)); @@ -612,7 +612,7 @@ std::any AstBuilderVisitor::visitDeclStmt(SpiceParser::DeclStmtContext *ctx) { std::any AstBuilderVisitor::visitSpecifierLst(SpiceParser::SpecifierLstContext *ctx) { auto specifierLstNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // DeclSpecifier currentNode = specifierLstNode->createChild(CodeLoc(fileName, rule->start)); @@ -630,7 +630,7 @@ std::any AstBuilderVisitor::visitSpecifierLst(SpiceParser::SpecifierLstContext * std::any AstBuilderVisitor::visitSpecifier(SpiceParser::SpecifierContext *ctx) { auto specifierNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { auto token = dynamic_cast(subTree); assert(token != nullptr); size_t symbolType = token->getSymbol()->getType(); @@ -666,7 +666,7 @@ std::any AstBuilderVisitor::visitImportStmt(SpiceParser::ImportStmtContext *ctx) std::any AstBuilderVisitor::visitReturnStmt(SpiceParser::ReturnStmtContext *ctx) { auto returnStmtNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) { // AssignExpr currentNode = returnStmtNode->createChild(CodeLoc(fileName, rule->start)); @@ -703,7 +703,7 @@ std::any AstBuilderVisitor::visitContinueStmt(SpiceParser::ContinueStmtContext * std::any AstBuilderVisitor::visitBuiltinCall(SpiceParser::BuiltinCallContext *ctx) { auto atomicExprNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // PrintfCall currentNode = atomicExprNode->createChild(CodeLoc(fileName, rule->start)); @@ -735,7 +735,7 @@ std::any AstBuilderVisitor::visitPrintfCall(SpiceParser::PrintfCallContext *ctx) replaceEscapeChars(templatedString); printfCallNode->templatedString = templatedString; - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // AssignExpr currentNode = printfCallNode->createChild(CodeLoc(fileName, rule->start)); @@ -756,7 +756,7 @@ std::any AstBuilderVisitor::visitSizeOfCall(SpiceParser::SizeOfCallContext *ctx) // Check if type or value sizeofCallNode->isType = ctx->TYPE(); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // AssignExpr currentNode = sizeofCallNode->createChild(CodeLoc(fileName, rule->start)); @@ -776,7 +776,7 @@ std::any AstBuilderVisitor::visitSizeOfCall(SpiceParser::SizeOfCallContext *ctx) std::any AstBuilderVisitor::visitLenCall(SpiceParser::LenCallContext *ctx) { auto lenCallNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // AssignExpr currentNode = lenCallNode->createChild(CodeLoc(fileName, rule->start)); @@ -796,7 +796,7 @@ std::any AstBuilderVisitor::visitTidCall(SpiceParser::TidCallContext *ctx) { ret std::any AstBuilderVisitor::visitJoinCall(SpiceParser::JoinCallContext *ctx) { auto joinCallNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // AssignExpr currentNode = joinCallNode->createChild(CodeLoc(fileName, rule->start)); @@ -814,7 +814,7 @@ std::any AstBuilderVisitor::visitJoinCall(SpiceParser::JoinCallContext *ctx) { std::any AstBuilderVisitor::visitAssignExpr(SpiceParser::AssignExprContext *ctx) { auto assignExprNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // PrefixUnaryExpr currentNode = assignExprNode->createChild(CodeLoc(fileName, rule->start)); @@ -840,7 +840,7 @@ std::any AstBuilderVisitor::visitAssignExpr(SpiceParser::AssignExprContext *ctx) std::any AstBuilderVisitor::visitTernaryExpr(SpiceParser::TernaryExprContext *ctx) { auto ternaryExprNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // LogicalOrExpr currentNode = ternaryExprNode->createChild(CodeLoc(fileName, rule->start)); @@ -858,7 +858,7 @@ std::any AstBuilderVisitor::visitTernaryExpr(SpiceParser::TernaryExprContext *ct std::any AstBuilderVisitor::visitLogicalOrExpr(SpiceParser::LogicalOrExprContext *ctx) { auto logicalOrExprNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // LogicalAndExpr currentNode = logicalOrExprNode->createChild(CodeLoc(fileName, rule->start)); @@ -876,7 +876,7 @@ std::any AstBuilderVisitor::visitLogicalOrExpr(SpiceParser::LogicalOrExprContext std::any AstBuilderVisitor::visitLogicalAndExpr(SpiceParser::LogicalAndExprContext *ctx) { auto logicalAndExprNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // BitwiseOr currentNode = logicalAndExprNode->createChild(CodeLoc(fileName, rule->start)); @@ -894,7 +894,7 @@ std::any AstBuilderVisitor::visitLogicalAndExpr(SpiceParser::LogicalAndExprConte std::any AstBuilderVisitor::visitBitwiseOrExpr(SpiceParser::BitwiseOrExprContext *ctx) { auto bitwiseOrExprNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // BitwiseXor currentNode = bitwiseOrExprNode->createChild(CodeLoc(fileName, rule->start)); @@ -912,7 +912,7 @@ std::any AstBuilderVisitor::visitBitwiseOrExpr(SpiceParser::BitwiseOrExprContext std::any AstBuilderVisitor::visitBitwiseXorExpr(SpiceParser::BitwiseXorExprContext *ctx) { auto bitwiseXorExprNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // BitwiseAnd currentNode = bitwiseXorExprNode->createChild(CodeLoc(fileName, rule->start)); @@ -930,7 +930,7 @@ std::any AstBuilderVisitor::visitBitwiseXorExpr(SpiceParser::BitwiseXorExprConte std::any AstBuilderVisitor::visitBitwiseAndExpr(SpiceParser::BitwiseAndExprContext *ctx) { auto bitwiseAndExprNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // EqualityExpr currentNode = bitwiseAndExprNode->createChild(CodeLoc(fileName, rule->start)); @@ -954,7 +954,7 @@ std::any AstBuilderVisitor::visitEqualityExpr(SpiceParser::EqualityExprContext * else if (ctx->NOT_EQUAL()) equalityExprNode->op = EqualityExprNode::OP_NOT_EQUAL; - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // RelationalExpr currentNode = equalityExprNode->createChild(CodeLoc(fileName, rule->start)); @@ -982,7 +982,7 @@ std::any AstBuilderVisitor::visitRelationalExpr(SpiceParser::RelationalExprConte else if (ctx->GREATER_EQUAL()) relationalExprNode->op = RelationalExprNode::OP_GREATER_EQUAL; - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // ShiftExpr currentNode = relationalExprNode->createChild(CodeLoc(fileName, rule->start)); @@ -1006,7 +1006,7 @@ std::any AstBuilderVisitor::visitShiftExpr(SpiceParser::ShiftExprContext *ctx) { else if (!ctx->GREATER().empty()) shiftExprNode->op = ShiftExprNode::OP_SHIFT_RIGHT; - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // AdditiveExpr currentNode = shiftExprNode->createChild(CodeLoc(fileName, rule->start)); @@ -1024,14 +1024,14 @@ std::any AstBuilderVisitor::visitShiftExpr(SpiceParser::ShiftExprContext *ctx) { std::any AstBuilderVisitor::visitAdditiveExpr(SpiceParser::AdditiveExprContext *ctx) { auto additiveExprNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // MultiplicativeExpr currentNode = additiveExprNode->createChild(CodeLoc(fileName, rule->start)); else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::PLUS) - additiveExprNode->opQueue.push(AdditiveExprNode::OP_PLUS); + additiveExprNode->opQueue.emplace(AdditiveExprNode::OP_PLUS, SymbolType(TY_INVALID)); else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::MINUS) - additiveExprNode->opQueue.push(AdditiveExprNode::OP_MINUS); + additiveExprNode->opQueue.emplace(AdditiveExprNode::OP_MINUS, SymbolType(TY_INVALID)); else assert(dynamic_cast(subTree)); // Fail if we did not get a terminal @@ -1046,14 +1046,14 @@ std::any AstBuilderVisitor::visitAdditiveExpr(SpiceParser::AdditiveExprContext * std::any AstBuilderVisitor::visitMultiplicativeExpr(SpiceParser::MultiplicativeExprContext *ctx) { auto multiplicativeExprNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // CastExpr currentNode = multiplicativeExprNode->createChild(CodeLoc(fileName, rule->start)); else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::MUL) - multiplicativeExprNode->opQueue.push(MultiplicativeExprNode::OP_MUL); + multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::OP_MUL, SymbolType(TY_INVALID)); else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::DIV) - multiplicativeExprNode->opQueue.push(MultiplicativeExprNode::OP_DIV); + multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::OP_DIV, SymbolType(TY_INVALID)); else assert(dynamic_cast(subTree)); // Fail if we did not get a terminal @@ -1068,7 +1068,7 @@ std::any AstBuilderVisitor::visitMultiplicativeExpr(SpiceParser::MultiplicativeE std::any AstBuilderVisitor::visitCastExpr(SpiceParser::CastExprContext *ctx) { auto castExprNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // PrefixUnaryExpr currentNode = castExprNode->createChild(CodeLoc(fileName, rule->start)); @@ -1089,7 +1089,7 @@ std::any AstBuilderVisitor::visitCastExpr(SpiceParser::CastExprContext *ctx) { std::any AstBuilderVisitor::visitPrefixUnaryExpr(SpiceParser::PrefixUnaryExprContext *ctx) { auto prefixUnaryExprNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // PrefixUnaryOp visit(rule); @@ -1109,7 +1109,7 @@ std::any AstBuilderVisitor::visitPrefixUnaryExpr(SpiceParser::PrefixUnaryExprCon std::any AstBuilderVisitor::visitPostfixUnaryExpr(SpiceParser::PostfixUnaryExprContext *ctx) { auto postfixUnaryExprNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // AtomicExpr currentNode = postfixUnaryExprNode->createChild(CodeLoc(fileName, rule->start)); @@ -1118,13 +1118,13 @@ std::any AstBuilderVisitor::visitPostfixUnaryExpr(SpiceParser::PostfixUnaryExprC else if (rule = dynamic_cast(subTree); rule != nullptr) // PostfixUnaryExpr currentNode = postfixUnaryExprNode->createChild(CodeLoc(fileName, rule->start)); else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::LBRACKET) - postfixUnaryExprNode->opQueue.push(PostfixUnaryExprNode::OP_SUBSCRIPT); + postfixUnaryExprNode->opQueue.emplace(PostfixUnaryExprNode::OP_SUBSCRIPT, SymbolType(TY_INVALID)); else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::DOT) - postfixUnaryExprNode->opQueue.push(PostfixUnaryExprNode::OP_MEMBER_ACCESS); + postfixUnaryExprNode->opQueue.emplace(PostfixUnaryExprNode::OP_MEMBER_ACCESS, SymbolType(TY_INVALID)); else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::PLUS_PLUS) - postfixUnaryExprNode->opQueue.push(PostfixUnaryExprNode::OP_PLUS_PLUS); + postfixUnaryExprNode->opQueue.emplace(PostfixUnaryExprNode::OP_PLUS_PLUS, SymbolType(TY_INVALID)); else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::MINUS_MINUS) - postfixUnaryExprNode->opQueue.push(PostfixUnaryExprNode::OP_MINUS_MINUS); + postfixUnaryExprNode->opQueue.emplace(PostfixUnaryExprNode::OP_MINUS_MINUS, SymbolType(TY_INVALID)); else assert(dynamic_cast(subTree)); // Fail if we did not get a terminal @@ -1139,7 +1139,7 @@ std::any AstBuilderVisitor::visitPostfixUnaryExpr(SpiceParser::PostfixUnaryExprC std::any AstBuilderVisitor::visitAtomicExpr(SpiceParser::AtomicExprContext *ctx) { auto atomicExprNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // Value currentNode = atomicExprNode->createChild(CodeLoc(fileName, rule->start)); @@ -1163,7 +1163,7 @@ std::any AstBuilderVisitor::visitAtomicExpr(SpiceParser::AtomicExprContext *ctx) std::any AstBuilderVisitor::visitValue(SpiceParser::ValueContext *ctx) { auto valueNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // PrimitiveValue currentNode = valueNode->createChild(CodeLoc(fileName, rule->start)); @@ -1190,7 +1190,7 @@ std::any AstBuilderVisitor::visitValue(SpiceParser::ValueContext *ctx) { std::any AstBuilderVisitor::visitPrimitiveValue(SpiceParser::PrimitiveValueContext *ctx) { auto primitiveValueNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::DOUBLE_LIT) { primitiveValueNode->type = PrimitiveValueNode::TY_DOUBLE; @@ -1236,7 +1236,7 @@ std::any AstBuilderVisitor::visitPrimitiveValue(SpiceParser::PrimitiveValueConte std::any AstBuilderVisitor::visitFunctionCall(SpiceParser::FunctionCallContext *ctx) { auto fctCallNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) { // TypeLst currentNode = fctCallNode->createChild(CodeLoc(fileName, rule->start)); @@ -1265,7 +1265,7 @@ std::any AstBuilderVisitor::visitFunctionCall(SpiceParser::FunctionCallContext * std::any AstBuilderVisitor::visitArrayInitialization(SpiceParser::ArrayInitializationContext *ctx) { auto arrayInitializationNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // ArgLst currentNode = arrayInitializationNode->createChild(CodeLoc(fileName, rule->start)); @@ -1283,7 +1283,7 @@ std::any AstBuilderVisitor::visitArrayInitialization(SpiceParser::ArrayInitializ std::any AstBuilderVisitor::visitStructInstantiation(SpiceParser::StructInstantiationContext *ctx) { auto structInstantiationNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // TypeLst currentNode = structInstantiationNode->createChild(CodeLoc(fileName, rule->start)); @@ -1349,7 +1349,7 @@ std::any AstBuilderVisitor::visitDataType(SpiceParser::DataTypeContext *ctx) { std::any AstBuilderVisitor::visitBaseDataType(SpiceParser::BaseDataTypeContext *ctx) { auto baseDataTypeNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) { // CustomDataType baseDataTypeNode->type = BaseDataTypeNode::TY_CUSTOM; @@ -1387,7 +1387,7 @@ std::any AstBuilderVisitor::visitBaseDataType(SpiceParser::BaseDataTypeContext * std::any AstBuilderVisitor::visitCustomDataType(SpiceParser::CustomDataTypeContext *ctx) { auto customDataTypeNode = dynamic_cast(currentNode); - for (auto subTree : ctx->children) { + for (const auto &subTree : ctx->children) { antlr4::ParserRuleContext *rule; if (rule = dynamic_cast(subTree); rule != nullptr) // TypeLst currentNode = customDataTypeNode->createChild(CodeLoc(fileName, rule->start)); @@ -1447,29 +1447,29 @@ std::any AstBuilderVisitor::visitPrefixUnaryOp(SpiceParser::PrefixUnaryOpContext // Extract assign operator if (ctx->MINUS()) - prefixUnaryExprNode->opStack.push(PrefixUnaryExprNode::OP_MINUS); + prefixUnaryExprNode->opStack.emplace(PrefixUnaryExprNode::OP_MINUS, SymbolType(TY_INVALID)); else if (ctx->PLUS_PLUS()) - prefixUnaryExprNode->opStack.push(PrefixUnaryExprNode::OP_PLUS_PLUS); + prefixUnaryExprNode->opStack.emplace(PrefixUnaryExprNode::OP_PLUS_PLUS, SymbolType(TY_INVALID)); else if (ctx->MINUS_MINUS()) - prefixUnaryExprNode->opStack.push(PrefixUnaryExprNode::OP_MINUS_MINUS); + prefixUnaryExprNode->opStack.emplace(PrefixUnaryExprNode::OP_MINUS_MINUS, SymbolType(TY_INVALID)); else if (ctx->NOT()) - prefixUnaryExprNode->opStack.push(PrefixUnaryExprNode::OP_NOT); + prefixUnaryExprNode->opStack.emplace(PrefixUnaryExprNode::OP_NOT, SymbolType(TY_INVALID)); else if (ctx->BITWISE_NOT()) - prefixUnaryExprNode->opStack.push(PrefixUnaryExprNode::OP_BITWISE_NOT); + prefixUnaryExprNode->opStack.emplace(PrefixUnaryExprNode::OP_BITWISE_NOT, SymbolType(TY_INVALID)); else if (ctx->MUL()) - prefixUnaryExprNode->opStack.push(PrefixUnaryExprNode::OP_INDIRECTION); + prefixUnaryExprNode->opStack.emplace(PrefixUnaryExprNode::OP_INDIRECTION, SymbolType(TY_INVALID)); else if (ctx->BITWISE_AND()) - prefixUnaryExprNode->opStack.push(PrefixUnaryExprNode::OP_ADDRESS_OF); + prefixUnaryExprNode->opStack.emplace(PrefixUnaryExprNode::OP_ADDRESS_OF, SymbolType(TY_INVALID)); else if (ctx->LOGICAL_AND()) { - prefixUnaryExprNode->opStack.push(PrefixUnaryExprNode::OP_ADDRESS_OF); - prefixUnaryExprNode->opStack.push(PrefixUnaryExprNode::OP_ADDRESS_OF); + prefixUnaryExprNode->opStack.emplace(PrefixUnaryExprNode::OP_ADDRESS_OF, SymbolType(TY_INVALID)); + prefixUnaryExprNode->opStack.emplace(PrefixUnaryExprNode::OP_ADDRESS_OF, SymbolType(TY_INVALID)); } else assert(false); return nullptr; } -void AstBuilderVisitor::replaceEscapeChars(std::string &string) const { +void AstBuilderVisitor::replaceEscapeChars(std::string &string) { CommonUtil::replaceAll(string, "\\a", "\a"); CommonUtil::replaceAll(string, "\\b", "\b"); CommonUtil::replaceAll(string, "\\f", "\f"); diff --git a/src/parser/AstBuilderVisitor.h b/src/parser/AstBuilderVisitor.h index 85f098c17..078ed3c16 100644 --- a/src/parser/AstBuilderVisitor.h +++ b/src/parser/AstBuilderVisitor.h @@ -86,5 +86,5 @@ class AstBuilderVisitor : public SpiceVisitor { std::string fileName; // Private methods - void replaceEscapeChars(std::string &string) const; + static void replaceEscapeChars(std::string &string); }; \ No newline at end of file diff --git a/src/symbol/Function.cpp b/src/symbol/Function.cpp index 7ba485cab..72f24f2e3 100644 --- a/src/symbol/Function.cpp +++ b/src/symbol/Function.cpp @@ -80,7 +80,7 @@ std::string Function::getMangledName() const { size_t startPos = baseSubType.find_last_of('.'); startPos = startPos == std::string::npos ? 0 : startPos + 1; thisTyStr = baseSubType.substr(startPos); - for (auto &templateType : thisType.getTemplateTypes()) + for (const auto &templateType : thisType.getTemplateTypes()) thisTyStr += "_" + templateType.getName(false, true); } diff --git a/src/symbol/SymbolTable.cpp b/src/symbol/SymbolTable.cpp index 75c374093..c20a11744 100644 --- a/src/symbol/SymbolTable.cpp +++ b/src/symbol/SymbolTable.cpp @@ -304,6 +304,21 @@ std::map &SymbolTable::getSymbols() { return symb */ std::map &SymbolTable::getCaptures() { return captures; } +/** + * Get the number of fields if this is a struct scope + * + * @return Number of fields + */ +size_t SymbolTable::getFieldCount() const { + assert(scopeType == SCOPE_STRUCT); + size_t fieldCount = 0; + for (auto &symbol : symbols) { + if (!symbol.second.getType().isOneOf({TY_FUNCTION, TY_PROCEDURE, TY_IMPORT, TY_INVALID, TY_GENERIC})) + fieldCount++; + } + return fieldCount; +} + /** * Insert a function object into this symbol table scope * @@ -428,7 +443,8 @@ Function *SymbolTable::matchFunction(SymbolTable *currentScope, const std::strin if ((f.isMethodFunction() || f.isMethodProcedure()) && !fctThisType.getTemplateTypes().empty()) { SymbolTableEntry *thisEntry = childBlock->lookup(THIS_VARIABLE_NAME); assert(thisEntry != nullptr); - thisEntry->updateType(callThisType.toPointer(err, codeLoc), true); + SymbolType newThisType = callThisType.toPointer(err, codeLoc); + thisEntry->updateType(newThisType, true); } } diff --git a/src/symbol/SymbolTable.h b/src/symbol/SymbolTable.h index 527607f03..f0122f1e9 100644 --- a/src/symbol/SymbolTable.h +++ b/src/symbol/SymbolTable.h @@ -70,6 +70,7 @@ class SymbolTable { std::map &getSymbols(); std::map &getCaptures(); + [[nodiscard]] size_t getFieldCount() const; void insertFunction(const Function &function, ErrorFactory *err); Function *matchFunction(SymbolTable *currentScope, const std::string &callFunctionName, const SymbolType &callThisType, diff --git a/src/symbol/SymbolTableEntry.cpp b/src/symbol/SymbolTableEntry.cpp index 159cf345c..04f35f61d 100644 --- a/src/symbol/SymbolTableEntry.cpp +++ b/src/symbol/SymbolTableEntry.cpp @@ -80,18 +80,24 @@ void SymbolTableEntry::updateState(SymbolState newState, const ErrorFactory *err const CodeLoc &SymbolTableEntry::getDeclCodeLoc() const { return declCodeLoc; } /** - * Retrieve the llvm type of the current symbol + * Retrieve the llvm type of the current struct symbol * - * @return LLVM type of the current symbol + * @return LLVM type of the current struct symbol */ -llvm::Type *SymbolTableEntry::getLLVMType() const { return llvmType; } +llvm::Type *SymbolTableEntry::getStructLLVMType() const { + assert(type.is(TY_STRUCT)); + return llvmType; +} /** - * Update the LLVM type of a symbol + * Update the struct LLVM type of a symbol * - * @param newType New LLVM type + * @param newStructType New struct LLVM type */ -void SymbolTableEntry::updateLLVMType(llvm::Type *newType) { llvmType = newType; } +void SymbolTableEntry::setStructLLVMType(llvm::Type *newStructType) { + assert(type.is(TY_STRUCT)); + llvmType = newStructType; +} /** * Retrieve the address of the assigned value @@ -128,7 +134,7 @@ void SymbolTableEntry::popAddress() { memAddress.pop(); } * * @return Order index */ -unsigned int SymbolTableEntry::getOrderIndex() const { return orderIndex; } +size_t SymbolTableEntry::getOrderIndex() const { return orderIndex; } /** * Returns if the symbol is in a local scope or in the global scope diff --git a/src/symbol/SymbolTableEntry.h b/src/symbol/SymbolTableEntry.h index 58a9e2658..9e568e65c 100644 --- a/src/symbol/SymbolTableEntry.h +++ b/src/symbol/SymbolTableEntry.h @@ -39,13 +39,13 @@ class SymbolTableEntry { [[nodiscard]] SymbolState getState() const; void updateState(SymbolState newState, const ErrorFactory *errorFactory, const CodeLoc &codeLoc, bool force = false); [[nodiscard]] const CodeLoc &getDeclCodeLoc() const; - [[nodiscard]] llvm::Type *getLLVMType() const; - void updateLLVMType(llvm::Type *newType); + [[nodiscard]] llvm::Type *getStructLLVMType() const; + void setStructLLVMType(llvm::Type *newStructType); [[nodiscard]] virtual llvm::Value *getAddress() const; void updateAddress(llvm::Value *address); void pushAddress(llvm::Value *address); void popAddress(); - [[nodiscard]] unsigned int getOrderIndex() const; + [[nodiscard]] size_t getOrderIndex() const; [[nodiscard]] bool isGlobal() const; [[nodiscard]] bool isVolatile() const; void setVolatile(bool volatility = true); @@ -66,7 +66,7 @@ class SymbolTableEntry { // size_t refCount = 0; const CodeLoc &declCodeLoc; std::stack memAddress; - unsigned int orderIndex; + size_t orderIndex; const bool global; bool volatility = false; bool used = false; diff --git a/src/symbol/SymbolType.cpp b/src/symbol/SymbolType.cpp index 7435d6901..c123fa739 100644 --- a/src/symbol/SymbolType.cpp +++ b/src/symbol/SymbolType.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2021-2022 ChilliBits. All rights reserved. #include "SymbolType.h" +#include "analyzer/AnalyzerVisitor.h" #include #include @@ -103,6 +104,8 @@ SymbolType SymbolType::replaceBaseType(const SymbolType &newBaseType) const { /** * Return the LLVM type for this symbol type * + * @param context LLVM context + * @param accessScope Access scope for structs * @return Corresponding LLVM type */ llvm::Type *SymbolType::toLLVMType(llvm::LLVMContext &context, SymbolTable *accessScope) const { @@ -133,7 +136,7 @@ llvm::Type *SymbolType::toLLVMType(llvm::LLVMContext &context, SymbolTable *acce std::string structSignature = Struct::getSignature(getSubType(), getTemplateTypes()); SymbolTableEntry *structSymbol = accessScope->lookup(structSignature); assert(structSymbol); - llvm::Type *structType = structSymbol->getLLVMType(); + llvm::Type *structType = structSymbol->getStructLLVMType(); assert(structType); return structType; } @@ -148,7 +151,6 @@ llvm::Type *SymbolType::toLLVMType(llvm::LLVMContext &context, SymbolTable *acce return static_cast(arrayType); } - assert(!is(TY_GENERIC)); throw std::runtime_error("Internal compiler error: Cannot determine LLVM type of " + getName(true)); } diff --git a/src/symbol/SymbolType.h b/src/symbol/SymbolType.h index 3e41a2281..689a2514e 100644 --- a/src/symbol/SymbolType.h +++ b/src/symbol/SymbolType.h @@ -6,7 +6,10 @@ #include #include +#include +#include #include +#include #include #include diff --git a/src/util/CodeLoc.cpp b/src/util/CodeLoc.cpp index 0a3b86c40..e94c2299b 100644 --- a/src/util/CodeLoc.cpp +++ b/src/util/CodeLoc.cpp @@ -4,4 +4,6 @@ std::string CodeLoc::toString() const { return "L" + std::to_string(line) + "C" + std::to_string(col); } -std::string CodeLoc::toPrettyString() const { return sourceFilePath + ":" + std::to_string(line) + ":" + std::to_string(col); } \ No newline at end of file +std::string CodeLoc::toPrettyString() const { return sourceFilePath + ":" + std::to_string(line) + ":" + std::to_string(col); } + +std::string CodeLoc::toPrettyLine() const { return "l" + std::to_string(line); } \ No newline at end of file diff --git a/src/util/CodeLoc.h b/src/util/CodeLoc.h index 1fd4a541c..0a8afb3d5 100644 --- a/src/util/CodeLoc.h +++ b/src/util/CodeLoc.h @@ -23,4 +23,5 @@ struct CodeLoc { // Public methods [[nodiscard]] std::string toString() const; [[nodiscard]] std::string toPrettyString() const; + [[nodiscard]] std::string toPrettyLine() const; }; \ No newline at end of file diff --git a/test/test-files/generator/arbitrary/success-ackermann/ir-code-O3.ll b/test/test-files/generator/arbitrary/success-ackermann/ir-code-O3.ll index a2ca8df7e..2150545c0 100644 --- a/test/test-files/generator/arbitrary/success-ackermann/ir-code-O3.ll +++ b/test/test-files/generator/arbitrary/success-ackermann/ir-code-O3.ll @@ -7,43 +7,43 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nosync nounwind readnone define internal fastcc i32 @_f__void__ack__int_int(i32 %0, i32 %1) unnamed_addr #0 { -entry: +entry.l1: %2 = icmp eq i32 %0, 0 - br i1 %2, label %if.then, label %if.end + br i1 %2, label %if.then.l2, label %if.end.l2 -if.then: ; preds = %tailrecurse.backedge, %entry - %.tr17.lcssa = phi i32 [ %1, %entry ], [ %.tr17.be, %tailrecurse.backedge ] - %3 = add i32 %.tr17.lcssa, 1 +if.then.l2: ; preds = %tailrecurse.backedge, %entry.l1 + %.tr15.lcssa = phi i32 [ %1, %entry.l1 ], [ %.tr15.be, %tailrecurse.backedge ] + %3 = add i32 %.tr15.lcssa, 1 ret i32 %3 -if.end: ; preds = %entry, %tailrecurse.backedge - %.tr1719 = phi i32 [ %.tr17.be, %tailrecurse.backedge ], [ %1, %entry ] - %.tr18 = phi i32 [ %.tr.be, %tailrecurse.backedge ], [ %0, %entry ] - %4 = icmp eq i32 %.tr1719, 0 - br i1 %4, label %tailrecurse.backedge, label %if.end2 +if.end.l2: ; preds = %entry.l1, %tailrecurse.backedge + %.tr1517 = phi i32 [ %.tr15.be, %tailrecurse.backedge ], [ %1, %entry.l1 ] + %.tr16 = phi i32 [ %.tr.be, %tailrecurse.backedge ], [ %0, %entry.l1 ] + %4 = icmp eq i32 %.tr1517, 0 + br i1 %4, label %tailrecurse.backedge, label %if.end.l3 -tailrecurse.backedge: ; preds = %if.end, %if.end2 - %.tr17.be = phi i32 [ %7, %if.end2 ], [ 1, %if.end ] - %.tr.be = add i32 %.tr18, -1 +tailrecurse.backedge: ; preds = %if.end.l2, %if.end.l3 + %.tr15.be = phi i32 [ %7, %if.end.l3 ], [ 1, %if.end.l2 ] + %.tr.be = add i32 %.tr16, -1 %5 = icmp eq i32 %.tr.be, 0 - br i1 %5, label %if.then, label %if.end + br i1 %5, label %if.then.l2, label %if.end.l2 -if.end2: ; preds = %if.end - %6 = add i32 %.tr1719, -1 - %7 = tail call fastcc i32 @_f__void__ack__int_int(i32 %.tr18, i32 %6) +if.end.l3: ; preds = %if.end.l2 + %6 = add i32 %.tr1517, -1 + %7 = tail call fastcc i32 @_f__void__ack__int_int(i32 %.tr16, i32 %6) br label %tailrecurse.backedge } ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #1 { -entry: +entry.l7: %0 = tail call fastcc i32 @_f__void__ack__int_int(i32 3, i32 12) - %1 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @0, i64 0, i64 0), i32 3, i32 12, i32 %0) + %1 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 3, i32 12, i32 %0) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #1 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1 attributes #0 = { nofree nosync nounwind readnone } attributes #1 = { nofree nounwind } diff --git a/test/test-files/generator/arbitrary/success-ackermann/ir-code.ll b/test/test-files/generator/arbitrary/success-ackermann/ir-code.ll index 8210e4c07..8358cde0a 100644 --- a/test/test-files/generator/arbitrary/success-ackermann/ir-code.ll +++ b/test/test-files/generator/arbitrary/success-ackermann/ir-code.ll @@ -6,7 +6,7 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [36 x i8] c"Ackermann of base m=%d and n=%d: %d\00", align 1 define internal i32 @_f__void__ack__int_int(i32 %0, i32 %1) { -entry: +entry.l1: %m = alloca i32, align 4 %n = alloca i32, align 4 %result = alloca i32, align 4 @@ -20,78 +20,78 @@ entry: %9 = alloca i32, align 4 %10 = alloca i32, align 4 %11 = alloca i32, align 4 - store i32 %0, i32* %m, align 4 - store i32 %1, i32* %n, align 4 - %12 = load i32, i32* %m, align 4 + store i32 %0, ptr %m, align 4 + store i32 %1, ptr %n, align 4 + %12 = load i32, ptr %m, align 4 %13 = icmp eq i32 %12, 0 - store i1 %13, i1* %2, align 1 - %14 = load i1, i1* %2, align 1 - br i1 %14, label %if.then, label %if.end + store i1 %13, ptr %2, align 1 + %14 = load i1, ptr %2, align 1 + br i1 %14, label %if.then.l2, label %if.end.l2 -if.then: ; preds = %entry - %15 = load i32, i32* %n, align 4 +if.then.l2: ; preds = %entry.l1 + %15 = load i32, ptr %n, align 4 %16 = add i32 %15, 1 - store i32 %16, i32* %3, align 4 - %17 = load i32, i32* %3, align 4 + store i32 %16, ptr %3, align 4 + %17 = load i32, ptr %3, align 4 ret i32 %17 -if.end: ; preds = %entry - %18 = load i32, i32* %n, align 4 +if.end.l2: ; preds = %entry.l1 + %18 = load i32, ptr %n, align 4 %19 = icmp eq i32 %18, 0 - store i1 %19, i1* %4, align 1 - %20 = load i1, i1* %4, align 1 - br i1 %20, label %if.then1, label %if.end2 + store i1 %19, ptr %4, align 1 + %20 = load i1, ptr %4, align 1 + br i1 %20, label %if.then.l3, label %if.end.l3 -if.then1: ; preds = %if.end - %21 = load i32, i32* %m, align 4 +if.then.l3: ; preds = %if.end.l2 + %21 = load i32, ptr %m, align 4 %22 = sub i32 %21, 1 - store i32 %22, i32* %5, align 4 - %23 = load i32, i32* %5, align 4 - store i32 1, i32* %6, align 4 - %24 = load i32, i32* %6, align 4 + store i32 %22, ptr %5, align 4 + %23 = load i32, ptr %5, align 4 + store i32 1, ptr %6, align 4 + %24 = load i32, ptr %6, align 4 %25 = call i32 @_f__void__ack__int_int(i32 %23, i32 %24) - store i32 %25, i32* %7, align 4 - %26 = load i32, i32* %7, align 4 + store i32 %25, ptr %7, align 4 + %26 = load i32, ptr %7, align 4 ret i32 %26 -if.end2: ; preds = %if.end - %27 = load i32, i32* %m, align 4 +if.end.l3: ; preds = %if.end.l2 + %27 = load i32, ptr %m, align 4 %28 = sub i32 %27, 1 - store i32 %28, i32* %8, align 4 - %29 = load i32, i32* %8, align 4 - %30 = load i32, i32* %m, align 4 - %31 = load i32, i32* %n, align 4 + store i32 %28, ptr %8, align 4 + %29 = load i32, ptr %8, align 4 + %30 = load i32, ptr %m, align 4 + %31 = load i32, ptr %n, align 4 %32 = sub i32 %31, 1 - store i32 %32, i32* %9, align 4 - %33 = load i32, i32* %9, align 4 + store i32 %32, ptr %9, align 4 + %33 = load i32, ptr %9, align 4 %34 = call i32 @_f__void__ack__int_int(i32 %30, i32 %33) - store i32 %34, i32* %10, align 4 - %35 = load i32, i32* %10, align 4 + store i32 %34, ptr %10, align 4 + %35 = load i32, ptr %10, align 4 %36 = call i32 @_f__void__ack__int_int(i32 %29, i32 %35) - store i32 %36, i32* %11, align 4 - %37 = load i32, i32* %11, align 4 + store i32 %36, ptr %11, align 4 + %37 = load i32, ptr %11, align 4 ret i32 %37 } define i32 @main() { -entry: +entry.l7: %result = alloca i32, align 4 %baseM = alloca i32, align 4 %baseN = alloca i32, align 4 %0 = alloca i32, align 4 - store i32 0, i32* %result, align 4 - store i32 3, i32* %baseM, align 4 - store i32 12, i32* %baseN, align 4 - %1 = load i32, i32* %baseM, align 4 - %2 = load i32, i32* %baseN, align 4 - %3 = load i32, i32* %baseM, align 4 - %4 = load i32, i32* %baseN, align 4 + store i32 0, ptr %result, align 4 + store i32 3, ptr %baseM, align 4 + store i32 12, ptr %baseN, align 4 + %1 = load i32, ptr %baseM, align 4 + %2 = load i32, ptr %baseN, align 4 + %3 = load i32, ptr %baseM, align 4 + %4 = load i32, ptr %baseN, align 4 %5 = call i32 @_f__void__ack__int_int(i32 %3, i32 %4) - store i32 %5, i32* %0, align 4 - %6 = load i32, i32* %0, align 4 - %7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @0, i32 0, i32 0), i32 %1, i32 %2, i32 %6) - %8 = load i32, i32* %result, align 4 + store i32 %5, ptr %0, align 4 + %6 = load i32, ptr %0, align 4 + %7 = call i32 (ptr, ...) @printf(ptr @0, i32 %1, i32 %2, i32 %6) + %8 = load i32, ptr %result, align 4 ret i32 %8 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/arbitrary/success-faculty/ir-code-O3.ll b/test/test-files/generator/arbitrary/success-faculty/ir-code-O3.ll index 05dd5e32a..77df330c8 100644 --- a/test/test-files/generator/arbitrary/success-faculty/ir-code-O3.ll +++ b/test/test-files/generator/arbitrary/success-faculty/ir-code-O3.ll @@ -7,12 +7,12 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #0 { -entry: - %0 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @0, i64 0, i64 0), i32 10, i32 3628800) +entry.l8: + %0 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 10, i32 3628800) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/arbitrary/success-faculty/ir-code.ll b/test/test-files/generator/arbitrary/success-faculty/ir-code.ll index a1d2eead7..561ecf929 100644 --- a/test/test-files/generator/arbitrary/success-faculty/ir-code.ll +++ b/test/test-files/generator/arbitrary/success-faculty/ir-code.ll @@ -6,7 +6,7 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [21 x i8] c"Faculty of %d is: %d\00", align 1 define internal i32 @_f__void__faculty__int(i32 %0) { -entry: +entry.l1: %input = alloca i32, align 4 %result = alloca i32, align 4 %1 = alloca i1, align 1 @@ -14,50 +14,50 @@ entry: %3 = alloca i32, align 4 %4 = alloca i32, align 4 %5 = alloca i32, align 4 - store i32 %0, i32* %input, align 4 - %6 = load i32, i32* %input, align 4 + store i32 %0, ptr %input, align 4 + %6 = load i32, ptr %input, align 4 %7 = icmp slt i32 %6, 2 - store i1 %7, i1* %1, align 1 - %8 = load i1, i1* %1, align 1 - br i1 %8, label %if.then, label %if.end + store i1 %7, ptr %1, align 1 + %8 = load i1, ptr %1, align 1 + br i1 %8, label %if.then.l2, label %if.end.l2 -if.then: ; preds = %entry - store i32 1, i32* %2, align 4 - %9 = load i32, i32* %2, align 4 +if.then.l2: ; preds = %entry.l1 + store i32 1, ptr %2, align 4 + %9 = load i32, ptr %2, align 4 ret i32 %9 -if.end: ; preds = %entry - %10 = load i32, i32* %input, align 4 - %11 = load i32, i32* %input, align 4 +if.end.l2: ; preds = %entry.l1 + %10 = load i32, ptr %input, align 4 + %11 = load i32, ptr %input, align 4 %12 = sub i32 %11, 1 - store i32 %12, i32* %3, align 4 - %13 = load i32, i32* %3, align 4 + store i32 %12, ptr %3, align 4 + %13 = load i32, ptr %3, align 4 %14 = call i32 @_f__void__faculty__int(i32 %13) - store i32 %14, i32* %4, align 4 - %15 = load i32, i32* %4, align 4 + store i32 %14, ptr %4, align 4 + %15 = load i32, ptr %4, align 4 %16 = mul i32 %10, %15 - store i32 %16, i32* %5, align 4 - %17 = load i32, i32* %5, align 4 - store i32 %17, i32* %result, align 4 - %18 = load i32, i32* %result, align 4 + store i32 %16, ptr %5, align 4 + %17 = load i32, ptr %5, align 4 + store i32 %17, ptr %result, align 4 + %18 = load i32, ptr %result, align 4 ret i32 %18 } define i32 @main() { -entry: +entry.l8: %result = alloca i32, align 4 %input = alloca i32, align 4 %0 = alloca i32, align 4 - store i32 0, i32* %result, align 4 - store i32 10, i32* %input, align 4 - %1 = load i32, i32* %input, align 4 + store i32 0, ptr %result, align 4 + store i32 10, ptr %input, align 4 + %1 = load i32, ptr %input, align 4 %2 = call i32 @_f__void__faculty__int(i32 %1) - store i32 %2, i32* %0, align 4 - %3 = load i32, i32* %input, align 4 - %4 = load i32, i32* %0, align 4 - %5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @0, i32 0, i32 0), i32 %3, i32 %4) - %6 = load i32, i32* %result, align 4 + store i32 %2, ptr %0, align 4 + %3 = load i32, ptr %input, align 4 + %4 = load i32, ptr %0, align 4 + %5 = call i32 (ptr, ...) @printf(ptr @0, i32 %3, i32 %4) + %6 = load i32, ptr %result, align 4 ret i32 %6 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/arbitrary/success-fibonacci-threaded/ir-code-O3.ll b/test/test-files/generator/arbitrary/success-fibonacci-threaded/ir-code-O3.ll index 524fa865c..3876486f3 100644 --- a/test/test-files/generator/arbitrary/success-fibonacci-threaded/ir-code-O3.ll +++ b/test/test-files/generator/arbitrary/success-fibonacci-threaded/ir-code-O3.ll @@ -9,87 +9,86 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nosync nounwind readnone define internal fastcc i32 @_f__void__fib__int(i32 %0) unnamed_addr #0 { -entry: +entry.l1: %1 = icmp slt i32 %0, 3 - br i1 %1, label %common.ret, label %if.end + br i1 %1, label %common.ret, label %if.end.l2 -common.ret.loopexit: ; preds = %if.end +common.ret.loopexit: ; preds = %if.end.l2 %phi.bo = add i32 %5, 1 br label %common.ret -common.ret: ; preds = %common.ret.loopexit, %entry - %accumulator.tr.lcssa = phi i32 [ 1, %entry ], [ %phi.bo, %common.ret.loopexit ] +common.ret: ; preds = %common.ret.loopexit, %entry.l1 + %accumulator.tr.lcssa = phi i32 [ 1, %entry.l1 ], [ %phi.bo, %common.ret.loopexit ] ret i32 %accumulator.tr.lcssa -if.end: ; preds = %entry, %if.end - %.tr9 = phi i32 [ %4, %if.end ], [ %0, %entry ] - %accumulator.tr8 = phi i32 [ %5, %if.end ], [ 0, %entry ] +if.end.l2: ; preds = %entry.l1, %if.end.l2 + %.tr9 = phi i32 [ %4, %if.end.l2 ], [ %0, %entry.l1 ] + %accumulator.tr8 = phi i32 [ %5, %if.end.l2 ], [ 0, %entry.l1 ] %2 = add nsw i32 %.tr9, -1 %3 = tail call fastcc i32 @_f__void__fib__int(i32 %2) %4 = add nsw i32 %.tr9, -2 %5 = add i32 %3, %accumulator.tr8 %6 = icmp ult i32 %.tr9, 5 - br i1 %6, label %common.ret.loopexit, label %if.end + br i1 %6, label %common.ret.loopexit, label %if.end.l2 } define i32 @main() local_unnamed_addr { -entry: +entry.l6: %0 = alloca {}, align 8 - %1 = bitcast {}* %0 to i8* - %2 = alloca i8*, align 8 - %3 = call i32 @pthread_create(i8** nonnull %2, i8* null, i8* (i8*)* nonnull @_thread0, i8* nonnull %1) - %4 = load i8*, i8** %2, align 8 - %5 = alloca i8*, align 8 - %6 = call i32 @pthread_create(i8** nonnull %5, i8* null, i8* (i8*)* nonnull @_thread0, i8* nonnull %1) - %7 = load i8*, i8** %5, align 8 - %8 = alloca i8*, align 8 - %9 = call i32 @pthread_create(i8** nonnull %8, i8* null, i8* (i8*)* nonnull @_thread0, i8* nonnull %1) - %10 = load i8*, i8** %8, align 8 - %11 = alloca i8*, align 8 - %12 = call i32 @pthread_create(i8** nonnull %11, i8* null, i8* (i8*)* nonnull @_thread0, i8* nonnull %1) - %13 = load i8*, i8** %11, align 8 - %14 = alloca i8*, align 8 - %15 = call i32 @pthread_create(i8** nonnull %14, i8* null, i8* (i8*)* nonnull @_thread0, i8* nonnull %1) - %16 = load i8*, i8** %14, align 8 - %17 = alloca i8*, align 8 - %18 = call i32 @pthread_create(i8** nonnull %17, i8* null, i8* (i8*)* nonnull @_thread0, i8* nonnull %1) - %19 = load i8*, i8** %17, align 8 - %20 = alloca i8*, align 8 - %21 = call i32 @pthread_create(i8** nonnull %20, i8* null, i8* (i8*)* nonnull @_thread0, i8* nonnull %1) - %22 = load i8*, i8** %20, align 8 - %23 = alloca i8*, align 8 - %24 = call i32 @pthread_create(i8** nonnull %23, i8* null, i8* (i8*)* nonnull @_thread0, i8* nonnull %1) - %25 = load i8*, i8** %23, align 8 - %puts = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0)) - %26 = call i32 @pthread_join(i8* %4, i8** null) - %27 = call i32 @pthread_join(i8* %7, i8** null) - %28 = call i32 @pthread_join(i8* %10, i8** null) - %29 = call i32 @pthread_join(i8* %13, i8** null) - %30 = call i32 @pthread_join(i8* %16, i8** null) - %31 = call i32 @pthread_join(i8* %19, i8** null) - %32 = call i32 @pthread_join(i8* %22, i8** null) - %33 = call i32 @pthread_join(i8* %25, i8** null) - %34 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @1, i64 0, i64 0)) + %1 = alloca ptr, align 8 + %2 = call i32 @pthread_create(ptr nonnull %1, ptr null, ptr nonnull @_thread0, ptr nonnull %0) + %3 = load ptr, ptr %1, align 8 + %4 = alloca ptr, align 8 + %5 = call i32 @pthread_create(ptr nonnull %4, ptr null, ptr nonnull @_thread0, ptr nonnull %0) + %6 = load ptr, ptr %4, align 8 + %7 = alloca ptr, align 8 + %8 = call i32 @pthread_create(ptr nonnull %7, ptr null, ptr nonnull @_thread0, ptr nonnull %0) + %9 = load ptr, ptr %7, align 8 + %10 = alloca ptr, align 8 + %11 = call i32 @pthread_create(ptr nonnull %10, ptr null, ptr nonnull @_thread0, ptr nonnull %0) + %12 = load ptr, ptr %10, align 8 + %13 = alloca ptr, align 8 + %14 = call i32 @pthread_create(ptr nonnull %13, ptr null, ptr nonnull @_thread0, ptr nonnull %0) + %15 = load ptr, ptr %13, align 8 + %16 = alloca ptr, align 8 + %17 = call i32 @pthread_create(ptr nonnull %16, ptr null, ptr nonnull @_thread0, ptr nonnull %0) + %18 = load ptr, ptr %16, align 8 + %19 = alloca ptr, align 8 + %20 = call i32 @pthread_create(ptr nonnull %19, ptr null, ptr nonnull @_thread0, ptr nonnull %0) + %21 = load ptr, ptr %19, align 8 + %22 = alloca ptr, align 8 + %23 = call i32 @pthread_create(ptr nonnull %22, ptr null, ptr nonnull @_thread0, ptr nonnull %0) + %24 = load ptr, ptr %22, align 8 + %puts = call i32 @puts(ptr nonnull @str) + %25 = call i32 @pthread_join(ptr %3, ptr null) + %26 = call i32 @pthread_join(ptr %6, ptr null) + %27 = call i32 @pthread_join(ptr %9, ptr null) + %28 = call i32 @pthread_join(ptr %12, ptr null) + %29 = call i32 @pthread_join(ptr %15, ptr null) + %30 = call i32 @pthread_join(ptr %18, ptr null) + %31 = call i32 @pthread_join(ptr %21, ptr null) + %32 = call i32 @pthread_join(ptr %24, ptr null) + %33 = call i32 (ptr, ...) @printf(ptr nonnull @1) ret i32 0 } ; Function Attrs: nofree nounwind -define internal noalias i8* @_thread0(i8* nocapture readnone %0) #1 { -entry: +define internal noalias ptr @_thread0(ptr nocapture readnone %0) #1 { +thread.entry.l10: %1 = tail call fastcc i32 @_f__void__fib__int(i32 46) - %2 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @0, i64 0, i64 0), i32 %1) - ret i8* null + %2 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 %1) + ret ptr null } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #1 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1 -declare i32 @pthread_create(i8**, i8*, i8* (i8*)*, i8*) local_unnamed_addr +declare i32 @pthread_create(ptr, ptr, ptr, ptr) local_unnamed_addr -declare i32 @pthread_join(i8*, i8**) local_unnamed_addr +declare i32 @pthread_join(ptr, ptr) local_unnamed_addr ; Function Attrs: nofree nounwind -declare noundef i32 @puts(i8* nocapture noundef readonly) local_unnamed_addr #1 +declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #1 attributes #0 = { nofree nosync nounwind readnone } attributes #1 = { nofree nounwind } diff --git a/test/test-files/generator/arbitrary/success-fibonacci/ir-code-O3.ll b/test/test-files/generator/arbitrary/success-fibonacci/ir-code-O3.ll index 7f88c9590..51a14b479 100644 --- a/test/test-files/generator/arbitrary/success-fibonacci/ir-code-O3.ll +++ b/test/test-files/generator/arbitrary/success-fibonacci/ir-code-O3.ll @@ -7,39 +7,39 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nosync nounwind readnone define internal fastcc i32 @_f__void__fib__int(i32 %0) unnamed_addr #0 { -entry: +entry.l1: %1 = icmp slt i32 %0, 3 - br i1 %1, label %common.ret, label %if.end + br i1 %1, label %common.ret, label %if.end.l2 -common.ret.loopexit: ; preds = %if.end +common.ret.loopexit: ; preds = %if.end.l2 %phi.bo = add i32 %5, 1 br label %common.ret -common.ret: ; preds = %common.ret.loopexit, %entry - %accumulator.tr.lcssa = phi i32 [ 1, %entry ], [ %phi.bo, %common.ret.loopexit ] +common.ret: ; preds = %common.ret.loopexit, %entry.l1 + %accumulator.tr.lcssa = phi i32 [ 1, %entry.l1 ], [ %phi.bo, %common.ret.loopexit ] ret i32 %accumulator.tr.lcssa -if.end: ; preds = %entry, %if.end - %.tr9 = phi i32 [ %4, %if.end ], [ %0, %entry ] - %accumulator.tr8 = phi i32 [ %5, %if.end ], [ 0, %entry ] +if.end.l2: ; preds = %entry.l1, %if.end.l2 + %.tr9 = phi i32 [ %4, %if.end.l2 ], [ %0, %entry.l1 ] + %accumulator.tr8 = phi i32 [ %5, %if.end.l2 ], [ 0, %entry.l1 ] %2 = add nsw i32 %.tr9, -1 %3 = tail call fastcc i32 @_f__void__fib__int(i32 %2) %4 = add nsw i32 %.tr9, -2 %5 = add i32 %3, %accumulator.tr8 %6 = icmp ult i32 %.tr9, 5 - br i1 %6, label %common.ret.loopexit, label %if.end + br i1 %6, label %common.ret.loopexit, label %if.end.l2 } ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #1 { -entry: +entry.l6: %0 = tail call fastcc i32 @_f__void__fib__int(i32 46) - %1 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @0, i64 0, i64 0), i32 46, i32 %0) + %1 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 46, i32 %0) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #1 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1 attributes #0 = { nofree nosync nounwind readnone } attributes #1 = { nofree nounwind } diff --git a/test/test-files/generator/arbitrary/success-fibonacci/ir-code.ll b/test/test-files/generator/arbitrary/success-fibonacci/ir-code.ll index a571699ff..ab35101f1 100644 --- a/test/test-files/generator/arbitrary/success-fibonacci/ir-code.ll +++ b/test/test-files/generator/arbitrary/success-fibonacci/ir-code.ll @@ -6,7 +6,7 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [20 x i8] c"Fibonacci of %d: %d\00", align 1 define internal i32 @_f__void__fib__int(i32 %0) { -entry: +entry.l1: %n = alloca i32, align 4 %result = alloca i32, align 4 %1 = alloca i1, align 1 @@ -16,54 +16,54 @@ entry: %5 = alloca i32, align 4 %6 = alloca i32, align 4 %7 = alloca i32, align 4 - store i32 %0, i32* %n, align 4 - %8 = load i32, i32* %n, align 4 + store i32 %0, ptr %n, align 4 + %8 = load i32, ptr %n, align 4 %9 = icmp sle i32 %8, 2 - store i1 %9, i1* %1, align 1 - %10 = load i1, i1* %1, align 1 - br i1 %10, label %if.then, label %if.end + store i1 %9, ptr %1, align 1 + %10 = load i1, ptr %1, align 1 + br i1 %10, label %if.then.l2, label %if.end.l2 -if.then: ; preds = %entry - store i32 1, i32* %2, align 4 - %11 = load i32, i32* %2, align 4 +if.then.l2: ; preds = %entry.l1 + store i32 1, ptr %2, align 4 + %11 = load i32, ptr %2, align 4 ret i32 %11 -if.end: ; preds = %entry - %12 = load i32, i32* %n, align 4 +if.end.l2: ; preds = %entry.l1 + %12 = load i32, ptr %n, align 4 %13 = sub i32 %12, 1 - store i32 %13, i32* %3, align 4 - %14 = load i32, i32* %3, align 4 + store i32 %13, ptr %3, align 4 + %14 = load i32, ptr %3, align 4 %15 = call i32 @_f__void__fib__int(i32 %14) - store i32 %15, i32* %4, align 4 - %16 = load i32, i32* %4, align 4 - %17 = load i32, i32* %n, align 4 + store i32 %15, ptr %4, align 4 + %16 = load i32, ptr %4, align 4 + %17 = load i32, ptr %n, align 4 %18 = sub i32 %17, 2 - store i32 %18, i32* %5, align 4 - %19 = load i32, i32* %5, align 4 + store i32 %18, ptr %5, align 4 + %19 = load i32, ptr %5, align 4 %20 = call i32 @_f__void__fib__int(i32 %19) - store i32 %20, i32* %6, align 4 - %21 = load i32, i32* %6, align 4 + store i32 %20, ptr %6, align 4 + %21 = load i32, ptr %6, align 4 %22 = add i32 %16, %21 - store i32 %22, i32* %7, align 4 - %23 = load i32, i32* %7, align 4 + store i32 %22, ptr %7, align 4 + %23 = load i32, ptr %7, align 4 ret i32 %23 } define i32 @main() { -entry: +entry.l6: %result = alloca i32, align 4 %base = alloca i32, align 4 %0 = alloca i32, align 4 - store i32 0, i32* %result, align 4 - store i32 46, i32* %base, align 4 - %1 = load i32, i32* %base, align 4 - %2 = load i32, i32* %base, align 4 + store i32 0, ptr %result, align 4 + store i32 46, ptr %base, align 4 + %1 = load i32, ptr %base, align 4 + %2 = load i32, ptr %base, align 4 %3 = call i32 @_f__void__fib__int(i32 %2) - store i32 %3, i32* %0, align 4 - %4 = load i32, i32* %0, align 4 - %5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @0, i32 0, i32 0), i32 %1, i32 %4) - %6 = load i32, i32* %result, align 4 + store i32 %3, ptr %0, align 4 + %4 = load i32, ptr %0, align 4 + %5 = call i32 (ptr, ...) @printf(ptr @0, i32 %1, i32 %4) + %6 = load i32, ptr %result, align 4 ret i32 %6 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/arbitrary/success-hello-world/ir-code-O2.ll b/test/test-files/generator/arbitrary/success-hello-world/ir-code-O2.ll index 2b60faa0f..9df61dd56 100644 --- a/test/test-files/generator/arbitrary/success-hello-world/ir-code-O2.ll +++ b/test/test-files/generator/arbitrary/success-hello-world/ir-code-O2.ll @@ -7,12 +7,12 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #0 { -entry: - %0 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @0, i64 0, i64 0)) +entry.l1: + %0 = tail call i32 (ptr, ...) @printf(ptr nonnull @0) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/arbitrary/success-hello-world2/ir-code-O3.ll b/test/test-files/generator/arbitrary/success-hello-world2/ir-code-O3.ll index 76baa2c5d..38986eb0a 100644 --- a/test/test-files/generator/arbitrary/success-hello-world2/ir-code-O3.ll +++ b/test/test-files/generator/arbitrary/success-hello-world2/ir-code-O3.ll @@ -5,7 +5,7 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #0 { -entry: +entry.l3: %putchar = tail call i32 @putchar(i32 72) %putchar.1 = tail call i32 @putchar(i32 101) %putchar.2 = tail call i32 @putchar(i32 108) diff --git a/test/test-files/generator/arbitrary/success-pidigits/ir-code-O3.ll b/test/test-files/generator/arbitrary/success-pidigits/ir-code-O3.ll index fcd760c07..d65d44385 100644 --- a/test/test-files/generator/arbitrary/success-pidigits/ir-code-O3.ll +++ b/test/test-files/generator/arbitrary/success-pidigits/ir-code-O3.ll @@ -7,81 +7,81 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #0 { -entry: - br label %for +entry.l4: + br label %for.l21 -for: ; preds = %entry, %for.inc - %q.164 = phi i64 [ 1, %entry ], [ %q.0, %for.inc ] - %r.163 = phi i64 [ 0, %entry ], [ %r.0, %for.inc ] - %t.162 = phi i64 [ 1, %entry ], [ %t.0, %for.inc ] - %k.161 = phi i64 [ 1, %entry ], [ %k.0, %for.inc ] - %m.160 = phi i64 [ 3, %entry ], [ %m.0, %for.inc ] - %x.159 = phi i64 [ 3, %entry ], [ %x.0, %for.inc ] - %printedDigits.158 = phi i32 [ 0, %entry ], [ %printedDigits.0, %for.inc ] - %i.057 = phi i32 [ 0, %entry ], [ %29, %for.inc ] - %0 = shl i64 %q.164, 2 - %1 = sub i64 %r.163, %t.162 +for.l21: ; preds = %entry.l4, %for.inc.l21 + %q.162 = phi i64 [ 1, %entry.l4 ], [ %q.0, %for.inc.l21 ] + %r.161 = phi i64 [ 0, %entry.l4 ], [ %r.0, %for.inc.l21 ] + %t.160 = phi i64 [ 1, %entry.l4 ], [ %t.0, %for.inc.l21 ] + %k.159 = phi i64 [ 1, %entry.l4 ], [ %k.0, %for.inc.l21 ] + %m.158 = phi i64 [ 3, %entry.l4 ], [ %m.0, %for.inc.l21 ] + %x.157 = phi i64 [ 3, %entry.l4 ], [ %x.0, %for.inc.l21 ] + %printedDigits.156 = phi i32 [ 0, %entry.l4 ], [ %printedDigits.0, %for.inc.l21 ] + %i.055 = phi i32 [ 0, %entry.l4 ], [ %29, %for.inc.l21 ] + %0 = shl i64 %q.162, 2 + %1 = sub i64 %r.161, %t.160 %2 = add i64 %1, %0 - %3 = mul i64 %t.162, %m.160 + %3 = mul i64 %t.160, %m.158 %4 = icmp slt i64 %2, %3 - br i1 %4, label %if.then, label %if.else + br i1 %4, label %if.then.l22, label %if.else.l22 -if.then: ; preds = %for - %5 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @0, i64 0, i64 0), i64 %m.160) - %6 = icmp eq i32 %printedDigits.158, 0 - br i1 %6, label %if.then1, label %if.end +if.then.l22: ; preds = %for.l21 + %5 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i64 %m.158) + %6 = icmp eq i32 %printedDigits.156, 0 + br i1 %6, label %if.then.l24, label %if.end.l24 -if.then1: ; preds = %if.then +if.then.l24: ; preds = %if.then.l22 %putchar = tail call i32 @putchar(i32 46) - br label %if.end + br label %if.end.l24 -if.end: ; preds = %if.then1, %if.then - %7 = add i32 %printedDigits.158, 1 - %8 = mul i64 %q.164, 10 - %9 = sub i64 %r.163, %3 +if.end.l24: ; preds = %if.then.l24, %if.then.l22 + %7 = add i32 %printedDigits.156, 1 + %8 = mul i64 %q.162, 10 + %9 = sub i64 %r.161, %3 %10 = mul i64 %9, 10 - %11 = mul i64 %q.164, 3 - %12 = add i64 %11, %r.163 + %11 = mul i64 %q.162, 3 + %12 = add i64 %11, %r.161 %13 = mul i64 %12, 10 - %14 = sdiv i64 %13, %t.162 - %.neg = mul i64 %m.160, -10 + %14 = sdiv i64 %13, %t.160 + %.neg = mul i64 %m.158, -10 %15 = add i64 %14, %.neg - br label %for.inc + br label %for.inc.l21 -if.else: ; preds = %for - %16 = mul i64 %q.164, %k.161 - %17 = shl i64 %q.164, 1 - %18 = add i64 %17, %r.163 - %19 = mul i64 %18, %x.159 - %20 = mul i64 %t.162, %x.159 - %21 = add i64 %k.161, 1 - %22 = mul i64 %k.161, 7 +if.else.l22: ; preds = %for.l21 + %16 = mul i64 %q.162, %k.159 + %17 = shl i64 %q.162, 1 + %18 = add i64 %17, %r.161 + %19 = mul i64 %18, %x.157 + %20 = mul i64 %t.160, %x.157 + %21 = add i64 %k.159, 1 + %22 = mul i64 %k.159, 7 %23 = add i64 %22, 2 - %24 = mul i64 %q.164, %23 - %25 = mul i64 %r.163, %x.159 + %24 = mul i64 %q.162, %23 + %25 = mul i64 %r.161, %x.157 %26 = add i64 %24, %25 %27 = sdiv i64 %26, %20 - %28 = add i64 %x.159, 2 - br label %for.inc + %28 = add i64 %x.157, 2 + br label %for.inc.l21 -for.inc: ; preds = %if.end, %if.else - %printedDigits.0 = phi i32 [ %7, %if.end ], [ %printedDigits.158, %if.else ] - %x.0 = phi i64 [ %x.159, %if.end ], [ %28, %if.else ] - %m.0 = phi i64 [ %15, %if.end ], [ %27, %if.else ] - %k.0 = phi i64 [ %k.161, %if.end ], [ %21, %if.else ] - %t.0 = phi i64 [ %t.162, %if.end ], [ %20, %if.else ] - %r.0 = phi i64 [ %10, %if.end ], [ %19, %if.else ] - %q.0 = phi i64 [ %8, %if.end ], [ %16, %if.else ] - %29 = add nuw nsw i32 %i.057, 1 +for.inc.l21: ; preds = %if.end.l24, %if.else.l22 + %printedDigits.0 = phi i32 [ %7, %if.end.l24 ], [ %printedDigits.156, %if.else.l22 ] + %x.0 = phi i64 [ %x.157, %if.end.l24 ], [ %28, %if.else.l22 ] + %m.0 = phi i64 [ %15, %if.end.l24 ], [ %27, %if.else.l22 ] + %k.0 = phi i64 [ %k.159, %if.end.l24 ], [ %21, %if.else.l22 ] + %t.0 = phi i64 [ %t.160, %if.end.l24 ], [ %20, %if.else.l22 ] + %r.0 = phi i64 [ %10, %if.end.l24 ], [ %19, %if.else.l22 ] + %q.0 = phi i64 [ %8, %if.end.l24 ], [ %16, %if.else.l22 ] + %29 = add nuw nsw i32 %i.055, 1 %exitcond.not = icmp eq i32 %29, 20 - br i1 %exitcond.not, label %for.end, label %for + br i1 %exitcond.not, label %for.end.l21, label %for.l21 -for.end: ; preds = %for.inc +for.end.l21: ; preds = %for.inc.l21 ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 ; Function Attrs: nofree nounwind declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #0 diff --git a/test/test-files/generator/arbitrary/success-pidigits/ir-code.ll b/test/test-files/generator/arbitrary/success-pidigits/ir-code.ll index c4c204e51..22bb8b9dd 100644 --- a/test/test-files/generator/arbitrary/success-pidigits/ir-code.ll +++ b/test/test-files/generator/arbitrary/success-pidigits/ir-code.ll @@ -7,7 +7,7 @@ target triple = "x86_64-w64-windows-gnu" @1 = private unnamed_addr constant [2 x i8] c".\00", align 1 define i32 @main() { -entry: +entry.l4: %result = alloca i32, align 4 %q = alloca i64, align 8 %q_new = alloca i64, align 8 @@ -55,203 +55,203 @@ entry: %28 = alloca i64, align 8 %29 = alloca i32, align 4 %30 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - store i64 1, i64* %q, align 8 - store i64 0, i64* %q_new, align 8 - store i64 0, i64* %r, align 8 - store i64 0, i64* %r_new, align 8 - store i64 1, i64* %t, align 8 - store i64 0, i64* %t_new, align 8 - store i64 1, i64* %k, align 8 - store i64 0, i64* %k_new, align 8 - store i64 3, i64* %m, align 8 - store i64 0, i64* %m_new, align 8 - store i64 3, i64* %x, align 8 - store i64 0, i64* %x_new, align 8 - store i32 20, i32* %iterations, align 4 - store i32 0, i32* %printedDigits, align 4 - store i32 0, i32* %i, align 4 - br label %for.cond + store i32 0, ptr %result, align 4 + store i64 1, ptr %q, align 8 + store i64 0, ptr %q_new, align 8 + store i64 0, ptr %r, align 8 + store i64 0, ptr %r_new, align 8 + store i64 1, ptr %t, align 8 + store i64 0, ptr %t_new, align 8 + store i64 1, ptr %k, align 8 + store i64 0, ptr %k_new, align 8 + store i64 3, ptr %m, align 8 + store i64 0, ptr %m_new, align 8 + store i64 3, ptr %x, align 8 + store i64 0, ptr %x_new, align 8 + store i32 20, ptr %iterations, align 4 + store i32 0, ptr %printedDigits, align 4 + store i32 0, ptr %i, align 4 + br label %for.cond.l21 -for: ; preds = %for.cond - %31 = load i64, i64* %q, align 8 +for.l21: ; preds = %for.cond.l21 + %31 = load i64, ptr %q, align 8 %32 = mul i64 4, %31 - store i64 %32, i64* %0, align 8 - %33 = load i64, i64* %0, align 8 - %34 = load i64, i64* %r, align 8 + store i64 %32, ptr %0, align 8 + %33 = load i64, ptr %0, align 8 + %34 = load i64, ptr %r, align 8 %35 = add i64 %33, %34 - %36 = load i64, i64* %t, align 8 + %36 = load i64, ptr %t, align 8 %37 = sub i64 %35, %36 - store i64 %37, i64* %1, align 8 - %38 = load i64, i64* %1, align 8 - %39 = load i64, i64* %m, align 8 - %40 = load i64, i64* %t, align 8 + store i64 %37, ptr %1, align 8 + %38 = load i64, ptr %1, align 8 + %39 = load i64, ptr %m, align 8 + %40 = load i64, ptr %t, align 8 %41 = mul i64 %39, %40 - store i64 %41, i64* %2, align 8 - %42 = load i64, i64* %2, align 8 + store i64 %41, ptr %2, align 8 + %42 = load i64, ptr %2, align 8 %43 = icmp slt i64 %38, %42 - store i1 %43, i1* %3, align 1 - %44 = load i1, i1* %3, align 1 - br i1 %44, label %if.then, label %if.else + store i1 %43, ptr %3, align 1 + %44 = load i1, ptr %3, align 1 + br i1 %44, label %if.then.l22, label %if.else.l22 -if.then: ; preds = %for - %45 = load i64, i64* %m, align 8 - %46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @0, i32 0, i32 0), i64 %45) - %47 = load i32, i32* %printedDigits, align 4 +if.then.l22: ; preds = %for.l21 + %45 = load i64, ptr %m, align 8 + %46 = call i32 (ptr, ...) @printf(ptr @0, i64 %45) + %47 = load i32, ptr %printedDigits, align 4 %48 = icmp eq i32 %47, 0 - store i1 %48, i1* %4, align 1 - %49 = load i1, i1* %4, align 1 - br i1 %49, label %if.then1, label %if.end + store i1 %48, ptr %4, align 1 + %49 = load i1, ptr %4, align 1 + br i1 %49, label %if.then.l24, label %if.end.l24 -if.then1: ; preds = %if.then - %50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @1, i32 0, i32 0)) - br label %if.end +if.then.l24: ; preds = %if.then.l22 + %50 = call i32 (ptr, ...) @printf(ptr @1) + br label %if.end.l24 -if.end: ; preds = %if.then1, %if.then - %51 = load i32, i32* %printedDigits, align 4 +if.end.l24: ; preds = %if.then.l24, %if.then.l22 + %51 = load i32, ptr %printedDigits, align 4 %52 = add i32 %51, 1 - store i32 %52, i32* %printedDigits, align 4 - store i32 %51, i32* %5, align 4 - %53 = load i64, i64* %q, align 8 + store i32 %52, ptr %printedDigits, align 4 + store i32 %51, ptr %5, align 4 + %53 = load i64, ptr %q, align 8 %54 = mul i64 10, %53 - store i64 %54, i64* %6, align 8 - %55 = load i64, i64* %6, align 8 - store i64 %55, i64* %q_new, align 8 - %56 = load i64, i64* %r, align 8 - %57 = load i64, i64* %m, align 8 - %58 = load i64, i64* %t, align 8 + store i64 %54, ptr %6, align 8 + %55 = load i64, ptr %6, align 8 + store i64 %55, ptr %q_new, align 8 + %56 = load i64, ptr %r, align 8 + %57 = load i64, ptr %m, align 8 + %58 = load i64, ptr %t, align 8 %59 = mul i64 %57, %58 - store i64 %59, i64* %7, align 8 - %60 = load i64, i64* %7, align 8 + store i64 %59, ptr %7, align 8 + %60 = load i64, ptr %7, align 8 %61 = sub i64 %56, %60 - store i64 %61, i64* %8, align 8 - %62 = load i64, i64* %8, align 8 + store i64 %61, ptr %8, align 8 + %62 = load i64, ptr %8, align 8 %63 = mul i64 10, %62 - store i64 %63, i64* %9, align 8 - %64 = load i64, i64* %9, align 8 - store i64 %64, i64* %r_new, align 8 - %65 = load i64, i64* %q, align 8 + store i64 %63, ptr %9, align 8 + %64 = load i64, ptr %9, align 8 + store i64 %64, ptr %r_new, align 8 + %65 = load i64, ptr %q, align 8 %66 = mul i64 3, %65 - store i64 %66, i64* %10, align 8 - %67 = load i64, i64* %10, align 8 - %68 = load i64, i64* %r, align 8 + store i64 %66, ptr %10, align 8 + %67 = load i64, ptr %10, align 8 + %68 = load i64, ptr %r, align 8 %69 = add i64 %67, %68 - store i64 %69, i64* %11, align 8 - %70 = load i64, i64* %11, align 8 + store i64 %69, ptr %11, align 8 + %70 = load i64, ptr %11, align 8 %71 = mul i64 10, %70 - store i64 %71, i64* %12, align 8 - %72 = load i64, i64* %12, align 8 - %73 = load i64, i64* %t, align 8 + store i64 %71, ptr %12, align 8 + %72 = load i64, ptr %12, align 8 + %73 = load i64, ptr %t, align 8 %74 = sdiv i64 %72, %73 - store i64 %74, i64* %13, align 8 - %75 = load i64, i64* %13, align 8 - %76 = load i64, i64* %m, align 8 + store i64 %74, ptr %13, align 8 + %75 = load i64, ptr %13, align 8 + %76 = load i64, ptr %m, align 8 %77 = mul i64 10, %76 - store i64 %77, i64* %14, align 8 - %78 = load i64, i64* %14, align 8 + store i64 %77, ptr %14, align 8 + %78 = load i64, ptr %14, align 8 %79 = sub i64 %75, %78 - store i64 %79, i64* %15, align 8 - %80 = load i64, i64* %15, align 8 - store i64 %80, i64* %m, align 8 - %81 = load i64, i64* %q_new, align 8 - store i64 %81, i64* %q, align 8 - %82 = load i64, i64* %r_new, align 8 - store i64 %82, i64* %r, align 8 - br label %if.end2 + store i64 %79, ptr %15, align 8 + %80 = load i64, ptr %15, align 8 + store i64 %80, ptr %m, align 8 + %81 = load i64, ptr %q_new, align 8 + store i64 %81, ptr %q, align 8 + %82 = load i64, ptr %r_new, align 8 + store i64 %82, ptr %r, align 8 + br label %if.end.l22 -if.else: ; preds = %for - %83 = load i64, i64* %q, align 8 - %84 = load i64, i64* %k, align 8 +if.else.l22: ; preds = %for.l21 + %83 = load i64, ptr %q, align 8 + %84 = load i64, ptr %k, align 8 %85 = mul i64 %83, %84 - store i64 %85, i64* %16, align 8 - %86 = load i64, i64* %16, align 8 - store i64 %86, i64* %q_new, align 8 - %87 = load i64, i64* %q, align 8 + store i64 %85, ptr %16, align 8 + %86 = load i64, ptr %16, align 8 + store i64 %86, ptr %q_new, align 8 + %87 = load i64, ptr %q, align 8 %88 = mul i64 2, %87 - store i64 %88, i64* %17, align 8 - %89 = load i64, i64* %17, align 8 - %90 = load i64, i64* %r, align 8 + store i64 %88, ptr %17, align 8 + %89 = load i64, ptr %17, align 8 + %90 = load i64, ptr %r, align 8 %91 = add i64 %89, %90 - store i64 %91, i64* %18, align 8 - %92 = load i64, i64* %18, align 8 - %93 = load i64, i64* %x, align 8 + store i64 %91, ptr %18, align 8 + %92 = load i64, ptr %18, align 8 + %93 = load i64, ptr %x, align 8 %94 = mul i64 %92, %93 - store i64 %94, i64* %19, align 8 - %95 = load i64, i64* %19, align 8 - store i64 %95, i64* %r_new, align 8 - %96 = load i64, i64* %t, align 8 - %97 = load i64, i64* %x, align 8 + store i64 %94, ptr %19, align 8 + %95 = load i64, ptr %19, align 8 + store i64 %95, ptr %r_new, align 8 + %96 = load i64, ptr %t, align 8 + %97 = load i64, ptr %x, align 8 %98 = mul i64 %96, %97 - store i64 %98, i64* %20, align 8 - %99 = load i64, i64* %20, align 8 - store i64 %99, i64* %t_new, align 8 - %100 = load i64, i64* %k, align 8 + store i64 %98, ptr %20, align 8 + %99 = load i64, ptr %20, align 8 + store i64 %99, ptr %t_new, align 8 + %100 = load i64, ptr %k, align 8 %101 = add i64 %100, 1 - store i64 %101, i64* %21, align 8 - %102 = load i64, i64* %21, align 8 - store i64 %102, i64* %k_new, align 8 - %103 = load i64, i64* %q, align 8 - %104 = load i64, i64* %k, align 8 + store i64 %101, ptr %21, align 8 + %102 = load i64, ptr %21, align 8 + store i64 %102, ptr %k_new, align 8 + %103 = load i64, ptr %q, align 8 + %104 = load i64, ptr %k, align 8 %105 = mul i64 7, %104 - store i64 %105, i64* %22, align 8 - %106 = load i64, i64* %22, align 8 + store i64 %105, ptr %22, align 8 + %106 = load i64, ptr %22, align 8 %107 = add i64 %106, 2 - store i64 %107, i64* %23, align 8 - %108 = load i64, i64* %23, align 8 + store i64 %107, ptr %23, align 8 + %108 = load i64, ptr %23, align 8 %109 = mul i64 %103, %108 - store i64 %109, i64* %24, align 8 - %110 = load i64, i64* %24, align 8 - %111 = load i64, i64* %r, align 8 - %112 = load i64, i64* %x, align 8 + store i64 %109, ptr %24, align 8 + %110 = load i64, ptr %24, align 8 + %111 = load i64, ptr %r, align 8 + %112 = load i64, ptr %x, align 8 %113 = mul i64 %111, %112 - store i64 %113, i64* %25, align 8 - %114 = load i64, i64* %25, align 8 + store i64 %113, ptr %25, align 8 + %114 = load i64, ptr %25, align 8 %115 = add i64 %110, %114 - store i64 %115, i64* %26, align 8 - %116 = load i64, i64* %26, align 8 - %117 = load i64, i64* %t, align 8 - %118 = load i64, i64* %x, align 8 + store i64 %115, ptr %26, align 8 + %116 = load i64, ptr %26, align 8 + %117 = load i64, ptr %t, align 8 + %118 = load i64, ptr %x, align 8 %119 = mul i64 %117, %118 - store i64 %119, i64* %27, align 8 - %120 = load i64, i64* %27, align 8 + store i64 %119, ptr %27, align 8 + %120 = load i64, ptr %27, align 8 %121 = sdiv i64 %116, %120 - store i64 %121, i64* %28, align 8 - %122 = load i64, i64* %28, align 8 - store i64 %122, i64* %m, align 8 - %123 = load i64, i64* %x, align 8 + store i64 %121, ptr %28, align 8 + %122 = load i64, ptr %28, align 8 + store i64 %122, ptr %m, align 8 + %123 = load i64, ptr %x, align 8 %124 = add i64 %123, 2 - store i64 %124, i64* %x, align 8 - %125 = load i64, i64* %q_new, align 8 - store i64 %125, i64* %q, align 8 - %126 = load i64, i64* %r_new, align 8 - store i64 %126, i64* %r, align 8 - %127 = load i64, i64* %t_new, align 8 - store i64 %127, i64* %t, align 8 - %128 = load i64, i64* %k_new, align 8 - store i64 %128, i64* %k, align 8 - br label %if.end2 + store i64 %124, ptr %x, align 8 + %125 = load i64, ptr %q_new, align 8 + store i64 %125, ptr %q, align 8 + %126 = load i64, ptr %r_new, align 8 + store i64 %126, ptr %r, align 8 + %127 = load i64, ptr %t_new, align 8 + store i64 %127, ptr %t, align 8 + %128 = load i64, ptr %k_new, align 8 + store i64 %128, ptr %k, align 8 + br label %if.end.l22 -if.end2: ; preds = %if.else, %if.end - br label %for.inc +if.end.l22: ; preds = %if.else.l22, %if.end.l24 + br label %for.inc.l21 -for.inc: ; preds = %if.end2 - %129 = load i32, i32* %i, align 4 +for.inc.l21: ; preds = %if.end.l22 + %129 = load i32, ptr %i, align 4 %130 = add i32 %129, 1 - store i32 %130, i32* %i, align 4 - store i32 %129, i32* %29, align 4 - br label %for.cond + store i32 %130, ptr %i, align 4 + store i32 %129, ptr %29, align 4 + br label %for.cond.l21 -for.cond: ; preds = %for.inc, %entry - %131 = load i32, i32* %i, align 4 - %132 = load i32, i32* %iterations, align 4 +for.cond.l21: ; preds = %for.inc.l21, %entry.l4 + %131 = load i32, ptr %i, align 4 + %132 = load i32, ptr %iterations, align 4 %133 = icmp slt i32 %131, %132 - store i1 %133, i1* %30, align 1 - %134 = load i1, i1* %30, align 1 - br i1 %134, label %for, label %for.end + store i1 %133, ptr %30, align 1 + %134 = load i1, ptr %30, align 1 + br i1 %134, label %for.l21, label %for.end.l21 -for.end: ; preds = %for.cond - %135 = load i32, i32* %result, align 4 +for.end.l21: ; preds = %for.cond.l21 + %135 = load i32, ptr %result, align 4 ret i32 %135 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/arrays/success-arrays-dynamic-size/ir-code.ll b/test/test-files/generator/arrays/success-arrays-dynamic-size/ir-code.ll index f6beac20b..adb4588b4 100644 --- a/test/test-files/generator/arrays/success-arrays-dynamic-size/ir-code.ll +++ b/test/test-files/generator/arrays/success-arrays-dynamic-size/ir-code.ll @@ -16,219 +16,219 @@ target triple = "x86_64-w64-windows-gnu" @10 = private unnamed_addr constant [10 x i8] c"Item: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %arraySize1 = alloca i16, align 2 - %array1 = alloca i32*, align 8 + %array1 = alloca ptr, align 8 %idx = alloca i32, align 4 %item = alloca i32, align 4 %arraySize2 = alloca i64, align 8 - %array2 = alloca i8**, align 8 + %array2 = alloca ptr, align 8 %idx2 = alloca i32, align 4 - %item3 = alloca i8*, align 8 + %item3 = alloca ptr, align 8 %arraySize3 = alloca i32, align 4 - %array3 = alloca i32*, align 8 - %idx10 = alloca i32, align 4 - %item11 = alloca i32, align 4 + %array3 = alloca ptr, align 8 + %idx6 = alloca i32, align 4 + %item7 = alloca i32, align 4 %arraySize4 = alloca i32, align 4 - %array4 = alloca i32*, align 8 - %array418 = alloca i32*, align 8 - %idx19 = alloca i32, align 4 - %item20 = alloca i32, align 4 - store i32 0, i32* %result, align 4 - %0 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @0, i32 0, i32 0)) - store i16 4, i16* %arraySize1, align 2 - %1 = load i16, i16* %arraySize1, align 2 - %2 = call i8* @llvm.stacksave() + %array4 = alloca ptr, align 8 + %array410 = alloca ptr, align 8 + %idx11 = alloca i32, align 4 + %item12 = alloca i32, align 4 + store i32 0, ptr %result, align 4 + %0 = call i32 (ptr, ...) @printf(ptr @0) + store i16 4, ptr %arraySize1, align 2 + %1 = load i16, ptr %arraySize1, align 2 + %2 = call ptr @llvm.stacksave() %3 = alloca i32, i16 %1, align 4 - %4 = getelementptr inbounds i32, i32* %3, i32 0 - store i32 1, i32* %4, align 4 - %5 = getelementptr inbounds i32, i32* %3, i32 1 - store i32 2, i32* %5, align 4 - %6 = getelementptr inbounds i32, i32* %3, i32 2 - store i32 3, i32* %6, align 4 - store i32* %3, i32** %array1, align 8 - %7 = load i32*, i32** %array1, align 8 - %8 = getelementptr inbounds i32, i32* %7, i32 3 - store i32 0, i32* %8, align 4 - store i32 0, i32* %idx, align 4 - store i32 0, i32* %item, align 4 - %9 = load i32*, i32** %array1, align 8 + %4 = getelementptr inbounds i32, ptr %3, i32 0 + store i32 1, ptr %4, align 4 + %5 = getelementptr inbounds i32, ptr %3, i32 1 + store i32 2, ptr %5, align 4 + %6 = getelementptr inbounds i32, ptr %3, i32 2 + store i32 3, ptr %6, align 4 + store ptr %3, ptr %array1, align 8 + %7 = load ptr, ptr %array1, align 8 + %8 = getelementptr inbounds i32, ptr %7, i32 3 + store i32 0, ptr %8, align 4 + store i32 0, ptr %idx, align 4 + store i32 0, ptr %item, align 4 + %9 = load ptr, ptr %array1, align 8 %10 = sext i16 %1 to i32 - %11 = load i32, i32* %idx, align 4 - %12 = load i32*, i32** %array1, align 8 - %13 = getelementptr inbounds i32, i32* %12, i32 %11 - %14 = load i32, i32* %13, align 4 - store i32 %14, i32* %item, align 4 - br label %foreach.loop - -foreach.loop: ; preds = %foreach.cond, %entry - %15 = load i32, i32* %item, align 4 - %16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @1, i32 0, i32 0), i32 %15) - br label %foreach.inc - -foreach.inc: ; preds = %foreach.loop - %idx1 = load i32, i32* %idx, align 4 + %11 = load i32, ptr %idx, align 4 + %12 = load ptr, ptr %array1, align 8 + %13 = getelementptr inbounds i32, ptr %12, i32 %11 + %14 = load i32, ptr %13, align 4 + store i32 %14, ptr %item, align 4 + br label %foreach.loop.l6 + +foreach.loop.l6: ; preds = %foreach.cond.l6, %entry.l1 + %15 = load i32, ptr %item, align 4 + %16 = call i32 (ptr, ...) @printf(ptr @1, i32 %15) + br label %foreach.inc.l6 + +foreach.inc.l6: ; preds = %foreach.loop.l6 + %idx1 = load i32, ptr %idx, align 4 %idx.inc = add i32 %idx1, 1 - store i32 %idx.inc, i32* %idx, align 4 - %17 = getelementptr inbounds i32, i32* %12, i32 %idx.inc - %18 = load i32, i32* %17, align 4 - store i32 %18, i32* %item, align 4 - br label %foreach.cond - -foreach.cond: ; preds = %foreach.inc - %19 = load i32, i32* %idx, align 4 + store i32 %idx.inc, ptr %idx, align 4 + %17 = getelementptr inbounds i32, ptr %12, i32 %idx.inc + %18 = load i32, ptr %17, align 4 + store i32 %18, ptr %item, align 4 + br label %foreach.cond.l6 + +foreach.cond.l6: ; preds = %foreach.inc.l6 + %19 = load i32, ptr %idx, align 4 %20 = icmp ult i32 %19, %10 - br i1 %20, label %foreach.loop, label %foreach.end - -foreach.end: ; preds = %foreach.cond - %21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @2, i32 0, i32 0)) - store i64 2, i64* %arraySize2, align 8 - %22 = load i64, i64* %arraySize2, align 8 - %23 = call i8* @llvm.stacksave() - %24 = alloca i8*, i64 %22, align 8 - store i8** %24, i8*** %array2, align 8 - %25 = load i8**, i8*** %array2, align 8 - %26 = getelementptr inbounds i8*, i8** %25, i32 0 - store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @3, i32 0, i32 0), i8** %26, align 8 - %27 = load i8**, i8*** %array2, align 8 - %28 = getelementptr inbounds i8*, i8** %27, i32 1 - store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @4, i32 0, i32 0), i8** %28, align 8 - store i32 0, i32* %idx2, align 4 - store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @5, i32 0, i32 0), i8** %item3, align 8 - %29 = load i8**, i8*** %array2, align 8 + br i1 %20, label %foreach.loop.l6, label %foreach.end.l6 + +foreach.end.l6: ; preds = %foreach.cond.l6 + %21 = call i32 (ptr, ...) @printf(ptr @2) + store i64 2, ptr %arraySize2, align 8 + %22 = load i64, ptr %arraySize2, align 8 + %23 = call ptr @llvm.stacksave() + %24 = alloca ptr, i64 %22, align 8 + store ptr %24, ptr %array2, align 8 + %25 = load ptr, ptr %array2, align 8 + %26 = getelementptr inbounds ptr, ptr %25, i32 0 + store ptr @3, ptr %26, align 8 + %27 = load ptr, ptr %array2, align 8 + %28 = getelementptr inbounds ptr, ptr %27, i32 1 + store ptr @4, ptr %28, align 8 + store i32 0, ptr %idx2, align 4 + store ptr @5, ptr %item3, align 8 + %29 = load ptr, ptr %array2, align 8 %30 = trunc i64 %22 to i32 - %31 = load i32, i32* %idx2, align 4 - %32 = load i8**, i8*** %array2, align 8 - %33 = getelementptr inbounds i8*, i8** %32, i32 %31 - %34 = load i8*, i8** %33, align 8 - store i8* %34, i8** %item3, align 8 - br label %foreach.loop4 - -foreach.loop4: ; preds = %foreach.cond8, %foreach.end - %35 = load i8*, i8** %item3, align 8 - %36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @6, i32 0, i32 0), i8* %35) - br label %foreach.inc5 - -foreach.inc5: ; preds = %foreach.loop4 - %idx6 = load i32, i32* %idx2, align 4 - %idx.inc7 = add i32 %idx6, 1 - store i32 %idx.inc7, i32* %idx2, align 4 - %37 = getelementptr inbounds i8*, i8** %32, i32 %idx.inc7 - %38 = load i8*, i8** %37, align 8 - store i8* %38, i8** %item3, align 8 - br label %foreach.cond8 - -foreach.cond8: ; preds = %foreach.inc5 - %39 = load i32, i32* %idx2, align 4 + %31 = load i32, ptr %idx2, align 4 + %32 = load ptr, ptr %array2, align 8 + %33 = getelementptr inbounds ptr, ptr %32, i32 %31 + %34 = load ptr, ptr %33, align 8 + store ptr %34, ptr %item3, align 8 + br label %foreach.loop.l15 + +foreach.loop.l15: ; preds = %foreach.cond.l15, %foreach.end.l6 + %35 = load ptr, ptr %item3, align 8 + %36 = call i32 (ptr, ...) @printf(ptr @6, ptr %35) + br label %foreach.inc.l15 + +foreach.inc.l15: ; preds = %foreach.loop.l15 + %idx4 = load i32, ptr %idx2, align 4 + %idx.inc5 = add i32 %idx4, 1 + store i32 %idx.inc5, ptr %idx2, align 4 + %37 = getelementptr inbounds ptr, ptr %32, i32 %idx.inc5 + %38 = load ptr, ptr %37, align 8 + store ptr %38, ptr %item3, align 8 + br label %foreach.cond.l15 + +foreach.cond.l15: ; preds = %foreach.inc.l15 + %39 = load i32, ptr %idx2, align 4 %40 = icmp ult i32 %39, %30 - br i1 %40, label %foreach.loop4, label %foreach.end9 - -foreach.end9: ; preds = %foreach.cond8 - %41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @7, i32 0, i32 0)) - store i32 3, i32* %arraySize3, align 4 - %42 = load i32, i32* %arraySize3, align 4 - %43 = load i32, i32* %arraySize3, align 4 - %44 = load i32, i32* %arraySize3, align 4 - %45 = call i8* @llvm.stacksave() + br i1 %40, label %foreach.loop.l15, label %foreach.end.l15 + +foreach.end.l15: ; preds = %foreach.cond.l15 + %41 = call i32 (ptr, ...) @printf(ptr @7) + store i32 3, ptr %arraySize3, align 4 + %42 = load i32, ptr %arraySize3, align 4 + %43 = load i32, ptr %arraySize3, align 4 + %44 = load i32, ptr %arraySize3, align 4 + %45 = call ptr @llvm.stacksave() %46 = alloca i32, i32 %42, align 4 - %47 = getelementptr inbounds i32, i32* %46, i32 0 - store i32 1, i32* %47, align 4 - %48 = getelementptr inbounds i32, i32* %46, i32 1 - store i32 %43, i32* %48, align 4 - %49 = getelementptr inbounds i32, i32* %46, i32 2 - store i32 %44, i32* %49, align 4 - store i32* %46, i32** %array3, align 8 - store i32 0, i32* %idx10, align 4 - store i32 0, i32* %item11, align 4 - %50 = load i32*, i32** %array3, align 8 - %51 = load i32, i32* %idx10, align 4 - %52 = load i32*, i32** %array3, align 8 - %53 = getelementptr inbounds i32, i32* %52, i32 %51 - %54 = load i32, i32* %53, align 4 - store i32 %54, i32* %item11, align 4 - br label %foreach.loop12 - -foreach.loop12: ; preds = %foreach.cond16, %foreach.end9 - %55 = load i32, i32* %item11, align 4 - %56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @8, i32 0, i32 0), i32 %55) - br label %foreach.inc13 - -foreach.inc13: ; preds = %foreach.loop12 - %idx14 = load i32, i32* %idx10, align 4 - %idx.inc15 = add i32 %idx14, 1 - store i32 %idx.inc15, i32* %idx10, align 4 - %57 = getelementptr inbounds i32, i32* %52, i32 %idx.inc15 - %58 = load i32, i32* %57, align 4 - store i32 %58, i32* %item11, align 4 - br label %foreach.cond16 - -foreach.cond16: ; preds = %foreach.inc13 - %59 = load i32, i32* %idx10, align 4 + %47 = getelementptr inbounds i32, ptr %46, i32 0 + store i32 1, ptr %47, align 4 + %48 = getelementptr inbounds i32, ptr %46, i32 1 + store i32 %43, ptr %48, align 4 + %49 = getelementptr inbounds i32, ptr %46, i32 2 + store i32 %44, ptr %49, align 4 + store ptr %46, ptr %array3, align 8 + store i32 0, ptr %idx6, align 4 + store i32 0, ptr %item7, align 4 + %50 = load ptr, ptr %array3, align 8 + %51 = load i32, ptr %idx6, align 4 + %52 = load ptr, ptr %array3, align 8 + %53 = getelementptr inbounds i32, ptr %52, i32 %51 + %54 = load i32, ptr %53, align 4 + store i32 %54, ptr %item7, align 4 + br label %foreach.loop.l22 + +foreach.loop.l22: ; preds = %foreach.cond.l22, %foreach.end.l15 + %55 = load i32, ptr %item7, align 4 + %56 = call i32 (ptr, ...) @printf(ptr @8, i32 %55) + br label %foreach.inc.l22 + +foreach.inc.l22: ; preds = %foreach.loop.l22 + %idx8 = load i32, ptr %idx6, align 4 + %idx.inc9 = add i32 %idx8, 1 + store i32 %idx.inc9, ptr %idx6, align 4 + %57 = getelementptr inbounds i32, ptr %52, i32 %idx.inc9 + %58 = load i32, ptr %57, align 4 + store i32 %58, ptr %item7, align 4 + br label %foreach.cond.l22 + +foreach.cond.l22: ; preds = %foreach.inc.l22 + %59 = load i32, ptr %idx6, align 4 %60 = icmp ult i32 %59, %42 - br i1 %60, label %foreach.loop12, label %foreach.end17 + br i1 %60, label %foreach.loop.l22, label %foreach.end.l22 -foreach.end17: ; preds = %foreach.cond16 - %61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @9, i32 0, i32 0)) - store i32 3, i32* %arraySize4, align 4 - %62 = load i32, i32* %arraySize4, align 4 - %63 = call i8* @llvm.stacksave() +foreach.end.l22: ; preds = %foreach.cond.l22 + %61 = call i32 (ptr, ...) @printf(ptr @9) + store i32 3, ptr %arraySize4, align 4 + %62 = load i32, ptr %arraySize4, align 4 + %63 = call ptr @llvm.stacksave() %64 = alloca i32, i32 %62, align 4 - store i32* %64, i32** %array4, align 8 - %65 = load i32, i32* %arraySize4, align 4 - %66 = load i32, i32* %arraySize4, align 4 - %67 = call i8* @llvm.stacksave() + store ptr %64, ptr %array4, align 8 + %65 = load i32, ptr %arraySize4, align 4 + %66 = load i32, ptr %arraySize4, align 4 + %67 = call ptr @llvm.stacksave() %68 = alloca i32, align 4 - %69 = getelementptr inbounds i32, i32* %68, i32 0 - store i32 1, i32* %69, align 4 - %70 = getelementptr inbounds i32, i32* %68, i32 1 - store i32 %65, i32* %70, align 4 - %71 = getelementptr inbounds i32, i32* %68, i32 2 - store i32 %66, i32* %71, align 4 - store i32* %68, i32** %array418, align 8 - %72 = load i32*, i32** %array418, align 8 - store i32* %72, i32** %array4, align 8 - store i32 0, i32* %idx19, align 4 - store i32 0, i32* %item20, align 4 - %73 = load i32*, i32** %array4, align 8 - %74 = load i32, i32* %idx19, align 4 - %75 = load i32*, i32** %array4, align 8 - %76 = getelementptr inbounds i32, i32* %75, i32 %74 - %77 = load i32, i32* %76, align 4 - store i32 %77, i32* %item20, align 4 - br label %foreach.loop21 - -foreach.loop21: ; preds = %foreach.cond25, %foreach.end17 - %78 = load i32, i32* %item20, align 4 - %79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @10, i32 0, i32 0), i32 %78) - br label %foreach.inc22 - -foreach.inc22: ; preds = %foreach.loop21 - %idx23 = load i32, i32* %idx19, align 4 - %idx.inc24 = add i32 %idx23, 1 - store i32 %idx.inc24, i32* %idx19, align 4 - %80 = getelementptr inbounds i32, i32* %75, i32 %idx.inc24 - %81 = load i32, i32* %80, align 4 - store i32 %81, i32* %item20, align 4 - br label %foreach.cond25 - -foreach.cond25: ; preds = %foreach.inc22 - %82 = load i32, i32* %idx19, align 4 + %69 = getelementptr inbounds i32, ptr %68, i32 0 + store i32 1, ptr %69, align 4 + %70 = getelementptr inbounds i32, ptr %68, i32 1 + store i32 %65, ptr %70, align 4 + %71 = getelementptr inbounds i32, ptr %68, i32 2 + store i32 %66, ptr %71, align 4 + store ptr %68, ptr %array410, align 8 + %72 = load ptr, ptr %array410, align 8 + store ptr %72, ptr %array4, align 8 + store i32 0, ptr %idx11, align 4 + store i32 0, ptr %item12, align 4 + %73 = load ptr, ptr %array4, align 8 + %74 = load i32, ptr %idx11, align 4 + %75 = load ptr, ptr %array4, align 8 + %76 = getelementptr inbounds i32, ptr %75, i32 %74 + %77 = load i32, ptr %76, align 4 + store i32 %77, ptr %item12, align 4 + br label %foreach.loop.l30 + +foreach.loop.l30: ; preds = %foreach.cond.l30, %foreach.end.l22 + %78 = load i32, ptr %item12, align 4 + %79 = call i32 (ptr, ...) @printf(ptr @10, i32 %78) + br label %foreach.inc.l30 + +foreach.inc.l30: ; preds = %foreach.loop.l30 + %idx13 = load i32, ptr %idx11, align 4 + %idx.inc14 = add i32 %idx13, 1 + store i32 %idx.inc14, ptr %idx11, align 4 + %80 = getelementptr inbounds i32, ptr %75, i32 %idx.inc14 + %81 = load i32, ptr %80, align 4 + store i32 %81, ptr %item12, align 4 + br label %foreach.cond.l30 + +foreach.cond.l30: ; preds = %foreach.inc.l30 + %82 = load i32, ptr %idx11, align 4 %83 = icmp ult i32 %82, %62 - br i1 %83, label %foreach.loop21, label %foreach.end26 + br i1 %83, label %foreach.loop.l30, label %foreach.end.l30 -foreach.end26: ; preds = %foreach.cond25 - call void @llvm.stackrestore(i8* %67) - %84 = load i32, i32* %result, align 4 +foreach.end.l30: ; preds = %foreach.cond.l30 + call void @llvm.stackrestore(ptr %67) + %84 = load i32, ptr %result, align 4 ret i32 %84 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) -; Function Attrs: nofree nosync nounwind willreturn -declare i8* @llvm.stacksave() #0 +; Function Attrs: nocallback nofree nosync nounwind willreturn +declare ptr @llvm.stacksave() #0 -; Function Attrs: nofree nosync nounwind willreturn -declare void @llvm.stackrestore(i8*) #0 +; Function Attrs: nocallback nofree nosync nounwind willreturn +declare void @llvm.stackrestore(ptr) #0 -attributes #0 = { nofree nosync nounwind willreturn } +attributes #0 = { nocallback nofree nosync nounwind willreturn } diff --git a/test/test-files/generator/arrays/success-arrays-multidimensional/ir-code.ll b/test/test-files/generator/arrays/success-arrays-multidimensional/ir-code.ll index 376bf47bc..a0be65a82 100644 --- a/test/test-files/generator/arrays/success-arrays-multidimensional/ir-code.ll +++ b/test/test-files/generator/arrays/success-arrays-multidimensional/ir-code.ll @@ -6,7 +6,7 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [15 x i8] c"Cell [1,3]: %d\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %a = alloca [10 x [10 x i32]], align 4 %i = alloca i32, align 4 @@ -16,70 +16,70 @@ entry: %2 = alloca i1, align 1 %3 = alloca i32, align 4 %4 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - store [10 x [10 x i32]] zeroinitializer, [10 x [10 x i32]]* %a, align 4 - store i32 0, i32* %i, align 4 - br label %for.cond3 + store i32 0, ptr %result, align 4 + store [10 x [10 x i32]] zeroinitializer, ptr %a, align 4 + store i32 0, ptr %i, align 4 + br label %for.cond.l3 -for: ; preds = %for.cond3 - store i32 0, i32* %j, align 4 - br label %for.cond +for.l3: ; preds = %for.cond.l3 + store i32 0, ptr %j, align 4 + br label %for.cond.l4 -for1: ; preds = %for.cond - %5 = load i32, i32* %i, align 4 - %6 = load i32, i32* %j, align 4 +for.l4: ; preds = %for.cond.l4 + %5 = load i32, ptr %i, align 4 + %6 = load i32, ptr %j, align 4 %7 = mul i32 %5, %6 - store i32 %7, i32* %0, align 4 - %8 = load i32, i32* %0, align 4 - %9 = load [10 x [10 x i32]], [10 x [10 x i32]]* %a, align 4 - %10 = load i32, i32* %i, align 4 - %11 = getelementptr inbounds [10 x [10 x i32]], [10 x [10 x i32]]* %a, i32 0, i32 %10 - %12 = load [10 x i32], [10 x i32]* %11, align 4 - %13 = load i32, i32* %j, align 4 - %14 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i32 0, i32 %13 - store i32 %8, i32* %14, align 4 - br label %for.inc + store i32 %7, ptr %0, align 4 + %8 = load i32, ptr %0, align 4 + %9 = load [10 x [10 x i32]], ptr %a, align 4 + %10 = load i32, ptr %i, align 4 + %11 = getelementptr inbounds [10 x [10 x i32]], ptr %a, i32 0, i32 %10 + %12 = load [10 x i32], ptr %11, align 4 + %13 = load i32, ptr %j, align 4 + %14 = getelementptr inbounds [10 x i32], ptr %11, i32 0, i32 %13 + store i32 %8, ptr %14, align 4 + br label %for.inc.l4 -for.inc: ; preds = %for1 - %15 = load i32, i32* %j, align 4 +for.inc.l4: ; preds = %for.l4 + %15 = load i32, ptr %j, align 4 %16 = add i32 %15, 1 - store i32 %16, i32* %j, align 4 - store i32 %15, i32* %1, align 4 - br label %for.cond + store i32 %16, ptr %j, align 4 + store i32 %15, ptr %1, align 4 + br label %for.cond.l4 -for.cond: ; preds = %for.inc, %for - %17 = load i32, i32* %j, align 4 +for.cond.l4: ; preds = %for.inc.l4, %for.l3 + %17 = load i32, ptr %j, align 4 %18 = icmp slt i32 %17, 10 - store i1 %18, i1* %2, align 1 - %19 = load i1, i1* %2, align 1 - br i1 %19, label %for1, label %for.end + store i1 %18, ptr %2, align 1 + %19 = load i1, ptr %2, align 1 + br i1 %19, label %for.l4, label %for.end.l4 -for.end: ; preds = %for.cond - br label %for.inc2 +for.end.l4: ; preds = %for.cond.l4 + br label %for.inc.l3 -for.inc2: ; preds = %for.end - %20 = load i32, i32* %i, align 4 +for.inc.l3: ; preds = %for.end.l4 + %20 = load i32, ptr %i, align 4 %21 = add i32 %20, 1 - store i32 %21, i32* %i, align 4 - store i32 %20, i32* %3, align 4 - br label %for.cond3 + store i32 %21, ptr %i, align 4 + store i32 %20, ptr %3, align 4 + br label %for.cond.l3 -for.cond3: ; preds = %for.inc2, %entry - %22 = load i32, i32* %i, align 4 +for.cond.l3: ; preds = %for.inc.l3, %entry.l1 + %22 = load i32, ptr %i, align 4 %23 = icmp slt i32 %22, 10 - store i1 %23, i1* %4, align 1 - %24 = load i1, i1* %4, align 1 - br i1 %24, label %for, label %for.end4 + store i1 %23, ptr %4, align 1 + %24 = load i1, ptr %4, align 1 + br i1 %24, label %for.l3, label %for.end.l3 -for.end4: ; preds = %for.cond3 - %25 = load [10 x [10 x i32]], [10 x [10 x i32]]* %a, align 4 - %26 = getelementptr inbounds [10 x [10 x i32]], [10 x [10 x i32]]* %a, i32 0, i32 1 - %27 = load [10 x i32], [10 x i32]* %26, align 4 - %28 = getelementptr inbounds [10 x i32], [10 x i32]* %26, i32 0, i32 3 - %29 = load i32, i32* %28, align 4 - %30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @0, i32 0, i32 0), i32 %29) - %31 = load i32, i32* %result, align 4 +for.end.l3: ; preds = %for.cond.l3 + %25 = load [10 x [10 x i32]], ptr %a, align 4 + %26 = getelementptr inbounds [10 x [10 x i32]], ptr %a, i32 0, i32 1 + %27 = load [10 x i32], ptr %26, align 4 + %28 = getelementptr inbounds [10 x i32], ptr %26, i32 0, i32 3 + %29 = load i32, ptr %28, align 4 + %30 = call i32 (ptr, ...) @printf(ptr @0, i32 %29) + %31 = load i32, ptr %result, align 4 ret i32 %31 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/arrays/success-arrays/ir-code.ll b/test/test-files/generator/arrays/success-arrays/ir-code.ll index 9967a5786..d8d6cb480 100644 --- a/test/test-files/generator/arrays/success-arrays/ir-code.ll +++ b/test/test-files/generator/arrays/success-arrays/ir-code.ll @@ -6,40 +6,40 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [23 x i8] c"Item 0: %d, item 2: %d\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %value0 = alloca i32, align 4 %intArray = alloca [5 x i32], align 4 - store i32 0, i32* %result, align 4 - store i32 2, i32* %value0, align 4 - %0 = load i32, i32* %value0, align 4 - %1 = getelementptr inbounds [5 x i32], [5 x i32]* %intArray, i32 0, i32 0 - store i32 %0, i32* %1, align 4 - %2 = getelementptr inbounds [5 x i32], [5 x i32]* %intArray, i32 0, i32 1 - store i32 7, i32* %2, align 4 - %3 = getelementptr inbounds [5 x i32], [5 x i32]* %intArray, i32 0, i32 2 - store i32 4, i32* %3, align 4 - %4 = getelementptr inbounds [5 x i32], [5 x i32]* %intArray, i32 0, i32 3 - store i32 0, i32* %4, align 4 - %5 = getelementptr inbounds [5 x i32], [5 x i32]* %intArray, i32 0, i32 4 - store i32 0, i32* %5, align 4 - %6 = load [5 x i32], [5 x i32]* %intArray, align 4 - %7 = getelementptr inbounds [5 x i32], [5 x i32]* %intArray, i32 0, i32 2 - %8 = load i32, i32* %7, align 4 + store i32 0, ptr %result, align 4 + store i32 2, ptr %value0, align 4 + %0 = load i32, ptr %value0, align 4 + %1 = getelementptr inbounds [5 x i32], ptr %intArray, i32 0, i32 0 + store i32 %0, ptr %1, align 4 + %2 = getelementptr inbounds [5 x i32], ptr %intArray, i32 0, i32 1 + store i32 7, ptr %2, align 4 + %3 = getelementptr inbounds [5 x i32], ptr %intArray, i32 0, i32 2 + store i32 4, ptr %3, align 4 + %4 = getelementptr inbounds [5 x i32], ptr %intArray, i32 0, i32 3 + store i32 0, ptr %4, align 4 + %5 = getelementptr inbounds [5 x i32], ptr %intArray, i32 0, i32 4 + store i32 0, ptr %5, align 4 + %6 = load [5 x i32], ptr %intArray, align 4 + %7 = getelementptr inbounds [5 x i32], ptr %intArray, i32 0, i32 2 + %8 = load i32, ptr %7, align 4 %9 = mul i32 %8, 11 - store i32 %9, i32* %7, align 4 - %10 = load [5 x i32], [5 x i32]* %intArray, align 4 - %11 = getelementptr inbounds [5 x i32], [5 x i32]* %intArray, i32 0, i32 0 - store i32 3, i32* %11, align 4 - %12 = load [5 x i32], [5 x i32]* %intArray, align 4 - %13 = getelementptr inbounds [5 x i32], [5 x i32]* %intArray, i32 0, i32 0 - %14 = load i32, i32* %13, align 4 - %15 = load [5 x i32], [5 x i32]* %intArray, align 4 - %16 = getelementptr inbounds [5 x i32], [5 x i32]* %intArray, i32 0, i32 2 - %17 = load i32, i32* %16, align 4 - %18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @0, i32 0, i32 0), i32 %14, i32 %17) - %19 = load i32, i32* %result, align 4 + store i32 %9, ptr %7, align 4 + %10 = load [5 x i32], ptr %intArray, align 4 + %11 = getelementptr inbounds [5 x i32], ptr %intArray, i32 0, i32 0 + store i32 3, ptr %11, align 4 + %12 = load [5 x i32], ptr %intArray, align 4 + %13 = getelementptr inbounds [5 x i32], ptr %intArray, i32 0, i32 0 + %14 = load i32, ptr %13, align 4 + %15 = load [5 x i32], ptr %intArray, align 4 + %16 = getelementptr inbounds [5 x i32], ptr %intArray, i32 0, i32 2 + %17 = load i32, ptr %16, align 4 + %18 = call i32 (ptr, ...) @printf(ptr @0, i32 %14, i32 %17) + %19 = load i32, ptr %result, align 4 ret i32 %19 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/arrays/success-arrays2/ir-code.ll b/test/test-files/generator/arrays/success-arrays2/ir-code.ll index 1789de8e0..c2038dac1 100644 --- a/test/test-files/generator/arrays/success-arrays2/ir-code.ll +++ b/test/test-files/generator/arrays/success-arrays2/ir-code.ll @@ -9,25 +9,25 @@ target triple = "x86_64-w64-windows-gnu" @2 = private unnamed_addr constant [17 x i8] c"intArray[9]: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %intArray = alloca [10 x i32], align 4 - store i32 0, i32* %result, align 4 - store [10 x i32] [i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128, i32 256, i32 512], [10 x i32]* %intArray, align 4 - %0 = load [10 x i32], [10 x i32]* %intArray, align 4 - %1 = getelementptr inbounds [10 x i32], [10 x i32]* %intArray, i32 0, i32 3 - %2 = load i32, i32* %1, align 4 - %3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @0, i32 0, i32 0), i32 %2) - %4 = load [10 x i32], [10 x i32]* %intArray, align 4 - %5 = getelementptr inbounds [10 x i32], [10 x i32]* %intArray, i32 0, i32 7 - %6 = load i32, i32* %5, align 4 - %7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @1, i32 0, i32 0), i32 %6) - %8 = load [10 x i32], [10 x i32]* %intArray, align 4 - %9 = getelementptr inbounds [10 x i32], [10 x i32]* %intArray, i32 0, i32 9 - %10 = load i32, i32* %9, align 4 - %11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @2, i32 0, i32 0), i32 %10) - %12 = load i32, i32* %result, align 4 + store i32 0, ptr %result, align 4 + store [10 x i32] [i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128, i32 256, i32 512], ptr %intArray, align 4 + %0 = load [10 x i32], ptr %intArray, align 4 + %1 = getelementptr inbounds [10 x i32], ptr %intArray, i32 0, i32 3 + %2 = load i32, ptr %1, align 4 + %3 = call i32 (ptr, ...) @printf(ptr @0, i32 %2) + %4 = load [10 x i32], ptr %intArray, align 4 + %5 = getelementptr inbounds [10 x i32], ptr %intArray, i32 0, i32 7 + %6 = load i32, ptr %5, align 4 + %7 = call i32 (ptr, ...) @printf(ptr @1, i32 %6) + %8 = load [10 x i32], ptr %intArray, align 4 + %9 = getelementptr inbounds [10 x i32], ptr %intArray, i32 0, i32 9 + %10 = load i32, ptr %9, align 4 + %11 = call i32 (ptr, ...) @printf(ptr @2, i32 %10) + %12 = load i32, ptr %result, align 4 ret i32 %12 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/arrays/success-arrays3/ir-code.ll b/test/test-files/generator/arrays/success-arrays3/ir-code.ll index 0b20eabbb..86bd444d5 100644 --- a/test/test-files/generator/arrays/success-arrays3/ir-code.ll +++ b/test/test-files/generator/arrays/success-arrays3/ir-code.ll @@ -7,21 +7,21 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [17 x i8] c"intArray[1]: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %intArray = alloca [2 x i32], align 4 %intArray1 = alloca [2 x i32], align 4 - store i32 0, i32* %result, align 4 - store [2 x i32] zeroinitializer, [2 x i32]* %intArray, align 4 - store [2 x i32] [i32 1, i32 2], [2 x i32]* %intArray1, align 4 - %0 = load [2 x i32], [2 x i32]* %intArray1, align 4 - store [2 x i32] %0, [2 x i32]* %intArray, align 4 - %1 = load [2 x i32], [2 x i32]* %intArray, align 4 - %2 = getelementptr inbounds [2 x i32], [2 x i32]* %intArray, i32 0, i32 1 - %3 = load i32, i32* %2, align 4 - %4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @0, i32 0, i32 0), i32 %3) - %5 = load i32, i32* %result, align 4 + store i32 0, ptr %result, align 4 + store [2 x i32] zeroinitializer, ptr %intArray, align 4 + store [2 x i32] [i32 1, i32 2], ptr %intArray1, align 4 + %0 = load [2 x i32], ptr %intArray1, align 4 + store [2 x i32] %0, ptr %intArray, align 4 + %1 = load [2 x i32], ptr %intArray, align 4 + %2 = getelementptr inbounds [2 x i32], ptr %intArray, i32 0, i32 1 + %3 = load i32, ptr %2, align 4 + %4 = call i32 (ptr, ...) @printf(ptr @0, i32 %3) + %5 = load i32, ptr %result, align 4 ret i32 %5 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/arrays/success-arrays4/ir-code.ll b/test/test-files/generator/arrays/success-arrays4/ir-code.ll index 385017a3b..c8e4c4813 100644 --- a/test/test-files/generator/arrays/success-arrays4/ir-code.ll +++ b/test/test-files/generator/arrays/success-arrays4/ir-code.ll @@ -7,50 +7,50 @@ target triple = "x86_64-w64-windows-gnu" @1 = private unnamed_addr constant [6 x i8] c"Spice\00", align 1 @2 = private unnamed_addr constant [13 x i8] c"programmers!\00", align 1 @3 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 -@welcomeMessage = constant [5 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @0, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @1, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @2, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @3, i32 0, i32 0)] +@welcomeMessage = constant [5 x ptr] [ptr @0, ptr @1, ptr @2, ptr @3, ptr @3] @4 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 @5 = private unnamed_addr constant [17 x i8] c"Word no. %d: %s\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 - %welcomeMessage = alloca [5 x i8*], align 8 + %welcomeMessage = alloca [5 x ptr], align 8 %i = alloca i32, align 4 - %word = alloca i8*, align 8 - store i32 0, i32* %result, align 4 - store [5 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @0, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @1, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @2, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @3, i32 0, i32 0)], [5 x i8*]* %welcomeMessage, align 8 - store i32 0, i32* %i, align 4 - store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @4, i32 0, i32 0), i8** %word, align 8 - %0 = load [5 x i8*], [5 x i8*]* %welcomeMessage, align 8 - %1 = load i32, i32* %i, align 4 - %2 = getelementptr inbounds [5 x i8*], [5 x i8*]* %welcomeMessage, i32 0, i32 %1 - %3 = load i8*, i8** %2, align 8 - store i8* %3, i8** %word, align 8 - br label %foreach.loop + %word = alloca ptr, align 8 + store i32 0, ptr %result, align 4 + store [5 x ptr] [ptr @0, ptr @1, ptr @2, ptr @3, ptr @3], ptr %welcomeMessage, align 8 + store i32 0, ptr %i, align 4 + store ptr @4, ptr %word, align 8 + %0 = load [5 x ptr], ptr %welcomeMessage, align 8 + %1 = load i32, ptr %i, align 4 + %2 = getelementptr inbounds [5 x ptr], ptr %welcomeMessage, i32 0, i32 %1 + %3 = load ptr, ptr %2, align 8 + store ptr %3, ptr %word, align 8 + br label %foreach.loop.l3 -foreach.loop: ; preds = %foreach.cond, %entry - %4 = load i32, i32* %i, align 4 - %5 = load i8*, i8** %word, align 8 - %6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @5, i32 0, i32 0), i32 %4, i8* %5) - br label %foreach.inc +foreach.loop.l3: ; preds = %foreach.cond.l3, %entry.l1 + %4 = load i32, ptr %i, align 4 + %5 = load ptr, ptr %word, align 8 + %6 = call i32 (ptr, ...) @printf(ptr @5, i32 %4, ptr %5) + br label %foreach.inc.l3 -foreach.inc: ; preds = %foreach.loop - %idx = load i32, i32* %i, align 4 +foreach.inc.l3: ; preds = %foreach.loop.l3 + %idx = load i32, ptr %i, align 4 %idx.inc = add i32 %idx, 1 - store i32 %idx.inc, i32* %i, align 4 - %7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %welcomeMessage, i32 0, i32 %idx.inc - %8 = load i8*, i8** %7, align 8 - store i8* %8, i8** %word, align 8 - br label %foreach.cond + store i32 %idx.inc, ptr %i, align 4 + %7 = getelementptr inbounds [5 x ptr], ptr %welcomeMessage, i32 0, i32 %idx.inc + %8 = load ptr, ptr %7, align 8 + store ptr %8, ptr %word, align 8 + br label %foreach.cond.l3 -foreach.cond: ; preds = %foreach.inc - %9 = load i32, i32* %i, align 4 +foreach.cond.l3: ; preds = %foreach.inc.l3 + %9 = load i32, ptr %i, align 4 %10 = icmp ult i32 %9, 5 - br i1 %10, label %foreach.loop, label %foreach.end + br i1 %10, label %foreach.loop.l3, label %foreach.end.l3 -foreach.end: ; preds = %foreach.cond - %11 = load i32, i32* %result, align 4 +foreach.end.l3: ; preds = %foreach.cond.l3 + %11 = load i32, ptr %result, align 4 ret i32 %11 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/arrays/success-string-char-access/ir-code.ll b/test/test-files/generator/arrays/success-string-char-access/ir-code.ll index 244ef95cf..0c20e2763 100644 --- a/test/test-files/generator/arrays/success-string-char-access/ir-code.ll +++ b/test/test-files/generator/arrays/success-string-char-access/ir-code.ll @@ -7,18 +7,18 @@ target triple = "x86_64-w64-windows-gnu" @1 = private unnamed_addr constant [10 x i8] c"Char: %c\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 - %test = alloca i8*, align 8 - store i32 0, i32* %result, align 4 - store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @0, i32 0, i32 0), i8** %test, align 8 - %0 = load i8*, i8** %test, align 8 - %1 = getelementptr inbounds i8, i8* %0, i32 2 - %2 = load i8, i8* %1, align 1 + %test = alloca ptr, align 8 + store i32 0, ptr %result, align 4 + store ptr @0, ptr %test, align 8 + %0 = load ptr, ptr %test, align 8 + %1 = getelementptr inbounds i8, ptr %0, i32 2 + %2 = load i8, ptr %1, align 1 %3 = sext i8 %2 to i32 - %4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @1, i32 0, i32 0), i32 %3) - %5 = load i32, i32* %result, align 4 + %4 = call i32 (ptr, ...) @printf(ptr @1, i32 %3) + %5 = load i32, ptr %result, align 4 ret i32 %5 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/assertions/success-basic-assertion/ir-code.ll b/test/test-files/generator/assertions/success-basic-assertion/ir-code.ll index 12f034eae..92ec3734d 100644 --- a/test/test-files/generator/assertions/success-basic-assertion/ir-code.ll +++ b/test/test-files/generator/assertions/success-basic-assertion/ir-code.ll @@ -7,25 +7,25 @@ target triple = "x86_64-w64-windows-gnu" @1 = private unnamed_addr constant [12 x i8] c"Unreachable\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %0 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - store i1 false, i1* %0, align 1 - %1 = load i1, i1* %0, align 1 - br i1 %1, label %if.end, label %if.then + store i32 0, ptr %result, align 4 + store i1 false, ptr %0, align 1 + %1 = load i1, ptr %0, align 1 + br i1 %1, label %assert.end.l2, label %assert.then.l2 -if.then: ; preds = %entry - %2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @0, i32 0, i32 0)) +assert.then.l2: ; preds = %entry.l1 + %2 = call i32 (ptr, ...) @printf(ptr @0) call void @exit(i32 1) unreachable -if.end: ; preds = %entry - %3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @1, i32 0, i32 0)) - %4 = load i32, i32* %result, align 4 +assert.end.l2: ; preds = %entry.l1 + %3 = call i32 (ptr, ...) @printf(ptr @1) + %4 = load i32, ptr %result, align 4 ret i32 %4 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) declare void @exit(i32) diff --git a/test/test-files/generator/builtins/success-len/ir-code-O2.ll b/test/test-files/generator/builtins/success-len/ir-code-O2.ll index 754dacce2..ac7580275 100644 --- a/test/test-files/generator/builtins/success-len/ir-code-O2.ll +++ b/test/test-files/generator/builtins/success-len/ir-code-O2.ll @@ -8,12 +8,12 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #0 { -entry: - %0 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @0, i64 0, i64 0), i32 7) +entry.l1: + %0 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 7) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/builtins/success-len/ir-code.ll b/test/test-files/generator/builtins/success-len/ir-code.ll index e19bd4ffc..1b58e9dea 100644 --- a/test/test-files/generator/builtins/success-len/ir-code.ll +++ b/test/test-files/generator/builtins/success-len/ir-code.ll @@ -7,18 +7,18 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [18 x i8] c"Array length: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %testIntArray = alloca [7 x i32], align 4 %0 = alloca i32, align 4 - store i32 0, i32* %result, align 4 - store [7 x i32] [i32 1, i32 2, i32 3, i32 4, i32 0, i32 0, i32 0], [7 x i32]* %testIntArray, align 4 - %1 = load [7 x i32], [7 x i32]* %testIntArray, align 4 - store i32 7, i32* %0, align 4 - %2 = load i32, i32* %0, align 4 - %3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @0, i32 0, i32 0), i32 %2) - %4 = load i32, i32* %result, align 4 + store i32 0, ptr %result, align 4 + store [7 x i32] [i32 1, i32 2, i32 3, i32 4, i32 0, i32 0, i32 0], ptr %testIntArray, align 4 + %1 = load [7 x i32], ptr %testIntArray, align 4 + store i32 7, ptr %0, align 4 + %2 = load i32, ptr %0, align 4 + %3 = call i32 (ptr, ...) @printf(ptr @0, i32 %2) + %4 = load i32, ptr %result, align 4 ret i32 %4 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/builtins/success-printf/ir-code-O2.ll b/test/test-files/generator/builtins/success-printf/ir-code-O2.ll index 2b60faa0f..9df61dd56 100644 --- a/test/test-files/generator/builtins/success-printf/ir-code-O2.ll +++ b/test/test-files/generator/builtins/success-printf/ir-code-O2.ll @@ -7,12 +7,12 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #0 { -entry: - %0 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @0, i64 0, i64 0)) +entry.l1: + %0 = tail call i32 (ptr, ...) @printf(ptr nonnull @0) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/builtins/success-printf/ir-code.ll b/test/test-files/generator/builtins/success-printf/ir-code.ll index d44a68a99..69b9a3284 100644 --- a/test/test-files/generator/builtins/success-printf/ir-code.ll +++ b/test/test-files/generator/builtins/success-printf/ir-code.ll @@ -6,12 +6,12 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [13 x i8] c"Hello World!\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 - store i32 0, i32* %result, align 4 - %0 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @0, i32 0, i32 0)) - %1 = load i32, i32* %result, align 4 + store i32 0, ptr %result, align 4 + %0 = call i32 (ptr, ...) @printf(ptr @0) + %1 = load i32, ptr %result, align 4 ret i32 %1 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/builtins/success-sizeof/ir-code-O2.ll b/test/test-files/generator/builtins/success-sizeof/ir-code-O2.ll index c7cc6ea9b..c3f28a6cd 100644 --- a/test/test-files/generator/builtins/success-sizeof/ir-code-O2.ll +++ b/test/test-files/generator/builtins/success-sizeof/ir-code-O2.ll @@ -18,22 +18,22 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #0 { -entry: - %0 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @0, i64 0, i64 0), i32 64) - %1 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @1, i64 0, i64 0), i32 32) - %2 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @2, i64 0, i64 0), i32 16) - %3 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @3, i64 0, i64 0), i32 64) - %4 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @4, i64 0, i64 0), i32 8) - %5 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @5, i64 0, i64 0), i32 8) - %6 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @6, i64 0, i64 0), i32 64) - %7 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @7, i64 0, i64 0), i32 1) - %8 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @8, i64 0, i64 0), i32 224) - %9 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @9, i64 0, i64 0), i32 64) - %10 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @10, i64 0, i64 0), i32 128) +entry.l7: + %0 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 64) + %1 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i32 32) + %2 = tail call i32 (ptr, ...) @printf(ptr nonnull @2, i32 16) + %3 = tail call i32 (ptr, ...) @printf(ptr nonnull @3, i32 64) + %4 = tail call i32 (ptr, ...) @printf(ptr nonnull @4, i32 8) + %5 = tail call i32 (ptr, ...) @printf(ptr nonnull @5, i32 8) + %6 = tail call i32 (ptr, ...) @printf(ptr nonnull @6, i32 64) + %7 = tail call i32 (ptr, ...) @printf(ptr nonnull @7, i32 1) + %8 = tail call i32 (ptr, ...) @printf(ptr nonnull @8, i32 224) + %9 = tail call i32 (ptr, ...) @printf(ptr nonnull @9, i32 64) + %10 = tail call i32 (ptr, ...) @printf(ptr nonnull @10, i32 128) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/builtins/success-sizeof/ir-code.ll b/test/test-files/generator/builtins/success-sizeof/ir-code.ll index 2ba199b11..36d25b3e3 100644 --- a/test/test-files/generator/builtins/success-sizeof/ir-code.ll +++ b/test/test-files/generator/builtins/success-sizeof/ir-code.ll @@ -18,7 +18,7 @@ target triple = "x86_64-w64-windows-gnu" @11 = private unnamed_addr constant [29 x i8] c"Size of struct instance: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l7: %result = alloca i32, align 4 %0 = alloca double, align 8 %1 = alloca double, align 8 @@ -35,59 +35,59 @@ entry: %12 = alloca [7 x i32], align 4 %13 = alloca i32, align 4 %intVariable = alloca i32, align 4 - %14 = alloca i32*, align 8 + %14 = alloca ptr, align 8 %15 = alloca i32, align 4 %16 = alloca i32, align 4 - store i32 0, i32* %result, align 4 - store double 0x40335992641B328B, double* %0, align 8 - %17 = load double, double* %0, align 8 + store i32 0, ptr %result, align 4 + store double 0x40335992641B328B, ptr %0, align 8 + %17 = load double, ptr %0, align 8 %18 = fmul double %17, -1.000000e+00 - store double %18, double* %1, align 8 - %19 = load double, double* %1, align 8 - store i32 64, i32* %2, align 4 - %20 = load i32, i32* %2, align 4 - %21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @0, i32 0, i32 0), i32 %20) - store i32 32, i32* %3, align 4 - %22 = load i32, i32* %3, align 4 - %23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @1, i32 0, i32 0), i32 %22) - store i32 16, i32* %4, align 4 - %24 = load i32, i32* %4, align 4 - %25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @2, i32 0, i32 0), i32 %24) - store i32 64, i32* %5, align 4 - %26 = load i32, i32* %5, align 4 - %27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @3, i32 0, i32 0), i32 %26) - store i8 13, i8* %6, align 1 - %28 = load i8, i8* %6, align 1 - store i32 8, i32* %7, align 4 - %29 = load i32, i32* %7, align 4 - %30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @4, i32 0, i32 0), i32 %29) - store i8 65, i8* %8, align 1 - %31 = load i8, i8* %8, align 1 - store i32 8, i32* %9, align 4 - %32 = load i32, i32* %9, align 4 - %33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @5, i32 0, i32 0), i32 %32) - store i32 64, i32* %10, align 4 - %34 = load i32, i32* %10, align 4 - %35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @6, i32 0, i32 0), i32 %34) - store i32 1, i32* %11, align 4 - %36 = load i32, i32* %11, align 4 - %37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @8, i32 0, i32 0), i32 %36) - store [7 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7], [7 x i32]* %12, align 4 - %38 = load [7 x i32], [7 x i32]* %12, align 4 - store i32 224, i32* %13, align 4 - %39 = load i32, i32* %13, align 4 - %40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @9, i32 0, i32 0), i32 %39) - store i32 123, i32* %intVariable, align 4 - store i32* %intVariable, i32** %14, align 8 - %41 = load i32*, i32** %14, align 8 - store i32 64, i32* %15, align 4 - %42 = load i32, i32* %15, align 4 - %43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @10, i32 0, i32 0), i32 %42) - store i32 128, i32* %16, align 4 - %44 = load i32, i32* %16, align 4 - %45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @11, i32 0, i32 0), i32 %44) - %46 = load i32, i32* %result, align 4 + store double %18, ptr %1, align 8 + %19 = load double, ptr %1, align 8 + store i32 64, ptr %2, align 4 + %20 = load i32, ptr %2, align 4 + %21 = call i32 (ptr, ...) @printf(ptr @0, i32 %20) + store i32 32, ptr %3, align 4 + %22 = load i32, ptr %3, align 4 + %23 = call i32 (ptr, ...) @printf(ptr @1, i32 %22) + store i32 16, ptr %4, align 4 + %24 = load i32, ptr %4, align 4 + %25 = call i32 (ptr, ...) @printf(ptr @2, i32 %24) + store i32 64, ptr %5, align 4 + %26 = load i32, ptr %5, align 4 + %27 = call i32 (ptr, ...) @printf(ptr @3, i32 %26) + store i8 13, ptr %6, align 1 + %28 = load i8, ptr %6, align 1 + store i32 8, ptr %7, align 4 + %29 = load i32, ptr %7, align 4 + %30 = call i32 (ptr, ...) @printf(ptr @4, i32 %29) + store i8 65, ptr %8, align 1 + %31 = load i8, ptr %8, align 1 + store i32 8, ptr %9, align 4 + %32 = load i32, ptr %9, align 4 + %33 = call i32 (ptr, ...) @printf(ptr @5, i32 %32) + store i32 64, ptr %10, align 4 + %34 = load i32, ptr %10, align 4 + %35 = call i32 (ptr, ...) @printf(ptr @6, i32 %34) + store i32 1, ptr %11, align 4 + %36 = load i32, ptr %11, align 4 + %37 = call i32 (ptr, ...) @printf(ptr @8, i32 %36) + store [7 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7], ptr %12, align 4 + %38 = load [7 x i32], ptr %12, align 4 + store i32 224, ptr %13, align 4 + %39 = load i32, ptr %13, align 4 + %40 = call i32 (ptr, ...) @printf(ptr @9, i32 %39) + store i32 123, ptr %intVariable, align 4 + store ptr %intVariable, ptr %14, align 8 + %41 = load ptr, ptr %14, align 8 + store i32 64, ptr %15, align 4 + %42 = load i32, ptr %15, align 4 + %43 = call i32 (ptr, ...) @printf(ptr @10, i32 %42) + store i32 128, ptr %16, align 4 + %44 = load i32, ptr %16, align 4 + %45 = call i32 (ptr, ...) @printf(ptr @11, i32 %44) + %46 = load i32, ptr %result, align 4 ret i32 %46 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/cli-args/success-cli-args/ir-code.ll b/test/test-files/generator/cli-args/success-cli-args/ir-code.ll index ca810cafe..46e79b2b8 100644 --- a/test/test-files/generator/cli-args/success-cli-args/ir-code.ll +++ b/test/test-files/generator/cli-args/success-cli-args/ir-code.ll @@ -7,37 +7,37 @@ target triple = "x86_64-w64-windows-gnu" @1 = private unnamed_addr constant [16 x i8] c"Argv no. 0: %s\0A\00", align 1 @2 = private unnamed_addr constant [16 x i8] c"Argv no. 1: %s\0A\00", align 1 -define i32 @main(i32 %0, i8** %1) { -entry: +define i32 @main(i32 %0, ptr %1) { +entry.l1: %argc = alloca i32, align 4 - %argv = alloca i8**, align 8 + %argv = alloca ptr, align 8 %result = alloca i32, align 4 %2 = alloca i1, align 1 - store i32 %0, i32* %argc, align 4 - store i8** %1, i8*** %argv, align 8 - store i32 0, i32* %result, align 4 - %3 = load i32, i32* %argc, align 4 - %4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @0, i32 0, i32 0), i32 %3) - %5 = load i8**, i8*** %argv, align 8 - %6 = getelementptr inbounds i8*, i8** %5, i32 0 - %7 = load i8*, i8** %6, align 8 - %8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @1, i32 0, i32 0), i8* %7) - %9 = load i32, i32* %argc, align 4 + store i32 %0, ptr %argc, align 4 + store ptr %1, ptr %argv, align 8 + store i32 0, ptr %result, align 4 + %3 = load i32, ptr %argc, align 4 + %4 = call i32 (ptr, ...) @printf(ptr @0, i32 %3) + %5 = load ptr, ptr %argv, align 8 + %6 = getelementptr inbounds ptr, ptr %5, i32 0 + %7 = load ptr, ptr %6, align 8 + %8 = call i32 (ptr, ...) @printf(ptr @1, ptr %7) + %9 = load i32, ptr %argc, align 4 %10 = icmp sgt i32 %9, 1 - store i1 %10, i1* %2, align 1 - %11 = load i1, i1* %2, align 1 - br i1 %11, label %if.then, label %if.end + store i1 %10, ptr %2, align 1 + %11 = load i1, ptr %2, align 1 + br i1 %11, label %if.then.l4, label %if.end.l4 -if.then: ; preds = %entry - %12 = load i8**, i8*** %argv, align 8 - %13 = getelementptr inbounds i8*, i8** %12, i32 1 - %14 = load i8*, i8** %13, align 8 - %15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @2, i32 0, i32 0), i8* %14) - br label %if.end +if.then.l4: ; preds = %entry.l1 + %12 = load ptr, ptr %argv, align 8 + %13 = getelementptr inbounds ptr, ptr %12, i32 1 + %14 = load ptr, ptr %13, align 8 + %15 = call i32 (ptr, ...) @printf(ptr @2, ptr %14) + br label %if.end.l4 -if.end: ; preds = %if.then, %entry - %16 = load i32, i32* %result, align 4 +if.end.l4: ; preds = %if.then.l4, %entry.l1 + %16 = load i32, ptr %result, align 4 ret i32 %16 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/ext-decl/success-ext-decl/ir-code-O1.ll b/test/test-files/generator/ext-decl/success-ext-decl/ir-code-O1.ll index 0418a10f6..53aa5ea9a 100644 --- a/test/test-files/generator/ext-decl/success-ext-decl/ir-code-O1.ll +++ b/test/test-files/generator/ext-decl/success-ext-decl/ir-code-O1.ll @@ -9,26 +9,26 @@ target triple = "x86_64-w64-windows-gnu" @str.1 = private unnamed_addr constant [17 x i8] c"Deleting dir ...\00", align 1 ; Function Attrs: nofree nounwind -declare noundef i32 @mkdir(i8* nocapture noundef readonly, i32 noundef) local_unnamed_addr #0 +declare noundef i32 @mkdir(ptr nocapture noundef readonly, i32 noundef) local_unnamed_addr #0 ; Function Attrs: nofree nounwind -declare noundef i32 @rmdir(i8* nocapture noundef readonly) local_unnamed_addr #0 +declare noundef i32 @rmdir(ptr nocapture noundef readonly) local_unnamed_addr #0 ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #0 { -entry: - %puts = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0)) - %0 = call i32 @mkdir(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @0, i64 0, i64 0), i32 511) - %puts2 = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.1, i64 0, i64 0)) - %1 = call i32 @rmdir(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @0, i64 0, i64 0)) - %2 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @1, i64 0, i64 0)) +entry.l7: + %puts = tail call i32 @puts(ptr nonnull @str) + %0 = tail call i32 @mkdir(ptr nonnull @0, i32 511) + %puts2 = tail call i32 @puts(ptr nonnull @str.1) + %1 = tail call i32 @rmdir(ptr nonnull @0) + %2 = tail call i32 (ptr, ...) @printf(ptr nonnull @1) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 ; Function Attrs: nofree nounwind -declare noundef i32 @puts(i8* nocapture noundef readonly) local_unnamed_addr #0 +declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/ext-decl/success-ext-decl/ir-code.ll b/test/test-files/generator/ext-decl/success-ext-decl/ir-code.ll index 27cf27c4e..46a815666 100644 --- a/test/test-files/generator/ext-decl/success-ext-decl/ir-code.ll +++ b/test/test-files/generator/ext-decl/success-ext-decl/ir-code.ll @@ -10,34 +10,34 @@ target triple = "x86_64-w64-windows-gnu" @3 = private unnamed_addr constant [11 x i8] c"./test-dir\00", align 1 @4 = private unnamed_addr constant [6 x i8] c"Done.\00", align 1 -declare i32 @mkdir(i8*, i32) +declare i32 @mkdir(ptr, i32) -declare i32 @rmdir(i8*) +declare i32 @rmdir(ptr) -declare void @free(i8*) +declare void @free(ptr) define i32 @main() { -entry: +entry.l7: %result = alloca i32, align 4 - %0 = alloca i8*, align 8 + %0 = alloca ptr, align 8 %1 = alloca i32, align 4 - %2 = alloca i8*, align 8 + %2 = alloca ptr, align 8 %3 = alloca i32, align 4 - store i32 0, i32* %result, align 4 - %4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @0, i32 0, i32 0)) - store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @1, i32 0, i32 0), i8** %0, align 8 - %5 = load i8*, i8** %0, align 8 - %6 = load i32, i32* @MODE_ALL_RWX, align 4 - %7 = call i32 @mkdir(i8* %5, i32 %6) - store i32 %7, i32* %1, align 4 - %8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @2, i32 0, i32 0)) - store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @3, i32 0, i32 0), i8** %2, align 8 - %9 = load i8*, i8** %2, align 8 - %10 = call i32 @rmdir(i8* %9) - store i32 %10, i32* %3, align 4 - %11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @4, i32 0, i32 0)) - %12 = load i32, i32* %result, align 4 + store i32 0, ptr %result, align 4 + %4 = call i32 (ptr, ...) @printf(ptr @0) + store ptr @1, ptr %0, align 8 + %5 = load ptr, ptr %0, align 8 + %6 = load i32, ptr @MODE_ALL_RWX, align 4 + %7 = call i32 @mkdir(ptr %5, i32 %6) + store i32 %7, ptr %1, align 4 + %8 = call i32 (ptr, ...) @printf(ptr @2) + store ptr @3, ptr %2, align 8 + %9 = load ptr, ptr %2, align 8 + %10 = call i32 @rmdir(ptr %9) + store i32 %10, ptr %3, align 4 + %11 = call i32 (ptr, ...) @printf(ptr @4) + %12 = load i32, ptr %result, align 4 ret i32 %12 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/for-loops/success-for-loop-break/ir-code-O2.ll b/test/test-files/generator/for-loops/success-for-loop-break/ir-code-O2.ll index 0551fd8da..0aaf5be96 100644 --- a/test/test-files/generator/for-loops/success-for-loop-break/ir-code-O2.ll +++ b/test/test-files/generator/for-loops/success-for-loop-break/ir-code-O2.ll @@ -9,29 +9,29 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #0 { -entry: - br label %for +entry.l1: + br label %for.l2 -for: ; preds = %for, %entry - %counter.018 = phi i32 [ 0, %entry ], [ %2, %for ] - %0 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @0, i64 0, i64 0), i32 %counter.018) - %1 = icmp ugt i32 %counter.018, 9000 - %2 = add nuw nsw i32 %counter.018, 2 - br i1 %1, label %for1, label %for +for.l2: ; preds = %for.l2, %entry.l1 + %counter.012 = phi i32 [ 0, %entry.l1 ], [ %2, %for.l2 ] + %0 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 %counter.012) + %1 = icmp ugt i32 %counter.012, 9000 + %2 = add nuw nsw i32 %counter.012, 2 + br i1 %1, label %for.l5, label %for.l2 -for1: ; preds = %for, %for1 - %subCounter.017 = phi i32 [ %5, %for1 ], [ 100, %for ] - %3 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @1, i64 0, i64 0), i32 %subCounter.017) - %4 = icmp eq i32 %subCounter.017, 11 - %5 = add nsw i32 %subCounter.017, -1 - br i1 %4, label %for.end6, label %for1 +for.l5: ; preds = %for.l2, %for.l5 + %subCounter.011 = phi i32 [ %5, %for.l5 ], [ 100, %for.l2 ] + %3 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i32 %subCounter.011) + %4 = icmp eq i32 %subCounter.011, 11 + %5 = add nsw i32 %subCounter.011, -1 + br i1 %4, label %for.end.l2, label %for.l5 -for.end6: ; preds = %for1 - %6 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @2, i64 0, i64 0)) +for.end.l2: ; preds = %for.l5 + %6 = tail call i32 (ptr, ...) @printf(ptr nonnull @2) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/for-loops/success-for-loop-break/ir-code.ll b/test/test-files/generator/for-loops/success-for-loop-break/ir-code.ll index 0061bb600..e0a812a19 100644 --- a/test/test-files/generator/for-loops/success-for-loop-break/ir-code.ll +++ b/test/test-files/generator/for-loops/success-for-loop-break/ir-code.ll @@ -8,7 +8,7 @@ target triple = "x86_64-w64-windows-gnu" @2 = private unnamed_addr constant [5 x i8] c"End.\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %counter = alloca i32, align 4 %0 = alloca i1, align 1 @@ -16,74 +16,74 @@ entry: %1 = alloca i1, align 1 %2 = alloca i1, align 1 %3 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - store i32 0, i32* %counter, align 4 - br label %for.cond5 + store i32 0, ptr %result, align 4 + store i32 0, ptr %counter, align 4 + br label %for.cond.l2 -for: ; preds = %for.cond5 - %4 = load i32, i32* %counter, align 4 - %5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @0, i32 0, i32 0), i32 %4) - %6 = load i32, i32* %counter, align 4 +for.l2: ; preds = %for.cond.l2 + %4 = load i32, ptr %counter, align 4 + %5 = call i32 (ptr, ...) @printf(ptr @0, i32 %4) + %6 = load i32, ptr %counter, align 4 %7 = icmp sge i32 %6, 9001 - store i1 %7, i1* %0, align 1 - %8 = load i1, i1* %0, align 1 - br i1 %8, label %if.then, label %if.end3 + store i1 %7, ptr %0, align 1 + %8 = load i1, ptr %0, align 1 + br i1 %8, label %if.then.l4, label %if.end.l4 -if.then: ; preds = %for - store i32 100, i32* %subCounter, align 4 - br label %for.cond +if.then.l4: ; preds = %for.l2 + store i32 100, ptr %subCounter, align 4 + br label %for.cond.l5 -for1: ; preds = %for.cond - %9 = load i32, i32* %subCounter, align 4 - %10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @1, i32 0, i32 0), i32 %9) - %11 = load i32, i32* %subCounter, align 4 +for.l5: ; preds = %for.cond.l5 + %9 = load i32, ptr %subCounter, align 4 + %10 = call i32 (ptr, ...) @printf(ptr @1, i32 %9) + %11 = load i32, ptr %subCounter, align 4 %12 = icmp eq i32 %11, 11 - store i1 %12, i1* %1, align 1 - %13 = load i1, i1* %1, align 1 - br i1 %13, label %if.then2, label %if.end + store i1 %12, ptr %1, align 1 + %13 = load i1, ptr %1, align 1 + br i1 %13, label %if.then.l7, label %if.end.l7 -if.then2: ; preds = %for1 - br label %for.end6 +if.then.l7: ; preds = %for.l5 + br label %for.end.l2 -if.end: ; preds = %for1 - br label %for.inc +if.end.l7: ; preds = %for.l5 + br label %for.inc.l5 -for.inc: ; preds = %if.end - %14 = load i32, i32* %subCounter, align 4 +for.inc.l5: ; preds = %if.end.l7 + %14 = load i32, ptr %subCounter, align 4 %15 = sub i32 %14, 1 - store i32 %15, i32* %subCounter, align 4 - br label %for.cond + store i32 %15, ptr %subCounter, align 4 + br label %for.cond.l5 -for.cond: ; preds = %for.inc, %if.then - %16 = load i32, i32* %subCounter, align 4 +for.cond.l5: ; preds = %for.inc.l5, %if.then.l4 + %16 = load i32, ptr %subCounter, align 4 %17 = icmp sge i32 %16, 10 - store i1 %17, i1* %2, align 1 - %18 = load i1, i1* %2, align 1 - br i1 %18, label %for1, label %for.end + store i1 %17, ptr %2, align 1 + %18 = load i1, ptr %2, align 1 + br i1 %18, label %for.l5, label %for.end.l5 -for.end: ; preds = %for.cond - br label %if.end3 +for.end.l5: ; preds = %for.cond.l5 + br label %if.end.l4 -if.end3: ; preds = %for.end, %for - br label %for.inc4 +if.end.l4: ; preds = %for.end.l5, %for.l2 + br label %for.inc.l2 -for.inc4: ; preds = %if.end3 - %19 = load i32, i32* %counter, align 4 +for.inc.l2: ; preds = %if.end.l4 + %19 = load i32, ptr %counter, align 4 %20 = add i32 %19, 2 - store i32 %20, i32* %counter, align 4 - br label %for.cond5 + store i32 %20, ptr %counter, align 4 + br label %for.cond.l2 -for.cond5: ; preds = %for.inc4, %entry - %21 = load i32, i32* %counter, align 4 +for.cond.l2: ; preds = %for.inc.l2, %entry.l1 + %21 = load i32, ptr %counter, align 4 %22 = icmp slt i32 %21, 10000 - store i1 %22, i1* %3, align 1 - %23 = load i1, i1* %3, align 1 - br i1 %23, label %for, label %for.end6 + store i1 %22, ptr %3, align 1 + %23 = load i1, ptr %3, align 1 + br i1 %23, label %for.l2, label %for.end.l2 -for.end6: ; preds = %for.cond5, %if.then2 - %24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0)) - %25 = load i32, i32* %result, align 4 +for.end.l2: ; preds = %for.cond.l2, %if.then.l7 + %24 = call i32 (ptr, ...) @printf(ptr @2) + %25 = load i32, ptr %result, align 4 ret i32 %25 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/for-loops/success-for-loop-continue/ir-code-O2.ll b/test/test-files/generator/for-loops/success-for-loop-continue/ir-code-O2.ll index c4fb82eb7..e5851a2b3 100644 --- a/test/test-files/generator/for-loops/success-for-loop-continue/ir-code-O2.ll +++ b/test/test-files/generator/for-loops/success-for-loop-continue/ir-code-O2.ll @@ -9,37 +9,39 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #0 { -for1.preheader.3: - %0 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @0, i64 0, i64 0), i32 0) - %1 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @0, i64 0, i64 0), i32 2) - %2 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @0, i64 0, i64 0), i32 4) - %3 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @0, i64 0, i64 0), i32 6) - br label %for1.3 - -for1.3: ; preds = %for1.3, %for1.preheader.3 - %subCounter.016.3 = phi i32 [ %5, %for1.3 ], [ 100, %for1.preheader.3 ] - %4 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @1, i64 0, i64 0), i32 %subCounter.016.3) - %.not = icmp eq i32 %subCounter.016.3, 11 - %5 = add nsw i32 %subCounter.016.3, -1 - br i1 %.not, label %for1.preheader.4, label %for1.3 - -for1.preheader.4: ; preds = %for1.3 - %6 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @0, i64 0, i64 0), i32 8) - br label %for1.4 - -for1.4: ; preds = %for1.4, %for1.preheader.4 - %subCounter.016.4 = phi i32 [ %8, %for1.4 ], [ 100, %for1.preheader.4 ] - %7 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @1, i64 0, i64 0), i32 %subCounter.016.4) - %.not18 = icmp eq i32 %subCounter.016.4, 11 - %8 = add nsw i32 %subCounter.016.4, -1 - br i1 %.not18, label %for.inc4.4, label %for1.4 - -for.inc4.4: ; preds = %for1.4 - %9 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @2, i64 0, i64 0)) +for.l5.preheader.3: + %0 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 0) + %1 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 2) + %2 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 4) + %3 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 6) + br label %for.l5.3 + +for.l5.3: ; preds = %for.l5.3, %for.l5.preheader.3 + %subCounter.010.3 = phi i32 [ %5, %for.l5.3 ], [ 100, %for.l5.preheader.3 ] + %4 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i32 %subCounter.010.3) + %5 = add nsw i32 %subCounter.010.3, -1 + %6 = add nsw i32 %subCounter.010.3, -12 + %7 = icmp ult i32 %6, -11 + br i1 %7, label %for.l5.3, label %for.l5.preheader.4 + +for.l5.preheader.4: ; preds = %for.l5.3 + %8 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 8) + br label %for.l5.4 + +for.l5.4: ; preds = %for.l5.4, %for.l5.preheader.4 + %subCounter.010.4 = phi i32 [ %10, %for.l5.4 ], [ 100, %for.l5.preheader.4 ] + %9 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i32 %subCounter.010.4) + %10 = add nsw i32 %subCounter.010.4, -1 + %11 = add nsw i32 %subCounter.010.4, -12 + %12 = icmp ult i32 %11, -11 + br i1 %12, label %for.l5.4, label %for.inc.l2.4 + +for.inc.l2.4: ; preds = %for.l5.4 + %13 = tail call i32 (ptr, ...) @printf(ptr nonnull @2) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/for-loops/success-for-loop-continue/ir-code.ll b/test/test-files/generator/for-loops/success-for-loop-continue/ir-code.ll index 0dc9c858f..d4820f8f9 100644 --- a/test/test-files/generator/for-loops/success-for-loop-continue/ir-code.ll +++ b/test/test-files/generator/for-loops/success-for-loop-continue/ir-code.ll @@ -8,7 +8,7 @@ target triple = "x86_64-w64-windows-gnu" @2 = private unnamed_addr constant [5 x i8] c"End.\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %counter = alloca i32, align 4 %0 = alloca i1, align 1 @@ -16,74 +16,74 @@ entry: %1 = alloca i1, align 1 %2 = alloca i1, align 1 %3 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - store i32 0, i32* %counter, align 4 - br label %for.cond5 + store i32 0, ptr %result, align 4 + store i32 0, ptr %counter, align 4 + br label %for.cond.l2 -for: ; preds = %for.cond5 - %4 = load i32, i32* %counter, align 4 - %5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @0, i32 0, i32 0), i32 %4) - %6 = load i32, i32* %counter, align 4 +for.l2: ; preds = %for.cond.l2 + %4 = load i32, ptr %counter, align 4 + %5 = call i32 (ptr, ...) @printf(ptr @0, i32 %4) + %6 = load i32, ptr %counter, align 4 %7 = icmp sge i32 %6, 5 - store i1 %7, i1* %0, align 1 - %8 = load i1, i1* %0, align 1 - br i1 %8, label %if.then, label %if.end3 + store i1 %7, ptr %0, align 1 + %8 = load i1, ptr %0, align 1 + br i1 %8, label %if.then.l4, label %if.end.l4 -if.then: ; preds = %for - store i32 100, i32* %subCounter, align 4 - br label %for.cond +if.then.l4: ; preds = %for.l2 + store i32 100, ptr %subCounter, align 4 + br label %for.cond.l5 -for1: ; preds = %for.cond - %9 = load i32, i32* %subCounter, align 4 - %10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @1, i32 0, i32 0), i32 %9) - %11 = load i32, i32* %subCounter, align 4 +for.l5: ; preds = %for.cond.l5 + %9 = load i32, ptr %subCounter, align 4 + %10 = call i32 (ptr, ...) @printf(ptr @1, i32 %9) + %11 = load i32, ptr %subCounter, align 4 %12 = icmp eq i32 %11, 11 - store i1 %12, i1* %1, align 1 - %13 = load i1, i1* %1, align 1 - br i1 %13, label %if.then2, label %if.end + store i1 %12, ptr %1, align 1 + %13 = load i1, ptr %1, align 1 + br i1 %13, label %if.then.l7, label %if.end.l7 -if.then2: ; preds = %for1 - br label %for.inc4 +if.then.l7: ; preds = %for.l5 + br label %for.inc.l2 -if.end: ; preds = %for1 - br label %for.inc +if.end.l7: ; preds = %for.l5 + br label %for.inc.l5 -for.inc: ; preds = %if.end - %14 = load i32, i32* %subCounter, align 4 +for.inc.l5: ; preds = %if.end.l7 + %14 = load i32, ptr %subCounter, align 4 %15 = sub i32 %14, 1 - store i32 %15, i32* %subCounter, align 4 - br label %for.cond + store i32 %15, ptr %subCounter, align 4 + br label %for.cond.l5 -for.cond: ; preds = %for.inc, %if.then - %16 = load i32, i32* %subCounter, align 4 +for.cond.l5: ; preds = %for.inc.l5, %if.then.l4 + %16 = load i32, ptr %subCounter, align 4 %17 = icmp sge i32 %16, 10 - store i1 %17, i1* %2, align 1 - %18 = load i1, i1* %2, align 1 - br i1 %18, label %for1, label %for.end + store i1 %17, ptr %2, align 1 + %18 = load i1, ptr %2, align 1 + br i1 %18, label %for.l5, label %for.end.l5 -for.end: ; preds = %for.cond - br label %if.end3 +for.end.l5: ; preds = %for.cond.l5 + br label %if.end.l4 -if.end3: ; preds = %for.end, %for - br label %for.inc4 +if.end.l4: ; preds = %for.end.l5, %for.l2 + br label %for.inc.l2 -for.inc4: ; preds = %if.end3, %if.then2 - %19 = load i32, i32* %counter, align 4 +for.inc.l2: ; preds = %if.end.l4, %if.then.l7 + %19 = load i32, ptr %counter, align 4 %20 = add i32 %19, 2 - store i32 %20, i32* %counter, align 4 - br label %for.cond5 + store i32 %20, ptr %counter, align 4 + br label %for.cond.l2 -for.cond5: ; preds = %for.inc4, %entry - %21 = load i32, i32* %counter, align 4 +for.cond.l2: ; preds = %for.inc.l2, %entry.l1 + %21 = load i32, ptr %counter, align 4 %22 = icmp slt i32 %21, 10 - store i1 %22, i1* %3, align 1 - %23 = load i1, i1* %3, align 1 - br i1 %23, label %for, label %for.end6 + store i1 %22, ptr %3, align 1 + %23 = load i1, ptr %3, align 1 + br i1 %23, label %for.l2, label %for.end.l2 -for.end6: ; preds = %for.cond5 - %24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0)) - %25 = load i32, i32* %result, align 4 +for.end.l2: ; preds = %for.cond.l2 + %24 = call i32 (ptr, ...) @printf(ptr @2) + %25 = load i32, ptr %result, align 4 ret i32 %25 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/for-loops/success-for-loop/ir-code.ll b/test/test-files/generator/for-loops/success-for-loop/ir-code.ll index b2e4a97b6..75c578b9c 100644 --- a/test/test-files/generator/for-loops/success-for-loop/ir-code.ll +++ b/test/test-files/generator/for-loops/success-for-loop/ir-code.ll @@ -6,35 +6,35 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [9 x i8] c"Step %d\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %i = alloca i32, align 4 %0 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - store i32 0, i32* %i, align 4 - br label %for.cond + store i32 0, ptr %result, align 4 + store i32 0, ptr %i, align 4 + br label %for.cond.l2 -for: ; preds = %for.cond - %1 = load i32, i32* %i, align 4 - %2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @0, i32 0, i32 0), i32 %1) - br label %for.inc +for.l2: ; preds = %for.cond.l2 + %1 = load i32, ptr %i, align 4 + %2 = call i32 (ptr, ...) @printf(ptr @0, i32 %1) + br label %for.inc.l2 -for.inc: ; preds = %for - %3 = load i32, i32* %i, align 4 +for.inc.l2: ; preds = %for.l2 + %3 = load i32, ptr %i, align 4 %4 = add i32 %3, 2 - store i32 %4, i32* %i, align 4 - br label %for.cond + store i32 %4, ptr %i, align 4 + br label %for.cond.l2 -for.cond: ; preds = %for.inc, %entry - %5 = load i32, i32* %i, align 4 +for.cond.l2: ; preds = %for.inc.l2, %entry.l1 + %5 = load i32, ptr %i, align 4 %6 = icmp slt i32 %5, 10 - store i1 %6, i1* %0, align 1 - %7 = load i1, i1* %0, align 1 - br i1 %7, label %for, label %for.end + store i1 %6, ptr %0, align 1 + %7 = load i1, ptr %0, align 1 + br i1 %7, label %for.l2, label %for.end.l2 -for.end: ; preds = %for.cond - %8 = load i32, i32* %result, align 4 +for.end.l2: ; preds = %for.cond.l2 + %8 = load i32, ptr %result, align 4 ret i32 %8 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/foreach-loops/success-foreach-loop-array-in-place/ir-code.ll b/test/test-files/generator/foreach-loops/success-foreach-loop-array-in-place/ir-code.ll index 3fad137d9..c38230d90 100644 --- a/test/test-files/generator/foreach-loops/success-foreach-loop-array-in-place/ir-code.ll +++ b/test/test-files/generator/foreach-loops/success-foreach-loop-array-in-place/ir-code.ll @@ -8,47 +8,47 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [13 x i8] c"Item %d: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %0 = alloca [5 x i32], align 4 %idx = alloca i32, align 4 %item = alloca i32, align 4 %item1 = alloca [5 x i32], align 4 - store i32 0, i32* %result, align 4 - store [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5], [5 x i32]* %0, align 4 - store i32 0, i32* %idx, align 4 - store i32 0, i32* %item, align 4 - store [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5], [5 x i32]* %item1, align 4 - %1 = load [5 x i32], [5 x i32]* %item1, align 4 - %2 = load i32, i32* %idx, align 4 - %3 = getelementptr inbounds [5 x i32], [5 x i32]* %item1, i32 0, i32 %2 - %4 = load i32, i32* %3, align 4 - store i32 %4, i32* %item, align 4 - br label %foreach.loop + store i32 0, ptr %result, align 4 + store [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5], ptr %0, align 4 + store i32 0, ptr %idx, align 4 + store i32 0, ptr %item, align 4 + store [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5], ptr %item1, align 4 + %1 = load [5 x i32], ptr %item1, align 4 + %2 = load i32, ptr %idx, align 4 + %3 = getelementptr inbounds [5 x i32], ptr %item1, i32 0, i32 %2 + %4 = load i32, ptr %3, align 4 + store i32 %4, ptr %item, align 4 + br label %foreach.loop.l2 -foreach.loop: ; preds = %foreach.cond, %entry - %5 = load i32, i32* %idx, align 4 - %6 = load i32, i32* %item, align 4 - %7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @0, i32 0, i32 0), i32 %5, i32 %6) - br label %foreach.inc +foreach.loop.l2: ; preds = %foreach.cond.l2, %entry.l1 + %5 = load i32, ptr %idx, align 4 + %6 = load i32, ptr %item, align 4 + %7 = call i32 (ptr, ...) @printf(ptr @0, i32 %5, i32 %6) + br label %foreach.inc.l2 -foreach.inc: ; preds = %foreach.loop - %idx2 = load i32, i32* %idx, align 4 +foreach.inc.l2: ; preds = %foreach.loop.l2 + %idx2 = load i32, ptr %idx, align 4 %idx.inc = add i32 %idx2, 1 - store i32 %idx.inc, i32* %idx, align 4 - %8 = getelementptr inbounds [5 x i32], [5 x i32]* %item1, i32 0, i32 %idx.inc - %9 = load i32, i32* %8, align 4 - store i32 %9, i32* %item, align 4 - br label %foreach.cond + store i32 %idx.inc, ptr %idx, align 4 + %8 = getelementptr inbounds [5 x i32], ptr %item1, i32 0, i32 %idx.inc + %9 = load i32, ptr %8, align 4 + store i32 %9, ptr %item, align 4 + br label %foreach.cond.l2 -foreach.cond: ; preds = %foreach.inc - %10 = load i32, i32* %idx, align 4 +foreach.cond.l2: ; preds = %foreach.inc.l2 + %10 = load i32, ptr %idx, align 4 %11 = icmp ult i32 %10, 5 - br i1 %11, label %foreach.loop, label %foreach.end + br i1 %11, label %foreach.loop.l2, label %foreach.end.l2 -foreach.end: ; preds = %foreach.cond - %12 = load i32, i32* %result, align 4 +foreach.end.l2: ; preds = %foreach.cond.l2 + %12 = load i32, ptr %result, align 4 ret i32 %12 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/foreach-loops/success-foreach-loop-break/ir-code-O2.ll b/test/test-files/generator/foreach-loops/success-foreach-loop-break/ir-code-O2.ll index 2a7710b16..9926de12a 100644 --- a/test/test-files/generator/foreach-loops/success-foreach-loop-break/ir-code-O2.ll +++ b/test/test-files/generator/foreach-loops/success-foreach-loop-break/ir-code-O2.ll @@ -11,14 +11,14 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #0 { -foreach.end10: - %0 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @0, i64 0, i64 0), i32 1) - %1 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @1, i64 0, i64 0), i64 1) - %2 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @2, i64 0, i64 0)) +foreach.end.l4: + %0 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 1) + %1 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i64 1) + %2 = tail call i32 (ptr, ...) @printf(ptr nonnull @2) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/foreach-loops/success-foreach-loop-break/ir-code.ll b/test/test-files/generator/foreach-loops/success-foreach-loop-break/ir-code.ll index 6c6a109ce..c0503a815 100644 --- a/test/test-files/generator/foreach-loops/success-foreach-loop-break/ir-code.ll +++ b/test/test-files/generator/foreach-loops/success-foreach-loop-break/ir-code.ll @@ -10,7 +10,7 @@ target triple = "x86_64-w64-windows-gnu" @2 = private unnamed_addr constant [5 x i8] c"End.\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %s1 = alloca i16, align 2 %0 = alloca i16, align 2 @@ -25,104 +25,104 @@ entry: %idx2 = alloca i32, align 4 %l = alloca i64, align 8 %l3 = alloca [2 x i64], align 8 - store i32 0, i32* %result, align 4 - store i16 5, i16* %s1, align 2 - %5 = load i16, i16* %s1, align 2 - store i16 -2, i16* %0, align 2 - %6 = load i16, i16* %0, align 2 - store i16 63, i16* %shortArray, align 2 - %7 = load i16, i16* %shortArray, align 2 + store i32 0, ptr %result, align 4 + store i16 5, ptr %s1, align 2 + %5 = load i16, ptr %s1, align 2 + store i16 -2, ptr %0, align 2 + %6 = load i16, ptr %0, align 2 + store i16 63, ptr %shortArray, align 2 + %7 = load i16, ptr %shortArray, align 2 %8 = sub i16 0, %7 - store i16 %8, i16* %1, align 2 - %9 = load i16, i16* %1, align 2 - %10 = getelementptr inbounds [5 x i16], [5 x i16]* %shortArray1, i32 0, i32 0 - store i16 1, i16* %10, align 2 - %11 = getelementptr inbounds [5 x i16], [5 x i16]* %shortArray1, i32 0, i32 1 - store i16 %5, i16* %11, align 2 - %12 = getelementptr inbounds [5 x i16], [5 x i16]* %shortArray1, i32 0, i32 2 - store i16 %6, i16* %12, align 2 - %13 = getelementptr inbounds [5 x i16], [5 x i16]* %shortArray1, i32 0, i32 3 - store i16 %9, i16* %13, align 2 - %14 = getelementptr inbounds [5 x i16], [5 x i16]* %shortArray1, i32 0, i32 4 - store i16 0, i16* %14, align 2 - store i32 0, i32* %idx, align 4 - store i16 0, i16* %s, align 2 - %15 = load [5 x i16], [5 x i16]* %shortArray1, align 2 - %16 = load i32, i32* %idx, align 4 - %17 = getelementptr inbounds [5 x i16], [5 x i16]* %shortArray1, i32 0, i32 %16 - %18 = load i16, i16* %17, align 2 - store i16 %18, i16* %s, align 2 - br label %foreach.loop + store i16 %8, ptr %1, align 2 + %9 = load i16, ptr %1, align 2 + %10 = getelementptr inbounds [5 x i16], ptr %shortArray1, i32 0, i32 0 + store i16 1, ptr %10, align 2 + %11 = getelementptr inbounds [5 x i16], ptr %shortArray1, i32 0, i32 1 + store i16 %5, ptr %11, align 2 + %12 = getelementptr inbounds [5 x i16], ptr %shortArray1, i32 0, i32 2 + store i16 %6, ptr %12, align 2 + %13 = getelementptr inbounds [5 x i16], ptr %shortArray1, i32 0, i32 3 + store i16 %9, ptr %13, align 2 + %14 = getelementptr inbounds [5 x i16], ptr %shortArray1, i32 0, i32 4 + store i16 0, ptr %14, align 2 + store i32 0, ptr %idx, align 4 + store i16 0, ptr %s, align 2 + %15 = load [5 x i16], ptr %shortArray1, align 2 + %16 = load i32, ptr %idx, align 4 + %17 = getelementptr inbounds [5 x i16], ptr %shortArray1, i32 0, i32 %16 + %18 = load i16, ptr %17, align 2 + store i16 %18, ptr %s, align 2 + br label %foreach.loop.l4 -foreach.loop: ; preds = %foreach.cond9, %entry - %19 = load i16, i16* %s, align 2 +foreach.loop.l4: ; preds = %foreach.cond.l4, %entry.l1 + %19 = load i16, ptr %s, align 2 %20 = sext i16 %19 to i32 - %21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @0, i32 0, i32 0), i32 %20) - %22 = load i16, i16* %s, align 2 + %21 = call i32 (ptr, ...) @printf(ptr @0, i32 %20) + %22 = load i16, ptr %s, align 2 %23 = and i16 %22, 1 - store i16 %23, i16* %2, align 2 - %24 = load i16, i16* %2, align 2 + store i16 %23, ptr %2, align 2 + %24 = load i16, ptr %2, align 2 %25 = sext i16 %24 to i32 %26 = icmp eq i32 %25, 1 - store i1 %26, i1* %3, align 1 - %27 = load i1, i1* %3, align 1 - br i1 %27, label %if.then, label %if.end + store i1 %26, ptr %3, align 1 + %27 = load i1, ptr %3, align 1 + br i1 %27, label %if.then.l6, label %if.end.l6 -if.then: ; preds = %foreach.loop - store [2 x i64] [i64 1, i64 2], [2 x i64]* %4, align 8 - store i32 0, i32* %idx2, align 4 - store i64 0, i64* %l, align 8 - store [2 x i64] [i64 1, i64 2], [2 x i64]* %l3, align 8 - %28 = load [2 x i64], [2 x i64]* %l3, align 8 - %29 = load i32, i32* %idx2, align 4 - %30 = getelementptr inbounds [2 x i64], [2 x i64]* %l3, i32 0, i32 %29 - %31 = load i64, i64* %30, align 8 - store i64 %31, i64* %l, align 8 - br label %foreach.loop4 +if.then.l6: ; preds = %foreach.loop.l4 + store [2 x i64] [i64 1, i64 2], ptr %4, align 8 + store i32 0, ptr %idx2, align 4 + store i64 0, ptr %l, align 8 + store [2 x i64] [i64 1, i64 2], ptr %l3, align 8 + %28 = load [2 x i64], ptr %l3, align 8 + %29 = load i32, ptr %idx2, align 4 + %30 = getelementptr inbounds [2 x i64], ptr %l3, i32 0, i32 %29 + %31 = load i64, ptr %30, align 8 + store i64 %31, ptr %l, align 8 + br label %foreach.loop.l7 -foreach.loop4: ; preds = %foreach.cond, %if.then - %32 = load i64, i64* %l, align 8 - %33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @1, i32 0, i32 0), i64 %32) - br label %foreach.end10 +foreach.loop.l7: ; preds = %foreach.cond.l7, %if.then.l6 + %32 = load i64, ptr %l, align 8 + %33 = call i32 (ptr, ...) @printf(ptr @1, i64 %32) + br label %foreach.end.l4 -foreach.inc: ; No predecessors! - %idx5 = load i32, i32* %idx2, align 4 - %idx.inc = add i32 %idx5, 1 - store i32 %idx.inc, i32* %idx2, align 4 - %34 = getelementptr inbounds [2 x i64], [2 x i64]* %l3, i32 0, i32 %idx.inc - %35 = load i64, i64* %34, align 8 - store i64 %35, i64* %l, align 8 - br label %foreach.cond +foreach.inc.l7: ; No predecessors! + %idx4 = load i32, ptr %idx2, align 4 + %idx.inc = add i32 %idx4, 1 + store i32 %idx.inc, ptr %idx2, align 4 + %34 = getelementptr inbounds [2 x i64], ptr %l3, i32 0, i32 %idx.inc + %35 = load i64, ptr %34, align 8 + store i64 %35, ptr %l, align 8 + br label %foreach.cond.l7 -foreach.cond: ; preds = %foreach.inc - %36 = load i32, i32* %idx2, align 4 +foreach.cond.l7: ; preds = %foreach.inc.l7 + %36 = load i32, ptr %idx2, align 4 %37 = icmp ult i32 %36, 2 - br i1 %37, label %foreach.loop4, label %foreach.end + br i1 %37, label %foreach.loop.l7, label %foreach.end.l7 -foreach.end: ; preds = %foreach.cond - br label %if.end +foreach.end.l7: ; preds = %foreach.cond.l7 + br label %if.end.l6 -if.end: ; preds = %foreach.end, %foreach.loop - br label %foreach.inc6 +if.end.l6: ; preds = %foreach.end.l7, %foreach.loop.l4 + br label %foreach.inc.l4 -foreach.inc6: ; preds = %if.end - %idx7 = load i32, i32* %idx, align 4 - %idx.inc8 = add i32 %idx7, 1 - store i32 %idx.inc8, i32* %idx, align 4 - %38 = getelementptr inbounds [5 x i16], [5 x i16]* %shortArray1, i32 0, i32 %idx.inc8 - %39 = load i16, i16* %38, align 2 - store i16 %39, i16* %s, align 2 - br label %foreach.cond9 +foreach.inc.l4: ; preds = %if.end.l6 + %idx5 = load i32, ptr %idx, align 4 + %idx.inc6 = add i32 %idx5, 1 + store i32 %idx.inc6, ptr %idx, align 4 + %38 = getelementptr inbounds [5 x i16], ptr %shortArray1, i32 0, i32 %idx.inc6 + %39 = load i16, ptr %38, align 2 + store i16 %39, ptr %s, align 2 + br label %foreach.cond.l4 -foreach.cond9: ; preds = %foreach.inc6 - %40 = load i32, i32* %idx, align 4 +foreach.cond.l4: ; preds = %foreach.inc.l4 + %40 = load i32, ptr %idx, align 4 %41 = icmp ult i32 %40, 5 - br i1 %41, label %foreach.loop, label %foreach.end10 + br i1 %41, label %foreach.loop.l4, label %foreach.end.l4 -foreach.end10: ; preds = %foreach.cond9, %foreach.loop4 - %42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0)) - %43 = load i32, i32* %result, align 4 +foreach.end.l4: ; preds = %foreach.cond.l4, %foreach.loop.l7 + %42 = call i32 (ptr, ...) @printf(ptr @2) + %43 = load i32, ptr %result, align 4 ret i32 %43 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/foreach-loops/success-foreach-loop-continue/ir-code-O2.ll b/test/test-files/generator/foreach-loops/success-foreach-loop-continue/ir-code-O2.ll index 39cd5a69e..4416ac017 100644 --- a/test/test-files/generator/foreach-loops/success-foreach-loop-continue/ir-code-O2.ll +++ b/test/test-files/generator/foreach-loops/success-foreach-loop-continue/ir-code-O2.ll @@ -11,22 +11,22 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #0 { -foreach.inc7.4: - %0 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @0, i64 0, i64 0), i32 1) - %1 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @1, i64 0, i64 0), i64 1) - %2 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @0, i64 0, i64 0), i32 5) - %3 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @1, i64 0, i64 0), i64 1) - %4 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @0, i64 0, i64 0), i32 25) - %5 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @1, i64 0, i64 0), i64 1) - %6 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @0, i64 0, i64 0), i32 -27) - %7 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @1, i64 0, i64 0), i64 1) - %8 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @0, i64 0, i64 0), i32 -63) - %9 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @1, i64 0, i64 0), i64 1) - %10 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @2, i64 0, i64 0)) +foreach.inc.l4.4: + %0 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 1) + %1 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i64 1) + %2 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 5) + %3 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i64 1) + %4 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 25) + %5 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i64 1) + %6 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 -27) + %7 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i64 1) + %8 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 -63) + %9 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i64 1) + %10 = tail call i32 (ptr, ...) @printf(ptr nonnull @2) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/foreach-loops/success-foreach-loop-continue/ir-code.ll b/test/test-files/generator/foreach-loops/success-foreach-loop-continue/ir-code.ll index e4a72f1db..e1153eb8f 100644 --- a/test/test-files/generator/foreach-loops/success-foreach-loop-continue/ir-code.ll +++ b/test/test-files/generator/foreach-loops/success-foreach-loop-continue/ir-code.ll @@ -10,7 +10,7 @@ target triple = "x86_64-w64-windows-gnu" @2 = private unnamed_addr constant [5 x i8] c"End.\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %s1 = alloca i16, align 2 %shortArray = alloca i16, align 2 @@ -26,107 +26,107 @@ entry: %idx3 = alloca i32, align 4 %l = alloca i64, align 8 %l4 = alloca [2 x i64], align 8 - store i32 0, i32* %result, align 4 - store i16 5, i16* %s1, align 2 - %5 = load i16, i16* %s1, align 2 - store i16 27, i16* %shortArray, align 2 - %6 = load i16, i16* %shortArray, align 2 + store i32 0, ptr %result, align 4 + store i16 5, ptr %s1, align 2 + %5 = load i16, ptr %s1, align 2 + store i16 27, ptr %shortArray, align 2 + %6 = load i16, ptr %shortArray, align 2 %7 = sub i16 0, %6 - store i16 %7, i16* %0, align 2 - %8 = load i16, i16* %0, align 2 - store i16 63, i16* %shortArray1, align 2 - %9 = load i16, i16* %shortArray1, align 2 + store i16 %7, ptr %0, align 2 + %8 = load i16, ptr %0, align 2 + store i16 63, ptr %shortArray1, align 2 + %9 = load i16, ptr %shortArray1, align 2 %10 = sub i16 0, %9 - store i16 %10, i16* %1, align 2 - %11 = load i16, i16* %1, align 2 - %12 = getelementptr inbounds [5 x i16], [5 x i16]* %shortArray2, i32 0, i32 0 - store i16 1, i16* %12, align 2 - %13 = getelementptr inbounds [5 x i16], [5 x i16]* %shortArray2, i32 0, i32 1 - store i16 %5, i16* %13, align 2 - %14 = getelementptr inbounds [5 x i16], [5 x i16]* %shortArray2, i32 0, i32 2 - store i16 25, i16* %14, align 2 - %15 = getelementptr inbounds [5 x i16], [5 x i16]* %shortArray2, i32 0, i32 3 - store i16 %8, i16* %15, align 2 - %16 = getelementptr inbounds [5 x i16], [5 x i16]* %shortArray2, i32 0, i32 4 - store i16 %11, i16* %16, align 2 - store i32 0, i32* %idx, align 4 - store i16 0, i16* %s, align 2 - %17 = load [5 x i16], [5 x i16]* %shortArray2, align 2 - %18 = load i32, i32* %idx, align 4 - %19 = getelementptr inbounds [5 x i16], [5 x i16]* %shortArray2, i32 0, i32 %18 - %20 = load i16, i16* %19, align 2 - store i16 %20, i16* %s, align 2 - br label %foreach.loop + store i16 %10, ptr %1, align 2 + %11 = load i16, ptr %1, align 2 + %12 = getelementptr inbounds [5 x i16], ptr %shortArray2, i32 0, i32 0 + store i16 1, ptr %12, align 2 + %13 = getelementptr inbounds [5 x i16], ptr %shortArray2, i32 0, i32 1 + store i16 %5, ptr %13, align 2 + %14 = getelementptr inbounds [5 x i16], ptr %shortArray2, i32 0, i32 2 + store i16 25, ptr %14, align 2 + %15 = getelementptr inbounds [5 x i16], ptr %shortArray2, i32 0, i32 3 + store i16 %8, ptr %15, align 2 + %16 = getelementptr inbounds [5 x i16], ptr %shortArray2, i32 0, i32 4 + store i16 %11, ptr %16, align 2 + store i32 0, ptr %idx, align 4 + store i16 0, ptr %s, align 2 + %17 = load [5 x i16], ptr %shortArray2, align 2 + %18 = load i32, ptr %idx, align 4 + %19 = getelementptr inbounds [5 x i16], ptr %shortArray2, i32 0, i32 %18 + %20 = load i16, ptr %19, align 2 + store i16 %20, ptr %s, align 2 + br label %foreach.loop.l4 -foreach.loop: ; preds = %foreach.cond10, %entry - %21 = load i16, i16* %s, align 2 +foreach.loop.l4: ; preds = %foreach.cond.l4, %entry.l1 + %21 = load i16, ptr %s, align 2 %22 = sext i16 %21 to i32 - %23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @0, i32 0, i32 0), i32 %22) - %24 = load i16, i16* %s, align 2 + %23 = call i32 (ptr, ...) @printf(ptr @0, i32 %22) + %24 = load i16, ptr %s, align 2 %25 = and i16 %24, 1 - store i16 %25, i16* %2, align 2 - %26 = load i16, i16* %2, align 2 + store i16 %25, ptr %2, align 2 + %26 = load i16, ptr %2, align 2 %27 = sext i16 %26 to i32 %28 = icmp eq i32 %27, 1 - store i1 %28, i1* %3, align 1 - %29 = load i1, i1* %3, align 1 - br i1 %29, label %if.then, label %if.end + store i1 %28, ptr %3, align 1 + %29 = load i1, ptr %3, align 1 + br i1 %29, label %if.then.l6, label %if.end.l6 -if.then: ; preds = %foreach.loop - store [2 x i64] [i64 1, i64 2], [2 x i64]* %4, align 8 - store i32 0, i32* %idx3, align 4 - store i64 0, i64* %l, align 8 - store [2 x i64] [i64 1, i64 2], [2 x i64]* %l4, align 8 - %30 = load [2 x i64], [2 x i64]* %l4, align 8 - %31 = load i32, i32* %idx3, align 4 - %32 = getelementptr inbounds [2 x i64], [2 x i64]* %l4, i32 0, i32 %31 - %33 = load i64, i64* %32, align 8 - store i64 %33, i64* %l, align 8 - br label %foreach.loop5 +if.then.l6: ; preds = %foreach.loop.l4 + store [2 x i64] [i64 1, i64 2], ptr %4, align 8 + store i32 0, ptr %idx3, align 4 + store i64 0, ptr %l, align 8 + store [2 x i64] [i64 1, i64 2], ptr %l4, align 8 + %30 = load [2 x i64], ptr %l4, align 8 + %31 = load i32, ptr %idx3, align 4 + %32 = getelementptr inbounds [2 x i64], ptr %l4, i32 0, i32 %31 + %33 = load i64, ptr %32, align 8 + store i64 %33, ptr %l, align 8 + br label %foreach.loop.l7 -foreach.loop5: ; preds = %foreach.cond, %if.then - %34 = load i64, i64* %l, align 8 - %35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @1, i32 0, i32 0), i64 %34) - br label %foreach.inc7 +foreach.loop.l7: ; preds = %foreach.cond.l7, %if.then.l6 + %34 = load i64, ptr %l, align 8 + %35 = call i32 (ptr, ...) @printf(ptr @1, i64 %34) + br label %foreach.inc.l4 -foreach.inc: ; No predecessors! - %idx6 = load i32, i32* %idx3, align 4 - %idx.inc = add i32 %idx6, 1 - store i32 %idx.inc, i32* %idx3, align 4 - %36 = getelementptr inbounds [2 x i64], [2 x i64]* %l4, i32 0, i32 %idx.inc - %37 = load i64, i64* %36, align 8 - store i64 %37, i64* %l, align 8 - br label %foreach.cond +foreach.inc.l7: ; No predecessors! + %idx5 = load i32, ptr %idx3, align 4 + %idx.inc = add i32 %idx5, 1 + store i32 %idx.inc, ptr %idx3, align 4 + %36 = getelementptr inbounds [2 x i64], ptr %l4, i32 0, i32 %idx.inc + %37 = load i64, ptr %36, align 8 + store i64 %37, ptr %l, align 8 + br label %foreach.cond.l7 -foreach.cond: ; preds = %foreach.inc - %38 = load i32, i32* %idx3, align 4 +foreach.cond.l7: ; preds = %foreach.inc.l7 + %38 = load i32, ptr %idx3, align 4 %39 = icmp ult i32 %38, 2 - br i1 %39, label %foreach.loop5, label %foreach.end + br i1 %39, label %foreach.loop.l7, label %foreach.end.l7 -foreach.end: ; preds = %foreach.cond - br label %if.end +foreach.end.l7: ; preds = %foreach.cond.l7 + br label %if.end.l6 -if.end: ; preds = %foreach.end, %foreach.loop - br label %foreach.inc7 +if.end.l6: ; preds = %foreach.end.l7, %foreach.loop.l4 + br label %foreach.inc.l4 -foreach.inc7: ; preds = %if.end, %foreach.loop5 - %idx8 = load i32, i32* %idx, align 4 - %idx.inc9 = add i32 %idx8, 1 - store i32 %idx.inc9, i32* %idx, align 4 - %40 = getelementptr inbounds [5 x i16], [5 x i16]* %shortArray2, i32 0, i32 %idx.inc9 - %41 = load i16, i16* %40, align 2 - store i16 %41, i16* %s, align 2 - br label %foreach.cond10 +foreach.inc.l4: ; preds = %if.end.l6, %foreach.loop.l7 + %idx6 = load i32, ptr %idx, align 4 + %idx.inc7 = add i32 %idx6, 1 + store i32 %idx.inc7, ptr %idx, align 4 + %40 = getelementptr inbounds [5 x i16], ptr %shortArray2, i32 0, i32 %idx.inc7 + %41 = load i16, ptr %40, align 2 + store i16 %41, ptr %s, align 2 + br label %foreach.cond.l4 -foreach.cond10: ; preds = %foreach.inc7 - %42 = load i32, i32* %idx, align 4 +foreach.cond.l4: ; preds = %foreach.inc.l4 + %42 = load i32, ptr %idx, align 4 %43 = icmp ult i32 %42, 5 - br i1 %43, label %foreach.loop, label %foreach.end11 + br i1 %43, label %foreach.loop.l4, label %foreach.end.l4 -foreach.end11: ; preds = %foreach.cond10 - %44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0)) - %45 = load i32, i32* %result, align 4 +foreach.end.l4: ; preds = %foreach.cond.l4 + %44 = call i32 (ptr, ...) @printf(ptr @2) + %45 = load i32, ptr %result, align 4 ret i32 %45 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/foreach-loops/success-foreach-loop-indexed-modified/ir-code.ll b/test/test-files/generator/foreach-loops/success-foreach-loop-indexed-modified/ir-code.ll index 8fd399ba5..cb7674379 100644 --- a/test/test-files/generator/foreach-loops/success-foreach-loop-indexed-modified/ir-code.ll +++ b/test/test-files/generator/foreach-loops/success-foreach-loop-indexed-modified/ir-code.ll @@ -7,50 +7,50 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [23 x i8] c"Item for index %d, %d\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %intArray = alloca [7 x i32], align 4 %idx = alloca i32, align 4 %item = alloca i32, align 4 %0 = alloca i32, align 4 - store i32 0, i32* %result, align 4 - store [7 x i32] [i32 1, i32 5, i32 4, i32 0, i32 12, i32 12345, i32 9], [7 x i32]* %intArray, align 4 - store i32 2, i32* %idx, align 4 - store i32 0, i32* %item, align 4 - %1 = load [7 x i32], [7 x i32]* %intArray, align 4 - %2 = load i32, i32* %idx, align 4 - %3 = getelementptr inbounds [7 x i32], [7 x i32]* %intArray, i32 0, i32 %2 - %4 = load i32, i32* %3, align 4 - store i32 %4, i32* %item, align 4 - br label %foreach.loop + store i32 0, ptr %result, align 4 + store [7 x i32] [i32 1, i32 5, i32 4, i32 0, i32 12, i32 12345, i32 9], ptr %intArray, align 4 + store i32 2, ptr %idx, align 4 + store i32 0, ptr %item, align 4 + %1 = load [7 x i32], ptr %intArray, align 4 + %2 = load i32, ptr %idx, align 4 + %3 = getelementptr inbounds [7 x i32], ptr %intArray, i32 0, i32 %2 + %4 = load i32, ptr %3, align 4 + store i32 %4, ptr %item, align 4 + br label %foreach.loop.l3 -foreach.loop: ; preds = %foreach.cond, %entry - %5 = load i32, i32* %idx, align 4 - %6 = load i32, i32* %item, align 4 - %7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @0, i32 0, i32 0), i32 %5, i32 %6) - %8 = load i32, i32* %idx, align 4 +foreach.loop.l3: ; preds = %foreach.cond.l3, %entry.l1 + %5 = load i32, ptr %idx, align 4 + %6 = load i32, ptr %item, align 4 + %7 = call i32 (ptr, ...) @printf(ptr @0, i32 %5, i32 %6) + %8 = load i32, ptr %idx, align 4 %9 = add i32 %8, 1 - store i32 %9, i32* %idx, align 4 - store i32 %8, i32* %0, align 4 - br label %foreach.inc + store i32 %9, ptr %idx, align 4 + store i32 %8, ptr %0, align 4 + br label %foreach.inc.l3 -foreach.inc: ; preds = %foreach.loop - %idx1 = load i32, i32* %idx, align 4 +foreach.inc.l3: ; preds = %foreach.loop.l3 + %idx1 = load i32, ptr %idx, align 4 %idx.inc = add i32 %idx1, 1 - store i32 %idx.inc, i32* %idx, align 4 - %10 = getelementptr inbounds [7 x i32], [7 x i32]* %intArray, i32 0, i32 %idx.inc - %11 = load i32, i32* %10, align 4 - store i32 %11, i32* %item, align 4 - br label %foreach.cond + store i32 %idx.inc, ptr %idx, align 4 + %10 = getelementptr inbounds [7 x i32], ptr %intArray, i32 0, i32 %idx.inc + %11 = load i32, ptr %10, align 4 + store i32 %11, ptr %item, align 4 + br label %foreach.cond.l3 -foreach.cond: ; preds = %foreach.inc - %12 = load i32, i32* %idx, align 4 +foreach.cond.l3: ; preds = %foreach.inc.l3 + %12 = load i32, ptr %idx, align 4 %13 = icmp ult i32 %12, 7 - br i1 %13, label %foreach.loop, label %foreach.end + br i1 %13, label %foreach.loop.l3, label %foreach.end.l3 -foreach.end: ; preds = %foreach.cond - %14 = load i32, i32* %result, align 4 +foreach.end.l3: ; preds = %foreach.cond.l3 + %14 = load i32, ptr %result, align 4 ret i32 %14 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/foreach-loops/success-foreach-loop-indexed/ir-code.ll b/test/test-files/generator/foreach-loops/success-foreach-loop-indexed/ir-code.ll index 3dea54ebc..8fdcac0ef 100644 --- a/test/test-files/generator/foreach-loops/success-foreach-loop-indexed/ir-code.ll +++ b/test/test-files/generator/foreach-loops/success-foreach-loop-indexed/ir-code.ll @@ -7,45 +7,45 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [23 x i8] c"Item for index %d, %d\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %intArray = alloca [7 x i32], align 4 %index = alloca i32, align 4 %item = alloca i32, align 4 - store i32 0, i32* %result, align 4 - store [7 x i32] [i32 1, i32 5, i32 4, i32 0, i32 12, i32 12345, i32 9], [7 x i32]* %intArray, align 4 - store i32 0, i32* %index, align 4 - store i32 0, i32* %item, align 4 - %0 = load [7 x i32], [7 x i32]* %intArray, align 4 - %1 = load i32, i32* %index, align 4 - %2 = getelementptr inbounds [7 x i32], [7 x i32]* %intArray, i32 0, i32 %1 - %3 = load i32, i32* %2, align 4 - store i32 %3, i32* %item, align 4 - br label %foreach.loop + store i32 0, ptr %result, align 4 + store [7 x i32] [i32 1, i32 5, i32 4, i32 0, i32 12, i32 12345, i32 9], ptr %intArray, align 4 + store i32 0, ptr %index, align 4 + store i32 0, ptr %item, align 4 + %0 = load [7 x i32], ptr %intArray, align 4 + %1 = load i32, ptr %index, align 4 + %2 = getelementptr inbounds [7 x i32], ptr %intArray, i32 0, i32 %1 + %3 = load i32, ptr %2, align 4 + store i32 %3, ptr %item, align 4 + br label %foreach.loop.l3 -foreach.loop: ; preds = %foreach.cond, %entry - %4 = load i32, i32* %index, align 4 - %5 = load i32, i32* %item, align 4 - %6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @0, i32 0, i32 0), i32 %4, i32 %5) - br label %foreach.inc +foreach.loop.l3: ; preds = %foreach.cond.l3, %entry.l1 + %4 = load i32, ptr %index, align 4 + %5 = load i32, ptr %item, align 4 + %6 = call i32 (ptr, ...) @printf(ptr @0, i32 %4, i32 %5) + br label %foreach.inc.l3 -foreach.inc: ; preds = %foreach.loop - %idx = load i32, i32* %index, align 4 +foreach.inc.l3: ; preds = %foreach.loop.l3 + %idx = load i32, ptr %index, align 4 %idx.inc = add i32 %idx, 1 - store i32 %idx.inc, i32* %index, align 4 - %7 = getelementptr inbounds [7 x i32], [7 x i32]* %intArray, i32 0, i32 %idx.inc - %8 = load i32, i32* %7, align 4 - store i32 %8, i32* %item, align 4 - br label %foreach.cond + store i32 %idx.inc, ptr %index, align 4 + %7 = getelementptr inbounds [7 x i32], ptr %intArray, i32 0, i32 %idx.inc + %8 = load i32, ptr %7, align 4 + store i32 %8, ptr %item, align 4 + br label %foreach.cond.l3 -foreach.cond: ; preds = %foreach.inc - %9 = load i32, i32* %index, align 4 +foreach.cond.l3: ; preds = %foreach.inc.l3 + %9 = load i32, ptr %index, align 4 %10 = icmp ult i32 %9, 7 - br i1 %10, label %foreach.loop, label %foreach.end + br i1 %10, label %foreach.loop.l3, label %foreach.end.l3 -foreach.end: ; preds = %foreach.cond - %11 = load i32, i32* %result, align 4 +foreach.end.l3: ; preds = %foreach.cond.l3 + %11 = load i32, ptr %result, align 4 ret i32 %11 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/foreach-loops/success-foreach-loop-normal/ir-code.ll b/test/test-files/generator/foreach-loops/success-foreach-loop-normal/ir-code.ll index 2116d5e7c..055aea035 100644 --- a/test/test-files/generator/foreach-loops/success-foreach-loop-normal/ir-code.ll +++ b/test/test-files/generator/foreach-loops/success-foreach-loop-normal/ir-code.ll @@ -7,45 +7,45 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [22 x i8] c"Item at index %d: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %intArray = alloca [7 x i32], align 4 %idx = alloca i32, align 4 %item = alloca i32, align 4 - store i32 0, i32* %result, align 4 - store [7 x i32] [i32 1, i32 5, i32 4, i32 0, i32 12, i32 12345, i32 9], [7 x i32]* %intArray, align 4 - store i32 0, i32* %idx, align 4 - store i32 0, i32* %item, align 4 - %0 = load [7 x i32], [7 x i32]* %intArray, align 4 - %1 = load i32, i32* %idx, align 4 - %2 = getelementptr inbounds [7 x i32], [7 x i32]* %intArray, i32 0, i32 %1 - %3 = load i32, i32* %2, align 4 - store i32 %3, i32* %item, align 4 - br label %foreach.loop + store i32 0, ptr %result, align 4 + store [7 x i32] [i32 1, i32 5, i32 4, i32 0, i32 12, i32 12345, i32 9], ptr %intArray, align 4 + store i32 0, ptr %idx, align 4 + store i32 0, ptr %item, align 4 + %0 = load [7 x i32], ptr %intArray, align 4 + %1 = load i32, ptr %idx, align 4 + %2 = getelementptr inbounds [7 x i32], ptr %intArray, i32 0, i32 %1 + %3 = load i32, ptr %2, align 4 + store i32 %3, ptr %item, align 4 + br label %foreach.loop.l3 -foreach.loop: ; preds = %foreach.cond, %entry - %4 = load i32, i32* %idx, align 4 - %5 = load i32, i32* %item, align 4 - %6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @0, i32 0, i32 0), i32 %4, i32 %5) - br label %foreach.inc +foreach.loop.l3: ; preds = %foreach.cond.l3, %entry.l1 + %4 = load i32, ptr %idx, align 4 + %5 = load i32, ptr %item, align 4 + %6 = call i32 (ptr, ...) @printf(ptr @0, i32 %4, i32 %5) + br label %foreach.inc.l3 -foreach.inc: ; preds = %foreach.loop - %idx1 = load i32, i32* %idx, align 4 +foreach.inc.l3: ; preds = %foreach.loop.l3 + %idx1 = load i32, ptr %idx, align 4 %idx.inc = add i32 %idx1, 1 - store i32 %idx.inc, i32* %idx, align 4 - %7 = getelementptr inbounds [7 x i32], [7 x i32]* %intArray, i32 0, i32 %idx.inc - %8 = load i32, i32* %7, align 4 - store i32 %8, i32* %item, align 4 - br label %foreach.cond + store i32 %idx.inc, ptr %idx, align 4 + %7 = getelementptr inbounds [7 x i32], ptr %intArray, i32 0, i32 %idx.inc + %8 = load i32, ptr %7, align 4 + store i32 %8, ptr %item, align 4 + br label %foreach.cond.l3 -foreach.cond: ; preds = %foreach.inc - %9 = load i32, i32* %idx, align 4 +foreach.cond.l3: ; preds = %foreach.inc.l3 + %9 = load i32, ptr %idx, align 4 %10 = icmp ult i32 %9, 7 - br i1 %10, label %foreach.loop, label %foreach.end + br i1 %10, label %foreach.loop.l3, label %foreach.end.l3 -foreach.end: ; preds = %foreach.cond - %11 = load i32, i32* %result, align 4 +foreach.end.l3: ; preds = %foreach.cond.l3 + %11 = load i32, ptr %result, align 4 ret i32 %11 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/functions/success-default-arg-value-expressions/ir-code.ll b/test/test-files/generator/functions/success-default-arg-value-expressions/ir-code.ll index cefa69f5d..c202148c9 100644 --- a/test/test-files/generator/functions/success-default-arg-value-expressions/ir-code.ll +++ b/test/test-files/generator/functions/success-default-arg-value-expressions/ir-code.ll @@ -6,39 +6,39 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [10 x i8] c"Test: %f\0A\00", align 1 define internal double @_f__void__getArg() { -entry: +entry.l1: %result = alloca double, align 8 %0 = alloca double, align 8 - store double 4.300000e+00, double* %0, align 8 - %1 = load double, double* %0, align 8 + store double 4.300000e+00, ptr %0, align 8 + %1 = load double, ptr %0, align 8 ret double %1 } define internal double @_f__void__test() { -entry: +entry.l5: %0 = call double @_f__void__getArg() %1 = alloca double, align 8 %2 = alloca double, align 8 %result = alloca double, align 8 - store double %0, double* %1, align 8 - %3 = load double, double* %1, align 8 + store double %0, ptr %1, align 8 + %3 = load double, ptr %1, align 8 %4 = fadd double %3, 1.200000e+00 - store double %4, double* %2, align 8 - %5 = load double, double* %2, align 8 + store double %4, ptr %2, align 8 + %5 = load double, ptr %2, align 8 ret double %5 } define i32 @main() { -entry: +entry.l9: %result = alloca i32, align 4 %0 = alloca double, align 8 - store i32 0, i32* %result, align 4 + store i32 0, ptr %result, align 4 %1 = call double @_f__void__test() - store double %1, double* %0, align 8 - %2 = load double, double* %0, align 8 - %3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @0, i32 0, i32 0), double %2) - %4 = load i32, i32* %result, align 4 + store double %1, ptr %0, align 8 + %2 = load double, ptr %0, align 8 + %3 = call i32 (ptr, ...) @printf(ptr @0, double %2) + %4 = load i32, ptr %result, align 4 ret i32 %4 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/functions/success-default-arg-values/ir-code.ll b/test/test-files/generator/functions/success-default-arg-values/ir-code.ll index a90865598..4e9d280cd 100644 --- a/test/test-files/generator/functions/success-default-arg-values/ir-code.ll +++ b/test/test-files/generator/functions/success-default-arg-values/ir-code.ll @@ -6,43 +6,43 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [5 x i8] c"Test\00", align 1 @1 = private unnamed_addr constant [12 x i8] c"Result: %s\0A\00", align 1 -define internal i8* @_f__void__getTestString__int_double_bool(i32 %0, double %1, i1 %2) { -entry: +define internal ptr @_f__void__getTestString__int_double_bool(i32 %0, double %1, i1 %2) { +entry.l1: %arg0 = alloca i32, align 4 %arg1 = alloca double, align 8 %arg2 = alloca i1, align 1 %arg3 = alloca double, align 8 - %result = alloca i8*, align 8 - %arg31 = alloca i8*, align 8 - store i32 %0, i32* %arg0, align 4 - store double %1, double* %arg1, align 8 - store i1 %2, i1* %arg2, align 1 - store double 1.340000e+00, double* %arg3, align 8 - store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @0, i32 0, i32 0), i8** %arg31, align 8 - %3 = load i8*, i8** %arg31, align 8 - ret i8* %3 + %result = alloca ptr, align 8 + %arg31 = alloca ptr, align 8 + store i32 %0, ptr %arg0, align 4 + store double %1, ptr %arg1, align 8 + store i1 %2, ptr %arg2, align 1 + store double 1.340000e+00, ptr %arg3, align 8 + store ptr @0, ptr %arg31, align 8 + %3 = load ptr, ptr %arg31, align 8 + ret ptr %3 } define i32 @main() { -entry: +entry.l5: %result = alloca i32, align 4 %0 = alloca i32, align 4 %1 = alloca double, align 8 %2 = alloca i1, align 1 - %3 = alloca i8*, align 8 - store i32 0, i32* %result, align 4 - store i32 1, i32* %0, align 4 - %4 = load i32, i32* %0, align 4 - store double 3.400000e+00, double* %1, align 8 - %5 = load double, double* %1, align 8 - store i1 true, i1* %2, align 1 - %6 = load i1, i1* %2, align 1 - %7 = call i8* @_f__void__getTestString__int_double_bool(i32 %4, double %5, i1 %6) - store i8* %7, i8** %3, align 8 - %8 = load i8*, i8** %3, align 8 - %9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @1, i32 0, i32 0), i8* %8) - %10 = load i32, i32* %result, align 4 + %3 = alloca ptr, align 8 + store i32 0, ptr %result, align 4 + store i32 1, ptr %0, align 4 + %4 = load i32, ptr %0, align 4 + store double 3.400000e+00, ptr %1, align 8 + %5 = load double, ptr %1, align 8 + store i1 true, ptr %2, align 1 + %6 = load i1, ptr %2, align 1 + %7 = call ptr @_f__void__getTestString__int_double_bool(i32 %4, double %5, i1 %6) + store ptr %7, ptr %3, align 8 + %8 = load ptr, ptr %3, align 8 + %9 = call i32 (ptr, ...) @printf(ptr @1, ptr %8) + %10 = load i32, ptr %result, align 4 ret i32 %10 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/functions/success-down-call/ir-code.ll b/test/test-files/generator/functions/success-down-call/ir-code.ll index b6d4e6774..1208a825b 100644 --- a/test/test-files/generator/functions/success-down-call/ir-code.ll +++ b/test/test-files/generator/functions/success-down-call/ir-code.ll @@ -6,25 +6,25 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [11 x i8] c"Result: %d\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %0 = alloca i32, align 4 - store i32 0, i32* %result, align 4 + store i32 0, ptr %result, align 4 %1 = call i32 @_f__void__test() - store i32 %1, i32* %0, align 4 - %2 = load i32, i32* %0, align 4 - %3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @0, i32 0, i32 0), i32 %2) - %4 = load i32, i32* %result, align 4 + store i32 %1, ptr %0, align 4 + %2 = load i32, ptr %0, align 4 + %3 = call i32 (ptr, ...) @printf(ptr @0, i32 %2) + %4 = load i32, ptr %result, align 4 ret i32 %4 } define internal i32 @_f__void__test() { -entry: +entry.l6: %result = alloca i32, align 4 %0 = alloca i32, align 4 - store i32 1, i32* %0, align 4 - %1 = load i32, i32* %0, align 4 + store i32 1, ptr %0, align 4 + %1 = load i32, ptr %0, align 4 ret i32 %1 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/functions/success-explicit-inlining/ir-code-O2.ll b/test/test-files/generator/functions/success-explicit-inlining/ir-code-O2.ll index d671d5423..723122d94 100644 --- a/test/test-files/generator/functions/success-explicit-inlining/ir-code-O2.ll +++ b/test/test-files/generator/functions/success-explicit-inlining/ir-code-O2.ll @@ -7,12 +7,12 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #0 { -entry: - %0 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @0, i64 0, i64 0), i64 12) +entry.l5: + %0 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i64 12) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/functions/success-explicit-inlining/ir-code.ll b/test/test-files/generator/functions/success-explicit-inlining/ir-code.ll index ef21d00da..fef69c7a3 100644 --- a/test/test-files/generator/functions/success-explicit-inlining/ir-code.ll +++ b/test/test-files/generator/functions/success-explicit-inlining/ir-code.ll @@ -7,27 +7,27 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: alwaysinline define internal i64 @_f__void__getInlinedValue() #0 { -entry: +entry.l1: %result = alloca i64, align 8 %0 = alloca i64, align 8 - store i64 12, i64* %0, align 8 - %1 = load i64, i64* %0, align 8 + store i64 12, ptr %0, align 8 + %1 = load i64, ptr %0, align 8 ret i64 %1 } define i32 @main() { -entry: +entry.l5: %result = alloca i32, align 4 %0 = alloca i64, align 8 - store i32 0, i32* %result, align 4 + store i32 0, ptr %result, align 4 %1 = call i64 @_f__void__getInlinedValue() - store i64 %1, i64* %0, align 8 - %2 = load i64, i64* %0, align 8 - %3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @0, i32 0, i32 0), i64 %2) - %4 = load i32, i32* %result, align 4 + store i64 %1, ptr %0, align 8 + %2 = load i64, ptr %0, align 8 + %3 = call i32 (ptr, ...) @printf(ptr @0, i64 %2) + %4 = load i32, ptr %result, align 4 ret i32 %4 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) attributes #0 = { alwaysinline } diff --git a/test/test-files/generator/functions/success-overloading/ir-code.ll b/test/test-files/generator/functions/success-overloading/ir-code.ll index b3a32eacb..096115f48 100644 --- a/test/test-files/generator/functions/success-overloading/ir-code.ll +++ b/test/test-files/generator/functions/success-overloading/ir-code.ll @@ -7,26 +7,26 @@ target triple = "x86_64-w64-windows-gnu" @1 = private unnamed_addr constant [12 x i8] c"Result: %d\0A\00", align 1 define internal i32 @_f__void__testFunc() { -entry: +entry.l1: %result = alloca i32, align 4 %0 = alloca i32, align 4 - %1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @0, i32 0, i32 0)) - store i32 1, i32* %0, align 4 - %2 = load i32, i32* %0, align 4 + %1 = call i32 (ptr, ...) @printf(ptr @0) + store i32 1, ptr %0, align 4 + %2 = load i32, ptr %0, align 4 ret i32 %2 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) define i32 @main() { -entry: +entry.l11: %result = alloca i32, align 4 %0 = alloca i32, align 4 - store i32 0, i32* %result, align 4 + store i32 0, ptr %result, align 4 %1 = call i32 @_f__void__testFunc() - store i32 %1, i32* %0, align 4 - %2 = load i32, i32* %0, align 4 - %3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @1, i32 0, i32 0), i32 %2) - %4 = load i32, i32* %result, align 4 + store i32 %1, ptr %0, align 4 + %2 = load i32, ptr %0, align 4 + %3 = call i32 (ptr, ...) @printf(ptr @1, i32 %2) + %4 = load i32, ptr %result, align 4 ret i32 %4 } diff --git a/test/test-files/generator/functions/success-result-variable/ir-code.ll b/test/test-files/generator/functions/success-result-variable/ir-code.ll index 45267cf00..3c832ecdc 100644 --- a/test/test-files/generator/functions/success-result-variable/ir-code.ll +++ b/test/test-files/generator/functions/success-result-variable/ir-code.ll @@ -6,47 +6,47 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [15 x i8] c"The age is: %d\00", align 1 define internal i32 @_f__void__getAge() { -entry: +entry.l1: %result = alloca i32, align 4 %i = alloca i1, align 1 %0 = alloca i32, align 4 - store i1 false, i1* %i, align 1 - br i1 true, label %if.then, label %if.else + store i1 false, ptr %i, align 1 + br i1 true, label %if.then.l3, label %if.else.l3 -if.then: ; preds = %entry - store i32 20, i32* %result, align 4 - %1 = load i32, i32* %result, align 4 +if.then.l3: ; preds = %entry.l1 + store i32 20, ptr %result, align 4 + %1 = load i32, ptr %result, align 4 ret i32 %1 -if.else: ; preds = %entry - store i1 false, i1* %i, align 1 - %2 = load i1, i1* %i, align 1 - br i1 %2, label %if.then1, label %if.end +if.else.l3: ; preds = %entry.l1 + store i1 false, ptr %i, align 1 + %2 = load i1, ptr %i, align 1 + br i1 %2, label %if.then.l6, label %if.end.l6 -if.then1: ; preds = %if.else - store i32 19, i32* %result, align 4 - br label %if.end +if.then.l6: ; preds = %if.else.l3 + store i32 19, ptr %result, align 4 + br label %if.end.l6 -if.end: ; preds = %if.then1, %if.else - br label %if.end2 +if.end.l6: ; preds = %if.then.l6, %if.else.l3 + br label %if.end.l3 -if.end2: ; preds = %if.end - store i32 15, i32* %0, align 4 - %3 = load i32, i32* %0, align 4 +if.end.l3: ; preds = %if.end.l6 + store i32 15, ptr %0, align 4 + %3 = load i32, ptr %0, align 4 ret i32 %3 } define i32 @main() { -entry: +entry.l12: %result = alloca i32, align 4 %0 = alloca i32, align 4 - store i32 0, i32* %result, align 4 + store i32 0, ptr %result, align 4 %1 = call i32 @_f__void__getAge() - store i32 %1, i32* %0, align 4 - %2 = load i32, i32* %0, align 4 - %3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @0, i32 0, i32 0), i32 %2) - %4 = load i32, i32* %result, align 4 + store i32 %1, ptr %0, align 4 + %2 = load i32, ptr %0, align 4 + %3 = call i32 (ptr, ...) @printf(ptr @0, i32 %2) + %4 = load i32, ptr %result, align 4 ret i32 %4 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/generics/success-external-generic-functions/ir-code.ll b/test/test-files/generator/generics/success-external-generic-functions/ir-code.ll index 09698d564..b4030fe82 100644 --- a/test/test-files/generator/generics/success-external-generic-functions/ir-code.ll +++ b/test/test-files/generator/generics/success-external-generic-functions/ir-code.ll @@ -5,31 +5,31 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [6 x i8] c"Hello\00", align 1 @1 = private unnamed_addr constant [6 x i8] c"World\00", align 1 -@anonymous.0 = constant [2 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @0, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @1, i32 0, i32 0)] +@anonymous.0 = constant [2 x ptr] [ptr @0, ptr @1] define i32 @main() { -entry: +entry.l3: %result = alloca i32, align 4 %0 = alloca double, align 8 %1 = alloca i1, align 1 %2 = alloca i32, align 4 %3 = alloca i1, align 1 - %4 = alloca [2 x i8*], align 8 + %4 = alloca [2 x ptr], align 8 %5 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - store double 1.123000e+00, double* %0, align 8 - %6 = load double, double* %0, align 8 + store i32 0, ptr %result, align 4 + store double 1.123000e+00, ptr %0, align 8 + %6 = load double, ptr %0, align 8 call void @_p__void__printFormat__double(double %6) - store i1 true, i1* %1, align 1 - store i32 543, i32* %2, align 4 - %7 = load i32, i32* %2, align 4 + store i1 true, ptr %1, align 1 + store i32 543, ptr %2, align 4 + %7 = load i32, ptr %2, align 4 call void @_p__void__printFormat__int(i32 %7) - store i1 true, i1* %3, align 1 - store [2 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @0, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @1, i32 0, i32 0)], [2 x i8*]* %4, align 8 - %8 = load [2 x i8*], [2 x i8*]* %4, align 8 - call void @_p__void__printFormat__stringarray([2 x i8*] %8) - store i1 true, i1* %5, align 1 - %9 = load i32, i32* %result, align 4 + store i1 true, ptr %3, align 1 + store [2 x ptr] [ptr @0, ptr @1], ptr %4, align 8 + %8 = load [2 x ptr], ptr %4, align 8 + call void @_p__void__printFormat__stringarray([2 x ptr] %8) + store i1 true, ptr %5, align 1 + %9 = load i32, ptr %result, align 4 ret i32 %9 } @@ -37,4 +37,4 @@ declare void @_p__void__printFormat__double(double) declare void @_p__void__printFormat__int(i32) -declare void @_p__void__printFormat__stringarray([2 x i8*]) +declare void @_p__void__printFormat__stringarray([2 x ptr]) diff --git a/test/test-files/generator/generics/success-generic-functions/ir-code.ll b/test/test-files/generator/generics/success-generic-functions/ir-code.ll index 8b44ec85b..49103f5b3 100644 --- a/test/test-files/generator/generics/success-generic-functions/ir-code.ll +++ b/test/test-files/generator/generics/success-generic-functions/ir-code.ll @@ -7,51 +7,51 @@ target triple = "x86_64-w64-windows-gnu" @1 = private unnamed_addr constant [4 x i8] c"%f\0A\00", align 1 define internal double @_f__void__genericFunction__int_double(i32 %0, double %1) { -entry: +entry.l4: %arg1 = alloca i32, align 4 %arg2 = alloca double, align 8 %arg3 = alloca i32, align 4 %result = alloca double, align 8 %2 = alloca double, align 8 - store i32 %0, i32* %arg1, align 4 - store double %1, double* %arg2, align 8 - store i32 10, i32* %arg3, align 4 - %3 = load i32, i32* %arg1, align 4 - %4 = load double, double* %arg2, align 8 + store i32 %0, ptr %arg1, align 4 + store double %1, ptr %arg2, align 8 + store i32 10, ptr %arg3, align 4 + %3 = load i32, ptr %arg1, align 4 + %4 = load double, ptr %arg2, align 8 %5 = sitofp i32 %3 to double %6 = fadd double %5, %4 - %7 = load i32, i32* %arg3, align 4 + %7 = load i32, ptr %arg3, align 4 %8 = sitofp i32 %7 to double %9 = fadd double %6, %8 - store double %9, double* %2, align 8 - %10 = load double, double* %2, align 8 + store double %9, ptr %2, align 8 + %10 = load double, ptr %2, align 8 ret double %10 } define internal double @_f__void__genericFunction__long_double(i64 %0, double %1) { -entry: +entry.l4: %arg1 = alloca i64, align 8 %arg2 = alloca double, align 8 %arg3 = alloca i32, align 4 %result = alloca double, align 8 %2 = alloca double, align 8 - store i64 %0, i64* %arg1, align 8 - store double %1, double* %arg2, align 8 - store i32 10, i32* %arg3, align 4 - %3 = load i64, i64* %arg1, align 8 - %4 = load double, double* %arg2, align 8 + store i64 %0, ptr %arg1, align 8 + store double %1, ptr %arg2, align 8 + store i32 10, ptr %arg3, align 4 + %3 = load i64, ptr %arg1, align 8 + %4 = load double, ptr %arg2, align 8 %5 = sitofp i64 %3 to double %6 = fadd double %5, %4 - %7 = load i32, i32* %arg3, align 4 + %7 = load i32, ptr %arg3, align 4 %8 = sitofp i32 %7 to double %9 = fadd double %6, %8 - store double %9, double* %2, align 8 - %10 = load double, double* %2, align 8 + store double %9, ptr %2, align 8 + %10 = load double, ptr %2, align 8 ret double %10 } define i32 @main() { -entry: +entry.l12: %result = alloca i32, align 4 %0 = alloca i32, align 4 %1 = alloca double, align 8 @@ -59,25 +59,25 @@ entry: %3 = alloca i64, align 8 %4 = alloca double, align 8 %5 = alloca double, align 8 - store i32 0, i32* %result, align 4 - store i32 1, i32* %0, align 4 - %6 = load i32, i32* %0, align 4 - store double 2.400000e+00, double* %1, align 8 - %7 = load double, double* %1, align 8 + store i32 0, ptr %result, align 4 + store i32 1, ptr %0, align 4 + %6 = load i32, ptr %0, align 4 + store double 2.400000e+00, ptr %1, align 8 + %7 = load double, ptr %1, align 8 %8 = call double @_f__void__genericFunction__int_double(i32 %6, double %7) - store double %8, double* %2, align 8 - %9 = load double, double* %2, align 8 - %10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @0, i32 0, i32 0), double %9) - store i64 12, i64* %3, align 8 - %11 = load i64, i64* %3, align 8 - store double 2.000000e+00, double* %4, align 8 - %12 = load double, double* %4, align 8 + store double %8, ptr %2, align 8 + %9 = load double, ptr %2, align 8 + %10 = call i32 (ptr, ...) @printf(ptr @0, double %9) + store i64 12, ptr %3, align 8 + %11 = load i64, ptr %3, align 8 + store double 2.000000e+00, ptr %4, align 8 + %12 = load double, ptr %4, align 8 %13 = call double @_f__void__genericFunction__long_double(i64 %11, double %12) - store double %13, double* %5, align 8 - %14 = load double, double* %5, align 8 - %15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @1, i32 0, i32 0), double %14) - %16 = load i32, i32* %result, align 4 + store double %13, ptr %5, align 8 + %14 = load double, ptr %5, align 8 + %15 = call i32 (ptr, ...) @printf(ptr @1, double %14) + %16 = load i32, ptr %result, align 4 ret i32 %16 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/generics/success-generic-functions2/ir-code.ll b/test/test-files/generator/generics/success-generic-functions2/ir-code.ll index f10969d24..7ff4e1395 100644 --- a/test/test-files/generator/generics/success-generic-functions2/ir-code.ll +++ b/test/test-files/generator/generics/success-generic-functions2/ir-code.ll @@ -8,139 +8,139 @@ target triple = "x86_64-w64-windows-gnu" @numberList2 = constant [4 x i64] [i64 10, i64 12, i64 14, i64 16] @1 = private unnamed_addr constant [17 x i8] c"Results: %d, %d\0A\00", align 1 -define internal i32 @_f__void__sumNumbers__longarray_int(i64* %0, i32 %1) { -entry: - %numberArray = alloca i64*, align 8 +define internal i32 @_f__void__sumNumbers__longarray_int(ptr %0, i32 %1) { +entry.l4: + %numberArray = alloca ptr, align 8 %arrayLength = alloca i32, align 4 %result = alloca i32, align 4 %i = alloca i32, align 4 %2 = alloca i32, align 4 %3 = alloca i1, align 1 - store i64* %0, i64** %numberArray, align 8 - store i32 %1, i32* %arrayLength, align 4 - store i32 0, i32* %result, align 4 - store i32 0, i32* %i, align 4 - br label %for.cond - -for: ; preds = %for.cond - %4 = load i64*, i64** %numberArray, align 8 - %5 = load i32, i32* %i, align 4 - %6 = getelementptr inbounds i64, i64* %4, i32 %5 - %7 = load i64, i64* %6, align 8 - %8 = load i32, i32* %result, align 4 + store ptr %0, ptr %numberArray, align 8 + store i32 %1, ptr %arrayLength, align 4 + store i32 0, ptr %result, align 4 + store i32 0, ptr %i, align 4 + br label %for.cond.l6 + +for.l6: ; preds = %for.cond.l6 + %4 = load ptr, ptr %numberArray, align 8 + %5 = load i32, ptr %i, align 4 + %6 = getelementptr inbounds i64, ptr %4, i32 %5 + %7 = load i64, ptr %6, align 8 + %8 = load i32, ptr %result, align 4 %9 = trunc i64 %7 to i32 %10 = add i32 %8, %9 - store i32 %10, i32* %result, align 4 - br label %for.inc + store i32 %10, ptr %result, align 4 + br label %for.inc.l6 -for.inc: ; preds = %for - %11 = load i32, i32* %i, align 4 +for.inc.l6: ; preds = %for.l6 + %11 = load i32, ptr %i, align 4 %12 = add i32 %11, 1 - store i32 %12, i32* %i, align 4 - store i32 %11, i32* %2, align 4 - br label %for.cond + store i32 %12, ptr %i, align 4 + store i32 %11, ptr %2, align 4 + br label %for.cond.l6 -for.cond: ; preds = %for.inc, %entry - %13 = load i32, i32* %i, align 4 - %14 = load i32, i32* %arrayLength, align 4 +for.cond.l6: ; preds = %for.inc.l6, %entry.l4 + %13 = load i32, ptr %i, align 4 + %14 = load i32, ptr %arrayLength, align 4 %15 = icmp slt i32 %13, %14 - store i1 %15, i1* %3, align 1 - %16 = load i1, i1* %3, align 1 - br i1 %16, label %for, label %for.end + store i1 %15, ptr %3, align 1 + %16 = load i1, ptr %3, align 1 + br i1 %16, label %for.l6, label %for.end.l6 -for.end: ; preds = %for.cond - %17 = load i32, i32* %result, align 4 +for.end.l6: ; preds = %for.cond.l6 + %17 = load i32, ptr %result, align 4 ret i32 %17 } -define internal i32 @_f__void__sumNumbers__shortarray_int(i16* %0, i32 %1) { -entry: - %numberArray = alloca i16*, align 8 +define internal i32 @_f__void__sumNumbers__shortarray_int(ptr %0, i32 %1) { +entry.l4: + %numberArray = alloca ptr, align 8 %arrayLength = alloca i32, align 4 %result = alloca i32, align 4 %i = alloca i32, align 4 %2 = alloca i32, align 4 %3 = alloca i1, align 1 - store i16* %0, i16** %numberArray, align 8 - store i32 %1, i32* %arrayLength, align 4 - store i32 0, i32* %result, align 4 - store i32 0, i32* %i, align 4 - br label %for.cond - -for: ; preds = %for.cond - %4 = load i16*, i16** %numberArray, align 8 - %5 = load i32, i32* %i, align 4 - %6 = getelementptr inbounds i16, i16* %4, i32 %5 - %7 = load i16, i16* %6, align 2 - %8 = load i32, i32* %result, align 4 + store ptr %0, ptr %numberArray, align 8 + store i32 %1, ptr %arrayLength, align 4 + store i32 0, ptr %result, align 4 + store i32 0, ptr %i, align 4 + br label %for.cond.l6 + +for.l6: ; preds = %for.cond.l6 + %4 = load ptr, ptr %numberArray, align 8 + %5 = load i32, ptr %i, align 4 + %6 = getelementptr inbounds i16, ptr %4, i32 %5 + %7 = load i16, ptr %6, align 2 + %8 = load i32, ptr %result, align 4 %9 = sext i16 %7 to i32 %10 = add i32 %8, %9 - store i32 %10, i32* %result, align 4 - br label %for.inc + store i32 %10, ptr %result, align 4 + br label %for.inc.l6 -for.inc: ; preds = %for - %11 = load i32, i32* %i, align 4 +for.inc.l6: ; preds = %for.l6 + %11 = load i32, ptr %i, align 4 %12 = add i32 %11, 1 - store i32 %12, i32* %i, align 4 - store i32 %11, i32* %2, align 4 - br label %for.cond + store i32 %12, ptr %i, align 4 + store i32 %11, ptr %2, align 4 + br label %for.cond.l6 -for.cond: ; preds = %for.inc, %entry - %13 = load i32, i32* %i, align 4 - %14 = load i32, i32* %arrayLength, align 4 +for.cond.l6: ; preds = %for.inc.l6, %entry.l4 + %13 = load i32, ptr %i, align 4 + %14 = load i32, ptr %arrayLength, align 4 %15 = icmp slt i32 %13, %14 - store i1 %15, i1* %3, align 1 - %16 = load i1, i1* %3, align 1 - br i1 %16, label %for, label %for.end + store i1 %15, ptr %3, align 1 + %16 = load i1, ptr %3, align 1 + br i1 %16, label %for.l6, label %for.end.l6 -for.end: ; preds = %for.cond - %17 = load i32, i32* %result, align 4 +for.end.l6: ; preds = %for.cond.l6 + %17 = load i32, ptr %result, align 4 ret i32 %17 } define internal void @_p__void__printData__int_intarray(i32 %0, [2 x i32] %1) { -entry: +entry.l11: %arrayLength = alloca i32, align 4 %list = alloca [2 x i32], align 4 %i = alloca i32, align 4 %2 = alloca i32, align 4 %3 = alloca i1, align 1 - store i32 %0, i32* %arrayLength, align 4 - store [2 x i32] %1, [2 x i32]* %list, align 4 - store i32 0, i32* %i, align 4 - br label %for.cond - -for: ; preds = %for.cond - %4 = load [2 x i32], [2 x i32]* %list, align 4 - %5 = load i32, i32* %i, align 4 - %6 = getelementptr inbounds [2 x i32], [2 x i32]* %list, i32 0, i32 %5 - %7 = load i32, i32* %6, align 4 - %8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @0, i32 0, i32 0), i32 %7) - br label %for.inc - -for.inc: ; preds = %for - %9 = load i32, i32* %i, align 4 + store i32 %0, ptr %arrayLength, align 4 + store [2 x i32] %1, ptr %list, align 4 + store i32 0, ptr %i, align 4 + br label %for.cond.l12 + +for.l12: ; preds = %for.cond.l12 + %4 = load [2 x i32], ptr %list, align 4 + %5 = load i32, ptr %i, align 4 + %6 = getelementptr inbounds [2 x i32], ptr %list, i32 0, i32 %5 + %7 = load i32, ptr %6, align 4 + %8 = call i32 (ptr, ...) @printf(ptr @0, i32 %7) + br label %for.inc.l12 + +for.inc.l12: ; preds = %for.l12 + %9 = load i32, ptr %i, align 4 %10 = add i32 %9, 1 - store i32 %10, i32* %i, align 4 - store i32 %9, i32* %2, align 4 - br label %for.cond + store i32 %10, ptr %i, align 4 + store i32 %9, ptr %2, align 4 + br label %for.cond.l12 -for.cond: ; preds = %for.inc, %entry - %11 = load i32, i32* %i, align 4 - %12 = load i32, i32* %arrayLength, align 4 +for.cond.l12: ; preds = %for.inc.l12, %entry.l11 + %11 = load i32, ptr %i, align 4 + %12 = load i32, ptr %arrayLength, align 4 %13 = icmp slt i32 %11, %12 - store i1 %13, i1* %3, align 1 - %14 = load i1, i1* %3, align 1 - br i1 %14, label %for, label %for.end + store i1 %13, ptr %3, align 1 + %14 = load i1, ptr %3, align 1 + br i1 %14, label %for.l12, label %for.end.l12 -for.end: ; preds = %for.cond +for.end.l12: ; preds = %for.cond.l12 ret void } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) define i32 @main() { -entry: +entry.l17: %result = alloca i32, align 4 %numberList1 = alloca [7 x i16], align 2 %0 = alloca i32, align 4 @@ -151,36 +151,36 @@ entry: %resultList = alloca [2 x i32], align 4 %4 = alloca i32, align 4 %5 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - store [7 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7], [7 x i16]* %numberList1, align 2 - %6 = getelementptr inbounds [7 x i16], [7 x i16]* %numberList1, i32 0, i32 0 - %7 = load [7 x i16], [7 x i16]* %numberList1, align 2 - store i32 7, i32* %0, align 4 - %8 = load i32, i32* %0, align 4 - %9 = call i32 @_f__void__sumNumbers__shortarray_int(i16* %6, i32 %8) - store i32 %9, i32* %1, align 4 - store [4 x i64] [i64 10, i64 12, i64 14, i64 16], [4 x i64]* %numberList2, align 8 - %10 = getelementptr inbounds [4 x i64], [4 x i64]* %numberList2, i32 0, i32 0 - %11 = load [4 x i64], [4 x i64]* %numberList2, align 8 - store i32 4, i32* %2, align 4 - %12 = load i32, i32* %2, align 4 - %13 = call i32 @_f__void__sumNumbers__longarray_int(i64* %10, i32 %12) - store i32 %13, i32* %3, align 4 - %14 = load i32, i32* %1, align 4 - %15 = load i32, i32* %3, align 4 - %16 = getelementptr inbounds [2 x i32], [2 x i32]* %resultList, i32 0, i32 0 - store i32 %14, i32* %16, align 4 - %17 = getelementptr inbounds [2 x i32], [2 x i32]* %resultList, i32 0, i32 1 - store i32 %15, i32* %17, align 4 - %18 = load [2 x i32], [2 x i32]* %resultList, align 4 - store i32 2, i32* %4, align 4 - %19 = load i32, i32* %4, align 4 - %20 = load [2 x i32], [2 x i32]* %resultList, align 4 + store i32 0, ptr %result, align 4 + store [7 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7], ptr %numberList1, align 2 + %6 = getelementptr inbounds [7 x i16], ptr %numberList1, i32 0, i32 0 + %7 = load [7 x i16], ptr %numberList1, align 2 + store i32 7, ptr %0, align 4 + %8 = load i32, ptr %0, align 4 + %9 = call i32 @_f__void__sumNumbers__shortarray_int(ptr %6, i32 %8) + store i32 %9, ptr %1, align 4 + store [4 x i64] [i64 10, i64 12, i64 14, i64 16], ptr %numberList2, align 8 + %10 = getelementptr inbounds [4 x i64], ptr %numberList2, i32 0, i32 0 + %11 = load [4 x i64], ptr %numberList2, align 8 + store i32 4, ptr %2, align 4 + %12 = load i32, ptr %2, align 4 + %13 = call i32 @_f__void__sumNumbers__longarray_int(ptr %10, i32 %12) + store i32 %13, ptr %3, align 4 + %14 = load i32, ptr %1, align 4 + %15 = load i32, ptr %3, align 4 + %16 = getelementptr inbounds [2 x i32], ptr %resultList, i32 0, i32 0 + store i32 %14, ptr %16, align 4 + %17 = getelementptr inbounds [2 x i32], ptr %resultList, i32 0, i32 1 + store i32 %15, ptr %17, align 4 + %18 = load [2 x i32], ptr %resultList, align 4 + store i32 2, ptr %4, align 4 + %19 = load i32, ptr %4, align 4 + %20 = load [2 x i32], ptr %resultList, align 4 call void @_p__void__printData__int_intarray(i32 %19, [2 x i32] %20) - store i1 true, i1* %5, align 1 - %21 = load i32, i32* %1, align 4 - %22 = load i32, i32* %3, align 4 - %23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @1, i32 0, i32 0), i32 %21, i32 %22) - %24 = load i32, i32* %result, align 4 + store i1 true, ptr %5, align 1 + %21 = load i32, ptr %1, align 4 + %22 = load i32, ptr %3, align 4 + %23 = call i32 (ptr, ...) @printf(ptr @1, i32 %21, i32 %22) + %24 = load i32, ptr %result, align 4 ret i32 %24 } diff --git a/test/test-files/generator/generics/success-generic-structs/ir-code.ll b/test/test-files/generator/generics/success-generic-structs/ir-code.ll index 64263d817..f434bb7b2 100644 --- a/test/test-files/generator/generics/success-generic-structs/ir-code.ll +++ b/test/test-files/generator/generics/success-generic-structs/ir-code.ll @@ -3,30 +3,30 @@ source_filename = "source.spice" target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-w64-windows-gnu" -%_s__double__Vector__doubleptr_int = type { double*, i32 } +%_s__double__Vector__doubleptr_int = type { ptr, i32 } @0 = private unnamed_addr constant [24 x i8] c"Capacity of vector: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l8: %result = alloca i32, align 4 %dbl = alloca double, align 8 %0 = alloca %_s__double__Vector__doubleptr_int, align 8 - %1 = alloca double*, align 8 - store i32 0, i32* %result, align 4 - store double 3.467000e+00, double* %dbl, align 8 - store double* %dbl, double** %1, align 8 - %2 = load double*, double** %1, align 8 - %3 = getelementptr inbounds %_s__double__Vector__doubleptr_int, %_s__double__Vector__doubleptr_int* %0, i32 0, i32 0 - store double* %2, double** %3, align 8 - %4 = getelementptr inbounds %_s__double__Vector__doubleptr_int, %_s__double__Vector__doubleptr_int* %0, i32 0, i32 1 - store i32 1, i32* %4, align 4 - %5 = load %_s__double__Vector__doubleptr_int, %_s__double__Vector__doubleptr_int* %0, align 8 - %6 = getelementptr inbounds %_s__double__Vector__doubleptr_int, %_s__double__Vector__doubleptr_int* %0, i32 0, i32 1 - %7 = load i32, i32* %6, align 4 - %8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @0, i32 0, i32 0), i32 %7) - %9 = load i32, i32* %result, align 4 + %1 = alloca ptr, align 8 + store i32 0, ptr %result, align 4 + store double 3.467000e+00, ptr %dbl, align 8 + store ptr %dbl, ptr %1, align 8 + %2 = load ptr, ptr %1, align 8 + %3 = getelementptr inbounds %_s__double__Vector__doubleptr_int, ptr %0, i32 0, i32 0 + store ptr %2, ptr %3, align 8 + %4 = getelementptr inbounds %_s__double__Vector__doubleptr_int, ptr %0, i32 0, i32 1 + store i32 1, ptr %4, align 4 + %5 = load %_s__double__Vector__doubleptr_int, ptr %0, align 8 + %6 = getelementptr inbounds %_s__double__Vector__doubleptr_int, ptr %0, i32 0, i32 1 + %7 = load i32, ptr %6, align 4 + %8 = call i32 (ptr, ...) @printf(ptr @0, i32 %7) + %9 = load i32, ptr %result, align 4 ret i32 %9 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/if-stmts/success-if-else-stmt/ir-code.ll b/test/test-files/generator/if-stmts/success-if-else-stmt/ir-code.ll index a7d1ecc91..033c185ce 100644 --- a/test/test-files/generator/if-stmts/success-if-else-stmt/ir-code.ll +++ b/test/test-files/generator/if-stmts/success-if-else-stmt/ir-code.ll @@ -9,51 +9,51 @@ target triple = "x86_64-w64-windows-gnu" @3 = private unnamed_addr constant [5 x i8] c"Else\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %0 = alloca i1, align 1 %1 = alloca i1, align 1 %2 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - store i1 false, i1* %0, align 1 - %3 = load i1, i1* %0, align 1 - br i1 %3, label %if.then, label %if.else + store i32 0, ptr %result, align 4 + store i1 false, ptr %0, align 1 + %3 = load i1, ptr %0, align 1 + br i1 %3, label %if.then.l2, label %if.else.l2 -if.then: ; preds = %entry - %4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @0, i32 0, i32 0)) - br label %if.end6 +if.then.l2: ; preds = %entry.l1 + %4 = call i32 (ptr, ...) @printf(ptr @0) + br label %if.end.l2 -if.else: ; preds = %entry - store i1 false, i1* %1, align 1 - %5 = load i1, i1* %1, align 1 - br i1 %5, label %if.then1, label %if.else2 +if.else.l2: ; preds = %entry.l1 + store i1 false, ptr %1, align 1 + %5 = load i1, ptr %1, align 1 + br i1 %5, label %if.then.l4, label %if.else.l4 -if.then1: ; preds = %if.else - %6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @1, i32 0, i32 0)) - br label %if.end5 +if.then.l4: ; preds = %if.else.l2 + %6 = call i32 (ptr, ...) @printf(ptr @1) + br label %if.end.l4 -if.else2: ; preds = %if.else - store i1 false, i1* %2, align 1 - %7 = load i1, i1* %2, align 1 - br i1 %7, label %if.then3, label %if.else4 +if.else.l4: ; preds = %if.else.l2 + store i1 false, ptr %2, align 1 + %7 = load i1, ptr %2, align 1 + br i1 %7, label %if.then.l6, label %if.else.l6 -if.then3: ; preds = %if.else2 - %8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @2, i32 0, i32 0)) - br label %if.end +if.then.l6: ; preds = %if.else.l4 + %8 = call i32 (ptr, ...) @printf(ptr @2) + br label %if.end.l6 -if.else4: ; preds = %if.else2 - %9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @3, i32 0, i32 0)) - br label %if.end +if.else.l6: ; preds = %if.else.l4 + %9 = call i32 (ptr, ...) @printf(ptr @3) + br label %if.end.l6 -if.end: ; preds = %if.else4, %if.then3 - br label %if.end5 +if.end.l6: ; preds = %if.else.l6, %if.then.l6 + br label %if.end.l4 -if.end5: ; preds = %if.end, %if.then1 - br label %if.end6 +if.end.l4: ; preds = %if.end.l6, %if.then.l4 + br label %if.end.l2 -if.end6: ; preds = %if.end5, %if.then - %10 = load i32, i32* %result, align 4 +if.end.l2: ; preds = %if.end.l4, %if.then.l2 + %10 = load i32, ptr %result, align 4 ret i32 %10 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/if-stmts/success-if-stmt/ir-code.ll b/test/test-files/generator/if-stmts/success-if-stmt/ir-code.ll index dabaae7bf..378af45c6 100644 --- a/test/test-files/generator/if-stmts/success-if-stmt/ir-code.ll +++ b/test/test-files/generator/if-stmts/success-if-stmt/ir-code.ll @@ -7,25 +7,25 @@ target triple = "x86_64-w64-windows-gnu" @1 = private unnamed_addr constant [17 x i8] c"Condition false\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %0 = alloca i1, align 1 %1 = alloca i32, align 4 - store i32 0, i32* %result, align 4 - store i1 true, i1* %0, align 1 - %2 = load i1, i1* %0, align 1 - br i1 %2, label %if.then, label %if.end + store i32 0, ptr %result, align 4 + store i1 true, ptr %0, align 1 + %2 = load i1, ptr %0, align 1 + br i1 %2, label %if.then.l3, label %if.end.l3 -if.then: ; preds = %entry - %3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @0, i32 0, i32 0)) - store i32 0, i32* %1, align 4 - %4 = load i32, i32* %1, align 4 +if.then.l3: ; preds = %entry.l1 + %3 = call i32 (ptr, ...) @printf(ptr @0) + store i32 0, ptr %1, align 4 + %4 = load i32, ptr %1, align 4 ret i32 %4 -if.end: ; preds = %entry - %5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @1, i32 0, i32 0)) - %6 = load i32, i32* %result, align 4 +if.end.l3: ; preds = %entry.l1 + %5 = call i32 (ptr, ...) @printf(ptr @1) + %6 = load i32, ptr %result, align 4 ret i32 %6 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/imports/success-modules-std/ir-code.ll b/test/test-files/generator/imports/success-modules-std/ir-code.ll index d9eebf601..04dd024d2 100644 --- a/test/test-files/generator/imports/success-modules-std/ir-code.ll +++ b/test/test-files/generator/imports/success-modules-std/ir-code.ll @@ -6,21 +6,21 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [12 x i8] c"Result: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l3: %result = alloca i32, align 4 %0 = alloca i1, align 1 %1 = alloca i32, align 4 - store i32 0, i32* %result, align 4 - store i1 true, i1* %0, align 1 - %2 = load i1, i1* %0, align 1 + store i32 0, ptr %result, align 4 + store i1 true, ptr %0, align 1 + %2 = load i1, ptr %0, align 1 %3 = call i32 @_f__void__toInt__bool(i1 %2) - store i32 %3, i32* %1, align 4 - %4 = load i32, i32* %1, align 4 - %5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @0, i32 0, i32 0), i32 %4) - %6 = load i32, i32* %result, align 4 + store i32 %3, ptr %1, align 4 + %4 = load i32, ptr %1, align 4 + %5 = call i32 (ptr, ...) @printf(ptr @0, i32 %4) + %6 = load i32, ptr %result, align 4 ret i32 %6 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) declare i32 @_f__void__toInt__bool(i1) diff --git a/test/test-files/generator/imports/success-modules/ir-code.ll b/test/test-files/generator/imports/success-modules/ir-code.ll index daeb32d4c..d702f402e 100644 --- a/test/test-files/generator/imports/success-modules/ir-code.ll +++ b/test/test-files/generator/imports/success-modules/ir-code.ll @@ -6,18 +6,18 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [11 x i8] c"Result: %d\00", align 1 define i32 @main() { -entry: +entry.l3: %result = alloca i32, align 4 %0 = alloca i32, align 4 - store i32 0, i32* %result, align 4 + store i32 0, ptr %result, align 4 %1 = call i32 @_f__void__forwardToOtherModule() - store i32 %1, i32* %0, align 4 - %2 = load i32, i32* %0, align 4 - %3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @0, i32 0, i32 0), i32 %2) - %4 = load i32, i32* %result, align 4 + store i32 %1, ptr %0, align 4 + %2 = load i32, ptr %0, align 4 + %3 = call i32 (ptr, ...) @printf(ptr @0, i32 %2) + %4 = load i32, ptr %result, align 4 ret i32 %4 } declare i32 @_f__void__forwardToOtherModule() -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/methods/success-method-down-up-call/ir-code.ll b/test/test-files/generator/methods/success-method-down-up-call/ir-code.ll index 38f1bd539..f5f420ac6 100644 --- a/test/test-files/generator/methods/success-method-down-up-call/ir-code.ll +++ b/test/test-files/generator/methods/success-method-down-up-call/ir-code.ll @@ -8,70 +8,70 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [10 x i8] c"Test: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %0 = alloca %_s__char__TestStruct__char_int, align 8 %1 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - %2 = getelementptr inbounds %_s__char__TestStruct__char_int, %_s__char__TestStruct__char_int* %0, i32 0, i32 0 - store i8 97, i8* %2, align 1 - %3 = getelementptr inbounds %_s__char__TestStruct__char_int, %_s__char__TestStruct__char_int* %0, i32 0, i32 1 - store i32 1, i32* %3, align 4 - call void @_mp__TestStruct_char__printTest(%_s__char__TestStruct__char_int* %0) - store i1 true, i1* %1, align 1 - %4 = load i32, i32* %result, align 4 + store i32 0, ptr %result, align 4 + %2 = getelementptr inbounds %_s__char__TestStruct__char_int, ptr %0, i32 0, i32 0 + store i8 97, ptr %2, align 1 + %3 = getelementptr inbounds %_s__char__TestStruct__char_int, ptr %0, i32 0, i32 1 + store i32 1, ptr %3, align 4 + call void @_mp__TestStruct_char__printTest(ptr %0) + store i1 true, ptr %1, align 1 + %4 = load i32, ptr %result, align 4 ret i32 %4 } -define internal void @_mp__TestStruct_char__printTest(%_s__char__TestStruct__char_int* %0) { -entry: - %this = alloca %_s__char__TestStruct__char_int*, align 8 +define internal void @_mp__TestStruct_char__printTest(ptr %0) { +entry.l13: + %this = alloca ptr, align 8 %1 = alloca i32, align 4 - store %_s__char__TestStruct__char_int* %0, %_s__char__TestStruct__char_int** %this, align 8 - %2 = load %_s__char__TestStruct__char_int*, %_s__char__TestStruct__char_int** %this, align 8 - %3 = call i32 @_mf__TestStruct_char__getTest(%_s__char__TestStruct__char_int* %2) - store i32 %3, i32* %1, align 4 - %4 = load i32, i32* %1, align 4 - %5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @0, i32 0, i32 0), i32 %4) + store ptr %0, ptr %this, align 8 + %2 = load ptr, ptr %this, align 8 + %3 = call i32 @_mf__TestStruct_char__getTest(ptr %2) + store i32 %3, ptr %1, align 4 + %4 = load i32, ptr %1, align 4 + %5 = call i32 (ptr, ...) @printf(ptr @0, i32 %4) ret void } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) -define internal i32 @_mf__TestStruct_char__getTest(%_s__char__TestStruct__char_int* %0) { -entry: - %this = alloca %_s__char__TestStruct__char_int*, align 8 +define internal i32 @_mf__TestStruct_char__getTest(ptr %0) { +entry.l17: + %this = alloca ptr, align 8 %result = alloca i32, align 4 %1 = alloca i1, align 1 %2 = alloca i32, align 4 %3 = alloca i1, align 1 - store %_s__char__TestStruct__char_int* %0, %_s__char__TestStruct__char_int** %this, align 8 - %4 = load %_s__char__TestStruct__char_int*, %_s__char__TestStruct__char_int** %this, align 8 - %5 = load %_s__char__TestStruct__char_int*, %_s__char__TestStruct__char_int** %this, align 8 - %6 = getelementptr inbounds %_s__char__TestStruct__char_int, %_s__char__TestStruct__char_int* %5, i32 0, i32 1 - %7 = load i32, i32* %6, align 4 + store ptr %0, ptr %this, align 8 + %4 = load ptr, ptr %this, align 8 + %5 = load ptr, ptr %this, align 8 + %6 = getelementptr inbounds %_s__char__TestStruct__char_int, ptr %5, i32 0, i32 1 + %7 = load i32, ptr %6, align 4 %8 = icmp eq i32 %7, 1 - store i1 %8, i1* %1, align 1 - %9 = load i1, i1* %1, align 1 - br i1 %9, label %if.then, label %if.end + store i1 %8, ptr %1, align 1 + %9 = load i1, ptr %1, align 1 + br i1 %9, label %if.then.l18, label %if.end.l18 -if.then: ; preds = %entry - %10 = load %_s__char__TestStruct__char_int*, %_s__char__TestStruct__char_int** %this, align 8 - %11 = load %_s__char__TestStruct__char_int*, %_s__char__TestStruct__char_int** %this, align 8 - %12 = getelementptr inbounds %_s__char__TestStruct__char_int, %_s__char__TestStruct__char_int* %11, i32 0, i32 1 - %13 = load i32, i32* %12, align 4 +if.then.l18: ; preds = %entry.l17 + %10 = load ptr, ptr %this, align 8 + %11 = load ptr, ptr %this, align 8 + %12 = getelementptr inbounds %_s__char__TestStruct__char_int, ptr %11, i32 0, i32 1 + %13 = load i32, ptr %12, align 4 %14 = add i32 %13, 1 - store i32 %14, i32* %12, align 4 - store i32 %13, i32* %2, align 4 - %15 = load %_s__char__TestStruct__char_int*, %_s__char__TestStruct__char_int** %this, align 8 - call void @_mp__TestStruct_char__printTest(%_s__char__TestStruct__char_int* %15) - store i1 true, i1* %3, align 1 - br label %if.end + store i32 %14, ptr %12, align 4 + store i32 %13, ptr %2, align 4 + %15 = load ptr, ptr %this, align 8 + call void @_mp__TestStruct_char__printTest(ptr %15) + store i1 true, ptr %3, align 1 + br label %if.end.l18 -if.end: ; preds = %if.then, %entry - %16 = load %_s__char__TestStruct__char_int*, %_s__char__TestStruct__char_int** %this, align 8 - %17 = load %_s__char__TestStruct__char_int*, %_s__char__TestStruct__char_int** %this, align 8 - %18 = getelementptr inbounds %_s__char__TestStruct__char_int, %_s__char__TestStruct__char_int* %17, i32 0, i32 1 - %19 = load i32, i32* %18, align 4 +if.end.l18: ; preds = %if.then.l18, %entry.l17 + %16 = load ptr, ptr %this, align 8 + %17 = load ptr, ptr %this, align 8 + %18 = getelementptr inbounds %_s__char__TestStruct__char_int, ptr %17, i32 0, i32 1 + %19 = load i32, ptr %18, align 4 ret i32 %19 } diff --git a/test/test-files/generator/methods/success-methods/ir-code.ll b/test/test-files/generator/methods/success-methods/ir-code.ll index 465d0ce29..a452ad6a9 100644 --- a/test/test-files/generator/methods/success-methods/ir-code.ll +++ b/test/test-files/generator/methods/success-methods/ir-code.ll @@ -3,58 +3,58 @@ source_filename = "source.spice" target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-w64-windows-gnu" -%_s__Letter__string = type { i8* } +%_s__Letter__string = type { ptr } @0 = private unnamed_addr constant [11 x i8] c"No content\00", align 1 @1 = private unnamed_addr constant [13 x i8] c"Hello World!\00", align 1 @2 = private unnamed_addr constant [13 x i8] c"Content: %s\0A\00", align 1 -define internal i8* @_mf__Letter__getContent(%_s__Letter__string* %0) { -entry: - %this = alloca %_s__Letter__string*, align 8 - %result = alloca i8*, align 8 - store %_s__Letter__string* %0, %_s__Letter__string** %this, align 8 - %1 = load %_s__Letter__string*, %_s__Letter__string** %this, align 8 - %2 = load %_s__Letter__string*, %_s__Letter__string** %this, align 8 - %3 = getelementptr inbounds %_s__Letter__string, %_s__Letter__string* %2, i32 0, i32 0 - %4 = load i8*, i8** %3, align 8 - ret i8* %4 +define internal ptr @_mf__Letter__getContent(ptr %0) { +entry.l5: + %this = alloca ptr, align 8 + %result = alloca ptr, align 8 + store ptr %0, ptr %this, align 8 + %1 = load ptr, ptr %this, align 8 + %2 = load ptr, ptr %this, align 8 + %3 = getelementptr inbounds %_s__Letter__string, ptr %2, i32 0, i32 0 + %4 = load ptr, ptr %3, align 8 + ret ptr %4 } -define internal void @_mp__Letter__setContent__string(%_s__Letter__string* %0, i8* %1) { -entry: - %this = alloca %_s__Letter__string*, align 8 - %text = alloca i8*, align 8 - store %_s__Letter__string* %0, %_s__Letter__string** %this, align 8 - store i8* %1, i8** %text, align 8 - %2 = load i8*, i8** %text, align 8 - %3 = load %_s__Letter__string*, %_s__Letter__string** %this, align 8 - %4 = load %_s__Letter__string*, %_s__Letter__string** %this, align 8 - %5 = getelementptr inbounds %_s__Letter__string, %_s__Letter__string* %4, i32 0, i32 0 - store i8* %2, i8** %5, align 8 +define internal void @_mp__Letter__setContent__string(ptr %0, ptr %1) { +entry.l9: + %this = alloca ptr, align 8 + %text = alloca ptr, align 8 + store ptr %0, ptr %this, align 8 + store ptr %1, ptr %text, align 8 + %2 = load ptr, ptr %text, align 8 + %3 = load ptr, ptr %this, align 8 + %4 = load ptr, ptr %this, align 8 + %5 = getelementptr inbounds %_s__Letter__string, ptr %4, i32 0, i32 0 + store ptr %2, ptr %5, align 8 ret void } define i32 @main() { -entry: +entry.l13: %result = alloca i32, align 4 %0 = alloca %_s__Letter__string, align 8 - %1 = alloca i8*, align 8 + %1 = alloca ptr, align 8 %2 = alloca i1, align 1 - %3 = alloca i8*, align 8 - store i32 0, i32* %result, align 4 - %4 = getelementptr inbounds %_s__Letter__string, %_s__Letter__string* %0, i32 0, i32 0 - store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @0, i32 0, i32 0), i8** %4, align 8 - store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @1, i32 0, i32 0), i8** %1, align 8 - %5 = load i8*, i8** %1, align 8 - call void @_mp__Letter__setContent__string(%_s__Letter__string* %0, i8* %5) - store i1 true, i1* %2, align 1 - %6 = call i8* @_mf__Letter__getContent(%_s__Letter__string* %0) - store i8* %6, i8** %3, align 8 - %7 = load i8*, i8** %3, align 8 - %8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @2, i32 0, i32 0), i8* %7) - %9 = load i32, i32* %result, align 4 + %3 = alloca ptr, align 8 + store i32 0, ptr %result, align 4 + %4 = getelementptr inbounds %_s__Letter__string, ptr %0, i32 0, i32 0 + store ptr @0, ptr %4, align 8 + store ptr @1, ptr %1, align 8 + %5 = load ptr, ptr %1, align 8 + call void @_mp__Letter__setContent__string(ptr %0, ptr %5) + store i1 true, ptr %2, align 1 + %6 = call ptr @_mf__Letter__getContent(ptr %0) + store ptr %6, ptr %3, align 8 + %7 = load ptr, ptr %3, align 8 + %8 = call i32 (ptr, ...) @printf(ptr @2, ptr %7) + %9 = load i32, ptr %result, align 4 ret i32 %9 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/operators/success-operators/ir-code.ll b/test/test-files/generator/operators/success-operators/ir-code.ll index fcdd8c919..a6fbd106b 100644 --- a/test/test-files/generator/operators/success-operators/ir-code.ll +++ b/test/test-files/generator/operators/success-operators/ir-code.ll @@ -6,7 +6,7 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [11 x i8] c"Value: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %val = alloca i32, align 4 %val1 = alloca i32, align 4 @@ -14,31 +14,31 @@ entry: %1 = alloca i32, align 4 %2 = alloca i32, align 4 %3 = alloca i32, align 4 - store i32 0, i32* %result, align 4 - store i32 1, i32* %val, align 4 - store i32 1, i32* %val1, align 4 - %4 = load i32, i32* %val1, align 4 + store i32 0, ptr %result, align 4 + store i32 1, ptr %val, align 4 + store i32 1, ptr %val1, align 4 + %4 = load i32, ptr %val1, align 4 %5 = add i32 %4, 1 - store i32 %5, i32* %val1, align 4 - store i32 %4, i32* %0, align 4 - %6 = load i32, i32* %0, align 4 + store i32 %5, ptr %val1, align 4 + store i32 %4, ptr %0, align 4 + %6 = load i32, ptr %0, align 4 %7 = sub i32 %6, 1 - store i32 %7, i32* %0, align 4 - store i32 %6, i32* %1, align 4 - %8 = load i32, i32* %1, align 4 + store i32 %7, ptr %0, align 4 + store i32 %6, ptr %1, align 4 + %8 = load i32, ptr %1, align 4 %9 = mul i32 %8, 2 - store i32 %9, i32* %2, align 4 - %10 = load i32, i32* %2, align 4 + store i32 %9, ptr %2, align 4 + %10 = load i32, ptr %2, align 4 %11 = shl i32 %10, 2 - store i32 %11, i32* %3, align 4 - %12 = load i32, i32* %3, align 4 - %13 = load i32, i32* %val, align 4 + store i32 %11, ptr %3, align 4 + %12 = load i32, ptr %3, align 4 + %13 = load i32, ptr %val, align 4 %14 = add i32 %13, %12 - store i32 %14, i32* %val, align 4 - %15 = load i32, i32* %val, align 4 - %16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @0, i32 0, i32 0), i32 %15) - %17 = load i32, i32* %result, align 4 + store i32 %14, ptr %val, align 4 + %15 = load i32, ptr %val, align 4 + %16 = call i32 (ptr, ...) @printf(ptr @0, i32 %15) + %17 = load i32, ptr %result, align 4 ret i32 %17 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/operators/success-operators2/ir-code.ll b/test/test-files/generator/operators/success-operators2/ir-code.ll index 262eeeebd..8212d3bbf 100644 --- a/test/test-files/generator/operators/success-operators2/ir-code.ll +++ b/test/test-files/generator/operators/success-operators2/ir-code.ll @@ -7,41 +7,41 @@ target triple = "x86_64-w64-windows-gnu" @1 = private unnamed_addr constant [14 x i8] c"Result 2: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %i = alloca i32, align 4 - store i32 0, i32* %result, align 4 - store i32 1, i32* %i, align 4 - %0 = load i32, i32* %i, align 4 + store i32 0, ptr %result, align 4 + store i32 1, ptr %i, align 4 + %0 = load i32, ptr %i, align 4 %1 = add i32 %0, 2 - store i32 %1, i32* %i, align 4 - %2 = load i32, i32* %i, align 4 + store i32 %1, ptr %i, align 4 + %2 = load i32, ptr %i, align 4 %3 = mul i32 %2, 2 - store i32 %3, i32* %i, align 4 - %4 = load i32, i32* %i, align 4 + store i32 %3, ptr %i, align 4 + %4 = load i32, ptr %i, align 4 %5 = sdiv i32 %4, 2 - store i32 %5, i32* %i, align 4 - %6 = load i32, i32* %i, align 4 + store i32 %5, ptr %i, align 4 + %6 = load i32, ptr %i, align 4 %7 = sub i32 %6, 2 - store i32 %7, i32* %i, align 4 - %8 = load i32, i32* %i, align 4 - %9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @0, i32 0, i32 0), i32 %8) - %10 = load i32, i32* %i, align 4 + store i32 %7, ptr %i, align 4 + %8 = load i32, ptr %i, align 4 + %9 = call i32 (ptr, ...) @printf(ptr @0, i32 %8) + %10 = load i32, ptr %i, align 4 %11 = add i32 %10, 494665727 - store i32 %11, i32* %i, align 4 - %12 = load i32, i32* %i, align 4 + store i32 %11, ptr %i, align 4 + %12 = load i32, ptr %i, align 4 %13 = sdiv i32 %12, 2 - store i32 %13, i32* %i, align 4 - %14 = load i32, i32* %i, align 4 + store i32 %13, ptr %i, align 4 + %14 = load i32, ptr %i, align 4 %15 = mul i32 %14, 2 - store i32 %15, i32* %i, align 4 - %16 = load i32, i32* %i, align 4 + store i32 %15, ptr %i, align 4 + %16 = load i32, ptr %i, align 4 %17 = sub i32 %16, 494665727 - store i32 %17, i32* %i, align 4 - %18 = load i32, i32* %i, align 4 - %19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @1, i32 0, i32 0), i32 %18) - %20 = load i32, i32* %result, align 4 + store i32 %17, ptr %i, align 4 + %18 = load i32, ptr %i, align 4 + %19 = call i32 (ptr, ...) @printf(ptr @1, i32 %18) + %20 = load i32, ptr %result, align 4 ret i32 %20 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/operators/success-short-circuiting/ir-code.ll b/test/test-files/generator/operators/success-short-circuiting/ir-code.ll index 901084da6..54d01c50e 100644 --- a/test/test-files/generator/operators/success-short-circuiting/ir-code.ll +++ b/test/test-files/generator/operators/success-short-circuiting/ir-code.ll @@ -9,29 +9,29 @@ target triple = "x86_64-w64-windows-gnu" @3 = private unnamed_addr constant [29 x i8] c"Logical or evaluated to: %d\0A\00", align 1 define internal i1 @_f__void__functionTrue() { -entry: +entry.l1: %result = alloca i1, align 1 %0 = alloca i1, align 1 - %1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @0, i32 0, i32 0)) - store i1 true, i1* %0, align 1 - %2 = load i1, i1* %0, align 1 + %1 = call i32 (ptr, ...) @printf(ptr @0) + store i1 true, ptr %0, align 1 + %2 = load i1, ptr %0, align 1 ret i1 %2 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) define internal i1 @_f__void__functionFalse() { -entry: +entry.l6: %result = alloca i1, align 1 %0 = alloca i1, align 1 - %1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @1, i32 0, i32 0)) - store i1 false, i1* %0, align 1 - %2 = load i1, i1* %0, align 1 + %1 = call i32 (ptr, ...) @printf(ptr @1) + store i1 false, ptr %0, align 1 + %2 = load i1, ptr %0, align 1 ret i1 %2 } define i32 @main() { -entry: +entry.l11: %result = alloca i32, align 4 %0 = alloca i1, align 1 %1 = alloca i1, align 1 @@ -39,41 +39,41 @@ entry: %3 = alloca i1, align 1 %4 = alloca i1, align 1 %5 = alloca i1, align 1 - store i32 0, i32* %result, align 4 + store i32 0, ptr %result, align 4 %6 = call i1 @_f__void__functionFalse() - store i1 %6, i1* %0, align 1 - %7 = load i1, i1* %0, align 1 - br i1 %7, label %land.1, label %land.end + store i1 %6, ptr %0, align 1 + %7 = load i1, ptr %0, align 1 + br i1 %7, label %land.1.l13, label %land.end.l13 -land.1: ; preds = %entry +land.1.l13: ; preds = %entry.l11 %8 = call i1 @_f__void__functionTrue() - store i1 %8, i1* %1, align 1 - %9 = load i1, i1* %1, align 1 - br label %land.end + store i1 %8, ptr %1, align 1 + %9 = load i1, ptr %1, align 1 + br label %land.end.l13 -land.end: ; preds = %land.1, %entry - %land_phi = phi i1 [ %7, %entry ], [ %9, %land.1 ] - store i1 %land_phi, i1* %2, align 1 - %10 = load i1, i1* %2, align 1 +land.end.l13: ; preds = %land.1.l13, %entry.l11 + %land_phi = phi i1 [ %7, %entry.l11 ], [ %9, %land.1.l13 ] + store i1 %land_phi, ptr %2, align 1 + %10 = load i1, ptr %2, align 1 %11 = zext i1 %10 to i32 - %12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @2, i32 0, i32 0), i32 %11) + %12 = call i32 (ptr, ...) @printf(ptr @2, i32 %11) %13 = call i1 @_f__void__functionTrue() - store i1 %13, i1* %3, align 1 - %14 = load i1, i1* %3, align 1 - br i1 %14, label %lor.end, label %lor.1 + store i1 %13, ptr %3, align 1 + %14 = load i1, ptr %3, align 1 + br i1 %14, label %lor.end.l16, label %lor.1.l16 -lor.1: ; preds = %land.end +lor.1.l16: ; preds = %land.end.l13 %15 = call i1 @_f__void__functionFalse() - store i1 %15, i1* %4, align 1 - %16 = load i1, i1* %4, align 1 - br label %lor.end + store i1 %15, ptr %4, align 1 + %16 = load i1, ptr %4, align 1 + br label %lor.end.l16 -lor.end: ; preds = %lor.1, %land.end - %lor_phi = phi i1 [ %14, %land.end ], [ %16, %lor.1 ] - store i1 %lor_phi, i1* %5, align 1 - %17 = load i1, i1* %5, align 1 +lor.end.l16: ; preds = %lor.1.l16, %land.end.l13 + %lor_phi = phi i1 [ %14, %land.end.l13 ], [ %16, %lor.1.l16 ] + store i1 %lor_phi, ptr %5, align 1 + %17 = load i1, ptr %5, align 1 %18 = zext i1 %17 to i32 - %19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @3, i32 0, i32 0), i32 %18) - %20 = load i32, i32* %result, align 4 + %19 = call i32 (ptr, ...) @printf(ptr @3, i32 %18) + %20 = load i32, ptr %result, align 4 ret i32 %20 } diff --git a/test/test-files/generator/pointers/success-nested-pointers/ir-code.ll b/test/test-files/generator/pointers/success-nested-pointers/ir-code.ll index b7637ac70..9edff5a24 100644 --- a/test/test-files/generator/pointers/success-nested-pointers/ir-code.ll +++ b/test/test-files/generator/pointers/success-nested-pointers/ir-code.ll @@ -10,70 +10,70 @@ target triple = "x86_64-w64-windows-gnu" @intArray = constant [4 x i32] [i32 1, i32 2, i32 3, i32 4] @4 = private unnamed_addr constant [7 x i8] c"1: %d\0A\00", align 1 -define internal void @_p__void__testProc__intarrayptrptrptr(i32**** %0) { -entry: - %nums = alloca i32****, align 8 - store i32**** %0, i32***** %nums, align 8 - %1 = load i32****, i32***** %nums, align 8 - %2 = load i32***, i32**** %1, align 8 - %3 = load i32**, i32*** %2, align 8 - store i32** %3, i32*** %2, align 8 - %4 = load i32**, i32*** %2, align 8 - %5 = load i32*, i32** %4, align 8 - store i32* %5, i32** %4, align 8 - %6 = load i32*, i32** %4, align 8 - %7 = getelementptr inbounds i32, i32* %6, i32 2 - store i32 10, i32* %7, align 4 - %8 = load i32*, i32** %4, align 8 - %9 = getelementptr inbounds i32, i32* %8, i32 0 - %10 = load i32, i32* %9, align 4 - %11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @0, i32 0, i32 0), i32 %10) - %12 = load i32*, i32** %4, align 8 - %13 = getelementptr inbounds i32, i32* %12, i32 1 - %14 = load i32, i32* %13, align 4 - %15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @1, i32 0, i32 0), i32 %14) - %16 = load i32*, i32** %4, align 8 - %17 = getelementptr inbounds i32, i32* %16, i32 2 - %18 = load i32, i32* %17, align 4 - %19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @2, i32 0, i32 0), i32 %18) - %20 = load i32*, i32** %4, align 8 - %21 = getelementptr inbounds i32, i32* %20, i32 3 - %22 = load i32, i32* %21, align 4 - %23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @3, i32 0, i32 0), i32 %22) +define internal void @_p__void__testProc__intarrayptrptrptr(ptr %0) { +entry.l1: + %nums = alloca ptr, align 8 + store ptr %0, ptr %nums, align 8 + %1 = load ptr, ptr %nums, align 8 + %2 = load ptr, ptr %1, align 8 + %3 = load ptr, ptr %2, align 8 + store ptr %3, ptr %2, align 8 + %4 = load ptr, ptr %2, align 8 + %5 = load ptr, ptr %4, align 8 + store ptr %5, ptr %4, align 8 + %6 = load ptr, ptr %4, align 8 + %7 = getelementptr inbounds i32, ptr %6, i32 2 + store i32 10, ptr %7, align 4 + %8 = load ptr, ptr %4, align 8 + %9 = getelementptr inbounds i32, ptr %8, i32 0 + %10 = load i32, ptr %9, align 4 + %11 = call i32 (ptr, ...) @printf(ptr @0, i32 %10) + %12 = load ptr, ptr %4, align 8 + %13 = getelementptr inbounds i32, ptr %12, i32 1 + %14 = load i32, ptr %13, align 4 + %15 = call i32 (ptr, ...) @printf(ptr @1, i32 %14) + %16 = load ptr, ptr %4, align 8 + %17 = getelementptr inbounds i32, ptr %16, i32 2 + %18 = load i32, ptr %17, align 4 + %19 = call i32 (ptr, ...) @printf(ptr @2, i32 %18) + %20 = load ptr, ptr %4, align 8 + %21 = getelementptr inbounds i32, ptr %20, i32 3 + %22 = load i32, ptr %21, align 4 + %23 = call i32 (ptr, ...) @printf(ptr @3, i32 %22) ret void } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) define i32 @main() { -entry: +entry.l11: %result = alloca i32, align 4 %intArray = alloca [4 x i32], align 4 - %0 = alloca [4 x i32]*, align 8 - %1 = alloca [4 x i32]**, align 8 - %2 = alloca [4 x i32]***, align 8 - %3 = alloca i32*, align 8 - %4 = alloca i32**, align 8 - %5 = alloca i32***, align 8 + %0 = alloca ptr, align 8 + %1 = alloca ptr, align 8 + %2 = alloca ptr, align 8 + %3 = alloca ptr, align 8 + %4 = alloca ptr, align 8 + %5 = alloca ptr, align 8 %6 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - store [4 x i32] [i32 1, i32 2, i32 3, i32 4], [4 x i32]* %intArray, align 4 - %7 = load [4 x i32], [4 x i32]* %intArray, align 4 - %8 = getelementptr inbounds [4 x i32], [4 x i32]* %intArray, i32 0, i32 1 - %9 = load i32, i32* %8, align 4 - %10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @4, i32 0, i32 0), i32 %9) - store [4 x i32]* %intArray, [4 x i32]** %0, align 8 - store [4 x i32]** %0, [4 x i32]*** %1, align 8 - store [4 x i32]*** %1, [4 x i32]**** %2, align 8 - %11 = load [4 x i32]***, [4 x i32]**** %2, align 8 - %12 = load [4 x i32]**, [4 x i32]*** %11, align 8 - %13 = load [4 x i32]*, [4 x i32]** %12, align 8 - %14 = getelementptr inbounds [4 x i32], [4 x i32]* %13, i32 0, i32 0 - store i32* %14, i32** %3, align 8 - store i32** %3, i32*** %4, align 8 - store i32*** %4, i32**** %5, align 8 - call void @_p__void__testProc__intarrayptrptrptr(i32**** %5) - store i1 true, i1* %6, align 1 - %15 = load i32, i32* %result, align 4 + store i32 0, ptr %result, align 4 + store [4 x i32] [i32 1, i32 2, i32 3, i32 4], ptr %intArray, align 4 + %7 = load [4 x i32], ptr %intArray, align 4 + %8 = getelementptr inbounds [4 x i32], ptr %intArray, i32 0, i32 1 + %9 = load i32, ptr %8, align 4 + %10 = call i32 (ptr, ...) @printf(ptr @4, i32 %9) + store ptr %intArray, ptr %0, align 8 + store ptr %0, ptr %1, align 8 + store ptr %1, ptr %2, align 8 + %11 = load ptr, ptr %2, align 8 + %12 = load ptr, ptr %11, align 8 + %13 = load ptr, ptr %12, align 8 + %14 = getelementptr inbounds [4 x i32], ptr %13, i32 0, i32 0 + store ptr %14, ptr %3, align 8 + store ptr %3, ptr %4, align 8 + store ptr %4, ptr %5, align 8 + call void @_p__void__testProc__intarrayptrptrptr(ptr %5) + store i1 true, ptr %6, align 1 + %15 = load i32, ptr %result, align 4 ret i32 %15 } diff --git a/test/test-files/generator/pointers/success-pointer-functions/ir-code.ll b/test/test-files/generator/pointers/success-pointer-functions/ir-code.ll index 5a1351c64..95b7089f4 100644 --- a/test/test-files/generator/pointers/success-pointer-functions/ir-code.ll +++ b/test/test-files/generator/pointers/success-pointer-functions/ir-code.ll @@ -3,7 +3,7 @@ source_filename = "source.spice" target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-w64-windows-gnu" -%_s__Person__string_string_int = type { i8*, i8*, i32 } +%_s__Person__string_string_int = type { ptr, ptr, i32 } @0 = private unnamed_addr constant [5 x i8] c"Mike\00", align 1 @1 = private unnamed_addr constant [7 x i8] c"Miller\00", align 1 @@ -11,55 +11,55 @@ target triple = "x86_64-w64-windows-gnu" @3 = private unnamed_addr constant [25 x i8] c"Age before birthday: %d\0A\00", align 1 @4 = private unnamed_addr constant [24 x i8] c"Age after birthday: %d\0A\00", align 1 -define internal void @_p__void__birthday__Personptr(%_s__Person__string_string_int* %0) { -entry: - %person = alloca %_s__Person__string_string_int*, align 8 +define internal void @_p__void__birthday__Personptr(ptr %0) { +entry.l7: + %person = alloca ptr, align 8 %1 = alloca i32, align 4 - store %_s__Person__string_string_int* %0, %_s__Person__string_string_int** %person, align 8 - %2 = load %_s__Person__string_string_int*, %_s__Person__string_string_int** %person, align 8 - %3 = load %_s__Person__string_string_int*, %_s__Person__string_string_int** %person, align 8 - %4 = getelementptr inbounds %_s__Person__string_string_int, %_s__Person__string_string_int* %3, i32 0, i32 2 - %5 = load i32, i32* %4, align 4 + store ptr %0, ptr %person, align 8 + %2 = load ptr, ptr %person, align 8 + %3 = load ptr, ptr %person, align 8 + %4 = getelementptr inbounds %_s__Person__string_string_int, ptr %3, i32 0, i32 2 + %5 = load i32, ptr %4, align 4 %6 = add i32 %5, 1 - store i32 %6, i32* %4, align 4 - store i32 %5, i32* %1, align 4 + store i32 %6, ptr %4, align 4 + store i32 %5, ptr %1, align 4 ret void } define i32 @main() { -entry: +entry.l11: %result = alloca i32, align 4 %0 = alloca %_s__Person__string_string_int, align 8 - %1 = alloca %_s__Person__string_string_int*, align 8 + %1 = alloca ptr, align 8 %2 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - %3 = getelementptr inbounds %_s__Person__string_string_int, %_s__Person__string_string_int* %0, i32 0, i32 0 - store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @0, i32 0, i32 0), i8** %3, align 8 - %4 = getelementptr inbounds %_s__Person__string_string_int, %_s__Person__string_string_int* %0, i32 0, i32 1 - store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @1, i32 0, i32 0), i8** %4, align 8 - %5 = getelementptr inbounds %_s__Person__string_string_int, %_s__Person__string_string_int* %0, i32 0, i32 2 - store i32 32, i32* %5, align 4 - %6 = load %_s__Person__string_string_int, %_s__Person__string_string_int* %0, align 8 - %7 = getelementptr inbounds %_s__Person__string_string_int, %_s__Person__string_string_int* %0, i32 0, i32 1 - %8 = load i8*, i8** %7, align 8 - %9 = load %_s__Person__string_string_int, %_s__Person__string_string_int* %0, align 8 - %10 = getelementptr inbounds %_s__Person__string_string_int, %_s__Person__string_string_int* %0, i32 0, i32 0 - %11 = load i8*, i8** %10, align 8 - %12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @2, i32 0, i32 0), i8* %8, i8* %11) - %13 = load %_s__Person__string_string_int, %_s__Person__string_string_int* %0, align 8 - %14 = getelementptr inbounds %_s__Person__string_string_int, %_s__Person__string_string_int* %0, i32 0, i32 2 - %15 = load i32, i32* %14, align 4 - %16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @3, i32 0, i32 0), i32 %15) - store %_s__Person__string_string_int* %0, %_s__Person__string_string_int** %1, align 8 - %17 = load %_s__Person__string_string_int*, %_s__Person__string_string_int** %1, align 8 - call void @_p__void__birthday__Personptr(%_s__Person__string_string_int* %17) - store i1 true, i1* %2, align 1 - %18 = load %_s__Person__string_string_int, %_s__Person__string_string_int* %0, align 8 - %19 = getelementptr inbounds %_s__Person__string_string_int, %_s__Person__string_string_int* %0, i32 0, i32 2 - %20 = load i32, i32* %19, align 4 - %21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @4, i32 0, i32 0), i32 %20) - %22 = load i32, i32* %result, align 4 + store i32 0, ptr %result, align 4 + %3 = getelementptr inbounds %_s__Person__string_string_int, ptr %0, i32 0, i32 0 + store ptr @0, ptr %3, align 8 + %4 = getelementptr inbounds %_s__Person__string_string_int, ptr %0, i32 0, i32 1 + store ptr @1, ptr %4, align 8 + %5 = getelementptr inbounds %_s__Person__string_string_int, ptr %0, i32 0, i32 2 + store i32 32, ptr %5, align 4 + %6 = load %_s__Person__string_string_int, ptr %0, align 8 + %7 = getelementptr inbounds %_s__Person__string_string_int, ptr %0, i32 0, i32 1 + %8 = load ptr, ptr %7, align 8 + %9 = load %_s__Person__string_string_int, ptr %0, align 8 + %10 = getelementptr inbounds %_s__Person__string_string_int, ptr %0, i32 0, i32 0 + %11 = load ptr, ptr %10, align 8 + %12 = call i32 (ptr, ...) @printf(ptr @2, ptr %8, ptr %11) + %13 = load %_s__Person__string_string_int, ptr %0, align 8 + %14 = getelementptr inbounds %_s__Person__string_string_int, ptr %0, i32 0, i32 2 + %15 = load i32, ptr %14, align 4 + %16 = call i32 (ptr, ...) @printf(ptr @3, i32 %15) + store ptr %0, ptr %1, align 8 + %17 = load ptr, ptr %1, align 8 + call void @_p__void__birthday__Personptr(ptr %17) + store i1 true, ptr %2, align 1 + %18 = load %_s__Person__string_string_int, ptr %0, align 8 + %19 = getelementptr inbounds %_s__Person__string_string_int, ptr %0, i32 0, i32 2 + %20 = load i32, ptr %19, align 4 + %21 = call i32 (ptr, ...) @printf(ptr @4, i32 %20) + %22 = load i32, ptr %result, align 4 ret i32 %22 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/pointers/success-pointer/ir-code.ll b/test/test-files/generator/pointers/success-pointer/ir-code.ll index a67542c7d..81196c21d 100644 --- a/test/test-files/generator/pointers/success-pointer/ir-code.ll +++ b/test/test-files/generator/pointers/success-pointer/ir-code.ll @@ -10,34 +10,34 @@ target triple = "x86_64-w64-windows-gnu" @4 = private unnamed_addr constant [28 x i8] c"Restored value address: %p\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 - %food = alloca i8*, align 8 - %0 = alloca i8**, align 8 - %1 = alloca i8**, align 8 - store i32 0, i32* %result, align 4 - store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @0, i32 0, i32 0), i8** %food, align 8 - store i8** %food, i8*** %0, align 8 - %2 = load i8**, i8*** %0, align 8 - %3 = load i8**, i8*** %0, align 8 - %4 = load i8*, i8** %3, align 8 - store i8* %4, i8** %3, align 8 - %5 = load i8*, i8** %3, align 8 - %6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @1, i32 0, i32 0), i8** %2, i8* %5) - %7 = load i8**, i8*** %0, align 8 - %8 = load i8*, i8** %7, align 8 - store i8* %8, i8** %7, align 8 - store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @2, i32 0, i32 0), i8** %7, align 8 - %9 = load i8**, i8*** %0, align 8 - %10 = load i8*, i8** %9, align 8 - store i8* %10, i8** %9, align 8 - %11 = load i8*, i8** %9, align 8 - %12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @3, i32 0, i32 0), i8* %11) - store i8** %9, i8*** %1, align 8 - %13 = load i8**, i8*** %1, align 8 - %14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @4, i32 0, i32 0), i8** %13) - %15 = load i32, i32* %result, align 4 + %food = alloca ptr, align 8 + %0 = alloca ptr, align 8 + %1 = alloca ptr, align 8 + store i32 0, ptr %result, align 4 + store ptr @0, ptr %food, align 8 + store ptr %food, ptr %0, align 8 + %2 = load ptr, ptr %0, align 8 + %3 = load ptr, ptr %0, align 8 + %4 = load ptr, ptr %3, align 8 + store ptr %4, ptr %3, align 8 + %5 = load ptr, ptr %3, align 8 + %6 = call i32 (ptr, ...) @printf(ptr @1, ptr %2, ptr %5) + %7 = load ptr, ptr %0, align 8 + %8 = load ptr, ptr %7, align 8 + store ptr %8, ptr %7, align 8 + store ptr @2, ptr %7, align 8 + %9 = load ptr, ptr %0, align 8 + %10 = load ptr, ptr %9, align 8 + store ptr %10, ptr %9, align 8 + %11 = load ptr, ptr %9, align 8 + %12 = call i32 (ptr, ...) @printf(ptr @3, ptr %11) + store ptr %9, ptr %1, align 8 + %13 = load ptr, ptr %1, align 8 + %14 = call i32 (ptr, ...) @printf(ptr @4, ptr %13) + %15 = load i32, ptr %result, align 4 ret i32 %15 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/procedures/success-early-return/ir-code.ll b/test/test-files/generator/procedures/success-early-return/ir-code.ll index a7827f61a..58fdcaf42 100644 --- a/test/test-files/generator/procedures/success-early-return/ir-code.ll +++ b/test/test-files/generator/procedures/success-early-return/ir-code.ll @@ -6,32 +6,32 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [16 x i8] c"Input was false\00", align 1 define internal void @_p__void__executeAction__bool(i1 %0) { -entry: +entry.l1: %input = alloca i1, align 1 - store i1 %0, i1* %input, align 1 - %1 = load i1, i1* %input, align 1 - br i1 %1, label %if.then, label %if.end + store i1 %0, ptr %input, align 1 + %1 = load i1, ptr %input, align 1 + br i1 %1, label %if.then.l2, label %if.end.l2 -if.then: ; preds = %entry +if.then.l2: ; preds = %entry.l1 ret void -if.end: ; preds = %entry - %2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @0, i32 0, i32 0)) +if.end.l2: ; preds = %entry.l1 + %2 = call i32 (ptr, ...) @printf(ptr @0) ret void } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) define i32 @main() { -entry: +entry.l6: %result = alloca i32, align 4 %0 = alloca i1, align 1 %1 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - store i1 false, i1* %0, align 1 - %2 = load i1, i1* %0, align 1 + store i32 0, ptr %result, align 4 + store i1 false, ptr %0, align 1 + %2 = load i1, ptr %0, align 1 call void @_p__void__executeAction__bool(i1 %2) - store i1 true, i1* %1, align 1 - %3 = load i32, i32* %result, align 4 + store i1 true, ptr %1, align 1 + %3 = load i32, ptr %result, align 4 ret i32 %3 } diff --git a/test/test-files/generator/procedures/success-explicit-inlining/ir-code-O2.ll b/test/test-files/generator/procedures/success-explicit-inlining/ir-code-O2.ll index 49c623703..2fdd2f1f3 100644 --- a/test/test-files/generator/procedures/success-explicit-inlining/ir-code-O2.ll +++ b/test/test-files/generator/procedures/success-explicit-inlining/ir-code-O2.ll @@ -8,19 +8,18 @@ target triple = "x86_64-w64-windows-gnu" @str.1 = private unnamed_addr constant [12 x i8] c"After value\00", align 1 ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #0 { -entry: - %puts = tail call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0)) - %0 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @0, i64 0, i64 0), i32 5) #1 - %puts1 = tail call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.1, i64 0, i64 0)) +entry.l5: + %puts = tail call i32 @puts(ptr nonnull @str) + %0 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 5) + %puts1 = tail call i32 @puts(ptr nonnull @str.1) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @puts(i8* nocapture noundef readonly) local_unnamed_addr #0 +declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #0 attributes #0 = { nofree nounwind } -attributes #1 = { nounwind } diff --git a/test/test-files/generator/procedures/success-explicit-inlining/ir-code.ll b/test/test-files/generator/procedures/success-explicit-inlining/ir-code.ll index f4abc67af..976954842 100644 --- a/test/test-files/generator/procedures/success-explicit-inlining/ir-code.ll +++ b/test/test-files/generator/procedures/success-explicit-inlining/ir-code.ll @@ -9,26 +9,26 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: alwaysinline define internal void @_p__void__printAValue() #0 { -entry: +entry.l1: %0 = alloca i32, align 4 - store i32 5, i32* %0, align 4 - %1 = load i32, i32* %0, align 4 - %2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @0, i32 0, i32 0), i32 %1) + store i32 5, ptr %0, align 4 + %1 = load i32, ptr %0, align 4 + %2 = call i32 (ptr, ...) @printf(ptr @0, i32 %1) ret void } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) define i32 @main() { -entry: +entry.l5: %result = alloca i32, align 4 %0 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - %1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @1, i32 0, i32 0)) + store i32 0, ptr %result, align 4 + %1 = call i32 (ptr, ...) @printf(ptr @1) call void @_p__void__printAValue() - store i1 true, i1* %0, align 1 - %2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @2, i32 0, i32 0)) - %3 = load i32, i32* %result, align 4 + store i1 true, ptr %0, align 1 + %2 = call i32 (ptr, ...) @printf(ptr @2) + %3 = load i32, ptr %result, align 4 ret i32 %3 } diff --git a/test/test-files/generator/structs/success-constructors/ir-code.ll b/test/test-files/generator/structs/success-constructors/ir-code.ll index a439e4161..0b61e8dc4 100644 --- a/test/test-files/generator/structs/success-constructors/ir-code.ll +++ b/test/test-files/generator/structs/success-constructors/ir-code.ll @@ -3,42 +3,42 @@ source_filename = "source.spice" target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-w64-windows-gnu" -%_s__Vector__bool_string = type { i1, i8* } +%_s__Vector__bool_string = type { i1, ptr } @0 = private unnamed_addr constant [12 x i8] c"Test string\00", align 1 @1 = private unnamed_addr constant [15 x i8] c"Fields: %d, %s\00", align 1 -define internal void @_mp__Vector__ctor(%_s__Vector__bool_string* %0) { -entry: - %this = alloca %_s__Vector__bool_string*, align 8 - store %_s__Vector__bool_string* %0, %_s__Vector__bool_string** %this, align 8 - %1 = load %_s__Vector__bool_string*, %_s__Vector__bool_string** %this, align 8 - %2 = load %_s__Vector__bool_string*, %_s__Vector__bool_string** %this, align 8 - %3 = getelementptr inbounds %_s__Vector__bool_string, %_s__Vector__bool_string* %2, i32 0, i32 0 - store i1 false, i1* %3, align 1 - %4 = load %_s__Vector__bool_string*, %_s__Vector__bool_string** %this, align 8 - %5 = load %_s__Vector__bool_string*, %_s__Vector__bool_string** %this, align 8 - %6 = getelementptr inbounds %_s__Vector__bool_string, %_s__Vector__bool_string* %5, i32 0, i32 1 - store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @0, i32 0, i32 0), i8** %6, align 8 +define internal void @_mp__Vector__ctor(ptr %0) { +entry.l6: + %this = alloca ptr, align 8 + store ptr %0, ptr %this, align 8 + %1 = load ptr, ptr %this, align 8 + %2 = load ptr, ptr %this, align 8 + %3 = getelementptr inbounds %_s__Vector__bool_string, ptr %2, i32 0, i32 0 + store i1 false, ptr %3, align 1 + %4 = load ptr, ptr %this, align 8 + %5 = load ptr, ptr %this, align 8 + %6 = getelementptr inbounds %_s__Vector__bool_string, ptr %5, i32 0, i32 1 + store ptr @0, ptr %6, align 8 ret void } define i32 @main() { -entry: +entry.l11: %result = alloca i32, align 4 %vec = alloca %_s__Vector__bool_string, align 8 - store i32 0, i32* %result, align 4 - call void @_mp__Vector__ctor(%_s__Vector__bool_string* %vec) - %0 = load %_s__Vector__bool_string, %_s__Vector__bool_string* %vec, align 8 - %1 = getelementptr inbounds %_s__Vector__bool_string, %_s__Vector__bool_string* %vec, i32 0, i32 0 - %2 = load i1, i1* %1, align 1 + store i32 0, ptr %result, align 4 + call void @_mp__Vector__ctor(ptr %vec) + %0 = load %_s__Vector__bool_string, ptr %vec, align 8 + %1 = getelementptr inbounds %_s__Vector__bool_string, ptr %vec, i32 0, i32 0 + %2 = load i1, ptr %1, align 1 %3 = zext i1 %2 to i32 - %4 = load %_s__Vector__bool_string, %_s__Vector__bool_string* %vec, align 8 - %5 = getelementptr inbounds %_s__Vector__bool_string, %_s__Vector__bool_string* %vec, i32 0, i32 1 - %6 = load i8*, i8** %5, align 8 - %7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @1, i32 0, i32 0), i32 %3, i8* %6) - %8 = load i32, i32* %result, align 4 + %4 = load %_s__Vector__bool_string, ptr %vec, align 8 + %5 = getelementptr inbounds %_s__Vector__bool_string, ptr %vec, i32 0, i32 1 + %6 = load ptr, ptr %5, align 8 + %7 = call i32 (ptr, ...) @printf(ptr @1, i32 %3, ptr %6) + %8 = load i32, ptr %result, align 4 ret i32 %8 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/structs/success-external-nested-struct/ir-code.ll b/test/test-files/generator/structs/success-external-nested-struct/ir-code.ll index 2717216a8..088f43855 100644 --- a/test/test-files/generator/structs/success-external-nested-struct/ir-code.ll +++ b/test/test-files/generator/structs/success-external-nested-struct/ir-code.ll @@ -4,35 +4,35 @@ target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16 target triple = "x86_64-w64-windows-gnu" %_s__Socket__int_short_NestedSocket = type { i32, i16, %_s__NestedSocket__string_long } -%_s__NestedSocket__string_long = type { i8*, i64 } +%_s__NestedSocket__string_long = type { ptr, i64 } @0 = private unnamed_addr constant [17 x i8] c"Test string: %s\0A\00", align 1 @1 = private unnamed_addr constant [12 x i8] c"Socket: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l3: %result = alloca i32, align 4 %s = alloca i16, align 2 %0 = alloca %_s__Socket__int_short_NestedSocket, align 8 - store i32 0, i32* %result, align 4 - store i16 8080, i16* %s, align 2 - %1 = load i16, i16* %s, align 2 + store i32 0, ptr %result, align 4 + store i16 8080, ptr %s, align 2 + %1 = load i16, ptr %s, align 2 %2 = call %_s__Socket__int_short_NestedSocket @_f__void__openServerSocket__short(i16 %1) - store %_s__Socket__int_short_NestedSocket %2, %_s__Socket__int_short_NestedSocket* %0, align 8 - %3 = load %_s__Socket__int_short_NestedSocket, %_s__Socket__int_short_NestedSocket* %0, align 8 - %4 = getelementptr inbounds %_s__Socket__int_short_NestedSocket, %_s__Socket__int_short_NestedSocket* %0, i32 0, i32 2 - %5 = load %_s__NestedSocket__string_long, %_s__NestedSocket__string_long* %4, align 8 - %6 = getelementptr inbounds %_s__NestedSocket__string_long, %_s__NestedSocket__string_long* %4, i32 0, i32 0 - %7 = load i8*, i8** %6, align 8 - %8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @0, i32 0, i32 0), i8* %7) - %9 = load %_s__Socket__int_short_NestedSocket, %_s__Socket__int_short_NestedSocket* %0, align 8 - %10 = getelementptr inbounds %_s__Socket__int_short_NestedSocket, %_s__Socket__int_short_NestedSocket* %0, i32 0, i32 0 - %11 = load i32, i32* %10, align 4 - %12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @1, i32 0, i32 0), i32 %11) - %13 = load i32, i32* %result, align 4 + store %_s__Socket__int_short_NestedSocket %2, ptr %0, align 8 + %3 = load %_s__Socket__int_short_NestedSocket, ptr %0, align 8 + %4 = getelementptr inbounds %_s__Socket__int_short_NestedSocket, ptr %0, i32 0, i32 2 + %5 = load %_s__NestedSocket__string_long, ptr %4, align 8 + %6 = getelementptr inbounds %_s__NestedSocket__string_long, ptr %4, i32 0, i32 0 + %7 = load ptr, ptr %6, align 8 + %8 = call i32 (ptr, ...) @printf(ptr @0, ptr %7) + %9 = load %_s__Socket__int_short_NestedSocket, ptr %0, align 8 + %10 = getelementptr inbounds %_s__Socket__int_short_NestedSocket, ptr %0, i32 0, i32 0 + %11 = load i32, ptr %10, align 4 + %12 = call i32 (ptr, ...) @printf(ptr @1, i32 %11) + %13 = load i32, ptr %result, align 4 ret i32 %13 } declare %_s__Socket__int_short_NestedSocket @_f__void__openServerSocket__short(i16) -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/structs/success-external-structs/ir-code.ll b/test/test-files/generator/structs/success-external-structs/ir-code.ll index 7885bd430..064ae5015 100644 --- a/test/test-files/generator/structs/success-external-structs/ir-code.ll +++ b/test/test-files/generator/structs/success-external-structs/ir-code.ll @@ -6,19 +6,19 @@ target triple = "x86_64-w64-windows-gnu" %_s__Vec__int_bool = type { i32, i1 } define i32 @main() { -entry: +entry.l3: %result = alloca i32, align 4 %0 = alloca %_s__Vec__int_bool, align 8 %1 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - %2 = getelementptr inbounds %_s__Vec__int_bool, %_s__Vec__int_bool* %0, i32 0, i32 0 - store i32 11, i32* %2, align 4 - %3 = getelementptr inbounds %_s__Vec__int_bool, %_s__Vec__int_bool* %0, i32 0, i32 1 - store i1 false, i1* %3, align 1 - call void @_mp__Vec__print(%_s__Vec__int_bool* %0) - store i1 true, i1* %1, align 1 - %4 = load i32, i32* %result, align 4 + store i32 0, ptr %result, align 4 + %2 = getelementptr inbounds %_s__Vec__int_bool, ptr %0, i32 0, i32 0 + store i32 11, ptr %2, align 4 + %3 = getelementptr inbounds %_s__Vec__int_bool, ptr %0, i32 0, i32 1 + store i1 false, ptr %3, align 1 + call void @_mp__Vec__print(ptr %0) + store i1 true, ptr %1, align 1 + %4 = load i32, ptr %result, align 4 ret i32 %4 } -declare void @_mp__Vec__print(%_s__Vec__int_bool*) +declare void @_mp__Vec__print(ptr) diff --git a/test/test-files/generator/structs/success-struct-field-access/ir-code.ll b/test/test-files/generator/structs/success-struct-field-access/ir-code.ll index a21e87fd4..d826dfbb6 100644 --- a/test/test-files/generator/structs/success-struct-field-access/ir-code.ll +++ b/test/test-files/generator/structs/success-struct-field-access/ir-code.ll @@ -3,32 +3,32 @@ source_filename = "source.spice" target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-w64-windows-gnu" -%_s__Person__string_string_int = type { i8*, i8*, i32 } +%_s__Person__string_string_int = type { ptr, ptr, i32 } @0 = private unnamed_addr constant [5 x i8] c"John\00", align 1 @1 = private unnamed_addr constant [4 x i8] c"Doe\00", align 1 @2 = private unnamed_addr constant [15 x i8] c"John's age: %d\00", align 1 define i32 @main() { -entry: +entry.l7: %result = alloca i32, align 4 %0 = alloca %_s__Person__string_string_int, align 8 - store i32 0, i32* %result, align 4 - %1 = getelementptr inbounds %_s__Person__string_string_int, %_s__Person__string_string_int* %0, i32 0, i32 0 - store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @0, i32 0, i32 0), i8** %1, align 8 - %2 = getelementptr inbounds %_s__Person__string_string_int, %_s__Person__string_string_int* %0, i32 0, i32 1 - store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @1, i32 0, i32 0), i8** %2, align 8 - %3 = getelementptr inbounds %_s__Person__string_string_int, %_s__Person__string_string_int* %0, i32 0, i32 2 - store i32 46, i32* %3, align 4 - %4 = load %_s__Person__string_string_int, %_s__Person__string_string_int* %0, align 8 - %5 = getelementptr inbounds %_s__Person__string_string_int, %_s__Person__string_string_int* %0, i32 0, i32 2 - store i32 47, i32* %5, align 4 - %6 = load %_s__Person__string_string_int, %_s__Person__string_string_int* %0, align 8 - %7 = getelementptr inbounds %_s__Person__string_string_int, %_s__Person__string_string_int* %0, i32 0, i32 2 - %8 = load i32, i32* %7, align 4 - %9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @2, i32 0, i32 0), i32 %8) - %10 = load i32, i32* %result, align 4 + store i32 0, ptr %result, align 4 + %1 = getelementptr inbounds %_s__Person__string_string_int, ptr %0, i32 0, i32 0 + store ptr @0, ptr %1, align 8 + %2 = getelementptr inbounds %_s__Person__string_string_int, ptr %0, i32 0, i32 1 + store ptr @1, ptr %2, align 8 + %3 = getelementptr inbounds %_s__Person__string_string_int, ptr %0, i32 0, i32 2 + store i32 46, ptr %3, align 4 + %4 = load %_s__Person__string_string_int, ptr %0, align 8 + %5 = getelementptr inbounds %_s__Person__string_string_int, ptr %0, i32 0, i32 2 + store i32 47, ptr %5, align 4 + %6 = load %_s__Person__string_string_int, ptr %0, align 8 + %7 = getelementptr inbounds %_s__Person__string_string_int, ptr %0, i32 0, i32 2 + %8 = load i32, ptr %7, align 4 + %9 = call i32 (ptr, ...) @printf(ptr @2, i32 %8) + %10 = load i32, ptr %result, align 4 ret i32 %10 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/structs/success-struct-self-ref/ir-code.ll b/test/test-files/generator/structs/success-struct-self-ref/ir-code.ll index c145bb503..ab1ee4ff5 100644 --- a/test/test-files/generator/structs/success-struct-self-ref/ir-code.ll +++ b/test/test-files/generator/structs/success-struct-self-ref/ir-code.ll @@ -3,80 +3,80 @@ source_filename = "source.spice" target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-w64-windows-gnu" -%_s__TreeNode__TreeNodeptr_int = type { %_s__TreeNode__TreeNodeptr_int*, i32 } +%_s__TreeNode__TreeNodeptr_int = type { ptr, i32 } @0 = private unnamed_addr constant [21 x i8] c"Root node number: %d\00", align 1 define i32 @main() { -entry: +entry.l13: %result = alloca i32, align 4 %0 = alloca %_s__TreeNode__TreeNodeptr_int, align 8 - %rootNode = alloca %_s__TreeNode__TreeNodeptr_int*, align 8 + %rootNode = alloca ptr, align 8 %1 = alloca %_s__TreeNode__TreeNodeptr_int, align 8 - %2 = alloca %_s__TreeNode__TreeNodeptr_int*, align 8 + %2 = alloca ptr, align 8 %3 = alloca %_s__TreeNode__TreeNodeptr_int, align 8 - %4 = alloca %_s__TreeNode__TreeNodeptr_int*, align 8 + %4 = alloca ptr, align 8 %5 = alloca %_s__TreeNode__TreeNodeptr_int, align 8 - %6 = alloca %_s__TreeNode__TreeNodeptr_int*, align 8 - %7 = alloca %_s__TreeNode__TreeNodeptr_int*, align 8 - %8 = alloca %_s__TreeNode__TreeNodeptr_int*, align 8 + %6 = alloca ptr, align 8 + %7 = alloca ptr, align 8 + %8 = alloca ptr, align 8 %9 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - store %_s__TreeNode__TreeNodeptr_int* null, %_s__TreeNode__TreeNodeptr_int** %rootNode, align 8 - %10 = load %_s__TreeNode__TreeNodeptr_int*, %_s__TreeNode__TreeNodeptr_int** %rootNode, align 8 - %11 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, %_s__TreeNode__TreeNodeptr_int* %0, i32 0, i32 0 - store %_s__TreeNode__TreeNodeptr_int* %10, %_s__TreeNode__TreeNodeptr_int** %11, align 8 - %12 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, %_s__TreeNode__TreeNodeptr_int* %0, i32 0, i32 1 - store i32 0, i32* %12, align 4 - store %_s__TreeNode__TreeNodeptr_int* %0, %_s__TreeNode__TreeNodeptr_int** %2, align 8 - %13 = load %_s__TreeNode__TreeNodeptr_int*, %_s__TreeNode__TreeNodeptr_int** %2, align 8 - %14 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, %_s__TreeNode__TreeNodeptr_int* %1, i32 0, i32 0 - store %_s__TreeNode__TreeNodeptr_int* %13, %_s__TreeNode__TreeNodeptr_int** %14, align 8 - %15 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, %_s__TreeNode__TreeNodeptr_int* %1, i32 0, i32 1 - store i32 1, i32* %15, align 4 - store %_s__TreeNode__TreeNodeptr_int* %0, %_s__TreeNode__TreeNodeptr_int** %4, align 8 - %16 = load %_s__TreeNode__TreeNodeptr_int*, %_s__TreeNode__TreeNodeptr_int** %4, align 8 - %17 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, %_s__TreeNode__TreeNodeptr_int* %3, i32 0, i32 0 - store %_s__TreeNode__TreeNodeptr_int* %16, %_s__TreeNode__TreeNodeptr_int** %17, align 8 - %18 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, %_s__TreeNode__TreeNodeptr_int* %3, i32 0, i32 1 - store i32 2, i32* %18, align 4 - store %_s__TreeNode__TreeNodeptr_int* %3, %_s__TreeNode__TreeNodeptr_int** %6, align 8 - %19 = load %_s__TreeNode__TreeNodeptr_int*, %_s__TreeNode__TreeNodeptr_int** %6, align 8 - %20 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, %_s__TreeNode__TreeNodeptr_int* %5, i32 0, i32 0 - store %_s__TreeNode__TreeNodeptr_int* %19, %_s__TreeNode__TreeNodeptr_int** %20, align 8 - %21 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, %_s__TreeNode__TreeNodeptr_int* %5, i32 0, i32 1 - store i32 3, i32* %21, align 4 - store %_s__TreeNode__TreeNodeptr_int* %5, %_s__TreeNode__TreeNodeptr_int** %7, align 8 - br label %while.cond + store i32 0, ptr %result, align 4 + store ptr null, ptr %rootNode, align 8 + %10 = load ptr, ptr %rootNode, align 8 + %11 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %0, i32 0, i32 0 + store ptr %10, ptr %11, align 8 + %12 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %0, i32 0, i32 1 + store i32 0, ptr %12, align 4 + store ptr %0, ptr %2, align 8 + %13 = load ptr, ptr %2, align 8 + %14 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %1, i32 0, i32 0 + store ptr %13, ptr %14, align 8 + %15 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %1, i32 0, i32 1 + store i32 1, ptr %15, align 4 + store ptr %0, ptr %4, align 8 + %16 = load ptr, ptr %4, align 8 + %17 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %3, i32 0, i32 0 + store ptr %16, ptr %17, align 8 + %18 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %3, i32 0, i32 1 + store i32 2, ptr %18, align 4 + store ptr %3, ptr %6, align 8 + %19 = load ptr, ptr %6, align 8 + %20 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %5, i32 0, i32 0 + store ptr %19, ptr %20, align 8 + %21 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %5, i32 0, i32 1 + store i32 3, ptr %21, align 4 + store ptr %5, ptr %7, align 8 + br label %while.cond.l21 -while.cond: ; preds = %while, %entry - %22 = load %_s__TreeNode__TreeNodeptr_int*, %_s__TreeNode__TreeNodeptr_int** %7, align 8 - %23 = load %_s__TreeNode__TreeNodeptr_int*, %_s__TreeNode__TreeNodeptr_int** %7, align 8 - %24 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, %_s__TreeNode__TreeNodeptr_int* %23, i32 0, i32 0 - %25 = load %_s__TreeNode__TreeNodeptr_int*, %_s__TreeNode__TreeNodeptr_int** %24, align 8 - store %_s__TreeNode__TreeNodeptr_int* null, %_s__TreeNode__TreeNodeptr_int** %8, align 8 - %26 = load %_s__TreeNode__TreeNodeptr_int*, %_s__TreeNode__TreeNodeptr_int** %8, align 8 - %27 = icmp ne %_s__TreeNode__TreeNodeptr_int* %25, %26 - store i1 %27, i1* %9, align 1 - %28 = load i1, i1* %9, align 1 - br i1 %28, label %while, label %while.end +while.cond.l21: ; preds = %while.l21, %entry.l13 + %22 = load ptr, ptr %7, align 8 + %23 = load ptr, ptr %7, align 8 + %24 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %23, i32 0, i32 0 + %25 = load ptr, ptr %24, align 8 + store ptr null, ptr %8, align 8 + %26 = load ptr, ptr %8, align 8 + %27 = icmp ne ptr %25, %26 + store i1 %27, ptr %9, align 1 + %28 = load i1, ptr %9, align 1 + br i1 %28, label %while.l21, label %while.end.l21 -while: ; preds = %while.cond - %29 = load %_s__TreeNode__TreeNodeptr_int*, %_s__TreeNode__TreeNodeptr_int** %7, align 8 - %30 = load %_s__TreeNode__TreeNodeptr_int*, %_s__TreeNode__TreeNodeptr_int** %7, align 8 - %31 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, %_s__TreeNode__TreeNodeptr_int* %30, i32 0, i32 0 - %32 = load %_s__TreeNode__TreeNodeptr_int*, %_s__TreeNode__TreeNodeptr_int** %31, align 8 - store %_s__TreeNode__TreeNodeptr_int* %32, %_s__TreeNode__TreeNodeptr_int** %7, align 8 - br label %while.cond +while.l21: ; preds = %while.cond.l21 + %29 = load ptr, ptr %7, align 8 + %30 = load ptr, ptr %7, align 8 + %31 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %30, i32 0, i32 0 + %32 = load ptr, ptr %31, align 8 + store ptr %32, ptr %7, align 8 + br label %while.cond.l21 -while.end: ; preds = %while.cond - %33 = load %_s__TreeNode__TreeNodeptr_int*, %_s__TreeNode__TreeNodeptr_int** %7, align 8 - %34 = load %_s__TreeNode__TreeNodeptr_int*, %_s__TreeNode__TreeNodeptr_int** %7, align 8 - %35 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, %_s__TreeNode__TreeNodeptr_int* %34, i32 0, i32 1 - %36 = load i32, i32* %35, align 4 - %37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @0, i32 0, i32 0), i32 %36) - %38 = load i32, i32* %result, align 4 +while.end.l21: ; preds = %while.cond.l21 + %33 = load ptr, ptr %7, align 8 + %34 = load ptr, ptr %7, align 8 + %35 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %34, i32 0, i32 1 + %36 = load i32, ptr %35, align 4 + %37 = call i32 (ptr, ...) @printf(ptr @0, i32 %36) + %38 = load i32, ptr %result, align 4 ret i32 %38 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/structs/success-struct/ir-code.ll b/test/test-files/generator/structs/success-struct/ir-code.ll index 4e015fdcf..34d12f059 100644 --- a/test/test-files/generator/structs/success-struct/ir-code.ll +++ b/test/test-files/generator/structs/success-struct/ir-code.ll @@ -3,65 +3,65 @@ source_filename = "source.spice" target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-w64-windows-gnu" -%_s__Nested__string_boolptr = type { i8*, i1* } -%_s__TestStruct__intptr_double_Nestedptr = type { i32*, double, %_s__Nested__string_boolptr* } +%_s__Nested__string_boolptr = type { ptr, ptr } +%_s__TestStruct__intptr_double_Nestedptr = type { ptr, double, ptr } @0 = private unnamed_addr constant [13 x i8] c"Hello World!\00", align 1 @1 = private unnamed_addr constant [24 x i8] c"Field1: %d, field2: %f\0A\00", align 1 @2 = private unnamed_addr constant [12 x i8] c"Output: %s\0A\00", align 1 define i32 @main() { -entry: +entry.l12: %result = alloca i32, align 4 %input = alloca i32, align 4 %boolean = alloca i1, align 1 %0 = alloca %_s__Nested__string_boolptr, align 8 - %1 = alloca i1*, align 8 + %1 = alloca ptr, align 8 %2 = alloca %_s__TestStruct__intptr_double_Nestedptr, align 8 - %3 = alloca i32*, align 8 - %4 = alloca %_s__Nested__string_boolptr*, align 8 - store i32 0, i32* %result, align 4 - store i32 12, i32* %input, align 4 - store i1 true, i1* %boolean, align 1 - %5 = getelementptr inbounds %_s__Nested__string_boolptr, %_s__Nested__string_boolptr* %0, i32 0, i32 0 - store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @0, i32 0, i32 0), i8** %5, align 8 - store i1* %boolean, i1** %1, align 8 - %6 = load i1*, i1** %1, align 8 - %7 = getelementptr inbounds %_s__Nested__string_boolptr, %_s__Nested__string_boolptr* %0, i32 0, i32 1 - store i1* %6, i1** %7, align 8 - store i32* %input, i32** %3, align 8 - %8 = load i32*, i32** %3, align 8 - %9 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, %_s__TestStruct__intptr_double_Nestedptr* %2, i32 0, i32 0 - store i32* %8, i32** %9, align 8 - %10 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, %_s__TestStruct__intptr_double_Nestedptr* %2, i32 0, i32 1 - store double 4.634000e+01, double* %10, align 8 - store %_s__Nested__string_boolptr* %0, %_s__Nested__string_boolptr** %4, align 8 - %11 = load %_s__Nested__string_boolptr*, %_s__Nested__string_boolptr** %4, align 8 - %12 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, %_s__TestStruct__intptr_double_Nestedptr* %2, i32 0, i32 2 - store %_s__Nested__string_boolptr* %11, %_s__Nested__string_boolptr** %12, align 8 - %13 = load %_s__TestStruct__intptr_double_Nestedptr, %_s__TestStruct__intptr_double_Nestedptr* %2, align 8 - %14 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, %_s__TestStruct__intptr_double_Nestedptr* %2, i32 0, i32 2 - %15 = load %_s__Nested__string_boolptr*, %_s__Nested__string_boolptr** %14, align 8 - %16 = load %_s__Nested__string_boolptr*, %_s__Nested__string_boolptr** %14, align 8 - %17 = getelementptr inbounds %_s__Nested__string_boolptr, %_s__Nested__string_boolptr* %16, i32 0, i32 1 - %18 = load i1*, i1** %17, align 8 - %19 = load i1, i1* %18, align 1 - store i1 %19, i1* %18, align 1 - %20 = load i1, i1* %18, align 1 + %3 = alloca ptr, align 8 + %4 = alloca ptr, align 8 + store i32 0, ptr %result, align 4 + store i32 12, ptr %input, align 4 + store i1 true, ptr %boolean, align 1 + %5 = getelementptr inbounds %_s__Nested__string_boolptr, ptr %0, i32 0, i32 0 + store ptr @0, ptr %5, align 8 + store ptr %boolean, ptr %1, align 8 + %6 = load ptr, ptr %1, align 8 + %7 = getelementptr inbounds %_s__Nested__string_boolptr, ptr %0, i32 0, i32 1 + store ptr %6, ptr %7, align 8 + store ptr %input, ptr %3, align 8 + %8 = load ptr, ptr %3, align 8 + %9 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, ptr %2, i32 0, i32 0 + store ptr %8, ptr %9, align 8 + %10 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, ptr %2, i32 0, i32 1 + store double 4.634000e+01, ptr %10, align 8 + store ptr %0, ptr %4, align 8 + %11 = load ptr, ptr %4, align 8 + %12 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, ptr %2, i32 0, i32 2 + store ptr %11, ptr %12, align 8 + %13 = load %_s__TestStruct__intptr_double_Nestedptr, ptr %2, align 8 + %14 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, ptr %2, i32 0, i32 2 + %15 = load ptr, ptr %14, align 8 + %16 = load ptr, ptr %14, align 8 + %17 = getelementptr inbounds %_s__Nested__string_boolptr, ptr %16, i32 0, i32 1 + %18 = load ptr, ptr %17, align 8 + %19 = load i1, ptr %18, align 1 + store i1 %19, ptr %18, align 1 + %20 = load i1, ptr %18, align 1 %21 = zext i1 %20 to i32 - %22 = load %_s__TestStruct__intptr_double_Nestedptr, %_s__TestStruct__intptr_double_Nestedptr* %2, align 8 - %23 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, %_s__TestStruct__intptr_double_Nestedptr* %2, i32 0, i32 1 - %24 = load double, double* %23, align 8 - %25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @1, i32 0, i32 0), i32 %21, double %24) - %26 = load %_s__TestStruct__intptr_double_Nestedptr, %_s__TestStruct__intptr_double_Nestedptr* %2, align 8 - %27 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, %_s__TestStruct__intptr_double_Nestedptr* %2, i32 0, i32 2 - %28 = load %_s__Nested__string_boolptr*, %_s__Nested__string_boolptr** %27, align 8 - %29 = load %_s__Nested__string_boolptr*, %_s__Nested__string_boolptr** %27, align 8 - %30 = getelementptr inbounds %_s__Nested__string_boolptr, %_s__Nested__string_boolptr* %29, i32 0, i32 0 - %31 = load i8*, i8** %30, align 8 - %32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @2, i32 0, i32 0), i8* %31) - %33 = load i32, i32* %result, align 4 + %22 = load %_s__TestStruct__intptr_double_Nestedptr, ptr %2, align 8 + %23 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, ptr %2, i32 0, i32 1 + %24 = load double, ptr %23, align 8 + %25 = call i32 (ptr, ...) @printf(ptr @1, i32 %21, double %24) + %26 = load %_s__TestStruct__intptr_double_Nestedptr, ptr %2, align 8 + %27 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, ptr %2, i32 0, i32 2 + %28 = load ptr, ptr %27, align 8 + %29 = load ptr, ptr %27, align 8 + %30 = getelementptr inbounds %_s__Nested__string_boolptr, ptr %29, i32 0, i32 0 + %31 = load ptr, ptr %30, align 8 + %32 = call i32 (ptr, ...) @printf(ptr @2, ptr %31) + %33 = load i32, ptr %result, align 4 ret i32 %33 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/ternary/success-ternary-short-circuiting/ir-code.ll b/test/test-files/generator/ternary/success-ternary-short-circuiting/ir-code.ll index 428230150..8a7c32f1f 100644 --- a/test/test-files/generator/ternary/success-ternary-short-circuiting/ir-code.ll +++ b/test/test-files/generator/ternary/success-ternary-short-circuiting/ir-code.ll @@ -6,54 +6,54 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [11 x i8] c"Result: %d\00", align 1 define internal i1 @_f__void__condition1() { -entry: +entry.l1: %result = alloca i1, align 1 %0 = alloca i1, align 1 - store i1 false, i1* %0, align 1 - %1 = load i1, i1* %0, align 1 + store i1 false, ptr %0, align 1 + %1 = load i1, ptr %0, align 1 ret i1 %1 } define internal i1 @_f__void__condition2() { -entry: +entry.l5: %result = alloca i1, align 1 %0 = alloca i1, align 1 - store i1 true, i1* %0, align 1 - %1 = load i1, i1* %0, align 1 + store i1 true, ptr %0, align 1 + %1 = load i1, ptr %0, align 1 ret i1 %1 } define i32 @main() { -entry: +entry.l9: %result = alloca i32, align 4 %0 = alloca i1, align 1 %1 = alloca i1, align 1 %2 = alloca i1, align 1 %3 = alloca i32, align 4 %4 = alloca i32, align 4 - store i32 0, i32* %result, align 4 + store i32 0, ptr %result, align 4 %5 = call i1 @_f__void__condition1() - store i1 %5, i1* %0, align 1 - %6 = load i1, i1* %0, align 1 - br i1 %6, label %land.1, label %land.end + store i1 %5, ptr %0, align 1 + %6 = load i1, ptr %0, align 1 + br i1 %6, label %land.1.l10, label %land.end.l10 -land.1: ; preds = %entry +land.1.l10: ; preds = %entry.l9 %7 = call i1 @_f__void__condition2() - store i1 %7, i1* %1, align 1 - %8 = load i1, i1* %1, align 1 - br label %land.end + store i1 %7, ptr %1, align 1 + %8 = load i1, ptr %1, align 1 + br label %land.end.l10 -land.end: ; preds = %land.1, %entry - %land_phi = phi i1 [ %6, %entry ], [ %8, %land.1 ] - store i1 %land_phi, i1* %2, align 1 - store i32 2, i32* %3, align 4 - store i32 3, i32* %4, align 4 - %9 = load i1, i1* %2, align 1 - %10 = select i1 %9, i32* %3, i32* %4 - %11 = load i32, i32* %10, align 4 - %12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @0, i32 0, i32 0), i32 %11) - %13 = load i32, i32* %result, align 4 +land.end.l10: ; preds = %land.1.l10, %entry.l9 + %land_phi = phi i1 [ %6, %entry.l9 ], [ %8, %land.1.l10 ] + store i1 %land_phi, ptr %2, align 1 + store i32 2, ptr %3, align 4 + store i32 3, ptr %4, align 4 + %9 = load i1, ptr %2, align 1 + %10 = select i1 %9, ptr %3, ptr %4 + %11 = load i32, ptr %10, align 4 + %12 = call i32 (ptr, ...) @printf(ptr @0, i32 %11) + %13 = load i32, ptr %result, align 4 ret i32 %13 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/ternary/success-ternary-stmt/ir-code.ll b/test/test-files/generator/ternary/success-ternary-stmt/ir-code.ll index a122e9fed..9caffc9b2 100644 --- a/test/test-files/generator/ternary/success-ternary-stmt/ir-code.ll +++ b/test/test-files/generator/ternary/success-ternary-stmt/ir-code.ll @@ -6,31 +6,31 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [11 x i8] c"Result: %d\00", align 1 define internal i32 @_f__void__get() { -entry: +entry.l1: %result = alloca i32, align 4 %0 = alloca i32, align 4 - store i32 12, i32* %0, align 4 - %1 = load i32, i32* %0, align 4 + store i32 12, ptr %0, align 4 + %1 = load i32, ptr %0, align 4 ret i32 %1 } define i32 @main() { -entry: +entry.l5: %result = alloca i32, align 4 %condition = alloca i1, align 1 %0 = alloca i32, align 4 %r = alloca i32, align 4 - store i32 0, i32* %result, align 4 - store i1 true, i1* %condition, align 1 + store i32 0, ptr %result, align 4 + store i1 true, ptr %condition, align 1 %1 = call i32 @_f__void__get() - store i32 %1, i32* %0, align 4 - store i32 24, i32* %r, align 4 - %2 = load i1, i1* %condition, align 1 - %3 = select i1 %2, i32* %0, i32* %r - %4 = load i32, i32* %3, align 4 - %5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @0, i32 0, i32 0), i32 %4) - %6 = load i32, i32* %result, align 4 + store i32 %1, ptr %0, align 4 + store i32 24, ptr %r, align 4 + %2 = load i1, ptr %condition, align 1 + %3 = select i1 %2, ptr %0, ptr %r + %4 = load i32, ptr %3, align 4 + %5 = call i32 (ptr, ...) @printf(ptr @0, i32 %4) + %6 = load i32, ptr %result, align 4 ret i32 %6 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/threads/success-basic-threads/ir-code-O2.ll b/test/test-files/generator/threads/success-basic-threads/ir-code-O2.ll index 1dec945bf..1e1d0a2c6 100644 --- a/test/test-files/generator/threads/success-basic-threads/ir-code-O2.ll +++ b/test/test-files/generator/threads/success-basic-threads/ir-code-O2.ll @@ -11,36 +11,35 @@ target triple = "x86_64-w64-windows-gnu" declare i32 @usleep(i32) local_unnamed_addr define i32 @main() local_unnamed_addr { -entry: +entry.l3: %0 = alloca {}, align 8 - %puts = tail call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0)) - %1 = alloca i8*, align 8 - %2 = bitcast {}* %0 to i8* - %3 = call i32 @pthread_create(i8** nonnull %1, i8* null, i8* (i8*)* nonnull @_thread0, i8* nonnull %2) - %4 = alloca i8*, align 8 - %5 = call i32 @pthread_create(i8** nonnull %4, i8* null, i8* (i8*)* nonnull @_thread1, i8* nonnull %2) - %6 = call i32 @usleep(i32 1000000) - %puts1 = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.1, i64 0, i64 0)) + %puts = tail call i32 @puts(ptr nonnull @str) + %1 = alloca ptr, align 8 + %2 = call i32 @pthread_create(ptr nonnull %1, ptr null, ptr nonnull @_thread0, ptr nonnull %0) + %3 = alloca ptr, align 8 + %4 = call i32 @pthread_create(ptr nonnull %3, ptr null, ptr nonnull @_thread1, ptr nonnull %0) + %5 = call i32 @usleep(i32 1000000) + %puts1 = call i32 @puts(ptr nonnull @str.1) ret i32 0 } -define internal noalias i8* @_thread0(i8* nocapture readnone %0) { -entry: +define internal noalias ptr @_thread0(ptr nocapture readnone %0) { +thread.entry.l5: %1 = tail call i32 @usleep(i32 500000) - %puts = tail call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.2, i64 0, i64 0)) - ret i8* null + %puts = tail call i32 @puts(ptr nonnull @str.2) + ret ptr null } -declare i32 @pthread_create(i8**, i8*, i8* (i8*)*, i8*) local_unnamed_addr +declare i32 @pthread_create(ptr, ptr, ptr, ptr) local_unnamed_addr -define internal noalias i8* @_thread1(i8* nocapture readnone %0) { -entry: +define internal noalias ptr @_thread1(ptr nocapture readnone %0) { +thread.entry.l9: %1 = tail call i32 @usleep(i32 200000) - %puts = tail call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.3, i64 0, i64 0)) - ret i8* null + %puts = tail call i32 @puts(ptr nonnull @str.3) + ret ptr null } ; Function Attrs: nofree nounwind -declare noundef i32 @puts(i8* nocapture noundef readonly) local_unnamed_addr #0 +declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/threads/success-basic-threads/ir-code.ll b/test/test-files/generator/threads/success-basic-threads/ir-code.ll index c67c58032..68e730a63 100644 --- a/test/test-files/generator/threads/success-basic-threads/ir-code.ll +++ b/test/test-files/generator/threads/success-basic-threads/ir-code.ll @@ -11,55 +11,51 @@ target triple = "x86_64-w64-windows-gnu" declare i32 @usleep(i32) define i32 @main() { -entry: +entry.l3: %result = alloca i32, align 4 %0 = alloca {}, align 8 %1 = alloca {}, align 8 %2 = alloca i32, align 4 %3 = alloca i32, align 4 - store i32 0, i32* %result, align 4 - %4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @0, i32 0, i32 0)) - %5 = alloca i8*, align 8 - %6 = bitcast {}* %0 to i8* - %7 = call i32 @pthread_create(i8** %5, i8* null, i8* (i8*)* @_thread0, i8* %6) - %8 = alloca i8*, align 8 - %9 = bitcast {}* %1 to i8* - %10 = call i32 @pthread_create(i8** %8, i8* null, i8* (i8*)* @_thread1, i8* %9) - store i32 1000000, i32* %2, align 4 - %11 = load i32, i32* %2, align 4 - %12 = call i32 @usleep(i32 %11) - store i32 %12, i32* %3, align 4 - %13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @3, i32 0, i32 0)) - %14 = load i32, i32* %result, align 4 - ret i32 %14 + store i32 0, ptr %result, align 4 + %4 = call i32 (ptr, ...) @printf(ptr @0) + %5 = alloca ptr, align 8 + %6 = call i32 @pthread_create(ptr %5, ptr null, ptr @_thread0, ptr %0) + %7 = alloca ptr, align 8 + %8 = call i32 @pthread_create(ptr %7, ptr null, ptr @_thread1, ptr %1) + store i32 1000000, ptr %2, align 4 + %9 = load i32, ptr %2, align 4 + %10 = call i32 @usleep(i32 %9) + store i32 %10, ptr %3, align 4 + %11 = call i32 (ptr, ...) @printf(ptr @3) + %12 = load i32, ptr %result, align 4 + ret i32 %12 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) -define internal i8* @_thread0(i8* %0) { -entry: - %1 = bitcast i8* %0 to {}* +define internal ptr @_thread0(ptr %0) { +thread.entry.l5: + %1 = alloca i32, align 4 %2 = alloca i32, align 4 - %3 = alloca i32, align 4 - store i32 500000, i32* %2, align 4 - %4 = load i32, i32* %2, align 4 - %5 = call i32 @usleep(i32 %4) - store i32 %5, i32* %3, align 4 - %6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @1, i32 0, i32 0)) - ret i8* null + store i32 500000, ptr %1, align 4 + %3 = load i32, ptr %1, align 4 + %4 = call i32 @usleep(i32 %3) + store i32 %4, ptr %2, align 4 + %5 = call i32 (ptr, ...) @printf(ptr @1) + ret ptr null } -declare i32 @pthread_create(i8**, i8*, i8* (i8*)*, i8*) +declare i32 @pthread_create(ptr, ptr, ptr, ptr) -define internal i8* @_thread1(i8* %0) { -entry: - %1 = bitcast i8* %0 to {}* +define internal ptr @_thread1(ptr %0) { +thread.entry.l9: + %1 = alloca i32, align 4 %2 = alloca i32, align 4 - %3 = alloca i32, align 4 - store i32 200000, i32* %2, align 4 - %4 = load i32, i32* %2, align 4 - %5 = call i32 @usleep(i32 %4) - store i32 %5, i32* %3, align 4 - %6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @2, i32 0, i32 0)) - ret i8* null + store i32 200000, ptr %1, align 4 + %3 = load i32, ptr %1, align 4 + %4 = call i32 @usleep(i32 %3) + store i32 %4, ptr %2, align 4 + %5 = call i32 (ptr, ...) @printf(ptr @2) + ret ptr null } diff --git a/test/test-files/generator/threads/success-thread-joining/ir-code-O2.ll b/test/test-files/generator/threads/success-thread-joining/ir-code-O2.ll index a75e02ccf..5d700a3e0 100644 --- a/test/test-files/generator/threads/success-thread-joining/ir-code-O2.ll +++ b/test/test-files/generator/threads/success-thread-joining/ir-code-O2.ll @@ -3,7 +3,6 @@ source_filename = "source.spice" target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-w64-windows-gnu" -@0 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 @str = private unnamed_addr constant [17 x i8] c"Program finished\00", align 1 @str.1 = private unnamed_addr constant [18 x i8] c"Thread 1 finished\00", align 1 @str.2 = private unnamed_addr constant [18 x i8] c"Thread 2 finished\00", align 1 @@ -12,72 +11,67 @@ target triple = "x86_64-w64-windows-gnu" declare i32 @usleep(i32) local_unnamed_addr define i32 @main() local_unnamed_addr { -entry: +entry.l3: %0 = alloca {}, align 8 - %t1 = alloca i8*, align 8 - %t3 = alloca i8*, align 8 - %1 = alloca { i8**, i8** }, align 8 - store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @0, i64 0, i64 0), i8** %t3, align 8 - %2 = alloca i8*, align 8 - %3 = bitcast {}* %0 to i8* - %4 = call i32 @pthread_create(i8** nonnull %2, i8* null, i8* (i8*)* nonnull @_thread0, i8* nonnull %3) - %5 = load i8*, i8** %2, align 8 - store i8* %5, i8** %t1, align 8 - %6 = getelementptr inbounds { i8**, i8** }, { i8**, i8** }* %1, i64 0, i32 0 - store i8** %t1, i8*** %6, align 8 - %7 = getelementptr inbounds { i8**, i8** }, { i8**, i8** }* %1, i64 0, i32 1 - store i8** %t3, i8*** %7, align 8 - %8 = alloca i8*, align 8 - %9 = bitcast { i8**, i8** }* %1 to i8* - %10 = call i32 @pthread_create(i8** nonnull %8, i8* null, i8* (i8*)* nonnull @_thread1, i8* nonnull %9) - %11 = load i8*, i8** %8, align 8 - %12 = alloca i8*, align 8 - %13 = call i32 @pthread_create(i8** nonnull %12, i8* null, i8* (i8*)* nonnull @_thread2, i8* nonnull %3) - %14 = load i8*, i8** %12, align 8 - store i8* %14, i8** %t3, align 8 - %15 = load i8*, i8** %t1, align 8 - %16 = call i32 @pthread_join(i8* %15, i8** null) - %17 = call i32 @pthread_join(i8* %11, i8** null) - %18 = load i8*, i8** %t3, align 8 - %19 = call i32 @pthread_join(i8* %18, i8** null) - %puts = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0)) + %t1 = alloca ptr, align 8 + %t3 = alloca ptr, align 8 + %1 = alloca { ptr, ptr }, align 8 + store ptr null, ptr %t3, align 8 + %2 = alloca ptr, align 8 + %3 = call i32 @pthread_create(ptr nonnull %2, ptr null, ptr nonnull @_thread0, ptr nonnull %0) + %4 = load ptr, ptr %2, align 8 + store ptr %4, ptr %t1, align 8 + store ptr %t1, ptr %1, align 8 + %5 = getelementptr inbounds { ptr, ptr }, ptr %1, i64 0, i32 1 + store ptr %t3, ptr %5, align 8 + %6 = alloca ptr, align 8 + %7 = call i32 @pthread_create(ptr nonnull %6, ptr null, ptr nonnull @_thread1, ptr nonnull %1) + %8 = load ptr, ptr %6, align 8 + %9 = alloca ptr, align 8 + %10 = call i32 @pthread_create(ptr nonnull %9, ptr null, ptr nonnull @_thread2, ptr nonnull %0) + %11 = load ptr, ptr %9, align 8 + store ptr %11, ptr %t3, align 8 + %12 = load ptr, ptr %t1, align 8 + %13 = call i32 @pthread_join(ptr %12, ptr null) + %14 = call i32 @pthread_join(ptr %8, ptr null) + %15 = load ptr, ptr %t3, align 8 + %16 = call i32 @pthread_join(ptr %15, ptr null) + %puts = call i32 @puts(ptr nonnull @str) ret i32 0 } -define internal noalias i8* @_thread0(i8* nocapture readnone %0) { -entry: +define internal noalias ptr @_thread0(ptr nocapture readnone %0) { +thread.entry.l8: %1 = tail call i32 @usleep(i32 300000) - %puts = tail call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.1, i64 0, i64 0)) - ret i8* null + %puts = tail call i32 @puts(ptr nonnull @str.1) + ret ptr null } -declare i32 @pthread_create(i8**, i8*, i8* (i8*)*, i8*) local_unnamed_addr +declare i32 @pthread_create(ptr, ptr, ptr, ptr) local_unnamed_addr -define internal noalias i8* @_thread1(i8* nocapture readonly %0) { -entry: - %1 = bitcast i8* %0 to i8*** - %2 = load i8**, i8*** %1, align 8 - %3 = getelementptr inbounds i8, i8* %0, i64 8 - %4 = bitcast i8* %3 to i8*** - %5 = load i8**, i8*** %4, align 8 - %6 = load i8*, i8** %2, align 8 - %7 = tail call i32 @pthread_join(i8* %6, i8** null) - %8 = load i8*, i8** %5, align 8 - %9 = tail call i32 @pthread_join(i8* %8, i8** null) - %puts = tail call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.2, i64 0, i64 0)) - ret i8* null +define internal noalias ptr @_thread1(ptr nocapture readonly %0) { +thread.entry.l13: + %1 = load ptr, ptr %0, align 8 + %2 = getelementptr inbounds { ptr, ptr }, ptr %0, i64 0, i32 1 + %3 = load ptr, ptr %2, align 8 + %4 = load ptr, ptr %1, align 8 + %5 = tail call i32 @pthread_join(ptr %4, ptr null) + %6 = load ptr, ptr %3, align 8 + %7 = tail call i32 @pthread_join(ptr %6, ptr null) + %puts = tail call i32 @puts(ptr nonnull @str.2) + ret ptr null } -declare i32 @pthread_join(i8*, i8**) local_unnamed_addr +declare i32 @pthread_join(ptr, ptr) local_unnamed_addr -define internal noalias i8* @_thread2(i8* nocapture readnone %0) { -entry: +define internal noalias ptr @_thread2(ptr nocapture readnone %0) { +thread.entry.l18: %1 = tail call i32 @usleep(i32 200000) - %puts = tail call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0)) - ret i8* null + %puts = tail call i32 @puts(ptr nonnull @str.3) + ret ptr null } ; Function Attrs: nofree nounwind -declare noundef i32 @puts(i8* nocapture noundef readonly) local_unnamed_addr #0 +declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/threads/success-thread-joining/ir-code.ll b/test/test-files/generator/threads/success-thread-joining/ir-code.ll index 7a350ecd3..d3ca42d6b 100644 --- a/test/test-files/generator/threads/success-thread-joining/ir-code.ll +++ b/test/test-files/generator/threads/success-thread-joining/ir-code.ll @@ -3,106 +3,97 @@ source_filename = "source.spice" target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-w64-windows-gnu" -@0 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 -@1 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 -@2 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 -@3 = private unnamed_addr constant [19 x i8] c"Thread 1 finished\0A\00", align 1 -@4 = private unnamed_addr constant [19 x i8] c"Thread 2 finished\0A\00", align 1 -@5 = private unnamed_addr constant [19 x i8] c"Thread 3 finished\0A\00", align 1 -@6 = private unnamed_addr constant [18 x i8] c"Program finished\0A\00", align 1 +@0 = private unnamed_addr constant [19 x i8] c"Thread 1 finished\0A\00", align 1 +@1 = private unnamed_addr constant [19 x i8] c"Thread 2 finished\0A\00", align 1 +@2 = private unnamed_addr constant [19 x i8] c"Thread 3 finished\0A\00", align 1 +@3 = private unnamed_addr constant [18 x i8] c"Program finished\0A\00", align 1 declare i32 @usleep(i32) define i32 @main() { -entry: +entry.l3: %result = alloca i32, align 4 - %t1 = alloca i8*, align 8 - %t2 = alloca i8*, align 8 - %t3 = alloca i8*, align 8 + %t1 = alloca ptr, align 8 + %t2 = alloca ptr, align 8 + %t3 = alloca ptr, align 8 %0 = alloca {}, align 8 - %1 = alloca { i8**, i8** }, align 8 + %1 = alloca { ptr, ptr }, align 8 %2 = alloca {}, align 8 %3 = alloca i32, align 4 - store i32 0, i32* %result, align 4 - store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @0, i32 0, i32 0), i8** %t1, align 8 - store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @1, i32 0, i32 0), i8** %t2, align 8 - store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @2, i32 0, i32 0), i8** %t3, align 8 - %4 = alloca i8*, align 8 - %5 = bitcast {}* %0 to i8* - %6 = call i32 @pthread_create(i8** %4, i8* null, i8* (i8*)* @_thread0, i8* %5) - %7 = load i8*, i8** %4, align 8 - store i8* %7, i8** %t1, align 8 - %8 = getelementptr inbounds { i8**, i8** }, { i8**, i8** }* %1, i32 0, i32 0 - store i8** %t1, i8*** %8, align 8 - %9 = getelementptr inbounds { i8**, i8** }, { i8**, i8** }* %1, i32 0, i32 1 - store i8** %t3, i8*** %9, align 8 - %10 = alloca i8*, align 8 - %11 = bitcast { i8**, i8** }* %1 to i8* - %12 = call i32 @pthread_create(i8** %10, i8* null, i8* (i8*)* @_thread1, i8* %11) - %13 = load i8*, i8** %10, align 8 - store i8* %13, i8** %t2, align 8 - %14 = alloca i8*, align 8 - %15 = bitcast {}* %2 to i8* - %16 = call i32 @pthread_create(i8** %14, i8* null, i8* (i8*)* @_thread2, i8* %15) - %17 = load i8*, i8** %14, align 8 - store i8* %17, i8** %t3, align 8 - %18 = load i8*, i8** %t1, align 8 - %19 = call i32 @pthread_join(i8* %18, i8** null) - %20 = load i8*, i8** %t2, align 8 - %21 = call i32 @pthread_join(i8* %20, i8** null) - %22 = load i8*, i8** %t3, align 8 - %23 = call i32 @pthread_join(i8* %22, i8** null) - store i32 3, i32* %3, align 4 - %24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @6, i32 0, i32 0)) - %25 = load i32, i32* %result, align 4 - ret i32 %25 + store i32 0, ptr %result, align 4 + store ptr null, ptr %t1, align 8 + store ptr null, ptr %t2, align 8 + store ptr null, ptr %t3, align 8 + %4 = alloca ptr, align 8 + %5 = call i32 @pthread_create(ptr %4, ptr null, ptr @_thread0, ptr %0) + %6 = load ptr, ptr %4, align 8 + store ptr %6, ptr %t1, align 8 + %7 = getelementptr inbounds { ptr, ptr }, ptr %1, i32 0, i32 0 + store ptr %t1, ptr %7, align 8 + %8 = getelementptr inbounds { ptr, ptr }, ptr %1, i32 0, i32 1 + store ptr %t3, ptr %8, align 8 + %9 = alloca ptr, align 8 + %10 = call i32 @pthread_create(ptr %9, ptr null, ptr @_thread1, ptr %1) + %11 = load ptr, ptr %9, align 8 + store ptr %11, ptr %t2, align 8 + %12 = alloca ptr, align 8 + %13 = call i32 @pthread_create(ptr %12, ptr null, ptr @_thread2, ptr %2) + %14 = load ptr, ptr %12, align 8 + store ptr %14, ptr %t3, align 8 + %15 = load ptr, ptr %t1, align 8 + %16 = call i32 @pthread_join(ptr %15, ptr null) + %17 = load ptr, ptr %t2, align 8 + %18 = call i32 @pthread_join(ptr %17, ptr null) + %19 = load ptr, ptr %t3, align 8 + %20 = call i32 @pthread_join(ptr %19, ptr null) + store i32 3, ptr %3, align 4 + %21 = call i32 (ptr, ...) @printf(ptr @3) + %22 = load i32, ptr %result, align 4 + ret i32 %22 } -define internal i8* @_thread0(i8* %0) { -entry: - %1 = bitcast i8* %0 to {}* +define internal ptr @_thread0(ptr %0) { +thread.entry.l8: + %1 = alloca i32, align 4 %2 = alloca i32, align 4 - %3 = alloca i32, align 4 - store i32 300000, i32* %2, align 4 - %4 = load i32, i32* %2, align 4 - %5 = call i32 @usleep(i32 %4) - store i32 %5, i32* %3, align 4 - %6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @3, i32 0, i32 0)) - ret i8* null + store i32 300000, ptr %1, align 4 + %3 = load i32, ptr %1, align 4 + %4 = call i32 @usleep(i32 %3) + store i32 %4, ptr %2, align 4 + %5 = call i32 (ptr, ...) @printf(ptr @0) + ret ptr null } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) -declare i32 @pthread_create(i8**, i8*, i8* (i8*)*, i8*) +declare i32 @pthread_create(ptr, ptr, ptr, ptr) -define internal i8* @_thread1(i8* %0) { -entry: - %1 = bitcast i8* %0 to { i8**, i8** }* - %2 = getelementptr inbounds { i8**, i8** }, { i8**, i8** }* %1, i32 0, i32 0 - %3 = load i8**, i8*** %2, align 8 - %4 = getelementptr inbounds { i8**, i8** }, { i8**, i8** }* %1, i32 0, i32 1 - %5 = load i8**, i8*** %4, align 8 - %6 = load i8*, i8** %3, align 8 - %7 = call i32 @pthread_join(i8* %6, i8** null) - %8 = load i8*, i8** %5, align 8 - %9 = call i32 @pthread_join(i8* %8, i8** null) - %10 = alloca i32, align 4 - store i32 2, i32* %10, align 4 - %11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @4, i32 0, i32 0)) - ret i8* null +define internal ptr @_thread1(ptr %0) { +thread.entry.l13: + %1 = getelementptr inbounds { ptr, ptr }, ptr %0, i32 0, i32 0 + %2 = load ptr, ptr %1, align 8 + %3 = getelementptr inbounds { ptr, ptr }, ptr %0, i32 0, i32 1 + %4 = load ptr, ptr %3, align 8 + %5 = load ptr, ptr %2, align 8 + %6 = call i32 @pthread_join(ptr %5, ptr null) + %7 = load ptr, ptr %4, align 8 + %8 = call i32 @pthread_join(ptr %7, ptr null) + %9 = alloca i32, align 4 + store i32 2, ptr %9, align 4 + %10 = call i32 (ptr, ...) @printf(ptr @1) + ret ptr null } -declare i32 @pthread_join(i8*, i8**) +declare i32 @pthread_join(ptr, ptr) -define internal i8* @_thread2(i8* %0) { -entry: - %1 = bitcast i8* %0 to {}* +define internal ptr @_thread2(ptr %0) { +thread.entry.l18: + %1 = alloca i32, align 4 %2 = alloca i32, align 4 - %3 = alloca i32, align 4 - store i32 200000, i32* %2, align 4 - %4 = load i32, i32* %2, align 4 - %5 = call i32 @usleep(i32 %4) - store i32 %5, i32* %3, align 4 - %6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @5, i32 0, i32 0)) - ret i8* null + store i32 200000, ptr %1, align 4 + %3 = load i32, ptr %1, align 4 + %4 = call i32 @usleep(i32 %3) + store i32 %4, ptr %2, align 4 + %5 = call i32 (ptr, ...) @printf(ptr @2) + ret ptr null } diff --git a/test/test-files/generator/threads/success-threads-captures1/ir-code-O2.ll b/test/test-files/generator/threads/success-threads-captures1/ir-code-O2.ll index b232cf2be..0f6a381ac 100644 --- a/test/test-files/generator/threads/success-threads-captures1/ir-code-O2.ll +++ b/test/test-files/generator/threads/success-threads-captures1/ir-code-O2.ll @@ -11,50 +11,47 @@ target triple = "x86_64-w64-windows-gnu" declare i32 @usleep(i32) local_unnamed_addr define i32 @main() local_unnamed_addr { -entry: +entry.l3: %i = alloca i32, align 4 - %0 = alloca { i32* }, align 8 - %puts = tail call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0)) - store i32 1, i32* %i, align 4 - %1 = getelementptr inbounds { i32* }, { i32* }* %0, i64 0, i32 0 - %2 = bitcast { i32* }* %0 to i8* - br label %for - -for: ; preds = %entry, %for - %storemerge2 = phi i32 [ 1, %entry ], [ %7, %for ] - %3 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @0, i64 0, i64 0), i32 %storemerge2) - store i32* %i, i32** %1, align 8 - %4 = alloca i8*, align 8 - %5 = call i32 @pthread_create(i8** nonnull %4, i8* null, i8* (i8*)* nonnull @_thread0, i8* nonnull %2) - %6 = load i32, i32* %i, align 4 - %7 = add i32 %6, 1 - store i32 %7, i32* %i, align 4 - %8 = icmp slt i32 %7, 9 - br i1 %8, label %for, label %for.end - -for.end: ; preds = %for - %9 = call i32 @usleep(i32 1000000) - %puts1 = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.1, i64 0, i64 0)) + %0 = alloca { ptr }, align 8 + %puts = tail call i32 @puts(ptr nonnull @str) + store i32 1, ptr %i, align 4 + br label %for.l5 + +for.l5: ; preds = %entry.l3, %for.l5 + %storemerge2 = phi i32 [ 1, %entry.l3 ], [ %5, %for.l5 ] + %1 = call i32 (ptr, ...) @printf(ptr nonnull @0, i32 %storemerge2) + store ptr %i, ptr %0, align 8 + %2 = alloca ptr, align 8 + %3 = call i32 @pthread_create(ptr nonnull %2, ptr null, ptr nonnull @_thread0, ptr nonnull %0) + %4 = load i32, ptr %i, align 4 + %5 = add i32 %4, 1 + store i32 %5, ptr %i, align 4 + %6 = icmp slt i32 %5, 9 + br i1 %6, label %for.l5, label %for.end.l5 + +for.end.l5: ; preds = %for.l5 + %7 = call i32 @usleep(i32 1000000) + %puts1 = call i32 @puts(ptr nonnull @str.1) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 - -define internal noalias i8* @_thread0(i8* nocapture readonly %0) { -entry: - %1 = bitcast i8* %0 to i32** - %2 = load i32*, i32** %1, align 8 - %3 = load i32, i32* %2, align 4 - %4 = mul i32 %3, 100000 - %5 = tail call i32 @usleep(i32 %4) - %puts = tail call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.2, i64 0, i64 0)) - ret i8* null +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 + +define internal noalias ptr @_thread0(ptr nocapture readonly %0) { +thread.entry.l7: + %1 = load ptr, ptr %0, align 8 + %2 = load i32, ptr %1, align 4 + %3 = mul i32 %2, 100000 + %4 = tail call i32 @usleep(i32 %3) + %puts = tail call i32 @puts(ptr nonnull @str.2) + ret ptr null } -declare i32 @pthread_create(i8**, i8*, i8* (i8*)*, i8*) local_unnamed_addr +declare i32 @pthread_create(ptr, ptr, ptr, ptr) local_unnamed_addr ; Function Attrs: nofree nounwind -declare noundef i32 @puts(i8* nocapture noundef readonly) local_unnamed_addr #0 +declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/threads/success-threads-captures1/ir-code.ll b/test/test-files/generator/threads/success-threads-captures1/ir-code.ll index 7a2f40f20..b32baa470 100644 --- a/test/test-files/generator/threads/success-threads-captures1/ir-code.ll +++ b/test/test-files/generator/threads/success-threads-captures1/ir-code.ll @@ -11,71 +11,69 @@ target triple = "x86_64-w64-windows-gnu" declare i32 @usleep(i32) define i32 @main() { -entry: +entry.l3: %result = alloca i32, align 4 %i = alloca i32, align 4 - %0 = alloca { i32* }, align 8 + %0 = alloca { ptr }, align 8 %1 = alloca i32, align 4 %2 = alloca i1, align 1 %3 = alloca i32, align 4 %4 = alloca i32, align 4 - store i32 0, i32* %result, align 4 - %5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @0, i32 0, i32 0)) - store i32 1, i32* %i, align 4 - br label %for.cond + store i32 0, ptr %result, align 4 + %5 = call i32 (ptr, ...) @printf(ptr @0) + store i32 1, ptr %i, align 4 + br label %for.cond.l5 -for: ; preds = %for.cond - %6 = load i32, i32* %i, align 4 - %7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @1, i32 0, i32 0), i32 %6) - %8 = getelementptr inbounds { i32* }, { i32* }* %0, i32 0, i32 0 - store i32* %i, i32** %8, align 8 - %9 = alloca i8*, align 8 - %10 = bitcast { i32* }* %0 to i8* - %11 = call i32 @pthread_create(i8** %9, i8* null, i8* (i8*)* @_thread0, i8* %10) - br label %for.inc +for.l5: ; preds = %for.cond.l5 + %6 = load i32, ptr %i, align 4 + %7 = call i32 (ptr, ...) @printf(ptr @1, i32 %6) + %8 = getelementptr inbounds { ptr }, ptr %0, i32 0, i32 0 + store ptr %i, ptr %8, align 8 + %9 = alloca ptr, align 8 + %10 = call i32 @pthread_create(ptr %9, ptr null, ptr @_thread0, ptr %0) + br label %for.inc.l5 -for.inc: ; preds = %for - %12 = load i32, i32* %i, align 4 - %13 = add i32 %12, 1 - store i32 %13, i32* %i, align 4 - store i32 %12, i32* %1, align 4 - br label %for.cond +for.inc.l5: ; preds = %for.l5 + %11 = load i32, ptr %i, align 4 + %12 = add i32 %11, 1 + store i32 %12, ptr %i, align 4 + store i32 %11, ptr %1, align 4 + br label %for.cond.l5 -for.cond: ; preds = %for.inc, %entry - %14 = load i32, i32* %i, align 4 - %15 = icmp sle i32 %14, 8 - store i1 %15, i1* %2, align 1 - %16 = load i1, i1* %2, align 1 - br i1 %16, label %for, label %for.end +for.cond.l5: ; preds = %for.inc.l5, %entry.l3 + %13 = load i32, ptr %i, align 4 + %14 = icmp sle i32 %13, 8 + store i1 %14, ptr %2, align 1 + %15 = load i1, ptr %2, align 1 + br i1 %15, label %for.l5, label %for.end.l5 -for.end: ; preds = %for.cond - store i32 1000000, i32* %3, align 4 - %17 = load i32, i32* %3, align 4 - %18 = call i32 @usleep(i32 %17) - store i32 %18, i32* %4, align 4 - %19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @3, i32 0, i32 0)) - %20 = load i32, i32* %result, align 4 - ret i32 %20 +for.end.l5: ; preds = %for.cond.l5 + store i32 1000000, ptr %3, align 4 + %16 = load i32, ptr %3, align 4 + %17 = call i32 @usleep(i32 %16) + store i32 %17, ptr %4, align 4 + %18 = call i32 (ptr, ...) @printf(ptr @3) + %19 = load i32, ptr %result, align 4 + ret i32 %19 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) -define internal i8* @_thread0(i8* %0) { -entry: - %1 = bitcast i8* %0 to { i32* }* - %2 = getelementptr inbounds { i32* }, { i32* }* %1, i32 0, i32 0 - %3 = load i32*, i32** %2, align 8 - %4 = load i32, i32* %3, align 4 - %5 = mul i32 100, %4 - %6 = mul i32 %5, 1000 +define internal ptr @_thread0(ptr %0) { +thread.entry.l7: + %1 = getelementptr inbounds { ptr }, ptr %0, i32 0, i32 0 + %2 = load ptr, ptr %1, align 8 + %3 = load i32, ptr %2, align 4 + %4 = mul i32 100, %3 + %5 = mul i32 %4, 1000 + %6 = alloca i32, align 4 %7 = alloca i32, align 4 - %8 = alloca i32, align 4 - store i32 %6, i32* %7, align 4 - %9 = load i32, i32* %7, align 4 - %10 = call i32 @usleep(i32 %9) - store i32 %10, i32* %8, align 4 - %11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @2, i32 0, i32 0)) - ret i8* null + store i32 %5, ptr %6, align 4 + %8 = load i32, ptr %6, align 4 + %9 = call i32 @usleep(i32 %8) + store i32 %9, ptr %7, align 4 + %10 = call i32 (ptr, ...) @printf(ptr @2) + ret ptr null } -declare i32 @pthread_create(i8**, i8*, i8* (i8*)*, i8*) +declare i32 @pthread_create(ptr, ptr, ptr, ptr) diff --git a/test/test-files/generator/threads/success-threads-captures2/ir-code-O2.ll b/test/test-files/generator/threads/success-threads-captures2/ir-code-O2.ll index 6ba358c04..76dc24fac 100644 --- a/test/test-files/generator/threads/success-threads-captures2/ir-code-O2.ll +++ b/test/test-files/generator/threads/success-threads-captures2/ir-code-O2.ll @@ -11,60 +11,56 @@ target triple = "x86_64-w64-windows-gnu" declare i32 @usleep(i32) local_unnamed_addr define i32 @main() local_unnamed_addr { -entry: +entry.l3: %capturedVariable = alloca i32, align 4 %i = alloca i32, align 4 - %0 = alloca { i32*, i32* }, align 8 - %puts = tail call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0)) - store i32 0, i32* %capturedVariable, align 4 - store i32 1, i32* %i, align 4 - %1 = getelementptr inbounds { i32*, i32* }, { i32*, i32* }* %0, i64 0, i32 0 - %2 = getelementptr inbounds { i32*, i32* }, { i32*, i32* }* %0, i64 0, i32 1 - %3 = bitcast { i32*, i32* }* %0 to i8* - br label %for + %0 = alloca { ptr, ptr }, align 8 + %puts = tail call i32 @puts(ptr nonnull @str) + store i32 0, ptr %capturedVariable, align 4 + store i32 1, ptr %i, align 4 + %1 = getelementptr inbounds { ptr, ptr }, ptr %0, i64 0, i32 1 + br label %for.l6 -for: ; preds = %entry, %for - %storemerge2 = phi i32 [ 1, %entry ], [ %8, %for ] - %4 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @0, i64 0, i64 0), i32 %storemerge2) - store i32* %capturedVariable, i32** %1, align 8 - store i32* %i, i32** %2, align 8 - %5 = alloca i8*, align 8 - %6 = call i32 @pthread_create(i8** nonnull %5, i8* null, i8* (i8*)* nonnull @_thread0, i8* nonnull %3) - %7 = load i32, i32* %i, align 4 - %8 = add i32 %7, 1 - store i32 %8, i32* %i, align 4 - %9 = icmp slt i32 %8, 9 - br i1 %9, label %for, label %for.end +for.l6: ; preds = %entry.l3, %for.l6 + %storemerge2 = phi i32 [ 1, %entry.l3 ], [ %6, %for.l6 ] + %2 = call i32 (ptr, ...) @printf(ptr nonnull @0, i32 %storemerge2) + store ptr %capturedVariable, ptr %0, align 8 + store ptr %i, ptr %1, align 8 + %3 = alloca ptr, align 8 + %4 = call i32 @pthread_create(ptr nonnull %3, ptr null, ptr nonnull @_thread0, ptr nonnull %0) + %5 = load i32, ptr %i, align 4 + %6 = add i32 %5, 1 + store i32 %6, ptr %i, align 4 + %7 = icmp slt i32 %6, 9 + br i1 %7, label %for.l6, label %for.end.l6 -for.end: ; preds = %for - %10 = call i32 @usleep(i32 1000000) - %puts1 = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.1, i64 0, i64 0)) +for.end.l6: ; preds = %for.l6 + %8 = call i32 @usleep(i32 1000000) + %puts1 = call i32 @puts(ptr nonnull @str.1) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 -define internal noalias i8* @_thread0(i8* nocapture readonly %0) { -entry: - %1 = bitcast i8* %0 to i32** - %2 = load i32*, i32** %1, align 8 - %3 = getelementptr inbounds i8, i8* %0, i64 8 - %4 = bitcast i8* %3 to i32** - %5 = load i32*, i32** %4, align 8 - %6 = load i32, i32* %5, align 4 - %7 = mul i32 %6, 100000 - %8 = tail call i32 @usleep(i32 %7) - %9 = load i32, i32* %2, align 4 - %10 = shl i32 %9, 1 - store volatile i32 %10, i32* %2, align 4 - %puts = tail call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.2, i64 0, i64 0)) - ret i8* null +define internal noalias ptr @_thread0(ptr nocapture readonly %0) { +thread.entry.l8: + %1 = load ptr, ptr %0, align 8 + %2 = getelementptr inbounds { ptr, ptr }, ptr %0, i64 0, i32 1 + %3 = load ptr, ptr %2, align 8 + %4 = load i32, ptr %3, align 4 + %5 = mul i32 %4, 100000 + %6 = tail call i32 @usleep(i32 %5) + %7 = load i32, ptr %1, align 4 + %8 = shl i32 %7, 1 + store volatile i32 %8, ptr %1, align 4 + %puts = tail call i32 @puts(ptr nonnull @str.2) + ret ptr null } -declare i32 @pthread_create(i8**, i8*, i8* (i8*)*, i8*) local_unnamed_addr +declare i32 @pthread_create(ptr, ptr, ptr, ptr) local_unnamed_addr ; Function Attrs: nofree nounwind -declare noundef i32 @puts(i8* nocapture noundef readonly) local_unnamed_addr #0 +declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/threads/success-threads-captures2/ir-code.ll b/test/test-files/generator/threads/success-threads-captures2/ir-code.ll index 3019926a1..3f0c8beb1 100644 --- a/test/test-files/generator/threads/success-threads-captures2/ir-code.ll +++ b/test/test-files/generator/threads/success-threads-captures2/ir-code.ll @@ -11,80 +11,78 @@ target triple = "x86_64-w64-windows-gnu" declare i32 @usleep(i32) define i32 @main() { -entry: +entry.l3: %result = alloca i32, align 4 %capturedVariable = alloca i32, align 4 %i = alloca i32, align 4 - %0 = alloca { i32*, i32* }, align 8 + %0 = alloca { ptr, ptr }, align 8 %1 = alloca i32, align 4 %2 = alloca i1, align 1 %3 = alloca i32, align 4 %4 = alloca i32, align 4 - store i32 0, i32* %result, align 4 - %5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @0, i32 0, i32 0)) - store i32 0, i32* %capturedVariable, align 4 - store i32 1, i32* %i, align 4 - br label %for.cond + store i32 0, ptr %result, align 4 + %5 = call i32 (ptr, ...) @printf(ptr @0) + store i32 0, ptr %capturedVariable, align 4 + store i32 1, ptr %i, align 4 + br label %for.cond.l6 -for: ; preds = %for.cond - %6 = load i32, i32* %i, align 4 - %7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @1, i32 0, i32 0), i32 %6) - %8 = getelementptr inbounds { i32*, i32* }, { i32*, i32* }* %0, i32 0, i32 0 - store i32* %capturedVariable, i32** %8, align 8 - %9 = getelementptr inbounds { i32*, i32* }, { i32*, i32* }* %0, i32 0, i32 1 - store i32* %i, i32** %9, align 8 - %10 = alloca i8*, align 8 - %11 = bitcast { i32*, i32* }* %0 to i8* - %12 = call i32 @pthread_create(i8** %10, i8* null, i8* (i8*)* @_thread0, i8* %11) - br label %for.inc +for.l6: ; preds = %for.cond.l6 + %6 = load i32, ptr %i, align 4 + %7 = call i32 (ptr, ...) @printf(ptr @1, i32 %6) + %8 = getelementptr inbounds { ptr, ptr }, ptr %0, i32 0, i32 0 + store ptr %capturedVariable, ptr %8, align 8 + %9 = getelementptr inbounds { ptr, ptr }, ptr %0, i32 0, i32 1 + store ptr %i, ptr %9, align 8 + %10 = alloca ptr, align 8 + %11 = call i32 @pthread_create(ptr %10, ptr null, ptr @_thread0, ptr %0) + br label %for.inc.l6 -for.inc: ; preds = %for - %13 = load i32, i32* %i, align 4 - %14 = add i32 %13, 1 - store i32 %14, i32* %i, align 4 - store i32 %13, i32* %1, align 4 - br label %for.cond +for.inc.l6: ; preds = %for.l6 + %12 = load i32, ptr %i, align 4 + %13 = add i32 %12, 1 + store i32 %13, ptr %i, align 4 + store i32 %12, ptr %1, align 4 + br label %for.cond.l6 -for.cond: ; preds = %for.inc, %entry - %15 = load i32, i32* %i, align 4 - %16 = icmp sle i32 %15, 8 - store i1 %16, i1* %2, align 1 - %17 = load i1, i1* %2, align 1 - br i1 %17, label %for, label %for.end +for.cond.l6: ; preds = %for.inc.l6, %entry.l3 + %14 = load i32, ptr %i, align 4 + %15 = icmp sle i32 %14, 8 + store i1 %15, ptr %2, align 1 + %16 = load i1, ptr %2, align 1 + br i1 %16, label %for.l6, label %for.end.l6 -for.end: ; preds = %for.cond - store i32 1000000, i32* %3, align 4 - %18 = load i32, i32* %3, align 4 - %19 = call i32 @usleep(i32 %18) - store i32 %19, i32* %4, align 4 - %20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @3, i32 0, i32 0)) - %21 = load i32, i32* %result, align 4 - ret i32 %21 +for.end.l6: ; preds = %for.cond.l6 + store i32 1000000, ptr %3, align 4 + %17 = load i32, ptr %3, align 4 + %18 = call i32 @usleep(i32 %17) + store i32 %18, ptr %4, align 4 + %19 = call i32 (ptr, ...) @printf(ptr @3) + %20 = load i32, ptr %result, align 4 + ret i32 %20 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) -define internal i8* @_thread0(i8* %0) { -entry: - %1 = bitcast i8* %0 to { i32*, i32* }* - %2 = getelementptr inbounds { i32*, i32* }, { i32*, i32* }* %1, i32 0, i32 0 - %3 = load i32*, i32** %2, align 8 - %4 = getelementptr inbounds { i32*, i32* }, { i32*, i32* }* %1, i32 0, i32 1 - %5 = load i32*, i32** %4, align 8 - %6 = load i32, i32* %5, align 4 - %7 = mul i32 100, %6 - %8 = mul i32 %7, 1000 +define internal ptr @_thread0(ptr %0) { +thread.entry.l8: + %1 = getelementptr inbounds { ptr, ptr }, ptr %0, i32 0, i32 0 + %2 = load ptr, ptr %1, align 8 + %3 = getelementptr inbounds { ptr, ptr }, ptr %0, i32 0, i32 1 + %4 = load ptr, ptr %3, align 8 + %5 = load i32, ptr %4, align 4 + %6 = mul i32 100, %5 + %7 = mul i32 %6, 1000 + %8 = alloca i32, align 4 %9 = alloca i32, align 4 - %10 = alloca i32, align 4 - store i32 %8, i32* %9, align 4 - %11 = load i32, i32* %9, align 4 - %12 = call i32 @usleep(i32 %11) - store i32 %12, i32* %10, align 4 - %13 = load i32, i32* %3, align 4 - %14 = mul i32 %13, 2 - store volatile i32 %14, i32* %3, align 4 - %15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @2, i32 0, i32 0)) - ret i8* null + store i32 %7, ptr %8, align 4 + %10 = load i32, ptr %8, align 4 + %11 = call i32 @usleep(i32 %10) + store i32 %11, ptr %9, align 4 + %12 = load i32, ptr %2, align 4 + %13 = mul i32 %12, 2 + store volatile i32 %13, ptr %2, align 4 + %14 = call i32 (ptr, ...) @printf(ptr @2) + ret ptr null } -declare i32 @pthread_create(i8**, i8*, i8* (i8*)*, i8*) +declare i32 @pthread_create(ptr, ptr, ptr, ptr) diff --git a/test/test-files/generator/unsafe/success-pointer-cast/ir-code.ll b/test/test-files/generator/unsafe/success-pointer-cast/ir-code.ll index 308f78df3..30b2ea95c 100644 --- a/test/test-files/generator/unsafe/success-pointer-cast/ir-code.ll +++ b/test/test-files/generator/unsafe/success-pointer-cast/ir-code.ll @@ -6,28 +6,27 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [9 x i8] c"Int: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %l = alloca i64, align 8 - %0 = alloca i64*, align 8 - %iPtr = alloca i32*, align 8 - %1 = alloca i32*, align 8 - store i32 0, i32* %result, align 4 - store i64 1234, i64* %l, align 8 - store i64* %l, i64** %0, align 8 - store i32* null, i32** %iPtr, align 8 - %2 = load i64*, i64** %0, align 8 - %3 = bitcast i64* %2 to i32* - store i32* %3, i32** %1, align 8 - %4 = load i32*, i32** %1, align 8 - store i32* %4, i32** %iPtr, align 8 - %5 = load i32*, i32** %iPtr, align 8 - %6 = load i32, i32* %5, align 4 - store i32 %6, i32* %5, align 4 - %7 = load i32, i32* %5, align 4 - %8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @0, i32 0, i32 0), i32 %7) - %9 = load i32, i32* %result, align 4 - ret i32 %9 + %0 = alloca ptr, align 8 + %iPtr = alloca ptr, align 8 + %1 = alloca ptr, align 8 + store i32 0, ptr %result, align 4 + store i64 1234, ptr %l, align 8 + store ptr %l, ptr %0, align 8 + store ptr null, ptr %iPtr, align 8 + %2 = load ptr, ptr %0, align 8 + store ptr %2, ptr %1, align 8 + %3 = load ptr, ptr %1, align 8 + store ptr %3, ptr %iPtr, align 8 + %4 = load ptr, ptr %iPtr, align 8 + %5 = load i32, ptr %4, align 4 + store i32 %5, ptr %4, align 4 + %6 = load i32, ptr %4, align 4 + %7 = call i32 (ptr, ...) @printf(ptr @0, i32 %6) + %8 = load i32, ptr %result, align 4 + ret i32 %8 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/variables/success-decl-default-value/cout.out b/test/test-files/generator/variables/success-decl-default-value/cout.out index 3537fa4e1..f853d1044 100644 --- a/test/test-files/generator/variables/success-decl-default-value/cout.out +++ b/test/test-files/generator/variables/success-decl-default-value/cout.out @@ -5,4 +5,4 @@ Long value: 0 String value: Byte value: 0 Char value: Bool value: 0 -Struct array value: (null) +Struct array value: diff --git a/test/test-files/generator/variables/success-decl-default-value/ir-code.ll b/test/test-files/generator/variables/success-decl-default-value/ir-code.ll index ee734985b..3bbb7c664 100644 --- a/test/test-files/generator/variables/success-decl-default-value/ir-code.ll +++ b/test/test-files/generator/variables/success-decl-default-value/ir-code.ll @@ -3,7 +3,7 @@ source_filename = "source.spice" target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-w64-windows-gnu" -%_s__NestedStruct__int_string = type { i32, i8* } +%_s__NestedStruct__int_string = type { i32, ptr } @0 = private unnamed_addr constant [18 x i8] c"Double value: %f\0A\00", align 1 @1 = private unnamed_addr constant [15 x i8] c"Int value: %d\0A\00", align 1 @@ -18,59 +18,59 @@ target triple = "x86_64-w64-windows-gnu" @10 = private unnamed_addr constant [24 x i8] c"Struct array value: %s\0A\00", align 1 define i32 @main() { -entry: +entry.l11: %result = alloca i32, align 4 %doubleVar = alloca double, align 8 %intVar = alloca i32, align 4 %shortVar = alloca i16, align 2 %longVar = alloca i64, align 8 - %stringVar = alloca i8*, align 8 + %stringVar = alloca ptr, align 8 %byteVar = alloca i8, align 1 %charVar = alloca i8, align 1 %boolVar = alloca i1, align 1 %0 = alloca %_s__NestedStruct__int_string, align 8 %structArrayVar = alloca [4 x %_s__NestedStruct__int_string], align 8 - store i32 0, i32* %result, align 4 - store double 0.000000e+00, double* %doubleVar, align 8 - %1 = load double, double* %doubleVar, align 8 - %2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @0, i32 0, i32 0), double %1) - store i32 0, i32* %intVar, align 4 - %3 = load i32, i32* %intVar, align 4 - %4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @1, i32 0, i32 0), i32 %3) - store i16 0, i16* %shortVar, align 2 - %5 = load i16, i16* %shortVar, align 2 + store i32 0, ptr %result, align 4 + store double 0.000000e+00, ptr %doubleVar, align 8 + %1 = load double, ptr %doubleVar, align 8 + %2 = call i32 (ptr, ...) @printf(ptr @0, double %1) + store i32 0, ptr %intVar, align 4 + %3 = load i32, ptr %intVar, align 4 + %4 = call i32 (ptr, ...) @printf(ptr @1, i32 %3) + store i16 0, ptr %shortVar, align 2 + %5 = load i16, ptr %shortVar, align 2 %6 = sext i16 %5 to i32 - %7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @2, i32 0, i32 0), i32 %6) - store i64 0, i64* %longVar, align 8 - %8 = load i64, i64* %longVar, align 8 - %9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @3, i32 0, i32 0), i64 %8) - store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @4, i32 0, i32 0), i8** %stringVar, align 8 - %10 = load i8*, i8** %stringVar, align 8 - %11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @5, i32 0, i32 0), i8* %10) - store i8 0, i8* %byteVar, align 1 - %12 = load i8, i8* %byteVar, align 1 + %7 = call i32 (ptr, ...) @printf(ptr @2, i32 %6) + store i64 0, ptr %longVar, align 8 + %8 = load i64, ptr %longVar, align 8 + %9 = call i32 (ptr, ...) @printf(ptr @3, i64 %8) + store ptr @4, ptr %stringVar, align 8 + %10 = load ptr, ptr %stringVar, align 8 + %11 = call i32 (ptr, ...) @printf(ptr @5, ptr %10) + store i8 0, ptr %byteVar, align 1 + %12 = load i8, ptr %byteVar, align 1 %13 = sext i8 %12 to i32 - %14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @6, i32 0, i32 0), i32 %13) - store i8 0, i8* %charVar, align 1 - %15 = load i8, i8* %charVar, align 1 + %14 = call i32 (ptr, ...) @printf(ptr @6, i32 %13) + store i8 0, ptr %charVar, align 1 + %15 = load i8, ptr %charVar, align 1 %16 = sext i8 %15 to i32 - %17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @7, i32 0, i32 0), i32 %16) - store i1 false, i1* %boolVar, align 1 - %18 = load i1, i1* %boolVar, align 1 + %17 = call i32 (ptr, ...) @printf(ptr @7, i32 %16) + store i1 false, ptr %boolVar, align 1 + %18 = load i1, ptr %boolVar, align 1 %19 = zext i1 %18 to i32 - %20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @8, i32 0, i32 0), i32 %19) - %21 = getelementptr inbounds %_s__NestedStruct__int_string, %_s__NestedStruct__int_string* %0, i32 0, i32 0 - store i32 0, i32* %21, align 4 - %22 = getelementptr inbounds %_s__NestedStruct__int_string, %_s__NestedStruct__int_string* %0, i32 0, i32 1 - store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @9, i32 0, i32 0), i8** %22, align 8 - store [4 x %_s__NestedStruct__int_string] [%_s__NestedStruct__int_string { i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @9, i32 0, i32 0) }, %_s__NestedStruct__int_string { i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @9, i32 0, i32 0) }, %_s__NestedStruct__int_string { i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @9, i32 0, i32 0) }, %_s__NestedStruct__int_string { i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @9, i32 0, i32 0) }], [4 x %_s__NestedStruct__int_string]* %structArrayVar, align 8 - %23 = load [4 x %_s__NestedStruct__int_string], [4 x %_s__NestedStruct__int_string]* %structArrayVar, align 8 - %24 = getelementptr inbounds [4 x %_s__NestedStruct__int_string], [4 x %_s__NestedStruct__int_string]* %structArrayVar, i32 0, i32 2 - %25 = getelementptr inbounds [4 x %_s__NestedStruct__int_string], [4 x %_s__NestedStruct__int_string]* %structArrayVar, i32 0, i32 1 - %26 = load %_s__NestedStruct__int_string, %_s__NestedStruct__int_string* %25, align 8 - %27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @10, i32 0, i32 0), %_s__NestedStruct__int_string %26) - %28 = load i32, i32* %result, align 4 + %20 = call i32 (ptr, ...) @printf(ptr @8, i32 %19) + %21 = getelementptr inbounds %_s__NestedStruct__int_string, ptr %0, i32 0, i32 0 + store i32 0, ptr %21, align 4 + %22 = getelementptr inbounds %_s__NestedStruct__int_string, ptr %0, i32 0, i32 1 + store ptr @9, ptr %22, align 8 + store [4 x %_s__NestedStruct__int_string] [%_s__NestedStruct__int_string { i32 0, ptr @9 }, %_s__NestedStruct__int_string { i32 0, ptr @9 }, %_s__NestedStruct__int_string { i32 0, ptr @9 }, %_s__NestedStruct__int_string { i32 0, ptr @9 }], ptr %structArrayVar, align 8 + %23 = load [4 x %_s__NestedStruct__int_string], ptr %structArrayVar, align 8 + %24 = getelementptr inbounds [4 x %_s__NestedStruct__int_string], ptr %structArrayVar, i32 0, i32 2 + %25 = getelementptr inbounds %_s__NestedStruct__int_string, ptr %24, i32 0, i32 1 + %26 = load ptr, ptr %25, align 8 + %27 = call i32 (ptr, ...) @printf(ptr @10, ptr %26) + %28 = load i32, ptr %result, align 4 ret i32 %28 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/variables/success-external-global-var/ir-code.ll b/test/test-files/generator/variables/success-external-global-var/ir-code.ll index ea5e77832..716f8fc33 100644 --- a/test/test-files/generator/variables/success-external-global-var/ir-code.ll +++ b/test/test-files/generator/variables/success-external-global-var/ir-code.ll @@ -4,16 +4,16 @@ target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16 target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [16 x i8] c"Global var: %s\0A\00", align 1 -@GLOBAL = external global i8* +@GLOBAL = external global ptr define i32 @main() { -entry: +entry.l3: %result = alloca i32, align 4 - store i32 0, i32* %result, align 4 - %0 = load i8*, i8** @GLOBAL, align 8 - %1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @0, i32 0, i32 0), i8* %0) - %2 = load i32, i32* %result, align 4 + store i32 0, ptr %result, align 4 + %0 = load ptr, ptr @GLOBAL, align 8 + %1 = call i32 (ptr, ...) @printf(ptr @0, ptr %0) + %2 = load i32, ptr %result, align 4 ret i32 %2 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/variables/success-global-variables/ir-code.ll b/test/test-files/generator/variables/success-global-variables/ir-code.ll index 1dbe9661b..b311e555f 100644 --- a/test/test-files/generator/variables/success-global-variables/ir-code.ll +++ b/test/test-files/generator/variables/success-global-variables/ir-code.ll @@ -4,7 +4,7 @@ target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16 target triple = "x86_64-w64-windows-gnu" @test1 = internal global i32 10 -@test2 = internal global i8* getelementptr inbounds ([12 x i8], [12 x i8]* @0, i32 0, i32 0) +@test2 = internal global ptr @0 @0 = private unnamed_addr constant [12 x i8] c"test string\00", align 1 @test3 = internal global double 5.830000e+00 @test4 = internal global i1 false @@ -12,21 +12,21 @@ target triple = "x86_64-w64-windows-gnu" @2 = private unnamed_addr constant [32 x i8] c"Variable values: %d, %s, %f, %u\00", align 1 define i32 @main() { -entry: +entry.l6: %result = alloca i32, align 4 - store i32 0, i32* %result, align 4 - store i32 11, i32* @test1, align 4 - store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @1, i32 0, i32 0), i8** @test2, align 8 - store double 5.840000e+00, double* @test3, align 8 - store i1 true, i1* @test4, align 1 - %0 = load i32, i32* @test1, align 4 - %1 = load i8*, i8** @test2, align 8 - %2 = load double, double* @test3, align 8 - %3 = load i1, i1* @test4, align 1 + store i32 0, ptr %result, align 4 + store i32 11, ptr @test1, align 4 + store ptr @1, ptr @test2, align 8 + store double 5.840000e+00, ptr @test3, align 8 + store i1 true, ptr @test4, align 1 + %0 = load i32, ptr @test1, align 4 + %1 = load ptr, ptr @test2, align 8 + %2 = load double, ptr @test3, align 8 + %3 = load i1, ptr @test4, align 1 %4 = zext i1 %3 to i32 - %5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @2, i32 0, i32 0), i32 %0, i8* %1, double %2, i32 %4) - %6 = load i32, i32* %result, align 4 + %5 = call i32 (ptr, ...) @printf(ptr @2, i32 %0, ptr %1, double %2, i32 %4) + %6 = load i32, ptr %result, align 4 ret i32 %6 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/while-loops/success-while-loop-break/ir-code-O2.ll b/test/test-files/generator/while-loops/success-while-loop-break/ir-code-O2.ll index 5f2ebc7c2..86d6e95c5 100644 --- a/test/test-files/generator/while-loops/success-while-loop-break/ir-code-O2.ll +++ b/test/test-files/generator/while-loops/success-while-loop-break/ir-code-O2.ll @@ -7,12 +7,12 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #0 { -entry: - %0 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @0, i64 0, i64 0), double 0.000000e+00, i32 10) +entry.l1: + %0 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, double 0.000000e+00, i32 10) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/while-loops/success-while-loop-break/ir-code.ll b/test/test-files/generator/while-loops/success-while-loop-break/ir-code.ll index 5f9cae882..1405ee0d6 100644 --- a/test/test-files/generator/while-loops/success-while-loop-break/ir-code.ll +++ b/test/test-files/generator/while-loops/success-while-loop-break/ir-code.ll @@ -6,7 +6,7 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [22 x i8] c"Outer: %f, inner: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %loopCounterOuter = alloca double, align 8 %0 = alloca i1, align 1 @@ -14,59 +14,59 @@ entry: %loopCounterInner = alloca i16, align 2 %2 = alloca i1, align 1 %3 = alloca i16, align 2 - store i32 0, i32* %result, align 4 - store double 0.000000e+00, double* %loopCounterOuter, align 8 - br label %while.cond + store i32 0, ptr %result, align 4 + store double 0.000000e+00, ptr %loopCounterOuter, align 8 + br label %while.cond.l3 -while.cond: ; preds = %if.end, %entry - %4 = load double, double* %loopCounterOuter, align 8 +while.cond.l3: ; preds = %if.end.l4, %entry.l1 + %4 = load double, ptr %loopCounterOuter, align 8 %5 = fcmp olt double %4, 1.000000e+01 - store i1 %5, i1* %0, align 1 - %6 = load i1, i1* %0, align 1 - br i1 %6, label %while, label %while.end3 + store i1 %5, ptr %0, align 1 + %6 = load i1, ptr %0, align 1 + br i1 %6, label %while.l3, label %while.end.l3 -while: ; preds = %while.cond - %7 = load double, double* %loopCounterOuter, align 8 +while.l3: ; preds = %while.cond.l3 + %7 = load double, ptr %loopCounterOuter, align 8 %8 = fcmp olt double %7, 4.000000e+00 - store i1 %8, i1* %1, align 1 - %9 = load i1, i1* %1, align 1 - br i1 %9, label %if.then, label %if.end + store i1 %8, ptr %1, align 1 + %9 = load i1, ptr %1, align 1 + br i1 %9, label %if.then.l4, label %if.end.l4 -if.then: ; preds = %while - store i16 10, i16* %loopCounterInner, align 2 - br label %while.cond1 +if.then.l4: ; preds = %while.l3 + store i16 10, ptr %loopCounterInner, align 2 + br label %while.cond.l6 -while.cond1: ; preds = %if.then - %10 = load i16, i16* %loopCounterInner, align 2 +while.cond.l6: ; preds = %if.then.l4 + %10 = load i16, ptr %loopCounterInner, align 2 %11 = sext i16 %10 to i32 %12 = icmp sgt i32 %11, 0 - store i1 %12, i1* %2, align 1 - %13 = load i1, i1* %2, align 1 - br i1 %13, label %while2, label %while.end + store i1 %12, ptr %2, align 1 + %13 = load i1, ptr %2, align 1 + br i1 %13, label %while.l6, label %while.end.l6 -while2: ; preds = %while.cond1 - %14 = load double, double* %loopCounterOuter, align 8 - %15 = load i16, i16* %loopCounterInner, align 2 +while.l6: ; preds = %while.cond.l6 + %14 = load double, ptr %loopCounterOuter, align 8 + %15 = load i16, ptr %loopCounterInner, align 2 %16 = sext i16 %15 to i32 - %17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @0, i32 0, i32 0), double %14, i32 %16) - %18 = load i16, i16* %loopCounterInner, align 2 + %17 = call i32 (ptr, ...) @printf(ptr @0, double %14, i32 %16) + %18 = load i16, ptr %loopCounterInner, align 2 %19 = sub i16 %18, 1 - store i16 %19, i16* %loopCounterInner, align 2 - store i16 %18, i16* %3, align 2 - br label %while.end3 + store i16 %19, ptr %loopCounterInner, align 2 + store i16 %18, ptr %3, align 2 + br label %while.end.l3 -while.end: ; preds = %while.cond1 - br label %if.end +while.end.l6: ; preds = %while.cond.l6 + br label %if.end.l4 -if.end: ; preds = %while.end, %while - %20 = load double, double* %loopCounterOuter, align 8 +if.end.l4: ; preds = %while.end.l6, %while.l3 + %20 = load double, ptr %loopCounterOuter, align 8 %21 = fadd double %20, 1.500000e-01 - store double %21, double* %loopCounterOuter, align 8 - br label %while.cond + store double %21, ptr %loopCounterOuter, align 8 + br label %while.cond.l3 -while.end3: ; preds = %while2, %while.cond - %22 = load i32, i32* %result, align 4 +while.end.l3: ; preds = %while.l6, %while.cond.l3 + %22 = load i32, ptr %result, align 4 ret i32 %22 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/while-loops/success-while-loop-continue/ir-code-O2.ll b/test/test-files/generator/while-loops/success-while-loop-continue/ir-code-O2.ll index 0b11f4262..093e6896e 100644 --- a/test/test-files/generator/while-loops/success-while-loop-continue/ir-code-O2.ll +++ b/test/test-files/generator/while-loops/success-while-loop-continue/ir-code-O2.ll @@ -7,32 +7,32 @@ target triple = "x86_64-w64-windows-gnu" ; Function Attrs: nofree nounwind define i32 @main() local_unnamed_addr #0 { -entry: - br label %while +entry.l1: + br label %while.l3 -while: ; preds = %entry, %while.cond.backedge - %loopCounterOuter.016 = phi double [ 0.000000e+00, %entry ], [ %0, %while.cond.backedge ] - %0 = fadd double %loopCounterOuter.016, 1.500000e-01 +while.l3: ; preds = %entry.l1, %while.cond.l3.backedge + %loopCounterOuter.011 = phi double [ 0.000000e+00, %entry.l1 ], [ %0, %while.cond.l3.backedge ] + %0 = fadd double %loopCounterOuter.011, 1.500000e-01 %1 = fcmp olt double %0, 4.000000e+00 - br i1 %1, label %while.cond.backedge.loopexit, label %while.cond.backedge + br i1 %1, label %while.cond.l3.backedge.loopexit, label %while.cond.l3.backedge -while.cond.backedge.loopexit: ; preds = %while - %2 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @0, i64 0, i64 0), double %0, i32 10) - %3 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @0, i64 0, i64 0), double %0, i32 9) - %4 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @0, i64 0, i64 0), double %0, i32 8) - %5 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @0, i64 0, i64 0), double %0, i32 7) - %6 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @0, i64 0, i64 0), double %0, i32 6) - br label %while.cond.backedge +while.cond.l3.backedge.loopexit: ; preds = %while.l3 + %2 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, double %0, i32 10) + %3 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, double %0, i32 9) + %4 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, double %0, i32 8) + %5 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, double %0, i32 7) + %6 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, double %0, i32 6) + br label %while.cond.l3.backedge -while.cond.backedge: ; preds = %while.cond.backedge.loopexit, %while +while.cond.l3.backedge: ; preds = %while.cond.l3.backedge.loopexit, %while.l3 %7 = fcmp olt double %0, 1.000000e+01 - br i1 %7, label %while, label %while.end5 + br i1 %7, label %while.l3, label %while.end.l3 -while.end5: ; preds = %while.cond.backedge +while.end.l3: ; preds = %while.cond.l3.backedge ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 attributes #0 = { nofree nounwind } diff --git a/test/test-files/generator/while-loops/success-while-loop-continue/ir-code.ll b/test/test-files/generator/while-loops/success-while-loop-continue/ir-code.ll index 2a9571ecf..e02520015 100644 --- a/test/test-files/generator/while-loops/success-while-loop-continue/ir-code.ll +++ b/test/test-files/generator/while-loops/success-while-loop-continue/ir-code.ll @@ -6,7 +6,7 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [22 x i8] c"Outer: %f, inner: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %loopCounterOuter = alloca double, align 8 %0 = alloca i1, align 1 @@ -15,70 +15,70 @@ entry: %2 = alloca i1, align 1 %3 = alloca i16, align 2 %4 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - store double 0.000000e+00, double* %loopCounterOuter, align 8 - br label %while.cond + store i32 0, ptr %result, align 4 + store double 0.000000e+00, ptr %loopCounterOuter, align 8 + br label %while.cond.l3 -while.cond: ; preds = %if.end4, %if.then3, %entry - %5 = load double, double* %loopCounterOuter, align 8 +while.cond.l3: ; preds = %if.end.l5, %if.then.l10, %entry.l1 + %5 = load double, ptr %loopCounterOuter, align 8 %6 = fcmp olt double %5, 1.000000e+01 - store i1 %6, i1* %0, align 1 - %7 = load i1, i1* %0, align 1 - br i1 %7, label %while, label %while.end5 + store i1 %6, ptr %0, align 1 + %7 = load i1, ptr %0, align 1 + br i1 %7, label %while.l3, label %while.end.l3 -while: ; preds = %while.cond - %8 = load double, double* %loopCounterOuter, align 8 +while.l3: ; preds = %while.cond.l3 + %8 = load double, ptr %loopCounterOuter, align 8 %9 = fadd double %8, 1.500000e-01 - store double %9, double* %loopCounterOuter, align 8 - %10 = load double, double* %loopCounterOuter, align 8 + store double %9, ptr %loopCounterOuter, align 8 + %10 = load double, ptr %loopCounterOuter, align 8 %11 = fcmp olt double %10, 4.000000e+00 - store i1 %11, i1* %1, align 1 - %12 = load i1, i1* %1, align 1 - br i1 %12, label %if.then, label %if.end4 + store i1 %11, ptr %1, align 1 + %12 = load i1, ptr %1, align 1 + br i1 %12, label %if.then.l5, label %if.end.l5 -if.then: ; preds = %while - store i16 10, i16* %loopCounterInner, align 2 - br label %while.cond1 +if.then.l5: ; preds = %while.l3 + store i16 10, ptr %loopCounterInner, align 2 + br label %while.cond.l7 -while.cond1: ; preds = %if.end, %if.then - %13 = load i16, i16* %loopCounterInner, align 2 +while.cond.l7: ; preds = %if.end.l10, %if.then.l5 + %13 = load i16, ptr %loopCounterInner, align 2 %14 = sext i16 %13 to i32 %15 = icmp sgt i32 %14, 0 - store i1 %15, i1* %2, align 1 - %16 = load i1, i1* %2, align 1 - br i1 %16, label %while2, label %while.end + store i1 %15, ptr %2, align 1 + %16 = load i1, ptr %2, align 1 + br i1 %16, label %while.l7, label %while.end.l7 -while2: ; preds = %while.cond1 - %17 = load double, double* %loopCounterOuter, align 8 - %18 = load i16, i16* %loopCounterInner, align 2 +while.l7: ; preds = %while.cond.l7 + %17 = load double, ptr %loopCounterOuter, align 8 + %18 = load i16, ptr %loopCounterInner, align 2 %19 = sext i16 %18 to i32 - %20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @0, i32 0, i32 0), double %17, i32 %19) - %21 = load i16, i16* %loopCounterInner, align 2 + %20 = call i32 (ptr, ...) @printf(ptr @0, double %17, i32 %19) + %21 = load i16, ptr %loopCounterInner, align 2 %22 = sub i16 %21, 1 - store i16 %22, i16* %loopCounterInner, align 2 - store i16 %21, i16* %3, align 2 - %23 = load i16, i16* %loopCounterInner, align 2 + store i16 %22, ptr %loopCounterInner, align 2 + store i16 %21, ptr %3, align 2 + %23 = load i16, ptr %loopCounterInner, align 2 %24 = sext i16 %23 to i32 %25 = icmp eq i32 %24, 5 - store i1 %25, i1* %4, align 1 - %26 = load i1, i1* %4, align 1 - br i1 %26, label %if.then3, label %if.end + store i1 %25, ptr %4, align 1 + %26 = load i1, ptr %4, align 1 + br i1 %26, label %if.then.l10, label %if.end.l10 -if.then3: ; preds = %while2 - br label %while.cond +if.then.l10: ; preds = %while.l7 + br label %while.cond.l3 -if.end: ; preds = %while2 - br label %while.cond1 +if.end.l10: ; preds = %while.l7 + br label %while.cond.l7 -while.end: ; preds = %while.cond1 - br label %if.end4 +while.end.l7: ; preds = %while.cond.l7 + br label %if.end.l5 -if.end4: ; preds = %while.end, %while - br label %while.cond +if.end.l5: ; preds = %while.end.l7, %while.l3 + br label %while.cond.l3 -while.end5: ; preds = %while.cond - %27 = load i32, i32* %result, align 4 +while.end.l3: ; preds = %while.cond.l3 + %27 = load i32, ptr %result, align 4 ret i32 %27 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/generator/while-loops/success-while-loop/ir-code.ll b/test/test-files/generator/while-loops/success-while-loop/ir-code.ll index 47d2dbbde..05259587c 100644 --- a/test/test-files/generator/while-loops/success-while-loop/ir-code.ll +++ b/test/test-files/generator/while-loops/success-while-loop/ir-code.ll @@ -6,32 +6,32 @@ target triple = "x86_64-w64-windows-gnu" @0 = private unnamed_addr constant [17 x i8] c"i is now at: %d\0A\00", align 1 define i32 @main() { -entry: +entry.l1: %result = alloca i32, align 4 %i = alloca i32, align 4 %0 = alloca i1, align 1 - store i32 0, i32* %result, align 4 - store i32 0, i32* %i, align 4 - br label %while.cond + store i32 0, ptr %result, align 4 + store i32 0, ptr %i, align 4 + br label %while.cond.l3 -while.cond: ; preds = %while, %entry - %1 = load i32, i32* %i, align 4 +while.cond.l3: ; preds = %while.l3, %entry.l1 + %1 = load i32, ptr %i, align 4 %2 = icmp slt i32 %1, 10 - store i1 %2, i1* %0, align 1 - %3 = load i1, i1* %0, align 1 - br i1 %3, label %while, label %while.end + store i1 %2, ptr %0, align 1 + %3 = load i1, ptr %0, align 1 + br i1 %3, label %while.l3, label %while.end.l3 -while: ; preds = %while.cond - %4 = load i32, i32* %i, align 4 +while.l3: ; preds = %while.cond.l3 + %4 = load i32, ptr %i, align 4 %5 = add i32 %4, 1 - store i32 %5, i32* %i, align 4 - %6 = load i32, i32* %i, align 4 - %7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @0, i32 0, i32 0), i32 %6) - br label %while.cond + store i32 %5, ptr %i, align 4 + %6 = load i32, ptr %i, align 4 + %7 = call i32 (ptr, ...) @printf(ptr @0, i32 %6) + br label %while.cond.l3 -while.end: ; preds = %while.cond - %8 = load i32, i32* %result, align 4 +while.end.l3: ; preds = %while.cond.l3 + %8 = load i32, ptr %result, align 4 ret i32 %8 } -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/test/test-files/std/data/pair-normal-usecase/ir-code-O2.ll b/test/test-files/std/data/pair-normal-usecase/ir-code-O2.ll index 287e23c26..8a56bf37e 100644 --- a/test/test-files/std/data/pair-normal-usecase/ir-code-O2.ll +++ b/test/test-files/std/data/pair-normal-usecase/ir-code-O2.ll @@ -3,30 +3,30 @@ source_filename = "source.spice" target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-w64-windows-gnu" -%_s__string_int__Pair__string_int = type { i8*, i32 } +%_s__string_int__Pair__string_int = type { ptr, i32 } @0 = private unnamed_addr constant [5 x i8] c"Test\00", align 1 @1 = private unnamed_addr constant [11 x i8] c"First: %s\0A\00", align 1 @2 = private unnamed_addr constant [12 x i8] c"Second: %d\0A\00", align 1 define i32 @main() local_unnamed_addr { -entry: +entry.l3: %stringIntPair = alloca %_s__string_int__Pair__string_int, align 8 - call void @_mp__Pair_string_int__ctor__string_int(%_s__string_int__Pair__string_int* nonnull %stringIntPair, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @0, i64 0, i64 0), i32 1234) - %0 = call i8* @_mf__Pair_string_int__getFirst(%_s__string_int__Pair__string_int* nonnull %stringIntPair) - %1 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @1, i64 0, i64 0), i8* %0) - %2 = call i32 @_mf__Pair_string_int__getSecond(%_s__string_int__Pair__string_int* nonnull %stringIntPair) - %3 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @2, i64 0, i64 0), i32 %2) + call void @_mp__Pair_string_int__ctor__string_int(ptr nonnull %stringIntPair, ptr nonnull @0, i32 1234) + %0 = call ptr @_mf__Pair_string_int__getFirst(ptr nonnull %stringIntPair) + %1 = call i32 (ptr, ...) @printf(ptr nonnull @1, ptr %0) + %2 = call i32 @_mf__Pair_string_int__getSecond(ptr nonnull %stringIntPair) + %3 = call i32 (ptr, ...) @printf(ptr nonnull @2, i32 %2) ret i32 0 } -declare void @_mp__Pair_string_int__ctor__string_int(%_s__string_int__Pair__string_int*, i8*, i32) local_unnamed_addr +declare void @_mp__Pair_string_int__ctor__string_int(ptr, ptr, i32) local_unnamed_addr ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 -declare i8* @_mf__Pair_string_int__getFirst(%_s__string_int__Pair__string_int*) local_unnamed_addr +declare ptr @_mf__Pair_string_int__getFirst(ptr) local_unnamed_addr -declare i32 @_mf__Pair_string_int__getSecond(%_s__string_int__Pair__string_int*) local_unnamed_addr +declare i32 @_mf__Pair_string_int__getSecond(ptr) local_unnamed_addr attributes #0 = { nofree nounwind } diff --git a/test/test-files/std/data/queue-normal-usecase/ir-code-O2.ll b/test/test-files/std/data/queue-normal-usecase/ir-code-O2.ll index 4784a4dd1..6ed25e563 100644 --- a/test/test-files/std/data/queue-normal-usecase/ir-code-O2.ll +++ b/test/test-files/std/data/queue-normal-usecase/ir-code-O2.ll @@ -3,54 +3,54 @@ source_filename = "source.spice" target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-w64-windows-gnu" -%_s__char__Queue__charptr_long_long_long_long_int = type { i8*, i64, i64, i64, i64, i32 } +%_s__char__Queue__charptr_long_long_long_long_int = type { ptr, i64, i64, i64, i64, i32 } @0 = private unnamed_addr constant [24 x i8] c"Size: %d, Capacity: %d\0A\00", align 1 define i32 @main() local_unnamed_addr { -entry: +entry.l3: %q1 = alloca %_s__char__Queue__charptr_long_long_long_long_int, align 8 - call void @_mp__Queue_char__ctor(%_s__char__Queue__charptr_long_long_long_long_int* nonnull %q1) - call void @_mp__Queue_char__push__char(%_s__char__Queue__charptr_long_long_long_long_int* nonnull %q1, i8 72) - call void @_mp__Queue_char__push__char(%_s__char__Queue__charptr_long_long_long_long_int* nonnull %q1, i8 101) - call void @_mp__Queue_char__push__char(%_s__char__Queue__charptr_long_long_long_long_int* nonnull %q1, i8 108) - call void @_mp__Queue_char__push__char(%_s__char__Queue__charptr_long_long_long_long_int* nonnull %q1, i8 108) - call void @_mp__Queue_char__push__char(%_s__char__Queue__charptr_long_long_long_long_int* nonnull %q1, i8 111) - call void @_mp__Queue_char__push__char(%_s__char__Queue__charptr_long_long_long_long_int* nonnull %q1, i8 33) - %0 = call i64 @_mf__Queue_char__getSize(%_s__char__Queue__charptr_long_long_long_long_int* nonnull %q1) - %1 = call i64 @_mf__Queue_char__getCapacity(%_s__char__Queue__charptr_long_long_long_long_int* nonnull %q1) - %2 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @0, i64 0, i64 0), i64 %0, i64 %1) - %3 = call i1 @_mf__Queue_char__isEmpty(%_s__char__Queue__charptr_long_long_long_long_int* nonnull %q1) - br i1 %3, label %cleanup, label %while - -while: ; preds = %entry, %while - %4 = call i8 @_mf__Queue_char__pop(%_s__char__Queue__charptr_long_long_long_long_int* nonnull %q1) + call void @_mp__Queue_char__ctor(ptr nonnull %q1) + call void @_mp__Queue_char__push__char(ptr nonnull %q1, i8 72) + call void @_mp__Queue_char__push__char(ptr nonnull %q1, i8 101) + call void @_mp__Queue_char__push__char(ptr nonnull %q1, i8 108) + call void @_mp__Queue_char__push__char(ptr nonnull %q1, i8 108) + call void @_mp__Queue_char__push__char(ptr nonnull %q1, i8 111) + call void @_mp__Queue_char__push__char(ptr nonnull %q1, i8 33) + %0 = call i64 @_mf__Queue_char__getSize(ptr nonnull %q1) + %1 = call i64 @_mf__Queue_char__getCapacity(ptr nonnull %q1) + %2 = call i32 (ptr, ...) @printf(ptr nonnull @0, i64 %0, i64 %1) + %3 = call i1 @_mf__Queue_char__isEmpty(ptr nonnull %q1) + br i1 %3, label %cleanup.l3, label %while.l12 + +while.l12: ; preds = %entry.l3, %while.l12 + %4 = call i8 @_mf__Queue_char__pop(ptr nonnull %q1) %5 = sext i8 %4 to i32 %putchar = call i32 @putchar(i32 %5) - %6 = call i1 @_mf__Queue_char__isEmpty(%_s__char__Queue__charptr_long_long_long_long_int* nonnull %q1) - br i1 %6, label %cleanup, label %while + %6 = call i1 @_mf__Queue_char__isEmpty(ptr nonnull %q1) + br i1 %6, label %cleanup.l3, label %while.l12 -cleanup: ; preds = %while, %entry - call void @_mp__Queue_char__dtor(%_s__char__Queue__charptr_long_long_long_long_int* nonnull %q1) +cleanup.l3: ; preds = %while.l12, %entry.l3 + call void @_mp__Queue_char__dtor(ptr nonnull %q1) ret i32 0 } -declare void @_mp__Queue_char__ctor(%_s__char__Queue__charptr_long_long_long_long_int*) local_unnamed_addr +declare void @_mp__Queue_char__ctor(ptr) local_unnamed_addr -declare void @_mp__Queue_char__push__char(%_s__char__Queue__charptr_long_long_long_long_int*, i8) local_unnamed_addr +declare void @_mp__Queue_char__push__char(ptr, i8) local_unnamed_addr ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 -declare i64 @_mf__Queue_char__getSize(%_s__char__Queue__charptr_long_long_long_long_int*) local_unnamed_addr +declare i64 @_mf__Queue_char__getSize(ptr) local_unnamed_addr -declare i64 @_mf__Queue_char__getCapacity(%_s__char__Queue__charptr_long_long_long_long_int*) local_unnamed_addr +declare i64 @_mf__Queue_char__getCapacity(ptr) local_unnamed_addr -declare i1 @_mf__Queue_char__isEmpty(%_s__char__Queue__charptr_long_long_long_long_int*) local_unnamed_addr +declare i1 @_mf__Queue_char__isEmpty(ptr) local_unnamed_addr -declare i8 @_mf__Queue_char__pop(%_s__char__Queue__charptr_long_long_long_long_int*) local_unnamed_addr +declare i8 @_mf__Queue_char__pop(ptr) local_unnamed_addr -declare void @_mp__Queue_char__dtor(%_s__char__Queue__charptr_long_long_long_long_int*) local_unnamed_addr +declare void @_mp__Queue_char__dtor(ptr) local_unnamed_addr ; Function Attrs: nofree nounwind declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #0 diff --git a/test/test-files/std/data/stack-normal-usecase/ir-code-O2.ll b/test/test-files/std/data/stack-normal-usecase/ir-code-O2.ll index 790713999..c9e6d45b1 100644 --- a/test/test-files/std/data/stack-normal-usecase/ir-code-O2.ll +++ b/test/test-files/std/data/stack-normal-usecase/ir-code-O2.ll @@ -3,7 +3,7 @@ source_filename = "source.spice" target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-w64-windows-gnu" -%_s__int__Stack__intptr_long_long_int = type { i32*, i64, i64, i32 } +%_s__int__Stack__intptr_long_long_int = type { ptr, i64, i64, i32 } @0 = private unnamed_addr constant [16 x i8] c"Stack size: %d\0A\00", align 1 @1 = private unnamed_addr constant [20 x i8] c"Stack capacity: %d\0A\00", align 1 @@ -12,39 +12,39 @@ target triple = "x86_64-w64-windows-gnu" @4 = private unnamed_addr constant [18 x i8] c"Stack item 1: %d\0A\00", align 1 define i32 @main() local_unnamed_addr { -entry: +entry.l3: %0 = alloca %_s__int__Stack__intptr_long_long_int, align 8 - call void @_mp__Stack_int__ctor(%_s__int__Stack__intptr_long_long_int* nonnull %0) - call void @_mp__Stack_int__push__int(%_s__int__Stack__intptr_long_long_int* nonnull %0, i32 123) - call void @_mp__Stack_int__push__int(%_s__int__Stack__intptr_long_long_int* nonnull %0, i32 456) - call void @_mp__Stack_int__push__int(%_s__int__Stack__intptr_long_long_int* nonnull %0, i32 789) - %1 = call i64 @_mf__Stack_int__getSize(%_s__int__Stack__intptr_long_long_int* nonnull %0) - %2 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @0, i64 0, i64 0), i64 %1) - %3 = call i64 @_mf__Stack_int__getCapacity(%_s__int__Stack__intptr_long_long_int* nonnull %0) - %4 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @1, i64 0, i64 0), i64 %3) - %5 = call i32 @_mf__Stack_int__pop(%_s__int__Stack__intptr_long_long_int* nonnull %0) - %6 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @2, i64 0, i64 0), i32 %5) - %7 = call i32 @_mf__Stack_int__pop(%_s__int__Stack__intptr_long_long_int* nonnull %0) - %8 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @3, i64 0, i64 0), i32 %7) - %9 = call i32 @_mf__Stack_int__pop(%_s__int__Stack__intptr_long_long_int* nonnull %0) - %10 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @4, i64 0, i64 0), i32 %9) - call void @_mp__Stack_int__dtor(%_s__int__Stack__intptr_long_long_int* nonnull %0) + call void @_mp__Stack_int__ctor(ptr nonnull %0) + call void @_mp__Stack_int__push__int(ptr nonnull %0, i32 123) + call void @_mp__Stack_int__push__int(ptr nonnull %0, i32 456) + call void @_mp__Stack_int__push__int(ptr nonnull %0, i32 789) + %1 = call i64 @_mf__Stack_int__getSize(ptr nonnull %0) + %2 = call i32 (ptr, ...) @printf(ptr nonnull @0, i64 %1) + %3 = call i64 @_mf__Stack_int__getCapacity(ptr nonnull %0) + %4 = call i32 (ptr, ...) @printf(ptr nonnull @1, i64 %3) + %5 = call i32 @_mf__Stack_int__pop(ptr nonnull %0) + %6 = call i32 (ptr, ...) @printf(ptr nonnull @2, i32 %5) + %7 = call i32 @_mf__Stack_int__pop(ptr nonnull %0) + %8 = call i32 (ptr, ...) @printf(ptr nonnull @3, i32 %7) + %9 = call i32 @_mf__Stack_int__pop(ptr nonnull %0) + %10 = call i32 (ptr, ...) @printf(ptr nonnull @4, i32 %9) + call void @_mp__Stack_int__dtor(ptr nonnull %0) ret i32 0 } -declare void @_mp__Stack_int__ctor(%_s__int__Stack__intptr_long_long_int*) local_unnamed_addr +declare void @_mp__Stack_int__ctor(ptr) local_unnamed_addr -declare void @_mp__Stack_int__push__int(%_s__int__Stack__intptr_long_long_int*, i32) local_unnamed_addr +declare void @_mp__Stack_int__push__int(ptr, i32) local_unnamed_addr ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 -declare i64 @_mf__Stack_int__getSize(%_s__int__Stack__intptr_long_long_int*) local_unnamed_addr +declare i64 @_mf__Stack_int__getSize(ptr) local_unnamed_addr -declare i64 @_mf__Stack_int__getCapacity(%_s__int__Stack__intptr_long_long_int*) local_unnamed_addr +declare i64 @_mf__Stack_int__getCapacity(ptr) local_unnamed_addr -declare i32 @_mf__Stack_int__pop(%_s__int__Stack__intptr_long_long_int*) local_unnamed_addr +declare i32 @_mf__Stack_int__pop(ptr) local_unnamed_addr -declare void @_mp__Stack_int__dtor(%_s__int__Stack__intptr_long_long_int*) local_unnamed_addr +declare void @_mp__Stack_int__dtor(ptr) local_unnamed_addr attributes #0 = { nofree nounwind } diff --git a/test/test-files/std/data/triple-normal-usecase/ir-code-O2.ll b/test/test-files/std/data/triple-normal-usecase/ir-code-O2.ll index cca3cf047..313f30b21 100644 --- a/test/test-files/std/data/triple-normal-usecase/ir-code-O2.ll +++ b/test/test-files/std/data/triple-normal-usecase/ir-code-O2.ll @@ -3,7 +3,7 @@ source_filename = "source.spice" target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-w64-windows-gnu" -%_s__string_int_bool__Triple__string_int_bool = type { i8*, i32, i1 } +%_s__string_int_bool__Triple__string_int_bool = type { ptr, i32, i1 } @0 = private unnamed_addr constant [5 x i8] c"Test\00", align 1 @1 = private unnamed_addr constant [11 x i8] c"First: %s\0A\00", align 1 @@ -11,28 +11,28 @@ target triple = "x86_64-w64-windows-gnu" @3 = private unnamed_addr constant [11 x i8] c"Third: %d\0A\00", align 1 define i32 @main() local_unnamed_addr { -entry: +entry.l3: %stringIntBoolTriple = alloca %_s__string_int_bool__Triple__string_int_bool, align 8 - call void @_mp__Triple_string_int_bool__ctor__string_int_bool(%_s__string_int_bool__Triple__string_int_bool* nonnull %stringIntBoolTriple, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @0, i64 0, i64 0), i32 1234, i1 true) - %0 = call i8* @_mf__Triple_string_int_bool__getFirst(%_s__string_int_bool__Triple__string_int_bool* nonnull %stringIntBoolTriple) - %1 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @1, i64 0, i64 0), i8* %0) - %2 = call i32 @_mf__Triple_string_int_bool__getSecond(%_s__string_int_bool__Triple__string_int_bool* nonnull %stringIntBoolTriple) - %3 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @2, i64 0, i64 0), i32 %2) - %4 = call i1 @_mf__Triple_string_int_bool__getThird(%_s__string_int_bool__Triple__string_int_bool* nonnull %stringIntBoolTriple) + call void @_mp__Triple_string_int_bool__ctor__string_int_bool(ptr nonnull %stringIntBoolTriple, ptr nonnull @0, i32 1234, i1 true) + %0 = call ptr @_mf__Triple_string_int_bool__getFirst(ptr nonnull %stringIntBoolTriple) + %1 = call i32 (ptr, ...) @printf(ptr nonnull @1, ptr %0) + %2 = call i32 @_mf__Triple_string_int_bool__getSecond(ptr nonnull %stringIntBoolTriple) + %3 = call i32 (ptr, ...) @printf(ptr nonnull @2, i32 %2) + %4 = call i1 @_mf__Triple_string_int_bool__getThird(ptr nonnull %stringIntBoolTriple) %5 = zext i1 %4 to i32 - %6 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @3, i64 0, i64 0), i32 %5) + %6 = call i32 (ptr, ...) @printf(ptr nonnull @3, i32 %5) ret i32 0 } -declare void @_mp__Triple_string_int_bool__ctor__string_int_bool(%_s__string_int_bool__Triple__string_int_bool*, i8*, i32, i1) local_unnamed_addr +declare void @_mp__Triple_string_int_bool__ctor__string_int_bool(ptr, ptr, i32, i1) local_unnamed_addr ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 -declare i8* @_mf__Triple_string_int_bool__getFirst(%_s__string_int_bool__Triple__string_int_bool*) local_unnamed_addr +declare ptr @_mf__Triple_string_int_bool__getFirst(ptr) local_unnamed_addr -declare i32 @_mf__Triple_string_int_bool__getSecond(%_s__string_int_bool__Triple__string_int_bool*) local_unnamed_addr +declare i32 @_mf__Triple_string_int_bool__getSecond(ptr) local_unnamed_addr -declare i1 @_mf__Triple_string_int_bool__getThird(%_s__string_int_bool__Triple__string_int_bool*) local_unnamed_addr +declare i1 @_mf__Triple_string_int_bool__getThird(ptr) local_unnamed_addr attributes #0 = { nofree nounwind } diff --git a/test/test-files/std/data/vector-normal-usecase/ir-code-O2.ll b/test/test-files/std/data/vector-normal-usecase/ir-code-O2.ll index e18ceeeec..13b3b6573 100644 --- a/test/test-files/std/data/vector-normal-usecase/ir-code-O2.ll +++ b/test/test-files/std/data/vector-normal-usecase/ir-code-O2.ll @@ -3,46 +3,46 @@ source_filename = "source.spice" target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-w64-windows-gnu" -%_s__double__Vector__doubleptr_long_long_int = type { double*, i64, i64, i32 } +%_s__double__Vector__doubleptr_long_long_int = type { ptr, i64, i64, i32 } @0 = private unnamed_addr constant [17 x i8] c"Vector size: %d\0A\00", align 1 @1 = private unnamed_addr constant [21 x i8] c"Vector capacity: %d\0A\00", align 1 @2 = private unnamed_addr constant [19 x i8] c"Vector item 5: %f\0A\00", align 1 define i32 @main() local_unnamed_addr { -entry: +entry.l3: %v1 = alloca %_s__double__Vector__doubleptr_long_long_int, align 8 - call void @_mp__Vector_double__ctor__int(%_s__double__Vector__doubleptr_long_long_int* nonnull %v1, i32 3) - call void @_mp__Vector_double__pushBack__double(%_s__double__Vector__doubleptr_long_long_int* nonnull %v1, double 1.200000e+00) - call void @_mp__Vector_double__pushBack__double(%_s__double__Vector__doubleptr_long_long_int* nonnull %v1, double 0x401DFC5FF5331D64) - call void @_mp__Vector_double__pushBack__double(%_s__double__Vector__doubleptr_long_long_int* nonnull %v1, double 5.300000e+00) - call void @_mp__Vector_double__pushBack__double(%_s__double__Vector__doubleptr_long_long_int* nonnull %v1, double 0xC10D2BF1D70A3D71) - call void @_mp__Vector_double__pushBack__double(%_s__double__Vector__doubleptr_long_long_int* nonnull %v1, double 2.323420e+04) - call void @_mp__Vector_double__pushBack__double(%_s__double__Vector__doubleptr_long_long_int* nonnull %v1, double -1.234900e+03) - call void @_mp__Vector_double__pushBack__double(%_s__double__Vector__doubleptr_long_long_int* nonnull %v1, double 0.000000e+00) - %0 = call i64 @_mf__Vector_double__getSize(%_s__double__Vector__doubleptr_long_long_int* nonnull %v1) - %1 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @0, i64 0, i64 0), i64 %0) - %2 = call i64 @_mf__Vector_double__getCapacity(%_s__double__Vector__doubleptr_long_long_int* nonnull %v1) - %3 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @1, i64 0, i64 0), i64 %2) - %4 = call double @_mf__Vector_double__get__int(%_s__double__Vector__doubleptr_long_long_int* nonnull %v1, i32 5) - %5 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @2, i64 0, i64 0), double %4) - call void @_mp__Vector_double__dtor(%_s__double__Vector__doubleptr_long_long_int* nonnull %v1) + call void @_mp__Vector_double__ctor__int(ptr nonnull %v1, i32 3) + call void @_mp__Vector_double__pushBack__double(ptr nonnull %v1, double 1.200000e+00) + call void @_mp__Vector_double__pushBack__double(ptr nonnull %v1, double 0x401DFC5FF5331D64) + call void @_mp__Vector_double__pushBack__double(ptr nonnull %v1, double 5.300000e+00) + call void @_mp__Vector_double__pushBack__double(ptr nonnull %v1, double 0xC10D2BF1D70A3D71) + call void @_mp__Vector_double__pushBack__double(ptr nonnull %v1, double 2.323420e+04) + call void @_mp__Vector_double__pushBack__double(ptr nonnull %v1, double -1.234900e+03) + call void @_mp__Vector_double__pushBack__double(ptr nonnull %v1, double 0.000000e+00) + %0 = call i64 @_mf__Vector_double__getSize(ptr nonnull %v1) + %1 = call i32 (ptr, ...) @printf(ptr nonnull @0, i64 %0) + %2 = call i64 @_mf__Vector_double__getCapacity(ptr nonnull %v1) + %3 = call i32 (ptr, ...) @printf(ptr nonnull @1, i64 %2) + %4 = call double @_mf__Vector_double__get__int(ptr nonnull %v1, i32 5) + %5 = call i32 (ptr, ...) @printf(ptr nonnull @2, double %4) + call void @_mp__Vector_double__dtor(ptr nonnull %v1) ret i32 0 } -declare void @_mp__Vector_double__ctor__int(%_s__double__Vector__doubleptr_long_long_int*, i32) local_unnamed_addr +declare void @_mp__Vector_double__ctor__int(ptr, i32) local_unnamed_addr -declare void @_mp__Vector_double__pushBack__double(%_s__double__Vector__doubleptr_long_long_int*, double) local_unnamed_addr +declare void @_mp__Vector_double__pushBack__double(ptr, double) local_unnamed_addr ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 -declare i64 @_mf__Vector_double__getSize(%_s__double__Vector__doubleptr_long_long_int*) local_unnamed_addr +declare i64 @_mf__Vector_double__getSize(ptr) local_unnamed_addr -declare i64 @_mf__Vector_double__getCapacity(%_s__double__Vector__doubleptr_long_long_int*) local_unnamed_addr +declare i64 @_mf__Vector_double__getCapacity(ptr) local_unnamed_addr -declare double @_mf__Vector_double__get__int(%_s__double__Vector__doubleptr_long_long_int*, i32) local_unnamed_addr +declare double @_mf__Vector_double__get__int(ptr, i32) local_unnamed_addr -declare void @_mp__Vector_double__dtor(%_s__double__Vector__doubleptr_long_long_int*) local_unnamed_addr +declare void @_mp__Vector_double__dtor(ptr) local_unnamed_addr attributes #0 = { nofree nounwind } diff --git a/test/test-files/std/io/mkdir-rmdir-direxists/ir-code-O2.ll b/test/test-files/std/io/mkdir-rmdir-direxists/ir-code-O2.ll index 0ef063de4..319df54a0 100644 --- a/test/test-files/std/io/mkdir-rmdir-direxists/ir-code-O2.ll +++ b/test/test-files/std/io/mkdir-rmdir-direxists/ir-code-O2.ll @@ -12,31 +12,31 @@ target triple = "x86_64-w64-windows-gnu" @5 = private unnamed_addr constant [7 x i8] c"./test\00", align 1 define i32 @main() local_unnamed_addr { -entry: - %0 = tail call i1 @_f__void__dirExists__string(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @5, i64 0, i64 0)) +entry.l3: + %0 = tail call i1 @_f__void__dirExists__string(ptr nonnull @5) %1 = zext i1 %0 to i32 - %2 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @0, i64 0, i64 0), i32 %1) - %3 = load i32, i32* @MODE_ALL_RWX, align 4 - %4 = tail call i32 @_f__void__mkDir__string_int(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @5, i64 0, i64 0), i32 %3) - %5 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @1, i64 0, i64 0), i32 %4) - %6 = tail call i1 @_f__void__dirExists__string(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @5, i64 0, i64 0)) + %2 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 %1) + %3 = load i32, ptr @MODE_ALL_RWX, align 4 + %4 = tail call i32 @_f__void__mkDir__string_int(ptr nonnull @5, i32 %3) + %5 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i32 %4) + %6 = tail call i1 @_f__void__dirExists__string(ptr nonnull @5) %7 = zext i1 %6 to i32 - %8 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @2, i64 0, i64 0), i32 %7) - %9 = tail call i32 @_f__void__rmDir__string(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @5, i64 0, i64 0)) - %10 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @3, i64 0, i64 0), i32 %9) - %11 = tail call i1 @_f__void__dirExists__string(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @5, i64 0, i64 0)) + %8 = tail call i32 (ptr, ...) @printf(ptr nonnull @2, i32 %7) + %9 = tail call i32 @_f__void__rmDir__string(ptr nonnull @5) + %10 = tail call i32 (ptr, ...) @printf(ptr nonnull @3, i32 %9) + %11 = tail call i1 @_f__void__dirExists__string(ptr nonnull @5) %12 = zext i1 %11 to i32 - %13 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @4, i64 0, i64 0), i32 %12) + %13 = tail call i32 (ptr, ...) @printf(ptr nonnull @4, i32 %12) ret i32 0 } ; Function Attrs: nofree nounwind -declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 +declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0 -declare i1 @_f__void__dirExists__string(i8*) local_unnamed_addr +declare i1 @_f__void__dirExists__string(ptr) local_unnamed_addr -declare i32 @_f__void__mkDir__string_int(i8*, i32) local_unnamed_addr +declare i32 @_f__void__mkDir__string_int(ptr, i32) local_unnamed_addr -declare i32 @_f__void__rmDir__string(i8*) local_unnamed_addr +declare i32 @_f__void__rmDir__string(ptr) local_unnamed_addr attributes #0 = { nofree nounwind }