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
cb4e06e2
Verified
Commit
cb4e06e2
authored
Jan 08, 2021
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add an extra parameter to import functions
parent
7f7ca746
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
1 deletion
+56
-1
kyuk.cpp
src/kyuk.cpp
+56
-1
No files found.
src/kyuk.cpp
View file @
cb4e06e2
#include <fmt/printf.h>
#include <fmt/printf.h>
#include "cmdline.h"
#include "cmdline.h"
#include "wasm-io.h"
#include "wasm-io.h"
#include "wasm-validator.h"
namespace
{
namespace
{
const
std
::
string
program_name
=
"kyuk"
;
const
std
::
string
program_name
=
"kyuk"
;
const
std
::
string
version
=
"0.1.0"
;
const
std
::
string
version
=
"0.1.0"
;
void
add_parameter
(
wasm
::
Function
&
f
)
{
wasm
::
Type
new_param
{
wasm
::
Type
::
i32
};
switch
(
f
.
sig
.
params
.
getID
())
{
case
wasm
:
:
Type
::
none
:
// No parameter
f
.
sig
.
params
=
new_param
;
break
;
case
wasm
:
:
Type
::
i32
:
case
wasm
:
:
Type
::
i64
:
case
wasm
:
:
Type
::
f32
:
case
wasm
:
:
Type
::
f64
:
case
wasm
:
:
Type
::
v128
:
// 1 primitive parameter
f
.
sig
.
params
=
wasm
::
Type
{
f
.
sig
.
params
,
new_param
};
break
;
default:
if
(
f
.
sig
.
params
.
isTuple
())
{
// 2 or more parameters
wasm
::
Tuple
tuple
{};
for
(
const
auto
&
t
:
f
.
sig
.
params
)
{
tuple
.
types
.
emplace_back
(
t
);
}
tuple
.
types
.
emplace_back
(
new_param
);
f
.
sig
.
params
=
wasm
::
Type
{
tuple
};
}
else
{
// May not be reached
throw
std
::
runtime_error
{
"unknown parameter type"
};
}
break
;
}
}
}
// namespace
}
// namespace
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
...
@@ -60,7 +96,26 @@ int main(int argc, char* argv[]) {
...
@@ -60,7 +96,26 @@ int main(int argc, char* argv[]) {
wasm
::
Module
module
{};
wasm
::
Module
module
{};
wasm
::
ModuleReader
{}.
read
(
input
,
module
);
wasm
::
ModuleReader
{}.
read
(
input
,
module
);
// TODO: Embedding
// Embedding
// TODO: Add extra arguments to import function callings
// Add extra parameters to import functions
for
(
const
auto
&
f
:
module
.
functions
)
{
if
(
f
->
body
!=
nullptr
)
{
continue
;
}
// `f` is an import function
fmt
::
print
(
"f: {}, {}
\n
"
,
f
->
name
,
f
->
sig
.
params
.
toString
());
add_parameter
(
*
f
);
fmt
::
print
(
"f: {}, {}
\n
"
,
f
->
name
,
f
->
sig
.
params
.
toString
());
}
// Validation
if
(
!
wasm
::
WasmValidator
{}.
validate
(
module
))
{
std
::
exit
(
EXIT_FAILURE
);
}
wasm
::
ModuleWriter
w
{};
wasm
::
ModuleWriter
w
{};
w
.
setDebugInfo
(
preserve_debug
);
w
.
setDebugInfo
(
preserve_debug
);
...
...
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