Skip to content

Commit b39ed42

Browse files
committed
final commit for paper
1 parent 9b6e5ac commit b39ed42

File tree

5 files changed

+72
-82
lines changed

5 files changed

+72
-82
lines changed

tool/rlc-doc/src/Main.cpp

Lines changed: 70 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ static cl::opt<bool> createDirectories(
4343
static cl::opt<std::string> OutputFilePath(
4444
"o", cl::desc("<output-file>"), cl::init("-"), cl::cat(Category));
4545

46-
static void printTemplateParameter(mlir::Attribute attr, llvm::raw_ostream& OS)
46+
/// Print a template parameter inside back‑ticks.
47+
static void printTemplateParameter(mlir::Attribute attr, llvm::raw_ostream &OS)
4748
{
4849
auto param = attr.cast<mlir::TypeAttr>()
4950
.getValue()
@@ -55,153 +56,145 @@ static void printTemplateParameter(mlir::Attribute attr, llvm::raw_ostream& OS)
5556
}
5657
}
5758

58-
static void writeComment(mlir::Operation* op, llvm::raw_ostream& OS)
59+
/// Emit a fenced Markdown code‑block for an operation comment, if present.
60+
static void writeComment(mlir::Operation *op, llvm::raw_ostream &OS)
5961
{
6062
if (op->hasAttr("comment"))
6163
{
6264
auto comment = op->getAttr("comment").cast<mlir::StringAttr>();
63-
OS << "<pre><code>\n" << comment.strref() << "\n</code></pre>\n";
65+
OS << "\n```text\n" << comment.strref() << "\n```\n\n";
6466
}
6567
}
6668

67-
static void printFunction(mlir::rlc::FunctionOp op, llvm::raw_ostream& OS)
69+
static void printFunction(mlir::rlc::FunctionOp op, llvm::raw_ostream &OS)
6870
{
6971
// Skip internal functions
7072
if (op.isInternal())
7173
return;
7274

73-
OS << "<li><strong>Function</strong>: <code>" << op.getUnmangledName();
75+
OS << "- **Function**: `" << op.getUnmangledName();
7476

7577
// Handle template parameters if present
7678
if (!op.getTemplateParameters().empty())
7779
{
78-
OS << "&lt;";
79-
for (auto& name : llvm::drop_end(op.getTemplateParameters()))
80+
OS << "<";
81+
for (auto &name : llvm::drop_end(op.getTemplateParameters()))
8082
{
8183
printTemplateParameter(name, OS);
8284
OS << ", ";
8385
}
8486
printTemplateParameter(*(op.getTemplateParameters().end() - 1), OS);
85-
OS << "&gt;";
87+
OS << ">";
8688
}
8789

8890
OS << mlir::rlc::prettyPrintFunctionTypeWithNameArgs(
8991
op.getType(), op.getInfo())
90-
<< "</code></li>\n";
92+
<< "`\n";
9193
writeComment(op, OS);
9294
}
9395

94-
static void printActionFuntion(
95-
mlir::rlc::ActionFunction op, llvm::raw_ostream& OS)
96+
static void printActionFunction(
97+
mlir::rlc::ActionFunction op, llvm::raw_ostream &OS)
9698
{
9799
// Print action function signature
98-
OS << "<div><strong>Action</strong>: <code>" << op.getUnmangledName()
99-
<< mlir::rlc::prettyType(op.getType()) << "</code></div>\n";
100+
OS << "- **Action**: `" << op.getUnmangledName()
101+
<< mlir::rlc::prettyType(op.getType()) << "`\n";
100102
writeComment(op, OS);
101103

102104
// Walk through action statements
103105
op.walk([&](mlir::rlc::ActionStatement action) {
104-
OS << "<ul>\n";
105-
OS << " <li><strong>Action Statement</strong>: <code>" << action.getName()
106-
<< "(";
106+
OS << " - **Action Statement**: `" << action.getName() << "(";
107107
for (size_t i = 0; i < action.getResultTypes().size(); ++i)
108108
{
109109
OS << mlir::rlc::prettyType(action.getResultTypes()[i]) << " "
110110
<< action.getDeclaredNames()[i];
111111
if (i < action.getResultTypes().size() - 1)
112112
OS << ", ";
113113
}
114-
OS << ")</code></li>\n";
114+
OS << ")`\n";
115115
writeComment(action, OS);
116-
OS << "</ul>\n";
117116
});
118117
}
119118

