准引用 LLVM 中的引用变量
Reference variable in quasiquoted LLVM
如何将变量传递到准引用部分?
我正在使用 llvm-quote-general 并想将 Type
传递到我正在使用准引用器构建的指令中。
我可以仅从文本构建指令:
alloci64 :: Instruction
alloci64 = [lli|alloc i64|]
我希望能够传入一个类型。这样做的语法是什么?
alloc :: Type -> Instruction
alloc t = [lli|alloc t|]
我已经尝试了以下所有方法,其中 none 有效。它们导致 lexer error
s.
[lli|alloc $t|]
[lli|alloc $$t|]
[lli|alloc $t$|]
[lli|alloc $$t$$|]
库中的quasiquoter是用happy生成的。查看源代码,我能找到的与反引号相关的标记最接近的是符号happy_dollar_dollar
,它似乎没有在任何地方定义。
编辑:我解决了 Type
秒的问题;一个例子是 [lli|alloc $type:t]
操作数
我用 Type
s 解决了这个问题,但仍然不知道如何反引用一般的东西。我想使用 Operand
s 构建指令。尝试这样做会导致错误。
add' :: Operand -> Operand -> Instruction
add' a b = [lli|add $opr:a $opr:b|]
^
parse error on `ANTI_OPR'
pre-happy source 建议以下所有内容,包括 $opr:
应该做某事
<0> {
"$dl:" / { allowAnti } { lexAnti Tanti_dl }
"$dlM:" / { allowAnti } { lexAntiM Tanti_dl }
"$tt:" / { allowAnti } { lexAnti Tanti_tt }
"$ttM:" / { allowAnti } { lexAntiM Tanti_tt }
"$def:" / { allowAnti } { lexAnti Tanti_def }
"$defM:" / { allowAnti } { lexAntiM Tanti_def }
"$defs:" / { allowAnti } { lexAnti Tanti_defs }
"$defsM:" / { allowAnti } { lexAntiM Tanti_defs }
"$bb:" / { allowAnti } { lexAnti Tanti_bb }
"$bbM:" / { allowAnti } { lexAntiM Tanti_bb }
"$bbs:" / { allowAnti } { lexAnti Tanti_bbs }
"$bbsM:" / { allowAnti } { lexAntiM Tanti_bbs }
"$instr:" / { allowAnti } { lexAnti Tanti_instr }
"$instrM:" / { allowAnti } { lexAntiM Tanti_instr }
"$instrs:" / { allowAnti } { lexAnti Tanti_instrs }
"$instrsM:" / { allowAnti } { lexAntiM Tanti_instrs }
"$type:" / { allowAnti } { lexAnti Tanti_type }
"$typeM:" / { allowAnti } { lexAntiM Tanti_type }
"$opr:" / { allowAnti } { lexAnti Tanti_opr }
"$oprM:" / { allowAnti } { lexAntiM Tanti_opr }
"$const:" / { allowAnti } { lexAnti Tanti_const }
"$constM:" / { allowAnti } { lexAntiM Tanti_const }
"$id:" / { allowAnti } { lexAnti Tanti_id }
"$idM:" / { allowAnti } { lexAntiM Tanti_id }
"$gid:" / { allowAnti } { lexAnti Tanti_gid }
"$gidM:" / { allowAnti } { lexAntiM Tanti_gid }
"$param:" / { allowAnti } { lexAnti Tanti_param }
"$paramM:" / { allowAnti } { lexAntiM Tanti_param }
"$params:" / { allowAnti } { lexAnti Tanti_params }
"$paramsM:" / { allowAnti } { lexAntiM Tanti_params }
}
再摆弄一些,以下工作正常
alloc :: Type -> Instruction
alloc t = [lli|alloc $type:t|]
字符串 "type"
在 the source code 中,其他示例包含 $exp:e1
之类的文本,但没有解释它是什么。
如何将变量传递到准引用部分?
我正在使用 llvm-quote-general 并想将 Type
传递到我正在使用准引用器构建的指令中。
我可以仅从文本构建指令:
alloci64 :: Instruction
alloci64 = [lli|alloc i64|]
我希望能够传入一个类型。这样做的语法是什么?
alloc :: Type -> Instruction
alloc t = [lli|alloc t|]
我已经尝试了以下所有方法,其中 none 有效。它们导致 lexer error
s.
[lli|alloc $t|]
[lli|alloc $$t|]
[lli|alloc $t$|]
[lli|alloc $$t$$|]
库中的quasiquoter是用happy生成的。查看源代码,我能找到的与反引号相关的标记最接近的是符号happy_dollar_dollar
,它似乎没有在任何地方定义。
编辑:我解决了 Type
秒的问题;一个例子是 [lli|alloc $type:t]
操作数
我用 Type
s 解决了这个问题,但仍然不知道如何反引用一般的东西。我想使用 Operand
s 构建指令。尝试这样做会导致错误。
add' :: Operand -> Operand -> Instruction
add' a b = [lli|add $opr:a $opr:b|]
^
parse error on `ANTI_OPR'
pre-happy source 建议以下所有内容,包括 $opr:
应该做某事
<0> {
"$dl:" / { allowAnti } { lexAnti Tanti_dl }
"$dlM:" / { allowAnti } { lexAntiM Tanti_dl }
"$tt:" / { allowAnti } { lexAnti Tanti_tt }
"$ttM:" / { allowAnti } { lexAntiM Tanti_tt }
"$def:" / { allowAnti } { lexAnti Tanti_def }
"$defM:" / { allowAnti } { lexAntiM Tanti_def }
"$defs:" / { allowAnti } { lexAnti Tanti_defs }
"$defsM:" / { allowAnti } { lexAntiM Tanti_defs }
"$bb:" / { allowAnti } { lexAnti Tanti_bb }
"$bbM:" / { allowAnti } { lexAntiM Tanti_bb }
"$bbs:" / { allowAnti } { lexAnti Tanti_bbs }
"$bbsM:" / { allowAnti } { lexAntiM Tanti_bbs }
"$instr:" / { allowAnti } { lexAnti Tanti_instr }
"$instrM:" / { allowAnti } { lexAntiM Tanti_instr }
"$instrs:" / { allowAnti } { lexAnti Tanti_instrs }
"$instrsM:" / { allowAnti } { lexAntiM Tanti_instrs }
"$type:" / { allowAnti } { lexAnti Tanti_type }
"$typeM:" / { allowAnti } { lexAntiM Tanti_type }
"$opr:" / { allowAnti } { lexAnti Tanti_opr }
"$oprM:" / { allowAnti } { lexAntiM Tanti_opr }
"$const:" / { allowAnti } { lexAnti Tanti_const }
"$constM:" / { allowAnti } { lexAntiM Tanti_const }
"$id:" / { allowAnti } { lexAnti Tanti_id }
"$idM:" / { allowAnti } { lexAntiM Tanti_id }
"$gid:" / { allowAnti } { lexAnti Tanti_gid }
"$gidM:" / { allowAnti } { lexAntiM Tanti_gid }
"$param:" / { allowAnti } { lexAnti Tanti_param }
"$paramM:" / { allowAnti } { lexAntiM Tanti_param }
"$params:" / { allowAnti } { lexAnti Tanti_params }
"$paramsM:" / { allowAnti } { lexAntiM Tanti_params }
}
再摆弄一些,以下工作正常
alloc :: Type -> Instruction
alloc t = [lli|alloc $type:t|]
字符串 "type"
在 the source code 中,其他示例包含 $exp:e1
之类的文本,但没有解释它是什么。