Hooks for tracing/printfs. replace %T with the type-specific format specifier. For some reason, float/double literals are getting lost when printing with the generic printf. so, use a wrapper instead.
| 1418 | // For some reason, float/double literals are getting lost when printing with the generic |
| 1419 | // printf. so, use a wrapper instead. |
| 1420 | std::string LLVMGenerator::ReplaceFormatInTrace(const std::string& in_msg, |
| 1421 | llvm::Value* value, |
| 1422 | std::string* print_fn) { |
| 1423 | std::string msg = in_msg; |
| 1424 | std::size_t pos = msg.find("%T"); |
| 1425 | if (pos == std::string::npos) { |
| 1426 | DCHECK(0); |
| 1427 | return msg; |
| 1428 | } |
| 1429 | |
| 1430 | llvm::Type* type = value->getType(); |
| 1431 | const char* fmt = ""; |
| 1432 | if (type->isIntegerTy(1) || type->isIntegerTy(8) || type->isIntegerTy(16) || |
| 1433 | type->isIntegerTy(32)) { |
| 1434 | fmt = "%d"; |
| 1435 | } else if (type->isIntegerTy(64)) { |
| 1436 | // bigint |
| 1437 | fmt = "%lld"; |
| 1438 | } else if (type->isFloatTy()) { |
| 1439 | // float |
| 1440 | fmt = "%f"; |
| 1441 | *print_fn = "print_float"; |
| 1442 | } else if (type->isDoubleTy()) { |
| 1443 | // float |
| 1444 | fmt = "%lf"; |
| 1445 | *print_fn = "print_double"; |
| 1446 | } else if (type->isPointerTy()) { |
| 1447 | // string |
| 1448 | fmt = "%s"; |
| 1449 | } else { |
| 1450 | DCHECK(0); |
| 1451 | } |
| 1452 | msg.replace(pos, 2, fmt); |
| 1453 | return msg; |
| 1454 | } |
| 1455 | |
| 1456 | void LLVMGenerator::AddTrace(const std::string& msg, llvm::Value* value) { |
| 1457 | if (!enable_ir_traces_) { |