LLVM:通过OCaml绑定定义新类型 [英] LLVM: Defining a new type via OCaml bindings

查看:66
本文介绍了LLVM:通过OCaml绑定定义新类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LLVM OCaml绑定为无类型语言构建编译器.不幸的是,我唯一的参考是来源中的 llvm.mli .

I'm using the LLVM OCaml bindings to build a compiler for an untyped language. Unfortunately, the only reference I have is llvm.mli from the source.

因此,我尝试声明一个 value_t 如下:

So, I tried declaring a value_t as follows:

let llar = [| i64_type;
              array_type i8_type 10;
              vector_type i64_type 10 |] in
let value_t = struct_type llar in
declare_global value_t "value_t" the_module

在生成函数之前.发出的是:

before I generate functions. What gets emitted is:

@value_t = external global { i64, [10 x i8], <10 x i64> }

稍后再参考,我尝试使用 type_by_name ,但没有找到匹配的方法.如果我使用 lookup_global ,则会得到一个 llvalue 而不是 lltype (我该怎么办?).我想我真正想要的是:

To reference it later, I tried using type_by_name, but nothing matched; if I use lookup_global, I get a llvalue instead of an lltype (what do I do with it?). I guess what I really wanted is:

@value_t = type { i64, [10 x i8], <10 x i64> }

希望我可以与此配合使用 type_by_name .有关如何生成此内容的任何提示?

Hopefully, I'll be able to use type_by_name with this. Any hints on how to generate this?

推荐答案

你想要的函数是named_struct_typestruct_set_body:

let llvalue_t = named_struct_type context "value_t" in
struct_set_body llvalue_t llar false

这篇关于LLVM:通过OCaml绑定定义新类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