summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Language/C.hs15
-rw-r--r--Language/C/Print.hs10
-rw-r--r--SC/Afun.hs3
-rw-r--r--SC/Exp.hs2
-rw-r--r--test.c60
5 files changed, 37 insertions, 53 deletions
diff --git a/Language/C.hs b/Language/C.hs
index 6a3256f..9a65115 100644
--- a/Language/C.hs
+++ b/Language/C.hs
@@ -5,10 +5,17 @@ data Program = Program [FunDef]
deriving (Show)
data FunDef
- = FunDef Type Name [(Type, Name)] StExpr
- | ProcDef Name [(Type, Name)] [Stmt]
+ = FunDef FunAttrs Type Name [(Type, Name)] StExpr
+ | ProcDef FunAttrs Name [(Type, Name)] [Stmt]
deriving (Show, Eq)
+data FunAttrs = FunAttrs
+ { faStatic :: Bool }
+ deriving (Show, Eq)
+
+defAttrs :: FunAttrs
+defAttrs = FunAttrs { faStatic = False }
+
-- | Some C types.
data Type
= TInt Bits
@@ -53,5 +60,5 @@ data Expr
fundefName :: FunDef -> Name
-fundefName (FunDef _ n _ _) = n
-fundefName (ProcDef n _ _) = n
+fundefName (FunDef _ _ n _ _) = n
+fundefName (ProcDef _ n _ _) = n
diff --git a/Language/C/Print.hs b/Language/C/Print.hs
index cc511b2..5852601 100644
--- a/Language/C/Print.hs
+++ b/Language/C/Print.hs
@@ -14,15 +14,17 @@ printProgram :: Program -> PrintS
printProgram (Program defs) = intercalates "\n" (map printFunDef defs)
printFunDef :: FunDef -> PrintS
-printFunDef (FunDef rt n as (StExpr ss rete)) =
- printType rt % printString " " % printName n
+printFunDef (FunDef attrs rt n as (StExpr ss rete)) =
+ printString (if faStatic attrs then "static " else "")
+ % printType rt % printString " " % printName n
% printString "("
% intercalates ", " [printType t % printString " " % printName an | (t, an) <- as]
% printString ") {\n "
% addIndent 2 (intercalates "\n" (map printStmt ss))
% printString "\n return (" % printExpr rete % printString ");\n}\n"
-printFunDef (ProcDef n as ss) =
- printString "void " % printName n
+printFunDef (ProcDef attrs n as ss) =
+ printString (if faStatic attrs then "static " else "")
+ % printString "void " % printName n
% printString "("
% intercalates ", " [printType t % printString " " % printName an | (t, an) <- as]
% printString ") " % printBlock ss % printString "\n"
diff --git a/SC/Afun.hs b/SC/Afun.hs
index 3379cc6..2f1346f 100644
--- a/SC/Afun.hs
+++ b/SC/Afun.hs
@@ -87,7 +87,8 @@ compileAfun1 procname (A.Alam lhs (A.Abody acc)) = do
outnames <- genAVarsTup (A.arraysR acc)
(auxdefs, stmts) <- compileCommands <$> compileAcc' aenv destnames acc
return (auxdefs
- ,C.ProcDef procname
+ ,C.ProcDef C.defAttrs
+ procname
(map (\case Left (TypedName t n) -> (t, n)
Right (TypedAName t n) -> (t, n))
(tupanamesList' argnames)
diff --git a/SC/Exp.hs b/SC/Exp.hs
index 5c0bc72..ef18a7f 100644
--- a/SC/Exp.hs
+++ b/SC/Exp.hs
@@ -54,7 +54,7 @@ compileFun aenv (A.Lam lhs (A.Body body)) = do
++ map (\(TypedName t n) -> (t, n)) (itupList argnames)
++ map (\(TypedName t n) -> (t, n)) (itupList outnames)
return $ CompiledFun
- (C.ProcDef funname arguments (sts1 ++ sts2))
+ (C.ProcDef C.defAttrs { C.faStatic = True }funname arguments (sts1 ++ sts2))
(\argexprs destnames ->
map (C.EVar . snd) arrayarguments
++ itupList argexprs
diff --git a/test.c b/test.c
index 24b7b3d..afd0685 100644
--- a/test.c
+++ b/test.c
@@ -16,47 +16,21 @@
#include <stdint.h>
#include <inttypes.h>
-void expfun_13(int64_t* x14, int64_t* x15) {
- int64_t x16;
- int64_t x17;
- x16 = (2LL);
- x17 = (3LL);
- x14[(0)] = x16;
- x15[(0)] = x17;
+static void expfun_13(int64_t* x14, int64_t* x15) {
+ x14[(0)] = (2LL);
+ x15[(0)] = (3LL);
}
-void expfun_18(int64_t n1, int64_t n2, int64_t* a3, int64_t n4, int64_t* a5, int64_t* a6, int64_t x19, int64_t x20, int64_t* x21) {
- int64_t x35;
- int64_t x36;
- int64_t x27;
- int64_t x28;
+static void expfun_16(int64_t n1, int64_t n2, int64_t* a3, int64_t n4, int64_t* a5, int64_t* a6, int64_t x17, int64_t x18, int64_t* x19) {
+ int64_t i20;
+ i20 = ((x17) * (n2)) + (x18);
+ int64_t x21;
int64_t x22;
- int64_t x23;
- x22 = x19;
- x23 = x20;
- x27 = (x22) * (x23);
- int64_t i24;
- int64_t x25;
- int64_t x26;
- x25 = x19;
- x26 = x20;
- i24 = ((x25) * (n2)) + (x26);
- x28 = a3[i24];
- x35 = (x27) + (x28);
- int64_t x29;
- int64_t x30;
- int64_t i31;
- int64_t x32;
- x32 = x19;
- i31 = x32;
- x29 = a5[i31];
- x30 = a6[i31];
- int64_t x33;
- int64_t x34;
- x33 = x29;
- x34 = x30;
- x36 = (x33) * (x34);
- x21[(0)] = (x35) + (x36);
+ int64_t i23;
+ i23 = x17;
+ x21 = a5[i23];
+ x22 = a6[i23];
+ x19[(0)] = (((x17) * (x18)) + (a3[i20])) + ((x21) * (x22));
}
void kaas(int64_t n1, int64_t n2, int64_t* a3, int64_t n4, int64_t* a5, int64_t* a6, int64_t* n10, int64_t* n11, int64_t** a12) {
@@ -64,11 +38,11 @@ void kaas(int64_t n1, int64_t n2, int64_t* a3, int64_t n4, int64_t* a5, int64_t*
int64_t n8;
expfun_13(&(n7), &(n8));
int64_t* a9 = malloc(((n7) * (n8)) * ((sizeof (int64_t))));
- for (int64_t n38 = (0); n38 < (n7); n38++) {
- for (int64_t n39 = (0); n39 < (n8); n39++) {
- int64_t x37;
- expfun_18(n1, n2, a3, n4, a5, a6, n38, n39, &(x37));
- a9[((n38) * (n8)) + (n39)] = x37;
+ for (int64_t n25 = (0); n25 < (n7); n25++) {
+ for (int64_t n26 = (0); n26 < (n8); n26++) {
+ int64_t x24;
+ expfun_16(n1, n2, a3, n4, a5, a6, n25, n26, &(x24));
+ a9[((n25) * (n8)) + (n26)] = x24;
}
}
n10[(0)] = n7;