Skip to content

Commit

Permalink
reset get costs builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianGCalderon committed Jan 15, 2025
1 parent 3296ccb commit be15f36
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions src/metadata/runtime_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use crate::{
utils::BlockExt,
};
use melior::{
dialect::{llvm, ods},
dialect::{func, llvm, ods},
ir::{
attribute::{FlatSymbolRefAttribute, StringAttribute, TypeAttribute},
operation::OperationBuilder,
r#type::IntegerType,
Attribute, Block, Location, Module, OperationRef, Region, Value,
r#type::{FunctionType, IntegerType},
Attribute, Block, Identifier, Location, Module, OperationRef, Region, Value,
},
Context,
};
Expand Down Expand Up @@ -619,20 +619,36 @@ impl RuntimeBindingsMeta {
where
'c: 'a,
{
let function = self.build_function(
if self.active_map.insert(RuntimeBinding::GetGasBuiltin) {
module.body().append_operation(func::func(
context,
StringAttribute::new(context, "cairo_native__get_costs_builtin"),
TypeAttribute::new(
FunctionType::new(context, &[], &[llvm::r#type::pointer(context, 0)]).into(),
),
Region::new(),
&[
(
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<external>")
.ok_or(Error::ParseAttributeError)?,
),
],
Location::unknown(context),
));
}

Ok(block.append_operation(func::call(
context,
module,
block,
FlatSymbolRefAttribute::new(context, "cairo_native__get_costs_builtin"),
&[],
&[llvm::r#type::pointer(context, 0)],
location,
RuntimeBinding::GetGasBuiltin,
)?;

Ok(block.append_operation(
OperationBuilder::new("llvm.call", location)
.add_operands(&[function])
.add_results(&[llvm::r#type::pointer(context, 0)])
.build()?,
))
)))
}

/// Register if necessary, then invoke the `vtable_cheatcode()` runtime function.
Expand Down

0 comments on commit be15f36

Please sign in to comment.