120119
static void printEnumDecl(
121-
mlir::rlc::EnumDeclarationOp op, llvm::raw_ostream& OS)
120+
mlir::rlc::EnumDeclarationOp op, llvm::raw_ostream &OS)
122121
{
123-
OS << "<h2>Enum " << op.getName() << "</h2>\n";
122+
OS << "## Enum " << op.getName() << "\n\n";
124123
writeComment(op, OS);
125124

125+
// Print enum fields with their types (if any expression gives more details)
126126
op.walk([&](mlir::rlc::EnumFieldDeclarationOp field) -> mlir::WalkResult {
127-
OS << "<ul>\n";
128127
field.walk([&](mlir::rlc::EnumFieldExpressionOp exp) {
129-
OS << " <li><code>" << mlir::rlc::prettyType(exp.getResult().getType())
130-
<< " " << exp.getName() << "</code></li>\n";
128+
OS << "- `" << mlir::rlc::prettyType(exp.getResult().getType()) << " "
129+
<< exp.getName() << "`\n";
131130
});
132-
OS << "</ul>\n";
131+
// Interrupt after first level
133132
return mlir::WalkResult::interrupt();
134133
});
135-
OS << "<br/>\n";
136-
OS << "<ul>\n";
137-
// Fields
138-
for (auto& op : op.getBody().front())
134+
135+
// List plain field names
136+
for (auto &innerOp : op.getBody().front())
139137
{
140-
auto casted = mlir::dyn_cast<mlir::rlc::EnumFieldDeclarationOp>(op);
141-
if (not casted)
138+
auto field = mlir::dyn_cast<mlir::rlc::EnumFieldDeclarationOp>(innerOp);
139+
if (!field)
142140
continue;
143-
144-
OS << " <li><code>" << casted.getName() << "</code></li>\n";
141+
OS << "- `" << field.getName() << "`\n";
145142
}
146-
OS << "</ul>\n";
143+
OS << "\n";
147144
}
148145

149146
static void printClassDecl(
150-
mlir::rlc::ClassDeclaration op, llvm::raw_ostream& OS)
147+
mlir::rlc::ClassDeclaration op, llvm::raw_ostream &OS)
151148
{
152-
OS << "<h2>Class " << op.getName() << "</h2>\n";
149+
OS << "## Class " << op.getName() << "\n\n";
153150
writeComment(op, OS);
154151

155152
// Fields
156153
if (!op.getMembers().empty())
157-
OS << "<h3>Fields</h3>\n<ul>\n";
158-
for (size_t i = 0; i < op.getMembers().size(); ++i)
159154
{
160-
auto name = op.getMemberField(i).getName();
161-
// Skip fields starting with underscore
162-
if (name.starts_with("_"))
163-
continue;
164-
165-
OS << " <li><code>"
166-
<< mlir::rlc::prettyType(
167-
op.getMemberField(i).getShugarizedType().getType())
168-
<< " " << name.str() << "</code></li>\n";
155+
OS << "### Fields\n";
156+
for (size_t i = 0; i < op.getMembers().size(); ++i)
157+
{
158+
auto name = op.getMemberField(i).getName();
159+
// Skip fields starting with underscore
160+
if (name.starts_with("_"))
161+
continue;
162+
OS << "- `"
163+
<< mlir::rlc::prettyType(
164+
op.getMemberField(i).getShugarizedType().getType())
165+
<< " " << name.str() << "`\n";
166+
}
167+
OS << "\n";
169168
}
170-
if (!op.getMembers().empty())
171-
OS << "</ul>\n";
172169

173170
// Methods
174171
auto methodOps = op.getBody().getOps<mlir::rlc::FunctionOp>();
175172
if (!methodOps.empty())
176173
{
177-
OS << "<h3>Methods</h3>\n<ul>\n";
174+
OS << "### Methods\n";
178175
for (auto member : methodOps)
179176
{
180177
printFunction(member, OS);
181178
}
182-
OS << "</ul>\n";
179+
OS << "\n";
183180
}
184181
}
185182

186183
static void printTrait(
187-
mlir::rlc::UncheckedTraitDefinition op, llvm::raw_ostream& OS)
184+
mlir::rlc::UncheckedTraitDefinition op, llvm::raw_ostream &OS)
188185
{
189-
OS << "<h2>Trait " << op.getName() << "</h2>\n";
186+
OS << "## Trait " << op.getName() << "\n\n";
190187
writeComment(op, OS);
191188

192189
auto funcs = op.getBody().getOps<mlir::rlc::FunctionOp>();
193-
if (!funcs.empty())
190+
for (auto member : funcs)
194191
{
195-
OS << "<ul>\n";
196-
for (auto member : funcs)
197-
{
198-
printFunction(member, OS);
199-
}
200-
OS << "</ul>\n";
192+
printFunction(member, OS);
201193
}
194+
OS << "\n";
202195
}
203196

204-
int main(int argc, char* argv[])
197+
int main(int argc, char *argv[])
205198
{
206199
llvm::cl::HideUnrelatedOptions(Category);
207200
cl::ParseCommandLineOptions(argc, argv);
@@ -220,7 +213,10 @@ int main(int argc, char* argv[])
220213
}
221214

