├── OlaTests ├── googletest │ ├── docs │ │ ├── _config.yml │ │ ├── assets │ │ │ └── css │ │ │ │ └── style.scss │ │ ├── platforms.md │ │ ├── community_created_documentation.md │ │ ├── index.md │ │ ├── samples.md │ │ └── _data │ │ │ └── navigation.yml │ ├── .clang-format │ ├── googlemock │ │ ├── docs │ │ │ └── README.md │ │ ├── include │ │ │ └── gmock │ │ │ │ └── internal │ │ │ │ └── custom │ │ │ │ ├── gmock-generated-actions.h │ │ │ │ ├── README.md │ │ │ │ ├── gmock-matchers.h │ │ │ │ └── gmock-port.h │ │ ├── cmake │ │ │ ├── gmock.pc.in │ │ │ └── gmock_main.pc.in │ │ ├── README.md │ │ └── test │ │ │ ├── gmock_link2_test.cc │ │ │ └── gmock_link_test.cc │ ├── googletest │ │ ├── docs │ │ │ └── README.md │ │ ├── cmake │ │ │ ├── gtest.pc.in │ │ │ ├── gtest_main.pc.in │ │ │ ├── Config.cmake.in │ │ │ └── libgtest.la.in │ │ ├── include │ │ │ └── gtest │ │ │ │ └── internal │ │ │ │ └── custom │ │ │ │ ├── README.md │ │ │ │ ├── gtest.h │ │ │ │ └── gtest-port.h │ │ ├── test │ │ │ ├── production.cc │ │ │ ├── gtest_main_unittest.cc │ │ │ ├── googletest-uninitialized-test_.cc │ │ │ ├── gtest_testbridge_test_.cc │ │ │ ├── gtest-typed-test2_test.cc │ │ │ ├── googletest-setuptestsuite-test_.cc │ │ │ └── gtest_xml_outfile1_test_.cc │ │ └── samples │ │ │ └── sample1.h │ ├── .github │ │ └── ISSUE_TEMPLATE │ │ │ ├── config.yml │ │ │ └── 10-feature_request.yml │ ├── CMakeLists.txt │ ├── fake_fuchsia_sdk.bzl │ ├── googletest_deps.bzl │ ├── WORKSPACE │ ├── LICENSE │ ├── WORKSPACE.bzlmod │ ├── .gitignore │ └── ci │ │ └── windows-presubmit.bat └── Tests │ ├── Custom │ ├── test_class.ola │ ├── test_const.ola │ ├── test_floats.ola │ ├── test_constructors.ola │ ├── test_inheritance.ola │ ├── test_polymorphism.ola │ ├── test_overloading.ola │ ├── test_alias.ola │ ├── test_implicitcasts.ola │ ├── test_string.ola │ ├── test_sizeof.ola │ ├── test_plusminus.ola │ ├── test_ref.ola │ ├── test_goto.ola │ ├── test_enum.ola │ ├── test_returns.ola │ ├── test_array.ola │ └── test_functioncalls.ola │ └── LLVM │ ├── test_const.ola │ ├── test_alias.ola │ ├── test_floats.ola │ ├── test_constructors.ola │ ├── test_string.ola │ ├── test_sizeof.ola │ ├── test_polymorphism.ola │ ├── test_plusminus.ola │ ├── test_overloading.ola │ ├── test_class.ola │ ├── test_goto.ola │ ├── test_functioncalls.ola │ ├── test_enum.ola │ ├── test_implicitcasts.ola │ ├── test_returns.ola │ └── test_array.ola ├── OlaPlayground ├── Test │ └── test.ola ├── CMakeLists.txt └── main.cpp ├── OlaDocs ├── olaarch.png ├── olalogo.png ├── olalogo_wide.png ├── olalogo_wide_new.png ├── olalogo_wide_new2.png ├── Images │ ├── llvm_cfg_O0.png │ ├── llvm_cfg_O1.png │ ├── custom_cfg_O0.png │ ├── custom_cfg_O1.png │ ├── custom_domtree.png │ ├── llvm_domtree_O0.png │ └── llvm_domtree_O1.png └── todo.md ├── OlaLib ├── std │ ├── assert.ola │ ├── io.ola │ ├── string.ola │ └── math.ola ├── olalib.cpp ├── olaassert.h ├── olaio.h ├── olastring.h └── CMakeLists.txt ├── OlaCompiler ├── Compiler │ ├── Compiler.h │ ├── CompilerOptions.h │ ├── CompileRequest.h │ └── CompilerMacros.h ├── Utility │ ├── Command.h │ ├── Attribute.h │ ├── IteratorRange.h │ └── CLIParser.cpp ├── Backend │ ├── LLVM │ │ ├── LLVMUtils.h │ │ ├── LLVMIRPassManager.h │ │ ├── LLVMUtils.cpp │ │ ├── LLVMIRGenContext.h │ │ ├── Passes │ │ │ └── TestPass.h │ │ └── LLVMIRGenContext.cpp │ └── Custom │ │ ├── IR │ │ ├── Value.cpp │ │ ├── Pass.cpp │ │ ├── IRPrinter.h │ │ ├── CFGPrinter.h │ │ ├── IRGenContext.cpp │ │ ├── IRGenContext.h │ │ ├── Passes │ │ │ ├── GlobalAttributeInferPass.h │ │ │ ├── DeadCodeEliminationPass.h │ │ │ ├── GlobalDeadCodeEliminationPass.h │ │ │ ├── GlobalValueNumberingPass.h │ │ │ ├── ConstantPropagationPass.h │ │ │ ├── ArithmeticReductionPass.h │ │ │ ├── DominatorTreeAnalysisPass.cpp │ │ │ ├── FunctionPassManagerModuleAdaptor.cpp │ │ │ ├── FunctionInlinerPass.h │ │ │ ├── LoopInvariantCodeMotionPass.h │ │ │ ├── CommonSubexpressionEliminationPass.h │ │ │ ├── SimplifyCFGPass.h │ │ │ ├── LoopAnalysisPass.h │ │ │ ├── Mem2RegPass.h │ │ │ ├── FunctionPassManagerModuleAdaptor.h │ │ │ ├── CFGAnalysisPass.h │ │ │ ├── DominatorTreeAnalysisPass.h │ │ │ ├── DominanceFrontierAnalysisPass.h │ │ │ ├── DeadCodeEliminationPass.cpp │ │ │ ├── CFGAnalysisPass.cpp │ │ │ ├── DominanceFrontierAnalysisPass.cpp │ │ │ ├── GlobalDeadCodeEliminationPass.cpp │ │ │ └── LoopInvariantCodeMotionPass.cpp │ │ ├── Pass.h │ │ ├── Constant.cpp │ │ ├── IRModulePass.h │ │ ├── FunctionPass.h │ │ ├── IRPrinter.cpp │ │ ├── IRPassManager.h │ │ ├── IRModule.cpp │ │ ├── IRModule.h │ │ ├── DominanceFrontier.h │ │ ├── CFGPrinter.cpp │ │ ├── Value.h │ │ ├── DominanceFrontier.cpp │ │ ├── GlobalValue.cpp │ │ ├── ConstantFold.h │ │ ├── CFG.h │ │ ├── CFG.cpp │ │ └── PassManager.h │ │ └── Codegen │ │ ├── MachineOperand.cpp │ │ ├── x64 │ │ ├── x64TargetInstInfo.h │ │ ├── x64TargetISelInfo.h │ │ ├── SysV │ │ │ ├── SysV_x64Target.h │ │ │ ├── SysV_x64TargetFrameInfo.h │ │ │ └── SysV_x64.h │ │ ├── Microsoft │ │ │ ├── Microsoft_x64Target.h │ │ │ ├── Microsoft_x64TargetFrameInfo.h │ │ │ └── Microsoft_x64.h │ │ └── x64AsmPrinter.h │ │ ├── ARM64 │ │ ├── ARM64TargetInstInfo.h │ │ ├── ARM64Target.h │ │ ├── ARM64TargetFrameInfo.h │ │ └── ARM64AsmPrinter.h │ │ ├── MachineFunction.cpp │ │ ├── AsmPrinter.cpp │ │ ├── Target.cpp │ │ ├── MachineGlobal.h │ │ ├── RegisterAllocator.h │ │ ├── AsmPrinter.h │ │ ├── LinearScanRegisterAllocator.h │ │ ├── MachineRelocable.h │ │ ├── LivenessAnalysis.h │ │ ├── MachineIRPrinter.h │ │ ├── MachineInstruction.cpp │ │ ├── MachineBasicBlock.h │ │ └── MachineStorage.h ├── main.cpp ├── Frontend │ ├── AST │ │ ├── ASTNode.h │ │ ├── AST.cpp │ │ ├── AST.h │ │ └── ASTFwd.h │ ├── TokenKind.h │ ├── SourceLocation.h │ ├── SourceBuffer.cpp │ ├── ImportProcessor.h │ ├── SourceBuffer.h │ ├── TokenKind.cpp │ ├── FrontendContext.h │ ├── Diagnostics.h │ ├── Lexer.h │ └── Diagnostics.cpp └── Core │ ├── Types.h │ ├── Log.h │ └── Log.cpp ├── ola_config.h.in └── LICENSE.txt /OlaTests/googletest/docs/_config.yml: -------------------------------------------------------------------------------- 1 | title: GoogleTest 2 | -------------------------------------------------------------------------------- /OlaPlayground/Test/test.ola: -------------------------------------------------------------------------------- 1 | public int main() 2 | { 3 | return 0b1010; 4 | } 5 | -------------------------------------------------------------------------------- /OlaDocs/olaarch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mateeeeeee/Ola/HEAD/OlaDocs/olaarch.png -------------------------------------------------------------------------------- /OlaDocs/olalogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mateeeeeee/Ola/HEAD/OlaDocs/olalogo.png -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_class.ola: -------------------------------------------------------------------------------- 1 | public int main() 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_const.ola: -------------------------------------------------------------------------------- 1 | public int main() 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_floats.ola: -------------------------------------------------------------------------------- 1 | public int main() 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /OlaDocs/olalogo_wide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mateeeeeee/Ola/HEAD/OlaDocs/olalogo_wide.png -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_constructors.ola: -------------------------------------------------------------------------------- 1 | public int main() 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_inheritance.ola: -------------------------------------------------------------------------------- 1 | public int main() 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_polymorphism.ola: -------------------------------------------------------------------------------- 1 | public int main() 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /OlaDocs/olalogo_wide_new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mateeeeeee/Ola/HEAD/OlaDocs/olalogo_wide_new.png -------------------------------------------------------------------------------- /OlaDocs/olalogo_wide_new2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mateeeeeee/Ola/HEAD/OlaDocs/olalogo_wide_new2.png -------------------------------------------------------------------------------- /OlaLib/std/assert.ola: -------------------------------------------------------------------------------- 1 | extern nomangle void Assert(bool); 2 | extern nomangle void AssertMsg(bool, char[]); -------------------------------------------------------------------------------- /OlaDocs/Images/llvm_cfg_O0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mateeeeeee/Ola/HEAD/OlaDocs/Images/llvm_cfg_O0.png -------------------------------------------------------------------------------- /OlaDocs/Images/llvm_cfg_O1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mateeeeeee/Ola/HEAD/OlaDocs/Images/llvm_cfg_O1.png -------------------------------------------------------------------------------- /OlaDocs/Images/custom_cfg_O0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mateeeeeee/Ola/HEAD/OlaDocs/Images/custom_cfg_O0.png -------------------------------------------------------------------------------- /OlaDocs/Images/custom_cfg_O1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mateeeeeee/Ola/HEAD/OlaDocs/Images/custom_cfg_O1.png -------------------------------------------------------------------------------- /OlaDocs/Images/custom_domtree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mateeeeeee/Ola/HEAD/OlaDocs/Images/custom_domtree.png -------------------------------------------------------------------------------- /OlaDocs/Images/llvm_domtree_O0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mateeeeeee/Ola/HEAD/OlaDocs/Images/llvm_domtree_O0.png -------------------------------------------------------------------------------- /OlaDocs/Images/llvm_domtree_O1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mateeeeeee/Ola/HEAD/OlaDocs/Images/llvm_domtree_O1.png -------------------------------------------------------------------------------- /OlaTests/Tests/LLVM/test_const.ola: -------------------------------------------------------------------------------- 1 | 2 | public void main() 3 | { 4 | const int a = 5; 5 | a = 10; 6 | return a; 7 | } -------------------------------------------------------------------------------- /OlaTests/googletest/docs/assets/css/style.scss: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | 4 | @import "jekyll-theme-primer"; 5 | @import "main"; 6 | -------------------------------------------------------------------------------- /OlaCompiler/Compiler/Compiler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace ola 4 | { 5 | class CompileRequest; 6 | Int Compile(CompileRequest const&); 7 | } -------------------------------------------------------------------------------- /OlaLib/olalib.cpp: -------------------------------------------------------------------------------- 1 | #include "olaio.h" 2 | #include "olaassert.h" 3 | #include "olamath.h" 4 | #include "olastring.h" 5 | #include "olafile.h" 6 | 7 | -------------------------------------------------------------------------------- /OlaTests/googletest/.clang-format: -------------------------------------------------------------------------------- 1 | # Run manually to reformat a file: 2 | # clang-format -i --style=file 3 | Language: Cpp 4 | BasedOnStyle: Google 5 | -------------------------------------------------------------------------------- /OlaCompiler/Utility/Command.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | namespace ola 5 | { 6 | Int ExecuteCommand(Char const* cmd); 7 | Int ExecuteCommand_NonBlocking(Char const* cmd, Float timeout); 8 | } -------------------------------------------------------------------------------- /OlaTests/googletest/googlemock/docs/README.md: -------------------------------------------------------------------------------- 1 | # Content Moved 2 | 3 | We are working on updates to the GoogleTest documentation, which has moved to 4 | the top-level [docs](../../docs) directory. 5 | -------------------------------------------------------------------------------- /OlaTests/googletest/googletest/docs/README.md: -------------------------------------------------------------------------------- 1 | # Content Moved 2 | 3 | We are working on updates to the GoogleTest documentation, which has moved to 4 | the top-level [docs](../../docs) directory. 5 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/LLVM/LLVMUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | namespace llvm 5 | { 6 | class Module; 7 | } 8 | 9 | namespace ola 10 | { 11 | Bool VerifyLLVMModule(llvm::Module& module); 12 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Value.cpp: -------------------------------------------------------------------------------- 1 | #include "Value.h" 2 | #include "IRType.h" 3 | 4 | namespace ola 5 | { 6 | 7 | OLA_NODISCARD IRContext& Value::GetContext() const 8 | { 9 | return type->GetContext(); 10 | } 11 | 12 | } -------------------------------------------------------------------------------- /OlaTests/googletest/.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Get Help 4 | url: https://github.com/google/googletest/discussions 5 | about: Please ask and answer questions here. 6 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/MachineOperand.cpp: -------------------------------------------------------------------------------- 1 | #include "MachineOperand.h" 2 | 3 | 4 | namespace ola 5 | { 6 | Uint64 MachineOperand::GetHash() const 7 | { 8 | return std::hash{}(storage); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Pass.cpp: -------------------------------------------------------------------------------- 1 | #include "Pass.h" 2 | #include "PassRegistry.h" 3 | 4 | namespace ola 5 | { 6 | 7 | std::string_view Pass::GetPassName() const 8 | { 9 | return g_PassRegistry.GetInfo(ID)->GetName(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /OlaDocs/todo.md: -------------------------------------------------------------------------------- 1 | ## TODO 2 | 3 | ### Custom Backend 4 | - IR optimization passes 5 | - Mem2Reg (Finish DominatorTreeAnalysis) 6 | - CSE 7 | - GVN 8 | - DCE 9 | - Add support for: 10 | - Classes 11 | - Stack Layout/Call Conventions 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ola_config.h.in: -------------------------------------------------------------------------------- 1 | #define OLA_COMPILER_PATH "@OLA_COMPILER_PATH@" 2 | #define OLA_LIB_PATH "@OLA_LIB_PATH@" 3 | #define OLA_TESTS_PATH "@OLA_TESTS_PATH@" 4 | #define OLA_PLAYGROUND_PATH "@OLA_PLAYGROUND_PATH@" 5 | #define OLA_BINARY_PATH "@OLA_BINARY_PATH@" 6 | -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_overloading.ola: -------------------------------------------------------------------------------- 1 | import std.Assert; 2 | 3 | int f(int a) 4 | { 5 | return 1; 6 | } 7 | int f(int a, int b) 8 | { 9 | return 2; 10 | } 11 | 12 | 13 | public int main() 14 | { 15 | Assert(f(1) == 1); 16 | Assert(f(1,2) == 2); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/IRPrinter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "PrinterBase.h" 3 | 4 | namespace ola 5 | { 6 | class IRPrinter final : public PrinterBase 7 | { 8 | public: 9 | explicit IRPrinter(std::ostream& os) : os(os) {} 10 | void PrintModule(IRModule const& M); 11 | 12 | private: 13 | std::ostream& os; 14 | }; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_alias.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | alias MyInt = int; 4 | 5 | public int main() 6 | { 7 | MyInt myInt = 1; 8 | alias MyIntArray = int[3]; 9 | MyIntArray myIntArray = {myInt, myInt + 1, myInt + 2}; 10 | Assert(myIntArray[0] == 1); 11 | Assert(myIntArray[1] == 2); 12 | Assert(myIntArray[2] == 3); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /OlaTests/Tests/LLVM/test_alias.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | alias MyInt = int; 4 | 5 | public int main() 6 | { 7 | MyInt myInt = 1; 8 | alias MyIntArray = int[3]; 9 | MyIntArray myIntArray = {myInt, myInt + 1, myInt + 2}; 10 | Assert(myIntArray[0] == 1); 11 | Assert(myIntArray[1] == 2); 12 | Assert(myIntArray[2] == 3); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /OlaLib/std/io.ola: -------------------------------------------------------------------------------- 1 | extern nomangle void PrintInt(int i); 2 | extern nomangle void PrintFloat(float f); 3 | extern nomangle void PrintChar(char c); 4 | extern nomangle void PrintString(char[] str); 5 | extern nomangle int ReadInt(); 6 | extern nomangle float ReadFloat(); 7 | extern nomangle char ReadChar(); 8 | extern nomangle void ReadString(char[] str, int size); -------------------------------------------------------------------------------- /OlaCompiler/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Core/Log.h" 2 | #include "Compiler/CompileRequest.h" 3 | #include "Compiler/Compiler.h" 4 | 5 | int main(int argc, char** argv) 6 | { 7 | OLA_LOG_INIT(); 8 | ola::CompileRequest compile_request{}; 9 | if (compile_request.Parse(argc, argv)) 10 | { 11 | return ola::Compile(compile_request); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/x64/x64TargetInstInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/Codegen/Target.h" 3 | 4 | namespace ola 5 | { 6 | class x64TargetInstInfo : public TargetInstInfo 7 | { 8 | public: 9 | virtual InstInfo GetInstInfo(Uint32 opcode) const override; 10 | virtual std::string GetInstName(Uint32 opcode) const override; 11 | }; 12 | } -------------------------------------------------------------------------------- /OlaCompiler/Frontend/AST/ASTNode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | namespace ola 5 | { 6 | class ASTVisitor; 7 | 8 | class ASTNode 9 | { 10 | public: 11 | virtual ~ASTNode() = default; 12 | virtual void Accept(ASTVisitor& visitor, Uint32 depth) const {}; 13 | virtual void Accept(ASTVisitor& visitor) const {} 14 | protected: 15 | ASTNode() = default; 16 | }; 17 | } -------------------------------------------------------------------------------- /OlaCompiler/Frontend/TokenKind.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ola 5 | { 6 | enum class TokenKind : Uint16 7 | { 8 | #define TOKEN(X) X, 9 | #include "Tokens.def" 10 | }; 11 | std::string_view GetTokenName(TokenKind t); 12 | 13 | Bool IsKeyword(std::string_view identifer); 14 | TokenKind GetKeywordType(std::string_view identifer); 15 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/ARM64/ARM64TargetInstInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/Codegen/Target.h" 3 | 4 | namespace ola 5 | { 6 | class ARM64TargetInstInfo : public TargetInstInfo 7 | { 8 | public: 9 | virtual InstInfo GetInstInfo(Uint32 opcode) const override; 10 | virtual std::string GetInstName(Uint32 opcode) const override; 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/CFGPrinter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "PrinterBase.h" 3 | 4 | namespace ola 5 | { 6 | class CFG; 7 | 8 | class CFGPrinter final : public PrinterBase 9 | { 10 | public: 11 | CFGPrinter() { } 12 | void Print(Function const*, CFG const&); 13 | 14 | private: 15 | void PrintFunction(Function const*, CFG const&); 16 | }; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /OlaLib/olaassert.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern "C" 5 | { 6 | void Assert(bool expr) 7 | { 8 | if (!expr) 9 | { 10 | puts("Assert failed!"); 11 | exit(-252); 12 | } 13 | } 14 | void AssertMsg(bool expr, char* msg) 15 | { 16 | if (!expr) 17 | { 18 | printf("Assert failed: %s!", msg); 19 | exit(-252); 20 | } 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /OlaTests/googletest/googletest/cmake/gtest.pc.in: -------------------------------------------------------------------------------- 1 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 2 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 3 | 4 | Name: gtest 5 | Description: GoogleTest (without main() function) 6 | Version: @PROJECT_VERSION@ 7 | URL: https://github.com/google/googletest 8 | Libs: -L${libdir} -lgtest @CMAKE_THREAD_LIBS_INIT@ 9 | Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ 10 | -------------------------------------------------------------------------------- /OlaTests/googletest/docs/platforms.md: -------------------------------------------------------------------------------- 1 | # Supported Platforms 2 | 3 | GoogleTest follows Google's 4 | [Foundational C++ Support Policy](https://opensource.google/documentation/policies/cplusplus-support). 5 | See 6 | [this table](https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md) 7 | for a list of currently supported versions compilers, platforms, and build 8 | tools. 9 | -------------------------------------------------------------------------------- /OlaTests/googletest/googlemock/include/gmock/internal/custom/gmock-generated-actions.h: -------------------------------------------------------------------------------- 1 | // IWYU pragma: private, include "gmock/gmock.h" 2 | // IWYU pragma: friend gmock/.* 3 | 4 | #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ 5 | #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ 6 | 7 | #endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ 8 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/MachineFunction.cpp: -------------------------------------------------------------------------------- 1 | #include "MachineFunction.h" 2 | #include "MachineBasicBlock.h" 3 | 4 | namespace ola 5 | { 6 | MachineFunction::MachineFunction(std::string_view symbol, Bool is_declaration) : MachineRelocable(symbol), is_declaration(is_declaration) 7 | { 8 | local_stack_objects.reserve(32); 9 | } 10 | 11 | MachineFunction::~MachineFunction() = default; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /OlaTests/googletest/docs/community_created_documentation.md: -------------------------------------------------------------------------------- 1 | # Community-Created Documentation 2 | 3 | The following is a list, in no particular order, of links to documentation 4 | created by the Googletest community. 5 | 6 | * [Googlemock Insights](https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/blob/master/googletest/insights.md), 7 | by [ElectricRCAircraftGuy](https://github.com/ElectricRCAircraftGuy) 8 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/AsmPrinter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "AsmPrinter.h" 3 | 4 | namespace ola 5 | { 6 | 7 | void AsmPrinter::Finalize() 8 | { 9 | for (auto const& [section, buffer] : section_map) 10 | { 11 | std::string section_label = GetSectionLabel(section); 12 | if (!section_label.empty()) os << section_label << "\n\n"; 13 | os << buffer; 14 | } 15 | } 16 | 17 | } 18 | 19 | -------------------------------------------------------------------------------- /OlaTests/Tests/LLVM/test_floats.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | const float globalFloat = 10.0; 4 | 5 | public int main() 6 | { 7 | float localFloat = 3 * 3.3; 8 | Assert(globalFloat > localFloat); 9 | float diff = globalFloat - localFloat; 10 | float diffCubed = diff * diff * diff; 11 | int int1 = diffCubed * 999; 12 | Assert(int1 == 0); 13 | int int2 = diffCubed * 1000; 14 | Assert(int2 == 1); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /OlaCompiler/Frontend/AST/AST.cpp: -------------------------------------------------------------------------------- 1 | #include "AST.h" 2 | #include "ASTVisitor.h" 3 | 4 | namespace ola 5 | { 6 | void TranslationUnit::Accept(ASTVisitor& visitor, Uint32 depth) const 7 | { 8 | visitor.Visit(*this, depth); 9 | for (auto&& decl : declarations) decl->Accept(visitor, depth + 1); 10 | } 11 | 12 | void TranslationUnit::Accept(ASTVisitor& visitor) const 13 | { 14 | visitor.Visit(*this, 0); 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /OlaTests/googletest/googlemock/cmake/gmock.pc.in: -------------------------------------------------------------------------------- 1 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 2 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 3 | 4 | Name: gmock 5 | Description: GoogleMock (without main() function) 6 | Version: @PROJECT_VERSION@ 7 | URL: https://github.com/google/googletest 8 | Requires: gtest = @PROJECT_VERSION@ 9 | Libs: -L${libdir} -lgmock @CMAKE_THREAD_LIBS_INIT@ 10 | Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ 11 | -------------------------------------------------------------------------------- /OlaTests/googletest/googlemock/cmake/gmock_main.pc.in: -------------------------------------------------------------------------------- 1 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 2 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 3 | 4 | Name: gmock_main 5 | Description: GoogleMock (with main() function) 6 | Version: @PROJECT_VERSION@ 7 | URL: https://github.com/google/googletest 8 | Requires: gmock = @PROJECT_VERSION@ 9 | Libs: -L${libdir} -lgmock_main @CMAKE_THREAD_LIBS_INIT@ 10 | Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ 11 | -------------------------------------------------------------------------------- /OlaTests/googletest/googletest/cmake/gtest_main.pc.in: -------------------------------------------------------------------------------- 1 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 2 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 3 | 4 | Name: gtest_main 5 | Description: GoogleTest (with main() function) 6 | Version: @PROJECT_VERSION@ 7 | URL: https://github.com/google/googletest 8 | Requires: gtest = @PROJECT_VERSION@ 9 | Libs: -L${libdir} -lgtest_main @CMAKE_THREAD_LIBS_INIT@ 10 | Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ 11 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/IRGenContext.cpp: -------------------------------------------------------------------------------- 1 | #include "IRGenContext.h" 2 | #include "IRVisitor.h" 3 | 4 | namespace ola 5 | { 6 | IRGenContext::IRGenContext(std::string_view filename) : context(), module(context, filename) 7 | {} 8 | 9 | IRGenContext::~IRGenContext() = default; 10 | 11 | void IRGenContext::Generate(AST const* ast) 12 | { 13 | IRVisitor ir_visitor(context, module); 14 | ir_visitor.VisitAST(ast); 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/IRGenContext.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "IRContext.h" 3 | #include "IRModule.h" 4 | 5 | namespace ola 6 | { 7 | struct AST; 8 | 9 | class IRGenContext 10 | { 11 | public: 12 | explicit IRGenContext(std::string_view filename); 13 | ~IRGenContext(); 14 | 15 | void Generate(AST const* ast); 16 | IRModule& GetModule() { return module; } 17 | 18 | private: 19 | IRContext context; 20 | IRModule module; 21 | }; 22 | } -------------------------------------------------------------------------------- /OlaTests/googletest/googletest/cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | include(CMakeFindDependencyMacro) 3 | if (@GTEST_HAS_PTHREAD@) 4 | set(THREADS_PREFER_PTHREAD_FLAG @THREADS_PREFER_PTHREAD_FLAG@) 5 | find_dependency(Threads) 6 | endif() 7 | if (@GTEST_HAS_ABSL@) 8 | find_dependency(absl) 9 | find_dependency(re2) 10 | endif() 11 | 12 | include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") 13 | check_required_components("@project_name@") 14 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/LLVM/LLVMIRPassManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Compiler/CompilerOptions.h" 3 | 4 | namespace llvm 5 | { 6 | class Module; 7 | } 8 | 9 | namespace ola 10 | { 11 | struct LLVMIRPassOptions 12 | { 13 | Bool domfrontier_print; 14 | }; 15 | class LLVMIRPassManager 16 | { 17 | public: 18 | explicit LLVMIRPassManager(llvm::Module& module); 19 | void Run(OptimizationLevel level, LLVMIRPassOptions const& opts); 20 | 21 | private: 22 | llvm::Module& module; 23 | }; 24 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/LLVM/LLVMUtils.cpp: -------------------------------------------------------------------------------- 1 | #include "LLVMUtils.h" 2 | #include "Core/Log.h" 3 | #include "llvm/IR/Verifier.h" 4 | 5 | namespace ola 6 | { 7 | Bool VerifyLLVMModule(llvm::Module& module) 8 | { 9 | std::string error_msg; 10 | llvm::raw_string_ostream error_stream(error_msg); 11 | if (llvm::verifyModule(module, &error_stream)) 12 | { 13 | error_stream.flush(); 14 | OLA_ERROR("Module verification failed: {}", error_msg); 15 | return false; 16 | } 17 | return true; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/x64/x64TargetISelInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/Codegen/Target.h" 3 | 4 | namespace ola 5 | { 6 | class x64TargetISelInfo : public TargetISelInfo 7 | { 8 | public: 9 | virtual Bool LowerInstruction(Instruction* I, MachineContext& ctx) const override; 10 | virtual void LegalizeInstruction(InstLegalizeContext& legalize_ctx, MachineContext& lowering_ctx) const override; 11 | virtual void PostLegalizeInstruction(InstLegalizeContext& legalize_ctx) const override; 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /OlaLib/std/string.ola: -------------------------------------------------------------------------------- 1 | 2 | extern nomangle bool IsAlnum(char ch); 3 | extern nomangle bool IsAlpha(char ch); 4 | extern nomangle bool IsLower(char ch); 5 | extern nomangle bool IsUpper(char ch); 6 | extern nomangle bool IsDigit(char ch); 7 | extern nomangle bool IsSpace(char ch); 8 | extern nomangle char ToLower(char ch); 9 | extern nomangle char ToUpper(char ch); 10 | 11 | extern nomangle float StringToFloat(char[] str); 12 | extern nomangle int StringToInt(char[] str); 13 | extern nomangle void StringCopy(char[] src, char[] dst, int size); -------------------------------------------------------------------------------- /OlaCompiler/Backend/LLVM/LLVMIRGenContext.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "llvm/IR/LLVMContext.h" 5 | #include "llvm/IR/Module.h" 6 | 7 | namespace ola 8 | { 9 | struct AST; 10 | class LLVMIRVisitor; 11 | 12 | class LLVMIRGenContext 13 | { 14 | public: 15 | explicit LLVMIRGenContext(std::string_view file_name); 16 | ~LLVMIRGenContext(); 17 | 18 | void Generate(AST const* ast); 19 | llvm::Module& GetModule() { return module; } 20 | 21 | private: 22 | llvm::LLVMContext context; 23 | llvm::Module module; 24 | }; 25 | 26 | } -------------------------------------------------------------------------------- /OlaTests/Tests/LLVM/test_constructors.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | import std.io; 3 | 4 | class B 5 | { 6 | B(int y) 7 | { 8 | this.y = y; 9 | } 10 | public int y = 0; 11 | }; 12 | 13 | class D : B 14 | { 15 | D(int x) 16 | { 17 | super(x * 2); 18 | this.x = x; 19 | } 20 | D(int x, int y) 21 | { 22 | this(x); 23 | this.x *= y; 24 | } 25 | public int x = 0; 26 | }; 27 | 28 | public int main() 29 | { 30 | D d1(5); 31 | Assert(d1.x == 5); 32 | Assert(d1.y == 10); 33 | 34 | D d2(2,3); 35 | Assert(d2.x == 6); 36 | Assert(d2.y == 4); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/GlobalAttributeInferPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/IR/IRModulePass.h" 3 | 4 | namespace ola 5 | { 6 | class GlobalAttributeInferPass : public IRModulePass 7 | { 8 | inline static Char id = 0; 9 | public: 10 | GlobalAttributeInferPass() : IRModulePass(id) {} 11 | virtual Bool RunOn(IRModule&, IRModuleAnalysisManager&) override; 12 | 13 | static void const* ID() { return &id; } 14 | }; 15 | OLA_REGISTER_PASS(GlobalAttributeInferPass, "Global Attribute Infer Pass"); 16 | inline IRModulePass* CreateGlobalAttributeInferPass() { return new GlobalAttributeInferPass(); } 17 | } -------------------------------------------------------------------------------- /OlaTests/googletest/googletest/cmake/libgtest.la.in: -------------------------------------------------------------------------------- 1 | # libgtest.la - a libtool library file 2 | # Generated by libtool (GNU libtool) 2.4.6 3 | 4 | # Please DO NOT delete this file! 5 | # It is necessary for linking the library. 6 | 7 | # Names of this library. 8 | library_names='libgtest.so' 9 | 10 | # Is this an already installed library? 11 | installed=yes 12 | 13 | # Should we warn about portability when linking against -modules? 14 | shouldnotlink=no 15 | 16 | # Files to dlopen/dlpreopen 17 | dlopen='' 18 | dlpreopen='' 19 | 20 | # Directory that this library needs to be installed in: 21 | libdir='@CMAKE_INSTALL_FULL_LIBDIR@' 22 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/Target.cpp: -------------------------------------------------------------------------------- 1 | #include "Target.h" 2 | #include "MachineInstruction.h" 3 | #include "Utility/EnumOperators.h" 4 | 5 | namespace ola 6 | { 7 | ENABLE_ENUM_BIT_OPERATORS(InstFlag); 8 | ENABLE_ENUM_BIT_OPERATORS(OperandFlag); 9 | 10 | InstInfo TargetInstInfo::GetInstInfo(MachineInstruction const& inst) const 11 | { 12 | return GetInstInfo(inst.GetOpcode()); 13 | } 14 | 15 | void InstInfo::SetOpFlag(Uint32 idx, OperandFlag flag) 16 | { 17 | operand_flags[idx] |= flag; 18 | } 19 | 20 | void InstInfo::SetInstFlag(InstFlag inst_flag) 21 | { 22 | instruction_flag |= inst_flag; 23 | } 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /OlaTests/googletest/googlemock/include/gmock/internal/custom/README.md: -------------------------------------------------------------------------------- 1 | # Customization Points 2 | 3 | The custom directory is an injection point for custom user configurations. 4 | 5 | ## Header `gmock-port.h` 6 | 7 | The following macros can be defined: 8 | 9 | ### Flag related macros: 10 | 11 | * `GMOCK_DECLARE_bool_(name)` 12 | * `GMOCK_DECLARE_int32_(name)` 13 | * `GMOCK_DECLARE_string_(name)` 14 | * `GMOCK_DEFINE_bool_(name, default_val, doc)` 15 | * `GMOCK_DEFINE_int32_(name, default_val, doc)` 16 | * `GMOCK_DEFINE_string_(name, default_val, doc)` 17 | * `GMOCK_FLAG_GET(flag_name)` 18 | * `GMOCK_FLAG_SET(flag_name, value)` 19 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/DeadCodeEliminationPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/IR/FunctionPass.h" 3 | 4 | namespace ola 5 | { 6 | class DeadCodeEliminationPass : public FunctionPass 7 | { 8 | inline static Char id = 0; 9 | public: 10 | DeadCodeEliminationPass() : FunctionPass(id) {} 11 | virtual Bool RunOn(Function& F, FunctionAnalysisManager& FAM) override; 12 | 13 | static void const* ID() { return &id; } 14 | }; 15 | using DCEPass = DeadCodeEliminationPass; 16 | OLA_REGISTER_PASS(DeadCodeEliminationPass, "Dead Code Elimination Pass"); 17 | 18 | inline FunctionPass* CreateDCEPass() { return new DCEPass(); } 19 | } -------------------------------------------------------------------------------- /OlaCompiler/Frontend/SourceLocation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace ola 6 | { 7 | struct SourceLocation 8 | { 9 | std::string filename = ""; 10 | Uint32 line = 1; 11 | Uint32 column = 1; 12 | 13 | SourceLocation operator+(Int32 i) 14 | { 15 | return SourceLocation 16 | { 17 | .filename = filename, 18 | .line = line, 19 | .column = column + i 20 | }; 21 | } 22 | 23 | void NewChar() 24 | { 25 | ++column; 26 | } 27 | void NewChars(Int32 i) 28 | { 29 | column += i; 30 | } 31 | void NewLine() 32 | { 33 | ++line; 34 | column = 1; 35 | } 36 | }; 37 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Pass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace ola 7 | { 8 | class IRModule; 9 | 10 | using PassID = void const*; 11 | enum class PassKind 12 | { 13 | Function, 14 | Module 15 | }; 16 | 17 | class Pass 18 | { 19 | public: 20 | Pass(Char& pass_id, PassKind kind) : ID(&pass_id), kind(kind) {} 21 | virtual ~Pass() = default; 22 | 23 | PassID GetPassID() const { return ID; } 24 | PassKind GetPassKind() const { return kind; } 25 | std::string_view GetPassName() const; 26 | 27 | private: 28 | PassID ID; 29 | PassKind kind; 30 | }; 31 | 32 | } -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_implicitcasts.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | void TestImplicitCastAssignInit() 4 | { 5 | int intVal = 42; 6 | float floatVal = intVal; 7 | bool boolVal = intVal; 8 | 9 | Assert(floatVal == 42.0); 10 | Assert(boolVal == true); 11 | 12 | floatVal = 3.14; 13 | intVal = floatVal; 14 | boolVal = floatVal; 15 | 16 | Assert(intVal == 3); 17 | Assert(boolVal == true); 18 | 19 | boolVal = true; 20 | intVal = boolVal; 21 | floatVal = boolVal; 22 | 23 | Assert(intVal == 1); 24 | Assert(floatVal == 1.0); 25 | } 26 | 27 | public int main() 28 | { 29 | TestImplicitCastAssignInit(); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/ARM64/ARM64Target.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/Codegen/Target.h" 3 | 4 | namespace ola 5 | { 6 | class ARM64Target : public Target 7 | { 8 | public: 9 | ARM64Target() = default; 10 | 11 | virtual TargetDataLayout const& GetDataLayout() const override; 12 | virtual TargetInstInfo const& GetInstInfo() const override; 13 | virtual TargetRegisterInfo const& GetRegisterInfo() const override; 14 | virtual TargetISelInfo const& GetISelInfo() const override; 15 | virtual TargetFrameInfo const& GetFrameInfo() const override; 16 | 17 | virtual void EmitAssembly(MachineModule& M, std::string_view file) const override; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /OlaPlayground/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(SOURCE 3 | main.cpp 4 | ) 5 | 6 | set(TEST_FILES 7 | Test/test.ola 8 | ) 9 | 10 | add_executable(OlaPlayground ${SOURCE} ${TEST_FILES}) 11 | set_target_properties(OlaPlayground PROPERTIES OUTPUT_NAME OlaPlayground) 12 | 13 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 14 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE} ${TEST_FILES}) 15 | 16 | target_include_directories(OlaPlayground PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) 17 | target_include_directories(OlaPlayground PRIVATE ${CMAKE_SOURCE_DIR}/OlaCompiler/) 18 | 19 | target_link_libraries(OlaPlayground PRIVATE OlaCompiler) 20 | 21 | install(TARGETS OlaPlayground DESTINATION bin) 22 | 23 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/x64/SysV/SysV_x64Target.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/Codegen/Target.h" 3 | 4 | namespace ola 5 | { 6 | class SysV_x64Target : public Target 7 | { 8 | public: 9 | SysV_x64Target() = default; 10 | 11 | virtual TargetDataLayout const& GetDataLayout() const override; 12 | virtual TargetInstInfo const& GetInstInfo() const override; 13 | virtual TargetRegisterInfo const& GetRegisterInfo() const override; 14 | virtual TargetISelInfo const& GetISelInfo() const override; 15 | virtual TargetFrameInfo const& GetFrameInfo() const override; 16 | 17 | virtual void EmitAssembly(MachineModule& M, std::string_view file) const override; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/GlobalDeadCodeEliminationPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/IR/IRModulePass.h" 3 | 4 | namespace ola 5 | { 6 | class GlobalDeadCodeEliminationPass : public IRModulePass 7 | { 8 | inline static Char id = 0; 9 | public: 10 | GlobalDeadCodeEliminationPass() : IRModulePass(id) {} 11 | virtual Bool RunOn(IRModule& M, IRModuleAnalysisManager& FAM) override; 12 | 13 | static void const* ID() { return &id; } 14 | }; 15 | using GlobalDCEPass = GlobalDeadCodeEliminationPass; 16 | OLA_REGISTER_PASS(GlobalDeadCodeEliminationPass, "Global Dead Code Elimination Pass"); 17 | 18 | inline IRModulePass* CreateGlobalDCEPass() { return new GlobalDCEPass(); } 19 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/GlobalValueNumberingPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/IR/FunctionPass.h" 3 | 4 | namespace ola 5 | { 6 | class Instruction; 7 | class BasicBlock; 8 | 9 | class GlobalValueNumberingPass : public FunctionPass 10 | { 11 | inline static Char id = 0; 12 | public: 13 | GlobalValueNumberingPass() : FunctionPass(id) {} 14 | virtual Bool RunOn(Function& F, FunctionAnalysisManager& FAM) override; 15 | 16 | static void const* ID() { return &id; } 17 | }; 18 | using GVNPass = GlobalValueNumberingPass; 19 | OLA_REGISTER_PASS(GlobalValueNumberingPass, "Global Value Numbering Pass"); 20 | 21 | inline FunctionPass* CreateGVNPass() { return new GVNPass(); } 22 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/x64/Microsoft/Microsoft_x64Target.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/Codegen/Target.h" 3 | 4 | namespace ola 5 | { 6 | class Microsoft_x64Target : public Target 7 | { 8 | public: 9 | Microsoft_x64Target() = default; 10 | 11 | virtual TargetDataLayout const& GetDataLayout() const override; 12 | virtual TargetInstInfo const& GetInstInfo() const override; 13 | virtual TargetRegisterInfo const& GetRegisterInfo() const override; 14 | virtual TargetISelInfo const& GetISelInfo() const override; 15 | virtual TargetFrameInfo const& GetFrameInfo() const override; 16 | 17 | virtual void EmitAssembly(MachineModule& M, std::string_view file) const override; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/ConstantPropagationPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Backend/Custom/IR/FunctionPass.h" 4 | #include "Backend/Custom/IR/PassRegistry.h" 5 | 6 | namespace ola 7 | { 8 | class Value; 9 | class ConstantPropagationPass : public FunctionPass 10 | { 11 | inline static Char id = 0; 12 | public: 13 | ConstantPropagationPass() : FunctionPass(id) {} 14 | virtual Bool RunOn(Function& F, FunctionAnalysisManager& FAM) override; 15 | static void const* ID() { return &id; } 16 | }; 17 | OLA_REGISTER_PASS(ConstantPropagationPass, "Constant Propagation Pass"); 18 | inline FunctionPass* CreateConstantPropagationPass() { return new ConstantPropagationPass(); } 19 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/MachineGlobal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "MachineRelocable.h" 4 | #include "Backend/Custom/IR/GlobalValue.h" 5 | 6 | namespace ola 7 | { 8 | 9 | class MachineGlobal 10 | { 11 | public: 12 | MachineGlobal(MachineRelocable* relocable, Linkage linkage, Uint32 alignment = 0) 13 | : relocable(relocable), linkage(linkage), alignment(alignment) {} 14 | 15 | Linkage GetLinkage() const { return linkage; } 16 | Uint32 GetAlignment() const { return alignment; } 17 | MachineRelocable* GetRelocable() const { return relocable.get(); } 18 | 19 | private: 20 | std::unique_ptr relocable; 21 | Linkage linkage; 22 | Uint32 alignment; 23 | }; 24 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/ArithmeticReductionPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/IR/FunctionPass.h" 3 | #include "Backend/Custom/IR/PassRegistry.h" 4 | 5 | namespace ola 6 | { 7 | class Instruction; 8 | class BinaryInst; 9 | 10 | class ArithmeticReductionPass : public FunctionPass 11 | { 12 | inline static Char id = 0; 13 | public: 14 | ArithmeticReductionPass() : FunctionPass(id) {} 15 | virtual Bool RunOn(Function& F, FunctionAnalysisManager& FAM) override; 16 | static void const* ID() { return &id; } 17 | }; 18 | OLA_REGISTER_PASS(ArithmeticReductionPass, "Arithmetic Reduction Pass"); 19 | inline FunctionPass* CreateArithmeticReductionPass() { return new ArithmeticReductionPass(); } 20 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/LLVM/Passes/TestPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "llvm/Pass.h" 3 | #include "llvm/IR/Function.h" 4 | #include "llvm/Support/raw_ostream.h" 5 | #include "llvm/IR/LegacyPassManager.h" 6 | 7 | namespace ola 8 | { 9 | struct TestPass : public llvm::FunctionPass 10 | { 11 | static Char ID; 12 | 13 | TestPass() : llvm::FunctionPass(ID) {} 14 | 15 | Bool runOnFunction(llvm::Function& F) override 16 | { 17 | llvm::errs() << "Test: "; 18 | llvm::errs().write_escaped(F.getName()) << '\n'; 19 | return false; 20 | } 21 | }; 22 | 23 | Char TestPass::ID = 0; 24 | static llvm::RegisterPass X("Test", "Test Pass", false /* Only looks at CFG */, 25 | false /* Analysis Pass */); 26 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/DominatorTreeAnalysisPass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "DominatorTreeAnalysisPass.h" 3 | #include "CFGAnalysisPass.h" 4 | #include "Backend/Custom/IR/GlobalValue.h" 5 | 6 | namespace ola 7 | { 8 | Bool DominatorTreeAnalysisPass::RunOn(Function& F, FunctionAnalysisManager& FAM) 9 | { 10 | CFG const& cfg = FAM.GetResult(F); 11 | DT.Initialize(cfg); 12 | return false; 13 | } 14 | 15 | Bool DominatorTreePrinterPass::RunOn(Function& F, FunctionAnalysisManager& FAM) 16 | { 17 | DominatorTree const& DT = FAM.GetResult(F); 18 | std::string function_name(F.GetName()); 19 | DT.Print(function_name); 20 | return false; 21 | } 22 | 23 | } 24 | 25 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/FunctionPassManagerModuleAdaptor.cpp: -------------------------------------------------------------------------------- 1 | #include "FunctionPassManagerModuleAdaptor.h" 2 | #include "CFGAnalysisPass.h" 3 | #include "DominatorTreeAnalysisPass.h" 4 | #include "DominanceFrontierAnalysisPass.h" 5 | #include "Backend/Custom/IR/IRModule.h" 6 | #include "Backend/Custom/IR/GlobalValue.h" 7 | 8 | namespace ola 9 | { 10 | Bool FunctionPassManagerModuleAdaptor::RunOn(IRModule& M, IRModuleAnalysisManager& MAM) 11 | { 12 | Bool changed = false; 13 | for (auto& G : M.Globals()) 14 | { 15 | if (Function* F = dyn_cast(G); F && !F->IsDeclaration() && !F->IsNoOptimizations()) 16 | { 17 | changed |= FPM.Run(*F, FAM); 18 | } 19 | } 20 | return changed; 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/RegisterAllocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ola 5 | { 6 | struct UsedRegistersInfo 7 | { 8 | std::unordered_set gp_used_registers; 9 | std::unordered_set fp_used_registers; 10 | }; 11 | 12 | class MachineFunction; 13 | class MachineModule; 14 | class RegisterAllocator 15 | { 16 | public: 17 | explicit RegisterAllocator(MachineModule& M) : M(M) {} 18 | virtual ~RegisterAllocator() = default; 19 | 20 | virtual void AssignRegisters(MachineFunction&) = 0; 21 | virtual UsedRegistersInfo const& GetUsedRegistersInfo() const { return used_registers_info; } 22 | 23 | protected: 24 | MachineModule& M; 25 | UsedRegistersInfo used_registers_info; 26 | }; 27 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/ARM64/ARM64TargetFrameInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/Codegen/Target.h" 3 | 4 | namespace ola 5 | { 6 | class ARM64TargetFrameInfo : public TargetFrameInfo 7 | { 8 | public: 9 | virtual void EmitCall(CallInst* CI, MachineContext& ctx) const override; 10 | virtual void EmitPrologue(MachineFunction& MF, MachineContext& ctx) const override; 11 | virtual void EmitProloguePostRA(MachineFunction& MF, MachineContext& ctx) const override; 12 | virtual void EmitEpilogue(MachineFunction& MF, MachineContext& ctx) const override; 13 | virtual void EmitEpiloguePostRA(MachineFunction& MF, MachineContext& ctx) const override; 14 | virtual void EmitReturn(ReturnInst* RI, MachineContext& ctx) const override; 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /OlaCompiler/Frontend/AST/AST.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ASTNode.h" 3 | #include "Decl.h" 4 | 5 | namespace ola 6 | { 7 | class TranslationUnit final : public ASTNode 8 | { 9 | public: 10 | TranslationUnit() = default; 11 | 12 | void AddDecl(UniqueDeclPtr&& declaration) 13 | { 14 | declarations.push_back(std::move(declaration)); 15 | } 16 | UniqueDeclPtrList const& GetDecls() const { return declarations; } 17 | 18 | virtual void Accept(ASTVisitor&, Uint32) const override; 19 | virtual void Accept(ASTVisitor&) const override; 20 | 21 | private: 22 | UniqueDeclPtrList declarations; 23 | }; 24 | struct AST 25 | { 26 | AST() { translation_unit = std::make_unique(); } 27 | std::unique_ptr translation_unit; 28 | }; 29 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/x64/SysV/SysV_x64TargetFrameInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/Codegen/Target.h" 3 | 4 | namespace ola 5 | { 6 | class SysV_x64TargetFrameInfo : public TargetFrameInfo 7 | { 8 | public: 9 | virtual void EmitCall(CallInst* CI, MachineContext& ctx) const override; 10 | virtual void EmitPrologue(MachineFunction& MF, MachineContext& ctx) const override; 11 | virtual void EmitProloguePostRA(MachineFunction& MF, MachineContext& ctx) const override; 12 | virtual void EmitEpilogue(MachineFunction& MF, MachineContext& ctx) const override; 13 | virtual void EmitEpiloguePostRA(MachineFunction& MF, MachineContext& ctx) const override; 14 | virtual void EmitReturn(ReturnInst* RI, MachineContext& ctx) const override; 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Constant.cpp: -------------------------------------------------------------------------------- 1 | #include "Constant.h" 2 | #include "IRType.h" 3 | #include "IRContext.h" 4 | 5 | namespace ola 6 | { 7 | Constant* Constant::GetNullValue(IRType* Ty) 8 | { 9 | IRContext& ctx = Ty->GetContext(); 10 | switch (Ty->GetKind()) 11 | { 12 | case IRTypeKind::Integer: 13 | return cast(Ty)->GetWidth() == 1 ? ctx.GetInt8(0) : ctx.GetInt64(0); 14 | case IRTypeKind::Float: 15 | return ctx.GetZeroFloat(); 16 | case IRTypeKind::Struct: 17 | case IRTypeKind::Array: 18 | { 19 | IRArrayType* array_type = cast(Ty); 20 | return ctx.GetNullArray(array_type); 21 | } 22 | case IRTypeKind::Pointer: 23 | { 24 | } 25 | default: 26 | OLA_ASSERT(false); 27 | } 28 | return nullptr; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /OlaTests/Tests/LLVM/test_string.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | import std.string; 3 | 4 | const char[] globalString = "global"; 5 | 6 | void PassStringLiteral(const char[] literal) 7 | { 8 | Assert(literal[0] == 'L'); 9 | } 10 | void PassStringVariable(const char[] variable) 11 | { 12 | Assert(variable[0] == 'l'); 13 | } 14 | 15 | public int main() 16 | { 17 | Assert(length(globalString) == 7); 18 | 19 | const char[] localString = "local"; 20 | 21 | Assert(length(localString) == 6); 22 | const char[] localAlias = localString; 23 | Assert(localAlias[0] == 'l'); 24 | 25 | PassStringLiteral("Literal"); 26 | PassStringVariable(localString); 27 | 28 | const char[] numString = "12345"; 29 | int number = StringToInt(numString); 30 | Assert(number == 12345); 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/x64/Microsoft/Microsoft_x64TargetFrameInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/Codegen/Target.h" 3 | 4 | namespace ola 5 | { 6 | class Microsoft_x64TargetFrameInfo : public TargetFrameInfo 7 | { 8 | public: 9 | virtual void EmitCall(CallInst* CI, MachineContext& ctx) const override; 10 | virtual void EmitPrologue(MachineFunction& MF, MachineContext& ctx) const override; 11 | virtual void EmitProloguePostRA(MachineFunction& MF, MachineContext& ctx) const override; 12 | virtual void EmitEpilogue(MachineFunction& MF, MachineContext& ctx) const override; 13 | virtual void EmitEpiloguePostRA(MachineFunction& MF, MachineContext& ctx) const override; 14 | virtual void EmitReturn(ReturnInst* RI, MachineContext& ctx) const override; 15 | }; 16 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/IRModulePass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "PassManager.h" 3 | #include "AnalysisManager.h" 4 | 5 | namespace ola 6 | { 7 | class IRModule; 8 | using IRModulePassManager = PassManager; 9 | using IRModuleAnalysisManager = AnalysisManager; 10 | 11 | class IRModulePass : public Pass 12 | { 13 | public: 14 | explicit IRModulePass(Char& pid) : Pass(pid, PassKind::Module) {} 15 | 16 | virtual void Init(IRModule&) {} 17 | virtual void Deinit(IRModule&) {} 18 | virtual Bool RunOn(IRModule&, IRModuleAnalysisManager&) = 0; 19 | }; 20 | 21 | template<> 22 | struct UnitTraits 23 | { 24 | using BasePassT = IRModulePass; 25 | using ParentUnitT = IRModule; 26 | using AnalysisManagerT = IRModuleAnalysisManager; 27 | }; 28 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/LLVM/LLVMIRGenContext.cpp: -------------------------------------------------------------------------------- 1 | #include "LLVMIRGenContext.h" 2 | #include "LLVMIRVisitor.h" 3 | #include "LLVMUtils.h" 4 | #include "Core/Log.h" 5 | #include "llvm/Support/TargetSelect.h" 6 | 7 | namespace ola 8 | { 9 | 10 | LLVMIRGenContext::LLVMIRGenContext(std::string_view file_name) : context(), module(file_name.data(), context) 11 | { 12 | llvm::InitializeAllTargets(); 13 | llvm::InitializeAllTargetMCs(); 14 | llvm::InitializeAllAsmPrinters(); 15 | llvm::InitializeAllAsmParsers(); 16 | } 17 | LLVMIRGenContext::~LLVMIRGenContext() = default; 18 | 19 | void LLVMIRGenContext::Generate(AST const* ast) 20 | { 21 | LLVMIRVisitor llvm_visitor(context, module); 22 | llvm_visitor.VisitAST(ast); 23 | Bool verified = VerifyLLVMModule(module); 24 | } 25 | } 26 | 27 | 28 | -------------------------------------------------------------------------------- /OlaCompiler/Frontend/SourceBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "SourceBuffer.h" 2 | #include 3 | #include 4 | 5 | namespace ola 6 | { 7 | SourceBuffer::SourceBuffer(std::string_view source_file) 8 | : ref_name(source_file) 9 | { 10 | std::string path(source_file); 11 | std::ifstream input_stream(path); 12 | auto good = input_stream.good(); 13 | std::ostringstream buf; 14 | buf << input_stream.rdbuf(); 15 | data_buffer = buf.str(); 16 | data_buffer.push_back('\0'); 17 | } 18 | 19 | SourceBuffer::SourceBuffer(Char const* buffer_start, Uint64 buffer_size, std::string_view refname) 20 | : data_buffer(buffer_start, buffer_size), ref_name(refname) 21 | {} 22 | 23 | void SourceBuffer::Prepend(Char const* str) 24 | { 25 | data_buffer = str + data_buffer; 26 | } 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/FunctionPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "PassManager.h" 3 | #include "AnalysisManager.h" 4 | 5 | namespace ola 6 | { 7 | class Function; 8 | using FunctionPassManager = PassManager; 9 | using FunctionAnalysisManager = AnalysisManager; 10 | 11 | class FunctionPass : public Pass 12 | { 13 | public: 14 | explicit FunctionPass(Char& pid) : Pass(pid, PassKind::Function) {} 15 | 16 | virtual void Init(IRModule&) {} 17 | virtual void Deinit(IRModule&) {} 18 | virtual Bool RunOn(Function&, FunctionAnalysisManager&) = 0; 19 | }; 20 | 21 | class IRModule; 22 | template<> 23 | struct UnitTraits 24 | { 25 | using BasePassT = FunctionPass; 26 | using ParentUnitT = IRModule; 27 | using AnalysisManagerT = FunctionAnalysisManager; 28 | }; 29 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/FunctionInlinerPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/IR/FunctionPass.h" 3 | #include "Backend/Custom/IR/PassRegistry.h" 4 | 5 | namespace ola 6 | { 7 | class Instruction; 8 | class CallInst; 9 | 10 | class FunctionInlinerPass : public FunctionPass 11 | { 12 | inline static Char id = 0; 13 | public: 14 | FunctionInlinerPass() : FunctionPass(id) {} 15 | virtual Bool RunOn(Function& F, FunctionAnalysisManager& FAM) override; 16 | static void const* ID() { return &id; } 17 | 18 | private: 19 | static Bool ShouldInline(CallInst* CI); 20 | static Bool InlineFunction(CallInst* Call); 21 | }; 22 | OLA_REGISTER_PASS(FunctionInlinerPass, "Function Inliner Pass"); 23 | 24 | inline FunctionPass* CreateFunctionInlinerPass() { return new FunctionInlinerPass(); } 25 | } -------------------------------------------------------------------------------- /OlaCompiler/Core/Types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace ola 6 | { 7 | using Uint8 = std::uint8_t; 8 | using Uint16 = std::uint16_t; 9 | using Uint32 = std::uint32_t; 10 | using Uint64 = std::uint64_t; 11 | using Int8 = std::int8_t; 12 | using Int16 = std::int16_t; 13 | using Int32 = std::int32_t; 14 | using Int64 = std::int64_t; 15 | using Bool32 = std::int32_t; 16 | using Bool = bool; 17 | using Char = char; 18 | using Uchar = unsigned char; 19 | using Wchar = wchar_t; 20 | using Short = short; 21 | using Ushort = unsigned short; 22 | using Int = int; 23 | using Uint = unsigned int; 24 | using Float = float; 25 | using Float64 = double; 26 | using Usize = std::size_t; 27 | using Uintptr = std::uintptr_t; 28 | using Intptr = std::intptr_t; 29 | } -------------------------------------------------------------------------------- /OlaPlayground/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Core/Types.h" 2 | #include "Core/Defines.h" 3 | #include "Core/Log.h" 4 | #include "Compiler/CompileRequest.h" 5 | #include "Compiler/Compiler.h" 6 | #include "autogen/OlaConfig.h" 7 | 8 | using namespace ola; 9 | 10 | static constexpr Char const* BACKEND = "--nollvm"; 11 | static constexpr Char const* OPT_LEVEL = "--O3"; 12 | static constexpr Char const* TARGET = "arm64"; 13 | 14 | Int main() 15 | { 16 | OLA_LOG_INIT(); 17 | CompileRequest compile_request{}; 18 | Char const* argv[] = { "-i", "test", "--target", TARGET, OPT_LEVEL, BACKEND, "--emit-asm", "--emit-ir", "--directory", OLA_PLAYGROUND_PATH"Test"}; 19 | if (compile_request.Parse(OLA_ARRAYSIZE(argv), const_cast(argv))) 20 | { 21 | Int compile_result = Compile(compile_request); 22 | return compile_result; 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/IRPrinter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "IRPrinter.h" 3 | #include "IRModule.h" 4 | #include "GlobalValue.h" 5 | 6 | namespace ola 7 | { 8 | void IRPrinter::PrintModule(IRModule const& M) 9 | { 10 | std::string_view module_id = M.GetModuleId(); 11 | EmitLn("Module ID : {}", module_id); 12 | 13 | std::vector const& globals = M.Globals(); 14 | for (GlobalValue const* global : globals) 15 | { 16 | if (GlobalVariable const* GV = dyn_cast(global)) 17 | { 18 | EmitLn(""); 19 | PrintGlobalVariable(GV); 20 | EmitLn(""); 21 | } 22 | else if (Function const* F = dyn_cast(global)) 23 | { 24 | name_manager.ClearLocals(); 25 | EmitLn(""); 26 | PrintFunction(F); 27 | EmitLn(""); 28 | } 29 | } 30 | os << output; 31 | } 32 | 33 | } 34 | 35 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/LoopInvariantCodeMotionPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/IR/FunctionPass.h" 3 | #include "Backend/Custom/IR/PassRegistry.h" 4 | 5 | 6 | namespace ola 7 | { 8 | class Instruction; 9 | class Loop; 10 | 11 | class LoopInvariantCodeMotionPass : public FunctionPass 12 | { 13 | inline static Char id = 0; 14 | public: 15 | LoopInvariantCodeMotionPass() : FunctionPass(id) {} 16 | virtual Bool RunOn(Function& F, FunctionAnalysisManager& FAM) override; 17 | static void const* ID() { return &id; } 18 | 19 | private: 20 | static Bool IsLoopInvariant(Instruction* I, Loop const* L); 21 | }; 22 | OLA_REGISTER_PASS(LoopInvariantCodeMotionPass, "Loop Invariant Code Motion Pass"); 23 | using LICMPass = LoopInvariantCodeMotionPass; 24 | 25 | inline FunctionPass* CreateLICMPass() { return new LICMPass(); } 26 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/CommonSubexpressionEliminationPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/IR/FunctionPass.h" 3 | 4 | namespace ola 5 | { 6 | class Instruction; 7 | class BasicBlock; 8 | 9 | class CommonSubexpressionEliminationPass : public FunctionPass 10 | { 11 | inline static Char id = 0; 12 | public: 13 | CommonSubexpressionEliminationPass() : FunctionPass(id) {} 14 | virtual Bool RunOn(Function& F, FunctionAnalysisManager& FAM) override; 15 | 16 | static void const* ID() { return &id; } 17 | 18 | private: 19 | Bool RunOn(BasicBlock& BB, FunctionAnalysisManager& FAM); 20 | }; 21 | using CSEPass = CommonSubexpressionEliminationPass; 22 | OLA_REGISTER_PASS(CommonSubexpressionEliminationPass, "Common Subexpression Elimination Pass"); 23 | 24 | inline FunctionPass* CreateCSEPass() { return new CSEPass(); } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/SimplifyCFGPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/IR/FunctionPass.h" 3 | #include "Backend/Custom/IR/PassRegistry.h" 4 | 5 | namespace ola 6 | { 7 | class CFG; 8 | class SimplifyCFGPass : public FunctionPass 9 | { 10 | inline static Char id = 0; 11 | public: 12 | SimplifyCFGPass() : FunctionPass(id), cfg(nullptr) {} 13 | virtual Bool RunOn(Function& F, FunctionAnalysisManager& FAM) override; 14 | static void const* ID() { return &id; } 15 | 16 | private: 17 | CFG const* cfg; 18 | 19 | private: 20 | void ResetCFG(Function& F, FunctionAnalysisManager& FAM); 21 | Bool MergeBlocks(Function& F); 22 | Bool RemoveUnreachableBlocks(Function& F); 23 | Bool SimplifyPHIs(Function& F); 24 | }; 25 | OLA_REGISTER_PASS(SimplifyCFGPass, "Simplify CFG Pass"); 26 | 27 | inline FunctionPass* CreateSimplifyCFGPass() { return new SimplifyCFGPass(); } 28 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/AsmPrinter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace ola 8 | { 9 | using SectionId = Uint32; 10 | class MachineModule; 11 | 12 | class AsmPrinter 13 | { 14 | public: 15 | explicit AsmPrinter(std::ostream& os) : os(os) {} 16 | ~AsmPrinter() = default; 17 | virtual void PrintModule(MachineModule const& M) = 0; 18 | 19 | protected: 20 | std::ostream& os; 21 | std::map section_map; 22 | 23 | protected: 24 | virtual std::string GetSectionLabel(SectionId) const = 0; 25 | 26 | template 27 | void Emit(Char const* fmt, Args&&... args) 28 | { 29 | std::string output = std::vformat(fmt, std::make_format_args(args...)); 30 | output += "\n"; 31 | section_map[Section] += output; 32 | } 33 | void Finalize(); 34 | }; 35 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/IRPassManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Compiler/CompilerOptions.h" 3 | 4 | 5 | namespace ola 6 | { 7 | class IRModule; 8 | 9 | struct IRPassOptions 10 | { 11 | Bool cfg_print; 12 | Bool domtree_print; 13 | Bool domfrontier_print; 14 | }; 15 | 16 | class Function; 17 | template 18 | class AnalysisManager; 19 | using FunctionAnalysisManager = AnalysisManager; 20 | 21 | class IRPassManager 22 | { 23 | public: 24 | IRPassManager(IRModule& M, FunctionAnalysisManager& FAM); 25 | void Run(OptimizationLevel level, IRPassOptions const& opts); 26 | 27 | private: 28 | IRModule& M; 29 | FunctionAnalysisManager& FAM; 30 | 31 | private: 32 | void RunEarlyOptimizationPipeline(); 33 | void RunMainOptimizationLoop(Uint32 max_iterations); 34 | void RunLateOptimizationPipeline(); 35 | void RunDebugPasses(IRPassOptions const& opts); 36 | }; 37 | } -------------------------------------------------------------------------------- /OlaCompiler/Compiler/CompilerOptions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Utility/EnumOperators.h" 3 | 4 | namespace ola 5 | { 6 | enum CompilerFlags : Uint32 7 | { 8 | CompilerFlag_None = 0x00, 9 | CompilerFlag_NoLLVM = 0x01, 10 | CompilerFlag_DumpAST = 0x02, 11 | CompilerFlag_DumpCFG = 0x04, 12 | CompilerFlag_DumpCallGraph = 0x08, 13 | CompilerFlag_DumpDomTree = 0x10, 14 | CompilerFlag_PrintDomFrontier = 0x20, 15 | CompilerFlag_EmitASM = 0x40, 16 | CompilerFlag_EmitIR = 0x80, 17 | CompilerFlag_EmitMIR = 0x100, 18 | CompilerFlag_TimeoutDetection = 0x200, 19 | CompilerFlag_NoRun = 0x400, 20 | CompilerFlag_StaticLib = 0x800 21 | }; 22 | ENABLE_ENUM_BIT_OPERATORS(CompilerFlags); 23 | 24 | enum class OptimizationLevel : Uint8 25 | { 26 | Od = 0, 27 | O0 = Od, 28 | O1, 29 | O2, 30 | O3 31 | }; 32 | 33 | enum class TargetArch : Uint8 34 | { 35 | Default, 36 | x64, 37 | ARM64 38 | }; 39 | 40 | } -------------------------------------------------------------------------------- /OlaCompiler/Utility/Attribute.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace ola 3 | { 4 | template 5 | class Attribute 6 | { 7 | public: 8 | 9 | constexpr Attribute() : attribute{ static_cast(0) } {} 10 | constexpr Attribute(Attr attr) : attribute{ attr } {} 11 | 12 | OLA_NODISCARD Bool HasAttr(Attr attr) const 13 | { 14 | return static_cast(attribute) & static_cast(attr); 15 | } 16 | Attribute& AddAttr(Attr attr) 17 | { 18 | attribute = static_cast(static_cast(attribute) | static_cast(attr)); 19 | return *this; 20 | } 21 | Attribute& RemoveAttr(Attr attr) 22 | { 23 | attribute = static_cast(static_cast(attribute) & (~static_cast(attr))); 24 | return *this; 25 | } 26 | OLA_NODISCARD Bool Empty() const 27 | { 28 | return !static_cast(attribute); 29 | } 30 | 31 | private: 32 | Attr attribute; 33 | }; 34 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/LinearScanRegisterAllocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "RegisterAllocator.h" 5 | 6 | namespace ola 7 | { 8 | struct LiveInterval; 9 | class LinearScanRegisterAllocator : public RegisterAllocator 10 | { 11 | public: 12 | explicit LinearScanRegisterAllocator(MachineModule& M) : RegisterAllocator(M), frame_register() {} 13 | 14 | virtual void AssignRegisters(MachineFunction&) override; 15 | 16 | private: 17 | std::vector active_gp; 18 | std::vector active_fp; 19 | std::vector gp_regs; 20 | std::vector fp_regs; 21 | Uint32 frame_register; 22 | std::unordered_map vreg2reg_map; 23 | 24 | private: 25 | void ExpireOldIntervals(LiveInterval& LI); 26 | void SpillAtInterval(LiveInterval& LI); 27 | void Finalize(MachineFunction&, std::vector&); 28 | }; 29 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/LoopAnalysisPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "Backend/Custom/IR/PassRegistry.h" 6 | #include "Backend/Custom/IR/Loop.h" 7 | #include "Backend/Custom/IR/FunctionPass.h" 8 | 9 | namespace ola 10 | { 11 | class DominatorTree; 12 | class LoopAnalysisPass : public FunctionPass 13 | { 14 | public: 15 | inline static Char id = 0; 16 | using Result = LoopInfo; 17 | public: 18 | LoopAnalysisPass() : FunctionPass(id) {} 19 | 20 | virtual Bool RunOn(Function& F, FunctionAnalysisManager& FAM) override; 21 | LoopInfo const& GetResult() const { return LI; } 22 | static void const* ID() { return &id; } 23 | 24 | private: 25 | LoopInfo LI; 26 | 27 | private: 28 | void DiscoverLoop(Loop* L, std::span BackEdges, DominatorTree const& DT, LoopInfo& LI); 29 | }; 30 | OLA_REGISTER_ANALYSIS_PASS(LoopAnalysisPass, "Loop Analysis"); 31 | } -------------------------------------------------------------------------------- /OlaCompiler/Utility/IteratorRange.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ola 5 | { 6 | template 7 | class IteratorRange 8 | { 9 | public: 10 | IteratorRange(Iterator begin_iterator, Iterator end_iterator) 11 | : begin_iterator(std::move(begin_iterator)), 12 | end_iterator(std::move(end_iterator)) {} 13 | 14 | Iterator begin() const { return begin_iterator; } 15 | Iterator end() const { return end_iterator; } 16 | Bool empty() const { return begin_iterator == end_iterator; } 17 | 18 | private: 19 | Iterator begin_iterator, end_iterator; 20 | }; 21 | 22 | template 23 | IteratorRange MakeRange(T x, T y) 24 | { 25 | return IteratorRange(std::move(x), std::move(y)); 26 | } 27 | 28 | template 29 | IteratorRange MakeRange(std::pair p) 30 | { 31 | return IteratorRange(std::move(p.first), std::move(p.second)); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/MachineRelocable.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ola 5 | { 6 | enum class RelocableKind : Uint8 7 | { 8 | Function, 9 | ZeroStorage, 10 | DataStorage, 11 | Block 12 | }; 13 | 14 | class MachineRelocable 15 | { 16 | public: 17 | explicit MachineRelocable(std::string_view symbol) : symbol(symbol) {} 18 | virtual ~MachineRelocable() = default; 19 | 20 | std::string_view GetSymbol() const { return symbol; } 21 | virtual RelocableKind GetRelocableKind() const = 0; 22 | 23 | Bool IsFunction() const { return GetRelocableKind() == RelocableKind::Function; } 24 | Bool IsZeroStorage() const { return GetRelocableKind() == RelocableKind::ZeroStorage; } 25 | Bool IsDataStorage() const { return GetRelocableKind() == RelocableKind::DataStorage; } 26 | Bool IsBlock() const { return GetRelocableKind() == RelocableKind::Block; } 27 | 28 | private: 29 | std::string symbol; 30 | }; 31 | 32 | } -------------------------------------------------------------------------------- /OlaCompiler/Frontend/ImportProcessor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Token.h" 4 | 5 | 6 | namespace ola 7 | { 8 | class FrontendContext; 9 | class Diagnostics; 10 | 11 | class ImportProcessor 12 | { 13 | using TokenPtr = std::vector::iterator; 14 | 15 | public: 16 | ImportProcessor(FrontendContext* context, Diagnostics& diagnostics); 17 | void ProcessImports(std::vector&& tokens); 18 | void RemoveImports(std::vector&& tokens); 19 | std::vector GetProcessedTokens() const 20 | { 21 | return tokens; 22 | } 23 | 24 | private: 25 | FrontendContext* context; 26 | Diagnostics& diagnostics; 27 | std::vector tokens; 28 | TokenPtr current_token; 29 | 30 | private: 31 | Bool Consume(TokenKind k); 32 | Bool Expect(TokenKind k); 33 | 34 | void PreFilterTokens(); 35 | void PostFilterTokens(); 36 | 37 | std::vector GetImportTokens(std::string_view import_path); 38 | 39 | }; 40 | } -------------------------------------------------------------------------------- /OlaCompiler/Frontend/SourceBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ola 5 | { 6 | class SourceBuffer 7 | { 8 | public: 9 | 10 | explicit SourceBuffer(std::string_view source_file); 11 | SourceBuffer(Char const* buffer_start, Uint64 buffer_size, std::string_view refname = ""); 12 | OLA_NONCOPYABLE(SourceBuffer) 13 | OLA_DEFAULT_MOVABLE(SourceBuffer) 14 | ~SourceBuffer() = default; 15 | 16 | void Prepend(Char const* str); 17 | 18 | Char const* GetBufferStart() const { return data_buffer.c_str(); } 19 | Char const* GetBufferEnd() const { return GetBufferStart() + data_buffer.size(); } 20 | Uint64 GetBufferSize() const { return data_buffer.size(); } 21 | std::string_view GetBuffer() const 22 | { 23 | return std::string_view{ data_buffer }; 24 | } 25 | std::string_view GetRefName() const 26 | { 27 | return ref_name; 28 | } 29 | 30 | private: 31 | std::string data_buffer; 32 | std::string ref_name; 33 | }; 34 | } -------------------------------------------------------------------------------- /OlaCompiler/Frontend/TokenKind.cpp: -------------------------------------------------------------------------------- 1 | #include "TokenKind.h" 2 | #include 3 | #include 4 | #include 5 | 6 | namespace ola 7 | { 8 | namespace 9 | { 10 | std::string_view token_names[] = { 11 | #define TOKEN(X) #X, 12 | #include "Tokens.def" 13 | }; 14 | 15 | std::unordered_set const keywords = 16 | { 17 | #define KEYWORD(X) #X, 18 | #include "Tokens.def" 19 | }; 20 | std::unordered_map keywords_map = 21 | { 22 | #define KEYWORD(X) {#X, TokenKind::KW_##X}, 23 | #include "Tokens.def" 24 | }; 25 | } 26 | 27 | std::string_view GetTokenName(TokenKind t) 28 | { 29 | return token_names[(Uint16)t]; 30 | } 31 | 32 | Bool IsKeyword(std::string_view identifer) 33 | { 34 | return keywords.contains(identifer); 35 | } 36 | TokenKind GetKeywordType(std::string_view identifer) 37 | { 38 | return keywords_map[std::string(identifer)]; 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /OlaLib/olaio.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #pragma warning( push ) 6 | #pragma warning( disable : 6031 ) 7 | 8 | extern "C" 9 | { 10 | 11 | void PrintInt(int64_t i) 12 | { 13 | printf("%" PRId64 "\n", i); 14 | } 15 | void PrintFloat(double d) 16 | { 17 | printf("%lf\n", d); 18 | } 19 | void PrintChar(char c) 20 | { 21 | printf("%c\n", c); 22 | } 23 | void PrintString(char* str) 24 | { 25 | printf("%s\n", str); 26 | } 27 | 28 | int64_t ReadInt() 29 | { 30 | int64_t i; 31 | scanf("%" SCNd64, &i); 32 | return i; 33 | } 34 | double ReadFloat() 35 | { 36 | double d; 37 | scanf("%lf", &d); 38 | return d; 39 | } 40 | char ReadChar() 41 | { 42 | char c; 43 | scanf("%c", &c); 44 | return c; 45 | } 46 | void ReadString(char* str, int64_t str_size) 47 | { 48 | unsigned int buf_size = (unsigned int)str_size; 49 | scanf("%s", str); 50 | } 51 | } 52 | #pragma warning( pop ) 53 | 54 | -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_string.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | import std.string; 3 | 4 | const char[] globalString = "global"; 5 | 6 | void PassStringLiteral(const char[] literal) 7 | { 8 | Assert(literal[0] == 'L'); 9 | Assert(literal[1] == 'i'); 10 | Assert(literal[2] == 't'); 11 | } 12 | void PassStringVariable(const char[] variable) 13 | { 14 | Assert(variable[0] == 'l'); 15 | Assert(variable[1] == 'o'); 16 | Assert(variable[2] == 'c'); 17 | Assert(variable[3] == 'a'); 18 | Assert(variable[4] == 'l'); 19 | } 20 | 21 | public int main() 22 | { 23 | Assert(length(globalString) == 7); 24 | 25 | const char[] localString = "local"; 26 | 27 | Assert(length(localString) == 6); 28 | const char[] localAlias = localString; 29 | Assert(localAlias[0] == 'l'); 30 | 31 | PassStringLiteral("Literal"); 32 | PassStringVariable(localString); 33 | 34 | const char[] numString = "12345"; 35 | int number = StringToInt(numString); 36 | Assert(number == 12345); 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_sizeof.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | void TestSizeofTypes() 4 | { 5 | Assert(sizeof(int) == 8); 6 | Assert(sizeof(float) == 8); 7 | Assert(sizeof(bool) == 1); 8 | } 9 | 10 | void TestSizeofExpressions() 11 | { 12 | int intVar = 42; 13 | float floatVar = 3.14; 14 | bool boolVar = true; 15 | 16 | Assert(sizeof(intVar) == 8); 17 | Assert(sizeof(floatVar) == 8); 18 | Assert(sizeof(boolVar) == 1); 19 | } 20 | 21 | // Test sizeof with arrays 22 | void TestSizeofArrays() 23 | { 24 | int[5] intArray; 25 | float[10] floatArray; 26 | bool[3] boolArray; 27 | 28 | Assert(sizeof(intArray) == 40); // 8 bytes per int * 5 ints 29 | Assert(sizeof(floatArray) == 80); // 8 bytes per float * 10 floats 30 | Assert(sizeof(boolArray) == 3); // 1 byte per bool * 3 bools 31 | } 32 | 33 | public int main() 34 | { 35 | TestSizeofTypes(); 36 | TestSizeofExpressions(); 37 | TestSizeofArrays(); 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /OlaTests/Tests/LLVM/test_sizeof.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | void TestSizeofTypes() 4 | { 5 | Assert(sizeof(int) == 8); 6 | Assert(sizeof(float) == 8); 7 | Assert(sizeof(bool) == 1); 8 | } 9 | 10 | void TestSizeofExpressions() 11 | { 12 | int intVar = 42; 13 | float floatVar = 3.14; 14 | bool boolVar = true; 15 | 16 | Assert(sizeof(intVar) == 8); 17 | Assert(sizeof(floatVar) == 8); 18 | Assert(sizeof(boolVar) == 1); 19 | } 20 | 21 | // Test sizeof with arrays 22 | void TestSizeofArrays() 23 | { 24 | int[5] intArray; 25 | float[10] floatArray; 26 | bool[3] boolArray; 27 | 28 | Assert(sizeof(intArray) == 40); // 8 bytes per int * 5 ints 29 | Assert(sizeof(floatArray) == 80); // 8 bytes per float * 10 floats 30 | Assert(sizeof(boolArray) == 3); // 1 byte per bool * 3 bools 31 | } 32 | 33 | public int main() 34 | { 35 | TestSizeofTypes(); 36 | TestSizeofExpressions(); 37 | TestSizeofArrays(); 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /OlaLib/olastring.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | extern "C" 9 | { 10 | bool IsAlnum(char ch) 11 | { 12 | return !!isalnum(ch); 13 | } 14 | bool IsAlpha(char ch) 15 | { 16 | return !!isalpha(ch); 17 | } 18 | bool IsLower(char ch) 19 | { 20 | return !!islower(ch); 21 | } 22 | bool IsUpper(char ch) 23 | { 24 | return !!isupper(ch); 25 | } 26 | bool IsDigit(char ch) 27 | { 28 | return !!isdigit(ch); 29 | } 30 | bool IsSpace(char ch) 31 | { 32 | return !!isspace(ch); 33 | } 34 | char ToLower(char ch) 35 | { 36 | return (char)tolower(ch); 37 | } 38 | char ToUpper(char ch) 39 | { 40 | return (char)toupper(ch); 41 | } 42 | 43 | double StringToFloat(char* str) 44 | { 45 | return atof(str); 46 | } 47 | int64_t StringToInt(char* str) 48 | { 49 | return atoll(str); 50 | } 51 | void StringCopy(char* dst, char* src, int64_t size) 52 | { 53 | memcpy(dst, src, size); 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /OlaLib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(SOURCE 3 | olalib.cpp 4 | ) 5 | 6 | set(HEADERS 7 | olaassert.h 8 | olaio.h 9 | olamath.h 10 | olastring.h 11 | olafile.h 12 | ) 13 | 14 | set(OLA_STD_FILES 15 | std/assert.ola 16 | std/file.ola 17 | std/io.ola 18 | std/math.ola 19 | std/string.ola 20 | ) 21 | 22 | add_library(OlaLib ${SOURCE} ${HEADERS} ${OLA_STD_FILES}) 23 | 24 | source_group(" " FILES ${SOURCE} ${HEADERS}) 25 | source_group("std" FILES ${OLA_STD_FILES}) 26 | 27 | target_include_directories(OlaLib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) 28 | 29 | if(MSVC) 30 | target_link_libraries(OlaLib PRIVATE legacy_stdio_definitions) 31 | endif() 32 | 33 | if(APPLE) 34 | # Don't build universal binary when ASan is enabled 35 | if(NOT ENABLE_ASAN) 36 | set_target_properties(OlaLib PROPERTIES 37 | OSX_ARCHITECTURES "arm64;x86_64" 38 | ) 39 | endif() 40 | endif() 41 | 42 | install(TARGETS OlaLib DESTINATION lib) 43 | install(FILES ${HEADERS} DESTINATION include/OlaLib) 44 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/IRModule.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "IRModule.h" 3 | #include "IRType.h" 4 | #include "GlobalValue.h" 5 | #include "IRPrinter.h" 6 | 7 | namespace ola 8 | { 9 | 10 | IRModule::IRModule(IRContext& context, std::string_view module_id) : context(context), module_id(module_id) 11 | { 12 | } 13 | 14 | IRModule::~IRModule() 15 | { 16 | for (GlobalValue* GV : globals) 17 | { 18 | delete GV; 19 | } 20 | } 21 | 22 | 23 | void IRModule::AddGlobal(GlobalValue* GV) 24 | { 25 | globals.push_back(GV); 26 | if (GV->IsFunction()) 27 | { 28 | function_map[GV->GetName()] = cast(GV); 29 | } 30 | } 31 | 32 | void IRModule::RemoveGlobal(GlobalValue* GV) 33 | { 34 | globals.erase(std::remove(std::begin(globals), std::end(globals), GV), std::end(globals)); 35 | } 36 | 37 | void IRModule::Print(std::string_view filename) const 38 | { 39 | std::ofstream ir_stream(filename.data()); 40 | IRPrinter ir_printer(ir_stream); 41 | ir_printer.PrintModule(*this); 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/LivenessAnalysis.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace ola 7 | { 8 | 9 | struct LiveInterval 10 | { 11 | Uint64 begin, end; 12 | Uint32 vreg; 13 | Uint32 reg; 14 | Int32 stack_offset; 15 | Bool spilled; 16 | Bool is_float; 17 | 18 | void Extend(Uint64 val) 19 | { 20 | if (val < begin) 21 | { 22 | begin = val; 23 | } 24 | else if (val > end) 25 | { 26 | end = val; 27 | } 28 | } 29 | }; 30 | 31 | inline Bool operator<(LiveInterval const& lhs, LiveInterval const& rhs) 32 | { 33 | return lhs.begin < rhs.begin; 34 | } 35 | 36 | 37 | class MachineInstruction; 38 | class MachineBasicBlock; 39 | class MachineFunction; 40 | class MachineModule; 41 | 42 | struct LivenessAnalysisResult 43 | { 44 | std::vector live_intervals; 45 | std::unordered_map instruction_numbering_map; 46 | }; 47 | 48 | LivenessAnalysisResult DoLivenessAnalysis(MachineModule& M, MachineFunction& MF); 49 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/Mem2RegPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Backend/Custom/IR/FunctionPass.h" 5 | 6 | namespace ola 7 | { 8 | class CFG; 9 | class DominatorTree; 10 | class AllocaInst; 11 | class PhiInst; 12 | class Value; 13 | class DominatorTreeNode; 14 | class DominanceFrontier; 15 | 16 | class Mem2RegPass : public FunctionPass 17 | { 18 | inline static Char id = 0; 19 | public: 20 | Mem2RegPass() : FunctionPass(id) {} 21 | virtual Bool RunOn(Function& F, FunctionAnalysisManager& FAM) override; 22 | static void const* ID() { return &id; } 23 | 24 | private: 25 | DominanceFrontier const* DF = nullptr; 26 | 27 | private: 28 | std::vector FindPromotableAllocaInstructions(Function& F); 29 | void InsertPhiFunctions(std::vector const& Allocas, CFG const& cfg); 30 | void RenameVariables(std::vector const& Allocas, CFG const& cfg); 31 | }; 32 | 33 | OLA_REGISTER_PASS(Mem2RegPass, "Memory to Register Pass"); 34 | inline FunctionPass* CreateMem2RegPass() { return new Mem2RegPass(); } 35 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/IRModule.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace ola 8 | { 9 | class IRContext; 10 | class Function; 11 | class GlobalVariable; 12 | class GlobalValue; 13 | 14 | class IRModule 15 | { 16 | public: 17 | IRModule(IRContext& context, std::string_view module_id); 18 | OLA_NONCOPYABLE_NONMOVABLE(IRModule) 19 | ~IRModule(); 20 | 21 | IRContext& GetContext() const { return context; } 22 | std::string_view GetModuleId() const 23 | { 24 | return module_id; 25 | } 26 | 27 | Function* GetFunctionByName(std::string_view name) 28 | { 29 | return function_map[name]; 30 | } 31 | void AddGlobal(GlobalValue* GV); 32 | void RemoveGlobal(GlobalValue* GV); 33 | std::vector const& Globals() const { return globals; } 34 | 35 | void Print(std::string_view filename) const; 36 | 37 | private: 38 | IRContext& context; 39 | std::string module_id; 40 | std::vector globals; 41 | std::unordered_map function_map; 42 | }; 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /OlaTests/Tests/LLVM/test_polymorphism.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | //alternative way instead of interface 4 | //class Abstract 5 | //{ 6 | // public int GetX() const pure virtual; 7 | //}; 8 | 9 | interface Abstract 10 | { 11 | public int GetX() const; 12 | }; 13 | 14 | class Base : Abstract 15 | { 16 | public int GetX() const virtual 17 | { 18 | return x; 19 | } 20 | public int GetSumX() const virtual 21 | { 22 | return GetX(); 23 | } 24 | int x = 1; 25 | }; 26 | 27 | class Derived : Base 28 | { 29 | public int GetX() const virtual 30 | { 31 | return x; 32 | } 33 | public int GetSumX() const virtual 34 | { 35 | return GetX() + super.GetX(); 36 | } 37 | 38 | int x = 10; 39 | }; 40 | 41 | void TestBase(ref Abstract a) 42 | { 43 | Assert(a.GetX() == 1); 44 | } 45 | 46 | void TestDerived(ref Abstract a) 47 | { 48 | Assert(a.GetX() == 10); 49 | } 50 | 51 | void TestDerived2(ref Base b) 52 | { 53 | Assert(b.GetX() == 10); 54 | Assert(b.GetSumX() == 11); 55 | } 56 | 57 | public int main() 58 | { 59 | Base b; 60 | TestBase(b); 61 | Derived d; 62 | TestDerived(d); 63 | TestDerived2(d); 64 | return 0; 65 | } -------------------------------------------------------------------------------- /OlaTests/googletest/docs/index.md: -------------------------------------------------------------------------------- 1 | # GoogleTest User's Guide 2 | 3 | ## Welcome to GoogleTest! 4 | 5 | GoogleTest is Google's C++ testing and mocking framework. This user's guide has 6 | the following contents: 7 | 8 | * [GoogleTest Primer](primer.md) - Teaches you how to write simple tests using 9 | GoogleTest. Read this first if you are new to GoogleTest. 10 | * [GoogleTest Advanced](advanced.md) - Read this when you've finished the 11 | Primer and want to utilize GoogleTest to its full potential. 12 | * [GoogleTest Samples](samples.md) - Describes some GoogleTest samples. 13 | * [GoogleTest FAQ](faq.md) - Have a question? Want some tips? Check here 14 | first. 15 | * [Mocking for Dummies](gmock_for_dummies.md) - Teaches you how to create mock 16 | objects and use them in tests. 17 | * [Mocking Cookbook](gmock_cook_book.md) - Includes tips and approaches to 18 | common mocking use cases. 19 | * [Mocking Cheat Sheet](gmock_cheat_sheet.md) - A handy reference for 20 | matchers, actions, invariants, and more. 21 | * [Mocking FAQ](gmock_faq.md) - Contains answers to some mocking-specific 22 | questions. 23 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Mate Buljan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /OlaTests/googletest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Note: CMake support is community-based. The maintainers do not use CMake 2 | # internally. 3 | 4 | cmake_minimum_required(VERSION 3.13) 5 | 6 | project(googletest-distribution) 7 | set(GOOGLETEST_VERSION 1.15.2) 8 | 9 | if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX) 10 | set(CMAKE_CXX_EXTENSIONS OFF) 11 | endif() 12 | 13 | enable_testing() 14 | 15 | include(CMakeDependentOption) 16 | include(GNUInstallDirs) 17 | 18 | # Note that googlemock target already builds googletest. 19 | option(BUILD_GMOCK "Builds the googlemock subproject" ON) 20 | option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" ON) 21 | option(GTEST_HAS_ABSL "Use Abseil and RE2. Requires Abseil and RE2 to be separately added to the build." OFF) 22 | 23 | if(GTEST_HAS_ABSL) 24 | if(NOT TARGET absl::base) 25 | find_package(absl REQUIRED) 26 | endif() 27 | if(NOT TARGET re2::re2) 28 | find_package(re2 REQUIRED) 29 | endif() 30 | endif() 31 | 32 | if(BUILD_GMOCK) 33 | add_subdirectory( googlemock ) 34 | else() 35 | add_subdirectory( googletest ) 36 | endif() 37 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/DominanceFrontier.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace ola 6 | { 7 | class BasicBlock; 8 | class CFG; 9 | class DominatorTree; 10 | 11 | class DominanceFrontier 12 | { 13 | using DominanceFrontierMap = std::unordered_map>; 14 | public: 15 | DominanceFrontier() : dominance_frontier_map{} {} 16 | void Initialize(DominatorTree const& DT, CFG const& cfg); 17 | std::unordered_set const& GetFrontier(BasicBlock* BB) const 18 | { 19 | OLA_ASSERT(dominance_frontier_map.contains(BB)); 20 | return dominance_frontier_map.find(BB)->second; 21 | } 22 | 23 | using iterator = typename DominanceFrontierMap::iterator; 24 | using const_iterator = typename DominanceFrontierMap::const_iterator; 25 | iterator begin() { return dominance_frontier_map.begin(); } 26 | const_iterator begin() const { return dominance_frontier_map.begin(); } 27 | iterator end() { return dominance_frontier_map.end(); } 28 | const_iterator end() const { return dominance_frontier_map.end(); } 29 | 30 | private: 31 | DominanceFrontierMap dominance_frontier_map; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /OlaCompiler/Compiler/CompileRequest.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "CompilerOptions.h" 5 | 6 | namespace ola 7 | { 8 | class Compiler; 9 | class CompileRequest 10 | { 11 | public: 12 | CompileRequest() = default; 13 | ~CompileRequest() = default; 14 | 15 | Bool Parse(Int argc, Char** argv); 16 | 17 | CompilerFlags GetCompilerFlags() const { return compiler_flags; } 18 | OptimizationLevel GetOptimizationLevel() const { return opt_level; } 19 | TargetArch GetTargetArch() const { return target_arch; } 20 | std::string_view GetInputDirectory() const { return input_directory; } 21 | std::string const& GetOutputFile() const { return output_file; } 22 | std::vector const& GetSourceFiles() const { return input_files; } 23 | std::vector const& GetLibraries() const { return libraries; } 24 | 25 | private: 26 | CompilerFlags compiler_flags = CompilerFlag_None; 27 | OptimizationLevel opt_level = OptimizationLevel::O0; 28 | TargetArch target_arch = TargetArch::Default; 29 | std::string input_directory; 30 | std::vector input_files; 31 | std::string output_file; 32 | std::vector libraries; 33 | }; 34 | } -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_plusminus.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | int GlobalInt = 7; 4 | float GlobalFloat = 14.0; 5 | 6 | public int main() 7 | { 8 | // Local variables 9 | int a = 5; 10 | int b = -a; 11 | Assert(b == -5); 12 | 13 | int c = 10; 14 | int d = +c; 15 | Assert(d == 10); 16 | 17 | float f = 10.0; 18 | float g = +f; 19 | Assert(g == 10.0); 20 | 21 | float e = -f; 22 | Assert(e == -10.0); 23 | 24 | int globalNegate = -GlobalInt; 25 | Assert(globalNegate == -7); 26 | 27 | int globalIdentity = +GlobalInt; 28 | Assert(globalIdentity == 7); // GlobalInt is 7 29 | 30 | float globalFloatNegate = -GlobalFloat; 31 | Assert(globalFloatNegate == -14.0); 32 | 33 | float globalFloatIdentity = +GlobalFloat; 34 | Assert(globalFloatIdentity == 14.0); 35 | 36 | int literalNegate = -8; 37 | Assert(literalNegate == -8); 38 | 39 | int literalIdentity = +8; 40 | Assert(literalIdentity == 8); 41 | 42 | float literalFloatNegate = -3.5; 43 | Assert(literalFloatNegate == -3.5); 44 | 45 | float literalFloatIdentity = +3.5; 46 | Assert(literalFloatIdentity == 3.5); 47 | 48 | return 0; 49 | } -------------------------------------------------------------------------------- /OlaTests/Tests/LLVM/test_plusminus.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | int GlobalInt = 7; 4 | float GlobalFloat = 14.0; 5 | 6 | public int main() 7 | { 8 | // Local variables 9 | int a = 5; 10 | int b = -a; 11 | Assert(b == -5); 12 | 13 | int c = 10; 14 | int d = +c; 15 | Assert(d == 10); 16 | 17 | float f = 10.0; 18 | float g = +f; 19 | Assert(g == 10.0); 20 | 21 | float e = -f; 22 | Assert(e == -10.0); 23 | 24 | int globalNegate = -GlobalInt; 25 | Assert(globalNegate == -7); 26 | 27 | int globalIdentity = +GlobalInt; 28 | Assert(globalIdentity == 7); // GlobalInt is 7 29 | 30 | float globalFloatNegate = -GlobalFloat; 31 | Assert(globalFloatNegate == -14.0); 32 | 33 | float globalFloatIdentity = +GlobalFloat; 34 | Assert(globalFloatIdentity == 14.0); 35 | 36 | int literalNegate = -8; 37 | Assert(literalNegate == -8); 38 | 39 | int literalIdentity = +8; 40 | Assert(literalIdentity == 8); 41 | 42 | float literalFloatNegate = -3.5; 43 | Assert(literalFloatNegate == -3.5); 44 | 45 | float literalFloatIdentity = +3.5; 46 | Assert(literalFloatIdentity == 3.5); 47 | 48 | return 0; 49 | } -------------------------------------------------------------------------------- /OlaTests/googletest/docs/samples.md: -------------------------------------------------------------------------------- 1 | # Googletest Samples 2 | 3 | If you're like us, you'd like to look at 4 | [googletest samples.](https://github.com/google/googletest/blob/main/googletest/samples) 5 | The sample directory has a number of well-commented samples showing how to use a 6 | variety of googletest features. 7 | 8 | * Sample #1 shows the basic steps of using googletest to test C++ functions. 9 | * Sample #2 shows a more complex unit test for a class with multiple member 10 | functions. 11 | * Sample #3 uses a test fixture. 12 | * Sample #4 teaches you how to use googletest and `googletest.h` together to 13 | get the best of both libraries. 14 | * Sample #5 puts shared testing logic in a base test fixture, and reuses it in 15 | derived fixtures. 16 | * Sample #6 demonstrates type-parameterized tests. 17 | * Sample #7 teaches the basics of value-parameterized tests. 18 | * Sample #8 shows using `Combine()` in value-parameterized tests. 19 | * Sample #9 shows use of the listener API to modify Google Test's console 20 | output and the use of its reflection API to inspect test results. 21 | * Sample #10 shows use of the listener API to implement a primitive memory 22 | leak checker. 23 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/x64/SysV/SysV_x64.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/Codegen/x64/x64.h" 3 | 4 | namespace ola 5 | { 6 | // SysV x64 ABI calling convention register classification 7 | inline constexpr Bool x64_SysV_IsCallerSaved(Uint32 r) 8 | { 9 | switch (r) 10 | { 11 | case x64_RAX: 12 | case x64_RCX: 13 | case x64_RDX: 14 | case x64_RDI: 15 | case x64_RSI: 16 | case x64_R8: 17 | case x64_R9: 18 | case x64_R10: 19 | case x64_R11: 20 | case x64_XMM0: 21 | case x64_XMM1: 22 | case x64_XMM2: 23 | case x64_XMM3: 24 | case x64_XMM4: 25 | case x64_XMM5: 26 | case x64_XMM6: 27 | case x64_XMM7: 28 | case x64_XMM8: 29 | case x64_XMM9: 30 | case x64_XMM10: 31 | case x64_XMM11: 32 | case x64_XMM12: 33 | case x64_XMM13: 34 | case x64_XMM14: 35 | case x64_XMM15: 36 | return true; 37 | default: 38 | return false; 39 | } 40 | } 41 | 42 | inline constexpr Bool x64_SysV_IsCalleeSaved(Uint32 r) 43 | { 44 | switch (r) 45 | { 46 | case x64_RBX: 47 | case x64_RBP: 48 | case x64_RSP: 49 | case x64_R12: 50 | case x64_R13: 51 | case x64_R14: 52 | case x64_R15: 53 | return true; 54 | default: 55 | return false; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /OlaTests/Tests/LLVM/test_overloading.ola: -------------------------------------------------------------------------------- 1 | import std.Assert; 2 | 3 | int f(int a) 4 | { 5 | return 1; 6 | } 7 | int f(float b) 8 | { 9 | return -1; 10 | } 11 | int f(float a, float b) 12 | { 13 | return -1; 14 | } 15 | int f(float a, int b) 16 | { 17 | return 0; 18 | } 19 | int f(int a, int b) 20 | { 21 | return 1; 22 | } 23 | 24 | class D 25 | { 26 | public int f(int a) 27 | { 28 | return x; 29 | } 30 | public int f(float b) 31 | { 32 | return z; 33 | } 34 | public int f(float a, float b) 35 | { 36 | return z; 37 | } 38 | public int f(float a, int b) 39 | { 40 | return y; 41 | } 42 | public int f(int a, int b) 43 | { 44 | return x; 45 | } 46 | 47 | public int x = 1; 48 | public int y = 0; 49 | public int z = -1; 50 | }; 51 | 52 | public int main() 53 | { 54 | Assert(f(1) > 0); 55 | Assert(f(1.0) < 0); 56 | Assert(f(1.0,1.0) < 0); 57 | Assert(f(1.0,1) == 0); 58 | Assert(f(1,1) > 0); 59 | 60 | D d; 61 | Assert(d.f(1) > 0); 62 | Assert(d.f(1.0) < 0); 63 | Assert(d.f(1.0,1.0) < 0); 64 | Assert(d.f(1.0,1) == 0); 65 | Assert(d.f(1,1) > 0); 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/x64/Microsoft/Microsoft_x64.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/Codegen/x64/x64.h" 3 | 4 | namespace ola 5 | { 6 | // Microsoft x64 ABI calling convention register classification 7 | inline constexpr Bool x64_IsCallerSaved(Uint32 r) 8 | { 9 | switch (r) 10 | { 11 | case x64_RAX: 12 | case x64_RCX: 13 | case x64_RDX: 14 | case x64_R8: 15 | case x64_R9: 16 | case x64_R10: 17 | case x64_R11: 18 | case x64_XMM0: 19 | case x64_XMM1: 20 | case x64_XMM2: 21 | case x64_XMM3: 22 | case x64_XMM4: 23 | case x64_XMM5: 24 | return true; 25 | default: 26 | return false; 27 | } 28 | } 29 | 30 | inline constexpr Bool x64_IsCalleeSaved(Uint32 r) 31 | { 32 | switch (r) 33 | { 34 | case x64_RBX: 35 | case x64_RBP: 36 | case x64_RSP: 37 | case x64_RDI: 38 | case x64_RSI: 39 | case x64_R12: 40 | case x64_R13: 41 | case x64_R14: 42 | case x64_R15: 43 | case x64_XMM6: 44 | case x64_XMM7: 45 | case x64_XMM8: 46 | case x64_XMM9: 47 | case x64_XMM10: 48 | case x64_XMM11: 49 | case x64_XMM12: 50 | case x64_XMM13: 51 | case x64_XMM14: 52 | case x64_XMM15: 53 | return true; 54 | default: 55 | return false; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/FunctionPassManagerModuleAdaptor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/IR/IRModulePass.h" 3 | #include "Backend/Custom/IR/FunctionPass.h" 4 | #include "Backend/Custom/IR/PassRegistry.h" 5 | 6 | namespace ola 7 | { 8 | template 9 | class PassManager; 10 | using FunctionPassManager = PassManager; 11 | template 12 | class AnalysisManager; 13 | using FunctionAnalysisManager = AnalysisManager; 14 | 15 | class FunctionPassManagerModuleAdaptor : public IRModulePass 16 | { 17 | inline static Char id = 0; 18 | public: 19 | explicit FunctionPassManagerModuleAdaptor(FunctionPassManager& FPM, FunctionAnalysisManager& FAM) : IRModulePass(id), FPM(FPM), FAM(FAM) {} 20 | virtual Bool RunOn(IRModule&, IRModuleAnalysisManager&) override; 21 | 22 | static void const* ID() { return &id; } 23 | 24 | private: 25 | FunctionPassManager& FPM; 26 | FunctionAnalysisManager& FAM; 27 | }; 28 | OLA_REGISTER_PASS(FunctionPassManagerModuleAdaptor, "IRModule To Function Pass Adaptor"); 29 | inline IRModulePass* CreateFunctionPassManagerModuleAdaptor(FunctionPassManager& FPM, FunctionAnalysisManager& FAM) { return new FunctionPassManagerModuleAdaptor(FPM, FAM); } 30 | } -------------------------------------------------------------------------------- /OlaTests/googletest/.github/ISSUE_TEMPLATE/10-feature_request.yml: -------------------------------------------------------------------------------- 1 | name: Feature request 2 | description: Propose a new feature. 3 | title: "[FR]: Please title this feature request" 4 | labels: "enhancement" 5 | body: 6 | - type: textarea 7 | id: version 8 | attributes: 9 | label: Does the feature exist in the most recent commit? 10 | description: We recommend using the latest commit from GitHub in your projects. 11 | validations: 12 | required: true 13 | - type: textarea 14 | id: why 15 | attributes: 16 | label: Why do we need this feature? 17 | description: Ideally, explain why a combination of existing features cannot be used instead. 18 | validations: 19 | required: true 20 | - type: textarea 21 | id: proposal 22 | attributes: 23 | label: Describe the proposal. 24 | description: Include a detailed description of the feature, with usage examples. 25 | validations: 26 | required: true 27 | - type: textarea 28 | id: platform 29 | attributes: 30 | label: Is the feature specific to an operating system, compiler, or build system version? 31 | description: If it is, please specify which versions. 32 | validations: 33 | required: true 34 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/CFGAnalysisPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Backend/Custom/IR/PassRegistry.h" 5 | #include "Backend/Custom/IR/FunctionPass.h" 6 | #include "Backend/Custom/IR/CFG.h" 7 | 8 | namespace ola 9 | { 10 | class BasicBlock; 11 | class CFGAnalysisPass : public FunctionPass 12 | { 13 | inline static Char id = 0; 14 | public: 15 | using Result = CFG; 16 | public: 17 | CFGAnalysisPass() : FunctionPass(id) {} 18 | OLA_MAYBE_UNUSED virtual Bool RunOn(Function& F, FunctionAnalysisManager& FAM) override; 19 | 20 | CFG const& GetResult() const { return cfg; } 21 | static void const* ID() { return &id; } 22 | 23 | private: 24 | CFG cfg; 25 | }; 26 | OLA_REGISTER_ANALYSIS_PASS(CFGAnalysisPass, "CFG Analysis"); 27 | 28 | class CFGPrinterPass : public FunctionPass 29 | { 30 | inline static Char id = 0; 31 | public: 32 | using Result = void; 33 | public: 34 | CFGPrinterPass() : FunctionPass(id) {} 35 | virtual Bool RunOn(Function& F, FunctionAnalysisManager& FAM) override; 36 | 37 | static void const* ID() { return &id; } 38 | }; 39 | OLA_REGISTER_PASS(CFGPrinterPass, "CFG Printer"); 40 | inline FunctionPass* CreateCFGPrinterPass() { return new CFGPrinterPass(); } 41 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/MachineIRPrinter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace ola 7 | { 8 | class Target; 9 | class MachineModule; 10 | class MachineGlobal; 11 | class MachineBasicBlock; 12 | class MachineInstruction; 13 | class MachineOperand; 14 | 15 | class MachineIRPrinter 16 | { 17 | public: 18 | explicit MachineIRPrinter(Target const& target, std::ostream& os) : target(target), os(os) {} 19 | void PrintModule(MachineModule const& M); 20 | 21 | private: 22 | Target const& target; 23 | std::ostream& os; 24 | std::string output; 25 | 26 | private: 27 | template 28 | void EmitLn(Char const* fmt, Args&&... args) 29 | { 30 | output += std::vformat(fmt, std::make_format_args(args...)); 31 | output += "\n"; 32 | } 33 | template 34 | void Emit(Char const* fmt, Args&&... args) 35 | { 36 | output += std::vformat(fmt, std::make_format_args(args...)); 37 | } 38 | 39 | void PrintGlobalVariable(MachineGlobal const&); 40 | void PrintFunction(MachineGlobal const&); 41 | void PrintBlock(MachineBasicBlock const&); 42 | void PrintInstruction(MachineInstruction const&); 43 | void PrintOperand(MachineOperand const&); 44 | }; 45 | 46 | } 47 | 48 | -------------------------------------------------------------------------------- /OlaTests/Tests/LLVM/test_class.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | public class S 4 | { 5 | public void Init(int x, int y) 6 | { 7 | this.x = x; 8 | this.y = y; 9 | } 10 | 11 | public void SetX(int x) {this.x = x;} 12 | public void SetY(int y) {this.y = y;} 13 | 14 | public int GetX() const {return x;} 15 | public int GetY() const {return y;} 16 | 17 | private int x = 0; 18 | private int y = 0; 19 | }; 20 | 21 | void StructByValue(S s) 22 | { 23 | s.SetX(100); 24 | s.SetY(100); 25 | Assert(s.GetX() == 100); 26 | Assert(s.GetY() == 100); 27 | } 28 | 29 | void StructByRef(ref S s) 30 | { 31 | s.SetX(1000); 32 | s.SetY(1000); 33 | Assert(s.GetX() == 1000); 34 | Assert(s.GetY() == 1000); 35 | } 36 | 37 | public int main() 38 | { 39 | S s; s.Init(10, 10); 40 | StructByValue(s); 41 | Assert(s.GetX() == 10); 42 | Assert(s.GetY() == 10); 43 | 44 | S s2 = s; //copy 45 | s.SetX(25); 46 | s.SetY(25); 47 | Assert(s2.GetX() == 10); 48 | Assert(s2.GetY() == 10); 49 | Assert(s.GetX() == 25); 50 | Assert(s.GetY() == 25); 51 | 52 | StructByRef(s); 53 | Assert(s.GetX() == 1000); 54 | Assert(s.GetY() == 1000); 55 | 56 | ref S s3 = s; 57 | Assert(s3.GetX() == 1000); 58 | Assert(s3.GetY() == 1000); 59 | 60 | s3.SetX(0); 61 | Assert(s.GetX() == 0); 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /OlaTests/googletest/fake_fuchsia_sdk.bzl: -------------------------------------------------------------------------------- 1 | """Provides a fake @fuchsia_sdk implementation that's used when the real one isn't available. 2 | 3 | This is needed since bazel queries on targets that depend on //:gtest (eg: 4 | `bazel query "deps(set(//googletest/test:gtest_all_test))"`) will fail if @fuchsia_sdk is not 5 | defined when bazel is evaluating the transitive closure of the query target. 6 | 7 | See https://github.com/google/googletest/issues/4472. 8 | """ 9 | 10 | def _fake_fuchsia_sdk_impl(repo_ctx): 11 | for stub_target in repo_ctx.attr._stub_build_targets: 12 | stub_package = stub_target 13 | stub_target_name = stub_target.split("/")[-1] 14 | repo_ctx.file("%s/BUILD.bazel" % stub_package, """ 15 | filegroup( 16 | name = "%s", 17 | ) 18 | """ % stub_target_name) 19 | 20 | fake_fuchsia_sdk = repository_rule( 21 | doc = "Used to create a fake @fuchsia_sdk repository with stub build targets.", 22 | implementation = _fake_fuchsia_sdk_impl, 23 | attrs = { 24 | "_stub_build_targets": attr.string_list( 25 | doc = "The stub build targets to initialize.", 26 | default = [ 27 | "pkg/fdio", 28 | "pkg/syslog", 29 | "pkg/zx", 30 | ], 31 | ), 32 | }, 33 | ) 34 | -------------------------------------------------------------------------------- /OlaTests/googletest/googletest_deps.bzl: -------------------------------------------------------------------------------- 1 | """Load dependencies needed to use the googletest library as a 3rd-party consumer.""" 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | load("//:fake_fuchsia_sdk.bzl", "fake_fuchsia_sdk") 5 | 6 | def googletest_deps(): 7 | """Loads common dependencies needed to use the googletest library.""" 8 | 9 | if not native.existing_rule("com_googlesource_code_re2"): 10 | http_archive( 11 | name = "com_googlesource_code_re2", 12 | sha256 = "eb2df807c781601c14a260a507a5bb4509be1ee626024cb45acbd57cb9d4032b", 13 | strip_prefix = "re2-2024-07-02", 14 | urls = ["https://github.com/google/re2/releases/download/2024-07-02/re2-2024-07-02.tar.gz"], 15 | ) 16 | 17 | if not native.existing_rule("com_google_absl"): 18 | http_archive( 19 | name = "com_google_absl", 20 | sha256 = "733726b8c3a6d39a4120d7e45ea8b41a434cdacde401cba500f14236c49b39dc", 21 | strip_prefix = "abseil-cpp-20240116.2", 22 | urls = ["https://github.com/abseil/abseil-cpp/releases/download/20240116.2/abseil-cpp-20240116.2.tar.gz"], 23 | ) 24 | 25 | if not native.existing_rule("fuchsia_sdk"): 26 | fake_fuchsia_sdk( 27 | name = "fuchsia_sdk", 28 | ) 29 | -------------------------------------------------------------------------------- /OlaTests/googletest/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "com_google_googletest") 2 | 3 | load("//:googletest_deps.bzl", "googletest_deps") 4 | googletest_deps() 5 | 6 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 7 | 8 | http_archive( 9 | name = "rules_python", 10 | sha256 = "d71d2c67e0bce986e1c5a7731b4693226867c45bfe0b7c5e0067228a536fc580", 11 | strip_prefix = "rules_python-0.29.0", 12 | urls = ["https://github.com/bazelbuild/rules_python/releases/download/0.29.0/rules_python-0.29.0.tar.gz"], 13 | ) 14 | 15 | # https://github.com/bazelbuild/rules_python/releases/tag/0.29.0 16 | load("@rules_python//python:repositories.bzl", "py_repositories") 17 | py_repositories() 18 | 19 | http_archive( 20 | name = "bazel_skylib", 21 | sha256 = "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94", 22 | urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz"], 23 | ) 24 | 25 | http_archive( 26 | name = "platforms", 27 | urls = [ 28 | "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", 29 | "https://github.com/bazelbuild/platforms/releases/download/0.0.10/platforms-0.0.10.tar.gz", 30 | ], 31 | sha256 = "218efe8ee736d26a3572663b374a253c012b716d8af0c07e842e82f238a0a7ee", 32 | ) 33 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/CFGPrinter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "CFGPrinter.h" 3 | #include "CFG.h" 4 | #include "GlobalValue.h" 5 | 6 | namespace ola 7 | { 8 | void CFGPrinter::Print(Function const* F, CFG const& cfg) 9 | { 10 | if (!F->IsDeclaration()) 11 | { 12 | output.clear(); 13 | name_manager.ClearLocals(); 14 | 15 | EmitLn(R"(digraph "CFG for '{}' function" {{ 16 | label="CFG for '{} function"; 17 | )", F->GetName(), F->GetName()); 18 | 19 | PrintFunction(F, cfg); 20 | EmitLn("}}"); 21 | 22 | std::string file_name(F->GetName()); 23 | file_name += "_cfg.dot"; 24 | std::ofstream dot_stream(file_name); 25 | dot_stream << output; 26 | } 27 | } 28 | 29 | void CFGPrinter::PrintFunction(Function const* F, CFG const& cfg) 30 | { 31 | for (BasicBlock const& BB : F->Blocks()) 32 | { 33 | Emit("Node{}[shape = record, color = \"#b70d28ff\", style = filled, fillcolor = \"#b70d2870\", label = \"{{ \n", static_cast(&BB)); 34 | use_line_break = true; 35 | PrintBasicBlock(BB); 36 | use_line_break = false; 37 | EmitLn("}}\"];\n"); 38 | 39 | for (BasicBlock const* succ : cfg.GetSuccessors(&BB)) 40 | { 41 | EmitLn(R"(Node{}->Node{})", static_cast(&BB), static_cast(succ)); 42 | } 43 | EmitLn(""); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_ref.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | void IntByValue(int a) 4 | { 5 | ++a; 6 | } 7 | 8 | void IntByRef(ref int a) 9 | { 10 | ++a; 11 | } 12 | 13 | void TestRefSimple() 14 | { 15 | //passing T variable to ref T function parameter 16 | int a = 9; 17 | IntByRef(a); 18 | Assert(a == 10); 19 | 20 | //assigning T to ref T variable 21 | ref int b = a; 22 | ++b; 23 | Assert(a == 11); 24 | 25 | //assigning ref T to T variable 26 | int c = b; 27 | ++c; 28 | Assert(c == 12); 29 | Assert(a == 11); 30 | 31 | //assigning ref T to ref T variable 32 | ref int d = b; 33 | ++d; 34 | Assert(a == 12); 35 | 36 | //passing ref T variable to ref T function parameter 37 | IntByRef(d); 38 | Assert(a == 13); 39 | 40 | //passing ref T variable to T function parameter 41 | IntByValue(d); 42 | Assert(a == 13); 43 | } 44 | 45 | int g = 9; 46 | ref int ReturnRef() 47 | { 48 | return g; 49 | } 50 | int ReturnValue() 51 | { 52 | return g; 53 | } 54 | 55 | void TestRefReturnSimple() 56 | { 57 | ref int gRef = ReturnRef(); 58 | gRef++; 59 | Assert(g == 10); 60 | 61 | int gRefCopy = ReturnRef(); 62 | gRefCopy++; 63 | Assert(g == 10); 64 | 65 | int gValue = ReturnValue(); 66 | gValue++; 67 | Assert(g == 10); 68 | } 69 | 70 | 71 | public int main() 72 | { 73 | TestRefSimple(); 74 | TestRefReturnSimple(); 75 | return 0; 76 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/DominatorTreeAnalysisPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Backend/Custom/IR/PassRegistry.h" 5 | #include "Backend/Custom/IR/DominatorTree.h" 6 | #include "Backend/Custom/IR/FunctionPass.h" 7 | 8 | namespace ola 9 | { 10 | class DominatorTreeAnalysisPass : public FunctionPass 11 | { 12 | public: 13 | inline static Char id = 0; 14 | using Result = DominatorTree; 15 | public: 16 | DominatorTreeAnalysisPass() : FunctionPass(id) {} 17 | 18 | virtual Bool RunOn(Function& F, FunctionAnalysisManager& FAM) override; 19 | DominatorTree const& GetResult() const { return DT; } 20 | static void const* ID() { return &id; } 21 | 22 | private: 23 | DominatorTree DT; 24 | }; 25 | OLA_REGISTER_ANALYSIS_PASS(DominatorTreeAnalysisPass, "Dominator Tree Analysis"); 26 | 27 | class DominatorTreePrinterPass : public FunctionPass 28 | { 29 | public: 30 | inline static Char id = 0; 31 | using Result = void; 32 | 33 | public: 34 | DominatorTreePrinterPass() : FunctionPass(id) {} 35 | virtual Bool RunOn(Function& F, FunctionAnalysisManager& FAM) override; 36 | 37 | static void const* ID() { return &id; } 38 | }; 39 | OLA_REGISTER_PASS(DominatorTreePrinterPass, "Dominator Tree Printer"); 40 | inline FunctionPass* CreateDominatorTreePrinterPass() { return new DominatorTreePrinterPass(); } 41 | } -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_goto.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | void TestGotoNestedLoops() 4 | { 5 | int targetValue = 5; 6 | int i, j; 7 | 8 | for (i = 0; i < 10; i++) 9 | { 10 | for (j = 0; j < 10; j++) 11 | { 12 | if (i * j == targetValue) 13 | { 14 | goto Found; 15 | } 16 | } 17 | } 18 | 19 | Found: 20 | Assert(i * j == targetValue); 21 | } 22 | 23 | int TestGotoErrorHandling() 24 | { 25 | int result = 0; 26 | 27 | int errorCode = 1; 28 | 29 | if (errorCode != 0) 30 | { 31 | goto HandleError; 32 | } 33 | 34 | result = 42; 35 | return result; 36 | 37 | HandleError: 38 | result = -1; 39 | return result; 40 | } 41 | 42 | int TestGotoEndOfFunction() 43 | { 44 | int result = 0; 45 | 46 | // Some code... 47 | 48 | if (result != 0) 49 | { 50 | goto CleanUpAndReturn; 51 | } 52 | 53 | // More code... 54 | 55 | CleanUpAndReturn: 56 | // Clean up resources and return 57 | return result; 58 | } 59 | 60 | public int main() 61 | { 62 | TestGotoNestedLoops(); 63 | 64 | int errorHandlingResult = TestGotoErrorHandling(); 65 | Assert(errorHandlingResult == -1); 66 | 67 | int endOfFunctionResult = TestGotoEndOfFunction(); 68 | Assert(endOfFunctionResult == 0); 69 | 70 | return 0; 71 | } -------------------------------------------------------------------------------- /OlaTests/Tests/LLVM/test_goto.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | void TestGotoNestedLoops() 4 | { 5 | int targetValue = 5; 6 | int i, j; 7 | 8 | for (i = 0; i < 10; i++) 9 | { 10 | for (j = 0; j < 10; j++) 11 | { 12 | if (i * j == targetValue) 13 | { 14 | goto Found; 15 | } 16 | } 17 | } 18 | 19 | Found: 20 | Assert(i * j == targetValue); 21 | } 22 | 23 | int TestGotoErrorHandling() 24 | { 25 | int result = 0; 26 | 27 | int errorCode = 1; 28 | 29 | if (errorCode != 0) 30 | { 31 | goto HandleError; 32 | } 33 | 34 | result = 42; 35 | return result; 36 | 37 | HandleError: 38 | result = -1; 39 | return result; 40 | } 41 | 42 | int TestGotoEndOfFunction() 43 | { 44 | int result = 0; 45 | 46 | // Some code... 47 | 48 | if (result != 0) 49 | { 50 | goto CleanUpAndReturn; 51 | } 52 | 53 | // More code... 54 | 55 | CleanUpAndReturn: 56 | // Clean up resources and return 57 | return result; 58 | } 59 | 60 | public int main() 61 | { 62 | TestGotoNestedLoops(); 63 | 64 | int errorHandlingResult = TestGotoErrorHandling(); 65 | Assert(errorHandlingResult == -1); 66 | 67 | int endOfFunctionResult = TestGotoEndOfFunction(); 68 | Assert(endOfFunctionResult == 0); 69 | 70 | return 0; 71 | } -------------------------------------------------------------------------------- /OlaLib/std/math.ola: -------------------------------------------------------------------------------- 1 | extern float E; 2 | extern float LOG2E; 3 | extern float LOG10E; 4 | extern float LN2; 5 | extern float LN10; 6 | extern float PI; 7 | extern float PI_2; 8 | extern float PI_4; 9 | extern float SQRT2; 10 | extern float SQRT1_2; 11 | 12 | extern nomangle float Fabs(float x); 13 | extern nomangle float Fmod(float x, float y); 14 | extern nomangle float Ffma(float x, float y, float z); 15 | extern nomangle float Fmax(float x, float y); 16 | extern nomangle float Fmin(float x, float y); 17 | 18 | extern nomangle float Ceil(float x); 19 | extern nomangle float Floor(float x); 20 | extern nomangle float Round(float x); 21 | extern nomangle float Trunc(float x); 22 | 23 | extern nomangle float Sqrt(float x); 24 | extern nomangle float Cbrt(float x); 25 | extern nomangle float Pow(float x, float y); 26 | extern nomangle float Log(float x); 27 | extern nomangle float Log2(float x); 28 | extern nomangle float Log10(float x); 29 | extern nomangle float Exp(float x); 30 | 31 | extern nomangle float Sin(float x); 32 | extern nomangle float Cos(float x); 33 | extern nomangle float Tan(float x); 34 | extern nomangle float Asin(float x); 35 | extern nomangle float Acos(float x); 36 | extern nomangle float Atan(float x); 37 | extern nomangle float Atan2(float y, float x); 38 | 39 | extern nomangle int Abs(int x); 40 | extern nomangle int Min(int x, int y); 41 | extern nomangle int Max(int x, int y); -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/MachineInstruction.cpp: -------------------------------------------------------------------------------- 1 | #include "MachineInstruction.h" 2 | 3 | namespace ola 4 | { 5 | Char const* MachineOpcodeNames[] = 6 | { 7 | "InstUnknown", 8 | // control-flow 9 | "InstCall", 10 | "InstRet", 11 | "InstJump", 12 | "InstJE", 13 | "InstJNE", 14 | 15 | // Memory 16 | "InstMove", 17 | "InstLoad", 18 | "InstStore", 19 | "InstLoadGlobalAddress", 20 | "InstCMoveEQ", 21 | "InstCMoveNE", 22 | 23 | // Stack 24 | "InstPush", 25 | "InstPop", 26 | 27 | // Arithmetic 28 | "InstAdd", 29 | "InstSub", 30 | "InstUMul", 31 | "InstSMul", 32 | "InstUDiv", 33 | "InstURem", 34 | 35 | // Signed Div/Rem 36 | "InstSDiv", 37 | "InstSRem", 38 | 39 | // Bitwise 40 | "InstAnd", 41 | "InstOr", 42 | "InstXor", 43 | "InstShl", 44 | "InstLShr", 45 | "InstAShr", 46 | 47 | // Unary 48 | "InstNeg", 49 | "InstNot", 50 | 51 | // FP 52 | "InstFAdd", 53 | "InstFSub", 54 | "InstFMul", 55 | "InstFDiv", 56 | "InstFNeg", 57 | 58 | // Comparison 59 | "InstICmp", 60 | "InstFCmp", 61 | "InstTest", 62 | 63 | // Conversion 64 | "InstZExt", 65 | "InstF2S", 66 | "InstS2F", 67 | }; 68 | static_assert(std::size(MachineOpcodeNames) == InstOpcodeCount); 69 | 70 | Char const* MachineInstruction::GetOpcodeName() const 71 | { 72 | return opcode < ISASpecificBegin ? MachineOpcodeNames[opcode] : ""; 73 | } 74 | } 75 | 76 | -------------------------------------------------------------------------------- /OlaTests/googletest/docs/_data/navigation.yml: -------------------------------------------------------------------------------- 1 | nav: 2 | - section: "Get Started" 3 | items: 4 | - title: "Supported Platforms" 5 | url: "/platforms.html" 6 | - title: "Quickstart: Bazel" 7 | url: "/quickstart-bazel.html" 8 | - title: "Quickstart: CMake" 9 | url: "/quickstart-cmake.html" 10 | - section: "Guides" 11 | items: 12 | - title: "GoogleTest Primer" 13 | url: "/primer.html" 14 | - title: "Advanced Topics" 15 | url: "/advanced.html" 16 | - title: "Mocking for Dummies" 17 | url: "/gmock_for_dummies.html" 18 | - title: "Mocking Cookbook" 19 | url: "/gmock_cook_book.html" 20 | - title: "Mocking Cheat Sheet" 21 | url: "/gmock_cheat_sheet.html" 22 | - section: "References" 23 | items: 24 | - title: "Testing Reference" 25 | url: "/reference/testing.html" 26 | - title: "Mocking Reference" 27 | url: "/reference/mocking.html" 28 | - title: "Assertions" 29 | url: "/reference/assertions.html" 30 | - title: "Matchers" 31 | url: "/reference/matchers.html" 32 | - title: "Actions" 33 | url: "/reference/actions.html" 34 | - title: "Testing FAQ" 35 | url: "/faq.html" 36 | - title: "Mocking FAQ" 37 | url: "/gmock_faq.html" 38 | - title: "Code Samples" 39 | url: "/samples.html" 40 | - title: "Using pkg-config" 41 | url: "/pkgconfig.html" 42 | - title: "Community Documentation" 43 | url: "/community_created_documentation.html" 44 | -------------------------------------------------------------------------------- /OlaCompiler/Utility/CLIParser.cpp: -------------------------------------------------------------------------------- 1 | #include "CLIParser.h" 2 | 3 | namespace ola 4 | { 5 | CLIParseResult::CLIParseResult(std::vector const& args, std::unordered_map const& prefix_index_map) 6 | { 7 | for (auto const& [prefix, index] : prefix_index_map) 8 | { 9 | cli_arg_map[prefix] = args[index]; 10 | } 11 | } 12 | 13 | CLIParseResult CLIParser::Parse(Int argc, Char** argv) 14 | { 15 | std::unordered_map cli_arg_map; 16 | for (Int i = 0; i < argc; ++i) 17 | { 18 | std::string arg = argv[i]; 19 | if (arg.empty()) 20 | { 21 | continue; 22 | } 23 | 24 | if (prefix_arg_index_map.find(arg) != prefix_arg_index_map.end()) 25 | { 26 | Uint32 arg_index = prefix_arg_index_map[arg]; 27 | CLIArg& cli_arg = args[arg_index]; 28 | cli_arg.SetIsPresent(); 29 | if (cli_arg.has_value) 30 | { 31 | while (i + 1 < argc && !prefix_arg_index_map.contains(argv[i + 1])) 32 | { 33 | cli_arg.AddValue(argv[++i]); 34 | } 35 | if (cli_arg.values.empty()) 36 | { 37 | OLA_ASSERT_MSG(false, "Missing value for cmdline argument"); 38 | } 39 | } 40 | } 41 | } 42 | 43 | for (CLIArg const& arg : args) 44 | { 45 | for (std::string const& prefix : arg.prefixes) 46 | { 47 | cli_arg_map[prefix] = arg; 48 | } 49 | } 50 | 51 | return CLIParseResult(args, prefix_arg_index_map); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /OlaTests/Tests/LLVM/test_functioncalls.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | 4 | int Add(int a, int b) 5 | { 6 | return a + b; 7 | } 8 | 9 | float Multiply(float x, float y) 10 | { 11 | return x * y; 12 | } 13 | 14 | bool LogicalAnd(bool p, bool q) 15 | { 16 | return p && q; 17 | } 18 | 19 | float MixParams(int a, float b, bool c, int[] arr, int size) 20 | { 21 | int arrSum = 0; 22 | for (int i = 0; i < size; i++) arrSum += arr[i]; 23 | return a + b + (c ? 1.0 : 0.0) + arrSum; 24 | } 25 | 26 | void ConcatArrays(int[] arr1, int size1, int[] arr2, int size2, int[] result) 27 | { 28 | for (int i = 0; i < size1; i++) 29 | { 30 | result[i] = arr1[i]; 31 | } 32 | 33 | for (int j = 0; j < size2; j++) 34 | { 35 | result[size1 + j] = arr2[j]; 36 | } 37 | } 38 | 39 | public int main() 40 | { 41 | Assert(Add(3, 5) == 8); 42 | 43 | Assert(Multiply(2.5, 3.0) == 7.5); 44 | 45 | Assert(LogicalAnd(true, false) == false); 46 | 47 | int[2] mixArr = {10, 20}; 48 | float mixResult = MixParams(1, 2.5, true, mixArr, length(mixArr)); 49 | Assert(mixResult == 34.5); 50 | 51 | int[2] arr1 = {1,2}; 52 | int[2] arr2 = {3,4}; 53 | int[length(arr1) + length(arr2)] arr3; 54 | ConcatArrays(arr1, length(arr1), arr2, length(arr2), arr3); 55 | Assert(arr3[0] == 1); 56 | Assert(arr3[1] == 2); 57 | Assert(arr3[2] == 3); 58 | Assert(arr3[3] == 4); 59 | return 0; 60 | } -------------------------------------------------------------------------------- /OlaCompiler/Frontend/FrontendContext.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ola 5 | { 6 | class Type; 7 | class QualType; 8 | class ArrayType; 9 | class ClassType; 10 | class RefType; 11 | class FuncType; 12 | class VoidType; 13 | class BoolType; 14 | class CharType; 15 | class IntType; 16 | class FloatType; 17 | class ClassDecl; 18 | 19 | class FrontendContext 20 | { 21 | public: 22 | 23 | FrontendContext(); 24 | OLA_NONCOPYABLE_NONMOVABLE(FrontendContext) 25 | ~FrontendContext(); 26 | 27 | VoidType* GetVoidType() const { return void_type; } 28 | BoolType* GetBoolType() const { return bool_type; } 29 | CharType* GetCharType() const { return char_type; } 30 | IntType* GetIntType() const { return int_type; } 31 | FloatType* GetFloatType() const { return float_type; } 32 | 33 | ArrayType* GetArrayType(QualType const& type, Uint32 array_size); 34 | RefType* GetRefType(QualType const& type); 35 | FuncType* GetFuncType(QualType const& return_type, std::vector const& param_types); 36 | ClassType* GetClassType(ClassDecl const* class_decl); 37 | 38 | private: 39 | VoidType* void_type; 40 | BoolType* bool_type; 41 | CharType* char_type; 42 | IntType* int_type; 43 | FloatType* float_type; 44 | 45 | std::vector array_types; 46 | std::vector class_types; 47 | std::vector ref_types; 48 | std::vector function_types; 49 | }; 50 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/DominanceFrontierAnalysisPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/IR/PassRegistry.h" 3 | #include "Backend/Custom/IR/DominanceFrontier.h" 4 | #include "Backend/Custom/IR/FunctionPass.h" 5 | 6 | namespace ola 7 | { 8 | class DominanceFrontierAnalysisPass : public FunctionPass 9 | { 10 | public: 11 | inline static Char id = 0; 12 | using Result = DominanceFrontier; 13 | public: 14 | DominanceFrontierAnalysisPass() : FunctionPass(id) {} 15 | 16 | virtual Bool RunOn(Function& F, FunctionAnalysisManager& FAM) override; 17 | DominanceFrontier const& GetResult() const { return DF; } 18 | static void const* ID() { return &id; } 19 | 20 | private: 21 | DominanceFrontier DF; 22 | }; 23 | OLA_REGISTER_ANALYSIS_PASS(DominanceFrontierAnalysisPass, "Dominance Frontier Analysis"); 24 | 25 | class DominanceFrontierPrinterPass : public FunctionPass 26 | { 27 | public: 28 | inline static Char id = 0; 29 | using Result = void; 30 | 31 | public: 32 | DominanceFrontierPrinterPass() : FunctionPass(id) {} 33 | virtual Bool RunOn(Function& F, FunctionAnalysisManager& FAM) override; 34 | 35 | static void const* ID() { return &id; } 36 | 37 | private: 38 | static Uint GetMaxBasicBlockNameLength(DominanceFrontier const& DF); 39 | }; 40 | OLA_REGISTER_PASS(DominanceFrontierPrinterPass, "Dominance Frontier Printer"); 41 | inline FunctionPass* CreateDominanceFrontierPrinterPass() { return new DominanceFrontierPrinterPass(); } 42 | } -------------------------------------------------------------------------------- /OlaCompiler/Core/Log.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace ola 7 | { 8 | enum class LogLevel : Uint8 9 | { 10 | Debug, 11 | Info, 12 | Warning, 13 | Error 14 | }; 15 | std::string GetLogPrefix(LogLevel level); 16 | std::string GetCurrentTimeString(); 17 | 18 | void LogInit(); 19 | void LogDestroy(); 20 | void WriteToLogFile(std::string const&); 21 | 22 | template 23 | void Log(LogLevel level, char const* fmt, Args&&... args) 24 | { 25 | std::string log_entry = std::vformat(fmt, std::make_format_args(args...)); 26 | std::string full_log_entry = std::format("{} {} {}", GetCurrentTimeString(), GetLogPrefix(level), log_entry); 27 | printf("%s\n", full_log_entry.c_str()); 28 | WriteToLogFile(full_log_entry); 29 | } 30 | struct LogInitScope 31 | { 32 | LogInitScope() { LogInit(); } 33 | ~LogInitScope() { LogDestroy(); } 34 | }; 35 | } 36 | #define OLA_LOG_INIT() ola::LogInitScope __log_init_scope{}; 37 | 38 | #if defined(DEBUG) 39 | #define OLA_DEBUG(fmt, ...) ola::Log(ola::LogLevel::Debug, fmt, ##__VA_ARGS__) 40 | #define OLA_INFO(fmt, ...) ola::Log(ola::LogLevel::Info, fmt, ##__VA_ARGS__) 41 | #define OLA_WARN(fmt, ...) ola::Log(ola::LogLevel::Warning, fmt, ##__VA_ARGS__) 42 | #else 43 | #define OLA_DEBUG(fmt, ...) ((void)0) 44 | #define OLA_INFO(fmt, ...) ((void)0) 45 | #define OLA_WARN(fmt, ...) 46 | #endif 47 | #define OLA_ERROR(fmt, ...) ola::Log(ola::LogLevel::Error, fmt, __VA_ARGS__) -------------------------------------------------------------------------------- /OlaTests/googletest/googletest/include/gtest/internal/custom/README.md: -------------------------------------------------------------------------------- 1 | # Customization Points 2 | 3 | The custom directory is an injection point for custom user configurations. 4 | 5 | ## Header `gtest.h` 6 | 7 | ### The following macros can be defined: 8 | 9 | * `GTEST_OS_STACK_TRACE_GETTER_` - The name of an implementation of 10 | `OsStackTraceGetterInterface`. 11 | * `GTEST_CUSTOM_TEMPDIR_FUNCTION_` - An override for `testing::TempDir()`. See 12 | `testing::TempDir` for semantics and signature. 13 | 14 | ## Header `gtest-port.h` 15 | 16 | The following macros can be defined: 17 | 18 | ### Logging: 19 | 20 | * `GTEST_LOG_(severity)` 21 | * `GTEST_CHECK_(condition)` 22 | * Functions `LogToStderr()` and `FlushInfoLog()` have to be provided too. 23 | 24 | ### Threading: 25 | 26 | * `GTEST_HAS_NOTIFICATION_` - Enabled if Notification is already provided. 27 | * `GTEST_HAS_MUTEX_AND_THREAD_LOCAL_` - Enabled if `Mutex` and `ThreadLocal` 28 | are already provided. Must also provide `GTEST_DECLARE_STATIC_MUTEX_(mutex)` 29 | and `GTEST_DEFINE_STATIC_MUTEX_(mutex)` 30 | * `GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)` 31 | * `GTEST_LOCK_EXCLUDED_(locks)` 32 | 33 | ### Underlying library support features 34 | 35 | * `GTEST_HAS_CXXABI_H_` 36 | 37 | ### Exporting API symbols: 38 | 39 | * `GTEST_API_` - Specifier for exported symbols. 40 | 41 | ## Header `gtest-printers.h` 42 | 43 | * See documentation at `gtest/gtest-printers.h` for details on how to define a 44 | custom printer. 45 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Value.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace ola 5 | { 6 | 7 | class IRContext; 8 | class IRType; 9 | class BasicBlock; 10 | 11 | enum class ValueKind : Uint8 12 | { 13 | Instruction, 14 | Constant, 15 | Argument, 16 | BasicBlock 17 | }; 18 | 19 | class Value 20 | { 21 | public: 22 | OLA_NONCOPYABLE(Value) 23 | virtual ~Value() = default; 24 | 25 | OLA_NODISCARD ValueKind GetKind() const { return kind; } 26 | OLA_NODISCARD IRType* GetType() const { return type; } 27 | OLA_NODISCARD IRContext& GetContext() const; 28 | 29 | Bool HasName() const { return !name.empty(); } 30 | std::string_view GetName() const { return name; } 31 | void SetName(std::string_view _name) 32 | { 33 | name = _name; 34 | } 35 | 36 | OLA_NODISCARD Bool IsConstant() const 37 | { 38 | return kind == ValueKind::Constant; 39 | } 40 | OLA_NODISCARD Bool IsInstruction() const 41 | { 42 | return kind == ValueKind::Instruction; 43 | } 44 | OLA_NODISCARD Bool IsArgument() const 45 | { 46 | return kind == ValueKind::Argument; 47 | } 48 | OLA_NODISCARD Bool IsBasicBlock() const 49 | { 50 | return kind == ValueKind::BasicBlock; 51 | } 52 | 53 | OLA_NODISCARD virtual Bool IsUndefined() const 54 | { 55 | return false; 56 | } 57 | 58 | protected: 59 | Value(ValueKind kind, IRType* type = nullptr) : kind(kind), type(type) 60 | {} 61 | 62 | private: 63 | ValueKind kind; 64 | IRType* type; 65 | std::string name; 66 | }; 67 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/DominanceFrontier.cpp: -------------------------------------------------------------------------------- 1 | #include "DominanceFrontier.h" 2 | #include "DominatorTree.h" 3 | #include "CFG.h" 4 | 5 | namespace ola 6 | { 7 | //Efficiently Computing Static Single Assignment Form and the Control Dependence Graph, Cytron et al 8 | //(Section 4.2) Dominance Frontiers 9 | //for each X in a bottom - up traversal of the dominator tree do 10 | // 11 | // DF(X) <- null 12 | // for each Y in Succ(X) do 13 | // if (idom(Y) != X) then DF(X) <- DF(X) U {Y} 14 | // end 15 | // for each Z in {idom(Z) = X} do 16 | // for each Y in DF(Z) do 17 | // if (idom(Y) != X) then DF(X) <- DF(X) U {Y} 18 | // end 19 | void DominanceFrontier::Initialize(DominatorTree const& DT, CFG const& cfg) 20 | { 21 | dominance_frontier_map.clear(); 22 | dominance_frontier_map[cfg.GetEntryBlock()] = {}; 23 | DT.VisitPostOrder([this, &DT, &cfg](DominatorTreeNode const* node) -> Bool 24 | { 25 | BasicBlock* X = node->GetBasicBlock(); 26 | for (BasicBlock* Y : cfg.GetSuccessors(X)) 27 | { 28 | if (!DT.StrictlyDominates(X, Y)) 29 | { 30 | dominance_frontier_map[X].insert(Y); 31 | } 32 | } 33 | 34 | for (DominatorTreeNode const* child : *node) 35 | { 36 | BasicBlock* Z = child->GetBasicBlock(); 37 | for (BasicBlock* Y : dominance_frontier_map[Z]) 38 | { 39 | if (!DT.StrictlyDominates(X, Y)) 40 | { 41 | dominance_frontier_map[X].insert(Y); 42 | } 43 | } 44 | } 45 | return true; 46 | }); 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/GlobalValue.cpp: -------------------------------------------------------------------------------- 1 | #include "GlobalValue.h" 2 | 3 | namespace ola 4 | { 5 | 6 | Function::Function(std::string_view name, IRFuncType* type, Linkage linkage) : GlobalValue(name, type, linkage) 7 | { 8 | IRFuncType* function_type = GetFunctionType(); 9 | arguments.resize(function_type->GetParamCount()); 10 | for (Uint32 i = 0; i < arguments.size(); ++i) 11 | { 12 | arguments[i] = new Argument(function_type->GetParamType(i), i); 13 | } 14 | } 15 | 16 | Function::~Function() 17 | { 18 | arguments.clear(); 19 | } 20 | 21 | Uint64 Function::GetInstructionCount() const 22 | { 23 | Uint64 instruction_count = 0; 24 | for (auto const& bb : block_list) instruction_count += bb.Instructions().Size(); 25 | return instruction_count; 26 | } 27 | 28 | IRFuncType* Function::GetFunctionType() const 29 | { 30 | return cast(GetValueType()); 31 | } 32 | 33 | void Function::Insert(BasicBlock* BB) 34 | { 35 | block_list.PushBack(BB); 36 | } 37 | 38 | void Function::InsertBefore(BasicBlock* BB, BasicBlock* before) 39 | { 40 | block_list.Insert(before->GetIterator(), BB); 41 | } 42 | 43 | Uint64 Function::Size() const 44 | { 45 | return block_list.Size(); 46 | } 47 | 48 | Bool Function::HasCallInstruction() const 49 | { 50 | for (BasicBlock const& bb : block_list) 51 | { 52 | for (Instruction const& I : bb) 53 | { 54 | if (I.GetOpcode() == Opcode::Call) 55 | { 56 | return true; 57 | } 58 | } 59 | } 60 | return false; 61 | } 62 | 63 | } 64 | 65 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/DeadCodeEliminationPass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "DeadCodeEliminationPass.h" 3 | #include "Backend/Custom/IR/GlobalValue.h" 4 | 5 | namespace ola 6 | { 7 | Bool DeadCodeEliminationPass::RunOn(Function& F, FunctionAnalysisManager& FAM) 8 | { 9 | std::unordered_set AliveInsts; 10 | for (BasicBlock& BB : F) 11 | { 12 | for (Instruction& I : BB) 13 | { 14 | if (I.IsTerminator() || isa(&I) || isa(&I)) 15 | { 16 | AliveInsts.insert(&I); 17 | } 18 | } 19 | } 20 | 21 | Bool Changed = false; 22 | Bool KeepGoing = true; 23 | while (KeepGoing) 24 | { 25 | KeepGoing = false; 26 | for (BasicBlock& BB : F) 27 | { 28 | for (Instruction& I : BB) 29 | { 30 | if (AliveInsts.contains(&I)) 31 | { 32 | for (Use& U : I.Operands()) 33 | { 34 | if (Instruction* OpInst = dyn_cast(U.GetValue()); OpInst && AliveInsts.insert(OpInst).second) 35 | KeepGoing = true; 36 | } 37 | } 38 | } 39 | } 40 | } 41 | 42 | std::vector DeadInsts; 43 | for (BasicBlock& BB : F) 44 | { 45 | for (Instruction& I : BB) 46 | { 47 | if (!AliveInsts.contains(&I)) 48 | { 49 | DeadInsts.push_back(&I); 50 | Changed = true; 51 | } 52 | } 53 | } 54 | for (auto it = DeadInsts.rbegin(); it != DeadInsts.rend(); ++it) 55 | { 56 | Instruction* I = *it; 57 | I->EraseFromParent(); 58 | } 59 | return Changed; 60 | } 61 | } 62 | 63 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/MachineBasicBlock.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "MachineInstruction.h" 5 | #include "MachineGlobal.h" 6 | 7 | namespace ola 8 | { 9 | class MachineFunction; 10 | class MachineBasicBlock : public MachineRelocable 11 | { 12 | public: 13 | MachineBasicBlock(MachineFunction* function, std::string_view label) : MachineRelocable(label), function(function) 14 | {} 15 | 16 | MachineFunction* GetFunction() const 17 | { 18 | return function; 19 | } 20 | std::list& Instructions() 21 | { 22 | return instructions; 23 | } 24 | std::list const& Instructions() const 25 | { 26 | return instructions; 27 | } 28 | 29 | void AddSuccessor(MachineBasicBlock* MBB) 30 | { 31 | successors.insert(MBB); 32 | MBB->predecessors.insert(this); 33 | } 34 | void AddPredecessor(MachineBasicBlock* MBB) 35 | { 36 | predecessors.insert(MBB); 37 | MBB->successors.insert(this); 38 | } 39 | std::unordered_set const& Predecessors() const { return predecessors; } 40 | std::unordered_set const& Successors() const { return successors; } 41 | 42 | virtual RelocableKind GetRelocableKind() const override 43 | { 44 | return RelocableKind::Block; 45 | } 46 | 47 | private: 48 | MachineFunction* function; 49 | std::list instructions; 50 | std::unordered_set successors; 51 | std::unordered_set predecessors; 52 | }; 53 | } -------------------------------------------------------------------------------- /OlaCompiler/Frontend/AST/ASTFwd.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace ola 4 | { 5 | class ASTNode; 6 | class TranslationUnit; 7 | 8 | class Decl; 9 | class FunctionDecl; 10 | class MethodDecl; 11 | class ConstructorDecl; 12 | class VarDecl; 13 | class ParamVarDecl; 14 | class FieldDecl; 15 | class TagDecl; 16 | class EnumDecl; 17 | class EnumMemberDecl; 18 | class AliasDecl; 19 | class ClassDecl; 20 | 21 | class Stmt; 22 | class CompoundStmt; 23 | class ExprStmt; 24 | class DeclStmt; 25 | class NullStmt; 26 | class ReturnStmt; 27 | class IfStmt; 28 | class BreakStmt; 29 | class ContinueStmt; 30 | class ForStmt; 31 | class WhileStmt; 32 | class DoWhileStmt; 33 | class CaseStmt; 34 | class SwitchStmt; 35 | class GotoStmt; 36 | class LabelStmt; 37 | 38 | class Expr; 39 | class UnaryExpr; 40 | class BinaryExpr; 41 | class TernaryExpr; 42 | class IdentifierExpr; 43 | class DeclRefExpr; 44 | class IntLiteral; 45 | class CharLiteral; 46 | class StringLiteral; 47 | class BoolLiteral; 48 | class FloatLiteral; 49 | class ImplicitCastExpr; 50 | class CallExpr; 51 | class InitializerListExpr; 52 | class ArrayAccessExpr; 53 | class MemberExpr; 54 | class MethodCallExpr; 55 | class ThisExpr; 56 | class SuperExpr; 57 | class ConstructorExpr; 58 | 59 | struct AST; 60 | } 61 | 62 | /* 63 | //todo list for adding new ast node 64 | 0. Add forward declaration, type alias, add to visitor interface and implement it in all visitors (debug,llvm) 65 | 1. add a class and member definitions 66 | 2. Add in Parser::Parse* 67 | 3. Add in Sema::ActOn* 68 | */ -------------------------------------------------------------------------------- /OlaTests/googletest/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2008, Google Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /OlaTests/Tests/LLVM/test_enum.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | enum Color 4 | { 5 | Red, 6 | Green, 7 | Blue 8 | }; 9 | 10 | Color globalColor = Red; 11 | 12 | public int TestEnumValues() 13 | { 14 | Color color = Blue; 15 | Assert(color == Blue); 16 | return 0; 17 | } 18 | 19 | enum Day 20 | { 21 | Monday, 22 | Tuesday, 23 | Wednesday, 24 | Thursday = 4, 25 | Friday, 26 | Saturday, 27 | Sunday 28 | }; 29 | 30 | public int TestEnumValuesAfterModification() 31 | { 32 | Day weekendDay = Sunday; 33 | Assert(weekendDay == Sunday); 34 | 35 | Day midweekDay = Wednesday; 36 | Assert(midweekDay == Wednesday); 37 | 38 | return 0; 39 | } 40 | 41 | public int TestEnumSwitch() 42 | { 43 | Color switchColor = Green; 44 | int result = 0; 45 | 46 | switch (switchColor) 47 | { 48 | case Red: 49 | result = 1; 50 | break; 51 | case Green: 52 | result = 2; 53 | break; 54 | case Blue: 55 | result = 3; 56 | break; 57 | } 58 | 59 | Assert(result == 2); 60 | return 0; 61 | } 62 | 63 | public int TestLocalEnumDeclaration() 64 | { 65 | enum Status 66 | { 67 | Active, 68 | Inactive, 69 | Pending 70 | }; 71 | 72 | Status localStatus = Active; 73 | Assert(localStatus == Active); 74 | return 0; 75 | } 76 | 77 | public int main() 78 | { 79 | Assert(globalColor == Red); 80 | TestLocalEnumDeclaration(); 81 | TestEnumValues(); 82 | TestEnumValuesAfterModification(); 83 | TestEnumSwitch(); 84 | 85 | return 0; 86 | } -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_enum.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | enum Color 4 | { 5 | Red, 6 | Green, 7 | Blue 8 | }; 9 | 10 | Color globalColor = Red; 11 | 12 | public int TestEnumValues() 13 | { 14 | Color color = Blue; 15 | Assert(color == Blue); 16 | return 0; 17 | } 18 | 19 | enum Day 20 | { 21 | Monday, 22 | Tuesday, 23 | Wednesday, 24 | Thursday = 4, 25 | Friday, 26 | Saturday, 27 | Sunday 28 | }; 29 | 30 | public int TestEnumValuesAfterModification() 31 | { 32 | Day weekendDay = Sunday; 33 | Assert(weekendDay == Sunday); 34 | 35 | Day midweekDay = Wednesday; 36 | Assert(midweekDay == Wednesday); 37 | 38 | return 0; 39 | } 40 | 41 | public int TestEnumSwitch() 42 | { 43 | Color switchColor = Green; 44 | int result = 0; 45 | 46 | switch (switchColor) 47 | { 48 | case Red: 49 | result = 1; 50 | break; 51 | case Green: 52 | result = 2; 53 | break; 54 | case Blue: 55 | result = 3; 56 | break; 57 | } 58 | 59 | Assert(result == 2); 60 | return 0; 61 | } 62 | 63 | public int TestLocalEnumDeclaration() 64 | { 65 | enum Status 66 | { 67 | Active, 68 | Inactive, 69 | Pending 70 | }; 71 | 72 | Status localStatus = Active; 73 | Assert(localStatus == Active); 74 | return 0; 75 | } 76 | 77 | public int main() 78 | { 79 | Assert(globalColor == Red); 80 | TestLocalEnumDeclaration(); 81 | TestEnumValues(); 82 | TestEnumValuesAfterModification(); 83 | TestEnumSwitch(); 84 | 85 | return 0; 86 | } -------------------------------------------------------------------------------- /OlaTests/Tests/LLVM/test_implicitcasts.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | void TestImplicitCastAssignInit() 4 | { 5 | int intVal = 42; 6 | float floatVal = intVal; 7 | bool boolVal = intVal; 8 | 9 | Assert(floatVal == 42.0); 10 | Assert(boolVal == true); 11 | 12 | floatVal = 3.14; 13 | intVal = floatVal; 14 | boolVal = floatVal; 15 | 16 | Assert(intVal == 3); 17 | Assert(boolVal == true); 18 | 19 | boolVal = true; 20 | intVal = boolVal; 21 | floatVal = boolVal; 22 | 23 | Assert(intVal == 1); 24 | Assert(floatVal == 1.0); 25 | } 26 | 27 | void TestImplicitCastParamBool(bool boolParam) 28 | { 29 | Assert(boolParam == true); 30 | } 31 | 32 | void TestImplicitCastParamInt(int intParam) 33 | { 34 | Assert(intParam == 1); 35 | } 36 | 37 | void TestImplicitCastParamFloat(float floatParam) 38 | { 39 | Assert(floatParam == 1.0); 40 | } 41 | 42 | void TestImplicitCastParam() 43 | { 44 | int arg = 1; 45 | float farg = 1.0; 46 | bool barg = true; 47 | 48 | TestImplicitCastParamBool(arg); 49 | TestImplicitCastParamBool(farg); 50 | TestImplicitCastParamBool(1); 51 | TestImplicitCastParamBool(1.0); 52 | 53 | TestImplicitCastParamInt(barg); 54 | TestImplicitCastParamInt(farg); 55 | TestImplicitCastParamInt(true); 56 | TestImplicitCastParamInt(1.0); 57 | 58 | TestImplicitCastParamFloat(arg); 59 | TestImplicitCastParamFloat(barg); 60 | TestImplicitCastParamFloat(1); 61 | TestImplicitCastParamFloat(true); 62 | } 63 | 64 | 65 | public int main() 66 | { 67 | TestImplicitCastAssignInit(); 68 | TestImplicitCastParam(); 69 | return 0; 70 | } -------------------------------------------------------------------------------- /OlaTests/Tests/LLVM/test_returns.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | int TestIfElse() 4 | { 5 | int a = 6; 6 | if(a > 5) return 10; 7 | else return 0; 8 | } 9 | 10 | int TestWhile() 11 | { 12 | int a = 0; 13 | while(a < 10) 14 | { 15 | if (a == 5) return a * 2; 16 | ++a; 17 | } 18 | return 0; 19 | } 20 | int TestMultipleReturns() 21 | { 22 | int x = 5; 23 | if (x < 0) return -1; 24 | else if (x == 0) return 0; 25 | else if (x > 0) return 1; 26 | return -999; // Should never reach this point, but included for completeness 27 | } 28 | int TestEarlyReturnInLoop() 29 | { 30 | for (int i = 0; i < 10; i++) 31 | { 32 | if (i == 5) return i; 33 | } 34 | return -1; // Should never reach here if the return in the loop works correctly 35 | } 36 | int TestNestedReturn() 37 | { 38 | for (int i = 0; i < 3; i++) 39 | { 40 | if (i == 1) 41 | { 42 | for (int j = 0; j < 2; j++) 43 | { 44 | if (j == 1) return i * j; // Should return 1 * 1 = 1 45 | } 46 | } 47 | } 48 | return -1; // Should not reach here if nested return works correctly 49 | } 50 | void TestVoidWithEarlyReturn() 51 | { 52 | int sum = 0; 53 | for (int i = 1; i <= 10; i++) 54 | { 55 | sum += i; 56 | if (sum > 30) return; 57 | } 58 | Assert(false); // This should not be reached 59 | } 60 | 61 | public int main() 62 | { 63 | Assert(TestIfElse() == 10); 64 | Assert(TestWhile() == 10); 65 | Assert(TestMultipleReturns() == 1); 66 | Assert(TestEarlyReturnInLoop() == 5); 67 | Assert(TestNestedReturn() == 1); 68 | TestVoidWithEarlyReturn(); 69 | return 0; 70 | } -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_returns.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | int TestIfElse() 4 | { 5 | int a = 6; 6 | if(a > 5) return 10; 7 | else return 0; 8 | } 9 | 10 | int TestWhile() 11 | { 12 | int a = 0; 13 | while(a < 10) 14 | { 15 | if (a == 5) return a * 2; 16 | ++a; 17 | } 18 | return 0; 19 | } 20 | int TestMultipleReturns() 21 | { 22 | int x = 5; 23 | if (x < 0) return -1; 24 | else if (x == 0) return 0; 25 | else if (x > 0) return 1; 26 | return -999; // Should never reach this point, but included for completeness 27 | } 28 | int TestEarlyReturnInLoop() 29 | { 30 | for (int i = 0; i < 10; i++) 31 | { 32 | if (i == 5) return i; 33 | } 34 | return -1; // Should never reach here if the return in the loop works correctly 35 | } 36 | int TestNestedReturn() 37 | { 38 | for (int i = 0; i < 3; i++) 39 | { 40 | if (i == 1) 41 | { 42 | for (int j = 0; j < 2; j++) 43 | { 44 | if (j == 1) return i * j; // Should return 1 * 1 = 1 45 | } 46 | } 47 | } 48 | return -1; // Should not reach here if nested return works correctly 49 | } 50 | void TestVoidWithEarlyReturn() 51 | { 52 | int sum = 0; 53 | for (int i = 1; i <= 10; i++) 54 | { 55 | sum += i; 56 | if (sum > 30) return; 57 | } 58 | Assert(false); // This should not be reached 59 | } 60 | 61 | public int main() 62 | { 63 | Assert(TestIfElse() == 10); 64 | Assert(TestWhile() == 10); 65 | Assert(TestMultipleReturns() == 1); 66 | Assert(TestEarlyReturnInLoop() == 5); 67 | Assert(TestNestedReturn() == 1); 68 | TestVoidWithEarlyReturn(); 69 | return 0; 70 | } -------------------------------------------------------------------------------- /OlaTests/Tests/LLVM/test_array.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | private void modifyArray(int[] arr) 4 | { 5 | arr[0] = 100; 6 | } 7 | 8 | private void modifyArrayCopy(int[3] arr) 9 | { 10 | arr[0] = 100; 11 | } 12 | 13 | private int sumOfArray(int[] arr, int size) 14 | { 15 | int sum = 0; 16 | for(int i = 0; i < size; ++i) 17 | { 18 | sum += arr[i]; 19 | } 20 | return sum; 21 | } 22 | 23 | auto GlobalArray1 = {1,1,1}; 24 | int[5] GlobalArray2 = {1,2,3}; 25 | int[3] GlobalArray3 = {10,20,30}; 26 | int[2][2] Global2dArray = { {1,2}, {3,4}}; 27 | 28 | public int main() 29 | { 30 | Assert(length(GlobalArray1) == 3); 31 | Assert(sizeof(GlobalArray2) == 40); 32 | Assert(GlobalArray3[0] == 10); 33 | 34 | int[10] LocalArray1 = {1,2}; 35 | Assert(sizeof(LocalArray1) == 80); 36 | Assert(LocalArray1[6] == 0); 37 | Assert(sumOfArray(LocalArray1, length(LocalArray1)) == 3); 38 | 39 | int[3] LocalArray2 = {-5,0,5}; 40 | Assert(LocalArray2[1] == 0); 41 | Assert(length(LocalArray2) == 3); 42 | 43 | int[] LocalArray3 = LocalArray2; 44 | modifyArrayCopy(LocalArray2); 45 | Assert(LocalArray2[0] == -5); 46 | Assert(LocalArray3[0] == -5); 47 | modifyArray(LocalArray2); 48 | Assert(LocalArray2[0] == 100); 49 | Assert(LocalArray3[0] == 100); 50 | 51 | LocalArray3[0] = 1000; 52 | Assert(LocalArray2[0] == 1000); 53 | Assert(LocalArray3[0] == 1000); 54 | 55 | int sum2d = 0; 56 | int globalSum2d = 0; 57 | int[2][2] int2d = { {1,2}, {3,4}}; 58 | for(int i = 0; i < 2; ++i) 59 | { 60 | for(int j = 0; j < 2; ++j) 61 | { 62 | sum2d += int2d[i][j]; 63 | globalSum2d += Global2dArray[i][j]; 64 | } 65 | } 66 | Assert(sum2d == 10); 67 | Assert(globalSum2d == 10); 68 | 69 | return 0; 70 | } -------------------------------------------------------------------------------- /OlaTests/googletest/googlemock/README.md: -------------------------------------------------------------------------------- 1 | # Googletest Mocking (gMock) Framework 2 | 3 | ### Overview 4 | 5 | Google's framework for writing and using C++ mock classes. It can help you 6 | derive better designs of your system and write better tests. 7 | 8 | It is inspired by: 9 | 10 | * [jMock](http://www.jmock.org/) 11 | * [EasyMock](https://easymock.org/) 12 | * [Hamcrest](https://code.google.com/p/hamcrest/) 13 | 14 | It is designed with C++'s specifics in mind. 15 | 16 | gMock: 17 | 18 | - Provides a declarative syntax for defining mocks. 19 | - Can define partial (hybrid) mocks, which are a cross of real and mock 20 | objects. 21 | - Handles functions of arbitrary types and overloaded functions. 22 | - Comes with a rich set of matchers for validating function arguments. 23 | - Uses an intuitive syntax for controlling the behavior of a mock. 24 | - Does automatic verification of expectations (no record-and-replay needed). 25 | - Allows arbitrary (partial) ordering constraints on function calls to be 26 | expressed. 27 | - Lets a user extend it by defining new matchers and actions. 28 | - Does not use exceptions. 29 | - Is easy to learn and use. 30 | 31 | Details and examples can be found here: 32 | 33 | * [gMock for Dummies](https://google.github.io/googletest/gmock_for_dummies.html) 34 | * [Legacy gMock FAQ](https://google.github.io/googletest/gmock_faq.html) 35 | * [gMock Cookbook](https://google.github.io/googletest/gmock_cook_book.html) 36 | * [gMock Cheat Sheet](https://google.github.io/googletest/gmock_cheat_sheet.html) 37 | 38 | GoogleMock is a part of 39 | [GoogleTest C++ testing framework](https://github.com/google/googletest/) and a 40 | subject to the same requirements. 41 | -------------------------------------------------------------------------------- /OlaCompiler/Core/Log.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Log.h" 4 | 5 | namespace ola 6 | { 7 | static FILE* gLogFile = nullptr; 8 | 9 | std::string GetLogPrefix(LogLevel level) 10 | { 11 | switch (level) 12 | { 13 | case LogLevel::Debug: return "[DEBUG]"; 14 | case LogLevel::Info: return "[INFO]"; 15 | case LogLevel::Warning: return "[WARNING]"; 16 | case LogLevel::Error: return "[ERROR]"; 17 | } 18 | return ""; 19 | } 20 | std::string GetCurrentTimeString() 21 | { 22 | auto now = std::chrono::system_clock::now(); 23 | auto in_time_t = std::chrono::system_clock::to_time_t(now); 24 | auto ms = std::chrono::duration_cast(now.time_since_epoch()) % 1000; 25 | 26 | std::tm local_time{}; 27 | #if defined(_WIN32) || defined(_WIN64) 28 | localtime_s(&local_time, &in_time_t); 29 | #else 30 | localtime_r(&in_time_t, &local_time); 31 | #endif 32 | Char timestamp[64]; 33 | std::snprintf(timestamp, sizeof(timestamp), "[%04d-%02d-%02d %02d:%02d:%02d.%03d]", 34 | local_time.tm_year + 1900, 35 | local_time.tm_mon + 1, 36 | local_time.tm_mday, 37 | local_time.tm_hour, 38 | local_time.tm_min, 39 | local_time.tm_sec, 40 | static_cast(ms.count())); 41 | return timestamp; 42 | } 43 | 44 | void LogInit() 45 | { 46 | if (!gLogFile) 47 | { 48 | static Char const* gLogFileName = "olalog.txt"; 49 | gLogFile = fopen(gLogFileName, "w+"); 50 | setbuf(gLogFile, nullptr); 51 | } 52 | setbuf(stdout, nullptr); 53 | } 54 | 55 | void LogDestroy() 56 | { 57 | if (gLogFile) 58 | { 59 | fclose(gLogFile); 60 | } 61 | } 62 | 63 | void WriteToLogFile(std::string const& log_entry) 64 | { 65 | if (gLogFile) 66 | { 67 | fprintf(gLogFile, "%s\n", log_entry.c_str()); 68 | } 69 | } 70 | 71 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/ConstantFold.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Instruction.h" 4 | 5 | 6 | namespace ola 7 | { 8 | Value* TryConstantFold_BinaryInst(Opcode opcode, Value* lhs, Value* rhs); 9 | Value* TryConstantFold_UnaryInst(Opcode opcode, Value* val); 10 | Value* TryConstantFold_CompareInst(Opcode opcode, Value* lhs, Value* rhs); 11 | Value* TryConstantFold_GetElementPtrInst(Value* base, std::span indices); 12 | Value* TryConstantFold_SelectInst(Value* predicate, Value* lhs, Value* rhs); 13 | Value* TryConstantFold_BranchInst(Value* condition, BasicBlock* true_target, BasicBlock* false_target); 14 | 15 | template requires std::is_constructible_v 16 | constexpr Value* TryConstantFold(Args&&... args) 17 | { 18 | if constexpr (std::is_same_v) 19 | { 20 | return TryConstantFold_BinaryInst(std::forward(args)...); 21 | } 22 | else if constexpr (std::is_same_v) 23 | { 24 | return TryConstantFold_UnaryInst(std::forward(args)...); 25 | } 26 | else if constexpr (std::is_same_v) 27 | { 28 | return TryConstantFold_CompareInst(std::forward(args)...); 29 | } 30 | else if constexpr (std::is_same_v) 31 | { 32 | return TryConstantFold_GetElementPtrInst(std::forward(args)...); 33 | } 34 | else if constexpr (std::is_same_v) 35 | { 36 | return TryConstantFold_SelectInst(std::forward(args)...); 37 | } 38 | else if constexpr (std::is_same_v && sizeof...(Args) == 3) 39 | { 40 | return TryConstantFold_BranchInst(std::forward(args)...); 41 | } 42 | return nullptr; 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_array.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | //private void modifyArray(int[] arr) 4 | //{ 5 | // arr[0] = 100; 6 | //} 7 | // 8 | //private void modifyArrayCopy(int[3] arr) 9 | //{ 10 | // arr[0] = 100; 11 | //} 12 | // 13 | //private int sumOfArray(int[] arr, int size) 14 | //{ 15 | // int sum = 0; 16 | // for(int i = 0; i < size; ++i) 17 | // { 18 | // sum += arr[i]; 19 | // } 20 | // return sum; 21 | //} 22 | 23 | auto GlobalArray1 = {1,1,1}; 24 | int[5] GlobalArray2 = {1,2,3}; 25 | int[3] GlobalArray3 = {10,20,30}; 26 | //int[2][2] Global2dArray = { {1,2}, {3,4}}; 27 | 28 | public int main() 29 | { 30 | Assert(length(GlobalArray1) == 3); 31 | Assert(sizeof(GlobalArray2) == 40); 32 | Assert(GlobalArray3[0] == 10); 33 | 34 | int[10] LocalArray1 = {1,2}; 35 | Assert(sizeof(LocalArray1) == 80); 36 | Assert(LocalArray1[1] == 2); 37 | Assert(LocalArray1[6] == 0); 38 | //Assert(sumOfArray(LocalArray1, length(LocalArray1)) == 3); 39 | 40 | int[3] LocalArray2 = {-5,0,5}; 41 | Assert(LocalArray2[1] == 0); 42 | Assert(length(LocalArray2) == 3); 43 | 44 | //int[] LocalArray3 = LocalArray2; 45 | //modifyArrayCopy(LocalArray2); 46 | //Assert(LocalArray2[0] == -5); 47 | //Assert(LocalArray3[0] == -5); 48 | //modifyArray(LocalArray2); 49 | //Assert(LocalArray2[0] == 100); 50 | //Assert(LocalArray3[0] == 100); 51 | // 52 | //LocalArray3[0] = 1000; 53 | //Assert(LocalArray2[0] == 1000); 54 | //Assert(LocalArray3[0] == 1000); 55 | //int sum2d = 0; 56 | //int globalSum2d = 0; 57 | //int[2][2] int2d = { {1,2}, {3,4}}; 58 | //for(int i = 0; i < 2; ++i) 59 | //{ 60 | // for(int j = 0; j < 2; ++j) 61 | // { 62 | // sum2d += int2d[i][j]; 63 | // globalSum2d += Global2dArray[i][j]; 64 | // } 65 | //} 66 | //Assert(sum2d == 10); 67 | //Assert(globalSum2d == 10); 68 | 69 | return 0; 70 | } -------------------------------------------------------------------------------- /OlaTests/googletest/googletest/test/production.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // 31 | // This is part of the unit test for gtest_prod.h. 32 | 33 | #include "production.h" 34 | 35 | PrivateCode::PrivateCode() : x_(0) {} 36 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/MachineStorage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "MachineRelocable.h" 5 | 6 | namespace ola 7 | { 8 | class MachineZeroStorage final : public MachineRelocable 9 | { 10 | public: 11 | explicit MachineZeroStorage(std::string_view symbol, Uint64 size) : MachineRelocable(symbol), size(size) {} 12 | 13 | Uint64 GetSize() const { return size; } 14 | 15 | virtual RelocableKind GetRelocableKind() const override 16 | { 17 | return RelocableKind::ZeroStorage; 18 | } 19 | 20 | private: 21 | Uint64 size; 22 | }; 23 | 24 | class MachineDataStorage final : public MachineRelocable 25 | { 26 | public: 27 | using Storage = std::vector>; 28 | public: 29 | MachineDataStorage(std::string_view symbol, Bool read_only) : MachineRelocable(symbol), read_only(read_only) {} 30 | 31 | Bool IsReadOnly() const 32 | { 33 | return read_only; 34 | } 35 | Storage const& GetStorage() const { return data; } 36 | 37 | Uint32 AppendByte(Uint8 val) 38 | { 39 | return Append(val); 40 | } 41 | Uint32 AppendWord(Uint16 val) 42 | { 43 | return Append(val); 44 | } 45 | Uint32 AppendDWord(Uint32 val) 46 | { 47 | return Append(val); 48 | } 49 | Uint32 AppendQWord(Uint64 val) 50 | { 51 | return Append(val); 52 | } 53 | 54 | Uint32 AppendString(std::string_view str) 55 | { 56 | return Append(std::string(str)); 57 | } 58 | 59 | virtual RelocableKind GetRelocableKind() const override 60 | { 61 | return RelocableKind::DataStorage; 62 | } 63 | 64 | private: 65 | Storage data; 66 | Bool read_only; 67 | 68 | private: 69 | template 70 | Uint32 Append(T val) 71 | { 72 | Uint32 idx = (Uint32)data.size(); 73 | data.push_back(val); 74 | return idx; 75 | } 76 | }; 77 | 78 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/CFGAnalysisPass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "CFGAnalysisPass.h" 3 | #include "Backend/Custom/IR/CFGPrinter.h" 4 | #include "Backend/Custom/IR/GlobalValue.h" 5 | 6 | namespace ola 7 | { 8 | Bool CFGAnalysisPass::RunOn(Function& F, FunctionAnalysisManager& FAM) 9 | { 10 | cfg.Clear(); 11 | for (auto& block : F.Blocks()) 12 | { 13 | Instruction const* terminator = block.GetTerminator(); 14 | if (terminator && terminator->IsBranch()) 15 | { 16 | if (SwitchInst const* switch_inst = dyn_cast(terminator)) 17 | { 18 | std::unordered_set switch_targets; 19 | switch_targets.insert(switch_inst->GetDefaultCase()); 20 | for (auto&& switch_case : switch_inst->Cases()) 21 | { 22 | switch_targets.insert(switch_case.GetCaseBlock()); 23 | } 24 | 25 | for (BasicBlock* target : switch_targets) 26 | { 27 | cfg.AddSuccessor(&block, target); 28 | } 29 | } 30 | else if (BranchInst const* branch_inst = dyn_cast(terminator)) 31 | { 32 | BasicBlock* true_target = branch_inst->GetTrueTarget(); 33 | BasicBlock* false_target = branch_inst->GetFalseTarget(); 34 | cfg.AddSuccessor(&block, true_target); 35 | if (false_target && false_target != true_target) 36 | { 37 | cfg.AddSuccessor(&block, false_target); 38 | } 39 | } 40 | else OLA_ASSERT(false); 41 | } 42 | cfg.AddBasicBlock(&block); 43 | } 44 | OLA_ASSERT(cfg.GetPredecessors(&F.GetEntryBlock()).empty()); 45 | cfg.SetEntryBlock(&F.GetEntryBlock()); 46 | return false; 47 | } 48 | 49 | Bool CFGPrinterPass::RunOn(Function& F, FunctionAnalysisManager& FAM) 50 | { 51 | CFG const& cfg = FAM.GetResult(F); 52 | CFGPrinter cfg_printer; 53 | cfg_printer.Print(&F, cfg); 54 | return false; 55 | } 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/DominanceFrontierAnalysisPass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "DominanceFrontierAnalysisPass.h" 4 | #include "DominatorTreeAnalysisPass.h" 5 | #include "CFGAnalysisPass.h" 6 | #include "Backend/Custom/IR/GlobalValue.h" 7 | 8 | namespace ola 9 | { 10 | Bool DominanceFrontierAnalysisPass::RunOn(Function& F, FunctionAnalysisManager& FAM) 11 | { 12 | CFG const& cfg = FAM.GetResult(F); 13 | DominatorTree const& DT = FAM.GetResult(F); 14 | DF.Initialize(DT, cfg); 15 | return false; 16 | } 17 | 18 | Bool DominanceFrontierPrinterPass::RunOn(Function& F, FunctionAnalysisManager& FAM) 19 | { 20 | auto const& DF = FAM.GetResult(F); 21 | Uint MaxBBNameLength = GetMaxBasicBlockNameLength(DF); 22 | 23 | std::cout << "Dominance Frontiers for Function " << F.GetName() << ":\n"; 24 | for (auto I = DF.begin(), E = DF.end(); I != E; ++I) 25 | { 26 | std::cout << "\tDominance Frontier for BB "; 27 | std::cout << std::left << std::setw(MaxBBNameLength) << I->first->GetName(); 28 | std::cout << " is:\t"; 29 | auto const& Frontier = I->second; 30 | for (BasicBlock const* BB : Frontier) 31 | { 32 | std::cout << ' '; 33 | if (BB) std::cout << std::left << std::setw(MaxBBNameLength) << BB->GetName(); 34 | } 35 | std::cout << '\n'; 36 | } 37 | std::cout << '\n'; 38 | return false; 39 | } 40 | 41 | Uint DominanceFrontierPrinterPass::GetMaxBasicBlockNameLength(DominanceFrontier const& DF) 42 | { 43 | Uint MaxBBNameLength = 0; 44 | for (auto I = DF.begin(), E = DF.end(); I != E; ++I) 45 | { 46 | Uint BBNameLength = I->first->GetName().size(); 47 | if (BBNameLength > MaxBBNameLength) 48 | { 49 | MaxBBNameLength = BBNameLength; 50 | } 51 | } 52 | return MaxBBNameLength; 53 | } 54 | 55 | } 56 | 57 | -------------------------------------------------------------------------------- /OlaCompiler/Frontend/Diagnostics.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Compiler/CompilerMacros.h" 5 | #include "SourceLocation.h" 6 | 7 | 8 | namespace ola 9 | { 10 | enum DiagCode : Uint32 11 | { 12 | #define DIAG(diag_code, diag_kind, diag_msg) diag_code, 13 | #include "Diagnostics.def" 14 | }; 15 | 16 | class Diagnostics 17 | { 18 | enum class DiagKind : Uint32 19 | { 20 | info, 21 | warning, 22 | error 23 | }; 24 | static std::unordered_map diag_msgs; 25 | static std::unordered_map diag_kinds; 26 | static std::string ToString(DiagKind c); 27 | static void PrintMessage(DiagKind diag_kind, std::string const& msg); 28 | 29 | public: 30 | explicit Diagnostics(Bool warnings_as_errors = false, Bool exit_on_error = true); 31 | 32 | void SetDefaultLocation(SourceLocation const& loc); 33 | void Report(DiagCode code); 34 | void Report(SourceLocation const& loc, DiagCode code); 35 | template 36 | void Report(SourceLocation const& loc, DiagCode code, Args&&... args) 37 | { 38 | DiagKind diag_kind = diag_kinds[code]; 39 | std::string_view fmt = diag_msgs[code]; 40 | std::string diag_msg = std::vformat(fmt, std::make_format_args(args...)); 41 | std::string output = std::format("[Diagnostics][{}]: {} in file {} at line: {}, col: {}\n", 42 | ToString(diag_kind), diag_msg, loc.filename, loc.line, loc.column); 43 | output += "\n"; 44 | 45 | PrintMessage(diag_kind, output); 46 | if (exit_on_error && diag_kind == DiagKind::error) 47 | { 48 | std::exit(OLA_INVALID_SOURCE_CODE); 49 | } 50 | } 51 | 52 | private: 53 | Bool warnings_as_errors = false; 54 | Bool exit_on_error = false; 55 | SourceLocation loc; 56 | OLA_MAYBE_UNUSED Bool error_reported = false; 57 | }; 58 | } 59 | -------------------------------------------------------------------------------- /OlaCompiler/Frontend/Lexer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Token.h" 5 | 6 | namespace ola 7 | { 8 | class SourceBuffer; 9 | class Diagnostics; 10 | 11 | template 12 | concept CharPredicate = requires(P p, Char a) 13 | { 14 | { p(a) } -> std::convertible_to; 15 | }; 16 | 17 | class Lexer 18 | { 19 | public: 20 | explicit Lexer(Diagnostics& diagnostics); 21 | OLA_NONCOPYABLE_NONMOVABLE(Lexer) 22 | ~Lexer() = default; 23 | 24 | void Lex(SourceBuffer const& source); 25 | std::vector&& GetTokens() { return std::move(tokens); } 26 | 27 | private: 28 | Diagnostics& diagnostics; 29 | Char const* buf_ptr = nullptr; 30 | Char const* cur_ptr = nullptr; 31 | 32 | SourceLocation loc; 33 | std::vector tokens; 34 | private: 35 | 36 | Bool LexToken(Token&); 37 | Bool LexNumber(Token&); 38 | Bool LexIdentifier(Token&); 39 | Bool LexChar(Token&); 40 | Bool LexString(Token&); 41 | Bool LexEndOfFile(Token&); 42 | Bool LexNewLine(Token&); 43 | Bool LexComment(Token&); 44 | Bool LexPunctuator(Token&); 45 | 46 | void UpdatePointersAndLocation() 47 | { 48 | loc.NewChars(static_cast(cur_ptr - buf_ptr)); 49 | buf_ptr = cur_ptr; 50 | } 51 | 52 | void FillToken(Token& t, TokenKind type, Char const* end) 53 | { 54 | t.SetLocation(loc); 55 | t.SetKind(type); 56 | t.SetData(cur_ptr, end); 57 | cur_ptr = end; 58 | } 59 | template 60 | void Consume(Char const*& start, P&& predicate) 61 | { 62 | for (; predicate(*start); ++start); 63 | } 64 | template 65 | void FillToken(Token& t, TokenKind type, P&& predicate) 66 | { 67 | t.SetLocation(loc); 68 | t.SetKind(type); 69 | Char const* tmp_ptr = cur_ptr; 70 | Consume(tmp_ptr, std::forward

