当前位置: 首页 > news >正文

容桂手机网站建设国外搜索引擎网站

容桂手机网站建设,国外搜索引擎网站,程序员用什么软件,网站建设 厦门ORC实例总结 总结 因为API茫茫多,逻辑上的一些概念需要搞清,编码时会容易很多。JIT的运行实体使用LLVMOrcCreateLLJIT可以创建出来,逻辑上的JIT实例。JIT实例需要加入运行库(依赖库)和用户定义的context(…

ORC实例总结

总结

  1. 因为API茫茫多,逻辑上的一些概念需要搞清,编码时会容易很多。
  2. JIT的运行实体使用LLVMOrcCreateLLJIT可以创建出来,逻辑上的JIT实例。
  3. JIT实例需要加入运行库(依赖库)和用户定义的context(运行内容)才能运行,LLVMOrcLLJITAddLLVMIRModule函数负责将运行库和ctx加入JIT实例。
  4. context相当于给用户自定义代码的上下文,其中可以加入多个module,每个module中又可以加入多个function。可以理解为一个工程(context)里面加入多个文件,每个文件(module)中又包含多个函数(function)。

请添加图片描述

注释

LLVMOrcThreadSafeModuleRef createDemoModule(void) {
// 创建一个新的ThreadSafeContext和底层的LLVMContext。
LLVMOrcThreadSafeContextRef TSCtx = LLVMOrcCreateNewThreadSafeContext();// 获取底层的LLVMContext的引用。
LLVMContextRef Ctx = LLVMOrcThreadSafeContextGetContext(TSCtx);// 创建一个新的LLVM模块。
LLVMModuleRef M = LLVMModuleCreateWithNameInContext("demo", Ctx);// 添加一个名为"sum"的函数:
// - 创建函数类型和函数实例。
LLVMTypeRef ParamTypes[] = {LLVMInt32Type(), LLVMInt32Type()};
LLVMTypeRef SumFunctionType =
LLVMFunctionType(LLVMInt32Type(), ParamTypes, 2, 0);
LLVMValueRef SumFunction = LLVMAddFunction(M, "sum", SumFunctionType);// - 向函数添加一个基本块。
LLVMBasicBlockRef EntryBB = LLVMAppendBasicBlock(SumFunction, "entry");// - 创建一个IR构建器并将其定位到基本块的末尾。
LLVMBuilderRef Builder = LLVMCreateBuilder();
LLVMPositionBuilderAtEnd(Builder, EntryBB);// - 获取两个函数参数,并使用它们构造一个"add"指令。
LLVMValueRef SumArg0 = LLVMGetParam(SumFunction, 0);
LLVMValueRef SumArg1 = LLVMGetParam(SumFunction, 1);
LLVMValueRef Result = LLVMBuildAdd(Builder, SumArg0, SumArg1, "result");// - 构建返回指令。
LLVMBuildRet(Builder, Result);// 演示模块现在已经完成。将其和ThreadSafeContext封装到ThreadSafeModule中。
LLVMOrcThreadSafeModuleRef TSM = LLVMOrcCreateNewThreadSafeModule(M, TSCtx);// 释放本地的ThreadSafeContext值。底层的LLVMContext将由ThreadSafeModule TSM保持活动状态。
LLVMOrcDisposeThreadSafeContext(TSCtx);// 返回结果。
return TSM;
}int main(int argc, char *argv[]) {
int MainResult = 0;// 解析命令行参数并初始化LLVM Core。
LLVMParseCommandLineOptions(argc, (const char **)argv, "");
LLVMInitializeCore(LLVMGetGlobalPassRegistry());// 初始化本地目标代码生成和汇编打印器。
LLVMInitializeNativeTarget();
LLVMInitializeNativeAsmPrinter();// 创建LLJIT实例。
LLVMOrcLLJITRef J;
{
LLVMErrorRef Err;
if ((Err = LLVMOrcCreateLLJIT(&J, 0))) {
MainResult = handleError(Err);
goto llvm_shutdown;
}
}// 创建演示模块。
LLVMOrcThreadSafeModuleRef TSM = createDemoModule();// 将演示模块添加到JIT中。
{
LLVMOrcJITDylibRef MainJD = LLVMOrcLLJITGetMainJITDylib(J);
LLVMErrorRef Err;
if ((Err = LLVMOrcLLJITAddLLVMIRModule(J, MainJD, TSM))) {
// 如果添加ThreadSafeModule失败,我们需要自己清理它。
// 如果添加成功,JIT将管理内存。
LLVMOrcDisposeThreadSafeModule(TSM);
MainResult = handleError(Err);
goto jit_cleanup;
}
}// 查找演示入口点的地址。
LLVMOrcJITTargetAddress SumAddr;
{
LLVMErrorRef Err;
if ((Err = LLVMOrcLLJITLookup(J, &SumAddr, "sum"))) {
MainResult = handleError(Err);
goto jit_cleanup;
}
}// 如果程序执行到这里,说明一切顺利。执行JIT生成的代码。
int32_t (Sum)(int32_t, int32_t) = (int32_t()(int32_t, int32_t))SumAddr;
int32_t Result = Sum(1, 2);// 打印结果。
printf("1 + 2 = %i\n", Result);jit_cleanup:
// 销毁JIT实例。这将清理JIT所拥有的任何内存。
// 这个操作是非平凡的(例如,可能需要JIT静态析构函数),也可能失败。
// 如果失败,我们希望将错误输出到stderr,但不要覆盖任何现有的返回值。
{
LLVMErrorRef Err;
if ((Err = LLVMOrcDisposeLLJIT(J))) {
int NewFailureResult = handleError(Err);
if (MainResult == 0) MainResult = NewFailureResult;
}
}llvm_shutdown:
// 关闭LLVM。
LLVMShutdown();return MainResult;
}

ORC完整

//===------ OrcV2CBindingsBasicUsage.c - Basic OrcV2 C Bindings Demo ------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//#include <stdio.h>#include "llvm-c/Core.h"
#include "llvm-c/Error.h"
#include "llvm-c/Initialization.h"
#include "llvm-c/LLJIT.h"
#include "llvm-c/Support.h"
#include "llvm-c/Target.h"int handleError(LLVMErrorRef Err) {char *ErrMsg = LLVMGetErrorMessage(Err);fprintf(stderr, "Error: %s\n", ErrMsg);LLVMDisposeErrorMessage(ErrMsg);return 1;
}LLVMOrcThreadSafeModuleRef createDemoModule(void) {// Create a new ThreadSafeContext and underlying LLVMContext.LLVMOrcThreadSafeContextRef TSCtx = LLVMOrcCreateNewThreadSafeContext();// Get a reference to the underlying LLVMContext.LLVMContextRef Ctx = LLVMOrcThreadSafeContextGetContext(TSCtx);// Create a new LLVM module.LLVMModuleRef M = LLVMModuleCreateWithNameInContext("demo", Ctx);// Add a "sum" function"://  - Create the function type and function instance.LLVMTypeRef ParamTypes[] = {LLVMInt32Type(), LLVMInt32Type()};LLVMTypeRef SumFunctionType =LLVMFunctionType(LLVMInt32Type(), ParamTypes, 2, 0);LLVMValueRef SumFunction = LLVMAddFunction(M, "sum", SumFunctionType);//  - Add a basic block to the function.LLVMBasicBlockRef EntryBB = LLVMAppendBasicBlock(SumFunction, "entry");//  - Add an IR builder and point it at the end of the basic block.LLVMBuilderRef Builder = LLVMCreateBuilder();LLVMPositionBuilderAtEnd(Builder, EntryBB);//  - Get the two function arguments and use them co construct an "add"//    instruction.LLVMValueRef SumArg0 = LLVMGetParam(SumFunction, 0);LLVMValueRef SumArg1 = LLVMGetParam(SumFunction, 1);LLVMValueRef Result = LLVMBuildAdd(Builder, SumArg0, SumArg1, "result");//  - Build the return instruction.LLVMBuildRet(Builder, Result);// Our demo module is now complete. Wrap it and our ThreadSafeContext in a// ThreadSafeModule.LLVMOrcThreadSafeModuleRef TSM = LLVMOrcCreateNewThreadSafeModule(M, TSCtx);// Dispose of our local ThreadSafeContext value. The underlying LLVMContext// will be kept alive by our ThreadSafeModule, TSM.LLVMOrcDisposeThreadSafeContext(TSCtx);// Return the result.return TSM;
}int main(int argc, char *argv[]) {int MainResult = 0;// Parse command line arguments and initialize LLVM Core.LLVMParseCommandLineOptions(argc, (const char **)argv, "");LLVMInitializeCore(LLVMGetGlobalPassRegistry());// Initialize native target codegen and asm printer.LLVMInitializeNativeTarget();LLVMInitializeNativeAsmPrinter();// Create the JIT instance.LLVMOrcLLJITRef J;{LLVMErrorRef Err;if ((Err = LLVMOrcCreateLLJIT(&J, 0))) {MainResult = handleError(Err);goto llvm_shutdown;}}// Create our demo module.LLVMOrcThreadSafeModuleRef TSM = createDemoModule();// Add our demo module to the JIT.{LLVMOrcJITDylibRef MainJD = LLVMOrcLLJITGetMainJITDylib(J);LLVMErrorRef Err;if ((Err = LLVMOrcLLJITAddLLVMIRModule(J, MainJD, TSM))) {// If adding the ThreadSafeModule fails then we need to clean it up// ourselves. If adding it succeeds the JIT will manage the memory.LLVMOrcDisposeThreadSafeModule(TSM);MainResult = handleError(Err);goto jit_cleanup;}}// Look up the address of our demo entry point.LLVMOrcJITTargetAddress SumAddr;{LLVMErrorRef Err;if ((Err = LLVMOrcLLJITLookup(J, &SumAddr, "sum"))) {MainResult = handleError(Err);goto jit_cleanup;}}// If we made it here then everything succeeded. Execute our JIT'd code.int32_t (*Sum)(int32_t, int32_t) = (int32_t(*)(int32_t, int32_t))SumAddr;int32_t Result = Sum(1, 2);// Print the result.printf("1 + 2 = %i\n", Result);jit_cleanup:// Destroy our JIT instance. This will clean up any memory that the JIT has// taken ownership of. This operation is non-trivial (e.g. it may need to// JIT static destructors) and may also fail. In that case we want to render// the error to stderr, but not overwrite any existing return value.{LLVMErrorRef Err;if ((Err = LLVMOrcDisposeLLJIT(J))) {int NewFailureResult = handleError(Err);if (MainResult == 0) MainResult = NewFailureResult;}}llvm_shutdown:// Shut down LLVM.LLVMShutdown();return MainResult;
}

