-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added c89 source to repository for old env.
- Loading branch information
ab25cq
committed
Feb 9, 2018
1 parent
0300a9e
commit cd707b4
Showing
57 changed files
with
254,990 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
make CC=arm-linux-gnueabi-gcc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 .. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 _ = [] |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.