Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use clap::{Parser, ValueEnum};
use codegen::options::{BuildDir, CodeGenLinkerOptions, CodeGenOptions, CodeGenSanitizer, CodeModelOptions, RelocModeOptions};
use codegen::options::{
BuildDir, CodeGenLinkerOptions, CodeGenOptions, CodeGenSanitizer, CodeModelOptions, RelocModeOptions,
};
use commands::*;
use diagcentral::display_single_custom_diag;
use project_layout::PROJECT_FILE_PATH;
Expand Down Expand Up @@ -112,17 +114,17 @@ struct CompilerOptions {
#[clap(long, help = "Disables all warnings.")]
disable_warnings: bool,

#[clap(long, help = "Build artifacts in release mode, with optimizations.")]
release: bool,

#[clap(long, help = "Set cyrus standard library path.")]
stdlib: Option<String>,

#[clap(long = "target-machine", help = "Display Target Machine information.")]
display_target_machine: bool,

#[clap(long = "sanitize", help = "Enables dynamic code analysis for bug detection.")]
#[clap(
value_enum,
value_delimiter = ','
)]
#[clap(value_enum, value_delimiter = ',')]
pub sanitizer: Vec<Sanitizer>,

#[clap(long, value_enum, default_value_t = RelocMode::default(),
Expand Down Expand Up @@ -214,6 +216,7 @@ impl Sanitizer {
impl CompilerOptions {
pub fn to_compiler_options(&self) -> CodeGenOptions {
CodeGenOptions {
release: self.release,
sanitizer: self.sanitizer.iter().map(|s| s.to_compiler_sanitizer()).collect(),
linker_flags: self.linkerflags.clone(),
linker_options: CodeGenLinkerOptions::default(),
Expand Down
6 changes: 5 additions & 1 deletion crates/codegen/src/context/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,13 @@ impl CodeGenContext {

linker_command.arg("-o").arg(output_path);
linker_command.args(object_files_str_list);

linker_command.args(self.opts.linker_flags.clone());

if !self.opts.release {
linker_command.arg("-g");
linker_command.arg("-fno-omit-frame-pointer");
}

if !self.opts.sanitizer.is_empty() {
let sanitizer_flags: Vec<String> = self.opts.sanitizer.iter().map(|s| s.to_string()).collect();
let joined_flags = sanitizer_flags.join(",");
Expand Down
3 changes: 3 additions & 0 deletions crates/codegen/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use serde::Deserialize;

#[derive(Deserialize, Debug, Clone)]
pub struct CodeGenOptions {
pub release: bool,
pub sanitizer: Vec<CodeGenSanitizer>,
pub linker: Option<String>,
pub linker_options: CodeGenLinkerOptions,
Expand Down Expand Up @@ -82,11 +83,13 @@ impl CodeGenOptions {
linker_options: CodeGenLinkerOptions::default(),
linker_flags: Vec::new(),
sanitizer: Vec::new(),
release: false,
}
}

pub fn override_options(&mut self, instance: Self) {
*self = Self {
release: instance.release || self.release,
linker: instance.linker.or(self.linker.clone()),
project_type: instance.project_type.or(self.project_type.clone()),
project_name: instance.project_name.or(self.project_name.clone()),
Expand Down
4 changes: 1 addition & 3 deletions examples/main.cyr
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import std::libc{printf};

fn main() {

}
fn main() {}

// pub config = const struct {
// host = "127.0.0.1",
Expand Down