Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
D7050E_2020
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
D7050E_2020
Commits
573f6314
Commit
573f6314
authored
4 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
cranelift wip 0.3
parent
4930f443
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.vscode/settings.json
+1
-0
1 addition, 0 deletions
.vscode/settings.json
src/jit.rs
+24
-21
24 additions, 21 deletions
src/jit.rs
with
25 additions
and
21 deletions
.vscode/settings.json
+
1
−
0
View file @
573f6314
{
"cSpell.ignoreWords"
:
[
"binemit"
,
"codegen"
,
"cranelift"
,
"cranelift simplejit"
,
...
...
This diff is collapsed.
Click to expand it.
src/jit.rs
+
24
−
21
View file @
573f6314
...
...
@@ -44,18 +44,11 @@ impl JIT {
// First, parse the string, producing AST nodes.
let
f
=
&
p
.fn_decls
[
0
];
// let (name, params, the_return, stmts) =
// parser::function(&input).map_err(|e| e.to_string())?;
// Then, translate the AST nodes into Cranelift IR.
// Translate the AST nodes into Cranelift IR.
self
.translate
(
f
)
.map_err
(|
e
|
e
.to_string
())
?
;
// // Next, declare the function to simplejit. Functions must be declared
// // before they can be called, or defined.
// //
// // TODO: This may be an area where the API should be streamlined; should
// // we have a version of `declare_function` that automatically declares
// // the function?
// Next, declare the function to simplejit. Functions must be declared
// before they can be called, or defined.
let
id
=
self
.module
.declare_function
(
f
.id
.as_str
(),
Linkage
::
Export
,
&
self
.ctx.func.signature
)
...
...
@@ -137,8 +130,6 @@ impl JIT {
// Since this is the entry block, add block parameters corresponding to
// the function's parameters.
//
// TODO: Streamline the API here.
builder
.append_block_params_for_function_params
(
entry_block
);
// Tell the builder to emit code in this block.
...
...
@@ -164,15 +155,15 @@ impl JIT {
variables
,
module
:
&
mut
self
.module
,
};
for
expr
in
stmts
{
trans
.translate_
expr
(
expr
);
for
stmt
in
&
f
.body.
stmts
{
trans
.translate_
stmt
(
stmt
);
}
//
// Set up the return variable of the function. Above, we declared a
//
// variable to hold the return value. Here, we just do a use of that
//
// variable.
//
let return_variable = trans.variables.get(&the_return).unwrap();
//
let return_value = trans.builder.use_var(*return_variable);
// Set up the return variable of the function. Above, we declared a
// variable to hold the return value. Here, we just do a use of that
// variable.
let
return_variable
=
trans
.variables
.get
(
&
the_return
)
.unwrap
();
let
return_value
=
trans
.builder
.use_var
(
*
return_variable
);
// // Emit the return instruction.
// trans.builder.ins().return_(&[return_value]);
...
...
@@ -200,6 +191,18 @@ impl<'a> FunctionTranslator<'a> {
_
=>
unimplemented!
(),
}
}
fn
translate_stmt
(
&
mut
self
,
stmt
:
&
Stmt
)
->
Value
{
match
stmt
{
Stmt
::
Assign
(
l
,
r
)
=>
{
let
new_value
=
self
.translate_expr
(
r
);
let
variable
=
self
.variables
.get
(
"res"
)
.unwrap
();
self
.builder
.def_var
(
*
variable
,
new_value
);
new_value
}
_
=>
unimplemented!
(),
}
}
}
// Expr::Add(lhs, rhs) => {
...
...
@@ -430,9 +433,9 @@ fn declare_variables(
let
mut
variables
=
HashMap
::
new
();
let
mut
index
=
0
;
// for
for
(
i
,
name
)
in
params
.iter
()
.enumerate
()
{
// TODO: cranelift_frontend should really have an API to make it easy to set
// up param variables.
let
val
=
builder
.block_params
(
entry_block
)[
i
];
let
var
=
declare_variable
(
int
,
builder
,
&
mut
variables
,
&
mut
index
,
name
);
builder
.def_var
(
var
,
val
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment