Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
inox
Commits
7c5a623c
Commit
7c5a623c
authored
9 years ago
by
Marco Antognini
Committed by
Etienne Kneuss
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Use VLA only when really needed
parent
7c5038f0
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/scala/leon/genc/CPrinter.scala
+12
-6
12 additions, 6 deletions
src/main/scala/leon/genc/CPrinter.scala
with
12 additions
and
6 deletions
src/main/scala/leon/genc/CPrinter.scala
+
12
−
6
View file @
7c5a623c
...
@@ -74,6 +74,14 @@ class CPrinter(val sb: StringBuffer = new StringBuffer) {
...
@@ -74,6 +74,14 @@ class CPrinter(val sb: StringBuffer = new StringBuffer) {
case
Var
(
id
,
_
)
=>
c
"$id"
case
Var
(
id
,
_
)
=>
c
"$id"
case
DeclVar
(
Var
(
id
,
typ
))
=>
c
"$typ $id;"
case
DeclVar
(
Var
(
id
,
typ
))
=>
c
"$typ $id;"
// If the length is a literal we don't need VLA
case
DeclInitVar
(
Var
(
id
,
typ
),
ai
@
ArrayInit
(
IntLiteral
(
length
),
_
,
_
))
=>
val
buffer
=
FreshId
(
"buffer"
)
val
values
=
for
(
i
<-
0
until
length
)
yield
ai
.
defaultValue
c
"""|${ai.valueType} $buffer[${ai.length}] = { $values };
|$typ $id = { .length = ${ai.length}, .data = $buffer };
|"""
// TODO depending on the type of array (e.g. `char`) or the value (e.g. `0`), we could use `memset`.
// TODO depending on the type of array (e.g. `char`) or the value (e.g. `0`), we could use `memset`.
case
DeclInitVar
(
Var
(
id
,
typ
),
ai
:
ArrayInit
)
=>
// Note that `typ` is a struct here
case
DeclInitVar
(
Var
(
id
,
typ
),
ai
:
ArrayInit
)
=>
// Note that `typ` is a struct here
val
buffer
=
FreshId
(
"vla_buffer"
)
val
buffer
=
FreshId
(
"vla_buffer"
)
...
@@ -86,12 +94,10 @@ class CPrinter(val sb: StringBuffer = new StringBuffer) {
...
@@ -86,12 +94,10 @@ class CPrinter(val sb: StringBuffer = new StringBuffer) {
|"""
|"""
case
DeclInitVar
(
Var
(
id
,
typ
),
ai
:
ArrayInitWithValues
)
=>
// Note that `typ` is a struct here
case
DeclInitVar
(
Var
(
id
,
typ
),
ai
:
ArrayInitWithValues
)
=>
// Note that `typ` is a struct here
val
buffer
=
FreshId
(
"vla_buffer"
)
val
buffer
=
FreshId
(
"buffer"
)
c
"$NewLine${ai.valueType} $buffer[${ai.length}];$NewLine"
c
"""|${ai.valueType} $buffer[${ai.length}] = { ${ai.values} };
for
((
v
,
i
)
<-
ai
.
values
.
zipWithIndex
)
{
|$typ $id = { .length = ${ai.length}, .data = $buffer };
c
"$buffer[$i] = $v;$NewLine"
|"""
}
c
"$typ $id = { .length = ${ai.length}, .data = $buffer };$NewLine"
case
DeclInitVar
(
Var
(
id
,
typ
),
value
)
=>
case
DeclInitVar
(
Var
(
id
,
typ
),
value
)
=>
c
"$typ $id = $value;"
c
"$typ $id = $value;"
...
...
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