Mercurial > projects > ldc
comparison gen/llvmhelpers.cpp @ 365:bfb9d28f045a trunk
[svn r386] Fixed broken DtoBoolean.
Some code cleanup.
author | lindquist |
---|---|
date | Tue, 15 Jul 2008 00:17:03 +0200 |
parents | 4d7495038ae8 |
children | 051ab876fe11 |
comparison
equal
deleted
inserted
replaced
364:8014dbd24605 | 365:bfb9d28f045a |
---|---|
2 #include "llvm/Target/TargetMachineRegistry.h" | 2 #include "llvm/Target/TargetMachineRegistry.h" |
3 | 3 |
4 #include "mars.h" | 4 #include "mars.h" |
5 #include "init.h" | 5 #include "init.h" |
6 #include "id.h" | 6 #include "id.h" |
7 #include "expression.h" | |
7 | 8 |
8 #include "gen/tollvm.h" | 9 #include "gen/tollvm.h" |
9 #include "gen/llvmhelpers.h" | 10 #include "gen/llvmhelpers.h" |
10 #include "gen/irstate.h" | 11 #include "gen/irstate.h" |
11 #include "gen/runtime.h" | 12 #include "gen/runtime.h" |
1310 else | 1311 else |
1311 { | 1312 { |
1312 global.params.llvmArch = const_cast<char*>(e->Name); | 1313 global.params.llvmArch = const_cast<char*>(e->Name); |
1313 } | 1314 } |
1314 } | 1315 } |
1316 | |
1317 ////////////////////////////////////////////////////////////////////////////////////////// | |
1318 | |
1319 LLValue* DtoBoolean(DValue* dval) | |
1320 { | |
1321 Type* dtype = dval->getType()->toBasetype(); | |
1322 TY ty = dtype->ty; | |
1323 | |
1324 // integer | |
1325 if (dtype->isintegral()) | |
1326 { | |
1327 LLValue* val = dval->getRVal(); | |
1328 if (val->getType() == LLType::Int1Ty) | |
1329 return val; | |
1330 else { | |
1331 LLValue* zero = LLConstantInt::get(val->getType(), 0, false); | |
1332 return gIR->ir->CreateICmpNE(val, zero, "tmp"); | |
1333 } | |
1334 } | |
1335 // complex | |
1336 else if (dtype->iscomplex()) | |
1337 { | |
1338 // huh? | |
1339 return DtoComplexEquals(TOKnotequal, dval, DtoComplex(dtype, new DNullValue(Type::tint8, llvm::ConstantInt::get(LLType::Int8Ty, 0)))); | |
1340 } | |
1341 // floating point | |
1342 else if (dtype->isfloating()) | |
1343 { | |
1344 LLValue* val = dval->getRVal(); | |
1345 LLValue* zero = LLConstant::getNullValue(val->getType()); | |
1346 return gIR->ir->CreateFCmpONE(val, zero, "tmp"); | |
1347 } | |
1348 // pointer/class | |
1349 else if (ty == Tpointer || ty == Tclass) { | |
1350 LLValue* val = dval->getRVal(); | |
1351 LLValue* zero = LLConstant::getNullValue(val->getType()); | |
1352 return gIR->ir->CreateICmpNE(val, zero, "tmp"); | |
1353 } | |
1354 // dynamic array | |
1355 else if (ty == Tarray) | |
1356 { | |
1357 // return (arr.length != 0) | |
1358 return gIR->ir->CreateICmpNE(DtoArrayLen(dval), DtoConstSize_t(0), "tmp"); | |
1359 } | |
1360 // delegate | |
1361 else if (ty == Tdelegate) | |
1362 { | |
1363 // return (dg !is null) | |
1364 return DtoDelegateEquals(TOKnotequal, dval->getRVal(), NULL); | |
1365 } | |
1366 // unknown | |
1367 std::cout << "unsupported -> bool : " << dtype->toChars() << '\n'; | |
1368 assert(0); | |
1369 return 0; | |
1370 } |