From 0c65be312dabadd3b0f51d1dc8815ac746d015f7 Mon Sep 17 00:00:00 2001 From: Rob Dockins Date: Fri, 17 Sep 2021 11:12:00 -0700 Subject: [PATCH] Add the `volatile` type qualifier to the global variables representing external streams. As we expect these variables to be modifed concurrently or via interrupts, the volatile qualifier is appropriate, and prevents the compiler from performing code motion that might cause unexpected behavior. Ideally, these reads (which occur at the beginning of the step function) should also be protected by a critical section that masks interrupts or takes a mutex. Partially addresses #257 --- copilot-c99/src/Copilot/Compile/C99/CodeGen.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/copilot-c99/src/Copilot/Compile/C99/CodeGen.hs b/copilot-c99/src/Copilot/Compile/C99/CodeGen.hs index 9b9ea8db..7b49cf59 100644 --- a/copilot-c99/src/Copilot/Compile/C99/CodeGen.hs +++ b/copilot-c99/src/Copilot/Compile/C99/CodeGen.hs @@ -31,7 +31,7 @@ genfun name expr ty = C.FunDef cty name [] cvars [C.Return $ Just cexpr] where mkextdecln :: External -> C.Decln mkextdecln (External name _ ty) = decln where decln = C.VarDecln (Just C.Extern) cty name Nothing - cty = transtype ty + cty = C.Volatile (transtype ty) -- | Make a declaration for a copy of an external variable. mkextcpydecln :: External -> C.Decln