222215
rlc::Parser parser(
223-
&context, buffer.get()->getBuffer().str(), InputFilePath, true);
216+
&context,
217+
buffer.get()->getBuffer().str(),
218+
InputFilePath,
219+
/*silent=*/true);
224220

225221
auto ast = mlir::ModuleOp::create(
226222
mlir::FileLineColLoc::get(&context, InputFilePath, 0, 0), InputFilePath);
@@ -244,17 +240,11 @@ int main(int argc, char* argv[])
244240
}
245241

246242
std::error_code EC;
247-
llvm::ToolOutputFile output(
248-
OutputFilePath, EC, llvm::sys::fs::OpenFlags::OF_None);
249-
auto& OS = output.os();
243+
llvm::ToolOutputFile output(OutputFilePath, EC, llvm::sys::fs::OF_None);
244+
auto &OS = output.os();
250245

251246
// Main heading
252-
OS << "<!DOCTYPE html>\n<html>\n<head>\n"
253-
<< " <meta charset=\"utf-8\">\n"
254-
<< " <title>Documentation - " << llvm::sys::path::filename(InputFilePath)
255-
<< "</title>\n</head>\n<body>\n";
256-
257-
OS << "<h1>" << llvm::sys::path::filename(InputFilePath) << "</h1>\n";
247+
OS << "# " << llvm::sys::path::filename(InputFilePath) << "\n\n";
258248

259249
// Classes
260250
for (auto op : ast.getOps<mlir::rlc::ClassDeclaration>())
@@ -266,49 +256,50 @@ int main(int argc, char* argv[])
266256
auto actionFuncs = ast.getOps<mlir::rlc::ActionFunction>();
267257
if (!actionFuncs.empty())
268258
{
269-
OS << "<h2>Actions</h2>\n";
259+
OS << "## Actions\n\n";
270260
for (auto op : actionFuncs)
271261
{
272-
printActionFuntion(op, OS);
262+
printActionFunction(op, OS);
273263
}
264+
OS << "\n";
274265
}
275266

276267
// Free functions
277268
auto freeFuncs = ast.getOps<mlir::rlc::FunctionOp>();
278-
// Filter out internal functions. printFunction() does that check internally.
279269
if (!freeFuncs.empty())
280270
{
281-
OS << "<h2>Free Functions</h2>\n<ul>\n";
271+
OS << "## Free Functions\n\n";
282272
for (auto op : freeFuncs)
283273
{
284274
printFunction(op, OS);
285275
}
286-
OS << "</ul>\n";
276+
OS << "\n";
287277
}
288278

289279
// Traits
290280
auto traits = ast.getOps<mlir::rlc::UncheckedTraitDefinition>();
291281
if (!traits.empty())
292282
{
293-
OS << "<h2>Traits</h2>\n";
283+
OS << "## Traits\n\n";
294284
for (auto op : traits)
295285
{
296286
printTrait(op, OS);
297287
}
288+
OS << "\n";
298289
}
299290

291+
// Enums
300292
auto enums = ast.getOps<mlir::rlc::EnumDeclarationOp>();
301293
if (!enums.empty())
302294
{
303-
OS << "<h2>Enums</h2>\n";
295+
OS << "## Enums\n\n";
304296
for (auto op : enums)
305297
{
306298
printEnumDecl(op, OS);
307299
}
300+
OS << "\n";
308301
}
309302

310-
OS << "</body>\n</html>\n";
311-
312303
output.keep();
313304
return 0;
314305
}

tool/rlc/test/examples/battleship.rl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ fun score(Game g, Int player_id) -> Float:
165165
fun get_num_players() -> Int:
166166
return 2
167167

168-
169168
fun fuzz(Vector<Byte> input):
170169
if input.size() == 0:
171170
return

tool/rlc/test/examples/checkers.rl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ fun pretty_print(Game g):
249249
print(s)
250250
x = x + 1
251251

252-
253252
fun fuzz(Vector<Byte> input):
254253
let state = play()
255254
let x : AnyGameAction

tool/rlc/test/examples/connect_four.rl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ fun score(Game g, Int player_id) -> Float:
207207
return -1.0
208208
return 0.0 # Draw
209209

210+
211+
210212
# Return number of players
211213
fun get_num_players() -> Int:
212214
return 2

tool/rlc/test/examples/hanabi.rl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ fun fuzz(Vector<Byte> input):
180180
let action : AnyGameAction
181181
parse_and_execute(state, action, input)
182182

183-
184183
fun pretty_print(Game g):
185184
print(g.player_hands)
186185
print(g.highest_card_played)

0 commit comments

Comments
 (0)