Skip to content

Commit 9830731

Browse files
committed
string: unify string types on i8*
Made-with: Cursor
1 parent 4a75cf7 commit 9830731

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

src/irx/builders/llvmliteir.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ class VariablesLLVM:
187187
type: ir.types.Type
188188
BOOLEAN_TYPE:
189189
type: ir.types.Type
190-
STRING_TYPE:
191-
type: ir.types.Type
192190
ASCII_STRING_TYPE:
193191
type: ir.types.Type
194192
UTF8_STRING_TYPE:
@@ -220,7 +218,6 @@ class VariablesLLVM:
220218
INT32_TYPE: ir.types.Type
221219
VOID_TYPE: ir.types.Type
222220
BOOLEAN_TYPE: ir.types.Type
223-
STRING_TYPE: ir.types.Type
224221
ASCII_STRING_TYPE: ir.types.Type
225222
UTF8_STRING_TYPE: ir.types.Type
226223
TIME_TYPE: ir.types.Type
@@ -263,12 +260,8 @@ def get_data_type(self, type_name: str) -> ir.types.Type:
263260
return self.INT64_TYPE
264261
elif type_name == "char":
265262
return self.INT8_TYPE
266-
elif type_name == "string":
267-
return self.STRING_TYPE
268-
elif type_name == "stringascii":
263+
elif type_name in ("string", "stringascii", "utf8string"):
269264
return self.ASCII_STRING_TYPE
270-
elif type_name == "utf8string":
271-
return self.UTF8_STRING_TYPE
272265
elif type_name == "nonetype":
273266
return self.VOID_TYPE
274267

@@ -418,11 +411,8 @@ def initialize(self) -> None:
418411
self._llvm.INT32_TYPE = ir.IntType(32)
419412
self._llvm.INT64_TYPE = ir.IntType(64)
420413
self._llvm.VOID_TYPE = ir.VoidType()
421-
self._llvm.STRING_TYPE = ir.LiteralStructType(
422-
[ir.IntType(32), ir.IntType(8).as_pointer()]
423-
)
424414
self._llvm.ASCII_STRING_TYPE = ir.IntType(8).as_pointer()
425-
self._llvm.UTF8_STRING_TYPE = self._llvm.STRING_TYPE
415+
self._llvm.UTF8_STRING_TYPE = self._llvm.ASCII_STRING_TYPE
426416
# Composite types
427417
self._llvm.TIME_TYPE = ir.LiteralStructType(
428418
[
@@ -2942,7 +2932,7 @@ def visit(self, node: system.Cast) -> None:
29422932

29432933
elif target_type in (
29442934
self._llvm.ASCII_STRING_TYPE,
2945-
self._llvm.STRING_TYPE,
2935+
self._llvm.UTF8_STRING_TYPE,
29462936
):
29472937
if is_int_type(value.type):
29482938
arg, fmt_str = self._normalize_int_for_printf(value)

tests/test_llvmlite_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def test_get_data_type_aliases_and_invalid() -> None:
134134
assert llvm_vars.get_data_type("float16") == llvm_vars.FLOAT16_TYPE
135135
assert llvm_vars.get_data_type("double") == llvm_vars.DOUBLE_TYPE
136136
assert llvm_vars.get_data_type("char") == llvm_vars.INT8_TYPE
137-
assert llvm_vars.get_data_type("utf8string") == llvm_vars.UTF8_STRING_TYPE
137+
assert llvm_vars.get_data_type("utf8string") == llvm_vars.ASCII_STRING_TYPE
138138

139139
with pytest.raises(Exception, match="not valid"):
140140
llvm_vars.get_data_type("not-a-type")

0 commit comments

Comments
 (0)