@@ -143,6 +143,17 @@ public function register(): void
143
143
$ fn___cfcd208495d565ef66e7dff9f98764da ->addAttributeAtIndex (\PHPLLVM \Attribute::INDEX_FUNCTION , $ this ->context ->attributes ['alwaysinline ' ]);
144
144
145
145
$ this ->context ->registerFunction ('__value__writeString ' , $ fn___cfcd208495d565ef66e7dff9f98764da );
146
+
147
+ $ fntype___cfcd208495d565ef66e7dff9f98764da = $ this ->context ->context ->functionType (
148
+ $ this ->context ->getTypeFromString ('void ' ),
149
+ false ,
150
+ $ this ->context ->getTypeFromString ('__value__* ' )
151
+
152
+ );
153
+ $ fn___cfcd208495d565ef66e7dff9f98764da = $ this ->context ->module ->addFunction ('__value__writeNull ' , $ fntype___cfcd208495d565ef66e7dff9f98764da );
154
+ $ fn___cfcd208495d565ef66e7dff9f98764da ->addAttributeAtIndex (\PHPLLVM \Attribute::INDEX_FUNCTION , $ this ->context ->attributes ['alwaysinline ' ]);
155
+
156
+ $ this ->context ->registerFunction ('__value__writeNull ' , $ fn___cfcd208495d565ef66e7dff9f98764da );
146
157
}
147
158
148
159
public function implement (): void
@@ -152,6 +163,7 @@ public function implement(): void
152
163
$ this ->implementValueWriteLong ();
153
164
$ this ->implementValueReadDouble ();
154
165
$ this ->implementValueWriteDouble ();
166
+ $ this ->implementValueWriteNull ();
155
167
$ this ->implementValueDelref ();
156
168
}
157
169
@@ -865,6 +877,116 @@ public function implementValueWriteString(): void
865
877
$ this ->context ->builder ->clearInsertionPosition ();
866
878
}
867
879
880
+ public function implementValueWriteNull (): void
881
+ {
882
+ $ fn___34173cb38f07f89ddbebc2ac9128303f = $ this ->context ->lookupFunction ('__value__writeNull ' );
883
+ $ block___34173cb38f07f89ddbebc2ac9128303f = $ fn___34173cb38f07f89ddbebc2ac9128303f ->appendBasicBlock ('main ' );
884
+ $ this ->context ->builder ->positionAtEnd ($ block___34173cb38f07f89ddbebc2ac9128303f );
885
+ $ value = $ fn___34173cb38f07f89ddbebc2ac9128303f ->getParam (0 );
886
+
887
+ $ this ->context ->builder ->call (
888
+ $ this ->context ->lookupFunction ('__value__valueDelref ' ),
889
+ $ value
890
+
891
+ );
892
+ $ __type = $ this ->context ->getTypeFromString ('int8 ' );
893
+
894
+ $ __kind = $ __type ->getKind ();
895
+ $ __value = Variable::TYPE_NULL ;
896
+ switch ($ __kind ) {
897
+ case \PHPLLVM \Type::KIND_INTEGER :
898
+ if (! is_object ($ __value )) {
899
+ $ type = $ __type ->constInt ($ __value , false );
900
+
901
+ break ;
902
+ }
903
+ $ __other_type = $ __value ->typeOf ();
904
+ switch ($ __other_type ->getKind ()) {
905
+ case \PHPLLVM \Type::KIND_INTEGER :
906
+ if ($ __other_type ->getWidth () >= $ __type ->getWidth ()) {
907
+ $ type = $ this ->context ->builder ->truncOrBitCast ($ __value , $ __type );
908
+ } else {
909
+ $ type = $ this ->context ->builder ->zExtOrBitCast ($ __value , $ __type );
910
+ }
911
+
912
+ break ;
913
+ case \PHPLLVM \Type::KIND_DOUBLE :
914
+
915
+ $ type = $ this ->context ->builder ->fpToSi ($ __value , $ __type );
916
+
917
+ break ;
918
+ case \PHPLLVM \Type::KIND_ARRAY :
919
+ case \PHPLLVM \Type::KIND_POINTER :
920
+ $ type = $ this ->context ->builder ->ptrToInt ($ __value , $ __type );
921
+
922
+ break ;
923
+ default :
924
+ throw new \LogicException ('Unknown how to handle type pair (int, ' .$ __other_type ->toString ().') ' );
925
+ }
926
+
927
+ break ;
928
+ case \PHPLLVM \Type::KIND_DOUBLE :
929
+ if (! is_object ($ __value )) {
930
+ $ type = $ __type ->constReal (Variable::TYPE_NULL );
931
+
932
+ break ;
933
+ }
934
+ $ __other_type = $ __value ->typeOf ();
935
+ switch ($ __other_type ->getKind ()) {
936
+ case \PHPLLVM \Type::KIND_INTEGER :
937
+
938
+ $ type = $ this ->context ->builder ->siToFp ($ __value , $ __type );
939
+
940
+ break ;
941
+ case \PHPLLVM \Type::KIND_DOUBLE :
942
+ $ type = $ this ->context ->builder ->fpCast ($ __value , $ __type );
943
+
944
+ break ;
945
+ default :
946
+ throw new \LogicException ('Unknown how to handle type pair (double, ' .$ __other_type ->toString ().') ' );
947
+ }
948
+
949
+ break ;
950
+ case \PHPLLVM \Type::KIND_ARRAY :
951
+ case \PHPLLVM \Type::KIND_POINTER :
952
+ if (! is_object ($ __value )) {
953
+ // this is very likely very wrong...
954
+ $ type = $ __type ->constInt ($ __value , false );
955
+
956
+ break ;
957
+ }
958
+ $ __other_type = $ __value ->typeOf ();
959
+ switch ($ __other_type ->getKind ()) {
960
+ case \PHPLLVM \Type::KIND_INTEGER :
961
+ $ type = $ this ->context ->builder ->intToPtr ($ __value , $ __type );
962
+
963
+ break ;
964
+ case \PHPLLVM \Type::KIND_ARRAY :
965
+ // $__tmp = $this->context->builder->($__value, $this->context->context->int64Type());
966
+ // $(result) = $this->context->builder->intToPtr($__tmp, $__type);
967
+ // break;
968
+ case \PHPLLVM \Type::KIND_POINTER :
969
+ $ type = $ this ->context ->builder ->pointerCast ($ __value , $ __type );
970
+
971
+ break ;
972
+ default :
973
+ throw new \LogicException ('Unknown how to handle type pair (double, ' .$ __other_type ->toString ().') ' );
974
+ }
975
+
976
+ break ;
977
+ default :
978
+ throw new \LogicException ('Unsupported type cast: ' .$ __type ->toString ());
979
+ }
980
+ $ offset = $ this ->context ->structFieldMap [$ value ->typeOf ()->getElementType ()->getName ()]['type ' ];
981
+ $ this ->context ->builder ->store (
982
+ $ type ,
983
+ $ this ->context ->builder ->structGep ($ value , $ offset )
984
+ );
985
+ $ this ->context ->builder ->returnVoid ();
986
+
987
+ $ this ->context ->builder ->clearInsertionPosition ();
988
+ }
989
+
868
990
protected function implementValueDelref (): void
869
991
{
870
992
$ fn___c4ca4238a0b923820dcc509a6f75849b = $ this ->context ->lookupFunction ('__value__valueDelref ' );
0 commit comments