blob: 67a24ece96526e23b8c1035ad34b208d0ce7e490 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
//===- ChildTarget.inc - Child process for external JIT execution for Unix -==//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Implementation of the Unix-specific parts of the ChildTarget class
// which executes JITed code in a separate process from where it was built.
//
//===----------------------------------------------------------------------===//
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
namespace {
struct ConnectionData_t {
int InputPipe;
int OutputPipe;
ConnectionData_t(int in, int out) : InputPipe(in), OutputPipe(out) {}
};
} // namespace
LLIChildTarget::~LLIChildTarget() {
delete static_cast<ConnectionData_t *>(ConnectionData);
}
// OS-specific methods
void LLIChildTarget::initializeConnection() {
// Store the parent ends of the pipes
ConnectionData = (void*)new ConnectionData_t(STDIN_FILENO, STDOUT_FILENO);
}
int LLIChildTarget::WriteBytes(const void *Data, size_t Size) {
return write(((ConnectionData_t*)ConnectionData)->OutputPipe, Data, Size);
}
int LLIChildTarget::ReadBytes(void *Data, size_t Size) {
return read(((ConnectionData_t*)ConnectionData)->InputPipe, Data, Size);
}
|