{"id":236281,"date":"2020-12-31T05:42:18","date_gmt":"2020-12-30T21:42:18","guid":{"rendered":"http:\/\/4563.org\/?p=236281"},"modified":"2020-12-31T05:42:18","modified_gmt":"2020-12-30T21:42:18","slug":"%e6%88%91%e6%83%b3%e7%94%a8-llvm-%e5%88%b6%e4%bd%9c%e4%b8%80%e9%97%a8%e8%af%ad%e8%a8%80%e7%9a%84%e7%bc%96%e8%af%91%e5%99%a8%ef%bc%8c%e6%98%af%e4%b8%8d%e6%98%af%e8%a6%81%e5%ad%a6%e4%bc%9a-llvm-ir","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=236281","title":{"rendered":"\u6211\u60f3\u7528 llvm \u5236\u4f5c\u4e00\u95e8\u8bed\u8a00\u7684\u7f16\u8bd1\u5668\uff0c\u662f\u4e0d\u662f\u8981\u5b66\u4f1a llvm ir \u91cc\u7684\u54ea\u4e2a\u5947\u602a\u7684\u8bed\u6cd5"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6211\u60f3\u7528 llvm \u5236\u4f5c\u4e00\u95e8\u8bed\u8a00\u7684\u7f16\u8bd1\u5668\uff0c\u662f\u4e0d\u662f\u8981\u5b66\u4f1a llvm ir \u91cc\u7684\u54ea\u4e2a\u5947\u602a\u7684\u8bed\u6cd5               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : find456789 <\/span>  <span><i><\/i> 9<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6211\u7684\u7406\u89e3\u662f\uff0cllvm ir \u91cc\u7684\u8bed\u6cd5\uff0c\u5e94\u8be5\u4e5f\u7c7b\u4f3c\u4e00\u95e8\u7f16\u7a0b\u8bed\u8a00\uff0c\u4f46\u8fd9\u4e2a\u8bed\u8a00\u662f\u9488\u5bf9\u5927\u90e8\u5206\u786c\u4ef6\u5e73\u53f0\u901a\u7528\u7684<\/p>\n<p>\u6211\u53ea\u8981\u628a\u6211\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u7ffb\u8bd1\u6210 llvm ir \u91cc\u7684\u8bed\u8a00\uff0c \u5c31\u53ef\u4ee5\u5b9e\u73b0\u4e00\u95e8\u53ef\u4ee5\u5728\u5927\u591a\u6570\u5e73\u53f0\u7f16\u8bd1\u7684\u8bed\u8a00\u4e86<\/p>\n<p>\u6240\u4ee5\uff0c\u5728\u6211\u7684\u8bed\u8a00\u91cc\uff0c\u6211\u8981\u5b9e\u73b0 print(&#8220;hello world&#8221;), \u90a3\u6211\u5c31\u8981\u638c\u63e1 llvm ir \u91cc\uff0c\u600e\u4e48\u5b9e\u73b0 \u6253\u5370 hello word, <\/p>\n<p>\u5982\u679c\u6211\u8981\u5b9e\u73b0 \u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u7684\u529f\u80fd\uff0c \u5c31\u8981\u638c\u63e1 \u7528 llvm ir \u8bed\u8a00\u5b9a\u4e49\u51fd\u6570\u7684\u65b9\u6cd5<\/p>\n<p>\u53ea\u6709\u638c\u63e1\u4e86 llvm ir \u8bed\u8a00\uff0c \u624d\u80fd\u5b9e\u73b0\u8fd9\u4e2a\u7ffb\u8bd1\u7684\u8fc7\u7a0b<\/p>\n<p>\u8bf7\u95ee\u6211\u7684\u7406\u89e3\u5bf9\u5417\uff1f \u6211\u5e94\u8be5\u600e\u4e48\u529e<\/p>\n<p>\u4e0b\u56fe\u662f\u6211\u53d1\u73b0\u7684 llvm ir \u7684\u8bed\u8a00<\/p>\n<p>\u5982\u56fe<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/12\/20201231_5fedd79b1c9e1.png\" alt=\"\u6211\u60f3\u7528 llvm \u5236\u4f5c\u4e00\u95e8\u8bed\u8a00\u7684\u7f16\u8bd1\u5668\uff0c\u662f\u4e0d\u662f\u8981\u5b66\u4f1a llvm ir \u91cc\u7684\u54ea\u4e2a\u5947\u602a\u7684\u8bed\u6cd5\" \/><\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>9<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4643260\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sfqtsh <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/llvm.org\/docs\/tutorial\/                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4643261\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ghostheaven <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u9700\u8981\u7684\u662f\u5b9e\u73b0 llvm \u7684\u524d\u7aef\uff0c\u627e\u672c\u7f16\u8bd1\u539f\u7406\u770b\u770b\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4643262\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ghostheaven <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5f53\u7136 llvm \u7684 ir \u4e5f\u662f\u8981\u61c2\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4643263\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xiri <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5b9e\u73b0\u4e00\u95e8\u7f16\u7a0b\u8bed\u8a00 \/\u7f16\u8bd1\u5668\u5e76\u4e0d\u662f\u7b80\u5355\u5730\u201c\u7ffb\u8bd1\u201d\u5c31\u591f\u4e86\u3002\u4e00\u822c\u6765\u8bf4\u9700\u8981\u5148\u8fdb\u884c\u8bcd\u6cd5\u5206\u6790\u3001\u8bed\u6cd5\u5206\u6790\u751f\u6210\u4e0d\u4f9d\u8d56\u4e8e\u5177\u4f53\u6587\u6cd5\u548c\u8bed\u8a00\u7ec6\u8282\u7684 AST \u6811\uff0c\u7136\u540e\u5728\u6b64\u57fa\u7840\u4e0a\u8fdb\u884c\u5904\u7406\u3001\u4f18\u5316\uff0c\u6700\u540e\u6839\u636e\u5177\u4f53\u7684\u5e73\u53f0 \/\u7cfb\u7edf\u751f\u6210\u76ee\u6807\u4ee3\u7801\u3002<br \/>\u4e0d\u80fd\u7b80\u5355\u7684\u770b\u6210\u7528\u4e00\u95e8\u5df2\u6709\u7684\u8bed\u8a00\u5c06\u65b0\u8bed\u8a00\u7684\u529f\u80fd\u4e00\u4e00\u5bf9\u5e94\u7ffb\u8bd1\u51fa\u6765\uff0c\u5efa\u8bae\u8fd8\u662f\u53bb\u7cfb\u7edf\u7684\u5b66\u4e60\u4e00\u4e0b\u7f16\u8bd1\u539f\u7406\u6bd4\u8f83\u597d\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4643264\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : secondwtq <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u60f3\u7528 x86 \u5236\u4f5c\u4e00\u95e8\u8bed\u8a00\u7684\u7f16\u8bd1\u5668\uff0c\u662f\u4e0d\u662f\u8981\u5b66\u4f1a x86 \u6c47\u7f16\u91cc\u7684\u54ea\u4e2a\u5947\u602a\u7684\u8bed\u6cd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4643265\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : codehz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7136\u800c llvm ir \u6ca1\u6709\u5e2e\u4f60\u5904\u7406\u597d abi\uff0c\u4e5f\u5c31\u662f\u5305\u62ec\u8c03\u7528\u7ea6\u5b9a\u5728\u5185\u7684\u8fd8\u662f\u5f97\u548c\u5404\u4e2a\u5177\u4f53\u5e73\u53f0\u5bf9\u63a5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4643266\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : GeruzoniAnsasu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u5b8c\u5168\u662f\uff0c\u4f60\u5199\u4ee3\u7801\u7684\u65f6\u5019\u7528\u7684\u662f llvm \u6846\u67b6\u63d0\u4f9b\u7684 ir builder\uff0c\u5b83\u6709\u81ea\u5df1\u7684\u4ee3\u7801\u6765\u751f\u6210\u5bf9\u5e94\u7684 byte code<\/p>\n<p>\u4f46\u4f60\u81ea\u5df1\u7684\u8bed\u8a00\u91cc\uff0c\u8981\u5c06\u8bed\u8a00\u80cc\u540e\u7684\u6570\u636e\u7ed3\u6784\uff08\u7c7b\u4f3c PyObject \u8fd9\u79cd\u4e1c\u897f\uff09\u505a\u597d\u5b9a\u4e49\uff0c\u5e76\u4e14\u6bcf\u4e2a\u8bcd\u6cd5\u5143\u7d20\u4e4b\u95f4\u7684\u76f8\u4e92\u4f5c\u7528\u4e5f\u8981\u81ea\u5df1\u5b9e\u73b0\uff0c\u8fd9\u662f\u5b9e\u73b0\u7f16\u8bd1\u5668\u5f88\u9ebb\u70e6\u7684\u4e00\u4e2a\u5730\u65b9\u3002\u4e3e\u4e2a\u4f8b\u5b50\u6211\u60f3\u5b9e\u73b0\u5168 OO \u8bed\u8a00\uff0c\u628a\u6240\u6709\u8bcd\u6cd5\u5143\u7d20\u90fd\u770b\u505a MyLangObject \u8fd9\u5f88\u597d\uff0c\u4f46 MyLangObject \u7684\u7ed3\u6784\u5982\u4f55\u5b9a\u4e49\uff0c\u5185\u5b58\u5982\u4f55\u5206\u914d\uff0c\u662f\u5426\u8981\u8c03\u8bed\u8a00 Runtime \u5b9e\u73b0\u7684 API\uff0c\u8fd9\u4e9b\u90fd\u662f\u8981\u63d0\u524d\u8003\u8651\u7684\uff0c\u7136\u540e\u8c03\u7528 Runtime \u7684\u5185\u5b58\u5206\u914d\u8fd9\u4ef6\u4e8b\uff0c\u4f60\u8981\u7528 byte code \u5b9e\u73b0\u51fa\u6765                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4643267\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : amimo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u9700\u8981\u3002\u4f60\u4f7f\u7528\u7684\u662f LLVM \u63d0\u4f9b API \u751f\u6210 IR\uff0c\u4e0d\u9700\u8981\u9884\u5148\u5b66\u4e60\u8fd9\u4e2a IR \u7684\u6587\u672c\u8868\u793a\uff0c\u4f46\u770b\u61c2\u5b83\u6709\u52a9\u4e8e\u8c03\u8bd5\u4f60\u7684\u524d\u7aef\u3002<br \/>\u56e0\u4e3a llvm ir \u662f ssa \u5f62\u5f0f\u7684\uff0c\u6ca1\u6709\u63a5\u89e6\u8fc7\u53ef\u80fd\u8fd8\u4e0d\u597d\u8f6c\uff0c\u4f60\u53ef\u4ee5\u8003\u8651\u628a\u4f60\u7684\u8bed\u8a00\u5148\u8f6c\u6210 C\uff0c\u63a7\u5236\u6d41\u4f7f\u7528 goto\uff0c\u8fd9\u6b65\u8d70\u901a\u4e4b\u540e\u518d\u4f7f\u7528 llvm \u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4643268\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : msg7086 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u6b62\u662f\u8bed\u8a00\u5427\uff0c\u8fd8\u6709\u8fd0\u884c\u65f6\u3002\u4f60\u8bf4\u7684 print \u662f\u8981\u771f\u7684\u6709\u4eba\u5199\u51fa\u6765\u7684\u3002<br \/>\u4f60\u53ef\u4ee5\u8c03\u7528\u73b0\u6709 C \u8fd0\u884c\u65f6\u91cc\u7684\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u81ea\u5df1\u7684\u7248\u672c\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u60f3\u7528 llvm \u5236\u4f5c\u4e00\u95e8\u8bed\u8a00\u7684\u7f16&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/236281"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=236281"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/236281\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=236281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=236281"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=236281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}