-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
Charms.Constant.from_literal/5
(#56)
- Loading branch information
1 parent
123ab77
commit 37abfda
Showing
8 changed files
with
87 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule Charms.Constant do | ||
@moduledoc false | ||
use Beaver | ||
alias Beaver.MLIR.Dialect.{Arith, Index} | ||
|
||
def from_literal(literal, %MLIR.Value{} = v, ctx, blk, loc) do | ||
t = MLIR.CAPI.mlirValueGetType(v) | ||
from_literal(literal, t, ctx, blk, loc) | ||
end | ||
|
||
def from_literal(literal, %MLIR.Type{} = t, ctx, blk, loc) do | ||
mlir ctx: ctx, blk: blk do | ||
cond do | ||
MLIR.Type.integer?(t) -> | ||
Arith.constant(value: Attribute.integer(t, literal), loc: loc) >>> t | ||
|
||
MLIR.Type.float?(t) -> | ||
Arith.constant(value: Attribute.float(t, literal), loc: loc) >>> t | ||
|
||
MLIR.Type.index?(t) -> | ||
Index.constant(value: Attribute.index(literal), loc: loc) >>> t | ||
|
||
true -> | ||
loc = Beaver.Deferred.create(loc, ctx) | ||
raise CompileError, Charms.Diagnostic.meta_from_loc(loc) ++ [description: "Not a supported type for constant, #{to_string(t)}"] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters