summaryrefslogtreecommitdiffstats
path: root/llvm/test/MC
diff options
context:
space:
mode:
authorMichael Zuckerman <Michael.zuckerman@intel.com>2017-05-01 13:20:12 +0000
committerMichael Zuckerman <Michael.zuckerman@intel.com>2017-05-01 13:20:12 +0000
commit56704618aa037fbaaa0e141f86b1c78be45569d4 (patch)
tree49e7c2d494c8f0964bf18c74eb3d29c1327b64da /llvm/test/MC
parent6c60ed5a45937d5644bafb2fa7272994c337e8d7 (diff)
downloadbcm5719-llvm-56704618aa037fbaaa0e141f86b1c78be45569d4.tar.gz
bcm5719-llvm-56704618aa037fbaaa0e141f86b1c78be45569d4.zip
[LLVM][inline-asm] Altmacro absolute expression '%' feature
In this patch, I introduce a new alt macro feature. This feature adds meaning for the % when using it as a prefix to the calling macro arguments. In the altmacro mode, the percent sign '%' before an absolute expression convert the expression first to a string. As described in the https://sourceware.org/binutils/docs-2.27/as/Altmacro.html "Expression results as strings You can write `%expr' to evaluate the expression expr and use the result as a string." expression assumptions: 1. '%' can only evaluate an absolute expression. 2. Altmacro '%' must be the first character of the evaluated expression. 3. If no '%' is located before the expression, a regular module operation is expected. 4. The result of Absolute Expressions can be only integer. Differential Revision: https://reviews.llvm.org/D32526 llvm-svn: 301797
Diffstat (limited to 'llvm/test/MC')
-rw-r--r--llvm/test/MC/AsmParser/altmacro_expression.s65
-rw-r--r--llvm/test/MC/AsmParser/negativ_altmacro_expression.s34
2 files changed, 99 insertions, 0 deletions
diff --git a/llvm/test/MC/AsmParser/altmacro_expression.s b/llvm/test/MC/AsmParser/altmacro_expression.s
new file mode 100644
index 00000000000..871e5af727b
--- /dev/null
+++ b/llvm/test/MC/AsmParser/altmacro_expression.s
@@ -0,0 +1,65 @@
+# RUN: llvm-mc %s| FileCheck %s
+
+# Checking that the '%' was evaluated as a string first
+# In a fail scenario: The asmprint will print: addl $%(1+4), %eax
+
+# CHECK: addl $5, %eax
+.altmacro
+.macro percent_expr arg
+ addl $\arg, %eax
+.endm
+
+percent_expr %(1+4)
+
+
+# Checking that the second '%' acts as modulo operator
+# The altmacro percent '%' must be located before the first argument
+# If a percent is located in the middle of the estimated argument without any
+# '%' in the beginning , error will be generated.
+# The second percent '%' after the first altmacro percent '%' is a regular operator.
+
+# CHECK: addl $1, %eax
+.macro inner_percent arg
+ addl $\arg, %eax
+.endm
+
+inner_percent %(1%4)
+
+
+# Checking for nested macro
+# The first argument use is for the calling function and the second use is for the evaluation.
+
+# CHECK: addl $1, %eax
+.macro macro_call_0 number
+ addl $\number, %eax
+.endm
+
+.macro macro_call_1 number
+ macro_call_\number %(\number + 1)
+.endm
+
+macro_call_1 %(1-1)
+
+
+# Checking the ability to pass a number of arguments.
+# The arguments can be separated by ',' or not.
+
+# CHECK: label013:
+# CHECK: addl $0, %eax
+# CHECK: addl $1, %eax
+# CHECK: addl $3, %eax
+
+# CHECK: label014:
+# CHECK: addl $0, %eax
+# CHECK: addl $1, %eax
+# CHECK: addl $4, %eax
+
+.macro multi_args_macro arg1 arg2 arg3
+ label\arg1\arg2\arg3:
+ addl $\arg1, %eax
+ addl $\arg2, %eax
+ addl $\arg3, %eax
+.endm
+
+multi_args_macro %(1+4-5) 1 %2+1
+multi_args_macro %(1+4-5),1,%4%10
diff --git a/llvm/test/MC/AsmParser/negativ_altmacro_expression.s b/llvm/test/MC/AsmParser/negativ_altmacro_expression.s
new file mode 100644
index 00000000000..d0fbc6c1e46
--- /dev/null
+++ b/llvm/test/MC/AsmParser/negativ_altmacro_expression.s
@@ -0,0 +1,34 @@
+# RUN: not llvm-mc %s 2>&1 | FileCheck %s
+
+# This test is a negative test for the altmacro expression.
+# In this test we check the '.noaltmacro' directive.
+# We expect that '.altmacro' and '.noaltmacro' will act as a switch on/off directives to the alternate macro mode.
+# .noaltmacro returns the format into a regular macro handling.
+# The defult mode is ".noaltmacro" as first test checks.
+
+# CHECK: error: unknown token in expression
+# CHECK-NEXT: addl $%(1%4), %eax
+.macro inner_percent arg
+ addl $\arg, %eax
+.endm
+
+inner_percent %(1%4)
+
+.altmacro
+.noaltmacro
+
+# CHECK: multi_args_macro %(1+4-5) 1 %2+1
+# CHECK: error: unknown token in expression
+# CHECK-NEXT: addl $%(1+4-5), %eax
+
+
+# CHECK: multi_args_macro %(1+4-5),1,%4%10
+# CHECK: error: unknown token in expression
+# CHECK-NEXT: addl $%(1+4-5), %eax
+.macro multi_args_macro arg1 arg2 arg3
+ label\arg1\arg2\arg3:
+ addl $\arg1, %eax
+.endm
+
+multi_args_macro %(1+4-5) 1 %2+1
+multi_args_macro %(1+4-5),1,%4%10
OpenPOWER on IntegriCloud