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:
xermicus
2025-09-27 20:52:22 +02:00
committed by GitHub
parent 13faedf08a
commit 94ec34c4d5
169 changed files with 6288 additions and 5206 deletions
@@ -7,6 +7,12 @@ use num::Zero;
use serde::Deserialize;
use serde::Serialize;
use revive_common::BASE_DECIMAL;
use revive_common::BASE_HEXADECIMAL;
use revive_common::BYTE_LENGTH_WORD;
use revive_llvm_context::PolkaVMArgument;
use revive_llvm_context::PolkaVMContext;
use crate::error::Error;
use crate::lexer::token::lexeme::literal::boolean::Boolean as BooleanLiteral;
use crate::lexer::token::lexeme::literal::integer::Integer as IntegerLiteral;
@@ -72,13 +78,10 @@ impl Literal {
}
/// Converts the literal into its LLVM.
pub fn into_llvm<'ctx, D>(
pub fn into_llvm<'ctx>(
self,
context: &revive_llvm_context::PolkaVMContext<'ctx, D>,
) -> anyhow::Result<revive_llvm_context::PolkaVMArgument<'ctx>>
where
D: revive_llvm_context::PolkaVMDependency + Clone,
{
context: &PolkaVMContext<'ctx>,
) -> anyhow::Result<PolkaVMArgument<'ctx>> {
match self.inner {
LexicalLiteral::Boolean(inner) => {
let value = self
@@ -99,7 +102,7 @@ impl Literal {
BooleanLiteral::True => num::BigUint::one(),
};
Ok(revive_llvm_context::PolkaVMArgument::value(value).with_constant(constant))
Ok(PolkaVMArgument::value(value).with_constant(constant))
}
LexicalLiteral::Integer(inner) => {
let r#type = self.yul_type.unwrap_or_default().into_llvm(context);
@@ -118,16 +121,15 @@ impl Literal {
let constant = match inner {
IntegerLiteral::Decimal { ref inner } => {
num::BigUint::from_str_radix(inner.as_str(), revive_common::BASE_DECIMAL)
num::BigUint::from_str_radix(inner.as_str(), BASE_DECIMAL)
}
IntegerLiteral::Hexadecimal { ref inner } => {
num::BigUint::from_str_radix(&inner["0x".len()..], BASE_HEXADECIMAL)
}
IntegerLiteral::Hexadecimal { ref inner } => num::BigUint::from_str_radix(
&inner["0x".len()..],
revive_common::BASE_HEXADECIMAL,
),
}
.expect("Always valid");
Ok(revive_llvm_context::PolkaVMArgument::value(value).with_constant(constant))
Ok(PolkaVMArgument::value(value).with_constant(constant))
}
LexicalLiteral::String(inner) => {
let string = inner.inner;
@@ -136,7 +138,7 @@ impl Literal {
let mut hex_string = if inner.is_hexadecimal {
string.clone()
} else {
let mut hex_string = String::with_capacity(revive_common::BYTE_LENGTH_WORD * 2);
let mut hex_string = String::with_capacity(BYTE_LENGTH_WORD * 2);
let mut index = 0;
loop {
if index >= string.len() {
@@ -151,17 +153,16 @@ impl Literal {
index += 3;
} else if string[index..].starts_with('u') {
let codepoint_str = &string[index + 1..index + 5];
let codepoint = u32::from_str_radix(
codepoint_str,
revive_common::BASE_HEXADECIMAL,
)
.map_err(|error| {
anyhow::anyhow!(
"Invalid codepoint `{}`: {}",
codepoint_str,
error
)
})?;
let codepoint =
u32::from_str_radix(codepoint_str, BASE_HEXADECIMAL).map_err(
|error| {
anyhow::anyhow!(
"Invalid codepoint `{}`: {}",
codepoint_str,
error
)
},
)?;
let unicode_char = char::from_u32(codepoint).ok_or_else(|| {
anyhow::anyhow!("Invalid codepoint {}", codepoint)
})?;
@@ -197,16 +198,16 @@ impl Literal {
hex_string
};
if hex_string.len() > revive_common::BYTE_LENGTH_WORD * 2 {
if hex_string.len() > BYTE_LENGTH_WORD * 2 {
return Ok(revive_llvm_context::PolkaVMArgument::value(
r#type.const_zero().as_basic_value_enum(),
)
.with_original(string));
}
if hex_string.len() < revive_common::BYTE_LENGTH_WORD * 2 {
if hex_string.len() < BYTE_LENGTH_WORD * 2 {
hex_string.push_str(
"0".repeat((revive_common::BYTE_LENGTH_WORD * 2) - hex_string.len())
"0".repeat((BYTE_LENGTH_WORD * 2) - hex_string.len())
.as_str(),
);
}
@@ -218,7 +219,7 @@ impl Literal {
)
.expect("The value is valid")
.as_basic_value_enum();
Ok(revive_llvm_context::PolkaVMArgument::value(value).with_original(string))
Ok(PolkaVMArgument::value(value).with_original(string))
}
}
}