String to enum
All checks were successful
CI / ci (ReleaseFast, ubuntu-latest) (pull_request) Successful in 2m3s
CI / ci (ReleaseSmall, ubuntu-latest) (pull_request) Successful in 2m3s
CI / ci (ReleaseSafe, ubuntu-latest) (pull_request) Successful in 2m7s
CI / ci (Debug, ubuntu-latest) (pull_request) Successful in 3m12s
CI / ci (ReleaseFast, ubuntu-latest) (push) Successful in 2m2s
CI / ci (ReleaseSmall, ubuntu-latest) (push) Successful in 2m0s
CI / ci (ReleaseSafe, ubuntu-latest) (push) Successful in 2m7s
CI / ci (Debug, ubuntu-latest) (push) Successful in 3m10s
All checks were successful
CI / ci (ReleaseFast, ubuntu-latest) (pull_request) Successful in 2m3s
CI / ci (ReleaseSmall, ubuntu-latest) (pull_request) Successful in 2m3s
CI / ci (ReleaseSafe, ubuntu-latest) (pull_request) Successful in 2m7s
CI / ci (Debug, ubuntu-latest) (pull_request) Successful in 3m12s
CI / ci (ReleaseFast, ubuntu-latest) (push) Successful in 2m2s
CI / ci (ReleaseSmall, ubuntu-latest) (push) Successful in 2m0s
CI / ci (ReleaseSafe, ubuntu-latest) (push) Successful in 2m7s
CI / ci (Debug, ubuntu-latest) (push) Successful in 3m10s
This commit is contained in:
parent
0e789d3f13
commit
408d53a6f9
21
src/LLVM.zig
21
src/LLVM.zig
@ -808,6 +808,10 @@ pub const Module = opaque {
|
||||
pub fn get_intrinsic_declaration(module: *Module, intrinsic_id: Intrinsic.Id, parameter_types: []const *Type) *Value {
|
||||
return api.LLVMGetIntrinsicDeclaration(module, intrinsic_id, parameter_types.ptr, parameter_types.len);
|
||||
}
|
||||
|
||||
pub fn get_named_function(module: *Module, name: [*:0]const u8) ?*Function {
|
||||
return api.LLVMGetNamedFunction(module, name);
|
||||
}
|
||||
};
|
||||
|
||||
pub const VerifyResult = struct {
|
||||
@ -956,6 +960,10 @@ pub const Builder = opaque {
|
||||
return api.LLVMBuildTrunc(builder, value, destination_type, "");
|
||||
}
|
||||
|
||||
pub fn create_int_cast(builder: *Builder, value: *Value, destination_type: *Type, is_signed: bool) *Value {
|
||||
return api.LLVMBuildIntCast2(builder, value, destination_type, @intFromBool(is_signed), "");
|
||||
}
|
||||
|
||||
pub const create_unreachable = api.LLVMBuildUnreachable;
|
||||
|
||||
pub const create_memcpy = api.LLVMBuildMemCpy;
|
||||
@ -996,10 +1004,15 @@ pub const GlobalVariable = opaque {
|
||||
pub const set_initializer = api.LLVMSetInitializer;
|
||||
pub const erase_from_parent = api.LLVMDeleteGlobal;
|
||||
pub const delete = api.llvm_global_variable_delete;
|
||||
|
||||
pub fn to_value(global_variable: *GlobalVariable) *Value {
|
||||
return @ptrCast(global_variable);
|
||||
}
|
||||
|
||||
pub fn to_constant(global_variable: *GlobalVariable) *Constant {
|
||||
return @ptrCast(global_variable);
|
||||
}
|
||||
|
||||
pub const UnnamedAddress = enum(c_uint) {
|
||||
none,
|
||||
local,
|
||||
@ -1036,6 +1049,10 @@ pub const Function = opaque {
|
||||
return api.llvm_function_to_string(function).to_slice().?;
|
||||
}
|
||||
|
||||
pub fn dump(function: *Function) void {
|
||||
return lib.print_string(function.to_string());
|
||||
}
|
||||
|
||||
pub const set_calling_convention = api.LLVMSetFunctionCallConv;
|
||||
pub const get_calling_convention = api.LLVMGetFunctionCallConv;
|
||||
|
||||
@ -1060,6 +1077,10 @@ pub const Constant = opaque {
|
||||
pub fn to_value(constant: *Constant.Integer) *Value {
|
||||
return @ptrCast(constant);
|
||||
}
|
||||
|
||||
pub fn to_constant(constant: *Constant.Integer) *Constant {
|
||||
return @ptrCast(constant);
|
||||
}
|
||||
};
|
||||
|
||||
pub const get_sign_extended_value = api.LLVMConstIntGetSExtValue;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -225,13 +225,25 @@ global_state_initialize = fn () void
|
||||
};
|
||||
}
|
||||
|
||||
CompilerCommand = enum
|
||||
{
|
||||
compile,
|
||||
test,
|
||||
}
|
||||
|
||||
[export] main = fn [cc(c)] (argument_count: u32, argv: &&u8) s32
|
||||
{
|
||||
global_state_initialize();
|
||||
|
||||
if (argument_count < 2)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
>command_string = c_string_to_slice(argv[1]);
|
||||
|
||||
> a = #string_to_enum(CompilerCommand, command_string);
|
||||
|
||||
>relative_file_path_pointer = argv[2];
|
||||
if (!relative_file_path_pointer)
|
||||
{
|
||||
@ -256,6 +268,5 @@ global_state_initialize = fn () void
|
||||
return 1;
|
||||
}
|
||||
|
||||
global_state_initialize();
|
||||
return 0;
|
||||
}
|
||||
|
@ -103,12 +103,13 @@ pub extern fn LLVMBuildSwitch(builder: *llvm.Builder, discriminant: *llvm.Value,
|
||||
pub extern fn LLVMAddCase(switchi: *llvm.Instruction.Switch, case_value: *llvm.Value, case_block: *llvm.BasicBlock) void;
|
||||
|
||||
// Casts
|
||||
pub extern fn LLVMBuildIntCast2(builder: *llvm.Builder, value: *llvm.Value, destination_type: *llvm.Type, is_signed: Bool, name: [*:0]const u8) *llvm.Value;
|
||||
pub extern fn LLVMBuildZExt(builder: *llvm.Builder, value: *llvm.Value, destination_type: *llvm.Type, name: [*:0]const u8) *llvm.Value;
|
||||
pub extern fn LLVMBuildSExt(builder: *llvm.Builder, value: *llvm.Value, destination_type: *llvm.Type, name: [*:0]const u8) *llvm.Value;
|
||||
pub extern fn LLVMBuildTrunc(builder: *llvm.Builder, value: *llvm.Value, destination_type: *llvm.Type, name: [*:0]const u8) *llvm.Value;
|
||||
pub extern fn LLVMBuildIntToPtr(builder: *llvm.Builder, value: *llvm.Value, destination_type: *llvm.Type, name: [*:0]const u8) *llvm.Value;
|
||||
pub extern fn LLVMBuildPtrToInt(builder: *llvm.Builder, value: *llvm.Value, destination_type: *llvm.Type, name: [*:0]const u8) *llvm.Value;
|
||||
pub extern fn LLVMBuildPointerCast(builder: *llvm.Builder, value: *llvm.Value, ty: *llvm.Type, name: [*:0]const u8) *llvm.Value;
|
||||
pub extern fn LLVMBuildTrunc(builder: *llvm.Builder, value: *llvm.Value, destination_type: *llvm.Type, name: [*:0]const u8) *llvm.Value;
|
||||
|
||||
pub extern fn LLVMSetCurrentDebugLocation2(builder: *llvm.Builder, location: ?*llvm.DI.Location) void;
|
||||
|
||||
@ -124,6 +125,7 @@ pub extern fn llvm_value_is_instruction(value: *llvm.Value) bool;
|
||||
|
||||
// Intrinsics
|
||||
pub extern fn LLVMLookupIntrinsicID(name_pointer: [*]const u8, name_length: usize) llvm.Intrinsic.Id;
|
||||
pub extern fn LLVMGetNamedFunction(module: *llvm.Module, name: [*:0]const u8) *llvm.Function;
|
||||
pub extern fn LLVMGetIntrinsicDeclaration(module: *llvm.Module, intrinsic_id: llvm.Intrinsic.Id, parameter_type_pointer: [*]const *llvm.Type, parameter_type_count: usize) *llvm.Value;
|
||||
pub extern fn LLVMIntrinsicGetType(context: *llvm.Context, intrinsic_id: llvm.Intrinsic.Id, parameter_type_pointer: [*]const *llvm.Type, parameter_type_count: usize) *llvm.Type.Function;
|
||||
|
||||
|
@ -309,4 +309,6 @@ const names = &[_][]const u8{
|
||||
"c_struct_with_array",
|
||||
"c_function_pointer",
|
||||
"c_abi",
|
||||
"string_to_enum",
|
||||
"abi_enum_bool",
|
||||
};
|
||||
|
36
tests/abi_enum_bool.bbb
Normal file
36
tests/abi_enum_bool.bbb
Normal file
@ -0,0 +1,36 @@
|
||||
Foo = enum {
|
||||
a,
|
||||
b,
|
||||
c,
|
||||
d,
|
||||
e,
|
||||
f,
|
||||
g,
|
||||
}
|
||||
|
||||
S = struct
|
||||
{
|
||||
enum: Foo,
|
||||
some_boolean: u1,
|
||||
}
|
||||
|
||||
require = fn (ok: u1) void
|
||||
{
|
||||
if (!ok)
|
||||
{
|
||||
#trap();
|
||||
}
|
||||
}
|
||||
|
||||
[export] main = fn [cc(c)] () s32
|
||||
{
|
||||
>s: S = {
|
||||
.enum = .f,
|
||||
.some_boolean = 1,
|
||||
};
|
||||
|
||||
require(s.enum == .f);
|
||||
require(s.some_boolean);
|
||||
|
||||
return 0;
|
||||
}
|
20
tests/string_to_enum.bbb
Normal file
20
tests/string_to_enum.bbb
Normal file
@ -0,0 +1,20 @@
|
||||
E = enum
|
||||
{
|
||||
asd,
|
||||
dsa,
|
||||
gsa,
|
||||
}
|
||||
|
||||
[export] main = fn [cc(c)] () s32
|
||||
{
|
||||
>e = "dsa";
|
||||
>s2e = #string_to_enum(E, e);
|
||||
>result: s32 = 1;
|
||||
|
||||
if (s2e.is_valid)
|
||||
{
|
||||
result = #extend(s2e.enum_value != .dsa);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user