Skip to content

Commit 13a80c2

Browse files
committed
rewrite: Initial codegen
1 parent 6e89a89 commit 13a80c2

File tree

266 files changed

+2412
-18
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

266 files changed

+2412
-18
lines changed

analysis/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ edition = "2021"
66
[dependencies]
77
roxmltree = "0.20"
88
tracing = "0.1"
9+
indexmap = "2"

analysis/src/cdecl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct UnsupportedCTok<'a>(&'a str);
3333
impl<'a> CTok<'a> {
3434
pub const SUPPORTED_KEYWORDS: &'static [&'static str] = &["const", "struct", "typedef", "void"];
3535

36-
pub fn lex_into(
36+
pub(crate) fn lex_into(
3737
s: &'a str,
3838
out: &mut impl Extend<CTok<'a>>,
3939
) -> Result<(), UnsupportedCTok<'a>> {
@@ -143,7 +143,7 @@ pub enum CDeclParseErrorKind<'a> {
143143

144144
impl<'a> CDecl<'a> {
145145
// HACK(eddyb) this split is literally just to simplify error tracking.
146-
pub fn parse<'b>(
146+
pub(crate) fn parse<'b>(
147147
mode: CDeclMode,
148148
tokens: &'b [CTok<'a>],
149149
) -> Result<CDecl<'a>, CDeclParseError<'a, 'b>> {

