FileΒΆ
Declare some objects that must be on the file
function = CFunction(
name="examplefun",
return_type=Cuint32,
static=True,
arguments=[
CFunction.Argument(name="first", c_type=Cuint32, doc=Doc("First argument")),
CFunction.Argument(name="second", c_type=Cdouble, default=CLiteral(2), doc=Doc("Second Argument"))
],
doc=Doc("Awesome function", "This function is awesome because it does marvellous things",
ret="returns a lucky number"),
content=CStatements([
CVariable("local_var", Cint8).declare()
])
)
var = CVariable(
c_type=Cint8,
name="i8Mycustomint",
initial_value=CCast(Cint8, CLiteral(12, c_type=Cuint8, literal_format=CLiteral.Format.decimal))
)
Declare User Section Statements. These will create sections in the file where the user can edit the file and the generation of code will not overwrite those changes
user_section = UserSection("first")
user_section_2 = UserSection("second")
list the declarations or sections for the code
declarations = CDeclarations([
var.declare(),
user_section,
function.declare(),
user_section_2
])
and generate to a file
file = File(declarations)
file.generate("generated_code/test_file_output.c")