-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EVM] Adding lld-c API to lld-as-library functionality.
- Loading branch information
1 parent
66b9122
commit c4b7b65
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//==----- EVMFrameLowering.h - Define frame lowering for EVM --*- C++ -*----==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This header declares the C interface to the lld-as-a-library, which can be | ||
// used to invoke LLD functionality. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLD_C_LLDASLIBRARYC_H | ||
#define LLD_C_LLDASLIBRARYC_H | ||
|
||
#include "llvm-c/ExternC.h" | ||
#include "llvm-c/Types.h" | ||
|
||
LLVM_C_EXTERN_C_BEGIN | ||
|
||
/** Performs linkage a operation of an object code via lld-as-a-library. | ||
Input/output files are transferred via memory buffers. */ | ||
|
||
LLVMBool llvmLinkMemoryBuffers(LLVMMemoryBufferRef *inMemBufs, size_t numInBufs, | ||
LLVMMemoryBufferRef *outMemBuf, | ||
const char **lldArgs, size_t numLldArgs); | ||
|
||
LLVM_C_EXTERN_C_END | ||
|
||
#endif // LLD_C_LLDASLIBRARYC_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
add_lld_library(lldC | ||
LLDAsLibraryC.cpp | ||
|
||
${LLD_INCLUDE_DIR}/lld/Common | ||
|
||
LINK_COMPONENTS | ||
Core | ||
|
||
DEPENDS | ||
intrinsics_gen | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "lld-c/LLDAsLibraryC.h" | ||
#include "lld/Common/Driver.h" | ||
#include "lld/Common/ErrorHandler.h" | ||
#include "llvm/ADT/SmallString.h" | ||
#include "llvm/Support/MemoryBuffer.h" | ||
#include "llvm-c/Core.h" | ||
|
||
LLD_HAS_DRIVER_MEM_BUF(elf) | ||
|
||
LLVMBool llvmLinkMemoryBuffers(LLVMMemoryBufferRef *inMemBufs, size_t numInBufs, | ||
LLVMMemoryBufferRef *outMemBuf, | ||
const char **lldArgs, size_t numLldArgs) { | ||
llvm::SmallVector<llvm::MemoryBufferRef> inData(numInBufs); | ||
for (unsigned idx = 0; idx < numInBufs; ++idx) | ||
inData[idx] = *llvm::unwrap(inMemBufs[idx]); | ||
|
||
llvm::SmallVector<const char *> args(numLldArgs); | ||
for (unsigned idx = 0; idx < numLldArgs; ++idx) | ||
args[idx] = lldArgs[idx]; | ||
|
||
llvm::SmallString<0> codeString; | ||
llvm::raw_svector_ostream ostream(codeString); | ||
const lld::Result s = | ||
lld::lldMainMemBuf(inData, &ostream, args, llvm::outs(), llvm::errs(), | ||
{{lld::Gnu, &lld::elf::linkMemBuf}}); | ||
llvm::StringRef data = ostream.str(); | ||
*outMemBuf = | ||
LLVMCreateMemoryBufferWithMemoryRangeCopy(data.data(), data.size(), ""); | ||
|
||
return !s.retCode && s.canRunAgain; | ||
} |