diff --git a/test/c_demo/README.md b/test/c_demo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..5560fb8e65b761993f3f5d848c0fb1f217ecee6a --- /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 0000000000000000000000000000000000000000..19ef9620f05c094572d20f191270667125f11acb --- /dev/null +++ b/test/c_demo/maple_aarch64_with_whirl2mpl.sh @@ -0,0 +1,59 @@ +#!/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. +# + +set -e + +[ -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 0000000000000000000000000000000000000000..f83d4c1fc8f62a8b453d5abb1eccafea9aadfa78 --- /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 2220f18fdedcdb2ce1390f3f792fad8a3fd7b1b6..87b8b3a9e8e1270875a0d17c99d8714083fe1dbf 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