| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
wanenjie
8年前发布

Swift开源:LLVMSwift - LLVM C API 的 Swift 封装库

   <h2>LLVMSwift</h2>    <p>LLVMSwift is a set of Swifty API wrappers for the LLVM C API. It makes compiler development feel great from Swift!</p>    <h2>Usage</h2>    <p>To start emitting IR, you'll want to create a Module object, with an optional Context parameter, and an IRBuilder that will build instructions for that module.</p>    <pre>  <code class="language-swift">let module = Module(name: "main")  let builder = IRBuilder(module: module)</code></pre>    <p>Once you do that, you can start adding functions, global variables, and generating instructions!</p>    <pre>  <code class="language-swift">let main = builder.addFunction(name: "main",                                  type: FunctionType(argTypes: [],                                                     returnType: VoidType())  let entry = builder.appendBasicBlock(named: "entry")  builder.positionAtEnd(of: entry)    builder.buildRetVoid()    module.dump()</code></pre>    <p>The IRBuilder class has methods for almost all functions from the LLVM C API, like:</p>    <ul>     <li>builder.buildAdd</li>     <li>builder.buildSub</li>     <li>builder.buildMul</li>     <li>builder.buildCondBr</li>     <li>builder.addSwitch</li>    </ul>    <p>and so many more.</p>    <p>Plus, it provides common wrappers around oft-used types like Function , Global , Switch , and PhiNode .</p>    <h2>Installation</h2>    <p>There are a couple, annoying steps you need to get it working before it'll build. Number one, you'll need a custom cllvm pkg-config file, which is included in the repo. Drop that in /usr/local/lib/pkgconfig and make sure you have LLVM installed through homebrew :</p>    <pre>  <code class="language-swift">brew install llvm</code></pre>    <p>Once you do that, you can add LLVMSwift as a dependency for your own Swift compiler projects!</p>    <p>This project is used byTrill for all its code generation.</p>    <h2>Authors</h2>    <ul>     <li>Harlan Haskins (@harlanhaskins)</li>     <li>Robert Widmann (@CodaFi)</li>    </ul>    <h2>License</h2>    <p>This project is released under the MIT license, a copy of which is available in this repo.</p>    <p> </p>    <p> </p>    <p> </p>    
 本文由用户 wanenjie 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1484099787019.html
LLVM API Swift Apple Swift开发