Skip to content

Commit 4767962

Browse files
committed
Merge all run_program() functions of codegens into generate_programs()
This dramatically reduces the surface area between the compiler and the codegens which is important for further decoupling of them.
1 parent 81b8314 commit 4767962

6 files changed

Lines changed: 409 additions & 434 deletions

File tree

src/b.rs

Lines changed: 65 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,122 +1356,84 @@ pub unsafe fn main(mut argc: i32, mut argv: *mut*mut c_char) -> Option<()> {
13561356

13571357
match target {
13581358
Target::Gas_AArch64_Linux => {
1359-
if !*nobuild {
1360-
codegen::gas_aarch64::generate_program(
1361-
// Inputs
1362-
&c.program, program_path, garbage_base, da_slice(*linker), targets::Os::Linux, *nostdlib, *debug,
1363-
// Temporaries
1364-
&mut output, &mut cmd,
1365-
)?;
1366-
}
1367-
1368-
if *run {
1369-
codegen::gas_aarch64::run_program(&mut cmd, program_path, da_slice(run_args), Os::Linux)?;
1370-
}
1359+
codegen::gas_aarch64::generate_program(
1360+
// Inputs
1361+
&c.program, program_path, garbage_base,
1362+
da_slice(*linker), da_slice(run_args), targets::Os::Linux,
1363+
*nostdlib, *debug, *nobuild, *run,
1364+
// Temporaries
1365+
&mut output, &mut cmd,
1366+
)?;
13711367
}
13721368
Target::Gas_AArch64_Darwin => {
1373-
if !*nobuild {
1374-
codegen::gas_aarch64::generate_program(
1375-
// Inputs
1376-
&c.program, program_path, garbage_base, da_slice(*linker), targets::Os::Darwin, *nostdlib, *debug,
1377-
// Temporaries
1378-
&mut output, &mut cmd,
1379-
)?;
1380-
}
1381-
1382-
if *run {
1383-
codegen::gas_aarch64::run_program(&mut cmd, program_path, da_slice(run_args), Os::Darwin)?;
1384-
}
1369+
codegen::gas_aarch64::generate_program(
1370+
// Inputs
1371+
&c.program, program_path, garbage_base,
1372+
da_slice(*linker), da_slice(run_args), targets::Os::Darwin,
1373+
*nostdlib, *debug, *nobuild, *run,
1374+
// Temporaries
1375+
&mut output, &mut cmd,
1376+
)?;
13851377
}
13861378
Target::Gas_x86_64_Linux => {
1387-
if !*nobuild {
1388-
codegen::gas_x86_64::generate_program(
1389-
// Inputs
1390-
&c.program, program_path, garbage_base, da_slice(*linker), targets::Os::Linux, *nostdlib, *debug,
1391-
// Temporaries
1392-
&mut output, &mut cmd,
1393-
)?;
1394-
}
1395-
1396-
if *run {
1397-
codegen::gas_x86_64::run_program(&mut cmd, program_path, da_slice(run_args), Os::Linux)?
1398-
}
1379+
codegen::gas_x86_64::generate_program(
1380+
// Inputs
1381+
&c.program, program_path, garbage_base,
1382+
da_slice(*linker), da_slice(run_args), targets::Os::Linux,
1383+
*nostdlib, *debug, *nobuild, *run,
1384+
// Temporaries
1385+
&mut output, &mut cmd,
1386+
)?;
13991387
}
14001388
Target::Gas_x86_64_Windows => {
1401-
if !*nobuild {
1402-
codegen::gas_x86_64::generate_program(
1403-
// Inputs
1404-
&c.program, program_path, garbage_base, da_slice(*linker), targets::Os::Windows, *nostdlib, *debug,
1405-
// Temporaries
1406-
&mut output, &mut cmd,
1407-
)?;
1408-
}
1409-
1410-
if *run {
1411-
codegen::gas_x86_64::run_program(&mut cmd, program_path, da_slice(run_args), Os::Windows)?;
1412-
}
1413-
},
1389+
codegen::gas_x86_64::generate_program(
1390+
// Inputs
1391+
&c.program, program_path, garbage_base,
1392+
da_slice(*linker), da_slice(run_args), targets::Os::Windows,
1393+
*nostdlib, *debug, *nobuild, *run,
1394+
// Temporaries
1395+
&mut output, &mut cmd,
1396+
)?;
1397+
}
14141398
Target::Gas_x86_64_Darwin => {
1415-
if !*nobuild {
1416-
codegen::gas_x86_64::generate_program(
1417-
// Inputs
1418-
&c.program, program_path, garbage_base, da_slice(*linker), targets::Os::Darwin, *nostdlib, *debug,
1419-
// Temporaries
1420-
&mut output, &mut cmd,
1421-
)?;
1422-
}
1423-
1424-
if *run {
1425-
codegen::gas_x86_64::run_program(&mut cmd, program_path, da_slice(run_args), Os::Darwin)?;
1426-
}
1399+
codegen::gas_x86_64::generate_program(
1400+
// Inputs
1401+
&c.program, program_path, garbage_base,
1402+
da_slice(*linker), da_slice(run_args), targets::Os::Darwin,
1403+
*nostdlib, *debug, *nobuild, *run,
1404+
// Temporaries
1405+
&mut output, &mut cmd,
1406+
)?;
14271407
}
14281408
Target::Uxn => {
1429-
if !*nobuild {
1430-
codegen::uxn::generate_program(
1431-
// Inputs
1432-
&c.program, program_path, garbage_base, da_slice(*linker), *debug,
1433-
// Temporaries
1434-
&mut output, &mut cmd,
1435-
)?;
1436-
}
1437-
1438-
if *run {
1439-
// TODO: the exact uxn runner (`uxncli` or `uxnemu`) should be customizable via the codegen parameters (-C)
1440-
// when they are implemented. For now we are hardcoding the runner to be `uxncli` so it passes the CI.
1441-
// But ideally, for a better first impression purposes (especially when the user tries out examples/uxn/screen.b),
1442-
// the default runner should be `uxnemu`.
1443-
codegen::uxn::run_program(&mut cmd, c!("uxncli"), program_path, da_slice(run_args))?;
1444-
}
1409+
codegen::uxn::generate_program(
1410+
// Inputs
1411+
&c.program, program_path, garbage_base,
1412+
da_slice(*linker), da_slice(run_args),
1413+
*nostdlib, *debug, *nobuild, *run,
1414+
// Temporaries
1415+
&mut output, &mut cmd,
1416+
)?;
14451417
}
14461418
Target::Mos6502_Posix => {
1447-
let config = codegen::mos6502::parse_config_from_link_flags(da_slice(*linker))?;
1448-
1449-
if !*nobuild {
1450-
codegen::mos6502::generate_program(
1451-
// Inputs
1452-
&c.program, program_path, garbage_base, config, *debug,
1453-
// Temporaries
1454-
&mut output, &mut cmd,
1455-
)?;
1456-
}
1457-
1458-
if *run {
1459-
codegen::mos6502::run_program(&mut cmd, config, program_path, da_slice(run_args))?;
1460-
}
1419+
codegen::mos6502::generate_program(
1420+
// Inputs
1421+
&c.program, program_path, garbage_base,
1422+
da_slice(*linker), da_slice(run_args),
1423+
*nostdlib, *debug, *nobuild, *run,
1424+
// Temporaries
1425+
&mut output, &mut cmd,
1426+
)?;
14611427
}
14621428
Target::ILasm_Mono => {
1463-
if !*nobuild {
1464-
codegen::ilasm_mono::generate_program(
1465-
// Inputs
1466-
&c.program, program_path, garbage_base, da_slice(*linker), *debug,
1467-
// Temporaries
1468-
&mut output, &mut cmd,
1469-
)?;
1470-
}
1471-
1472-
if *run {
1473-
codegen::ilasm_mono::run_program(&mut cmd, program_path, da_slice(run_args))?;
1474-
}
1429+
codegen::ilasm_mono::generate_program(
1430+
// Inputs
1431+
&c.program, program_path, garbage_base,
1432+
da_slice(*linker), da_slice(run_args),
1433+
*nostdlib, *debug, *nobuild, *run,
1434+
// Temporaries
1435+
&mut output, &mut cmd,
1436+
)?;
14751437
}
14761438
}
14771439
Some(())

0 commit comments

Comments
 (0)