From ad3f5f1551e8a450af44a6bd26405844c21126de Mon Sep 17 00:00:00 2001 From: Anthony Ferrara Date: Tue, 16 Apr 2019 09:58:49 -0400 Subject: [PATCH] A few more changes, getting dockerhub setup and building initial images --- .circleci/config.yml | 3 + Docker/dev/ubuntu-16.04/Dockerfile | 34 + Docker/{ => dev}/ubuntu-16.04/php.ini | 0 Docker/{ => dev}/ubuntu-18.04/Dockerfile | 0 Docker/{ => dev}/ubuntu-18.04/php.ini | 0 Docker/ubuntu-16.04/Dockerfile | 35 +- Makefile | 23 +- README.md | 2 + examples/000-HelloWorld/example.bc | 166 +- examples/000-HelloWorld/example.s | 326 +- examples/README.md | 2 +- lib/JIT/Builtin/Type/Value.php | 3433 ++++++++++++---------- src/macro_functions.php | 5 +- 13 files changed, 2361 insertions(+), 1668 deletions(-) mode change 100644 => 100755 .circleci/config.yml create mode 100755 Docker/dev/ubuntu-16.04/Dockerfile rename Docker/{ => dev}/ubuntu-16.04/php.ini (100%) rename Docker/{ => dev}/ubuntu-18.04/Dockerfile (100%) rename Docker/{ => dev}/ubuntu-18.04/php.ini (100%) mode change 100644 => 100755 src/macro_functions.php diff --git a/.circleci/config.yml b/.circleci/config.yml old mode 100644 new mode 100755 index c6470ca..a3d91b5 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,3 +9,6 @@ jobs: - run: make build - run: make phan - run: make test + - run: | + docker login -u $DOCKER_USER -p $DOCKER_PASS + docker push ircmaxell/php-compiler:16.04-dev diff --git a/Docker/dev/ubuntu-16.04/Dockerfile b/Docker/dev/ubuntu-16.04/Dockerfile new file mode 100755 index 0000000..c3ec7e4 --- /dev/null +++ b/Docker/dev/ubuntu-16.04/Dockerfile @@ -0,0 +1,34 @@ +FROM ubuntu:16.04 + +RUN mkdir compiler && \ + apt-get update && \ + apt-get -y install git build-essential gdb llvm-4.0-dev clang-4.0 unzip curl libcurl4-openssl-dev autoconf libssl-dev libgd-dev libzip-dev bison re2c libxml2-dev libsqlite3-dev libonig-dev vim clang + +RUN curl -L https://github.com/php/php-src/archive/PHP-7.4.zip -o PHP-7.4.zip && unzip PHP-7.4.zip && mv php-src-PHP-7.4 php + +WORKDIR php + +RUN ./buildconf && \ + ./configure --disable-cgi --with-ffi --with-openssl --enable-mbstring --with-pcre-jit --with-zlib --enable-bcmath --with-curl --with-gd --enable-pcntl --enable-zip && \ + make -j16 && \ + make install + +WORKDIR ../ + +RUN curl --silent --show-error https://getcomposer.org/installer | php + +ENV PHP="/usr/local/bin/php", PHP_7_4="/usr/local/bin/php", PHP_CS_FIXER_IGNORE_ENV="true" + +COPY php.ini /usr/local/lib/php.ini + +WORKDIR php-ast + +RUN git clone https://github.com/nikic/php-ast . && \ + phpize && \ + ./configure && \ + make && \ + make install + +WORKDIR ../compiler + +CMD ["/bin/bash"] diff --git a/Docker/ubuntu-16.04/php.ini b/Docker/dev/ubuntu-16.04/php.ini similarity index 100% rename from Docker/ubuntu-16.04/php.ini rename to Docker/dev/ubuntu-16.04/php.ini diff --git a/Docker/ubuntu-18.04/Dockerfile b/Docker/dev/ubuntu-18.04/Dockerfile similarity index 100% rename from Docker/ubuntu-18.04/Dockerfile rename to Docker/dev/ubuntu-18.04/Dockerfile diff --git a/Docker/ubuntu-18.04/php.ini b/Docker/dev/ubuntu-18.04/php.ini similarity index 100% rename from Docker/ubuntu-18.04/php.ini rename to Docker/dev/ubuntu-18.04/php.ini diff --git a/Docker/ubuntu-16.04/Dockerfile b/Docker/ubuntu-16.04/Dockerfile index c3ec7e4..43581bd 100755 --- a/Docker/ubuntu-16.04/Dockerfile +++ b/Docker/ubuntu-16.04/Dockerfile @@ -1,34 +1,15 @@ -FROM ubuntu:16.04 - -RUN mkdir compiler && \ - apt-get update && \ - apt-get -y install git build-essential gdb llvm-4.0-dev clang-4.0 unzip curl libcurl4-openssl-dev autoconf libssl-dev libgd-dev libzip-dev bison re2c libxml2-dev libsqlite3-dev libonig-dev vim clang - -RUN curl -L https://github.com/php/php-src/archive/PHP-7.4.zip -o PHP-7.4.zip && unzip PHP-7.4.zip && mv php-src-PHP-7.4 php - -WORKDIR php - -RUN ./buildconf && \ - ./configure --disable-cgi --with-ffi --with-openssl --enable-mbstring --with-pcre-jit --with-zlib --enable-bcmath --with-curl --with-gd --enable-pcntl --enable-zip && \ - make -j16 && \ - make install +FROM ircmaxell/php-compiler:16.04-dev WORKDIR ../ -RUN curl --silent --show-error https://getcomposer.org/installer | php - -ENV PHP="/usr/local/bin/php", PHP_7_4="/usr/local/bin/php", PHP_CS_FIXER_IGNORE_ENV="true" - -COPY php.ini /usr/local/lib/php.ini +RUN curl -L https://github.com/ircmaxell/php-compiler/archive/master.zip -o master.zip && \ + unzip master.zip && \ + mv php-compiler-master/* compiler/ -WORKDIR php-ast +WORKDIR compiler -RUN git clone https://github.com/nikic/php-ast . && \ - phpize && \ - ./configure && \ - make && \ - make install +RUN php /composer.phar install --no-ansi --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader -WORKDIR ../compiler +ENTRYPOINT ["php", "/compiler/bin/jit.php"] -CMD ["/bin/bash"] +CMD ["-r", "'echo \"Hello World\n\";'"] \ No newline at end of file diff --git a/Makefile b/Makefile index 74a9abd..b278949 100755 --- a/Makefile +++ b/Makefile @@ -2,43 +2,44 @@ .PHONY: composer-install composer-install: - docker run -v $(shell pwd):/compiler php-compiler-16-04 php /composer.phar install + docker run -v $(shell pwd):/compiler ircmaxell/php-compiler:16.04-dev php /composer.phar install --no-ansi --no-interaction --no-progress .PHONY: shell shell: - docker run -it --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v $(shell pwd):/compiler php-compiler-16-04 /bin/bash + docker run -it --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v $(shell pwd):/compiler ircmaxell/php-compiler:16.04-dev /bin/bash .PHONY: docker-build docker-build: - docker build -t php-compiler-16-04 Docker/ubuntu-16.04 + docker build -t ircmaxell/php-compiler:16.04-dev Docker/dev/ubuntu-16.04 + docker build -t ircmaxell/php-compiler:16.04 Docker/ubuntu-16.04 .PHONY: benchmark benchmark: rebuild-changed - docker run -v $(shell pwd):/compiler php-compiler-16-04 php script/bench.php + docker run -v $(shell pwd):/compiler ircmaxell/php-compiler:16.04-dev php script/bench.php .PHONY: build -build: docker-build composer-install rebuild rebuild-examples +build: composer-install rebuild rebuild-examples .PHONY: rebuild rebuild: - docker run -v $(shell pwd):/compiler php-compiler-16-04 php script/rebuild.php + docker run -v $(shell pwd):/compiler ircmaxell/php-compiler:16.04-dev php script/rebuild.php .PHONY: rebuild-changed rebuild-changed: - docker run -v $(shell pwd):/compiler php-compiler-16-04 php script/rebuild.php onlyChanged + docker run -v $(shell pwd):/compiler ircmaxell/php-compiler:16.04-dev php script/rebuild.php onlyChanged .PHONY: rebuild-examples rebuild-examples: - docker run -v $(shell pwd):/compiler php-compiler-16-04 php script/rebuild-examples.php + docker run -v $(shell pwd):/compiler ircmaxell/php-compiler:16.04-dev php script/rebuild-examples.php .PHONY: fix fix: - docker run -v $(shell pwd):/compiler php-compiler-16-04 php vendor/bin/php-cs-fixer fix --allow-risky=yes + docker run -v $(shell pwd):/compiler ircmaxell/php-compiler:16.04-dev php vendor/bin/php-cs-fixer fix --allow-risky=yes .PHONY: phan phan: - docker run -v $(shell pwd):/compiler php-compiler-16-04 php vendor/bin/phan + docker run -v $(shell pwd):/compiler ircmaxell/php-compiler:16.04-dev php vendor/bin/phan .PHONY: test test: rebuild-changed - docker run -v $(shell pwd):/compiler php-compiler-16-04 php vendor/bin/phpunit \ No newline at end of file + docker run -v $(shell pwd):/compiler ircmaxell/php-compiler:16.04-dev php vendor/bin/phpunit \ No newline at end of file diff --git a/README.md b/README.md index 7371006..e5c9ad3 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # A compiler for PHP +[![CircleCI](https://circleci.com/gh/ircmaxell/php-compiler.svg?style=svg)](https://circleci.com/gh/ircmaxell/php-compiler) + Ok, so this used to be a dead project. It required calling out to all sorts of hackery to generate PHP extensions, or PHP itself. Now, thanks to [FFI landing in PHP 7.4](https://wiki.php.net/rfc/ffi), the potential for all sorts of crazy is HUGE. diff --git a/examples/000-HelloWorld/example.bc b/examples/000-HelloWorld/example.bc index e006c61..3a81c30 100644 --- a/examples/000-HelloWorld/example.bc +++ b/examples/000-HelloWorld/example.bc @@ -5,6 +5,7 @@ source_filename = "main" %__ref__ = type <{ i32, i32 }> %__ref__virtual = type <{ %__ref__ }> %__value__ = type <{ i8, [8 x i8] }> +%__value__value = type <{ %__ref__, %__value__ }> @string_const_0 = global %__string__* null @0 = global [1 x i8] zeroinitializer @@ -258,22 +259,175 @@ main: } ; Function Attrs: alwaysinline -declare void @__value__valueDelref(%__value__*) #0 +define void @__value__valueDelref(%__value__*) #0 { +main: + %1 = getelementptr inbounds %__value__, %__value__* %0, i32 0, i32 0 + %2 = load i8, i8* %1 + %3 = and i8 %2, -128 + %4 = icmp ne i8 %3, 0 + br i1 %4, label %ifBlock, label %endBlock + +endBlock: ; preds = %ifBlock, %main + ret void + +ifBlock: ; preds = %main + %5 = getelementptr inbounds %__value__, %__value__* %0, i32 0, i32 1 + %6 = bitcast [8 x i8]* %5 to %__ref__virtual* + call void @__ref__delref(%__ref__virtual* %6) + br label %endBlock +} ; Function Attrs: alwaysinline -declare %__value__* @__value__toNumeric(%__value__*) #0 +define %__value__* @__value__toNumeric(%__value__*) #0 { +main: + %1 = getelementptr inbounds %__value__, %__value__* %0, i32 0, i32 0 + %2 = load i8, i8* %1 + switch i8 %2, label %default [ + i8 1, label %case_0 + i8 3, label %case_01 + i8 -122, label %case_02 + ] + +end: ; preds = %default + %3 = alloca %__value__ + call void @__value__writeLong(%__value__* %3, i64 0) + ret %__value__* %3 + +case_0: ; preds = %main + %4 = bitcast %__value__* %0 to %__ref__virtual* + call void @__ref__addref(%__ref__virtual* %4) + ret %__value__* %0 + +case_01: ; preds = %main + %5 = bitcast %__value__* %0 to %__ref__virtual* + call void @__ref__addref(%__ref__virtual* %5) + ret %__value__* %0 + +case_02: ; preds = %main + %6 = getelementptr inbounds %__value__, %__value__* %0, i32 0, i32 1 + %7 = bitcast [8 x i8]* %6 to %__value__value* + %8 = getelementptr inbounds %__value__value, %__value__value* %7, i32 0, i32 1 + %9 = call %__value__* @__value__toNumeric(%__value__* %8) + %10 = icmp eq %__value__* %9, %8 + br i1 %10, label %ifBlock, label %endBlock + +endBlock: ; preds = %ifBlock, %case_02 + ret %__value__* %9 + +ifBlock: ; preds = %case_02 + %11 = bitcast [8 x i8]* %6 to %__ref__virtual* + call void @__ref__addref(%__ref__virtual* %11) + br label %endBlock + +default: ; preds = %main + br label %end +} ; Function Attrs: alwaysinline -declare i64 @__value__readLong(%__value__*) #0 +define i64 @__value__readLong(%__value__*) #0 { +main: + %1 = getelementptr inbounds %__value__, %__value__* %0, i32 0, i32 0 + %2 = load i8, i8* %1 + switch i8 %2, label %default [ + i8 1, label %case_0 + i8 3, label %case_01 + i8 -122, label %case_02 + ] + +end: ; preds = %default + ret i64 0 + +case_0: ; preds = %main + %3 = getelementptr inbounds %__value__, %__value__* %0, i32 0, i32 1 + %4 = bitcast [8 x i8]* %3 to i64* + %5 = getelementptr i64, i64* %4, i32 0 + %6 = load i64, i64* %5 + ret i64 %6 + +case_01: ; preds = %main + %7 = getelementptr inbounds %__value__, %__value__* %0, i32 0, i32 1 + %8 = bitcast [8 x i8]* %7 to double* + %9 = getelementptr double, double* %8, i32 0 + %10 = load double, double* %9 + %11 = fptosi double %10 to i64 + ret i64 %11 + +case_02: ; preds = %main + %12 = getelementptr inbounds %__value__, %__value__* %0, i32 0, i32 1 + %13 = bitcast [8 x i8]* %12 to %__value__value* + %14 = getelementptr inbounds %__value__value, %__value__value* %13, i32 0, i32 1 + %15 = call i64 @__value__readLong(%__value__* %14) + ret i64 %15 + +default: ; preds = %main + br label %end +} ; Function Attrs: alwaysinline -declare void @__value__writeLong(%__value__*, i64) #0 +define void @__value__writeLong(%__value__*, i64) #0 { +main: + call void @__value__valueDelref(%__value__* %0) + %2 = getelementptr inbounds %__value__, %__value__* %0, i32 0, i32 0 + store i8 1, i8* %2 + %3 = getelementptr inbounds %__value__, %__value__* %0, i32 0, i32 1 + %4 = bitcast [8 x i8]* %3 to i64* + %5 = getelementptr i64, i64* %4, i32 0 + store i64 %1, i64* %5 + ret void +} ; Function Attrs: alwaysinline -declare double @__value__readDouble(%__value__*) #0 +define double @__value__readDouble(%__value__*) #0 { +main: + %1 = getelementptr inbounds %__value__, %__value__* %0, i32 0, i32 0 + %2 = load i8, i8* %1 + switch i8 %2, label %default [ + i8 1, label %case_0 + i8 3, label %case_01 + i8 -122, label %case_02 + ] + +end: ; preds = %default + ret double 0.000000e+00 + +case_0: ; preds = %main + %3 = getelementptr inbounds %__value__, %__value__* %0, i32 0, i32 1 + %4 = bitcast [8 x i8]* %3 to i64* + %5 = getelementptr i64, i64* %4, i32 0 + %6 = load i64, i64* %5 + %7 = sitofp i64 %6 to double + ret double %7 + +case_01: ; preds = %main + %8 = getelementptr inbounds %__value__, %__value__* %0, i32 0, i32 1 + %9 = bitcast [8 x i8]* %8 to double* + %10 = getelementptr double, double* %9, i32 0 + %11 = load double, double* %10 + ret double %11 + +case_02: ; preds = %main + %12 = getelementptr inbounds %__value__, %__value__* %0, i32 0, i32 1 + %13 = bitcast [8 x i8]* %12 to %__value__value* + %14 = getelementptr inbounds %__value__value, %__value__value* %13, i32 0, i32 1 + %15 = call double @__value__readDouble(%__value__* %14) + ret double %15 + +default: ; preds = %main + br label %end +} ; Function Attrs: alwaysinline -declare void @__value__writeDouble(%__value__*, double) #0 +define void @__value__writeDouble(%__value__*, double) #0 { +main: + call void @__value__valueDelref(%__value__* %0) + %2 = getelementptr inbounds %__value__, %__value__* %0, i32 0, i32 0 + store i8 3, i8* %2 + %3 = getelementptr inbounds %__value__, %__value__* %0, i32 0, i32 1 + %4 = bitcast [8 x i8]* %3 to double* + %5 = getelementptr double, double* %4, i32 0 + store double %1, double* %5 + ret void +} ; Function Attrs: alwaysinline declare %__string__* @__value__readString(%__value__*) #0 diff --git a/examples/000-HelloWorld/example.s b/examples/000-HelloWorld/example.s index 3a4f2b9..c8820d0 100644 --- a/examples/000-HelloWorld/example.s +++ b/examples/000-HelloWorld/example.s @@ -403,13 +403,303 @@ __string__separate: .size __string__separate, .Lfunc_end12-__string__separate .cfi_endproc + .globl __value__valueDelref + .p2align 4, 0x90 + .type __value__valueDelref,@function +__value__valueDelref: + .cfi_startproc + pushq %rax +.Lcfi10: + .cfi_def_cfa_offset 16 + movb (%rdi), %al + andb $-128, %al + cmpb $0, %al + movq %rdi, (%rsp) + jne .LBB13_2 +.LBB13_1: + popq %rax + retq +.LBB13_2: + movq (%rsp), %rax + addq $1, %rax + movabsq $__ref__delref, %rcx + movq %rax, %rdi + callq *%rcx + jmp .LBB13_1 +.Lfunc_end13: + .size __value__valueDelref, .Lfunc_end13-__value__valueDelref + .cfi_endproc + + .globl __value__toNumeric + .p2align 4, 0x90 + .type __value__toNumeric,@function +__value__toNumeric: + .cfi_startproc + pushq %rbp +.Lcfi11: + .cfi_def_cfa_offset 16 +.Lcfi12: + .cfi_offset %rbp, -16 + movq %rsp, %rbp +.Lcfi13: + .cfi_def_cfa_register %rbp + subq $80, %rsp + movb (%rdi), %al + movb %al, %cl + subb $-122, %cl + movq %rdi, -8(%rbp) + movb %al, -9(%rbp) + movb %cl, -10(%rbp) + je .LBB14_4 + jmp .LBB14_8 +.LBB14_8: + movb -9(%rbp), %al + subb $1, %al + movb %al, -11(%rbp) + je .LBB14_2 + jmp .LBB14_9 +.LBB14_9: + movb -9(%rbp), %al + subb $3, %al + movb %al, -12(%rbp) + je .LBB14_3 + jmp .LBB14_7 +.LBB14_1: + xorl %eax, %eax + movl %eax, %ecx + movq %rsp, %rdx + addq $-16, %rdx + movq %rdx, %rsp + movabsq $__value__writeLong, %rsi + xorl %eax, %eax + movl %eax, %edi + movq %rdi, -24(%rbp) + movq %rdx, %rdi + movq -24(%rbp), %r8 + movq %rsi, -32(%rbp) + movq %r8, %rsi + movq -32(%rbp), %r9 + movq %rcx, -40(%rbp) + movq %rdx, -48(%rbp) + callq *%r9 + movq -48(%rbp), %rax + movq %rbp, %rsp + popq %rbp + retq +.LBB14_2: + movq -8(%rbp), %rax + movabsq $__ref__addref, %rcx + movq %rax, %rdi + callq *%rcx + movq -8(%rbp), %rax + movq %rbp, %rsp + popq %rbp + retq +.LBB14_3: + movq -8(%rbp), %rax + movabsq $__ref__addref, %rcx + movq %rax, %rdi + callq *%rcx + movq -8(%rbp), %rax + movq %rbp, %rsp + popq %rbp + retq +.LBB14_4: + movq -8(%rbp), %rax + addq $1, %rax + movq %rax, %rcx + addq $8, %rcx + movabsq $__value__toNumeric, %rdx + movq %rcx, %rdi + movq %rax, -56(%rbp) + movq %rcx, -64(%rbp) + callq *%rdx + movq -64(%rbp), %rcx + cmpq %rcx, %rax + movq %rax, -72(%rbp) + je .LBB14_6 +.LBB14_5: + movq -72(%rbp), %rax + movq %rbp, %rsp + popq %rbp + retq +.LBB14_6: + movq -56(%rbp), %rax + movabsq $__ref__addref, %rcx + movq %rax, %rdi + callq *%rcx + jmp .LBB14_5 +.LBB14_7: + jmp .LBB14_1 +.Lfunc_end14: + .size __value__toNumeric, .Lfunc_end14-__value__toNumeric + .cfi_endproc + + .globl __value__readLong + .p2align 4, 0x90 + .type __value__readLong,@function +__value__readLong: + .cfi_startproc + subq $24, %rsp +.Lcfi14: + .cfi_def_cfa_offset 32 + movb (%rdi), %al + movb %al, %cl + subb $-122, %cl + movq %rdi, 16(%rsp) + movb %al, 15(%rsp) + movb %cl, 14(%rsp) + je .LBB15_4 + jmp .LBB15_6 +.LBB15_6: + movb 15(%rsp), %al + subb $1, %al + movb %al, 13(%rsp) + je .LBB15_2 + jmp .LBB15_7 +.LBB15_7: + movb 15(%rsp), %al + subb $3, %al + movb %al, 12(%rsp) + je .LBB15_3 + jmp .LBB15_5 +.LBB15_1: + xorl %eax, %eax + addq $24, %rsp + retq +.LBB15_2: + movq 16(%rsp), %rax + movq 1(%rax), %rax + addq $24, %rsp + retq +.LBB15_3: + movq 16(%rsp), %rax + cvttsd2si 1(%rax), %rax + addq $24, %rsp + retq +.LBB15_4: + movq 16(%rsp), %rax + addq $1, %rax + addq $8, %rax + movabsq $__value__readLong, %rcx + movq %rax, %rdi + callq *%rcx + addq $24, %rsp + retq +.LBB15_5: + jmp .LBB15_1 +.Lfunc_end15: + .size __value__readLong, .Lfunc_end15-__value__readLong + .cfi_endproc + + .globl __value__writeLong + .p2align 4, 0x90 + .type __value__writeLong,@function +__value__writeLong: + .cfi_startproc + subq $24, %rsp +.Lcfi15: + .cfi_def_cfa_offset 32 + movabsq $__value__valueDelref, %rax + movq %rdi, 16(%rsp) + movq %rsi, 8(%rsp) + callq *%rax + movq 16(%rsp), %rax + movb $1, (%rax) + movq 8(%rsp), %rsi + movq %rsi, 1(%rax) + addq $24, %rsp + retq +.Lfunc_end16: + .size __value__writeLong, .Lfunc_end16-__value__writeLong + .cfi_endproc + + .globl __value__readDouble + .p2align 4, 0x90 + .type __value__readDouble,@function +__value__readDouble: + .cfi_startproc + subq $24, %rsp +.Lcfi16: + .cfi_def_cfa_offset 32 + movb (%rdi), %al + movb %al, %cl + subb $-122, %cl + movq %rdi, 16(%rsp) + movb %al, 15(%rsp) + movb %cl, 14(%rsp) + je .LBB17_4 + jmp .LBB17_6 +.LBB17_6: + movb 15(%rsp), %al + subb $1, %al + movb %al, 13(%rsp) + je .LBB17_2 + jmp .LBB17_7 +.LBB17_7: + movb 15(%rsp), %al + subb $3, %al + movb %al, 12(%rsp) + je .LBB17_3 + jmp .LBB17_5 +.LBB17_1: + xorps %xmm0, %xmm0 + addq $24, %rsp + retq +.LBB17_2: + movq 16(%rsp), %rax + cvtsi2sdq 1(%rax), %xmm0 + addq $24, %rsp + retq +.LBB17_3: + movq 16(%rsp), %rax + movsd 1(%rax), %xmm0 + addq $24, %rsp + retq +.LBB17_4: + movq 16(%rsp), %rax + addq $1, %rax + addq $8, %rax + movabsq $__value__readDouble, %rcx + movq %rax, %rdi + callq *%rcx + addq $24, %rsp + retq +.LBB17_5: + jmp .LBB17_1 +.Lfunc_end17: + .size __value__readDouble, .Lfunc_end17-__value__readDouble + .cfi_endproc + + .globl __value__writeDouble + .p2align 4, 0x90 + .type __value__writeDouble,@function +__value__writeDouble: + .cfi_startproc + subq $24, %rsp +.Lcfi17: + .cfi_def_cfa_offset 32 + movabsq $__value__valueDelref, %rax + movq %rdi, 16(%rsp) + movsd %xmm0, 8(%rsp) + callq *%rax + movq 16(%rsp), %rax + movb $3, (%rax) + movsd 8(%rsp), %xmm0 + movsd %xmm0, 1(%rax) + addq $24, %rsp + retq +.Lfunc_end18: + .size __value__writeDouble, .Lfunc_end18-__value__writeDouble + .cfi_endproc + .globl __init__ .p2align 4, 0x90 .type __init__,@function __init__: .cfi_startproc pushq %rax -.Lcfi10: +.Lcfi18: .cfi_def_cfa_offset 16 movabsq $__unnamed_1, %rsi movabsq $__string__init, %rax @@ -428,8 +718,8 @@ __init__: movq %rax, (%rsi) popq %rax retq -.Lfunc_end13: - .size __init__, .Lfunc_end13-__init__ +.Lfunc_end19: + .size __init__, .Lfunc_end19-__init__ .cfi_endproc .globl __shutdown__ @@ -438,7 +728,7 @@ __init__: __shutdown__: .cfi_startproc pushq %rax -.Lcfi11: +.Lcfi19: .cfi_def_cfa_offset 16 movabsq $string_const_0, %rax movq (%rax), %rdi @@ -453,8 +743,8 @@ __shutdown__: callq *%rax popq %rax retq -.Lfunc_end14: - .size __shutdown__, .Lfunc_end14-__shutdown__ +.Lfunc_end20: + .size __shutdown__, .Lfunc_end20-__shutdown__ .cfi_endproc .globl str_repeat @@ -463,7 +753,7 @@ __shutdown__: str_repeat: .cfi_startproc subq $216, %rsp -.Lcfi12: +.Lcfi20: .cfi_def_cfa_offset 224 leaq 208(%rsp), %rax movq $0, 208(%rsp) @@ -498,16 +788,16 @@ str_repeat: movq %rax, %rdi callq *%rcx movq $0, 200(%rsp) -.LBB15_1: +.LBB21_1: movq 200(%rsp), %rax cmpq 192(%rsp), %rax setl %cl andb $1, %cl movb %cl, 191(%rsp) testb $1, 191(%rsp) - jne .LBB15_2 - jmp .LBB15_4 -.LBB15_2: + jne .LBB21_2 + jmp .LBB21_4 +.LBB21_2: leaq 208(%rsp), %rax movq 208(%rsp), %rcx movq 176(%rsp), %rdx @@ -562,8 +852,8 @@ str_repeat: movq %rax, 160(%rsp) movq 160(%rsp), %rax movq %rax, 200(%rsp) - jmp .LBB15_1 -.LBB15_4: + jmp .LBB21_1 +.LBB21_4: leaq 208(%rsp), %rax movabsq $__ref__addref, %rcx movq %rax, %rdi @@ -587,8 +877,8 @@ str_repeat: movq 8(%rsp), %rax addq $216, %rsp retq -.Lfunc_end15: - .size str_repeat, .Lfunc_end15-str_repeat +.Lfunc_end21: + .size str_repeat, .Lfunc_end21-str_repeat .cfi_endproc .globl internal_1 @@ -597,7 +887,7 @@ str_repeat: internal_1: .cfi_startproc pushq %rax -.Lcfi13: +.Lcfi21: .cfi_def_cfa_offset 16 movabsq $string_const_1, %rax movq (%rax), %rax @@ -613,8 +903,8 @@ internal_1: movl %eax, 4(%rsp) popq %rax retq -.Lfunc_end16: - .size internal_1, .Lfunc_end16-internal_1 +.Lfunc_end22: + .size internal_1, .Lfunc_end22-internal_1 .cfi_endproc .type string_const_0,@object diff --git a/examples/README.md b/examples/README.md index 147f602..0210b3e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -10,5 +10,5 @@ Each example includes a benchmark that compares each mode of operation to just r | Example Name | Native PHP | bin/vm.php | bin/jit.php | bin/compile.php | ./compiled | |----------------------|-----------------|-----------------|-----------------|-----------------|-----------------| -| 000-HelloWorld | 0.01147 | 0.07213 | 0.17435 | 0.20752 | 0.00154 | +| 000-HelloWorld | 0.01242 | 0.06492 | 0.15396 | 0.18702 | 0.00137 | diff --git a/lib/JIT/Builtin/Type/Value.php b/lib/JIT/Builtin/Type/Value.php index 5acccee..4a3d490 100644 --- a/lib/JIT/Builtin/Type/Value.php +++ b/lib/JIT/Builtin/Type/Value.php @@ -1,1740 +1,1908 @@ context->context->namedStructType('__value__'); - // declare first so recursive structs are possible :) - $this->context->registerType('__value__', $struct___cfcd208495d565ef66e7dff9f98764da); - $this->context->registerType('__value__' . '*', $struct___cfcd208495d565ef66e7dff9f98764da->pointerType(0)); - $this->context->registerType('__value__' . '**', $struct___cfcd208495d565ef66e7dff9f98764da->pointerType(0)->pointerType(0)); - $struct___cfcd208495d565ef66e7dff9f98764da->setBody( - false , // packed - $this->context->getTypeFromString('int8') - , $this->context->getTypeFromString('int8[8]') - + // declare first so recursive structs are possible :) + $this->context->registerType('__value__', $struct___cfcd208495d565ef66e7dff9f98764da); + $this->context->registerType('__value__'.'*', $struct___cfcd208495d565ef66e7dff9f98764da->pointerType(0)); + $this->context->registerType('__value__'.'**', $struct___cfcd208495d565ef66e7dff9f98764da->pointerType(0)->pointerType(0)); + $struct___cfcd208495d565ef66e7dff9f98764da->setBody( + false, // packed + $this->context->getTypeFromString('int8'), $this->context->getTypeFromString('int8[8]') + ); - $this->context->structFieldMap['__value__'] = [ - 'type' => 0 - , 'value' => 1 - - ]; - - + $this->context->structFieldMap['__value__'] = [ + 'type' => 0, 'value' => 1, - + ]; $struct___cfcd208495d565ef66e7dff9f98764da = $this->context->context->namedStructType('__value__value'); - // declare first so recursive structs are possible :) - $this->context->registerType('__value__value', $struct___cfcd208495d565ef66e7dff9f98764da); - $this->context->registerType('__value__value' . '*', $struct___cfcd208495d565ef66e7dff9f98764da->pointerType(0)); - $this->context->registerType('__value__value' . '**', $struct___cfcd208495d565ef66e7dff9f98764da->pointerType(0)->pointerType(0)); - $struct___cfcd208495d565ef66e7dff9f98764da->setBody( - false , // packed - $this->context->getTypeFromString('__ref__') - , $this->context->getTypeFromString('__value__') - + // declare first so recursive structs are possible :) + $this->context->registerType('__value__value', $struct___cfcd208495d565ef66e7dff9f98764da); + $this->context->registerType('__value__value'.'*', $struct___cfcd208495d565ef66e7dff9f98764da->pointerType(0)); + $this->context->registerType('__value__value'.'**', $struct___cfcd208495d565ef66e7dff9f98764da->pointerType(0)->pointerType(0)); + $struct___cfcd208495d565ef66e7dff9f98764da->setBody( + false, // packed + $this->context->getTypeFromString('__ref__'), $this->context->getTypeFromString('__value__') + ); - $this->context->structFieldMap['__value__value'] = [ - 'ref' => 0 - , 'value' => 1 - - ]; - - $fntype___cfcd208495d565ef66e7dff9f98764da = $this->context->context->functionType( + $this->context->structFieldMap['__value__value'] = [ + 'ref' => 0, 'value' => 1, + + ]; + + $fntype___cfcd208495d565ef66e7dff9f98764da = $this->context->context->functionType( $this->context->getTypeFromString('void'), - false , + false, $this->context->getTypeFromString('__value__*') - + ); - $fn___cfcd208495d565ef66e7dff9f98764da = $this->context->module->addFunction('__value__valueDelref', $fntype___cfcd208495d565ef66e7dff9f98764da); - $fn___cfcd208495d565ef66e7dff9f98764da->addAttributeAtIndex(PHPLLVM\Attribute::INDEX_FUNCTION, $this->context->attributes['alwaysinline']); - - - - $this->context->registerFunction('__value__valueDelref', $fn___cfcd208495d565ef66e7dff9f98764da); - - - - - - $fntype___cfcd208495d565ef66e7dff9f98764da = $this->context->context->functionType( + $fn___cfcd208495d565ef66e7dff9f98764da = $this->context->module->addFunction('__value__valueDelref', $fntype___cfcd208495d565ef66e7dff9f98764da); + $fn___cfcd208495d565ef66e7dff9f98764da->addAttributeAtIndex(PHPLLVM\Attribute::INDEX_FUNCTION, $this->context->attributes['alwaysinline']); + + $this->context->registerFunction('__value__valueDelref', $fn___cfcd208495d565ef66e7dff9f98764da); + + $fntype___cfcd208495d565ef66e7dff9f98764da = $this->context->context->functionType( $this->context->getTypeFromString('__value__*'), - false , + false, $this->context->getTypeFromString('__value__*') - + ); - $fn___cfcd208495d565ef66e7dff9f98764da = $this->context->module->addFunction('__value__toNumeric', $fntype___cfcd208495d565ef66e7dff9f98764da); - $fn___cfcd208495d565ef66e7dff9f98764da->addAttributeAtIndex(PHPLLVM\Attribute::INDEX_FUNCTION, $this->context->attributes['alwaysinline']); - - - - $this->context->registerFunction('__value__toNumeric', $fn___cfcd208495d565ef66e7dff9f98764da); - - - - - - $fntype___cfcd208495d565ef66e7dff9f98764da = $this->context->context->functionType( + $fn___cfcd208495d565ef66e7dff9f98764da = $this->context->module->addFunction('__value__toNumeric', $fntype___cfcd208495d565ef66e7dff9f98764da); + $fn___cfcd208495d565ef66e7dff9f98764da->addAttributeAtIndex(PHPLLVM\Attribute::INDEX_FUNCTION, $this->context->attributes['alwaysinline']); + + $this->context->registerFunction('__value__toNumeric', $fn___cfcd208495d565ef66e7dff9f98764da); + + $fntype___cfcd208495d565ef66e7dff9f98764da = $this->context->context->functionType( $this->context->getTypeFromString('int64'), - false , + false, $this->context->getTypeFromString('__value__*') - + ); - $fn___cfcd208495d565ef66e7dff9f98764da = $this->context->module->addFunction('__value__readLong', $fntype___cfcd208495d565ef66e7dff9f98764da); - $fn___cfcd208495d565ef66e7dff9f98764da->addAttributeAtIndex(PHPLLVM\Attribute::INDEX_FUNCTION, $this->context->attributes['alwaysinline']); - - - - $this->context->registerFunction('__value__readLong', $fn___cfcd208495d565ef66e7dff9f98764da); - - - - - - $fntype___cfcd208495d565ef66e7dff9f98764da = $this->context->context->functionType( + $fn___cfcd208495d565ef66e7dff9f98764da = $this->context->module->addFunction('__value__readLong', $fntype___cfcd208495d565ef66e7dff9f98764da); + $fn___cfcd208495d565ef66e7dff9f98764da->addAttributeAtIndex(PHPLLVM\Attribute::INDEX_FUNCTION, $this->context->attributes['alwaysinline']); + + $this->context->registerFunction('__value__readLong', $fn___cfcd208495d565ef66e7dff9f98764da); + + $fntype___cfcd208495d565ef66e7dff9f98764da = $this->context->context->functionType( $this->context->getTypeFromString('void'), - false , - $this->context->getTypeFromString('__value__*') - , $this->context->getTypeFromString('int64') - + false, + $this->context->getTypeFromString('__value__*'), $this->context->getTypeFromString('int64') + ); - $fn___cfcd208495d565ef66e7dff9f98764da = $this->context->module->addFunction('__value__writeLong', $fntype___cfcd208495d565ef66e7dff9f98764da); - $fn___cfcd208495d565ef66e7dff9f98764da->addAttributeAtIndex(PHPLLVM\Attribute::INDEX_FUNCTION, $this->context->attributes['alwaysinline']); - - - - - $this->context->registerFunction('__value__writeLong', $fn___cfcd208495d565ef66e7dff9f98764da); - - - - - - $fntype___cfcd208495d565ef66e7dff9f98764da = $this->context->context->functionType( + $fn___cfcd208495d565ef66e7dff9f98764da = $this->context->module->addFunction('__value__writeLong', $fntype___cfcd208495d565ef66e7dff9f98764da); + $fn___cfcd208495d565ef66e7dff9f98764da->addAttributeAtIndex(PHPLLVM\Attribute::INDEX_FUNCTION, $this->context->attributes['alwaysinline']); + + $this->context->registerFunction('__value__writeLong', $fn___cfcd208495d565ef66e7dff9f98764da); + + $fntype___cfcd208495d565ef66e7dff9f98764da = $this->context->context->functionType( $this->context->getTypeFromString('double'), - false , + false, $this->context->getTypeFromString('__value__*') - + ); - $fn___cfcd208495d565ef66e7dff9f98764da = $this->context->module->addFunction('__value__readDouble', $fntype___cfcd208495d565ef66e7dff9f98764da); - $fn___cfcd208495d565ef66e7dff9f98764da->addAttributeAtIndex(PHPLLVM\Attribute::INDEX_FUNCTION, $this->context->attributes['alwaysinline']); - - - - $this->context->registerFunction('__value__readDouble', $fn___cfcd208495d565ef66e7dff9f98764da); - - - - - - $fntype___cfcd208495d565ef66e7dff9f98764da = $this->context->context->functionType( + $fn___cfcd208495d565ef66e7dff9f98764da = $this->context->module->addFunction('__value__readDouble', $fntype___cfcd208495d565ef66e7dff9f98764da); + $fn___cfcd208495d565ef66e7dff9f98764da->addAttributeAtIndex(PHPLLVM\Attribute::INDEX_FUNCTION, $this->context->attributes['alwaysinline']); + + $this->context->registerFunction('__value__readDouble', $fn___cfcd208495d565ef66e7dff9f98764da); + + $fntype___cfcd208495d565ef66e7dff9f98764da = $this->context->context->functionType( $this->context->getTypeFromString('void'), - false , - $this->context->getTypeFromString('__value__*') - , $this->context->getTypeFromString('double') - + false, + $this->context->getTypeFromString('__value__*'), $this->context->getTypeFromString('double') + ); - $fn___cfcd208495d565ef66e7dff9f98764da = $this->context->module->addFunction('__value__writeDouble', $fntype___cfcd208495d565ef66e7dff9f98764da); - $fn___cfcd208495d565ef66e7dff9f98764da->addAttributeAtIndex(PHPLLVM\Attribute::INDEX_FUNCTION, $this->context->attributes['alwaysinline']); - - - - - $this->context->registerFunction('__value__writeDouble', $fn___cfcd208495d565ef66e7dff9f98764da); - - - - - - $fntype___cfcd208495d565ef66e7dff9f98764da = $this->context->context->functionType( + $fn___cfcd208495d565ef66e7dff9f98764da = $this->context->module->addFunction('__value__writeDouble', $fntype___cfcd208495d565ef66e7dff9f98764da); + $fn___cfcd208495d565ef66e7dff9f98764da->addAttributeAtIndex(PHPLLVM\Attribute::INDEX_FUNCTION, $this->context->attributes['alwaysinline']); + + $this->context->registerFunction('__value__writeDouble', $fn___cfcd208495d565ef66e7dff9f98764da); + + $fntype___cfcd208495d565ef66e7dff9f98764da = $this->context->context->functionType( $this->context->getTypeFromString('__string__*'), - false , + false, $this->context->getTypeFromString('__value__*') - + ); - $fn___cfcd208495d565ef66e7dff9f98764da = $this->context->module->addFunction('__value__readString', $fntype___cfcd208495d565ef66e7dff9f98764da); - $fn___cfcd208495d565ef66e7dff9f98764da->addAttributeAtIndex(PHPLLVM\Attribute::INDEX_FUNCTION, $this->context->attributes['alwaysinline']); - - - - $this->context->registerFunction('__value__readString', $fn___cfcd208495d565ef66e7dff9f98764da); - - - - - - $fntype___cfcd208495d565ef66e7dff9f98764da = $this->context->context->functionType( + $fn___cfcd208495d565ef66e7dff9f98764da = $this->context->module->addFunction('__value__readString', $fntype___cfcd208495d565ef66e7dff9f98764da); + $fn___cfcd208495d565ef66e7dff9f98764da->addAttributeAtIndex(PHPLLVM\Attribute::INDEX_FUNCTION, $this->context->attributes['alwaysinline']); + + $this->context->registerFunction('__value__readString', $fn___cfcd208495d565ef66e7dff9f98764da); + + $fntype___cfcd208495d565ef66e7dff9f98764da = $this->context->context->functionType( $this->context->getTypeFromString('void'), - false , - $this->context->getTypeFromString('__value__*') - , $this->context->getTypeFromString('__string__*') - + false, + $this->context->getTypeFromString('__value__*'), $this->context->getTypeFromString('__string__*') + ); - $fn___cfcd208495d565ef66e7dff9f98764da = $this->context->module->addFunction('__value__writeString', $fntype___cfcd208495d565ef66e7dff9f98764da); - $fn___cfcd208495d565ef66e7dff9f98764da->addAttributeAtIndex(PHPLLVM\Attribute::INDEX_FUNCTION, $this->context->attributes['alwaysinline']); - - - - - $this->context->registerFunction('__value__writeString', $fn___cfcd208495d565ef66e7dff9f98764da); - - - - - - - } - - public function implement(): void { - $this->implementValueToNumeric(); - $this->implementValueReadLong(); - $this->implementValueWriteLong(); - $this->implementValueReadDouble(); - $this->implementValueWriteDouble(); - $this->implementValueDelref(); - } - - public function initialize(): void { - } - - protected function implementValueDelref(): void { - $fn___c4ca4238a0b923820dcc509a6f75849b = $this->context->lookupFunction('__value__valueDelref'); - $block___c4ca4238a0b923820dcc509a6f75849b = $fn___c4ca4238a0b923820dcc509a6f75849b->appendBasicBlock('main'); - $this->context->builder->positionAtEnd($block___c4ca4238a0b923820dcc509a6f75849b); - $value = $fn___c4ca4238a0b923820dcc509a6f75849b->getParam(0); - - $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['type']; - $oldType = $this->context->builder->load( - $this->context->builder->structGep($value, $offset) - ); - $__type = $this->context->getTypeFromString('int8'); - - - $__kind = $__type->getKind(); - $__value = Variable::IS_REFCOUNTED; - switch ($__kind) { + $fn___cfcd208495d565ef66e7dff9f98764da = $this->context->module->addFunction('__value__writeString', $fntype___cfcd208495d565ef66e7dff9f98764da); + $fn___cfcd208495d565ef66e7dff9f98764da->addAttributeAtIndex(PHPLLVM\Attribute::INDEX_FUNCTION, $this->context->attributes['alwaysinline']); + + $this->context->registerFunction('__value__writeString', $fn___cfcd208495d565ef66e7dff9f98764da); + } + + public function implement(): void + { + $this->implementValueToNumeric(); + $this->implementValueReadLong(); + $this->implementValueWriteLong(); + $this->implementValueReadDouble(); + $this->implementValueWriteDouble(); + $this->implementValueDelref(); + } + + public function initialize(): void + { + } + + public function implementValueWriteLong(): void + { + $fn___9bf31c7ff062936a96d3c8bd1f8f2ff3 = $this->context->lookupFunction('__value__writeLong'); + $block___9bf31c7ff062936a96d3c8bd1f8f2ff3 = $fn___9bf31c7ff062936a96d3c8bd1f8f2ff3->appendBasicBlock('main'); + $this->context->builder->positionAtEnd($block___9bf31c7ff062936a96d3c8bd1f8f2ff3); + $value = $fn___9bf31c7ff062936a96d3c8bd1f8f2ff3->getParam(0); + $long = $fn___9bf31c7ff062936a96d3c8bd1f8f2ff3->getParam(1); + + $this->context->builder->call( + $this->context->lookupFunction('__value__valueDelref'), + $value + + ); + $__type = $this->context->getTypeFromString('int8'); + + $__kind = $__type->getKind(); + $__value = Variable::TYPE_NATIVE_LONG; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $mask = $__type->constInt($__value, false); + if (! is_object($__value)) { + $type = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $mask = $this->context->builder->truncOrBitCast($__value, $__type); + $type = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $mask = $this->context->builder->zExtOrBitCast($__value, $__type); + $type = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $mask = $this->context->builder->fpToSi($__value, $__type); - + + $type = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $mask = $this->context->builder->ptrToInt($__value, $__type); + $type = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $mask = $__type->constReal(Variable::IS_REFCOUNTED); + if (! is_object($__value)) { + $type = $__type->constReal(Variable::TYPE_NATIVE_LONG); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $mask = $this->context->builder->siToFp($__value, $__type); - + + $type = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $mask = $this->context->builder->fpCast($__value, $__type); + $type = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $mask = $__type->constInt($__value, false); + $type = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $mask = $this->context->builder->intToPtr($__value, $__type); + $type = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $mask = $this->context->builder->pointerCast($__value, $__type); + $type = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $__right = $this->context->builder->intCast($mask, $oldType->typeOf()); - - - - - $isCounted = $this->context->builder->bitwiseAnd($oldType, $__right); - $bool = $this->context->castToBool($isCounted); - $prev = $this->context->builder->getInsertBlock(); - $ifBlock = $prev->insertBasicBlock('ifBlock'); - $prev->moveBefore($ifBlock); - - $endBlock[] = $tmp = $ifBlock->insertBasicBlock('endBlock'); - $this->context->builder->branchIf($bool, $ifBlock, $tmp); - - $this->context->builder->positionAtEnd($ifBlock); - { $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; - $ptr = $this->context->builder->structGep($value, $offset); - $__type = $this->context->getTypeFromString('__ref__virtual*'); - - - $__kind = $__type->getKind(); - $__value = $ptr; - switch ($__kind) { + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['type']; + $this->context->builder->store( + $type, + $this->context->builder->structGep($value, $offset) + ); + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; + $ptr = $this->context->builder->structGep($value, $offset); + $__type = $this->context->getTypeFromString('int64*'); + + $__kind = $__type->getKind(); + $__value = $ptr; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $virtual = $__type->constInt($__value, false); + if (! is_object($__value)) { + $resultPtr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $virtual = $this->context->builder->truncOrBitCast($__value, $__type); + $resultPtr = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $virtual = $this->context->builder->zExtOrBitCast($__value, $__type); + $resultPtr = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $virtual = $this->context->builder->fpToSi($__value, $__type); - + + $resultPtr = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $virtual = $this->context->builder->ptrToInt($__value, $__type); + $resultPtr = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $virtual = $__type->constReal($ptr); + if (! is_object($__value)) { + $resultPtr = $__type->constReal($ptr); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $virtual = $this->context->builder->siToFp($__value, $__type); - + + $resultPtr = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $virtual = $this->context->builder->fpCast($__value, $__type); + $resultPtr = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $virtual = $__type->constInt($__value, false); + $resultPtr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $virtual = $this->context->builder->intToPtr($__value, $__type); + $resultPtr = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $virtual = $this->context->builder->pointerCast($__value, $__type); + $resultPtr = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $this->context->builder->call( - $this->context->lookupFunction('__ref__delref') , - $virtual - - ); - } - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($endBlock)); - } - - $this->context->builder->positionAtEnd(array_pop($endBlock)); - $this->context->builder->returnVoid(); - - $this->context->builder->clearInsertionPosition(); - } - - protected function implementValueToNumeric(): void { - $fn___a87ff679a2f3e71d9181a67b7542122c = $this->context->lookupFunction('__value__toNumeric'); - $block___a87ff679a2f3e71d9181a67b7542122c = $fn___a87ff679a2f3e71d9181a67b7542122c->appendBasicBlock('main'); - $this->context->builder->positionAtEnd($block___a87ff679a2f3e71d9181a67b7542122c); - $value = $fn___a87ff679a2f3e71d9181a67b7542122c->getParam(0); - - $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['type']; - $type = $this->context->builder->load( - $this->context->builder->structGep($value, $offset) - ); - $__switches[] = $__switch = new \StdClass; - $__switch->type = $type->typeOf(); - $__prev = $this->context->builder->getInsertBlock(); - $__switch->default = $__prev->insertBasicBlock('default'); - $__prev->moveBefore($__switch->default); - $__switch->end = $__switch->default->insertBasicBlock('end'); - $__switch->endIsUsed = false; - $__switch->numCases = 0; - $__switch->numCases++; - $__switch->numCases++; - $__switch->numCases++; - - $__switch->switch = $this->context->builder->branchSwitch($type, $__switch->default, $__switch->numCases); - $__case = end($__switches)->default->insertBasicBlock('case_' . 0); - $this->context->builder->positionAtEnd($__case); - if (is_int(Variable::TYPE_NATIVE_LONG)) { - end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_NATIVE_LONG, false), $__case); - } elseif (Variable::TYPE_NATIVE_LONG instanceof PHPLLVM\Value) { - end($__switches)->switch->addCase(Variable::TYPE_NATIVE_LONG, $__case); - } else { - throw new \LogicException("Unknown type for switch case"); - } - { $__type = $this->context->getTypeFromString('__ref__virtual*'); - - - $__kind = $__type->getKind(); - $__value = $value; - switch ($__kind) { + $__type = $this->context->getTypeFromString('int32'); + + $__kind = $__type->getKind(); + $__value = 0; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $var = $__type->constInt($__value, false); + if (! is_object($__value)) { + $offset = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $var = $this->context->builder->truncOrBitCast($__value, $__type); + $offset = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $var = $this->context->builder->zExtOrBitCast($__value, $__type); + $offset = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $var = $this->context->builder->fpToSi($__value, $__type); - + + $offset = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $var = $this->context->builder->ptrToInt($__value, $__type); + $offset = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $var = $__type->constReal($value); + if (! is_object($__value)) { + $offset = $__type->constReal(0); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $var = $this->context->builder->siToFp($__value, $__type); - + + $offset = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $var = $this->context->builder->fpCast($__value, $__type); + $offset = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $var = $__type->constInt($__value, false); + $offset = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $var = $this->context->builder->intToPtr($__value, $__type); + $offset = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $var = $this->context->builder->pointerCast($__value, $__type); + $offset = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $this->context->builder->call( - $this->context->lookupFunction('__ref__addref') , - $var - + $this->context->builder->store($long, $this->context->builder->gep( + $resultPtr, + //$this->context->context->int32Type()->constInt(0, false), + //$this->context->context->int32Type()->constInt(0, false), + $offset + )); + $this->context->builder->returnVoid(); + + $this->context->builder->clearInsertionPosition(); + } + + public function implementValueWriteDouble(): void + { + $fn___b6d767d2f8ed5d21a44b0e5886680cb9 = $this->context->lookupFunction('__value__writeDouble'); + $block___b6d767d2f8ed5d21a44b0e5886680cb9 = $fn___b6d767d2f8ed5d21a44b0e5886680cb9->appendBasicBlock('main'); + $this->context->builder->positionAtEnd($block___b6d767d2f8ed5d21a44b0e5886680cb9); + $value = $fn___b6d767d2f8ed5d21a44b0e5886680cb9->getParam(0); + $double = $fn___b6d767d2f8ed5d21a44b0e5886680cb9->getParam(1); + + $this->context->builder->call( + $this->context->lookupFunction('__value__valueDelref'), + $value + ); - $this->context->builder->returnValue($value); - } - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($__switches)->end); - end($__switches)->endIsUsed = true; - } - $__case = end($__switches)->default->insertBasicBlock('case_' . 0); - $this->context->builder->positionAtEnd($__case); - if (is_int(Variable::TYPE_NATIVE_DOUBLE)) { - end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_NATIVE_DOUBLE, false), $__case); - } elseif (Variable::TYPE_NATIVE_DOUBLE instanceof PHPLLVM\Value) { - end($__switches)->switch->addCase(Variable::TYPE_NATIVE_DOUBLE, $__case); - } else { - throw new \LogicException("Unknown type for switch case"); - } - { $__type = $this->context->getTypeFromString('__ref__virtual*'); - - - $__kind = $__type->getKind(); - $__value = $value; - switch ($__kind) { + $__type = $this->context->getTypeFromString('int8'); + + $__kind = $__type->getKind(); + $__value = Variable::TYPE_NATIVE_DOUBLE; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $var = $__type->constInt($__value, false); + if (! is_object($__value)) { + $type = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $var = $this->context->builder->truncOrBitCast($__value, $__type); + $type = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $var = $this->context->builder->zExtOrBitCast($__value, $__type); + $type = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $var = $this->context->builder->fpToSi($__value, $__type); - + + $type = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $var = $this->context->builder->ptrToInt($__value, $__type); + $type = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $var = $__type->constReal($value); + if (! is_object($__value)) { + $type = $__type->constReal(Variable::TYPE_NATIVE_DOUBLE); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $var = $this->context->builder->siToFp($__value, $__type); - + + $type = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $var = $this->context->builder->fpCast($__value, $__type); + $type = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $var = $__type->constInt($__value, false); + $type = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $var = $this->context->builder->intToPtr($__value, $__type); + $type = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $var = $this->context->builder->pointerCast($__value, $__type); + $type = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $this->context->builder->call( - $this->context->lookupFunction('__ref__addref') , - $var - + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['type']; + $this->context->builder->store( + $type, + $this->context->builder->structGep($value, $offset) ); - $this->context->builder->returnValue($value); - } - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($__switches)->end); - end($__switches)->endIsUsed = true; - } - $__case = end($__switches)->default->insertBasicBlock('case_' . 0); - $this->context->builder->positionAtEnd($__case); - if (is_int(Variable::TYPE_VALUE)) { - end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_VALUE, false), $__case); - } elseif (Variable::TYPE_VALUE instanceof PHPLLVM\Value) { - end($__switches)->switch->addCase(Variable::TYPE_VALUE, $__case); - } else { - throw new \LogicException("Unknown type for switch case"); - } - { $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; - $var = $this->context->builder->structGep($value, $offset); - $__type = $this->context->getTypeFromString('__value__value*'); - - - $__kind = $__type->getKind(); - $__value = $var; - switch ($__kind) { + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; + $ptr = $this->context->builder->structGep($value, $offset); + $__type = $this->context->getTypeFromString('double*'); + + $__kind = $__type->getKind(); + $__value = $ptr; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $ptr = $__type->constInt($__value, false); + if (! is_object($__value)) { + $resultPtr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $ptr = $this->context->builder->truncOrBitCast($__value, $__type); + $resultPtr = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $ptr = $this->context->builder->zExtOrBitCast($__value, $__type); + $resultPtr = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $ptr = $this->context->builder->fpToSi($__value, $__type); - + + $resultPtr = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $ptr = $this->context->builder->ptrToInt($__value, $__type); + $resultPtr = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $ptr = $__type->constReal($var); + if (! is_object($__value)) { + $resultPtr = $__type->constReal($ptr); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $ptr = $this->context->builder->siToFp($__value, $__type); - + + $resultPtr = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $ptr = $this->context->builder->fpCast($__value, $__type); + $resultPtr = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $ptr = $__type->constInt($__value, false); + $resultPtr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $ptr = $this->context->builder->intToPtr($__value, $__type); + $resultPtr = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $ptr = $this->context->builder->pointerCast($__value, $__type); + $resultPtr = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $offset = $this->context->structFieldMap[$ptr->typeOf()->getElementType()->getName()]['value']; - $num = $this->context->builder->structGep($ptr, $offset); - $result = $this->context->builder->call( - $this->context->lookupFunction('__value__toNumeric') , - $num - - ); - $__right = $this->context->builder->intCast($num, $result->typeOf()); - - - + $__type = $this->context->getTypeFromString('int32'); + + $__kind = $__type->getKind(); + $__value = 0; + switch ($__kind) { + case PHPLLVM\Type::KIND_INTEGER: + if (! is_object($__value)) { + $offset = $__type->constInt($__value, false); - + break; + } + $__other_type = $__value->typeOf(); + switch ($__other_type->getKind()) { + case PHPLLVM\Type::KIND_INTEGER: + if ($__other_type->getWidth() >= $__type->getWidth()) { + $offset = $this->context->builder->truncOrBitCast($__value, $__type); + } else { + $offset = $this->context->builder->zExtOrBitCast($__value, $__type); + } - + break; + case PHPLLVM\Type::KIND_DOUBLE: - + $offset = $this->context->builder->fpToSi($__value, $__type); - + break; + case PHPLLVM\Type::KIND_ARRAY: + case PHPLLVM\Type::KIND_POINTER: + $offset = $this->context->builder->ptrToInt($__value, $__type); - + break; + default: + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); + } - + break; + case PHPLLVM\Type::KIND_DOUBLE: + if (! is_object($__value)) { + $offset = $__type->constReal(0); - + break; + } + $__other_type = $__value->typeOf(); + switch ($__other_type->getKind()) { + case PHPLLVM\Type::KIND_INTEGER: - + $offset = $this->context->builder->siToFp($__value, $__type); - + break; + case PHPLLVM\Type::KIND_DOUBLE: + $offset = $this->context->builder->fpCast($__value, $__type); - + break; + default: + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); + } - + break; + case PHPLLVM\Type::KIND_ARRAY: + case PHPLLVM\Type::KIND_POINTER: + if (! is_object($__value)) { + // this is very likely very wrong... + $offset = $__type->constInt($__value, false); - + break; + } + $__other_type = $__value->typeOf(); + switch ($__other_type->getKind()) { + case PHPLLVM\Type::KIND_INTEGER: + $offset = $this->context->builder->intToPtr($__value, $__type); - $test = $this->context->builder->icmp(PHPLLVM\Builder::INT_EQ, $result, $__right); - $bool = $this->context->castToBool($test); - $prev = $this->context->builder->getInsertBlock(); - $ifBlock = $prev->insertBasicBlock('ifBlock'); - $prev->moveBefore($ifBlock); - - $endBlock[] = $tmp = $ifBlock->insertBasicBlock('endBlock'); - $this->context->builder->branchIf($bool, $ifBlock, $tmp); - - $this->context->builder->positionAtEnd($ifBlock); - { $__type = $this->context->getTypeFromString('__ref__virtual*'); - - - $__kind = $__type->getKind(); - $__value = $var; - switch ($__kind) { + break; + case PHPLLVM\Type::KIND_ARRAY: + // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); + // $(result) = $this->context->builder->intToPtr($__tmp, $__type); + // break; + case PHPLLVM\Type::KIND_POINTER: + $offset = $this->context->builder->pointerCast($__value, $__type); + + break; + default: + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); + } + + break; + default: + throw new \LogicException('Unsupported type cast: '.$__type->toString()); + } + $this->context->builder->store($double, $this->context->builder->gep( + $resultPtr, + //$this->context->context->int32Type()->constInt(0, false), + //$this->context->context->int32Type()->constInt(0, false), + $offset + )); + $this->context->builder->returnVoid(); + + $this->context->builder->clearInsertionPosition(); + } + + public function implementValueWriteString(): void + { + $fn___33e75ff09dd601bbe69f351039152189 = $this->context->lookupFunction('__value__writeString'); + $block___33e75ff09dd601bbe69f351039152189 = $fn___33e75ff09dd601bbe69f351039152189->appendBasicBlock('main'); + $this->context->builder->positionAtEnd($block___33e75ff09dd601bbe69f351039152189); + $value = $fn___33e75ff09dd601bbe69f351039152189->getParam(0); + $string = $fn___33e75ff09dd601bbe69f351039152189->getParam(1); + + $this->context->builder->call( + $this->context->lookupFunction('__value__valueDelref'), + $value + + ); + $__type = $this->context->getTypeFromString('int8'); + + $__kind = $__type->getKind(); + $__value = Variable::TYPE_STRING; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $virtual = $__type->constInt($__value, false); + if (! is_object($__value)) { + $type = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $virtual = $this->context->builder->truncOrBitCast($__value, $__type); + $type = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $virtual = $this->context->builder->zExtOrBitCast($__value, $__type); + $type = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $virtual = $this->context->builder->fpToSi($__value, $__type); - + + $type = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $virtual = $this->context->builder->ptrToInt($__value, $__type); + $type = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $virtual = $__type->constReal($var); + if (! is_object($__value)) { + $type = $__type->constReal(Variable::TYPE_STRING); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $virtual = $this->context->builder->siToFp($__value, $__type); - + + $type = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $virtual = $this->context->builder->fpCast($__value, $__type); + $type = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $virtual = $__type->constInt($__value, false); + $type = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $virtual = $this->context->builder->intToPtr($__value, $__type); + $type = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $virtual = $this->context->builder->pointerCast($__value, $__type); + $type = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $this->context->builder->call( - $this->context->lookupFunction('__ref__addref') , - $virtual - + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['type']; + $this->context->builder->store( + $type, + $this->context->builder->structGep($value, $offset) ); + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; + $this->context->builder->store( + $string, + $this->context->builder->structGep($value, $offset) + ); + $this->context->builder->returnVoid(); + + $this->context->builder->clearInsertionPosition(); } - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($endBlock)); - } - - $this->context->builder->positionAtEnd(array_pop($endBlock)); - $this->context->builder->returnValue($result); - } - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($__switches)->end); - end($__switches)->endIsUsed = true; - } - - $this->context->builder->positionAtEnd(end($__switches)->default); - - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($__switches)->end); - end($__switches)->endIsUsed = true; - } - $__switch = array_pop($__switches); - if ($__switch->endIsUsed) { - $this->context->builder->positionAtEnd($__switch->end); - } else { - $__switch->end->remove(); - } - $type = $this->context->getTypeFromString('__value__'); - $var = $this->context->builder->alloca($type); - $__type = $this->context->getTypeFromString('int64'); - - - $__kind = $__type->getKind(); - $__value = 0; - switch ($__kind) { + + protected function implementValueDelref(): void + { + $fn___c4ca4238a0b923820dcc509a6f75849b = $this->context->lookupFunction('__value__valueDelref'); + $block___c4ca4238a0b923820dcc509a6f75849b = $fn___c4ca4238a0b923820dcc509a6f75849b->appendBasicBlock('main'); + $this->context->builder->positionAtEnd($block___c4ca4238a0b923820dcc509a6f75849b); + $value = $fn___c4ca4238a0b923820dcc509a6f75849b->getParam(0); + + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['type']; + $oldType = $this->context->builder->load( + $this->context->builder->structGep($value, $offset) + ); + $__type = $this->context->getTypeFromString('int8'); + + $__kind = $__type->getKind(); + $__value = Variable::IS_REFCOUNTED; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $tmp = $__type->constInt($__value, false); + if (! is_object($__value)) { + $mask = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $tmp = $this->context->builder->truncOrBitCast($__value, $__type); + $mask = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $tmp = $this->context->builder->zExtOrBitCast($__value, $__type); + $mask = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $tmp = $this->context->builder->fpToSi($__value, $__type); - + + $mask = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $tmp = $this->context->builder->ptrToInt($__value, $__type); + $mask = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $tmp = $__type->constReal(0); + if (! is_object($__value)) { + $mask = $__type->constReal(Variable::IS_REFCOUNTED); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $tmp = $this->context->builder->siToFp($__value, $__type); - + + $mask = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $tmp = $this->context->builder->fpCast($__value, $__type); + $mask = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $tmp = $__type->constInt($__value, false); + $mask = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $tmp = $this->context->builder->intToPtr($__value, $__type); + $mask = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $tmp = $this->context->builder->pointerCast($__value, $__type); + $mask = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $this->context->builder->call( - $this->context->lookupFunction('__value__writeLong') , - $var - , $tmp - - ); - $this->context->builder->returnValue($var); - - $this->context->builder->clearInsertionPosition(); - } - - protected function implementValueReadLong(): void { - $fn___d3d9446802a44259755d38e6d163e820 = $this->context->lookupFunction('__value__readLong'); - $block___d3d9446802a44259755d38e6d163e820 = $fn___d3d9446802a44259755d38e6d163e820->appendBasicBlock('main'); - $this->context->builder->positionAtEnd($block___d3d9446802a44259755d38e6d163e820); - $value = $fn___d3d9446802a44259755d38e6d163e820->getParam(0); - - $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['type']; - $type = $this->context->builder->load( - $this->context->builder->structGep($value, $offset) - ); - $__switches[] = $__switch = new \StdClass; - $__switch->type = $type->typeOf(); - $__prev = $this->context->builder->getInsertBlock(); - $__switch->default = $__prev->insertBasicBlock('default'); - $__prev->moveBefore($__switch->default); - $__switch->end = $__switch->default->insertBasicBlock('end'); - $__switch->endIsUsed = false; - $__switch->numCases = 0; - $__switch->numCases++; - $__switch->numCases++; - $__switch->numCases++; - - $__switch->switch = $this->context->builder->branchSwitch($type, $__switch->default, $__switch->numCases); - $__case = end($__switches)->default->insertBasicBlock('case_' . 0); - $this->context->builder->positionAtEnd($__case); - if (is_int(Variable::TYPE_NATIVE_LONG)) { - end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_NATIVE_LONG, false), $__case); - } elseif (Variable::TYPE_NATIVE_LONG instanceof PHPLLVM\Value) { - end($__switches)->switch->addCase(Variable::TYPE_NATIVE_LONG, $__case); - } else { - throw new \LogicException("Unknown type for switch case"); - } - { $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; - $ptr = $this->context->builder->structGep($value, $offset); - $__type = $this->context->getTypeFromString('int64*'); - - - $__kind = $__type->getKind(); - $__value = $ptr; - switch ($__kind) { + $__right = $this->context->builder->intCast($mask, $oldType->typeOf()); + + $isCounted = $this->context->builder->bitwiseAnd($oldType, $__right); + $bool = $this->context->castToBool($isCounted); + $prev = $this->context->builder->getInsertBlock(); + $ifBlock = $prev->insertBasicBlock('ifBlock'); + $prev->moveBefore($ifBlock); + + $endBlock[] = $tmp = $ifBlock->insertBasicBlock('endBlock'); + $this->context->builder->branchIf($bool, $ifBlock, $tmp); + + $this->context->builder->positionAtEnd($ifBlock); + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; + $ptr = $this->context->builder->structGep($value, $offset); + $__type = $this->context->getTypeFromString('__ref__virtual*'); + + $__kind = $__type->getKind(); + $__value = $ptr; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $resultPtr = $__type->constInt($__value, false); + if (! is_object($__value)) { + $virtual = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $resultPtr = $this->context->builder->truncOrBitCast($__value, $__type); + $virtual = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $resultPtr = $this->context->builder->zExtOrBitCast($__value, $__type); + $virtual = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $resultPtr = $this->context->builder->fpToSi($__value, $__type); - + + $virtual = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $resultPtr = $this->context->builder->ptrToInt($__value, $__type); + $virtual = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $resultPtr = $__type->constReal($ptr); + if (! is_object($__value)) { + $virtual = $__type->constReal($ptr); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $resultPtr = $this->context->builder->siToFp($__value, $__type); - + + $virtual = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $resultPtr = $this->context->builder->fpCast($__value, $__type); + $virtual = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $resultPtr = $__type->constInt($__value, false); + $virtual = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $resultPtr = $this->context->builder->intToPtr($__value, $__type); + $virtual = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $resultPtr = $this->context->builder->pointerCast($__value, $__type); + $virtual = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $__type = $this->context->getTypeFromString('int32'); - - - $__kind = $__type->getKind(); - $__value = 0; - switch ($__kind) { + $this->context->builder->call( + $this->context->lookupFunction('__ref__delref'), + $virtual + + ); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($endBlock)); + } + + $this->context->builder->positionAtEnd(array_pop($endBlock)); + $this->context->builder->returnVoid(); + + $this->context->builder->clearInsertionPosition(); + } + + protected function implementValueToNumeric(): void + { + $fn___a87ff679a2f3e71d9181a67b7542122c = $this->context->lookupFunction('__value__toNumeric'); + $block___a87ff679a2f3e71d9181a67b7542122c = $fn___a87ff679a2f3e71d9181a67b7542122c->appendBasicBlock('main'); + $this->context->builder->positionAtEnd($block___a87ff679a2f3e71d9181a67b7542122c); + $value = $fn___a87ff679a2f3e71d9181a67b7542122c->getParam(0); + + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['type']; + $type = $this->context->builder->load( + $this->context->builder->structGep($value, $offset) + ); + $__switches[] = $__switch = new \StdClass(); + $__switch->type = $type->typeOf(); + $__prev = $this->context->builder->getInsertBlock(); + $__switch->default = $__prev->insertBasicBlock('default'); + $__prev->moveBefore($__switch->default); + $__switch->end = $__switch->default->insertBasicBlock('end'); + $__switch->endIsUsed = false; + $__switch->numCases = 0; + ++$__switch->numCases; + ++$__switch->numCases; + ++$__switch->numCases; + + $__switch->switch = $this->context->builder->branchSwitch($type, $__switch->default, $__switch->numCases); + $__case = end($__switches)->default->insertBasicBlock('case_'. 0); + $this->context->builder->positionAtEnd($__case); + if (is_int(Variable::TYPE_NATIVE_LONG)) { + end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_NATIVE_LONG, false), $__case); + } elseif (Variable::TYPE_NATIVE_LONG instanceof PHPLLVM\Value) { + end($__switches)->switch->addCase(Variable::TYPE_NATIVE_LONG, $__case); + } else { + throw new \LogicException('Unknown type for switch case'); + } + $__type = $this->context->getTypeFromString('__ref__virtual*'); + + $__kind = $__type->getKind(); + $__value = $value; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $offset = $__type->constInt($__value, false); + if (! is_object($__value)) { + $var = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $offset = $this->context->builder->truncOrBitCast($__value, $__type); + $var = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $offset = $this->context->builder->zExtOrBitCast($__value, $__type); + $var = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $offset = $this->context->builder->fpToSi($__value, $__type); - + + $var = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $offset = $this->context->builder->ptrToInt($__value, $__type); + $var = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $offset = $__type->constReal(0); + if (! is_object($__value)) { + $var = $__type->constReal($value); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $offset = $this->context->builder->siToFp($__value, $__type); - + + $var = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $offset = $this->context->builder->fpCast($__value, $__type); + $var = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $offset = $__type->constInt($__value, false); + $var = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $offset = $this->context->builder->intToPtr($__value, $__type); + $var = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $offset = $this->context->builder->pointerCast($__value, $__type); + $var = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); - } - $result = $this->context->builder->load($this->context->builder->gep( - $resultPtr, - //$this->context->context->int32Type()->constInt(0, false), - //$this->context->context->int32Type()->constInt(0, false), - $offset - )); - $this->context->builder->returnValue($result); - } - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($__switches)->end); - end($__switches)->endIsUsed = true; + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $__case = end($__switches)->default->insertBasicBlock('case_' . 0); - $this->context->builder->positionAtEnd($__case); - if (is_int(Variable::TYPE_NATIVE_DOUBLE)) { - end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_NATIVE_DOUBLE, false), $__case); - } elseif (Variable::TYPE_NATIVE_DOUBLE instanceof PHPLLVM\Value) { - end($__switches)->switch->addCase(Variable::TYPE_NATIVE_DOUBLE, $__case); - } else { - throw new \LogicException("Unknown type for switch case"); - } - { $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; - $ptr = $this->context->builder->structGep($value, $offset); - $__type = $this->context->getTypeFromString('double*'); - - - $__kind = $__type->getKind(); - $__value = $ptr; - switch ($__kind) { + $this->context->builder->call( + $this->context->lookupFunction('__ref__addref'), + $var + + ); + $this->context->builder->returnValue($value); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($__switches)->end); + end($__switches)->endIsUsed = true; + } + $__case = end($__switches)->default->insertBasicBlock('case_'. 0); + $this->context->builder->positionAtEnd($__case); + if (is_int(Variable::TYPE_NATIVE_DOUBLE)) { + end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_NATIVE_DOUBLE, false), $__case); + } elseif (Variable::TYPE_NATIVE_DOUBLE instanceof PHPLLVM\Value) { + end($__switches)->switch->addCase(Variable::TYPE_NATIVE_DOUBLE, $__case); + } else { + throw new \LogicException('Unknown type for switch case'); + } + $__type = $this->context->getTypeFromString('__ref__virtual*'); + + $__kind = $__type->getKind(); + $__value = $value; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $resultPtr = $__type->constInt($__value, false); + if (! is_object($__value)) { + $var = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $resultPtr = $this->context->builder->truncOrBitCast($__value, $__type); + $var = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $resultPtr = $this->context->builder->zExtOrBitCast($__value, $__type); + $var = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $resultPtr = $this->context->builder->fpToSi($__value, $__type); - + + $var = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $resultPtr = $this->context->builder->ptrToInt($__value, $__type); + $var = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $resultPtr = $__type->constReal($ptr); + if (! is_object($__value)) { + $var = $__type->constReal($value); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $resultPtr = $this->context->builder->siToFp($__value, $__type); - + + $var = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $resultPtr = $this->context->builder->fpCast($__value, $__type); + $var = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $resultPtr = $__type->constInt($__value, false); + $var = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $resultPtr = $this->context->builder->intToPtr($__value, $__type); + $var = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $resultPtr = $this->context->builder->pointerCast($__value, $__type); + $var = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $__type = $this->context->getTypeFromString('int32'); - - - $__kind = $__type->getKind(); - $__value = 0; - switch ($__kind) { + $this->context->builder->call( + $this->context->lookupFunction('__ref__addref'), + $var + + ); + $this->context->builder->returnValue($value); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($__switches)->end); + end($__switches)->endIsUsed = true; + } + $__case = end($__switches)->default->insertBasicBlock('case_'. 0); + $this->context->builder->positionAtEnd($__case); + if (is_int(Variable::TYPE_VALUE)) { + end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_VALUE, false), $__case); + } elseif (Variable::TYPE_VALUE instanceof PHPLLVM\Value) { + end($__switches)->switch->addCase(Variable::TYPE_VALUE, $__case); + } else { + throw new \LogicException('Unknown type for switch case'); + } + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; + $var = $this->context->builder->structGep($value, $offset); + $__type = $this->context->getTypeFromString('__value__value*'); + + $__kind = $__type->getKind(); + $__value = $var; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $offset = $__type->constInt($__value, false); + if (! is_object($__value)) { + $ptr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $offset = $this->context->builder->truncOrBitCast($__value, $__type); + $ptr = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $offset = $this->context->builder->zExtOrBitCast($__value, $__type); + $ptr = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $offset = $this->context->builder->fpToSi($__value, $__type); - + + $ptr = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $offset = $this->context->builder->ptrToInt($__value, $__type); + $ptr = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $offset = $__type->constReal(0); + if (! is_object($__value)) { + $ptr = $__type->constReal($var); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $offset = $this->context->builder->siToFp($__value, $__type); - + + $ptr = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $offset = $this->context->builder->fpCast($__value, $__type); + $ptr = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $offset = $__type->constInt($__value, false); + $ptr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $offset = $this->context->builder->intToPtr($__value, $__type); + $ptr = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $offset = $this->context->builder->pointerCast($__value, $__type); + $ptr = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $result = $this->context->builder->load($this->context->builder->gep( - $resultPtr, - //$this->context->context->int32Type()->constInt(0, false), - //$this->context->context->int32Type()->constInt(0, false), - $offset - )); - $__type = $this->context->getTypeFromString('int64'); - - - $__kind = $__type->getKind(); - $__value = $result; - switch ($__kind) { + $offset = $this->context->structFieldMap[$ptr->typeOf()->getElementType()->getName()]['value']; + $num = $this->context->builder->structGep($ptr, $offset); + $result = $this->context->builder->call( + $this->context->lookupFunction('__value__toNumeric'), + $num + + ); + $__right = $this->context->builder->intCast($num, $result->typeOf()); + + $test = $this->context->builder->icmp(PHPLLVM\Builder::INT_EQ, $result, $__right); + $bool = $this->context->castToBool($test); + $prev = $this->context->builder->getInsertBlock(); + $ifBlock = $prev->insertBasicBlock('ifBlock'); + $prev->moveBefore($ifBlock); + + $endBlock[] = $tmp = $ifBlock->insertBasicBlock('endBlock'); + $this->context->builder->branchIf($bool, $ifBlock, $tmp); + + $this->context->builder->positionAtEnd($ifBlock); + $__type = $this->context->getTypeFromString('__ref__virtual*'); + + $__kind = $__type->getKind(); + $__value = $var; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $return = $__type->constInt($__value, false); + if (! is_object($__value)) { + $virtual = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $return = $this->context->builder->truncOrBitCast($__value, $__type); + $virtual = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $return = $this->context->builder->zExtOrBitCast($__value, $__type); + $virtual = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $return = $this->context->builder->fpToSi($__value, $__type); - + + $virtual = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $return = $this->context->builder->ptrToInt($__value, $__type); + $virtual = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $return = $__type->constReal($result); + if (! is_object($__value)) { + $virtual = $__type->constReal($var); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $return = $this->context->builder->siToFp($__value, $__type); - + + $virtual = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $return = $this->context->builder->fpCast($__value, $__type); + $virtual = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $return = $__type->constInt($__value, false); + $virtual = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $return = $this->context->builder->intToPtr($__value, $__type); + $virtual = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $return = $this->context->builder->pointerCast($__value, $__type); + $virtual = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); - } - $this->context->builder->returnValue($return); - } - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($__switches)->end); - end($__switches)->endIsUsed = true; - } - $__case = end($__switches)->default->insertBasicBlock('case_' . 0); - $this->context->builder->positionAtEnd($__case); - if (is_int(Variable::TYPE_VALUE)) { - end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_VALUE, false), $__case); - } elseif (Variable::TYPE_VALUE instanceof PHPLLVM\Value) { - end($__switches)->switch->addCase(Variable::TYPE_VALUE, $__case); - } else { - throw new \LogicException("Unknown type for switch case"); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - { $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; - $var = $this->context->builder->structGep($value, $offset); - $__type = $this->context->getTypeFromString('__value__value*'); - - - $__kind = $__type->getKind(); - $__value = $var; - switch ($__kind) { + $this->context->builder->call( + $this->context->lookupFunction('__ref__addref'), + $virtual + + ); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($endBlock)); + } + + $this->context->builder->positionAtEnd(array_pop($endBlock)); + $this->context->builder->returnValue($result); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($__switches)->end); + end($__switches)->endIsUsed = true; + } + + $this->context->builder->positionAtEnd(end($__switches)->default); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($__switches)->end); + end($__switches)->endIsUsed = true; + } + $__switch = array_pop($__switches); + if ($__switch->endIsUsed) { + $this->context->builder->positionAtEnd($__switch->end); + } else { + $__switch->end->remove(); + } + $type = $this->context->getTypeFromString('__value__'); + $var = $this->context->builder->alloca($type); + $__type = $this->context->getTypeFromString('int64'); + + $__kind = $__type->getKind(); + $__value = 0; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $ptr = $__type->constInt($__value, false); + if (! is_object($__value)) { + $tmp = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $ptr = $this->context->builder->truncOrBitCast($__value, $__type); + $tmp = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $ptr = $this->context->builder->zExtOrBitCast($__value, $__type); + $tmp = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $ptr = $this->context->builder->fpToSi($__value, $__type); - + + $tmp = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $ptr = $this->context->builder->ptrToInt($__value, $__type); + $tmp = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $ptr = $__type->constReal($var); + if (! is_object($__value)) { + $tmp = $__type->constReal(0); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $ptr = $this->context->builder->siToFp($__value, $__type); - + + $tmp = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $ptr = $this->context->builder->fpCast($__value, $__type); + $tmp = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $ptr = $__type->constInt($__value, false); + $tmp = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $ptr = $this->context->builder->intToPtr($__value, $__type); + $tmp = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $ptr = $this->context->builder->pointerCast($__value, $__type); + $tmp = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $offset = $this->context->structFieldMap[$ptr->typeOf()->getElementType()->getName()]['value']; - $varPtr = $this->context->builder->structGep($ptr, $offset); - $result = $this->context->builder->call( - $this->context->lookupFunction('__value__readLong') , - $varPtr - + $this->context->builder->call( + $this->context->lookupFunction('__value__writeLong'), + $var, $tmp + + ); + $this->context->builder->returnValue($var); + + $this->context->builder->clearInsertionPosition(); + } + + protected function implementValueReadLong(): void + { + $fn___d3d9446802a44259755d38e6d163e820 = $this->context->lookupFunction('__value__readLong'); + $block___d3d9446802a44259755d38e6d163e820 = $fn___d3d9446802a44259755d38e6d163e820->appendBasicBlock('main'); + $this->context->builder->positionAtEnd($block___d3d9446802a44259755d38e6d163e820); + $value = $fn___d3d9446802a44259755d38e6d163e820->getParam(0); + + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['type']; + $type = $this->context->builder->load( + $this->context->builder->structGep($value, $offset) ); - $this->context->builder->returnValue($result); - } - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($__switches)->end); - end($__switches)->endIsUsed = true; - } - - $this->context->builder->positionAtEnd(end($__switches)->default); - - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($__switches)->end); - end($__switches)->endIsUsed = true; - } - $__switch = array_pop($__switches); - if ($__switch->endIsUsed) { - $this->context->builder->positionAtEnd($__switch->end); - } else { - $__switch->end->remove(); - } - $__type = $this->context->getTypeFromString('int64'); - - - $__kind = $__type->getKind(); - $__value = 0; - switch ($__kind) { + $__switches[] = $__switch = new \StdClass(); + $__switch->type = $type->typeOf(); + $__prev = $this->context->builder->getInsertBlock(); + $__switch->default = $__prev->insertBasicBlock('default'); + $__prev->moveBefore($__switch->default); + $__switch->end = $__switch->default->insertBasicBlock('end'); + $__switch->endIsUsed = false; + $__switch->numCases = 0; + ++$__switch->numCases; + ++$__switch->numCases; + ++$__switch->numCases; + + $__switch->switch = $this->context->builder->branchSwitch($type, $__switch->default, $__switch->numCases); + $__case = end($__switches)->default->insertBasicBlock('case_'. 0); + $this->context->builder->positionAtEnd($__case); + if (is_int(Variable::TYPE_NATIVE_LONG)) { + end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_NATIVE_LONG, false), $__case); + } elseif (Variable::TYPE_NATIVE_LONG instanceof PHPLLVM\Value) { + end($__switches)->switch->addCase(Variable::TYPE_NATIVE_LONG, $__case); + } else { + throw new \LogicException('Unknown type for switch case'); + } + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; + $ptr = $this->context->builder->structGep($value, $offset); + $__type = $this->context->getTypeFromString('int64*'); + + $__kind = $__type->getKind(); + $__value = $ptr; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $result = $__type->constInt($__value, false); + if (! is_object($__value)) { + $resultPtr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $result = $this->context->builder->truncOrBitCast($__value, $__type); + $resultPtr = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $result = $this->context->builder->zExtOrBitCast($__value, $__type); + $resultPtr = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $result = $this->context->builder->fpToSi($__value, $__type); - + + $resultPtr = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $result = $this->context->builder->ptrToInt($__value, $__type); + $resultPtr = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $result = $__type->constReal(0); + if (! is_object($__value)) { + $resultPtr = $__type->constReal($ptr); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $result = $this->context->builder->siToFp($__value, $__type); - + + $resultPtr = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $result = $this->context->builder->fpCast($__value, $__type); + $resultPtr = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $result = $__type->constInt($__value, false); + $resultPtr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $result = $this->context->builder->intToPtr($__value, $__type); + $resultPtr = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $result = $this->context->builder->pointerCast($__value, $__type); + $resultPtr = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $this->context->builder->returnValue($result); - - $this->context->builder->clearInsertionPosition(); - } - - public function implementValueWriteLong(): void { - $fn___9bf31c7ff062936a96d3c8bd1f8f2ff3 = $this->context->lookupFunction('__value__writeLong'); - $block___9bf31c7ff062936a96d3c8bd1f8f2ff3 = $fn___9bf31c7ff062936a96d3c8bd1f8f2ff3->appendBasicBlock('main'); - $this->context->builder->positionAtEnd($block___9bf31c7ff062936a96d3c8bd1f8f2ff3); - $value = $fn___9bf31c7ff062936a96d3c8bd1f8f2ff3->getParam(0); - $long = $fn___9bf31c7ff062936a96d3c8bd1f8f2ff3->getParam(1); - - $this->context->builder->call( - $this->context->lookupFunction('__value__valueDelref') , - $value - - ); - $__type = $this->context->getTypeFromString('int8'); - - - $__kind = $__type->getKind(); - $__value = Variable::TYPE_NATIVE_LONG; - switch ($__kind) { + $__type = $this->context->getTypeFromString('int32'); + + $__kind = $__type->getKind(); + $__value = 0; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $type = $__type->constInt($__value, false); + if (! is_object($__value)) { + $offset = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $type = $this->context->builder->truncOrBitCast($__value, $__type); + $offset = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $type = $this->context->builder->zExtOrBitCast($__value, $__type); + $offset = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $type = $this->context->builder->fpToSi($__value, $__type); - + + $offset = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $type = $this->context->builder->ptrToInt($__value, $__type); + $offset = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $type = $__type->constReal(Variable::TYPE_NATIVE_LONG); + if (! is_object($__value)) { + $offset = $__type->constReal(0); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $type = $this->context->builder->siToFp($__value, $__type); - + + $offset = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $type = $this->context->builder->fpCast($__value, $__type); + $offset = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $type = $__type->constInt($__value, false); + $offset = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $type = $this->context->builder->intToPtr($__value, $__type); + $offset = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $type = $this->context->builder->pointerCast($__value, $__type); + $offset = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['type']; - $this->context->builder->store( - $type, - $this->context->builder->structGep($value, $offset) - ); - $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; - $ptr = $this->context->builder->structGep($value, $offset); - $__type = $this->context->getTypeFromString('int64*'); - - - $__kind = $__type->getKind(); - $__value = $ptr; - switch ($__kind) { + $result = $this->context->builder->load($this->context->builder->gep( + $resultPtr, + //$this->context->context->int32Type()->constInt(0, false), + //$this->context->context->int32Type()->constInt(0, false), + $offset + )); + $this->context->builder->returnValue($result); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($__switches)->end); + end($__switches)->endIsUsed = true; + } + $__case = end($__switches)->default->insertBasicBlock('case_'. 0); + $this->context->builder->positionAtEnd($__case); + if (is_int(Variable::TYPE_NATIVE_DOUBLE)) { + end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_NATIVE_DOUBLE, false), $__case); + } elseif (Variable::TYPE_NATIVE_DOUBLE instanceof PHPLLVM\Value) { + end($__switches)->switch->addCase(Variable::TYPE_NATIVE_DOUBLE, $__case); + } else { + throw new \LogicException('Unknown type for switch case'); + } + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; + $ptr = $this->context->builder->structGep($value, $offset); + $__type = $this->context->getTypeFromString('double*'); + + $__kind = $__type->getKind(); + $__value = $ptr; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { + if (! is_object($__value)) { $resultPtr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); @@ -1745,50 +1913,58 @@ public function implementValueWriteLong(): void { } else { $resultPtr = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - + $resultPtr = $this->context->builder->fpToSi($__value, $__type); - + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: $resultPtr = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { + if (! is_object($__value)) { $resultPtr = $__type->constReal($ptr); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - + $resultPtr = $this->context->builder->siToFp($__value, $__type); - + break; case PHPLLVM\Type::KIND_DOUBLE: $resultPtr = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... $resultPtr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: $resultPtr = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); @@ -1796,23 +1972,25 @@ public function implementValueWriteLong(): void { // break; case PHPLLVM\Type::KIND_POINTER: $resultPtr = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $__type = $this->context->getTypeFromString('int32'); - - - $__kind = $__type->getKind(); - $__value = 0; - switch ($__kind) { + $__type = $this->context->getTypeFromString('int32'); + + $__kind = $__type->getKind(); + $__value = 0; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { + if (! is_object($__value)) { $offset = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); @@ -1823,50 +2001,58 @@ public function implementValueWriteLong(): void { } else { $offset = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - + $offset = $this->context->builder->fpToSi($__value, $__type); - + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: $offset = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { + if (! is_object($__value)) { $offset = $__type->constReal(0); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - + $offset = $this->context->builder->siToFp($__value, $__type); - + break; case PHPLLVM\Type::KIND_DOUBLE: $offset = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... $offset = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: $offset = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); @@ -1874,326 +2060,378 @@ public function implementValueWriteLong(): void { // break; case PHPLLVM\Type::KIND_POINTER: $offset = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); - } - $this->context->builder->store($long, $this->context->builder->gep( - $resultPtr, - //$this->context->context->int32Type()->constInt(0, false), - //$this->context->context->int32Type()->constInt(0, false), - $offset - )); - $this->context->builder->returnVoid(); - - $this->context->builder->clearInsertionPosition(); - } - - protected function implementValueReadDouble(): void { - $fn___70efdf2ec9b086079795c442636b55fb = $this->context->lookupFunction('__value__readDouble'); - $block___70efdf2ec9b086079795c442636b55fb = $fn___70efdf2ec9b086079795c442636b55fb->appendBasicBlock('main'); - $this->context->builder->positionAtEnd($block___70efdf2ec9b086079795c442636b55fb); - $value = $fn___70efdf2ec9b086079795c442636b55fb->getParam(0); - - $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['type']; - $type = $this->context->builder->load( - $this->context->builder->structGep($value, $offset) - ); - $__switches[] = $__switch = new \StdClass; - $__switch->type = $type->typeOf(); - $__prev = $this->context->builder->getInsertBlock(); - $__switch->default = $__prev->insertBasicBlock('default'); - $__prev->moveBefore($__switch->default); - $__switch->end = $__switch->default->insertBasicBlock('end'); - $__switch->endIsUsed = false; - $__switch->numCases = 0; - $__switch->numCases++; - $__switch->numCases++; - $__switch->numCases++; - - $__switch->switch = $this->context->builder->branchSwitch($type, $__switch->default, $__switch->numCases); - $__case = end($__switches)->default->insertBasicBlock('case_' . 0); - $this->context->builder->positionAtEnd($__case); - if (is_int(Variable::TYPE_NATIVE_LONG)) { - end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_NATIVE_LONG, false), $__case); - } elseif (Variable::TYPE_NATIVE_LONG instanceof PHPLLVM\Value) { - end($__switches)->switch->addCase(Variable::TYPE_NATIVE_LONG, $__case); - } else { - throw new \LogicException("Unknown type for switch case"); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - { $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; - $ptr = $this->context->builder->structGep($value, $offset); - $__type = $this->context->getTypeFromString('int64*'); - - - $__kind = $__type->getKind(); - $__value = $ptr; - switch ($__kind) { + $result = $this->context->builder->load($this->context->builder->gep( + $resultPtr, + //$this->context->context->int32Type()->constInt(0, false), + //$this->context->context->int32Type()->constInt(0, false), + $offset + )); + $__type = $this->context->getTypeFromString('int64'); + + $__kind = $__type->getKind(); + $__value = $result; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $resultPtr = $__type->constInt($__value, false); + if (! is_object($__value)) { + $return = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $resultPtr = $this->context->builder->truncOrBitCast($__value, $__type); + $return = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $resultPtr = $this->context->builder->zExtOrBitCast($__value, $__type); + $return = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $resultPtr = $this->context->builder->fpToSi($__value, $__type); - + + $return = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $resultPtr = $this->context->builder->ptrToInt($__value, $__type); + $return = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $resultPtr = $__type->constReal($ptr); + if (! is_object($__value)) { + $return = $__type->constReal($result); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $resultPtr = $this->context->builder->siToFp($__value, $__type); - + + $return = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $resultPtr = $this->context->builder->fpCast($__value, $__type); + $return = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $resultPtr = $__type->constInt($__value, false); + $return = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $resultPtr = $this->context->builder->intToPtr($__value, $__type); + $return = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $resultPtr = $this->context->builder->pointerCast($__value, $__type); + $return = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $__type = $this->context->getTypeFromString('int32'); - - - $__kind = $__type->getKind(); - $__value = 0; - switch ($__kind) { + $this->context->builder->returnValue($return); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($__switches)->end); + end($__switches)->endIsUsed = true; + } + $__case = end($__switches)->default->insertBasicBlock('case_'. 0); + $this->context->builder->positionAtEnd($__case); + if (is_int(Variable::TYPE_VALUE)) { + end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_VALUE, false), $__case); + } elseif (Variable::TYPE_VALUE instanceof PHPLLVM\Value) { + end($__switches)->switch->addCase(Variable::TYPE_VALUE, $__case); + } else { + throw new \LogicException('Unknown type for switch case'); + } + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; + $var = $this->context->builder->structGep($value, $offset); + $__type = $this->context->getTypeFromString('__value__value*'); + + $__kind = $__type->getKind(); + $__value = $var; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $offset = $__type->constInt($__value, false); + if (! is_object($__value)) { + $ptr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $offset = $this->context->builder->truncOrBitCast($__value, $__type); + $ptr = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $offset = $this->context->builder->zExtOrBitCast($__value, $__type); + $ptr = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $offset = $this->context->builder->fpToSi($__value, $__type); - + + $ptr = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $offset = $this->context->builder->ptrToInt($__value, $__type); + $ptr = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $offset = $__type->constReal(0); + if (! is_object($__value)) { + $ptr = $__type->constReal($var); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $offset = $this->context->builder->siToFp($__value, $__type); - + + $ptr = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $offset = $this->context->builder->fpCast($__value, $__type); + $ptr = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $offset = $__type->constInt($__value, false); + $ptr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $offset = $this->context->builder->intToPtr($__value, $__type); + $ptr = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $offset = $this->context->builder->pointerCast($__value, $__type); + $ptr = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $result = $this->context->builder->load($this->context->builder->gep( - $resultPtr, - //$this->context->context->int32Type()->constInt(0, false), - //$this->context->context->int32Type()->constInt(0, false), - $offset - )); - $__type = $this->context->context->doubleType(); - - - - $__kind = $__type->getKind(); - $__value = $result; - switch ($__kind) { + $offset = $this->context->structFieldMap[$ptr->typeOf()->getElementType()->getName()]['value']; + $varPtr = $this->context->builder->structGep($ptr, $offset); + $result = $this->context->builder->call( + $this->context->lookupFunction('__value__readLong'), + $varPtr + + ); + $this->context->builder->returnValue($result); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($__switches)->end); + end($__switches)->endIsUsed = true; + } + + $this->context->builder->positionAtEnd(end($__switches)->default); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($__switches)->end); + end($__switches)->endIsUsed = true; + } + $__switch = array_pop($__switches); + if ($__switch->endIsUsed) { + $this->context->builder->positionAtEnd($__switch->end); + } else { + $__switch->end->remove(); + } + $__type = $this->context->getTypeFromString('int64'); + + $__kind = $__type->getKind(); + $__value = 0; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $return = $__type->constInt($__value, false); + if (! is_object($__value)) { + $result = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $return = $this->context->builder->truncOrBitCast($__value, $__type); + $result = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $return = $this->context->builder->zExtOrBitCast($__value, $__type); + $result = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $return = $this->context->builder->fpToSi($__value, $__type); - + + $result = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $return = $this->context->builder->ptrToInt($__value, $__type); + $result = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $return = $__type->constReal($result); + if (! is_object($__value)) { + $result = $__type->constReal(0); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $return = $this->context->builder->siToFp($__value, $__type); - + + $result = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $return = $this->context->builder->fpCast($__value, $__type); + $result = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $return = $__type->constInt($__value, false); + $result = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $return = $this->context->builder->intToPtr($__value, $__type); + $result = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $return = $this->context->builder->pointerCast($__value, $__type); + $result = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); - } - $this->context->builder->returnValue($return); - } - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($__switches)->end); - end($__switches)->endIsUsed = true; + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $__case = end($__switches)->default->insertBasicBlock('case_' . 0); - $this->context->builder->positionAtEnd($__case); - if (is_int(Variable::TYPE_NATIVE_DOUBLE)) { - end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_NATIVE_DOUBLE, false), $__case); - } elseif (Variable::TYPE_NATIVE_DOUBLE instanceof PHPLLVM\Value) { - end($__switches)->switch->addCase(Variable::TYPE_NATIVE_DOUBLE, $__case); - } else { - throw new \LogicException("Unknown type for switch case"); - } - { $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; - $ptr = $this->context->builder->structGep($value, $offset); - $__type = $this->context->getTypeFromString('double*'); - - - $__kind = $__type->getKind(); - $__value = $ptr; - switch ($__kind) { + $this->context->builder->returnValue($result); + + $this->context->builder->clearInsertionPosition(); + } + + protected function implementValueReadDouble(): void + { + $fn___70efdf2ec9b086079795c442636b55fb = $this->context->lookupFunction('__value__readDouble'); + $block___70efdf2ec9b086079795c442636b55fb = $fn___70efdf2ec9b086079795c442636b55fb->appendBasicBlock('main'); + $this->context->builder->positionAtEnd($block___70efdf2ec9b086079795c442636b55fb); + $value = $fn___70efdf2ec9b086079795c442636b55fb->getParam(0); + + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['type']; + $type = $this->context->builder->load( + $this->context->builder->structGep($value, $offset) + ); + $__switches[] = $__switch = new \StdClass(); + $__switch->type = $type->typeOf(); + $__prev = $this->context->builder->getInsertBlock(); + $__switch->default = $__prev->insertBasicBlock('default'); + $__prev->moveBefore($__switch->default); + $__switch->end = $__switch->default->insertBasicBlock('end'); + $__switch->endIsUsed = false; + $__switch->numCases = 0; + ++$__switch->numCases; + ++$__switch->numCases; + ++$__switch->numCases; + + $__switch->switch = $this->context->builder->branchSwitch($type, $__switch->default, $__switch->numCases); + $__case = end($__switches)->default->insertBasicBlock('case_'. 0); + $this->context->builder->positionAtEnd($__case); + if (is_int(Variable::TYPE_NATIVE_LONG)) { + end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_NATIVE_LONG, false), $__case); + } elseif (Variable::TYPE_NATIVE_LONG instanceof PHPLLVM\Value) { + end($__switches)->switch->addCase(Variable::TYPE_NATIVE_LONG, $__case); + } else { + throw new \LogicException('Unknown type for switch case'); + } + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; + $ptr = $this->context->builder->structGep($value, $offset); + $__type = $this->context->getTypeFromString('int64*'); + + $__kind = $__type->getKind(); + $__value = $ptr; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { + if (! is_object($__value)) { $resultPtr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); @@ -2204,50 +2442,58 @@ protected function implementValueReadDouble(): void { } else { $resultPtr = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - + $resultPtr = $this->context->builder->fpToSi($__value, $__type); - + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: $resultPtr = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { + if (! is_object($__value)) { $resultPtr = $__type->constReal($ptr); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - + $resultPtr = $this->context->builder->siToFp($__value, $__type); - + break; case PHPLLVM\Type::KIND_DOUBLE: $resultPtr = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... $resultPtr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: $resultPtr = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); @@ -2255,23 +2501,25 @@ protected function implementValueReadDouble(): void { // break; case PHPLLVM\Type::KIND_POINTER: $resultPtr = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $__type = $this->context->getTypeFromString('int32'); - - - $__kind = $__type->getKind(); - $__value = 0; - switch ($__kind) { + $__type = $this->context->getTypeFromString('int32'); + + $__kind = $__type->getKind(); + $__value = 0; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { + if (! is_object($__value)) { $offset = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); @@ -2282,50 +2530,58 @@ protected function implementValueReadDouble(): void { } else { $offset = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - + $offset = $this->context->builder->fpToSi($__value, $__type); - + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: $offset = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { + if (! is_object($__value)) { $offset = $__type->constReal(0); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - + $offset = $this->context->builder->siToFp($__value, $__type); - + break; case PHPLLVM\Type::KIND_DOUBLE: $offset = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... $offset = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: $offset = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); @@ -2333,531 +2589,576 @@ protected function implementValueReadDouble(): void { // break; case PHPLLVM\Type::KIND_POINTER: $offset = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $result = $this->context->builder->load($this->context->builder->gep( + $result = $this->context->builder->load($this->context->builder->gep( $resultPtr, //$this->context->context->int32Type()->constInt(0, false), //$this->context->context->int32Type()->constInt(0, false), $offset )); - $this->context->builder->returnValue($result); - } - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($__switches)->end); - end($__switches)->endIsUsed = true; - } - $__case = end($__switches)->default->insertBasicBlock('case_' . 0); - $this->context->builder->positionAtEnd($__case); - if (is_int(Variable::TYPE_VALUE)) { - end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_VALUE, false), $__case); - } elseif (Variable::TYPE_VALUE instanceof PHPLLVM\Value) { - end($__switches)->switch->addCase(Variable::TYPE_VALUE, $__case); - } else { - throw new \LogicException("Unknown type for switch case"); - } - { $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; - $var = $this->context->builder->structGep($value, $offset); - $__type = $this->context->getTypeFromString('__value__value*'); - - - $__kind = $__type->getKind(); - $__value = $var; - switch ($__kind) { + $__type = $this->context->context->doubleType(); + + $__kind = $__type->getKind(); + $__value = $result; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $ptr = $__type->constInt($__value, false); + if (! is_object($__value)) { + $return = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $ptr = $this->context->builder->truncOrBitCast($__value, $__type); + $return = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $ptr = $this->context->builder->zExtOrBitCast($__value, $__type); + $return = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $ptr = $this->context->builder->fpToSi($__value, $__type); - + + $return = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $ptr = $this->context->builder->ptrToInt($__value, $__type); + $return = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $ptr = $__type->constReal($var); + if (! is_object($__value)) { + $return = $__type->constReal($result); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $ptr = $this->context->builder->siToFp($__value, $__type); - + + $return = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $ptr = $this->context->builder->fpCast($__value, $__type); + $return = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $ptr = $__type->constInt($__value, false); + $return = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $ptr = $this->context->builder->intToPtr($__value, $__type); + $return = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $ptr = $this->context->builder->pointerCast($__value, $__type); + $return = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); - } - $offset = $this->context->structFieldMap[$ptr->typeOf()->getElementType()->getName()]['value']; - $varPtr = $this->context->builder->structGep($ptr, $offset); - $result = $this->context->builder->call( - $this->context->lookupFunction('__value__readDouble') , - $varPtr - - ); - $this->context->builder->returnValue($result); - } - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($__switches)->end); - end($__switches)->endIsUsed = true; + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - - $this->context->builder->positionAtEnd(end($__switches)->default); - - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($__switches)->end); - end($__switches)->endIsUsed = true; - } - $__switch = array_pop($__switches); - if ($__switch->endIsUsed) { - $this->context->builder->positionAtEnd($__switch->end); - } else { - $__switch->end->remove(); - } - $__type = $this->context->context->doubleType(); - - - - $__kind = $__type->getKind(); - $__value = 0.0; - switch ($__kind) { + $this->context->builder->returnValue($return); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($__switches)->end); + end($__switches)->endIsUsed = true; + } + $__case = end($__switches)->default->insertBasicBlock('case_'. 0); + $this->context->builder->positionAtEnd($__case); + if (is_int(Variable::TYPE_NATIVE_DOUBLE)) { + end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_NATIVE_DOUBLE, false), $__case); + } elseif (Variable::TYPE_NATIVE_DOUBLE instanceof PHPLLVM\Value) { + end($__switches)->switch->addCase(Variable::TYPE_NATIVE_DOUBLE, $__case); + } else { + throw new \LogicException('Unknown type for switch case'); + } + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; + $ptr = $this->context->builder->structGep($value, $offset); + $__type = $this->context->getTypeFromString('double*'); + + $__kind = $__type->getKind(); + $__value = $ptr; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $result = $__type->constInt($__value, false); + if (! is_object($__value)) { + $resultPtr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $result = $this->context->builder->truncOrBitCast($__value, $__type); + $resultPtr = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $result = $this->context->builder->zExtOrBitCast($__value, $__type); + $resultPtr = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $result = $this->context->builder->fpToSi($__value, $__type); - + + $resultPtr = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $result = $this->context->builder->ptrToInt($__value, $__type); + $resultPtr = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $result = $__type->constReal(0.0); + if (! is_object($__value)) { + $resultPtr = $__type->constReal($ptr); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $result = $this->context->builder->siToFp($__value, $__type); - + + $resultPtr = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $result = $this->context->builder->fpCast($__value, $__type); + $resultPtr = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $result = $__type->constInt($__value, false); + $resultPtr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $result = $this->context->builder->intToPtr($__value, $__type); + $resultPtr = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $result = $this->context->builder->pointerCast($__value, $__type); + $resultPtr = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $this->context->builder->returnValue($result); - - $this->context->builder->clearInsertionPosition(); - } - - public function implementValueWriteDouble(): void { - $fn___b6d767d2f8ed5d21a44b0e5886680cb9 = $this->context->lookupFunction('__value__writeDouble'); - $block___b6d767d2f8ed5d21a44b0e5886680cb9 = $fn___b6d767d2f8ed5d21a44b0e5886680cb9->appendBasicBlock('main'); - $this->context->builder->positionAtEnd($block___b6d767d2f8ed5d21a44b0e5886680cb9); - $value = $fn___b6d767d2f8ed5d21a44b0e5886680cb9->getParam(0); - $double = $fn___b6d767d2f8ed5d21a44b0e5886680cb9->getParam(1); - - $this->context->builder->call( - $this->context->lookupFunction('__value__valueDelref') , - $value - - ); - $__type = $this->context->getTypeFromString('int8'); - - - $__kind = $__type->getKind(); - $__value = Variable::TYPE_NATIVE_DOUBLE; - switch ($__kind) { + $__type = $this->context->getTypeFromString('int32'); + + $__kind = $__type->getKind(); + $__value = 0; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $type = $__type->constInt($__value, false); + if (! is_object($__value)) { + $offset = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $type = $this->context->builder->truncOrBitCast($__value, $__type); + $offset = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $type = $this->context->builder->zExtOrBitCast($__value, $__type); + $offset = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $type = $this->context->builder->fpToSi($__value, $__type); - + + $offset = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $type = $this->context->builder->ptrToInt($__value, $__type); + $offset = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $type = $__type->constReal(Variable::TYPE_NATIVE_DOUBLE); + if (! is_object($__value)) { + $offset = $__type->constReal(0); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $type = $this->context->builder->siToFp($__value, $__type); - + + $offset = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $type = $this->context->builder->fpCast($__value, $__type); + $offset = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $type = $__type->constInt($__value, false); + $offset = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $type = $this->context->builder->intToPtr($__value, $__type); + $offset = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $type = $this->context->builder->pointerCast($__value, $__type); + $offset = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['type']; - $this->context->builder->store( - $type, - $this->context->builder->structGep($value, $offset) - ); - $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; - $ptr = $this->context->builder->structGep($value, $offset); - $__type = $this->context->getTypeFromString('double*'); - - - $__kind = $__type->getKind(); - $__value = $ptr; - switch ($__kind) { + $result = $this->context->builder->load($this->context->builder->gep( + $resultPtr, + //$this->context->context->int32Type()->constInt(0, false), + //$this->context->context->int32Type()->constInt(0, false), + $offset + )); + $this->context->builder->returnValue($result); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($__switches)->end); + end($__switches)->endIsUsed = true; + } + $__case = end($__switches)->default->insertBasicBlock('case_'. 0); + $this->context->builder->positionAtEnd($__case); + if (is_int(Variable::TYPE_VALUE)) { + end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_VALUE, false), $__case); + } elseif (Variable::TYPE_VALUE instanceof PHPLLVM\Value) { + end($__switches)->switch->addCase(Variable::TYPE_VALUE, $__case); + } else { + throw new \LogicException('Unknown type for switch case'); + } + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; + $var = $this->context->builder->structGep($value, $offset); + $__type = $this->context->getTypeFromString('__value__value*'); + + $__kind = $__type->getKind(); + $__value = $var; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $resultPtr = $__type->constInt($__value, false); + if (! is_object($__value)) { + $ptr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $resultPtr = $this->context->builder->truncOrBitCast($__value, $__type); + $ptr = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $resultPtr = $this->context->builder->zExtOrBitCast($__value, $__type); + $ptr = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $resultPtr = $this->context->builder->fpToSi($__value, $__type); - + + $ptr = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $resultPtr = $this->context->builder->ptrToInt($__value, $__type); + $ptr = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $resultPtr = $__type->constReal($ptr); + if (! is_object($__value)) { + $ptr = $__type->constReal($var); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $resultPtr = $this->context->builder->siToFp($__value, $__type); - + + $ptr = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $resultPtr = $this->context->builder->fpCast($__value, $__type); + $ptr = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $resultPtr = $__type->constInt($__value, false); + $ptr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $resultPtr = $this->context->builder->intToPtr($__value, $__type); + $ptr = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $resultPtr = $this->context->builder->pointerCast($__value, $__type); + $ptr = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $__type = $this->context->getTypeFromString('int32'); - - - $__kind = $__type->getKind(); - $__value = 0; - switch ($__kind) { + $offset = $this->context->structFieldMap[$ptr->typeOf()->getElementType()->getName()]['value']; + $varPtr = $this->context->builder->structGep($ptr, $offset); + $result = $this->context->builder->call( + $this->context->lookupFunction('__value__readDouble'), + $varPtr + + ); + $this->context->builder->returnValue($result); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($__switches)->end); + end($__switches)->endIsUsed = true; + } + + $this->context->builder->positionAtEnd(end($__switches)->default); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($__switches)->end); + end($__switches)->endIsUsed = true; + } + $__switch = array_pop($__switches); + if ($__switch->endIsUsed) { + $this->context->builder->positionAtEnd($__switch->end); + } else { + $__switch->end->remove(); + } + $__type = $this->context->context->doubleType(); + + $__kind = $__type->getKind(); + $__value = 0.0; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $offset = $__type->constInt($__value, false); + if (! is_object($__value)) { + $result = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: if ($__other_type->getWidth() >= $__type->getWidth()) { - $offset = $this->context->builder->truncOrBitCast($__value, $__type); + $result = $this->context->builder->truncOrBitCast($__value, $__type); } else { - $offset = $this->context->builder->zExtOrBitCast($__value, $__type); + $result = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - - $offset = $this->context->builder->fpToSi($__value, $__type); - + + $result = $this->context->builder->fpToSi($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - $offset = $this->context->builder->ptrToInt($__value, $__type); + $result = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $offset = $__type->constReal(0); + if (! is_object($__value)) { + $result = $__type->constReal(0.0); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - - $offset = $this->context->builder->siToFp($__value, $__type); - + + $result = $this->context->builder->siToFp($__value, $__type); + break; case PHPLLVM\Type::KIND_DOUBLE: - $offset = $this->context->builder->fpCast($__value, $__type); + $result = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... - $offset = $__type->constInt($__value, false); + $result = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - $offset = $this->context->builder->intToPtr($__value, $__type); + $result = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); // $(result) = $this->context->builder->intToPtr($__tmp, $__type); // break; case PHPLLVM\Type::KIND_POINTER: - $offset = $this->context->builder->pointerCast($__value, $__type); + $result = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $this->context->builder->store($double, $this->context->builder->gep( - $resultPtr, - //$this->context->context->int32Type()->constInt(0, false), - //$this->context->context->int32Type()->constInt(0, false), - $offset - )); - $this->context->builder->returnVoid(); - - $this->context->builder->clearInsertionPosition(); - } - - protected function implementValueReadString(): void { + $this->context->builder->returnValue($result); + + $this->context->builder->clearInsertionPosition(); + } + + protected function implementValueReadString(): void + { $fn___1ff1de774005f8da13f42943881c655f = $this->context->lookupFunction('__value__readString'); - $block___1ff1de774005f8da13f42943881c655f = $fn___1ff1de774005f8da13f42943881c655f->appendBasicBlock('main'); - $this->context->builder->positionAtEnd($block___1ff1de774005f8da13f42943881c655f); - $value = $fn___1ff1de774005f8da13f42943881c655f->getParam(0); - - $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['type']; - $type = $this->context->builder->load( + $block___1ff1de774005f8da13f42943881c655f = $fn___1ff1de774005f8da13f42943881c655f->appendBasicBlock('main'); + $this->context->builder->positionAtEnd($block___1ff1de774005f8da13f42943881c655f); + $value = $fn___1ff1de774005f8da13f42943881c655f->getParam(0); + + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['type']; + $type = $this->context->builder->load( $this->context->builder->structGep($value, $offset) ); - $__switches[] = $__switch = new \StdClass; - $__switch->type = $type->typeOf(); - $__prev = $this->context->builder->getInsertBlock(); - $__switch->default = $__prev->insertBasicBlock('default'); - $__prev->moveBefore($__switch->default); - $__switch->end = $__switch->default->insertBasicBlock('end'); - $__switch->endIsUsed = false; - $__switch->numCases = 0; - $__switch->numCases++; - $__switch->numCases++; - - $__switch->switch = $this->context->builder->branchSwitch($type, $__switch->default, $__switch->numCases); - $__case = end($__switches)->default->insertBasicBlock('case_' . 0); - $this->context->builder->positionAtEnd($__case); - if (is_int(Variable::TYPE_STRING)) { - end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_STRING, false), $__case); - } elseif (Variable::TYPE_STRING instanceof PHPLLVM\Value) { - end($__switches)->switch->addCase(Variable::TYPE_STRING, $__case); - } else { - throw new \LogicException("Unknown type for switch case"); - } - { $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; - $ptr = $this->context->builder->structGep($value, $offset); - $__type = $this->context->getTypeFromString('__string__*'); - - - $__kind = $__type->getKind(); - $__value = $ptr; - switch ($__kind) { + $__switches[] = $__switch = new \StdClass(); + $__switch->type = $type->typeOf(); + $__prev = $this->context->builder->getInsertBlock(); + $__switch->default = $__prev->insertBasicBlock('default'); + $__prev->moveBefore($__switch->default); + $__switch->end = $__switch->default->insertBasicBlock('end'); + $__switch->endIsUsed = false; + $__switch->numCases = 0; + ++$__switch->numCases; + ++$__switch->numCases; + + $__switch->switch = $this->context->builder->branchSwitch($type, $__switch->default, $__switch->numCases); + $__case = end($__switches)->default->insertBasicBlock('case_'. 0); + $this->context->builder->positionAtEnd($__case); + if (is_int(Variable::TYPE_STRING)) { + end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_STRING, false), $__case); + } elseif (Variable::TYPE_STRING instanceof PHPLLVM\Value) { + end($__switches)->switch->addCase(Variable::TYPE_STRING, $__case); + } else { + throw new \LogicException('Unknown type for switch case'); + } + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; + $ptr = $this->context->builder->structGep($value, $offset); + $__type = $this->context->getTypeFromString('__string__*'); + + $__kind = $__type->getKind(); + $__value = $ptr; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { + if (! is_object($__value)) { $resultPtr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); @@ -2868,50 +3169,58 @@ protected function implementValueReadString(): void { } else { $resultPtr = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - + $resultPtr = $this->context->builder->fpToSi($__value, $__type); - + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: $resultPtr = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { + if (! is_object($__value)) { $resultPtr = $__type->constReal($ptr); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - + $resultPtr = $this->context->builder->siToFp($__value, $__type); - + break; case PHPLLVM\Type::KIND_DOUBLE: $resultPtr = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... $resultPtr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: $resultPtr = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); @@ -2919,40 +3228,42 @@ protected function implementValueReadString(): void { // break; case PHPLLVM\Type::KIND_POINTER: $resultPtr = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $this->context->builder->returnValue($resultPtr); - } - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($__switches)->end); - end($__switches)->endIsUsed = true; - } - $__case = end($__switches)->default->insertBasicBlock('case_' . 0); - $this->context->builder->positionAtEnd($__case); - if (is_int(Variable::TYPE_VALUE)) { - end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_VALUE, false), $__case); - } elseif (Variable::TYPE_VALUE instanceof PHPLLVM\Value) { - end($__switches)->switch->addCase(Variable::TYPE_VALUE, $__case); - } else { - throw new \LogicException("Unknown type for switch case"); - } - { $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; - $var = $this->context->builder->structGep($value, $offset); - $__type = $this->context->getTypeFromString('__value__value*'); - - - $__kind = $__type->getKind(); - $__value = $var; - switch ($__kind) { + $this->context->builder->returnValue($resultPtr); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($__switches)->end); + end($__switches)->endIsUsed = true; + } + $__case = end($__switches)->default->insertBasicBlock('case_'. 0); + $this->context->builder->positionAtEnd($__case); + if (is_int(Variable::TYPE_VALUE)) { + end($__switches)->switch->addCase(end($__switches)->type->constInt(Variable::TYPE_VALUE, false), $__case); + } elseif (Variable::TYPE_VALUE instanceof PHPLLVM\Value) { + end($__switches)->switch->addCase(Variable::TYPE_VALUE, $__case); + } else { + throw new \LogicException('Unknown type for switch case'); + } + $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; + $var = $this->context->builder->structGep($value, $offset); + $__type = $this->context->getTypeFromString('__value__value*'); + + $__kind = $__type->getKind(); + $__value = $var; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { + if (! is_object($__value)) { $ptr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); @@ -2963,50 +3274,58 @@ protected function implementValueReadString(): void { } else { $ptr = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - + $ptr = $this->context->builder->fpToSi($__value, $__type); - + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: $ptr = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { + if (! is_object($__value)) { $ptr = $__type->constReal($var); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - + $ptr = $this->context->builder->siToFp($__value, $__type); - + break; case PHPLLVM\Type::KIND_DOUBLE: $ptr = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... $ptr = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: $ptr = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); @@ -3014,51 +3333,53 @@ protected function implementValueReadString(): void { // break; case PHPLLVM\Type::KIND_POINTER: $ptr = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $offset = $this->context->structFieldMap[$var->typeOf()->getElementType()->getName()]['value']; - $varPtr = $this->context->builder->load( + $offset = $this->context->structFieldMap[$var->typeOf()->getElementType()->getName()]['value']; + $varPtr = $this->context->builder->load( $this->context->builder->structGep($var, $offset) ); - $result = $this->context->builder->call( - $this->context->lookupFunction('__value__readString') , + $result = $this->context->builder->call( + $this->context->lookupFunction('__value__readString'), $varPtr - + ); - $this->context->builder->returnValue($result); - } - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($__switches)->end); - end($__switches)->endIsUsed = true; - } - - $this->context->builder->positionAtEnd(end($__switches)->default); - - if ($this->context->builder->getInsertBlock()->getTerminator() === null) { - $this->context->builder->branch(end($__switches)->end); - end($__switches)->endIsUsed = true; - } - $__switch = array_pop($__switches); - if ($__switch->endIsUsed) { - $this->context->builder->positionAtEnd($__switch->end); - } else { - $__switch->end->remove(); - } - $__type = $this->context->getTypeFromString('__string__*'); - - - $__kind = $__type->getKind(); - $__value = null; - switch ($__kind) { + $this->context->builder->returnValue($result); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($__switches)->end); + end($__switches)->endIsUsed = true; + } + + $this->context->builder->positionAtEnd(end($__switches)->default); + + if ($this->context->builder->getInsertBlock()->getTerminator() === null) { + $this->context->builder->branch(end($__switches)->end); + end($__switches)->endIsUsed = true; + } + $__switch = array_pop($__switches); + if ($__switch->endIsUsed) { + $this->context->builder->positionAtEnd($__switch->end); + } else { + $__switch->end->remove(); + } + $__type = $this->context->getTypeFromString('__string__*'); + + $__kind = $__type->getKind(); + $__value = null; + switch ($__kind) { case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { + if (! is_object($__value)) { $result = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); @@ -3069,50 +3390,58 @@ protected function implementValueReadString(): void { } else { $result = $this->context->builder->zExtOrBitCast($__value, $__type); } + break; case PHPLLVM\Type::KIND_DOUBLE: - + $result = $this->context->builder->fpToSi($__value, $__type); - + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: $result = $this->context->builder->ptrToInt($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (int, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { + if (! is_object($__value)) { $result = $__type->constReal(null); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: - + $result = $this->context->builder->siToFp($__value, $__type); - + break; case PHPLLVM\Type::KIND_DOUBLE: $result = $this->context->builder->fpCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; case PHPLLVM\Type::KIND_ARRAY: case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { + if (! is_object($__value)) { // this is very likely very wrong... $result = $__type->constInt($__value, false); + break; } $__other_type = $__value->typeOf(); switch ($__other_type->getKind()) { case PHPLLVM\Type::KIND_INTEGER: $result = $this->context->builder->intToPtr($__value, $__type); + break; case PHPLLVM\Type::KIND_ARRAY: // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); @@ -3120,122 +3449,18 @@ protected function implementValueReadString(): void { // break; case PHPLLVM\Type::KIND_POINTER: $result = $this->context->builder->pointerCast($__value, $__type); + break; default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); - } - break; - default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); - } - $this->context->builder->returnValue($result); - - $this->context->builder->clearInsertionPosition(); - } - - public function implementValueWriteString(): void { - $fn___33e75ff09dd601bbe69f351039152189 = $this->context->lookupFunction('__value__writeString'); - $block___33e75ff09dd601bbe69f351039152189 = $fn___33e75ff09dd601bbe69f351039152189->appendBasicBlock('main'); - $this->context->builder->positionAtEnd($block___33e75ff09dd601bbe69f351039152189); - $value = $fn___33e75ff09dd601bbe69f351039152189->getParam(0); - $string = $fn___33e75ff09dd601bbe69f351039152189->getParam(1); - - $this->context->builder->call( - $this->context->lookupFunction('__value__valueDelref') , - $value - - ); - $__type = $this->context->getTypeFromString('int8'); - - - $__kind = $__type->getKind(); - $__value = Variable::TYPE_STRING; - switch ($__kind) { - case PHPLLVM\Type::KIND_INTEGER: - if (!is_object($__value)) { - $type = $__type->constInt($__value, false); - break; - } - $__other_type = $__value->typeOf(); - switch ($__other_type->getKind()) { - case PHPLLVM\Type::KIND_INTEGER: - if ($__other_type->getWidth() >= $__type->getWidth()) { - $type = $this->context->builder->truncOrBitCast($__value, $__type); - } else { - $type = $this->context->builder->zExtOrBitCast($__value, $__type); - } - break; - case PHPLLVM\Type::KIND_DOUBLE: - - $type = $this->context->builder->fpToSi($__value, $__type); - - break; - case PHPLLVM\Type::KIND_ARRAY: - case PHPLLVM\Type::KIND_POINTER: - $type = $this->context->builder->ptrToInt($__value, $__type); - break; - default: - throw new \LogicException("Unknown how to handle type pair (int, " . $__other_type->toString() . ")"); - } - break; - case PHPLLVM\Type::KIND_DOUBLE: - if (!is_object($__value)) { - $type = $__type->constReal(Variable::TYPE_STRING); - break; - } - $__other_type = $__value->typeOf(); - switch ($__other_type->getKind()) { - case PHPLLVM\Type::KIND_INTEGER: - - $type = $this->context->builder->siToFp($__value, $__type); - - break; - case PHPLLVM\Type::KIND_DOUBLE: - $type = $this->context->builder->fpCast($__value, $__type); - break; - default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); - } - break; - case PHPLLVM\Type::KIND_ARRAY: - case PHPLLVM\Type::KIND_POINTER: - if (!is_object($__value)) { - // this is very likely very wrong... - $type = $__type->constInt($__value, false); - break; - } - $__other_type = $__value->typeOf(); - switch ($__other_type->getKind()) { - case PHPLLVM\Type::KIND_INTEGER: - $type = $this->context->builder->intToPtr($__value, $__type); - break; - case PHPLLVM\Type::KIND_ARRAY: - // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type()); - // $(result) = $this->context->builder->intToPtr($__tmp, $__type); - // break; - case PHPLLVM\Type::KIND_POINTER: - $type = $this->context->builder->pointerCast($__value, $__type); - break; - default: - throw new \LogicException("Unknown how to handle type pair (double, " . $__other_type->toString() . ")"); + throw new \LogicException('Unknown how to handle type pair (double, '.$__other_type->toString().')'); } + break; default: - throw new \LogicException("Unsupported type cast: " . $__type->toString()); + throw new \LogicException('Unsupported type cast: '.$__type->toString()); } - $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['type']; - $this->context->builder->store( - $type, - $this->context->builder->structGep($value, $offset) - ); - $offset = $this->context->structFieldMap[$value->typeOf()->getElementType()->getName()]['value']; - $this->context->builder->store( - $string, - $this->context->builder->structGep($value, $offset) - ); - $this->context->builder->returnVoid(); - - $this->context->builder->clearInsertionPosition(); - } - -} + $this->context->builder->returnValue($result); + + $this->context->builder->clearInsertionPosition(); + } +} diff --git a/src/macro_functions.php b/src/macro_functions.php old mode 100644 new mode 100755 index efd4ec7..f206e9c --- a/src/macro_functions.php +++ b/src/macro_functions.php @@ -14,7 +14,10 @@ use function Pre\Plugin\addMacro; // ideally this would happen automatically, but whatever - addMacro(__DIR__.'/macros.yay'); + if (function_exists('Pre\Plugin\addMacro')) { + // Guard this so a production deploy will work properly + addMacro(__DIR__.'/macros.yay'); + } function ctype(): Parser {