Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Update to codespan and codespan-reporting 0.6 #160

Merged
merged 5 commits into from
Jan 6, 2020
Merged
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
33 changes: 12 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ libloading = "0.5"
arret-syntax = { path = "../syntax" }
arret-runtime = { path = "../runtime" }
arret-runtime-syntax = { path = "../runtime-syntax" }
codespan = "0.3"
codespan-reporting = "0.3"
codespan = "0.7"
codespan-reporting = "0.7"
termcolor = "1"
rayon = "1"

Expand Down
73 changes: 33 additions & 40 deletions compiler/codegen/debug_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ use std::collections::HashMap;
use std::os::unix::ffi::OsStrExt;
use std::{env, ffi, ptr};

use codespan::FileName;

use llvm_sys::core::*;
use llvm_sys::debuginfo::*;
use llvm_sys::prelude::*;

use arret_syntax::datum::DataStr;
use arret_syntax::span::Span;

use crate::source::{FileMap, SourceLoader};
use crate::source::SourceLoader;

pub struct DebugInfoBuilder<'sl> {
pub llvm_dib: LLVMDIBuilderRef,

source_loader: &'sl SourceLoader,
current_dir: ffi::CString,
file_metadata: HashMap<FileName, Option<LLVMMetadataRef>>,
file_metadata: HashMap<codespan::FileId, Option<LLVMMetadataRef>>,
}

impl<'sl> DebugInfoBuilder<'sl> {
Expand Down Expand Up @@ -49,17 +47,13 @@ impl<'sl> DebugInfoBuilder<'sl> {
}

fn add_compile_unit_metadata(&mut self, optimised: bool, main_span: Span) {
let main_span_start = main_span.start();

let code_map = self.source_loader.code_map();
let main_file_map = if let Some(file_map) = code_map.find_file(main_span_start) {
file_map
let main_file_id = if let Some(file_id) = main_span.file_id() {
file_id
} else {
return;
};

let main_file_metadata = if let Some(metadata) = self.file_metadata(main_file_map.as_ref())
{
let main_file_metadata = if let Some(metadata) = self.file_metadata(main_file_id) {
metadata
} else {
return;
Expand Down Expand Up @@ -89,28 +83,25 @@ impl<'sl> DebugInfoBuilder<'sl> {
}
}

pub fn file_metadata(&mut self, file_map: &FileMap) -> Option<LLVMMetadataRef> {
if let Some(metadata) = self.file_metadata.get(file_map.name()) {
pub fn file_metadata(&mut self, file_id: codespan::FileId) -> Option<LLVMMetadataRef> {
if let Some(metadata) = self.file_metadata.get(&file_id) {
return *metadata;
}

let metadata = if let FileName::Real(ref filename) = file_map.name() {
ffi::CString::new(filename.to_string_lossy().as_bytes())
.ok()
.map(|c_filename| unsafe {
LLVMDIBuilderCreateFile(
self.llvm_dib,
c_filename.as_ptr() as *const _,
c_filename.as_bytes().len(),
self.current_dir.as_ptr() as *const _,
self.current_dir.as_bytes().len(),
)
})
} else {
None
};
let files = self.source_loader.files();
let filename = files.name(file_id);

let metadata = ffi::CString::new(filename).ok().map(|c_filename| unsafe {
LLVMDIBuilderCreateFile(
self.llvm_dib,
c_filename.as_ptr() as *const _,
c_filename.as_bytes().len(),
self.current_dir.as_ptr() as *const _,
self.current_dir.as_bytes().len(),
)
});

self.file_metadata.insert(file_map.name().clone(), metadata);
self.file_metadata.insert(file_id, metadata);
metadata
}

Expand All @@ -137,23 +128,25 @@ impl<'sl> DebugInfoBuilder<'sl> {
source_name: Option<&DataStr>,
llvm_function: LLVMValueRef,
) {
let span_start = span.start();

let code_map = self.source_loader.code_map();

let file_map = if let Some(file_map) = code_map.find_file(span_start) {
file_map
let file_id = if let Some(file_id) = span.file_id() {
file_id
} else {
return;
};

let line_index = if let Ok((line_index, _)) = file_map.location(span_start) {
line_index
let location = if let Ok(location) = self
.source_loader
.files()
.location(file_id, span.codespan_span().start())
{
location
} else {
return;
};

let file_metadata = if let Some(file_metadata) = self.file_metadata(file_map.as_ref()) {
let line_index = location.line.to_usize();

let file_metadata = if let Some(file_metadata) = self.file_metadata(file_id) {
file_metadata
} else {
return;
Expand All @@ -180,11 +173,11 @@ impl<'sl> DebugInfoBuilder<'sl> {
linkage_name_ptr,
linkage_name_len,
file_metadata,
line_index.number().0 as u32,
line_index as u32,
self.placeholder_subroutine_type(file_metadata),
source_name.is_none() as i32, // `IsLocalToUnit`
1, // `IsDefinition`
line_index.number().0 as u32, // `ScopeLine`
line_index as u32, // `ScopeLine`
LLVMDIFlags::LLVMDIFlagZero,
1, // `IsOptimized`
);
Expand Down
2 changes: 1 addition & 1 deletion compiler/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::{HashMap, HashSet};
use std::hash;
use std::sync::Arc;

use codespan_reporting::Diagnostic;
use codespan_reporting::diagnostic::Diagnostic;

use arret_syntax::datum::Datum;
use arret_syntax::span::Span;
Expand Down
Loading