llvm.org GIT mirror llvm / 68a590d
Add C API for specifying CPU to the disassembler. It was a nasty oversight that we didn't include this when we added this API in the first place. Blech. rdar://12839439 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169653 91177308-0d34-0410-b5e6-96231b3b80d8 Jim Grosbach 6 years ago
3 changed file(s) with 31 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
138138 * by passing a block of information in the DisInfo parameter and specifying the
139139 * TagType and callback functions as described above. These can all be passed
140140 * as NULL. If successful, this returns a disassembler context. If not, it
141 * returns NULL.
141 * returns NULL. This function is equivalent to calling LLVMCreateDisasmCPU()
142 * with an empty CPU name.
142143 */
143144 LLVMDisasmContextRef LLVMCreateDisasm(const char *TripleName, void *DisInfo,
144145 int TagType, LLVMOpInfoCallback GetOpInfo,
145146 LLVMSymbolLookupCallback SymbolLookUp);
147
148 /**
149 * Create a disassembler for the TripleName and a specific CPU. Symbolic
150 * disassembly is supported by passing a block of information in the DisInfo
151 * parameter and specifying the TagType and callback functions as described
152 * above. These can all be passed * as NULL. If successful, this returns a
153 * disassembler context. If not, it returns NULL.
154 */
155 LLVMDisasmContextRef LLVMCreateDisasmCPU(const char *Triple, const char *CPU,
156 void *DisInfo, int TagType,
157 LLVMOpInfoCallback GetOpInfo,
158 LLVMSymbolLookupCallback SymbolLookUp);
146159
147160 /**
148161 * Set the disassembler's options. Returns 1 if it can set the Options and 0
3232 // functions can all be passed as NULL. If successful, this returns a
3333 // disassembler context. If not, it returns NULL.
3434 //
35 LLVMDisasmContextRef LLVMCreateDisasm(const char *TripleName, void *DisInfo,
36 int TagType, LLVMOpInfoCallback GetOpInfo,
37 LLVMSymbolLookupCallback SymbolLookUp) {
35 LLVMDisasmContextRef LLVMCreateDisasmCPU(const char *Triple, const char *CPU,
36 void *DisInfo, int TagType,
37 LLVMOpInfoCallback GetOpInfo,
38 LLVMSymbolLookupCallback SymbolLookUp){
3839 // Get the target.
3940 std::string Error;
40 const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
41 const Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
4142 assert(TheTarget && "Unable to create target!");
4243
4344 // Get the assembler info needed to setup the MCContext.
44 const MCAsmInfo *MAI = TheTarget->createMCAsmInfo(TripleName);
45 const MCAsmInfo *MAI = TheTarget->createMCAsmInfo(Triple);
4546 assert(MAI && "Unable to create target asm info!");
4647
4748 const MCInstrInfo *MII = TheTarget->createMCInstrInfo();
4849 assert(MII && "Unable to create target instruction info!");
4950
50 const MCRegisterInfo *MRI = TheTarget->createMCRegInfo(TripleName);
51 const MCRegisterInfo *MRI = TheTarget->createMCRegInfo(Triple);
5152 assert(MRI && "Unable to create target register info!");
5253
5354 // Package up features to be passed to target/subtarget
5455 std::string FeaturesStr;
55 std::string CPU;
5656
57 const MCSubtargetInfo *STI = TheTarget->createMCSubtargetInfo(TripleName, CPU,
57 const MCSubtargetInfo *STI = TheTarget->createMCSubtargetInfo(Triple, CPU,
5858 FeaturesStr);
5959 assert(STI && "Unable to create subtarget info!");
6060
7373 *MAI, *MII, *MRI, *STI);
7474 assert(IP && "Unable to create instruction printer!");
7575
76 LLVMDisasmContext *DC = new LLVMDisasmContext(TripleName, DisInfo, TagType,
76 LLVMDisasmContext *DC = new LLVMDisasmContext(Triple, DisInfo, TagType,
7777 GetOpInfo, SymbolLookUp,
7878 TheTarget, MAI, MRI,
7979 STI, MII, Ctx, DisAsm, IP);
8080 assert(DC && "Allocation failure!");
8181
8282 return DC;
83 }
84
85 LLVMDisasmContextRef LLVMCreateDisasm(const char *Triple, void *DisInfo,
86 int TagType, LLVMOpInfoCallback GetOpInfo,
87 LLVMSymbolLookupCallback SymbolLookUp) {
88 return LLVMCreateDisasmCPU(Triple, "", DisInfo, TagType, GetOpInfo,
89 SymbolLookUp);
8390 }
8491
8592 //
2828 lto_codegen_set_cpu
2929 lto_codegen_compile_to_file
3030 LLVMCreateDisasm
31 LLVMCreateDisasmCPU
3132 LLVMDisasmDispose
3233 LLVMDisasmInstruction
3334 LLVMSetDisasmOptions