Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
proc-collect
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
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
proc-collect
Commits
9b867ab9
Commit
9b867ab9
authored
5 years ago
by
Per
Browse files
Options
Downloads
Patches
Plain Diff
POC for cortex-m-rt like code gen
parent
52fdbbb0
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
.vscode/tasks.json
+6
-3
6 additions, 3 deletions
.vscode/tasks.json
examples/trust.rs
+17
-7
17 additions, 7 deletions
examples/trust.rs
expanded.rs
+68
-0
68 additions, 0 deletions
expanded.rs
src/lib.rs
+66
-9
66 additions, 9 deletions
src/lib.rs
with
159 additions
and
19 deletions
.gitignore
0 → 100644
+
2
−
0
View file @
9b867ab9
/target
**/*.rs.bk
This diff is collapsed.
Click to expand it.
.vscode/tasks.json
+
6
−
3
View file @
9b867ab9
...
@@ -4,13 +4,16 @@
...
@@ -4,13 +4,16 @@
"version"
:
"2.0.0"
,
"version"
:
"2.0.0"
,
"tasks"
:
[
"tasks"
:
[
{
{
"label"
:
"cargo
run
--example
main
"
,
"label"
:
"cargo
expand
--example
trust > expanded.rs
"
,
"type"
:
"shell"
,
"type"
:
"shell"
,
"command"
:
"cargo
run
--example
main
"
,
"command"
:
"cargo
expand
--example
trust > expanded.rs
"
,
"group"
:
{
"group"
:
{
"kind"
:
"build"
,
"kind"
:
"build"
,
"isDefault"
:
true
"isDefault"
:
true
}
},
"problemMatcher"
:
[
"$rustc"
]
},
},
{
{
"label"
:
"cargo run --example trust"
,
"label"
:
"cargo run --example trust"
,
...
...
This diff is collapsed.
Click to expand it.
examples/trust.rs
+
17
−
7
View file @
9b867ab9
...
@@ -3,22 +3,32 @@ use proc_collect::*;
...
@@ -3,22 +3,32 @@ use proc_collect::*;
#[trust]
#[trust]
mod
kalleanka
{
mod
kalleanka
{
fn
hello
()
{
fn
hello
()
{
println!
(
"in trust hello"
);
ext_hello
();
ext_hello
();
}
}
#[entry]
#[entry]
fn
entry
()
{}
#[inline(always)]
fn
entry
()
{
hello
();
}
#[interrupt]
#[interrupt]
fn
interrupt
()
{}
fn
i1
()
{
println!
(
"i1"
);
}
#[interrupt]
fn
i2
()
{
println!
(
"i2"
);
}
#[exception]
#[exception]
fn
exception
()
{}
fn
exception
()
{
println!
(
"exc"
);
}
}
}
fn
ext_hello
()
{
fn
ext_hello
()
{
println!
(
"hello"
);
println!
(
"ext_hello"
);
}
fn
main
()
{
hello
();
}
}
This diff is collapsed.
Click to expand it.
expanded.rs
0 → 100644
+
68
−
0
View file @
9b867ab9
#![feature(prelude_import)]
#[prelude_import]
use
std
::
prelude
::
v1
::
*
;
#[macro_use]
extern
crate
std
;
use
proc_collect
::
*
;
fn
hello
()
{
{
::
std
::
io
::
_print
(::
core
::
fmt
::
Arguments
::
new_v1
(
&
[
"in trust hello
\n
"
],
&
match
()
{
()
=>
[],
},
));
};
ext_hello
();
}
#[inline(always)]
fn
entry
()
{
hello
();
}
fn
i1
()
{
{
::
std
::
io
::
_print
(::
core
::
fmt
::
Arguments
::
new_v1
(
&
[
"i1
\n
"
],
&
match
()
{
()
=>
[],
},
));
};
}
fn
i2
()
{
{
::
std
::
io
::
_print
(::
core
::
fmt
::
Arguments
::
new_v1
(
&
[
"i2
\n
"
],
&
match
()
{
()
=>
[],
},
));
};
}
fn
exception
()
{
{
::
std
::
io
::
_print
(::
core
::
fmt
::
Arguments
::
new_v1
(
&
[
"exc
\n
"
],
&
match
()
{
()
=>
[],
},
));
};
}
fn
main
()
{
let
_
=
entry
();
let
_
=
i1
();
let
_
=
i2
();
let
_
=
exception
();
}
fn
ext_hello
()
{
{
::
std
::
io
::
_print
(::
core
::
fmt
::
Arguments
::
new_v1
(
&
[
"ext_hello
\n
"
],
&
match
()
{
()
=>
[],
},
));
};
}
This diff is collapsed.
Click to expand it.
src/lib.rs
+
66
−
9
View file @
9b867ab9
...
@@ -6,36 +6,75 @@ use std::fs::{File, OpenOptions};
...
@@ -6,36 +6,75 @@ use std::fs::{File, OpenOptions};
use
std
::
io
::
prelude
::
*
;
use
std
::
io
::
prelude
::
*
;
use
std
::
iter
::
FromIterator
;
use
std
::
iter
::
FromIterator
;
use
syn
::
parse
::{
Parse
,
ParseStream
};
use
syn
::
parse
::{
Parse
,
ParseStream
};
use
syn
::{
parse_macro_input
,
Attribute
,
Ident
,
Item
,
ItemMod
,
Result
,
Token
};
use
syn
::{
parse_macro_input
,
Attribute
,
Ident
,
Item
,
ItemFn
,
ItemMod
,
Result
,
Token
};
// use syn::{parse_macro_input, Attribute, Ident, ItemMod, Result, Token};
// use syn::{parse_macro_input, Attribute, Ident, ItemMod, Result, Token};
#[proc_macro_attribute]
#[proc_macro_attribute]
pub
fn
entry
(
_args
:
TokenStream
,
input
:
TokenStream
)
->
TokenStream
{
pub
fn
entry
(
_args
:
TokenStream
,
input
:
TokenStream
)
->
TokenStream
{
let
item
s
=
parse_macro_input!
(
input
as
Fn
Item
)
.items
;
let
fn_
item
=
parse_macro_input!
(
input
as
Item
Fn
)
;
(
quote!
{
#
(
#
item
s
)
*
})
.into
()
(
quote!
{
#
fn_
item
})
.into
()
}
}
#[proc_macro_attribute]
#[proc_macro_attribute]
pub
fn
interrupt
(
_args
:
TokenStream
,
input
:
TokenStream
)
->
TokenStream
{
pub
fn
interrupt
(
_args
:
TokenStream
,
input
:
TokenStream
)
->
TokenStream
{
input
let
fn_item
=
parse_macro_input!
(
input
as
ItemFn
);
(
quote!
{
#
fn_item
})
.into
()
}
}
#[proc_macro_attribute]
#[proc_macro_attribute]
pub
fn
exception
(
_args
:
TokenStream
,
input
:
TokenStream
)
->
TokenStream
{
pub
fn
exception
(
_args
:
TokenStream
,
input
:
TokenStream
)
->
TokenStream
{
input
let
fn_item
=
parse_macro_input!
(
input
as
ItemFn
);
(
quote!
{
#
fn_item
})
.into
()
}
}
#[derive(Debug)]
#[derive(Debug)]
struct
TrustMod
{
struct
TrustMod
{
items
:
Vec
<
Item
>
,
items
:
Vec
<
Item
>
,
entries
:
Vec
<
Entry
>
,
}
#[derive(Debug)]
enum
Entry
{
Entry
(
Ident
),
Interrupt
(
Ident
),
Exception
(
Ident
),
}
}
impl
Parse
for
TrustMod
{
impl
Parse
for
TrustMod
{
fn
parse
(
input
:
ParseStream
)
->
Result
<
Self
>
{
fn
parse
(
input
:
ParseStream
)
->
Result
<
Self
>
{
let
module
:
ItemMod
=
input
.parse
()
?
;
let
module
:
ItemMod
=
input
.parse
()
?
;
match
module
.content
{
match
module
.content
{
Some
((
_
,
items
))
=>
Ok
(
TrustMod
{
items
}),
Some
((
_
,
items
))
=>
{
let
mut
v
=
vec!
[];
let
mut
e
=
vec!
[];
for
i
in
items
{
match
i
{
Item
::
Fn
(
ref
item_fn
)
=>
{
for
a
in
&
item_fn
.attrs
{
for
s
in
&
a
.path.segments
{
match
s
.ident
.to_string
()
.as_str
()
{
"entry"
=>
e
.push
(
Entry
::
Entry
(
item_fn
.sig.ident
.clone
())),
"interrupt"
=>
{
e
.push
(
Entry
::
Interrupt
(
item_fn
.sig.ident
.clone
()))
}
"exception"
=>
{
e
.push
(
Entry
::
Exception
(
item_fn
.sig.ident
.clone
()))
}
_
=>
(),
}
}
}
}
_
=>
(),
}
v
.push
(
i
);
}
Ok
(
TrustMod
{
items
:
v
,
entries
:
e
,
})
}
_
=>
panic!
(
"illegal trust module"
),
_
=>
panic!
(
"illegal trust module"
),
}
}
}
}
...
@@ -43,6 +82,24 @@ impl Parse for TrustMod {
...
@@ -43,6 +82,24 @@ impl Parse for TrustMod {
#[proc_macro_attribute]
#[proc_macro_attribute]
pub
fn
trust
(
_args
:
TokenStream
,
input
:
TokenStream
)
->
TokenStream
{
pub
fn
trust
(
_args
:
TokenStream
,
input
:
TokenStream
)
->
TokenStream
{
let
items
=
parse_macro_input!
(
input
as
TrustMod
)
.items
;
let
trust_mod
=
parse_macro_input!
(
input
as
TrustMod
);
(
quote!
{
#
(
#
items
)
*
})
.into
()
let
items
=
trust_mod
.items
;
let
mut
calls
=
vec!
[];
for
e
in
trust_mod
.entries
{
let
id
=
match
e
{
Entry
::
Entry
(
id
)
=>
id
,
Entry
::
Interrupt
(
id
)
=>
id
,
Entry
::
Exception
(
id
)
=>
id
,
};
calls
.push
(
quote!
{
let
_
=
#
id
();
});
}
(
quote!
{
#
(
#
items
)
*
fn
main
()
{
#
(
#
calls
)
*
}
})
.into
()
}
}
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