save
This commit is contained in:
parent
4d913462cb
commit
2361e166cd
|
@ -747,18 +747,18 @@ impl Codegen {
|
||||||
return ty.expand().inner();
|
return ty.expand().inner();
|
||||||
}
|
}
|
||||||
|
|
||||||
let prev_tmp = self.tys.tmp.fields.len();
|
let prev_tmp = self.tys.ins.fields.len();
|
||||||
for sf in fields.iter().filter_map(CommentOr::or) {
|
for sf in fields.iter().filter_map(CommentOr::or) {
|
||||||
let f = Field { name: self.tys.names.intern(sf.name), ty: self.ty(&sf.ty) };
|
let f = Field { name: self.tys.names.intern(sf.name), ty: self.ty(&sf.ty) };
|
||||||
self.tys.tmp.fields.push(f);
|
self.tys.ins.fields.push(f);
|
||||||
}
|
}
|
||||||
self.tys.ins.structs.push(Struct {
|
self.tys.ins.structs.push(Struct {
|
||||||
field_start: self.tys.fields.len() as _,
|
field_start: self.tys.ins.fields.len() as _,
|
||||||
explicit_alignment,
|
explicit_alignment,
|
||||||
file,
|
file,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
self.tys.fields.extend(self.tys.tmp.fields.drain(prev_tmp..));
|
self.tys.ins.fields.extend(self.tys.ins.fields.drain(prev_tmp..));
|
||||||
|
|
||||||
if let Some(sym) = sym {
|
if let Some(sym) = sym {
|
||||||
self.tys
|
self.tys
|
||||||
|
@ -1123,8 +1123,8 @@ impl Codegen {
|
||||||
}
|
}
|
||||||
|
|
||||||
let reloc = Reloc::new(self.ci.code.len() as _, 3, 4);
|
let reloc = Reloc::new(self.ci.code.len() as _, 3, 4);
|
||||||
let glob = self.tys.globals.len() as ty::Global;
|
let glob = self.tys.ins.globals.len() as ty::Global;
|
||||||
self.tys.globals.push(Global { data: str, ..Default::default() });
|
self.tys.ins.globals.push(Global { data: str, ..Default::default() });
|
||||||
self.ci
|
self.ci
|
||||||
.relocs
|
.relocs
|
||||||
.push(TypedReloc { target: ty::Kind::Global(glob).compress(), reloc });
|
.push(TypedReloc { target: ty::Kind::Global(glob).compress(), reloc });
|
||||||
|
@ -2043,7 +2043,7 @@ impl Codegen {
|
||||||
let ptr = self.ci.regs.allocate();
|
let ptr = self.ci.regs.allocate();
|
||||||
|
|
||||||
let reloc = Reloc::new(self.ci.code.len(), 3, 4);
|
let reloc = Reloc::new(self.ci.code.len(), 3, 4);
|
||||||
let global = &mut self.tys.globals[id as usize];
|
let global = &mut self.tys.ins.globals[id as usize];
|
||||||
self.ci.relocs.push(TypedReloc { target: ty::Kind::Global(id).compress(), reloc });
|
self.ci.relocs.push(TypedReloc { target: ty::Kind::Global(id).compress(), reloc });
|
||||||
self.ci.emit(instrs::lra(ptr.get(), 0, 0));
|
self.ci.emit(instrs::lra(ptr.get(), 0, 0));
|
||||||
|
|
||||||
|
@ -2525,8 +2525,8 @@ impl Codegen {
|
||||||
ty::Kind::Struct(str)
|
ty::Kind::Struct(str)
|
||||||
}
|
}
|
||||||
Expr::BinOp { left, op: TokenKind::Decl, right } => {
|
Expr::BinOp { left, op: TokenKind::Decl, right } => {
|
||||||
let gid = self.tys.globals.len() as ty::Global;
|
let gid = self.tys.ins.globals.len() as ty::Global;
|
||||||
self.tys.globals.push(Global { file, name: ident, ..Default::default() });
|
self.tys.ins.globals.push(Global { file, name: ident, ..Default::default() });
|
||||||
|
|
||||||
let ci = ItemCtx {
|
let ci = ItemCtx {
|
||||||
file,
|
file,
|
||||||
|
@ -2535,7 +2535,7 @@ impl Codegen {
|
||||||
};
|
};
|
||||||
|
|
||||||
_ = left.find_pattern_path(ident, right, |expr| {
|
_ = left.find_pattern_path(ident, right, |expr| {
|
||||||
self.tys.globals[gid as usize] = self
|
self.tys.ins.globals[gid as usize] = self
|
||||||
.ct_eval(ci, |s, _| Ok::<_, !>(s.generate_global(expr, file, ident)))
|
.ct_eval(ci, |s, _| Ok::<_, !>(s.generate_global(expr, file, ident)))
|
||||||
.into_ok();
|
.into_ok();
|
||||||
});
|
});
|
||||||
|
@ -2754,7 +2754,7 @@ impl Codegen {
|
||||||
|
|
||||||
pub fn assemble(&mut self, buf: &mut Vec<u8>) {
|
pub fn assemble(&mut self, buf: &mut Vec<u8>) {
|
||||||
self.tys.funcs.iter_mut().for_each(|f| f.offset = u32::MAX);
|
self.tys.funcs.iter_mut().for_each(|f| f.offset = u32::MAX);
|
||||||
self.tys.globals.iter_mut().for_each(|g| g.offset = u32::MAX);
|
self.tys.ins.globals.iter_mut().for_each(|g| g.offset = u32::MAX);
|
||||||
self.tys.assemble(buf)
|
self.tys.assemble(buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -736,12 +736,12 @@ impl Types {
|
||||||
let end = self
|
let end = self
|
||||||
.ins.structs
|
.ins.structs
|
||||||
.get(strct as usize + 1)
|
.get(strct as usize + 1)
|
||||||
.map_or(self.fields.len(), |s| s.field_start as usize);
|
.map_or(self.ins.fields.len(), |s| s.field_start as usize);
|
||||||
start..end
|
start..end
|
||||||
}
|
}
|
||||||
|
|
||||||
fn struct_fields(&self, strct: ty::Struct) -> &[Field] {
|
fn struct_fields(&self, strct: ty::Struct) -> &[Field] {
|
||||||
&self.fields[self.struct_field_range(strct)]
|
&self.ins.fields[self.struct_field_range(strct)]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_type(
|
fn find_type(
|
||||||
|
@ -754,7 +754,7 @@ impl Types {
|
||||||
&& let Some(&ty) = self.syms.get(&SymKey::Decl(file, id))
|
&& let Some(&ty) = self.syms.get(&SymKey::Decl(file, id))
|
||||||
{
|
{
|
||||||
if let ty::Kind::Global(g) = ty.expand() {
|
if let ty::Kind::Global(g) = ty.expand() {
|
||||||
let g = &self.globals[g as usize];
|
let g = &self.ins.globals[g as usize];
|
||||||
if g.ty == ty::Id::TYPE {
|
if g.ty == ty::Id::TYPE {
|
||||||
return Some(ty::Id::from(
|
return Some(ty::Id::from(
|
||||||
u32::from_ne_bytes(*g.data.first_chunk().unwrap()) as u64
|
u32::from_ne_bytes(*g.data.first_chunk().unwrap()) as u64
|
||||||
|
@ -810,22 +810,22 @@ impl Types {
|
||||||
return Some(ty);
|
return Some(ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
let prev_tmp = self.tmp.fields.len();
|
let prev_tmp = self.ins.fields.len();
|
||||||
for field in fields.iter().filter_map(CommentOr::or) {
|
for field in fields.iter().filter_map(CommentOr::or) {
|
||||||
let Some(ty) = self.ty(file, &field.ty, files) else {
|
let Some(ty) = self.ty(file, &field.ty, files) else {
|
||||||
self.tmp.fields.truncate(prev_tmp);
|
self.ins.fields.truncate(prev_tmp);
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
self.tmp.fields.push(Field { name: self.names.intern(field.name), ty });
|
self.ins.fields.push(Field { name: self.names.intern(field.name), ty });
|
||||||
}
|
}
|
||||||
|
|
||||||
self.ins.structs.push(Struct {
|
self.ins.structs.push(Struct {
|
||||||
file,
|
file,
|
||||||
field_start: self.fields.len() as _,
|
field_start: self.ins.fields.len() as _,
|
||||||
explicit_alignment: packed.then_some(1),
|
explicit_alignment: packed.then_some(1),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
self.fields.extend(self.tmp.fields.drain(prev_tmp..));
|
self.ins.fields.extend(self.ins.fields.drain(prev_tmp..));
|
||||||
|
|
||||||
let ty = ty::Kind::Struct(self.ins.structs.len() as u32 - 1).compress();
|
let ty = ty::Kind::Struct(self.ins.structs.len() as u32 - 1).compress();
|
||||||
self.syms.insert(sym, ty);
|
self.syms.insert(sym, ty);
|
||||||
|
@ -849,7 +849,7 @@ impl Types {
|
||||||
fn dump_reachable(&mut self, from: ty::Func, to: &mut Vec<u8>) -> AbleOsExecutableHeader {
|
fn dump_reachable(&mut self, from: ty::Func, to: &mut Vec<u8>) -> AbleOsExecutableHeader {
|
||||||
debug_assert!(self.tmp.frontier.is_empty());
|
debug_assert!(self.tmp.frontier.is_empty());
|
||||||
debug_assert!(self.tmp.funcs.is_empty());
|
debug_assert!(self.tmp.funcs.is_empty());
|
||||||
debug_assert!(self.tmp.globals.is_empty());
|
debug_assert!(self.ins.globals.is_empty());
|
||||||
|
|
||||||
self.tmp.frontier.push(ty::Kind::Func(from).compress());
|
self.tmp.frontier.push(ty::Kind::Func(from).compress());
|
||||||
while let Some(itm) = self.tmp.frontier.pop() {
|
while let Some(itm) = self.tmp.frontier.pop() {
|
||||||
|
@ -864,12 +864,12 @@ impl Types {
|
||||||
self.tmp.frontier.extend(fuc.relocs.iter().map(|r| r.target));
|
self.tmp.frontier.extend(fuc.relocs.iter().map(|r| r.target));
|
||||||
}
|
}
|
||||||
ty::Kind::Global(glob) => {
|
ty::Kind::Global(glob) => {
|
||||||
let glb = &mut self.globals[glob as usize];
|
let glb = &mut self.ins.globals[glob as usize];
|
||||||
if task::is_done(glb.offset) {
|
if task::is_done(glb.offset) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
glb.offset = 0;
|
glb.offset = 0;
|
||||||
self.tmp.globals.push(glob);
|
self.ins.globals.push(glob);
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
@ -883,8 +883,8 @@ impl Types {
|
||||||
|
|
||||||
let code_length = to.len();
|
let code_length = to.len();
|
||||||
|
|
||||||
for global in self.tmp.globals.drain(..) {
|
for global in self.ins.globals.drain(..) {
|
||||||
let global = &mut self.globals[global as usize];
|
let global = &mut self.ins.globals[global as usize];
|
||||||
global.offset = to.len() as _;
|
global.offset = to.len() as _;
|
||||||
to.extend(&global.data);
|
to.extend(&global.data);
|
||||||
}
|
}
|
||||||
|
@ -896,7 +896,7 @@ impl Types {
|
||||||
for rel in &fuc.relocs {
|
for rel in &fuc.relocs {
|
||||||
let offset = match rel.target.expand() {
|
let offset = match rel.target.expand() {
|
||||||
ty::Kind::Func(fun) => self.funcs[fun as usize].offset,
|
ty::Kind::Func(fun) => self.funcs[fun as usize].offset,
|
||||||
ty::Kind::Global(glo) => self.globals[glo as usize].offset,
|
ty::Kind::Global(glo) => self.ins.globals[glo as usize].offset,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
rel.reloc.apply_jump(to, offset, fuc.offset);
|
rel.reloc.apply_jump(to, offset, fuc.offset);
|
||||||
|
@ -940,7 +940,7 @@ impl Types {
|
||||||
};
|
};
|
||||||
(f.offset, (name, f.code.len() as u32, DisasmItem::Func))
|
(f.offset, (name, f.code.len() as u32, DisasmItem::Func))
|
||||||
})
|
})
|
||||||
.chain(self.globals.iter().filter(|g| task::is_done(g.offset)).map(|g| {
|
.chain(self.ins.globals.iter().filter(|g| task::is_done(g.offset)).map(|g| {
|
||||||
let name = if g.file == u32::MAX {
|
let name = if g.file == u32::MAX {
|
||||||
core::str::from_utf8(&g.data).unwrap()
|
core::str::from_utf8(&g.data).unwrap()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1082,7 +1082,7 @@ impl OffsetIter {
|
||||||
|
|
||||||
fn next<'a>(&mut self, tys: &'a Types) -> Option<(&'a Field, Offset)> {
|
fn next<'a>(&mut self, tys: &'a Types) -> Option<(&'a Field, Offset)> {
|
||||||
let stru = &tys.ins.structs[self.strct as usize];
|
let stru = &tys.ins.structs[self.strct as usize];
|
||||||
let field = &tys.fields[self.fields.next()?];
|
let field = &tys.ins.fields[self.ins.fields.next()?];
|
||||||
|
|
||||||
let align = stru.explicit_alignment.map_or_else(|| tys.align_of(field.ty), |a| a as u32);
|
let align = stru.explicit_alignment.map_or_else(|| tys.align_of(field.ty), |a| a as u32);
|
||||||
self.offset = (self.offset + align - 1) & !(align - 1);
|
self.offset = (self.offset + align - 1) & !(align - 1);
|
||||||
|
|
Loading…
Reference in a new issue