[PATCH] D98537: WIP: [M68k] Implement AsmParser

Ricky Taylor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 17 16:47:32 PDT 2021


ricky26 created this revision.
ricky26 added a reviewer: myhsu.
Herald added subscribers: hiraditya, mgorny.
ricky26 edited the summary of this revision.
ricky26 updated this revision to Diff 330395.
ricky26 added a comment.
ricky26 published this revision for review.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Move operand parser definitions into earlier patch


myhsu added a comment.

> Should this use Motorola or gas syntax? (At the moment it uses Motorola syntax.)

I spent some time dig into GCC and binutils's source. By default GCC generate assembly that conforms to Motorola's syntax (thus GAS should consume that syntax by default). Jessica has pointed out in the review for the 4-th patch that for some reason, (GNU) objdump doesn't conform to Motorola's syntax. Though I didn't know the full story but apparently objdump and GCC are using separate code base to print out assembly and for unknown reasons, the former just didn't want to adopt Motorola's syntax :-P (it doesn't have the option to switch between different syntaxes either)
The bottom line is that I would recommend to implement Motorola's syntax first. We can always add "GNU flavor" assembly printer if needed in the future, just like ATT/Intel syntax in X86 land.

P.S. Alternatively GCC can generate they called "MIT syntax" which -- I have no idea what that is tbh --is probably closer to conventional GNU assembly syntax. But that syntax is only enabled if you're building cross-compile m68k gcc for openbsd


ricky26 added a comment.

I've marked this 'Ready for Review' since otherwise notifications don't happen. To be clear though, this is **not ready to merge**.

In D98537#2625355 <https://reviews.llvm.org/D98537#2625355>, @myhsu wrote:

>> Should this use Motorola or gas syntax? (At the moment it uses Motorola syntax.)
>
> I spent some time dig into GCC and binutils's source. By default GCC generate assembly that conforms to Motorola's syntax (thus GAS should consume that syntax by default). Jessica has pointed out in the review for the 4-th patch that for some reason, (GNU) objdump doesn't conform to Motorola's syntax. Though I didn't know the full story but apparently objdump and GCC are using separate code base to print out assembly and for unknown reasons, the former just didn't want to adopt Motorola's syntax :-P (it doesn't have the option to switch between different syntaxes either)
> The bottom line is that I would recommend to implement Motorola's syntax first. We can always add "GNU flavor" assembly printer if needed in the future, just like ATT/Intel syntax in X86 land.
>
> P.S. Alternatively GCC can generate they called "MIT syntax" which -- I have no idea what that is tbh --is probably closer to conventional GNU assembly syntax. But that syntax is only enabled if you're building cross-compile m68k gcc for openbsd

The MIT syntax appears to be the default documented syntax in the `as` manual (http://web.mit.edu/gnu/doc/html/as_16.html#SEC189, a mirror but it seems up to date). Their logic seems sensible to me: we should support both addressing syntaxes and it should be pretty sane to support both.

However, as' manual on Motorola Syntax still does something which doesn't match Motorola's manual: prefixing the registers with %. Does GCC do this? It looks like `as` supports this, but it's behind a flag. (Motorola's assembly syntax uses % for binary numbers but we can support both with a bit of peeking.)

So, perhaps the strategy should be this:

- Change the assembler/disassembler to use %-prefixed registers in this patch
- Add support for parsing MIT operand syntax in a later patch
- Add support for emitting MIT operand syntax on a flag in a later patch
- Add support for the alternate assembly directive names in a later patch
- Add support for parsing register names without a prefix on a flag in a later patch

The last point worries me a little since it seems a very commonly referenced format but we'd be doing what `as` does, if I understand correctly.


This is a work-in-progress implementation of an assembler for M68k.

Outstanding work:

- Updating existing tests assembly syntax
- Writing new tests for the assembler (and disassembler)

I've left those until there's consensus that this approach is okay (I hope that's okay!).

Questions I'm aware of:

- Should this use Motorola or gas syntax? (At the moment it uses Motorola syntax.)

Depends on D98519 <https://reviews.llvm.org/D98519>

Depends on D98532 <https://reviews.llvm.org/D98532>

Depends on D98534 <https://reviews.llvm.org/D98534>

Depends on D98535 <https://reviews.llvm.org/D98535>

Depends on D98536 <https://reviews.llvm.org/D98536>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98537

Files:
  llvm/lib/Target/M68k/AsmParser/CMakeLists.txt
  llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp
  llvm/lib/Target/M68k/CMakeLists.txt
  llvm/lib/Target/M68k/M68k.td

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98537.330395.patch
Type: text/x-patch
Size: 27605 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210317/a0ab64b9/attachment.bin>


More information about the llvm-commits mailing list