From 16f077b4c6639da2db025de4c0bd18f2e8787ab5 Mon Sep 17 00:00:00 2001 From: Wen HU Date: Fri, 19 Feb 2021 15:16:29 -0800 Subject: [PATCH 1/2] add c demo printHuawei.c --- test/c_demo/README.md | 30 +++++++++++ test/c_demo/maple_aarch64_with_whirl2mpl.sh | 57 +++++++++++++++++++++ test/c_demo/printHuawei.c | 47 +++++++++++++++++ tools/setup_tools.sh | 12 +++++ 4 files changed, 146 insertions(+) create mode 100644 test/c_demo/README.md create mode 100755 test/c_demo/maple_aarch64_with_whirl2mpl.sh create mode 100644 test/c_demo/printHuawei.c diff --git a/test/c_demo/README.md b/test/c_demo/README.md new file mode 100644 index 0000000000..5560fb8e65 --- /dev/null +++ b/test/c_demo/README.md @@ -0,0 +1,30 @@ +``` +# +# Copyright (C) [2020-2021] Futurewei Technologies, Inc. All rights reverved. +# +# Licensed under the Mulan Permissive Software License v2. +# You can use this software according to the terms and conditions of the MulanPSL - 2.0. +# You may obtain a copy of MulanPSL - 2.0 at: +# +# https://opensource.org/licenses/MulanPSL-2.0 +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the MulanPSL - 2.0 for more details. +# +``` + +# Maple compiler for C Language + +#### 介绍 +example of Maple Compiler for C Language + +Besides maple compiler, included are processes using C front end tools: + 1. whirl2mpl - Front end using Open64 Whirl IR. + source code is available at https://gitee.com/open64ark/open64ark + +#### 使用说明 + run the following scripts for details + + ./maple_aarch64_with_whirl2mpl.sh diff --git a/test/c_demo/maple_aarch64_with_whirl2mpl.sh b/test/c_demo/maple_aarch64_with_whirl2mpl.sh new file mode 100755 index 0000000000..3c3020c8ef --- /dev/null +++ b/test/c_demo/maple_aarch64_with_whirl2mpl.sh @@ -0,0 +1,57 @@ +#!/bin/bash +# Copyright (C) [2020-2021] Futurewei Technologies, Inc. All rights reverved. +# +# Licensed under the Mulan Permissive Software License v2 +# You can use this software according to the terms and conditions of the MulanPSL - 2.0. +# You may obtain a copy of MulanPSL - 2.0 at: +# +# https://opensource.org/licenses/MulanPSL-2.0 +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +# FIT FOR A PARTICULAR PURPOSE. +# See the MulanPSL - 2.0 for more details. +# + +[ -n "$MAPLE_ROOT" ] || { echo MAPLE_ROOT not set. Please source envsetup.sh.; exit 1; } + +CURRDIR=`pwd` +WORKDIR=$CURRDIR/aarch64_use_whirl2mpl + +mkdir -p $WORKDIR +cd $WORKDIR + +echo ======================================================================== > cmd.log +echo ============= Use clangfe/whirl2mpl as C Frontend ======================= >> cmd.log +echo ======================================================================== >> cmd.log +echo cd $WORKDIR >> cmd.log + +if [ $# -eq 0 ]; then + src=printHuawei +else + src=$1 +fi + +cp $CURRDIR/$src.c . + +V=$(cd /usr/lib/gcc-cross/aarch64-linux-gnu/; ls | head -1) +FLAGS="-cc1 -emit-llvm -triple aarch64-linux-gnu -D__clang__ -D__BLOCKS__ -isystem /usr/aarch64-linux-gnu/include -isystem /usr/lib/gcc-cross/aarch64-linux-gnu/$V/include" +echo $MAPLE_ROOT/tools/open64_prebuilt/x86/aarch64/bin/clangfe $FLAGS $src.c >> cmd.log +$MAPLE_ROOT/tools/open64_prebuilt/x86/aarch64/bin/clangfe $FLAGS $src.c > doit.log 2>&1 + +echo $MAPLE_ROOT/tools/open64_prebuilt/x86/aarch64/bin/whirl2mpl -a $src.B >> cmd.log +$MAPLE_ROOT/tools/open64_prebuilt/x86/aarch64/bin/whirl2mpl -a $src.B >> doit.log 2>&1 + +echo $MAPLE_EXECUTE_BIN/maple --run=mplcg --option=\"-O2 -quiet\" $src.mpl >> cmd.log +$MAPLE_EXECUTE_BIN/maple --run=mplcg --option="-O2 -quiet" $src.mpl >> doit.log 2>&1 + +echo /usr/bin/aarch64-linux-gnu-gcc-$V -o $src.out $src.s >> cmd.log +/usr/bin/aarch64-linux-gnu-gcc-$V -o $src.out $src.s + +echo qemu-aarch64 -L /usr/aarch64-linux-gnu/ $src.out >> cmd.log +qemu-aarch64 -L /usr/aarch64-linux-gnu/ $src.out > output.log + +if [ $# -eq 0 ]; then + cat cmd.log + cat output.log +fi diff --git a/test/c_demo/printHuawei.c b/test/c_demo/printHuawei.c new file mode 100644 index 0000000000..f83d4c1fc8 --- /dev/null +++ b/test/c_demo/printHuawei.c @@ -0,0 +1,47 @@ +/* + * Copyright (C) [2020] Futurewei Technologies, Inc. All rights reverved. + * + * Licensed under the Mulan Permissive Software License v2. + * You can use this software according to the terms and conditions of the MulanPSL - 2.0. + * You may obtain a copy of MulanPSL - 2.0 at: + * + * https://opensource.org/licenses/MulanPSL-2.0 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the MulanPSL - 2.0 for more details. + */ + +#include + +int main() { + int width = 142; + char *str = "\ + F efifdfifkehfhfhfgnefb;efifdfifjghffhffgoefb; \ + U efifdfifiigffhfffpefb;efifdfifiigfeiffeqefb; \ + T efifdfifhkgeejeeegpfb;efifdfifhkgfdjdfefqfb; \ + U efifdfifgfafffckdfdfrfb;eudfifgfafgeceafceesefb; \ + R eudfifffcfffbebebfesefb;eudfifffcfffafbfaefsefb; \ + E eudfifefefefaecfaefsefb;efifdfifeqfeaedeaeffrfb; \ + W efifdfifdsekdkffrfb;efifdfifdsejfjfgqfb; \ + E efifdfifcueifihfqfb;efifefgfdfifeifihhofb; \ + I efifescfkfdhhhiqefb;efiffqdfkfdhhhjpefb; \ + efifgodfmfdghgmnefb;efifikffmfdfjfolefb;"; + putchar('\n'); + char c; + int idx = 0; + int loc = 0; + while ((c = str[idx++])) { + char fillChar = (idx & 1) ? 'H' : ' '; + for(char b = 'a'; b <= c; b++) { + if (loc++ == width) { + loc = 0; + fillChar = '\n'; + } + putchar(fillChar); + } + } + putchar('\n'); + return 0; +} diff --git a/tools/setup_tools.sh b/tools/setup_tools.sh index 2220f18fde..87b8b3a9e8 100755 --- a/tools/setup_tools.sh +++ b/tools/setup_tools.sh @@ -156,3 +156,15 @@ if [ "$installQemu" == "true" ]; then sudo dpkg -i ./qemu-user_2.5+dfsg-5ubuntu10.48_amd64.deb || sudo apt install -f echo Installed qemu-aarch64 fi + +if [ ! -f $TOOLS/open64_prebuilt/README.md ]; then + git clone https://gitee.com/open64ark/open64_prebuilt.git +fi +if [ ! -f $TOOLS/open64_prebuilt/x86/riscv64/bin/clangfe ]; then + cd $TOOLS/open64_prebuilt/x86 + git pull + tar zxf open64ark-aarch64.tar.gz + tar zxf open64ark-riscv.tar.gz + mv riscv riscv64 + echo Downloaded open64_prebuilt. +fi -- Gitee From d3273f642f5ae9cbbbaff1340bc91613f1daaea1 Mon Sep 17 00:00:00 2001 From: Wen HU Date: Fri, 19 Feb 2021 15:41:06 -0800 Subject: [PATCH 2/2] quit if error --- test/c_demo/maple_aarch64_with_whirl2mpl.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/c_demo/maple_aarch64_with_whirl2mpl.sh b/test/c_demo/maple_aarch64_with_whirl2mpl.sh index 3c3020c8ef..19ef9620f0 100755 --- a/test/c_demo/maple_aarch64_with_whirl2mpl.sh +++ b/test/c_demo/maple_aarch64_with_whirl2mpl.sh @@ -13,6 +13,8 @@ # See the MulanPSL - 2.0 for more details. # +set -e + [ -n "$MAPLE_ROOT" ] || { echo MAPLE_ROOT not set. Please source envsetup.sh.; exit 1; } CURRDIR=`pwd` -- Gitee