mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-07 19:36:06 +03:00
Refactoring: Improve Ir{Aggr,Class,Struct} encapsulation
This commit is contained in:
parent
a765bf8901
commit
e9021fd6c8
6 changed files with 122 additions and 112 deletions
|
@ -51,19 +51,26 @@ bool IrAggr::suppressTypeInfo() const {
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LLConstant *&IrAggr::getInitSymbol() {
|
||||
if (init) {
|
||||
return init;
|
||||
LLConstant *IrAggr::getInitSymbol(bool define) {
|
||||
if (!init) {
|
||||
const auto irMangle = getIRMangledInitSymbolName(aggrdecl);
|
||||
|
||||
auto initGlobal =
|
||||
declareGlobal(aggrdecl->loc, gIR->module, getLLStructType(), irMangle,
|
||||
/*isConstant=*/true);
|
||||
initGlobal->setAlignment(LLMaybeAlign(DtoAlignment(type)));
|
||||
|
||||
init = initGlobal;
|
||||
}
|
||||
|
||||
// create the initZ symbol
|
||||
const auto irMangle = getIRMangledInitSymbolName(aggrdecl);
|
||||
|
||||
auto initGlobal = declareGlobal(aggrdecl->loc, gIR->module, getLLStructType(),
|
||||
irMangle, /*isConstant=*/true);
|
||||
initGlobal->setAlignment(LLMaybeAlign(DtoAlignment(type)));
|
||||
|
||||
init = initGlobal;
|
||||
if (define) {
|
||||
auto initConstant = getDefaultInit();
|
||||
auto initGlobal = llvm::dyn_cast<LLGlobalVariable>(init);
|
||||
if (initGlobal // NOT a bitcast pointer to helper global
|
||||
&& !initGlobal->hasInitializer()) {
|
||||
init = gIR->setGlobalVarInitializer(initGlobal, initConstant, aggrdecl);
|
||||
}
|
||||
}
|
||||
|
||||
return init;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue