-
-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathtarget.cpp
More file actions
71 lines (58 loc) · 1.93 KB
/
target.cpp
File metadata and controls
71 lines (58 loc) · 1.93 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//===-- gen/dcompute/target.cpp -------------------------------------------===//
//
// LDC – the LLVM D compiler
//
// This file is distributed under the BSD-style LDC license. See the LICENSE
// file for details.
//
//===----------------------------------------------------------------------===//
#if LDC_LLVM_SUPPORTED_TARGET_SPIRV || LDC_LLVM_SUPPORTED_TARGET_NVPTX || LDC_LLVM_SUPPORTED_TARGET_AArch64
#include "dmd/dsymbol.h"
#include "dmd/errors.h"
#include "dmd/module.h"
#include "dmd/scope.h"
#include "driver/linker.h"
#include "driver/toobj.h"
#include "driver/cl_options.h"
#include "gen/dcompute/target.h"
#include "gen/llvmhelpers.h"
#include "gen/runtime.h"
#include "ir/irtypestruct.h"
void DComputeTarget::doCodeGen(Module *m) {
// Reset any generated type info for dcompute types.
// The ll types get generated when the host code gets
// gen'd which means the address space info is not
// properly set.
IrTypeStruct::resetDComputeTypes();
// process module members
for (unsigned k = 0; k < m->members->length; k++) {
Dsymbol *dsym = (*m->members)[k];
assert(dsym);
Declaration_codegen(dsym, _ir);
}
if (global.errors)
fatal();
}
void DComputeTarget::emit(Module *m) {
// Reset the global ABI to the target's ABI. Necessary because we have
// multiple ABI we are trying to target. Also reset gIR. These are both
// reused. MAJOR HACK.
gABI = abi;
gIR = _ir;
gTargetMachine = targetMachine;
doCodeGen(m);
}
void DComputeTarget::writeModule() {
addMetadata();
std::string filename;
llvm::raw_string_ostream os(filename);
const bool is64 = global.params.targetTriple->isArch64Bit();
os << opts::dcomputeFilePrefix << '_' << short_name << tversion << '_'
<< (is64 ? 64 : 32) << '.' << binSuffix;
const char *path =
FileName::combine(global.params.objdir.ptr, os.str().c_str());
::writeModule(&_ir->module, path);
delete _ir;
_ir = nullptr;
}
#endif