Skip to main content

luaur_code_gen/functions/
get_assembly_from_ir.rs

1//! @interface-stub
2use alloc::string::String;
3use alloc::vec::Vec;
4
5use crate::enums::abix_64::ABIX64;
6use crate::enums::features_a_64::FeaturesA64;
7use crate::enums::target::Target;
8use crate::functions::get_assembly_from_ir_impl::{
9    get_assembly_from_ir_impl_a_64, get_assembly_from_ir_impl_x_64,
10};
11use crate::functions::get_cpu_features_a_64::get_cpu_features_a_64;
12use crate::functions::get_cpu_features_x_64::get_cpu_features_x_64;
13use crate::records::assembly_builder_a_64::AssemblyBuilderA64;
14use crate::records::assembly_builder_x_64::AssemblyBuilderX64;
15use crate::records::assembly_options::AssemblyOptions;
16use crate::records::ir_builder::IrBuilder;
17use crate::records::lowering_stats::LoweringStats;
18
19pub unsafe fn get_assembly_from_ir(
20    ir: &mut IrBuilder,
21    options: AssemblyOptions,
22    stats: *mut LoweringStats,
23) -> String {
24    match options.target {
25        Target::Host => {
26            #[cfg(target_arch = "aarch64")]
27            {
28                let cpu_features = get_cpu_features_a_64();
29                let mut build = AssemblyBuilderA64 {
30                    data: Vec::new(),
31                    code: Vec::new(),
32                    text: String::new(),
33                    log_text: false,
34                    features: 0,
35                    next_label: 1,
36                    pending_labels: Vec::new(),
37                    label_locations: Vec::new(),
38                    finalized: false,
39                    overflowed: false,
40                    data_pos: 0,
41                    code_pos: core::ptr::null_mut(),
42                    code_end: core::ptr::null_mut(),
43                };
44                build.assembly_builder_a_64_assembly_builder_a_64(
45                    options.include_assembly,
46                    cpu_features,
47                );
48
49                get_assembly_from_ir_impl_a_64(&mut build, ir, options, stats)
50            }
51
52            #[cfg(not(target_arch = "aarch64"))]
53            {
54                let cpu_features = get_cpu_features_x_64();
55                let mut build = AssemblyBuilderX64::assembly_builder_x_64_bool_i32(
56                    options.include_assembly,
57                    cpu_features,
58                );
59
60                get_assembly_from_ir_impl_x_64(&mut build, ir, options, stats)
61            }
62        }
63
64        Target::A64 => {
65            let mut build = AssemblyBuilderA64 {
66                data: Vec::new(),
67                code: Vec::new(),
68                text: String::new(),
69                log_text: false,
70                features: 0,
71                next_label: 1,
72                pending_labels: Vec::new(),
73                label_locations: Vec::new(),
74                finalized: false,
75                overflowed: false,
76                data_pos: 0,
77                code_pos: core::ptr::null_mut(),
78                code_end: core::ptr::null_mut(),
79            };
80            build.assembly_builder_a_64_assembly_builder_a_64(
81                options.include_assembly,
82                FeaturesA64::Feature_JSCVT as u32,
83            );
84
85            get_assembly_from_ir_impl_a_64(&mut build, ir, options, stats)
86        }
87
88        Target::A64_NoFeatures => {
89            let mut build = AssemblyBuilderA64 {
90                data: Vec::new(),
91                code: Vec::new(),
92                text: String::new(),
93                log_text: false,
94                features: 0,
95                next_label: 1,
96                pending_labels: Vec::new(),
97                label_locations: Vec::new(),
98                finalized: false,
99                overflowed: false,
100                data_pos: 0,
101                code_pos: core::ptr::null_mut(),
102                code_end: core::ptr::null_mut(),
103            };
104            build.assembly_builder_a_64_assembly_builder_a_64(options.include_assembly, 0);
105
106            get_assembly_from_ir_impl_a_64(&mut build, ir, options, stats)
107        }
108
109        Target::X64_Windows => {
110            let mut build = AssemblyBuilderX64::assembly_builder_x_64_bool_abix_64_i32(
111                options.include_assembly,
112                ABIX64::Windows,
113                0,
114            );
115
116            get_assembly_from_ir_impl_x_64(&mut build, ir, options, stats)
117        }
118
119        Target::X64_SystemV => {
120            let mut build = AssemblyBuilderX64::assembly_builder_x_64_bool_abix_64_i32(
121                options.include_assembly,
122                ABIX64::SystemV,
123                0,
124            );
125
126            get_assembly_from_ir_impl_x_64(&mut build, ir, options, stats)
127        }
128    }
129}