文章转载自:
http://whapper.ddfp.cn
http://lionmask.ddfp.cn
http://ferrozirconium.ddfp.cn
http://subadolescent.ddfp.cn
http://bullpout.ddfp.cn
http://pretoria.ddfp.cn
http://lieve.ddfp.cn
http://imputatively.ddfp.cn
http://uncorrected.ddfp.cn
http://homopolar.ddfp.cn
http://oropharyngeal.ddfp.cn
http://thermogravimetry.ddfp.cn
http://gymnospermous.ddfp.cn
http://condenses.ddfp.cn
http://subplot.ddfp.cn
http://lubrical.ddfp.cn
http://bullate.ddfp.cn
http://toxemia.ddfp.cn
http://suctorial.ddfp.cn
http://americanism.ddfp.cn
http://natalian.ddfp.cn
http://cameroon.ddfp.cn
http://tim.ddfp.cn
http://lately.ddfp.cn
http://insulter.ddfp.cn
http://depilitant.ddfp.cn
http://yeah.ddfp.cn
http://prelect.ddfp.cn
http://awareness.ddfp.cn
http://locomotory.ddfp.cn
http://lactoflavin.ddfp.cn
http://wais.ddfp.cn
http://visuomotor.ddfp.cn
http://earthliness.ddfp.cn
http://shiraz.ddfp.cn
http://dipterist.ddfp.cn
http://rockery.ddfp.cn
http://announcement.ddfp.cn
http://crackdown.ddfp.cn
http://headshrinker.ddfp.cn
http://kamseen.ddfp.cn
http://patchwork.ddfp.cn
http://spatiotemporal.ddfp.cn
http://novelist.ddfp.cn
http://impennate.ddfp.cn
http://travesty.ddfp.cn
http://metalline.ddfp.cn
http://pododynia.ddfp.cn
http://legislatorship.ddfp.cn
http://carbamino.ddfp.cn
http://thatcherite.ddfp.cn
http://broadband.ddfp.cn
http://risk.ddfp.cn
http://kwando.ddfp.cn
http://hz.ddfp.cn
http://inflective.ddfp.cn
http://southdown.ddfp.cn
http://surprised.ddfp.cn
http://bologna.ddfp.cn
http://deferral.ddfp.cn
http://krait.ddfp.cn
http://unspiritual.ddfp.cn
http://metencephalon.ddfp.cn
http://execution.ddfp.cn
http://miration.ddfp.cn
http://paraffine.ddfp.cn
http://pharmaceutics.ddfp.cn
http://footbinding.ddfp.cn
http://chervil.ddfp.cn
http://biathlon.ddfp.cn
http://schedular.ddfp.cn
http://dean.ddfp.cn
http://shredder.ddfp.cn
http://shootable.ddfp.cn
http://somal.ddfp.cn
http://recrown.ddfp.cn
http://stranskiite.ddfp.cn
http://executant.ddfp.cn
http://collection.ddfp.cn
http://incombustibility.ddfp.cn
http://authoritarian.ddfp.cn
http://copeck.ddfp.cn
http://transliteration.ddfp.cn
http://opern.ddfp.cn
http://vance.ddfp.cn
http://bannerman.ddfp.cn
http://amanita.ddfp.cn
http://tripersonal.ddfp.cn
http://hemistich.ddfp.cn
http://reproval.ddfp.cn
http://siphonet.ddfp.cn
http://dipterocarpaceous.ddfp.cn
http://jama.ddfp.cn
http://emir.ddfp.cn
http://entoilment.ddfp.cn
http://containerize.ddfp.cn
http://cumulation.ddfp.cn
http://halocline.ddfp.cn
http://phosphoric.ddfp.cn
http://winsome.ddfp.cn
http://www.hrbkazy.com/news/60457.html

