Skip to content

Commit 6c5d49e

Browse files
committed
copilot-c99: Remove struct declarations from .c file. Refs #373.
Copilot-generated C99 monitor implementation files import the corresponding generated headers before defining the necessary C structs. Part of those headers contain the declarations of the handlers, which may take structs as arguments. By using such forward declarations, the C compiler is not always able to figure out the size of the arguments to those handler functions, and the code cannot be compiled. This commit removes the struct declarations from the `.c` file, so that we can later move the declarations to an external header file and include them before the external handlers are declared.
1 parent 2f105a7 commit 6c5d49e

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

copilot-c99/src/Copilot/Compile/C99/Compile.hs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,10 @@ compilec cSettings spec = C.TransUnit declns funs
7474
streams = specStreams spec
7575
triggers = specTriggers spec
7676
exts = gatherexts streams triggers
77-
exprs = gatherexprs streams triggers
7877

79-
declns = mkstructdeclns exprs ++ mkexts exts ++ mkglobals streams
78+
declns = mkexts exts ++ mkglobals streams
8079
funs = genfuns streams triggers ++ [mkstep cSettings streams triggers exts]
8180

82-
-- Write struct datatypes
83-
mkstructdeclns :: [UExpr] -> [C.Decln]
84-
mkstructdeclns es = catMaybes $ map mkdecln utypes
85-
where
86-
mkdecln (UType ty) = case ty of
87-
Struct x -> Just $ mkstructdecln ty
88-
_ -> Nothing
89-
90-
utypes = nub $ concatMap (\(UExpr _ e) -> exprtypes e) es
91-
9281
-- Make declarations for copies of external variables.
9382
mkexts :: [External] -> [C.Decln]
9483
mkexts exts = map mkextcpydecln exts

0 commit comments

Comments
 (0)