Skip to content

Commit

Permalink
Use yulgen context object in yul::runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
sbillig committed Jun 24, 2021
1 parent 3a20b74 commit c4e50c7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion compiler/src/yul/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use fe_analyzer::context::Context as AnalyzerContext;
use crate::yul::AnalyzerContext;
use indexmap::IndexSet;

// This is contract context, but it's used all over so it has a short name.
Expand Down
11 changes: 5 additions & 6 deletions compiler/src/yul/mappers/contracts.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::yul::constructor;
use crate::yul::mappers::functions;
use crate::yul::runtime;
use crate::yul::Context;
use fe_analyzer::context::Context as AnalyzerContext;
use crate::yul::{AnalyzerContext, Context};
use fe_common::utils::keccak;
use fe_parser::ast as fe;
use fe_parser::node::Node;
Expand Down Expand Up @@ -42,15 +41,15 @@ pub fn contract_def(
}

// build the set of functions needed during runtime
let runtime_functions = runtime::build_with_abi_dispatcher(analysis, stmt);
let runtime_functions = runtime::build_with_abi_dispatcher(&context, stmt);

// build data objects for static strings (also for constants in the future)
let data = context
.string_literals
.into_iter()
.iter()
.map(|val| yul::Data {
name: keccak::full(val.as_bytes()),
value: val,
value: val.clone(),
})
.collect::<Vec<_>>();

Expand Down Expand Up @@ -88,7 +87,7 @@ pub fn contract_def(
// user-defined functions can be called from `__init__`.
let (constructor_code, constructor_objects) =
if let Some((init_func, init_params)) = init_function {
let init_runtime_functions = [runtime::build(analysis, stmt), user_functions].concat();
let init_runtime_functions = [runtime::build(&context, stmt), user_functions].concat();
let constructor_code = constructor::build_with_init(
contract_name,
init_func,
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/yul/runtime/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
mod abi_dispatcher;
pub mod functions;

use fe_analyzer::context::{Context, FunctionAttributes};
use crate::yul::Context;
use fe_analyzer::context::FunctionAttributes;
use fe_analyzer::namespace::types::{AbiDecodeLocation, Contract, FixedSize};
use fe_parser::ast as fe;
use fe_parser::node::Node;
use yultsur::*;

/// Builds the set of function statements that are needed during runtime.
pub fn build(context: &Context, contract: &Node<fe::Contract>) -> Vec<yul::Statement> {
if let Some(attributes) = context.get_contract(contract) {
if let Some(attributes) = context.analysis.get_contract(contract) {
let std = functions::std();

let external_functions =
Expand Down Expand Up @@ -120,7 +120,7 @@ pub fn build_with_abi_dispatcher(
context: &Context,
contract: &Node<fe::Contract>,
) -> Vec<yul::Statement> {
if let Some(attributes) = context.get_contract(contract) {
if let Some(attributes) = context.analysis.get_contract(contract) {
let mut runtime = build(context, contract);
runtime.push(abi_dispatcher::dispatcher(
attributes.public_functions.to_owned(),
Expand Down

0 comments on commit c4e50c7

Please sign in to comment.