Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sequencer-2-2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
epics-modules
sequencer-2-2
Commits
7534d6fa
Commit
7534d6fa
authored
14 years ago
by
ben.franksen
Browse files
Options
Downloads
Patches
Plain Diff
finally found the right solution to variable initialization, added array initializers
parent
d7ca66af
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/snc/gen_code.c
+15
-2
15 additions, 2 deletions
src/snc/gen_code.c
src/snc/gen_ss_code.c
+117
-32
117 additions, 32 deletions
src/snc/gen_ss_code.c
src/snc/gen_ss_code.h
+2
-0
2 additions, 0 deletions
src/snc/gen_ss_code.h
src/snc/snl.lem
+9
-1
9 additions, 1 deletion
src/snc/snl.lem
with
143 additions
and
35 deletions
src/snc/gen_code.c
+
15
−
2
View file @
7534d6fa
...
@@ -158,7 +158,13 @@ static void gen_user_var(Program *p)
...
@@ -158,7 +158,13 @@ static void gen_user_var(Program *p)
gen_line_marker
(
vp
->
decl
);
gen_line_marker
(
vp
->
decl
);
if
(
!
opt_reent
)
printf
(
"static"
);
if
(
!
opt_reent
)
printf
(
"static"
);
indent
(
1
);
indent
(
1
);
gen_var_decl
(
vp
);
printf
(
";
\n
"
);
gen_var_decl
(
vp
);
if
(
!
opt_reent
)
{
printf
(
" = "
);
gen_var_init
(
vp
,
0
);
}
printf
(
";
\n
"
);
}
}
}
}
foreach
(
ssp
,
p
->
prog
->
prog_statesets
)
foreach
(
ssp
,
p
->
prog
->
prog_statesets
)
...
@@ -200,10 +206,17 @@ static void gen_user_var(Program *p)
...
@@ -200,10 +206,17 @@ static void gen_user_var(Program *p)
printf
(
"} %s_%s;
\n
"
,
VAR_PREFIX
,
sp
->
value
);
printf
(
"} %s_%s;
\n
"
,
VAR_PREFIX
,
sp
->
value
);
}
}
}
}
indent
(
level
);
printf
(
"} %s_%s;
\n
"
,
VAR_PREFIX
,
ssp
->
value
);
indent
(
level
);
printf
(
"} %s_%s"
,
VAR_PREFIX
,
ssp
->
value
);
if
(
!
opt_reent
)
{
printf
(
" = "
);
gen_ss_user_var_init
(
ssp
,
level
);
}
printf
(
";
\n
"
);
}
}
}
}
if
(
opt_reent
)
printf
(
"};
\n
"
);
if
(
opt_reent
)
printf
(
"};
\n
"
);
printf
(
"
\n
"
);
}
}
/* Generate C code in definition section */
/* Generate C code in definition section */
...
...
This diff is collapsed.
Click to expand it.
src/snc/gen_ss_code.c
+
117
−
32
View file @
7534d6fa
...
@@ -136,7 +136,7 @@ static void gen_prog_func(
...
@@ -136,7 +136,7 @@ static void gen_prog_func(
const
char
*
name
,
const
char
*
name
,
Expr
*
xp
,
Expr
*
xp
,
void
(
*
gen_body
)(
Expr
*
xp
));
void
(
*
gen_body
)(
Expr
*
xp
));
static
void
gen_prog_init_func
(
Expr
*
prog
);
static
void
gen_prog_init_func
(
Expr
*
prog
,
int
opt_reent
);
/*
/*
* Expression context. Certain nodes of the syntax tree are
* Expression context. Certain nodes of the syntax tree are
...
@@ -216,7 +216,7 @@ void gen_ss_code(Program *program)
...
@@ -216,7 +216,7 @@ void gen_ss_code(Program *program)
Expr
*
sp
;
Expr
*
sp
;
/* Generate program init func */
/* Generate program init func */
gen_prog_init_func
(
prog
);
gen_prog_init_func
(
prog
,
program
->
options
.
reent
);
/* Generate program entry func */
/* Generate program entry func */
if
(
prog
->
prog_entry
)
if
(
prog
->
prog_entry
)
...
@@ -291,6 +291,40 @@ static void gen_local_var_decls(Expr *scope, int level)
...
@@ -291,6 +291,40 @@ static void gen_local_var_decls(Expr *scope, int level)
}
}
}
}
static
void
gen_type_default
(
Type
*
type
)
{
uint
n
;
assert
(
type
);
switch
(
type
->
tag
)
{
case
V_STRING
:
printf
(
"
\"\"
"
);
break
;
case
V_ARRAY
:
printf
(
"{"
);
for
(
n
=
0
;
n
<
type
->
val
.
array
.
num_elems
;
n
++
)
{
gen_type_default
(
type
->
val
.
array
.
elem_type
);
if
(
n
+
1
<
type
->
val
.
array
.
num_elems
)
printf
(
","
);
}
printf
(
"}"
);
break
;
default:
printf
(
"0"
);
}
}
void
gen_var_init
(
Var
*
vp
,
int
level
)
{
assert
(
vp
);
if
(
vp
->
init
)
gen_expr
(
C_INIT
,
vp
->
init
,
level
);
else
gen_type_default
(
vp
->
type
);
}
static
void
gen_state_func
(
static
void
gen_state_func
(
const
char
*
ss_name
,
const
char
*
ss_name
,
const
char
*
state_name
,
const
char
*
state_name
,
...
@@ -615,6 +649,16 @@ static void gen_expr(
...
@@ -615,6 +649,16 @@ static void gen_expr(
}
}
printf
(
")"
);
printf
(
")"
);
break
;
break
;
case
E_INIT
:
printf
(
"{"
);
foreach
(
cep
,
ep
->
init_elems
)
{
gen_expr
(
context
,
cep
,
0
);
if
(
cep
->
next
)
printf
(
", "
);
}
printf
(
"}"
);
break
;
case
E_TERNOP
:
case
E_TERNOP
:
gen_expr
(
context
,
ep
->
ternop_cond
,
0
);
gen_expr
(
context
,
ep
->
ternop_cond
,
0
);
printf
(
" ? "
);
printf
(
" ? "
);
...
@@ -945,51 +989,92 @@ static void gen_pv_func(
...
@@ -945,51 +989,92 @@ static void gen_pv_func(
#endif
#endif
}
}
/* Generate initiali
sation code for one element of
the UserVar struct. */
/* Generate initiali
zer for
the UserVar struct
s
. */
static
int
iter
_user_var_init
(
Expr
*
d
p
,
Expr
*
scope
,
void
*
parg
)
void
gen_ss
_user_var_init
(
Expr
*
ss
p
,
int
level
)
{
{
assert
(
dp
);
Var
*
vp
;
assert
(
dp
->
type
==
D_DECL
);
Expr
*
sp
;
Var
*
vp
=
dp
->
extra
.
e_decl
;
assert
(
vp
);
assert
(
ssp
->
type
==
D_SS
);
if
(
vp
->
init
&&
vp
->
decl
)
printf
(
"{
\n
"
);
foreach
(
vp
,
ssp
->
extra
.
e_ss
->
var_list
->
first
)
{
{
if
(
vp
->
type
->
tag
<
V_CHAR
)
indent
(
level
+
1
);
gen_var_init
(
vp
,
level
+
1
);
printf
(
",
\n
"
);
{
}
error_at_expr
(
vp
->
decl
,
foreach
(
sp
,
ssp
->
ss_states
)
"initialisation not allowed for variables of this type"
);
{
}
int
s_empty
;
else
assert
(
sp
->
type
==
D_STATE
);
s_empty
=
!
sp
->
extra
.
e_state
->
var_list
->
first
;
if
(
!
s_empty
)
{
{
gen_line_marker
(
dp
);
indent
(
level
+
1
);
printf
(
"{
\n
"
);
indent
(
1
);
foreach
(
vp
,
sp
->
extra
.
e_state
->
var_list
->
first
)
gen_var_access
(
vp
);
{
printf
(
" = "
);
indent
(
level
+
2
);
gen_var_init
(
vp
,
level
+
2
);
gen_expr
(
C_INIT
,
vp
->
init
,
0
);
printf
(
"%s
\n
"
,
vp
->
next
?
","
:
""
);
printf
(
";
\n
"
);
}
indent
(
level
+
1
);
printf
(
"}%s
\n
"
,
sp
->
next
?
","
:
""
);
}
}
}
}
return
FALSE
;
/* do not descend into children */
indent
(
level
);
printf
(
"}"
);
}
}
/* Generate initiali
sation for variables with global lifetime
. */
/* Generate initiali
zer for the UserVar structs
. */
static
void
gen_user_var_init
(
Expr
*
e
p
,
int
stop_mask
)
static
void
gen_user_var_init
(
Expr
*
p
rog
,
int
level
)
{
{
const
int
type_mask
=
(
1
<<
D_DECL
);
Var
*
vp
;
traverse_expr_tree
(
ep
,
type_mask
,
stop_mask
,
0
,
iter_user_var_init
,
0
);
Expr
*
ssp
;
assert
(
prog
->
type
==
D_PROG
);
printf
(
"{
\n
"
);
/* global variables */
foreach
(
vp
,
prog
->
extra
.
e_prog
->
first
)
{
if
(
vp
->
type
->
tag
>=
V_CHAR
)
{
indent
(
level
+
1
);
gen_var_init
(
vp
,
level
+
1
);
printf
(
",
\n
"
);
}
}
foreach
(
ssp
,
prog
->
prog_statesets
)
{
Expr
*
sp
;
int
ss_empty
=
!
ssp
->
extra
.
e_ss
->
var_list
->
first
;
if
(
ss_empty
)
{
foreach
(
sp
,
ssp
->
ss_states
)
{
if
(
sp
->
extra
.
e_state
->
var_list
->
first
)
{
ss_empty
=
0
;
break
;
}
}
}
if
(
!
ss_empty
)
{
indent
(
level
+
1
);
gen_ss_user_var_init
(
ssp
,
level
+
1
);
printf
(
"%s
\n
"
,
ssp
->
next
?
","
:
""
);
}
}
indent
(
level
);
printf
(
"}"
);
}
}
static
void
gen_prog_init_func
(
Expr
*
prog
)
static
void
gen_prog_init_func
(
Expr
*
prog
,
int
opt_reent
)
{
{
const
int
global_stop_mask
=
~
((
1
<<
D_DECL
)
|
(
1
<<
D_PROG
));
assert
(
prog
->
type
==
D_PROG
);
assert
(
prog
->
type
==
D_PROG
);
printf
(
"
\n
/* Program init func */
\n
"
);
printf
(
"
\n
/* Program init func */
\n
"
);
printf
(
"static void global_prog_init(struct %s *pVar)
\n
{
\n
"
,
VAR_PREFIX
);
printf
(
"static void global_prog_init(struct %s *pVar)
\n
{
\n
"
,
VAR_PREFIX
);
/* initialize global variables */
if
(
opt_reent
)
gen_user_var_init
(
prog
,
global_stop_mask
);
{
indent
(
1
);
printf
(
"*pVar = (struct %s)"
,
VAR_PREFIX
);
gen_user_var_init
(
prog
,
1
);
printf
(
";
\n
"
);
}
printf
(
"}
\n
"
);
printf
(
"}
\n
"
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/snc/gen_ss_code.h
+
2
−
0
View file @
7534d6fa
...
@@ -16,5 +16,7 @@
...
@@ -16,5 +16,7 @@
void
init_gen_ss_code
(
Program
*
program
);
void
init_gen_ss_code
(
Program
*
program
);
void
gen_ss_code
(
Program
*
program
);
void
gen_ss_code
(
Program
*
program
);
void
gen_ss_user_var_init
(
Expr
*
ssp
,
int
level
);
void
gen_var_init
(
Var
*
vp
,
int
level
);
#endif
/*INCLgensscodeh*/
#endif
/*INCLgensscodeh*/
This diff is collapsed.
Click to expand it.
src/snc/snl.lem
+
9
−
1
View file @
7534d6fa
...
@@ -164,7 +164,7 @@ init_declarators(p) ::= init_declarators(xs) COMMA init_declarator(x).
...
@@ -164,7 +164,7 @@ init_declarators(p) ::= init_declarators(xs) COMMA init_declarator(x).
{ p = link_expr(xs, x); }
{ p = link_expr(xs, x); }
init_declarator(p) ::= declarator(x). { p = decl_add_init(x, 0); }
init_declarator(p) ::= declarator(x). { p = decl_add_init(x, 0); }
init_declarator(p) ::= declarator(x) EQUAL expr(i).
init_declarator(p) ::= declarator(x) EQUAL
init_
expr(i).
{ p = decl_add_init(x, i); }
{ p = decl_add_init(x, i); }
declarator(p) ::= ASTERISK declarator(x). { p = decl_prefix_pointer(x); }
declarator(p) ::= ASTERISK declarator(x). { p = decl_prefix_pointer(x); }
...
@@ -176,6 +176,14 @@ direct_declarator(p) ::= LPAREN declarator(x) RPAREN.
...
@@ -176,6 +176,14 @@ direct_declarator(p) ::= LPAREN declarator(x) RPAREN.
direct_declarator(p) ::= direct_declarator(x) subscript(s).
direct_declarator(p) ::= direct_declarator(x) subscript(s).
{ p = decl_postfix_array(x, s.str); }
{ p = decl_postfix_array(x, s.str); }
// Initializer
init_expr(p) ::= LBRACE(t) init_exprs(x) RBRACE.{ p = expr(E_INIT, t, x); }
init_expr(p) ::= expr(x). { p = x; }
init_exprs(p) ::= init_exprs(xs) COMMA init_expr(x). { p = link_expr(xs, x); }
init_exprs(p) ::= init_expr(x). { p = x; }
init_exprs(p) ::= . { p = 0; }
%type type {int}
%type type {int}
type(p) ::= CHAR. { p = V_CHAR; }
type(p) ::= CHAR. { p = V_CHAR; }
type(p) ::= SHORT. { p = V_SHORT; }
type(p) ::= SHORT. { p = V_SHORT; }
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment