Skip to content

Commit b93367e

Browse files
Version 1.4.19 std::array/std::vector fixed
1 parent 720f9d2 commit b93367e

File tree

228 files changed

+5255
-1033
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+5255
-1033
lines changed

sc_tool/lib/sc_tool/SCTool.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,16 @@ namespace sc {
9090
);
9191

9292
// Pass command line options to Clang tooling for parsing
93-
CommonOptionsParser op(args.argc, args.argv, ScToolCategory);
94-
ClangTool Tool(op.getCompilations(), op.getSourcePathList());
93+
//CommonOptionsParser op(args.argc, args.argv, ScToolCategory);
94+
auto op = CommonOptionsParser::create(args.argc, args.argv, ScToolCategory,
95+
llvm::cl::OneOrMore);
96+
97+
if (!op) {
98+
auto error = op.takeError();
99+
outs() << "Errors happen during parsing parameters\n";
100+
}
101+
102+
ClangTool Tool(op.get().getCompilations(), op.get().getSourcePathList());
95103

96104
// Run SVC
97105
auto factory = getNewSCElabActionFactory();

sc_tool/lib/sc_tool/SCToolFrontendAction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ Object* getOuterArray(SCDesign& designDB, Object* memberObj)
112112
return arrayObj;
113113
}
114114

115-
const std::string SCElabASTConsumer::TOOL_VERSION = "1.4.18";
116-
const std::string SCElabASTConsumer::TOOL_DATE = "15 Apr,2022";
115+
const std::string SCElabASTConsumer::TOOL_VERSION = "1.4.19";
116+
const std::string SCElabASTConsumer::TOOL_DATE = "22 Apr,2022";
117117

