Pass in constraints
This commit is contained in:
@@ -20,11 +20,11 @@ i u32 <- 0, rep text[i] != 0:
|
||||
|
||||
// text data<u8> <- "Hello world!"
|
||||
|
||||
/*addStuff asm<+r, r>: num1 u32, num2 u32 -> u32
|
||||
/*addStuff asm<"+r, r">: num1 u32, num2 u32 -> u32
|
||||
add $1, $0
|
||||
;*/
|
||||
|
||||
rawAdd raw
|
||||
rawAdd raw<"~{ebx}">
|
||||
//push rbx
|
||||
mov ebx, 5
|
||||
//pop rbx
|
||||
|
||||
@@ -135,7 +135,7 @@ void ModuleBuilder::buildRawFunction(shared_ptr<StatementRawFunction> statement)
|
||||
vector<llvm::Type *> types;
|
||||
|
||||
llvm::FunctionType *funType = llvm::FunctionType::get(llvm::Type::getVoidTy(*context), types, false);
|
||||
llvm::InlineAsm *rawFun = llvm::InlineAsm::get(funType, statement->getRawSource(), "~{ebx}", false, false, llvm::InlineAsm::AsmDialect::AD_Intel);
|
||||
llvm::InlineAsm *rawFun = llvm::InlineAsm::get(funType, statement->getRawSource(), statement->getConstraints(), false, false, llvm::InlineAsm::AsmDialect::AD_Intel);
|
||||
if (!setRawFun(statement->getName(), rawFun))
|
||||
return;
|
||||
|
||||
|
||||
@@ -240,12 +240,26 @@ shared_ptr<Statement> Parser::matchStatementRawFunction() {
|
||||
return nullptr;
|
||||
|
||||
string name;
|
||||
string constraints;
|
||||
string rawSource;
|
||||
|
||||
// name
|
||||
name = tokens.at(currentIndex++)->getLexme();
|
||||
currentIndex++; // skip raw
|
||||
|
||||
// constraints
|
||||
|
||||
if (tryMatchingTokenKinds({TokenKind::LESS}, true, true)) {
|
||||
if (tokens.at(currentIndex)->isOfKind({TokenKind::STRING})) {
|
||||
constraints = tokens.at(currentIndex++)->getLexme();
|
||||
// remove enclosing quotes
|
||||
if (constraints.length() >= 2)
|
||||
constraints = constraints.substr(1, constraints.length() - 2);
|
||||
}
|
||||
if (!tryMatchingTokenKinds({TokenKind::GREATER}, true, true))
|
||||
markError({TokenKind::GREATER}, {});
|
||||
}
|
||||
|
||||
// consume new line
|
||||
if (!tryMatchingTokenKinds({TokenKind::NEW_LINE}, true, true)) {
|
||||
markError(TokenKind::NEW_LINE, {});
|
||||
@@ -267,7 +281,7 @@ shared_ptr<Statement> Parser::matchStatementRawFunction() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return make_shared<StatementRawFunction>(name, rawSource);
|
||||
return make_shared<StatementRawFunction>(name, constraints, rawSource);
|
||||
}
|
||||
|
||||
shared_ptr<Statement> Parser::matchStatementBlock(vector<TokenKind> terminalTokenKinds) {
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
#include "StatementRawFunction.h"
|
||||
|
||||
StatementRawFunction::StatementRawFunction(string name, string rawSource):
|
||||
Statement(StatementKind::RAW_FUNCTION), name(name), rawSource(rawSource) { }
|
||||
StatementRawFunction::StatementRawFunction(string name, string constraints, string rawSource):
|
||||
Statement(StatementKind::RAW_FUNCTION), name(name), constraints(constraints), rawSource(rawSource) { }
|
||||
|
||||
string StatementRawFunction::getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
string StatementRawFunction::getConstraints() {
|
||||
return constraints;
|
||||
}
|
||||
|
||||
string StatementRawFunction::getRawSource() {
|
||||
return rawSource;
|
||||
}
|
||||
@@ -5,10 +5,12 @@ class Expression;
|
||||
class StatementRawFunction: public Statement {
|
||||
private:
|
||||
string name;
|
||||
string constraints;
|
||||
string rawSource;
|
||||
|
||||
public:
|
||||
StatementRawFunction(string name, string rawSource);
|
||||
StatementRawFunction(string name, string constraints, string rawSource);
|
||||
string getName();
|
||||
string getConstraints();
|
||||
string getRawSource();
|
||||
};
|
||||
Reference in New Issue
Block a user