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
f0eb50a5
Unverified
Commit
f0eb50a5
authored
Jan 27, 2021
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Jan 27, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5303 from shuujii/split-presym_table-for-reduced-program-size
Split `presym_table` for reduced program size
parents
251fd743
3104aed8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
38 deletions
+45
-38
include/mruby/presym/enable.h
include/mruby/presym/enable.h
+1
-10
lib/mruby/presym.rb
lib/mruby/presym.rb
+31
-12
src/symbol.c
src/symbol.c
+8
-15
tasks/presym.rake
tasks/presym.rake
+5
-1
No files found.
include/mruby/presym/enable.h
View file @
f0eb50a5
...
...
@@ -7,16 +7,7 @@
#ifndef MRUBY_PRESYM_ENABLE_H
#define MRUBY_PRESYM_ENABLE_H
#undef MRB_PRESYM_MAX
#define MRB_PRESYM_NAMED(lit, num, type, name) MRB_##type##__##name = (num),
#define MRB_PRESYM_UNNAMED(lit, num)
enum
mruby_presym
{
# include <mruby/presym.inc>
};
#undef MRB_PRESYM_NAMED
#undef MRB_PRESYM_UNNAMED
#include <mruby/presym/id.h>
#define MRB_OPSYM(name) MRB_OPSYM__##name
#define MRB_CVSYM(name) MRB_CVSYM__##name
...
...
lib/mruby/presym.rb
View file @
f0eb50a5
...
...
@@ -67,34 +67,53 @@ module MRuby
File
.
binwrite
(
list_path
,
presyms
.
join
(
"
\n
"
)
<<
"
\n
"
)
end
def
write_header
(
presyms
)
def
write_
id_
header
(
presyms
)
prefix_re
=
Regexp
.
union
(
*
SYMBOL_TO_MACRO
.
keys
.
map
(
&
:first
).
uniq
)
suffix_re
=
Regexp
.
union
(
*
SYMBOL_TO_MACRO
.
keys
.
map
(
&
:last
).
uniq
)
sym_re
=
/\A(
#{
prefix_re
}
)?([\w&&\D]\w*)(
#{
suffix_re
}
)?\z/o
_pp
"GEN"
,
header_path
.
relative_path
mkdir_p
(
File
.
dirname
(
header_path
))
File
.
open
(
header_path
,
"w:binary"
)
do
|
f
|
f
.
puts
"/* MRB_PRESYM_NAMED(lit, num, type, name) */"
f
.
puts
"/* MRB_PRESYM_UNNAMED(lit, num) */"
_pp
"GEN"
,
id_header_path
.
relative_path
File
.
open
(
id_header_path
,
"w:binary"
)
do
|
f
|
f
.
puts
"enum mruby_presym {"
presyms
.
each
.
with_index
(
1
)
do
|
sym
,
num
|
if
sym_re
=~
sym
&&
(
affixes
=
SYMBOL_TO_MACRO
[[
$1
,
$3
]])
f
.
puts
%|MRB_PRESYM_NAMED("#{sym}", #{num}, #{affixes * 'SYM'}, #{$2})|
f
.
puts
" MRB_
#{
affixes
*
'SYM'
}
__
#{
$2
}
=
#{
num
}
,"
elsif
name
=
OPERATORS
[
sym
]
f
.
puts
%|MRB_PRESYM_NAMED("#{sym}", #{num}, OPSYM, #{name})|
elsif
f
.
puts
%|MRB_PRESYM_UNNAMED("#{sym}", #{num})|
f
.
puts
" MRB_OPSYM__
#{
name
}
=
#{
num
}
,"
end
end
f
.
puts
"};"
f
.
puts
f
.
puts
"#define MRB_PRESYM_MAX
#{
presyms
.
size
}
"
end
end
def
write_table_header
(
presyms
)
_pp
"GEN"
,
table_header_path
.
relative_path
File
.
open
(
table_header_path
,
"w:binary"
)
do
|
f
|
f
.
puts
"const uint16_t presym_length_table[] = {"
presyms
.
each
{
|
sym
|
f
.
puts
"
#{
sym
.
bytesize
}
,"
}
f
.
puts
"};"
f
.
puts
f
.
puts
"const char * const presym_name_table[] = {"
presyms
.
each
{
|
sym
|
f
.
puts
%| "#{sym}",|
}
f
.
puts
"};"
end
end
def
list_path
@list_pat
||=
"
#{
@build
.
build_dir
}
/presym"
.
freeze
end
def
header_path
@header_path
||=
"
#{
@build
.
build_dir
}
/include/mruby/presym.inc"
.
freeze
def
header_dir
;
@header_dir
||=
"
#{
@build
.
build_dir
}
/include/mruby/presym"
.
freeze
end
def
id_header_path
@id_header_path
||=
"
#{
header_dir
}
/id.h"
.
freeze
end
def
table_header_path
@table_header_path
||=
"
#{
header_dir
}
/table.h"
.
freeze
end
private
...
...
src/symbol.c
View file @
f0eb50a5
...
...
@@ -15,31 +15,24 @@
#ifndef MRB_NO_PRESYM
# undef MRB_PRESYM_MAX
# define MRB_PRESYM_NAMED(lit, num, type, name) {lit, sizeof(lit)-1},
# define MRB_PRESYM_UNNAMED(lit, num) {lit, sizeof(lit)-1},
static
const
struct
{
const
char
*
name
;
uint16_t
len
;
}
presym_table
[]
=
{
#ifndef MRB_PRESYM_SCANNING
# include <mruby/presym.inc>
/* const uint16_t presym_length_table[] */
/* const char * const presym_name_table[] */
# include <mruby/presym/table.h>
#endif
};
static
mrb_sym
presym_find
(
const
char
*
name
,
size_t
len
)
{
if
(
presym_
table
[
MRB_PRESYM_MAX
-
1
].
len
<
len
)
return
0
;
if
(
presym_
length_table
[
MRB_PRESYM_MAX
-
1
]
<
len
)
return
0
;
mrb_sym
start
,
idx
,
presym_size
=
MRB_PRESYM_MAX
;
int
cmp
;
for
(
start
=
0
;
presym_size
!=
0
;
presym_size
/=
2
)
{
idx
=
start
+
presym_size
/
2
;
cmp
=
(
int
)
len
-
(
int
)
presym_
table
[
idx
].
len
;
cmp
=
(
int
)
len
-
(
int
)
presym_
length_table
[
idx
]
;
if
(
cmp
==
0
)
{
cmp
=
memcmp
(
name
,
presym_
table
[
idx
].
name
,
len
);
cmp
=
memcmp
(
name
,
presym_
name_table
[
idx
]
,
len
);
if
(
cmp
==
0
)
return
idx
+
1
;
}
if
(
0
<
cmp
)
{
...
...
@@ -54,8 +47,8 @@ static const char*
presym_sym2name
(
mrb_sym
sym
,
mrb_int
*
lenp
)
{
if
(
sym
>
MRB_PRESYM_MAX
)
return
NULL
;
if
(
lenp
)
*
lenp
=
presym_
table
[
sym
-
1
].
len
;
return
presym_
table
[
sym
-
1
].
name
;
if
(
lenp
)
*
lenp
=
presym_
length_table
[
sym
-
1
]
;
return
presym_
name_table
[
sym
-
1
]
;
}
#endif
/* MRB_NO_PRESYM */
...
...
tasks/presym.rake
View file @
f0eb50a5
...
...
@@ -33,7 +33,11 @@ MRuby.each_target do |build|
current_presyms
=
presym
.
read_list
if
File
.
exist?
(
presym
.
list_path
)
update
=
presyms
!=
current_presyms
presym
.
write_list
(
presyms
)
if
update
presym
.
write_header
(
presyms
)
if
update
||
!
File
.
exist?
(
presym
.
header_path
)
mkdir_p
presym
.
header_dir
%w[id table]
.
each
do
|
type
|
next
if
!
update
&&
File
.
exist?
(
presym
.
send
(
"
#{
type
}
_header_path"
))
presym
.
send
(
"write_
#{
type
}
_header"
,
presyms
)
end
end
gensym_task
.
enhance
([
presym
.
list_path
])
...
...
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