Skip to content

Commit 0a22f10

Browse files
committed
Working first past build of Au projects
1 parent fa15b17 commit 0a22f10

File tree

20 files changed

+1239
-905
lines changed

20 files changed

+1239
-905
lines changed

src/main/kotlin/com/alchitry/labs/Log.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ object Log {
2929
// TODO: Make this show a dialog
3030
}
3131

32-
fun println(message: Any?, color: Color) {
33-
println(message, SpanStyle(color = color))
32+
fun println(message: Any?, color: Color?) {
33+
println(message, color?.let { SpanStyle(color = it) })
3434
}
3535

36-
fun print(message: Any?, color: Color) {
37-
print(message, SpanStyle(color = color))
36+
fun print(message: Any?, color: Color?) {
37+
print(message, color?.let { SpanStyle(color = it) })
3838
}
3939

4040
fun println(message: Any?, style: SpanStyle? = null) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.alchitry.labs
2+
3+
fun String.prefixLinesWith(prefix: String): String = lines().joinToString("\n") { prefix + it }

src/main/kotlin/com/alchitry/labs/parsers/acf/AcfParser.kt renamed to src/main/kotlin/com/alchitry/labs/parsers/acf/AcfExtractor.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import com.alchitry.labs.parsers.lucidv2.types.*
1010
import com.alchitry.labs.project.Board
1111
import kotlin.math.roundToInt
1212

13-
class AcfParser(
13+
class AcfExtractor(
1414
val topModule: ModuleInstance,
1515
val board: Board,
1616
val errorCollector: ErrorCollector,
@@ -31,7 +31,11 @@ class AcfParser(
3131
val selectionMap = children.subList(1, children.size).associate {
3232
when (it) {
3333
is AcfParser.NameContext -> SignalSelector.Struct(it.text) to it
34-
is AcfParser.ArrayIndexContext -> SignalSelector.Bits(it.text.toInt(), SelectionContext.Constant) to it
34+
is AcfParser.ArrayIndexContext -> SignalSelector.Bits(
35+
(it.INT() ?: return).text.toInt(),
36+
SelectionContext.Constant
37+
) to it
38+
3539
else -> error("Impossible as everything else should have been filtered out!")
3640
}
3741
}
@@ -47,6 +51,10 @@ class AcfParser(
4751
return
4852
}
4953
}
54+
if (selectedSignal.width.bitCount != 1) {
55+
errorCollector.reportError(ctx, "This signal is wider than a single bit!")
56+
return
57+
}
5058
signals[ctx] = selectedSignal
5159
}
5260

src/main/kotlin/com/alchitry/labs/parsers/acf/XdcConverter.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@ import com.alchitry.labs.hardware.pinout.PinConverter
44
import com.alchitry.labs.parsers.acf.types.ClockConstraint
55
import com.alchitry.labs.parsers.acf.types.PinConstraint
66
import com.alchitry.labs.parsers.acf.types.PinPull
7+
import com.alchitry.labs.parsers.errors.ErrorCollector
8+
import com.alchitry.labs.parsers.grammar.AcfLexer
9+
import com.alchitry.labs.parsers.grammar.AcfParser
10+
import com.alchitry.labs.parsers.lucidv2.types.ModuleInstance
711
import com.alchitry.labs.parsers.lucidv2.types.Signal
812
import com.alchitry.labs.parsers.lucidv2.types.SignalOrSubSignal
913
import com.alchitry.labs.parsers.lucidv2.types.SubSignal
14+
import com.alchitry.labs.project.Board
15+
import com.alchitry.labs.project.files.ConstraintFile
16+
import org.antlr.v4.kotlinruntime.CharStreams
17+
import org.antlr.v4.kotlinruntime.CommonTokenStream
18+
import org.antlr.v4.kotlinruntime.tree.ParseTreeWalker
1019

1120
object XdcConverter {
1221
private val SignalOrSubSignal.fullPortName: String
@@ -46,6 +55,37 @@ object XdcConverter {
4655
}
4756
}
4857

58+
fun convert(
59+
file: ConstraintFile,
60+
topModule: ModuleInstance,
61+
board: Board,
62+
errorCollector: ErrorCollector,
63+
): String? {
64+
val parser =
65+
AcfParser(
66+
CommonTokenStream(
67+
AcfLexer(
68+
CharStreams.fromStream(file.file.inputStream())
69+
).also { it.removeErrorListeners() }
70+
)
71+
).apply {
72+
(tokenStream?.tokenSource as? AcfLexer)?.addErrorListener(errorCollector)
73+
?: error("TokenSource was not an AcfLexer!")
74+
removeErrorListeners()
75+
addErrorListener(errorCollector)
76+
}
77+
78+
val tree = parser.source()
79+
80+
if (errorCollector.hasErrors) {
81+
return null
82+
}
83+
84+
val extractor = AcfExtractor(topModule, board, errorCollector)
85+
ParseTreeWalker.walk(extractor, tree)
86+
return convert(extractor.clocks, extractor.pins, board.pinConverter)
87+
}
88+
4989
fun convert(
5090
clockConstraints: List<ClockConstraint>,
5191
pinConstraints: List<PinConstraint>,

src/main/kotlin/com/alchitry/labs/parsers/errors/Notation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ data class Notation(
88
val type: NotationType
99
) {
1010
override fun toString(): String {
11-
return "${type.label} at line ${range.start.line} offset ${range.start.offset}${message?.let { ": $it" } ?: ""}"
11+
return "${type.label} at line ${range.start.line + 1} offset ${range.start.offset}${message?.let { ": $it" } ?: ""}"
1212
}
1313
}
1414

src/main/kotlin/com/alchitry/labs/parsers/grammar/Acf.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
grammar Acf;
22

33
// starting rule
4-
source: (pin | clock | NL)* EOF;
4+
source: (pin | clock | NL)* EOF?;
55

66
pin: 'pin' portName pinName (PULLUP|PULLDOWN)? semi;
77

@@ -20,7 +20,7 @@ number : INT | REAL;
2020
PULLUP: 'pullup';
2121
PULLDOWN: 'pulldown';
2222

23-
semi: NL | (NL* SEMICOLON);
23+
semi: NL | (NL* SEMICOLON) | EOF;
2424

2525
SEMICOLON : ';';
2626
NL : '\r' '\n' | '\n' | '\r';

src/main/kotlin/com/alchitry/labs/parsers/grammar/Acf.interp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ semi
5050

5151

5252
atn:
53-
[4, 1, 16, 91, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7,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4, 0, 32, 34, 3, 10, 5, 0, 33, 35, 7, 0, 0, 0, 34, 33, 1, 0, 0, 0, 34, 35, 1, 0, 0, 0, 35, 36, 1, 0, 0, 0, 36, 37, 3, 18, 9, 0, 37, 3, 1, 0, 0, 0, 38, 39, 5, 2, 0, 0, 39, 40, 3, 8, 4, 0, 40, 42, 3, 10, 5, 0, 41, 43, 7, 0, 0, 0, 42, 41, 1, 0, 0, 0, 42, 43, 1, 0, 0, 0, 43, 44, 1, 0, 0, 0, 44, 45, 3, 12, 6, 0, 45, 46, 3, 18, 9, 0, 46, 5, 1, 0, 0, 0, 47, 48, 7, 1, 0, 0, 48, 7, 1, 0, 0, 0, 49, 53, 3, 6, 3, 0, 50, 52, 3, 14, 7, 0, 51, 50, 1, 0, 0, 0, 52, 55, 1, 0, 0, 0, 53, 51, 1, 0, 0, 0, 53, 54, 1, 0, 0, 0, 54, 66, 1, 0, 0, 0, 55, 53, 1, 0, 0, 0, 56, 57, 5, 3, 0, 0, 57, 61, 3, 6, 3, 0, 58, 60, 3, 14, 7, 0, 59, 58, 1, 0, 0, 0, 60, 63, 1, 0, 0, 0, 61, 59, 1, 0, 0, 0, 61, 62, 1, 0, 0, 0, 62, 65, 1, 0, 0, 0, 63, 61, 1, 0, 0, 0, 64, 56, 1, 0, 0, 0, 65, 68, 1, 0, 0, 0, 66, 64, 1, 0, 0, 0, 66, 67, 1, 0, 0, 0, 67, 9, 1, 0, 0, 0, 68, 66, 1, 0, 0, 0, 69, 70, 3, 6, 3, 0, 70, 11, 1, 0, 0, 0, 71, 72, 3, 16, 8, 0, 72, 73, 5, 10, 0, 0, 73, 13, 1, 0, 0, 0, 74, 75, 5, 4, 0, 0, 75, 76, 5, 13, 0, 0, 76, 77, 5, 5, 0, 0, 77, 15, 1, 0, 0, 0, 78, 79, 7, 2, 0, 0, 79, 17, 1, 0, 0, 0, 80, 89, 5, 9, 0, 0, 81, 83, 5, 9, 0, 0, 82, 81, 1, 0, 0, 0, 83, 86, 1, 0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, 16, 79, 1, 0, 0, 0, 18, 90, 1, 0, 0, 0, 20, 24, 3, 2, 1, 0, 21, 24, 3, 4, 2, 0, 22, 24, 5, 9, 0, 0, 23, 20, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, 23, 22, 1, 0, 0, 0, 24, 27, 1, 0, 0, 0, 25, 23, 1, 0, 0, 0, 25, 26, 1, 0, 0, 0, 26, 29, 1, 0, 0, 0, 27, 25, 1, 0, 0, 0, 28, 30, 5, 0, 0, 1, 29, 28, 1, 0, 0, 0, 29, 30, 1, 0, 0, 0, 30, 1, 1, 0, 0, 0, 31, 32, 5, 1, 0, 0, 32, 33, 3, 8, 4, 0, 33, 35, 3, 10, 5, 0, 34, 36, 7, 0, 0, 0, 35, 34, 1, 0, 0, 0, 35, 36, 1, 0, 0, 0, 36, 37, 1, 0, 0, 0, 37, 38, 3, 18, 9, 0, 38, 3, 1, 0, 0, 0, 39, 40, 5, 2, 0, 0, 40, 41, 3, 8, 4, 0, 41, 43, 3, 10, 5, 0, 42, 44, 7, 0, 0, 0, 43, 42, 1, 0, 0, 0, 43, 44, 1, 0, 0, 0, 44, 45, 1, 0, 0, 0, 45, 46, 3, 12, 6, 0, 46, 47, 3, 18, 9, 0, 47, 5, 1, 0, 0, 0, 48, 49, 7, 1, 0, 0, 49, 7, 1, 0, 0, 0, 50, 54, 3, 6, 3, 0, 51, 53, 3, 14, 7, 0, 52, 51, 1, 0, 0, 0, 53, 56, 1, 0, 0, 0, 54, 52, 1, 0, 0, 0, 54, 55, 1, 0, 0, 0, 55, 67, 1, 0, 0, 0, 56, 54, 1, 0, 0, 0, 57, 58, 5, 3, 0, 0, 58, 62, 3, 6, 3, 0, 59, 61, 3, 14, 7, 0, 60, 59, 1, 0, 0, 0, 61, 64, 1, 0, 0, 0, 62, 60, 1, 0, 0, 0, 62, 63, 1, 0, 0, 0, 63, 66, 1, 0, 0, 0, 64, 62, 1, 0, 0, 0, 65, 57, 1, 0, 0, 0, 66, 69, 1, 0, 0, 0, 67, 65, 1, 0, 0, 0, 67, 68, 1, 0, 0, 0, 68, 9, 1, 0, 0, 0, 69, 67, 1, 0, 0, 0, 70, 71, 3, 6, 3, 0, 71, 11, 1, 0, 0, 0, 72, 73, 3, 16, 8, 0, 73, 74, 5, 10, 0, 0, 74, 13, 1, 0, 0, 0, 75, 76, 5, 4, 0, 0, 76, 77, 5, 13, 0, 0, 77, 78, 5, 5, 0, 0, 78, 15, 1, 0, 0, 0, 79, 80, 7, 2, 0, 0, 80, 17, 1, 0, 0, 0, 81, 91, 5, 9, 0, 0, 82, 84, 5, 9, 0, 0, 83, 82, 1, 0, 0, 0, 84, 87, 1, 0, 0, 0, 85, 83, 1, 0, 0, 0, 85, 86, 1, 0, 0, 0, 86, 88, 1, 0, 0, 0, 87, 85, 1, 0, 0, 0, 88, 91, 5, 8, 0, 0, 89, 91, 5, 0, 0, 1, 90, 81, 1, 0, 0, 0, 90, 85, 1, 0, 0, 0, 90, 89, 1, 0, 0, 0, 91, 19, 1, 0, 0, 0, 10, 23, 25, 29, 35, 43, 54, 62, 67, 85, 90]

src/main/kotlin/com/alchitry/labs/parsers/grammar/AcfLexer.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Generated from java-escape by ANTLR 4.13.0
22
package com.alchitry.labs.parsers.grammar
3-
43
import com.alchitry.kotlinmultiplatform.asCharArray
54
import org.antlr.v4.kotlinruntime.CharStream
65
import org.antlr.v4.kotlinruntime.Lexer

0 commit comments

Comments
 (0)