Skip to content

Commit f19356f

Browse files
authored
Merge branch 'main' into file-syntax-public
2 parents 45d8e24 + 62012e3 commit f19356f

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

crates/cairo-lang-executable/src/debug_info.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,22 @@ pub struct DebugInfo {
3333
/// - `scarb.swmansion.com/v1`
3434
/// - `scarb.swmansion.com/build-info/v1`
3535
pub type Annotations = OrderedHashMap<String, serde_json::Value>;
36+
37+
/// Program offsets information, for use by the profiler.
38+
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
39+
pub struct ProgramInformation {
40+
/// The bytecode offset of the first CASM instruction after all added headers.
41+
/// It is the offset of the first CASM instruction of the original CASM program (the one that
42+
/// is a direct result of Sierra compilation).
43+
pub program_offset: usize,
44+
}
45+
46+
impl From<ProgramInformation> for Annotations {
47+
fn from(value: ProgramInformation) -> Self {
48+
let mapping = serde_json::to_value(value).unwrap();
49+
OrderedHashMap::from([(
50+
"github.com/software-mansion/cairo-profiler".to_string(),
51+
serde_json::Value::from_iter([("program_info", mapping)]),
52+
)])
53+
}
54+
}

crates/cairo-lang-executable/src/executable.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use itertools::chain;
55
use serde::{Deserialize, Serialize};
66

77
use crate::compile::CompiledFunction;
8-
use crate::debug_info::DebugInfo;
8+
use crate::debug_info::{Annotations, DebugInfo, ProgramInformation};
99

1010
pub const NOT_RETURNING_HEADER_SIZE: usize = 6;
1111

@@ -47,7 +47,17 @@ impl Executable {
4747
kind: EntryPointKind::Bootloader,
4848
},
4949
],
50-
debug_info: Default::default(),
50+
debug_info: Some(DebugInfo {
51+
annotations: Annotations::from(ProgramInformation {
52+
program_offset: NOT_RETURNING_HEADER_SIZE
53+
+ compiled
54+
.wrapper
55+
.header
56+
.iter()
57+
.map(|inst| inst.body.op_size())
58+
.sum::<usize>(),
59+
}),
60+
}),
5161
}
5262
}
5363
}

0 commit comments

Comments
 (0)