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
7d57b57f
Verified
Commit
7d57b57f
authored
Oct 03, 2020
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(ordering): implement extractor
parent
6923124d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
3 deletions
+48
-3
Ordering-inl.hpp
lib/kyut/Ordering-inl.hpp
+1
-1
FunctionOrdering.hpp
lib/kyut/methods/FunctionOrdering.hpp
+19
-0
pisn.cpp
src/pisn.cpp
+25
-1
snpi.cpp
src/snpi.cpp
+3
-1
No files found.
lib/kyut/Ordering-inl.hpp
View file @
7d57b57f
...
...
@@ -94,7 +94,7 @@ namespace kyut {
for
(
std
::
size_t
i
=
0
;
i
<
count
;
i
++
)
{
const
auto
it
=
std
::
begin
(
chunk
)
+
i
;
// Find the position of `
it
`.
// Find the position of `
begin + i
`.
const
auto
found
=
std
::
find
(
it
,
std
::
end
(
chunk
),
begin
+
i
);
assert
(
found
!=
std
::
end
(
chunk
));
...
...
lib/kyut/methods/FunctionOrdering.hpp
View file @
7d57b57f
...
...
@@ -29,6 +29,25 @@ namespace kyut::methods::function_ordering {
return
size_bits
;
}
std
::
size_t
extract
(
BitStreamWriter
&
w
,
wasm
::
Module
&
module
,
std
::
size_t
chunk_size
)
{
const
auto
begin
=
std
::
begin
(
module
.
functions
);
const
auto
end
=
std
::
end
(
module
.
functions
);
const
auto
start
=
std
::
partition
(
begin
,
end
,
[](
const
auto
&
f
)
{
return
f
->
body
==
nullptr
;
});
const
auto
size_bits
=
extract_by_ordering
(
w
,
chunk_size
,
start
,
end
,
[](
const
auto
&
a
,
const
auto
&
b
)
{
return
a
->
name
<
b
->
name
;
});
return
size_bits
;
}
}
// namespace kyut::methods::function_ordering
#endif // INCLUDE_kyut_methods_FunctionOrdering_hpp
src/pisn.cpp
View file @
7d57b57f
#include <fmt/printf.h>
#include "cmdline.h"
#include "kyut/methods/FunctionOrdering.hpp"
#include "wasm-io.h"
namespace
{
...
...
@@ -15,6 +16,7 @@ int main(int argc, char* argv[]) {
options
.
add
<
std
::
string
>
(
"method"
,
'm'
,
"Embedding method (function-ordering)"
,
true
,
""
,
cmdline
::
oneof
<
std
::
string
>
(
"function-ordering"
));
options
.
add
<
std
::
size_t
>
(
"chunk-size"
,
'c'
,
"Chunk size [2~20]"
,
false
,
20
,
cmdline
::
range
<
std
::
size_t
>
(
2
,
20
));
options
.
add
<
std
::
string
>
(
"dump"
,
0
,
"Output format (ascii, hex)"
,
false
,
"ascii"
,
cmdline
::
oneof
<
std
::
string
>
(
"ascii"
,
"hex"
));
options
.
set_program_name
(
program_name
);
options
.
footer
(
"filename"
);
...
...
@@ -38,11 +40,33 @@ int main(int argc, char* argv[]) {
const
auto
input
=
options
.
rest
()[
0
];
const
auto
method
=
options
.
get
<
std
::
string
>
(
"method"
);
[[
maybe_unused
]]
const
auto
chunk_size
=
options
.
get
<
std
::
size_t
>
(
"chunk-size"
);
const
auto
chunk_size
=
options
.
get
<
std
::
size_t
>
(
"chunk-size"
);
const
auto
dump_format
=
options
.
get
<
std
::
string
>
(
"dump"
);
try
{
wasm
::
Module
module
{};
wasm
::
ModuleReader
{}.
read
(
input
,
module
);
kyut
::
BitStreamWriter
w
{};
std
::
size_t
size_bits
;
if
(
method
==
"function-ordering"
)
{
size_bits
=
kyut
::
methods
::
function_ordering
::
extract
(
w
,
module
,
chunk_size
);
}
else
{
WASM_UNREACHABLE
((
"unknown method: "
+
method
).
c_str
());
}
fmt
::
print
(
"{} bits
\n
"
,
size_bits
);
if
(
dump_format
==
"ascii"
)
{
fmt
::
print
(
"{}"
,
w
.
data_as_str
());
}
else
if
(
dump_format
==
"hex"
)
{
for
(
const
auto
&
byte
:
w
.
data
())
{
fmt
::
print
(
"{:02X}"
,
byte
);
}
}
else
{
WASM_UNREACHABLE
((
"unknown dump format: "
+
dump_format
).
c_str
());
}
}
catch
(
const
std
::
exception
&
e
)
{
fmt
::
print
(
std
::
cerr
,
"error: {}
\n
"
,
e
.
what
());
std
::
exit
(
EXIT_FAILURE
);
...
...
src/snpi.cpp
View file @
7d57b57f
#include <fmt/printf.h>
#include "cmdline.h"
#include "kyut/methods/FunctionOrdering.hpp"
#include "support/colors.h"
#include "wasm-io.h"
namespace
{
...
...
@@ -72,7 +73,8 @@ int main(int argc, char* argv[]) {
WASM_UNREACHABLE
((
"unknown method: "
+
method
).
c_str
());
}
wasm
::
ModuleWriter
{}.
write
(
module
,
output
);
Colors
::
setEnabled
(
false
);
wasm
::
ModuleWriter
{}.
writeText
(
module
,
output
);
fmt
::
print
(
"{} bits
\n
"
,
size_bits
);
}
catch
(
const
std
::
exception
&
e
)
{
...
...
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