-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Natalia Gavrilenko <[email protected]>
- Loading branch information
1 parent
28bb592
commit 4d76582
Showing
53 changed files
with
21,407 additions
and
24 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserSpirv.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.dat3m.dartagnan.parsers.program; | ||
|
||
import com.dat3m.dartagnan.exception.ParserErrorListener; | ||
import com.dat3m.dartagnan.parsers.*; | ||
import com.dat3m.dartagnan.parsers.program.visitors.VisitorSpirv; | ||
import com.dat3m.dartagnan.program.Program; | ||
import org.antlr.v4.runtime.CharStream; | ||
import org.antlr.v4.runtime.CommonTokenStream; | ||
import org.antlr.v4.runtime.DiagnosticErrorListener; | ||
import org.antlr.v4.runtime.ParserRuleContext; | ||
|
||
public class ParserSpirv implements ParserInterface { | ||
|
||
@Override | ||
public Program parse(CharStream charStream) { | ||
SpirvLexer lexer = new SpirvLexer(charStream); | ||
CommonTokenStream tokenStream = new CommonTokenStream(lexer); | ||
|
||
SpirvParser parser = new SpirvParser(tokenStream); | ||
parser.addErrorListener(new DiagnosticErrorListener(true)); | ||
parser.addErrorListener(new ParserErrorListener()); | ||
ParserRuleContext parserEntryPoint = parser.spv(); | ||
VisitorSpirv visitor = new VisitorSpirv(); | ||
|
||
parserEntryPoint.accept(visitor); | ||
return visitor.buildProgram(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/VisitorSpirv.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.dat3m.dartagnan.parsers.program.visitors; | ||
|
||
import com.dat3m.dartagnan.expression.Expression; | ||
import com.dat3m.dartagnan.parsers.SpirvBaseVisitor; | ||
import com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder; | ||
import com.dat3m.dartagnan.program.Program; | ||
|
||
public class VisitorSpirv extends SpirvBaseVisitor<Expression> { | ||
|
||
private final ProgramBuilder programBuilder = ProgramBuilder.forLanguage(Program.SourceLanguage.SPV); | ||
public Program buildProgram() { | ||
return programBuilder.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
dartagnan/src/test/java/com/dat3m/dartagnan/parsers/program/ParserSpirvTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.dat3m.dartagnan.parsers.program; | ||
|
||
import com.dat3m.dartagnan.program.Program; | ||
import org.antlr.v4.runtime.CharStream; | ||
import org.antlr.v4.runtime.CharStreams; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.stream.Stream; | ||
|
||
import static com.dat3m.dartagnan.utils.ResourceHelper.getTestResourcePath; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
@RunWith(Parameterized.class) | ||
public class ParserSpirvTest { | ||
|
||
private static final String PATH = "parsers/program/spirv/"; | ||
|
||
private final String filename; | ||
|
||
public ParserSpirvTest(String filename) { | ||
this.filename = filename; | ||
} | ||
|
||
@Parameterized.Parameters(name = "{index}: {0}") | ||
public static Iterable<Object[]> data() throws IOException { | ||
String path = Paths.get(getTestResourcePath(PATH)).toString(); | ||
File dir = new File(path); | ||
File[] files = dir.listFiles(); | ||
assertNotNull(files); | ||
return Stream.of(files) | ||
.filter(file -> !file.isDirectory()) | ||
.map(f -> new Object[]{f.getName()}) | ||
.toList(); | ||
} | ||
|
||
@Test | ||
public void testParsingFile() throws IOException { | ||
Program program; | ||
Path path = Paths.get(getTestResourcePath(PATH + filename)); | ||
try (FileInputStream stream = new FileInputStream(path.toString())) { | ||
CharStream charStream = CharStreams.fromStream(stream); | ||
ParserSpirv parser = new ParserSpirv(); | ||
program = parser.parse(charStream); | ||
} | ||
assertNotNull(program); | ||
} | ||
} |
Oops, something went wrong.