Skip to content

Commit

Permalink
A few more changes, getting dockerhub setup and building initial images
Browse files Browse the repository at this point in the history
  • Loading branch information
ircmaxell committed Apr 16, 2019
1 parent a0d2b6a commit ad3f5f1
Show file tree
Hide file tree
Showing 13 changed files with 2,361 additions and 1,668 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 34 additions & 0 deletions Docker/dev/ubuntu-16.04/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 8 additions & 27 deletions Docker/ubuntu-16.04/Dockerfile
Original file line number Diff line number Diff line change
@@ -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\";'"]
23 changes: 12 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
docker run -v $(shell pwd):/compiler ircmaxell/php-compiler:16.04-dev php vendor/bin/phpunit
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
166 changes: 160 additions & 6 deletions examples/000-HelloWorld/example.bc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit ad3f5f1

Please sign in to comment.