Skip to content

Commit 59c53aa

Browse files
committed
Argument node
1 parent 0c35ae4 commit 59c53aa

File tree

8 files changed

+20
-9
lines changed

8 files changed

+20
-9
lines changed

include/Builder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Builder {
1919
Node &newBasicBlockNode();
2020
Node &newInstructionNode();
2121
Node &newValueNode();
22+
Node &newArgumentNode();
2223
Node &newTypeNode();
2324

2425
Edge &newEdge(uint64_t source, uint64_t target);

include/Emitter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Emitter {
3636
Node &newBasicBlockNode(const llvm::Value *value);
3737
Node &newInstructionNode(const llvm::Value *value);
3838
Node &newValueNode(const llvm::Value *value);
39+
Node &newArgumentNode(const llvm::Value *value);
3940

4041
Node &node(const llvm::Value *value);
4142

include/Node.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66

77
namespace llvm2graphml {
88

9-
enum class NodeKind { Module, Function, BasicBlock, Instruction, Value, Type };
9+
enum class NodeKind { Module, Function, Argument, BasicBlock, Instruction, Value, Type };
1010

1111
enum class ValueKind {
12-
Argument,
1312
ConstantInt,
1413
ConstantFP,
1514
ConstantPointerNull,

src/Builder.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ Node &Builder::newValueNode() {
4444
return newNode(NodeKind::Value);
4545
}
4646

47+
Node &Builder::newArgumentNode() {
48+
return newNode(NodeKind::Argument);
49+
}
50+
4751
Node &Builder::newTypeNode() {
4852
return newNode(NodeKind::Type);
4953
}
50-
51-
/// Edge Connectors

src/EdgeConnector.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Edge &EdgeConnector::function(Node &to) {
2424
}
2525

2626
Edge &EdgeConnector::argument(const Node &to) {
27+
assert(to.getKind() == NodeKind::Argument);
2728
return edge(to.getID(), EdgeKind::Argument);
2829
}
2930

src/Emitter.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ Node &Emitter::emit(const llvm::Value *value) {
9797
case llvm::Value::BasicBlockVal: {
9898
fillIn(llvm::cast<llvm::BasicBlock>(value), newBasicBlockNode(value));
9999
} break;
100+
case llvm::Value::ArgumentVal: {
101+
fillIn(llvm::cast<llvm::Argument>(value), newArgumentNode(value));
102+
} break;
100103

101104
#define GRAPHML_HANDLE_VALUE(Name) \
102105
case Value::Name##Val: { \
@@ -114,7 +117,6 @@ Node &Emitter::emit(const llvm::Value *value) {
114117
GRAPHML_HANDLE_VALUE(GlobalAlias)
115118
GRAPHML_HANDLE_VALUE(GlobalIFunc)
116119
GRAPHML_HANDLE_VALUE(GlobalVariable)
117-
GRAPHML_HANDLE_VALUE(Argument)
118120
#include "llvm/IR/Value.def"
119121
#undef GRAPHML_HANDLE_VALUE
120122
default:
@@ -157,6 +159,12 @@ Node &Emitter::newValueNode(const llvm::Value *value) {
157159
return node;
158160
}
159161

162+
Node &Emitter::newArgumentNode(const llvm::Value *value) {
163+
Node &node = builder.newArgumentNode();
164+
emittedValues[value] = &node;
165+
return node;
166+
}
167+
160168
Node &Emitter::node(const llvm::Value *value) {
161169
return *emittedValues.at(value);
162170
}

src/Node.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ static std::string nodeKindToString(NodeKind kind) {
1818
return "value";
1919
case NodeKind::Type:
2020
return "type";
21+
case NodeKind::Argument:
22+
return "argument";
2123
}
2224
}
2325

2426
static std::string valueKindToString(ValueKind kind) {
2527
switch (kind) {
26-
case ValueKind::Argument:
27-
return "argument";
2828
case ValueKind::ConstantInt:
2929
return "constantInt";
3030
case ValueKind::ConstantFP:

tests/integration-tests/instruction/test.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ dump(g.V().has('basicBlock', 'name', 'entry')
8686
dump(g.V().has('basicBlock', 'name', 'entry')
8787
.out('instruction').has('opcode', 'icmp')
8888
.outE('operand').has('order', 0).inV()
89-
.valueMap('name', 'kind').order().by(values))
90-
// CHECK-NEXT: kind=[argument]
89+
.valueMap('name').order().by(values))
9190
// CHECK-NEXT: name=[x]
9291

9392
:exit

0 commit comments

Comments
 (0)