简体   繁体   English

声明在llvmlite中返回void的函数时出现AssertionError

[英]AssertionError while declaring function which returns void in llvmlite

I am trying to create a function which returns void in llvm-ir but a creation of such function gives AssertionError 我正在尝试创建一个在llvm-ir中返回void的函数,但是此类函数的创建给出了AssertionError

import llvmlite.ir as ir

int32 = ir.IntType(32)
m = ir.Module('demo')

main_ty = ir.FunctionType(int32, [])
main_fn = ir.Function(m, main_ty, "main")

print(str(m))

The above code works fine as the return type is int32 , and gives the following output, which is as expected. 上面的代码可以正常工作,因为返回类型为int32 ,并给出以下输出,这与预期的一样。

; ModuleID = "demo"
target triple = "unknown-unknown-unknown"
target datalayout = ""

declare i32 @"main"() 

but when I change the return type from int32 to VoidType it raises the AssertionError. 但是,当我将返回类型从int32更改为VoidType它将引发AssertionError。

m = ir.Module('demo')
main_ty = ir.FunctionType(ir.VoidType, [])
main_fn = ir.Function(m, main_ty, "main")
print(str(m))

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-2-298d109233fd> in <module>
      1 m = ir.Module('demo')
      2 main_ty = ir.FunctionType(ir.VoidType, [])
----> 3 main_fn = ir.Function(m, main_ty, "main")
      4 print(str(m))

~/.local/lib/python3.6/site-packages/llvmlite/ir/values.py in __init__(self, module, ftype, name)
    593         self.args = tuple([Argument(self, t)
    594                            for t in ftype.args])
--> 595         self.return_value = ReturnValue(self, ftype.return_type)
    596         self.parent.add_global(self)
    597         self.calling_convention = ''

~/.local/lib/python3.6/site-packages/llvmlite/ir/values.py in __init__(self, parent, typ, name)
    718 class _BaseArgument(NamedValue):
    719     def __init__(self, parent, typ, name=''):
--> 720         assert isinstance(typ, types.Type)
    721         super(_BaseArgument, self).__init__(parent, typ, name=name)
    722         self.parent = parent

AssertionError: 

Can anyone help me what I am missing here? 谁能帮我我在这里想念的东西吗?

VoidType is a class just like IntType is. VoidType是一类就像IntType是。 You still need to apply it (with zero arguments), to create an instance: 您仍然需要应用它(使用零参数)来创建实例:

main_ty = ir.FunctionType(ir.VoidType(), [])
//                                   ^^

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pandas AssertionError 应用 function 时返回包含列表的元组 - Pandas AssertionError when applying function which returns tuple containing list /graphql/ 处的 AssertionError 查询字段必须是一个以字段名称作为键的映射(dict / OrderedDict)或返回此类映射的 function - AssertionError at /graphql/ Query fields must be a mapping (dict / OrderedDict) with field names as keys or a function which returns such a mapping AssertionError:试图导出引用未跟踪资源的 function - AssertionError: Tried to export a function which references untracked resource Windows 7 上的 virtualenv 返回 AssertionError - virtualenv on windows 7 returns AssertionError 使用 pip 安装 turicreate 时出错 ...同时为 llvmlite 构建轮子 - Error while installing turicreate using pip …while building wheel for llvmlite 插入误差线时出现 AssertionError - AssertionError while inserting errorbars 如何在另一个函数内部调用多次返回变量的函数? - How do I call a function which returns a variable, multiple times, while inside another function? pytest`AssertionError:视图函数映射正在覆盖现有的端点函数:`flask-restful而注册蓝图 - pytest `AssertionError: View function mapping is overwriting an existing endpoint function:` flask-restful while registring blueprint tf.keras.Model 保存:“断言错误:试图导出一个引用未跟踪对象张量的函数” - tf.keras.Model save: "AssertionError: Tried to export a function which references untracked object Tensor" 当为 function 参数化时,href 属性返回“javascript:void(0)”? - href attribute returns “javascript:void(0)” when parameterized for a function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM