1 // Copyright (c) Facebook, Inc. and its affiliates.
3 // This source code is licensed under the MIT license found in the
4 // LICENSE file in the "hack" directory of this source tree.
6 use hhbc_by_ref_emit_pos::emit_pos;
7 use hhbc_by_ref_hhbc_ast::FatalOp;
8 use hhbc_by_ref_instruction_sequence::{instr, Error, InstrSeq};
9 use oxidized::pos::Pos;
11 pub fn raise_fatal_runtime(pos: &Pos, msg: impl Into<String>) -> Error {
12 Error::IncludeTimeFatalException(FatalOp::Runtime, pos.clone(), msg.into())
15 pub fn raise_fatal_parse(pos: &Pos, msg: impl Into<String>) -> Error {
16 Error::IncludeTimeFatalException(FatalOp::Parse, pos.clone(), msg.into())
19 pub fn emit_fatal<'arena>(
20 alloc: &'arena bumpalo::Bump,
24 ) -> InstrSeq<'arena> {
29 instr::string(alloc, msg.as_ref()),
30 instr::fatal(alloc, op),
35 pub fn emit_fatal_runtime<'arena>(
36 alloc: &'arena bumpalo::Bump,
39 ) -> InstrSeq<'arena> {
40 emit_fatal(alloc, FatalOp::Runtime, pos, msg)
43 pub fn emit_fatal_runtimeomitframe<'arena>(
44 alloc: &'arena bumpalo::Bump,
47 ) -> InstrSeq<'arena> {
48 emit_fatal(alloc, FatalOp::RuntimeOmitFrame, pos, msg)
51 pub fn emit_fatal_for_break_continue<'arena>(
52 alloc: &'arena bumpalo::Bump,
55 ) -> InstrSeq<'arena> {
56 let suffix = if level == 1 { "" } else { "s" };
57 let msg = format!("Cannot break/continue {} level{}", level, suffix);
58 emit_fatal_runtime(alloc, pos, msg)