Mercurial > projects > ldc
comparison gen/asmstmt.cpp @ 969:fe2d9bb7078d
Add some extra debug output that's useful in diagnosing inline assembler bugs.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Mon, 16 Feb 2009 23:56:56 +0100 |
parents | 7e669954db7d |
children | 985104c0f1db |
comparison
equal
deleted
inserted
replaced
968:a9feaed801d7 | 969:fe2d9bb7078d |
---|---|
344 } else if (*p == '$') | 344 } else if (*p == '$') |
345 pct = true; | 345 pct = true; |
346 ++p; | 346 ++p; |
347 } | 347 } |
348 | 348 |
349 Logger::println("final asm: %.*s", code->insnTemplateLen, code->insnTemplate); | 349 if (Logger::enabled()) { |
350 Logger::println("final asm: %.*s", code->insnTemplateLen, code->insnTemplate); | |
351 std::ostringstream ss; | |
352 | |
353 ss << "GCC-style output constraints: {"; | |
354 typedef std::deque<std::string>::iterator It; | |
355 for (It i = output_constraints.begin(), e = output_constraints.end(); i != e; ++i) { | |
356 ss << " " << *i; | |
357 } | |
358 ss << " }"; | |
359 Logger::println("%s", ss.str().c_str()); | |
360 | |
361 ss.str(""); | |
362 ss << "GCC-style input constraints: {"; | |
363 for (It i = input_constraints.begin(), e = input_constraints.end(); i != e; ++i) { | |
364 ss << " " << *i; | |
365 } | |
366 ss << " }"; | |
367 Logger::println("%s", ss.str().c_str()); | |
368 | |
369 ss.str(""); | |
370 ss << "GCC-style clobbers: {"; | |
371 for (It i = clobbers.begin(), e = clobbers.end(); i != e; ++i) { | |
372 ss << " " << *i; | |
373 } | |
374 ss << " }"; | |
375 Logger::println("%s", ss.str().c_str()); | |
376 } | |
350 | 377 |
351 std::string insnt(code->insnTemplate, code->insnTemplateLen); | 378 std::string insnt(code->insnTemplate, code->insnTemplateLen); |
352 | 379 |
353 // rewrite GCC-style constraints to LLVM-style constraints | 380 // rewrite GCC-style constraints to LLVM-style constraints |
354 std::string llvmOutConstraints; | 381 std::string llvmOutConstraints; |
663 types.insert(types.end(), outtypes.begin(), outtypes.end()); | 690 types.insert(types.end(), outtypes.begin(), outtypes.end()); |
664 types.insert(types.end(), intypes.begin(), intypes.end()); | 691 types.insert(types.end(), intypes.begin(), intypes.end()); |
665 llvm::FunctionType* fty = llvm::FunctionType::get(retty, types, false); | 692 llvm::FunctionType* fty = llvm::FunctionType::get(retty, types, false); |
666 if (Logger::enabled()) | 693 if (Logger::enabled()) |
667 Logger::cout() << "function type = " << *fty << '\n'; | 694 Logger::cout() << "function type = " << *fty << '\n'; |
668 llvm::InlineAsm* ia = llvm::InlineAsm::get(fty, code, out_c, true); | |
669 | 695 |
670 std::vector<LLValue*> args; | 696 std::vector<LLValue*> args; |
671 args.insert(args.end(), outargs.begin(), outargs.end()); | 697 args.insert(args.end(), outargs.begin(), outargs.end()); |
672 args.insert(args.end(), inargs.begin(), inargs.end()); | 698 args.insert(args.end(), inargs.begin(), inargs.end()); |
699 | |
700 if (Logger::enabled()) { | |
701 Logger::cout() << "Arguments:" << '\n'; | |
702 Logger::indent(); | |
703 for (std::vector<LLValue*>::iterator b = args.begin(), i = b, e = args.end(); i != e; ++i) | |
704 Logger::cout() << '$' << (i - b) << " ==> " << **i; | |
705 Logger::undent(); | |
706 } | |
707 | |
708 llvm::InlineAsm* ia = llvm::InlineAsm::get(fty, code, out_c, true); | |
709 | |
673 llvm::CallInst* call = p->ir->CreateCall(ia, args.begin(), args.end(), | 710 llvm::CallInst* call = p->ir->CreateCall(ia, args.begin(), args.end(), |
674 retty == LLType::VoidTy ? "" : "asm"); | 711 retty == LLType::VoidTy ? "" : "asm"); |
712 | |
713 if (Logger::enabled()) | |
714 Logger::cout() << "Complete asm statement: " << *call << '\n'; | |
675 | 715 |
676 // capture abi return value | 716 // capture abi return value |
677 if (useabiret) | 717 if (useabiret) |
678 { | 718 { |
679 IRAsmBlock* block = p->asmBlock; | 719 IRAsmBlock* block = p->asmBlock; |