Skip to content

Commit 1ff3533

Browse files
authored
Merge pull request eclipse-omr#8025 from Deigue/openxl-ddr-encode
Fix encoding of numbers within Type names in DDR
2 parents 62abd73 + 91a39c9 commit 1ff3533

File tree

4 files changed

+41
-33
lines changed

4 files changed

+41
-33
lines changed

ddr/include/ddr/blobgen/java/genBinaryBlob.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,14 @@ class JavaBlobGenerator : public BlobGenerator
123123
};
124124

125125
BuildBlobInfo _buildInfo;
126-
bool _printEmptyTypes;
126+
OMRPortLibrary * const _portLibrary;
127+
bool const _printEmptyTypes;
127128

128129
void copyStringTable();
129130
DDR_RC stringTableOffset(BlobHeader *blobHeader, J9HashTable *stringTable, const char *cString, uint32_t *offset);
130131
DDR_RC countStructsAndStrings(Symbol_IR *ir);
131132
DDR_RC addFieldAndConstCount(bool addStructureCount, size_t fieldCount, size_t constCount);
132-
DDR_RC buildBlobData(OMRPortLibrary *portLibrary, Symbol_IR *ir);
133+
DDR_RC buildBlobData(Symbol_IR *ir);
133134
DDR_RC addBlobField(Field *field, uint32_t *fieldCount, size_t baseOffset, const string &prefix);
134135
DDR_RC addBlobConst(const string &name, long long value, uint32_t *constCount);
135136
DDR_RC addBlobStruct(const string &name, const string &superName, uint32_t constCount, uint32_t fieldCount, uint32_t size);
@@ -139,7 +140,12 @@ class JavaBlobGenerator : public BlobGenerator
139140
friend class BlobEnumerateVisitor;
140141

141142
public:
142-
explicit JavaBlobGenerator(bool printEmptyTypes) : _printEmptyTypes(printEmptyTypes) {}
143+
JavaBlobGenerator(struct OMRPortLibrary *portLibrary, bool printEmptyTypes)
144+
: _buildInfo()
145+
, _portLibrary(portLibrary)
146+
, _printEmptyTypes(printEmptyTypes)
147+
{
148+
}
143149
DDR_RC genBinaryBlob(struct OMRPortLibrary *portLibrary, Symbol_IR *ir, const char *blobFile);
144150
};
145151

ddr/lib/ddr-blobgen/java/genBinaryBlob.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "ddr/ir/TypeVisitor.hpp"
3030
#include "ddr/ir/TypedefUDT.hpp"
3131
#include "ddr/ir/UnionUDT.hpp"
32-
#include "ddr/std/sstream.hpp"
3332

3433
#undef NDEBUG
3534

@@ -48,7 +47,6 @@ using std::string;
4847
using std::pair;
4948
using std::make_pair;
5049
using std::vector;
51-
using std::stringstream;
5250

5351
#define INVALID_OFFSET (~(uint32_t)0)
5452

@@ -281,7 +279,7 @@ JavaBlobGenerator::genBinaryBlob(OMRPortLibrary *portLibrary, Symbol_IR *ir, con
281279
/* compute offsets for each entry of string hash table
282280
* compute size of string data - update blob header
283281
*/
284-
rc = buildBlobData(portLibrary, ir);
282+
rc = buildBlobData(ir);
285283
}
286284

287285
intptr_t fd = -1;
@@ -368,13 +366,13 @@ JavaBlobGenerator::countStructsAndStrings(Symbol_IR *ir)
368366
}
369367

