libTriton version 1.0 build 1592
Loading...
Searching...
No Matches
liftingToLLVM.cpp
Go to the documentation of this file.
1
2/*
3** Copyright (C) - Triton
4**
5** This program is under the terms of the Apache License 2.0.
6*/
7
8#include <memory>
9#include <ostream>
10#include <string>
11
12#include <triton/astContext.hpp>
16
17#include <llvm/IR/LLVMContext.h>
18#include <llvm/IR/Module.h>
19
20
21
22namespace triton {
23 namespace engines {
24 namespace lifters {
25
28
29
30 std::ostream& LiftingToLLVM::liftToLLVM(std::ostream& stream, const triton::engines::symbolic::SharedSymbolicExpression& expr, const char* fname, bool optimize) {
31 this->liftToLLVM(stream, expr->getAst(), fname, optimize);
32 return stream;
33 }
34
35
36 std::ostream& LiftingToLLVM::liftToLLVM(std::ostream& stream, const triton::ast::SharedAbstractNode& node, const char* fname, bool optimize) {
37 /* The LLVM context */
38 llvm::LLVMContext context;
39
40 /* The lifter Triton -> LLVM */
41 triton::ast::TritonToLLVM lifter(context);
42
43 /* Lift AST to LLVM IR */
44 auto llvmModule = lifter.convert(node, fname, optimize);
45
46 /* Print the LLVM module into the stream */
47 std::string dump;
48 llvm::raw_string_ostream llvmStream(dump);
49 llvmModule->print(llvmStream, nullptr);
50 stream << dump;
51
52 return stream;
53 }
54
55
57 llvm::LLVMContext context;
58
59 triton::ast::TritonToLLVM ttllvm(context);
60 triton::ast::LLVMToTriton llvmtt(node->getContext());
61
62 auto llvmModule = ttllvm.convert(node, "__tmp", true); /* from triton to llvm */
63 return llvmtt.convert(llvmModule.get(), "__tmp"); /* from llvm to triton */
64 }
65
66 }; /* lifters namespace */
67 }; /* engines namespace */
68}; /* triton namespace */
Converts a LLVM IR to a Triton AST.
TRITON_EXPORT triton::ast::SharedAbstractNode convert(llvm::Module *llvmModule, const char *fname="__triton")
Converts a given function from an LLVM module to a Triton AST.
Converts a Triton's AST to LVM IR.
TRITON_EXPORT std::shared_ptr< llvm::Module > convert(const triton::ast::SharedAbstractNode &node, const char *fname="__triton", bool optimize=false)
Lifts a symbolic expression and all its references to LLVM format. fname represents the name of the L...
TRITON_EXPORT triton::ast::SharedAbstractNode simplifyAstViaLLVM(const triton::ast::SharedAbstractNode &node) const
Lifts and simplify an AST using LLVM.
TRITON_EXPORT LiftingToLLVM()
Constructor.
TRITON_EXPORT std::ostream & liftToLLVM(std::ostream &stream, const triton::engines::symbolic::SharedSymbolicExpression &expr, const char *fname="__triton", bool optimize=false)
Lifts a symbolic expression and all its references to LLVM format. fname represents the name of the L...
std::shared_ptr< triton::ast::AbstractNode > SharedAbstractNode
Shared Abstract Node.
Definition ast.hpp:59
std::shared_ptr< triton::engines::symbolic::SymbolicExpression > SharedSymbolicExpression
Shared Symbolic Expression.
Definition ast.hpp:40
The Triton namespace.