mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-12 18:41:02 +00:00
Suport passing arbitrary llvm arguments (#271)
- Support for passing LLVM command line options via the prcoess input or providing one or more `--llvm-arg='..'` resolc CLI flag. This allows more fine-grained control over the LLVM backend configuration. - Make LLVM initialization idempotent. --------- Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
@@ -83,6 +83,8 @@ where
|
||||
current_function: Option<Rc<RefCell<Function<'ctx>>>>,
|
||||
/// The loop context stack.
|
||||
loop_stack: Vec<Loop<'ctx>>,
|
||||
/// The extra LLVM arguments that were used during target initialization.
|
||||
llvm_arguments: &'ctx [String],
|
||||
|
||||
/// The project dependency manager. It can be any entity implementing the trait.
|
||||
/// The manager is used to get information about contracts and their dependencies during
|
||||
@@ -223,6 +225,7 @@ where
|
||||
dependency_manager: Option<D>,
|
||||
include_metadata_hash: bool,
|
||||
debug_config: DebugConfig,
|
||||
llvm_arguments: &'ctx [String],
|
||||
) -> Self {
|
||||
Self::set_data_layout(llvm, &module);
|
||||
Self::link_stdlib_module(llvm, &module);
|
||||
@@ -250,6 +253,7 @@ where
|
||||
functions: HashMap::with_capacity(Self::FUNCTIONS_HASHMAP_INITIAL_CAPACITY),
|
||||
current_function: None,
|
||||
loop_stack: Vec::with_capacity(Self::LOOP_STACK_INITIAL_CAPACITY),
|
||||
llvm_arguments,
|
||||
|
||||
dependency_manager,
|
||||
include_metadata_hash,
|
||||
@@ -639,6 +643,7 @@ where
|
||||
self.optimizer.settings().to_owned(),
|
||||
self.include_metadata_hash,
|
||||
self.debug_config.clone(),
|
||||
self.llvm_arguments,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,12 +10,20 @@ pub fn create_context(
|
||||
llvm: &inkwell::context::Context,
|
||||
optimizer_settings: OptimizerSettings,
|
||||
) -> Context<DummyDependency> {
|
||||
crate::polkavm::initialize_target();
|
||||
crate::initialize_llvm(crate::Target::PVM, "resolc", Default::default());
|
||||
|
||||
let module = llvm.create_module("test");
|
||||
let optimizer = Optimizer::new(optimizer_settings);
|
||||
|
||||
Context::<DummyDependency>::new(llvm, module, optimizer, None, true, Default::default())
|
||||
Context::<DummyDependency>::new(
|
||||
llvm,
|
||||
module,
|
||||
optimizer,
|
||||
None,
|
||||
true,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -17,11 +17,6 @@ use sha3::Digest;
|
||||
use self::context::build::Build;
|
||||
use self::context::Context;
|
||||
|
||||
/// Initializes the PolkaVM target machine.
|
||||
pub fn initialize_target() {
|
||||
inkwell::targets::Target::initialize_riscv(&Default::default());
|
||||
}
|
||||
|
||||
/// Builds PolkaVM assembly text.
|
||||
pub fn build_assembly_text(
|
||||
contract_path: &str,
|
||||
@@ -94,6 +89,7 @@ pub trait Dependency {
|
||||
optimizer_settings: OptimizerSettings,
|
||||
include_metadata_hash: bool,
|
||||
debug_config: DebugConfig,
|
||||
llvm_arguments: &[String],
|
||||
) -> anyhow::Result<String>;
|
||||
|
||||
/// Resolves a full contract path.
|
||||
@@ -114,6 +110,7 @@ impl Dependency for DummyDependency {
|
||||
_optimizer_settings: OptimizerSettings,
|
||||
_include_metadata_hash: bool,
|
||||
_debug_config: DebugConfig,
|
||||
_llvm_arguments: &[String],
|
||||
) -> anyhow::Result<String> {
|
||||
Ok(String::new())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user