Constant mul
This commit is contained in:
parent
892360a084
commit
7bd79cb741
@ -548,6 +548,10 @@ pub const Builder = opaque {
|
||||
return api.LLVMBuildSub(builder, left, right, "");
|
||||
}
|
||||
|
||||
pub fn create_mul(builder: *Builder, left: *Value, right: *Value) *Value {
|
||||
return api.LLVMBuildMul(builder, left, right, "");
|
||||
}
|
||||
|
||||
pub fn create_ret_void(builder: *Builder) void {
|
||||
builder.create_ret(null);
|
||||
}
|
||||
|
@ -268,8 +268,9 @@ const Converter = struct {
|
||||
|
||||
const ExpressionState = enum {
|
||||
none,
|
||||
sub,
|
||||
add,
|
||||
sub,
|
||||
mul,
|
||||
};
|
||||
|
||||
fn parse_value(noalias converter: *Converter, noalias thread: *llvm.Thread, expected_type: *llvm.Type) *llvm.Value {
|
||||
@ -293,6 +294,7 @@ const Converter = struct {
|
||||
.none => current_value,
|
||||
.sub => thread.builder.create_sub(left, right),
|
||||
.add => thread.builder.create_add(left, right),
|
||||
.mul => thread.builder.create_mul(left, right),
|
||||
};
|
||||
|
||||
const ch = converter.content[converter.offset];
|
||||
@ -306,6 +308,10 @@ const Converter = struct {
|
||||
converter.offset += 1;
|
||||
break :blk .add;
|
||||
},
|
||||
'*' => blk: {
|
||||
converter.offset += 1;
|
||||
break :blk .mul;
|
||||
},
|
||||
else => os.abort(),
|
||||
};
|
||||
|
||||
@ -693,3 +699,7 @@ test "constant add" {
|
||||
test "constant sub" {
|
||||
try invoke("constant_sub");
|
||||
}
|
||||
|
||||
test "constant mul" {
|
||||
try invoke("constant_mul");
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ pub extern fn LLVMPositionBuilderAtEnd(builder: *llvm.Builder, basic_block: *llv
|
||||
pub extern fn LLVMBuildRet(builder: *llvm.Builder, value: ?*llvm.Value) void;
|
||||
pub extern fn LLVMBuildAdd(builder: *llvm.Builder, left: *llvm.Value, right: *llvm.Value, name: [*:0]const u8) *llvm.Value;
|
||||
pub extern fn LLVMBuildSub(builder: *llvm.Builder, left: *llvm.Value, right: *llvm.Value, name: [*:0]const u8) *llvm.Value;
|
||||
pub extern fn LLVMBuildMul(builder: *llvm.Builder, left: *llvm.Value, right: *llvm.Value, name: [*:0]const u8) *llvm.Value;
|
||||
|
||||
pub extern fn LLVMTypeOf(value: *llvm.Value) *llvm.Type;
|
||||
pub extern fn LLVMGlobalGetValueType(value: *llvm.GlobalValue) *llvm.Type;
|
||||
|
4
tests/constant_mul.bbb
Normal file
4
tests/constant_mul.bbb
Normal file
@ -0,0 +1,4 @@
|
||||
[export] main = fn [cc(c)] () s32
|
||||
{
|
||||
return 1 * 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user