This is an archive of the discontinued LLVM Phabricator instance.

Add support for Code16GCC
ClosedPublic

Authored by niravd on May 10 2016, 8:40 AM.

Details

Summary

[X86] The Code16GCC directive parses X86 assembly input in 32-bit mode and
outputs in 16-bit mode. Teach Parser to switch modes appropriately.

Diff Detail

Event Timeline

niravd updated this revision to Diff 56726.May 10 2016, 8:40 AM
niravd retitled this revision from to Add support for Code16GCC.
niravd added reviewers: dwmw2, craig.topper.
niravd updated this object.
niravd added a subscriber: llvm-commits.
dwmw2 edited edge metadata.EditedMay 10 2016, 9:08 AM

Hm, why? We already added -m16 support to both GCC and Clang. So why would anyone use .code16gcc any more? It's just legacy.

And the *only* reason you'd use it is by putting asm(".code16gcc") at the start of a C file (which has problems with ensuring it's *first* in the asm output, which is why -m16 is so much better even in GCC). And didn't I see separately you forbade inline asm from leaving the assembler in a different mode to the one it starts in?

Hm, why? We already added -m16 support to both GCC and Clang. So why would anyone use .code16gcc any more? It's just legacy.

And the *only* reason you'd use it is by putting asm(".code16gcc") at the start of a C file (which has problems with ensuring it's *first* in the asm output, which is why -m16 is so much better even in GCC). And didn't I see separately you forbade inline asm from leaving the assembler in a different mode to the one it starts in?

Agreed. It's not particularlly worthwhile as one could rewrite the code. Further, that one use example (asm(".code16gcc")) doesn't do anything as we do not preserve modes changes from inline assembly (which is the only reasonable way to deal with it persistant inline asm changes) (see: http://reviews.llvm.org/D20067). The only thing this does is let the integrated assembler automatically do the rewriting.

Hm, why? We already added -m16 support to both GCC and Clang. So why would anyone use .code16gcc any more? It's just legacy.

People do seem to use it in asm files, presumably for the same reason GCC used it: you get the same behavior of the textual assembly targetting 16-bit processor mode, as you would if it were running in a 32-bit processor mode.

Since LLVM's assembler is not only intended for inline asm in C, but also as an actual assembler, I think it makes fine sense to support this directive.

niravd updated this revision to Diff 71839.Sep 19 2016, 9:12 AM
niravd edited edge metadata.

rebase and do minor cosmetic cleanup

jyknight accepted this revision.Sep 26 2016, 11:23 AM
jyknight added a reviewer: jyknight.

LGTM, modulo the one comment.

lib/Target/X86/AsmParser/X86AsmParser.cpp
64

Please put this variable with the other instance variables above.

This revision is now accepted and ready to land.Sep 26 2016, 11:23 AM
This revision was automatically updated to reflect the committed changes.
niravd marked an inline comment as done.