Updates hehe :)

This commit is contained in:
apio 2022-06-07 18:12:43 +02:00
parent 19b32214a4
commit 7a320fb70a
8 changed files with 74 additions and 4 deletions

16
core/init.sp Normal file
View File

@ -0,0 +1,16 @@
import core/flow;
namespace init {
i32 _libcore_Argc;
i8** _libcore_Argv;
@__libcore_call_init (i32 _Argc, i8** _Argv) {
_libcore_Argc = _Argc;
_libcore_Argv = _Argv;
main();
flow.exit(0);
}
}

View File

@ -1,19 +1,25 @@
#include "Arguments.h"
#include "Error.h"
#include "tclap/CmdLine.h"
#include "llvm/Support/Host.h"
std::string Arguments::input_fname;
std::string Arguments::output_fname;
bool Arguments::wimport;
llvm::Triple Arguments::TargetTriple;
std::string Arguments::cpu;
void Arguments::parse(int argc, char **argv)
{
try {
TCLAP::CmdLine command_line("The Sapphire compiler.",' ',"0.1");
TCLAP::UnlabeledValueArg<std::string> input_fname_arg("file","Input file.",true,"test.sp","filename");
TCLAP::UnlabeledValueArg<std::string> input_fname_arg("file","Input file.",true,"test.sp","string");
TCLAP::ValueArg<std::string> output_fname_arg("o","output","Output file.",false,"sp-output","output");
TCLAP::ValueArg<std::string> output_fname_arg("o","output","Output file.",false,"sp-output","string");
TCLAP::ValueArg<std::string> march_arg("","march","Architecture to compile for.",false,"native","string");
TCLAP::ValueArg<std::string> mcpu_arg("","mcpu","CPU to compile for.",false,"generic","string");
TCLAP::ValueArg<std::string> msystem_arg("","msystem","Operating System to compile for.",false,"native","string");
TCLAP::SwitchArg wimport_arg("","wimport","Show a warning when trying to import an already imported file.");
@ -22,13 +28,40 @@ void Arguments::parse(int argc, char **argv)
command_line.add(input_fname_arg);
command_line.add(output_fname_arg);
command_line.add(march_arg);
command_line.add(mcpu_arg);
command_line.add(msystem_arg);
command_line.parse(argc,argv);
input_fname = input_fname_arg.getValue();
output_fname = output_fname_arg.getValue();
wimport = wimport_arg.getValue();
cpu = mcpu_arg.getValue();
setTriple(march_arg.getValue(),msystem_arg.getValue());
} catch (TCLAP::ArgException &e) {
Error::throw_error_without_location(e.error());
}
}
void Arguments::setTriple(const std::string& arch, const std::string& system)
{
std::string triple = llvm::sys::getDefaultTargetTriple();
llvm::Triple tgTriple(triple);
if(arch != "native")
{
tgTriple.setArchName(arch);
}
if(system != "native")
{
tgTriple.setOSAndEnvironmentName(system);
}
tgTriple.setVendor(llvm::Triple::VendorType::UnknownVendor); // let's leave it like that
TargetTriple = tgTriple;
}

View File

@ -1,5 +1,6 @@
#pragma once
#include <string>
#include <llvm/ADT/Triple.h>
struct Arguments
{
@ -9,4 +10,10 @@ struct Arguments
static std::string output_fname;
static bool wimport;
static std::string cpu;
static llvm::Triple TargetTriple;
private:
static void setTriple(const std::string& arch, const std::string& system);
};

View File

@ -233,6 +233,7 @@ Token Lexer::create_identifier()
if (identifier == "syscall3") return Token::make_with_line({TT_Syscall3,{prev_line,prev_column,loc.fname}},current_line_text);
if (identifier == "syscall4") return Token::make_with_line({TT_Syscall4,{prev_line,prev_column,loc.fname}},current_line_text);
if (identifier == "syscall5") return Token::make_with_line({TT_Syscall5,{prev_line,prev_column,loc.fname}},current_line_text);
if( identifier == "compmacro" ) return Token::make_with_line({TT_CompilerMacro,{prev_line,prev_column,loc.fname}},current_line_text);
return Token::make_with_line({TT_Identifier,identifier,{prev_line,prev_column,loc.fname}},current_line_text);
}
}
@ -251,6 +252,7 @@ Token Lexer::create_identifier()
if (identifier == "syscall3") return Token::make_with_line({TT_Syscall3,{prev_line,prev_column,loc.fname}},current_line_text);
if (identifier == "syscall4") return Token::make_with_line({TT_Syscall4,{prev_line,prev_column,loc.fname}},current_line_text);
if (identifier == "syscall5") return Token::make_with_line({TT_Syscall5,{prev_line,prev_column,loc.fname}},current_line_text);
if( identifier == "compmacro" ) return Token::make_with_line({TT_CompilerMacro,{prev_line,prev_column,loc.fname}},current_line_text);
return Token::make_with_line({TT_Identifier,identifier,{prev_line,prev_column,loc.fname}},current_line_text);
}

View File

@ -1,4 +1,7 @@
#pragma once
#include <memory>
#include "Lexer.h"
#include "AST/ASTNode.h"
class Parser
{
@ -7,4 +10,7 @@ private:
public:
Parser(/* args */);
~Parser();
static std::shared_ptr<Parser> new_parser(const TokenStream& tokens);
std::shared_ptr<ASTNode> parse();
};

View File

@ -42,7 +42,8 @@ const std::string token_strings[] = {
"TT_SYSCALL2",
"TT_SYSCALL3",
"TT_SYSCALL4",
"TT_SYSCALL5"
"TT_SYSCALL5",
"TT_COMPILERMACRO"
};
Token::Token(const TokenType& type)
@ -186,6 +187,8 @@ std::string Token::to_string() const
return "SYSCALL4 " + details;
case TT_Syscall5:
return "SYSCALL5 " + details;
case TT_CompilerMacro:
return "COMPMACRO " + details;
}
return "";
}

View File

@ -43,7 +43,8 @@ enum TokenType
TT_Syscall2,
TT_Syscall3,
TT_Syscall4,
TT_Syscall5
TT_Syscall5,
TT_CompilerMacro
};
extern const std::string token_strings[];

View File

@ -22,4 +22,6 @@ int main(int argc, char** argv)
}
std::cout << "Output filename: " << Arguments::output_fname << std::endl;
std::cout << "Output target triple: " << Arguments::TargetTriple.getTriple() << std::endl;
}