feat: use PolkaVM disassembler (#6)

Integrate the PolkaVM disassembler to fix `--asm` output

Co-authored-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
Chris
2024-05-03 06:31:24 -04:00
committed by GitHub
parent c547a9ef78
commit a75fc55133
28 changed files with 261 additions and 145 deletions
@@ -132,10 +132,7 @@ impl<D> revive_llvm_context::PolkaVMWriteLLVM<D> for Block
where
D: revive_llvm_context::PolkaVMDependency + Clone,
{
fn into_llvm(
self,
context: &mut revive_llvm_context::PolkaVMContext<D>,
) -> anyhow::Result<()> {
fn into_llvm(self, context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()> {
let current_function = context.current_function().borrow().name().to_owned();
let current_block = context.basic_block();
@@ -59,10 +59,7 @@ impl<D> revive_llvm_context::PolkaVMWriteLLVM<D> for Code
where
D: revive_llvm_context::PolkaVMDependency + Clone,
{
fn into_llvm(
self,
context: &mut revive_llvm_context::PolkaVMContext<D>,
) -> anyhow::Result<()> {
fn into_llvm(self, context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()> {
self.block.into_llvm(context)?;
Ok(())
@@ -911,9 +911,7 @@ impl FunctionCall {
Ok(Some(context.integer_const(256, 0).as_basic_value_enum()))
}
Name::CallValue => {
revive_llvm_context::polkavm_evm_ether_gas::value(context).map(Some)
}
Name::CallValue => revive_llvm_context::polkavm_evm_ether_gas::value(context).map(Some),
Name::Gas => revive_llvm_context::polkavm_evm_ether_gas::gas(context).map(Some),
Name::Balance => {
let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
@@ -940,8 +938,7 @@ impl FunctionCall {
.map(Some)
}
Name::Number => {
revive_llvm_context::polkavm_evm_contract_context::block_number(context)
.map(Some)
revive_llvm_context::polkavm_evm_contract_context::block_number(context).map(Some)
}
Name::BlockHash => {
let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
@@ -137,9 +137,7 @@ impl Expression {
match constant {
Some(constant) => Ok(Some(
revive_llvm_context::PolkaVMArgument::new_with_constant(
value, constant,
),
revive_llvm_context::PolkaVMArgument::new_with_constant(value, constant),
)),
None => Ok(Some(value.into())),
}
@@ -64,10 +64,7 @@ impl<D> revive_llvm_context::PolkaVMWriteLLVM<D> for ForLoop
where
D: revive_llvm_context::PolkaVMDependency + Clone,
{
fn into_llvm(
self,
context: &mut revive_llvm_context::PolkaVMContext<D>,
) -> anyhow::Result<()> {
fn into_llvm(self, context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()> {
self.initializer.into_llvm(context)?;
let condition_block = context.append_basic_block("for_condition");
@@ -109,9 +109,10 @@ impl FunctionDefinition {
arguments.remove(0);
}
if identifier.inner.contains(
revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_EXCEPTION_HANDLER,
) && !arguments.is_empty()
if identifier
.inner
.contains(revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_EXCEPTION_HANDLER)
&& !arguments.is_empty()
{
return Err(ParserError::InvalidNumberOfArguments {
location,
@@ -52,10 +52,7 @@ impl<D> revive_llvm_context::PolkaVMWriteLLVM<D> for IfConditional
where
D: revive_llvm_context::PolkaVMDependency + Clone,
{
fn into_llvm(
self,
context: &mut revive_llvm_context::PolkaVMContext<D>,
) -> anyhow::Result<()> {
fn into_llvm(self, context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()> {
let condition = self
.condition
.into_llvm(context)?
@@ -219,16 +219,11 @@ where
Ok(())
}
fn into_llvm(
self,
context: &mut revive_llvm_context::PolkaVMContext<D>,
) -> anyhow::Result<()> {
fn into_llvm(self, context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()> {
if self.identifier.ends_with("_deployed") {
revive_llvm_context::PolkaVMRuntimeCodeFunction::new(self.code)
.into_llvm(context)?;
revive_llvm_context::PolkaVMRuntimeCodeFunction::new(self.code).into_llvm(context)?;
} else {
revive_llvm_context::PolkaVMDeployCodeFunction::new(self.code)
.into_llvm(context)?;
revive_llvm_context::PolkaVMDeployCodeFunction::new(self.code).into_llvm(context)?;
}
match self.inner_object {
@@ -122,10 +122,7 @@ impl<D> revive_llvm_context::PolkaVMWriteLLVM<D> for Switch
where
D: revive_llvm_context::PolkaVMDependency + Clone,
{
fn into_llvm(
self,
context: &mut revive_llvm_context::PolkaVMContext<D>,
) -> anyhow::Result<()> {
fn into_llvm(self, context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()> {
let scrutinee = self.expression.into_llvm(context)?;
if self.cases.is_empty() {