local in a sh script is not posix, and while some shells do support it, some 
do not,
e.g. ksh 88/93 (frequently used on traditional unix systems), yash, and more.

So portable sh scripts should not use local.

- avih

     On Sunday, February 14, 2021, 09:30:48 PM GMT+2, Danny Milosavljevic 
<dan...@scratchpost.org> wrote:  
 
 ---
 tests/arm-asm-testsuite.sh | 78 ++++++++++++++++++++++++--------------
 1 file changed, 50 insertions(+), 28 deletions(-)

diff --git a/tests/arm-asm-testsuite.sh b/tests/arm-asm-testsuite.sh
index 61c5dad..ae36eb1 100755
--- a/tests/arm-asm-testsuite.sh
+++ b/tests/arm-asm-testsuite.sh
@@ -2,6 +2,53 @@
 
 set -e
 
+# Parameter 1: source file name
+# Parameter 2: unique test id
+# Return value: Whether instruction worked in GNU as
+# Side effect: Files in ${state}: "expected-"*, "got-"*, maybe "ok-"*
+run_test() {
+    local s
+    local err
+    local as_object
+    local tcc_object
+    local expected
+    local got
+    local source_file
+    source_file="$1"
+    s="$2"
+    #echo ".syntax unified" > a.s
+    err="`mktemp --suffix=-stderr.log`"
+    as_object="${state}/as-$s.o"
+    tcc_object="${state}/tcc-$s.o"
+    expected="${state}/expected-$s"
+    got="${state}/got-$s"
+    if "${CROSS_COMPILE}as" -mlittle-endian ${as_opts} -o "${as_object}" 
"${source_file}" 2>"${err}"
+    then
+        cat "${err}"
+        rm -f "${err}"
+        "${CROSS_COMPILE}objdump" -S "${as_object}" |grep "^[ ]*0:" 
>"${expected}"
+        if ${TCC} -o "${tcc_object}" -c "${source_file}"
+        then
+            "${CROSS_COMPILE}objdump" -S "${tcc_object}" |grep "^[ ]*0:" 
>"${got}"
+            if diff -u "${got}" "${expected}"
+            then
+                touch "${state}/ok-$s"
+            else
+                echo "warning: '$s' did not work in tcc (see above)">&2
+            fi
+        else
+            rm -f "${tcc_object}"
+            echo "warning: '$s' did not work in tcc">&2
+        fi
+        rm -f "${err}"
+        return 0
+    else # GNU as can't do it either--so we don't care
+        rm -f "${as_object}"
+    fi
+    rm -f "${err}"
+    return 1
+}
+
 # Note: "{r3}" is definitely different--but would complicate the assembler.
 
 state="`mktemp -d`"
@@ -166,38 +213,13 @@ do
                    "d4, s3" \
                 ""
     do
-        #echo ".syntax unified" > a.s
-        err="`mktemp --suffix=-stderr.log`"
-        as_object="${state}/as-$s $args.o"
-        tcc_object="${state}/tcc-$s $args.o"
-        expected="${state}/expected-$s $args"
-        got="${state}/got-$s $args"
-        if echo "$s $args" | "${CROSS_COMPILE}as" -mlittle-endian ${as_opts} 
-o "${as_object}" - 2>"${err}"
+        src="${state}/src-${s} ${args}.s"
+        echo "${s} ${args}" > "${src}"
+        if run_test "${src}" "${s} ${args}"
         then
-            cat "${err}"
-            rm -f "${err}"
             total_count=`expr $total_count + 1`
-            "${CROSS_COMPILE}objdump" -S "${as_object}" |grep "^[ ]*0:" 
>"${expected}"
-
-            #echo '__asm__("'"$s ${args}"'");' > "${csource}"
-            if echo '__asm__("'"$s ${args}"'");'| ${TCC} -o "${tcc_object}" -c 
-
-            then
-                "${CROSS_COMPILE}objdump" -S "${tcc_object}" |grep "^[ ]*0:" 
>"${got}"
-                if diff -u "${got}" "${expected}"
-                then
-                    touch "${state}/ok-$s $args"
-                else
-                    echo "warning: '$s $args' did not work in tcc (see 
above)">&2
-                fi
-            else
-                rm -f "${tcc_object}"
-                echo "warning: '$s $args' did not work in tcc">&2
-            fi
             ok=1
-        else # GNU as can't do it either--so we don't care
-            rm -f "${as_object}"
         fi
-        rm -f "${err}"
     done
     if [ "${ok}" -eq "0" ]
     then

_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
  
_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to