Skip to content

Commit 475fa2f

Browse files
committed
wip
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
1 parent fad58ef commit 475fa2f

7 files changed

Lines changed: 37 additions & 23 deletions

File tree

crates/llvm-context/src/polkavm/context/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ impl<'ctx> Context<'ctx> {
316316
)
317317
})?;
318318

319-
let object = revive_linker::Linker::setup(true)?.link(buffer.as_slice(), None)?;
319+
//let object = revive_linker::Linker::setup(true)?.link(buffer.as_slice(), None)?;
320+
let object = buffer.as_slice().to_vec();
320321

321322
self.debug_config.dump_object(contract_path, &object)?;
322323

crates/llvm-context/src/polkavm/evm/call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub fn linker_symbol<'ctx>(
198198
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
199199
context.declare_global(
200200
&path,
201-
context.integer_type(revive_common::BYTE_LENGTH_ETH_ADDRESS),
201+
context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
202202
Default::default(),
203203
);
204204
context.build_load_address(context.get_global(path)?.into())

crates/llvm-context/src/polkavm/mod.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,24 @@ pub fn build(
3030
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_WORD]>,
3131
debug_config: &DebugConfig,
3232
) -> anyhow::Result<Build> {
33-
let program_blob = ProgramBlob::parse(bytecode.into())
34-
.map_err(anyhow::Error::msg)
35-
.with_context(|| format!("Failed to parse program blob for contract: {contract_path}"))?;
33+
//let program_blob = ProgramBlob::parse(bytecode.into())
34+
// .map_err(anyhow::Error::msg)
35+
// .with_context(|| format!("Failed to parse program blob for contract: {contract_path}"))?;
3636

37-
let mut disassembler = Disassembler::new(&program_blob, DisassemblyFormat::Guest)
38-
.map_err(anyhow::Error::msg)
39-
.with_context(|| format!("Failed to create disassembler for contract: {contract_path}"))?;
40-
disassembler.display_gas()?;
37+
//let mut disassembler = Disassembler::new(&program_blob, DisassemblyFormat::Guest)
38+
// .map_err(anyhow::Error::msg)
39+
// .with_context(|| format!("Failed to create disassembler for contract: {contract_path}"))?;
40+
//disassembler.display_gas()?;
4141

42-
let mut disassembled_code = Vec::new();
43-
disassembler
44-
.disassemble_into(&mut disassembled_code)
45-
.with_context(|| format!("Failed to disassemble contract: {contract_path}"))?;
42+
//let mut disassembled_code = Vec::new();
43+
//disassembler
44+
// .disassemble_into(&mut disassembled_code)
45+
// .with_context(|| format!("Failed to disassemble contract: {contract_path}"))?;
4646

47-
let assembly_text = String::from_utf8(disassembled_code).with_context(|| {
48-
format!("Failed to convert disassembled code to string for contract: {contract_path}")
49-
})?;
47+
//let assembly_text = String::from_utf8(disassembled_code).with_context(|| {
48+
// format!("Failed to convert disassembled code to string for contract: {contract_path}")
49+
//})?;
50+
let assembly_text = "";
5051

5152
debug_config.dump_assembly(contract_path, &assembly_text)?;
5253

@@ -79,8 +80,11 @@ pub fn link(
7980
Ok(value @ ObjectFormat::PVM) => Ok((bytecode, value)),
8081
Ok(ObjectFormat::ELF) => {
8182
let symbols = build_symbols(linker_symbols, factory_dependencies)?;
82-
let bytecode_linked = revive_linker::Linker::setup(false)?
83+
let mut bytecode_linked = revive_linker::Linker::setup(true)?
8384
.link(bytecode.as_slice(), Some(symbols.as_slice()))?;
85+
if let Ok(pvm) = revive_linker::polkavm_linker(&bytecode_linked, true) {
86+
bytecode_linked = pvm;
87+
}
8488
Ok((
8589
MemoryBuffer::create_from_memory_range(&bytecode_linked, "bytecode_linked"),
8690
ObjectFormat::try_from(bytecode_linked.as_slice())
@@ -102,6 +106,7 @@ pub fn build_symbols(
102106

103107
for (name, value) in linker_symbols {
104108
let global_value = module.add_global(address_type, Default::default(), name);
109+
global_value.set_linkage(inkwell::module::Linkage::External);
105110
global_value.set_initializer(
106111
&address_type
107112
.const_int_from_string(
@@ -114,6 +119,7 @@ pub fn build_symbols(
114119

115120
for (name, value) in factory_dependencies {
116121
let global_value = module.add_global(word_type, Default::default(), name);
122+
global_value.set_linkage(inkwell::module::Linkage::External);
117123
global_value.set_initializer(
118124
&word_type
119125
.const_int_from_string(

crates/resolc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ pub fn standard_json<T: Compiler>(
226226
let detect_missing_libraries =
227227
solc_input.settings.detect_missing_libraries || detect_missing_libraries;
228228

229+
solc_input.extend_selection(SolcStandardJsonInputSettingsSelection::new_required());
229230
let mut solc_output = solc.standard_json(
230231
&mut solc_input,
231232
messages,

crates/resolc/src/process/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ pub trait Process {
2626

2727
let source_location = SourceLocation::new(input.contract.identifier.path.to_owned());
2828

29-
initialize_llvm(
30-
Target::PVM,
31-
crate::DEFAULT_EXECUTABLE_NAME,
32-
&input.llvm_arguments,
33-
);
34-
3529
let result = std::thread::Builder::new()
3630
.stack_size(64 * 1024 * 1024)
3731
.spawn(move || {

crates/resolc/src/resolc/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{io::Write, path::PathBuf};
77

88
use resolc::Process;
99
use revive_common::MetadataHash;
10+
use revive_llvm_context::initialize_llvm;
1011
use revive_solc_json_interface::{
1112
SolcStandardJsonInputSettingsSelection, SolcStandardJsonOutput, SolcStandardJsonOutputError,
1213
};
@@ -90,6 +91,12 @@ fn main_inner(
9091
return Ok(());
9192
}
9293

94+
initialize_llvm(
95+
revive_llvm_context::Target::PVM,
96+
resolc::DEFAULT_EXECUTABLE_NAME,
97+
&arguments.llvm_arguments,
98+
);
99+
93100
#[cfg(feature = "parallel")]
94101
rayon::ThreadPoolBuilder::new()
95102
.stack_size(RAYON_WORKER_STACK_SIZE)

crates/solc-json-interface/src/standard_json/input/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,9 @@ impl Input {
138138
suppressed_warnings,
139139
})
140140
}
141+
142+
/// Extends the output selection with another one.
143+
pub fn extend_selection(&mut self, selection: SolcStandardJsonInputSettingsSelection) {
144+
self.settings.extend_selection(selection);
145+
}
141146
}

0 commit comments

Comments
 (0)