Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
clangml-transforms
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
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
memcad
clangml-transforms
Commits
d550841c
Commit
d550841c
authored
5 years ago
by
Thierry Martinez
Browse files
Options
Downloads
Patches
Plain Diff
Statically add coefficients for pointer offsets
parent
5a0f2bab
No related branches found
No related tags found
No related merge requests found
Pipeline
#111200
passed
5 years ago
Stage: snapshot
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
clangml-transforms/for_memcad.ml
+33
-4
33 additions, 4 deletions
clangml-transforms/for_memcad.ml
with
33 additions
and
4 deletions
clangml-transforms/for_memcad.ml
+
33
−
4
View file @
d550841c
...
...
@@ -148,6 +148,11 @@ let is_integer_type (t : Clang.Ast.qual_type) =
true
|
_
->
false
let
rec
remove_casts
(
expr
:
Clang
.
Ast
.
expr
)
=
match
expr
with
|
{
desc
=
Cast
{
kind
=
CStyle
;
operand
;
_
};
_
}
->
remove_casts
operand
|
_
->
expr
let
transform
=
object
(
self
)
inherit
[
_
]
Clangml_visitors
.
mapreduce
as
super
inherit
[
_
]
Free_monoid
.
free_monoid
as
monoid
...
...
@@ -266,8 +271,30 @@ let transform = object (self)
let
lhs
,
lhs_value
=
self
#
visit_expr
lhs_env
lhs
in
let
kind
,
kind_value
=
self
#
visit_binary_operator_kind
env
kind
in
let
rhs
,
rhs_value
=
self
#
visit_expr
rhs_env
rhs
in
BinaryOperator
{
lhs
;
kind
;
rhs
}
,
monoid
#
plus
lhs_value
(
monoid
#
plus
kind_value
rhs_value
)
let
delayed_stmts
=
monoid
#
plus
lhs_value
(
monoid
#
plus
kind_value
rhs_value
)
in
match
match
kind
with
|
Add
|
Sub
->
begin
match
Clang
.
Type
.
of_node
lhs
with
|
{
desc
=
Pointer
pointee_type
;
_
}
->
Some
pointee_type
|
_
->
None
end
|
_
->
None
with
|
None
->
BinaryOperator
{
lhs
;
kind
;
rhs
}
,
delayed_stmts
|
Some
pointee_type
->
let
size
=
Clang
.
Type
.
get_size_of
pointee_type
in
let
lhs
=
remove_casts
lhs
in
let
rhs
=
if
size
=
1
then
rhs
else
{
rhs
with
desc
=
BinaryOperator
{
lhs
=
integer_literal
size
;
kind
=
Mul
;
rhs
}}
in
BinaryOperator
{
lhs
;
kind
;
rhs
}
,
delayed_stmts
method
!
visit_UnaryOperator
env
kind
operand
=
let
operand_env
=
...
...
@@ -344,8 +371,10 @@ let transform = object (self)
field
=
FieldName
{
desc
=
{
name
=
IdentifierName
field_name
;
_
};
_
}};
_
};
_
};
_
}}
when
is_integer_type
integer_type
->
integer_literal
(
Clang
.
type_get_offset_of
named_type
.
cxtype
field_name
)
,
monoid
#
zero
let
offset
=
Clang
.
type_get_offset_of
named_type
.
cxtype
field_name
in
if
offset
mod
8
<>
0
then
failwith
"Bitfields are not supported!"
;
integer_literal
(
offset
/
8
)
,
monoid
#
zero
|
Cast
{
operand
;
_
}
->
self
#
visit_expr
env
{
expr
with
desc
=
operand
.
desc
}
(* liftConditionals *)
...
...
This diff is collapsed.
Click to expand it.
Thierry Martinez
@tmartine
mentioned in commit
20a90d1f
·
5 years ago
mentioned in commit
20a90d1f
mentioned in commit 20a90d1f040f49daef4be0bbb40e0c2c33174a11
Toggle commit list
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