Rust: run codegen again

This commit is contained in:
Paolo Tranquilli
2025-07-15 14:32:13 +02:00
parent 7b48cb2ce8
commit c5afc65491
12 changed files with 209 additions and 155 deletions

View File

@@ -1,2 +1,2 @@
mod.rs 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7
top.rs 409eb2e5fb18cb360a7d255fc2d7926a78bcd2d3c9f8dcdfce0419cea49d1489 409eb2e5fb18cb360a7d255fc2d7926a78bcd2d3c9f8dcdfce0419cea49d1489
top.rs 0fc473b83d7cd550396b5c147829487fa7264121b6823fd371b78f55e48935b0 0fc473b83d7cd550396b5c147829487fa7264121b6823fd371b78f55e48935b0

View File

@@ -3615,73 +3615,6 @@ impl From<trap::Label<AsmConst>> for trap::Label<Element> {
}
}
#[derive(Debug)]
pub struct AsmExpr {
pub id: trap::TrapId<AsmExpr>,
pub asm_pieces: Vec<trap::Label<AsmPiece>>,
pub attrs: Vec<trap::Label<Attr>>,
pub template: Vec<trap::Label<Expr>>,
}
impl trap::TrapEntry for AsmExpr {
fn extract_id(&mut self) -> trap::TrapId<Self> {
std::mem::replace(&mut self.id, trap::TrapId::Star)
}
fn emit(self, id: trap::Label<Self>, out: &mut trap::Writer) {
out.add_tuple("asm_exprs", vec![id.into()]);
for (i, v) in self.asm_pieces.into_iter().enumerate() {
out.add_tuple("asm_expr_asm_pieces", vec![id.into(), i.into(), v.into()]);
}
for (i, v) in self.attrs.into_iter().enumerate() {
out.add_tuple("asm_expr_attrs", vec![id.into(), i.into(), v.into()]);
}
for (i, v) in self.template.into_iter().enumerate() {
out.add_tuple("asm_expr_templates", vec![id.into(), i.into(), v.into()]);
}
}
}
impl trap::TrapClass for AsmExpr {
fn class_name() -> &'static str { "AsmExpr" }
}
impl From<trap::Label<AsmExpr>> for trap::Label<Expr> {
fn from(value: trap::Label<AsmExpr>) -> Self {
// SAFETY: this is safe because in the dbscheme AsmExpr is a subclass of Expr
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<AsmExpr>> for trap::Label<AstNode> {
fn from(value: trap::Label<AsmExpr>) -> Self {
// SAFETY: this is safe because in the dbscheme AsmExpr is a subclass of AstNode
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<AsmExpr>> for trap::Label<Locatable> {
fn from(value: trap::Label<AsmExpr>) -> Self {
// SAFETY: this is safe because in the dbscheme AsmExpr is a subclass of Locatable
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<AsmExpr>> for trap::Label<Element> {
fn from(value: trap::Label<AsmExpr>) -> Self {
// SAFETY: this is safe because in the dbscheme AsmExpr is a subclass of Element
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
#[derive(Debug)]
pub struct AsmLabel {
pub id: trap::TrapId<AsmLabel>,
@@ -8831,6 +8764,100 @@ impl From<trap::Label<Adt>> for trap::Label<Addressable> {
}
}
#[derive(Debug)]
pub struct AsmExpr {
pub id: trap::TrapId<AsmExpr>,
pub asm_pieces: Vec<trap::Label<AsmPiece>>,
pub attrs: Vec<trap::Label<Attr>>,
pub template: Vec<trap::Label<Expr>>,
}
impl trap::TrapEntry for AsmExpr {
fn extract_id(&mut self) -> trap::TrapId<Self> {
std::mem::replace(&mut self.id, trap::TrapId::Star)
}
fn emit(self, id: trap::Label<Self>, out: &mut trap::Writer) {
out.add_tuple("asm_exprs", vec![id.into()]);
for (i, v) in self.asm_pieces.into_iter().enumerate() {
out.add_tuple("asm_expr_asm_pieces", vec![id.into(), i.into(), v.into()]);
}
for (i, v) in self.attrs.into_iter().enumerate() {
out.add_tuple("asm_expr_attrs", vec![id.into(), i.into(), v.into()]);
}
for (i, v) in self.template.into_iter().enumerate() {
out.add_tuple("asm_expr_templates", vec![id.into(), i.into(), v.into()]);
}
}
}
impl trap::TrapClass for AsmExpr {
fn class_name() -> &'static str { "AsmExpr" }
}
impl From<trap::Label<AsmExpr>> for trap::Label<Expr> {
fn from(value: trap::Label<AsmExpr>) -> Self {
// SAFETY: this is safe because in the dbscheme AsmExpr is a subclass of Expr
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<AsmExpr>> for trap::Label<AstNode> {
fn from(value: trap::Label<AsmExpr>) -> Self {
// SAFETY: this is safe because in the dbscheme AsmExpr is a subclass of AstNode
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<AsmExpr>> for trap::Label<Locatable> {
fn from(value: trap::Label<AsmExpr>) -> Self {
// SAFETY: this is safe because in the dbscheme AsmExpr is a subclass of Locatable
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<AsmExpr>> for trap::Label<Element> {
fn from(value: trap::Label<AsmExpr>) -> Self {
// SAFETY: this is safe because in the dbscheme AsmExpr is a subclass of Element
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<AsmExpr>> for trap::Label<Item> {
fn from(value: trap::Label<AsmExpr>) -> Self {
// SAFETY: this is safe because in the dbscheme AsmExpr is a subclass of Item
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<AsmExpr>> for trap::Label<Stmt> {
fn from(value: trap::Label<AsmExpr>) -> Self {
// SAFETY: this is safe because in the dbscheme AsmExpr is a subclass of Stmt
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<AsmExpr>> for trap::Label<Addressable> {
fn from(value: trap::Label<AsmExpr>) -> Self {
// SAFETY: this is safe because in the dbscheme AsmExpr is a subclass of Addressable
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
#[derive(Debug)]
pub struct AssocItem {
_unused: ()

View File

@@ -212,6 +212,7 @@ impl Translator<'_> {
return Some(label);
}
let label = match node {
ast::Item::AsmExpr(inner) => self.emit_asm_expr(inner).map(Into::into),
ast::Item::Const(inner) => self.emit_const(inner).map(Into::into),
ast::Item::Enum(inner) => self.emit_enum(inner).map(Into::into),
ast::Item::ExternBlock(inner) => self.emit_extern_block(inner).map(Into::into),