Skip to content

Commit

Permalink
(ByteCode) Deleted copy() from SgAsmJvmInstruction
Browse files Browse the repository at this point in the history
- Replaced by doing a deep copy using base class SgNode copy()
- Fixed regression of parent pointer setting (now done by ROSETTA)

LDRD-SI-1
  • Loading branch information
rasmussn committed Apr 20, 2023
1 parent 24da464 commit 23cd7a1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 59 deletions.
3 changes: 0 additions & 3 deletions src/AstNodes/BinaryAnalysis/SgAsmJvmInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ class SgAsmJvmInstruction: public SgAsmInstruction {
Rose::BinaryAnalysis::JvmInstructionKind kind = Rose::BinaryAnalysis::JvmInstructionKind::unknown;

public:
// Make a (moderately deep copy of this instruction.
SgAsmJvmInstruction* copy() const;

// Overrides are documented in the base class
virtual std::string description() const override;
virtual bool terminatesBasicBlock() override;
Expand Down
8 changes: 4 additions & 4 deletions src/Rose/BinaryAnalysis/ByteCode/Analysis.C
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ void Class::partition(const PartitionerPtr &partitioner) const

for (auto astInsn : instructions) {
// A copy of the instruction must be made if it is linked to ROSE's AST
SgAsmInstruction* insn{astInsn};
if (auto jvmInsn = dynamic_cast<SgAsmJvmInstruction*>(astInsn)) {
insn = jvmInsn->copy();
}
SgTreeCopy deep;
SgAsmInstruction* insn = isSgAsmInstruction(astInsn->copy(deep));
ASSERT_not_null(insn);
ASSERT_require(insn != astInsn);
ASSERT_require(insn->get_address() == astInsn->get_address());

// A new block is needed if this instruction is a target of a branch and nonterminal
va = insn->get_address();
Expand Down
46 changes: 19 additions & 27 deletions src/frontend/BinaryFormats/CliHeader.C
Original file line number Diff line number Diff line change
Expand Up @@ -77,45 +77,37 @@ SgAsmCliHeader* SgAsmCliHeader::parse()
ROSE_ASSERT(0 == p_managedNativeHeader && "Always 0");
data += 8;

#if PRINT_DEBUG
std::cout << "------------------------SgAsmCliHeader::parse-----------------------------\n";
std::cout << "... SgAsmCliHeader: name: " << get_name()->get_string()
<< ": offset: " << get_offset() << ": p_data: "
<< &(p_data[0])
<< std::endl;
std::cout << "... SgAsmCliHeader: cb: " << p_cb << std::endl;
std::cout << "... SgAsmCliHeader: majorRuntimeVersion: " << p_majorRuntimeVersion << std::endl;
std::cout << "... SgAsmCliHeader: minorRuntimeVersion: " << p_minorRuntimeVersion << std::endl;
std::cout << "... SgAsmCliHeader: metaData: " << p_metaData << std::endl;
std::cout << "... SgAsmCliHeader: flags: " << p_flags << std::endl;
std::cout << "... SgAsmCliHeader: entryPointToken: " << p_entryPointToken << std::endl;
std::cout << "... SgAsmCliHeader: resources: " << p_resources << std::endl;
std::cout << "... SgAsmCliHeader: strongNameSignature: " << p_strongNameSignature << std::endl;
std::cout << "... SgAsmCliHeader: codeManagerTable: " << p_codeManagerTable << std::endl;
std::cout << "... SgAsmCliHeader: vTableFixups: " << p_vTableFixups << std::endl;
std::cout << "... SgAsmCliHeader: exportAddressTableJumps: " << p_exportAddressTableJumps << std::endl;
std::cout << "... SgAsmCliHeader: managedNativeHeader: " << p_managedNativeHeader << std::endl;
std::cout << "\n";
#endif

/* Construct and parse the CIL metatdata root */
SgAsmCilMetadataRoot* metadata_root = new SgAsmCilMetadataRoot;
ASSERT_not_null(metadata_root);

/* metadataRoot must be set before parsing */
this->set_metadataRoot(metadata_root);
metadata_root->set_parent(this);

metadata_root->parse();
this->set_metadataRoot(metadata_root);

return this;
}

void SgAsmCliHeader::dump(FILE*f, const char* prefix, ssize_t idx) const
{
#if PRINT_DEBUG
std::cout << "SgAsmCliHeader::dump\n";
#endif
//TODO
//fprintf(f, "%s:%d:%d:%d\n", prefix, p_access_flags, p_name_index, p_descriptor_index);
fprintf(f, "%s:\n", prefix);
fprintf(f, " name: %s\n", get_name()->get_string().c_str());
fprintf(f, " offset: %llu\n", get_offset());
fprintf(f, " data: %s\n", &(p_data[0]));
fprintf(f, " cb: %u\n", p_cb);
fprintf(f, " majorRuntimeVersion: %u\n", p_majorRuntimeVersion);
fprintf(f, " minorRuntimeVersion: %u\n", p_minorRuntimeVersion);
fprintf(f, " metaData: %llu\n", p_metaData);
fprintf(f, " flags: %u\n", p_flags);
fprintf(f, " entryPointToken: %u\n", p_entryPointToken);
fprintf(f, " resources: %llu\n", p_resources);
fprintf(f, " strongNameSignature: %llu\n", p_strongNameSignature);
fprintf(f, " codeManagerTable: %llu\n", p_codeManagerTable);
fprintf(f, " vTableFixups: %llu\n", p_vTableFixups);
fprintf(f, " exportAddressTableJumps: %llu\n", p_exportAddressTableJumps);
fprintf(f, " managedNativeHeader: %llu\n", p_managedNativeHeader);
}

#endif // ROSE_ENABLE_BINARY_ANALYSIS
25 changes: 0 additions & 25 deletions src/frontend/Disassemblers/SgAsmJvmInstruction.C
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,6 @@ using namespace Rose; // temporary until this
using namespace Rose::BinaryAnalysis;
using JvmOp = JvmInstructionKind;

// Make a (moderately) deep copy of this instruction.
// The parent is set to null so that it is detached from the ROSE AST.
SgAsmJvmInstruction*
SgAsmJvmInstruction::copy() const {
auto insn = new SgAsmJvmInstruction(get_address(), get_mnemonic(), get_kind());

insn->set_parent(nullptr); // SgNode member
insn->set_comment(get_comment()); // SgAsmNode member
insn->set_raw_bytes(get_raw_bytes()); // SgAsmInstruction member

// Create new operand list
auto operands = new SgAsmOperandList;
insn->set_operandList(operands);
operands->set_parent(insn);

// Copy operands (warning they become aliased)
for (auto expr: get_operandList()->get_operands()) {
// At moment the operand isn't attached? Whine to inform of the need for exploration.
ASSERT_require(expr->get_parent() == nullptr);
operands->append_operand(expr);
}

return insn;
}

unsigned
SgAsmJvmInstruction::get_anyKind() const {
return static_cast<unsigned>(p_kind);
Expand Down

0 comments on commit 23cd7a1

Please sign in to comment.