| 1 | //===--- Library.h - Library calls for llubi ------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file declares common libcalls for llubi. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_TOOLS_LLUBI_LIBRARY_H |
| 14 | #define LLVM_TOOLS_LLUBI_LIBRARY_H |
| 15 | |
| 16 | #include "Context.h" |
| 17 | #include "ExecutorBase.h" |
| 18 | #include "Value.h" |
| 19 | #include <optional> |
| 20 | #include <string> |
| 21 | |
| 22 | namespace llvm::ubi { |
| 23 | |
| 24 | class Library { |
| 25 | Context &Ctx; |
| 26 | EventHandler &Handler; |
| 27 | const DataLayout &DL; |
| 28 | ExecutorBase &Executor; |
| 29 | |
| 30 | std::optional<std::string> readStringFromMemory(const Pointer &Ptr); |
| 31 | |
| 32 | AnyValue executeMalloc(StringRef Name, Type *Type, ArrayRef<AnyValue> Args, |
| 33 | MemAllocKind AllocKind); |
| 34 | AnyValue executeCalloc(StringRef Name, Type *Type, ArrayRef<AnyValue> Args, |
| 35 | MemAllocKind AllocKind); |
| 36 | AnyValue executeFree(ArrayRef<AnyValue> Args); |
| 37 | AnyValue executePuts(ArrayRef<AnyValue> Args); |
| 38 | AnyValue executePrintf(ArrayRef<AnyValue> Args); |
| 39 | AnyValue executeExit(ArrayRef<AnyValue> Args); |
| 40 | AnyValue executeAbort(); |
| 41 | AnyValue executeTerminate(); |
| 42 | |
| 43 | public: |
| 44 | Library(Context &Ctx, EventHandler &Handler, const DataLayout &DL, |
| 45 | ExecutorBase &Executor); |
| 46 | |
| 47 | /// Simulates a libcall. Returns std::nullopt if an unsupported LibFunc is |
| 48 | /// passed. Note that the caller is responsible for ensuring the types and |
| 49 | /// number of the arguments are correct. |
| 50 | std::optional<AnyValue> executeLibcall(LibFunc LF, StringRef Name, Type *Type, |
| 51 | ArrayRef<AnyValue> Args); |
| 52 | }; |
| 53 | |
| 54 | } // namespace llvm::ubi |
| 55 | |
| 56 | #endif // LLVM_TOOLS_LLUBI_LIBRARY_H |
| 57 | |