Skip to content

Commit 467f572

Browse files
sc_vector of modular interface, unsigned mode added
1 parent d289192 commit 467f572

File tree

138 files changed

+3081
-4664
lines changed

Some content is hidden

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

138 files changed

+3081
-4664
lines changed

cmake/svc_target.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ function(svc_target exe_target)
1212
# REPLACE_CONST_VALUE -- replace constant with its number value if possible
1313
# NO_SVA_GENERATE -- disable SVA generating for SCT assertions
1414
# PORT_MAP_GENERATE -- generate port map file and top module wrapper
15+
# UNSIGNED -- design uses unsigned arithmetic only
1516
# NO_REMOVE_EXTRA_CODE -- disable removing unused variable and extra code
1617
# INIT_LOCAL_VARS -- initialize local variables at declaration with zero
1718
# INIT_RESET_LOCAL_VARS-- initialize CTHREAD reset section local variables
1819
# at declaration with zero
19-
# ELAB_ONLY -- run elaboration without process generation
2020
# WILL_FAIL -- test will fail on non-synthesizable code
2121
set(boolOptions REPLACE_CONST_VALUE
2222
NO_SVA_GENERATE
2323
PORT_MAP_GENERATE
24+
UNSIGNED
2425
NO_REMOVE_EXTRA_CODE
2526
INIT_LOCAL_VARS
2627
INIT_RESET_LOCAL_VARS
27-
ELAB_ONLY
2828
WILL_FAIL)
2929

3030
# Arguments with one value
@@ -42,10 +42,6 @@ function(svc_target exe_target)
4242
cmake_parse_arguments(PARAM "${boolOptions}" "${oneValueArgs}"
4343
"${multiValueArgs}" ${ARGN} )
4444

45-
if (${PARAM_ELAB_ONLY})
46-
set(ELAB_ONLY -elab_only)
47-
endif()
48-
4945
if (${PARAM_NO_SVA_GENERATE})
5046
set(NO_SVA_GENERATE -no_sva_generate)
5147
endif()
@@ -54,6 +50,10 @@ function(svc_target exe_target)
5450
set(PORT_MAP_GENERATE -portmap_generate)
5551
endif()
5652

53+
if (${PARAM_UNSIGNED})
54+
set(UNSIGNED -check_unsigned)
55+
endif()
56+
5757
if (${PARAM_NO_REMOVE_EXTRA_CODE})
5858
set(NO_REMOVE_EXTRA_CODE -no_remove_extra_code)
5959
endif()
@@ -162,10 +162,10 @@ function(svc_target exe_target)
162162
${REPLACE_CONST_VALUE}
163163
${NO_SVA_GENERATE}
164164
${PORT_MAP_GENERATE}
165+
${UNSIGNED}
165166
${NO_REMOVE_EXTRA_CODE}
166167
${INIT_LOCAL_VARS}
167168
${INIT_RESET_LOCAL_VARS}
168-
${ELAB_ONLY}
169169
--
170170
-D__SC_TOOL__ -D__SC_TOOL_ANALYZE__ -DNDEBUG
171171
-Wno-logical-op-parentheses

sc_tool/lib/sc_tool/SCToolFrontendAction.cpp

Lines changed: 4 additions & 4 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.8";
116-
const std::string SCElabASTConsumer::TOOL_DATE = "11 Dec,2021";
115+
const std::string SCElabASTConsumer::TOOL_VERSION = "1.4.11";
116+
const std::string SCElabASTConsumer::TOOL_DATE = "31 Dec,2021";
117117