(predicate)); 71 | t.SetData(cur_ptr, tmp_ptr); 72 | cur_ptr = tmp_ptr; 73 | } 74 | }; 75 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/CFG.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace ola 6 | { 7 | class Function; 8 | class BasicBlock; 9 | class CFG 10 | { 11 | public: 12 | CFG() = default; 13 | 14 | void SetEntryBlock(BasicBlock* bb) 15 | { 16 | entry_block = bb; 17 | } 18 | BasicBlock* GetEntryBlock() const { return entry_block; } 19 | 20 | void AddPredecessor(BasicBlock* bb, BasicBlock* pred); 21 | void AddSuccessor(BasicBlock* bb, BasicBlock* succ); 22 | void RemovePredecessor(BasicBlock* bb, BasicBlock* pred); 23 | void RemoveSuccessor(BasicBlock* bb, BasicBlock* succ); 24 | void AddBasicBlock(BasicBlock* bb); 25 | std::unordered_set const& GetPredecessors(BasicBlock const* bb) const; 26 | std::unordered_set const& GetSuccessors(BasicBlock const* bb) const; 27 | BasicBlock* GetUniquePredecessor(BasicBlock const* bb) const; 28 | BasicBlock* GetUniqueSuccessor(BasicBlock const* bb) const; 29 | 30 | void Clear() 31 | { 32 | basic_blocks.clear(); 33 | predecessors.clear(); 34 | successors.clear(); 35 | } 36 | 37 | using iterator = std::unordered_set::iterator; 38 | using const_iterator = std::unordered_set::const_iterator; 39 | 40 | iterator begin() { return basic_blocks.begin(); } 41 | iterator end() { return basic_blocks.end(); } 42 | const_iterator begin() const { return cbegin(); } 43 | const_iterator end() const { return cend(); } 44 | const_iterator cbegin() const { return basic_blocks.cbegin(); } 45 | const_iterator cend() const { return basic_blocks.cend(); } 46 | 47 | private: 48 | BasicBlock* entry_block = nullptr; 49 | std::unordered_set basic_blocks; 50 | std::unordered_map> predecessors; 51 | std::unordered_map> successors; 52 | }; 53 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/CFG.cpp: -------------------------------------------------------------------------------- 1 | #include "CFG.h" 2 | #include "Backend/Custom/IR/BasicBlock.h" 3 | 4 | namespace ola 5 | { 6 | static const std::unordered_set empty{}; 7 | 8 | void CFG::AddPredecessor(BasicBlock* bb, BasicBlock* pred) 9 | { 10 | predecessors[bb].insert(pred); 11 | successors[pred].insert(bb); 12 | } 13 | 14 | void CFG::AddSuccessor(BasicBlock* bb, BasicBlock* succ) 15 | { 16 | successors[bb].insert(succ); 17 | predecessors[succ].insert(bb); 18 | } 19 | 20 | void CFG::RemovePredecessor(BasicBlock* bb, BasicBlock* pred) 21 | { 22 | auto& preds = predecessors[bb]; 23 | preds.erase(pred); 24 | auto& succs = successors[pred]; 25 | succs.erase(bb); 26 | } 27 | 28 | void CFG::RemoveSuccessor(BasicBlock* bb, BasicBlock* succ) 29 | { 30 | auto& succs = successors[bb]; 31 | succs.erase(succ); 32 | auto& preds = predecessors[succ]; 33 | preds.erase(bb); 34 | } 35 | 36 | void CFG::AddBasicBlock(BasicBlock* bb) 37 | { 38 | basic_blocks.insert(bb); 39 | bb->SetCFG(this); 40 | } 41 | 42 | std::unordered_set const& CFG::GetPredecessors(BasicBlock const* bb) const 43 | { 44 | auto it = predecessors.find(bb); 45 | return (it != predecessors.end()) ? it->second : empty; 46 | } 47 | 48 | std::unordered_set const& CFG::GetSuccessors(BasicBlock const* bb) const 49 | { 50 | auto it = successors.find(bb); 51 | return (it != successors.end()) ? it->second : empty; 52 | } 53 | 54 | BasicBlock* CFG::GetUniquePredecessor(BasicBlock const* bb) const 55 | { 56 | std::unordered_set const& predecessors = GetPredecessors(bb); 57 | return predecessors.size() == 1 ? *predecessors.begin() : nullptr; 58 | } 59 | 60 | BasicBlock* CFG::GetUniqueSuccessor(BasicBlock const* bb) const 61 | { 62 | std::unordered_set const& successors = GetSuccessors(bb); 63 | return successors.size() == 1 ? *successors.begin() : nullptr; 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /OlaTests/googletest/WORKSPACE.bzlmod: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Google Inc. 2 | # All Rights Reserved. 3 | # 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are 7 | # met: 8 | # 9 | # * Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above 12 | # copyright notice, this list of conditions and the following disclaimer 13 | # in the documentation and/or other materials provided with the 14 | # distribution. 15 | # * Neither the name of Google Inc. nor the names of its 16 | # contributors may be used to endorse or promote products derived from 17 | # this software without specific prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | # https://bazel.build/external/migration#workspace.bzlmod 32 | # 33 | # This file is intentionally empty. When bzlmod is enabled and this 34 | # file exists, the content of WORKSPACE is ignored. This prevents 35 | # bzlmod builds from unintentionally depending on the WORKSPACE file. 36 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/GlobalDeadCodeEliminationPass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "GlobalDeadCodeEliminationPass.h" 4 | #include "Backend/Custom/IR/GlobalValue.h" 5 | #include "Backend/Custom/IR/IRModule.h" 6 | 7 | namespace ola 8 | { 9 | Bool GlobalDeadCodeEliminationPass::RunOn(IRModule& M, IRModuleAnalysisManager& FAM) 10 | { 11 | std::unordered_set UsedGlobals; 12 | std::function MarkFunctionAsUsed = [&](Function const* F) 13 | { 14 | if (!F || !UsedGlobals.insert(F).second) 15 | { 16 | return; 17 | } 18 | 19 | for (BasicBlock const& BB : *F) 20 | { 21 | for (Instruction const& I : BB) 22 | { 23 | if (CallInst const* Call = dyn_cast(&I)) 24 | { 25 | if (Function const* Callee = Call->GetCalleeAsFunction()) 26 | { 27 | MarkFunctionAsUsed(Callee); 28 | } 29 | } 30 | 31 | for (auto const& Op : I.Operands()) 32 | { 33 | if (GlobalVariable const* GV = dyn_cast(Op.GetValue())) 34 | { 35 | UsedGlobals.insert(GV); 36 | } 37 | } 38 | } 39 | } 40 | }; 41 | 42 | for (auto& G : M.Globals()) 43 | { 44 | if (Function* F = dyn_cast(G); F && F->GetLinkage() != Linkage::Internal) 45 | { 46 | MarkFunctionAsUsed(F); 47 | } 48 | } 49 | 50 | std::vector DeadGlobals; 51 | for (auto& G : M.Globals()) 52 | { 53 | if (Function* F = dyn_cast(G); F && F->GetLinkage() == Linkage::Internal && !UsedGlobals.contains(F)) 54 | { 55 | DeadGlobals.push_back(F); 56 | } 57 | if (GlobalVariable* GV = dyn_cast(G); GV && GV->GetLinkage() == Linkage::Internal && !UsedGlobals.contains(GV)) 58 | { 59 | DeadGlobals.push_back(GV); 60 | } 61 | } 62 | for (GlobalValue* DG : DeadGlobals) 63 | { 64 | M.RemoveGlobal(DG); 65 | } 66 | return !DeadGlobals.empty(); 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /OlaTests/Tests/Custom/test_functioncalls.ola: -------------------------------------------------------------------------------- 1 | import std.assert; 2 | 3 | 4 | int Add(int a, int b) 5 | { 6 | return a + b; 7 | } 8 | 9 | int AddThreeNumbers(int a, int b, int c) 10 | { 11 | return a + b + c; 12 | } 13 | 14 | int AddFourNumbers(int a, int b, int c, int d) 15 | { 16 | return a + b + c + d; 17 | } 18 | 19 | int AddSixNumbers(int a, int b, int c, int d, int e, int f) 20 | { 21 | return a + b + c + d + e + f; 22 | } 23 | 24 | int AddTenNumbers(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) 25 | { 26 | return a + b + c + d + e + f + g + h + i + j; 27 | } 28 | 29 | int AlternatingSum(int a, int b, int c, int d, int e, int f) 30 | { 31 | return a - b + c - d + e - f; 32 | } 33 | 34 | float AddFloats(float a, float b) 35 | { 36 | return a + b; 37 | } 38 | 39 | float AddIntAndFloat(int a, float b, float c) 40 | { 41 | return a + b + c; 42 | } 43 | 44 | float ConditionSum(float a, float b, float c, float d, bool e) 45 | { 46 | return e ? a + b : c + d; 47 | } 48 | 49 | int AddBooleans(bool a, bool b, bool c, bool d) 50 | { 51 | return a + b + c + d; // Implicit conversion (true = 1, false = 0) 52 | } 53 | 54 | 55 | void TestIntCalls() 56 | { 57 | Assert(Add(1, 2) == 3); 58 | Assert(AddThreeNumbers(1,2,3) == 6); 59 | Assert(AddFourNumbers(1,2,3,4) == 10); 60 | Assert(AddSixNumbers(1,2,3,4,5,6) == 21); 61 | Assert(AlternatingSum(1,2,3,4,5,6) == -3); 62 | } 63 | void TestFloatCalls() 64 | { 65 | Assert(AddFloats(1.0, 2.0) == 3.0); 66 | Assert(AddIntAndFloat(1, 2.0, 3.0) == 6.0); 67 | Assert(ConditionSum(1.0, 2.0, 3.0, 4.0, true) == 3.0); 68 | Assert(ConditionSum(1.0, 2.0, 3.0, 4.0, false) == 7.0); 69 | Assert(AddTenNumbers(1,2,3,4,5,6,7,8,9,10) == 55); 70 | } 71 | 72 | void TestBoolCalls() 73 | { 74 | Assert(AddBooleans(true, false, true, false) == 2); 75 | } 76 | 77 | public int main() 78 | { 79 | TestIntCalls(); 80 | TestFloatCalls(); 81 | TestBoolCalls(); 82 | return 0; 83 | } -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/ARM64/ARM64AsmPrinter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/Codegen/AsmPrinter.h" 3 | 4 | namespace ola 5 | { 6 | enum ARM64Section : Uint32 7 | { 8 | ARM64Section_Preamble, 9 | ARM64Section_ReadOnly, 10 | ARM64Section_BSS, 11 | ARM64Section_Data, 12 | ARM64Section_Text 13 | }; 14 | 15 | class MachineModule; 16 | class ARM64AsmPrinter : public AsmPrinter 17 | { 18 | public: 19 | ARM64AsmPrinter(std::ostream& os) : AsmPrinter(os) {} 20 | virtual void PrintModule(MachineModule const& M) override; 21 | 22 | private: 23 | virtual std::string GetSectionLabel(SectionId section) const override 24 | { 25 | switch (static_cast(section)) 26 | { 27 | case ARM64Section_Text: 28 | return ".text"; 29 | case ARM64Section_Data: 30 | return ".data"; 31 | case ARM64Section_ReadOnly: 32 | return ".const"; 33 | case ARM64Section_BSS: 34 | return ".bss"; 35 | case ARM64Section_Preamble: 36 | default: 37 | return ""; 38 | } 39 | } 40 | 41 | std::string GetFPConstantPoolEntry(Int64 value); 42 | std::string GetIntConstantPoolEntry(Int64 value); 43 | 44 | template 45 | void EmitPreamble(Char const* fmt, Args&&... args) 46 | { 47 | Emit(fmt, std::forward(args)...); 48 | } 49 | template 50 | void EmitText(Char const* fmt, Args&&... args) 51 | { 52 | Emit(fmt, std::forward(args)...); 53 | } 54 | template 55 | void EmitData(Char const* fmt, Args&&... args) 56 | { 57 | Emit(fmt, std::forward(args)...); 58 | } 59 | template 60 | void EmitReadOnly(Char const* fmt, Args&&... args) 61 | { 62 | Emit(fmt, std::forward(args)...); 63 | } 64 | template 65 | void EmitBSS(Char const* fmt, Args&&... args) 66 | { 67 | Emit(fmt, std::forward(args)...); 68 | } 69 | }; 70 | } 71 | -------------------------------------------------------------------------------- /OlaCompiler/Compiler/CompilerMacros.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Core/Defines.h" 3 | #include "autogen/OlaConfig.h" 4 | 5 | // MSVC requires OLA_CONCAT (##), Clang/GCC can use direct string concatenation 6 | #if defined(_MSC_VER) 7 | #define OLA_PATH_CONCAT(base, suffix) OLA_CONCAT(base, suffix) 8 | #else 9 | #define OLA_PATH_CONCAT(base, suffix) base suffix 10 | #endif 11 | 12 | // OLA_EXE_PATH is now provided by CMake at configure time via target_compile_definitions 13 | // This makes the test paths portable across different generators (Unix Makefiles, Xcode, Visual Studio, etc.) 14 | 15 | #if !LLVM_BACKEND 16 | 17 | #ifdef DEBUG 18 | #define OLA(...) std::system(OLA_STRINGIFY(OLA_EXE_PATH --O0 --nollvm __VA_ARGS__)) 19 | #define OLA_TEST(...) std::system(OLA_STRINGIFY(OLA_EXE_PATH --O0 --nollvm --timeout --test __VA_ARGS__)) 20 | #else 21 | #define OLA(...) std::system(OLA_STRINGIFY(OLA_EXE_PATH --O3 --nollvm __VA_ARGS__)) 22 | #define OLA_TEST(...) std::system(OLA_STRINGIFY(OLA_EXE_PATH --O3 --nollvm --timeout --test __VA_ARGS__)) 23 | #endif 24 | 25 | #else 26 | 27 | #ifdef DEBUG 28 | #define OLA(...) std::system(OLA_STRINGIFY(OLA_EXE_PATH --O0 __VA_ARGS__)) 29 | #define OLA_TEST(...) std::system(OLA_STRINGIFY(OLA_EXE_PATH --O0 --timeout --test __VA_ARGS__)) 30 | #else 31 | #define OLA(...) std::system(OLA_STRINGIFY(OLA_EXE_PATH --O3 __VA_ARGS__)) 32 | #define OLA_TEST(...) std::system(OLA_STRINGIFY(OLA_EXE_PATH --O3 --timeout --test __VA_ARGS__)) 33 | #endif 34 | 35 | #endif 36 | 37 | #if defined(OLA_PLATFORM_WINDOWS) 38 | #if DEBUG 39 | #define OLA_STATIC_LIB_PATH OLA_PATH_CONCAT(OLA_BINARY_PATH, "Debug/olalib.lib") 40 | #else 41 | #define OLA_STATIC_LIB_PATH OLA_PATH_CONCAT(OLA_BINARY_PATH, "Release/olalib.lib") 42 | #endif 43 | #else 44 | #define OLA_STATIC_LIB_PATH OLA_PATH_CONCAT(OLA_BINARY_PATH, "libOlaLib.a") 45 | #endif 46 | 47 | 48 | #define OLA_INVALID_SOURCE_CODE (-255) 49 | #define OLA_INVALID_ASSEMBLY_CODE (-254) 50 | #define OLA_TIMEOUT_ERROR_CODE (-253) 51 | #define OLA_ASSERT_ERROR_CODE (-252) -------------------------------------------------------------------------------- /OlaTests/googletest/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore CI build directory 2 | build/ 3 | xcuserdata 4 | cmake-build-debug/ 5 | .idea/ 6 | bazel-bin 7 | bazel-genfiles 8 | bazel-googletest 9 | bazel-out 10 | bazel-testlogs 11 | MODULE.bazel.lock 12 | # python 13 | *.pyc 14 | 15 | # Visual Studio files 16 | .vs 17 | *.sdf 18 | *.opensdf 19 | *.VC.opendb 20 | *.suo 21 | *.user 22 | _ReSharper.Caches/ 23 | Win32-Debug/ 24 | Win32-Release/ 25 | x64-Debug/ 26 | x64-Release/ 27 | 28 | # VSCode files 29 | .cache/ 30 | cmake-variants.yaml 31 | 32 | # Ignore autoconf / automake files 33 | Makefile.in 34 | aclocal.m4 35 | configure 36 | build-aux/ 37 | autom4te.cache/ 38 | googletest/m4/libtool.m4 39 | googletest/m4/ltoptions.m4 40 | googletest/m4/ltsugar.m4 41 | googletest/m4/ltversion.m4 42 | googletest/m4/lt~obsolete.m4 43 | googlemock/m4 44 | 45 | # Ignore generated directories. 46 | googlemock/fused-src/ 47 | googletest/fused-src/ 48 | 49 | # macOS files 50 | .DS_Store 51 | googletest/.DS_Store 52 | googletest/xcode/.DS_Store 53 | 54 | # Ignore cmake generated directories and files. 55 | CMakeFiles 56 | CTestTestfile.cmake 57 | Makefile 58 | cmake_install.cmake 59 | googlemock/CMakeFiles 60 | googlemock/CTestTestfile.cmake 61 | googlemock/Makefile 62 | googlemock/cmake_install.cmake 63 | googlemock/gtest 64 | /bin 65 | /googlemock/gmock.dir 66 | /googlemock/gmock_main.dir 67 | /googlemock/RUN_TESTS.vcxproj.filters 68 | /googlemock/RUN_TESTS.vcxproj 69 | /googlemock/INSTALL.vcxproj.filters 70 | /googlemock/INSTALL.vcxproj 71 | /googlemock/gmock_main.vcxproj.filters 72 | /googlemock/gmock_main.vcxproj 73 | /googlemock/gmock.vcxproj.filters 74 | /googlemock/gmock.vcxproj 75 | /googlemock/gmock.sln 76 | /googlemock/ALL_BUILD.vcxproj.filters 77 | /googlemock/ALL_BUILD.vcxproj 78 | /lib 79 | /Win32 80 | /ZERO_CHECK.vcxproj.filters 81 | /ZERO_CHECK.vcxproj 82 | /RUN_TESTS.vcxproj.filters 83 | /RUN_TESTS.vcxproj 84 | /INSTALL.vcxproj.filters 85 | /INSTALL.vcxproj 86 | /googletest-distribution.sln 87 | /CMakeCache.txt 88 | /ALL_BUILD.vcxproj.filters 89 | /ALL_BUILD.vcxproj 90 | -------------------------------------------------------------------------------- /OlaCompiler/Frontend/Diagnostics.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Diagnostics.h" 3 | #include "Core/Log.h" 4 | 5 | namespace ola 6 | { 7 | std::unordered_map Diagnostics::diag_msgs = 8 | { 9 | #define DIAG(diag_code, diag_kind, diag_msg) {DiagCode::diag_code, diag_msg}, 10 | #include "Diagnostics.def" 11 | }; 12 | std::unordered_map Diagnostics::diag_kinds = 13 | { 14 | #define DIAG(diag_code, diag_kind, diag_msg) {DiagCode::diag_code, DiagKind::diag_kind}, 15 | #include "Diagnostics.def" 16 | }; 17 | 18 | std::string Diagnostics::ToString(DiagKind c) 19 | { 20 | switch (c) 21 | { 22 | case DiagKind::error: return "Error"; 23 | case DiagKind::warning: return "Warning"; 24 | case DiagKind::info: return "Info"; 25 | } 26 | return ""; 27 | } 28 | 29 | void Diagnostics::PrintMessage(DiagKind diag_kind, std::string const& msg) 30 | { 31 | switch (diag_kind) 32 | { 33 | case DiagKind::info: 34 | OLA_INFO("{}", msg); 35 | break; 36 | case DiagKind::warning: 37 | OLA_WARN("{}", msg); 38 | break; 39 | case DiagKind::error: 40 | OLA_ERROR("{}", msg); 41 | break; 42 | } 43 | } 44 | 45 | Diagnostics::Diagnostics(Bool _warnings_as_errors, Bool _exit_on_error) 46 | { 47 | warnings_as_errors = _warnings_as_errors; 48 | exit_on_error = _exit_on_error; 49 | } 50 | 51 | void Diagnostics::SetDefaultLocation(SourceLocation const& _loc) 52 | { 53 | loc = _loc; 54 | } 55 | void Diagnostics::Report(DiagCode code) 56 | { 57 | Report(loc, code); 58 | } 59 | void Diagnostics::Report(SourceLocation const& loc, DiagCode code) 60 | { 61 | DiagKind diag_kind = diag_kinds[code]; 62 | std::string output = std::format("[Diagnostics][{}]: {} in file {} at line: {}, col: {}\n", 63 | ToString(diag_kind), diag_msgs[code], loc.filename, loc.line, loc.column); 64 | PrintMessage(diag_kind, output); 65 | if (exit_on_error && diag_kind == DiagKind::error) 66 | { 67 | std::exit(OLA_INVALID_SOURCE_CODE); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /OlaTests/googletest/googletest/test/gtest_main_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include "gtest/gtest.h" 31 | 32 | // Tests that we don't have to define main() when we link to 33 | // gtest_main instead of gtest. 34 | 35 | namespace { 36 | 37 | TEST(GTestMainTest, ShouldSucceed) {} 38 | 39 | } // namespace 40 | 41 | // We are using the main() function defined in gtest_main.cc, so we 42 | // don't define it here. 43 | -------------------------------------------------------------------------------- /OlaTests/googletest/googletest/include/gtest/internal/custom/gtest.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Injection point for custom user configurations. See README for details 31 | // 32 | // ** Custom implementation starts here ** 33 | 34 | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 35 | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 36 | 37 | #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 38 | -------------------------------------------------------------------------------- /OlaTests/googletest/googlemock/test/gmock_link2_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // Google Mock - a framework for writing C++ mock classes. 31 | // 32 | // This file is for verifying that various Google Mock constructs do not 33 | // produce linker errors when instantiated in different translation units. 34 | // Please see gmock_link_test.h for details. 35 | 36 | #define LinkTest LinkTest2 37 | 38 | #include "test/gmock_link_test.h" 39 | -------------------------------------------------------------------------------- /OlaTests/googletest/googlemock/test/gmock_link_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // Google Mock - a framework for writing C++ mock classes. 31 | // 32 | // This file is for verifying that various Google Mock constructs do not 33 | // produce linker errors when instantiated in different translation units. 34 | // Please see gmock_link_test.h for details. 35 | 36 | #define LinkTest LinkTest1 37 | 38 | #include "test/gmock_link_test.h" 39 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/Codegen/x64/x64AsmPrinter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Backend/Custom/Codegen/AsmPrinter.h" 3 | 4 | namespace ola 5 | { 6 | enum x64Section : Uint32 7 | { 8 | x64Section_Preamble, 9 | x64Section_ReadOnly, 10 | x64Section_BSS, 11 | x64Section_Data, 12 | x64Section_Text 13 | }; 14 | 15 | class MachineModule; 16 | class x64AsmPrinter : public AsmPrinter 17 | { 18 | public: 19 | x64AsmPrinter(std::ostream& os) : AsmPrinter(os) {} 20 | virtual void PrintModule(MachineModule const& M) override; 21 | 22 | private: 23 | virtual std::string GetSectionLabel(SectionId section) const override 24 | { 25 | switch (static_cast(section)) 26 | { 27 | case x64Section_Text: return ".text"; 28 | case x64Section_Data: return ".data"; 29 | case x64Section_ReadOnly: 30 | #if defined(OLA_PLATFORM_WINDOWS) 31 | return ".section .rodata"; 32 | #else 33 | return ".section __TEXT,__const"; 34 | #endif 35 | case x64Section_BSS: return ".bss"; 36 | case x64Section_Preamble: 37 | default: 38 | return ""; 39 | } 40 | } 41 | 42 | std::string GetFPConstantPoolEntry(Int64 value); 43 | std::string GetIntConstantPoolEntry(Int64 value); 44 | 45 | template 46 | void EmitPreamble(Char const* fmt, Args&&... args) 47 | { 48 | Emit(fmt, std::forward(args)...); 49 | } 50 | template 51 | void EmitText(Char const* fmt, Args&&... args) 52 | { 53 | Emit(fmt, std::forward(args)...); 54 | } 55 | template 56 | void EmitData(Char const* fmt, Args&&... args) 57 | { 58 | Emit(fmt, std::forward(args)...); 59 | } 60 | template 61 | void EmitReadOnly(Char const* fmt, Args&&... args) 62 | { 63 | Emit(fmt, std::forward(args)...); 64 | } 65 | template 66 | void EmitBSS(Char const* fmt, Args&&... args) 67 | { 68 | Emit(fmt, std::forward(args)...); 69 | } 70 | }; 71 | } -------------------------------------------------------------------------------- /OlaTests/googletest/googletest/include/gtest/internal/custom/gtest-port.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Injection point for custom user configurations. See README for details 31 | // 32 | // ** Custom implementation starts here ** 33 | 34 | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 35 | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 36 | 37 | #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 38 | -------------------------------------------------------------------------------- /OlaTests/googletest/ci/windows-presubmit.bat: -------------------------------------------------------------------------------- 1 | SETLOCAL ENABLEDELAYEDEXPANSION 2 | 3 | SET BAZEL_EXE=%KOKORO_GFILE_DIR%\bazel-7.0.0-windows-x86_64.exe 4 | 5 | SET PATH=C:\Python34;%PATH% 6 | SET BAZEL_PYTHON=C:\python34\python.exe 7 | SET BAZEL_SH=C:\tools\msys64\usr\bin\bash.exe 8 | SET CMAKE_BIN="cmake.exe" 9 | SET CTEST_BIN="ctest.exe" 10 | SET CTEST_OUTPUT_ON_FAILURE=1 11 | SET CMAKE_BUILD_PARALLEL_LEVEL=16 12 | SET CTEST_PARALLEL_LEVEL=16 13 | 14 | IF EXIST git\googletest ( 15 | CD git\googletest 16 | ) ELSE IF EXIST github\googletest ( 17 | CD github\googletest 18 | ) 19 | 20 | IF %errorlevel% neq 0 EXIT /B 1 21 | 22 | :: ---------------------------------------------------------------------------- 23 | :: CMake 24 | MKDIR cmake_msvc2022 25 | CD cmake_msvc2022 26 | 27 | %CMAKE_BIN% .. ^ 28 | -G "Visual Studio 17 2022" ^ 29 | -DPYTHON_EXECUTABLE:FILEPATH=c:\python37\python.exe ^ 30 | -DPYTHON_INCLUDE_DIR:PATH=c:\python37\include ^ 31 | -DPYTHON_LIBRARY:FILEPATH=c:\python37\lib\site-packages\pip ^ 32 | -Dgtest_build_samples=ON ^ 33 | -Dgtest_build_tests=ON ^ 34 | -Dgmock_build_tests=ON 35 | IF %errorlevel% neq 0 EXIT /B 1 36 | 37 | %CMAKE_BIN% --build . --target ALL_BUILD --config Debug -- -maxcpucount 38 | IF %errorlevel% neq 0 EXIT /B 1 39 | 40 | %CTEST_BIN% -C Debug --timeout 600 41 | IF %errorlevel% neq 0 EXIT /B 1 42 | 43 | CD .. 44 | RMDIR /S /Q cmake_msvc2022 45 | 46 | :: ---------------------------------------------------------------------------- 47 | :: Bazel 48 | 49 | :: The default home directory on Kokoro is a long path which causes errors 50 | :: because of Windows limitations on path length. 51 | :: --output_user_root=C:\tmp causes Bazel to use a shorter path. 52 | SET BAZEL_VS=C:\Program Files\Microsoft Visual Studio\2022\Community 53 | %BAZEL_EXE% ^ 54 | --output_user_root=C:\tmp ^ 55 | test ... ^ 56 | --compilation_mode=dbg ^ 57 | --copt=/std:c++14 ^ 58 | --copt=/WX ^ 59 | --enable_bzlmod=true ^ 60 | --keep_going ^ 61 | --test_output=errors ^ 62 | --test_tag_filters=-no_test_msvc2017 63 | IF %errorlevel% neq 0 EXIT /B 1 64 | -------------------------------------------------------------------------------- /OlaTests/googletest/googletest/test/googletest-uninitialized-test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include "gtest/gtest.h" 31 | 32 | TEST(DummyTest, Dummy) { 33 | // This test doesn't verify anything. We just need it to create a 34 | // realistic stage for testing the behavior of Google Test when 35 | // RUN_ALL_TESTS() is called without 36 | // testing::InitGoogleTest() being called first. 37 | } 38 | 39 | int main() { return RUN_ALL_TESTS(); } 40 | -------------------------------------------------------------------------------- /OlaTests/googletest/googletest/samples/sample1.h: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // A sample program demonstrating using Google C++ testing framework. 31 | 32 | #ifndef GOOGLETEST_SAMPLES_SAMPLE1_H_ 33 | #define GOOGLETEST_SAMPLES_SAMPLE1_H_ 34 | 35 | // Returns n! (the factorial of n). For negative n, n! is defined to be 1. 36 | int Factorial(int n); 37 | 38 | // Returns true if and only if n is a prime number. 39 | bool IsPrime(int n); 40 | 41 | #endif // GOOGLETEST_SAMPLES_SAMPLE1_H_ 42 | -------------------------------------------------------------------------------- /OlaTests/googletest/googlemock/include/gmock/internal/custom/gmock-matchers.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // Injection point for custom user configurations. See README for details 31 | 32 | // IWYU pragma: private, include "gmock/gmock.h" 33 | // IWYU pragma: friend gmock/.* 34 | 35 | #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_ 36 | #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_ 37 | #endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_ 38 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/PassManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "PassRegistry.h" 6 | #include "Pass.h" 7 | 8 | namespace ola 9 | { 10 | template 11 | struct UnitTraits; 12 | 13 | template 14 | class AnalysisManager; 15 | 16 | template 17 | class PassManager 18 | { 19 | using BasePassT = typename UnitTraits::BasePassT; 20 | using ParentUnitT = typename UnitTraits::ParentUnitT; 21 | static_assert(std::is_base_of_v); 22 | 23 | public: 24 | void AddPass(BasePassT* pass) 25 | { 26 | Verify(pass->GetPassID()); 27 | passes.emplace_back(pass); 28 | } 29 | template requires std::is_base_of_v 30 | void AddPass(Args&&... args) 31 | { 32 | Verify(PassT::ID()); 33 | passes.emplace_back(new PassT(std::forward(args)...)); 34 | } 35 | 36 | Bool Run(UnitT& U, AnalysisManager& AM) 37 | { 38 | Bool changed = false; 39 | for (auto& pass : passes) 40 | { 41 | changed |= pass->RunOn(U, AM); 42 | } 43 | return changed; 44 | } 45 | Bool Run(UnitT& U, ParentUnitT& PU, AnalysisManager& AM) 46 | { 47 | Bool changed = false; 48 | for (auto& pass : passes) 49 | { 50 | pass->Init(PU); 51 | } 52 | for (auto& pass : passes) 53 | { 54 | changed |= pass->RunOn(U, AM); 55 | } 56 | for (auto& pass : passes) 57 | { 58 | pass->Deinit(PU); 59 | } 60 | return changed; 61 | } 62 | 63 | Bool IsEmpty() const 64 | { 65 | return passes.empty(); 66 | } 67 | 68 | private: 69 | std::vector> passes; 70 | 71 | private: 72 | void Verify(void const* pass_id) 73 | { 74 | PassInfo const* pass_info = g_PassRegistry.GetInfo(pass_id); 75 | OLA_ASSERT_MSG(pass_info, "Pass was not registered! Did you forget to declare OLA_REGISTER_PASS or OLA_REGISTER_ANALYSIS_PASS? "); 76 | OLA_ASSERT_MSG(!pass_info->IsAnalysis(), "You can only register analysis pass to analysis manager!"); 77 | } 78 | }; 79 | 80 | 81 | } -------------------------------------------------------------------------------- /OlaTests/googletest/googletest/test/gtest_testbridge_test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2018, Google LLC. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // This program is meant to be run by gtest_test_filter_test.py. Do not run 31 | // it directly. 32 | 33 | #include "gtest/gtest.h" 34 | 35 | // These tests are used to detect if filtering is working. Only 36 | // 'TestThatSucceeds' should ever run. 37 | 38 | TEST(TestFilterTest, TestThatSucceeds) {} 39 | 40 | TEST(TestFilterTest, TestThatFails) { 41 | ASSERT_TRUE(false) << "This test should never be run."; 42 | } 43 | -------------------------------------------------------------------------------- /OlaCompiler/Backend/Custom/IR/Passes/LoopInvariantCodeMotionPass.cpp: -------------------------------------------------------------------------------- 1 | #include "LoopInvariantCodeMotionPass.h" 2 | #include "LoopAnalysisPass.h" 3 | #include "Backend/Custom/IR/GlobalValue.h" 4 | #include "Backend/Custom/IR/IRBuilder.h" 5 | #include "Backend/Custom/IR/IRContext.h" 6 | 7 | namespace ola 8 | { 9 | Bool LoopInvariantCodeMotionPass::RunOn(Function& F, FunctionAnalysisManager& FAM) 10 | { 11 | LoopInfo const& LI = FAM.GetResult(F); 12 | if (LI.Empty()) 13 | { 14 | return false; 15 | } 16 | Bool Changed = false; 17 | 18 | //#todo this goes only through top level loops 19 | for (Loop* L : LI) 20 | { 21 | BasicBlock* LoopPreheader = L->GetLoopPreheader(); 22 | if (!LoopPreheader) continue; 23 | 24 | Bool LocalChanged; 25 | do { 26 | LocalChanged = false; 27 | for (BasicBlock* BB : L->GetBlocks()) 28 | { 29 | if (BB == L->GetHeader()) 30 | { 31 | continue; 32 | } 33 | 34 | std::vector invariant_instructions; 35 | for (Instruction& Inst : *BB) 36 | { 37 | if (isa(&Inst) || Inst.IsTerminator()) continue; 38 | 39 | if (IsLoopInvariant(&Inst, L)) 40 | { 41 | invariant_instructions.push_back(&Inst); 42 | } 43 | } 44 | 45 | for (Instruction* I : invariant_instructions) 46 | { 47 | I->InsertBefore(LoopPreheader, LoopPreheader->GetTerminator()); 48 | LocalChanged = true; 49 | Changed = true; 50 | } 51 | } 52 | } while (LocalChanged); 53 | } 54 | 55 | return Changed; 56 | } 57 | 58 | Bool LoopInvariantCodeMotionPass::IsLoopInvariant(Instruction* I, Loop const* L) 59 | { 60 | if (isa(I) || isa(I) || isa(I) || I->IsTerminator()) 61 | { 62 | return false; 63 | } 64 | 65 | for (Value* Op : I->Operands()) 66 | { 67 | if (isa(Op)) 68 | { 69 | continue; 70 | } 71 | if (Instruction* OpInst = dyn_cast(Op)) 72 | { 73 | if (L->Contains(OpInst->GetBasicBlock())) 74 | { 75 | return false; 76 | } 77 | } 78 | } 79 | return true; 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /OlaTests/googletest/googletest/test/gtest-typed-test2_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Google Inc. 2 | // All Rights Reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include 31 | 32 | #include "gtest/gtest.h" 33 | #include "test/gtest-typed-test_test.h" 34 | 35 | // Tests that the same type-parameterized test case can be 36 | // instantiated in different translation units linked together. 37 | // (ContainerTest is also instantiated in gtest-typed-test_test.cc.) 38 | INSTANTIATE_TYPED_TEST_SUITE_P(Vector, ContainerTest, 39 | testing::Types >); 40 | -------------------------------------------------------------------------------- /OlaTests/googletest/googlemock/include/gmock/internal/custom/gmock-port.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // Injection point for custom user configurations. See README for details 31 | // 32 | // ** Custom implementation starts here ** 33 | 34 | // IWYU pragma: private, include "gmock/gmock.h" 35 | // IWYU pragma: friend gmock/.* 36 | 37 | #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_ 38 | #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_ 39 | 40 | #endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_ 41 | -------------------------------------------------------------------------------- /OlaTests/googletest/googletest/test/googletest-setuptestsuite-test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include "gtest/gtest.h" 31 | 32 | class SetupFailTest : public ::testing::Test { 33 | protected: 34 | static void SetUpTestSuite() { ASSERT_EQ("", "SET_UP_FAIL"); } 35 | }; 36 | 37 | TEST_F(SetupFailTest, NoopPassingTest) {} 38 | 39 | class TearDownFailTest : public ::testing::Test { 40 | protected: 41 | static void TearDownTestSuite() { ASSERT_EQ("", "TEAR_DOWN_FAIL"); } 42 | }; 43 | 44 | TEST_F(TearDownFailTest, NoopPassingTest) {} 45 | -------------------------------------------------------------------------------- /OlaTests/googletest/googletest/test/gtest_xml_outfile1_test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // gtest_xml_outfile1_test_ writes some xml via TestProperty used by 31 | // gtest_xml_outfiles_test.py 32 | 33 | #include "gtest/gtest.h" 34 | 35 | class PropertyOne : public testing::Test { 36 | protected: 37 | void SetUp() override { RecordProperty("SetUpProp", 1); } 38 | void TearDown() override { RecordProperty("TearDownProp", 1); } 39 | }; 40 | 41 | TEST_F(PropertyOne, TestSomeProperties) { 42 | RecordProperty("TestSomeProperty", 1); 43 | } 44 | --------------------------------------------------------------------------------