MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
ll.cpp
Go to the documentation of this file.
2
3#include <fstream>
4#include <string>
5
6#include "mim/util/print.h"
7#include "mim/util/sys.h"
8
9namespace mim::ll {
10
11using namespace std::string_literals;
12
13void emit(World& world, std::ostream& ostream) {
14 Emitter emitter(world, ostream);
15 emitter.run();
16}
17
18int compile(World& world, std::string name) {
19#ifdef _WIN32
20 auto exe = name + ".exe"s;
21#else
22 auto exe = name;
23#endif
24 return compile(world, name + ".ll"s, exe);
25}
26
27int compile(World& world, std::string ll, std::string out) {
28 std::ofstream ofs(ll);
29 emit(world, ofs);
30 ofs.close();
31 auto cmd = fmt("clang \"{}\" -o \"{}\" -Wno-override-module", ll, out);
32 return sys::system(cmd);
33}
34
35int compile_and_run(World& world, std::string name, std::string args) {
36 if (compile(world, name) == 0) return sys::run(name, args);
37 error("compilation failed");
38}
39
40} // namespace mim::ll
virtual void run()
Entry point and generates some debug output; invokes Phase::start.
Definition phase.cpp:13
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:31
Definition ll.h:39
int compile_and_run(World &, std::string name, std::string args={})
Definition ll.cpp:35
void emit(World &, std::ostream &)
Definition ll.cpp:13
int compile(World &, std::string name)
Definition ll.cpp:18
int run(std::string cmd, std::string args={})
Wraps sys::system and puts .exe at the back (Windows) and ./ at the front (otherwise) of cmd.
Definition sys.cpp:80
int system(std::string)
Wraps std::system and makes the return value usable.
Definition sys.cpp:74
std::string fmt(const char *s, Args &&... args)
Wraps mim::print to output a formatted std:string.
Definition print.h:178
void error(Loc loc, const char *f, Args &&... args)
Definition dbg.h:125