Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wasm-watermarker
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nagayama15
wasm-watermarker
Commits
b241ef19
Commit
b241ef19
authored
Mar 22, 2019
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Complete operand swapping method
parent
ea7361dd
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
8 deletions
+37
-8
kyut.cpp
src/kyut.cpp
+5
-1
circular_bit_stream.hpp
src/kyut/circular_bit_stream.hpp
+5
-1
operand_swapping_watermarker.cpp
src/kyut/pass/operand_swapping_watermarker.cpp
+24
-5
operand_swapping_watermarker.hpp
src/kyut/pass/operand_swapping_watermarker.hpp
+3
-1
No files found.
src/kyut.cpp
View file @
b241ef19
...
...
@@ -18,12 +18,16 @@ int main(int argc, char *argv[]) {
wasm
::
Module
module
;
wasm
::
ModuleReader
{}.
read
(
argv
[
1
],
module
);
kyut
::
pass
::
embedWatermarkOperandSwapping
(
module
);
const
auto
stream
=
kyut
::
CircularBitStream
::
from_string
(
argv
[
2
]);
kyut
::
pass
::
embedWatermarkOperandSwapping
(
module
,
*
stream
);
wasm
::
ModuleWriter
{}.
writeText
(
module
,
argv
[
3
]);
}
catch
(
wasm
::
ParseException
&
e
)
{
fmt
::
print
(
std
::
cerr
,
"parse error
\n
"
);
e
.
dump
(
std
::
cerr
);
return
1
;
}
catch
(
const
std
::
exception
&
e
)
{
fmt
::
print
(
std
::
cerr
,
"error: {}
\n
"
,
e
.
what
());
...
...
src/kyut/circular_bit_stream.hpp
View file @
b241ef19
...
...
@@ -37,12 +37,16 @@ namespace kyut {
return
size_bytes
()
*
8
;
}
[[
nodiscard
]]
std
::
size_t
pos_bits
()
const
noexcept
{
return
pos_bits_
;
}
bool
read_bit
()
noexcept
{
if
(
size_bits
()
==
0
)
{
return
false
;
}
const
auto
value
=
bytes_
[
pos_bits_
>>
3
]
>>
(
pos_bits_
&
0x7
)
;
const
auto
value
=
(
bytes_
[
pos_bits_
>>
3
]
>>
(
pos_bits_
&
0x7
))
&
0x1
;
if
(
++
pos_bits_
>=
size_bits
())
{
pos_bits_
=
0
;
...
...
src/kyut/pass/operand_swapping_watermarker.cpp
View file @
b241ef19
...
...
@@ -2,11 +2,15 @@
#include <pass.h>
#include "../commutativity.hpp"
#include "../comparison.hpp"
namespace
kyut
::
pass
{
class
OperandSwappingWatermarkingVisitor
:
public
wasm
::
OverriddenVisitor
<
OperandSwappingWatermarkingVisitor
,
bool
>
{
public
:
explicit
OperandSwappingWatermarkingVisitor
()
=
default
;
explicit
OperandSwappingWatermarkingVisitor
(
CircularBitStream
&
stream
)
:
stream_
(
stream
)
{}
OperandSwappingWatermarkingVisitor
(
const
OperandSwappingWatermarkingVisitor
&
)
=
delete
;
OperandSwappingWatermarkingVisitor
(
OperandSwappingWatermarkingVisitor
&&
)
=
delete
;
...
...
@@ -217,6 +221,14 @@ namespace kyut::pass {
has_side_effect
=
visit
(
curr
->
left
)
||
has_side_effect
;
has_side_effect
=
visit
(
curr
->
right
)
||
has_side_effect
;
if
(
isCommutative
(
curr
->
op
)
&&
!
has_side_effect
)
{
const
auto
bit
=
stream_
.
read_bit
();
if
(
bit
==
(
*
curr
->
left
<
*
curr
->
right
))
{
swapOperands
(
*
curr
);
}
}
return
has_side_effect
;
}
...
...
@@ -278,11 +290,15 @@ namespace kyut::pass {
bool
visitModule
([[
maybe_unused
]]
wasm
::
Module
*
curr
)
{
WASM_UNREACHABLE
();
}
private
:
CircularBitStream
&
stream_
;
};
class
OperandSwappingWatermarkingPass
:
public
wasm
::
Pass
{
public
:
explicit
OperandSwappingWatermarkingPass
()
=
default
;
explicit
OperandSwappingWatermarkingPass
(
CircularBitStream
&
stream
)
:
stream_
(
stream
)
{}
OperandSwappingWatermarkingPass
(
const
OperandSwappingWatermarkingPass
&
)
=
delete
;
OperandSwappingWatermarkingPass
(
OperandSwappingWatermarkingPass
&&
)
=
delete
;
...
...
@@ -297,17 +313,20 @@ namespace kyut::pass {
}
void
run
([[
maybe_unused
]]
wasm
::
PassRunner
*
runner
,
wasm
::
Module
*
module
)
override
{
OperandSwappingWatermarkingVisitor
visitor
{};
OperandSwappingWatermarkingVisitor
visitor
{
stream_
};
for
(
const
auto
&
func
:
module
->
functions
)
{
visitor
.
visit
(
func
->
body
);
}
}
private
:
CircularBitStream
&
stream_
;
};
void
embedWatermarkOperandSwapping
(
wasm
::
Module
&
module
)
{
void
embedWatermarkOperandSwapping
(
wasm
::
Module
&
module
,
CircularBitStream
&
stream
)
{
wasm
::
PassRunner
runner
{
&
module
};
runner
.
add
<
OperandSwappingWatermarkingPass
>
();
runner
.
add
<
OperandSwappingWatermarkingPass
>
(
std
::
ref
(
stream
)
);
runner
.
run
();
}
}
// namespace kyut::pass
src/kyut/pass/operand_swapping_watermarker.hpp
View file @
b241ef19
...
...
@@ -3,8 +3,10 @@
#include <wasm.h>
#include "../circular_bit_stream.hpp"
namespace
kyut
::
pass
{
void
embedWatermarkOperandSwapping
(
wasm
::
Module
&
module
);
void
embedWatermarkOperandSwapping
(
wasm
::
Module
&
module
,
CircularBitStream
&
stream
);
}
#endif // INCLUDE_kyut_pass_operand_swapping_watermarker_hpp
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment