├── .gitignore
├── .vscode
└── settings.json
├── LICENSE
├── Makefile
├── README.md
├── doc
└── Doxyfile
├── lib
├── uthash.h
└── utlist.h
├── src
├── api
│ ├── elementnode.h
│ ├── elements.c
│ └── esstee.c
├── elements
│ ├── array.c
│ ├── array.h
│ ├── block_header.c
│ ├── block_header.h
│ ├── builtins.c
│ ├── builtins.h
│ ├── date_time.c
│ ├── date_time.h
│ ├── derived.c
│ ├── derived.h
│ ├── directmemory.c
│ ├── directmemory.h
│ ├── enums.c
│ ├── enums.h
│ ├── iarray_index.h
│ ├── idirectmemory.h
│ ├── ifunction.h
│ ├── ifunction_block.h
│ ├── iinvoke_parameter.h
│ ├── integers.c
│ ├── integers.h
│ ├── invoke_parameters.c
│ ├── invoke_parameters.h
│ ├── iprogram.h
│ ├── iqualified_identifier.h
│ ├── iqueries.h
│ ├── itype.h
│ ├── ivalue.h
│ ├── ivariable.h
│ ├── qualified_identifier.c
│ ├── qualified_identifier.h
│ ├── queries.c
│ ├── queries.h
│ ├── reals.c
│ ├── reals.h
│ ├── strings.c
│ ├── strings.h
│ ├── struct.c
│ ├── struct.h
│ ├── subrange.c
│ ├── subrange.h
│ ├── subrange_case.c
│ ├── subrange_case.h
│ ├── types.c
│ ├── types.h
│ ├── user_function_blocks.c
│ ├── user_function_blocks.h
│ ├── user_functions.c
│ ├── user_functions.h
│ ├── user_programs.c
│ ├── user_programs.h
│ ├── values.c
│ ├── values.h
│ ├── variable.c
│ └── variable.h
├── esstee
│ ├── elements.h
│ ├── esstee.h
│ ├── flags.h
│ ├── issues.h
│ └── locations.h
├── expressions
│ ├── binary_expressions.c
│ ├── binary_expressions.h
│ ├── direct_address_term.c
│ ├── direct_address_term.h
│ ├── function_invocation.c
│ ├── function_invocation.h
│ ├── identifier.c
│ ├── identifier.h
│ ├── iexpression.h
│ ├── inline_expression.c
│ ├── inline_expression.h
│ ├── negative_prefix.c
│ ├── negative_prefix.h
│ ├── qualified_identifier_term.c
│ └── qualified_identifier_term.h
├── linker
│ ├── linker.c
│ └── linker.h
├── parser
│ ├── bison.tab.h
│ ├── bison.y
│ ├── flex.h
│ ├── flex.l
│ ├── parray.c
│ ├── parser.c
│ ├── parser.h
│ ├── pcases.c
│ ├── pconditionals.c
│ ├── pdirectmemory.c
│ ├── penums.c
│ ├── pexpressions.c
│ ├── pheader.c
│ ├── pinvokeparameters.c
│ ├── pliterals.c
│ ├── ppous.c
│ ├── pqualified_identifier.c
│ ├── pquery.c
│ ├── pstatements.c
│ ├── pstruct.c
│ ├── psubrange.c
│ ├── ptypes.c
│ ├── pvalues.c
│ ├── pvariables.c
│ └── scanneroptions.h
├── rt
│ ├── cursor.c
│ ├── cursor.h
│ ├── icursor.h
│ ├── isystime.h
│ ├── systime.c
│ └── systime.h
├── statements
│ ├── case.c
│ ├── case.h
│ ├── conditionals.c
│ ├── conditionals.h
│ ├── empty.c
│ ├── empty.h
│ ├── iinvoke.h
│ ├── invoke_statement.c
│ ├── invoke_statement.h
│ ├── loops.c
│ ├── loops.h
│ ├── pop_call_stack.c
│ ├── pop_call_stack.h
│ ├── qualified_assignment.c
│ ├── qualified_assignment.h
│ ├── simple_assignment.c
│ ├── simple_assignment.h
│ ├── statements.c
│ └── statements.h
├── tests
│ ├── integration
│ │ ├── README.md
│ │ ├── arrays.tests
│ │ ├── builtins.tests
│ │ ├── conditionals.tests
│ │ ├── derived_types.tests
│ │ ├── direct_memory.tests
│ │ ├── enum.tests
│ │ ├── expressions.tests
│ │ ├── function_blocks.tests
│ │ ├── functions.tests
│ │ ├── literals.tests
│ │ ├── loops.tests
│ │ ├── runtests.sh
│ │ └── subrange.tests
│ ├── program_tester
│ │ └── main.c
│ └── programs
│ │ ├── arrays.ST
│ │ ├── builtins
│ │ └── cast.ST
│ │ ├── conditionals.ST
│ │ ├── derived_types
│ │ ├── basic.ST
│ │ └── circularrefs.ST
│ │ ├── directmemory.ST
│ │ ├── enum.ST
│ │ ├── example.ST
│ │ ├── function
│ │ ├── badinput.ST
│ │ ├── badinputname.ST
│ │ ├── badnotin.ST
│ │ ├── badtoomany.ST
│ │ ├── disjointin.ST
│ │ ├── funcparams.ST
│ │ ├── min.ST
│ │ ├── recursion.ST
│ │ └── reset.ST
│ │ ├── function_blocks
│ │ ├── circular_ref.ST
│ │ ├── circular_ref_2.ST
│ │ ├── circular_ref_3.ST
│ │ ├── circular_ref_4.ST
│ │ ├── circular_ref_5.ST
│ │ ├── circular_ref_6.ST
│ │ ├── conditionals.ST
│ │ ├── invoke.ST
│ │ ├── loops.ST
│ │ ├── noninput.ST
│ │ ├── qualified_assignment.ST
│ │ ├── simple.ST
│ │ ├── simple_assignment.ST
│ │ ├── toomany.ST
│ │ └── undefined.ST
│ │ ├── literals.ST
│ │ ├── loops
│ │ ├── for.ST
│ │ ├── forexit.ST
│ │ ├── forrange.ST
│ │ ├── repeat.ST
│ │ ├── repeatnotbool.ST
│ │ ├── while.ST
│ │ └── whilenotbool.ST
│ │ └── subrange
│ │ ├── badrange.ST
│ │ └── basic.ST
└── util
│ ├── bitflag.h
│ ├── config.c
│ ├── config.h
│ ├── iconfig.h
│ ├── iissues.h
│ ├── inamed_ref_pool.h
│ ├── issue_context.c
│ ├── issue_context.h
│ ├── macros.h
│ ├── named_ref_pool.c
│ └── named_ref_pool.h
└── utils
├── countlines.sh
├── todos-3.7.2016
├── todos-5.1.2016
└── todos.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | *.o
2 | *~
3 | *.h.gch
4 | src/tests/temp
5 | src/testground
6 | bison.output
7 | build
8 | trash
9 | src/tests/integration/error.output
10 | src/tests/integration/test.gdb.commands
11 | .cproject
12 | .emacs.desktop
13 | .emacs.desktop.lock
14 | .settings
15 | .project
16 | docker
17 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "C_Cpp.clang_format_fallbackStyle": "Google",
3 | "C_Cpp.clang_format_style": "Chromium"
4 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # esstee
2 |
3 | esstee is an interpreter written in C (GNU C99), currently under work, for the
4 | Structured Text (ST) programming language. Structured Text is one of the five
5 | languages defined in the IEC-61131-3 standard, and used a lot in the automation
6 | industry.
7 |
8 | The aim of esstee is to provide a, "free as in freedom", platform for building
9 | better testing and debug tools for ST applications.
10 |
11 | esstee is licensed under GPLv3. Besides Bison and Flex, esstee has no external
12 | dependencies besides the header libraries included in the source. Compiling has
13 | so far only been tested under Debian, but should work without problems in any
14 | Linux distro.
15 |
16 | ## Quick Start
17 |
18 | The first milestone of esstee is to provide a library that allows ST syntax to
19 | be parsed into a representation which can be stepped/run. The public interface
20 | to the library is defined in `src/esstee/esstee.h`.
21 |
22 | Currently, the parsing step of the library is complete (Flex and Bison grammar).
23 | In addition there is support for types (elementary, derived and complex), all
24 | statements and expressions, however it is not yet properly tested (automatic
25 | integration tests not ready), and should be considered as **under work**.
26 |
27 | A simple test program using the library interface (and building all the current
28 | code) can be built by;
29 |
30 | ```
31 | make build/program-tester
32 | ```
33 |
34 | The program parses ST syntax from a file, then executes possible "pre" queries
35 | on the runnable representation, runs N cycles and finally executes possible
36 | "post" queries. A query is either a variable reference or an assignment. The
37 | program takes the following options:
38 |
39 | - **file** the file to parse
40 | - **program** the `PROGRAM` in the file that is to be run (a file may contain multiple programs)
41 | - **pre-run-queries** the queries to run right after parsing
42 | - **run-cycles** number of cycles to run (default 1)
43 | - **post-run-queries** the queries to run after the cycles have been run
44 |
45 | In pre and post queries, access the program variables by prefixing with `[name-of-program]`.
46 |
47 | An example:
48 |
49 | ```
50 | ./build/program-tester --file="src/tests/programs/example.ST" --program="testprgm" --pre-run-queries="[testprgm].a:=10*5+1" --post-run-queries="[testprgm].a"
51 |
52 | ```
53 |
--------------------------------------------------------------------------------
/src/api/elementnode.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2016 Kristian Nordman
3 |
4 | This file is part of esstee.
5 |
6 | esstee is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | esstee is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with esstee. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | #include
27 |
28 | struct element_node_context_t {
29 | struct issues_iface_t *issues;
30 | const struct config_iface_t *config;
31 | };
32 |
33 | struct element_node_t {
34 | struct st_element_t element;
35 | const struct element_node_context_t *context;
36 | struct value_iface_t *value;
37 |
38 | struct element_node_t *sub_nodes;
39 |
40 | char *identifier;
41 | UT_hash_handle hh;
42 | };
43 |
44 | struct element_node_t * st_new_element_node(
45 | const char *identifier,
46 | struct value_iface_t *value,
47 | const struct element_node_context_t *context);
48 |
--------------------------------------------------------------------------------
/src/elements/array.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2016 Kristian Nordman
3 |
4 | This file is part of esstee.
5 |
6 | esstee is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | esstee is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with esstee. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 |
29 | struct array_range_iface_t {
30 |
31 | int (*extend)(
32 | struct array_range_iface_t *self,
33 | struct subrange_iface_t *subrange,
34 | const struct config_iface_t *config,
35 | struct issues_iface_t *issues);
36 |
37 | void (*destroy)(
38 | struct array_range_iface_t *self);
39 | };
40 |
41 | struct array_initializer_iface_t {
42 |
43 | int (*extend_by_value)(
44 | struct array_initializer_iface_t *self,
45 | struct value_iface_t *value,
46 | const struct st_location_t *value_location,
47 | const struct config_iface_t *config,
48 | struct issues_iface_t *issues);
49 |
50 | int (*extend_by_multiplied_value)(
51 | struct array_initializer_iface_t *self,
52 | struct value_iface_t *multiplier,
53 | struct value_iface_t *value,
54 | const struct st_location_t *location,
55 | const struct config_iface_t *config,
56 | struct issues_iface_t *issues);
57 |
58 | struct value_iface_t * (*value)(
59 | struct array_initializer_iface_t *self);
60 |
61 | void (*destroy)(
62 | struct array_initializer_iface_t *self);
63 | };
64 |
65 | struct array_index_iface_t * st_create_array_index(
66 | const struct config_iface_t *config,
67 | struct issues_iface_t *issues);
68 |
69 | struct array_range_iface_t * st_create_array_range(
70 | const struct config_iface_t *config,
71 | struct issues_iface_t *issues);
72 |
73 | struct array_initializer_iface_t * st_create_array_initializer(
74 | const struct config_iface_t *config,
75 | struct issues_iface_t *issues);
76 |
77 | struct type_iface_t * st_create_array_type(
78 | struct array_range_iface_t *array_range,
79 | char *arrayed_type_identifier,
80 | const struct st_location_t *arrayed_type_identifier_location,
81 | struct value_iface_t *default_value,
82 | const struct st_location_t *default_value_location,
83 | struct named_ref_pool_iface_t *type_refs,
84 | const struct config_iface_t *config,
85 | struct issues_iface_t *issues);
86 |
--------------------------------------------------------------------------------
/src/elements/block_header.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2016 Kristian Nordman
3 |
4 | This file is part of esstee.
5 |
6 | esstee is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | esstee is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with esstee. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 |
23 |
24 | int st_create_header_tables(
25 | struct header_t *header,
26 | struct issues_iface_t *issues)
27 | {
28 | if(!header)
29 | {
30 | return ESSTEE_OK;
31 | }
32 |
33 | int result = ESSTEE_OK;
34 |
35 | /* Make hash table from type list */
36 | int issues_at_type_start = issues->count(issues, ESSTEE_FILTER_ANY_ERROR);
37 | struct type_iface_t *type_table =
38 | st_link_types(header->types, NULL, issues);
39 |
40 | if(issues->count(issues, ESSTEE_FILTER_ANY_ERROR) == issues_at_type_start)
41 | {
42 | header->types = type_table;
43 | }
44 | else
45 | {
46 | result = ESSTEE_ERROR;
47 | }
48 |
49 | /* Make hash table from var list */
50 | int issues_at_var_start = issues->count(issues, ESSTEE_FILTER_ANY_ERROR);
51 | struct variable_iface_t *variable_table
52 | = st_link_variables(header->variables, NULL, issues);
53 |
54 | if(issues->count(issues, ESSTEE_FILTER_ANY_ERROR) == issues_at_var_start)
55 | {
56 | header->variables = variable_table;
57 | }
58 | else
59 | {
60 | result = ESSTEE_ERROR;
61 | }
62 |
63 | return result;
64 | }
65 |
66 | void st_destroy_header(
67 | struct header_t *header)
68 | {
69 | /* TODO: destroy block header */
70 | }
71 |
--------------------------------------------------------------------------------
/src/elements/block_header.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2016 Kristian Nordman
3 |
4 | This file is part of esstee.
5 |
6 | esstee is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | esstee is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with esstee. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 | #include
23 | #include
24 |
25 | struct header_t {
26 | struct type_iface_t *types;
27 | struct variable_iface_t *variables;
28 | };
29 |
30 | int st_create_header_tables(
31 | struct header_t *header,
32 | struct issues_iface_t *issues);
33 |
34 | void st_destroy_header(
35 | struct header_t *header);
36 |
--------------------------------------------------------------------------------
/src/elements/builtins.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2015 Kristian Nordman
3 |
4 | This file is part of esstee.
5 |
6 | esstee is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | esstee is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with esstee. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 | #include
23 | #include
24 |
25 | struct function_iface_t * st_new_builtin_functions(
26 | struct type_iface_t *builtin_types
27 | );
28 |
29 | struct function_block_iface_t * st_new_builtin_function_blocks(
30 | struct type_iface_t *builtin_types
31 | );
32 |
--------------------------------------------------------------------------------
/src/elements/date_time.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2016 Kristian Nordman
3 |
4 | This file is part of esstee.
5 |
6 | esstee is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | esstee is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with esstee. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 | #include
23 |
24 | #include
25 |
26 | struct duration_t {
27 | double d;
28 | double h;
29 | double m;
30 | double s;
31 | double ms;
32 | };
33 |
34 | struct date_t {
35 | uint64_t y;
36 | uint8_t m;
37 | uint8_t d;
38 | };
39 |
40 | struct tod_t {
41 | uint8_t h;
42 | uint8_t m;
43 | uint8_t s;
44 | uint8_t fs;
45 | };
46 |
47 | struct date_tod_t {
48 | struct date_t date;
49 | struct tod_t tod;
50 | };
51 |
52 | struct type_iface_t * st_new_elementary_date_time_types();
53 |
54 | struct value_iface_t * st_new_typeless_duration_value(
55 | double days,
56 | double hours,
57 | double minutes,
58 | double seconds,
59 | double milliseconds,
60 | st_bitflag_t value_class,
61 | const struct config_iface_t *config,
62 | struct issues_iface_t *issues);
63 |
64 | struct value_iface_t * st_new_typeless_date_value(
65 | uint64_t year,
66 | uint8_t month,
67 | uint8_t day,
68 | st_bitflag_t value_class,
69 | const struct config_iface_t *config,
70 | struct issues_iface_t *issues);
71 |
72 | struct value_iface_t * st_new_typeless_tod_value(
73 | uint8_t hour,
74 | uint8_t minute,
75 | uint8_t second,
76 | uint8_t partial_second,
77 | st_bitflag_t value_class,
78 | const struct config_iface_t *config,
79 | struct issues_iface_t *issues);
80 |
81 | struct value_iface_t * st_new_typeless_date_tod_value(
82 | uint64_t year,
83 | uint8_t month,
84 | uint8_t day,
85 | uint8_t hour,
86 | uint8_t minute,
87 | uint8_t second,
88 | uint8_t partial_second,
89 | st_bitflag_t value_class,
90 | const struct config_iface_t *config,
91 | struct issues_iface_t *issues);
92 |
93 |
--------------------------------------------------------------------------------
/src/elements/derived.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2015 Kristian Nordman
3 |
4 | This file is part of esstee.
5 |
6 | esstee is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | esstee is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with esstee. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 | #include
23 | #include
24 |
25 | struct type_iface_t * st_create_derived_type(
26 | char *type_name,
27 | struct type_iface_t *parent_type,
28 | const struct st_location_t *location,
29 | struct value_iface_t *default_value,
30 | const struct st_location_t *default_value_location,
31 | struct named_ref_pool_iface_t *type_refs,
32 | const struct config_iface_t *config,
33 | struct issues_iface_t *issues);
34 |
35 | struct type_iface_t * st_create_derived_type_by_name(
36 | char *type_name,
37 | const struct st_location_t *location,
38 | char *parent_type_name,
39 | const struct st_location_t *parent_type_name_location,
40 | struct value_iface_t *default_value,
41 | const struct st_location_t *default_value_location,
42 | struct named_ref_pool_iface_t *type_refs,
43 | const struct config_iface_t *config,
44 | struct issues_iface_t *issues);
45 |
--------------------------------------------------------------------------------
/src/elements/directmemory.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2015 Kristian Nordman
3 |
4 | This file is part of esstee.
5 |
6 | esstee is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | esstee is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with esstee. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 |
23 | #include
24 |
25 | struct direct_memory_t {
26 | struct dmem_iface_t dmem;
27 | uint8_t *storage;
28 | size_t size;
29 | };
30 |
31 | static uint8_t * direct_memory_offset(
32 | struct dmem_iface_t *self,
33 | const struct direct_address_t *address,
34 | const struct config_iface_t *config,
35 | struct issues_iface_t *issues)
36 | {
37 | struct direct_memory_t *dm =
38 | CONTAINER_OF(self, struct direct_memory_t, dmem);
39 |
40 | if(address->byte_offset >= dm->size)
41 | {
42 | issues->new_issue(issues,
43 | "byte offset '%lu' fall outside the direct memory area of '%lu' bytes",
44 | ESSTEE_CONTEXT_ERROR,
45 | address->byte_offset,
46 | dm->size);
47 | return NULL;
48 | }
49 |
50 | size_t extra_byte_offset = address->bit_offset / 8;
51 | if(address->byte_offset + extra_byte_offset >= dm->size)
52 | {
53 | issues->new_issue(issues,
54 | "bit offset '%lu' makes the byte offset fall outside the direct memory area of '%lu' bytes",
55 | ESSTEE_CONTEXT_ERROR,
56 | address->bit_offset,
57 | dm->size);
58 | return NULL;
59 | }
60 |
61 | size_t offset_last_byte = address->byte_offset
62 | + extra_byte_offset
63 | + address->field_size_bits / 8;
64 |
65 | if(offset_last_byte > dm->size)
66 | {
67 | issues->new_issue(issues,
68 | "field of size '%lu' at offset '%lu' would extend outside the direct memory area of '%lu' bytes",
69 | ESSTEE_CONTEXT_ERROR,
70 | address->field_size_bits,
71 | address->byte_offset,
72 | dm->size);
73 | return NULL;
74 | }
75 |
76 | return dm->storage + address->byte_offset + extra_byte_offset;
77 | }
78 |
79 | static int direct_memory_reset(
80 | struct dmem_iface_t *self)
81 | {
82 | return ESSTEE_ERROR;
83 | }
84 |
85 | static void direct_memory_destroy(
86 | struct dmem_iface_t *self)
87 | {
88 | /* TODO: direct memory destructor */
89 | }
90 |
91 | struct dmem_iface_t * st_new_direct_memory(
92 | size_t direct_memory_bytes)
93 | {
94 | struct direct_memory_t *dm = NULL;
95 | uint8_t *storage = NULL;
96 |
97 | ALLOC_OR_JUMP(
98 | dm,
99 | struct direct_memory_t,
100 | error_free_resources);
101 |
102 | ALLOC_ARRAY_OR_JUMP(
103 | storage,
104 | uint8_t,
105 | direct_memory_bytes,
106 | error_free_resources);
107 |
108 | dm->storage = storage;
109 | dm->size = direct_memory_bytes;
110 | memset(dm->storage, 0, dm->size);
111 |
112 | dm->dmem.offset = direct_memory_offset;
113 | dm->dmem.reset = direct_memory_reset;
114 | dm->dmem.destroy = direct_memory_destroy;
115 |
116 | return &(dm->dmem);
117 |
118 | error_free_resources:
119 | free(dm);
120 | free(storage);
121 | return NULL;
122 | }
123 |
--------------------------------------------------------------------------------
/src/elements/directmemory.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2015 Kristian Nordman
3 |
4 | This file is part of esstee.
5 |
6 | esstee is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | esstee is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with esstee. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 | #include
23 | #include
24 |
25 | struct dmem_iface_t * st_new_direct_memory(
26 | size_t direct_memory_bytes);
27 |
28 |
--------------------------------------------------------------------------------
/src/elements/enums.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2016 Kristian Nordman
3 |
4 | This file is part of esstee.
5 |
6 | esstee is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | esstee is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with esstee. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 | #include
23 |
24 | struct enum_item_t {
25 | const char *identifier;
26 | const struct st_location_t *location;
27 | };
28 |
29 | struct enum_group_iface_t {
30 |
31 | int (*extend)(
32 | struct enum_group_iface_t *self,
33 | char *identifier,
34 | const struct st_location_t *location,
35 | const struct config_iface_t *config,
36 | struct issues_iface_t *issues);
37 |
38 | void (*destroy)(
39 | struct enum_group_iface_t *self);
40 | };
41 |
42 | struct enum_group_iface_t * st_create_enum_group(
43 | const struct config_iface_t *config,
44 | struct issues_iface_t *issues);
45 |
46 | struct type_iface_t * st_create_enum_type(
47 | struct enum_group_iface_t *group,
48 | const char *default_item,
49 | const struct st_location_t *default_item_location,
50 | const struct config_iface_t *config,
51 | struct issues_iface_t *issues);
52 |
53 | struct value_iface_t * st_create_enum_value(
54 | char *identifier,
55 | const struct st_location_t *location,
56 | const struct config_iface_t *config,
57 | struct issues_iface_t *issues);
58 |
--------------------------------------------------------------------------------
/src/elements/iarray_index.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2016 Kristian Nordman
3 |
4 | This file is part of esstee.
5 |
6 | esstee is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | esstee is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with esstee. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 |
23 | #include
24 | #include
25 | #include