rustc: Introduce ABI versioning so we can change value representations without breaking the compiler

This commit is contained in:
Patrick Walton 2011-08-20 14:22:09 -07:00
parent 2f650038ad
commit 25416bfae1
6 changed files with 35 additions and 6 deletions

View file

@ -84,15 +84,20 @@ fn eq_res_info(a: &res_info, b: &res_info) -> bool {
ret a.did.crate == b.did.crate && a.did.node == b.did.node && a.t == b.t;
}
fn mk_global(ccx: &@crate_ctxt, name: &str, llval: ValueRef) -> ValueRef {
fn mk_global(ccx: &@crate_ctxt, name: &str, llval: ValueRef,
internal: bool) -> ValueRef {
let llglobal =
lib::llvm::llvm::LLVMAddGlobal(ccx.llmod, val_ty(llval),
str::buf(name));
lib::llvm::llvm::LLVMSetInitializer(llglobal, llval);
lib::llvm::llvm::LLVMSetGlobalConstant(llglobal, True);
lib::llvm::llvm::LLVMSetLinkage(llglobal,
lib::llvm::LLVMInternalLinkage as
lib::llvm::llvm::Linkage);
if (internal) {
lib::llvm::llvm::LLVMSetLinkage(llglobal,
lib::llvm::LLVMInternalLinkage as
lib::llvm::llvm::Linkage);
}
ret llglobal;
}
@ -510,7 +515,7 @@ fn gen_tag_shapes(ccx: &@crate_ctxt) -> ValueRef {
header += data;
header += lv_table;
ret mk_global(ccx, "tag_shapes", C_bytes(header));
ret mk_global(ccx, "tag_shapes", C_bytes(header), true);
}
fn gen_resource_shapes(ccx: &@crate_ctxt) -> ValueRef {
@ -523,7 +528,7 @@ fn gen_resource_shapes(ccx: &@crate_ctxt) -> ValueRef {
i += 1u;
}
ret mk_global(ccx, "resource_shapes", C_struct(dtors));
ret mk_global(ccx, "resource_shapes", C_struct(dtors), true);
}
fn gen_shape_tables(ccx: &@crate_ctxt) {

View file

@ -6926,6 +6926,12 @@ fn write_metadata(cx: &@crate_ctxt, crate: &@ast::crate) {
llvm::LLVMSetInitializer(llvm_used, C_array(t_ptr_i8, [llglobal]));
}
// Writes the current ABI version into the crate.
fn write_abi_version(ccx: &@crate_ctxt) {
shape::mk_global(ccx, "rust_abi_version", C_uint(abi::abi_version),
false);
}
fn trans_crate(sess: &session::session, crate: &@ast::crate, tcx: &ty::ctxt,
output: &str, amap: &ast_map::map) -> ModuleRef {
let llmod =
@ -7001,6 +7007,7 @@ fn trans_crate(sess: &session::session, crate: &@ast::crate, tcx: &ty::ctxt,
create_crate_map(ccx);
emit_tydescs(ccx);
shape::gen_shape_tables(ccx);
write_abi_version(ccx);
// Translate the metadata.
write_metadata(cx.ccx, crate);