From 607d03ef60ccc9e05a952167bd8c493b466890a0 Mon Sep 17 00:00:00 2001 From: Marc Auberer Date: Mon, 22 Aug 2022 23:31:38 +0200 Subject: [PATCH] Fix nested in place array initializations (#185) * Code improvements * Further improvements * Upgrade to LLVM 15.0.0-rc2 * Fix bug * Add CMake option for faster dev compile times * Fix bug * Update test refs * Fix bug * Fix bug * Continue fixing bug * Continue fixing bug * Cleanup * Generate debug info for global variables * Add documentation for signed and unsigned modifiers * Improve debug info * Improvements * Add debug info for function parameters * Minor code improvements * Fix bug * Update test refs * Fix issue with error message * Improve LLVM var naming * Fix bug * Fix bug * Fix bug and update test refs --- .github/workflows/ci-cpp.yml | 6 +- .github/workflows/codeql-analysis.yml | 6 +- .github/workflows/publish.yml | 8 +- .run/Spice_run.run.xml | 2 +- Dockerfile | 2 +- Options.cmake | 11 + dev-setup.bat | 2 +- dev-setup.sh | 2 +- docs/docs/language/declaration-modifiers.md | 36 + media/test-project/os-test.spice | 13 +- setup-libs.bat | 2 +- setup-libs.sh | 2 +- src/Spice.g4 | 2 +- src/analyzer/AnalyzerVisitor.cpp | 76 ++- src/analyzer/OpRuleManager.cpp | 2 +- src/analyzer/OpRuleManager.h | 2 +- src/ast/AstNodes.h | 18 +- src/exception/ErrorFactory.cpp | 6 +- src/exception/ErrorFactory.h | 6 +- src/exception/IRError.cpp | 2 - src/exception/IRError.h | 1 - src/exception/SemanticError.cpp | 6 + src/exception/SemanticError.h | 3 + src/generator/GeneratorVisitor.cpp | 625 ++++++++++-------- src/generator/GeneratorVisitor.h | 14 +- src/generator/OpRuleConversionsManager.cpp | 51 +- src/linker/LinkerInterface.cpp | 5 +- src/linker/LinkerInterface.h | 2 +- src/parser/AstBuilderVisitor.cpp | 38 +- src/symbol/GenericType.h | 3 - src/symbol/Struct.cpp | 4 +- src/symbol/Struct.h | 2 +- src/symbol/SymbolTable.cpp | 18 +- src/symbol/SymbolTable.h | 4 +- src/symbol/SymbolTableEntry.cpp | 2 +- src/symbol/SymbolType.cpp | 13 +- src/util/FileUtil.cpp | 1 - .../error-sizeof-dyn-size-array/exception.out | 1 + .../error-sizeof-dyn-size-array/source.spice | 5 + .../exception.out | 1 + .../source.spice | 5 + .../arbitrary/success-ackermann/ir-code-O3.ll | 18 +- .../arbitrary/success-ackermann/ir-code.ll | 122 ++-- .../arbitrary/success-faculty/ir-code.ll | 62 +- .../success-fibonacci-threaded/ir-code-O3.ll | 12 +- .../arbitrary/success-fibonacci/ir-code-O3.ll | 12 +- .../arbitrary/success-fibonacci/ir-code.ll | 80 +-- .../arbitrary/success-pidigits/ir-code-O3.ll | 70 +- .../arbitrary/success-pidigits/ir-code.ll | 400 +++++------ .../success-arrays-dynamic-size/ir-code.ll | 194 +++--- .../ir-code.ll | 86 ++- .../arrays/success-arrays/ir-code.ll | 44 +- .../arrays/success-arrays2/ir-code.ll | 26 +- .../arrays/success-arrays3/ir-code.ll | 19 +- .../arrays/success-arrays4/ir-code.ll | 14 +- .../success-string-char-access/ir-code.ll | 2 +- .../success-basic-assertion/ir-code.ll | 2 +- .../builtins/success-len/ir-code-O2.ll | 2 +- .../generator/builtins/success-len/ir-code.ll | 12 +- .../builtins/success-sizeof/ir-code-O2.ll | 2 +- .../builtins/success-sizeof/ir-code.ll | 126 ++-- .../cli-args/success-cli-args/ir-code.ll | 26 +- .../ext-decl/success-ext-decl/ir-code.ll | 30 +- .../success-for-loop-break/ir-code-O2.ll | 16 +- .../success-for-loop-break/ir-code.ll | 70 +- .../success-for-loop-continue/ir-code-O2.ll | 16 +- .../success-for-loop-continue/ir-code.ll | 70 +- .../for-loops/success-for-loop/ir-code.ll | 22 +- .../ir-code.ll | 47 +- .../success-foreach-loop-break/ir-code-O2.ll | 6 +- .../success-foreach-loop-break/ir-code.ll | 121 ++-- .../ir-code-O2.ll | 28 +- .../success-foreach-loop-continue/ir-code.ll | 131 ++-- .../ir-code.ll | 36 +- .../success-foreach-loop-indexed/ir-code.ll | 14 +- .../success-foreach-loop-normal/ir-code.ll | 14 +- .../ir-code.ll | 20 +- .../success-default-arg-values/ir-code.ll | 32 +- .../functions/success-down-call/ir-code.ll | 8 +- .../success-explicit-inlining/ir-code.ll | 8 +- .../functions/success-overloading/ir-code.ll | 16 +- .../success-result-variable/ir-code.ll | 22 +- .../ir-code.ll | 36 +- .../success-generic-functions/ir-code.ll | 90 +-- .../success-generic-functions2/ir-code.ll | 201 +++--- .../success-generic-structs/ir-code.ll | 15 +- .../if-stmts/success-if-else-stmt/ir-code.ll | 24 +- .../if-stmts/success-if-stmt/ir-code.ll | 14 +- .../imports/success-modules-std/ir-code.ll | 12 +- .../imports/success-modules/ir-code.ll | 8 +- .../success-method-down-up-call/ir-code.ll | 75 +-- .../methods/success-methods/ir-code.ll | 42 +- .../operators/success-operators/ir-code.ll | 42 +- .../operators/success-operators2/ir-code.ll | 2 +- .../success-short-circuiting/ir-code.ll | 72 +- .../success-nested-pointers/ir-code.ll | 46 +- .../success-pointer-functions/ir-code.ll | 69 +- .../pointers/success-pointer/ir-code.ll | 38 +- .../success-early-return/ir-code.ll | 10 +- .../success-explicit-inlining/ir-code.ll | 6 +- .../structs/success-constructors/ir-code.ll | 32 +- .../success-external-nested-struct/ir-code.ll | 31 +- .../success-external-structs/ir-code.ll | 14 +- .../success-struct-field-access/ir-code.ll | 16 +- .../success-struct-self-ref/ir-code.ll | 107 ++- .../structs/success-struct/ir-code.ll | 85 ++- .../ir-code.ll | 36 +- .../ternary/success-ternary-stmt/ir-code.ll | 12 +- .../threads/success-basic-threads/ir-code.ll | 40 +- .../success-thread-joining/ir-code-O2.ll | 16 +- .../threads/success-thread-joining/ir-code.ll | 76 +-- .../success-threads-captures1/ir-code-O2.ll | 10 +- .../success-threads-captures1/ir-code.ll | 60 +- .../success-threads-captures2/ir-code-O2.ll | 16 +- .../success-threads-captures2/ir-code.ll | 66 +- .../unsafe/success-pointer-cast/ir-code.ll | 14 +- .../success-decl-default-value/ir-code.ll | 77 ++- .../success-while-loop-break/ir-code.ll | 60 +- .../success-while-loop-continue/ir-code-O2.ll | 4 +- .../success-while-loop-continue/ir-code.ll | 78 +-- .../while-loops/success-while-loop/ir-code.ll | 12 +- 121 files changed, 2410 insertions(+), 2322 deletions(-) mode change 100644 => 100755 setup-libs.sh create mode 100644 test/test-files/analyzer/builtins/error-sizeof-dyn-size-array/exception.out create mode 100644 test/test-files/analyzer/builtins/error-sizeof-dyn-size-array/source.spice create mode 100644 test/test-files/analyzer/variables/error-global-const-not-initialized/exception.out create mode 100644 test/test-files/analyzer/variables/error-global-const-not-initialized/source.spice diff --git a/.github/workflows/ci-cpp.yml b/.github/workflows/ci-cpp.yml index 2cc139db5..758881af4 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-15.0.0-rc1-invalidate + key: llvm-15.0.0-rc2 - name: Setup LLVM if: steps.cache-llvm.outputs.cache-hit != 'true' run: | cd .. rm -rf llvm - git clone --depth 1 --branch llvmorg-15.0.0-rc1 https://github.com/llvm/llvm-project llvm + git clone --depth 1 --branch llvmorg-15.0.0-rc2 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 @@ -67,7 +67,7 @@ jobs: run: | mkdir ./bin cd ./bin - cmake -DCMAKE_BUILD_TYPE=Debug -DSPICE_IS_GH_ACTIONS=ON -DSPICE_BUILT_BY="ghactions" -DSPICE_LINK_STATIC=OFF -DSPICE_RUN_COVERAGE=ON -GNinja -Wattributes .. + cmake -DCMAKE_BUILD_TYPE=Debug -DSPICE_IS_GH_ACTIONS=ON -DSPICE_BUILT_BY="ghactions" -DSPICE_LINK_STATIC=OFF -DSPICE_DEV_COMPILE=ON -DSPICE_RUN_COVERAGE=ON -GNinja -Wattributes .. cmake --build . --target Spice_test - name: Run Test target diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index c11d713d8..d681f7907 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: 15.0.0-rc1 + key: 15.0.0-rc2 - name: Setup LLVM if: steps.cache-llvm.outputs.cache-hit != 'true' run: | cd .. - git clone --depth 1 --branch llvmorg-15.0.0-rc1 https://github.com/llvm/llvm-project llvm + git clone --depth 1 --branch llvmorg-15.0.0-rc2 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 @@ -66,7 +66,7 @@ jobs: run: | mkdir ./bin cd ./bin - cmake -DCMAKE_BUILD_TYPE=Release -DSPICE_BUILT_BY="ghactions" -DSPICE_LINK_STATIC=OFF -GNinja -Wattributes .. + cmake -DCMAKE_BUILD_TYPE=Release -DSPICE_BUILT_BY="ghactions" -DSPICE_LINK_STATIC=OFF -DSPICE_DEV_COMPILE=ON -GNinja -Wattributes .. cmake --build . --target Spice_test - name: Perform CodeQL Analysis diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2419a948e..d55ba8ab1 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -44,12 +44,12 @@ jobs: uses: actions/cache@v3 with: path: /home/runner/work/spice/spice/llvm - key: llvm-15.0.0-rc1-linux-x64 + key: llvm-15.0.0-rc2-linux-x64 - 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 + git clone --depth 1 --branch llvmorg-15.0.0-rc2 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 @@ -124,12 +124,12 @@ jobs: uses: actions/cache@v3 with: path: D:/a/spice/spice/llvm - key: llvm-15.0.0-rc1-win-x64 + key: llvm-15.0.0-rc2-win-x64 - 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 + git clone --depth 1 --branch llvmorg-15.0.0-rc2 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." diff --git a/.run/Spice_run.run.xml b/.run/Spice_run.run.xml index 673269bd1..31edb635f 100644 --- a/.run/Spice_run.run.xml +++ b/.run/Spice_run.run.xml @@ -1,5 +1,5 @@ - + diff --git a/Dockerfile b/Dockerfile index ffdcc74e2..a88e293a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ ENV SPICE_DOCKERIZED=1 ARG COMPILER_PATH=linux-amd64 RUN apk update && apk add --repository=https://dl-cdn.alpinelinux.org/alpine/edge/main --no-cache \ - build-base ncurses-dev libc6-compat gcompat && rm -rf /var/cache/apk/* + build-base ncurses-dev libc6-compat gcompat zstd-dev && rm -rf /var/cache/apk/* RUN ln -sf /usr/lib/libncursesw.so.6 /usr/lib/libtinfo.so.6 COPY std/ /usr/lib/spice/std/ diff --git a/Options.cmake b/Options.cmake index 7e9625618..c69b648c2 100644 --- a/Options.cmake +++ b/Options.cmake @@ -18,6 +18,17 @@ else() message(STATUS "Spice: LTO for Spice is disabled.") endif() +# MOLD_X86_64_ONLY and MOLD_ARM64_ONLY are developer-only options. +# You should not use it for creating an executable for production use. +option(SPICE_DEV_COMPILE "Developer-only option" OFF) +if(SPICE_DEV_COMPILE) + message(STATUS "Spice: Dev build for Spice is enabled.") + SET(CMAKE_CXX_FLAGS_DEBUG "-ffunction-sections -fdata-sections ${CMAKE_CXX_FLAGS_DEBUG}") + set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections") +else() + message(STATUS "Spice: Dev build for Spice is disabled.") +endif() + # Link statically option(SPICE_LINK_STATIC "Link the compiler executable statically" OFF) if (SPICE_LINK_STATIC) diff --git a/dev-setup.bat b/dev-setup.bat index 4c14a627d..73cd44d25 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-15.0.0-rc1 https://github.com/llvm/llvm-project llvm +git clone --depth 1 --branch llvmorg-15.0.0-rc2 https://github.com/llvm/llvm-project llvm echo done. REM - Build LLVM diff --git a/dev-setup.sh b/dev-setup.sh index f81a5c358..da5169fe9 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-15.0.0-rc1 https://github.com/llvm/llvm-project llvm +git clone --depth 1 --branch llvmorg-15.0.0-rc2 https://github.com/llvm/llvm-project llvm colored_echo "done." # Build LLVM diff --git a/docs/docs/language/declaration-modifiers.md b/docs/docs/language/declaration-modifiers.md index 9ee81ae07..f03a7774b 100644 --- a/docs/docs/language/declaration-modifiers.md +++ b/docs/docs/language/declaration-modifiers.md @@ -85,4 +85,40 @@ const int THIS_IS_A_CONSTANT = 101; f main() { THIS_IS_A_CONSTANT++; // Will give a compiler error } +``` + +## The `signed` modifier + +Marks a numeric variable to use signed numbers explicitly. + +### Applicable for + +- Local variables +- Global variables +- Struct fields + +### Example + +```spice +f main() { + signed int signedInt = -0x567; +} +``` + +## The `unsigned` modifier + +Marks a numeric variable to use unsigned numbers explicitly. + +### Applicable for + +- Local variables +- Global variables +- Struct fields + +### Example + +```spice +f main() { + unsigned int unsignedInt = -0x567; // Will wrap around +} ``` \ No newline at end of file diff --git a/media/test-project/os-test.spice b/media/test-project/os-test.spice index 9dd407188..107ed585f 100644 --- a/media/test-project/os-test.spice +++ b/media/test-project/os-test.spice @@ -10,15 +10,8 @@ f main() { printf("Hello %s!", p1.getSecond()); }*/ -type TestStruct struct { - bool test -} - -p TestStruct.dtor(int test) { - printf("Dtor called"); -} - f main() { - TestStruct t = TestStruct(); - printf("Test: %d\n", 0o0000777); + foreach dyn item : { 1, 2, 3, 4, 5 } { + printf("Item %d: %d\n", idx, item); + } } \ No newline at end of file diff --git a/setup-libs.bat b/setup-libs.bat index eb57c924e..0fa2aa83d 100644 --- a/setup-libs.bat +++ b/setup-libs.bat @@ -8,7 +8,7 @@ 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.11.1/json.hpp" --output json/json.hpp +curl -SsL "https://github.com/nlohmann/json/releases/download/v3.11.2/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 old mode 100644 new mode 100755 index d33e42532..f4aabba30 --- a/setup-libs.sh +++ b/setup-libs.sh @@ -8,7 +8,7 @@ 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.11.1/json.hpp" --output json/json.hpp +curl -SsL "https://github.com/nlohmann/json/releases/download/v3.11.2/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/Spice.g4 b/src/Spice.g4 index 661a29294..37a00409b 100644 --- a/src/Spice.g4 +++ b/src/Spice.g4 @@ -89,6 +89,7 @@ TYPE_CHAR: 'char'; TYPE_STRING: 'string'; TYPE_BOOL: 'bool'; TYPE_DYN: 'dyn'; +CONST: 'const'; SIGNED: 'signed'; UNSIGNED: 'unsigned'; INLINE: 'inline'; @@ -101,7 +102,6 @@ ASSERT: 'assert'; FOR: 'for'; FOREACH: 'foreach'; WHILE: 'while'; -CONST: 'const'; IMPORT: 'import'; BREAK: 'break'; CONTINUE: 'continue'; diff --git a/src/analyzer/AnalyzerVisitor.cpp b/src/analyzer/AnalyzerVisitor.cpp index 71e19c089..839f9f628 100644 --- a/src/analyzer/AnalyzerVisitor.cpp +++ b/src/analyzer/AnalyzerVisitor.cpp @@ -688,6 +688,9 @@ std::any AnalyzerVisitor::visitGlobalVarDef(GlobalVarDefNode *node) { if (node->specifierLst()) { for (const auto &specifier : node->specifierLst()->specifiers()) { if (specifier->type == SpecifierNode::TY_CONST) { + // Check if a value is attached + if (!node->value()) + throw err->get(node->codeLoc, GLOBAL_CONST_WITHOUT_VALUE, "You must specify a value for constant global variables"); symbolTypeSpecifiers.setConst(true); } else if (specifier->type == SpecifierNode::TY_SIGNED) { symbolTypeSpecifiers.setSigned(true); @@ -1040,7 +1043,7 @@ std::any AnalyzerVisitor::visitReturnStmt(ReturnStmtNode *node) { // Check if there is a value attached to the return statement if (node->hasReturnValue) { // Visit the value - auto returnType = any_cast(visit(node->assignExpr())); + returnType = any_cast(visit(node->assignExpr())); // Check data type of return statement if (returnVariable->getType().is(TY_DYN)) { @@ -1056,6 +1059,8 @@ std::any AnalyzerVisitor::visitReturnStmt(ReturnStmtNode *node) { // Set the return variable to initialized returnVariable->updateState(INITIALIZED, err.get(), node->codeLoc); + } else { + returnType = returnVariable->getType(); } // Check if result variable is initialized @@ -1063,8 +1068,6 @@ std::any AnalyzerVisitor::visitReturnStmt(ReturnStmtNode *node) { throw err->get(node->codeLoc, RETURN_WITHOUT_VALUE_RESULT, "Return without value, but result variable is not initialized yet"); returnVariable->setUsed(); - - returnType = returnVariable->getType(); } else { // No return variable => procedure if (node->assignExpr()) @@ -1182,11 +1185,17 @@ std::any AnalyzerVisitor::visitPrintfCall(PrintfCallNode *node) { } std::any AnalyzerVisitor::visitSizeofCall(SizeofCallNode *node) { + SymbolType symbolType; if (node->isType) { // Size of type - any_cast(visit(node->dataType())); + symbolType = any_cast(visit(node->dataType())); } else { // Size of value - any_cast(visit(node->assignExpr())); + symbolType = any_cast(visit(node->assignExpr())); } + + // Check if symbol type is dynamically sized array + if (symbolType.is(TY_ARRAY) && symbolType.getArraySize() == -1) + throw err->get(node->codeLoc, SIZEOF_DYNAMIC_SIZED_ARRAY, "Cannot get sizeof dynamically sized array at compile time"); + return node->setEvaluatedSymbolType(SymbolType(TY_INT)); } @@ -1568,6 +1577,9 @@ std::any AnalyzerVisitor::visitPrefixUnaryExpr(PrefixUnaryExprNode *node) { std::any AnalyzerVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { auto lhs = any_cast(visit(node->atomicExpr())); + if (lhs.is(TY_INVALID)) + throw ErrorFactory::get(node->codeLoc, REFERENCED_UNDEFINED_VARIABLE, + "Variable '" + node->atomicExpr()->identifier + "' was referenced before declared"); size_t subscriptCounter = 0; size_t memberAccessCounter = 0; @@ -1792,21 +1804,21 @@ std::any AnalyzerVisitor::visitValue(ValueNode *node) { std::any AnalyzerVisitor::visitPrimitiveValue(PrimitiveValueNode *node) { switch (node->type) { - case PrimitiveValueNode::TY_DOUBLE: + case PrimitiveValueNode::TYPE_DOUBLE: return node->setEvaluatedSymbolType(SymbolType(TY_DOUBLE)); - case PrimitiveValueNode::TY_INT: + case PrimitiveValueNode::TYPE_INT: return node->setEvaluatedSymbolType(SymbolType(TY_INT)); - case PrimitiveValueNode::TY_SHORT: + case PrimitiveValueNode::TYPE_SHORT: return node->setEvaluatedSymbolType(SymbolType(TY_SHORT)); - case PrimitiveValueNode::TY_LONG: + case PrimitiveValueNode::TYPE_LONG: return node->setEvaluatedSymbolType(SymbolType(TY_LONG)); - case PrimitiveValueNode::TY_BYTE: + case PrimitiveValueNode::TYPE_BYTE: return node->setEvaluatedSymbolType(SymbolType(TY_BYTE)); - case PrimitiveValueNode::TY_CHAR: + case PrimitiveValueNode::TYPE_CHAR: return node->setEvaluatedSymbolType(SymbolType(TY_CHAR)); - case PrimitiveValueNode::TY_STRING: + case PrimitiveValueNode::TYPE_STRING: return node->setEvaluatedSymbolType(SymbolType(TY_STRING)); - case PrimitiveValueNode::TY_BOOL: + case PrimitiveValueNode::TYPE_BOOL: return node->setEvaluatedSymbolType(SymbolType(TY_BOOL)); } throw std::runtime_error("Primitive value fall-through"); @@ -1942,6 +1954,10 @@ std::any AnalyzerVisitor::visitArrayInitialization(ArrayInitializationNode *node int actualSize = 0; SymbolType actualItemType = SymbolType(TY_DYN); if (node->itemLst()) { + // Set the expected array type to the contained type + SymbolType expectedTypeBackup = expectedType; + expectedType = expectedType.isArray() ? expectedType.getContainedTy() : expectedType; + for (const auto &arg : node->itemLst()->args()) { auto itemType = any_cast(visit(arg)); if (actualItemType.is(TY_DYN)) { @@ -1953,6 +1969,9 @@ std::any AnalyzerVisitor::visitArrayInitialization(ArrayInitializationNode *node } actualSize++; } + + // Restore the expected array type + expectedType = expectedTypeBackup; } // Override actual array size if the expected type has a fixed size @@ -2045,14 +2064,15 @@ std::any AnalyzerVisitor::visitStructInstantiation(StructInstantiationNode *node // Get expected type SymbolTableEntry *expectedField = structTable->lookupByIndex(i); assert(expectedField != nullptr); - SymbolType expectedType = expectedField->getType(); + SymbolType expectedSymbolType = expectedField->getType(); // Replace expected type with the capture name - if (expectedType.is(TY_STRUCT)) - expectedType = expectedType.replaceBaseSubType(accessScopePrefix + expectedType.getBaseType().getSubType()); + if (expectedSymbolType.is(TY_STRUCT)) + expectedSymbolType = + expectedSymbolType.replaceBaseSubType(accessScopePrefix + expectedSymbolType.getBaseType().getSubType()); // Check if type matches declaration - if (actualType != expectedType) + if (actualType != expectedSymbolType) throw err->get(assignExpr->codeLoc, FIELD_TYPE_NOT_MATCHING, - "Expected type " + expectedType.getName(false) + " for the field '" + expectedField->getName() + + "Expected type " + expectedSymbolType.getName(false) + " for the field '" + expectedField->getName() + "', but got " + actualType.getName(false)); } } @@ -2069,11 +2089,11 @@ std::any AnalyzerVisitor::visitDataType(DataTypeNode *node) { while (!tmQueue.empty()) { DataTypeNode::TypeModifier typeModifier = tmQueue.front(); switch (typeModifier.modifierType) { - case DataTypeNode::TY_POINTER: { + case DataTypeNode::TYPE_PTR: { type = type.toPointer(err.get(), node->codeLoc); break; } - case DataTypeNode::TY_ARRAY: { + case DataTypeNode::TYPE_ARRAY: { if (typeModifier.hasSize) { if (typeModifier.isSizeHardcoded) { if (typeModifier.hardcodedSize <= 1) @@ -2098,21 +2118,21 @@ std::any AnalyzerVisitor::visitDataType(DataTypeNode *node) { std::any AnalyzerVisitor::visitBaseDataType(BaseDataTypeNode *node) { switch (node->type) { - case BaseDataTypeNode::TY_DOUBLE: + case BaseDataTypeNode::TYPE_DOUBLE: return node->setEvaluatedSymbolType(SymbolType(TY_DOUBLE)); - case BaseDataTypeNode::TY_INT: + case BaseDataTypeNode::TYPE_INT: return node->setEvaluatedSymbolType(SymbolType(TY_INT)); - case BaseDataTypeNode::TY_SHORT: + case BaseDataTypeNode::TYPE_SHORT: return node->setEvaluatedSymbolType(SymbolType(TY_SHORT)); - case BaseDataTypeNode::TY_LONG: + case BaseDataTypeNode::TYPE_LONG: return node->setEvaluatedSymbolType(SymbolType(TY_LONG)); - case BaseDataTypeNode::TY_BYTE: + case BaseDataTypeNode::TYPE_BYTE: return node->setEvaluatedSymbolType(SymbolType(TY_BYTE)); - case BaseDataTypeNode::TY_CHAR: + case BaseDataTypeNode::TYPE_CHAR: return node->setEvaluatedSymbolType(SymbolType(TY_CHAR)); - case BaseDataTypeNode::TY_STRING: + case BaseDataTypeNode::TYPE_STRING: return node->setEvaluatedSymbolType(SymbolType(TY_STRING)); - case BaseDataTypeNode::TY_BOOL: + case BaseDataTypeNode::TYPE_BOOL: return node->setEvaluatedSymbolType(SymbolType(TY_BOOL)); case BaseDataTypeNode::TY_CUSTOM: return node->setEvaluatedSymbolType(any_cast(visit(node->customDataType()))); diff --git a/src/analyzer/OpRuleManager.cpp b/src/analyzer/OpRuleManager.cpp index 20214d511..ff35577eb 100644 --- a/src/analyzer/OpRuleManager.cpp +++ b/src/analyzer/OpRuleManager.cpp @@ -217,7 +217,7 @@ SymbolType OpRuleManager::getPrefixMulResultType(const CodeLoc &codeLoc, const S return lhs.getContainedTy(); } -SymbolType OpRuleManager::getPrefixBitwiseAndResultType(const CodeLoc &codeLoc, SymbolType lhs) { +SymbolType OpRuleManager::getPrefixBitwiseAndResultType(const CodeLoc &codeLoc, const SymbolType& lhs) { return lhs.toPointer(err, codeLoc); } diff --git a/src/analyzer/OpRuleManager.h b/src/analyzer/OpRuleManager.h index 21fbecdb7..816601d6a 100644 --- a/src/analyzer/OpRuleManager.h +++ b/src/analyzer/OpRuleManager.h @@ -620,7 +620,7 @@ class OpRuleManager { SymbolType getPrefixNotResultType(const CodeLoc &codeLoc, const SymbolType &lhs); SymbolType getPrefixBitwiseNotResultType(const CodeLoc &codeLoc, const SymbolType &lhs); SymbolType getPrefixMulResultType(const CodeLoc &codeLoc, const SymbolType &lhs); - SymbolType getPrefixBitwiseAndResultType(const CodeLoc &codeLoc, SymbolType lhs); + SymbolType getPrefixBitwiseAndResultType(const CodeLoc &codeLoc, const SymbolType& lhs); SymbolType getPostfixPlusPlusResultType(const CodeLoc &codeLoc, const SymbolType &lhs); SymbolType getPostfixMinusMinusResultType(const CodeLoc &codeLoc, const SymbolType &lhs); SymbolType getCastResultType(const CodeLoc &codeLoc, const SymbolType &lhs, const SymbolType &); diff --git a/src/ast/AstNodes.h b/src/ast/AstNodes.h index 90bc687ca..44409fdf4 100644 --- a/src/ast/AstNodes.h +++ b/src/ast/AstNodes.h @@ -29,9 +29,9 @@ class AstNode { virtual std::any accept(AbstractAstVisitor *visitor) = 0; // Public methods - template T *createChild(const CodeLoc &codeLoc) { + template T *createChild(const CodeLoc &loc) { static_assert(std::is_base_of_v, "T must be derived from AstNode"); - T *node = new T(this, codeLoc); + T *node = new T(this, loc); children.push_back(node); return node; } @@ -76,9 +76,9 @@ class AstNode { } SymbolType getEvaluatedSymbolType() { - size_t symbolTypeIndex = getSymbolTypeIndex(); - if (!symbolTypes.empty() && !symbolTypes[symbolTypeIndex].is(TY_INVALID)) - return symbolTypes.at(symbolTypeIndex); + size_t idx = getSymbolTypeIndex(); + if (!symbolTypes.empty() && !symbolTypes[idx].is(TY_INVALID)) + return symbolTypes.at(idx); if (children.size() != 1) throw std::runtime_error("Cannot deduce evaluated symbol type"); return children.front()->getEvaluatedSymbolType(); @@ -1062,7 +1062,7 @@ class ValueNode : public AstNode { class PrimitiveValueNode : public AstNode { public: // Enum - enum PrimitiveValueType { TY_DOUBLE, TY_INT, TY_SHORT, TY_LONG, TY_BYTE, TY_CHAR, TY_STRING, TY_BOOL }; + enum PrimitiveValueType { TYPE_DOUBLE, TYPE_INT, TYPE_SHORT, TYPE_LONG, TYPE_BYTE, TYPE_CHAR, TYPE_STRING, TYPE_BOOL }; // Constructors using AstNode::AstNode; @@ -1144,11 +1144,11 @@ class StructInstantiationNode : public AstNode { class DataTypeNode : public AstNode { public: // Enums - enum TypeModifierType { TY_POINTER, TY_ARRAY }; + enum TypeModifierType { TYPE_PTR, TYPE_ARRAY }; // Structs struct TypeModifier { - TypeModifierType modifierType = TY_POINTER; + TypeModifierType modifierType = TYPE_PTR; bool hasSize = false; bool isSizeHardcoded = false; int hardcodedSize = 0; @@ -1173,7 +1173,7 @@ class DataTypeNode : public AstNode { class BaseDataTypeNode : public AstNode { public: // Enums - enum Type { TY_DOUBLE, TY_INT, TY_SHORT, TY_LONG, TY_BYTE, TY_CHAR, TY_STRING, TY_BOOL, TY_DYN, TY_CUSTOM }; + enum Type { TYPE_DOUBLE, TYPE_INT, TYPE_SHORT, TYPE_LONG, TYPE_BYTE, TYPE_CHAR, TYPE_STRING, TYPE_BOOL, TYPE_DYN, TY_CUSTOM }; // Constructors using AstNode::AstNode; diff --git a/src/exception/ErrorFactory.cpp b/src/exception/ErrorFactory.cpp index b23a17836..62fcb9d20 100644 --- a/src/exception/ErrorFactory.cpp +++ b/src/exception/ErrorFactory.cpp @@ -4,15 +4,15 @@ #include -SemanticError ErrorFactory::get(const CodeLoc &codeLoc, SemanticErrorType type, const std::string &message) const { +SemanticError ErrorFactory::get(const CodeLoc &codeLoc, SemanticErrorType type, const std::string &message) { return SemanticError(codeLoc, type, message); } -IRError ErrorFactory::get(const CodeLoc &codeLoc, IRErrorType type, const std::string &message) const { +IRError ErrorFactory::get(const CodeLoc &codeLoc, IRErrorType type, const std::string &message) { return IRError(codeLoc, type, message); } -IRError ErrorFactory::get(IRErrorType type, const std::string &message) const { return IRError(type, message); } +IRError ErrorFactory::get(IRErrorType type, const std::string &message) { return IRError(type, message); } CliError ErrorFactory::get(CliErrorType type, const std::string &message) { return CliError(type, message); } diff --git a/src/exception/ErrorFactory.h b/src/exception/ErrorFactory.h index c728d070d..a910fbdc1 100644 --- a/src/exception/ErrorFactory.h +++ b/src/exception/ErrorFactory.h @@ -19,9 +19,9 @@ class ErrorFactory { ErrorFactory() = default; // Public methods - [[nodiscard]] SemanticError get(const CodeLoc &codeLoc, SemanticErrorType type, const std::string &message) const; - [[nodiscard]] IRError get(const CodeLoc &codeLoc, IRErrorType type, const std::string &message) const; - [[nodiscard]] IRError get(IRErrorType type, const std::string &message) const; + [[nodiscard]] static SemanticError get(const CodeLoc &codeLoc, SemanticErrorType type, const std::string &message) ; + [[nodiscard]] static IRError get(const CodeLoc &codeLoc, IRErrorType type, const std::string &message) ; + [[nodiscard]] static IRError get(IRErrorType type, const std::string &message) ; [[nodiscard]] static CliError get(CliErrorType type, const std::string &message); [[nodiscard]] static LinkerError get(LinkerErrorType type, const std::string &message); }; \ No newline at end of file diff --git a/src/exception/IRError.cpp b/src/exception/IRError.cpp index e8160adf2..1382afa2f 100644 --- a/src/exception/IRError.cpp +++ b/src/exception/IRError.cpp @@ -52,8 +52,6 @@ std::string IRError::getMessagePrefix(IRErrorType type) { return "Unexpected type of dyn. Symbol table incomplete"; case PRINTF_NULL_TYPE: return "Printf has null type"; - case VARIABLE_NOT_FOUND: - return "Variable not found"; case INVALID_FUNCTION: return "Invalid function"; case INVALID_MODULE: diff --git a/src/exception/IRError.h b/src/exception/IRError.h index 9db8a3c82..d86c86684 100644 --- a/src/exception/IRError.h +++ b/src/exception/IRError.h @@ -17,7 +17,6 @@ enum IRErrorType { BRANCH_NOT_FOUND, UNEXPECTED_DYN_TYPE_IR, PRINTF_NULL_TYPE, - VARIABLE_NOT_FOUND, INVALID_FUNCTION, INVALID_MODULE, COMING_SOON_IR, diff --git a/src/exception/SemanticError.cpp b/src/exception/SemanticError.cpp index 6e130b9cc..3726263c0 100644 --- a/src/exception/SemanticError.cpp +++ b/src/exception/SemanticError.cpp @@ -52,6 +52,8 @@ std::string SemanticError::getMessagePrefix(SemanticErrorType type) { return "Global of type dyn"; case GLOBAL_OF_INVALID_TYPE: return "Global of invalid type"; + case GLOBAL_CONST_WITHOUT_VALUE: + return "Global const without value"; case FUNCTION_WITHOUT_RETURN_STMT: return "Missing return statement"; case INVALID_PARAM_ORDER: @@ -82,6 +84,8 @@ std::string SemanticError::getMessagePrefix(SemanticErrorType type) { return "Printf arg number not matching template string"; case STD_NOT_FOUND: return "Std lib not found"; + case DUPLICATE_IMPORT_NAME: + return "Duplicate import name"; case IMPORTED_FILE_NOT_EXISTING: return "Imported source file not existing"; case CIRCULAR_DEPENDENCY: @@ -100,6 +104,8 @@ std::string SemanticError::getMessagePrefix(SemanticErrorType type) { return "Array item type not matching"; case EXPECTED_ARRAY_TYPE: return "Expected array type"; + case SIZEOF_DYNAMIC_SIZED_ARRAY: + return "Sizeof dynamically sized array"; case RETURN_WITHOUT_VALUE_RESULT: return "Return without initialization of result variable"; case RETURN_WITH_VALUE_IN_PROCEDURE: diff --git a/src/exception/SemanticError.h b/src/exception/SemanticError.h index 126820648..e1c670af3 100644 --- a/src/exception/SemanticError.h +++ b/src/exception/SemanticError.h @@ -22,6 +22,7 @@ enum SemanticErrorType { STRUCT_DECLARED_TWICE, GLOBAL_OF_TYPE_DYN, GLOBAL_OF_INVALID_TYPE, + GLOBAL_CONST_WITHOUT_VALUE, FUNCTION_WITHOUT_RETURN_STMT, INVALID_PARAM_ORDER, DTOR_MUST_BE_PROCEDURE, @@ -37,6 +38,7 @@ enum SemanticErrorType { PRINTF_TYPE_ERROR, PRINTF_ARG_COUNT_ERROR, STD_NOT_FOUND, + DUPLICATE_IMPORT_NAME, IMPORTED_FILE_NOT_EXISTING, CIRCULAR_DEPENDENCY, UNKNOWN_DATATYPE, @@ -46,6 +48,7 @@ enum SemanticErrorType { ARRAY_INDEX_NO_INTEGER, ARRAY_ITEM_TYPE_NOT_MATCHING, EXPECTED_ARRAY_TYPE, + SIZEOF_DYNAMIC_SIZED_ARRAY, RETURN_WITHOUT_VALUE_RESULT, RETURN_WITH_VALUE_IN_PROCEDURE, DYN_POINTERS_NOT_ALLOWED, diff --git a/src/generator/GeneratorVisitor.cpp b/src/generator/GeneratorVisitor.cpp index 55a78492d..3109f4d2b 100644 --- a/src/generator/GeneratorVisitor.cpp +++ b/src/generator/GeneratorVisitor.cpp @@ -72,8 +72,14 @@ GeneratorVisitor::GeneratorVisitor(const std::shared_ptr &con // Initialize debug info generator if (cliOptions.generateDebugInfo) { - module->addModuleFlag(llvm::Module::Warning, "Dwarf Version", llvm::dwarf::DWARF_VERSION); module->addModuleFlag(llvm::Module::Warning, "Debug Info Version", llvm::DEBUG_METADATA_VERSION); + module->addModuleFlag(llvm::Module::Warning, "Dwarf Version", llvm::dwarf::DWARF_VERSION); + module->addModuleFlag(llvm::Module::Error, "PIC Level", llvm::PICLevel::BigPIC); + + auto identifierMetadata = module->getOrInsertNamedMetadata("llvm.ident"); + llvm::MDNode *n = llvm::MDNode::get(*context, llvm::MDString::get(*context, "spice version " + std::string(SPICE_VERSION))); + identifierMetadata->addOperand(n); + initializeDIBuilder(sourceFile.fileName, sourceFile.fileDir); } } @@ -175,131 +181,140 @@ std::any GeneratorVisitor::visitMainFctDef(MainFctDefNode *node) { if (!secondRun) return nullptr; - if (requiresMainFct) { // Only create main function when it is required - // Change scope to function scope - currentScope = node->fctScope; - assert(currentScope != nullptr); + // Only create main function when it is required + if (!requiresMainFct) + return nullptr; - // Visit arguments - std::vector argNames; - std::vector argTypes; - if (node->paramLst()) { - argNames.reserve(node->paramLst()->params().size()); - argTypes.reserve(node->paramLst()->params().size()); - for (const auto ¶m : node->paramLst()->params()) { - currentVarName = param->varName; - argNames.push_back(currentVarName); - SymbolTableEntry *argSymbol = currentScope->lookup(currentVarName); - assert(argSymbol != nullptr); - currentConstSigned = argSymbol->getSpecifiers().isSigned(); - auto argType = any_cast(visit(param->dataType())); - argTypes.push_back(argType); - } + // Change scope to function scope + currentScope = node->fctScope; + assert(currentScope != nullptr); + + // Visit arguments + std::vector argNames; + std::vector argTypes; + if (node->paramLst()) { + argNames.reserve(node->paramLst()->params().size()); + argTypes.reserve(node->paramLst()->params().size()); + for (const auto ¶m : node->paramLst()->params()) { + currentVarName = param->varName; + argNames.push_back(currentVarName); + SymbolTableEntry *argSymbol = currentScope->lookup(currentVarName); + assert(argSymbol != nullptr); + currentConstSigned = argSymbol->getSpecifiers().isSigned(); + auto argType = any_cast(visit(param->dataType())); + argTypes.push_back(argType); } + } - // Build function itself - llvm::Type *returnType = builder->getInt32Ty(); - llvm::FunctionType *fctType = llvm::FunctionType::get(returnType, argTypes, false); - llvm::Function *fct = llvm::Function::Create(fctType, llvm::Function::ExternalLinkage, MAIN_FUNCTION_NAME, module.get()); + // Build function itself + llvm::Type *returnType = builder->getInt32Ty(); + llvm::FunctionType *fctType = llvm::FunctionType::get(returnType, argTypes, false); + llvm::Function *fct = llvm::Function::Create(fctType, llvm::Function::ExternalLinkage, MAIN_FUNCTION_NAME, module.get()); - // Add debug info - if (cliOptions.generateDebugInfo) { - // Get arg types - std::vector> argTypes; - for (const auto &argName : argNames) { - SymbolTableEntry *argEntry = currentScope->lookup(argName); - assert(argEntry != nullptr); - argTypes.emplace_back(argEntry->getType(), true); - } - // Build spice function - SymbolSpecifiers specifiers = SymbolSpecifiers(SymbolType(TY_FUNCTION)); - Function spiceFunc("main", specifiers, SymbolType(TY_DYN), SymbolType(TY_INT), argTypes, {}, node->codeLoc); - // Add debug info - generateFunctionDebugInfo(fct, &spiceFunc); + // Add debug info + if (cliOptions.generateDebugInfo) { + // Get arg types + std::vector> argSymbolTypes; + for (const auto &argName : argNames) { + SymbolTableEntry *argEntry = currentScope->lookup(argName); + assert(argEntry != nullptr); + argSymbolTypes.emplace_back(argEntry->getType(), true); } + // Build spice function + SymbolSpecifiers specifiers = SymbolSpecifiers(SymbolType(TY_FUNCTION)); + Function spiceFunc("main", specifiers, SymbolType(TY_DYN), SymbolType(TY_INT), argSymbolTypes, {}, node->codeLoc); + // Add debug info + generateFunctionDebugInfo(fct, &spiceFunc); + setSourceLocation(node); + } - // Create entry block - 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; - - // Store function arguments - for (auto &arg : fct->args()) { - unsigned argNo = arg.getArgNo(); - std::string argName = argNames[argNo]; - llvm::Type *argType = fctType->getParamType(argNo); - llvm::Value *memAddress = insertAlloca(argType, argName); - SymbolTableEntry *argSymbol = currentScope->lookup(argName); - assert(argSymbol != nullptr); - argSymbol->updateAddress(memAddress); - builder->CreateStore(&arg, memAddress); - } + // Create entry block + 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; - // Declare result variable and set it to 0 for positive return code - llvm::Value *memAddress = insertAlloca(returnType, RETURN_VARIABLE_NAME); - SymbolTableEntry *returnSymbol = currentScope->lookup(RETURN_VARIABLE_NAME); - assert(returnSymbol != nullptr); - returnSymbol->updateAddress(memAddress); - builder->CreateStore(builder->getInt32(0), returnSymbol->getAddress()); + // Store function arguments + for (auto &arg : fct->args()) { + unsigned argNo = arg.getArgNo(); + std::string argName = argNames[argNo]; + llvm::Type *argType = fctType->getParamType(argNo); + llvm::Value *memAddress = insertAlloca(argType, argName); + SymbolTableEntry *argSymbol = currentScope->lookup(argName); + assert(argSymbol != nullptr); + argSymbol->updateAddress(memAddress); - // Reset stack state - stackState = nullptr; + if (cliOptions.generateDebugInfo) + generateDeclDebugInfo(node->codeLoc, argName, memAddress); - // Generate IR for function body - visit(node->stmtLst()); + builder->CreateStore(&arg, memAddress); + } - // Generate return statement for result variable - if (!blockAlreadyTerminated) { - std::vector varsToDestruct = currentScope->getVarsGoingOutOfScope(true); - if (!varsToDestruct.empty()) { - llvm::BasicBlock *predecessor = builder->GetInsertBlock(); - // Generate cleanup block - llvm::BasicBlock *bCleanup = llvm::BasicBlock::Create(*context, "cleanup." + codeLine); - moveInsertPointToBlock(bCleanup); + // Declare result variable and set it to 0 for positive return code + llvm::Value *memAddress = insertAlloca(returnType, RETURN_VARIABLE_NAME); + SymbolTableEntry *returnSymbol = currentScope->lookup(RETURN_VARIABLE_NAME); + assert(returnSymbol != nullptr); + returnSymbol->updateAddress(memAddress); + builder->CreateStore(builder->getInt32(0), returnSymbol->getAddress()); - // Generate cleanup instructions (e.g. dtor calls) - bool destructorCalled = false; - for (SymbolTableEntry *varEntry : varsToDestruct) - destructorCalled |= insertDestructorCall(node->codeLoc, varEntry); + // Reset stack state + stackState = nullptr; - if (destructorCalled) { - fct->getBasicBlockList().push_back(bCleanup); - moveInsertPointToBlock(predecessor); - builder->CreateBr(bCleanup); - moveInsertPointToBlock(bCleanup); - } else { - moveInsertPointToBlock(predecessor); - } - } + // Generate IR for function body + visit(node->stmtLst()); - // Restore stack if necessary - if (stackState != nullptr) - builder->CreateCall(retrieveStackRestoreFct(), {stackState}); + // Generate return statement for result variable + if (!blockAlreadyTerminated) { + std::vector varsToDestruct = currentScope->getVarsGoingOutOfScope(true); + if (!varsToDestruct.empty()) { + llvm::BasicBlock *predecessor = builder->GetInsertBlock(); + // Generate cleanup block + llvm::BasicBlock *bCleanup = llvm::BasicBlock::Create(*context, "cleanup." + codeLine); + moveInsertPointToBlock(bCleanup); - // Create return stmt - llvm::Value *result = returnSymbol->getAddress(); - builder->CreateRet(builder->CreateLoad(fct->getReturnType(), result)); + // Generate cleanup instructions (e.g. dtor calls) + bool destructorCalled = false; + for (SymbolTableEntry *varEntry : varsToDestruct) + destructorCalled |= insertDestructorCall(node->codeLoc, varEntry); + + if (destructorCalled) { + fct->getBasicBlockList().push_back(bCleanup); + moveInsertPointToBlock(predecessor); + builder->CreateBr(bCleanup); + moveInsertPointToBlock(bCleanup); + } else { + moveInsertPointToBlock(predecessor); + } } - // Conclude debug information - if (cliOptions.generateDebugInfo) - debugInfo.lexicalBlocks.pop_back(); - - // Verify function - if (!cliOptions.disableVerifier && !cliOptions.generateDebugInfo) { // Verifying while generating debug info throws errors - std::string output; - llvm::raw_string_ostream oss(output); - if (llvm::verifyFunction(*fct, &oss)) - throw err->get(node->codeLoc, INVALID_FUNCTION, oss.str()); + // Restore stack if necessary + if (stackState != nullptr) { + builder->CreateCall(retrieveStackRestoreFct(), {stackState}); + stackState = nullptr; } - // Change scope back - currentScope = currentScope->getParent(); - assert(currentScope != nullptr); + // Create return stmt + llvm::Value *result = returnSymbol->getAddress(); + builder->CreateRet(builder->CreateLoad(fct->getReturnType(), result)); + } + + // Conclude debug information + if (cliOptions.generateDebugInfo) + debugInfo.lexicalBlocks.pop(); + + // Verify function + if (!cliOptions.disableVerifier && !cliOptions.generateDebugInfo) { // Verifying while generating debug info throws errors + std::string output; + llvm::raw_string_ostream oss(output); + if (llvm::verifyFunction(*fct, &oss)) + throw err->get(node->codeLoc, INVALID_FUNCTION, oss.str()); } + // Change scope back + currentScope = currentScope->getParent(); + assert(currentScope != nullptr); + return nullptr; } @@ -307,6 +322,8 @@ std::any GeneratorVisitor::visitFctDef(FctDefNode *node) { if (!secondRun) return nullptr; + setSourceLocation(node); + // Change to the (potentially generic) struct scope SymbolTable *accessScope = currentScope; if (node->isMethod) @@ -388,8 +405,10 @@ std::any GeneratorVisitor::visitFctDef(FctDefNode *node) { fct->addFnAttr(llvm::Attribute::AlwaysInline); // Add debug info - if (cliOptions.generateDebugInfo) + if (cliOptions.generateDebugInfo) { generateFunctionDebugInfo(fct, &spiceFunc); + setSourceLocation(node); + } // Create entry block std::string codeLine = node->codeLoc.toPrettyLine(); @@ -407,6 +426,10 @@ std::any GeneratorVisitor::visitFctDef(FctDefNode *node) { SymbolTableEntry *argEntry = currentScope->lookup(argName); assert(argEntry != nullptr); argEntry->updateAddress(memAddress); + + if (cliOptions.generateDebugInfo) + generateDeclDebugInfo(node->codeLoc, argName, memAddress); + builder->CreateStore(&arg, memAddress); } @@ -453,8 +476,11 @@ std::any GeneratorVisitor::visitFctDef(FctDefNode *node) { } // Restore stack if necessary - if (stackState != nullptr) + if (stackState != nullptr) { builder->CreateCall(retrieveStackRestoreFct(), {stackState}); + stackState = nullptr; + } + // Create return stmt llvm::Value *result = returnSymbol->getAddress(); builder->CreateRet(builder->CreateLoad(fct->getReturnType(), result)); @@ -462,7 +488,7 @@ std::any GeneratorVisitor::visitFctDef(FctDefNode *node) { // Conclude debug information if (cliOptions.generateDebugInfo) - debugInfo.lexicalBlocks.pop_back(); + debugInfo.lexicalBlocks.pop(); // Verify function if (!cliOptions.disableVerifier && !cliOptions.generateDebugInfo) { // Verifying while generating debug info throws errors @@ -493,6 +519,8 @@ std::any GeneratorVisitor::visitProcDef(ProcDefNode *node) { if (!secondRun) return nullptr; + setSourceLocation(node); + // Change to the (potentially generic) struct scope SymbolTable *accessScope = currentScope; if (node->isMethod) @@ -570,8 +598,10 @@ std::any GeneratorVisitor::visitProcDef(ProcDefNode *node) { proc->addFnAttr(llvm::Attribute::AlwaysInline); // Add debug info - if (cliOptions.generateDebugInfo) + if (cliOptions.generateDebugInfo) { generateFunctionDebugInfo(proc, &spiceProc); + setSourceLocation(node); + } // Create entry block std::string codeLine = node->codeLoc.toPrettyLine(); @@ -589,6 +619,10 @@ std::any GeneratorVisitor::visitProcDef(ProcDefNode *node) { SymbolTableEntry *argSymbol = currentScope->lookup(argName); assert(argSymbol != nullptr); argSymbol->updateAddress(memAddress); + + if (cliOptions.generateDebugInfo) + generateDeclDebugInfo(node->codeLoc, argName, memAddress); + builder->CreateStore(&arg, memAddress); } @@ -629,15 +663,18 @@ std::any GeneratorVisitor::visitProcDef(ProcDefNode *node) { } // Restore stack if necessary - if (stackState != nullptr) + if (stackState != nullptr) { builder->CreateCall(retrieveStackRestoreFct(), {stackState}); + stackState = nullptr; + } + // Create return stmt builder->CreateRetVoid(); } // Conclude debug information if (cliOptions.generateDebugInfo) - debugInfo.lexicalBlocks.pop_back(); + debugInfo.lexicalBlocks.pop(); // Verify procedure if (!cliOptions.disableVerifier && !cliOptions.generateDebugInfo) { // Verifying while generating debug info throws errors @@ -668,6 +705,8 @@ std::any GeneratorVisitor::visitStructDef(StructDefNode *node) { if (secondRun) return nullptr; + setSourceLocation(node); + // Get all substantiated function which result from this function declaration std::map *manifestations = currentScope->getStructManifestations(node->codeLoc); if (manifestations) { @@ -715,6 +754,8 @@ std::any GeneratorVisitor::visitGlobalVarDef(GlobalVarDefNode *node) { if (secondRun) return nullptr; + setSourceLocation(node); + currentVarName = node->varName; // Get symbol table entry and the symbol specifiers @@ -736,11 +777,18 @@ std::any GeneratorVisitor::visitGlobalVarDef(GlobalVarDefNode *node) { global->setLinkage(linkage); global->setConstant(specifiers.isConst()); + // Add debug info + if (cliOptions.generateDebugInfo) + generateGlobalVarDebugInfo(global, globalVarEntry); + if (node->value()) { // Variable is initialized here - visit(node->value()); constNegate = node->negative; - global->setInitializer(currentConstValue); + visit(node->value()); constNegate = false; + global->setInitializer(currentConstValue); + } else { + llvm::Constant *defaultValue = getDefaultValueForSymbolType(globalVarEntry->getType()); + global->setInitializer(defaultValue); } return nullptr; @@ -750,6 +798,8 @@ std::any GeneratorVisitor::visitExtDecl(ExtDeclNode *node) { if (secondRun) return nullptr; + setSourceLocation(node); + // Get function name std::vector symbolTypes; @@ -792,7 +842,7 @@ std::any GeneratorVisitor::visitExtDecl(ExtDeclNode *node) { } std::any GeneratorVisitor::visitThreadDef(ThreadDefNode *node) { - emitSourceLocation(node); + setSourceLocation(node); // Create threaded function std::string threadedFctName = "_thread" + std::to_string(threadFactory.getNextFunctionSuffix()); @@ -900,7 +950,7 @@ std::any GeneratorVisitor::visitThreadDef(ThreadDefNode *node) { } std::any GeneratorVisitor::visitUnsafeBlockDef(UnsafeBlockDefNode *node) { - emitSourceLocation(node); + setSourceLocation(node); // Change scope currentScope = currentScope->getChild(node->getScopeId()); @@ -917,7 +967,7 @@ std::any GeneratorVisitor::visitUnsafeBlockDef(UnsafeBlockDefNode *node) { } std::any GeneratorVisitor::visitForLoop(ForLoopNode *node) { - emitSourceLocation(node); + setSourceLocation(node); // Create blocks std::string codeLine = node->codeLoc.toPrettyLine(); @@ -980,7 +1030,7 @@ std::any GeneratorVisitor::visitForLoop(ForLoopNode *node) { } std::any GeneratorVisitor::visitForeachLoop(ForeachLoopNode *node) { - emitSourceLocation(node); + setSourceLocation(node); // Create blocks std::string codeLine = node->codeLoc.toPrettyLine(); @@ -996,7 +1046,7 @@ std::any GeneratorVisitor::visitForeachLoop(ForeachLoopNode *node) { continueBlocks.push(bInc); // Get array variable entry - visit(node->arrayAssign()); + llvm::Value *arrayValuePtr = resolveAddress(node->arrayAssign()); SymbolTableEntry *arrayVarEntry = currentScope->lookup(currentVarName); bool dynamicallySized = arrayVarEntry && arrayVarEntry->getType().is(TY_PTR) && arrayVarEntry->getType().getDynamicArraySize() != nullptr; @@ -1028,9 +1078,8 @@ std::any GeneratorVisitor::visitForeachLoop(ForeachLoopNode *node) { llvm::Value *itemVarPtr = itemVarEntry->getAddress(); // Do loop variable initialization - llvm::Value *arrayValuePtr = resolveAddress(node->arrayAssign()); - SymbolType arraySymbolType = node->arrayAssign()->getEvaluatedSymbolType(); - llvm::Type *arrayValueType = arraySymbolType.toLLVMType(*context, currentScope); + SymbolType arrSymbolType = node->arrayAssign()->getEvaluatedSymbolType(); + llvm::Type *arrayValueType = arrSymbolType.toLLVMType(*context, currentScope); llvm::Value *arrayValue = builder->CreateLoad(arrayValueType, arrayValuePtr); llvm::Value *arraySizeValue = dynamicallySized ? arrayVarEntry->getType().getDynamicArraySize() : builder->getInt32(arrayValue->getType()->getArrayNumElements()); @@ -1046,12 +1095,12 @@ std::any GeneratorVisitor::visitForeachLoop(ForeachLoopNode *node) { llvm::Value *indices[2] = {builder->getInt32(0), index}; if (dynamicallySized) { arrayValuePtr = builder->CreateLoad(arrayValueType, arrayValuePtr); - arrayValueType = arraySymbolType.getContainedTy().toLLVMType(*context, currentScope); + arrayValueType = arrSymbolType.getContainedTy().toLLVMType(*context, currentScope); itemPtr = builder->CreateInBoundsGEP(arrayValueType, arrayValuePtr, index); } else { itemPtr = builder->CreateInBoundsGEP(arrayValueType, arrayValuePtr, indices); } - llvm::Type *itemPtrType = arraySymbolType.getContainedTy().toLLVMType(*context, currentScope); + llvm::Type *itemPtrType = arrSymbolType.getContainedTy().toLLVMType(*context, currentScope); llvm::Value *newItemValue = builder->CreateLoad(itemPtrType, itemPtr); builder->CreateStore(newItemValue, itemVarPtr); createBr(bLoop); @@ -1111,7 +1160,7 @@ std::any GeneratorVisitor::visitForeachLoop(ForeachLoopNode *node) { } std::any GeneratorVisitor::visitWhileLoop(WhileLoopNode *node) { - emitSourceLocation(node); + setSourceLocation(node); llvm::Function *parentFct = builder->GetInsertBlock()->getParent(); @@ -1157,8 +1206,6 @@ std::any GeneratorVisitor::visitWhileLoop(WhileLoopNode *node) { } std::any GeneratorVisitor::visitStmtLst(StmtLstNode *node) { - emitSourceLocation(node); - for (const auto &child : node->children) { if (!blockAlreadyTerminated) { visit(child); @@ -1173,7 +1220,7 @@ std::any GeneratorVisitor::visitTypeAltsLst(TypeAltsLstNode * /*node*/) { } std::any GeneratorVisitor::visitIfStmt(IfStmtNode *node) { - emitSourceLocation(node); + setSourceLocation(node); // Change scope currentScope = currentScope->getChild(node->getScopeId()); @@ -1219,7 +1266,7 @@ std::any GeneratorVisitor::visitIfStmt(IfStmtNode *node) { } std::any GeneratorVisitor::visitElseStmt(ElseStmtNode *node) { - emitSourceLocation(node); + setSourceLocation(node); if (node->ifStmt()) { // It is an else if branch visit(node->ifStmt()); @@ -1239,7 +1286,7 @@ std::any GeneratorVisitor::visitElseStmt(ElseStmtNode *node) { } std::any GeneratorVisitor::visitAssertStmt(AssertStmtNode *node) { - emitSourceLocation(node); + setSourceLocation(node); // Only generate assertions with -O0 if (cliOptions.optLevel == 0) { @@ -1278,7 +1325,7 @@ std::any GeneratorVisitor::visitAssertStmt(AssertStmtNode *node) { } std::any GeneratorVisitor::visitDeclStmt(DeclStmtNode *node) { - emitSourceLocation(node); + setSourceLocation(node); // Get var name currentVarName = lhsVarName = node->varName; @@ -1298,28 +1345,25 @@ std::any GeneratorVisitor::visitDeclStmt(DeclStmtNode *node) { llvm::Value *memAddress = nullptr; if (node->assignExpr()) { // Declaration with assignment memAddress = resolveAddress(node->assignExpr()); - - // Generate debug info for local variable - generateDeclDebugInfo(node->codeLoc, lhsVarName, memAddress); } else { // Declaration with default value if (entry->getType().is(TY_PTR) && entry->getType().getDynamicArraySize() != nullptr) { llvm::Type *itemType = entry->getType().getContainedTy().toLLVMType(*context, nullptr); dynamicArraySize = entry->getType().getDynamicArraySize(); - llvm::Value *arrayValue = allocateDynamicallySizedArray(itemType); - memAddress = insertAlloca(arrayValue->getType(), lhsVarName); - builder->CreateStore(arrayValue, memAddress, entry->isVolatile()); + llvm::Value *value = allocateDynamicallySizedArray(itemType); + memAddress = insertAlloca(value->getType(), lhsVarName); + builder->CreateStore(value, memAddress, entry->isVolatile()); } else { - llvm::Value *defaultValue = getDefaultValueForSymbolType(currentSymbolType); + llvm::Value *value = getDefaultValueForSymbolType(currentSymbolType); memAddress = insertAlloca(varType, lhsVarName); - // Generate debug info for local variable - generateDeclDebugInfo(node->codeLoc, lhsVarName, memAddress); - // Save default value to address - builder->CreateStore(defaultValue, memAddress, entry->isVolatile()); + builder->CreateStore(value, memAddress, entry->isVolatile()); } } + if (cliOptions.generateDebugInfo) + generateDeclDebugInfo(node->codeLoc, lhsVarName, memAddress, true); + // Update address in symbol table entry->updateAddress(memAddress); @@ -1335,7 +1379,7 @@ std::any GeneratorVisitor::visitImportStmt(ImportStmtNode * /*node*/) { } std::any GeneratorVisitor::visitReturnStmt(ReturnStmtNode *node) { - emitSourceLocation(node); + setSourceLocation(node); SymbolTableEntry *returnVarEntry = currentScope->lookup(RETURN_VARIABLE_NAME); @@ -1393,7 +1437,7 @@ std::any GeneratorVisitor::visitReturnStmt(ReturnStmtNode *node) { } std::any GeneratorVisitor::visitBreakStmt(BreakStmtNode *node) { - emitSourceLocation(node); + setSourceLocation(node); // Get destination block for (int i = 1; i < node->breakTimes; i++) @@ -1405,7 +1449,7 @@ std::any GeneratorVisitor::visitBreakStmt(BreakStmtNode *node) { } std::any GeneratorVisitor::visitContinueStmt(ContinueStmtNode *node) { - emitSourceLocation(node); + setSourceLocation(node); // Get destination block for (int i = 1; i < node->continueTimes; i++) @@ -1565,7 +1609,7 @@ std::any GeneratorVisitor::visitJoinCall(JoinCallNode *node) { } std::any GeneratorVisitor::visitAssignExpr(AssignExprNode *node) { - emitSourceLocation(node); + setSourceLocation(node); // Check if there is an assign operator applied if (node->hasOperator) { // This is an assignment or compound assignment @@ -1638,18 +1682,11 @@ std::any GeneratorVisitor::visitAssignExpr(AssignExprNode *node) { builder->CreateStore(rhs, lhsPtr, variableEntry->isVolatile()); } - // Add debug info for value change - generateAssignDebugInfo(node->codeLoc, lhsVarName, rhs); - return lhsPtr; } else if (node->ternaryExpr()) { - std::any rhs = visit(node->ternaryExpr()); - lhsType = nullptr; // Reset lhs type - return rhs; + return visit(node->ternaryExpr()); } else if (node->threadDef()) { - std::any rhs = visit(node->threadDef()); - lhsType = nullptr; // Reset lhs type - return rhs; + return visit(node->threadDef()); } // This is a fallthrough case -> throw an error @@ -1657,12 +1694,12 @@ std::any GeneratorVisitor::visitAssignExpr(AssignExprNode *node) { } std::any GeneratorVisitor::visitTernaryExpr(TernaryExprNode *node) { - emitSourceLocation(node); + setSourceLocation(node); if (node->operands().size() > 1) { - auto conditionPtr = resolveAddress(node->operands()[0]); - auto trueValuePtr = resolveAddress(node->operands()[1]); - auto falseValuePtr = resolveAddress(node->operands()[2]); + llvm::Value *conditionPtr = resolveAddress(node->operands()[0]); + llvm::Value *trueValuePtr = resolveAddress(node->operands()[1]); + llvm::Value *falseValuePtr = resolveAddress(node->operands()[2]); llvm::Type *conditionType = node->operands().front()->getEvaluatedSymbolType().toLLVMType(*context, currentScope); llvm::Value *condition = builder->CreateLoad(conditionType, conditionPtr); @@ -1672,7 +1709,7 @@ std::any GeneratorVisitor::visitTernaryExpr(TernaryExprNode *node) { } std::any GeneratorVisitor::visitLogicalOrExpr(LogicalOrExprNode *node) { - emitSourceLocation(node); + setSourceLocation(node); if (node->operands().size() > 1) { std::string codeLine = node->codeLoc.toPrettyLine(); @@ -1722,7 +1759,7 @@ std::any GeneratorVisitor::visitLogicalOrExpr(LogicalOrExprNode *node) { } std::any GeneratorVisitor::visitLogicalAndExpr(LogicalAndExprNode *node) { - emitSourceLocation(node); + setSourceLocation(node); if (node->operands().size() > 1) { std::string codeLine = node->codeLoc.toPrettyLine(); @@ -1772,7 +1809,7 @@ std::any GeneratorVisitor::visitLogicalAndExpr(LogicalAndExprNode *node) { } std::any GeneratorVisitor::visitBitwiseOrExpr(BitwiseOrExprNode *node) { - emitSourceLocation(node); + setSourceLocation(node); if (node->operands().size() > 1) { BitwiseXorExprNode *lhsOperand = node->operands().front(); @@ -1791,7 +1828,7 @@ std::any GeneratorVisitor::visitBitwiseOrExpr(BitwiseOrExprNode *node) { } std::any GeneratorVisitor::visitBitwiseXorExpr(BitwiseXorExprNode *node) { - emitSourceLocation(node); + setSourceLocation(node); if (node->operands().size() > 1) { BitwiseAndExprNode *lhsOperand = node->operands().front(); @@ -1810,7 +1847,7 @@ std::any GeneratorVisitor::visitBitwiseXorExpr(BitwiseXorExprNode *node) { } std::any GeneratorVisitor::visitBitwiseAndExpr(BitwiseAndExprNode *node) { - emitSourceLocation(node); + setSourceLocation(node); if (node->operands().size() > 1) { EqualityExprNode *lhsOperand = node->operands().front(); @@ -1829,7 +1866,7 @@ std::any GeneratorVisitor::visitBitwiseAndExpr(BitwiseAndExprNode *node) { } std::any GeneratorVisitor::visitEqualityExpr(EqualityExprNode *node) { - emitSourceLocation(node); + setSourceLocation(node); if (node->operands().size() > 1) { RelationalExprNode *lhsOperand = node->operands()[0]; @@ -1859,7 +1896,7 @@ std::any GeneratorVisitor::visitEqualityExpr(EqualityExprNode *node) { } std::any GeneratorVisitor::visitRelationalExpr(RelationalExprNode *node) { - emitSourceLocation(node); + setSourceLocation(node); if (node->operands().size() > 1) { ShiftExprNode *lhsOperand = node->operands()[0]; @@ -1895,7 +1932,7 @@ std::any GeneratorVisitor::visitRelationalExpr(RelationalExprNode *node) { } std::any GeneratorVisitor::visitShiftExpr(ShiftExprNode *node) { - emitSourceLocation(node); + setSourceLocation(node); // Check if there is a shift operation attached if (node->operands().size() > 1) { @@ -1926,7 +1963,7 @@ std::any GeneratorVisitor::visitShiftExpr(ShiftExprNode *node) { } std::any GeneratorVisitor::visitAdditiveExpr(AdditiveExprNode *node) { - emitSourceLocation(node); + setSourceLocation(node); // Check if at least one additive operator is applied if (!node->opQueue.empty()) { @@ -1965,7 +2002,7 @@ std::any GeneratorVisitor::visitAdditiveExpr(AdditiveExprNode *node) { } std::any GeneratorVisitor::visitMultiplicativeExpr(MultiplicativeExprNode *node) { - emitSourceLocation(node); + setSourceLocation(node); // Check if at least one multiplicative operator is applied if (!node->opQueue.empty()) { @@ -2007,7 +2044,7 @@ std::any GeneratorVisitor::visitMultiplicativeExpr(MultiplicativeExprNode *node) } std::any GeneratorVisitor::visitCastExpr(CastExprNode *node) { - emitSourceLocation(node); + setSourceLocation(node); if (node->isCasted) { // Cast operator is applied SymbolType lhsSymbolType = node->getEvaluatedSymbolType(); @@ -2027,7 +2064,7 @@ std::any GeneratorVisitor::visitCastExpr(CastExprNode *node) { } std::any GeneratorVisitor::visitPrefixUnaryExpr(PrefixUnaryExprNode *node) { - emitSourceLocation(node); + setSourceLocation(node); currentVarName = ""; // Reset the current variable name scopePath.clear(); // Clear the scope path @@ -2118,12 +2155,9 @@ std::any GeneratorVisitor::visitPrefixUnaryExpr(PrefixUnaryExprNode *node) { opStack.pop(); } - if (storeValue) { - // Store the value back again + // Store the value back again + if (storeValue) builder->CreateStore(lhs, lhsPtr, isVolatile); - // Create debug info for assignment - generateAssignDebugInfo(node->codeLoc, currentVarName, lhs); - } return lhsPtr; } @@ -2132,7 +2166,7 @@ std::any GeneratorVisitor::visitPrefixUnaryExpr(PrefixUnaryExprNode *node) { } std::any GeneratorVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { - emitSourceLocation(node); + setSourceLocation(node); if (!node->opQueue.empty()) { // Retrieve the address and the value if required @@ -2140,7 +2174,7 @@ std::any GeneratorVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { 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; + llvm::Value *lhs = nullptr; size_t subscriptCounter = 0; size_t memberAccessCounter = 0; @@ -2149,12 +2183,6 @@ std::any GeneratorVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { while (!opQueue.empty()) { switch (opQueue.front().first) { case PostfixUnaryExprNode::OP_SUBSCRIPT: { - if (!lhs) { - lhsTy = lhsSymbolType.toLLVMType(*context, currentScope); - lhs = builder->CreateLoad(lhsTy, lhsPtr); - } - - assert(lhs->getType()->isArrayTy() || lhs->getType()->isPointerTy()); // Save variables to restore later std::string currentVarNameBackup = currentVarName; @@ -2172,16 +2200,19 @@ std::any GeneratorVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { structAccessAddress = structAccessAddressBackup; structAccessType = structAccessTypeBackup; - if (lhs->getType()->isArrayTy()) { + if (lhsSymbolType.isArray() && lhsSymbolType.getArraySize() > 0) { // Array lhsTy = lhsSymbolType.toLLVMType(*context, currentScope); // Calculate address of array item llvm::Value *indices[2] = {builder->getInt32(0), indexValue}; lhsPtr = builder->CreateInBoundsGEP(lhsTy, lhsPtr, indices); + // lhsPtr = builder->CreateInBoundsGEP(lhsTy, lhsPtr, indexValue); structAccessType = lhsSymbolType.getContainedTy().toLLVMType(*context, currentScope); - } else { + } else { // Pointer + lhsTy = lhsSymbolType.toLLVMType(*context, currentScope); + lhsPtr = builder->CreateLoad(lhsTy, lhsPtr); lhsTy = lhsSymbolType.getContainedTy().toLLVMType(*context, currentScope); // Calculate address of pointer offset - lhsPtr = builder->CreateInBoundsGEP(lhsTy, lhs, indexValue); + lhsPtr = builder->CreateInBoundsGEP(lhsTy, lhsPtr, indexValue); structAccessType = lhsTy; } structAccessAddress = lhsPtr; @@ -2237,12 +2268,9 @@ std::any GeneratorVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { opQueue.pop(); } - if (lhs != nullptr) { - // Store the value back again + // Store the value back again + if (lhs != nullptr) builder->CreateStore(lhs, lhsPtr); - // Create debug info for assignment - generateAssignDebugInfo(node->codeLoc, currentVarName, lhs); - } return lhsPtr; } @@ -2251,7 +2279,7 @@ std::any GeneratorVisitor::visitPostfixUnaryExpr(PostfixUnaryExprNode *node) { } std::any GeneratorVisitor::visitAtomicExpr(AtomicExprNode *node) { - emitSourceLocation(node); + setSourceLocation(node); if (node->value()) return visit(node->value()); @@ -2364,7 +2392,7 @@ std::any GeneratorVisitor::visitAtomicExpr(AtomicExprNode *node) { } std::any GeneratorVisitor::visitValue(ValueNode *node) { - emitSourceLocation(node); + setSourceLocation(node); // Primitive value if (node->primitiveValue()) { @@ -2410,14 +2438,14 @@ std::any GeneratorVisitor::visitValue(ValueNode *node) { std::any GeneratorVisitor::visitPrimitiveValue(PrimitiveValueNode *node) { // Value is a double constant - if (node->type == PrimitiveValueNode::TY_DOUBLE) { + if (node->type == PrimitiveValueNode::TYPE_DOUBLE) { currentSymbolType = SymbolType(TY_DOUBLE); double value = constNegate ? -node->data.doubleValue : node->data.doubleValue; return static_cast(llvm::ConstantFP::get(*context, llvm::APFloat(value))); } // Value is an integer constant - if (node->type == PrimitiveValueNode::TY_INT) { + if (node->type == PrimitiveValueNode::TYPE_INT) { currentSymbolType = SymbolType(TY_INT); int value = constNegate ? -node->data.intValue : node->data.intValue; llvm::Type *intTy = builder->getInt32Ty(); @@ -2427,7 +2455,7 @@ std::any GeneratorVisitor::visitPrimitiveValue(PrimitiveValueNode *node) { } // Value is a short constant - if (node->type == PrimitiveValueNode::TY_SHORT) { + if (node->type == PrimitiveValueNode::TYPE_SHORT) { currentSymbolType = SymbolType(TY_SHORT); int value = constNegate ? -node->data.shortValue : node->data.shortValue; llvm::Type *shortTy = builder->getInt16Ty(); @@ -2437,7 +2465,7 @@ std::any GeneratorVisitor::visitPrimitiveValue(PrimitiveValueNode *node) { } // Value is a long constant - if (node->type == PrimitiveValueNode::TY_LONG) { + if (node->type == PrimitiveValueNode::TYPE_LONG) { currentSymbolType = SymbolType(TY_LONG); long long value = constNegate ? -node->data.longValue : node->data.longValue; llvm::Type *longTy = builder->getInt64Ty(); @@ -2447,7 +2475,7 @@ std::any GeneratorVisitor::visitPrimitiveValue(PrimitiveValueNode *node) { } // Value is a char constant - if (node->type == PrimitiveValueNode::TY_CHAR) { + if (node->type == PrimitiveValueNode::TYPE_CHAR) { currentSymbolType = SymbolType(TY_CHAR); char value = node->data.charValue; llvm::Type *charTy = builder->getInt8Ty(); @@ -2457,14 +2485,14 @@ std::any GeneratorVisitor::visitPrimitiveValue(PrimitiveValueNode *node) { } // Value is a string constant - if (node->type == PrimitiveValueNode::TY_STRING) { + if (node->type == PrimitiveValueNode::TYPE_STRING) { currentSymbolType = SymbolType(TY_STRING); std::string value = node->data.stringValue; return static_cast(builder->CreateGlobalStringPtr(value, "", 0, module.get())); } // Value is a boolean constant - if (node->type == PrimitiveValueNode::TY_BOOL) { + if (node->type == PrimitiveValueNode::TYPE_BOOL) { currentSymbolType = SymbolType(TY_BOOL); return static_cast(node->data.boolValue ? builder->getTrue() : builder->getFalse()); } @@ -2587,11 +2615,12 @@ std::any GeneratorVisitor::visitFunctionCall(FunctionCallNode *node) { // Get the actual arg value SymbolType actualArgSymbolType = arg->getEvaluatedSymbolType(); llvm::Value *actualArgPtr = resolveAddress(arg); - if (actualArgSymbolType != expectedArgSymbolType) { - argValues.push_back(doImplicitCast(actualArgPtr, expectedArgType, actualArgSymbolType)); + if (actualArgSymbolType == expectedArgSymbolType) { + actualArgPtr = builder->CreateLoad(actualArgSymbolType.toLLVMType(*context, accessScope), actualArgPtr); } else { - argValues.push_back(builder->CreateLoad(actualArgSymbolType.toLLVMType(*context, accessScope), actualArgPtr)); + actualArgPtr = doImplicitCast(actualArgPtr, expectedArgType, actualArgSymbolType); } + argValues.push_back(actualArgPtr); argIndex++; } } @@ -2616,34 +2645,75 @@ 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; - 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()) { + bool outermostArray = true; + if (!arraySymbolType.is(TY_INVALID)) { + dynamicallySized = arraySymbolType.is(TY_PTR) && arraySymbolType.getDynamicArraySize() != nullptr; + outermostArray = false; + } else if (!lhsVarName.empty()) { SymbolTableEntry *arrayEntry = currentScope->lookupStrict(lhsVarName); assert(arrayEntry != nullptr); - dynamicallySized = arrayEntry->getType().is(TY_PTR) && arrayEntry->getType().getDynamicArraySize() != nullptr; + arraySymbolType = arrayEntry->getType(); + dynamicallySized = arraySymbolType.isPointer() && arraySymbolType.getDynamicArraySize() != nullptr; + if (dynamicallySized) + dynamicArraySize = arraySymbolType.getDynamicArraySize(); + } else { + arraySymbolType = node->getEvaluatedSymbolType(); } + SymbolType itemSymbolType = arraySymbolType.getContainedTy(); + llvm::Type *arrayType = arraySymbolType.toLLVMType(*context, currentScope); + llvm::Type *itemType = itemSymbolType.toLLVMType(*context, currentScope); + std::vector itemValues; std::vector itemConstants; itemValues.reserve(arraySize); itemConstants.reserve(arraySize); + bool toggledConstantArray = false; + if (!withinConstantArray) + withinConstantArray = toggledConstantArray = true; + if (node->itemLst()) { // The array is initialized with values + // Set the lhs type to the item type + std::string lhsVarNameBackup = lhsVarName; + llvm::Type *lhsTypeBackup = lhsType; + lhsType = itemSymbolType.toLLVMType(*context, currentScope); + SymbolType arraySymbolTypeBackup = arraySymbolType; + arraySymbolType = arraySymbolType.getContainedTy(); + llvm::Value *dynamicArraySizeBackup = dynamicArraySize; + dynamicArraySize = nullptr; + // Visit all args to check if they are hardcoded or not allArgsHardcoded = true; for (size_t i = 0; i < std::min(node->itemLst()->args().size(), arraySize); i++) { currentConstValue = nullptr; - llvm::Value *itemValue = resolveValue(node->itemLst()->args()[i]); + lhsVarName = lhsVarNameBackup + "." + std::to_string(i); + + if (arraySymbolType.isPointer()) + dynamicArraySize = arraySymbolType.getDynamicArraySize(); + + AssignExprNode *arg = node->itemLst()->args()[i]; + llvm::Value *itemValue = resolveValue(arg); + itemValues.push_back(itemValue); itemConstants.push_back(currentConstValue); } + + // Restore lhs type + lhsVarName = lhsVarNameBackup; + lhsType = lhsTypeBackup; + arraySymbolType = arraySymbolTypeBackup; + dynamicArraySize = dynamicArraySizeBackup; } + if (toggledConstantArray) + withinConstantArray = false; + if (outermostArray) + arraySymbolType = SymbolType(TY_INVALID); + currentConstValue = nullptr; + // 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 @@ -2653,21 +2723,28 @@ std::any GeneratorVisitor::visitArrayInitialization(ArrayInitializationNode *nod itemConstants.push_back(constantValue); } - // Create global array from constant values + // Create hardcoded array assert(arrayType != nullptr); - return createGlobalArray(arrayType, itemConstants); + auto type = reinterpret_cast(arrayType); + currentConstValue = llvm::ConstantArray::get(type, itemConstants); + + if (withinConstantArray) + return {}; + + return createGlobalArray(currentConstValue); } else { // Global array is not possible => fallback to individual indexing + allArgsHardcoded = false; + // Allocate array llvm::Value *arrayAddress; if (dynamicallySized) { arrayAddress = allocateDynamicallySizedArray(itemType); - arrayType = arraySymbolType.getContainedTy().toLLVMType(*context, currentScope); + arrayType = itemSymbolType.toLLVMType(*context, currentScope); } else { - arrayAddress = insertAlloca(arrayType, lhsVarName); + arrayAddress = insertAlloca(arrayType); } // Insert all given values - llvm::Value *itemDefaultValue = getDefaultValueForSymbolType(itemSymbolType); for (size_t valueIndex = 0; valueIndex < arraySize; valueIndex++) { // Calculate item address llvm::Value *itemAddress; @@ -2679,18 +2756,22 @@ std::any GeneratorVisitor::visitArrayInitialization(ArrayInitializationNode *nod } // Store item value to item address - llvm::Value *itemValue = - node->itemLst() && valueIndex < node->itemLst()->args().size() ? itemValues[valueIndex] : itemDefaultValue; + llvm::Value *itemValue; + if (node->itemLst() && valueIndex < node->itemLst()->args().size()) { + itemValue = itemValues[valueIndex]; + } else { + itemValue = getDefaultValueForSymbolType(itemSymbolType); + } builder->CreateStore(itemValue, itemAddress); } + if (!dynamicallySized) + return arrayAddress; + // Save value to address - if (dynamicallySized) { - llvm::Value *newArrayAddress = insertAlloca(arrayAddress->getType(), lhsVarName); - builder->CreateStore(arrayAddress, newArrayAddress); - return newArrayAddress; - } - return arrayAddress; + llvm::Value *newArrayAddress = insertAlloca(arrayAddress->getType(), lhsVarName); + builder->CreateStore(arrayAddress, newArrayAddress); + return newArrayAddress; } } @@ -2748,7 +2829,7 @@ std::any GeneratorVisitor::visitStructInstantiation(StructInstantiationNode *nod } std::any GeneratorVisitor::visitDataType(DataTypeNode *node) { - emitSourceLocation(node); + setSourceLocation(node); SymbolType symbolType = node->getEvaluatedSymbolType(); if (symbolType.is(TY_DYN)) { @@ -2768,11 +2849,11 @@ std::any GeneratorVisitor::visitDataType(DataTypeNode *node) { while (!tmQueue.empty()) { DataTypeNode::TypeModifier typeModifier = tmQueue.front(); switch (typeModifier.modifierType) { - case DataTypeNode::TY_POINTER: { + case DataTypeNode::TYPE_PTR: { symbolType = symbolType.toPointer(err.get(), node->codeLoc); break; } - case DataTypeNode::TY_ARRAY: { + case DataTypeNode::TYPE_ARRAY: { if (!typeModifier.hasSize) { symbolType = symbolType.toPointer(err.get(), node->codeLoc); } else if (typeModifier.isSizeHardcoded) { @@ -2844,15 +2925,16 @@ void GeneratorVisitor::createCondBr(llvm::Value *condition, llvm::BasicBlock *tr llvm::Value *GeneratorVisitor::insertAlloca(llvm::Type *llvmType, const std::string &varName) { if (allocaInsertInst != nullptr) { - llvm::AllocaInst *allocaInst = builder->CreateAlloca(llvmType, nullptr, varName); - allocaInst->moveAfter(allocaInsertInst); - allocaInsertInst = allocaInst; + allocaInsertInst = builder->CreateAlloca(llvmType, nullptr, varName); + allocaInsertInst->setDebugLoc(llvm::DebugLoc()); + allocaInsertInst->moveAfter(allocaInsertInst); } else { // Save current basic block and move insert cursor to entry block of the current function llvm::BasicBlock *currentBlock = builder->GetInsertBlock(); builder->SetInsertPoint(allocaInsertBlock); allocaInsertInst = builder->CreateAlloca(llvmType, nullptr, varName); + allocaInsertInst->setDebugLoc(llvm::DebugLoc()); // Restore old basic block builder->SetInsertPoint(currentBlock); @@ -2863,21 +2945,18 @@ llvm::Value *GeneratorVisitor::insertAlloca(llvm::Type *llvmType, const std::str llvm::Value *GeneratorVisitor::allocateDynamicallySizedArray(llvm::Type *itemType) { // Call llvm.stacksave intrinsic llvm::Function *stackSaveFct = retrieveStackSaveFct(); - stackState = builder->CreateCall(stackSaveFct); + if (stackState == nullptr) + stackState = builder->CreateCall(stackSaveFct); // Allocate array llvm::Value *memAddress = builder->CreateAlloca(itemType, dynamicArraySize); // Intentionally not via insertAlloca dynamicArraySize = nullptr; return memAddress; } -llvm::Value *GeneratorVisitor::createGlobalArray(llvm::Type *arrayType, const std::vector &itemConstants) { - // Create hardcoded array - auto type = static_cast(arrayType); - llvm::Constant *constArray = llvm::ConstantArray::get(type, itemConstants); - +llvm::Value *GeneratorVisitor::createGlobalArray(llvm::Constant *constArray) { // Find an unused global name std::string globalVarName = lhsVarName; - if (globalVarName.empty()) { + if (globalVarName.empty() || module->getNamedGlobal(globalVarName) != nullptr) { unsigned int suffixNumber = 0; do { globalVarName = "anonymous." + std::to_string(suffixNumber); @@ -2886,15 +2965,11 @@ llvm::Value *GeneratorVisitor::createGlobalArray(llvm::Type *arrayType, const st } // Create global variable - module->getOrInsertGlobal(globalVarName, arrayType); - llvm::Value *arrayAddress = insertAlloca(arrayType, lhsVarName); - builder->CreateStore(constArray, arrayAddress); - - // Set some attributes to it + llvm::Value *memAddress = module->getOrInsertGlobal(globalVarName, constArray->getType()); llvm::GlobalVariable *global = module->getNamedGlobal(globalVarName); - global->setConstant(true); global->setInitializer(constArray); - return arrayAddress; + + return memAddress; } bool GeneratorVisitor::insertDestructorCall(const CodeLoc &codeLoc, SymbolTableEntry *varEntry) { @@ -3039,7 +3114,7 @@ llvm::Constant *GeneratorVisitor::getDefaultValueForSymbolType(const SymbolType assert(structScope != nullptr); size_t fieldCount = structScope->getFieldCount(); - auto structType = static_cast(structEntry->getType().toLLVMType(*context, structScope)); + auto structType = reinterpret_cast(structEntry->getType().toLLVMType(*context, structScope)); // Allocate space for the struct in memory llvm::Value *structAddress = insertAlloca(structType); @@ -3109,12 +3184,14 @@ llvm::Value *GeneratorVisitor::doImplicitCast(llvm::Value *src, llvm::Type *dstT } void GeneratorVisitor::initializeDIBuilder(const std::string &sourceFileName, const std::string &sourceFileDir) { + std::string producerString = "spice version " + std::string(SPICE_VERSION); // Create DIBuilder diBuilder = std::make_unique(*module); // Create compilation unit debugInfo.diFile = diBuilder->createFile(sourceFileName, sourceFileDir); - debugInfo.compileUnit = - diBuilder->createCompileUnit(llvm::dwarf::DW_LANG_C, debugInfo.diFile, "Spice Compiler", cliOptions.optLevel > 0, "", 0); + debugInfo.compileUnit = diBuilder->createCompileUnit(llvm::dwarf::DW_LANG_C, debugInfo.diFile, producerString, + cliOptions.optLevel > 0, "", 0, "", llvm::DICompileUnit::FullDebug, 0, + false, false, llvm::DICompileUnit::DebugNameTableKind::None); // Initialize primitive types debugInfo.doubleTy = diBuilder->createBasicType("double", 64, llvm::dwarf::DW_ATE_float); debugInfo.intTy = diBuilder->createBasicType("int", 32, llvm::dwarf::DW_ATE_signed); @@ -3167,9 +3244,6 @@ llvm::DIType *GeneratorVisitor::getDITypeForSymbolType(const SymbolType &symbolT } void GeneratorVisitor::generateFunctionDebugInfo(llvm::Function *llvmFunction, const Function *spiceFunc) { - llvm::DIFile *unit = diBuilder->createFile(debugInfo.compileUnit->getFilename(), debugInfo.compileUnit->getDirectory()); - size_t lineNumber = spiceFunc->getDeclCodeLoc().line; - // Create function type std::vector argTypes; argTypes.push_back(getDITypeForSymbolType(spiceFunc->getReturnType())); // Add result type @@ -3177,6 +3251,9 @@ void GeneratorVisitor::generateFunctionDebugInfo(llvm::Function *llvmFunction, c argTypes.push_back(getDITypeForSymbolType(argType)); llvm::DISubroutineType *functionTy = diBuilder->createSubroutineType(diBuilder->getOrCreateTypeArray(argTypes)); + llvm::DIFile *unit = diBuilder->createFile(debugInfo.compileUnit->getFilename(), debugInfo.compileUnit->getDirectory()); + size_t lineNumber = spiceFunc->getDeclCodeLoc().line; + llvm::DISubprogram *subprogram = diBuilder->createFunction(unit, spiceFunc->getName(), spiceFunc->getMangledName(), unit, lineNumber, functionTy, lineNumber, llvm::DINode::FlagZero, llvm::DISubprogram::SPFlagDefinition); @@ -3184,7 +3261,7 @@ void GeneratorVisitor::generateFunctionDebugInfo(llvm::Function *llvmFunction, c // Add debug info to LLVM function llvmFunction->setSubprogram(subprogram); // Add scope to lexicalBlocks - debugInfo.lexicalBlocks.push_back(subprogram); + debugInfo.lexicalBlocks.push(subprogram); } /*llvm::DIType *GeneratorVisitor::generateStructDebugInfo(llvm::StructType *llvmStructTy, const Struct *spiceStruct) const { @@ -3196,44 +3273,46 @@ void GeneratorVisitor::generateFunctionDebugInfo(llvm::Function *llvmFunction, c 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) - return; - // Get symbol table entry - SymbolTableEntry *variableEntry = currentScope->lookup(lhsVarName); - assert(variableEntry != nullptr); - // Build debug info +void GeneratorVisitor::generateGlobalVarDebugInfo(llvm::GlobalVariable *global, const SymbolTableEntry *globalEntry) { llvm::DIFile *unit = diBuilder->createFile(debugInfo.compileUnit->getFilename(), debugInfo.compileUnit->getDirectory()); - llvm::DIScope *scope = debugInfo.lexicalBlocks.back(); - llvm::DIType *diType = getDITypeForSymbolType(variableEntry->getType()); - llvm::DILocalVariable *varInfo = diBuilder->createAutoVariable(scope, currentVarName, unit, codeLoc.line, diType); - llvm::DIExpression *expr = diBuilder->createExpression(); - diBuilder->insertDbgAddrIntrinsic(address, varInfo, expr, builder->getCurrentDebugLocation(), allocaInsertBlock); + size_t lineNumber = globalEntry->getDeclCodeLoc().line; + llvm::StringRef name = global->getName(); + llvm::DIType *type = getDITypeForSymbolType(globalEntry->getType()); + bool isLocal = globalEntry->getSpecifiers().isPublic(); + + global->addDebugInfo(diBuilder->createGlobalVariableExpression(unit, name, name, unit, lineNumber, type, isLocal)); } -void GeneratorVisitor::generateAssignDebugInfo(const CodeLoc &codeLoc, const std::string &varName, llvm::Value *value) { +void GeneratorVisitor::generateDeclDebugInfo(const CodeLoc &codeLoc, const std::string &varName, llvm::Value *address, + bool moveToPrev) { if (!cliOptions.generateDebugInfo) return; // Get symbol table entry - SymbolTableEntry *variableEntry = currentScope->lookup(lhsVarName); + SymbolTableEntry *variableEntry = currentScope->lookup(varName); assert(variableEntry != nullptr); // Build debug info llvm::DIFile *unit = diBuilder->createFile(debugInfo.compileUnit->getFilename(), debugInfo.compileUnit->getDirectory()); - llvm::DIScope *scope = debugInfo.lexicalBlocks.back(); + llvm::DIScope *scope = debugInfo.lexicalBlocks.top(); llvm::DIType *diType = getDITypeForSymbolType(variableEntry->getType()); - llvm::DILocalVariable *varInfo = diBuilder->createAutoVariable(scope, currentVarName, unit, codeLoc.line, diType); + llvm::DILocalVariable *varInfo = diBuilder->createAutoVariable(scope, varName, unit, codeLoc.line, diType); llvm::DIExpression *expr = diBuilder->createExpression(); - // Insert intrinsic call - diBuilder->insertDbgValueIntrinsic(value, varInfo, expr, builder->getCurrentDebugLocation(), builder->GetInsertBlock()); + auto inst = diBuilder->insertDeclare(address, varInfo, expr, builder->getCurrentDebugLocation(), allocaInsertBlock); + if (moveToPrev) + inst->moveBefore(builder->GetInsertPoint()->getPrevNonDebugInstruction()); } -void GeneratorVisitor::emitSourceLocation(AstNode *node) { +void GeneratorVisitor::setSourceLocation(AstNode *node) { if (!cliOptions.generateDebugInfo) return; - if (debugInfo.lexicalBlocks.empty()) + + if (debugInfo.lexicalBlocks.empty()) { + builder->SetCurrentDebugLocation(llvm::DebugLoc()); return; - llvm::DIScope *scope = debugInfo.lexicalBlocks.back(); - builder->SetCurrentDebugLocation(llvm::DILocation::get(scope->getContext(), node->codeLoc.line, node->codeLoc.col, scope)); + } + + llvm::DIScope *scope = debugInfo.lexicalBlocks.top(); + auto codeLoc = llvm::DILocation::get(scope->getContext(), node->codeLoc.line, node->codeLoc.col, scope); + builder->SetCurrentDebugLocation(codeLoc); } llvm::OptimizationLevel GeneratorVisitor::getLLVMOptLevelFromSpiceOptLevel() const { diff --git a/src/generator/GeneratorVisitor.h b/src/generator/GeneratorVisitor.h index 18855b74f..85ed5ab67 100644 --- a/src/generator/GeneratorVisitor.h +++ b/src/generator/GeneratorVisitor.h @@ -113,7 +113,7 @@ class GeneratorVisitor : public AstVisitor { std::unique_ptr diBuilder; SymbolTable *currentScope; SymbolTable *rootScope; - SymbolType currentSymbolType; + SymbolType currentSymbolType = SymbolType(TY_INVALID); ScopePath scopePath; ThreadFactory &threadFactory; std::unique_ptr err; @@ -123,6 +123,7 @@ class GeneratorVisitor : public AstVisitor { std::stack breakBlocks; std::stack continueBlocks; bool constNegate = false; + bool withinConstantArray = false; bool allArgsHardcoded = true; llvm::Constant *currentConstValue = nullptr; bool currentConstSigned = true; @@ -133,11 +134,12 @@ class GeneratorVisitor : public AstVisitor { llvm::Type *structAccessType = nullptr; llvm::Value *dynamicArraySize = nullptr; llvm::Value *stackState = nullptr; + SymbolType arraySymbolType = SymbolType(TY_INVALID); bool secondRun = false; struct DebugInfo { llvm::DIFile *diFile; llvm::DICompileUnit *compileUnit; - std::vector lexicalBlocks; + std::stack lexicalBlocks; llvm::DIType *doubleTy; llvm::DIType *intTy; llvm::DIType *uIntTy; @@ -161,7 +163,7 @@ class GeneratorVisitor : public AstVisitor { void createCondBr(llvm::Value *condition, llvm::BasicBlock *trueBlock, llvm::BasicBlock *falseBlock); llvm::Value *insertAlloca(llvm::Type *llvmType, const std::string &varName = ""); llvm::Value *allocateDynamicallySizedArray(llvm::Type *itemType); - llvm::Value *createGlobalArray(llvm::Type *arrayType, const std::vector &itemConstants); + llvm::Value *createGlobalArray(llvm::Constant *constArray); bool insertDestructorCall(const CodeLoc &codeLoc, SymbolTableEntry *varEntry); llvm::Function *retrievePrintfFct(); llvm::Function *retrieveExitFct(); @@ -173,9 +175,9 @@ class GeneratorVisitor : public AstVisitor { 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; + void generateGlobalVarDebugInfo(llvm::GlobalVariable *global, const SymbolTableEntry *globalEntry); + void generateDeclDebugInfo(const CodeLoc &codeLoc, const std::string &varName, llvm::Value *address, bool moveToPrev = false); + void setSourceLocation(AstNode *node); [[nodiscard]] llvm::OptimizationLevel getLLVMOptLevelFromSpiceOptLevel() const; }; \ No newline at end of file diff --git a/src/generator/OpRuleConversionsManager.cpp b/src/generator/OpRuleConversionsManager.cpp index 9fd4e9eb4..c70cffa1b 100644 --- a/src/generator/OpRuleConversionsManager.cpp +++ b/src/generator/OpRuleConversionsManager.cpp @@ -41,10 +41,12 @@ llvm::Value *OpRuleConversionsManager::getPlusEqualInst(llvm::Value *lhs, llvm:: return builder->CreateAdd(lhs, rhs); 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '+=' operator for lhs=string and rhs=char yet"); 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '+=' operator for lhs=string and rhs=string yet"); case COMB(TY_PTR, TY_INT): // fallthrough case COMB(TY_PTR, TY_SHORT): // fallthrough case COMB(TY_PTR, TY_LONG): @@ -467,7 +469,8 @@ llvm::Value *OpRuleConversionsManager::getEqualInst(llvm::Value *lhs, llvm::Valu return builder->CreateICmpEQ(lhs, rhs); 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '==' operator for lhs=string and rhs=string yet"); case COMB(TY_BOOL, TY_BOOL): return builder->CreateICmpEQ(lhs, rhs); } @@ -572,7 +575,8 @@ llvm::Value *OpRuleConversionsManager::getNotEqualInst(llvm::Value *lhs, llvm::V return builder->CreateICmpNE(lhs, rhs); 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '!=' operator for lhs=string and rhs=string yet"); case COMB(TY_BOOL, TY_BOOL): return builder->CreateICmpNE(lhs, rhs); } @@ -945,7 +949,8 @@ llvm::Value *OpRuleConversionsManager::getPlusInst(llvm::Value *lhs, llvm::Value return builder->CreateAdd(lhs, rhs); 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '+' operator for lhs=string and rhs=string yet"); case COMB(TY_PTR, TY_INT): // fallthrough case COMB(TY_PTR, TY_SHORT): // fallthrough case COMB(TY_PTR, TY_LONG): @@ -1055,11 +1060,13 @@ llvm::Value *OpRuleConversionsManager::getMulInst(llvm::Value *lhs, llvm::Value } 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '*' operator for lhs=int and rhs=char yet"); } 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '*' operator for lhs=int and rhs=string yet"); } case COMB(TY_SHORT, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); @@ -1077,11 +1084,13 @@ llvm::Value *OpRuleConversionsManager::getMulInst(llvm::Value *lhs, llvm::Value } 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '*' operator for lhs=short and rhs=char yet"); } 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '*' operator for lhs=short and rhs=string yet"); } case COMB(TY_LONG, TY_DOUBLE): { llvm::Value *lhsFP = builder->CreateSIToFP(lhs, rhsTy); @@ -1096,37 +1105,45 @@ llvm::Value *OpRuleConversionsManager::getMulInst(llvm::Value *lhs, llvm::Value return builder->CreateMul(lhs, rhs); 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '*' operator for lhs=long and rhs=char yet"); } 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '*' operator for lhs=long and rhs=string yet"); } case COMB(TY_BYTE, TY_BYTE): return builder->CreateMul(lhs, rhs); 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '*' operator for lhs=char and rhs=int yet"); } 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '*' operator for lhs=char and rhs=short yet"); } 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '*' operator for lhs=char and rhs=long yet"); } 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '*' operator for lhs=string and rhs=int yet"); } 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '*' operator for lhs=string and rhs=short yet"); } 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"); + throw ErrorFactory::get(codeLoc, COMING_SOON_IR, + "The compiler does not support the '*' operator for lhs=string and rhs=long yet"); } } throw std::runtime_error("Internal compiler error: Operator fallthrough: *"); // GCOV_EXCL_LINE diff --git a/src/linker/LinkerInterface.cpp b/src/linker/LinkerInterface.cpp index e5e460a32..2dfb960bf 100644 --- a/src/linker/LinkerInterface.cpp +++ b/src/linker/LinkerInterface.cpp @@ -5,7 +5,6 @@ #include #include -#include #include #include #include @@ -69,6 +68,6 @@ void LinkerInterface::addLinkerFlag(const std::string &flag) { linkerFlags.push_ /** * Set executable output path * - * @param outputPath Output path + * @param path Output path */ -void LinkerInterface::setOutputPath(const std::string &outputPath) { this->outputPath = outputPath; } \ No newline at end of file +void LinkerInterface::setOutputPath(const std::string &path) { this->outputPath = path; } \ No newline at end of file diff --git a/src/linker/LinkerInterface.h b/src/linker/LinkerInterface.h index b1059819b..3424231e3 100644 --- a/src/linker/LinkerInterface.h +++ b/src/linker/LinkerInterface.h @@ -21,7 +21,7 @@ class LinkerInterface { void link(); void addObjectFilePath(const std::string &objectFilePath); void addLinkerFlag(const std::string &linkerFlag); - void setOutputPath(const std::string &outputPath); + void setOutputPath(const std::string &path); private: // Members diff --git a/src/parser/AstBuilderVisitor.cpp b/src/parser/AstBuilderVisitor.cpp index 91992632b..df81d6b2b 100644 --- a/src/parser/AstBuilderVisitor.cpp +++ b/src/parser/AstBuilderVisitor.cpp @@ -1193,30 +1193,30 @@ std::any AstBuilderVisitor::visitPrimitiveValue(SpiceParser::PrimitiveValueConte 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; + primitiveValueNode->type = PrimitiveValueNode::TYPE_DOUBLE; primitiveValueNode->data.doubleValue = std::stod(t->toString()); } else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::INT_LIT) { - primitiveValueNode->type = PrimitiveValueNode::TY_INT; + primitiveValueNode->type = PrimitiveValueNode::TYPE_INT; primitiveValueNode->data.intValue = parseInt(t->toString()); } else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::SHORT_LIT) { - primitiveValueNode->type = PrimitiveValueNode::TY_SHORT; + primitiveValueNode->type = PrimitiveValueNode::TYPE_SHORT; primitiveValueNode->data.shortValue = parseShort(t->toString()); } else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::LONG_LIT) { - primitiveValueNode->type = PrimitiveValueNode::TY_LONG; + primitiveValueNode->type = PrimitiveValueNode::TYPE_LONG; primitiveValueNode->data.longValue = parseLong(t->toString()); } else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::CHAR_LIT) { - primitiveValueNode->type = PrimitiveValueNode::TY_CHAR; + primitiveValueNode->type = PrimitiveValueNode::TYPE_CHAR; primitiveValueNode->data.charValue = parseChar(ctx->CHAR_LIT()->toString()); } else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::STRING_LIT) { - primitiveValueNode->type = PrimitiveValueNode::TY_STRING; + primitiveValueNode->type = PrimitiveValueNode::TYPE_STRING; primitiveValueNode->data.stringValue = parseString(ctx->STRING_LIT()->toString()); } else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::TRUE) { - primitiveValueNode->type = PrimitiveValueNode::TY_BOOL; + primitiveValueNode->type = PrimitiveValueNode::TYPE_BOOL; primitiveValueNode->data.boolValue = true; } else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::FALSE) { - primitiveValueNode->type = PrimitiveValueNode::TY_BOOL; + primitiveValueNode->type = PrimitiveValueNode::TYPE_BOOL; primitiveValueNode->data.boolValue = false; } else { assert(dynamic_cast(subTree)); // Fail if we did not get a terminal @@ -1312,7 +1312,7 @@ std::any AstBuilderVisitor::visitDataType(SpiceParser::DataTypeContext *ctx) { if (rule = dynamic_cast(subTree); rule != nullptr) // BaseDataType currentNode = dataTypeNode->createChild(CodeLoc(fileName, rule->start)); else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::MUL) - dataTypeNode->tmQueue.push({DataTypeNode::TY_POINTER, false, false, 0}); + dataTypeNode->tmQueue.push({DataTypeNode::TYPE_PTR, false, false, 0}); else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::LBRACKET) { i++; // Consume LBRACKET subTree = ctx->children[i]; @@ -1331,7 +1331,7 @@ std::any AstBuilderVisitor::visitDataType(SpiceParser::DataTypeContext *ctx) { hardCodedSize = std::stoi(t->getSymbol()->getText()); i++; // Consume INTEGER } - dataTypeNode->tmQueue.push({DataTypeNode::TY_ARRAY, hasSize, isHardcoded, hardCodedSize}); + dataTypeNode->tmQueue.push({DataTypeNode::TYPE_ARRAY, hasSize, isHardcoded, hardCodedSize}); } else assert(dynamic_cast(subTree)); // Fail if we did not get a terminal @@ -1353,23 +1353,23 @@ std::any AstBuilderVisitor::visitBaseDataType(SpiceParser::BaseDataTypeContext * currentNode = baseDataTypeNode->createChild(CodeLoc(fileName, rule->start)); } else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::TYPE_DOUBLE) - baseDataTypeNode->type = BaseDataTypeNode::TY_DOUBLE; + baseDataTypeNode->type = BaseDataTypeNode::TYPE_DOUBLE; else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::TYPE_INT) - baseDataTypeNode->type = BaseDataTypeNode::TY_INT; + baseDataTypeNode->type = BaseDataTypeNode::TYPE_INT; else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::TYPE_SHORT) - baseDataTypeNode->type = BaseDataTypeNode::TY_SHORT; + baseDataTypeNode->type = BaseDataTypeNode::TYPE_SHORT; else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::TYPE_LONG) - baseDataTypeNode->type = BaseDataTypeNode::TY_LONG; + baseDataTypeNode->type = BaseDataTypeNode::TYPE_LONG; else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::TYPE_BYTE) - baseDataTypeNode->type = BaseDataTypeNode::TY_BYTE; + baseDataTypeNode->type = BaseDataTypeNode::TYPE_BYTE; else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::TYPE_CHAR) - baseDataTypeNode->type = BaseDataTypeNode::TY_CHAR; + baseDataTypeNode->type = BaseDataTypeNode::TYPE_CHAR; else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::TYPE_STRING) - baseDataTypeNode->type = BaseDataTypeNode::TY_STRING; + baseDataTypeNode->type = BaseDataTypeNode::TYPE_STRING; else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::TYPE_BOOL) - baseDataTypeNode->type = BaseDataTypeNode::TY_BOOL; + baseDataTypeNode->type = BaseDataTypeNode::TYPE_BOOL; else if (auto t = dynamic_cast(subTree); t->getSymbol()->getType() == SpiceParser::TYPE_DYN) - baseDataTypeNode->type = BaseDataTypeNode::TY_DYN; + baseDataTypeNode->type = BaseDataTypeNode::TYPE_DYN; else assert(dynamic_cast(subTree)); // Fail if we did not get a terminal diff --git a/src/symbol/GenericType.h b/src/symbol/GenericType.h index 69ab91170..4d4f49cdc 100644 --- a/src/symbol/GenericType.h +++ b/src/symbol/GenericType.h @@ -7,9 +7,6 @@ #include -// Typedefs -typedef std::pair GenericTypeReplacement; // - class GenericType : public SymbolType { public: // Constructors diff --git a/src/symbol/Struct.cpp b/src/symbol/Struct.cpp index 22e4e3fc8..8c68e3d71 100644 --- a/src/symbol/Struct.cpp +++ b/src/symbol/Struct.cpp @@ -146,9 +146,9 @@ bool Struct::isFullySubstantiated() const { return hasSubstantiatedGenerics(); } /** * Set the associated symbol table * - * @param symbolTable Symbol table + * @param symTab Symbol table */ -void Struct::setSymbolTable(SymbolTable *symbolTable) { this->symbolTable = symbolTable; } +void Struct::setSymbolTable(SymbolTable *symTab) { this->symbolTable = symTab; } /** * Set the struct to used. The compiler only generates IR if the struct is used diff --git a/src/symbol/Struct.h b/src/symbol/Struct.h index f31a28b85..7624bc4bc 100644 --- a/src/symbol/Struct.h +++ b/src/symbol/Struct.h @@ -34,7 +34,7 @@ class Struct { [[nodiscard]] Struct substantiateGenerics(const std::vector &concreteTemplateTypes, SymbolTable *structScope) const; [[nodiscard]] bool hasSubstantiatedGenerics() const; [[nodiscard]] bool isFullySubstantiated() const; - void setSymbolTable(SymbolTable *symbolTable); + void setSymbolTable(SymbolTable *symTab); void setUsed(); [[nodiscard]] bool isUsed() const; [[nodiscard]] const CodeLoc &getDeclCodeLoc() const; diff --git a/src/symbol/SymbolTable.cpp b/src/symbol/SymbolTable.cpp index c20a11744..dc2b5dc0a 100644 --- a/src/symbol/SymbolTable.cpp +++ b/src/symbol/SymbolTable.cpp @@ -177,8 +177,8 @@ SymbolTable *SymbolTable::lookupTable(const std::string &tableName) { * @param childBlockName Name of the child scope * @return Newly created child table */ -SymbolTable *SymbolTable::createChildBlock(const std::string &childBlockName, const ScopeType &scopeType) { - children.insert({childBlockName, new SymbolTable(this, scopeType, isMainSourceFile)}); +SymbolTable *SymbolTable::createChildBlock(const std::string &childBlockName, const ScopeType &type) { + children.insert({childBlockName, new SymbolTable(this, type, isMainSourceFile)}); return children.at(childBlockName); } @@ -248,8 +248,10 @@ void SymbolTable::copyChildBlock(const std::string &originalChildBlockName, cons /** * Set the parent table of the current one in the tree structure + * + * @param parentTable Parent table */ -void SymbolTable::setParent(SymbolTable *parent) { this->parent = parent; } +void SymbolTable::setParent(SymbolTable *parentTable) { this->parent = parentTable; } /** * Retrieve the parent table of the current one in the tree structure @@ -459,7 +461,7 @@ Function *SymbolTable::matchFunction(SymbolTable *currentScope, const std::strin // Throw error if more than one function matches the criteria if (matches.size() > 1) - throw err->get( + throw ErrorFactory::get( codeLoc, FUNCTION_AMBIGUITY, "More than one function matches your requested signature criteria. Please try to specify the return type explicitly"); @@ -522,8 +524,8 @@ void SymbolTable::insertSubstantiatedFunction(const Function &function, ErrorFac std::string mangledFctName = function.getMangledName(); for (const auto &[_, manifestations] : functions) { if (manifestations->contains(mangledFctName)) - throw err->get(codeLoc, FUNCTION_DECLARED_TWICE, - "The function/procedure '" + function.getSignature() + "' is declared twice"); + throw ErrorFactory::get(codeLoc, FUNCTION_DECLARED_TWICE, + "The function/procedure '" + function.getSignature() + "' is declared twice"); } // Add function to function list assert(functions.contains(codeLoc.toString())); @@ -613,7 +615,7 @@ Struct *SymbolTable::matchStruct(SymbolTable *currentScope, const std::string &s // Throw error if more than one struct matches the criteria if (matches.size() > 1) - throw err->get( + throw ErrorFactory::get( codeLoc, STRUCT_AMBIGUITY, "More than one struct matches your requested signature criteria. Please try to specify the return type explicitly"); @@ -671,7 +673,7 @@ void SymbolTable::insertSubstantiatedStruct(const Struct &s, ErrorFactory *err, // Check if the struct exists already for (const auto &[_, manifestations] : structs) { if (manifestations->contains(s.getMangledName())) - throw err->get(codeLoc, STRUCT_DECLARED_TWICE, "The struct '" + s.getSignature() + "' is declared twice"); + throw ErrorFactory::get(codeLoc, STRUCT_DECLARED_TWICE, "The struct '" + s.getSignature() + "' is declared twice"); } // Add struct to struct list assert(structs.at(codeLoc.toString()) != nullptr); diff --git a/src/symbol/SymbolTable.h b/src/symbol/SymbolTable.h index f0122f1e9..f755ba135 100644 --- a/src/symbol/SymbolTable.h +++ b/src/symbol/SymbolTable.h @@ -55,14 +55,14 @@ class SymbolTable { Capture *lookupCapture(const std::string &symbolName); Capture *lookupCaptureStrict(const std::string &symbolName); SymbolTable *lookupTable(const std::string &tableName); - SymbolTable *createChildBlock(const std::string &childBlockName, const ScopeType &scopeType); + SymbolTable *createChildBlock(const std::string &childBlockName, const ScopeType &type); void insertGenericType(const std::string &typeName, const GenericType &genericType); GenericType *lookupGenericType(const std::string &typeName); void mountChildBlock(const std::string &childBlockName, SymbolTable *symbolTable, bool alterParent = true); void renameChildBlock(const std::string &oldName, const std::string &newName); void copyChildBlock(const std::string &originalChildBlockName, const std::string &newChildBlockName); - void setParent(SymbolTable *symbolTable); + void setParent(SymbolTable *parentTable); [[nodiscard]] SymbolTable *getParent() const; SymbolTable *getChild(const std::string &tableName); diff --git a/src/symbol/SymbolTableEntry.cpp b/src/symbol/SymbolTableEntry.cpp index 04f35f61d..4d5ae2cb6 100644 --- a/src/symbol/SymbolTableEntry.cpp +++ b/src/symbol/SymbolTableEntry.cpp @@ -65,7 +65,7 @@ SymbolState SymbolTableEntry::getState() const { return state; } void SymbolTableEntry::updateState(SymbolState newState, const ErrorFactory *err, const CodeLoc &codeLoc, bool force) { // Check if this is a constant variable and is already initialized if (state == INITIALIZED && specifiers.isConst() && !force) - throw err->get(codeLoc, REASSIGN_CONST_VARIABLE, "Not re-assignable variable '" + name + "'"); + throw ErrorFactory::get(codeLoc, REASSIGN_CONST_VARIABLE, "Not re-assignable variable '" + name + "'"); // Check if the type is known at time of initialization if (newState == INITIALIZED && type == SymbolType(TY_DYN)) // GCOV_EXCL_LINE throw std::runtime_error("Internal compiler error: could not determine type of variable '" + name + "'"); // GCOV_EXCL_LINE diff --git a/src/symbol/SymbolType.cpp b/src/symbol/SymbolType.cpp index c123fa739..73c719043 100644 --- a/src/symbol/SymbolType.cpp +++ b/src/symbol/SymbolType.cpp @@ -27,7 +27,7 @@ SymbolType::TypeChain SymbolType::getTypeChain() const { return typeChain; } SymbolType SymbolType::toPointer(const ErrorFactory *err, const CodeLoc &codeLoc, llvm::Value *dynamicSize) const { // Do not allow pointers of dyn if (typeChain.top().superType == TY_DYN) - throw err->get(codeLoc, DYN_POINTERS_NOT_ALLOWED, "Just use the dyn type without '*' instead"); + throw ErrorFactory::get(codeLoc, DYN_POINTERS_NOT_ALLOWED, "Just use the dyn type without '*' instead"); TypeChain newTypeChain = typeChain; newTypeChain.push({TY_PTR, "", {}, dynamicSize}); @@ -42,7 +42,7 @@ SymbolType SymbolType::toPointer(const ErrorFactory *err, const CodeLoc &codeLoc SymbolType SymbolType::toArray(const ErrorFactory *err, const CodeLoc &codeLoc, int size) const { // Do not allow arrays of dyn if (typeChain.top().superType == TY_DYN) - throw err->get(codeLoc, DYN_ARRAYS_NOT_ALLOWED, "Just use the dyn type without '[]' instead"); + throw ErrorFactory::get(codeLoc, DYN_ARRAYS_NOT_ALLOWED, "Just use the dyn type without '[]' instead"); TypeChain newTypeChain = typeChain; newTypeChain.push({TY_ARRAY, std::to_string(size), {}, nullptr}); @@ -109,7 +109,7 @@ SymbolType SymbolType::replaceBaseType(const SymbolType &newBaseType) const { * @return Corresponding LLVM type */ llvm::Type *SymbolType::toLLVMType(llvm::LLVMContext &context, SymbolTable *accessScope) const { - assert(!isOneOf({TY_DYN, TY_INVALID})); + assert(!typeChain.empty() && !isOneOf({TY_DYN, TY_INVALID})); if (is(TY_DOUBLE)) return llvm::Type::getDoubleTy(context); @@ -147,7 +147,8 @@ llvm::Type *SymbolType::toLLVMType(llvm::LLVMContext &context, SymbolTable *acce } if (isArray()) { - llvm::ArrayType *arrayType = llvm::ArrayType::get(getContainedTy().toLLVMType(context, accessScope), getArraySize()); + llvm::Type *containedType = getContainedTy().toLLVMType(context, accessScope); + llvm::ArrayType *arrayType = llvm::ArrayType::get(containedType, getArraySize()); return static_cast(arrayType); } @@ -413,7 +414,9 @@ std::string SymbolType::getNameFromChainElement(const TypeChainElement &chainEle case TY_ARRAY: { if (mangledName) return "array"; - return !withSize || chainElement.subType == "0" ? "[]" : "[" + chainElement.subType + "]"; + if (!withSize || chainElement.subType == "0") + return "[]"; + return chainElement.subType == "-1" ? "[size]" : "[" + chainElement.subType + "]"; } case TY_DOUBLE: return "double"; diff --git a/src/util/FileUtil.cpp b/src/util/FileUtil.cpp index 6f9df3c20..3006d743a 100644 --- a/src/util/FileUtil.cpp +++ b/src/util/FileUtil.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #ifdef __unix__ diff --git a/test/test-files/analyzer/builtins/error-sizeof-dyn-size-array/exception.out b/test/test-files/analyzer/builtins/error-sizeof-dyn-size-array/exception.out new file mode 100644 index 000000000..6aab87d71 --- /dev/null +++ b/test/test-files/analyzer/builtins/error-sizeof-dyn-size-array/exception.out @@ -0,0 +1 @@ +Semantic error in ./test-files/analyzer/builtins/error-sizeof-dyn-size-array/source.spice:4:18: Sizeof dynamically sized array: Cannot get sizeof dynamically sized array at compile time \ No newline at end of file diff --git a/test/test-files/analyzer/builtins/error-sizeof-dyn-size-array/source.spice b/test/test-files/analyzer/builtins/error-sizeof-dyn-size-array/source.spice new file mode 100644 index 000000000..f03e664ef --- /dev/null +++ b/test/test-files/analyzer/builtins/error-sizeof-dyn-size-array/source.spice @@ -0,0 +1,5 @@ +f main() { + int size = 5; + int[size] array; + printf("%d", sizeof(array)); +} \ No newline at end of file diff --git a/test/test-files/analyzer/variables/error-global-const-not-initialized/exception.out b/test/test-files/analyzer/variables/error-global-const-not-initialized/exception.out new file mode 100644 index 000000000..89bd3d87a --- /dev/null +++ b/test/test-files/analyzer/variables/error-global-const-not-initialized/exception.out @@ -0,0 +1 @@ +Semantic error in ./test-files/analyzer/variables/error-global-const-not-initialized/source.spice:1:1: Global const without value: You must specify a value for constant global variables \ No newline at end of file diff --git a/test/test-files/analyzer/variables/error-global-const-not-initialized/source.spice b/test/test-files/analyzer/variables/error-global-const-not-initialized/source.spice new file mode 100644 index 000000000..14fad0c4f --- /dev/null +++ b/test/test-files/analyzer/variables/error-global-const-not-initialized/source.spice @@ -0,0 +1,5 @@ +const int count; + +f main() { + printf("Test"); +} \ 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 2150545c0..207b1968f 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 @@ -12,25 +12,25 @@ entry.l1: br i1 %2, label %if.then.l2, label %if.end.l2 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 + %.tr7.lcssa = phi i32 [ %1, %entry.l1 ], [ %.tr7.be, %tailrecurse.backedge ] + %3 = add i32 %.tr7.lcssa, 1 ret i32 %3 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 + %.tr79 = phi i32 [ %.tr7.be, %tailrecurse.backedge ], [ %1, %entry.l1 ] + %.tr8 = phi i32 [ %.tr.be, %tailrecurse.backedge ], [ %0, %entry.l1 ] + %4 = icmp eq i32 %.tr79, 0 br i1 %4, label %tailrecurse.backedge, label %if.end.l3 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 + %.tr7.be = phi i32 [ %7, %if.end.l3 ], [ 1, %if.end.l2 ] + %.tr.be = add i32 %.tr8, -1 %5 = icmp eq i32 %.tr.be, 0 br i1 %5, label %if.then.l2, label %if.end.l2 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) + %6 = add i32 %.tr79, -1 + %7 = tail call fastcc i32 @_f__void__ack__int_int(i32 %.tr8, i32 %6) br label %tailrecurse.backedge } 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 8358cde0a..45e81a49f 100644 --- a/test/test-files/generator/arbitrary/success-ackermann/ir-code.ll +++ b/test/test-files/generator/arbitrary/success-ackermann/ir-code.ll @@ -8,88 +8,88 @@ target triple = "x86_64-w64-windows-gnu" define internal i32 @_f__void__ack__int_int(i32 %0, i32 %1) { entry.l1: %m = alloca i32, align 4 + store i32 %0, ptr %m, align 4 %n = alloca i32, align 4 + store i32 %1, ptr %n, align 4 %result = alloca i32, align 4 - %2 = alloca i1, align 1 - %3 = alloca i32, align 4 + %2 = load i32, ptr %m, align 4 + %3 = icmp eq i32 %2, 0 %4 = alloca i1, align 1 - %5 = alloca i32, align 4 - %6 = alloca i32, align 4 - %7 = alloca i32, align 4 - %8 = alloca i32, align 4 - %9 = alloca i32, align 4 - %10 = alloca i32, align 4 - %11 = alloca i32, 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, ptr %2, align 1 - %14 = load i1, ptr %2, align 1 - br i1 %14, label %if.then.l2, label %if.end.l2 + store i1 %3, ptr %4, align 1 + %5 = load i1, ptr %4, align 1 + br i1 %5, label %if.then.l2, label %if.end.l2 if.then.l2: ; preds = %entry.l1 - %15 = load i32, ptr %n, align 4 - %16 = add i32 %15, 1 - store i32 %16, ptr %3, align 4 - %17 = load i32, ptr %3, align 4 - ret i32 %17 + %6 = load i32, ptr %n, align 4 + %7 = add i32 %6, 1 + %8 = alloca i32, align 4 + store i32 %7, ptr %8, align 4 + %9 = load i32, ptr %8, align 4 + ret i32 %9 if.end.l2: ; preds = %entry.l1 - %18 = load i32, ptr %n, align 4 - %19 = icmp eq i32 %18, 0 - 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 + %10 = load i32, ptr %n, align 4 + %11 = icmp eq i32 %10, 0 + %12 = alloca i1, align 1 + store i1 %11, ptr %12, align 1 + %13 = load i1, ptr %12, align 1 + br i1 %13, label %if.then.l3, label %if.end.l3 if.then.l3: ; preds = %if.end.l2 - %21 = load i32, ptr %m, align 4 - %22 = sub i32 %21, 1 - 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, ptr %7, align 4 - %26 = load i32, ptr %7, align 4 - ret i32 %26 + %14 = load i32, ptr %m, align 4 + %15 = sub i32 %14, 1 + %16 = alloca i32, align 4 + store i32 %15, ptr %16, align 4 + %17 = load i32, ptr %16, align 4 + %18 = alloca i32, align 4 + store i32 1, ptr %18, align 4 + %19 = load i32, ptr %18, align 4 + %20 = call i32 @_f__void__ack__int_int(i32 %17, i32 %19) + %21 = alloca i32, align 4 + store i32 %20, ptr %21, align 4 + %22 = load i32, ptr %21, align 4 + ret i32 %22 if.end.l3: ; preds = %if.end.l2 + %23 = load i32, ptr %m, align 4 + %24 = sub i32 %23, 1 + %25 = alloca i32, align 4 + store i32 %24, ptr %25, align 4 + %26 = load i32, ptr %25, align 4 %27 = load i32, ptr %m, align 4 - %28 = sub i32 %27, 1 - 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, 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, 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, ptr %11, align 4 - %37 = load i32, ptr %11, align 4 + %28 = load i32, ptr %n, align 4 + %29 = sub i32 %28, 1 + %30 = alloca i32, align 4 + store i32 %29, ptr %30, align 4 + %31 = load i32, ptr %30, align 4 + %32 = call i32 @_f__void__ack__int_int(i32 %27, i32 %31) + %33 = alloca i32, align 4 + store i32 %32, ptr %33, align 4 + %34 = load i32, ptr %33, align 4 + %35 = call i32 @_f__void__ack__int_int(i32 %26, i32 %34) + %36 = alloca i32, align 4 + store i32 %35, ptr %36, align 4 + %37 = load i32, ptr %36, align 4 ret i32 %37 } define i32 @main() { 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, ptr %result, align 4 + %baseM = alloca i32, align 4 store i32 3, ptr %baseM, align 4 + %baseN = alloca i32, 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, ptr %0, align 4 - %6 = load i32, ptr %0, align 4 - %7 = call i32 (ptr, ...) @printf(ptr @0, i32 %1, i32 %2, i32 %6) + %0 = load i32, ptr %baseM, align 4 + %1 = load i32, ptr %baseN, align 4 + %2 = load i32, ptr %baseM, align 4 + %3 = load i32, ptr %baseN, align 4 + %4 = call i32 @_f__void__ack__int_int(i32 %2, i32 %3) + %5 = alloca i32, align 4 + store i32 %4, ptr %5, align 4 + %6 = load i32, ptr %5, align 4 + %7 = call i32 (ptr, ...) @printf(ptr @0, i32 %0, i32 %1, i32 %6) %8 = load i32, ptr %result, align 4 ret i32 %8 } 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 561ecf929..bdc9d9cef 100644 --- a/test/test-files/generator/arbitrary/success-faculty/ir-code.ll +++ b/test/test-files/generator/arbitrary/success-faculty/ir-code.ll @@ -8,36 +8,36 @@ target triple = "x86_64-w64-windows-gnu" define internal i32 @_f__void__faculty__int(i32 %0) { entry.l1: %input = alloca i32, align 4 - %result = alloca i32, align 4 - %1 = alloca i1, align 1 - %2 = alloca i32, align 4 - %3 = alloca i32, align 4 - %4 = alloca i32, align 4 - %5 = alloca i32, 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, ptr %1, align 1 - %8 = load i1, ptr %1, align 1 - br i1 %8, label %if.then.l2, label %if.end.l2 + %result = alloca i32, align 4 + %1 = load i32, ptr %input, align 4 + %2 = icmp slt i32 %1, 2 + %3 = alloca i1, align 1 + store i1 %2, ptr %3, align 1 + %4 = load i1, ptr %3, align 1 + br i1 %4, label %if.then.l2, label %if.end.l2 if.then.l2: ; preds = %entry.l1 - store i32 1, ptr %2, align 4 - %9 = load i32, ptr %2, align 4 - ret i32 %9 + %5 = alloca i32, align 4 + store i32 1, ptr %5, align 4 + %6 = load i32, ptr %5, align 4 + ret i32 %6 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, ptr %3, align 4 - %13 = load i32, ptr %3, align 4 - %14 = call i32 @_f__void__faculty__int(i32 %13) - store i32 %14, ptr %4, align 4 - %15 = load i32, ptr %4, align 4 - %16 = mul i32 %10, %15 - store i32 %16, ptr %5, align 4 - %17 = load i32, ptr %5, align 4 + %7 = load i32, ptr %input, align 4 + %8 = load i32, ptr %input, align 4 + %9 = sub i32 %8, 1 + %10 = alloca i32, align 4 + store i32 %9, ptr %10, align 4 + %11 = load i32, ptr %10, align 4 + %12 = call i32 @_f__void__faculty__int(i32 %11) + %13 = alloca i32, align 4 + store i32 %12, ptr %13, align 4 + %14 = load i32, ptr %13, align 4 + %15 = mul i32 %7, %14 + %16 = alloca i32, align 4 + store i32 %15, ptr %16, align 4 + %17 = load i32, ptr %16, align 4 store i32 %17, ptr %result, align 4 %18 = load i32, ptr %result, align 4 ret i32 %18 @@ -46,15 +46,15 @@ if.end.l2: ; preds = %entry.l1 define i32 @main() { entry.l8: %result = alloca i32, align 4 - %input = alloca i32, align 4 - %0 = alloca i32, align 4 store i32 0, ptr %result, align 4 + %input = alloca i32, 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, ptr %0, align 4 + %0 = load i32, ptr %input, align 4 + %1 = call i32 @_f__void__faculty__int(i32 %0) + %2 = alloca i32, align 4 + store i32 %1, ptr %2, align 4 %3 = load i32, ptr %input, align 4 - %4 = load i32, ptr %0, align 4 + %4 = load i32, ptr %2, align 4 %5 = call i32 (ptr, ...) @printf(ptr @0, i32 %3, i32 %4) %6 = load i32, ptr %result, align 4 ret i32 %6 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 3876486f3..835e4ec57 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 @@ -22,13 +22,13 @@ common.ret: ; preds = %common.ret.loopexit ret i32 %accumulator.tr.lcssa 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 + %.tr4 = phi i32 [ %4, %if.end.l2 ], [ %0, %entry.l1 ] + %accumulator.tr3 = phi i32 [ %5, %if.end.l2 ], [ 0, %entry.l1 ] + %2 = add nsw i32 %.tr4, -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 + %4 = add nsw i32 %.tr4, -2 + %5 = add i32 %3, %accumulator.tr3 + %6 = icmp ult i32 %.tr4, 5 br i1 %6, label %common.ret.loopexit, label %if.end.l2 } 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 51a14b479..d4439c608 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 @@ -20,13 +20,13 @@ common.ret: ; preds = %common.ret.loopexit ret i32 %accumulator.tr.lcssa 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 + %.tr4 = phi i32 [ %4, %if.end.l2 ], [ %0, %entry.l1 ] + %accumulator.tr3 = phi i32 [ %5, %if.end.l2 ], [ 0, %entry.l1 ] + %2 = add nsw i32 %.tr4, -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 + %4 = add nsw i32 %.tr4, -2 + %5 = add i32 %3, %accumulator.tr3 + %6 = icmp ult i32 %.tr4, 5 br i1 %6, label %common.ret.loopexit, label %if.end.l2 } 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 ab35101f1..d49f974b6 100644 --- a/test/test-files/generator/arbitrary/success-fibonacci/ir-code.ll +++ b/test/test-files/generator/arbitrary/success-fibonacci/ir-code.ll @@ -8,60 +8,60 @@ target triple = "x86_64-w64-windows-gnu" define internal i32 @_f__void__fib__int(i32 %0) { entry.l1: %n = alloca i32, align 4 - %result = alloca i32, align 4 - %1 = alloca i1, align 1 - %2 = alloca i32, align 4 - %3 = alloca i32, align 4 - %4 = alloca i32, align 4 - %5 = alloca i32, align 4 - %6 = alloca i32, align 4 - %7 = alloca i32, 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, ptr %1, align 1 - %10 = load i1, ptr %1, align 1 - br i1 %10, label %if.then.l2, label %if.end.l2 + %result = alloca i32, align 4 + %1 = load i32, ptr %n, align 4 + %2 = icmp sle i32 %1, 2 + %3 = alloca i1, align 1 + store i1 %2, ptr %3, align 1 + %4 = load i1, ptr %3, align 1 + br i1 %4, label %if.then.l2, label %if.end.l2 if.then.l2: ; preds = %entry.l1 - store i32 1, ptr %2, align 4 - %11 = load i32, ptr %2, align 4 - ret i32 %11 + %5 = alloca i32, align 4 + store i32 1, ptr %5, align 4 + %6 = load i32, ptr %5, align 4 + ret i32 %6 if.end.l2: ; preds = %entry.l1 - %12 = load i32, ptr %n, align 4 - %13 = sub i32 %12, 1 - 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, 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, ptr %5, align 4 - %19 = load i32, ptr %5, align 4 - %20 = call i32 @_f__void__fib__int(i32 %19) - store i32 %20, ptr %6, align 4 - %21 = load i32, ptr %6, align 4 - %22 = add i32 %16, %21 - store i32 %22, ptr %7, align 4 - %23 = load i32, ptr %7, align 4 + %7 = load i32, ptr %n, align 4 + %8 = sub i32 %7, 1 + %9 = alloca i32, align 4 + store i32 %8, ptr %9, align 4 + %10 = load i32, ptr %9, align 4 + %11 = call i32 @_f__void__fib__int(i32 %10) + %12 = alloca i32, align 4 + store i32 %11, ptr %12, align 4 + %13 = load i32, ptr %12, align 4 + %14 = load i32, ptr %n, align 4 + %15 = sub i32 %14, 2 + %16 = alloca i32, align 4 + store i32 %15, ptr %16, align 4 + %17 = load i32, ptr %16, align 4 + %18 = call i32 @_f__void__fib__int(i32 %17) + %19 = alloca i32, align 4 + store i32 %18, ptr %19, align 4 + %20 = load i32, ptr %19, align 4 + %21 = add i32 %13, %20 + %22 = alloca i32, align 4 + store i32 %21, ptr %22, align 4 + %23 = load i32, ptr %22, align 4 ret i32 %23 } define i32 @main() { entry.l6: %result = alloca i32, align 4 - %base = alloca i32, align 4 - %0 = alloca i32, align 4 store i32 0, ptr %result, align 4 + %base = alloca i32, align 4 store i32 46, ptr %base, align 4 + %0 = load i32, 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, ptr %0, align 4 - %4 = load i32, ptr %0, align 4 - %5 = call i32 (ptr, ...) @printf(ptr @0, i32 %1, i32 %4) + %2 = call i32 @_f__void__fib__int(i32 %1) + %3 = alloca i32, align 4 + store i32 %2, ptr %3, align 4 + %4 = load i32, ptr %3, align 4 + %5 = call i32 (ptr, ...) @printf(ptr @0, i32 %0, i32 %4) %6 = load i32, ptr %result, align 4 ret i32 %6 } 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 d65d44385..3940ec52c 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 @@ -11,24 +11,24 @@ entry.l4: br label %for.l21 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 + %i.035 = phi i32 [ 0, %entry.l4 ], [ %29, %for.inc.l21 ] + %printedDigits.134 = phi i32 [ 0, %entry.l4 ], [ %printedDigits.0, %for.inc.l21 ] + %q.133 = phi i64 [ 1, %entry.l4 ], [ %q.0, %for.inc.l21 ] + %x.132 = phi i64 [ 3, %entry.l4 ], [ %x.0, %for.inc.l21 ] + %r.131 = phi i64 [ 0, %entry.l4 ], [ %r.0, %for.inc.l21 ] + %m.130 = phi i64 [ 3, %entry.l4 ], [ %m.0, %for.inc.l21 ] + %k.129 = phi i64 [ 1, %entry.l4 ], [ %k.0, %for.inc.l21 ] + %t.128 = phi i64 [ 1, %entry.l4 ], [ %t.0, %for.inc.l21 ] + %0 = shl i64 %q.133, 2 + %1 = sub i64 %r.131, %t.128 %2 = add i64 %1, %0 - %3 = mul i64 %t.160, %m.158 + %3 = mul i64 %m.130, %t.128 %4 = icmp slt i64 %2, %3 br i1 %4, label %if.then.l22, label %if.else.l22 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 + %5 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i64 %m.130) + %6 = icmp eq i32 %printedDigits.134, 0 br i1 %6, label %if.then.l24, label %if.end.l24 if.then.l24: ; preds = %if.then.l22 @@ -36,43 +36,43 @@ if.then.l24: ; preds = %if.then.l22 br label %if.end.l24 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 + %7 = add i32 %printedDigits.134, 1 + %8 = mul i64 %q.133, 10 + %9 = sub i64 %r.131, %3 %10 = mul i64 %9, 10 - %11 = mul i64 %q.162, 3 - %12 = add i64 %11, %r.161 + %11 = mul i64 %q.133, 3 + %12 = add i64 %11, %r.131 %13 = mul i64 %12, 10 - %14 = sdiv i64 %13, %t.160 - %.neg = mul i64 %m.158, -10 + %14 = sdiv i64 %13, %t.128 + %.neg = mul i64 %m.130, -10 %15 = add i64 %14, %.neg br label %for.inc.l21 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 + %16 = mul i64 %q.133, %k.129 + %17 = shl i64 %q.133, 1 + %18 = add i64 %17, %r.131 + %19 = mul i64 %18, %x.132 + %20 = mul i64 %x.132, %t.128 + %21 = add i64 %k.129, 1 + %22 = mul i64 %k.129, 7 %23 = add i64 %22, 2 - %24 = mul i64 %q.162, %23 - %25 = mul i64 %r.161, %x.157 + %24 = mul i64 %q.133, %23 + %25 = mul i64 %x.132, %r.131 %26 = add i64 %24, %25 %27 = sdiv i64 %26, %20 - %28 = add i64 %x.157, 2 + %28 = add i64 %x.132, 2 br label %for.inc.l21 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 ] + %t.0 = phi i64 [ %t.128, %if.end.l24 ], [ %20, %if.else.l22 ] + %k.0 = phi i64 [ %k.129, %if.end.l24 ], [ %21, %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 ] + %x.0 = phi i64 [ %x.132, %if.end.l24 ], [ %28, %if.else.l22 ] %q.0 = phi i64 [ %8, %if.end.l24 ], [ %16, %if.else.l22 ] - %29 = add nuw nsw i32 %i.055, 1 + %printedDigits.0 = phi i32 [ %7, %if.end.l24 ], [ %printedDigits.134, %if.else.l22 ] + %29 = add nuw nsw i32 %i.035, 1 %exitcond.not = icmp eq i32 %29, 20 br i1 %exitcond.not, label %for.end.l21, label %for.l21 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 22bb8b9dd..b70dbe3b3 100644 --- a/test/test-files/generator/arbitrary/success-pidigits/ir-code.ll +++ b/test/test-files/generator/arbitrary/success-pidigits/ir-code.ll @@ -9,244 +9,244 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l4: %result = alloca i32, align 4 - %q = alloca i64, align 8 - %q_new = alloca i64, align 8 - %r = alloca i64, align 8 - %r_new = alloca i64, align 8 - %t = alloca i64, align 8 - %t_new = alloca i64, align 8 - %k = alloca i64, align 8 - %k_new = alloca i64, align 8 - %m = alloca i64, align 8 - %m_new = alloca i64, align 8 - %x = alloca i64, align 8 - %x_new = alloca i64, align 8 - %iterations = alloca i32, align 4 - %printedDigits = alloca i32, align 4 - %i = alloca i32, align 4 - %0 = alloca i64, align 8 - %1 = alloca i64, align 8 - %2 = alloca i64, align 8 - %3 = alloca i1, align 1 - %4 = alloca i1, align 1 - %5 = alloca i32, align 4 - %6 = alloca i64, align 8 - %7 = alloca i64, align 8 - %8 = alloca i64, align 8 - %9 = alloca i64, align 8 - %10 = alloca i64, align 8 - %11 = alloca i64, align 8 - %12 = alloca i64, align 8 - %13 = alloca i64, align 8 - %14 = alloca i64, align 8 - %15 = alloca i64, align 8 - %16 = alloca i64, align 8 - %17 = alloca i64, align 8 - %18 = alloca i64, align 8 - %19 = alloca i64, align 8 - %20 = alloca i64, align 8 - %21 = alloca i64, align 8 - %22 = alloca i64, align 8 - %23 = alloca i64, align 8 - %24 = alloca i64, align 8 - %25 = alloca i64, align 8 - %26 = alloca i64, align 8 - %27 = alloca i64, align 8 - %28 = alloca i64, align 8 - %29 = alloca i32, align 4 - %30 = alloca i1, align 1 store i32 0, ptr %result, align 4 + %q = alloca i64, align 8 store i64 1, ptr %q, align 8 + %q_new = alloca i64, align 8 store i64 0, ptr %q_new, align 8 + %r = alloca i64, align 8 store i64 0, ptr %r, align 8 + %r_new = alloca i64, align 8 store i64 0, ptr %r_new, align 8 + %t = alloca i64, align 8 store i64 1, ptr %t, align 8 + %t_new = alloca i64, align 8 store i64 0, ptr %t_new, align 8 + %k = alloca i64, align 8 store i64 1, ptr %k, align 8 + %k_new = alloca i64, align 8 store i64 0, ptr %k_new, align 8 + %m = alloca i64, align 8 store i64 3, ptr %m, align 8 + %m_new = alloca i64, align 8 store i64 0, ptr %m_new, align 8 + %x = alloca i64, align 8 store i64 3, ptr %x, align 8 + %x_new = alloca i64, align 8 store i64 0, ptr %x_new, align 8 + %iterations = alloca i32, align 4 store i32 20, ptr %iterations, align 4 + %printedDigits = alloca i32, align 4 store i32 0, ptr %printedDigits, align 4 + %i = alloca i32, align 4 store i32 0, ptr %i, align 4 br label %for.cond.l21 for.l21: ; preds = %for.cond.l21 - %31 = load i64, ptr %q, align 8 - %32 = mul i64 4, %31 - 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, ptr %t, align 8 - %37 = sub i64 %35, %36 - 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, ptr %2, align 8 - %42 = load i64, ptr %2, align 8 - %43 = icmp slt i64 %38, %42 - 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 + %0 = load i64, ptr %q, align 8 + %1 = mul i64 4, %0 + %2 = alloca i64, align 8 + store i64 %1, ptr %2, align 8 + %3 = load i64, ptr %2, align 8 + %4 = load i64, ptr %r, align 8 + %5 = add i64 %3, %4 + %6 = load i64, ptr %t, align 8 + %7 = sub i64 %5, %6 + %8 = alloca i64, align 8 + store i64 %7, ptr %8, align 8 + %9 = load i64, ptr %8, align 8 + %10 = load i64, ptr %m, align 8 + %11 = load i64, ptr %t, align 8 + %12 = mul i64 %10, %11 + %13 = alloca i64, align 8 + store i64 %12, ptr %13, align 8 + %14 = load i64, ptr %13, align 8 + %15 = icmp slt i64 %9, %14 + %16 = alloca i1, align 1 + store i1 %15, ptr %16, align 1 + %17 = load i1, ptr %16, align 1 + br i1 %17, label %if.then.l22, label %if.else.l22 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, ptr %4, align 1 - %49 = load i1, ptr %4, align 1 - br i1 %49, label %if.then.l24, label %if.end.l24 + %18 = load i64, ptr %m, align 8 + %19 = call i32 (ptr, ...) @printf(ptr @0, i64 %18) + %20 = load i32, ptr %printedDigits, align 4 + %21 = icmp eq i32 %20, 0 + %22 = alloca i1, align 1 + store i1 %21, ptr %22, align 1 + %23 = load i1, ptr %22, align 1 + br i1 %23, label %if.then.l24, label %if.end.l24 if.then.l24: ; preds = %if.then.l22 - %50 = call i32 (ptr, ...) @printf(ptr @1) + %24 = call i32 (ptr, ...) @printf(ptr @1) br label %if.end.l24 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, 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, 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, ptr %7, align 8 - %60 = load i64, ptr %7, align 8 - %61 = sub i64 %56, %60 - store i64 %61, ptr %8, align 8 - %62 = load i64, ptr %8, align 8 - %63 = mul i64 10, %62 - 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, 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, ptr %11, align 8 - %70 = load i64, ptr %11, align 8 - %71 = mul i64 10, %70 - 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, 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, ptr %14, align 8 - %78 = load i64, ptr %14, align 8 - %79 = sub i64 %75, %78 - 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 + %25 = load i32, ptr %printedDigits, align 4 + %26 = add i32 %25, 1 + store i32 %26, ptr %printedDigits, align 4 + %27 = alloca i32, align 4 + store i32 %25, ptr %27, align 4 + %28 = load i64, ptr %q, align 8 + %29 = mul i64 10, %28 + %30 = alloca i64, align 8 + store i64 %29, ptr %30, align 8 + %31 = load i64, ptr %30, align 8 + store i64 %31, ptr %q_new, align 8 + %32 = load i64, ptr %r, align 8 + %33 = load i64, ptr %m, align 8 + %34 = load i64, ptr %t, align 8 + %35 = mul i64 %33, %34 + %36 = alloca i64, align 8 + store i64 %35, ptr %36, align 8 + %37 = load i64, ptr %36, align 8 + %38 = sub i64 %32, %37 + %39 = alloca i64, align 8 + store i64 %38, ptr %39, align 8 + %40 = load i64, ptr %39, align 8 + %41 = mul i64 10, %40 + %42 = alloca i64, align 8 + store i64 %41, ptr %42, align 8 + %43 = load i64, ptr %42, align 8 + store i64 %43, ptr %r_new, align 8 + %44 = load i64, ptr %q, align 8 + %45 = mul i64 3, %44 + %46 = alloca i64, align 8 + store i64 %45, ptr %46, align 8 + %47 = load i64, ptr %46, align 8 + %48 = load i64, ptr %r, align 8 + %49 = add i64 %47, %48 + %50 = alloca i64, align 8 + store i64 %49, ptr %50, align 8 + %51 = load i64, ptr %50, align 8 + %52 = mul i64 10, %51 + %53 = alloca i64, align 8 + store i64 %52, ptr %53, align 8 + %54 = load i64, ptr %53, align 8 + %55 = load i64, ptr %t, align 8 + %56 = sdiv i64 %54, %55 + %57 = alloca i64, align 8 + store i64 %56, ptr %57, align 8 + %58 = load i64, ptr %57, align 8 + %59 = load i64, ptr %m, align 8 + %60 = mul i64 10, %59 + %61 = alloca i64, align 8 + store i64 %60, ptr %61, align 8 + %62 = load i64, ptr %61, align 8 + %63 = sub i64 %58, %62 + %64 = alloca i64, align 8 + store i64 %63, ptr %64, align 8 + %65 = load i64, ptr %64, align 8 + store i64 %65, ptr %m, align 8 + %66 = load i64, ptr %q_new, align 8 + store i64 %66, ptr %q, align 8 + %67 = load i64, ptr %r_new, align 8 + store i64 %67, ptr %r, align 8 br label %if.end.l22 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, 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, 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, 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, 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, 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, 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, ptr %22, align 8 - %106 = load i64, ptr %22, align 8 - %107 = add i64 %106, 2 - store i64 %107, ptr %23, align 8 - %108 = load i64, ptr %23, align 8 - %109 = mul i64 %103, %108 - 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, ptr %25, align 8 - %114 = load i64, ptr %25, align 8 - %115 = add i64 %110, %114 - 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, ptr %27, align 8 - %120 = load i64, ptr %27, align 8 - %121 = sdiv i64 %116, %120 - 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, 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 + %68 = load i64, ptr %q, align 8 + %69 = load i64, ptr %k, align 8 + %70 = mul i64 %68, %69 + %71 = alloca i64, align 8 + store i64 %70, ptr %71, align 8 + %72 = load i64, ptr %71, align 8 + store i64 %72, ptr %q_new, align 8 + %73 = load i64, ptr %q, align 8 + %74 = mul i64 2, %73 + %75 = alloca i64, align 8 + store i64 %74, ptr %75, align 8 + %76 = load i64, ptr %75, align 8 + %77 = load i64, ptr %r, align 8 + %78 = add i64 %76, %77 + %79 = alloca i64, align 8 + store i64 %78, ptr %79, align 8 + %80 = load i64, ptr %79, align 8 + %81 = load i64, ptr %x, align 8 + %82 = mul i64 %80, %81 + %83 = alloca i64, align 8 + store i64 %82, ptr %83, align 8 + %84 = load i64, ptr %83, align 8 + store i64 %84, ptr %r_new, align 8 + %85 = load i64, ptr %t, align 8 + %86 = load i64, ptr %x, align 8 + %87 = mul i64 %85, %86 + %88 = alloca i64, align 8 + store i64 %87, ptr %88, align 8 + %89 = load i64, ptr %88, align 8 + store i64 %89, ptr %t_new, align 8 + %90 = load i64, ptr %k, align 8 + %91 = add i64 %90, 1 + %92 = alloca i64, align 8 + store i64 %91, ptr %92, align 8 + %93 = load i64, ptr %92, align 8 + store i64 %93, ptr %k_new, align 8 + %94 = load i64, ptr %q, align 8 + %95 = load i64, ptr %k, align 8 + %96 = mul i64 7, %95 + %97 = alloca i64, align 8 + store i64 %96, ptr %97, align 8 + %98 = load i64, ptr %97, align 8 + %99 = add i64 %98, 2 + %100 = alloca i64, align 8 + store i64 %99, ptr %100, align 8 + %101 = load i64, ptr %100, align 8 + %102 = mul i64 %94, %101 + %103 = alloca i64, align 8 + store i64 %102, ptr %103, align 8 + %104 = load i64, ptr %103, align 8 + %105 = load i64, ptr %r, align 8 + %106 = load i64, ptr %x, align 8 + %107 = mul i64 %105, %106 + %108 = alloca i64, align 8 + store i64 %107, ptr %108, align 8 + %109 = load i64, ptr %108, align 8 + %110 = add i64 %104, %109 + %111 = alloca i64, align 8 + store i64 %110, ptr %111, align 8 + %112 = load i64, ptr %111, align 8 + %113 = load i64, ptr %t, align 8 + %114 = load i64, ptr %x, align 8 + %115 = mul i64 %113, %114 + %116 = alloca i64, align 8 + store i64 %115, ptr %116, align 8 + %117 = load i64, ptr %116, align 8 + %118 = sdiv i64 %112, %117 + %119 = alloca i64, align 8 + store i64 %118, ptr %119, align 8 + %120 = load i64, ptr %119, align 8 + store i64 %120, ptr %m, align 8 + %121 = load i64, ptr %x, align 8 + %122 = add i64 %121, 2 + store i64 %122, ptr %x, align 8 + %123 = load i64, ptr %q_new, align 8 + store i64 %123, ptr %q, align 8 + %124 = load i64, ptr %r_new, align 8 + store i64 %124, ptr %r, align 8 + %125 = load i64, ptr %t_new, align 8 + store i64 %125, ptr %t, align 8 + %126 = load i64, ptr %k_new, align 8 + store i64 %126, ptr %k, align 8 br label %if.end.l22 if.end.l22: ; preds = %if.else.l22, %if.end.l24 br label %for.inc.l21 for.inc.l21: ; preds = %if.end.l22 - %129 = load i32, ptr %i, align 4 - %130 = add i32 %129, 1 - store i32 %130, ptr %i, align 4 - store i32 %129, ptr %29, align 4 + %127 = load i32, ptr %i, align 4 + %128 = add i32 %127, 1 + store i32 %128, ptr %i, align 4 + %129 = alloca i32, align 4 + store i32 %127, ptr %129, align 4 br label %for.cond.l21 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, ptr %30, align 1 - %134 = load i1, ptr %30, align 1 + %130 = load i32, ptr %i, align 4 + %131 = load i32, ptr %iterations, align 4 + %132 = icmp slt i32 %130, %131 + %133 = alloca i1, align 1 + store i1 %132, ptr %133, align 1 + %134 = load i1, ptr %133, align 1 br i1 %134, label %for.l21, label %for.end.l21 for.end.l21: ; preds = %for.cond.l21 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 adb4588b4..46a2853cd 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 @@ -18,25 +18,9 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %arraySize1 = alloca i16, align 2 - %array1 = alloca ptr, align 8 - %idx = alloca i32, align 4 - %item = alloca i32, align 4 - %arraySize2 = alloca i64, align 8 - %array2 = alloca ptr, align 8 - %idx2 = alloca i32, align 4 - %item3 = alloca ptr, align 8 - %arraySize3 = 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 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) + %arraySize1 = alloca i16, align 2 store i16 4, ptr %arraySize1, align 2 %1 = load i16, ptr %arraySize1, align 2 %2 = call ptr @llvm.stacksave() @@ -47,11 +31,14 @@ entry.l1: store i32 2, ptr %5, align 4 %6 = getelementptr inbounds i32, ptr %3, i32 2 store i32 3, ptr %6, align 4 + %array1 = alloca ptr, align 8 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 + %idx = alloca i32, align 4 store i32 0, ptr %idx, align 4 + %item = alloca i32, align 4 store i32 0, ptr %item, align 4 %9 = load ptr, ptr %array1, align 8 %10 = sext i16 %1 to i32 @@ -83,144 +70,153 @@ foreach.cond.l6: ; preds = %foreach.inc.l6 foreach.end.l6: ; preds = %foreach.cond.l6 %21 = call i32 (ptr, ...) @printf(ptr @2) + %arraySize2 = alloca i64, align 8 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 + %23 = alloca ptr, i64 %22, align 8 + %array2 = alloca ptr, align 8 + store ptr %23, ptr %array2, align 8 + %24 = load ptr, ptr %array2, align 8 + %25 = getelementptr inbounds ptr, ptr %24, i32 0 + store ptr @3, ptr %25, align 8 + %26 = load ptr, ptr %array2, align 8 + %27 = getelementptr inbounds ptr, ptr %26, i32 1 + store ptr @4, ptr %27, align 8 + %idx2 = alloca i32, align 4 store i32 0, ptr %idx2, align 4 + %item3 = alloca ptr, align 8 store ptr @5, ptr %item3, align 8 - %29 = load ptr, ptr %array2, align 8 - %30 = trunc i64 %22 to i32 - %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 + %28 = load ptr, ptr %array2, align 8 + %29 = trunc i64 %22 to i32 + %30 = load i32, ptr %idx2, align 4 + %31 = load ptr, ptr %array2, align 8 + %32 = getelementptr inbounds ptr, ptr %31, i32 %30 + %33 = load ptr, ptr %32, align 8 + store ptr %33, 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) + %34 = load ptr, ptr %item3, align 8 + %35 = call i32 (ptr, ...) @printf(ptr @6, ptr %34) 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 + %36 = getelementptr inbounds ptr, ptr %31, i32 %idx.inc5 + %37 = load ptr, ptr %36, align 8 + store ptr %37, 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.loop.l15, label %foreach.end.l15 + %38 = load i32, ptr %idx2, align 4 + %39 = icmp ult i32 %38, %29 + br i1 %39, label %foreach.loop.l15, label %foreach.end.l15 foreach.end.l15: ; preds = %foreach.cond.l15 - %41 = call i32 (ptr, ...) @printf(ptr @7) + %40 = call i32 (ptr, ...) @printf(ptr @7) + %arraySize3 = alloca i32, align 4 store i32 3, ptr %arraySize3, align 4 + %41 = load i32, 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, 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 + %44 = alloca i32, i32 %41, align 4 + %45 = getelementptr inbounds i32, ptr %44, i32 0 + store i32 1, ptr %45, align 4 + %46 = getelementptr inbounds i32, ptr %44, i32 1 + store i32 %42, ptr %46, align 4 + %47 = getelementptr inbounds i32, ptr %44, i32 2 + store i32 %43, ptr %47, align 4 + %array3 = alloca ptr, align 8 + store ptr %44, ptr %array3, align 8 + %idx6 = alloca i32, align 4 store i32 0, ptr %idx6, align 4 + %item7 = alloca i32, align 4 store i32 0, ptr %item7, align 4 + %48 = load ptr, ptr %array3, align 8 + %49 = load i32, ptr %idx6, 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 + %51 = getelementptr inbounds i32, ptr %50, i32 %49 + %52 = load i32, ptr %51, align 4 + store i32 %52, 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) + %53 = load i32, ptr %item7, align 4 + %54 = call i32 (ptr, ...) @printf(ptr @8, i32 %53) 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 + %55 = getelementptr inbounds i32, ptr %50, i32 %idx.inc9 + %56 = load i32, ptr %55, align 4 + store i32 %56, 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.loop.l22, label %foreach.end.l22 + %57 = load i32, ptr %idx6, align 4 + %58 = icmp ult i32 %57, %41 + br i1 %58, label %foreach.loop.l22, label %foreach.end.l22 foreach.end.l22: ; preds = %foreach.cond.l22 - %61 = call i32 (ptr, ...) @printf(ptr @9) + %59 = call i32 (ptr, ...) @printf(ptr @9) + %arraySize4 = alloca i32, align 4 store i32 3, ptr %arraySize4, align 4 + %60 = load i32, ptr %arraySize4, align 4 + %61 = alloca i32, i32 %60, align 4 + %array4 = alloca ptr, align 8 + store ptr %61, ptr %array4, align 8 %62 = load i32, ptr %arraySize4, align 4 - %63 = call ptr @llvm.stacksave() - %64 = alloca i32, i32 %62, align 4 - 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, 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 + %63 = load i32, ptr %arraySize4, align 4 + %64 = alloca i32, i32 %60, align 4 + %65 = getelementptr inbounds i32, ptr %64, i32 0 + store i32 1, ptr %65, align 4 + %66 = getelementptr inbounds i32, ptr %64, i32 1 + store i32 %62, ptr %66, align 4 + %67 = getelementptr inbounds i32, ptr %64, i32 2 + store i32 %63, ptr %67, align 4 + %array410 = alloca ptr, align 8 + store ptr %64, ptr %array410, align 8 + %68 = load ptr, ptr %array410, align 8 + store ptr %68, ptr %array4, align 8 + %idx11 = alloca i32, align 4 store i32 0, ptr %idx11, align 4 + %item12 = alloca i32, 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 + %69 = load ptr, ptr %array4, align 8 + %70 = load i32, ptr %idx11, align 4 + %71 = load ptr, ptr %array4, align 8 + %72 = getelementptr inbounds i32, ptr %71, i32 %70 + %73 = load i32, ptr %72, align 4 + store i32 %73, 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) + %74 = load i32, ptr %item12, align 4 + %75 = call i32 (ptr, ...) @printf(ptr @10, i32 %74) 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 + %76 = getelementptr inbounds i32, ptr %71, i32 %idx.inc14 + %77 = load i32, ptr %76, align 4 + store i32 %77, 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.loop.l30, label %foreach.end.l30 + %78 = load i32, ptr %idx11, align 4 + %79 = icmp ult i32 %78, %60 + br i1 %79, label %foreach.loop.l30, label %foreach.end.l30 foreach.end.l30: ; preds = %foreach.cond.l30 - call void @llvm.stackrestore(ptr %67) - %84 = load i32, ptr %result, align 4 - ret i32 %84 + call void @llvm.stackrestore(ptr %2) + %80 = load i32, ptr %result, align 4 + ret i32 %80 } declare i32 @printf(ptr, ...) 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 a0be65a82..ad6edaa1c 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 @@ -8,78 +8,74 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %a = alloca [10 x [10 x i32]], align 4 - %i = alloca i32, align 4 - %j = alloca i32, align 4 - %0 = alloca i32, align 4 - %1 = alloca i32, align 4 - %2 = alloca i1, align 1 - %3 = alloca i32, align 4 - %4 = alloca i1, align 1 store i32 0, ptr %result, align 4 + %a = alloca [10 x [10 x i32]], align 4 store [10 x [10 x i32]] zeroinitializer, ptr %a, align 4 + %i = alloca i32, align 4 store i32 0, ptr %i, align 4 br label %for.cond.l3 for.l3: ; preds = %for.cond.l3 + %j = alloca i32, align 4 store i32 0, ptr %j, align 4 br label %for.cond.l4 for.l4: ; preds = %for.cond.l4 + %0 = load i32, ptr %i, align 4 + %1 = load i32, ptr %j, align 4 + %2 = mul i32 %0, %1 + %3 = alloca i32, align 4 + store i32 %2, ptr %3, align 4 + %4 = load i32, ptr %3, align 4 %5 = load i32, ptr %i, align 4 - %6 = load i32, ptr %j, align 4 - %7 = mul i32 %5, %6 - 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 + %6 = getelementptr inbounds [10 x [10 x i32]], ptr %a, i32 0, i32 %5 + %7 = load i32, ptr %j, align 4 + %8 = getelementptr inbounds [10 x i32], ptr %6, i32 0, i32 %7 + store i32 %4, ptr %8, align 4 br label %for.inc.l4 for.inc.l4: ; preds = %for.l4 - %15 = load i32, ptr %j, align 4 - %16 = add i32 %15, 1 - store i32 %16, ptr %j, align 4 - store i32 %15, ptr %1, align 4 + %9 = load i32, ptr %j, align 4 + %10 = add i32 %9, 1 + store i32 %10, ptr %j, align 4 + %11 = alloca i32, align 4 + store i32 %9, ptr %11, align 4 br label %for.cond.l4 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, ptr %2, align 1 - %19 = load i1, ptr %2, align 1 - br i1 %19, label %for.l4, label %for.end.l4 + %12 = load i32, ptr %j, align 4 + %13 = icmp slt i32 %12, 10 + %14 = alloca i1, align 1 + store i1 %13, ptr %14, align 1 + %15 = load i1, ptr %14, align 1 + br i1 %15, label %for.l4, label %for.end.l4 for.end.l4: ; preds = %for.cond.l4 br label %for.inc.l3 for.inc.l3: ; preds = %for.end.l4 - %20 = load i32, ptr %i, align 4 - %21 = add i32 %20, 1 - store i32 %21, ptr %i, align 4 - store i32 %20, ptr %3, align 4 + %16 = load i32, ptr %i, align 4 + %17 = add i32 %16, 1 + store i32 %17, ptr %i, align 4 + %18 = alloca i32, align 4 + store i32 %16, ptr %18, align 4 br label %for.cond.l3 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, ptr %4, align 1 - %24 = load i1, ptr %4, align 1 - br i1 %24, label %for.l3, label %for.end.l3 + %19 = load i32, ptr %i, align 4 + %20 = icmp slt i32 %19, 10 + %21 = alloca i1, align 1 + store i1 %20, ptr %21, align 1 + %22 = load i1, ptr %21, align 1 + br i1 %22, label %for.l3, label %for.end.l3 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 + %23 = getelementptr inbounds [10 x [10 x i32]], ptr %a, i32 0, i32 1 + %24 = getelementptr inbounds [10 x i32], ptr %23, i32 0, i32 3 + %25 = load i32, ptr %24, align 4 + %26 = call i32 (ptr, ...) @printf(ptr @0, i32 %25) + %27 = load i32, ptr %result, align 4 + ret i32 %27 } 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 d8d6cb480..7746beaae 100644 --- a/test/test-files/generator/arrays/success-arrays/ir-code.ll +++ b/test/test-files/generator/arrays/success-arrays/ir-code.ll @@ -8,38 +8,34 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %value0 = alloca i32, align 4 - %intArray = alloca [5 x i32], align 4 store i32 0, ptr %result, align 4 + %value0 = alloca i32, 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 + %1 = alloca [5 x i32], align 4 + %2 = getelementptr inbounds [5 x i32], ptr %1, i32 0, i32 0 + store i32 %0, ptr %2, align 4 + %3 = getelementptr inbounds [5 x i32], ptr %1, i32 0, i32 1 + store i32 7, ptr %3, align 4 + %4 = getelementptr inbounds [5 x i32], ptr %1, i32 0, i32 2 + store i32 4, ptr %4, align 4 + %5 = getelementptr inbounds [5 x i32], ptr %1, i32 0, i32 3 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 + %6 = getelementptr inbounds [5 x i32], ptr %1, i32 0, i32 4 + store i32 0, ptr %6, align 4 + %7 = getelementptr inbounds [5 x i32], ptr %1, i32 0, i32 2 %8 = load i32, ptr %7, align 4 %9 = mul i32 %8, 11 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 + %10 = getelementptr inbounds [5 x i32], ptr %1, i32 0, i32 0 + store i32 3, ptr %10, align 4 + %11 = getelementptr inbounds [5 x i32], ptr %1, i32 0, i32 0 + %12 = load i32, ptr %11, align 4 + %13 = getelementptr inbounds [5 x i32], ptr %1, i32 0, i32 2 %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 + %15 = call i32 (ptr, ...) @printf(ptr @0, i32 %12, i32 %14) + %16 = load i32, ptr %result, align 4 + ret i32 %16 } 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 c2038dac1..92a5de973 100644 --- a/test/test-files/generator/arrays/success-arrays2/ir-code.ll +++ b/test/test-files/generator/arrays/success-arrays2/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" -@intArray = constant [10 x i32] [i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128, i32 256, i32 512] +@intArray = global [10 x i32] [i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128, i32 256, i32 512] @0 = private unnamed_addr constant [17 x i8] c"intArray[3]: %d\0A\00", align 1 @1 = private unnamed_addr constant [17 x i8] c"intArray[7]: %d\0A\00", align 1 @2 = private unnamed_addr constant [17 x i8] c"intArray[9]: %d\0A\00", align 1 @@ -11,23 +11,15 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %intArray = alloca [10 x i32], 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 + %0 = load i32, ptr getelementptr inbounds ([10 x i32], ptr @intArray, i32 0, i32 3), align 4 + %1 = call i32 (ptr, ...) @printf(ptr @0, i32 %0) + %2 = load i32, ptr getelementptr inbounds ([10 x i32], ptr @intArray, i32 0, i32 7), align 4 + %3 = call i32 (ptr, ...) @printf(ptr @1, i32 %2) + %4 = load i32, ptr getelementptr inbounds ([10 x i32], ptr @intArray, i32 0, i32 9), align 4 + %5 = call i32 (ptr, ...) @printf(ptr @2, i32 %4) + %6 = load i32, ptr %result, align 4 + ret i32 %6 } 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 86bd444d5..f1fccfbf1 100644 --- a/test/test-files/generator/arrays/success-arrays3/ir-code.ll +++ b/test/test-files/generator/arrays/success-arrays3/ir-code.ll @@ -3,25 +3,22 @@ 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" -@intArray = constant [2 x i32] [i32 1, i32 2] +@intArray = global [2 x i32] [i32 1, i32 2] @0 = private unnamed_addr constant [17 x i8] c"intArray[1]: %d\0A\00", align 1 define i32 @main() { entry.l1: %result = alloca i32, align 4 - %intArray = alloca [2 x i32], align 4 - %intArray1 = alloca [2 x i32], align 4 store i32 0, ptr %result, align 4 + %intArray = alloca [2 x i32], 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 + %0 = load [2 x i32], ptr @intArray, 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 + %1 = getelementptr inbounds [2 x i32], ptr %intArray, i32 0, i32 1 + %2 = load i32, ptr %1, align 4 + %3 = call i32 (ptr, ...) @printf(ptr @0, i32 %2) + %4 = load i32, ptr %result, align 4 + ret i32 %4 } 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 c8e4c4813..be323176b 100644 --- a/test/test-files/generator/arrays/success-arrays4/ir-code.ll +++ b/test/test-files/generator/arrays/success-arrays4/ir-code.ll @@ -7,23 +7,21 @@ 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 ptr] [ptr @0, ptr @1, ptr @2, ptr @3, ptr @3] +@welcomeMessage = global [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.l1: %result = alloca i32, align 4 - %welcomeMessage = alloca [5 x ptr], align 8 - %i = alloca i32, align 4 - %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 + %i = alloca i32, align 4 store i32 0, ptr %i, align 4 + %word = alloca ptr, align 8 store ptr @4, ptr %word, align 8 - %0 = load [5 x ptr], ptr %welcomeMessage, 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 + %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 @@ -38,7 +36,7 @@ foreach.inc.l3: ; preds = %foreach.loop.l3 %idx = load i32, ptr %i, align 4 %idx.inc = add i32 %idx, 1 store i32 %idx.inc, ptr %i, align 4 - %7 = getelementptr inbounds [5 x ptr], ptr %welcomeMessage, i32 0, i32 %idx.inc + %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 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 0c20e2763..83ef8ae6d 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 @@ -9,8 +9,8 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %test = alloca ptr, align 8 store i32 0, ptr %result, align 4 + %test = alloca ptr, align 8 store ptr @0, ptr %test, align 8 %0 = load ptr, ptr %test, align 8 %1 = getelementptr inbounds i8, ptr %0, i32 2 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 92ec3734d..c8ae14855 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 @@ -9,8 +9,8 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %0 = alloca i1, align 1 store i32 0, ptr %result, align 4 + %0 = alloca i1, align 1 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 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 ac7580275..3c05ccfe9 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 @@ -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" -@testIntArray = local_unnamed_addr constant [7 x i32] [i32 1, i32 2, i32 3, i32 4, i32 0, i32 0, i32 0] +@testIntArray = local_unnamed_addr global [7 x i32] [i32 1, i32 2, i32 3, i32 4, i32 0, i32 0, i32 0] @0 = private unnamed_addr constant [18 x i8] c"Array length: %d\0A\00", align 1 ; Function Attrs: 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 1b58e9dea..f9a8a0267 100644 --- a/test/test-files/generator/builtins/success-len/ir-code.ll +++ b/test/test-files/generator/builtins/success-len/ir-code.ll @@ -3,19 +3,17 @@ 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" -@testIntArray = constant [7 x i32] [i32 1, i32 2, i32 3, i32 4, i32 0, i32 0, i32 0] +@testIntArray = global [7 x i32] [i32 1, i32 2, i32 3, i32 4, i32 0, i32 0, i32 0] @0 = private unnamed_addr constant [18 x i8] c"Array length: %d\0A\00", align 1 define i32 @main() { entry.l1: %result = alloca i32, align 4 - %testIntArray = alloca [7 x i32], align 4 - %0 = alloca i32, 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 + %0 = load [7 x i32], ptr @testIntArray, align 4 + %1 = alloca i32, align 4 + store i32 7, ptr %1, align 4 + %2 = load i32, ptr %1, align 4 %3 = call i32 (ptr, ...) @printf(ptr @0, i32 %2) %4 = load i32, ptr %result, align 4 ret i32 %4 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 c3f28a6cd..c2517e67d 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 @@ -12,7 +12,7 @@ target triple = "x86_64-w64-windows-gnu" @6 = private unnamed_addr constant [20 x i8] c"Size of string: %d\0A\00", align 1 @7 = private unnamed_addr constant [18 x i8] c"Size of bool: %d\0A\00", align 1 @8 = private unnamed_addr constant [19 x i8] c"Size of int[]: %d\0A\00", align 1 -@anonymous.0 = local_unnamed_addr constant [7 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7] +@anonymous.0 = local_unnamed_addr global [7 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7] @9 = private unnamed_addr constant [18 x i8] c"Size of int*: %d\0A\00", align 1 @10 = private unnamed_addr constant [29 x i8] c"Size of struct instance: %d\0A\00", align 1 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 36d25b3e3..9814973d2 100644 --- a/test/test-files/generator/builtins/success-sizeof/ir-code.ll +++ b/test/test-files/generator/builtins/success-sizeof/ir-code.ll @@ -13,81 +13,79 @@ target triple = "x86_64-w64-windows-gnu" @7 = private unnamed_addr constant [13 x i8] c"Hello Spice!\00", align 1 @8 = private unnamed_addr constant [18 x i8] c"Size of bool: %d\0A\00", align 1 @9 = private unnamed_addr constant [19 x i8] c"Size of int[]: %d\0A\00", align 1 -@anonymous.0 = constant [7 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7] +@anonymous.0 = global [7 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7] @10 = private unnamed_addr constant [18 x i8] c"Size of int*: %d\0A\00", align 1 @11 = private unnamed_addr constant [29 x i8] c"Size of struct instance: %d\0A\00", align 1 define i32 @main() { entry.l7: %result = alloca i32, align 4 + store i32 0, ptr %result, align 4 %0 = alloca double, align 8 - %1 = alloca double, align 8 - %2 = alloca i32, align 4 - %3 = alloca i32, align 4 - %4 = alloca i32, align 4 + store double 0x40335992641B328B, ptr %0, align 8 + %1 = load double, ptr %0, align 8 + %2 = fmul double %1, -1.000000e+00 + %3 = alloca double, align 8 + store double %2, ptr %3, align 8 + %4 = load double, ptr %3, align 8 %5 = alloca i32, align 4 - %6 = alloca i8, align 1 - %7 = alloca i32, align 4 - %8 = alloca i8, align 1 - %9 = alloca i32, align 4 - %10 = alloca i32, align 4 + store i32 64, ptr %5, align 4 + %6 = load i32, ptr %5, align 4 + %7 = call i32 (ptr, ...) @printf(ptr @0, i32 %6) + %8 = alloca i32, align 4 + store i32 32, ptr %8, align 4 + %9 = load i32, ptr %8, align 4 + %10 = call i32 (ptr, ...) @printf(ptr @1, i32 %9) %11 = alloca i32, align 4 - %12 = alloca [7 x i32], align 4 - %13 = alloca i32, align 4 + store i32 16, ptr %11, align 4 + %12 = load i32, ptr %11, align 4 + %13 = call i32 (ptr, ...) @printf(ptr @2, i32 %12) + %14 = alloca i32, align 4 + store i32 64, ptr %14, align 4 + %15 = load i32, ptr %14, align 4 + %16 = call i32 (ptr, ...) @printf(ptr @3, i32 %15) + %17 = alloca i8, align 1 + store i8 13, ptr %17, align 1 + %18 = load i8, ptr %17, align 1 + %19 = alloca i32, align 4 + store i32 8, ptr %19, align 4 + %20 = load i32, ptr %19, align 4 + %21 = call i32 (ptr, ...) @printf(ptr @4, i32 %20) + %22 = alloca i8, align 1 + store i8 65, ptr %22, align 1 + %23 = load i8, ptr %22, align 1 + %24 = alloca i32, align 4 + store i32 8, ptr %24, align 4 + %25 = load i32, ptr %24, align 4 + %26 = call i32 (ptr, ...) @printf(ptr @5, i32 %25) + %27 = alloca i32, align 4 + store i32 64, ptr %27, align 4 + %28 = load i32, ptr %27, align 4 + %29 = call i32 (ptr, ...) @printf(ptr @6, i32 %28) + %30 = alloca i32, align 4 + store i32 1, ptr %30, align 4 + %31 = load i32, ptr %30, align 4 + %32 = call i32 (ptr, ...) @printf(ptr @8, i32 %31) + %33 = load [7 x i32], ptr @anonymous.0, align 4 + %34 = alloca i32, align 4 + store i32 224, ptr %34, align 4 + %35 = load i32, ptr %34, align 4 + %36 = call i32 (ptr, ...) @printf(ptr @9, i32 %35) %intVariable = alloca i32, align 4 - %14 = alloca ptr, align 8 - %15 = alloca i32, align 4 - %16 = alloca i32, align 4 - 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, 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 + %37 = alloca ptr, align 8 + store ptr %intVariable, ptr %37, align 8 + %38 = load ptr, ptr %37, align 8 + %39 = alloca i32, align 4 + store i32 64, ptr %39, align 4 + %40 = load i32, ptr %39, align 4 + %41 = call i32 (ptr, ...) @printf(ptr @10, i32 %40) + %42 = alloca i32, align 4 + store i32 128, ptr %42, align 4 + %43 = load i32, ptr %42, align 4 + %44 = call i32 (ptr, ...) @printf(ptr @11, i32 %43) + %45 = load i32, ptr %result, align 4 + ret i32 %45 } 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 46e79b2b8..457d1c0e7 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 @@ -10,22 +10,22 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main(i32 %0, ptr %1) { entry.l1: %argc = alloca i32, align 4 - %argv = alloca ptr, align 8 - %result = alloca i32, align 4 - %2 = alloca i1, align 1 store i32 %0, ptr %argc, align 4 + %argv = alloca ptr, align 8 store ptr %1, ptr %argv, align 8 + %result = alloca i32, align 4 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, ptr %2, align 1 - %11 = load i1, ptr %2, align 1 + %2 = load i32, ptr %argc, align 4 + %3 = call i32 (ptr, ...) @printf(ptr @0, i32 %2) + %4 = load ptr, ptr %argv, align 8 + %5 = getelementptr inbounds ptr, ptr %4, i32 0 + %6 = load ptr, ptr %5, align 8 + %7 = call i32 (ptr, ...) @printf(ptr @1, ptr %6) + %8 = load i32, ptr %argc, align 4 + %9 = icmp sgt i32 %8, 1 + %10 = alloca i1, align 1 + store i1 %9, ptr %10, align 1 + %11 = load i1, ptr %10, align 1 br i1 %11, label %if.then.l4, label %if.end.l4 if.then.l4: ; preds = %entry.l1 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 46a815666..dcb48e19f 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 @@ -19,22 +19,22 @@ declare void @free(ptr) define i32 @main() { entry.l7: %result = alloca i32, align 4 - %0 = alloca ptr, align 8 - %1 = alloca i32, align 4 - %2 = alloca ptr, align 8 - %3 = alloca i32, 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 + %0 = call i32 (ptr, ...) @printf(ptr @0) + %1 = alloca ptr, align 8 + store ptr @1, ptr %1, align 8 + %2 = load ptr, ptr %1, align 8 + %3 = load i32, ptr @MODE_ALL_RWX, align 4 + %4 = call i32 @mkdir(ptr %2, i32 %3) + %5 = alloca i32, align 4 + store i32 %4, ptr %5, align 4 + %6 = call i32 (ptr, ...) @printf(ptr @2) + %7 = alloca ptr, align 8 + store ptr @3, ptr %7, align 8 + %8 = load ptr, ptr %7, align 8 + %9 = call i32 @rmdir(ptr %8) + %10 = alloca i32, align 4 + store i32 %9, ptr %10, align 4 %11 = call i32 (ptr, ...) @printf(ptr @4) %12 = load i32, ptr %result, align 4 ret i32 %12 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 0aaf5be96..97b3eb920 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 @@ -13,17 +13,17 @@ entry.l1: br label %for.l2 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 + %counter.06 = phi i32 [ 0, %entry.l1 ], [ %2, %for.l2 ] + %0 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 %counter.06) + %1 = icmp ugt i32 %counter.06, 9000 + %2 = add nuw nsw i32 %counter.06, 2 br i1 %1, label %for.l5, label %for.l2 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 + %storemerge5 = phi i32 [ %5, %for.l5 ], [ 100, %for.l2 ] + %3 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i32 %storemerge5) + %4 = icmp eq i32 %storemerge5, 11 + %5 = add nsw i32 %storemerge5, -1 br i1 %4, label %for.end.l2, label %for.l5 for.end.l2: ; preds = %for.l5 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 e0a812a19..373f4c94a 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 @@ -10,37 +10,35 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %counter = alloca i32, align 4 - %0 = alloca i1, align 1 - %subCounter = alloca i32, align 4 - %1 = alloca i1, align 1 - %2 = alloca i1, align 1 - %3 = alloca i1, align 1 store i32 0, ptr %result, align 4 + %counter = alloca i32, align 4 store i32 0, ptr %counter, align 4 br label %for.cond.l2 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, ptr %0, align 1 - %8 = load i1, ptr %0, align 1 - br i1 %8, label %if.then.l4, label %if.end.l4 + %0 = load i32, ptr %counter, align 4 + %1 = call i32 (ptr, ...) @printf(ptr @0, i32 %0) + %2 = load i32, ptr %counter, align 4 + %3 = icmp sge i32 %2, 9001 + %4 = alloca i1, align 1 + store i1 %3, ptr %4, align 1 + %5 = load i1, ptr %4, align 1 + br i1 %5, label %if.then.l4, label %if.end.l4 if.then.l4: ; preds = %for.l2 + %subCounter = alloca i32, align 4 store i32 100, ptr %subCounter, align 4 br label %for.cond.l5 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, ptr %1, align 1 - %13 = load i1, ptr %1, align 1 - br i1 %13, label %if.then.l7, label %if.end.l7 + %6 = load i32, ptr %subCounter, align 4 + %7 = call i32 (ptr, ...) @printf(ptr @1, i32 %6) + %8 = load i32, ptr %subCounter, align 4 + %9 = icmp eq i32 %8, 11 + %10 = alloca i1, align 1 + store i1 %9, ptr %10, align 1 + %11 = load i1, ptr %10, align 1 + br i1 %11, label %if.then.l7, label %if.end.l7 if.then.l7: ; preds = %for.l5 br label %for.end.l2 @@ -49,17 +47,18 @@ if.end.l7: ; preds = %for.l5 br label %for.inc.l5 for.inc.l5: ; preds = %if.end.l7 - %14 = load i32, ptr %subCounter, align 4 - %15 = sub i32 %14, 1 - store i32 %15, ptr %subCounter, align 4 + %12 = load i32, ptr %subCounter, align 4 + %13 = sub i32 %12, 1 + store i32 %13, ptr %subCounter, align 4 br label %for.cond.l5 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, ptr %2, align 1 - %18 = load i1, ptr %2, align 1 - br i1 %18, label %for.l5, label %for.end.l5 + %14 = load i32, ptr %subCounter, align 4 + %15 = icmp sge i32 %14, 10 + %16 = alloca i1, align 1 + store i1 %15, ptr %16, align 1 + %17 = load i1, ptr %16, align 1 + br i1 %17, label %for.l5, label %for.end.l5 for.end.l5: ; preds = %for.cond.l5 br label %if.end.l4 @@ -68,16 +67,17 @@ if.end.l4: ; preds = %for.end.l5, %for.l2 br label %for.inc.l2 for.inc.l2: ; preds = %if.end.l4 - %19 = load i32, ptr %counter, align 4 - %20 = add i32 %19, 2 - store i32 %20, ptr %counter, align 4 + %18 = load i32, ptr %counter, align 4 + %19 = add i32 %18, 2 + store i32 %19, ptr %counter, align 4 br label %for.cond.l2 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, ptr %3, align 1 - %23 = load i1, ptr %3, align 1 + %20 = load i32, ptr %counter, align 4 + %21 = icmp slt i32 %20, 10000 + %22 = alloca i1, align 1 + store i1 %21, ptr %22, align 1 + %23 = load i1, ptr %22, align 1 br i1 %23, label %for.l2, label %for.end.l2 for.end.l2: ; preds = %for.cond.l2, %if.then.l7 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 e5851a2b3..c8c3f979a 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 @@ -17,10 +17,10 @@ for.l5.preheader.3: 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 + %storemerge4.3 = phi i32 [ %5, %for.l5.3 ], [ 100, %for.l5.preheader.3 ] + %4 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i32 %storemerge4.3) + %5 = add nsw i32 %storemerge4.3, -1 + %6 = add nsw i32 %storemerge4.3, -12 %7 = icmp ult i32 %6, -11 br i1 %7, label %for.l5.3, label %for.l5.preheader.4 @@ -29,10 +29,10 @@ for.l5.preheader.4: ; preds = %for.l5.3 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 + %storemerge4.4 = phi i32 [ %10, %for.l5.4 ], [ 100, %for.l5.preheader.4 ] + %9 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i32 %storemerge4.4) + %10 = add nsw i32 %storemerge4.4, -1 + %11 = add nsw i32 %storemerge4.4, -12 %12 = icmp ult i32 %11, -11 br i1 %12, label %for.l5.4, label %for.inc.l2.4 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 d4820f8f9..313d8b952 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 @@ -10,37 +10,35 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %counter = alloca i32, align 4 - %0 = alloca i1, align 1 - %subCounter = alloca i32, align 4 - %1 = alloca i1, align 1 - %2 = alloca i1, align 1 - %3 = alloca i1, align 1 store i32 0, ptr %result, align 4 + %counter = alloca i32, align 4 store i32 0, ptr %counter, align 4 br label %for.cond.l2 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, ptr %0, align 1 - %8 = load i1, ptr %0, align 1 - br i1 %8, label %if.then.l4, label %if.end.l4 + %0 = load i32, ptr %counter, align 4 + %1 = call i32 (ptr, ...) @printf(ptr @0, i32 %0) + %2 = load i32, ptr %counter, align 4 + %3 = icmp sge i32 %2, 5 + %4 = alloca i1, align 1 + store i1 %3, ptr %4, align 1 + %5 = load i1, ptr %4, align 1 + br i1 %5, label %if.then.l4, label %if.end.l4 if.then.l4: ; preds = %for.l2 + %subCounter = alloca i32, align 4 store i32 100, ptr %subCounter, align 4 br label %for.cond.l5 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, ptr %1, align 1 - %13 = load i1, ptr %1, align 1 - br i1 %13, label %if.then.l7, label %if.end.l7 + %6 = load i32, ptr %subCounter, align 4 + %7 = call i32 (ptr, ...) @printf(ptr @1, i32 %6) + %8 = load i32, ptr %subCounter, align 4 + %9 = icmp eq i32 %8, 11 + %10 = alloca i1, align 1 + store i1 %9, ptr %10, align 1 + %11 = load i1, ptr %10, align 1 + br i1 %11, label %if.then.l7, label %if.end.l7 if.then.l7: ; preds = %for.l5 br label %for.inc.l2 @@ -49,17 +47,18 @@ if.end.l7: ; preds = %for.l5 br label %for.inc.l5 for.inc.l5: ; preds = %if.end.l7 - %14 = load i32, ptr %subCounter, align 4 - %15 = sub i32 %14, 1 - store i32 %15, ptr %subCounter, align 4 + %12 = load i32, ptr %subCounter, align 4 + %13 = sub i32 %12, 1 + store i32 %13, ptr %subCounter, align 4 br label %for.cond.l5 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, ptr %2, align 1 - %18 = load i1, ptr %2, align 1 - br i1 %18, label %for.l5, label %for.end.l5 + %14 = load i32, ptr %subCounter, align 4 + %15 = icmp sge i32 %14, 10 + %16 = alloca i1, align 1 + store i1 %15, ptr %16, align 1 + %17 = load i1, ptr %16, align 1 + br i1 %17, label %for.l5, label %for.end.l5 for.end.l5: ; preds = %for.cond.l5 br label %if.end.l4 @@ -68,16 +67,17 @@ if.end.l4: ; preds = %for.end.l5, %for.l2 br label %for.inc.l2 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, ptr %counter, align 4 + %18 = load i32, ptr %counter, align 4 + %19 = add i32 %18, 2 + store i32 %19, ptr %counter, align 4 br label %for.cond.l2 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, ptr %3, align 1 - %23 = load i1, ptr %3, align 1 + %20 = load i32, ptr %counter, align 4 + %21 = icmp slt i32 %20, 10 + %22 = alloca i1, align 1 + store i1 %21, ptr %22, align 1 + %23 = load i1, ptr %22, align 1 br i1 %23, label %for.l2, label %for.end.l2 for.end.l2: ; preds = %for.cond.l2 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 75c578b9c..caaa4f9e5 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 @@ -8,28 +8,28 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %i = alloca i32, align 4 - %0 = alloca i1, align 1 store i32 0, ptr %result, align 4 + %i = alloca i32, align 4 store i32 0, ptr %i, align 4 br label %for.cond.l2 for.l2: ; preds = %for.cond.l2 - %1 = load i32, ptr %i, align 4 - %2 = call i32 (ptr, ...) @printf(ptr @0, i32 %1) + %0 = load i32, ptr %i, align 4 + %1 = call i32 (ptr, ...) @printf(ptr @0, i32 %0) br label %for.inc.l2 for.inc.l2: ; preds = %for.l2 - %3 = load i32, ptr %i, align 4 - %4 = add i32 %3, 2 - store i32 %4, ptr %i, align 4 + %2 = load i32, ptr %i, align 4 + %3 = add i32 %2, 2 + store i32 %3, ptr %i, align 4 br label %for.cond.l2 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, ptr %0, align 1 - %7 = load i1, ptr %0, align 1 + %4 = load i32, ptr %i, align 4 + %5 = icmp slt i32 %4, 10 + %6 = alloca i1, align 1 + store i1 %5, ptr %6, align 1 + %7 = load i1, ptr %6, align 1 br i1 %7, label %for.l2, label %for.end.l2 for.end.l2: ; preds = %for.cond.l2 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 c38230d90..9b03353be 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 @@ -3,52 +3,47 @@ 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" -@anonymous.0 = constant [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5] -@item = constant [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5] +@anonymous.0 = global [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5] @0 = private unnamed_addr constant [13 x i8] c"Item %d: %d\0A\00", align 1 define i32 @main() { 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, ptr %result, align 4 - store [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5], ptr %0, align 4 + %idx = alloca i32, align 4 store i32 0, ptr %idx, align 4 + %item = alloca i32, 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 + %0 = load [5 x i32], ptr @anonymous.0, align 4 + %1 = load i32, ptr %idx, align 4 + %2 = getelementptr inbounds [5 x i32], ptr @anonymous.0, i32 0, i32 %1 + %3 = load i32, ptr %2, align 4 + store i32 %3, ptr %item, align 4 br label %foreach.loop.l2 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) + %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.l2 foreach.inc.l2: ; preds = %foreach.loop.l2 - %idx2 = load i32, ptr %idx, align 4 - %idx.inc = add i32 %idx2, 1 + %idx1 = load i32, ptr %idx, align 4 + %idx.inc = add i32 %idx1, 1 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 + %7 = getelementptr inbounds [5 x i32], ptr @anonymous.0, i32 0, i32 %idx.inc + %8 = load i32, ptr %7, align 4 + store i32 %8, ptr %item, align 4 br label %foreach.cond.l2 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.l2, label %foreach.end.l2 + %9 = load i32, ptr %idx, align 4 + %10 = icmp ult i32 %9, 5 + br i1 %10, label %foreach.loop.l2, label %foreach.end.l2 foreach.end.l2: ; preds = %foreach.cond.l2 - %12 = load i32, ptr %result, align 4 - ret i32 %12 + %11 = load i32, ptr %result, align 4 + ret i32 %11 } 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 9926de12a..60b18f717 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 @@ -4,8 +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" @0 = private unnamed_addr constant [10 x i8] c"Short %d\0A\00", align 1 -@anonymous.0 = local_unnamed_addr constant [2 x i64] [i64 1, i64 2] -@l = local_unnamed_addr constant [2 x i64] [i64 1, i64 2] +@anonymous.0 = local_unnamed_addr global [2 x i64] [i64 1, i64 2] @1 = private unnamed_addr constant [9 x i8] c"Long %d\0A\00", align 1 @2 = private unnamed_addr constant [5 x i8] c"End.\00", align 1 @@ -13,7 +12,8 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() local_unnamed_addr #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) + %.pre = load i64, ptr @anonymous.0, align 8 + %1 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i64 %.pre) %2 = tail call i32 (ptr, ...) @printf(ptr nonnull @2) ret i32 0 } 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 c0503a815..5d9282f50 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 @@ -4,78 +4,73 @@ 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 [10 x i8] c"Short %d\0A\00", align 1 -@anonymous.0 = constant [2 x i64] [i64 1, i64 2] -@l = constant [2 x i64] [i64 1, i64 2] +@anonymous.0 = global [2 x i64] [i64 1, i64 2] @1 = private unnamed_addr constant [9 x i8] c"Long %d\0A\00", align 1 @2 = private unnamed_addr constant [5 x i8] c"End.\00", align 1 define i32 @main() { entry.l1: %result = alloca i32, align 4 + store i32 0, ptr %result, align 4 %s1 = alloca i16, align 2 - %0 = alloca i16, align 2 - %shortArray = alloca i16, align 2 + store i16 5, ptr %s1, align 2 + %0 = load i16, ptr %s1, align 2 %1 = alloca i16, align 2 - %shortArray1 = alloca [5 x i16], align 2 + store i16 -2, ptr %1, align 2 + %2 = load i16, ptr %1, align 2 + %shortArray.3 = alloca i16, align 2 + store i16 63, ptr %shortArray.3, align 2 + %3 = load i16, ptr %shortArray.3, align 2 + %4 = sub i16 0, %3 + %5 = alloca i16, align 2 + store i16 %4, ptr %5, align 2 + %6 = load i16, ptr %5, align 2 + %7 = alloca [5 x i16], align 2 + %8 = getelementptr inbounds [5 x i16], ptr %7, i32 0, i32 0 + store i16 1, ptr %8, align 2 + %9 = getelementptr inbounds [5 x i16], ptr %7, i32 0, i32 1 + store i16 %0, ptr %9, align 2 + %10 = getelementptr inbounds [5 x i16], ptr %7, i32 0, i32 2 + store i16 %2, ptr %10, align 2 + %11 = getelementptr inbounds [5 x i16], ptr %7, i32 0, i32 3 + store i16 %6, ptr %11, align 2 + %12 = getelementptr inbounds [5 x i16], ptr %7, i32 0, i32 4 + store i16 0, ptr %12, align 2 %idx = alloca i32, align 4 - %s = alloca i16, align 2 - %2 = alloca i16, align 2 - %3 = alloca i1, align 1 - %4 = alloca [2 x i64], align 8 - %idx2 = alloca i32, align 4 - %l = alloca i64, align 8 - %l3 = alloca [2 x i64], align 8 - 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, 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 + %s = alloca i16, align 2 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 + %13 = load [5 x i16], ptr %7, align 2 + %14 = load i32, ptr %idx, align 4 + %15 = getelementptr inbounds [5 x i16], ptr %7, i32 0, i32 %14 + %16 = load i16, ptr %15, align 2 + store i16 %16, ptr %s, align 2 br label %foreach.loop.l4 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 (ptr, ...) @printf(ptr @0, i32 %20) - %22 = load i16, ptr %s, align 2 - %23 = and i16 %22, 1 - 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, ptr %3, align 1 - %27 = load i1, ptr %3, align 1 + %17 = load i16, ptr %s, align 2 + %18 = sext i16 %17 to i32 + %19 = call i32 (ptr, ...) @printf(ptr @0, i32 %18) + %20 = load i16, ptr %s, align 2 + %21 = and i16 %20, 1 + %22 = alloca i16, align 2 + store i16 %21, ptr %22, align 2 + %23 = load i16, ptr %22, align 2 + %24 = sext i16 %23 to i32 + %25 = icmp eq i32 %24, 1 + %26 = alloca i1, align 1 + store i1 %25, ptr %26, align 1 + %27 = load i1, ptr %26, align 1 br i1 %27, label %if.then.l6, label %if.end.l6 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 + %idx1 = alloca i32, align 4 + store i32 0, ptr %idx1, align 4 + %l = alloca i64, align 8 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 + %28 = load [2 x i64], ptr @anonymous.0, align 8 + %29 = load i32, ptr %idx1, align 4 + %30 = getelementptr inbounds [2 x i64], ptr @anonymous.0, i32 0, i32 %29 %31 = load i64, ptr %30, align 8 store i64 %31, ptr %l, align 8 br label %foreach.loop.l7 @@ -86,16 +81,16 @@ foreach.loop.l7: ; preds = %foreach.cond.l7, %i br label %foreach.end.l4 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 + %idx2 = load i32, ptr %idx1, align 4 + %idx.inc = add i32 %idx2, 1 + store i32 %idx.inc, ptr %idx1, align 4 + %34 = getelementptr inbounds [2 x i64], ptr @anonymous.0, 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.l7: ; preds = %foreach.inc.l7 - %36 = load i32, ptr %idx2, align 4 + %36 = load i32, ptr %idx1, align 4 %37 = icmp ult i32 %36, 2 br i1 %37, label %foreach.loop.l7, label %foreach.end.l7 @@ -106,10 +101,10 @@ if.end.l6: ; preds = %foreach.end.l7, %fo br label %foreach.inc.l4 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 + %idx3 = load i32, ptr %idx, align 4 + %idx.inc4 = add i32 %idx3, 1 + store i32 %idx.inc4, ptr %idx, align 4 + %38 = getelementptr inbounds [5 x i16], ptr %7, i32 0, i32 %idx.inc4 %39 = load i16, ptr %38, align 2 store i16 %39, ptr %s, align 2 br label %foreach.cond.l4 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 4416ac017..d15687041 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 @@ -4,8 +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" @0 = private unnamed_addr constant [10 x i8] c"Short %d\0A\00", align 1 -@anonymous.0 = local_unnamed_addr constant [2 x i64] [i64 1, i64 2] -@l = local_unnamed_addr constant [2 x i64] [i64 1, i64 2] +@anonymous.0 = local_unnamed_addr global [2 x i64] [i64 1, i64 2] @1 = private unnamed_addr constant [9 x i8] c"Long %d\0A\00", align 1 @2 = private unnamed_addr constant [5 x i8] c"End.\00", align 1 @@ -13,16 +12,21 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() local_unnamed_addr #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) + %1 = load i64, ptr @anonymous.0, align 8 + %2 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i64 %1) + %3 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 5) + %4 = load i64, ptr @anonymous.0, align 8 + %5 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i64 %4) + %6 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 25) + %7 = load i64, ptr @anonymous.0, align 8 + %8 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i64 %7) + %9 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 -27) + %10 = load i64, ptr @anonymous.0, align 8 + %11 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i64 %10) + %12 = tail call i32 (ptr, ...) @printf(ptr nonnull @0, i32 -63) + %13 = load i64, ptr @anonymous.0, align 8 + %14 = tail call i32 (ptr, ...) @printf(ptr nonnull @1, i64 %13) + %15 = tail call i32 (ptr, ...) @printf(ptr nonnull @2) ret i32 0 } 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 e1153eb8f..2e2936be4 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 @@ -4,82 +4,77 @@ 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 [10 x i8] c"Short %d\0A\00", align 1 -@anonymous.0 = constant [2 x i64] [i64 1, i64 2] -@l = constant [2 x i64] [i64 1, i64 2] +@anonymous.0 = global [2 x i64] [i64 1, i64 2] @1 = private unnamed_addr constant [9 x i8] c"Long %d\0A\00", align 1 @2 = private unnamed_addr constant [5 x i8] c"End.\00", align 1 define i32 @main() { entry.l1: %result = alloca i32, align 4 - %s1 = alloca i16, align 2 - %shortArray = alloca i16, align 2 - %0 = alloca i16, align 2 - %shortArray1 = alloca i16, align 2 - %1 = alloca i16, align 2 - %shortArray2 = alloca [5 x i16], align 2 - %idx = alloca i32, align 4 - %s = alloca i16, align 2 - %2 = alloca i16, align 2 - %3 = alloca i1, align 1 - %4 = alloca [2 x i64], align 8 - %idx3 = alloca i32, align 4 - %l = alloca i64, align 8 - %l4 = alloca [2 x i64], align 8 store i32 0, ptr %result, align 4 + %s1 = alloca i16, align 2 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, 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, 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 + %0 = load i16, ptr %s1, align 2 + %shortArray.3 = alloca i16, align 2 + store i16 27, ptr %shortArray.3, align 2 + %1 = load i16, ptr %shortArray.3, align 2 + %2 = sub i16 0, %1 + %3 = alloca i16, align 2 + store i16 %2, ptr %3, align 2 + %4 = load i16, ptr %3, align 2 + %shortArray.4 = alloca i16, align 2 + store i16 63, ptr %shortArray.4, align 2 + %5 = load i16, ptr %shortArray.4, align 2 + %6 = sub i16 0, %5 + %7 = alloca i16, align 2 + store i16 %6, ptr %7, align 2 + %8 = load i16, ptr %7, align 2 + %9 = alloca [5 x i16], align 2 + %10 = getelementptr inbounds [5 x i16], ptr %9, i32 0, i32 0 + store i16 1, ptr %10, align 2 + %11 = getelementptr inbounds [5 x i16], ptr %9, i32 0, i32 1 + store i16 %0, ptr %11, align 2 + %12 = getelementptr inbounds [5 x i16], ptr %9, i32 0, i32 2 + store i16 25, ptr %12, align 2 + %13 = getelementptr inbounds [5 x i16], ptr %9, i32 0, i32 3 + store i16 %4, ptr %13, align 2 + %14 = getelementptr inbounds [5 x i16], ptr %9, i32 0, i32 4 + store i16 %8, ptr %14, align 2 + %idx = alloca i32, align 4 store i32 0, ptr %idx, align 4 + %s = alloca i16, align 2 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 + %15 = load [5 x i16], ptr %9, align 2 + %16 = load i32, ptr %idx, align 4 + %17 = getelementptr inbounds [5 x i16], ptr %9, 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.l4: ; preds = %foreach.cond.l4, %entry.l1 - %21 = load i16, ptr %s, align 2 - %22 = sext i16 %21 to i32 - %23 = call i32 (ptr, ...) @printf(ptr @0, i32 %22) - %24 = load i16, ptr %s, align 2 - %25 = and i16 %24, 1 - 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, ptr %3, align 1 - %29 = load i1, ptr %3, align 1 + %19 = load i16, ptr %s, align 2 + %20 = sext i16 %19 to i32 + %21 = call i32 (ptr, ...) @printf(ptr @0, i32 %20) + %22 = load i16, ptr %s, align 2 + %23 = and i16 %22, 1 + %24 = alloca i16, align 2 + store i16 %23, ptr %24, align 2 + %25 = load i16, ptr %24, align 2 + %26 = sext i16 %25 to i32 + %27 = icmp eq i32 %26, 1 + %28 = alloca i1, align 1 + store i1 %27, ptr %28, align 1 + %29 = load i1, ptr %28, align 1 br i1 %29, label %if.then.l6, label %if.end.l6 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 + %idx1 = alloca i32, align 4 + store i32 0, ptr %idx1, align 4 + %l = alloca i64, align 8 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 + %30 = load [2 x i64], ptr @anonymous.0, align 8 + %31 = load i32, ptr %idx1, align 4 + %32 = getelementptr inbounds [2 x i64], ptr @anonymous.0, i32 0, i32 %31 %33 = load i64, ptr %32, align 8 store i64 %33, ptr %l, align 8 br label %foreach.loop.l7 @@ -90,16 +85,16 @@ foreach.loop.l7: ; preds = %foreach.cond.l7, %i br label %foreach.inc.l4 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 + %idx2 = load i32, ptr %idx1, align 4 + %idx.inc = add i32 %idx2, 1 + store i32 %idx.inc, ptr %idx1, align 4 + %36 = getelementptr inbounds [2 x i64], ptr @anonymous.0, 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.l7: ; preds = %foreach.inc.l7 - %38 = load i32, ptr %idx3, align 4 + %38 = load i32, ptr %idx1, align 4 %39 = icmp ult i32 %38, 2 br i1 %39, label %foreach.loop.l7, label %foreach.end.l7 @@ -110,10 +105,10 @@ if.end.l6: ; preds = %foreach.end.l7, %fo br label %foreach.inc.l4 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 + %idx3 = load i32, ptr %idx, align 4 + %idx.inc4 = add i32 %idx3, 1 + store i32 %idx.inc4, ptr %idx, align 4 + %40 = getelementptr inbounds [5 x i16], ptr %9, i32 0, i32 %idx.inc4 %41 = load i16, ptr %40, align 2 store i16 %41, ptr %s, align 2 br label %foreach.cond.l4 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 cb7674379..81fb6d99b 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 @@ -3,42 +3,40 @@ 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" -@intArray = constant [7 x i32] [i32 1, i32 5, i32 4, i32 0, i32 12, i32 12345, i32 9] +@intArray = global [7 x i32] [i32 1, i32 5, i32 4, i32 0, i32 12, i32 12345, i32 9] @0 = private unnamed_addr constant [23 x i8] c"Item for index %d, %d\0A\00", align 1 define i32 @main() { 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, 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 + %idx = alloca i32, align 4 store i32 2, ptr %idx, align 4 + %item = alloca i32, 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 + %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.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, ptr %idx, align 4 - store i32 %8, ptr %0, align 4 + %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) + %7 = load i32, ptr %idx, align 4 + %8 = add i32 %7, 1 + store i32 %8, ptr %idx, align 4 + %9 = alloca i32, align 4 + store i32 %7, ptr %9, align 4 br label %foreach.inc.l3 foreach.inc.l3: ; preds = %foreach.loop.l3 %idx1 = load i32, ptr %idx, align 4 %idx.inc = add i32 %idx1, 1 store i32 %idx.inc, ptr %idx, align 4 - %10 = getelementptr inbounds [7 x i32], ptr %intArray, i32 0, i32 %idx.inc + %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 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 8fdcac0ef..b02320b31 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 @@ -3,22 +3,20 @@ 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" -@intArray = constant [7 x i32] [i32 1, i32 5, i32 4, i32 0, i32 12, i32 12345, i32 9] +@intArray = global [7 x i32] [i32 1, i32 5, i32 4, i32 0, i32 12, i32 12345, i32 9] @0 = private unnamed_addr constant [23 x i8] c"Item for index %d, %d\0A\00", align 1 define i32 @main() { 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, 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 + %index = alloca i32, align 4 store i32 0, ptr %index, align 4 + %item = alloca i32, align 4 store i32 0, ptr %item, align 4 - %0 = load [7 x i32], ptr %intArray, 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 + %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 @@ -33,7 +31,7 @@ foreach.inc.l3: ; preds = %foreach.loop.l3 %idx = load i32, ptr %index, align 4 %idx.inc = add i32 %idx, 1 store i32 %idx.inc, ptr %index, align 4 - %7 = getelementptr inbounds [7 x i32], ptr %intArray, i32 0, i32 %idx.inc + %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 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 055aea035..033226ebd 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 @@ -3,22 +3,20 @@ 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" -@intArray = constant [7 x i32] [i32 1, i32 5, i32 4, i32 0, i32 12, i32 12345, i32 9] +@intArray = global [7 x i32] [i32 1, i32 5, i32 4, i32 0, i32 12, i32 12345, i32 9] @0 = private unnamed_addr constant [22 x i8] c"Item at index %d: %d\0A\00", align 1 define i32 @main() { 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, 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 + %idx = alloca i32, align 4 store i32 0, ptr %idx, align 4 + %item = alloca i32, align 4 store i32 0, ptr %item, align 4 - %0 = load [7 x i32], ptr %intArray, 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 + %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 @@ -33,7 +31,7 @@ foreach.inc.l3: ; preds = %foreach.loop.l3 %idx1 = load i32, ptr %idx, align 4 %idx.inc = add i32 %idx1, 1 store i32 %idx.inc, ptr %idx, align 4 - %7 = getelementptr inbounds [7 x i32], ptr %intArray, i32 0, i32 %idx.inc + %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 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 c202148c9..5d2c4292e 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 @@ -18,24 +18,24 @@ define internal double @_f__void__test() { 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, ptr %1, align 8 - %3 = load double, ptr %1, align 8 - %4 = fadd double %3, 1.200000e+00 - store double %4, ptr %2, align 8 - %5 = load double, ptr %2, align 8 + %2 = load double, ptr %1, align 8 + %3 = fadd double %2, 1.200000e+00 + %4 = alloca double, align 8 + store double %3, ptr %4, align 8 + %result = alloca double, align 8 + %5 = load double, ptr %4, align 8 ret double %5 } define i32 @main() { entry.l9: %result = alloca i32, align 4 - %0 = alloca double, align 8 store i32 0, ptr %result, align 4 - %1 = call double @_f__void__test() - store double %1, ptr %0, align 8 - %2 = load double, ptr %0, align 8 + %0 = call double @_f__void__test() + %1 = alloca double, align 8 + store double %0, ptr %1, align 8 + %2 = load double, ptr %1, align 8 %3 = call i32 (ptr, ...) @printf(ptr @0, double %2) %4 = load i32, ptr %result, align 4 ret i32 %4 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 4e9d280cd..63b8aeda8 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 @@ -9,15 +9,15 @@ target triple = "x86_64-w64-windows-gnu" define internal ptr @_f__void__getTestString__int_double_bool(i32 %0, double %1, i1 %2) { entry.l1: %arg0 = alloca i32, align 4 + store i32 %0, ptr %arg0, align 4 %arg1 = alloca double, align 8 + store double %1, ptr %arg1, align 8 %arg2 = alloca i1, align 1 + store i1 %2, ptr %arg2, align 1 %arg3 = alloca double, align 8 + store double 1.340000e+00, ptr %arg3, align 8 %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 @@ -26,20 +26,20 @@ entry.l1: define i32 @main() { entry.l5: %result = alloca i32, align 4 - %0 = alloca i32, align 4 - %1 = alloca double, align 8 - %2 = alloca i1, align 1 - %3 = alloca ptr, align 8 store i32 0, ptr %result, align 4 + %0 = alloca i32, 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 + %1 = load i32, ptr %0, align 4 + %2 = alloca double, align 8 + store double 3.400000e+00, ptr %2, align 8 + %3 = load double, ptr %2, align 8 + %4 = alloca i1, align 1 + store i1 true, ptr %4, align 1 + %5 = load i1, ptr %4, align 1 + %6 = call ptr @_f__void__getTestString__int_double_bool(i32 %1, double %3, i1 %5) + %7 = alloca ptr, align 8 + store ptr %6, ptr %7, align 8 + %8 = load ptr, ptr %7, align 8 %9 = call i32 (ptr, ...) @printf(ptr @1, ptr %8) %10 = load i32, ptr %result, align 4 ret i32 %10 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 1208a825b..432ff2d66 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 @@ -8,11 +8,11 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %0 = alloca i32, align 4 store i32 0, ptr %result, align 4 - %1 = call i32 @_f__void__test() - store i32 %1, ptr %0, align 4 - %2 = load i32, ptr %0, align 4 + %0 = call i32 @_f__void__test() + %1 = alloca i32, align 4 + store i32 %0, ptr %1, align 4 + %2 = load i32, ptr %1, align 4 %3 = call i32 (ptr, ...) @printf(ptr @0, i32 %2) %4 = load i32, ptr %result, align 4 ret i32 %4 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 fef69c7a3..d53ca717d 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 @@ -18,11 +18,11 @@ entry.l1: define i32 @main() { entry.l5: %result = alloca i32, align 4 - %0 = alloca i64, align 8 store i32 0, ptr %result, align 4 - %1 = call i64 @_f__void__getInlinedValue() - store i64 %1, ptr %0, align 8 - %2 = load i64, ptr %0, align 8 + %0 = call i64 @_f__void__getInlinedValue() + %1 = alloca i64, align 8 + store i64 %0, ptr %1, align 8 + %2 = load i64, ptr %1, align 8 %3 = call i32 (ptr, ...) @printf(ptr @0, i64 %2) %4 = load i32, ptr %result, align 4 ret i32 %4 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 096115f48..08ff211a0 100644 --- a/test/test-files/generator/functions/success-overloading/ir-code.ll +++ b/test/test-files/generator/functions/success-overloading/ir-code.ll @@ -9,10 +9,10 @@ target triple = "x86_64-w64-windows-gnu" define internal i32 @_f__void__testFunc() { entry.l1: %result = alloca i32, align 4 - %0 = alloca i32, align 4 - %1 = call i32 (ptr, ...) @printf(ptr @0) - store i32 1, ptr %0, align 4 - %2 = load i32, ptr %0, align 4 + %0 = call i32 (ptr, ...) @printf(ptr @0) + %1 = alloca i32, align 4 + store i32 1, ptr %1, align 4 + %2 = load i32, ptr %1, align 4 ret i32 %2 } @@ -21,11 +21,11 @@ declare i32 @printf(ptr, ...) define i32 @main() { entry.l11: %result = alloca i32, align 4 - %0 = alloca i32, align 4 store i32 0, ptr %result, align 4 - %1 = call i32 @_f__void__testFunc() - store i32 %1, ptr %0, align 4 - %2 = load i32, ptr %0, align 4 + %0 = call i32 @_f__void__testFunc() + %1 = alloca i32, align 4 + store i32 %0, ptr %1, align 4 + %2 = load i32, ptr %1, 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 3c832ecdc..737eb3754 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 @@ -9,19 +9,18 @@ define internal i32 @_f__void__getAge() { entry.l1: %result = alloca i32, align 4 %i = alloca i1, align 1 - %0 = alloca i32, align 4 store i1 false, ptr %i, align 1 br i1 true, label %if.then.l3, label %if.else.l3 if.then.l3: ; preds = %entry.l1 store i32 20, ptr %result, align 4 - %1 = load i32, ptr %result, align 4 - ret i32 %1 + %0 = load i32, ptr %result, align 4 + ret i32 %0 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 + %1 = load i1, ptr %i, align 1 + br i1 %1, label %if.then.l6, label %if.end.l6 if.then.l6: ; preds = %if.else.l3 store i32 19, ptr %result, align 4 @@ -31,19 +30,20 @@ if.end.l6: ; preds = %if.then.l6, %if.els br label %if.end.l3 if.end.l3: ; preds = %if.end.l6 - store i32 15, ptr %0, align 4 - %3 = load i32, ptr %0, align 4 + %2 = alloca i32, align 4 + store i32 15, ptr %2, align 4 + %3 = load i32, ptr %2, align 4 ret i32 %3 } define i32 @main() { entry.l12: %result = alloca i32, align 4 - %0 = alloca i32, align 4 store i32 0, ptr %result, align 4 - %1 = call i32 @_f__void__getAge() - store i32 %1, ptr %0, align 4 - %2 = load i32, ptr %0, align 4 + %0 = call i32 @_f__void__getAge() + %1 = alloca i32, align 4 + store i32 %0, ptr %1, align 4 + %2 = load i32, ptr %1, align 4 %3 = call i32 (ptr, ...) @printf(ptr @0, i32 %2) %4 = load i32, ptr %result, align 4 ret i32 %4 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 b4030fe82..bbdccb0be 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,32 +5,30 @@ 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 ptr] [ptr @0, ptr @1] +@anonymous.0 = global [2 x ptr] [ptr @0, ptr @1] define i32 @main() { 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 ptr], align 8 - %5 = alloca i1, align 1 store i32 0, ptr %result, align 4 + %0 = alloca double, align 8 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, 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, 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) + %1 = load double, ptr %0, align 8 + call void @_p__void__printFormat__double(double %1) + %2 = alloca i1, align 1 + store i1 true, ptr %2, align 1 + %3 = alloca i32, align 4 + store i32 543, ptr %3, align 4 + %4 = load i32, ptr %3, align 4 + call void @_p__void__printFormat__int(i32 %4) + %5 = alloca i1, align 1 store i1 true, ptr %5, align 1 - %9 = load i32, ptr %result, align 4 - ret i32 %9 + %6 = load [2 x ptr], ptr @anonymous.0, align 8 + call void @_p__void__printFormat__stringarray([2 x ptr] %6) + %7 = alloca i1, align 1 + store i1 true, ptr %7, align 1 + %8 = load i32, ptr %result, align 4 + ret i32 %8 } declare void @_p__void__printFormat__double(double) 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 49103f5b3..72e7f8fc4 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 @@ -9,72 +9,72 @@ target triple = "x86_64-w64-windows-gnu" define internal double @_f__void__genericFunction__int_double(i32 %0, double %1) { 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, ptr %arg1, align 4 + %arg2 = alloca double, align 8 store double %1, ptr %arg2, align 8 + %arg3 = alloca i32, align 4 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, ptr %arg3, align 4 - %8 = sitofp i32 %7 to double - %9 = fadd double %6, %8 - store double %9, ptr %2, align 8 - %10 = load double, ptr %2, align 8 + %result = alloca double, align 8 + %2 = load i32, ptr %arg1, align 4 + %3 = load double, ptr %arg2, align 8 + %4 = sitofp i32 %2 to double + %5 = fadd double %4, %3 + %6 = load i32, ptr %arg3, align 4 + %7 = sitofp i32 %6 to double + %8 = fadd double %5, %7 + %9 = alloca double, align 8 + store double %8, ptr %9, align 8 + %10 = load double, ptr %9, align 8 ret double %10 } define internal double @_f__void__genericFunction__long_double(i64 %0, double %1) { 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, ptr %arg1, align 8 + %arg2 = alloca double, align 8 store double %1, ptr %arg2, align 8 + %arg3 = alloca i32, align 4 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, ptr %arg3, align 4 - %8 = sitofp i32 %7 to double - %9 = fadd double %6, %8 - store double %9, ptr %2, align 8 - %10 = load double, ptr %2, align 8 + %result = alloca double, align 8 + %2 = load i64, ptr %arg1, align 8 + %3 = load double, ptr %arg2, align 8 + %4 = sitofp i64 %2 to double + %5 = fadd double %4, %3 + %6 = load i32, ptr %arg3, align 4 + %7 = sitofp i32 %6 to double + %8 = fadd double %5, %7 + %9 = alloca double, align 8 + store double %8, ptr %9, align 8 + %10 = load double, ptr %9, align 8 ret double %10 } define i32 @main() { entry.l12: %result = alloca i32, align 4 + store i32 0, ptr %result, align 4 %0 = alloca i32, align 4 - %1 = alloca double, align 8 + store i32 1, ptr %0, align 4 + %1 = load i32, ptr %0, align 4 %2 = alloca double, align 8 - %3 = alloca i64, align 8 - %4 = alloca double, align 8 + store double 2.400000e+00, ptr %2, align 8 + %3 = load double, ptr %2, align 8 + %4 = call double @_f__void__genericFunction__int_double(i32 %1, double %3) %5 = alloca double, 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, 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, ptr %5, align 8 - %14 = load double, ptr %5, align 8 + store double %4, ptr %5, align 8 + %6 = load double, ptr %5, align 8 + %7 = call i32 (ptr, ...) @printf(ptr @0, double %6) + %8 = alloca i64, align 8 + store i64 12, ptr %8, align 8 + %9 = load i64, ptr %8, align 8 + %10 = alloca double, align 8 + store double 2.000000e+00, ptr %10, align 8 + %11 = load double, ptr %10, align 8 + %12 = call double @_f__void__genericFunction__long_double(i64 %9, double %11) + %13 = alloca double, align 8 + store double %12, ptr %13, align 8 + %14 = load double, ptr %13, align 8 %15 = call i32 (ptr, ...) @printf(ptr @1, double %14) %16 = load i32, ptr %result, align 4 ret i32 %16 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 7ff4e1395..97804dde5 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 @@ -4,48 +4,48 @@ 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 [10 x i8] c"Data: %d\0A\00", align 1 -@numberList1 = constant [7 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7] -@numberList2 = constant [4 x i64] [i64 10, i64 12, i64 14, i64 16] +@numberList1 = global [7 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7] +@numberList2 = global [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(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 ptr %0, ptr %numberArray, align 8 + %arrayLength = alloca i32, align 4 store i32 %1, ptr %arrayLength, align 4 + %result = alloca i32, align 4 store i32 0, ptr %result, align 4 + %i = alloca i32, 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, ptr %result, align 4 + %2 = load i32, ptr %i, align 4 + %3 = load ptr, ptr %numberArray, align 8 + %4 = getelementptr inbounds i64, ptr %3, i32 %2 + %5 = load i64, ptr %4, align 8 + %6 = load i32, ptr %result, align 4 + %7 = trunc i64 %5 to i32 + %8 = add i32 %6, %7 + store i32 %8, ptr %result, align 4 br label %for.inc.l6 for.inc.l6: ; preds = %for.l6 - %11 = load i32, ptr %i, align 4 - %12 = add i32 %11, 1 - store i32 %12, ptr %i, align 4 - store i32 %11, ptr %2, align 4 + %9 = load i32, ptr %i, align 4 + %10 = add i32 %9, 1 + store i32 %10, ptr %i, align 4 + %11 = alloca i32, align 4 + store i32 %9, ptr %11, align 4 br label %for.cond.l6 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, ptr %3, align 1 - %16 = load i1, ptr %3, align 1 + %12 = load i32, ptr %i, align 4 + %13 = load i32, ptr %arrayLength, align 4 + %14 = icmp slt i32 %12, %13 + %15 = alloca i1, align 1 + store i1 %14, ptr %15, align 1 + %16 = load i1, ptr %15, align 1 br i1 %16, label %for.l6, label %for.end.l6 for.end.l6: ; preds = %for.cond.l6 @@ -56,41 +56,41 @@ for.end.l6: ; preds = %for.cond.l6 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 ptr %0, ptr %numberArray, align 8 + %arrayLength = alloca i32, align 4 store i32 %1, ptr %arrayLength, align 4 + %result = alloca i32, align 4 store i32 0, ptr %result, align 4 + %i = alloca i32, 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, ptr %result, align 4 + %2 = load i32, ptr %i, align 4 + %3 = load ptr, ptr %numberArray, align 8 + %4 = getelementptr inbounds i16, ptr %3, i32 %2 + %5 = load i16, ptr %4, align 2 + %6 = load i32, ptr %result, align 4 + %7 = sext i16 %5 to i32 + %8 = add i32 %6, %7 + store i32 %8, ptr %result, align 4 br label %for.inc.l6 for.inc.l6: ; preds = %for.l6 - %11 = load i32, ptr %i, align 4 - %12 = add i32 %11, 1 - store i32 %12, ptr %i, align 4 - store i32 %11, ptr %2, align 4 + %9 = load i32, ptr %i, align 4 + %10 = add i32 %9, 1 + store i32 %10, ptr %i, align 4 + %11 = alloca i32, align 4 + store i32 %9, ptr %11, align 4 br label %for.cond.l6 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, ptr %3, align 1 - %16 = load i1, ptr %3, align 1 + %12 = load i32, ptr %i, align 4 + %13 = load i32, ptr %arrayLength, align 4 + %14 = icmp slt i32 %12, %13 + %15 = alloca i1, align 1 + store i1 %14, ptr %15, align 1 + %16 = load i1, ptr %15, align 1 br i1 %16, label %for.l6, label %for.end.l6 for.end.l6: ; preds = %for.cond.l6 @@ -101,37 +101,36 @@ for.end.l6: ; preds = %for.cond.l6 define internal void @_p__void__printData__int_intarray(i32 %0, [2 x i32] %1) { 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, ptr %arrayLength, align 4 + %list = alloca [2 x i32], align 4 store [2 x i32] %1, ptr %list, align 4 + %i = alloca i32, 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) + %2 = load i32, ptr %i, align 4 + %3 = getelementptr inbounds [2 x i32], ptr %list, i32 0, i32 %2 + %4 = load i32, ptr %3, align 4 + %5 = call i32 (ptr, ...) @printf(ptr @0, i32 %4) 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, ptr %i, align 4 - store i32 %9, ptr %2, align 4 + %6 = load i32, ptr %i, align 4 + %7 = add i32 %6, 1 + store i32 %7, ptr %i, align 4 + %8 = alloca i32, align 4 + store i32 %6, ptr %8, align 4 br label %for.cond.l12 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, ptr %3, align 1 - %14 = load i1, ptr %3, align 1 - br i1 %14, label %for.l12, label %for.end.l12 + %9 = load i32, ptr %i, align 4 + %10 = load i32, ptr %arrayLength, align 4 + %11 = icmp slt i32 %9, %10 + %12 = alloca i1, align 1 + store i1 %11, ptr %12, align 1 + %13 = load i1, ptr %12, align 1 + br i1 %13, label %for.l12, label %for.end.l12 for.end.l12: ; preds = %for.cond.l12 ret void @@ -142,45 +141,39 @@ declare i32 @printf(ptr, ...) define i32 @main() { entry.l17: %result = alloca i32, align 4 - %numberList1 = alloca [7 x i16], align 2 - %0 = alloca i32, align 4 + store i32 0, ptr %result, align 4 + %0 = load [7 x i16], ptr @numberList1, align 2 %1 = alloca i32, align 4 - %numberList2 = alloca [4 x i64], align 8 - %2 = alloca i32, align 4 - %3 = alloca i32, align 4 - %resultList = alloca [2 x i32], align 4 + store i32 7, ptr %1, align 4 + %2 = load i32, ptr %1, align 4 + %3 = call i32 @_f__void__sumNumbers__shortarray_int(ptr @numberList1, i32 %2) %4 = alloca i32, align 4 - %5 = alloca i1, align 1 - 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, 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 + store i32 %3, ptr %4, align 4 + %5 = load [4 x i64], ptr @numberList2, align 8 + %6 = alloca i32, align 4 + store i32 4, ptr %6, align 4 + %7 = load i32, ptr %6, align 4 + %8 = call i32 @_f__void__sumNumbers__longarray_int(ptr @numberList2, i32 %7) + %9 = alloca i32, align 4 + store i32 %8, ptr %9, align 4 + %10 = load i32, ptr %4, align 4 + %11 = load i32, ptr %9, align 4 + %12 = alloca [2 x i32], align 4 + %13 = getelementptr inbounds [2 x i32], ptr %12, i32 0, i32 0 + store i32 %10, ptr %13, align 4 + %14 = getelementptr inbounds [2 x i32], ptr %12, i32 0, i32 1 + store i32 %11, ptr %14, align 4 + %15 = load [2 x i32], ptr %12, align 4 + %16 = alloca i32, align 4 + store i32 2, ptr %16, align 4 + %17 = load i32, ptr %16, align 4 + %18 = load [2 x i32], ptr %12, align 4 + call void @_p__void__printData__int_intarray(i32 %17, [2 x i32] %18) + %19 = alloca i1, align 1 + store i1 true, ptr %19, align 1 + %20 = load i32, ptr %4, align 4 + %21 = load i32, ptr %9, align 4 + %22 = call i32 (ptr, ...) @printf(ptr @1, i32 %20, i32 %21) + %23 = load i32, ptr %result, align 4 + ret i32 %23 } 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 f434bb7b2..684fcb166 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 @@ -10,23 +10,22 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l8: %result = alloca i32, align 4 + store i32 0, ptr %result, align 4 %dbl = alloca double, align 8 + store double 3.467000e+00, ptr %dbl, align 8 %0 = alloca %_s__double__Vector__doubleptr_int, align 8 %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 + %5 = getelementptr inbounds %_s__double__Vector__doubleptr_int, ptr %0, i32 0, i32 1 + %6 = load i32, ptr %5, align 4 + %7 = call i32 (ptr, ...) @printf(ptr @0, i32 %6) + %8 = load i32, ptr %result, align 4 + ret i32 %8 } 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 033c185ce..8e1e0fbc2 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 @@ -11,30 +11,30 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { 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, ptr %result, align 4 + %0 = alloca i1, align 1 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 + %1 = load i1, ptr %0, align 1 + br i1 %1, label %if.then.l2, label %if.else.l2 if.then.l2: ; preds = %entry.l1 - %4 = call i32 (ptr, ...) @printf(ptr @0) + %2 = call i32 (ptr, ...) @printf(ptr @0) br label %if.end.l2 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 + %3 = alloca i1, align 1 + store i1 false, ptr %3, align 1 + %4 = load i1, ptr %3, align 1 + br i1 %4, label %if.then.l4, label %if.else.l4 if.then.l4: ; preds = %if.else.l2 - %6 = call i32 (ptr, ...) @printf(ptr @1) + %5 = call i32 (ptr, ...) @printf(ptr @1) br label %if.end.l4 if.else.l4: ; preds = %if.else.l2 - store i1 false, ptr %2, align 1 - %7 = load i1, ptr %2, align 1 + %6 = alloca i1, align 1 + store i1 false, ptr %6, align 1 + %7 = load i1, ptr %6, align 1 br i1 %7, label %if.then.l6, label %if.else.l6 if.then.l6: ; preds = %if.else.l4 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 378af45c6..f70ecf65d 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 @@ -9,17 +9,17 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %0 = alloca i1, align 1 - %1 = alloca i32, align 4 store i32 0, ptr %result, align 4 + %0 = alloca i1, align 1 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 + %1 = load i1, ptr %0, align 1 + br i1 %1, label %if.then.l3, label %if.end.l3 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 + %2 = call i32 (ptr, ...) @printf(ptr @0) + %3 = alloca i32, align 4 + store i32 0, ptr %3, align 4 + %4 = load i32, ptr %3, align 4 ret i32 %4 if.end.l3: ; preds = %entry.l1 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 04dd024d2..53b2a8342 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 @@ -8,14 +8,14 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l3: %result = alloca i32, align 4 - %0 = alloca i1, align 1 - %1 = alloca i32, align 4 store i32 0, ptr %result, align 4 + %0 = alloca i1, align 1 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, ptr %1, align 4 - %4 = load i32, ptr %1, align 4 + %1 = load i1, ptr %0, align 1 + %2 = call i32 @_f__void__toInt__bool(i1 %1) + %3 = alloca i32, align 4 + store i32 %2, ptr %3, align 4 + %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 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 d702f402e..1a4a9bb2d 100644 --- a/test/test-files/generator/imports/success-modules/ir-code.ll +++ b/test/test-files/generator/imports/success-modules/ir-code.ll @@ -8,11 +8,11 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l3: %result = alloca i32, align 4 - %0 = alloca i32, align 4 store i32 0, ptr %result, align 4 - %1 = call i32 @_f__void__forwardToOtherModule() - store i32 %1, ptr %0, align 4 - %2 = load i32, ptr %0, align 4 + %0 = call i32 @_f__void__forwardToOtherModule() + %1 = alloca i32, align 4 + store i32 %0, ptr %1, align 4 + %2 = load i32, ptr %1, align 4 %3 = call i32 (ptr, ...) @printf(ptr @0, i32 %2) %4 = load i32, ptr %result, align 4 ret i32 %4 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 f5f420ac6..288a52cfd 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 @@ -10,15 +10,15 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %0 = alloca %_s__char__TestStruct__char_int, align 8 - %1 = alloca i1, align 1 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 + %0 = alloca %_s__char__TestStruct__char_int, align 8 + %1 = getelementptr inbounds %_s__char__TestStruct__char_int, ptr %0, i32 0, i32 0 + store i8 97, ptr %1, align 1 + %2 = getelementptr inbounds %_s__char__TestStruct__char_int, ptr %0, i32 0, i32 1 + store i32 1, ptr %2, align 4 call void @_mp__TestStruct_char__printTest(ptr %0) - store i1 true, ptr %1, align 1 + %3 = alloca i1, align 1 + store i1 true, ptr %3, align 1 %4 = load i32, ptr %result, align 4 ret i32 %4 } @@ -26,12 +26,12 @@ entry.l1: define internal void @_mp__TestStruct_char__printTest(ptr %0) { entry.l13: %this = alloca ptr, align 8 - %1 = alloca i32, align 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 + %1 = load ptr, ptr %this, align 8 + %2 = call i32 @_mf__TestStruct_char__getTest(ptr %1) + %3 = alloca i32, align 4 + store i32 %2, ptr %3, align 4 + %4 = load i32, ptr %3, align 4 %5 = call i32 (ptr, ...) @printf(ptr @0, i32 %4) ret void } @@ -41,37 +41,34 @@ declare i32 @printf(ptr, ...) 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 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, ptr %1, align 1 - %9 = load i1, ptr %1, align 1 - br i1 %9, label %if.then.l18, label %if.end.l18 + %result = alloca i32, align 4 + %1 = load ptr, ptr %this, align 8 + %2 = getelementptr inbounds %_s__char__TestStruct__char_int, ptr %1, i32 0, i32 1 + %3 = load i32, ptr %2, align 4 + %4 = icmp eq i32 %3, 1 + %5 = alloca i1, align 1 + store i1 %4, ptr %5, align 1 + %6 = load i1, ptr %5, align 1 + br i1 %6, label %if.then.l18, label %if.end.l18 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, 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 + %7 = load ptr, ptr %this, align 8 + %8 = getelementptr inbounds %_s__char__TestStruct__char_int, ptr %7, i32 0, i32 1 + %9 = load i32, ptr %8, align 4 + %10 = add i32 %9, 1 + store i32 %10, ptr %8, align 4 + %11 = alloca i32, align 4 + store i32 %9, ptr %11, align 4 + %12 = load ptr, ptr %this, align 8 + call void @_mp__TestStruct_char__printTest(ptr %12) + %13 = alloca i1, align 1 + store i1 true, ptr %13, align 1 br label %if.end.l18 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 + %14 = load ptr, ptr %this, align 8 + %15 = getelementptr inbounds %_s__char__TestStruct__char_int, ptr %14, i32 0, i32 1 + %16 = load i32, ptr %15, align 4 + ret i32 %16 } 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 a452ad6a9..63d1b68cf 100644 --- a/test/test-files/generator/methods/success-methods/ir-code.ll +++ b/test/test-files/generator/methods/success-methods/ir-code.ll @@ -12,46 +12,44 @@ target triple = "x86_64-w64-windows-gnu" 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 + %result = alloca ptr, 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 + %2 = getelementptr inbounds %_s__Letter__string, ptr %1, i32 0, i32 0 + %3 = load ptr, ptr %2, align 8 + ret ptr %3 } 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 + %text = alloca ptr, 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 + %4 = getelementptr inbounds %_s__Letter__string, ptr %3, i32 0, i32 0 + store ptr %2, ptr %4, align 8 ret void } define i32 @main() { entry.l13: %result = alloca i32, align 4 - %0 = alloca %_s__Letter__string, align 8 - %1 = alloca ptr, align 8 - %2 = alloca i1, align 1 - %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 + %0 = alloca %_s__Letter__string, align 8 + %1 = getelementptr inbounds %_s__Letter__string, ptr %0, i32 0, i32 0 + store ptr @0, ptr %1, align 8 + %2 = alloca ptr, align 8 + store ptr @1, ptr %2, align 8 + %3 = load ptr, ptr %2, align 8 + call void @_mp__Letter__setContent__string(ptr %0, ptr %3) + %4 = alloca i1, align 1 + store i1 true, ptr %4, align 1 + %5 = call ptr @_mf__Letter__getContent(ptr %0) + %6 = alloca ptr, align 8 + store ptr %5, ptr %6, align 8 + %7 = load ptr, ptr %6, align 8 %8 = call i32 (ptr, ...) @printf(ptr @2, ptr %7) %9 = load i32, ptr %result, align 4 ret i32 %9 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 a6fbd106b..6073994fc 100644 --- a/test/test-files/generator/operators/success-operators/ir-code.ll +++ b/test/test-files/generator/operators/success-operators/ir-code.ll @@ -8,30 +8,30 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %val = alloca i32, align 4 - %val1 = alloca i32, align 4 - %0 = alloca i32, align 4 - %1 = alloca i32, align 4 - %2 = alloca i32, align 4 - %3 = alloca i32, align 4 store i32 0, ptr %result, align 4 + %val = alloca i32, align 4 store i32 1, ptr %val, align 4 + %val1 = alloca i32, align 4 store i32 1, ptr %val1, align 4 - %4 = load i32, ptr %val1, align 4 - %5 = add i32 %4, 1 - 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, 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, ptr %2, align 4 - %10 = load i32, ptr %2, align 4 - %11 = shl i32 %10, 2 - store i32 %11, ptr %3, align 4 - %12 = load i32, ptr %3, align 4 + %0 = load i32, ptr %val1, align 4 + %1 = add i32 %0, 1 + store i32 %1, ptr %val1, align 4 + %2 = alloca i32, align 4 + store i32 %0, ptr %2, align 4 + %3 = load i32, ptr %2, align 4 + %4 = sub i32 %3, 1 + store i32 %4, ptr %2, align 4 + %5 = alloca i32, align 4 + store i32 %3, ptr %5, align 4 + %6 = load i32, ptr %5, align 4 + %7 = mul i32 %6, 2 + %8 = alloca i32, align 4 + store i32 %7, ptr %8, align 4 + %9 = load i32, ptr %8, align 4 + %10 = shl i32 %9, 2 + %11 = alloca i32, align 4 + store i32 %10, ptr %11, align 4 + %12 = load i32, ptr %11, align 4 %13 = load i32, ptr %val, align 4 %14 = add i32 %13, %12 store i32 %14, ptr %val, align 4 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 8212d3bbf..13ff7b58b 100644 --- a/test/test-files/generator/operators/success-operators2/ir-code.ll +++ b/test/test-files/generator/operators/success-operators2/ir-code.ll @@ -9,8 +9,8 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %i = alloca i32, align 4 store i32 0, ptr %result, align 4 + %i = alloca i32, align 4 store i32 1, ptr %i, align 4 %0 = load i32, ptr %i, align 4 %1 = add i32 %0, 2 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 54d01c50e..dcf2deef3 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 @@ -11,10 +11,10 @@ target triple = "x86_64-w64-windows-gnu" define internal i1 @_f__void__functionTrue() { entry.l1: %result = alloca i1, align 1 - %0 = alloca i1, align 1 - %1 = call i32 (ptr, ...) @printf(ptr @0) - store i1 true, ptr %0, align 1 - %2 = load i1, ptr %0, align 1 + %0 = call i32 (ptr, ...) @printf(ptr @0) + %1 = alloca i1, align 1 + store i1 true, ptr %1, align 1 + %2 = load i1, ptr %1, align 1 ret i1 %2 } @@ -23,55 +23,55 @@ declare i32 @printf(ptr, ...) define internal i1 @_f__void__functionFalse() { entry.l6: %result = alloca i1, align 1 - %0 = alloca i1, align 1 - %1 = call i32 (ptr, ...) @printf(ptr @1) - store i1 false, ptr %0, align 1 - %2 = load i1, ptr %0, align 1 + %0 = call i32 (ptr, ...) @printf(ptr @1) + %1 = alloca i1, align 1 + store i1 false, ptr %1, align 1 + %2 = load i1, ptr %1, align 1 ret i1 %2 } define i32 @main() { entry.l11: %result = alloca i32, align 4 - %0 = alloca i1, align 1 - %1 = alloca i1, align 1 - %2 = alloca i1, align 1 - %3 = alloca i1, align 1 - %4 = alloca i1, align 1 - %5 = alloca i1, align 1 store i32 0, ptr %result, align 4 - %6 = call i1 @_f__void__functionFalse() - 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 + %0 = call i1 @_f__void__functionFalse() + %1 = alloca i1, align 1 + store i1 %0, ptr %1, align 1 + %2 = load i1, ptr %1, align 1 + br i1 %2, label %land.1.l13, label %land.end.l13 land.1.l13: ; preds = %entry.l11 - %8 = call i1 @_f__void__functionTrue() - store i1 %8, ptr %1, align 1 - %9 = load i1, ptr %1, align 1 + %3 = call i1 @_f__void__functionTrue() + %4 = alloca i1, align 1 + store i1 %3, ptr %4, align 1 + %5 = load i1, ptr %4, align 1 br label %land.end.l13 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 (ptr, ...) @printf(ptr @2, i32 %11) - %13 = call i1 @_f__void__functionTrue() - 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 + %land_phi = phi i1 [ %2, %entry.l11 ], [ %5, %land.1.l13 ] + %6 = alloca i1, align 1 + store i1 %land_phi, ptr %6, align 1 + %7 = load i1, ptr %6, align 1 + %8 = zext i1 %7 to i32 + %9 = call i32 (ptr, ...) @printf(ptr @2, i32 %8) + %10 = call i1 @_f__void__functionTrue() + %11 = alloca i1, align 1 + store i1 %10, ptr %11, align 1 + %12 = load i1, ptr %11, align 1 + br i1 %12, label %lor.end.l16, label %lor.1.l16 lor.1.l16: ; preds = %land.end.l13 - %15 = call i1 @_f__void__functionFalse() - store i1 %15, ptr %4, align 1 - %16 = load i1, ptr %4, align 1 + %13 = call i1 @_f__void__functionFalse() + %14 = alloca i1, align 1 + store i1 %13, ptr %14, align 1 + %15 = load i1, ptr %14, align 1 br label %lor.end.l16 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 + %lor_phi = phi i1 [ %12, %land.end.l13 ], [ %15, %lor.1.l16 ] + %16 = alloca i1, align 1 + store i1 %lor_phi, ptr %16, align 1 + %17 = load i1, ptr %16, align 1 %18 = zext i1 %17 to i32 %19 = call i32 (ptr, ...) @printf(ptr @3, i32 %18) %20 = load i32, ptr %result, align 4 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 9edff5a24..3971783d3 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 @@ -7,7 +7,7 @@ target triple = "x86_64-w64-windows-gnu" @1 = private unnamed_addr constant [7 x i8] c"2: %d\0A\00", align 1 @2 = private unnamed_addr constant [7 x i8] c"3: %d\0A\00", align 1 @3 = private unnamed_addr constant [7 x i8] c"4: %d\0A\00", align 1 -@intArray = constant [4 x i32] [i32 1, i32 2, i32 3, i32 4] +@intArray = global [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(ptr %0) { @@ -48,32 +48,28 @@ declare i32 @printf(ptr, ...) define i32 @main() { entry.l11: %result = alloca i32, align 4 - %intArray = alloca [4 x i32], align 4 - %0 = alloca ptr, align 8 - %1 = alloca ptr, align 8 + store i32 0, ptr %result, align 4 + %0 = load i32, ptr getelementptr inbounds ([4 x i32], ptr @intArray, i32 0, i32 1), align 4 + %1 = call i32 (ptr, ...) @printf(ptr @4, i32 %0) %2 = alloca ptr, align 8 + store ptr @intArray, ptr %2, align 8 %3 = alloca ptr, align 8 + store ptr %2, ptr %3, align 8 %4 = alloca ptr, align 8 - %5 = alloca ptr, align 8 - %6 = alloca i1, align 1 - 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 + %5 = load ptr, ptr %4, align 8 + %6 = load ptr, ptr %5, align 8 + %7 = load ptr, ptr %6, align 8 + %8 = getelementptr inbounds [4 x i32], ptr %7, i32 0, i32 0 + %9 = alloca ptr, align 8 + store ptr %8, ptr %9, align 8 + %10 = alloca ptr, align 8 + store ptr %9, ptr %10, align 8 + %11 = alloca ptr, align 8 + store ptr %10, ptr %11, align 8 + call void @_p__void__testProc__intarrayptrptrptr(ptr %11) + %12 = alloca i1, align 1 + store i1 true, ptr %12, align 1 + %13 = load i32, ptr %result, align 4 + ret i32 %13 } 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 95b7089f4..5a2717619 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 @@ -14,52 +14,47 @@ target triple = "x86_64-w64-windows-gnu" define internal void @_p__void__birthday__Personptr(ptr %0) { entry.l7: %person = alloca ptr, align 8 - %1 = alloca i32, 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, ptr %4, align 4 - store i32 %5, ptr %1, align 4 + %1 = load ptr, ptr %person, align 8 + %2 = getelementptr inbounds %_s__Person__string_string_int, ptr %1, i32 0, i32 2 + %3 = load i32, ptr %2, align 4 + %4 = add i32 %3, 1 + store i32 %4, ptr %2, align 4 + %5 = alloca i32, align 4 + store i32 %3, ptr %5, align 4 ret void } define i32 @main() { entry.l11: %result = alloca i32, align 4 - %0 = alloca %_s__Person__string_string_int, align 8 - %1 = alloca ptr, align 8 - %2 = alloca i1, align 1 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 + %0 = alloca %_s__Person__string_string_int, align 8 + %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 32, ptr %3, align 4 %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 + %5 = load ptr, ptr %4, align 8 + %6 = getelementptr inbounds %_s__Person__string_string_int, ptr %0, i32 0, i32 0 + %7 = load ptr, ptr %6, align 8 + %8 = call i32 (ptr, ...) @printf(ptr @2, ptr %5, ptr %7) + %9 = getelementptr inbounds %_s__Person__string_string_int, ptr %0, i32 0, i32 2 + %10 = load i32, ptr %9, align 4 + %11 = call i32 (ptr, ...) @printf(ptr @3, i32 %10) + %12 = alloca ptr, align 8 + store ptr %0, ptr %12, align 8 + %13 = load ptr, ptr %12, align 8 + call void @_p__void__birthday__Personptr(ptr %13) + %14 = alloca i1, align 1 + store i1 true, ptr %14, align 1 + %15 = getelementptr inbounds %_s__Person__string_string_int, ptr %0, i32 0, i32 2 + %16 = load i32, ptr %15, align 4 + %17 = call i32 (ptr, ...) @printf(ptr @4, i32 %16) + %18 = load i32, ptr %result, align 4 + ret i32 %18 } 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 81196c21d..9b8855b82 100644 --- a/test/test-files/generator/pointers/success-pointer/ir-code.ll +++ b/test/test-files/generator/pointers/success-pointer/ir-code.ll @@ -12,29 +12,29 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %food = alloca ptr, align 8 - %0 = alloca ptr, align 8 - %1 = alloca ptr, align 8 store i32 0, ptr %result, align 4 + %food = alloca ptr, align 8 store ptr @0, ptr %food, align 8 + %0 = alloca ptr, align 8 store ptr %food, ptr %0, align 8 + %1 = load ptr, 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 + %3 = load ptr, ptr %2, align 8 + store ptr %3, ptr %2, align 8 + %4 = load ptr, ptr %2, align 8 + %5 = call i32 (ptr, ...) @printf(ptr @1, ptr %1, ptr %4) + %6 = load ptr, ptr %0, align 8 + %7 = load ptr, ptr %6, align 8 + store ptr %7, ptr %6, align 8 + store ptr @2, ptr %6, align 8 + %8 = load ptr, ptr %0, align 8 + %9 = load ptr, ptr %8, align 8 + store ptr %9, ptr %8, align 8 + %10 = load ptr, ptr %8, align 8 + %11 = call i32 (ptr, ...) @printf(ptr @3, ptr %10) + %12 = alloca ptr, align 8 + store ptr %8, ptr %12, align 8 + %13 = load ptr, ptr %12, align 8 %14 = call i32 (ptr, ...) @printf(ptr @4, ptr %13) %15 = load i32, ptr %result, align 4 ret i32 %15 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 58fdcaf42..d6fe0a7bc 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 @@ -25,13 +25,13 @@ declare i32 @printf(ptr, ...) define i32 @main() { entry.l6: %result = alloca i32, align 4 - %0 = alloca i1, align 1 - %1 = alloca i1, align 1 store i32 0, ptr %result, align 4 + %0 = alloca i1, align 1 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, ptr %1, align 1 + %1 = load i1, ptr %0, align 1 + call void @_p__void__executeAction__bool(i1 %1) + %2 = alloca i1, align 1 + store i1 true, ptr %2, 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.ll b/test/test-files/generator/procedures/success-explicit-inlining/ir-code.ll index 976954842..737cf42ab 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 @@ -22,11 +22,11 @@ declare i32 @printf(ptr, ...) define i32 @main() { entry.l5: %result = alloca i32, align 4 - %0 = alloca i1, align 1 store i32 0, ptr %result, align 4 - %1 = call i32 (ptr, ...) @printf(ptr @1) + %0 = call i32 (ptr, ...) @printf(ptr @1) call void @_p__void__printAValue() - store i1 true, ptr %0, align 1 + %1 = alloca i1, align 1 + store i1 true, ptr %1, 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 0b61e8dc4..ec014fd07 100644 --- a/test/test-files/generator/structs/success-constructors/ir-code.ll +++ b/test/test-files/generator/structs/success-constructors/ir-code.ll @@ -13,32 +13,28 @@ 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 + %2 = getelementptr inbounds %_s__Vector__bool_string, ptr %1, i32 0, i32 0 + store i1 false, ptr %2, align 1 + %3 = load ptr, ptr %this, align 8 + %4 = getelementptr inbounds %_s__Vector__bool_string, ptr %3, i32 0, i32 1 + store ptr @0, ptr %4, align 8 ret void } define i32 @main() { entry.l11: %result = alloca i32, align 4 - %vec = alloca %_s__Vector__bool_string, align 8 store i32 0, ptr %result, align 4 + %vec = alloca %_s__Vector__bool_string, align 8 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, 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 + %0 = getelementptr inbounds %_s__Vector__bool_string, ptr %vec, i32 0, i32 0 + %1 = load i1, ptr %0, align 1 + %2 = zext i1 %1 to i32 + %3 = getelementptr inbounds %_s__Vector__bool_string, ptr %vec, i32 0, i32 1 + %4 = load ptr, ptr %3, align 8 + %5 = call i32 (ptr, ...) @printf(ptr @1, i32 %2, ptr %4) + %6 = load i32, ptr %result, align 4 + ret i32 %6 } 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 088f43855..1422ff838 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 @@ -12,25 +12,22 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l3: %result = alloca i32, align 4 - %s = alloca i16, align 2 - %0 = alloca %_s__Socket__int_short_NestedSocket, align 8 store i32 0, ptr %result, align 4 + %s = alloca i16, align 2 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, 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 + %0 = load i16, ptr %s, align 2 + %1 = call %_s__Socket__int_short_NestedSocket @_f__void__openServerSocket__short(i16 %0) + %2 = alloca %_s__Socket__int_short_NestedSocket, align 8 + store %_s__Socket__int_short_NestedSocket %1, ptr %2, align 8 + %3 = getelementptr inbounds %_s__Socket__int_short_NestedSocket, ptr %2, i32 0, i32 2 + %4 = getelementptr inbounds %_s__NestedSocket__string_long, ptr %3, i32 0, i32 0 + %5 = load ptr, ptr %4, align 8 + %6 = call i32 (ptr, ...) @printf(ptr @0, ptr %5) + %7 = getelementptr inbounds %_s__Socket__int_short_NestedSocket, ptr %2, i32 0, i32 0 + %8 = load i32, ptr %7, align 4 + %9 = call i32 (ptr, ...) @printf(ptr @1, i32 %8) + %10 = load i32, ptr %result, align 4 + ret i32 %10 } declare %_s__Socket__int_short_NestedSocket @_f__void__openServerSocket__short(i16) 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 064ae5015..c7abfc14f 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 @@ -8,15 +8,15 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l3: %result = alloca i32, align 4 - %0 = alloca %_s__Vec__int_bool, align 8 - %1 = alloca i1, align 1 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 + %0 = alloca %_s__Vec__int_bool, align 8 + %1 = getelementptr inbounds %_s__Vec__int_bool, ptr %0, i32 0, i32 0 + store i32 11, ptr %1, align 4 + %2 = getelementptr inbounds %_s__Vec__int_bool, ptr %0, i32 0, i32 1 + store i1 false, ptr %2, align 1 call void @_mp__Vec__print(ptr %0) - store i1 true, ptr %1, align 1 + %3 = alloca i1, align 1 + store i1 true, ptr %3, align 1 %4 = load i32, ptr %result, align 4 ret i32 %4 } 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 d826dfbb6..784005cca 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 @@ -12,23 +12,21 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l7: %result = alloca i32, align 4 - %0 = alloca %_s__Person__string_string_int, align 8 store i32 0, ptr %result, align 4 + %0 = alloca %_s__Person__string_string_int, align 8 %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 + %4 = getelementptr inbounds %_s__Person__string_string_int, ptr %0, i32 0, i32 2 + store i32 47, ptr %4, align 4 %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 + %6 = load i32, ptr %5, align 4 + %7 = call i32 (ptr, ...) @printf(ptr @2, i32 %6) + %8 = load i32, ptr %result, align 4 + ret i32 %8 } 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 ab1ee4ff5..e13fc5721 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 @@ -10,73 +10,70 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l13: %result = alloca i32, align 4 + store i32 0, ptr %result, align 4 %0 = alloca %_s__TreeNode__TreeNodeptr_int, align 8 %rootNode = alloca ptr, align 8 - %1 = alloca %_s__TreeNode__TreeNodeptr_int, align 8 - %2 = alloca ptr, align 8 - %3 = alloca %_s__TreeNode__TreeNodeptr_int, align 8 - %4 = alloca ptr, align 8 - %5 = 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, 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 + %1 = load ptr, ptr %rootNode, align 8 + %2 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %0, i32 0, i32 0 + store ptr %1, ptr %2, align 8 + %3 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %0, i32 0, i32 1 + store i32 0, ptr %3, align 4 + %4 = alloca %_s__TreeNode__TreeNodeptr_int, align 8 + %5 = alloca ptr, align 8 + store ptr %0, ptr %5, align 8 + %6 = load ptr, ptr %5, align 8 + %7 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %4, i32 0, i32 0 + store ptr %6, ptr %7, align 8 + %8 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %4, i32 0, i32 1 + store i32 1, ptr %8, align 4 + %9 = alloca %_s__TreeNode__TreeNodeptr_int, align 8 + %10 = alloca ptr, align 8 + store ptr %0, ptr %10, align 8 + %11 = load ptr, ptr %10, align 8 + %12 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %9, i32 0, i32 0 + store ptr %11, ptr %12, align 8 + %13 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %9, i32 0, i32 1 + store i32 2, ptr %13, align 4 + %14 = alloca %_s__TreeNode__TreeNodeptr_int, align 8 + %15 = alloca ptr, align 8 + store ptr %9, ptr %15, align 8 + %16 = load ptr, ptr %15, align 8 + %17 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %14, 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 + %18 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %14, i32 0, i32 1 + store i32 3, ptr %18, align 4 + %19 = alloca ptr, align 8 + store ptr %14, ptr %19, align 8 br label %while.cond.l21 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 + %20 = load ptr, ptr %19, align 8 + %21 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %20, i32 0, i32 0 + %22 = load ptr, ptr %21, align 8 + %23 = alloca ptr, align 8 + store ptr null, ptr %23, align 8 + %24 = load ptr, ptr %23, align 8 + %25 = icmp ne ptr %22, %24 + %26 = alloca i1, align 1 + store i1 %25, ptr %26, align 1 + %27 = load i1, ptr %26, align 1 + br i1 %27, label %while.l21, label %while.end.l21 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 + %28 = load ptr, ptr %19, align 8 + %29 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %28, i32 0, i32 0 + %30 = load ptr, ptr %29, align 8 + store ptr %30, ptr %19, align 8 br label %while.cond.l21 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 + %31 = load ptr, ptr %19, align 8 + %32 = getelementptr inbounds %_s__TreeNode__TreeNodeptr_int, ptr %31, i32 0, i32 1 + %33 = load i32, ptr %32, align 4 + %34 = call i32 (ptr, ...) @printf(ptr @0, i32 %33) + %35 = load i32, ptr %result, align 4 + ret i32 %35 } 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 34d12f059..89106cded 100644 --- a/test/test-files/generator/structs/success-struct/ir-code.ll +++ b/test/test-files/generator/structs/success-struct/ir-code.ll @@ -13,55 +13,50 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { 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 ptr, align 8 - %2 = alloca %_s__TestStruct__intptr_double_Nestedptr, align 8 - %3 = alloca ptr, align 8 - %4 = alloca ptr, align 8 store i32 0, ptr %result, align 4 + %input = alloca i32, align 4 store i32 12, ptr %input, align 4 + %boolean = alloca i1, align 1 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 + %0 = alloca %_s__Nested__string_boolptr, align 8 + %1 = getelementptr inbounds %_s__Nested__string_boolptr, ptr %0, i32 0, i32 0 + store ptr @0, ptr %1, align 8 + %2 = alloca ptr, align 8 + store ptr %boolean, ptr %2, align 8 + %3 = load ptr, ptr %2, align 8 + %4 = getelementptr inbounds %_s__Nested__string_boolptr, ptr %0, i32 0, i32 1 + store ptr %3, ptr %4, align 8 + %5 = alloca %_s__TestStruct__intptr_double_Nestedptr, align 8 + %6 = alloca ptr, align 8 + store ptr %input, ptr %6, align 8 + %7 = load ptr, ptr %6, align 8 + %8 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, ptr %5, i32 0, i32 0 + store ptr %7, ptr %8, align 8 + %9 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, ptr %5, i32 0, i32 1 + store double 4.634000e+01, ptr %9, align 8 + %10 = alloca ptr, align 8 + store ptr %0, ptr %10, align 8 + %11 = load ptr, ptr %10, align 8 + %12 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, ptr %5, 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, 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 + %13 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, ptr %5, i32 0, i32 2 + %14 = load ptr, ptr %13, align 8 + %15 = getelementptr inbounds %_s__Nested__string_boolptr, ptr %14, i32 0, i32 1 + %16 = load ptr, ptr %15, align 8 + %17 = load i1, ptr %16, align 1 + store i1 %17, ptr %16, align 1 + %18 = load i1, ptr %16, align 1 + %19 = zext i1 %18 to i32 + %20 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, ptr %5, i32 0, i32 1 + %21 = load double, ptr %20, align 8 + %22 = call i32 (ptr, ...) @printf(ptr @1, i32 %19, double %21) + %23 = getelementptr inbounds %_s__TestStruct__intptr_double_Nestedptr, ptr %5, i32 0, i32 2 + %24 = load ptr, ptr %23, align 8 + %25 = getelementptr inbounds %_s__Nested__string_boolptr, ptr %24, i32 0, i32 0 + %26 = load ptr, ptr %25, align 8 + %27 = call i32 (ptr, ...) @printf(ptr @2, ptr %26) + %28 = load i32, ptr %result, align 4 + ret i32 %28 } 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 8a7c32f1f..1cfd51b80 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 @@ -26,30 +26,30 @@ entry.l5: define i32 @main() { 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, ptr %result, align 4 - %5 = call i1 @_f__void__condition1() - 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 + %0 = call i1 @_f__void__condition1() + %1 = alloca i1, align 1 + store i1 %0, ptr %1, align 1 + %2 = load i1, ptr %1, align 1 + br i1 %2, label %land.1.l10, label %land.end.l10 land.1.l10: ; preds = %entry.l9 - %7 = call i1 @_f__void__condition2() - store i1 %7, ptr %1, align 1 - %8 = load i1, ptr %1, align 1 + %3 = call i1 @_f__void__condition2() + %4 = alloca i1, align 1 + store i1 %3, ptr %4, align 1 + %5 = load i1, ptr %4, align 1 br label %land.end.l10 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 + %land_phi = phi i1 [ %2, %entry.l9 ], [ %5, %land.1.l10 ] + %6 = alloca i1, align 1 + store i1 %land_phi, ptr %6, align 1 + %7 = alloca i32, align 4 + store i32 2, ptr %7, align 4 + %8 = alloca i32, align 4 + store i32 3, ptr %8, align 4 + %9 = load i1, ptr %6, align 1 + %10 = select i1 %9, ptr %7, ptr %8 %11 = load i32, ptr %10, align 4 %12 = call i32 (ptr, ...) @printf(ptr @0, i32 %11) %13 = load i32, ptr %result, align 4 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 9caffc9b2..314646207 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 @@ -17,16 +17,16 @@ entry.l1: define i32 @main() { 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, ptr %result, align 4 + %condition = alloca i1, align 1 store i1 true, ptr %condition, align 1 - %1 = call i32 @_f__void__get() - store i32 %1, ptr %0, align 4 + %0 = call i32 @_f__void__get() + %1 = alloca i32, align 4 + store i32 %0, ptr %1, align 4 + %r = alloca i32, align 4 store i32 24, ptr %r, align 4 %2 = load i1, ptr %condition, align 1 - %3 = select i1 %2, ptr %0, ptr %r + %3 = select i1 %2, ptr %1, 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 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 68e730a63..feb3a42b2 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 @@ -13,20 +13,20 @@ declare i32 @usleep(i32) define i32 @main() { 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, ptr %result, align 4 - %4 = call i32 (ptr, ...) @printf(ptr @0) + %0 = call i32 (ptr, ...) @printf(ptr @0) + %1 = alloca {}, align 8 + %2 = alloca ptr, align 8 + %3 = call i32 @pthread_create(ptr %2, ptr null, ptr @_thread0, ptr %1) + %4 = alloca {}, align 8 %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 + %6 = call i32 @pthread_create(ptr %5, ptr null, ptr @_thread1, ptr %4) + %7 = alloca i32, align 4 + store i32 1000000, ptr %7, align 4 + %8 = load i32, ptr %7, align 4 + %9 = call i32 @usleep(i32 %8) + %10 = alloca i32, align 4 + store i32 %9, ptr %10, align 4 %11 = call i32 (ptr, ...) @printf(ptr @3) %12 = load i32, ptr %result, align 4 ret i32 %12 @@ -37,11 +37,11 @@ declare i32 @printf(ptr, ...) define internal ptr @_thread0(ptr %0) { thread.entry.l5: %1 = alloca i32, align 4 - %2 = alloca i32, align 4 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 + %2 = load i32, ptr %1, align 4 + %3 = call i32 @usleep(i32 %2) + %4 = alloca i32, align 4 + store i32 %3, ptr %4, align 4 %5 = call i32 (ptr, ...) @printf(ptr @1) ret ptr null } @@ -51,11 +51,11 @@ declare i32 @pthread_create(ptr, ptr, ptr, ptr) define internal ptr @_thread1(ptr %0) { thread.entry.l9: %1 = alloca i32, align 4 - %2 = alloca i32, align 4 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 + %2 = load i32, ptr %1, align 4 + %3 = call i32 @usleep(i32 %2) + %4 = alloca i32, align 4 + store i32 %3, ptr %4, 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 5d700a3e0..8e1e74b80 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 @@ -15,17 +15,17 @@ entry.l3: %0 = alloca {}, align 8 %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 + %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 + store ptr %3, ptr %t1, align 8 + %4 = alloca { ptr, ptr }, align 8 + store ptr %t1, ptr %4, align 8 + %5 = getelementptr inbounds { ptr, ptr }, ptr %4, 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) + %7 = call i32 @pthread_create(ptr nonnull %6, ptr null, ptr nonnull @_thread1, ptr nonnull %4) %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) 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 d3ca42d6b..c548b489c 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 @@ -13,40 +13,40 @@ declare i32 @usleep(i32) define i32 @main() { entry.l3: %result = alloca i32, align 4 - %t1 = alloca ptr, align 8 - %t2 = alloca ptr, align 8 - %t3 = alloca ptr, align 8 - %0 = alloca {}, align 8 - %1 = alloca { ptr, ptr }, align 8 - %2 = alloca {}, align 8 - %3 = alloca i32, align 4 store i32 0, ptr %result, align 4 + %t1 = alloca ptr, align 8 store ptr null, ptr %t1, align 8 + %t2 = alloca ptr, align 8 store ptr null, ptr %t2, align 8 + %t3 = alloca ptr, 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 + %0 = alloca {}, align 8 + %1 = alloca ptr, align 8 + %2 = call i32 @pthread_create(ptr %1, ptr null, ptr @_thread0, ptr %0) + %3 = load ptr, ptr %1, align 8 + store ptr %3, ptr %t1, align 8 + %4 = alloca { ptr, ptr }, align 8 + %5 = getelementptr inbounds { ptr, ptr }, ptr %4, i32 0, i32 0 + store ptr %t1, ptr %5, align 8 + %6 = getelementptr inbounds { ptr, ptr }, ptr %4, i32 0, i32 1 + store ptr %t3, ptr %6, align 8 + %7 = alloca ptr, align 8 + %8 = call i32 @pthread_create(ptr %7, ptr null, ptr @_thread1, ptr %4) + %9 = load ptr, ptr %7, align 8 + store ptr %9, ptr %t2, align 8 + %10 = alloca {}, align 8 + %11 = alloca ptr, align 8 + %12 = call i32 @pthread_create(ptr %11, ptr null, ptr @_thread2, ptr %10) + %13 = load ptr, ptr %11, align 8 + store ptr %13, ptr %t3, align 8 + %14 = load ptr, ptr %t1, align 8 + %15 = call i32 @pthread_join(ptr %14, ptr null) + %16 = load ptr, ptr %t2, align 8 + %17 = call i32 @pthread_join(ptr %16, ptr null) + %18 = load ptr, ptr %t3, align 8 + %19 = call i32 @pthread_join(ptr %18, ptr null) + %20 = alloca i32, align 4 + store i32 3, ptr %20, align 4 %21 = call i32 (ptr, ...) @printf(ptr @3) %22 = load i32, ptr %result, align 4 ret i32 %22 @@ -55,11 +55,11 @@ entry.l3: define internal ptr @_thread0(ptr %0) { thread.entry.l8: %1 = alloca i32, align 4 - %2 = alloca i32, align 4 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 + %2 = load i32, ptr %1, align 4 + %3 = call i32 @usleep(i32 %2) + %4 = alloca i32, align 4 + store i32 %3, ptr %4, align 4 %5 = call i32 (ptr, ...) @printf(ptr @0) ret ptr null } @@ -89,11 +89,11 @@ declare i32 @pthread_join(ptr, ptr) define internal ptr @_thread2(ptr %0) { thread.entry.l18: %1 = alloca i32, align 4 - %2 = alloca i32, align 4 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 + %2 = load i32, ptr %1, align 4 + %3 = call i32 @usleep(i32 %2) + %4 = alloca i32, align 4 + store i32 %3, ptr %4, 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 0f6a381ac..25c2b7ffe 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 @@ -12,18 +12,18 @@ declare i32 @usleep(i32) local_unnamed_addr define i32 @main() local_unnamed_addr { entry.l3: - %i = alloca i32, align 4 - %0 = alloca { ptr }, align 8 %puts = tail call i32 @puts(ptr nonnull @str) + %i = alloca i32, align 4 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 + %0 = call i32 (ptr, ...) @printf(ptr nonnull @0, i32 %storemerge2) + %1 = alloca { ptr }, align 8 + store ptr %i, ptr %1, align 8 %2 = alloca ptr, align 8 - %3 = call i32 @pthread_create(ptr nonnull %2, ptr null, ptr nonnull @_thread0, ptr nonnull %0) + %3 = call i32 @pthread_create(ptr nonnull %2, ptr null, ptr nonnull @_thread0, ptr nonnull %1) %4 = load i32, ptr %i, align 4 %5 = add i32 %4, 1 store i32 %5, ptr %i, align 4 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 b32baa470..c171d762d 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 @@ -13,45 +13,45 @@ declare i32 @usleep(i32) define i32 @main() { entry.l3: %result = alloca i32, align 4 - %i = alloca i32, align 4 - %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, ptr %result, align 4 - %5 = call i32 (ptr, ...) @printf(ptr @0) + %0 = call i32 (ptr, ...) @printf(ptr @0) + %i = alloca i32, align 4 store i32 1, ptr %i, align 4 br label %for.cond.l5 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) + %1 = load i32, ptr %i, align 4 + %2 = call i32 (ptr, ...) @printf(ptr @1, i32 %1) + %3 = alloca { ptr }, align 8 + %4 = getelementptr inbounds { ptr }, ptr %3, i32 0, i32 0 + store ptr %i, ptr %4, align 8 + %5 = alloca ptr, align 8 + %6 = call i32 @pthread_create(ptr %5, ptr null, ptr @_thread0, ptr %3) br label %for.inc.l5 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 + %7 = load i32, ptr %i, align 4 + %8 = add i32 %7, 1 + store i32 %8, ptr %i, align 4 + %9 = alloca i32, align 4 + store i32 %7, ptr %9, align 4 br label %for.cond.l5 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 + %10 = load i32, ptr %i, align 4 + %11 = icmp sle i32 %10, 8 + %12 = alloca i1, align 1 + store i1 %11, ptr %12, align 1 + %13 = load i1, ptr %12, align 1 + br i1 %13, label %for.l5, label %for.end.l5 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 + %14 = alloca i32, align 4 + store i32 1000000, ptr %14, align 4 + %15 = load i32, ptr %14, align 4 + %16 = call i32 @usleep(i32 %15) + %17 = alloca i32, align 4 + store i32 %16, ptr %17, align 4 %18 = call i32 (ptr, ...) @printf(ptr @3) %19 = load i32, ptr %result, align 4 ret i32 %19 @@ -67,11 +67,11 @@ thread.entry.l7: %4 = mul i32 100, %3 %5 = mul i32 %4, 1000 %6 = alloca i32, align 4 - %7 = alloca i32, align 4 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 + %7 = load i32, ptr %6, align 4 + %8 = call i32 @usleep(i32 %7) + %9 = alloca i32, align 4 + store i32 %8, ptr %9, align 4 %10 = call i32 (ptr, ...) @printf(ptr @2) ret ptr null } 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 76dc24fac..1c58e46be 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 @@ -12,22 +12,22 @@ declare i32 @usleep(i32) local_unnamed_addr define i32 @main() local_unnamed_addr { entry.l3: - %capturedVariable = alloca i32, align 4 - %i = alloca i32, align 4 - %0 = alloca { ptr, ptr }, align 8 %puts = tail call i32 @puts(ptr nonnull @str) + %capturedVariable = alloca i32, align 4 store i32 0, ptr %capturedVariable, align 4 + %i = alloca i32, 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.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 + %0 = call i32 (ptr, ...) @printf(ptr nonnull @0, i32 %storemerge2) + %1 = alloca { ptr, ptr }, align 8 + store ptr %capturedVariable, ptr %1, align 8 + %2 = getelementptr inbounds { ptr, ptr }, ptr %1, i64 0, i32 1 + store ptr %i, ptr %2, align 8 %3 = alloca ptr, align 8 - %4 = call i32 @pthread_create(ptr nonnull %3, ptr null, ptr nonnull @_thread0, ptr nonnull %0) + %4 = call i32 @pthread_create(ptr nonnull %3, ptr null, ptr nonnull @_thread0, ptr nonnull %1) %5 = load i32, ptr %i, align 4 %6 = add i32 %5, 1 store i32 %6, ptr %i, align 4 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 3f0c8beb1..9c7928000 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 @@ -13,49 +13,49 @@ declare i32 @usleep(i32) define i32 @main() { entry.l3: %result = alloca i32, align 4 - %capturedVariable = alloca i32, align 4 - %i = alloca i32, align 4 - %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, ptr %result, align 4 - %5 = call i32 (ptr, ...) @printf(ptr @0) + %0 = call i32 (ptr, ...) @printf(ptr @0) + %capturedVariable = alloca i32, align 4 store i32 0, ptr %capturedVariable, align 4 + %i = alloca i32, align 4 store i32 1, ptr %i, align 4 br label %for.cond.l6 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) + %1 = load i32, ptr %i, align 4 + %2 = call i32 (ptr, ...) @printf(ptr @1, i32 %1) + %3 = alloca { ptr, ptr }, align 8 + %4 = getelementptr inbounds { ptr, ptr }, ptr %3, i32 0, i32 0 + store ptr %capturedVariable, ptr %4, align 8 + %5 = getelementptr inbounds { ptr, ptr }, ptr %3, i32 0, i32 1 + store ptr %i, ptr %5, align 8 + %6 = alloca ptr, align 8 + %7 = call i32 @pthread_create(ptr %6, ptr null, ptr @_thread0, ptr %3) br label %for.inc.l6 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 + %8 = load i32, ptr %i, align 4 + %9 = add i32 %8, 1 + store i32 %9, ptr %i, align 4 + %10 = alloca i32, align 4 + store i32 %8, ptr %10, align 4 br label %for.cond.l6 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 + %11 = load i32, ptr %i, align 4 + %12 = icmp sle i32 %11, 8 + %13 = alloca i1, align 1 + store i1 %12, ptr %13, align 1 + %14 = load i1, ptr %13, align 1 + br i1 %14, label %for.l6, label %for.end.l6 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 + %15 = alloca i32, align 4 + store i32 1000000, ptr %15, align 4 + %16 = load i32, ptr %15, align 4 + %17 = call i32 @usleep(i32 %16) + %18 = alloca i32, align 4 + store i32 %17, ptr %18, align 4 %19 = call i32 (ptr, ...) @printf(ptr @3) %20 = load i32, ptr %result, align 4 ret i32 %20 @@ -73,11 +73,11 @@ thread.entry.l8: %6 = mul i32 100, %5 %7 = mul i32 %6, 1000 %8 = alloca i32, align 4 - %9 = alloca i32, align 4 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 + %9 = load i32, ptr %8, align 4 + %10 = call i32 @usleep(i32 %9) + %11 = alloca i32, align 4 + store i32 %10, ptr %11, align 4 %12 = load i32, ptr %2, align 4 %13 = mul i32 %12, 2 store volatile i32 %13, ptr %2, align 4 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 30b2ea95c..7ce9b477e 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 @@ -8,17 +8,17 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %l = alloca i64, align 8 - %0 = alloca ptr, align 8 - %iPtr = alloca ptr, align 8 - %1 = alloca ptr, align 8 store i32 0, ptr %result, align 4 + %l = alloca i64, align 8 store i64 1234, ptr %l, align 8 + %0 = alloca ptr, align 8 store ptr %l, ptr %0, align 8 + %iPtr = alloca ptr, 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 + %1 = load ptr, ptr %0, align 8 + %2 = alloca ptr, align 8 + store ptr %1, ptr %2, align 8 + %3 = load ptr, ptr %2, align 8 store ptr %3, ptr %iPtr, align 8 %4 = load ptr, ptr %iPtr, align 8 %5 = load i32, ptr %4, align 4 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 3bbb7c664..b021260e2 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 @@ -20,57 +20,56 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { 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 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, ptr %result, align 4 + %doubleVar = alloca double, align 8 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) + %0 = load double, ptr %doubleVar, align 8 + %1 = call i32 (ptr, ...) @printf(ptr @0, double %0) + %intVar = alloca i32, align 4 store i32 0, ptr %intVar, align 4 - %3 = load i32, ptr %intVar, align 4 - %4 = call i32 (ptr, ...) @printf(ptr @1, i32 %3) + %2 = load i32, ptr %intVar, align 4 + %3 = call i32 (ptr, ...) @printf(ptr @1, i32 %2) + %shortVar = alloca i16, align 2 store i16 0, ptr %shortVar, align 2 - %5 = load i16, ptr %shortVar, align 2 - %6 = sext i16 %5 to i32 - %7 = call i32 (ptr, ...) @printf(ptr @2, i32 %6) + %4 = load i16, ptr %shortVar, align 2 + %5 = sext i16 %4 to i32 + %6 = call i32 (ptr, ...) @printf(ptr @2, i32 %5) + %longVar = alloca i64, align 8 store i64 0, ptr %longVar, align 8 - %8 = load i64, ptr %longVar, align 8 - %9 = call i32 (ptr, ...) @printf(ptr @3, i64 %8) + %7 = load i64, ptr %longVar, align 8 + %8 = call i32 (ptr, ...) @printf(ptr @3, i64 %7) + %stringVar = alloca ptr, align 8 store ptr @4, ptr %stringVar, align 8 - %10 = load ptr, ptr %stringVar, align 8 - %11 = call i32 (ptr, ...) @printf(ptr @5, ptr %10) + %9 = load ptr, ptr %stringVar, align 8 + %10 = call i32 (ptr, ...) @printf(ptr @5, ptr %9) + %byteVar = alloca i8, align 1 store i8 0, ptr %byteVar, align 1 - %12 = load i8, ptr %byteVar, align 1 - %13 = sext i8 %12 to i32 - %14 = call i32 (ptr, ...) @printf(ptr @6, i32 %13) + %11 = load i8, ptr %byteVar, align 1 + %12 = sext i8 %11 to i32 + %13 = call i32 (ptr, ...) @printf(ptr @6, i32 %12) + %charVar = alloca i8, align 1 store i8 0, ptr %charVar, align 1 - %15 = load i8, ptr %charVar, align 1 - %16 = sext i8 %15 to i32 - %17 = call i32 (ptr, ...) @printf(ptr @7, i32 %16) + %14 = load i8, ptr %charVar, align 1 + %15 = sext i8 %14 to i32 + %16 = call i32 (ptr, ...) @printf(ptr @7, i32 %15) + %boolVar = alloca i1, align 1 store i1 false, ptr %boolVar, align 1 - %18 = load i1, ptr %boolVar, align 1 - %19 = zext i1 %18 to i32 - %20 = call i32 (ptr, ...) @printf(ptr @8, i32 %19) - %21 = getelementptr inbounds %_s__NestedStruct__int_string, ptr %0, i32 0, i32 0 + %17 = load i1, ptr %boolVar, align 1 + %18 = zext i1 %17 to i32 + %19 = call i32 (ptr, ...) @printf(ptr @8, i32 %18) + %20 = alloca %_s__NestedStruct__int_string, align 8 + %21 = getelementptr inbounds %_s__NestedStruct__int_string, ptr %20, i32 0, i32 0 store i32 0, ptr %21, align 4 - %22 = getelementptr inbounds %_s__NestedStruct__int_string, ptr %0, i32 0, i32 1 + %22 = getelementptr inbounds %_s__NestedStruct__int_string, ptr %20, i32 0, i32 1 store ptr @9, ptr %22, align 8 + %structArrayVar = alloca [4 x %_s__NestedStruct__int_string], 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 + %23 = getelementptr inbounds [4 x %_s__NestedStruct__int_string], ptr %structArrayVar, i32 0, i32 2 + %24 = getelementptr inbounds %_s__NestedStruct__int_string, ptr %23, i32 0, i32 1 + %25 = load ptr, ptr %24, align 8 + %26 = call i32 (ptr, ...) @printf(ptr @10, ptr %25) + %27 = load i32, ptr %result, align 4 + ret i32 %27 } declare i32 @printf(ptr, ...) 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 1405ee0d6..00d06d540 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 @@ -8,51 +8,51 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %loopCounterOuter = alloca double, align 8 - %0 = alloca i1, align 1 - %1 = alloca i1, align 1 - %loopCounterInner = alloca i16, align 2 - %2 = alloca i1, align 1 - %3 = alloca i16, align 2 store i32 0, ptr %result, align 4 + %loopCounterOuter = alloca double, align 8 store double 0.000000e+00, ptr %loopCounterOuter, align 8 br label %while.cond.l3 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, ptr %0, align 1 - %6 = load i1, ptr %0, align 1 - br i1 %6, label %while.l3, label %while.end.l3 + %0 = load double, ptr %loopCounterOuter, align 8 + %1 = fcmp olt double %0, 1.000000e+01 + %2 = alloca i1, align 1 + store i1 %1, ptr %2, align 1 + %3 = load i1, ptr %2, align 1 + br i1 %3, label %while.l3, label %while.end.l3 while.l3: ; preds = %while.cond.l3 - %7 = load double, ptr %loopCounterOuter, align 8 - %8 = fcmp olt double %7, 4.000000e+00 - 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 + %4 = load double, ptr %loopCounterOuter, align 8 + %5 = fcmp olt double %4, 4.000000e+00 + %6 = alloca i1, align 1 + store i1 %5, ptr %6, align 1 + %7 = load i1, ptr %6, align 1 + br i1 %7, label %if.then.l4, label %if.end.l4 if.then.l4: ; preds = %while.l3 + %loopCounterInner = alloca i16, align 2 store i16 10, ptr %loopCounterInner, align 2 br label %while.cond.l6 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, ptr %2, align 1 - %13 = load i1, ptr %2, align 1 - br i1 %13, label %while.l6, label %while.end.l6 + %8 = load i16, ptr %loopCounterInner, align 2 + %9 = sext i16 %8 to i32 + %10 = icmp sgt i32 %9, 0 + %11 = alloca i1, align 1 + store i1 %10, ptr %11, align 1 + %12 = load i1, ptr %11, align 1 + br i1 %12, label %while.l6, label %while.end.l6 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 (ptr, ...) @printf(ptr @0, double %14, i32 %16) - %18 = load i16, ptr %loopCounterInner, align 2 - %19 = sub i16 %18, 1 - store i16 %19, ptr %loopCounterInner, align 2 - store i16 %18, ptr %3, align 2 + %13 = load double, ptr %loopCounterOuter, align 8 + %14 = load i16, ptr %loopCounterInner, align 2 + %15 = sext i16 %14 to i32 + %16 = call i32 (ptr, ...) @printf(ptr @0, double %13, i32 %15) + %17 = load i16, ptr %loopCounterInner, align 2 + %18 = sub i16 %17, 1 + store i16 %18, ptr %loopCounterInner, align 2 + %19 = alloca i16, align 2 + store i16 %17, ptr %19, align 2 br label %while.end.l3 while.end.l6: ; preds = %while.cond.l6 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 093e6896e..cc35d4c68 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 @@ -11,8 +11,8 @@ entry.l1: br label %while.l3 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 + %loopCounterOuter.04 = phi double [ 0.000000e+00, %entry.l1 ], [ %0, %while.cond.l3.backedge ] + %0 = fadd double %loopCounterOuter.04, 1.500000e-01 %1 = fcmp olt double %0, 4.000000e+00 br i1 %1, label %while.cond.l3.backedge.loopexit, label %while.cond.l3.backedge 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 e02520015..88f6d5bd1 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 @@ -8,60 +8,60 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %loopCounterOuter = alloca double, align 8 - %0 = alloca i1, align 1 - %1 = alloca i1, align 1 - %loopCounterInner = alloca i16, align 2 - %2 = alloca i1, align 1 - %3 = alloca i16, align 2 - %4 = alloca i1, align 1 store i32 0, ptr %result, align 4 + %loopCounterOuter = alloca double, align 8 store double 0.000000e+00, ptr %loopCounterOuter, align 8 br label %while.cond.l3 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, ptr %0, align 1 - %7 = load i1, ptr %0, align 1 - br i1 %7, label %while.l3, label %while.end.l3 + %0 = load double, ptr %loopCounterOuter, align 8 + %1 = fcmp olt double %0, 1.000000e+01 + %2 = alloca i1, align 1 + store i1 %1, ptr %2, align 1 + %3 = load i1, ptr %2, align 1 + br i1 %3, label %while.l3, label %while.end.l3 while.l3: ; preds = %while.cond.l3 - %8 = load double, ptr %loopCounterOuter, align 8 - %9 = fadd double %8, 1.500000e-01 - 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, ptr %1, align 1 - %12 = load i1, ptr %1, align 1 - br i1 %12, label %if.then.l5, label %if.end.l5 + %4 = load double, ptr %loopCounterOuter, align 8 + %5 = fadd double %4, 1.500000e-01 + store double %5, ptr %loopCounterOuter, align 8 + %6 = load double, ptr %loopCounterOuter, align 8 + %7 = fcmp olt double %6, 4.000000e+00 + %8 = alloca i1, align 1 + store i1 %7, ptr %8, align 1 + %9 = load i1, ptr %8, align 1 + br i1 %9, label %if.then.l5, label %if.end.l5 if.then.l5: ; preds = %while.l3 + %loopCounterInner = alloca i16, align 2 store i16 10, ptr %loopCounterInner, align 2 br label %while.cond.l7 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, ptr %2, align 1 - %16 = load i1, ptr %2, align 1 - br i1 %16, label %while.l7, label %while.end.l7 + %10 = load i16, ptr %loopCounterInner, align 2 + %11 = sext i16 %10 to i32 + %12 = icmp sgt i32 %11, 0 + %13 = alloca i1, align 1 + store i1 %12, ptr %13, align 1 + %14 = load i1, ptr %13, align 1 + br i1 %14, label %while.l7, label %while.end.l7 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 (ptr, ...) @printf(ptr @0, double %17, i32 %19) - %21 = load i16, ptr %loopCounterInner, align 2 - %22 = sub i16 %21, 1 - 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, ptr %4, align 1 - %26 = load i1, ptr %4, align 1 + %15 = load double, ptr %loopCounterOuter, align 8 + %16 = load i16, ptr %loopCounterInner, align 2 + %17 = sext i16 %16 to i32 + %18 = call i32 (ptr, ...) @printf(ptr @0, double %15, i32 %17) + %19 = load i16, ptr %loopCounterInner, align 2 + %20 = sub i16 %19, 1 + store i16 %20, ptr %loopCounterInner, align 2 + %21 = alloca i16, align 2 + store i16 %19, ptr %21, align 2 + %22 = load i16, ptr %loopCounterInner, align 2 + %23 = sext i16 %22 to i32 + %24 = icmp eq i32 %23, 5 + %25 = alloca i1, align 1 + store i1 %24, ptr %25, align 1 + %26 = load i1, ptr %25, align 1 br i1 %26, label %if.then.l10, label %if.end.l10 if.then.l10: ; preds = %while.l7 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 05259587c..7fa14ffee 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 @@ -8,17 +8,17 @@ target triple = "x86_64-w64-windows-gnu" define i32 @main() { entry.l1: %result = alloca i32, align 4 - %i = alloca i32, align 4 - %0 = alloca i1, align 1 store i32 0, ptr %result, align 4 + %i = alloca i32, align 4 store i32 0, ptr %i, align 4 br label %while.cond.l3 while.cond.l3: ; preds = %while.l3, %entry.l1 - %1 = load i32, ptr %i, align 4 - %2 = icmp slt i32 %1, 10 - store i1 %2, ptr %0, align 1 - %3 = load i1, ptr %0, align 1 + %0 = load i32, ptr %i, align 4 + %1 = icmp slt i32 %0, 10 + %2 = alloca i1, align 1 + store i1 %1, ptr %2, align 1 + %3 = load i1, ptr %2, align 1 br i1 %3, label %while.l3, label %while.end.l3 while.l3: ; preds = %while.cond.l3