Skip to content

Commit

Permalink
Added c89 source to repository for old env.
Browse files Browse the repository at this point in the history
  • Loading branch information
ab25cq committed Feb 9, 2018
1 parent 0300a9e commit cd707b4
Show file tree
Hide file tree
Showing 57 changed files with 254,990 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ permission:
# clean
########################################################
clean:
rm -fR clover2 clover2.dSYM cclover2 cclover2.dSYM iclover2 iclover2.dSYM src/*.o config.log config.status *.stackdump autom4te.cache .DS_Store core.* a.out *.oclcl *.bc *.s *.o *.ocl code/*.ocl code/*.oclcl *.clm a.c src/*.dwo *.ll *.so.1.0.0 *.so *.class
rm -fR clover2 clover2.dSYM cclover2 cclover2.dSYM iclover2 iclover2.dSYM src/*.o config.log config.status *.stackdump autom4te.cache .DS_Store core.* a.out *.oclcl *.bc *.s *.o *.ocl code/*.ocl code/*.oclcl *.clm a.c src/*.dwo *.ll *.so.1.0.0 *.so *.class src/config.h moveVarDecls.hi moveVarDecls.o moveVarDecls
(cd examples/; make clean)

distclean: clean
Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -4169,7 +4169,7 @@ fi
CFLAGS="$CFLAGS -Qunused-arguments"
#CFLAGS="$CFLAGS -Qunused-arguments"
#CFLAGS="$CFLAGS -Qunused-arguments -Wunused-variable"
if test $ENABLE_JIT = 1
Expand Down
2 changes: 1 addition & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ fi

AC_SUBST(CXX)

CFLAGS="$CFLAGS -Qunused-arguments"
#CFLAGS="$CFLAGS -Qunused-arguments"
#CFLAGS="$CFLAGS -Qunused-arguments -Wunused-variable"

if test $ENABLE_JIT = 1
Expand Down
1 change: 1 addition & 0 deletions make_arm_el.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
make CC=arm-linux-gnueabi-gcc
20 changes: 20 additions & 0 deletions make_c89_source.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

ghc -o moveVarDecls moveVarDecls.hs

if test -e config.h
then
cp config.h src/
else
./configure
cp config.h src/
fi

cd src

for i in *.c
do
../moveVarDecls $i > ../src-c89/$i
done


cd ..
63 changes: 63 additions & 0 deletions moveVarDecls.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module Main where


import System.Environment(getArgs)
-- import System
import Data.Generics
import Language.C
import Language.C.System.GCC

-- 第一引数のファイルを読み込み標準出力に出力
main = do
(filename:[]) <- getArgs
parseMyFile filename >>= (printMyAST . moveVarDecls)

-- Language.C を使ってソースを parse
parseMyFile :: FilePath -> IO CTranslUnit
parseMyFile input_file =
do parse_result <- parseCFile (newGCC "gcc") Nothing [] input_file -- プリプロセスに使うgcc (cpp?) のパスを設定しよう
case parse_result of
Left parse_err -> error (show parse_err)
Right ast -> return ast

-- 表示
printMyAST :: CTranslUnit -> IO ()
printMyAST ctu = (print . pretty) ctu

-- Data.Generics (scrap your boilerplate) を使った、構文木のトラバース
moveVarDecls :: CTranslUnit -> CTranslUnit
moveVarDecls = everywhere (mkT moveVarDecls_)

-- ブロックの内容を宣言と代入文に分ける.
moveVarDecls_ :: [CBlockItem] -> [CBlockItem]
moveVarDecls_ bs = concat decls++concat stmts -- 宣言の後にブロックが来る
where
(decls,stmts) = unzip (map splitVarDecls bs)

-- 1つの変数宣言を宣言と代入文に分割する
splitVarDecls :: CBlockItem -> ([CBlockItem],[CBlockItem])
splitVarDecls (CBlockDecl (CDecl sp assign ninfo)) = ([mkDecl sp assign ninfo], mkStmts assign ninfo)
splitVarDecls x = ([],[x])

-- 宣言文から代入文を除去する.
-- sp 型、記憶子、修飾子のリスト
-- assign 変数名および代入文
-- ninfo ノード情報
mkDecl :: [CDeclSpec] -> [(Maybe CDeclr, Maybe CInit, Maybe CExpr)] -> NodeInfo -> CBlockItem
mkDecl sp assign ninfo = CBlockDecl (CDecl sp (map mkAssign assign) ninfo)
where
-- declr 変数名と、constやポインタ等の修飾子 (int *x; における *xの部分)
-- init 代入文の右辺
-- expr 構造体のフィールド宣言におけるビット長(ここではNothing)
mkAssign (a@(_, Nothing, _)) = a
mkAssign (declr, Just init, expr) = (declr, Nothing, expr) -- 代入文を除去

-- 宣言文から代入文を抜き出す.
-- assign 変数名および代入文
-- ninfo ノード情報
mkStmts :: [(Maybe CDeclr, Maybe CInit, Maybe CExpr)] -> NodeInfo -> [CBlockItem]
mkStmts assign ninfo = concatMap mkExpr assign
where
mkExpr (Just (CDeclr (Just name) _ _ _ v_ninfo), Just (CInitExpr expr i_ninfo), _)
= [CBlockStmt (CExpr (Just (CAssign CAssignOp (CVar name v_ninfo) expr i_ninfo)) ninfo)] -- 代入文を生成
mkExpr _ = []
4,166 changes: 4,166 additions & 0 deletions src-c89/alignment.c

Large diffs are not rendered by default.

4,209 changes: 4,209 additions & 0 deletions src-c89/array.c

Large diffs are not rendered by default.

4,195 changes: 4,195 additions & 0 deletions src-c89/block.c

Large diffs are not rendered by default.

4,173 changes: 4,173 additions & 0 deletions src-c89/bool.c

Large diffs are not rendered by default.

Loading

0 comments on commit cd707b4

Please sign in to comment.