Sto giocando con LLVM. Ho pensato di cambiare il valore di una costante nel codice intermedio. Tuttavia, per la classe llvm::ConstantInt, non vedo una funzione setvalue. Qualche idea su come posso modificare il valore di una costante nel codice IR?Valore impostato per llvm :: ConstantInt
6
A
risposta
12
ConstantInt è una fabbrica, non è vero? Classe ha la get method per costruire nuova costante:
/* ... return a ConstantInt for the given value. */
00069 static Constant *get(Type *Ty, uint64_t V, bool isSigned = false);
Quindi, penso, non è possibile modificare ConstantInt esistente. Se vuoi modificare IR, dovresti provare a cambiare il puntatore in argomento (cambia l'IR stesso, ma non l'oggetto costante).
Potrebbe essere che desideri qualcosa di simile (ricorda, non ho esperienza con LLVM e sono quasi sicuro che l'esempio non è corretto).
Instruction *I = /* your argument */;
/* check that instruction is of needed format, e.g: */
if (I->getOpcode() == Instruction::Add) {
/* read the first operand of instruction */
Value *oldvalue = I->getOperand(0);
/* construct new constant; here 0x1234 is used as value */
Value *newvalue = ConstantInt::get(oldValue->getType(), 0x1234);
/* replace operand with new value */
I->setOperand(0, newvalue);
}
Per "modificare" una costante sola c'è una soluzione (incremento e decremento are illustrated):
/// AddOne - Add one to a ConstantInt.
static Constant *AddOne(Constant *C) {
return ConstantExpr::getAdd(C, ConstantInt::get(C->getType(), 1));
}
/// SubOne - Subtract one from a ConstantInt.
static Constant *SubOne(ConstantInt *C) {
return ConstantInt::get(C->getContext(), C->getValue()-1);
}
PS, Constant.h ha importanti commentare nel accattonaggio sulla creazione e non di cancellazione Costanti http://llvm.org/docs/doxygen/html/Constant_8h_source.html
00035 /// Note that Constants are immutable (once created they never change)
00036 /// and are fully shared by structural equivalence. This means that two
00037 /// structurally equivalent constants will always have the same address.
00038 /// Constants are created on demand as needed and never deleted: thus clients
00039 /// don't have to worry about the lifetime of the objects.
00040 /// @brief LLVM Constant Representation
Problemi correlati
- 1. Come creare un ConstantInt in LLVM?
- 2. android sharedpreferences valore impostato
- 3. Valore impostato RoR per area testo
- 4. Rails collection_select valore impostato per include_blank
- 5. document.getElementById() valore non impostato il valore
- 6. LLVM valore di inserimento non ottimale?
- 7. valore html impostato da javascript?
- 8. Come sapere quale valore variabile è impostato per l'unione?
- 9. jquery valore impostato dei cookie per booleano VERO
- 10. Come impostare il valore impostato per l'opzione in CRM 2011?
- 11. Crea misto (valore impostato) CPPDEFINES in SCons
- 12. PowerShell - Oggetto IE, Errore valore impostato
- 13. panda DataFrame valore impostato su maschera booleana
- 14. Valore impostato del campo statico privato
- 15. Access asp: valore lable impostato con jquery?
- 16. eccezione LLVM gettando
- 17. Quanto spazio per un trampolino LLVM
- 18. impostato per vedere l'immagine
- 19. Edificio LLVM esempio
- 20. Condivisione di un puntatore C++ con codice JIT LLVM
- 21. LLVM Struct ritorno ottimizzazione
- 22. Infrastruttura del compilatore LLVM per architetture VLIW
- 23. Scelta dell'architettura CPU per LLVM/CLANG
- 24. LLVM è adatto per le lingue parallele?
- 25. Esiste un debugger per LLVM IR?
- 26. Lingua per compilatore basato su LLVM
- 27. Posso usare LLVM per analizzare Fortran?
- 28. LLVM costruire opzioni per ARM/Raspberry Pi
- 29. LLVM: modo corretto per creare/eliminare
- 30. php - filter_input - impostato sul valore predefinito se il tasto GET non impostato
La soluzione sembra buona, lo proverò :). – MetallicPriest
Spero che @Anton Korobeynikov risponda o commenta il mio codice. Inoltre dovresti sapere, che setOperand non può cambiare qualcosa che è una costante stessa. – osgx
Ha funzionato! Brillante per una persona (tu) che non l'ha mai usata! Verrà anche mostrato quanto bene sia scritto LLVM, poiché è così facile da imparare e usare! – MetallicPriest