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
81b384e3
Unverified
Commit
81b384e3
authored
Jul 21, 2021
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
codegen.c: introduce `gen_int()` to generate integer instructions.
parent
47fca900
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
35 deletions
+26
-35
mrbgems/mruby-compiler/core/codegen.c
mrbgems/mruby-compiler/core/codegen.c
+26
-35
No files found.
mrbgems/mruby-compiler/core/codegen.c
View file @
81b384e3
...
...
@@ -570,6 +570,10 @@ get_int_operand(struct mrb_insn_data *data, int32_t *n)
*
n
=
-
1
;
return
TRUE
;
case
OP_LOADINEG
:
*
n
=
-
data
->
b
;
return
TRUE
;
case
OP_LOADI_0
:
case
OP_LOADI_1
:
case
OP_LOADI_2
:
case
OP_LOADI_3
:
case
OP_LOADI_4
:
case
OP_LOADI_5
:
case
OP_LOADI_6
:
case
OP_LOADI_7
:
*
n
=
data
->
insn
-
OP_LOADI_0
;
...
...
@@ -836,6 +840,26 @@ new_sym(codegen_scope *s, mrb_sym sym)
return
s
->
irep
->
slen
++
;
}
static
void
gen_int
(
codegen_scope
*
s
,
uint16_t
dst
,
mrb_int
i
)
{
if
(
i
<
0
)
{
if
(
i
==
-
1
)
genop_1
(
s
,
OP_LOADI__1
,
dst
);
else
if
(
i
>=
-
0xff
)
genop_2
(
s
,
OP_LOADINEG
,
dst
,
(
uint16_t
)
-
i
);
else
if
(
i
>=
INT16_MIN
)
genop_2S
(
s
,
OP_LOADI16
,
dst
,
(
uint16_t
)
i
);
else
if
(
i
>=
INT32_MIN
)
genop_2SS
(
s
,
OP_LOADI32
,
dst
,
(
uint32_t
)
i
);
else
goto
int_lit
;
}
else
if
(
i
<
8
)
genop_1
(
s
,
OP_LOADI_0
+
(
uint8_t
)
i
,
dst
);
else
if
(
i
<=
0xff
)
genop_2
(
s
,
OP_LOADI
,
dst
,
(
uint16_t
)
i
);
else
if
(
i
<=
INT16_MAX
)
genop_2S
(
s
,
OP_LOADI16
,
dst
,
(
uint16_t
)
i
);
else
if
(
i
<=
INT32_MAX
)
genop_2SS
(
s
,
OP_LOADI32
,
dst
,
(
uint32_t
)
i
);
else
{
int_lit:
genop_2
(
s
,
OP_LOADL
,
dst
,
new_lit
(
s
,
mrb_int_value
(
s
->
mrb
,
i
)));
}
}
static
int
node_len
(
node
*
tree
)
{
...
...
@@ -2616,23 +2640,7 @@ codegen(codegen_scope *s, node *tree, int val)
genop_2
(
s
,
OP_LOADL
,
cursp
(),
off
);
}
else
{
if
(
i
<
0
)
{
if
(
i
==
-
1
)
genop_1
(
s
,
OP_LOADI__1
,
cursp
());
else
if
(
i
>=
-
0xff
)
genop_2
(
s
,
OP_LOADINEG
,
cursp
(),
(
uint16_t
)
-
i
);
else
if
(
i
>=
INT16_MIN
)
genop_2S
(
s
,
OP_LOADI16
,
cursp
(),
(
uint16_t
)
i
);
else
if
(
i
>=
INT32_MIN
)
genop_2SS
(
s
,
OP_LOADI32
,
cursp
(),
(
uint32_t
)
i
);
else
goto
lit_int
;
}
else
if
(
i
<
8
)
genop_1
(
s
,
OP_LOADI_0
+
(
uint8_t
)
i
,
cursp
());
else
if
(
i
<=
0xff
)
genop_2
(
s
,
OP_LOADI
,
cursp
(),
(
uint16_t
)
i
);
else
if
(
i
<=
INT16_MAX
)
genop_2S
(
s
,
OP_LOADI16
,
cursp
(),
(
uint16_t
)
i
);
else
if
(
i
<=
INT32_MAX
)
genop_2SS
(
s
,
OP_LOADI32
,
cursp
(),
(
uint32_t
)
i
);
else
{
int
off
;
lit_int:
off
=
new_lit
(
s
,
mrb_int_value
(
s
->
mrb
,
i
));
genop_2
(
s
,
OP_LOADL
,
cursp
(),
off
);
}
gen_int
(
s
,
cursp
(),
i
);
}
push
();
}
...
...
@@ -2680,25 +2688,8 @@ codegen(codegen_scope *s, node *tree, int val)
int
off
=
new_litbn
(
s
,
p
,
base
,
TRUE
);
genop_2
(
s
,
OP_LOADL
,
cursp
(),
off
);
}
else
if
(
i
==
0
)
{
genop_1
(
s
,
OP_LOADI_0
,
cursp
());
}
else
{
i
=
-
i
;
if
(
i
==
-
1
)
genop_1
(
s
,
OP_LOADI__1
,
cursp
());
else
if
(
i
>=
-
0xff
)
{
genop_2
(
s
,
OP_LOADINEG
,
cursp
(),
(
uint16_t
)
-
i
);
}
else
if
(
i
>=
INT16_MIN
)
{
genop_2S
(
s
,
OP_LOADI16
,
cursp
(),
(
uint16_t
)
i
);
}
else
if
(
i
>=
INT32_MIN
)
{
genop_2SS
(
s
,
OP_LOADI32
,
cursp
(),
(
uint32_t
)
i
);
}
else
{
int
off
=
new_lit
(
s
,
mrb_int_value
(
s
->
mrb
,
i
));
genop_2
(
s
,
OP_LOADL
,
cursp
(),
off
);
}
gen_int
(
s
,
cursp
(),
-
i
);
}
push
();
}
...
...
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