mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-02 16:11:08 +03:00
Range-ify usages of front-end Arrays
This commit is contained in:
parent
9fd7fa2d90
commit
383c2d3a59
14 changed files with 46 additions and 46 deletions
|
@ -346,8 +346,9 @@ int createStaticLibrary() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// object files
|
// object files
|
||||||
for (unsigned i = 0; i < global.params.objfiles->dim; i++)
|
for (auto objfile : *global.params.objfiles) {
|
||||||
args.push_back((*global.params.objfiles)[i]);
|
args.push_back(objfile);
|
||||||
|
}
|
||||||
|
|
||||||
// .res/.def files for lib.exe
|
// .res/.def files for lib.exe
|
||||||
if (isTargetMSVC) {
|
if (isTargetMSVC) {
|
||||||
|
|
|
@ -173,8 +173,9 @@ void ArgsBuilder::addLTOLinkFlags() {
|
||||||
void ArgsBuilder::build(llvm::StringRef outputPath,
|
void ArgsBuilder::build(llvm::StringRef outputPath,
|
||||||
llvm::cl::boolOrDefault fullyStaticFlag) {
|
llvm::cl::boolOrDefault fullyStaticFlag) {
|
||||||
// object files
|
// object files
|
||||||
for (unsigned i = 0; i < global.params.objfiles->dim; i++)
|
for (auto objfile : *global.params.objfiles) {
|
||||||
args.push_back((*global.params.objfiles)[i]);
|
args.push_back(objfile);
|
||||||
|
}
|
||||||
|
|
||||||
// Link with profile-rt library when generating an instrumented binary.
|
// Link with profile-rt library when generating an instrumented binary.
|
||||||
// profile-rt uses Phobos (MD5 hashing) and therefore must be passed on the
|
// profile-rt uses Phobos (MD5 hashing) and therefore must be passed on the
|
||||||
|
@ -191,8 +192,9 @@ void ArgsBuilder::build(llvm::StringRef outputPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
// user libs
|
// user libs
|
||||||
for (unsigned i = 0; i < global.params.libfiles->dim; i++)
|
for (auto libfile : *global.params.libfiles) {
|
||||||
args.push_back((*global.params.libfiles)[i]);
|
args.push_back(libfile);
|
||||||
|
}
|
||||||
|
|
||||||
if (global.params.dll) {
|
if (global.params.dll) {
|
||||||
args.push_back("-shared");
|
args.push_back("-shared");
|
||||||
|
@ -217,8 +219,8 @@ void ArgsBuilder::build(llvm::StringRef outputPath,
|
||||||
addUserSwitches();
|
addUserSwitches();
|
||||||
|
|
||||||
// libs added via pragma(lib, libname)
|
// libs added via pragma(lib, libname)
|
||||||
for (unsigned i = 0; i < global.params.linkswitches->dim; i++) {
|
for (auto ls : *global.params.linkswitches) {
|
||||||
args.push_back((*global.params.linkswitches)[i]);
|
args.push_back(ls);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global.params.targetTriple->getOS() == llvm::Triple::Linux) {
|
if (global.params.targetTriple->getOS() == llvm::Triple::Linux) {
|
||||||
|
|
|
@ -100,8 +100,9 @@ int linkObjToBinaryMSVC(llvm::StringRef outputPath, bool useInternalLinker,
|
||||||
args.push_back(("/OUT:" + outputPath).str());
|
args.push_back(("/OUT:" + outputPath).str());
|
||||||
|
|
||||||
// object files
|
// object files
|
||||||
for (unsigned i = 0; i < global.params.objfiles->dim; i++)
|
for (auto objfile : *global.params.objfiles) {
|
||||||
args.push_back((*global.params.objfiles)[i]);
|
args.push_back(objfile);
|
||||||
|
}
|
||||||
|
|
||||||
// .res/.def files
|
// .res/.def files
|
||||||
if (global.params.resfile)
|
if (global.params.resfile)
|
||||||
|
@ -118,8 +119,9 @@ int linkObjToBinaryMSVC(llvm::StringRef outputPath, bool useInternalLinker,
|
||||||
}
|
}
|
||||||
|
|
||||||
// user libs
|
// user libs
|
||||||
for (unsigned i = 0; i < global.params.libfiles->dim; i++)
|
for (auto libfile : *global.params.libfiles) {
|
||||||
args.push_back((*global.params.libfiles)[i]);
|
args.push_back(libfile);
|
||||||
|
}
|
||||||
|
|
||||||
// additional linker switches
|
// additional linker switches
|
||||||
auto addSwitch = [&](std::string str) {
|
auto addSwitch = [&](std::string str) {
|
||||||
|
@ -138,8 +140,8 @@ int linkObjToBinaryMSVC(llvm::StringRef outputPath, bool useInternalLinker,
|
||||||
addSwitch(str);
|
addSwitch(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned i = 0; i < global.params.linkswitches->dim; i++) {
|
for (auto ls : *global.params.linkswitches) {
|
||||||
addSwitch(global.params.linkswitches->data[i]);
|
addSwitch(ls);
|
||||||
}
|
}
|
||||||
|
|
||||||
// default libs
|
// default libs
|
||||||
|
|
|
@ -404,8 +404,8 @@ void parseCommandLine(int argc, char **argv, Strings &sourceFiles,
|
||||||
const auto toWinPaths = [](Strings *paths) {
|
const auto toWinPaths = [](Strings *paths) {
|
||||||
if (!paths)
|
if (!paths)
|
||||||
return;
|
return;
|
||||||
for (unsigned i = 0; i < paths->dim; ++i)
|
for (auto &path : *paths)
|
||||||
(*paths)[i] = dupPathString((*paths)[i]);
|
path = dupPathString(path);
|
||||||
};
|
};
|
||||||
toWinPaths(global.params.imppath);
|
toWinPaths(global.params.imppath);
|
||||||
toWinPaths(global.params.fileImppath);
|
toWinPaths(global.params.fileImppath);
|
||||||
|
|
|
@ -480,8 +480,7 @@ void CompoundAsmStatement_toIR(CompoundAsmStatement *stmt, IRState *p) {
|
||||||
|
|
||||||
// do asm statements
|
// do asm statements
|
||||||
for (unsigned i = 0; i < stmt->statements->dim; i++) {
|
for (unsigned i = 0; i < stmt->statements->dim; i++) {
|
||||||
Statement *s = (*stmt->statements)[i];
|
if (Statement *s = (*stmt->statements)[i]) {
|
||||||
if (s) {
|
|
||||||
Statement_toIR(s, p);
|
Statement_toIR(s, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1177,11 +1177,9 @@ void ldc::DIBuilder::EmitLocalVariable(llvm::Value *ll, VarDeclaration *vd,
|
||||||
size_t argNo = 0;
|
size_t argNo = 0;
|
||||||
if (fd->vthis != vd) {
|
if (fd->vthis != vd) {
|
||||||
assert(fd->parameters);
|
assert(fd->parameters);
|
||||||
for (argNo = 0; argNo < fd->parameters->dim; argNo++) {
|
auto it = std::find(fd->parameters->begin(), fd->parameters->end(), vd);
|
||||||
if ((*fd->parameters)[argNo] == vd)
|
assert(it != fd->parameters->end());
|
||||||
break;
|
argNo = it - fd->parameters->begin();
|
||||||
}
|
|
||||||
assert(argNo < fd->parameters->dim);
|
|
||||||
if (fd->vthis)
|
if (fd->vthis)
|
||||||
argNo++;
|
argNo++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,11 +165,10 @@ DValue *DtoInlineIRExpr(Loc &loc, FuncDeclaration *fdecl,
|
||||||
fun->setCallingConv(llvm::CallingConv::C);
|
fun->setCallingConv(llvm::CallingConv::C);
|
||||||
|
|
||||||
// Build the runtime arguments
|
// Build the runtime arguments
|
||||||
size_t n = arguments->dim;
|
|
||||||
llvm::SmallVector<llvm::Value *, 8> args;
|
llvm::SmallVector<llvm::Value *, 8> args;
|
||||||
args.reserve(n);
|
args.reserve(arguments->dim);
|
||||||
for (size_t i = 0; i < n; i++) {
|
for (auto arg : *arguments) {
|
||||||
args.push_back(DtoRVal((*arguments)[i]));
|
args.push_back(DtoRVal(arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::Value *rv = gIR->ir->CreateCall(fun, args);
|
llvm::Value *rv = gIR->ir->CreateCall(fun, args);
|
||||||
|
|
|
@ -988,8 +988,7 @@ DValue *DtoDeclarationExp(Dsymbol *declaration) {
|
||||||
} else if (AttribDeclaration *a = declaration->isAttribDeclaration()) {
|
} else if (AttribDeclaration *a = declaration->isAttribDeclaration()) {
|
||||||
Logger::println("AttribDeclaration");
|
Logger::println("AttribDeclaration");
|
||||||
// choose the right set in case this is a conditional declaration
|
// choose the right set in case this is a conditional declaration
|
||||||
Dsymbols *d = a->include(nullptr, nullptr);
|
if (auto d = a->include(nullptr, nullptr)) {
|
||||||
if (d) {
|
|
||||||
for (unsigned i = 0; i < d->dim; ++i) {
|
for (unsigned i = 0; i < d->dim; ++i) {
|
||||||
DtoDeclarationExp((*d)[i]);
|
DtoDeclarationExp((*d)[i]);
|
||||||
}
|
}
|
||||||
|
@ -1004,7 +1003,7 @@ DValue *DtoDeclarationExp(Dsymbol *declaration) {
|
||||||
assert(tupled->isexp && "Non-expression tuple decls not handled yet.");
|
assert(tupled->isexp && "Non-expression tuple decls not handled yet.");
|
||||||
assert(tupled->objects);
|
assert(tupled->objects);
|
||||||
for (unsigned i = 0; i < tupled->objects->dim; ++i) {
|
for (unsigned i = 0; i < tupled->objects->dim; ++i) {
|
||||||
DsymbolExp *exp = static_cast<DsymbolExp *>(tupled->objects->data[i]);
|
auto exp = static_cast<DsymbolExp *>((*tupled->objects)[i]);
|
||||||
DtoDeclarationExp(exp->s);
|
DtoDeclarationExp(exp->s);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -58,8 +58,8 @@ std::string hashSymbolName(llvm::StringRef name, Dsymbol *symb) {
|
||||||
auto moddecl = symb->getModule()->md;
|
auto moddecl = symb->getModule()->md;
|
||||||
assert(moddecl);
|
assert(moddecl);
|
||||||
if (auto packages = moddecl->packages) {
|
if (auto packages = moddecl->packages) {
|
||||||
for (size_t i = 0; i < packages->dim; ++i) {
|
for (auto package : *packages) {
|
||||||
llvm::StringRef str = (*packages)[i]->toChars();
|
llvm::StringRef str = package->toChars();
|
||||||
ret += std::to_string(str.size());
|
ret += std::to_string(str.size());
|
||||||
ret += str;
|
ret += str;
|
||||||
}
|
}
|
||||||
|
|
|
@ -718,6 +718,7 @@ void codegenModule(IRState *irs, Module *m) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// process module members
|
// process module members
|
||||||
|
// NOTE: m->members may grow during codegen
|
||||||
for (unsigned k = 0; k < m->members->dim; k++) {
|
for (unsigned k = 0; k < m->members->dim; k++) {
|
||||||
Dsymbol *dsym = (*m->members)[k];
|
Dsymbol *dsym = (*m->members)[k];
|
||||||
assert(dsym);
|
assert(dsym);
|
||||||
|
|
|
@ -1210,7 +1210,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// do statements
|
// do statements
|
||||||
Statement **stmts = static_cast<Statement **>(stmt->statements->data);
|
Statement **stmts = stmt->statements->data;
|
||||||
|
|
||||||
for (size_t i = 0; i < nstmt; i++) {
|
for (size_t i = 0; i < nstmt; i++) {
|
||||||
Statement *s = stmts[i];
|
Statement *s = stmts[i];
|
||||||
|
|
|
@ -591,8 +591,8 @@ public:
|
||||||
std::map<VarDeclaration *, llvm::Constant *> varInits;
|
std::map<VarDeclaration *, llvm::Constant *> varInits;
|
||||||
const size_t nexprs = e->elements->dim;
|
const size_t nexprs = e->elements->dim;
|
||||||
for (size_t i = 0; i < nexprs; i++) {
|
for (size_t i = 0; i < nexprs; i++) {
|
||||||
if ((*e->elements)[i]) {
|
if (auto elem = (*e->elements)[i]) {
|
||||||
LLConstant *c = toConstElem((*e->elements)[i]);
|
LLConstant *c = toConstElem(elem);
|
||||||
// extend i1 to i8
|
// extend i1 to i8
|
||||||
if (c->getType() == LLType::getInt1Ty(p->context()))
|
if (c->getType() == LLType::getInt1Ty(p->context()))
|
||||||
c = llvm::ConstantExpr::getZExt(c, LLType::getInt8Ty(p->context()));
|
c = llvm::ConstantExpr::getZExt(c, LLType::getInt8Ty(p->context()));
|
||||||
|
@ -641,12 +641,12 @@ public:
|
||||||
cur = classHierachy.top();
|
cur = classHierachy.top();
|
||||||
classHierachy.pop();
|
classHierachy.pop();
|
||||||
for (size_t j = 0; j < cur->fields.dim; ++j) {
|
for (size_t j = 0; j < cur->fields.dim; ++j) {
|
||||||
if ((*value->elements)[i]) {
|
if (auto elem = (*value->elements)[i]) {
|
||||||
VarDeclaration *field = cur->fields[j];
|
VarDeclaration *field = cur->fields[j];
|
||||||
IF_LOG Logger::println("Getting initializer for: %s",
|
IF_LOG Logger::println("Getting initializer for: %s",
|
||||||
field->toChars());
|
field->toChars());
|
||||||
LOG_SCOPE;
|
LOG_SCOPE;
|
||||||
varInits[field] = toConstElem((*value->elements)[i]);
|
varInits[field] = toConstElem(elem);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
14
gen/toir.cpp
14
gen/toir.cpp
|
@ -1466,8 +1466,8 @@ public:
|
||||||
size_t ndims = e->arguments->dim;
|
size_t ndims = e->arguments->dim;
|
||||||
std::vector<DValue *> dims;
|
std::vector<DValue *> dims;
|
||||||
dims.reserve(ndims);
|
dims.reserve(ndims);
|
||||||
for (size_t i = 0; i < ndims; ++i) {
|
for (auto arg : *e->arguments) {
|
||||||
dims.push_back(toElem((*e->arguments)[i]));
|
dims.push_back(toElem(arg));
|
||||||
}
|
}
|
||||||
result = DtoNewMulDimDynArray(e->loc, e->newtype, &dims[0], ndims);
|
result = DtoNewMulDimDynArray(e->loc, e->newtype, &dims[0], ndims);
|
||||||
}
|
}
|
||||||
|
@ -2272,7 +2272,7 @@ public:
|
||||||
auto global = new llvm::GlobalVariable(
|
auto global = new llvm::GlobalVariable(
|
||||||
gIR->module, init->getType(), true,
|
gIR->module, init->getType(), true,
|
||||||
llvm::GlobalValue::InternalLinkage, init, ".immutablearray");
|
llvm::GlobalValue::InternalLinkage, init, ".immutablearray");
|
||||||
result = new DSliceValue(arrayType, DtoConstSize_t(e->elements->dim),
|
result = new DSliceValue(arrayType, DtoConstSize_t(len),
|
||||||
DtoBitCast(global, getPtrToType(llElemType)));
|
DtoBitCast(global, getPtrToType(llElemType)));
|
||||||
} else {
|
} else {
|
||||||
DSliceValue *dynSlice = DtoNewDynArray(
|
DSliceValue *dynSlice = DtoNewDynArray(
|
||||||
|
@ -2431,8 +2431,8 @@ public:
|
||||||
keysInits.reserve(e->keys->dim);
|
keysInits.reserve(e->keys->dim);
|
||||||
valuesInits.reserve(e->keys->dim);
|
valuesInits.reserve(e->keys->dim);
|
||||||
for (size_t i = 0, n = e->keys->dim; i < n; ++i) {
|
for (size_t i = 0, n = e->keys->dim; i < n; ++i) {
|
||||||
Expression *ekey = e->keys->tdata()[i];
|
Expression *ekey = (*e->keys)[i];
|
||||||
Expression *eval = e->values->tdata()[i];
|
Expression *eval = (*e->values)[i];
|
||||||
IF_LOG Logger::println("(%llu) aa[%s] = %s",
|
IF_LOG Logger::println("(%llu) aa[%s] = %s",
|
||||||
static_cast<unsigned long long>(i),
|
static_cast<unsigned long long>(i),
|
||||||
ekey->toChars(), eval->toChars());
|
ekey->toChars(), eval->toChars());
|
||||||
|
@ -2585,8 +2585,8 @@ public:
|
||||||
|
|
||||||
std::vector<LLType *> types;
|
std::vector<LLType *> types;
|
||||||
types.reserve(e->exps->dim);
|
types.reserve(e->exps->dim);
|
||||||
for (size_t i = 0; i < e->exps->dim; i++) {
|
for (auto exp : *e->exps) {
|
||||||
types.push_back(DtoMemType((*e->exps)[i]->type));
|
types.push_back(DtoMemType(exp->type));
|
||||||
}
|
}
|
||||||
LLValue *val =
|
LLValue *val =
|
||||||
DtoRawAlloca(LLStructType::get(gIR->context(), types), 0, ".tuple");
|
DtoRawAlloca(LLStructType::get(gIR->context(), types), 0, ".tuple");
|
||||||
|
|
|
@ -486,8 +486,7 @@ public:
|
||||||
|
|
||||||
LLType *tiTy = DtoType(Type::dtypeinfo->type);
|
LLType *tiTy = DtoType(Type::dtypeinfo->type);
|
||||||
|
|
||||||
for (size_t i = 0; i < dim; i++) {
|
for (auto arg : *tu->arguments) {
|
||||||
Parameter *arg = static_cast<Parameter *>(tu->arguments->data[i]);
|
|
||||||
arrInits.push_back(DtoTypeInfoOf(arg->type, true));
|
arrInits.push_back(DtoTypeInfoOf(arg->type, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue