Safe Haskell | None |
---|
C code generator
- type C_Comment = String
- c_comment :: String -> C_Comment
- type C_Type = String
- c_typerep_ctype :: TypeRep -> C_Type
- type C_QName = (String, String, String)
- c_init_atom :: Show a => C_QName -> a -> String
- c_init_vec :: (Eq a, Show a) => C_QName -> [a] -> [String]
- c_init_var :: (Eq n, Show n) => C_QName -> Either n [n] -> [String]
- c_array_qual :: Maybe Int -> String -> Bool -> String
- type C_Call = (Maybe String, String, [(Var_Ty, Id)])
- c_call :: C_Call -> String
- data Var_Ty
- var_ty_char :: Var_Ty -> Char
- type Var = (Var_Ty, TypeRep, Id, Maybe (Either Float [Float]))
- var_nm :: Var -> String
- is_stateful :: Var -> Bool
- is_stateful_atom :: Var -> Bool
- k_var :: Id -> Var_Ty -> K -> Var
- buffer_var :: Id -> Vec Float -> Var
- var_init :: String -> String -> Var -> [String]
- var_decl :: Bool -> Var -> String
- gen_var_struct :: String -> (Var -> Bool) -> [Var] -> [String]
- clabel :: (Var_Ty, Id) -> String
- std_clabel :: Id -> String
- m_clabel :: (Var_Ty, Id) -> String
- c_const :: (Id, K) -> [String]
- dsp_fun_decl :: [String]
- cmem :: [Var] -> [String]
- cstate :: [Var] -> [String]
- dsp_memreq :: [String]
- dsp_init :: [Var] -> [String]
- type Instructions = ([(Id, K)], [Var], [C_Call])
- dsp_step :: Instructions -> [String]
- code_gen :: Host -> Instructions -> String
- data Host
- host_include :: Host -> String
- host_dsp_fun_decl :: Host -> [String]
- host_compiler_cmd :: (Host, FilePath) -> (String, [String])
- dl_gen :: FilePath -> (Host, FilePath) -> Instructions -> IO ()
- bracket :: (a, a) -> [a] -> [a]
- dx_d :: Num n => [n] -> [n]
C init / call
c_init_atom :: Show a => C_QName -> a -> StringSource
Initialise C_QName
to value.
c_init_atom ("s",".","r") 5 == "s.m = 5;"
c_init_vec :: (Eq a, Show a) => C_QName -> [a] -> [String]Source
Initialise C_QName
to array. Generates loop code for sequences
of equal initial values.
c_init_vec ("s",".","r") [0,1] == ["s.r[0] = 0;" ,"s.r[1] = 1;"]
let r = ["for(int i=0;i < 2;i++) {s.r[i] = 0;}"] in c_init_vec ("s",".","r") [0,0] == r
c_init_var :: (Eq n, Show n) => C_QName -> Either n [n] -> [String]Source
Initialise C_QName
to value or array.
let {qn = ("s","->","r") ;r = ["for(int i=0;i < 2;i++) {s->r[i] = 0;}","s->r[2] = 1;"]} in c_init_var qn (Right [0,0,1]) == r
c_array_qual :: Maybe Int -> String -> Bool -> StringSource
Qualify name if required. The rf flag indicates if array is a reference or an allocation.
c_array_qual (Vec_Port float_t 3) "a" True == "*a" c_array_qual (Vec_Port float_t 3) "a" False == "a[3]"
type C_Call = (Maybe String, String, [(Var_Ty, Id)])Source
C function call. (comment?,function,arguments)
c_call :: C_Call -> StringSource
Construct a function/macro call.
c_call (Nothing,"f",["0","1"]) == "f(0,1);" c_call ("c","f",["0","1"]) == "f(0,1); /* c */"
Variables
is_stateful_atom :: Var -> BoolSource
Rec_Var
are stateful and atoms.
gen_var_struct :: String -> (Var -> Bool) -> [Var] -> [String]Source
Generate a C struct
for Var
, predicate determines if array
variables are refernces or allocations.
Code generators
dsp_fun_decl :: [String]Source
C declarations for DSP functions (memreq,init and step).
cmem :: [Var] -> [String]Source
The structure for all memory stores. In the uniform model this is a notational convenience only. In a partioned model it is functional.
dsp_memreq :: [String]Source
Generate dsp_memreq function.
type Instructions = ([(Id, K)], [Var], [C_Call])Source
List of constants, list of variables, list of c-calls.
dsp_step :: Instructions -> [String]Source
Generate dsp_step
function.
code_gen :: Host -> Instructions -> StringSource
Generate C code for graph.
Host
host_include :: Host -> StringSource
Host specific #include
file.
host_dsp_fun_decl :: Host -> [String]Source
Host specific form of dsp_fun_decl
(extern C
where required).
host_compiler_cmd :: (Host, FilePath) -> (String, [String])Source
Generate compiler command for Host
given include
directory
prefix.
host_compiler_cmd (JACK,"/home/rohan/opt") host_compiler_cmd (SC3,"/home/rohan/opt") host_compiler_cmd (Text,"/home/rohan/opt")
IO
dl_gen :: FilePath -> (Host, FilePath) -> Instructions -> IO ()Source
Generate C code, write file to disk and call the GNU C compiler to build shared library.