Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
69a094dc
Commit
69a094dc
authored
May 22, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
git push origin masterMerge branch 'take-cheeze-refactor_dump'
parents
f4570d41
79a6574a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
63 deletions
+25
-63
src/dump.c
src/dump.c
+25
-63
No files found.
src/dump.c
View file @
69a094dc
...
@@ -514,20 +514,15 @@ static size_t
...
@@ -514,20 +514,15 @@ static size_t
get_filename_table_size
(
mrb_state
*
mrb
,
mrb_irep
*
irep
,
mrb_sym
**
fp
,
uint16_t
*
lp
)
get_filename_table_size
(
mrb_state
*
mrb
,
mrb_irep
*
irep
,
mrb_sym
**
fp
,
uint16_t
*
lp
)
{
{
mrb_sym
*
filenames
=
*
fp
;
mrb_sym
*
filenames
=
*
fp
;
uint16_t
tsize
=
0
;
size_t
i
,
size
=
0
;
uint32_t
file_i
;
size_t
size
=
0
;
mrb_irep_debug_info
*
di
=
irep
->
debug_info
;
mrb_irep_debug_info
*
di
=
irep
->
debug_info
;
if
(
lp
==
NULL
)
{
mrb_assert
(
lp
);
lp
=
&
tsize
;
for
(
i
=
0
;
i
<
di
->
flen
;
++
i
)
{
}
for
(
file_i
=
0
;
file_i
<
di
->
flen
;
++
file_i
)
{
mrb_irep_debug_info_file
*
file
;
mrb_irep_debug_info_file
*
file
;
mrb_int
filename_len
;
mrb_int
filename_len
;
size_t
i
;
file
=
di
->
files
[
file_
i
];
file
=
di
->
files
[
i
];
if
(
find_filename_index
(
filenames
,
*
lp
,
file
->
filename_sym
)
==
-
1
)
{
if
(
find_filename_index
(
filenames
,
*
lp
,
file
->
filename_sym
)
==
-
1
)
{
/* register filename */
/* register filename */
*
lp
+=
1
;
*
lp
+=
1
;
...
@@ -538,10 +533,9 @@ get_filename_table_size(mrb_state *mrb, mrb_irep *irep, mrb_sym **fp, uint16_t *
...
@@ -538,10 +533,9 @@ get_filename_table_size(mrb_state *mrb, mrb_irep *irep, mrb_sym **fp, uint16_t *
mrb_sym2name_len
(
mrb
,
file
->
filename_sym
,
&
filename_len
);
mrb_sym2name_len
(
mrb
,
file
->
filename_sym
,
&
filename_len
);
size
+=
sizeof
(
uint16_t
)
+
(
size_t
)
filename_len
;
size
+=
sizeof
(
uint16_t
)
+
(
size_t
)
filename_len
;
}
}
for
(
i
=
0
;
i
<
irep
->
rlen
;
i
++
)
{
}
size
+=
get_filename_table_size
(
mrb
,
irep
->
reps
[
i
],
fp
,
lp
);
for
(
i
=
0
;
i
<
irep
->
rlen
;
i
++
)
{
filenames
=
*
fp
;
size
+=
get_filename_table_size
(
mrb
,
irep
->
reps
[
i
],
fp
,
lp
);
}
}
}
return
size
;
return
size
;
}
}
...
@@ -618,50 +612,15 @@ write_debug_record(mrb_state *mrb, mrb_irep *irep, uint8_t *bin, mrb_sym const*
...
@@ -618,50 +612,15 @@ write_debug_record(mrb_state *mrb, mrb_irep *irep, uint8_t *bin, mrb_sym const*
return
size
;
return
size
;
}
}
static
size_t
write_filename_table
(
mrb_state
*
mrb
,
mrb_irep
*
irep
,
uint8_t
**
cp
,
mrb_sym
**
fp
,
uint16_t
*
lp
)
{
uint8_t
*
cur
=
*
cp
;
mrb_sym
*
filenames
=
*
fp
;
uint32_t
file_i
;
uint16_t
fn_len
;
size_t
size
=
0
;
mrb_irep_debug_info
*
debug_info
=
irep
->
debug_info
;
for
(
file_i
=
0
;
file_i
<
debug_info
->
flen
;
++
file_i
)
{
mrb_irep_debug_info_file
*
file
=
debug_info
->
files
[
file_i
];
if
(
find_filename_index
(
filenames
,
*
lp
,
file
->
filename_sym
)
!=
-
1
)
continue
;
/* register filename */
*
lp
+=
1
;
*
fp
=
filenames
=
(
mrb_sym
*
)
mrb_realloc
(
mrb
,
filenames
,
sizeof
(
mrb_sym
)
*
(
*
lp
));
filenames
[
*
lp
-
1
]
=
file
->
filename_sym
;
/* filename */
fn_len
=
(
uint16_t
)
strlen
(
file
->
filename
);
cur
+=
uint16_to_bin
(
fn_len
,
cur
);
memcpy
(
cur
,
file
->
filename
,
fn_len
);
cur
+=
fn_len
;
size
+=
sizeof
(
uint16_t
)
+
fn_len
;
}
for
(
file_i
=
0
;
file_i
<
irep
->
rlen
;
file_i
++
)
{
size
+=
write_filename_table
(
mrb
,
irep
->
reps
[
file_i
],
&
cur
,
fp
,
lp
);
}
*
cp
=
cur
;
return
size
;
}
static
int
static
int
write_section_debug
(
mrb_state
*
mrb
,
mrb_irep
*
irep
,
uint8_t
*
cur
)
write_section_debug
(
mrb_state
*
mrb
,
mrb_irep
*
irep
,
uint8_t
*
cur
,
mrb_sym
const
*
filenames
,
uint16_t
filenames_len
)
{
{
size_t
section_size
=
0
;
size_t
section_size
=
0
;
const
uint8_t
*
bin
=
cur
;
const
uint8_t
*
bin
=
cur
;
struct
rite_section_debug_header
*
header
;
struct
rite_section_debug_header
*
header
;
mrb_sym
*
filenames
;
uint16_t
filenames_len
=
0
;
uint8_t
*
filenames_len_out
;
size_t
dlen
;
size_t
dlen
;
uint16_t
i
;
char
const
*
sym
;
mrb_int
sym_len
;
if
(
mrb
==
NULL
||
cur
==
NULL
)
{
if
(
mrb
==
NULL
||
cur
==
NULL
)
{
return
MRB_DUMP_INVALID_ARGUMENT
;
return
MRB_DUMP_INVALID_ARGUMENT
;
...
@@ -672,12 +631,16 @@ write_section_debug(mrb_state *mrb, mrb_irep *irep, uint8_t *cur)
...
@@ -672,12 +631,16 @@ write_section_debug(mrb_state *mrb, mrb_irep *irep, uint8_t *cur)
section_size
+=
sizeof
(
struct
rite_section_debug_header
);
section_size
+=
sizeof
(
struct
rite_section_debug_header
);
/* filename table */
/* filename table */
filenames
=
(
mrb_sym
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_sym
)
*
1
);
cur
+=
uint16_to_bin
(
filenames_len
,
cur
);
filenames_len_out
=
cur
;
cur
+=
sizeof
(
uint16_t
);
section_size
+=
sizeof
(
uint16_t
);
section_size
+=
sizeof
(
uint16_t
);
section_size
+=
write_filename_table
(
mrb
,
irep
,
&
cur
,
&
filenames
,
&
filenames_len
);
for
(
i
=
0
;
i
<
filenames_len
;
++
i
)
{
uint16_to_bin
(
filenames_len
,
filenames_len_out
);
sym
=
mrb_sym2name_len
(
mrb
,
filenames
[
i
],
&
sym_len
);
mrb_assert
(
sym
);
cur
+=
uint16_to_bin
(
sym_len
,
cur
);
memcpy
(
cur
,
sym
,
sym_len
);
cur
+=
sym_len
;
section_size
+=
sizeof
(
uint16_t
)
+
sym_len
;
}
/* debug records */
/* debug records */
dlen
=
write_debug_record
(
mrb
,
irep
,
cur
,
filenames
,
filenames_len
);
dlen
=
write_debug_record
(
mrb
,
irep
,
cur
,
filenames
,
filenames_len
);
...
@@ -687,8 +650,6 @@ write_section_debug(mrb_state *mrb, mrb_irep *irep, uint8_t *cur)
...
@@ -687,8 +650,6 @@ write_section_debug(mrb_state *mrb, mrb_irep *irep, uint8_t *cur)
mrb_assert
(
section_size
<=
INT32_MAX
);
mrb_assert
(
section_size
<=
INT32_MAX
);
uint32_to_bin
(
section_size
,
header
->
section_size
);
uint32_to_bin
(
section_size
,
header
->
section_size
);
mrb_free
(
mrb
,
filenames
);
return
MRB_DUMP_OK
;
return
MRB_DUMP_OK
;
}
}
...
@@ -890,6 +851,7 @@ mrb_dump_irep(mrb_state *mrb, mrb_irep *irep, int debug_info, uint8_t **bin, siz
...
@@ -890,6 +851,7 @@ mrb_dump_irep(mrb_state *mrb, mrb_irep *irep, int debug_info, uint8_t **bin, siz
uint8_t
*
cur
=
NULL
;
uint8_t
*
cur
=
NULL
;
mrb_bool
const
debug_info_defined
=
is_debug_info_defined
(
irep
),
lv_defined
=
is_lv_defined
(
irep
);
mrb_bool
const
debug_info_defined
=
is_debug_info_defined
(
irep
),
lv_defined
=
is_lv_defined
(
irep
);
mrb_sym
*
lv_syms
=
NULL
;
uint32_t
lv_syms_len
=
0
;
mrb_sym
*
lv_syms
=
NULL
;
uint32_t
lv_syms_len
=
0
;
mrb_sym
*
filenames
=
NULL
;
uint16_t
filenames_len
=
0
;
if
(
mrb
==
NULL
)
{
if
(
mrb
==
NULL
)
{
*
bin
=
NULL
;
*
bin
=
NULL
;
...
@@ -902,16 +864,13 @@ mrb_dump_irep(mrb_state *mrb, mrb_irep *irep, int debug_info, uint8_t **bin, siz
...
@@ -902,16 +864,13 @@ mrb_dump_irep(mrb_state *mrb, mrb_irep *irep, int debug_info, uint8_t **bin, siz
/* DEBUG section size */
/* DEBUG section size */
if
(
debug_info
)
{
if
(
debug_info
)
{
if
(
debug_info_defined
)
{
if
(
debug_info_defined
)
{
mrb_sym
*
filenames
;
section_lineno_size
+=
sizeof
(
struct
rite_section_debug_header
);
section_lineno_size
+=
sizeof
(
struct
rite_section_debug_header
);
/* filename table */
/* filename table */
filenames
=
(
mrb_sym
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_sym
)
+
1
);
filenames
=
(
mrb_sym
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_sym
)
+
1
);
/* filename table size */
/* filename table size */
section_lineno_size
+=
sizeof
(
uint16_t
);
section_lineno_size
+=
sizeof
(
uint16_t
);
section_lineno_size
+=
get_filename_table_size
(
mrb
,
irep
,
&
filenames
,
NULL
);
section_lineno_size
+=
get_filename_table_size
(
mrb
,
irep
,
&
filenames
,
&
filenames_len
);
mrb_free
(
mrb
,
filenames
);
section_lineno_size
+=
get_debug_record_size
(
mrb
,
irep
);
section_lineno_size
+=
get_debug_record_size
(
mrb
,
irep
);
}
}
...
@@ -945,7 +904,7 @@ mrb_dump_irep(mrb_state *mrb, mrb_irep *irep, int debug_info, uint8_t **bin, siz
...
@@ -945,7 +904,7 @@ mrb_dump_irep(mrb_state *mrb, mrb_irep *irep, int debug_info, uint8_t **bin, siz
/* write DEBUG section */
/* write DEBUG section */
if
(
debug_info
)
{
if
(
debug_info
)
{
if
(
debug_info_defined
)
{
if
(
debug_info_defined
)
{
result
=
write_section_debug
(
mrb
,
irep
,
cur
);
result
=
write_section_debug
(
mrb
,
irep
,
cur
,
filenames
,
filenames_len
);
}
}
else
{
else
{
result
=
write_section_lineno
(
mrb
,
irep
,
cur
);
result
=
write_section_lineno
(
mrb
,
irep
,
cur
);
...
@@ -975,6 +934,9 @@ error_exit:
...
@@ -975,6 +934,9 @@ error_exit:
if
(
lv_syms
)
{
if
(
lv_syms
)
{
mrb_free
(
mrb
,
lv_syms
);
mrb_free
(
mrb
,
lv_syms
);
}
}
if
(
filenames
)
{
mrb_free
(
mrb
,
filenames
);
}
return
result
;
return
result
;
}
}
...
...
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