370368
DDR_RC
371-
JavaBlobGenerator::buildBlobData(OMRPortLibrary *portLibrary, Symbol_IR *ir)
369+
JavaBlobGenerator::buildBlobData(Symbol_IR *ir)
372370
{
373371
DDR_RC rc = DDR_RC_OK;
374372

375373
/* allocate hashtable */
376374
_buildInfo.stringHash =
377-
hashTableNew(portLibrary, OMR_GET_CALLSITE(), 0,
375+
hashTableNew(_portLibrary, OMR_GET_CALLSITE(), 0,
378376
sizeof(StringTableEntry), 0, 0, OMRMEM_CATEGORY_UNKNOWN,
379377
stringTableHash, stringTableEquals, NULL, NULL);
380378

@@ -782,12 +780,14 @@ JavaBlobGenerator::addBlobStruct(const string &name, const string &superName, ui
782780
class BlobFieldVisitor : public TypeVisitor
783781
{
784782
private:
783+
OMRPortLibrary * const _portLibrary;
785784
string * const _typePrefix;
786785
string * const _typeSuffix;
787786

788787
public:
789-
explicit BlobFieldVisitor(string *prefix, string *suffix)
790-
: _typePrefix(prefix)
788+
BlobFieldVisitor(OMRPortLibrary *portLibrary, string *prefix, string *suffix)
789+
: _portLibrary(portLibrary)
790+
, _typePrefix(prefix)
791791
, _typeSuffix(suffix)
792792
{
793793
}
@@ -808,11 +808,11 @@ BlobFieldVisitor::visitType(Type *type) const
808808
size_t bitWidth = 0;
809809

810810
if (Type::isStandardType(typeName.c_str(), (size_t)typeName.length(), &isSigned, &bitWidth)) {
811-
stringstream newType;
811+
OMRPORT_ACCESS_FROM_OMRPORT(_portLibrary);
812+
char newType[32];
812813

813-
newType << (isSigned ? "I" : "U") << bitWidth;
814-
815-
*_typePrefix += newType.str();
814+
omrstr_printf(newType, sizeof(newType), "%c%zu", isSigned ? 'I' : 'U', bitWidth);
815+
*_typePrefix += newType;
816816
} else {
817817
*_typePrefix += typeName;
818818
}
@@ -860,11 +860,11 @@ BlobFieldVisitor::visitTypedef(TypedefUDT *type) const
860860
size_t bitWidth = 0;
861861

862862
if (Type::isStandardType(fullName.c_str(), (size_t)fullName.length(), &isSigned, &bitWidth)) {
863-
stringstream newType;
864-
865-
newType << (isSigned ? "I" : "U") << bitWidth;
863+
OMRPORT_ACCESS_FROM_OMRPORT(_portLibrary);
864+
char newType[32];
866865

867-
*_typePrefix += newType.str();
866+
omrstr_printf(newType, sizeof(newType), "%c%zu", isSigned ? 'I' : 'U', bitWidth);
867+
*_typePrefix += newType;
868868
} else {
869869
*_typePrefix += fullName;
870870
}
@@ -917,18 +917,22 @@ JavaBlobGenerator::formatFieldType(Field *field, string *fieldType)
917917
} else {
918918
typePrefix = field->_modifiers.getModifierNames();
919919

920-
rc = type->acceptVisitor(BlobFieldVisitor(&typePrefix, &typeSuffix));
920+
rc = type->acceptVisitor(BlobFieldVisitor(_portLibrary, &typePrefix, &typeSuffix));
921921
}
922922
}
923923

924924
if ((DDR_RC_OK == rc) && (NULL != type)) {
925-
stringstream bits;
925+
string bitField;
926926

927927
if (0 != field->_bitField) {
928-
bits << ":" << field->_bitField;
928+
OMRPORT_ACCESS_FROM_OMRPORT(_portLibrary);
929+
char width[32];
930+
931+
omrstr_printf(width, sizeof(width), ":%zu", field->_bitField);
932+
bitField = width;
929933
}
930934

931-
*fieldType = typePrefix + typeSuffix + bits.str();
935+
*fieldType = typePrefix + typeSuffix + bitField;
932936
}
933937

934938
return rc;

ddr/lib/ddr-blobgen/java/genBlobJava.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ genBlob(struct OMRPortLibrary *portLibrary, Symbol_IR *ir, const char *supersetF
3131
DDR_RC rc = DDR_RC_OK;
3232

3333
if (NULL != blobFile) {
34-
JavaBlobGenerator blobGenerator(printEmptyTypes);
34+
JavaBlobGenerator blobGenerator(portLibrary, printEmptyTypes);
3535

3636
rc = blobGenerator.genBinaryBlob(portLibrary, ir, blobFile);
3737

ddr/lib/ddr-blobgen/java/genSuperset.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@
2727
#include "ddr/ir/Symbol_IR.hpp"
2828
#include "ddr/ir/TypedefUDT.hpp"
2929
#include "ddr/ir/UnionUDT.hpp"
30-
#include "ddr/std/sstream.hpp"
3130

3231
#include <assert.h>
3332
#include <stdio.h>
3433

35-
using std::stringstream;
36-
3734
static string
3835
replaceAll(string str, const string &subStr, const string &newStr)
3936
{
@@ -94,11 +91,11 @@ JavaSupersetGenerator::replaceBaseTypedef(Type *type, string *name)
9491
* types such as "U_32" are replaced with "U32".
9592
*/
9693
if (Type::isStandardType(name->c_str() + start, (size_t)length, &isSigned, &bitWidth)) {
97-
stringstream ss;
98-
99-
ss << (isSigned ? "I" : "U") << bitWidth;
94+
OMRPORT_ACCESS_FROM_OMRPORT(_portLibrary);
95+
char newType[32];
10096

101-
name->replace(start, length, ss.str());
97+
omrstr_printf(newType, sizeof(newType), "%c%zu", isSigned ? 'I' : 'U', bitWidth);
98+
name->replace(start, length, newType);
10299
}
103100
}
104101

@@ -259,10 +256,11 @@ JavaSupersetGenerator::getFieldType(Field *field, string *assembledTypeName, str
259256
string bitField;
260257

261258
if ((DDR_RC_OK == rc) && (0 != field->_bitField)) {
262-
stringstream ss;
259+
OMRPORT_ACCESS_FROM_OMRPORT(_portLibrary);
260+
char width[32];
263261

264-
ss << ":" << field->_bitField;
265-
bitField = ss.str();
262+
omrstr_printf(width, sizeof(width), ":%zu", field->_bitField);
263+
bitField = width;
266264
}
267265

268266
/* Assemble the type name. */

0 commit comments

Comments
 (0)