-
Notifications
You must be signed in to change notification settings - Fork 5
Syntax: Hostcode
There are several ways to add hostcode to your models.
You can declare a new object as external reference like before with
(internal) references. Use the keyword extern to mark it as extern.
Then use a string
to set the name of the function and an object which
you will use to reference this hostcode snippet. As it is handled as a
call, you can add parameters and they will be recognized by the
dependency analysis.
Additionally, you can annotate your code snippets with the name of the code generator (e.g. C, Java) to tell the code generation which one should be used when. See the example on the right for more details.
While an External Reference is the preferred way to declare a hostcode call, you can call any function without declaring it first. However, due to grammar limitations and platform-dependency this older features is considered deprecated. You should really use external references.
Nevertheless, you can still use this feature by using the extern
keyword directly inside the expression (e.g. r = extern gettimeofday()
)
without declaring the call beforehand.
The dependency analysis will consider parameters.
You can simply place the host code in accent grave (`) quotes. The code is put as it is into the final code. There is no further processing and also no parameter list. You can of course put the parameters inside the host code quotes, but they will be copied as they are.
You can create variables of non-built-in types by using host declarations. The type is given as a string that will be used in code generation.
C Example files
Related Synatx
There are pragmas that allow to include host code snippets, such as includes and imports, in the generated code (#hostcode). As well as ways to include header files or libraries in the simulation process to enable linking and execution of the SCCharts program (#resource). See: Annotations and Pragmas
Due to the introduction of object-orientation in SCCharts, there is also support for host classes and structs. See: Object Orientation
scchart hostcode#10 {
output float r
extern @C "rand",
@Java "Math.random" rand
entry do rand(0)
initial state init
do r = rand() go to init
}
scchart hostcode#30 {
entry do `srand();`
initial state init
}
scchart hostcode#40 {
host "int64" number
initial state init
}
KIELER is an open source software project by the RTSYS Group at Kiel University, licensed under the Eclipse Public License or Eclipse Public License 2.0 | KIELER Mailing List
- Basic Syntax
- Annotations and Pragmas
- Dataflow
- Hostcode
- Timed Automata
- Object Orientation
- LEGO Mindstorms
- Developer Eclipse Setup with Oomph
- Semantics Release Process
- Build KIELER without Eclipse
- Automated Tests and Benchmarks
- Simulation Visualization (KViz)
- Legacy .sct Models
- Simulation Visualization (KViz)
- KiCo Tutorial