Skip to content
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
1 change: 1 addition & 0 deletions UnitTest/AttrParser.lean
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ macro "#assert " e:term : command =>

/-! ## LLVM Byte type -/
#assert expectSuccessType "!llvm.byte<64>" (LLVM.ByteType.mk 64)
#assert expectSuccessType "!llvm.array<2 x byte<8>>" (LLVM.ArrayType.mk 2 $ LLVM.ByteType.mk 8)

/-! ## LLVM Struct type (parsed opaquely; see `parseOptionalLLVMStructType`)

Expand Down
25 changes: 15 additions & 10 deletions Veir/Parser/AttrParser.lean
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,18 @@ def parseOptionalFloatType : AttrParserM (Option FloatType) := do

/--
Parse an optional byte type.
A byte type is represented as `!llvm.byte<bitwidth>` where bitwidth is a positive integer.
A byte type is represented as `!llvm.byte<bitwidth>`, or `byte<bitwidth>` when `short`.
-/
def parseOptionalByteType : AttrParserM (Option LLVM.ByteType) := do
let token ← peekToken
let .exclamationIdent := token.kind | return none
let input := (← getThe ParserState).input
let typeName := { token.slice with start := token.slice.start + 1 }.of input
if typeName ≠ "llvm.byte".toByteArray then return none
let _ ← consumeToken
def parseOptionalByteType (short := false) : AttrParserM (Option LLVM.ByteType) := do
if short then
let .true ← parseOptionalKeyword "byte".toByteArray | return none
else
let token ← peekToken
let .exclamationIdent := token.kind | return none
let input := (← getThe ParserState).input
let typeName := { token.slice with start := token.slice.start + 1 }.of input
if typeName ≠ "llvm.byte".toByteArray then return none
let _ ← consumeToken
parsePunctuation "<"
let bitwidth ← parseInteger false false
parsePunctuation ">"
Expand Down Expand Up @@ -1109,8 +1112,8 @@ partial def parseOptionalLLVMStructType (short := false) : AttrParserM (Option T
/--
Parse a type within an LLVM-dialect type body, accepting the LLVM "pretty-print"
sugar keywords `void`, `ptr`, `x86_amx`, `ppc_fp128`, `label`, `metadata`, `token`, and
the bare nested forms `array<...>`, `struct<...>`, `func<...>`, and `target<...>` in
addition to the regular MLIR type forms.
the bare nested forms `byte<...>`, `array<...>`, `struct<...>`, `func<...>`, and
`target<...>` in addition to the regular MLIR type forms.

The bare nested form exists because the LLVM dialect has a custom directive
`PrettyLLVMType`, which allows types from the LLVM dialect to be written
Expand All @@ -1134,6 +1137,8 @@ partial def parseLLVMType (errorMsg : String := "type expected") : AttrParserM T
return LLVM.VoidType.mk
if ← parseOptionalKeyword "ptr".toByteArray then
return (LLVM.PointerType.mk : TypeAttr)
if let some type ← parseOptionalByteType true then
return type
if let some type ← parseOptionalLLVMArrayType true then
return type
if let some type ← parseOptionalLLVMStructType true then
Expand Down
Loading