Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename macro defintr #60

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/charms/env.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Charms.Env do
use Charms.Intrinsic
alias Charms.Intrinsic.Opts

defintrinsic t() do
defintr t() do
%Opts{ctx: ctx} = __IR__
Beaver.ENIF.Type.env(ctx: ctx)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/charms/intrinsic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ defmodule Charms.Intrinsic do
@doc """
To implement an intrinsic function
"""
defmacro defintrinsic(call, do: body) do
defmacro defintr(call, do: body) do
{name, _meta, args} = call
call = recompose_when_clauses(name, args)
placeholder_args = normalize_arg_names(args)
Expand Down
4 changes: 2 additions & 2 deletions lib/charms/kernel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule Charms.Kernel do
end

for name <- @binary_ops ++ @binary_macro_ops do
defintrinsic unquote(name)(left, right) do
defintr unquote(name)(left, right) do
%Opts{ctx: ctx, blk: blk, loc: loc} = __IR__

{operands, type} =
Expand Down Expand Up @@ -77,7 +77,7 @@ defmodule Charms.Kernel do
end
end

defintrinsic !value do
defintr !value do
t = MLIR.Value.type(value)

unless MLIR.CAPI.mlirTypeIsAInteger(t) |> Beaver.Native.to_term() do
Expand Down
22 changes: 11 additions & 11 deletions lib/charms/pointer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Charms.Pointer do
@doc """
Allocates a single element of the given `elem_type`, returning a pointer to it.
"""
defintrinsic allocate(elem_type) do
defintr allocate(elem_type) do
{quote do
Charms.Pointer.allocate(elem_type, 1)
end, elem_type: elem_type}
Expand All @@ -22,7 +22,7 @@ defmodule Charms.Pointer do
@doc """
Allocates an array of `size` elements of the given `elem_type`, returning a pointer to it.
"""
defintrinsic allocate(elem_type, size) do
defintr allocate(elem_type, size) do
%Opts{ctx: ctx, blk: blk, loc: loc} = __IR__

mlir ctx: ctx, blk: blk do
Expand Down Expand Up @@ -70,7 +70,7 @@ defmodule Charms.Pointer do
@doc """
Loads a value of `type` from the given pointer `ptr`.
"""
defintrinsic load(type, ptr) do
defintr load(type, ptr) do
%Opts{ctx: ctx, blk: blk, loc: loc} = __IR__

if MLIR.equal?(MLIR.Value.type(ptr), ~t{!llvm.ptr}) do
Expand All @@ -85,7 +85,7 @@ defmodule Charms.Pointer do
end
end

defintrinsic load(%MLIR.Value{} = ptr) do
defintr load(%MLIR.Value{} = ptr) do
t = MLIR.Value.type(ptr)

if memref_ptr?(t) do
Expand All @@ -100,7 +100,7 @@ defmodule Charms.Pointer do
@doc """
Stores a value `val` at the given pointer `ptr`.
"""
defintrinsic store(val, ptr) do
defintr store(val, ptr) do
%Opts{ctx: ctx, blk: blk, loc: loc} = __IR__

mlir ctx: ctx, blk: blk do
Expand Down Expand Up @@ -147,7 +147,7 @@ defmodule Charms.Pointer do
end
end

defintrinsic element_ptr(%MLIR.Type{} = elem_type, ptr, n) do
defintr element_ptr(%MLIR.Type{} = elem_type, ptr, n) do
%Opts{ctx: ctx, blk: blk, loc: loc} = __IR__

t = MLIR.Value.type(ptr)
Expand Down Expand Up @@ -179,7 +179,7 @@ defmodule Charms.Pointer do
@doc """
Gets the element pointer of `elem_type` for the given base pointer `ptr` and index `n`.
"""
defintrinsic element_ptr(%MLIR.Value{} = ptr, n) do
defintr element_ptr(%MLIR.Value{} = ptr, n) do
t = MLIR.Value.type(ptr)

if memref_ptr?(t) do
Expand All @@ -191,7 +191,7 @@ defmodule Charms.Pointer do
end
end

defintrinsic element_type(%MLIR.Value{} = ptr) do
defintr element_type(%MLIR.Value{} = ptr) do
t = MLIR.Value.type(ptr)

if memref_ptr?(t) do
Expand All @@ -204,12 +204,12 @@ defmodule Charms.Pointer do
@doc """
Return the pointer type
"""
defintrinsic t() do
defintr t() do
%Opts{ctx: ctx} = __IR__
Beaver.Deferred.create(~t{!llvm.ptr}, ctx)
end

defintrinsic t(elem_t) do
defintr t(elem_t) do
%Opts{ctx: ctx} = __IR__
ptr_type(elem_t, ctx)
end
Expand Down Expand Up @@ -252,7 +252,7 @@ defmodule Charms.Pointer do
end
end

defintrinsic copy(source, destination, bytes_count) do
defintr copy(source, destination, bytes_count) do
%Opts{ctx: ctx, blk: blk, loc: loc} = __IR__
source = extract_raw_pointer(source, __IR__)
destination = extract_raw_pointer(destination, __IR__)
Expand Down
10 changes: 5 additions & 5 deletions lib/charms/prelude.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Charms.Prelude do
v
end

defintrinsic result_at(%MLIR.Operation{} = op, index) do
defintr result_at(%MLIR.Operation{} = op, index) do
num_results = MLIR.CAPI.mlirOperationGetNumResults(op)

if index < num_results do
Expand All @@ -32,11 +32,11 @@ defmodule Charms.Prelude do
@doc """
Get the MLIR type of the given value.
"""
defintrinsic type_of(value) do
defintr type_of(value) do
MLIR.Value.type(value)
end

defintrinsic const(ast) do
defintr const(ast) do
{:"::", _type_meta, [value, type]} = ast
%Opts{ctx: ctx, blk: blk, loc: loc} = __IR__

Expand All @@ -48,7 +48,7 @@ defmodule Charms.Prelude do
@doc """
Dump the MLIR entity at compile time with `IO.puts/1`
"""
defintrinsic dump(entity) do
defintr dump(entity) do
entity |> tap(&IO.puts(MLIR.to_string(&1)))
end

Expand Down Expand Up @@ -98,7 +98,7 @@ defmodule Charms.Prelude do
arity = Beaver.ENIF.signature(signature_ctx, name) |> elem(0) |> length()
args = Macro.generate_arguments(arity, __MODULE__)

defintrinsic unquote(name)(unquote_splicing(args)) do
defintr unquote(name)(unquote_splicing(args)) do
call_enif(unquote(name), unquote(args), __IR__)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/charms/simd.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Charms.SIMD do
@doc """
Return the constant value of the given `type` and `literal_values`
"""
defintrinsic new(type, literal_values) do
defintr new(type, literal_values) do
%Opts{ctx: ctx, blk: blk} = __IR__

mlir ctx: ctx, blk: blk do
Expand Down Expand Up @@ -39,7 +39,7 @@ defmodule Charms.SIMD do
@doc """
Return the vector type of the given `type` and `width`
"""
defintrinsic t(type, width) do
defintr t(type, width) do
Type.vector([width], type)
end
end
2 changes: 1 addition & 1 deletion lib/charms/term.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Charms.Term do
@doc """
Return the Erlang term type.
"""
defintrinsic t() do
defintr t() do
%Opts{ctx: ctx} = __IR__
Beaver.ENIF.Type.term(ctx: ctx)
end
Expand Down
Loading