118118
void SCElabASTConsumer::HandleTranslationUnit(clang::ASTContext &astCtx)
119119
{
@@ -139,7 +139,7 @@ void SCElabASTConsumer::HandleTranslationUnit(clang::ASTContext &astCtx)
139139
//const char* optNames[] = {doConstCfg, doConstStmt, doModuleBuilder};
140140
//const char* optNames[] = {doGenFuncCall, doGenStmt, doModuleBuilder};
141141
//const char* optNames[] = {doConstStmt, doUseDef, doModuleBuilder};
142-
const char* optNames[] = {doUseDef, doConstStmt, doModuleBuilder};
142+
const char* optNames[] = {doModuleBuilder};
143143
size_t optSize = sizeof(optNames)/sizeof(const char*);
144144
//DebugOptions::enable(optNames, optSize);
145145

sc_tool/lib/sc_tool/ScProcAnalyzer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ void ScProcAnalyzer::initNonDefinedVars(sc_elab::ProcessView& procView,
543543
// cout << " verVar " << verVar->getName() << endl;
544544
// if (!initVals.empty()) {
545545
// cout << " add localparam for " << val;
546-
// for (auto& iv : initVals) cout << " " << iv.toString(10);
546+
// for (auto& iv : initVals) cout << " " << sc::APSintToString(iv, 10);
547547
// cout << endl;
548548
// } else {
549549
// cout << " add localparam for EMPTY" << endl;

sc_tool/lib/sc_tool/cfg/SValue.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
#include "sc_tool/cfg/SValue.h"
13+
#include "sc_tool/utils/StringFormat.h"
1314
#include "sc_tool/utils/ScTypeTraits.h"
1415
#include "sc_tool/utils/CppTypeTraits.h"
1516

@@ -513,10 +514,10 @@ string SValue::asString(bool debug) const {
513514
} else
514515
if (isInteger()) {
515516
char radix = getRadix();
516-
if (radix == 10) return getInteger().toString(10);
517+
if (radix == 10) return sc::APSintToString(getInteger(), 10);
517518

518519
char prefix = radix == 16 ? 'x' : radix == 8 ? 'o' : 'b';
519-
return (prefix + getInteger().toString(radix));
520+
return (prefix + sc::APSintToString(getInteger(), radix));
520521
} else
521522
if (isScChannel()) {
522523
return channel->asString(debug);

sc_tool/lib/sc_tool/cfg/ScState.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,37 @@ SValue ScState::createArrayInState(clang::QualType arrayType, unsigned level)
666666
}
667667
}
668668

669+
SValue ScState::createStdArrayInState(clang::QualType arrayType, unsigned level)
670+
{
671+
if (isStdArray(arrayType)) {
672+
auto elmType = getTemplateArgAsType(arrayType, 0);
673+
SCT_TOOL_ASSERT (elmType, "createStdArrayInState : No type inferred");
674+
auto sizeArg = sc::getTemplateArg(arrayType, 1);
675+
SCT_TOOL_ASSERT (sizeArg, "createStdArrayInState : No size inferred");
676+
size_t size = sizeArg->getAsIntegral().getZExtValue();
677+
678+
// Create array object
679+
SValue arrayRootVal = SValue(*elmType, size, 0);
680+
681+
// Fill array with elements
682+
for (unsigned i = 0; i < size; i++) {
683+
// Recursive call to create sub-arrays
684+
SValue eval = createStdArrayInState(*elmType, level);
685+
// Put sub_array value into @aval
686+
arrayRootVal.getArray().setOffset(i);
687+
putValue(arrayRootVal, eval, false); //@val -> @eval
688+
setValueLevel(arrayRootVal, level);
689+
}
690+
if (arrayRootVal.getArray().getSize() > 0) {
691+
arrayRootVal.getArray().setOffset(0);
692+
}
693+
return arrayRootVal;
694+
695+
} else {
696+
return NO_VALUE;
697+
}
698+
}
699+
669700
// \return <value found, array with unknown index returned>
670701
std::pair<bool, bool>
671702
ScState::getValue(const SValue& lval, SValue& rval, bool deReference,
@@ -1671,7 +1702,7 @@ vector<SValue>ScState::getAllRecordArrayElementsForAny(const SValue& val,
16711702

16721703
// Is value simple enough to store its value, if not no value put to state
16731704
// Not used for now
1674-
bool ScState::isSimpleValue(const SValue& val) const
1705+
/*bool ScState::isSimpleValue(const SValue& val) const
16751706
{
16761707
// Go up and count array number
16771708
vector<SValue> valStack;
@@ -1693,7 +1724,7 @@ bool ScState::isSimpleValue(const SValue& val) const
16931724
const QualType& type = val.getType();
16941725
bool comlType = (arrNum == 1) && sc::isArray(type);
16951726
return !comlType;
1696-
}
1727+
}*/
16971728

16981729
// Get all fields for given record value with
16991730
// TODO: update for inner records

sc_tool/lib/sc_tool/cfg/ScState.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,12 @@ class ScState
336336
/// re-declaration which required to get variable for value
337337
void removeSubValues(const SValue& val);
338338

339-
/// Recursively create multi-dimensional array and its elements at
340-
/// specified value level
339+
/// Recursively create multi-dimensional array and its elements
340+
/// at specified value level
341341
SValue createArrayInState(clang::QualType arrayType, unsigned level = 0);
342+
/// Recursively create multi-dimensional std::array and its elements
343+
/// at specified value level
344+
SValue createStdArrayInState(clang::QualType arrayType, unsigned level = 0);
342345

343346
/// Get value of @lval into @rval, set @rval into @NO_VALUE if no value for
344347
/// @lval found
@@ -527,7 +530,8 @@ class ScState
527530
unsigned crossModule = 0) const;
528531

529532
/// Is value simple enough to store its value, if not no value put to state
530-
bool isSimpleValue(const SValue& val) const;
533+
/// Not used
534+
///bool isSimpleValue(const SValue& val) const;
531535

532536
/// Get all fields for given record value with
533537
InsertionOrderSet<SValue> getRecordFields(const SValue& recval) const;

sc_tool/lib/sc_tool/cfg/ScTraverseCommon.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ bool sc::isUserCallExpr(clang::Stmt* stmt)
3434
(((nsname && *nsname == "std") || isLinkageDecl(funcDecl)) &&
3535
(fname == "printf" || fname == "fprintf" ||
3636
fname == "sprintf" || fname == "snprintf" ||
37-
fname == "fopen" || fname == "fclose"))) {
37+
fname == "fopen" || fname == "fclose" ||
38+
fname == "operator[]"))) {
3839
return false;
3940
}
4041
return true;

