LLVM 24.0.0git
Library.h
Go to the documentation of this file.
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 "ExecutorBase.h"
19#include <optional>
20#include <string>
21
22namespace llvm::ubi {
23
24class 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, unsigned AS);
37 AnyValue executeMemTransfer(ArrayRef<AnyValue> Args, Intrinsic::ID IID);
38 AnyValue executeMemset(ArrayRef<AnyValue> Args);
39 AnyValue executePuts(ArrayRef<AnyValue> Args);
40 AnyValue executePrintf(ArrayRef<AnyValue> Args);
41 AnyValue executeExit(ArrayRef<AnyValue> Args);
42 AnyValue executeAbort();
43 AnyValue executeTerminate();
44
45public:
46 Library(Context &Ctx, EventHandler &Handler, const DataLayout &DL,
47 ExecutorBase &Executor);
48
49 /// Simulates a libcall. Returns std::nullopt if an unsupported LibFunc is
50 /// passed. Note that the caller is responsible for ensuring the types and
51 /// number of the arguments are correct.
52 std::optional<AnyValue> executeLibcall(LibFunc LF, StringRef Name,
53 FunctionType *FuncType,
55};
56
57} // namespace llvm::ubi
58
59#endif // LLVM_TOOLS_LLUBI_LIBRARY_H
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Class to represent function types.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
The global context for the interpreter.
Definition Context.h:227
An interface for handling events and managing outputs during interpretation.
Definition Context.h:166
std::optional< AnyValue > executeLibcall(LibFunc LF, StringRef Name, FunctionType *FuncType, ArrayRef< AnyValue > Args)
Simulates a libcall.
Definition Library.cpp:365
Library(Context &Ctx, EventHandler &Handler, const DataLayout &DL, ExecutorBase &Executor)
Definition Library.cpp:27