Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brockelmore committed Jul 10, 2024
1 parent 38992f8 commit 0e03166
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 123 deletions.
2 changes: 1 addition & 1 deletion crates/graph/src/nodes/context/querying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl ContextNode {
tys.sort();
tys.dedup();

idxs.retain(|i| tys.contains(&i));
idxs.retain(|i| tys.contains(i));

Ok(())
}
Expand Down
12 changes: 7 additions & 5 deletions crates/graph/src/nodes/context/var/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,11 +608,13 @@ impl ContextVarNode {
if let Some(to_range) = to_ty.range(analyzer)? {
let mut min_expr = (*self)
.range_min(analyzer)?
.expect(&format!(
"{:?}, {} had no min",
self.loc(analyzer).unwrap(),
self.display_name(analyzer).unwrap()
))
.unwrap_or_else(|| {
panic!(
"{:?}, {} had no min",
self.loc(analyzer).unwrap(),
self.display_name(analyzer).unwrap()
)
})
.cast(to_range.min.clone())
.min(
(*self)
Expand Down
6 changes: 3 additions & 3 deletions crates/graph/src/nodes/context/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use shared::GraphError;

use petgraph::{visit::EdgeRef, Direction};
use petgraph::visit::EdgeRef;
use solang_parser::pt::Loc;

use std::collections::BTreeMap;
Expand Down Expand Up @@ -242,7 +242,7 @@ impl ContextNode {
let vars = self.all_vars(analyzer);
vars.iter()
.filter_map(|(_, var)| var.maybe_usertype(analyzer).ok())
.filter_map(|v| v)
.flatten()
.collect()
}

Expand Down Expand Up @@ -276,7 +276,7 @@ impl ContextNode {
reffed_usertypes.extend(cont.usertype_vars_referenced_global(analyzer));
});

reffed_usertypes.sort_by(|a, b| a.cmp(&b));
reffed_usertypes.sort();
reffed_usertypes.dedup();
reffed_usertypes
}
Expand Down
5 changes: 2 additions & 3 deletions crates/graph/src/nodes/debug_reconstruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
use shared::GraphError;

use petgraph::{visit::EdgeRef, Direction};
use shared::GraphError;
use solang_parser::pt::Loc;

use std::collections::BTreeMap;
Expand Down Expand Up @@ -246,7 +245,7 @@ impl ContractNode {
.iter()
.filter_map(|strukt| {
if used.contains(strukt) {
Some(format!("{}", strukt.reconstruct_src(analyzer).ok()?))
Some(strukt.reconstruct_src(analyzer).ok()?.to_string())
} else {
None
}
Expand Down Expand Up @@ -297,7 +296,7 @@ impl ContractNode {
.iter()
.filter_map(|enu| {
if used.contains(enu) {
Some(format!("{}", enu.reconstruct_src(analyzer).ok()?))
Some(enu.reconstruct_src(analyzer).ok()?.to_string())
} else {
None
}
Expand Down
3 changes: 1 addition & 2 deletions crates/graph/src/nodes/func_ty.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{
nodes::{Concrete, ContextNode, ContractNode, SourceUnitNode, SourceUnitPartNode, VarNode},
nodes::{Concrete, ContextNode, ContractNode, SourceUnitNode, SourceUnitPartNode},
range::elem::Elem,
AnalyzerBackend, AsDotStr, ContextEdge, Edge, GraphBackend, Node, SolcRange, VarType,
};

use ethers_core::k256::elliptic_curve::rand_core::impls;
use shared::{GraphError, NodeIdx, RangeArena, Search, StorageLocation};

use petgraph::{visit::EdgeRef, Direction};
Expand Down
4 changes: 2 additions & 2 deletions crates/pyrometer/src/graph_backend.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::Analyzer;
use graph::{
as_dot_str,
elem::Elem,
nodes::{ContextNode, ContextVarNode},
elem::{Elem, RangeElem},
nodes::{Concrete, ContextNode, ContextVarNode},
AnalyzerBackend, AsDotStr, ContextEdge, Edge, GraphBackend, Node, TOKYO_NIGHT_COLORS,
};
use reqwest::Client;
Expand Down
92 changes: 50 additions & 42 deletions crates/pyrometer/tests/test_data/assembly.sol
Original file line number Diff line number Diff line change
@@ -1,53 +1,61 @@
// SPDX-License-Identifier: MIT or APACHE2
pragma solidity ^0.8.0;

contract Assembly {
function switchStatement(uint256 x) public returns (uint256) {
uint256 y = x;
function switchStatement(uint256 x) public pure returns (uint256) {
uint256 y = x;
y;
assembly {
switch mod(x, 10)
case 1 {
x := add(x, 1)
}
case 2 {
x := add(x, 2)
}
case 3 {
x := add(x, 3)
}
case 4 {
x := add(x, 4)
}
default {
x := add(x, 10)
}
case 1 {
x := add(x, 1)
}
case 2 {
x := add(x, 2)
}
case 3 {
x := add(x, 3)
}
case 4 {
x := add(x, 4)
}
default {
x := add(x, 10)
}
}

return x;
}

function hasInline(uint256 a, uint256 b) public returns (uint256, uint256){
assembly {
a := add(100, a)
a := sub(a, 10)
a := div(a, 2)
a := mul(a, 2)
if lt(b, 200) {
b := 100
}
function hasInline(
uint256 a,
uint256 b
) public pure returns (uint256, uint256) {
assembly {
a := add(100, a)
a := sub(a, 10)
a := div(a, 2)
a := mul(a, 2)
if lt(b, 200) {
b := 100
}

// let c := 0x200
// let d := true
}
// let c := 0x200
// let d := true
}

if (b < 200) {
require(b == 100);
}
return (a, b);
}
if (b < 200) {
require(b == 100);
}
return (a, b);
}

function varDecl(uint256 a) public {
assembly {
let b := 200
let c := 0x200
let d := true
}
}
}
function varDecl(uint256 a) public pure {
a;
assembly {
let b := 200
let c := 0x200
let d := true
}
}
}
Loading

0 comments on commit 0e03166

Please sign in to comment.