118118
void SCElabASTConsumer::HandleTranslationUnit(clang::ASTContext &astCtx)
119119
{
@@ -141,8 +141,8 @@ void SCElabASTConsumer::HandleTranslationUnit(clang::ASTContext &astCtx)
141141
//const char* optNames[] = {doModuleBuilder, doGenStmt};
142142
//const char* optNames[] = {doGenTerm, doGenCfg, doGenStmt, doModuleBuilder};
143143
//const char* optNames[] = {doConstCfg, doConstLoop, doConstStmt, doConstBlock, doModuleBuilder};
144-
const char* optNames[] = {doConstCfg, doConstStmt, doModuleBuilder};
145-
//const char* optNames[] = {doModuleBuilder};
144+
//const char* optNames[] = {doConstCfg, doConstStmt, doModuleBuilder};
145+
const char* optNames[] = {doGenFuncCall, doGenStmt, doModuleBuilder};
146146
size_t optSize = sizeof(optNames)/sizeof(const char*);
147147
//DebugOptions::enable(optNames, optSize);
148148

sc_tool/lib/sc_tool/ScCommandLine.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ cl::opt<bool> noRemoveExtraCode(
3838
cl::cat(ScToolCategory)
3939
);
4040

41+
cl::opt<bool> checkUnsigned(
42+
"check_unsigned",
43+
cl::desc("Design uses unsigned arithmetic only"),
44+
cl::cat(ScToolCategory)
45+
);
46+
4147
cl::opt<bool> initLocalVars(
4248
"init_local_vars",
4349
cl::desc("Initialize local variables at declaration with zero"),
@@ -63,10 +69,3 @@ cl::opt<std::string> modulePrefix (
6369
);
6470

6571

66-
cl::opt<bool> noProcessAnalysis (
67-
"elab_only",
68-
cl::desc("Elaboration only, disable SystemC process analysis"),
69-
cl::cat(ScToolCategory)
70-
);
71-
72-

sc_tool/lib/sc_tool/ScCommandLine.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@ extern llvm::cl::opt<std::string> verilogFileName;
2121
extern llvm::cl::opt<bool> noSvaGenerate;
2222
extern llvm::cl::opt<bool> portMapGenerate;
2323
extern llvm::cl::opt<bool> noRemoveExtraCode;
24+
extern llvm::cl::opt<bool> checkUnsigned;
2425
extern llvm::cl::opt<bool> initLocalVars;
2526
extern llvm::cl::opt<bool> initResetLocalVars;
2627
extern llvm::cl::opt<bool> replaceConstByValue;
2728
extern llvm::cl::opt<std::string> modulePrefix;
2829

29-
// Planned to remove
30-
extern llvm::cl::opt<bool> noProcessAnalysis;
31-
3230
// Remove unusable variables in reset section of CTHREAD
3331
inline bool REMOVE_RESET_UNUSED() {
3432
return !noRemoveExtraCode;

sc_tool/lib/sc_tool/cfg/ScState.cpp

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -685,18 +685,29 @@ ScState::getValue(const SValue& lval, SValue& rval, bool deReference,
685685

686686
// For array access at unknown index any element could be accessed
687687
if (isArr && unkwIndex) {
688-
switch (returnUnknown) {
689-
case ArrayUnkwnMode::amNoValue:
690-
rval = NO_VALUE;
691-
return std::pair<bool, bool>(false, false);
692-
693-
case ArrayUnkwnMode::amArrayUnknown:
694-
rval = llval;
695-
return std::pair<bool, bool>(true, true);
696-
697-
case ArrayUnkwnMode::amFirstElement:
698-
llval = getFirstArrayElementForAny(llval);
699-
break;
688+
bool unkwIndexRec = false;
689+
if (returnUnknown == ArrayUnkwnMode::amFirstElementRec) {
690+
getBottomArrayForAny(llval, unkwIndexRec, 0, true);
691+
}
692+
693+
if (unkwIndexRec) {
694+
llval = getFirstArrayElementForAny(llval);
695+
696+
} else {
697+
switch (returnUnknown) {
698+
case ArrayUnkwnMode::amNoValue:
699+
case ArrayUnkwnMode::amFirstElementRec:
700+
rval = NO_VALUE;
701+
return std::pair<bool, bool>(false, false);
702+
703+
case ArrayUnkwnMode::amArrayUnknown:
704+
rval = llval;
705+
return std::pair<bool, bool>(true, true);
706+
707+
case ArrayUnkwnMode::amFirstElement:
708+
llval = getFirstArrayElementForAny(llval);
709+
break;
710+
}
700711
}
701712
}
702713

@@ -1438,9 +1449,10 @@ bool ScState::isArray(const SValue& val, bool& unkwIndex) const
14381449
// Get bottommost array for given value which can be element in array or
14391450
// field in record array element.
14401451
// \param unkwIndex -- unknown index for bottommost array
1452+
// \param checkRecOnly -- provide unkwIndex for record/MIF array only
14411453
// \return bottom array value or NO_VALUE
14421454
SValue ScState::getBottomArrayForAny(const SValue& eval, bool& unkwIndex,
1443-
unsigned crossModule) const
1455+
unsigned crossModule, bool checkRecOnly) const
14441456
{
14451457
//cout << "getBottomArrayForAny eval " << eval << endl;
14461458

@@ -1452,6 +1464,14 @@ SValue ScState::getBottomArrayForAny(const SValue& eval, bool& unkwIndex,
14521464
unkwIndex = false;
14531465
for (const SValue& mval : valStack) {
14541466
if (mval.isArray()) {
1467+
if (checkRecOnly) {
1468+
QualType elmtype = getArrayElementType(mval.getType());
1469+
if (isPointer(elmtype)) {
1470+
elmtype = elmtype->getPointeeType();
1471+
}
1472+
if (!isScModularInterface(elmtype) &&
1473+
!isUserDefinedClass(elmtype)) continue;
1474+
}
14551475
unkwIndex = unkwIndex || mval.getArray().isUnknown();
14561476
}
14571477
}

sc_tool/lib/sc_tool/cfg/ScState.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ struct VerilogVarTraits
129129
enum class ArrayUnkwnMode {
130130
amNoValue, // Return NO_VALUE
131131
amArrayUnknown, // Return the same array unknown element
132-
amFirstElement // Return first (zero index) element
132+
amFirstElement, // Return first (zero index) element
133+
amFirstElementRec // Return first element for record/MIF array
134+
// unknown index,NO_VALUE otherwise
133135
};
134136

135137
/// State of class, structure or module
@@ -487,9 +489,10 @@ class ScState
487489
/// Get bottommost array for given value which can be element in array or
488490
/// field in record array element.
489491
/// \param unkwIndex -- unknown index for bottommost array
492+
/// \param checkRecOnly -- provide unkwIndex for record/MIF array only
490493
/// \return bottom array value or NO_VALUE
491494
SValue getBottomArrayForAny(const SValue& val, bool& unkwIndex,
492-
unsigned crossModule = 0) const;
495+
unsigned crossModule = 0, bool checkRecOnly = false) const;
493496

494497
/// Get topmost array and field declaration for given value which can be
495498
/// element in array or field in record array element.

sc_tool/lib/sc_tool/cfg/ScTraverseConst.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ using namespace llvm;
2626

2727
// ---------------------------------------------------------------------------
2828
// Creates constant value in global state if necessary
29+
// Used for constant and constant array belong to template parameter class
2930
SValue ScTraverseConst::parseGlobalConstant(const SValue& val)
3031
{
3132
//cout << "parseGlobalConstant val " << val << endl;
@@ -39,8 +40,7 @@ SValue ScTraverseConst::parseGlobalConstant(const SValue& val)
3940
auto valDecl = const_cast<clang::ValueDecl*>(val.getVariable().getDecl());
4041
auto varDecl = dyn_cast<clang::VarDecl>(valDecl);
4142

42-
// @exprEval used in createStaticVariable() to evaulate
43-
// initializer expressions as constant
43+
// Create VerilogVar object in VerilogModule
4444
auto newElabObj = elabDB->createStaticVariable(currentModule, varDecl);
4545

4646
if (elabDB->hasVerilogModule(currentModule)) {
@@ -196,7 +196,11 @@ void ScTraverseConst::evaluateTermCond(Stmt* stmt, SValue& val)
196196

197197
//cout << "Condition #" << hex << stmt << dec << endl;
198198
//cond->dumpColor();
199-
auto condvals = evaluateConstInt(const_cast<Expr*>(cond), false);
199+
200+
// Use @checkRecOnly to have pointer null/not null value for record/MIF
201+
// array element accessed at unknown index, required for condition of
202+
// pointer initialized: if (p) p->f();
203+
auto condvals = evaluateConstInt(const_cast<Expr*>(cond), false, true);
200204
readFromValue(condvals.first);
201205
val = condvals.second;
202206

sc_tool/lib/sc_tool/cfg/ScTraverseConst.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ class ScTraverseConst : public ScParseExprValue {
262262

263263
protected:
264264
/// Creates constant value in global state if necessary
265+
/// Used for constant and constant array belong to template parameter class
265266
SValue parseGlobalConstant(const SValue& val) override;
266267

267268
/// Register variables accessed in and after reset section,

sc_tool/lib/sc_tool/cfg/ScTraverseProc.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -792,12 +792,14 @@ void ScTraverseProc::run()
792792
isStmt = true;
793793

794794
} else
795-
if (auto stmtLevel = stmtInfo.getSubStmtLevel(currStmt)) {
796-
level = *stmtLevel;
797-
isCallSubStmt = isUserCallExpr(currStmt);
798-
isStmt = isCallSubStmt;
795+
if (auto superStmt = stmtInfo.getSuperStmt(currStmt)) {
796+
if (auto superStmtLevel = stmtInfo.getLevel(superStmt)) {
797+
level = *superStmtLevel;
798+
isCallSubStmt = isUserCallExpr(currStmt);
799+
isStmt = isCallSubStmt && !isIoStreamStmt(superStmt);
800+
}
799801
//cout << hex << "getSubStmtLevel " << currStmt << endl;
800-
802+
801803
} else {
802804
cout << hex << "#" << currStmt << dec << endl;
803805
currStmt->dumpColor();

sc_tool/lib/sc_tool/diag/ScToolDiagnostic.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ class ScDiag {
193193
SYNTH_FUNC_CALL_WAIT_LOOP = 221,
194194
SYNTH_MULT_ASSIGN_REC = 222,
195195
SYNTH_INTERNAL_ASSIGN_OPER = 223,
196+
SYNTH_UNSIGNED_MODE_BINARY = 224,
197+
SYNTH_UNSIGNED_MODE_UNARY = 225,
198+
SYNTH_UNSIGNED_MODE_DECL = 226,
199+
CPP_BOOL_BITWISE_BINARY = 227,
196200

197201
SC_FATAL_ELAB_TYPES_NS = 300,
198202
SC_WARN_ELAB_UNSUPPORTED_TYPE,
@@ -561,8 +565,23 @@ class ScDiag {
561565
idFormatMap[SYNTH_INTERNAL_ASSIGN_OPER] =
562566
{clang::DiagnosticIDs::Error,
563567
"Internal assignment in binary/unary operation not supported yet"};
568+
569+
idFormatMap[SYNTH_UNSIGNED_MODE_BINARY] =
570+
{clang::DiagnosticIDs::Warning,
571+
"Signed assignment or other binary operator in unsigned mode"};
572+
573+
idFormatMap[SYNTH_UNSIGNED_MODE_UNARY] =
574+
{clang::DiagnosticIDs::Warning,
575+
"Signed unary operator in unsigned mode"};
564576

565-
577+
idFormatMap[SYNTH_UNSIGNED_MODE_DECL] =
578+
{clang::DiagnosticIDs::Warning,
579+
"Signed type variable declaration in unsigned mode"};
580+
581+
idFormatMap[CPP_BOOL_BITWISE_BINARY] =
582+
{clang::DiagnosticIDs::Remark,
583+
"Bitwise operation with boolean, use logical operation instead"};
584+
566585

567586
idFormatMap[CPP_UNKNOWN_STD_FUNC] =
568587
{clang::DiagnosticIDs::Warning,

0 commit comments

Comments
 (0)