Skip to content

Commit 7f81855

Browse files
Merge pull request #55 from charles-r-earp/normalize_file_paths
normalize file paths
2 parents 6cb68f3 + 7943451 commit 7f81855

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

crates/krnl/krnl.spv

-1.22 KB
Binary file not shown.

crates/krnlc/src/rust_in.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ fn process(spirv: Vec<u8>) -> Vec<u32> {
159159
vec![KrnlInst::GroupSlice],
160160
);
161161
strip_op_line(&mut module);
162+
if let Some(home_dir) = std::env::home_dir() {
163+
let home = home_dir.to_string_lossy();
164+
normalize_file_paths(&mut module, &home);
165+
}
162166
spirt::passes::legalize::structurize_func_cfgs(&mut module);
163167
let words = assemble(&module).unwrap();
164168
//validate(&words).expect("val before rspirv");
@@ -1184,3 +1188,49 @@ fn fix_group_slice_len(module: &mut Module) {
11841188
module.funcs[func].inner_in_place_transform_with(&mut transformer);
11851189
}
11861190
}
1191+
1192+
fn normalize_file_paths(module: &mut Module, home: &str) {
1193+
struct ModuleTransformer {
1194+
cx: Rc<Context>,
1195+
space_home: String,
1196+
}
1197+
1198+
impl Transformer for ModuleTransformer {
1199+
fn transform_const_use(&mut self, ct: Const) -> Transformed<Const> {
1200+
let cx = self.cx.clone();
1201+
let ct_def = &cx[ct];
1202+
if let Transformed::Changed(ct_def) = self.transform_const_def(ct_def) {
1203+
Transformed::Changed(self.cx.intern(ct_def))
1204+
} else {
1205+
Transformed::Unchanged
1206+
}
1207+
}
1208+
fn transform_const_def(&mut self, ct_def: &ConstDef) -> Transformed<ConstDef> {
1209+
if let ConstKind::SpvStringLiteralForExtInst(s) = ct_def.kind {
1210+
let s = &self.cx[s];
1211+
if s.contains(&self.space_home) {
1212+
let s = s.replace(&self.space_home, " $HOME");
1213+
let s = self.cx.intern(s);
1214+
let kind = ConstKind::SpvStringLiteralForExtInst(s);
1215+
let ct_def = ConstDef {
1216+
attrs: ct_def.attrs,
1217+
ty: ct_def.ty,
1218+
kind,
1219+
};
1220+
return Transformed::Changed(ct_def);
1221+
}
1222+
}
1223+
Transformed::Unchanged
1224+
}
1225+
}
1226+
1227+
let mut transformer = ModuleTransformer {
1228+
cx: module.cx(),
1229+
space_home: format!(" {home}"),
1230+
};
1231+
for exportee in module.exports.values().copied() {
1232+
if let Exportee::Func(func) = exportee {
1233+
module.funcs[func].inner_in_place_transform_with(&mut transformer);
1234+
}
1235+
}
1236+
}

0 commit comments

Comments
 (0)