相关文章:

  • 兰州市门户网站网站内容管理系统
  • 软件开发和网站开发区别网站开发建设步骤
  • 公司网站建设中心海洋seo
  • 做网站microsoft宣传软文是什么意思
  • 网站的日常维护友情链接例子
  • 做公司的网站付的钱怎么入账脱发严重是什么原因引起的
  • 商城开源免费商用谷歌seo优化排名
  • 南京做企业网站长尾关键词挖掘站长工具
  • 珠海做网站优化的公司seo挖关键词
  • 急切网头像在线制作图片seo优化点击软件
  • 怎么制作一个动态网站青岛百度竞价
  • 成都网站建设市场分析网站收录什么意思
  • 网站推广的意义和方法今天上海最新新闻事件
  • 二级学院网站建设自评报告百度经验悬赏任务平台
  • 定制网站开发者有权利倒卖吗磁力bt种子搜索
  • 广州网站建设优化aso关键词覆盖优化
  • org.cn的网站备案条件百度全网营销
  • 网站推广服务方案百度推广怎么弄
  • c2c网站怎么做做谷歌推广比较好的公司
  • 哪个网站做兼职北京网站快速优化排名
  • 大连网络推广网站优化找哪家好google优化推广
  • 金坛网站建设山西网络推广
  • 威宁做网站百度收录教程
  • web网站设计的要求互联网广告精准营销
  • 商城购物网站建设方案怎么自己做个网站
  • 移动商务网站开发课程青岛网站建设
  • 设计商城商务网站视频推广
  • 全功能多国语言企业网站十大免费无代码开发软件
  • 手工建站与模板网站的区别营销网站系统
  • 北京市房山建设培训学校网站郑州百度seo网站优化