Skip to content

Commit

Permalink
Derive copy for SBPFVersion (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte authored Oct 9, 2024
1 parent c6c1929 commit 7732088
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ enum InstructionType {
NoOperand,
}

fn make_instruction_map(sbpf_version: &SBPFVersion) -> HashMap<String, (InstructionType, u8)> {
fn make_instruction_map(sbpf_version: SBPFVersion) -> HashMap<String, (InstructionType, u8)> {
let mut result = HashMap::new();

let alu_binary_ops = [
Expand Down Expand Up @@ -313,10 +313,10 @@ pub fn assemble<C: ContextObject>(
src: &str,
loader: Arc<BuiltinProgram<C>>,
) -> Result<Executable<C>, String> {
let sbpf_version = loader.get_config().enabled_sbpf_versions.end().clone();
let sbpf_version = *loader.get_config().enabled_sbpf_versions.end();

let statements = parse(src)?;
let instruction_map = make_instruction_map(&sbpf_version);
let instruction_map = make_instruction_map(sbpf_version);
let mut insn_ptr = 0;
let mut function_registry = FunctionRegistry::default();
let mut labels = HashMap::new();
Expand Down
10 changes: 5 additions & 5 deletions src/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,7 @@ mod tests {
}

fn create_mockup_executable(config: Config, program: &[u8]) -> Executable<TestContextObject> {
let sbpf_version = config.enabled_sbpf_versions.end().clone();
let sbpf_version = *config.enabled_sbpf_versions.end();
let mut function_registry =
FunctionRegistry::<BuiltinFunction<TestContextObject>>::default();
function_registry
Expand Down Expand Up @@ -1769,7 +1769,7 @@ mod tests {
let empty_program_machine_code_length = {
let config = Config {
noop_instruction_rate: 0,
enabled_sbpf_versions: sbpf_version.clone()..=sbpf_version.clone(),
enabled_sbpf_versions: sbpf_version..=sbpf_version,
..Config::default()
};
let mut executable = create_mockup_executable(config, &prog[0..0]);
Expand All @@ -1780,7 +1780,7 @@ mod tests {
.machine_code_length()
};
assert!(empty_program_machine_code_length <= MAX_EMPTY_PROGRAM_MACHINE_CODE_LENGTH);
empty_program_machine_code_length_per_version[sbpf_version.clone() as usize] =
empty_program_machine_code_length_per_version[sbpf_version as usize] =
empty_program_machine_code_length;
}

Expand Down Expand Up @@ -1814,7 +1814,7 @@ mod tests {

for sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] {
let empty_program_machine_code_length =
empty_program_machine_code_length_per_version[sbpf_version.clone() as usize];
empty_program_machine_code_length_per_version[sbpf_version as usize];

for mut opcode in 0x00..=0xFF {
let (registers, immediate) = match opcode {
Expand All @@ -1841,7 +1841,7 @@ mod tests {
}
let config = Config {
noop_instruction_rate: 0,
enabled_sbpf_versions: sbpf_version.clone()..=sbpf_version.clone(),
enabled_sbpf_versions: sbpf_version..=sbpf_version,
..Config::default()
};
let mut executable = create_mockup_executable(config, &prog);
Expand Down
2 changes: 1 addition & 1 deletion src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
};

/// Defines a set of sbpf_version of an executable
#[derive(Debug, PartialEq, PartialOrd, Eq, Clone)]
#[derive(Debug, PartialEq, PartialOrd, Eq, Clone, Copy)]
pub enum SBPFVersion {
/// The legacy format
V1,
Expand Down
2 changes: 1 addition & 1 deletion tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ fn test_err_divide_overflow() {
fn test_memory_instructions() {
for sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] {
let config = Config {
enabled_sbpf_versions: sbpf_version.clone()..=sbpf_version,
enabled_sbpf_versions: sbpf_version..=sbpf_version,
..Config::default()
};

Expand Down
2 changes: 1 addition & 1 deletion tests/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ fn test_sdiv_disabled() {
&assembly,
Arc::new(BuiltinProgram::new_loader(
Config {
enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version.clone(),
enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version,
..Config::default()
},
FunctionRegistry::default(),
Expand Down

0 comments on commit 7732088

Please sign in to comment.