fixes & enhancements to location information associated w/ AST nodes & ZAM optimization

This commit is contained in:
Vern Paxson 2024-01-25 13:11:56 -08:00 committed by Arne Welzel
parent 7a283afe00
commit e5bb63c662
14 changed files with 299 additions and 259 deletions

View file

@ -217,7 +217,9 @@ void Inliner::CoalesceEventHandlers() {
void Inliner::CoalesceEventHandlers(ScriptFuncPtr func, const std::vector<Func::Body>& bodies,
const BodyInfo& body_to_info) {
auto merged_body = make_intrusive<StmtList>();
// We pattern the new (alternate) body off of the first body.
auto& b0 = func->GetBodies()[0].stmts;
auto merged_body = with_location_of(make_intrusive<StmtList>(), b0);
auto oi = merged_body->GetOptInfo();
auto& params = func->GetType()->Params();
@ -226,8 +228,6 @@ void Inliner::CoalesceEventHandlers(ScriptFuncPtr func, const std::vector<Func::
PreInline(oi, init_frame_size);
// We pattern the new (alternate) body off of the first body.
auto& b0 = func->GetBodies()[0].stmts;
auto b0_info = body_to_info.find(b0.get());
ASSERT(b0_info != body_to_info.end());
auto& info0 = funcs[b0_info->second];
@ -254,9 +254,9 @@ void Inliner::CoalesceEventHandlers(ScriptFuncPtr func, const std::vector<Func::
auto new_scope = pop_scope();
// Build up the calling arguments.
auto args = make_intrusive<ListExpr>();
auto args = with_location_of(make_intrusive<ListExpr>(), b0);
for ( auto& p : param_ids )
args->Append(make_intrusive<NameExpr>(p));
args->Append(with_location_of(make_intrusive<NameExpr>(p), b0));
for ( auto& b : bodies ) {
auto bp = b.stmts;
@ -272,7 +272,8 @@ void Inliner::CoalesceEventHandlers(ScriptFuncPtr func, const std::vector<Func::
// changes other than the function's scope.
return;
merged_body->Stmts().push_back(make_intrusive<ExprStmt>(ie));
auto ie_s = with_location_of(make_intrusive<ExprStmt>(ie), bp);
merged_body->Stmts().push_back(std::move(ie_s));
}
auto inlined_func = make_intrusive<CoalescedScriptFunc>(merged_body, new_scope, func);
@ -370,7 +371,7 @@ ExprPtr Inliner::CheckForInlining(CallExprPtr c) {
auto ie = DoInline(func_vf, body, c->ArgsPtr(), scope, ia->second);
if ( ie ) {
ie->SetOriginal(c);
ie->SetLocationInfo(c->GetLocationInfo());
did_inline.insert(func_vf.get());
}
@ -438,7 +439,9 @@ ExprPtr Inliner::DoInline(ScriptFuncPtr sf, StmtPtr body, ListExprPtr args, Scop
auto t = scope->GetReturnType();
ASSERT(params.size() == args->Exprs().size());
return make_intrusive<InlineExpr>(args, params, param_is_modified, body_dup, curr_frame_size, t);
return with_location_of(make_intrusive<InlineExpr>(sf, args, params, param_is_modified, body_dup, curr_frame_size,
t),
body);
}
} // namespace zeek::detail