mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-15 10:21:06 +00:00
Separate compilation and linker phases (#376)
Separate between compilation and linker phases to allow deploy time linking and back-porting era compiler changes to fix #91. Unlinked contract binaries (caused by missing libraries or missing factory dependencies in turn) are emitted as raw ELF object. Few drive by fixes: - #98 - A compiler panic on missing libraries definitions. - Fixes some incosistent type forwarding in JSON output (empty string vs. null object). - Remove the unused fallback for size optimization setting. - Remove the broken `--lvm-ir` mode. - CI workflow fixes. --------- Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com> Signed-off-by: xermicus <bigcyrill@hotmail.com> Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
@@ -2,18 +2,17 @@
|
||||
|
||||
use inkwell::values::BasicValue;
|
||||
|
||||
use revive_common::BIT_LENGTH_BYTE;
|
||||
use revive_common::BIT_LENGTH_WORD;
|
||||
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
|
||||
/// Translates the bitwise OR.
|
||||
pub fn or<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
pub fn or<'ctx>(
|
||||
context: &mut Context<'ctx>,
|
||||
operand_1: inkwell::values::IntValue<'ctx>,
|
||||
operand_2: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_or(operand_1, operand_2, "or_result")?
|
||||
@@ -21,14 +20,11 @@ where
|
||||
}
|
||||
|
||||
/// Translates the bitwise XOR.
|
||||
pub fn xor<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
pub fn xor<'ctx>(
|
||||
context: &mut Context<'ctx>,
|
||||
operand_1: inkwell::values::IntValue<'ctx>,
|
||||
operand_2: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_xor(operand_1, operand_2, "xor_result")?
|
||||
@@ -36,14 +32,11 @@ where
|
||||
}
|
||||
|
||||
/// Translates the bitwise AND.
|
||||
pub fn and<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
pub fn and<'ctx>(
|
||||
context: &mut Context<'ctx>,
|
||||
operand_1: inkwell::values::IntValue<'ctx>,
|
||||
operand_2: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_and(operand_1, operand_2, "and_result")?
|
||||
@@ -51,14 +44,11 @@ where
|
||||
}
|
||||
|
||||
/// Translates the bitwise shift left.
|
||||
pub fn shift_left<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
pub fn shift_left<'ctx>(
|
||||
context: &mut Context<'ctx>,
|
||||
shift: inkwell::values::IntValue<'ctx>,
|
||||
value: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
|
||||
let overflow_block = context.append_basic_block("shift_left_overflow");
|
||||
let non_overflow_block = context.append_basic_block("shift_left_non_overflow");
|
||||
let join_block = context.append_basic_block("shift_left_join");
|
||||
@@ -66,7 +56,7 @@ where
|
||||
let condition_is_overflow = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::UGT,
|
||||
shift,
|
||||
context.word_const((revive_common::BIT_LENGTH_WORD - 1) as u64),
|
||||
context.word_const((BIT_LENGTH_WORD - 1) as u64),
|
||||
"shift_left_is_overflow",
|
||||
)?;
|
||||
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
||||
@@ -93,14 +83,11 @@ where
|
||||
}
|
||||
|
||||
/// Translates the bitwise shift right.
|
||||
pub fn shift_right<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
pub fn shift_right<'ctx>(
|
||||
context: &mut Context<'ctx>,
|
||||
shift: inkwell::values::IntValue<'ctx>,
|
||||
value: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
|
||||
let overflow_block = context.append_basic_block("shift_right_overflow");
|
||||
let non_overflow_block = context.append_basic_block("shift_right_non_overflow");
|
||||
let join_block = context.append_basic_block("shift_right_join");
|
||||
@@ -108,7 +95,7 @@ where
|
||||
let condition_is_overflow = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::UGT,
|
||||
shift,
|
||||
context.word_const((revive_common::BIT_LENGTH_WORD - 1) as u64),
|
||||
context.word_const((BIT_LENGTH_WORD - 1) as u64),
|
||||
"shift_right_is_overflow",
|
||||
)?;
|
||||
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
||||
@@ -137,14 +124,11 @@ where
|
||||
}
|
||||
|
||||
/// Translates the arithmetic bitwise shift right.
|
||||
pub fn shift_right_arithmetic<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
pub fn shift_right_arithmetic<'ctx>(
|
||||
context: &mut Context<'ctx>,
|
||||
shift: inkwell::values::IntValue<'ctx>,
|
||||
value: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
|
||||
let overflow_block = context.append_basic_block("shift_right_arithmetic_overflow");
|
||||
let overflow_positive_block =
|
||||
context.append_basic_block("shift_right_arithmetic_overflow_positive");
|
||||
@@ -156,7 +140,7 @@ where
|
||||
let condition_is_overflow = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::UGT,
|
||||
shift,
|
||||
context.word_const((revive_common::BIT_LENGTH_WORD - 1) as u64),
|
||||
context.word_const((BIT_LENGTH_WORD - 1) as u64),
|
||||
"shift_right_arithmetic_is_overflow",
|
||||
)?;
|
||||
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
||||
@@ -164,7 +148,7 @@ where
|
||||
context.set_basic_block(overflow_block);
|
||||
let sign_bit = context.builder().build_right_shift(
|
||||
value,
|
||||
context.word_const((revive_common::BIT_LENGTH_WORD - 1) as u64),
|
||||
context.word_const((BIT_LENGTH_WORD - 1) as u64),
|
||||
false,
|
||||
"shift_right_arithmetic_sign_bit",
|
||||
)?;
|
||||
@@ -217,14 +201,11 @@ where
|
||||
/// Because this opcode returns zero on overflows, the index `operand_1`
|
||||
/// is checked for overflow. On overflow, the mask will be all zeros,
|
||||
/// resulting in a branchless implementation.
|
||||
pub fn byte<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
pub fn byte<'ctx>(
|
||||
context: &mut Context<'ctx>,
|
||||
operand_1: inkwell::values::IntValue<'ctx>,
|
||||
operand_2: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
|
||||
const MAX_INDEX_BYTES: u64 = 31;
|
||||
|
||||
let is_overflow_bit = context.builder().build_int_compare(
|
||||
@@ -254,16 +235,13 @@ where
|
||||
.build_int_truncate(operand_1, context.byte_type(), "index_truncated")?;
|
||||
let index_in_bits = context.builder().build_int_mul(
|
||||
index_truncated,
|
||||
context
|
||||
.byte_type()
|
||||
.const_int(revive_common::BIT_LENGTH_BYTE as u64, false),
|
||||
context.byte_type().const_int(BIT_LENGTH_BYTE as u64, false),
|
||||
"index_in_bits",
|
||||
)?;
|
||||
let index_from_most_significant_bit = context.builder().build_int_sub(
|
||||
context.byte_type().const_int(
|
||||
MAX_INDEX_BYTES * revive_common::BIT_LENGTH_BYTE as u64,
|
||||
false,
|
||||
),
|
||||
context
|
||||
.byte_type()
|
||||
.const_int(MAX_INDEX_BYTES * BIT_LENGTH_BYTE as u64, false),
|
||||
index_in_bits,
|
||||
"index_from_msb",
|
||||
)?;
|
||||
|
||||
Reference in New Issue
Block a user