analysis/src/items/mod.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use self::structures::Structure;
2+
use crate::{Library, LibraryId};
3+
use indexmap::IndexMap;
4+
use std::collections::HashMap;
5+
6+
pub mod structures;
7+
8+
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
9+
pub struct Origin {
10+
pub library_id: LibraryId,
11+
pub required_by: RequiredBy,
12+
}
13+
14+
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
15+
pub enum RequiredBy {
16+
Feature { major: u32, minor: u32 },
17+
Extension { name: &'static str },
18+
}
19+
20+
#[derive(Default, Debug)]
21+
pub struct Items {
22+
pub structures: IndexMap<&'static str, Structure>,
23+
}
24+
25+
impl Items {
26+
pub(super) fn collect(
27+
&mut self,
28+
library: &Library,
29+
types_require_map: HashMap<&str, RequiredBy>,
30+
) {
31+
for structure in &library.xml.structs {
32+
let name = structure.name;
33+
let Some(&required_by) = types_require_map.get(name) else {
34+
continue;
35+
};
36+
37+
let origin = Origin {
38+
library_id: library.id,
39+
required_by,
40+
};
41+
42+
let structure = Structure::new(origin, structure);
43+
assert!(self.structures.insert(name, structure).is_none());
44+
}
45+
}
46+
}

analysis/src/items/structures.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use super::Origin;
2+
use crate::xml;
3+
4+
#[derive(Debug)]
5+
pub struct Structure {
6+
pub origin: Origin,
7+
pub name: &'static str,
8+
}
9+
10+
impl Structure {
11+
pub fn new(origin: Origin, xml: &xml::Structure) -> Structure {
12+
Structure {
13+
origin,
14+
name: xml.name,
15+
}
16+
}
17+
}

analysis/src/lib.rs

Lines changed: 103 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,128 @@
1-
mod cdecl;
2-
mod xml;
1+
pub mod cdecl;
2+
pub mod items;
3+
pub mod xml;
34

4-
use std::{fs, path::Path};
5+
use items::{Items, RequiredBy};
6+
use std::{
7+
collections::HashMap,
8+
fmt::{self, Display},
9+
fs,
10+
path::{Path, PathBuf},
11+
};
512
use tracing::{debug, error_span};
613

714
#[derive(Debug)]
815
pub struct Analysis {
9-
pub vk: Library,
10-
pub video: Library,
16+
vk: Library,
17+
video: Library,
18+
items: Items,
1119
}
1220

1321
impl Analysis {
1422
pub fn new(vulkan_headers_path: impl AsRef<Path>) -> Analysis {
23+
let vk = Library::new(LibraryId::Vk, &vulkan_headers_path);
24+
let video = Library::new(LibraryId::Video, &vulkan_headers_path);
25+
26+
let mut items = Items::default();
27+
vk.collect_into(&mut items);
28+
video.collect_into(&mut items);
29+
30+
Analysis { vk, video, items }
31+
}
32+
33+
pub fn vk_xml(&self) -> &xml::Registry {
34+
&self.vk.xml
35+
}
36+
37+
pub fn video_xml(&self) -> &xml::Registry {
38+
&self.video.xml
39+
}
40+
41+
pub fn items(&self) -> &Items {
42+
&self.items
43+
}
44+
}
45+
46+
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
47+
pub enum LibraryId {
48+
Vk,
49+
Video,
50+
}
51+
52+
impl LibraryId {
53+
fn xml_path(&self, vulkan_headers_path: impl AsRef<Path>) -> PathBuf {
1554
let vulkan_headers_path = vulkan_headers_path.as_ref();
16-
Analysis {
17-
vk: Library::new(vulkan_headers_path.join("registry/vk.xml")),
18-
video: Library::new(vulkan_headers_path.join("registry/video.xml")),
55+
match self {
56+
LibraryId::Vk => vulkan_headers_path.join("registry/vk.xml"),
57+
LibraryId::Video => vulkan_headers_path.join("registry/video.xml"),
1958
}
2059
}
2160
}
2261

62+
impl Display for LibraryId {
63+
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
64+
formatter.write_str(match self {
65+
LibraryId::Vk => "vk",
66+
LibraryId::Video => "video",
67+
})
68+
}
69+
}
70+
2371
#[derive(Debug)]
2472
pub struct Library {
25-
_xml: xml::Registry,
73+
id: LibraryId,
74+
xml: xml::Registry,
2675
}
2776

2877
impl Library {
29-
fn new(xml_path: impl AsRef<Path>) -> Library {
30-
let xml = error_span!("xml", path = %xml_path.as_ref().display()).in_scope(|| {
78+
fn new(id: LibraryId, vulkan_headers_path: impl AsRef<Path>) -> Library {
79+
let xml = error_span!("xml", library_id = %id).in_scope(|| {
80+
let path = id.xml_path(vulkan_headers_path);
3181
// We leak the input string here for convenience, to avoid explicit lifetimes.
32-
let xml_input = Box::leak(fs::read_to_string(xml_path).unwrap().into_boxed_str());
82+
let input = Box::leak(fs::read_to_string(path).unwrap().into_boxed_str());
3383
debug!("parsing xml");
34-
xml::Registry::parse(xml_input, "vulkan")
84+
xml::Registry::parse(input, "vulkan")
3585
});
3686

37-
Library { _xml: xml }
87+
Library { id, xml }
88+
}
89+
90+
pub fn id(&self) -> LibraryId {
91+
self.id
92+
}
93+
94+
pub fn xml(&self) -> &xml::Registry {
95+
&self.xml
96+
}
97+
98+
fn collect_into(&self, items: &mut Items) {
99+
let mut types_require_map = HashMap::new();
100+
101+
for feature in &self.xml.features {
102+
let required_by = RequiredBy::Feature {
103+
major: feature.version.major,
104+
minor: feature.version.minor,
105+
};
106+
107+
for require in &feature.requires {
108+
for require_type in &require.types {
109+
types_require_map.insert(require_type.name, required_by);
110+
}
111+
}
112+
}
113+
114+
for extension in &self.xml.extensions {
115+
let required_by = RequiredBy::Extension {
116+
name: extension.name,
117+
};
118+
119+
for require in &extension.requires {
120+
for require_type in &require.types {
121+
types_require_map.insert(require_type.name, required_by);
122+
}
123+
}
124+
}
125+
126+
items.collect(self, types_require_map);
38127
}
39128
}

ash-rewrite/src/generated/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub mod video;
3+
pub mod vk;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct StdVideoH264SpsVuiFlags;
3+
pub struct StdVideoH264HrdParameters;
4+
pub struct StdVideoH264SequenceParameterSetVui;
5+
pub struct StdVideoH264SpsFlags;
6+
pub struct StdVideoH264ScalingLists;
7+
pub struct StdVideoH264SequenceParameterSet;
8+
pub struct StdVideoH264PpsFlags;
9+
pub struct StdVideoH264PictureParameterSet;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct StdVideoDecodeH264PictureInfoFlags;
3+
pub struct StdVideoDecodeH264PictureInfo;
4+
pub struct StdVideoDecodeH264ReferenceInfoFlags;
5+
pub struct StdVideoDecodeH264ReferenceInfo;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct StdVideoEncodeH264WeightTableFlags;
3+
pub struct StdVideoEncodeH264WeightTable;
4+
pub struct StdVideoEncodeH264SliceHeaderFlags;
5+
pub struct StdVideoEncodeH264PictureInfoFlags;
6+
pub struct StdVideoEncodeH264ReferenceInfoFlags;
7+
pub struct StdVideoEncodeH264ReferenceListsInfoFlags;
8+
pub struct StdVideoEncodeH264RefListModEntry;
9+
pub struct StdVideoEncodeH264RefPicMarkingEntry;
10+
pub struct StdVideoEncodeH264ReferenceListsInfo;
11+
pub struct StdVideoEncodeH264PictureInfo;
12+
pub struct StdVideoEncodeH264ReferenceInfo;
13+
pub struct StdVideoEncodeH264SliceHeader;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct StdVideoH265ProfileTierLevelFlags;
3+
pub struct StdVideoH265ProfileTierLevel;
4+
pub struct StdVideoH265DecPicBufMgr;
5+
pub struct StdVideoH265SubLayerHrdParameters;
6+
pub struct StdVideoH265HrdFlags;
7+
pub struct StdVideoH265HrdParameters;
8+
pub struct StdVideoH265VpsFlags;
9+
pub struct StdVideoH265VideoParameterSet;
10+
pub struct StdVideoH265ScalingLists;
11+
pub struct StdVideoH265ShortTermRefPicSetFlags;
12+
pub struct StdVideoH265ShortTermRefPicSet;
13+
pub struct StdVideoH265LongTermRefPicsSps;
14+
pub struct StdVideoH265SpsVuiFlags;
15+
pub struct StdVideoH265SequenceParameterSetVui;
16+
pub struct StdVideoH265PredictorPaletteEntries;
17+
pub struct StdVideoH265SpsFlags;
18+
pub struct StdVideoH265SequenceParameterSet;
19+
pub struct StdVideoH265PpsFlags;
20+
pub struct StdVideoH265PictureParameterSet;

0 commit comments

Comments
 (0)