Skip to content

Commit

Permalink
Don’t hardcode the x86 target (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
taahol committed Apr 14, 2024
1 parent c3c2efa commit 28b7c18
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@ static void cleanup(void)

void init_target(void)
{
#ifdef _WIN32
LLVMInitializeX86TargetInfo();
LLVMInitializeX86Target();
LLVMInitializeX86TargetMC();
LLVMInitializeX86AsmParser();
LLVMInitializeX86AsmPrinter();

#ifdef _WIN32
// Default is x86_64-pc-windows-msvc
strcpy(target.triple, "x86_64-pc-windows-gnu");
#else
LLVMInitializeAllTargetInfos();
LLVMInitializeAllTargets();
LLVMInitializeAllTargetMCs();
LLVMInitializeAllAsmParsers();
LLVMInitializeAllAsmPrinters();

char *triple = LLVMGetDefaultTargetTriple();
assert(strlen(triple) < sizeof target.triple);
strcpy(target.triple, triple);
Expand All @@ -37,7 +43,7 @@ void init_target(void)
assert(target.target_ref);

target.target_machine_ref = LLVMCreateTargetMachine(
target.target_ref, target.triple, "x86-64", "", LLVMCodeGenLevelDefault, LLVMRelocPIC, LLVMCodeModelDefault);
target.target_ref, target.triple, "", "", LLVMCodeGenLevelDefault, LLVMRelocPIC, LLVMCodeModelDefault);
assert(target.target_machine_ref);

target.target_data_ref = LLVMCreateTargetDataLayout(target.target_machine_ref);
Expand Down

0 comments on commit 28b7c18

Please sign in to comment.