Skip to content

Commit

Permalink
add a test (not working)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Lenharth committed Dec 31, 2024
1 parent 55542d9 commit dd2888a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
2 changes: 2 additions & 0 deletions include/circt/InitAllTranslations.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//

#include "circt/Dialect/Arc/ModelInfoExport.h"
#include "circt/Dialect/BLIF/BLIFParser.h"
#include "circt/Dialect/Calyx/CalyxEmitter.h"
#include "circt/Dialect/ESI/ESIDialect.h"
#include "circt/Dialect/FIRRTL/FIREmitter.h"
Expand All @@ -32,6 +33,7 @@ namespace circt {
inline void registerAllTranslations() {
static bool initOnce = []() {
arc::registerArcModelInfoTranslation();
blif::registerFromBLIFFileTranslation();
calyx::registerToCalyxTranslation();
firrtl::registerFromFIRFileTranslation();
firrtl::registerToFIRFileTranslation();
Expand Down
4 changes: 0 additions & 4 deletions lib/Dialect/BLIF/Import/BLIFLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,6 @@ BLIFToken BLIFLexer::lexTokenImpl() {
return lexFileInfo(tokStart);
// Unknown character, emit an error.
return emitError(tokStart, "unexpected character");
case '%':
if (*curPtr == '[')
return lexInlineAnnotation(tokStart);
return emitError(tokStart, "unexpected character following '%'");
case '|':
if (*curPtr == '}')
return ++curPtr, formToken(BLIFToken::r_brace_bar, tokStart);
Expand Down
38 changes: 30 additions & 8 deletions lib/Dialect/BLIF/Import/BLIFParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ struct BLIFParser {
ParseResult parseIdOrNil(StringRef &result, const Twine &message);
ParseResult parseIdOrNil(StringAttr &result, const Twine &message);

ParseResult parseIdList(SmallVectorImpl<std::string> &result,
const Twine &message);
ParseResult parseIdList(SmallVectorImpl<StringRef> &result,
const Twine &message, unsigned minCount = 0);

private:
BLIFParser(const BLIFParser &) = delete;
Expand Down Expand Up @@ -239,6 +239,28 @@ ParseResult BLIFParser::parseId(StringAttr &result, const Twine &message) {
return success();
}

ParseResult BLIFParser::parseIdList(SmallVectorImpl<StringRef> &result,
const Twine &message, unsigned minCount) {
while(true) {
switch (getToken().getKind()) {
// The most common case is an identifier.
case BLIFToken::identifier:
result.push_back(getTokenSpelling());
consumeToken();
if (minCount)
--minCount;
break;
default:
if (minCount) {
emitError(message);
return failure();
}
return success();
}
}
}


//===----------------------------------------------------------------------===//
// BLIFModelParser
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -292,9 +314,9 @@ Value BLIFModelParser::getReferencedModel(SMLoc loc, StringRef modelName) {
ParseResult BLIFModelParser::parseLogicGate() {
auto startTok = consumeToken(BLIFToken::kw_names);
auto loc = startTok.getLoc();
SmallVector<std::string> inputs;
SmallVector<StringRef> inputs;
std::string output;
if (parseIdList(inputs, "expected input list"))
if (parseIdList(inputs, "expected input list", 1))
return failure();
output = inputs.back();
inputs.pop_back();
Expand Down Expand Up @@ -413,22 +435,22 @@ struct BLIFFileParser : public BLIFParser {
ParseResult BLIFFileParser::parseModel() {
StringAttr name;
auto modLoc = getToken().getLoc();
SmallVector<std::string> inputs, outputs, clocks;
SmallVector<StringRef> inputs, outputs, clocks;
consumeToken(BLIFToken::kw_model);
if (parseId(name, "expected model name"))
return failure();
while (getToken().isModelHeaderKeyword()) {
switch (getToken().getKind()) {
case BLIFToken::kw_inputs:
if (parseIdList(inputs, "expected input list"))
if (parseIdList(inputs, "expected input list", 1))
return failure();
break;
case BLIFToken::kw_outputs:
if (parseIdList(outputs, "expected output list"))
if (parseIdList(outputs, "expected output list", 1))
return failure();
break;
case BLIFToken::kw_clock:
if (parseIdList(clocks, "expected clock list"))
if (parseIdList(clocks, "expected clock list", 1))
return failure();
break;
default:
Expand Down
16 changes: 16 additions & 0 deletions test/Dialect/BLIF/parse-basic.blif
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; RUN: circt-translate -import-blif -verify-diagnostics -split-input-file %s | circt-opt | FileCheck %s

.model simple
.inputs a B
.outputs c
.names a b c
11 1
.end

;// -----

# unamed model
.names a b \
c # test \
11 1

2 changes: 1 addition & 1 deletion test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)

# suffixes: A list of file extensions to treat as test files.
config.suffixes = ['.td', '.mlir', '.ll', '.fir', '.sv']
config.suffixes = ['.td', '.mlir', '.ll', '.blif', '.fir', '.sv']

# test_source_root: The root path where tests are located.
config.test_source_root = os.path.dirname(__file__)
Expand Down

0 comments on commit dd2888a

Please sign in to comment.