[PATCH] D20337: [MC] Support symbolic expressions in assembly directives
Rafael EspĂndola via llvm-commits
llvm-commits at lists.llvm.org
Wed May 18 10:30:23 PDT 2016
I mean filetype=asm :-)
On May 18, 2016 1:15 PM, "Rafael EspĂndola" <rafael.espindola at gmail.com>
wrote:
> What happens if you try to print the assembly back out? I.e., if you run
> llvm-mc with filetype=obj?
>
> Cheers,
> Rafael
> On May 17, 2016 5:48 PM, "Petr Hosek via llvm-commits" <
> llvm-commits at lists.llvm.org> wrote:
>
> phosek created this revision.
> phosek added a subscriber: llvm-commits.
> phosek set the repository for this revision to rL LLVM.
>
> This matches the behavior of GNU assembler which supports symbolic
> expressions in absolute expressions used in assembly directives.
>
> Repository:
> rL LLVM
>
> http://reviews.llvm.org/D20337
>
> Files:
> include/llvm/MC/MCObjectStreamer.h
> include/llvm/MC/MCStreamer.h
> lib/MC/MCParser/AsmParser.cpp
> test/MC/AsmParser/symbolic-expression.s
>
> Index: test/MC/AsmParser/symbolic-expression.s
> ===================================================================
> --- /dev/null
> +++ test/MC/AsmParser/symbolic-expression.s
> @@ -0,0 +1,18 @@
> +# RUN: llvm-mc -filetype=obj -triple=i386-unknown-elf %s | llvm-objdump
> -t - | FileCheck %s
> +
> +# CHECK: 00000000 .text 00000000 TEST0
> +TEST0:
> + .fill 0x10
> +# CHECK: 00000010 .text 00000000 TEST1
> +TEST1:
> + .fill TEST1 - TEST0 + 0x5
> +# CHECK: 00000025 .text 00000000 TEST2
> +TEST2:
> + .zero TEST2 - (TEST1 + 0x5)
> +# CHECK: 00000035 .text 00000000 TEST3
> +TEST3:
> + .align (TEST1 - TEST0) * 8
> +# CHECK: 00000080 .text 00000000 TEST4
> +TEST4:
> +# CHECK: 00000015 g *COM* 00000010 a
> + .comm a, TEST2 - TEST1, TEST1 - TEST0
> Index: lib/MC/MCParser/AsmParser.cpp
> ===================================================================
> --- lib/MC/MCParser/AsmParser.cpp
> +++ lib/MC/MCParser/AsmParser.cpp
> @@ -1131,7 +1131,7 @@
> if (parseExpression(Expr))
> return true;
>
> - if (!Expr->evaluateAsAbsolute(Res))
> + if (!getStreamer().evaluateAsAbsolute(Expr, Res))
> return Error(StartLoc, "expected absolute expression");
>
> return false;
> Index: include/llvm/MC/MCStreamer.h
> ===================================================================
> --- include/llvm/MC/MCStreamer.h
> +++ include/llvm/MC/MCStreamer.h
> @@ -772,6 +772,11 @@
> void Finish();
>
> virtual bool mayHaveInstructions(MCSection &Sec) const { return true; }
> +
> + /// \brief Try to evaluate the \p Value as an absolute value.
> + virtual bool evaluateAsAbsolute(const MCExpr *Value, int64_t &Res) {
> + return Value->evaluateAsAbsolute(Res);
> + }
> };
>
> /// Create a dummy machine code streamer, which does nothing. This is
> useful for
> Index: include/llvm/MC/MCObjectStreamer.h
> ===================================================================
> --- include/llvm/MC/MCObjectStreamer.h
> +++ include/llvm/MC/MCObjectStreamer.h
> @@ -154,6 +154,12 @@
> unsigned Size) override;
>
> bool mayHaveInstructions(MCSection &Sec) const override;
> +
> + bool evaluateAsAbsolute(const MCExpr *Value, int64_t &Res) override {
> + MCDataFragment *DF = getOrCreateDataFragment();
> + flushPendingLabels(DF, DF->getContents().size());
> + return Value->evaluateAsAbsolute(Res, getAssembler());
> + }
> };
>
> } // end namespace llvm
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160518/a07ef540/attachment.html>
More information about the llvm-commits
mailing list