<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 13, 2014, at 10:06 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Nov 12, 2014 at 6:34 PM, Frederic Riss <span dir="ltr" class=""><<a href="mailto:friss@apple.com" target="_blank" class="">friss@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I want to use this method in llvm-dwarfdump to be able to pretty<br class="">
print register names in dwarf expressions. As the data I'll feed<br class="">
to the method comes directly from the binary file, it might be<br class="">
anything and I'd like to avoid asserting when an unknown register<br class="">
number is requested.<br class="">
<br class="">
This patch makes the method return -1 when the register isn't found.<br class="">
The new behavior is the same as its inverse function getDwarfRegNum.<br class="">
Note that although this method returns an 'int', each and every user I<br class="">
could find stores the result in an 'unsigned' variable. Would it<br class="">
make sense to change the method return type to unsigned? Should the<br class="">
assert be kept and propagated to the callers? Any other suggestion<br class="">
to achieve what I want?<br class=""></blockquote><div class=""><br class="">I think it depnds on how many callers there are - if there's one or two (ish), then just putting an "assert(result != -1)" in the callers is probably sufficient. If there's a fair few, it might make sense to preserve this function as asserting on failure, and extract its implementation into another function ("tryGetLLVMRegNum"?) that returns -1 (or whatever) on failure - the original getLLVMRegNum would call this implementation, assert != -1, and return.<br class=""></div></div></div></div></div></blockquote><div><br class=""></div><div>There are like a dozen users, thus pushing the assert to the callers doesn’t seem like a good idea. I proposed removing the assert because getDwarfRegnum() is so similar and doesn’t assert. If that weren’t the case, I would have implemented the 2 functions approach right away. I’ll just update the revision with a tryGetLLVMRegNum helper.</div><div><br class=""></div><div>Fred </div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">If you were to change the return type to unsigned, what would you return on failure for your use case? If we have just one function (and push an assert into existing callers) I'd leave it signed and update callers to use signed values, assert, etc... if we end up with two functions I think it's fine for get* to return unsigned and tryGet* to return int.<br class=""><br class="">- David<br class=""><br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br class="">
<a href="http://reviews.llvm.org/D6243" target="_blank" class="">http://reviews.llvm.org/D6243</a><br class="">
<br class="">
Files:<br class="">
lib/MC/MCRegisterInfo.cpp<br class="">
<br class="">_______________________________________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br class="">
<br class=""></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></body></html>