sc_tool/lib/sc_tool/cthread/ScThreadBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "sc_tool/ScCommandLine.h"
2525
#include "sc_tool/utils/BitUtils.h"
2626
#include "sc_tool/utils/VerilogKeywords.h"
27+
#include <llvm/Support/Debug.h>
2728
#include <sstream>
2829

2930
using namespace llvm;

sc_tool/lib/sc_tool/diag/ScToolDiagnostic.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ class ScDiag {
201201
CPP_FOR_WITHOUT_DECL = 229,
202202
SYNTH_PART_INIT_VAR = 230,
203203
CPP_STRING_BINARY_OPER = 231,
204+
CPP_STATIC_STD_VECTOR = 232,
205+
SYNTH_LITER_OVERFLOW = 233,
204206

205207
SC_FATAL_ELAB_TYPES_NS = 300,
206208
SC_WARN_ELAB_UNSUPPORTED_TYPE,
@@ -698,6 +700,14 @@ class ScDiag {
698700
{clang::DiagnosticIDs::Error,
699701
"Binary operation with string argument not supported"};
700702

703+
idFormatMap[CPP_STATIC_STD_VECTOR] =
704+
{clang::DiagnosticIDs::Error,
705+
"Static std::vector is not supportd yet"};
706+
707+
idFormatMap[SYNTH_LITER_OVERFLOW] =
708+
{clang::DiagnosticIDs::Error,
709+
"Literal is too big, up to 4096 symbols supported"};
710+
701711
// Elaboration
702712
idFormatMap[SC_FATAL_ELAB_TYPES_NS] =
703713
{clang::DiagnosticIDs::Fatal,
@@ -857,5 +867,5 @@ class ScDiag {
857867
} // end namespace sc
858868

859869

860-
870+
861871
#endif //SCTOOL_SCTOOLDIAGNOSTIC_H

sc_tool/lib/sc_tool/dyn_elab/Reflection.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* Author: Roman Popov
1010
*/
1111

12+
13+
#include <sc_tool/utils/CppTypeTraits.h>
1214
#include <sc_tool/dyn_elab/Reflection.h>
1315
#include <sc_tool/dyn_elab/GlobalContext.h>
1416

@@ -410,6 +412,9 @@ ArrayObject::getArrayObjectKind(clang::QualType canonicalType)
410412

411413
if (isStdVector(canonicalType))
412414
return ArrayObject::STD_VECTOR;
415+
416+
if (isStdArray(canonicalType))
417+
return ArrayObject::STD_ARRAY;
413418
}
414419

415420
return llvm::None;
@@ -445,6 +450,14 @@ size_t ArrayObject::size() const
445450
return byteVec->size() / elSize;
446451
}
447452

453+
case STD_ARRAY: {
454+
auto type = typedObj.getType();
455+
auto tempArg = sc::getTemplateArg(type, 1);
456+
size_t size = tempArg->getAsIntegral().getZExtValue();
457+
458+
return size;
459+
}
460+
448461
case SC_VECTOR: {
449462
return getScVecInner(typedObj)->size();
450463
}
@@ -478,6 +491,12 @@ TypedObject ArrayObject::operator[](size_t idx) const
478491
startPtr = byteVec->data();
479492
elPtr = startPtr + idx * sizeOfEl;
480493
} break;
494+
495+
case STD_ARRAY: {
496+
std::array<uint8_t, 1> *byteVec =(std::array<uint8_t,1>*) typedObj.getPtr();
497+
startPtr = byteVec->data();
498+
elPtr = startPtr + idx * sizeOfEl;
499+
} break;
481500

482501
case SC_VECTOR:
483502
elPtr = getScVecInner(typedObj)->at(idx);

0 commit comments

Comments
 (0)