MCPcopy Create free account
hub / github.com/IntegralPilot/rustc_codegen_jvm / oomir_to_jvm_bytecode

Function oomir_to_jvm_bytecode

src/lower2.rs:35–263  ·  view source on GitHub ↗

Converts an OOMIR module into JVM class files Returns a HashMap where the key is the JVM class name (with '/') and the value is the bytecode

(
    module: &oomir::Module,
    _tcx: TyCtxt, // Keep tcx in signature if needed later, but unused now
)

Source from the content-addressed store, hash-verified

33};
34
35mod constant_pool;
36mod consts;
37mod helpers;
38mod jvm;
39mod jvm_gen;
40mod large_methods;
41mod optimise2;
42mod stackmaps;
43mod translator;
44
45pub const F128_CLASS: &str = "org/rustlang/runtime/F128";
46pub const I128_CLASS: &str = "org/rustlang/runtime/I128";
47pub const U128_CLASS: &str = "org/rustlang/runtime/U128";
48
49static OUTPUT_DIRECTORY_COUNTER: AtomicUsize = AtomicUsize::new(0);
50
51#[derive(Default)]
52pub(crate) struct EmittedClassRegistry {
53 variants: Mutex<HashMap<String, Vec<Arc<EmittedClassVariant>>>>,
54}
55
56struct EmittedClassVariant {
57 hash: u64,
58 len: usize,
59 state: Mutex<EmittedClassState>,
60 ready: Condvar,
61}
62
63enum EmittedClassState {
64 Pending,
65 Ready(Arc<[u8]>),
66}
67
68fn bytecode_hash(bytecode: &[u8]) -> u64 {
69 bytecode.iter().fold(0xcbf29ce484222325u64, |hash, byte| {
70 (hash ^ u64::from(*byte)).wrapping_mul(0x100000001b3)
71 })
72}
73
74fn factory_return_instruction(ty: &oomir::Type) -> Instruction {
75 match ty {
76 oomir::Type::I8
77 | oomir::Type::U8
78 | oomir::Type::I16
79 | oomir::Type::U16
80 | oomir::Type::F16
81 | oomir::Type::I32
82 | oomir::Type::U32
83 | oomir::Type::Boolean
84 | oomir::Type::Char => Instruction::Ireturn,
85 oomir::Type::I64 | oomir::Type::U64 => Instruction::Lreturn,
86 oomir::Type::F32 => Instruction::Freturn,
87 oomir::Type::F64 => Instruction::Dreturn,
88 oomir::Type::Str
89 | oomir::Type::Class(_)
90 | oomir::Type::Array(_)
91 | oomir::Type::Slice(_)
92 | oomir::Type::Reference(_)

Callers 1

codegen_crateMethod · 0.85

Calls 13

to_stringMethod · 0.80
add_classMethod · 0.80
add_utf8Method · 0.80
translateMethod · 0.80
into_innerMethod · 0.80
clean_duplicatesMethod · 0.80

Tested by

no test coverage detected