@@ -124,14 +124,16 @@ public class BSVToKami extends BSVBaseVisitor<Void>
124
124
public Void visitPackagedef (BSVParser .PackagedefContext ctx ) {
125
125
logger .fine ("Package " + pkgName );
126
126
127
- printstream .println ("Require Import Bool String List." );
127
+ printstream .println ("Require Import Bool String List Arith ." );
128
128
printstream .println ("Require Import Kami." );
129
129
printstream .println ("Require Import Lib.Indexer." );
130
+ printstream .println ("Require Import Bsvtokami." );
130
131
printstream .println ("" );
131
132
printstream .println ("Require Import FunctionalExtensionality." );
132
133
printstream .println ("" );
133
134
printstream .println ("Set Implicit Arguments." );
134
135
printstream .println ("" );
136
+ printstream .println ();
135
137
136
138
scope = scopes .pushScope (ctx );
137
139
@@ -337,36 +339,38 @@ BSVParser.CallexprContext getCall(ParserRuleContext ctx) {
337
339
@ Override public Void visitFunctiondef (BSVParser .FunctiondefContext ctx ) {
338
340
scope = scopes .pushScope (ctx );
339
341
BSVParser .FunctionprotoContext functionproto = ctx .functionproto ();
340
- printstream .print (String .format ("Definition %s ( " , functionproto .name .getText ()));
342
+ printstream .print (String .format ("Definition %s" , functionproto .name .getText ()));
341
343
if (functionproto .methodprotoformals () != null ) {
342
- String sep = "" ;
343
344
for (BSVParser .MethodprotoformalContext formal : functionproto .methodprotoformals ().methodprotoformal ()) {
344
345
BSVParser .BsvtypeContext bsvtype = formal .bsvtype ();
345
346
String varName = formal .name .getText ();
346
- printstream .print (sep + varName + ": " + bsvTypeToKami (bsvtype ));
347
- sep = ", " ;
347
+ printstream .print (String .format (" (%s: %s)" , varName , bsvTypeToKami (bsvtype )));
348
348
}
349
349
}
350
350
String returntype = (functionproto .bsvtype () != null ) ? bsvTypeToKami (functionproto .bsvtype ()) : "" ;
351
- printstream .println (String .format (") : %s := " , returntype ));
351
+ printstream .println (String .format (": %s := " , returntype ));
352
352
353
353
RegReadVisitor regReadVisitor = new RegReadVisitor (scope );
354
- for (BSVParser .StmtContext stmt : ctx .stmt ())
355
- regReadVisitor .visit (stmt );
356
- if (ctx .expression () != null )
354
+ if (ctx .expression () != null ) {
355
+ printstream .print (" " );
357
356
regReadVisitor .visit (ctx .expression ());
358
357
359
- for (Map .Entry <String ,BSVType > entry : regReadVisitor .regs .entrySet ()) {
360
- String regName = entry .getKey ();
361
- printstream .println (" Read " + regName + "_v : " + bsvTypeToKami (entry .getValue ()) + " <- \" " + regName + "\" ;" );
362
- }
363
- for (BSVParser .StmtContext stmt : ctx .stmt ())
364
- visit (stmt );
365
358
if (ctx .expression () != null )
366
359
visit (ctx .expression ());
360
+ } else {
367
361
368
- if (returntype .equals ("Action" ) || returntype .equals ("Void" ))
369
- printstream .println (" Retv" );
362
+ for (Map .Entry <String ,BSVType > entry : regReadVisitor .regs .entrySet ()) {
363
+ String regName = entry .getKey ();
364
+ printstream .println (" Read " + regName + "_v : " + bsvTypeToKami (entry .getValue ()) + " <- \" " + regName + "\" ;" );
365
+ }
366
+ for (BSVParser .StmtContext stmt : ctx .stmt ())
367
+ regReadVisitor .visit (stmt );
368
+ for (BSVParser .StmtContext stmt : ctx .stmt ())
369
+ visit (stmt );
370
+
371
+ if (returntype .equals ("Action" ) || returntype .equals ("Void" ))
372
+ printstream .println (" Retv" );
373
+ }
370
374
printstream .println ("." );
371
375
printstream .println ("" );
372
376
scope = scopes .popScope ();
@@ -475,12 +479,16 @@ public Void visitPattern(BSVParser.PatternContext ctx) {
475
479
@ Override public Void visitBinopexpr (BSVParser .BinopexprContext expr ) {
476
480
if (expr .right != null ) {
477
481
printstream .print ("(" );
478
- if (expr .left != null )
479
- visit (expr .left );
480
482
if (expr .op != null ) {
481
- printstream .print (" " + expr .op .getText () + " " );
483
+ String op = expr .op .getText ();
484
+ if (op .equals ("<" ))
485
+ op = "bitlt" ;
486
+ printstream .print (op );
482
487
}
483
-
488
+ printstream .print (" " );
489
+ if (expr .left != null )
490
+ visit (expr .left );
491
+ printstream .print (" " );
484
492
visit (expr .right );
485
493
printstream .print (")" );
486
494
} else {
@@ -601,11 +609,15 @@ public String bsvTypeToKami(BSVParser.BsvtypeContext t, int level) {
601
609
return "<nulltype>" ;
602
610
if (t .typeide () != null ) {
603
611
String kamitype = t .typeide ().getText ();
604
- if (kamitype .equals ("Action" ))
612
+ if (kamitype .equals ("Bit" ))
613
+ kamitype = "word" ;
614
+ else if (kamitype .equals ("Bool" ))
615
+ kamitype = "bool" ;
616
+ else if (kamitype .equals ("Action" ))
605
617
kamitype = "Void" ;
606
618
for (BSVParser .BsvtypeContext p : t .bsvtype ())
607
619
kamitype += " " + bsvTypeToKami (p , 1 );
608
- if (level > 0 )
620
+ if (t . bsvtype (). size () > 0 )
609
621
kamitype = String .format ("(%s)" , kamitype );
610
622
return kamitype ;
611
623
} else if (t .typenat () != null ) {
0 commit comments