Skip to content

Commit bce39bf

Browse files
committed
fix: mac debug
1 parent 86941f1 commit bce39bf

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ test:
2222
@cargo test --all
2323

2424
clean:
25-
@rm -f *.ll && rm -f *.bc && rm -rf *.dSYM && rm -f testout* && rm -f out*
25+
@rm -f *.ll && rm -f *.bc && rm -rf *.dSYM && rm -f testout* && rm -f out* && rm -f *.o

src/ast/builder/llvmbuilder.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,7 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for LLVMBuilder<'a, 'ctx> {
898898
}
899899
fn alloc(&self, name: &str, pltype: &PLType, ctx: &mut Ctx<'a>) -> ValueHandle {
900900
let builder = self.builder;
901+
builder.unset_current_debug_location();
901902
let lb = builder.get_insert_block().unwrap();
902903
match self
903904
.builder
@@ -920,17 +921,6 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for LLVMBuilder<'a, 'ctx> {
920921
None => panic!("alloc get entry failed!"),
921922
}
922923
}
923-
fn alloc_vtp(&self, name: &str, v: ValueHandle) -> ValueHandle {
924-
let alloca = self.builder.build_alloca::<BasicTypeEnum>(
925-
self.get_llvm_value(v)
926-
.unwrap()
927-
.get_type()
928-
.try_into()
929-
.unwrap(),
930-
name,
931-
);
932-
self.get_llvm_value_handle(&alloca.as_any_value_enum())
933-
}
934924
fn build_struct_gep(
935925
&self,
936926
structv: ValueHandle,

src/ast/builder/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ pub trait IRBuilder<'a, 'ctx> {
4040
line: u32,
4141
pltp: &PLType,
4242
) -> ValueHandle;
43-
fn alloc_vtp(&self, name: &str, v: ValueHandle) -> ValueHandle;
4443
fn alloc(&self, name: &str, pltype: &PLType, ctx: &mut Ctx<'a>) -> ValueHandle;
4544
fn build_conditional_branch(
4645
&self,

src/ast/builder/no_op_builder.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for NoOpBuilder {
4747
0
4848
}
4949

50-
fn alloc_vtp(&self, _name: &str, _v: super::ValueHandle) -> super::ValueHandle {
51-
0
52-
}
53-
5450
fn alloc(
5551
&self,
5652
_name: &str,

src/ast/compiler.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ pub fn compile_dry_file(db: &dyn Db, docs: FileCompileInput) -> Option<ModWrappe
144144

145145
#[salsa::tracked]
146146
pub fn compile(db: &dyn Db, docs: MemDocsInput, out: String, op: Options) {
147+
let targetdir = PathBuf::from("target");
148+
if !targetdir.exists() {
149+
fs::create_dir(&targetdir).unwrap();
150+
}
147151
let now = Instant::now();
148152
compile_dry(db, docs).unwrap();
149153
let errs = compile_dry::accumulated::<Diagnostics>(db, docs);
@@ -189,9 +193,15 @@ pub fn compile(db: &dyn Db, docs: MemDocsInput, out: String, op: Options) {
189193
return;
190194
}
191195
let mut mods = compile_dry::accumulated::<ModBuffer>(db, docs);
196+
let mut objs = vec![];
192197
let ctx = Context::create();
193198
let m = mods.pop().unwrap();
199+
let tm = get_target_machine(op.optimization.to_llvm());
194200
let llvmmod = Module::parse_bitcode_from_path(m.clone(), &ctx).unwrap();
201+
let o = m.with_extension("o");
202+
tm.write_to_file(&llvmmod, inkwell::targets::FileType::Object, &o)
203+
.unwrap();
204+
objs.push(o);
195205
let mut set = FxHashSet::default();
196206
set.insert(m.clone());
197207
_ = remove_file(m.clone()).unwrap();
@@ -201,8 +211,13 @@ pub fn compile(db: &dyn Db, docs: MemDocsInput, out: String, op: Options) {
201211
continue;
202212
}
203213
set.insert(m.clone());
214+
let o = m.with_extension("o");
204215
// println!("{}", m.clone().to_str().unwrap());
205-
_ = llvmmod.link_in_module(Module::parse_bitcode_from_path(m.clone(), &ctx).unwrap());
216+
let module = Module::parse_bitcode_from_path(m.clone(), &ctx).unwrap();
217+
tm.write_to_file(&module, inkwell::targets::FileType::Object, &o)
218+
.unwrap();
219+
objs.push(o);
220+
_ = llvmmod.link_in_module(module);
206221
_ = remove_file(m.clone()).unwrap();
207222
log::debug!("rm {}", m.to_str().unwrap());
208223
}
@@ -240,7 +255,6 @@ pub fn compile(db: &dyn Db, docs: MemDocsInput, out: String, op: Options) {
240255
let mut out = out.to_string();
241256
let pl_target = Target::host_target().expect("get host target failed");
242257
out.push_str(".bc");
243-
let tm = get_target_machine(op.optimization.to_llvm());
244258
llvmmod.set_triple(&tm.get_triple());
245259
llvmmod.set_data_layout(&tm.get_target_data().get_data_layout());
246260
llvmmod.write_bitcode_to_path(Path::new(&out));
@@ -278,8 +292,9 @@ pub fn compile(db: &dyn Db, docs: MemDocsInput, out: String, op: Options) {
278292
.to_string();
279293
// cmd.arg("-pthread").arg("-ldl");
280294
}
281-
282-
t.add_object(Path::new(&out)).unwrap();
295+
for o in objs {
296+
t.add_object(o.as_path()).unwrap();
297+
}
283298
t.add_object(Path::new(&vmpath)).unwrap();
284299
t.output_to(&fo);
285300
let res = t.finalize();

src/ast/node/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl Node for FuncCallNode {
159159
Some(v) => Ok((
160160
{
161161
builder.rm_curr_debug_location();
162-
let ptr = builder.alloc_vtp("ret_alloc_tmp", v);
162+
let ptr = builder.alloc("ret_alloc_tmp", &rettp.borrow(), ctx);
163163
builder.build_store(ptr, v);
164164
Some(plv!(ptr))
165165
},

src/ast/node/program.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ pub fn emit_file(db: &dyn Db, params: ProgramEmitParam) -> ModWrapper {
392392
let mut hasher = DefaultHasher::new();
393393
params.fullpath(db).hash(&mut hasher);
394394
let hashed = format!(
395-
"{}_{:x}",
395+
"target/{}_{:x}",
396396
Path::new(&params.file(db))
397397
.with_extension("")
398398
.to_str()

0 commit comments

Comments
 (0)