Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用LLVM API在可变变量中存储全局字符串_Php_String_Ocaml_Llvm - Fatal编程技术网

Php 使用LLVM API在可变变量中存储全局字符串

Php 使用LLVM API在可变变量中存储全局字符串,php,string,ocaml,llvm,Php,String,Ocaml,Llvm,我正在使用LLVM和OCaml为PHP的一个子集制作一个编译器。LLVM中的字符串处理教程有点缺乏——至少我找不到 这是我要编译的代码: <?php $a = "foo"; 以及我的错误消息: Stored value type does not match pointer operand type! store i8* getelementptr inbounds ([4 x i8]* @asd, i32 0, i32 0), i8* %"$a" i8LLVM ERROR: B

我正在使用LLVM和OCaml为PHP的一个子集制作一个编译器。LLVM中的字符串处理教程有点缺乏——至少我找不到

这是我要编译的代码:

<?php

$a = "foo";
以及我的错误消息:

Stored value type does not match pointer operand type!
  store i8* getelementptr inbounds ([4 x i8]* @asd, i32 0, i32 0), i8* %"$a"
 i8LLVM ERROR: Broken module found, compilation aborted!
问题是
i8*%“$a”
应该是
i8**%“$a”
,如简单C程序的LLVM IR所示:

int main() {
  char* str = "Hello, world!";
  puts(str);
  return 0;
}
这将生成此LLVM IR:

@.str = private unnamed_addr constant [14 x i8] c"Hello, world!\00", align 1

; Function Attrs: nounwind uwtable
define i32 @main() #0 {
  %1 = alloca i32, align 4
  %str = alloca i8*, align 8
  store i32 0, i32* %1
  store i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0), i8** %str, align 8
  %2 = load i8** %str, align 8
  %3 = call i32 @puts(i8* %2)
  ret i32 0
}
感谢您的帮助。

通过更改分配代码解决了(我真的希望如此)。而不是

build_alloca i8_t ...
应该是

build_alloca (pointer_type i8_t) ...
我通过直接编辑生成的代码,然后用llc编译来调试它,以查看需要更改的内容

build_alloca i8_t ...
build_alloca (pointer_type i8_t) ...