{"id":2938,"date":"2013-08-23T19:27:43","date_gmt":"2013-08-23T10:27:43","guid":{"rendered":"http:\/\/peta.okechan.net\/blog\/?p=2938"},"modified":"2013-08-23T19:27:43","modified_gmt":"2013-08-23T10:27:43","slug":"3-4-%e9%96%a2%e6%95%b0%e3%81%ae%e3%82%b3%e3%83%bc%e3%83%89%e7%94%9f%e6%88%90","status":"publish","type":"post","link":"https:\/\/peta.okechan.net\/blog\/archives\/2938","title":{"rendered":"3.4. \u95a2\u6570\u306e\u30b3\u30fc\u30c9\u751f\u6210"},"content":{"rendered":"<p><a href=\"https:\/\/peta.okechan.net\/blog\/archives\/2836\" title=\"LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\">LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u65e5\u672c\u8a9e\u8a33<\/a><br \/>\n\u7b2c3\u7ae0 \u4e07\u83ef\u93e1: LLVM IR\u30b3\u30fc\u30c9\u306e\u751f\u6210<br \/>\n<a href=\"http:\/\/llvm.org\/docs\/tutorial\/LangImpl03.html#function-code-generation\" target=\"_blank\">\u7b2c4\u7bc0 \u95a2\u6570\u306e\u30b3\u30fc\u30c9\u751f\u6210<\/a><\/p>\n<p>\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3068\u95a2\u6570\u306e\u305f\u3081\u306e\u30b3\u30fc\u30c9\u751f\u6210\u306f\u3001\u3044\u304f\u3064\u304b\u306e\u7d30\u304b\u3044\u70b9\u306b\u3064\u3044\u3066\u51e6\u7406\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<br \/>\n\u306a\u306e\u3067\u3001\u5f0f\u306b\u95a2\u3059\u308b\u30b3\u30fc\u30c9\u751f\u6210\u306e\u3068\u304d\u3088\u308a\u7f8e\u3057\u304f\u306a\u304f\u306a\u308b\u304c\u3001\u3057\u304b\u3057\u3044\u304f\u3064\u304b\u306e\u91cd\u8981\u306a\u70b9\u306b\u3064\u3044\u3066\u89e3\u8aac\u3059\u308b\u305f\u3081\u306e\u826f\u3044\u984c\u6750\u3068\u306a\u308b\u3002<br \/>\n\u307e\u305a\u3001\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306e\u305f\u3081\u306e\u30b3\u30fc\u30c9\u751f\u6210\u306b\u3064\u3044\u3066\u8003\u3048\u3066\u307f\u3088\u3046\u3002<br \/>\n\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306f\u3001\u95a2\u6570\u672c\u4f53\u3068\u5916\u90e8\u95a2\u6570\uff08extern\u95a2\u6570\uff09\u5ba3\u8a00\u306e\u4e21\u65b9\u3067\u4f7f\u7528\u3055\u308c\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">Function *PrototypeAST::Codegen() {\r\n  \/\/ double(double, double)\u306a\u3069\u306e\u95a2\u6570\u578b\u3092\u4f5c\u308b\u3002\r\n  std::vector&lt;Type*&gt; Doubles(Args.size(),\r\n                             Type::getDoubleTy(getGlobalContext()));\r\n  FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),\r\n                                       Doubles, false);\r\n\r\n  Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);<\/pre>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306e\u305f\u3063\u305f\u3053\u308c\u3060\u3051\u306e\u884c\u306b\u3001\u591a\u304f\u306e\u529b\u304c\u51dd\u7e2e\u3055\u308c\u3066\u3044\u308b\u3002<br \/>\n\u307e\u305a\u3001\u3053\u306e\u95a2\u6570\u306f&#8221;Value*&#8221;\u3067\u306f\u306a\u304f&#8221;Function*&#8221;\u3092\u8fd4\u3059\u3053\u3068\u306b\u6ce8\u610f\u3002<br \/>\n\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306f\u3001\u5b9f\u969b\u306b\u306f\u3042\u308b\u95a2\u6570\u306e\u5916\u90e8\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\uff08\u5f0f\u306b\u3088\u3063\u3066\u8a08\u7b97\u3055\u308c\u305f\u5024\u3067\u306f\u306a\u3044\uff09\u306b\u3064\u3044\u3066\u306e\u3082\u306e\u3067\u3042\u308a\u3001\u30b3\u30fc\u30c9\u751f\u6210\u6642\u306b\u305d\u308c\u306b\u5bfe\u5fdc\u3059\u308bLLVM\u95a2\u6570\u3092\u8fd4\u3059\u306e\u306f\u7406\u306b\u304b\u306a\u3063\u3066\u3044\u308b\u3002<\/p>\n<p>FunctionType::get\u306b\u3088\u3063\u3066\u3001\u6307\u5b9a\u3055\u308c\u305f\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306b\u5408\u3063\u305fFunctionType\u304c\u751f\u6210\u3055\u308c\u308b\u3002<br \/>\n\u4e07\u83ef\u93e1\u306b\u304a\u3051\u308b\u95a2\u6570\u306e\u5f15\u6570\u306f\u5168\u3066double\u306a\u306e\u3067\u3001\u6700\u521d\u306e\u884c\u306fN\u500b\u306eLLVM double\u578b\u306e\u30d9\u30af\u30bf\u3092\u751f\u6210\u3059\u308b\u3002<br \/>\n\u305d\u3057\u3066\u3001N\u500b\u306edouble\u306e\u5f15\u6570\u3092\u3068\u308a\u3001\u305d\u308c\u3089\u304c\u53ef\u5909\u9577\uff08vararg\uff09\u3067\u306f\u306a\u304f\uff08false\u304c\u305d\u308c\u3092\u793a\u3057\u3066\u3044\u308b\uff09\u3001\u3072\u3068\u3064\u306edouble\u306e\u623b\u308a\u5024\u3092\u8fd4\u3059\u95a2\u6570\u578b\u304cFunctionType::get\u306b\u3088\u3063\u3066\u751f\u6210\u3055\u308c\u308b\u3002<br \/>\nLLVM\u306b\u304a\u3051\u308b\u578b\u306f\u3001\u5b9a\u6570\u3068\u540c\u3058\u3088\u3046\u306b\u4e00\u610f\u3068\u306a\u308b\u306e\u3067\u3001\u578b\u3092&#8221;new&#8221;\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001&#8221;get&#8221;\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<br \/>\n<em>\u8a33\u6ce8: N\u500b = Args.size()\u500b\u3002<br \/>\nArgs\u306f\u5f15\u6570\u540d\u3092\u4fdd\u6301\u3059\u308bPrototypeAST\u306e\u30e1\u30f3\u30d0\u5909\u6570\u3067\u3001\u578b\u306fstd::vector&lt;std::string&gt;\u3067\u3042\u308b\u3002<\/em><\/p>\n<p>\u4e0a\u306e\u30b3\u30fc\u30c9\u306e\u6700\u5f8c\u306e\u884c\u3067\u306f\u3001\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306b\u5408\u81f4\u3059\u308b\u3067\u3042\u308d\u3046\u95a2\u6570\u304c\u5b9f\u969b\u306b\u751f\u6210\u3055\u308c\u308b\u3002<br \/>\n\u578b\u3084\u30ea\u30f3\u30b1\u30fc\u30b8\u3084\u540d\u524d\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u3069\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u633f\u5165\u3059\u308b\u304b\u3092\u793a\u3059\u3002<br \/>\n\u5916\u90e8\u30ea\u30f3\u30b1\u30fc\u30b8\uff08external linkage\uff09\u306f\u3001\u95a2\u6570\u304c\u73fe\u5728\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u5916\u90e8\u3067\u5b9a\u7fa9\u3055\u308c\u308b\u304b\u3082\u3057\u308c\u306a\u3044\u4e8b\u3001\u304a\u3088\u3073\uff08\u307e\u305f\u306f\uff09\u3001\u5916\u90e8\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u95a2\u6570\u304b\u3089\u547c\u3073\u51fa\u3057\u53ef\u80fd\u3067\u3042\u308b\u3068\u3044\u3046\u4e8b\u3092\u610f\u5473\u3059\u308b\u3002<br \/>\n\u4e0a\u8a18\u306e\u95a2\u6570\u547c\u3073\u51fa\u3057\u306b\u6e21\u3055\u308c\u3066\u308bName\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u6307\u5b9a\u3057\u305f\u3082\u306e\u3067\u3042\u308b\u3002<br \/>\nTheModule\u304c\u5f15\u6570\u306b\u6307\u5b9a\u3055\u308c\u3066\u308b\u306e\u3067\u3001\u305d\u306e\u540d\u524d\u306fTheModule\u306e\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u306b\u767b\u9332\u3055\u308c\u308b\u3002<br \/>\n<em>\u8a33\u6ce8: Name\u306fPrototypeAST\u306e\u30e1\u30f3\u30d0\u5909\u6570\u3067\u3042\u308a\u3001PrototypeAST\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u751f\u6210\u6642\u306b\u69cb\u6587\u89e3\u6790\u5668\u306b\u3088\u3063\u3066Name\u306e\u4e2d\u8eab\u306f\u6e21\u3055\u308c\u3066\u3044\u308b\u3002<\/em><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ F\u306e\u540d\u524d\u304cName\u3068\u4e00\u81f4\u3057\u306a\u3044\u5834\u5408, Name\u304c\u8868\u3059\u6587\u5b57\u5217\u3067\u540d\u4ed8\u3051\u3089\u308c\u305f\u4f55\u304b\u304c\u3059\u3067\u306b\u5b58\u5728\u3057\u3066\u3044\u308b\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308b\u3002\r\n\/\/ \u95a2\u6570\u672c\u4f53\u3092\u6301\u3064\u3082\u306e\u306b\u95a2\u3057\u3066\u306f\u3001\u518d\u5b9a\u7fa9\u3084\u518dextern\uff08reextern\uff09\u306f\u8a31\u53ef\u3057\u306a\u3044\u3002\r\nif (F-&gt;getName() != Name) {\r\n  \/\/ \u3072\u3068\u3064\u3060\u3051\u5b58\u5728\u3057\u3066\u308b\u72b6\u614b\u3092\u4fdd\u3064\u305f\u3081\u306b\u3001\u6d88\u53bb\u3059\u308b\u3002\r\n  F-&gt;eraseFromParent();\r\n  F = TheModule-&gt;getFunction(Name);<\/pre>\n<p>\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u306f\u3001\u540d\u524d\u306e\u4e0d\u4e00\u81f4\u304c\u3042\u3063\u305f\u5834\u5408\u306b\u306f\u95a2\u6570\u306e\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u3068\u3057\u3066\u52d5\u4f5c\u3059\u308b\u3002<br \/>\n\u3082\u3057\u65b0\u3057\u3044\u95a2\u6570\u304c\u3001\u3059\u3067\u306b\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u306b\u8ffd\u52a0\u3055\u308c\u3066\u3044\u308b\u3082\u306e\u3068\u540c\u3058\u540d\u524d\u306b\u3088\u3063\u3066\u751f\u6210\u3055\u308c\u305f\u5834\u5408\u3001\u305d\u306e\u95a2\u6570\u304c\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u8ffd\u52a0\u3055\u308c\u308b\u3068\u304d\u6697\u9ed9\u7684\u306b\u30ea\u30cd\u30fc\u30e0\u3055\u308c\u308b\u3002<br \/>\n\u4e0a\u306e\u30b3\u30fc\u30c9\u306f\u3001\u3053\u306e\u4e8b\u5b9f\u3092\u5229\u7528\u3057\u3066\u3053\u306e\u95a2\u6570\u304c\u3059\u3067\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3057\u3066\u3044\u308b\u3002<\/p>\n<p>\u4e07\u83ef\u93e1\u3067\u306f\u30012\u3064\u306e\u5834\u5408\u306b\u304a\u3044\u3066\u95a2\u6570\u306e\u518d\u5b9a\u7fa9\u3092\u8a31\u53ef\u3059\u308b\u3053\u3068\u306b\u3057\u305f\u3002<br \/>\n\u3072\u3068\u3064\u306f\u3001\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u304c\u5408\u81f4\u3059\u308b\u9650\u308a\uff08\u5f15\u6570\u306f\u3059\u3079\u3066\u540c\u3058\u578b\u306a\u306e\u3067\u3001\u5f15\u6570\u306e\u6570\u304c\u5408\u3063\u3066\u308b\u304b\u3069\u3046\u304b\u3060\u3051\u30c1\u30a7\u30c3\u30af\u3059\u308c\u3070\u3044\u3044\uff09\u3001extern\u306e\u5ba3\u8a00\u3092\u8907\u6570\u56de\u53ef\u80fd\u3068\u3057\u305f\u3044\u3002<br \/>\n\u3082\u3046\u3072\u3068\u3064\u306f\u3001\u307e\u305aextern\u5ba3\u8a00\u3057\u305f\u5f8c\u3001\u5f8c\u3067\u305d\u306e\u672c\u4f53\u3092\u5b9a\u7fa9\u3059\u308b\u4e8b\u3092\u53ef\u80fd\u3068\u3057\u305f\u3044\u3002<br \/>\n\u3053\u308c\u306f\u3001\u4e92\u3044\u306b\u518d\u5e30\u7684\u306a\u95a2\u6570\u306e\u5b9a\u7fa9\u3067\u5f79\u7acb\u3064\u3002<\/p>\n<p>\u3053\u308c\u3092\u5b9f\u88c5\u3059\u308b\u306b\u3042\u305f\u3063\u3066\u3001\u4e0a\u306e\u30b3\u30fc\u30c9\u3067\u306f\u307e\u305a\u95a2\u6570\u306e\u540d\u524d\u306e\u4e0d\u4e00\u81f4\u304c\u7121\u3044\u304b\u3069\u3046\u304b\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3002<br \/>\n\u3082\u3057\u4e0d\u4e00\u81f4\u304c\u3042\u308c\u3070\u3001\u305f\u3063\u305f\u4eca\u751f\u6210\u3057\u305f\u3070\u304b\u308a\u306e\u95a2\u6570\u3092\uff08eraseFromParent\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u306b\u3088\u3063\u3066\uff09\u524a\u9664\u3057\u3001\u305d\u308c\u304b\u3089\u6307\u5b9a\u3055\u308c\u305f\u540d\u524d\u3092\u4f7f\u3063\u3066\u3001\u3059\u3067\u306b\u5b58\u5728\u3057\u3066\u3044\u308b\u95a2\u6570\u3092\u5f97\u308b\u305f\u3081\u306bgetFunction\u3092\u547c\u3076\u3002<br \/>\nLLVM\u306b\u306f\u3001\u6d88\u53bb\uff08erase\uff09\u7cfb\u3084\u3001\u9664\u53bb\uff08remove\uff09\u7cfb\u306eAPI\u304c\u305f\u304f\u3055\u3093\u3042\u308b\u4e8b\u306b\u6ce8\u610f\u3002<br \/>\nremove\u7cfb\u306f\u3001\u8a72\u5f53\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u305d\u306e\u89aa\u304b\u3089\u5206\u96e2\uff08unlink\uff09\uff08\u4f8b\u3048\u3070\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u304b\u3089\u95a2\u6570\u3092\u5206\u96e2\u3001\u7b49\uff09\u3057\u3066\u3001\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3059\u3002<br \/>\nerase\u7cfb\u306f\u3001\u8a72\u5f53\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u305d\u306e\u89aa\u304b\u3089\u5206\u96e2\uff08unlink\uff09\u3057\u3066\u3001\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u524a\u9664\uff08delete\uff09\u3059\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">  \/\/ \u3059\u3067\u306bF\u304c\u672c\u4f53\u3092\u6301\u3064\u306a\u3089\u53d7\u3051\u5165\u308c\u306a\u3044\u3002\r\n  if (!F-&gt;empty()) {\r\n    ErrorF(&quot;redefinition of function&quot;);\r\n    return 0;\r\n  }\r\n\r\n  \/\/ \u3082\u3057F\u304c\u53d7\u3051\u53d6\u308b\u5f15\u6570\u306e\u6570\u304c\u9055\u3046\u306a\u3089\u53d7\u3051\u5165\u308c\u306a\u3044\u3002\r\n  if (F-&gt;arg_size() != Args.size()) {\r\n    ErrorF(&quot;redefinition of function with different # args&quot;);\r\n    return 0;\r\n  }\r\n}<\/pre>\n<p>\u4e0a\u8a18\u306e\u30ed\u30b8\u30c3\u30af\u3092\u691c\u8a3c\u3059\u308b\u305f\u3081\u306b\u3001\u307e\u305a\u3001\u3059\u3067\u306b\u5b58\u5728\u3057\u3066\u308b\u95a2\u6570\u304c&#8221;\u7a7a\uff08empty\uff09&#8221;\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3002<br \/>\n\u3053\u306e\u5834\u5408\u306e&#8221;\u7a7a\u201d\u3068\u306f\u3001\u305d\u306e\u95a2\u6570\u304c\u57fa\u672c\u30d6\u30ed\u30c3\u30af\u3092\u6301\u305f\u306a\u3044\u3001\u3064\u307e\u308a\u672c\u4f53\u3092\u6301\u305f\u306a\u3044\u3068\u3044\u3046\u4e8b\u3092\u610f\u5473\u3059\u308b\u3002<br \/>\n\u95a2\u6570\u304c\u672c\u4f53\u3092\u6301\u305f\u306a\u3044\u5834\u5408\u3001\u305d\u308c\u306f\u524d\u65b9\u5ba3\u8a00\u3067\u3042\u308b\u3002<br \/>\n\u95a2\u6570\u306e\u5b8c\u5168\u306a\u5b9a\u7fa9\u306e\u5f8c\u306f\u4f55\u3082\u8a31\u53ef\u3055\u308c\u306a\u3044\u306e\u3067\u3001\u305d\u306e\u5834\u5408\u306f\u3053\u306e\u30b3\u30fc\u30c9\u306f\u53d7\u3051\u5165\u308c\u306a\u3044\u3002<br \/>\nextern\u306e\u5834\u5408\u306f\u3001\u4ee5\u524d\u306e\u5ba3\u8a00\u3068\u4eca\u56de\u306e\u5ba3\u8a00\u304c\u5408\u81f4\u3059\u308b\u304b\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306b\u3001\u5358\u7d14\u306b\u5f15\u6570\u306e\u6570\u3060\u3051\u3092\u691c\u8a3c\u3059\u308b\u3002<br \/>\n\u5f15\u6570\u306e\u6570\u304c\u9055\u3046\u5834\u5408\u306f\u3001\u30a8\u30e9\u30fc\u304c\u767a\u884c\u3055\u308c\u308b\u3002<br \/>\n<em>\u8a33\u6ce8: \u57fa\u672c\u30d6\u30ed\u30c3\u30af\u3084\u524d\u65b9\u5ba3\u8a00\u306b\u3064\u3044\u3066\u77e5\u3089\u306a\u3051\u308c\u3070\u30b0\u30b0\u308b\u3079\u3057\u3002<\/em><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">  \/\/ \u5168\u3066\u306e\u5f15\u6570\u306b\u3064\u3044\u3066\u540d\u524d\u3092\u30bb\u30c3\u30c8\u3059\u308b\u3002\r\n  unsigned Idx = 0;\r\n  for (Function::arg_iterator AI = F-&gt;arg_begin(); Idx != Args.size();\r\n       ++AI, ++Idx) {\r\n    AI-&gt;setName(Args&#x5B;Idx]);\r\n\r\n    \/\/ \u5909\u6570\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u306b\u5f15\u6570\u3092\u8ffd\u52a0\u3059\u308b\u3002\r\n    NamedValues&#x5B;Args&#x5B;Idx]] = AI;\r\n  }\r\n  return F;\r\n}<\/pre>\n<p>\u6700\u5f8c\u306e\u3061\u3087\u3063\u3068\u3057\u305f\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306e\u305f\u3081\u306e\u30b3\u30fc\u30c9\u306f\u3001\u73fe\u5728\u306e\u95a2\u6570\u306b\u304a\u3051\u308b\u3059\u3079\u3066\u306e\u5f15\u6570\u306b\u3064\u3044\u3066\u30eb\u30fc\u30d7\u3092\u56de\u3057\u3001LLVM\u5f15\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff08LLVM Argument objects\uff09\u306e\u540d\u524d\u3092\u30bb\u30c3\u30c8\u3057\u3001\u3053\u306e\u5f8cVariableExprAST\u30ce\u30fc\u30c9\u3067\u4f7f\u3048\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u3001NamedValues\u306b\u305d\u306e\u5f15\u6570\u3092\u767b\u9332\u3059\u308b\u3002<br \/>\n\u3053\u308c\u304c\u7d42\u308f\u308c\u3070\u3001\u3053\u306e\u30e1\u30f3\u30d0\u95a2\u6570\u306f\u547c\u3073\u51fa\u3057\u5143\u306b\u95a2\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3059\u3002<br \/>\n\u3053\u3053\u3067\u306f\u3001\u5f15\u6570\u540d\u306e\u91cd\u8907\u306b\u3064\u3044\u3066\u306f\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3044\u306a\u3044\u70b9\u306b\u6ce8\u610f\u3002\uff08\u4f8b\u3048\u3070\u3001&#8221;extern foo(a b a)&#8221;\uff09<br \/>\n\u3053\u308c\u3092\u884c\u3046\u306b\u306f\u3001\u3053\u308c\u307e\u3067\u4f7f\u3063\u3066\u304d\u305f\u65b9\u6cd5\u3092\u4f7f\u3048\u3070\u7c21\u5358\u306b\u5b9f\u88c5\u3067\u304d\u308b\u3060\u308d\u3046\u3002<br \/>\n<em>\u8a33\u6ce8: \u5f15\u6570\u540d\u306fArgs\u914d\u5217\uff08vector&lt;std::string&gt;\uff09\u306b\u5165\u3063\u3066\u308b\u306e\u3067\u3001\u52b9\u7387\u306f\u3055\u3066\u7f6e\u3044\u3066\u91cd\u8907\u3092\u8abf\u3079\u308b\u306e\u306f\u7c21\u5358\u3060\u308d\u3046\u3002<br \/>\n\u5f8c\u306f\u3001\u91cd\u8907\u304c\u3042\u3063\u305f\u5834\u5408\u306b\u95a2\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u6d88\u3057\u3066\u3001return 0 \u3059\u308b\u3060\u3051\u3067\u826f\u3044\u3002\u3093\u3058\u3083\u306a\u3044\u304b\u306a\u3002<\/em><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">Function *FunctionAST::Codegen() {\r\n  NamedValues.clear();\r\n\r\n  Function *TheFunction = Proto-&gt;Codegen();\r\n  if (TheFunction == 0)\r\n    return 0;<\/pre>\n<p>\u95a2\u6570\u5b9a\u7fa9\u306e\u305f\u3081\u306e\u30b3\u30fc\u30c9\u751f\u6210\u51e6\u7406\u306e\u59cb\u307e\u308a\u306f\u3001\u3053\u308c\u3067\u5341\u5206\u3067\u3042\u308b\u3002<br \/>\n\u305d\u306e\u95a2\u6570\u306e\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\uff08Proto\uff09\u306e\u30b3\u30fc\u30c9\u751f\u6210\u3092\u884c\u3044\u3001\u623b\u308a\u5024\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3060\u3051\u3067\u3042\u308b\u3002<br \/>\nNamedValues\uff08std::map&lt;std::string, Value*&gt;\u3001\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\uff09\u3092\u30af\u30ea\u30a2\u3057\u3066\u3044\u308b\u306e\u306f\u3001\u76f4\u524d\u306e\u95a2\u6570\u306e\u30b3\u30f3\u30d1\u30a4\u30eb\u306b\u3088\u308b\u30c7\u30fc\u30bf\u3092\u6d88\u3057\u3066\u3001\u78ba\u5b9f\u306b\u7a7a\u306b\u3059\u308b\u305f\u3081\u3067\u3042\u308b\u3002<br \/>\n\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306e\u30b3\u30fc\u30c9\u751f\u6210\u306b\u3088\u3063\u3066\u3001\u3053\u306e\u5f8c\u306e\u51e6\u7406\u306b\u7528\u3044\u308bLLVM\u95a2\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5b58\u5728\u304c\u78ba\u5b9f\u306a\u3082\u306e\u3068\u306a\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ \u633f\u5165\u3059\u308b\u305f\u3081\u306e\u3001\u65b0\u3057\u3044\u57fa\u672c\u30d6\u30ed\u30c3\u30af\u3092\u4f5c\u6210\u3059\u308b\u3002\r\nBasicBlock *BB = BasicBlock::Create(getGlobalContext(), &quot;entry&quot;, TheFunction);\r\nBuilder.SetInsertPoint(BB);\r\n\r\nif (Value *RetVal = Body-&gt;Codegen()) {<\/pre>\n<p>\u3053\u308c\u306fBuilder\u3092\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3057\u3066\u308b\u90e8\u5206\u3067\u3042\u308b\u3002<br \/>\n\u6700\u521d\u306e\u884c\u3067\u3001\u65b0\u3057\u3044\u57fa\u672c\u30d6\u30ed\u30c3\u30af\uff08\u540d\u524d\u306f&#8221;entry&#8221;\uff09\u304c\u4f5c\u6210\u3055\u308c\u3001TheFunction\u306e\u4e2d\u306b\u633f\u5165\u3055\u308c\u308b\u3002<br \/>\n\u6b21\u306e\u884c\u3067\u3001\u4eca\u5f8c\u306e\u547d\u4ee4\u3092\u65b0\u3057\u3044\u57fa\u672c\u30d6\u30ed\u30c3\u30af\u306e\u672b\u5c3e\u306b\u633f\u5165\u3059\u3079\u304d\u3067\u3042\u308b\u3068\u3044\u3046\u4e8bBuilder\u306b\u4f1d\u3048\u308b\u3002<br \/>\nLLVM\u306b\u304a\u3051\u308b\u57fa\u672c\u30d6\u30ed\u30c3\u30af\u306f\u3001\u5236\u5fa1\u30d5\u30ed\u30fc\u30b0\u30e9\u30d5\uff08Control Flow Graph\uff09\u3092\u5b9a\u7fa9\u3059\u308b\u305f\u3081\u306e\u3001\u95a2\u6570\u306e\u91cd\u8981\u306a\u90e8\u5206\u3067\u3042\u308b\u3002<br \/>\n\u73fe\u6642\u70b9\u3067\u306f\u4f55\u306e\u5236\u5fa1\u30d5\u30ed\u30fc\u3082\u6301\u305f\u306a\u3044\u306e\u3067\u3001\u95a2\u6570\u306f\u3072\u3068\u3064\u306e\u30d6\u30ed\u30c3\u30af\u306e\u307f\u3092\u542b\u3080\u3060\u308d\u3046\u3002<br \/>\n\u3053\u308c\u306b\u3064\u3044\u3066\u306f\u7b2c5\u7ae0\u3067\u6539\u826f\u3059\u308b\u3002<br \/>\n<em>\u8a33\u6ce8: \u5236\u5fa1\u30d5\u30ed\u30fc\u30b0\u30e9\u30d5\u306b\u3064\u3044\u3066\u77e5\u3089\u306a\u3044\u5834\u5408\u306f\u30b0\u30b0\u308b\u3079\u3057\u3002<\/em><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">if (Value *RetVal = Body-&gt;Codegen()) {\r\n  \/\/ \u95a2\u6570\u3092\u4ed5\u4e0a\u3052\u308b\u3002\r\n  Builder.CreateRet(RetVal);\r\n\r\n  \/\/ \u77db\u76fe\u304c\u7121\u3044\u304b\u3001\u751f\u6210\u3055\u308c\u305f\u30b3\u30fc\u30c9\u3092\u691c\u8a3c\u3059\u308b\u3002\r\n  verifyFunction(*TheFunction);\r\n\r\n  return TheFunction;\r\n}<\/pre>\n<p>\u633f\u5165\u70b9\uff08insertion point\uff09\u304c\u30bb\u30c3\u30c8\u3055\u308c\u305f\u3089\u3001\u95a2\u6570\u306e\u30eb\u30fc\u30c8\u5f0f\uff08root expression\uff09\u306e\u305f\u3081\u306bCodeGen()\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3076\u3002<br \/>\n\u4f55\u3082\u30a8\u30e9\u30fc\u304c\u8d77\u304d\u306a\u3051\u308c\u3070\u3001entry\u30d6\u30ed\u30c3\u30af\u306e\u4e2d\u306b\u3001\u5f0f\u3092\u8a08\u7b97\u3057\u305d\u306e\u7d50\u679c\u3092\u8fd4\u3059\u305f\u3081\u306e\u30b3\u30fc\u30c9\u304c\u751f\u6210\u3055\u308b\u3002<br \/>\n\u30a8\u30e9\u30fc\u304c\u8d77\u304d\u306a\u3051\u308c\u3070\u3001\u95a2\u6570\u3092\u5b8c\u6210\u3055\u305b\u308b\u305f\u3081\u3001LLVM\u306eret\u547d\u4ee4\u304c\u751f\u6210\u3055\u308c\u308b\u3002<br \/>\n\u95a2\u6570\u304c\u51fa\u6765\u4e0a\u304c\u3063\u305f\u3089\u3001LLVM\u304c\u63d0\u4f9b\u3059\u308bverifyFunction\u95a2\u6570\u3092\u547c\u3076\u3002<br \/>\n\u3053\u306e\u95a2\u6570\u306f\u3001\u751f\u6210\u3055\u308c\u305f\u30b3\u30fc\u30c9\u306b\u5bfe\u3057\u3066\u7a2e\u3005\u306e\u6574\u5408\u6027\u30c1\u30a7\u30c3\u30af\u3092\u884c\u3046\u3053\u3068\u306b\u3088\u3063\u3066\u3001\u6211\u3005\u306e\u30b3\u30f3\u30d1\u30a4\u30e9\u306e\u52d5\u304d\u306b\u9593\u9055\u3044\u304c\u306a\u3044\u304b\u3092\u8abf\u3079\u308b\u3002<br \/>\n\u591a\u304f\u306e\u30d0\u30b0\u3092\u6355\u307e\u3048\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u306e\u3067\u3001\u3053\u306e\u95a2\u6570\u306f\u91cd\u8981\u3067\u3042\u308b\u3002<br \/>\n\u95a2\u6570\u304c\u5b8c\u6210\u3057\u691c\u8a3c\u3055\u308c\u308c\u3070\u3001\u305d\u308c\u3092\u8fd4\u3059\u3002<br \/>\n<em>\u8a33\u6ce8: ret\u547d\u4ee4\u306f\u4ee5\u4e0b\u306e\u5f62\u3092\u3068\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ret &lt;type&gt; &lt;value&gt;       ; \u975evoid\u95a2\u6570\u304b\u3089\u5024\u3092\u8fd4\u3059\u3002\r\nret void                 ; void\u95a2\u6570\u304b\u3089\u8fd4\u308b\u3002<\/pre>\n<p><\/em><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">  \/\/ \u672c\u4f53\u306e\u30b3\u30fc\u30c9\u751f\u6210\u3067\u30a8\u30e9\u30fc\u304c\u3042\u308c\u3070\u3001\u95a2\u6570\u3092\u6d88\u53bb\u3059\u308b\u3002\r\n  TheFunction-&gt;eraseFromParent();\r\n  return 0;\r\n}<\/pre>\n<p>\u6b8b\u308a\u306f\u3001\u30a8\u30e9\u30fc\u306e\u5834\u5408\u306e\u51e6\u7406\u3060\u3051\u3067\u3042\u308b\u3002<br \/>\n\u7c21\u5358\u306e\u305f\u3081\u3001eraseFromParent\u30e1\u30bd\u30c3\u30c9\u3067\u5358\u306b\u95a2\u6570\u3092\u6d88\u53bb\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u3001\u3053\u306e\u5834\u5408\u3092\u51e6\u7406\u3059\u308b\u3002<br \/>\n\u3053\u308c\u306b\u3088\u3063\u3066\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u4ee5\u524d\u306b\u9593\u9055\u3063\u3066\u5165\u529b\u3057\u305f\u95a2\u6570\u3092\u518d\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3068\u306a\u308b\u3002<br \/>\n\u3082\u3057\u3001\u30a8\u30e9\u30fc\u6642\u306b\u6d88\u53bb\u3057\u306a\u3044\u5834\u5408\u3001\u305d\u306e\u95a2\u6570\u672c\u4f53\u3068\u5171\u306b\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u306b\u6b8b\u308a\u7d9a\u3051\u3001\u518d\u5b9a\u7fa9\u3092\u59a8\u3052\u3066\u3057\u307e\u3046\u3060\u308d\u3046\u3002<\/p>\n<p>\u307e\u3041\u6b63\u76f4\u3044\u3046\u3068\u3001\u3053\u306e\u30b3\u30fc\u30c9\u306b\u306f\u30d0\u30b0\u304c\u3042\u308b\u3002<br \/>\nPrototypeAST::Codegen\u306f\u3001\u4ee5\u524d\u306b\u5b9a\u7fa9\u3055\u308c\u305f\u524d\u65b9\u5ba3\u8a00\u3092\u8fd4\u3059\u53ef\u80fd\u6027\u304c\u3042\u308b\u306e\u3067\u3001\u3053\u306e\u30b3\u30fc\u30c9\u3067\u306f\u5b9f\u306f\u524d\u65b9\u5ba3\u8a00\u3092\u524a\u9664\u3057\u3066\u3057\u307e\u3046\u53ef\u80fd\u6027\u304c\u3042\u308b\u3002<br \/>\n\u3053\u306e\u30d0\u30b0\u3092\u4fee\u6b63\u3059\u308b\u65b9\u6cd5\u306f\u305f\u304f\u3055\u3093\u3042\u308b\u304c\u3001\u3069\u3046\u3084\u3063\u305f\u3089\u305d\u308c\u304c\u53ef\u80fd\u304b\u8003\u3048\u3066\u307f\u3066\u6b32\u3057\u3044\u3002<br \/>\n\u4ee5\u4e0b\u306f\u305d\u306e\u305f\u3081\u306e\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u3067\u3042\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">extern foo(a b);     # ok, defines foo.\r\ndef foo(a b) c;      # error, 'c' is invalid.\r\ndef bar() foo(1, 2); # error, unknown function &quot;foo&quot;<\/pre>\n<p><em>\u8a33\u6ce8: 1\u884c\u76ee\u3067\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u304c\u751f\u6210\u3055\u308c\u308b\u3002<br \/>\n2\u884c\u76ee\u3067\u3001\u4e0d\u660e\u306a\u5909\u6570c\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u30a8\u30e9\u30fc\u3068\u306a\u308b\u3002<br \/>\n\u304c\u3001\u3053\u306e\u3068\u304d\u95a2\u6570\u672c\u4f53\u306e\u5b9a\u7fa9\u3060\u3051\u3067\u306a\u304f1\u884c\u76ee\u3067\u5ba3\u8a00\u3057\u305f\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3082\u6d88\u53bb\u3055\u308c\u308b\u3002<br \/>\n\u3088\u3063\u3066\u30013\u884c\u76ee\u3067foo\u3068\u3044\u3046\u95a2\u6570\u304c\u4e0d\u660e\u3068\u3044\u3046\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u3002<br \/>\n\u95a2\u6570\u672c\u4f53\u306e\u5b9a\u7fa9\u306b\u30a8\u30e9\u30fc\u304c\u3042\u3063\u3066\u3082\u3001\u4e8b\u524d\u306b\u5ba3\u8a00\u3055\u308c\u305f\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3092\u6d88\u53bb\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308c\u3070\u30013\u884c\u76ee\u3067\u306f\u30a8\u30e9\u30fc\u306f\u51fa\u306a\u304f\u306a\u308b\u306f\u305a\u3067\u3042\u308b\u3002<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p><a href=\"https:\/\/peta.okechan.net\/blog\/archives\/2836\" title=\"LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\">LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u65e5\u672c\u8a9e\u8a33<\/a><br \/>\n\u7b2c3\u7ae0 \u4e07\u83ef\u93e1: LLVM IR\u30b3\u30fc\u30c9\u306e\u751f\u6210<br \/>\n<a href=\"http:\/\/llvm.org\/docs\/tutorial\/LangImpl03.html#function-code-generation\" target=\"_blank\">\u7b2c4\u7bc0 \u95a2\u6570\u306e\u30b3\u30fc\u30c9\u751f\u6210<\/a><\/p>\n<p>\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3068\u95a2\u6570\u306e\u305f\u3081\u306e\u30b3\u30fc\u30c9\u751f\u6210\u306f\u3001\u3044\u304f\u3064\u304b\u306e\u7d30\u304b\u3044\u70b9\u306b\u3064\u3044\u3066\u51e6\u7406\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<br \/>\n\u306a\u306e\u3067\u3001\u5f0f\u306b\u95a2\u3059\u308b\u30b3\u30fc\u30c9\u751f\u6210\u306e\u3068\u304d\u3088\u308a\u7f8e\u3057\u304f\u306a\u304f\u306a\u308b\u304c\u3001\u3057\u304b\u3057\u3044\u304f\u3064\u304b\u306e\u91cd\u8981\u306a\u70b9\u306b\u3064\u3044\u3066\u89e3\u8aac\u3059\u308b\u305f\u3081\u306e\u826f\u3044\u984c\u6750\u3068\u306a\u308b\u3002<br \/>\n\u307e\u305a\u3001\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306e\u305f\u3081\u306e\u30b3\u30fc\u30c9\u751f\u6210\u306b\u3064\u3044\u3066\u8003\u3048\u3066\u307f\u3088\u3046\u3002<br \/>\n\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306f\u3001\u95a2\u6570\u672c\u4f53\u3068\u5916\u90e8\u95a2\u6570\uff08extern\u95a2\u6570\uff09\u5ba3\u8a00\u306e\u4e21\u65b9\u3067\u4f7f\u7528\u3055\u308c\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">Function *PrototypeAST::Codegen() {\r\n  \/\/ double(double, double)\u306a\u3069\u306e\u95a2\u6570\u578b\u3092\u4f5c\u308b\u3002\r\n  std::vector&lt;Type*&gt; Doubles(Args.size(),\r\n                             Type::getDoubleTy(getGlobalContext()));\r\n  FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),\r\n                                       Doubles, false);\r\n\r\n  Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);<\/pre>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306e\u305f\u3063\u305f\u3053\u308c\u3060\u3051\u306e\u884c\u306b\u3001\u591a\u304f\u306e\u529b\u304c\u51dd\u7e2e\u3055\u308c\u3066\u3044\u308b\u3002<br \/>\n\u307e\u305a\u3001\u3053\u306e\u95a2\u6570\u306f&#8221;Value*&#8221;\u3067\u306f\u306a\u304f&#8221;Function*&#8221;\u3092\u8fd4\u3059\u3053\u3068\u306b\u6ce8\u610f\u3002<br \/>\n\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306f\u3001\u5b9f\u969b\u306b\u306f\u3042\u308b\u95a2\u6570\u306e\u5916\u90e8\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\uff08\u5f0f\u306b\u3088\u3063\u3066\u8a08\u7b97\u3055\u308c\u305f\u5024\u3067\u306f\u306a\u3044\uff09\u306b\u3064\u3044\u3066\u306e\u3082\u306e\u3067\u3042\u308a\u3001\u30b3\u30fc\u30c9\u751f\u6210\u6642\u306b\u305d\u308c\u306b\u5bfe\u5fdc\u3059\u308bLLVM\u95a2\u6570\u3092\u8fd4\u3059\u306e\u306f\u7406\u306b\u304b\u306a\u3063\u3066\u3044\u308b\u3002<\/p>\n<p>FunctionType::get\u306b\u3088\u3063\u3066\u3001\u6307\u5b9a\u3055\u308c\u305f\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306b\u5408\u3063\u305fFunctionType\u304c\u751f\u6210\u3055\u308c\u308b\u3002<br \/>\n\u4e07\u83ef\u93e1\u306b\u304a\u3051\u308b\u95a2\u6570\u306e\u5f15\u6570\u306f\u5168\u3066double\u306a\u306e\u3067\u3001\u6700\u521d\u306e\u884c\u306fN\u500b\u306eLLVM double\u578b\u306e\u30d9\u30af\u30bf\u3092\u751f\u6210\u3059\u308b\u3002<br \/>\n\u305d\u3057\u3066\u3001N\u500b\u306edouble\u306e\u5f15\u6570\u3092\u3068\u308a\u3001\u305d\u308c\u3089\u304c\u53ef\u5909\u9577\uff08vararg\uff09\u3067\u306f\u306a\u304f\uff08false\u304c\u305d\u308c\u3092\u793a\u3057\u3066\u3044\u308b\uff09\u3001\u3072\u3068\u3064\u306edouble\u306e\u623b\u308a\u5024\u3092\u8fd4\u3059\u95a2\u6570\u578b\u304cFunctionType::get\u306b\u3088\u3063\u3066\u751f\u6210\u3055\u308c\u308b\u3002<br \/>\nLLVM\u306b\u304a\u3051\u308b\u578b\u306f\u3001\u5b9a\u6570\u3068\u540c\u3058\u3088\u3046\u306b\u4e00\u610f\u3068\u306a\u308b\u306e\u3067\u3001\u578b\u3092&#8221;new&#8221;\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001&#8221;get&#8221;\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<br \/>\n<em>\u8a33\u6ce8: N\u500b = Args.size()\u500b\u3002<br \/>\nArgs\u306f\u5f15\u6570\u540d\u3092\u4fdd\u6301\u3059\u308bPrototypeAST\u306e\u30e1\u30f3\u30d0\u5909\u6570\u3067\u3001\u578b\u306fstd::vector&lt;std::string&gt;\u3067\u3042\u308b\u3002<\/em><\/p>\n<p>\u4e0a\u306e\u30b3\u30fc\u30c9\u306e\u6700\u5f8c\u306e\u884c\u3067\u306f\u3001\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306b\u5408\u81f4\u3059\u308b\u3067\u3042\u308d\u3046\u95a2\u6570\u304c\u5b9f\u969b\u306b\u751f\u6210\u3055\u308c\u308b\u3002<br \/>\n\u578b\u3084\u30ea\u30f3\u30b1\u30fc\u30b8\u3084\u540d\u524d\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u3069\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u633f\u5165\u3059\u308b\u304b\u3092\u793a\u3059\u3002<br \/>\n\u5916\u90e8\u30ea\u30f3\u30b1\u30fc\u30b8\uff08external linkage\uff09\u306f\u3001\u95a2\u6570\u304c\u73fe\u5728\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u5916\u90e8\u3067\u5b9a\u7fa9\u3055\u308c\u308b\u304b\u3082\u3057\u308c\u306a\u3044\u4e8b\u3001\u304a\u3088\u3073\uff08\u307e\u305f\u306f\uff09\u3001\u5916\u90e8\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u95a2\u6570\u304b\u3089\u547c\u3073\u51fa\u3057\u53ef\u80fd\u3067\u3042\u308b\u3068\u3044\u3046\u4e8b\u3092\u610f\u5473\u3059\u308b\u3002<br \/>\n\u4e0a\u8a18\u306e\u95a2\u6570\u547c\u3073\u51fa\u3057\u306b\u6e21\u3055\u308c\u3066\u308bName\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u6307\u5b9a\u3057\u305f\u3082\u306e\u3067\u3042\u308b\u3002<br \/>\nTheModule\u304c\u5f15\u6570\u306b\u6307\u5b9a\u3055\u308c\u3066\u308b\u306e\u3067\u3001\u305d\u306e\u540d\u524d\u306fTheModule\u306e\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u306b\u767b\u9332\u3055\u308c\u308b\u3002<br \/>\n<em>\u8a33\u6ce8: Name\u306fPrototypeAST\u306e\u30e1\u30f3\u30d0\u5909\u6570\u3067\u3042\u308a\u3001PrototypeAST\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u751f\u6210\u6642\u306b\u69cb\u6587\u89e3\u6790\u5668\u306b\u3088\u3063\u3066Name\u306e\u4e2d\u8eab\u306f\u6e21\u3055\u308c\u3066\u3044\u308b\u3002<\/em><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ F\u306e\u540d\u524d\u304cName\u3068\u4e00\u81f4\u3057\u306a\u3044\u5834\u5408, Name\u304c\u8868\u3059\u6587\u5b57\u5217\u3067\u540d\u4ed8\u3051\u3089\u308c\u305f\u4f55\u304b\u304c\u3059\u3067\u306b\u5b58\u5728\u3057\u3066\u3044\u308b\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308b\u3002\r\n\/\/ \u95a2\u6570\u672c\u4f53\u3092\u6301\u3064\u3082\u306e\u306b\u95a2\u3057\u3066\u306f\u3001\u518d\u5b9a\u7fa9\u3084\u518dextern\uff08reextern\uff09\u306f\u8a31\u53ef\u3057\u306a\u3044\u3002\r\nif (F-&gt;getName() != Name) {\r\n  \/\/ \u3072\u3068\u3064\u3060\u3051\u5b58\u5728\u3057\u3066\u308b\u72b6\u614b\u3092\u4fdd\u3064\u305f\u3081\u306b\u3001\u6d88\u53bb\u3059\u308b\u3002\r\n  F-&gt;eraseFromParent();\r\n  F = TheModule-&gt;getFunction(Name);<\/pre>\n<p>\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u306f\u3001\u540d\u524d\u306e\u4e0d\u4e00\u81f4\u304c\u3042\u3063\u305f\u5834\u5408\u306b\u306f\u95a2\u6570\u306e\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u3068\u3057\u3066\u52d5\u4f5c\u3059\u308b\u3002<br \/>\n\u3082\u3057\u65b0\u3057\u3044\u95a2\u6570\u304c\u3001\u3059\u3067\u306b\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u306b\u8ffd\u52a0\u3055\u308c\u3066\u3044\u308b\u3082\u306e\u3068\u540c\u3058\u540d\u524d\u306b\u3088\u3063\u3066\u751f\u6210\u3055\u308c\u305f\u5834\u5408\u3001\u305d\u306e\u95a2\u6570\u304c\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u8ffd\u52a0\u3055\u308c\u308b\u3068\u304d\u6697\u9ed9\u7684\u306b\u30ea\u30cd\u30fc\u30e0\u3055\u308c\u308b\u3002<br \/>\n\u4e0a\u306e\u30b3\u30fc\u30c9\u306f\u3001\u3053\u306e\u4e8b\u5b9f\u3092\u5229\u7528\u3057\u3066\u3053\u306e\u95a2\u6570\u304c\u3059\u3067\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3057\u3066\u3044\u308b\u3002<\/p>\n<p>\u4e07\u83ef\u93e1\u3067\u306f\u30012\u3064\u306e\u5834\u5408\u306b\u304a\u3044\u3066\u95a2\u6570\u306e\u518d\u5b9a\u7fa9\u3092\u8a31\u53ef\u3059\u308b\u3053\u3068\u306b\u3057\u305f\u3002<br \/>\n\u3072\u3068\u3064\u306f\u3001\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u304c\u5408\u81f4\u3059\u308b\u9650\u308a\uff08\u5f15\u6570\u306f\u3059\u3079\u3066\u540c\u3058\u578b\u306a\u306e\u3067\u3001\u5f15\u6570\u306e\u6570\u304c\u5408\u3063\u3066\u308b\u304b\u3069\u3046\u304b\u3060\u3051\u30c1\u30a7\u30c3\u30af\u3059\u308c\u3070\u3044\u3044\uff09\u3001extern\u306e\u5ba3\u8a00\u3092\u8907\u6570\u56de\u53ef\u80fd\u3068\u3057\u305f\u3044\u3002<br \/>\n\u3082\u3046\u3072\u3068\u3064\u306f\u3001\u307e\u305aextern\u5ba3\u8a00\u3057\u305f\u5f8c\u3001\u5f8c\u3067\u305d\u306e\u672c\u4f53\u3092\u5b9a\u7fa9\u3059\u308b\u4e8b\u3092\u53ef\u80fd\u3068\u3057\u305f\u3044\u3002<br \/>\n\u3053\u308c\u306f\u3001\u4e92\u3044\u306b\u518d\u5e30\u7684\u306a\u95a2\u6570\u306e\u5b9a\u7fa9\u3067\u5f79\u7acb\u3064\u3002<\/p>\n<p>\u3053\u308c\u3092\u5b9f\u88c5\u3059\u308b\u306b\u3042\u305f\u3063\u3066\u3001\u4e0a\u306e\u30b3\u30fc\u30c9\u3067\u306f\u307e\u305a\u95a2\u6570\u306e\u540d\u524d\u306e\u4e0d\u4e00\u81f4\u304c\u7121\u3044\u304b\u3069\u3046\u304b\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3002<br \/>\n\u3082\u3057\u4e0d\u4e00\u81f4\u304c\u3042\u308c\u3070\u3001\u305f\u3063\u305f\u4eca\u751f\u6210\u3057\u305f\u3070\u304b\u308a\u306e\u95a2\u6570\u3092\uff08eraseFromParent\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u306b\u3088\u3063\u3066\uff09\u524a\u9664\u3057\u3001\u305d\u308c\u304b\u3089\u6307\u5b9a\u3055\u308c\u305f\u540d\u524d\u3092\u4f7f\u3063\u3066\u3001\u3059\u3067\u306b\u5b58\u5728\u3057\u3066\u3044\u308b\u95a2\u6570\u3092\u5f97\u308b\u305f\u3081\u306bgetFunction\u3092\u547c\u3076\u3002<br \/>\nLLVM\u306b\u306f\u3001\u6d88\u53bb\uff08erase\uff09\u7cfb\u3084\u3001\u9664\u53bb\uff08remove\uff09\u7cfb\u306eAPI\u304c\u305f\u304f\u3055\u3093\u3042\u308b\u4e8b\u306b\u6ce8\u610f\u3002<br \/>\nremove\u7cfb\u306f\u3001\u8a72\u5f53\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u305d\u306e\u89aa\u304b\u3089\u5206\u96e2\uff08unlink\uff09\uff08\u4f8b\u3048\u3070\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u304b\u3089\u95a2\u6570\u3092\u5206\u96e2\u3001\u7b49\uff09\u3057\u3066\u3001\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3059\u3002<br \/>\nerase\u7cfb\u306f\u3001\u8a72\u5f53\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u305d\u306e\u89aa\u304b\u3089\u5206\u96e2\uff08unlink\uff09\u3057\u3066\u3001\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u524a\u9664\uff08delete\uff09\u3059\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">  \/\/ \u3059\u3067\u306bF\u304c\u672c\u4f53\u3092\u6301\u3064\u306a\u3089\u53d7\u3051\u5165\u308c\u306a\u3044\u3002\r\n  if (!F-&gt;empty()) {\r\n    ErrorF(&quot;redefinition of function&quot;);\r\n    return 0;\r\n  }\r\n\r\n  \/\/ \u3082\u3057F\u304c\u53d7\u3051\u53d6\u308b\u5f15\u6570\u306e\u6570\u304c\u9055\u3046\u306a\u3089\u53d7\u3051\u5165\u308c\u306a\u3044\u3002\r\n  if (F-&gt;arg_size() != Args.size()) {\r\n    ErrorF(&quot;redefinition of function with different # args&quot;);\r\n    return 0;\r\n  }\r\n}<\/pre>\n<p>\u4e0a\u8a18\u306e\u30ed\u30b8\u30c3\u30af\u3092\u691c\u8a3c\u3059\u308b\u305f\u3081\u306b\u3001\u307e\u305a\u3001\u3059\u3067\u306b\u5b58\u5728\u3057\u3066\u308b\u95a2\u6570\u304c&#8221;\u7a7a\uff08empty\uff09&#8221;\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3002<br \/>\n\u3053\u306e\u5834\u5408\u306e&#8221;\u7a7a\u201d\u3068\u306f\u3001\u305d\u306e\u95a2\u6570\u304c\u57fa\u672c\u30d6\u30ed\u30c3\u30af\u3092\u6301\u305f\u306a\u3044\u3001\u3064\u307e\u308a\u672c\u4f53\u3092\u6301\u305f\u306a\u3044\u3068\u3044\u3046\u4e8b\u3092\u610f\u5473\u3059\u308b\u3002<br \/>\n\u95a2\u6570\u304c\u672c\u4f53\u3092\u6301\u305f\u306a\u3044\u5834\u5408\u3001\u305d\u308c\u306f\u524d\u65b9\u5ba3\u8a00\u3067\u3042\u308b\u3002<br \/>\n\u95a2\u6570\u306e\u5b8c\u5168\u306a\u5b9a\u7fa9\u306e\u5f8c\u306f\u4f55\u3082\u8a31\u53ef\u3055\u308c\u306a\u3044\u306e\u3067\u3001\u305d\u306e\u5834\u5408\u306f\u3053\u306e\u30b3\u30fc\u30c9\u306f\u53d7\u3051\u5165\u308c\u306a\u3044\u3002<br \/>\nextern\u306e\u5834\u5408\u306f\u3001\u4ee5\u524d\u306e\u5ba3\u8a00\u3068\u4eca\u56de\u306e\u5ba3\u8a00\u304c\u5408\u81f4\u3059\u308b\u304b\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306b\u3001\u5358\u7d14\u306b\u5f15\u6570\u306e\u6570\u3060\u3051\u3092\u691c\u8a3c\u3059\u308b\u3002<br \/>\n\u5f15\u6570\u306e\u6570\u304c\u9055\u3046\u5834\u5408\u306f\u3001\u30a8\u30e9\u30fc\u304c\u767a\u884c\u3055\u308c\u308b\u3002<br \/>\n<em>\u8a33\u6ce8: \u57fa\u672c\u30d6\u30ed\u30c3\u30af\u3084\u524d\u65b9\u5ba3\u8a00\u306b\u3064\u3044\u3066\u77e5\u3089\u306a\u3051\u308c\u3070\u30b0\u30b0\u308b\u3079\u3057\u3002<\/em><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">  \/\/ \u5168\u3066\u306e\u5f15\u6570\u306b\u3064\u3044\u3066\u540d\u524d\u3092\u30bb\u30c3\u30c8\u3059\u308b\u3002\r\n  unsigned Idx = 0;\r\n  for (Function::arg_iterator AI = F-&gt;arg_begin(); Idx != Args.size();\r\n       ++AI, ++Idx) {\r\n    AI-&gt;setName(Args&#x5B;Idx]);\r\n\r\n    \/\/ \u5909\u6570\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u306b\u5f15\u6570\u3092\u8ffd\u52a0\u3059\u308b\u3002\r\n    NamedValues&#x5B;Args&#x5B;Idx]] = AI;\r\n  }\r\n  return F;\r\n}<\/pre>\n<p>\u6700\u5f8c\u306e\u3061\u3087\u3063\u3068\u3057\u305f\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306e\u305f\u3081\u306e\u30b3\u30fc\u30c9\u306f\u3001\u73fe\u5728\u306e\u95a2\u6570\u306b\u304a\u3051\u308b\u3059\u3079\u3066\u306e\u5f15\u6570\u306b\u3064\u3044\u3066\u30eb\u30fc\u30d7\u3092\u56de\u3057\u3001LLVM\u5f15\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff08LLVM Argument objects\uff09\u306e\u540d\u524d\u3092\u30bb\u30c3\u30c8\u3057\u3001\u3053\u306e\u5f8cVariableExprAST\u30ce\u30fc\u30c9\u3067\u4f7f\u3048\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u3001NamedValues\u306b\u305d\u306e\u5f15\u6570\u3092\u767b\u9332\u3059\u308b\u3002<br \/>\n\u3053\u308c\u304c\u7d42\u308f\u308c\u3070\u3001\u3053\u306e\u30e1\u30f3\u30d0\u95a2\u6570\u306f\u547c\u3073\u51fa\u3057\u5143\u306b\u95a2\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3059\u3002<br \/>\n\u3053\u3053\u3067\u306f\u3001\u5f15\u6570\u540d\u306e\u91cd\u8907\u306b\u3064\u3044\u3066\u306f\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3044\u306a\u3044\u70b9\u306b\u6ce8\u610f\u3002\uff08\u4f8b\u3048\u3070\u3001&#8221;extern foo(a b a)&#8221;\uff09<br \/>\n\u3053\u308c\u3092\u884c\u3046\u306b\u306f\u3001\u3053\u308c\u307e\u3067\u4f7f\u3063\u3066\u304d\u305f\u65b9\u6cd5\u3092\u4f7f\u3048\u3070\u7c21\u5358\u306b\u5b9f\u88c5\u3067\u304d\u308b\u3060\u308d\u3046\u3002<br \/>\n<em>\u8a33\u6ce8: \u5f15\u6570\u540d\u306fArgs\u914d\u5217\uff08vector&lt;std::string&gt;\uff09\u306b\u5165\u3063\u3066\u308b\u306e\u3067\u3001\u52b9\u7387\u306f\u3055\u3066\u7f6e\u3044\u3066\u91cd\u8907\u3092\u8abf\u3079\u308b\u306e\u306f\u7c21\u5358\u3060\u308d\u3046\u3002<br \/>\n\u5f8c\u306f\u3001\u91cd\u8907\u304c\u3042\u3063\u305f\u5834\u5408\u306b\u95a2\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u6d88\u3057\u3066\u3001return 0 \u3059\u308b\u3060\u3051\u3067\u826f\u3044\u3002\u3093\u3058\u3083\u306a\u3044\u304b\u306a\u3002<\/em><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">Function *FunctionAST::Codegen() {\r\n  NamedValues.clear();\r\n\r\n  Function *TheFunction = Proto-&gt;Codegen();\r\n  if (TheFunction == 0)\r\n    return 0;<\/pre>\n<p>\u95a2\u6570\u5b9a\u7fa9\u306e\u305f\u3081\u306e\u30b3\u30fc\u30c9\u751f\u6210\u51e6\u7406\u306e\u59cb\u307e\u308a\u306f\u3001\u3053\u308c\u3067\u5341\u5206\u3067\u3042\u308b\u3002<br \/>\n\u305d\u306e\u95a2\u6570\u306e\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\uff08Proto\uff09\u306e\u30b3\u30fc\u30c9\u751f\u6210\u3092\u884c\u3044\u3001\u623b\u308a\u5024\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3060\u3051\u3067\u3042\u308b\u3002<br \/>\nNamedValues\uff08std::map&lt;std::string, Value*&gt;\u3001\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\uff09\u3092\u30af\u30ea\u30a2\u3057\u3066\u3044\u308b\u306e\u306f\u3001\u76f4\u524d\u306e\u95a2\u6570\u306e\u30b3\u30f3\u30d1\u30a4\u30eb\u306b\u3088\u308b\u30c7\u30fc\u30bf\u3092\u6d88\u3057\u3066\u3001\u78ba\u5b9f\u306b\u7a7a\u306b\u3059\u308b\u305f\u3081\u3067\u3042\u308b\u3002<br \/>\n\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306e\u30b3\u30fc\u30c9\u751f\u6210\u306b\u3088\u3063\u3066\u3001\u3053\u306e\u5f8c\u306e\u51e6\u7406\u306b\u7528\u3044\u308bLLVM\u95a2\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5b58\u5728\u304c\u78ba\u5b9f\u306a\u3082\u306e\u3068\u306a\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ \u633f\u5165\u3059\u308b\u305f\u3081\u306e\u3001\u65b0\u3057\u3044\u57fa\u672c\u30d6\u30ed\u30c3\u30af\u3092\u4f5c\u6210\u3059\u308b\u3002\r\nBasicBlock *BB = BasicBlock::Create(getGlobalContext(), &quot;entry&quot;, TheFunction);\r\nBuilder.SetInsertPoint(BB);\r\n\r\nif (Value *RetVal = Body-&gt;Codegen()) {<\/pre>\n<p>\u3053\u308c\u306fBuilder\u3092\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3057\u3066\u308b\u90e8\u5206\u3067\u3042\u308b\u3002<br \/>\n\u6700\u521d\u306e\u884c\u3067\u3001\u65b0\u3057\u3044\u57fa\u672c\u30d6\u30ed\u30c3\u30af\uff08\u540d\u524d\u306f&#8221;entry&#8221;\uff09\u304c\u4f5c\u6210\u3055\u308c\u3001TheFunction\u306e\u4e2d\u306b\u633f\u5165\u3055\u308c\u308b\u3002<br \/>\n\u6b21\u306e\u884c\u3067\u3001\u4eca\u5f8c\u306e\u547d\u4ee4\u3092\u65b0\u3057\u3044\u57fa\u672c\u30d6\u30ed\u30c3\u30af\u306e\u672b\u5c3e\u306b\u633f\u5165\u3059\u3079\u304d\u3067\u3042\u308b\u3068\u3044\u3046\u4e8bBuilder\u306b\u4f1d\u3048\u308b\u3002<br \/>\nLLVM\u306b\u304a\u3051\u308b\u57fa\u672c\u30d6\u30ed\u30c3\u30af\u306f\u3001\u5236\u5fa1\u30d5\u30ed\u30fc\u30b0\u30e9\u30d5\uff08Control Flow Graph\uff09\u3092\u5b9a\u7fa9\u3059\u308b\u305f\u3081\u306e\u3001\u95a2\u6570\u306e\u91cd\u8981\u306a\u90e8\u5206\u3067\u3042\u308b\u3002<br \/>\n\u73fe\u6642\u70b9\u3067\u306f\u4f55\u306e\u5236\u5fa1\u30d5\u30ed\u30fc\u3082\u6301\u305f\u306a\u3044\u306e\u3067\u3001\u95a2\u6570\u306f\u3072\u3068\u3064\u306e\u30d6\u30ed\u30c3\u30af\u306e\u307f\u3092\u542b\u3080\u3060\u308d\u3046\u3002<br \/>\n\u3053\u308c\u306b\u3064\u3044\u3066\u306f\u7b2c5\u7ae0\u3067\u6539\u826f\u3059\u308b\u3002<br \/>\n<em>\u8a33\u6ce8: \u5236\u5fa1\u30d5\u30ed\u30fc\u30b0\u30e9\u30d5\u306b\u3064\u3044\u3066\u77e5\u3089\u306a\u3044\u5834\u5408\u306f\u30b0\u30b0\u308b\u3079\u3057\u3002<\/em><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">if (Value *RetVal = Body-&gt;Codegen()) {\r\n  \/\/ \u95a2\u6570\u3092\u4ed5\u4e0a\u3052\u308b\u3002\r\n  Builder.CreateRet(RetVal);\r\n\r\n  \/\/ \u77db\u76fe\u304c\u7121\u3044\u304b\u3001\u751f\u6210\u3055\u308c\u305f\u30b3\u30fc\u30c9\u3092\u691c\u8a3c\u3059\u308b\u3002\r\n  verifyFunction(*TheFunction);\r\n\r\n  return TheFunction;\r\n}<\/pre>\n<p>\u633f\u5165\u70b9\uff08insertion point\uff09\u304c\u30bb\u30c3\u30c8\u3055\u308c\u305f\u3089\u3001\u95a2\u6570\u306e\u30eb\u30fc\u30c8\u5f0f\uff08root expression\uff09\u306e\u305f\u3081\u306bCodeGen()\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3076\u3002<br \/>\n\u4f55\u3082\u30a8\u30e9\u30fc\u304c\u8d77\u304d\u306a\u3051\u308c\u3070\u3001entry\u30d6\u30ed\u30c3\u30af\u306e\u4e2d\u306b\u3001\u5f0f\u3092\u8a08\u7b97\u3057\u305d\u306e\u7d50\u679c\u3092\u8fd4\u3059\u305f\u3081\u306e\u30b3\u30fc\u30c9\u304c\u751f\u6210\u3055\u308b\u3002<br \/>\n\u30a8\u30e9\u30fc\u304c\u8d77\u304d\u306a\u3051\u308c\u3070\u3001\u95a2\u6570\u3092\u5b8c\u6210\u3055\u305b\u308b\u305f\u3081\u3001LLVM\u306eret\u547d\u4ee4\u304c\u751f\u6210\u3055\u308c\u308b\u3002<br \/>\n\u95a2\u6570\u304c\u51fa\u6765\u4e0a\u304c\u3063\u305f\u3089\u3001LLVM\u304c\u63d0\u4f9b\u3059\u308bverifyFunction\u95a2\u6570\u3092\u547c\u3076\u3002<br \/>\n\u3053\u306e\u95a2\u6570\u306f\u3001\u751f\u6210\u3055\u308c\u305f\u30b3\u30fc\u30c9\u306b\u5bfe\u3057\u3066\u7a2e\u3005\u306e\u6574\u5408\u6027\u30c1\u30a7\u30c3\u30af\u3092\u884c\u3046\u3053\u3068\u306b\u3088\u3063\u3066\u3001\u6211\u3005\u306e\u30b3\u30f3\u30d1\u30a4\u30e9\u306e\u52d5\u304d\u306b\u9593\u9055\u3044\u304c\u306a\u3044\u304b\u3092\u8abf\u3079\u308b\u3002<br \/>\n\u591a\u304f\u306e\u30d0\u30b0\u3092\u6355\u307e\u3048\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u306e\u3067\u3001\u3053\u306e\u95a2\u6570\u306f\u91cd\u8981\u3067\u3042\u308b\u3002<br \/>\n\u95a2\u6570\u304c\u5b8c\u6210\u3057\u691c\u8a3c\u3055\u308c\u308c\u3070\u3001\u305d\u308c\u3092\u8fd4\u3059\u3002<br \/>\n<em>\u8a33\u6ce8: ret\u547d\u4ee4\u306f\u4ee5\u4e0b\u306e\u5f62\u3092\u3068\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ret &lt;type&gt; &lt;value&gt;       ; \u975evoid\u95a2\u6570\u304b\u3089\u5024\u3092\u8fd4\u3059\u3002\r\nret void                 ; void\u95a2\u6570\u304b\u3089\u8fd4\u308b\u3002<\/pre>\n<p><\/em><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">  \/\/ \u672c\u4f53\u306e\u30b3\u30fc\u30c9\u751f\u6210\u3067\u30a8\u30e9\u30fc\u304c\u3042\u308c\u3070\u3001\u95a2\u6570\u3092\u6d88\u53bb\u3059\u308b\u3002\r\n  TheFunction-&gt;eraseFromParent();\r\n  return 0;\r\n}<\/pre>\n<p>\u6b8b\u308a\u306f\u3001\u30a8\u30e9\u30fc\u306e\u5834\u5408\u306e\u51e6\u7406\u3060\u3051\u3067\u3042\u308b\u3002<br \/>\n\u7c21\u5358\u306e\u305f\u3081\u3001eraseFromParent\u30e1\u30bd\u30c3\u30c9\u3067\u5358\u306b\u95a2\u6570\u3092\u6d88\u53bb\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u3001\u3053\u306e\u5834\u5408\u3092\u51e6\u7406\u3059\u308b\u3002<br \/>\n\u3053\u308c\u306b\u3088\u3063\u3066\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u4ee5\u524d\u306b\u9593\u9055\u3063\u3066\u5165\u529b\u3057\u305f\u95a2\u6570\u3092\u518d\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3068\u306a\u308b\u3002<br \/>\n\u3082\u3057\u3001\u30a8\u30e9\u30fc\u6642\u306b\u6d88\u53bb\u3057\u306a\u3044\u5834\u5408\u3001\u305d\u306e\u95a2\u6570\u672c\u4f53\u3068\u5171\u306b\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u306b\u6b8b\u308a\u7d9a\u3051\u3001\u518d\u5b9a\u7fa9\u3092\u59a8\u3052\u3066\u3057\u307e\u3046\u3060\u308d\u3046\u3002<\/p>\n<p>\u307e\u3041\u6b63\u76f4\u3044\u3046\u3068\u3001\u3053\u306e\u30b3\u30fc\u30c9\u306b\u306f\u30d0\u30b0\u304c\u3042\u308b\u3002<br \/>\nPrototypeAST::Codegen\u306f\u3001\u4ee5\u524d\u306b\u5b9a\u7fa9\u3055\u308c\u305f\u524d\u65b9\u5ba3\u8a00\u3092\u8fd4\u3059\u53ef\u80fd\u6027\u304c\u3042\u308b\u306e\u3067\u3001\u3053\u306e\u30b3\u30fc\u30c9\u3067\u306f\u5b9f\u306f\u524d\u65b9\u5ba3\u8a00\u3092\u524a\u9664\u3057\u3066\u3057\u307e\u3046\u53ef\u80fd\u6027\u304c\u3042\u308b\u3002<br \/>\n\u3053\u306e\u30d0\u30b0\u3092\u4fee\u6b63\u3059\u308b\u65b9\u6cd5\u306f\u305f\u304f\u3055\u3093\u3042\u308b\u304c\u3001\u3069\u3046\u3084\u3063\u305f\u3089\u305d\u308c\u304c\u53ef\u80fd\u304b\u8003\u3048\u3066\u307f\u3066\u6b32\u3057\u3044\u3002<br \/>\n\u4ee5\u4e0b\u306f\u305d\u306e\u305f\u3081\u306e\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u3067\u3042\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">extern foo(a b);     # ok, defines foo.\r\ndef foo(a b) c;      # error, 'c' is invalid.\r\ndef bar() foo(1, 2); # error, unknown function &quot;foo&quot;<\/pre>\n<p><em>\u8a33\u6ce8: 1\u884c\u76ee\u3067\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u304c\u751f\u6210\u3055\u308c\u308b\u3002<br \/>\n2\u884c\u76ee\u3067\u3001\u4e0d\u660e\u306a\u5909\u6570c\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u30a8\u30e9\u30fc\u3068\u306a\u308b\u3002<br \/>\n\u304c\u3001\u3053\u306e\u3068\u304d\u95a2\u6570\u672c\u4f53\u306e\u5b9a\u7fa9\u3060\u3051\u3067\u306a\u304f1\u884c\u76ee\u3067\u5ba3\u8a00\u3057\u305f\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3082\u6d88\u53bb\u3055\u308c\u308b\u3002<br \/>\n\u3088\u3063\u3066\u30013\u884c\u76ee\u3067foo\u3068\u3044\u3046\u95a2\u6570\u304c\u4e0d\u660e\u3068\u3044\u3046\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u3002<br \/>\n\u95a2\u6570\u672c\u4f53\u306e\u5b9a\u7fa9\u306b\u30a8\u30e9\u30fc\u304c\u3042\u3063\u3066\u3082\u3001\u4e8b\u524d\u306b\u5ba3\u8a00\u3055\u308c\u305f\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3092\u6d88\u53bb\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308c\u3070\u30013\u884c\u76ee\u3067\u306f\u30a8\u30e9\u30fc\u306f\u51fa\u306a\u304f\u306a\u308b\u306f\u305a\u3067\u3042\u308b\u3002<\/em><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[466,467],"class_list":["post-2938","post","type-post","status-publish","format-standard","hentry","category-tech","tag-kaleidoscope","tag-llvm"],"_links":{"self":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/2938","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/comments?post=2938"}],"version-history":[{"count":0,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/2938\/revisions"}],"wp:attachment":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/media?parent=2938"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/categories?post=2938"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/tags?post=2938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}