Skip to content

Commit

Permalink
reticulating splines
Browse files Browse the repository at this point in the history
  • Loading branch information
rcgoodfellow committed Sep 20, 2024
1 parent bad3ad0 commit cf12d09
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions codegen/htq/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,55 @@ pub(crate) fn emit_statement(
}
S::If(_if_block) => Ok(Vec::default()), //TODO,
S::Variable(v) => {
//TODO(ry) it's unfortunate that a codegen module has to
// manually maintain scope information. Perhaps we should be using
// the AST visitor ... although I'm not sure if the AST visitor
// maintains a scope either, if not it probably should ....
names.insert(
v.name.clone(),
NameInfo {
ty: v.ty.clone(),
decl: DeclarationInfo::Local,
},
);
Ok(Vec::default())
emit_variable(hlir, ast, context, names, v, ra, afa, psub)
}
S::Constant(_c) => Ok(Vec::default()), //TODO
S::Transition(_t) => Ok(Vec::default()), //TODO
S::Return(_r) => Ok(Vec::default()), //TODO
}
}

fn emit_variable(
_hlir: &Hlir,
_ast: &p4::ast::AST,
_context: P4Context<'_>,
names: &mut HashMap<String, NameInfo>,
var: &p4::ast::Variable,
ra: &mut RegisterAllocator,
_afa: &mut AsyncFlagAllocator,
_psub: &mut HashMap<ControlParameter, Vec<Register>>,
) -> Result<Vec<htq::ast::Statement>, CodegenError> {
//TODO(ry) it's unfortunate that a codegen module has to
// manually maintain scope information. Perhaps we should be using
// the AST visitor ... although I'm not sure if the AST visitor
// maintains a scope either, if not it probably should ....
names.insert(
var.name.clone(),
NameInfo {
ty: var.ty.clone(),
decl: DeclarationInfo::Local,
},
);

if let Some(init) = &var.initializer {
if let ExpressionKind::Lvalue(lval) = &init.kind {
// TODO this could be modeled better (more explicitly) in the
// AST
if lval.leaf() == "await" {
return Ok(vec![htq::ast::Statement::Await(htq::ast::Await {
source: Value::reg(
// TODO this is extermely fragile relying on a
// register naming convention.
ra.get(&format!("{}_sync", lval.root())).unwrap(),
),
})]);
}
}
}

Ok(Vec::default())
}

fn emit_call(
hlir: &Hlir,
ast: &p4::ast::AST,
Expand Down

0 comments on commit cf12d09

Please sign in to comment.