Commit 33f45e32 authored by Théotime Grohens's avatar Théotime Grohens Committed by Commit Bot

[torque] Add constexpr String handling to Torque

This CL adds a 'constexpr String' type to Torque, which gets compiled
to 'const char*'.

It makes it easier to pass strings around in Torque files,
especially when trying to Print() them.

Bug: v8:7793
Change-Id: I2d4feac7012f5401f2b467475f8df086e46ac18a
Reviewed-on: https://chromium-review.googlesource.com/1104466
Commit-Queue: Théotime Grohens <theotime@google.com>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53814}
parent 380dba0a
......@@ -26,7 +26,8 @@ type AbstractCode extends HeapObject generates 'TNode<AbstractCode>';
type Code extends AbstractCode generates 'TNode<Code>';
type JSReceiver extends HeapObject generates 'TNode<JSReceiver>';
type Context extends HeapObject generates 'TNode<Context>';
type String extends HeapObject generates 'TNode<String>';
type String extends HeapObject generates 'TNode<String>'
constexpr 'const char*';
type Oddball extends HeapObject generates 'TNode<Oddball>';
type HeapNumber extends HeapObject generates 'TNode<HeapNumber>';
type Number = Smi | HeapNumber;
......@@ -145,6 +146,8 @@ const INTPTR_PARAMETERS: constexpr ParameterMode = 'INTPTR_PARAMETERS';
extern macro Is64(): constexpr bool;
extern macro Print(constexpr String);
extern macro Print(constexpr String, Object);
extern macro Print(Object);
extern macro DebugBreak();
extern macro ToInteger_Inline(Context, Object): Number;
......@@ -339,6 +342,7 @@ extern macro Int32Constant(constexpr int31): int32;
extern macro Int32Constant(constexpr int32): int32;
extern macro SmiConstant(constexpr int31): Smi;
extern macro BoolConstant(constexpr bool): bool;
extern macro StringConstant(constexpr String): String;
extern macro LanguageModeConstant(constexpr LanguageMode): LanguageMode;
extern macro Int32Constant(constexpr ElementsKind): ElementsKind;
......@@ -390,6 +394,13 @@ macro from_constexpr<A : type>(e: constexpr ElementsKind): A;
from_constexpr<ElementsKind>(e: constexpr ElementsKind): ElementsKind {
return Int32Constant(e);
}
macro from_constexpr<A: type>(s: constexpr String): A;
from_constexpr<String>(s: constexpr String): String {
return StringConstant(s);
}
from_constexpr<Object>(s: constexpr String): Object {
return StringConstant(s);
}
macro convert<A : type>(i: int32): A;
convert<Number>(i: int32): Number {
......
......@@ -490,11 +490,10 @@ VisitResult ImplementationVisitor::Visit(NumberLiteralExpression* expr) {
}
VisitResult ImplementationVisitor::Visit(StringLiteralExpression* expr) {
std::string temp = GenerateNewTempVariable(TypeOracle::GetStringType());
source_out() << "StringConstant(\""
<< expr->literal.substr(1, expr->literal.size() - 2) << "\");"
<< std::endl;
return VisitResult{TypeOracle::GetStringType(), temp};
std::string temp = GenerateNewTempVariable(TypeOracle::GetConstStringType());
source_out() << "\"" << expr->literal.substr(1, expr->literal.size() - 2)
<< "\";" << std::endl;
return VisitResult{TypeOracle::GetConstStringType(), temp};
}
VisitResult ImplementationVisitor::GetBuiltinCode(Builtin* builtin) {
......
......@@ -40,8 +40,8 @@ class TypeOracle : public ContextualClass<TypeOracle> {
return Get().GetBuiltinType(OBJECT_TYPE_STRING);
}
static const Type* GetStringType() {
return Get().GetBuiltinType(STRING_TYPE_STRING);
static const Type* GetConstStringType() {
return Get().GetBuiltinType(CONST_STRING_TYPE_STRING);
}
static const Type* GetIntPtrType() {
......
......@@ -221,6 +221,7 @@ bool IsAssignableFrom(const Type* to, const Type* from) {
bool IsCompatibleSignature(const Signature& sig, const TypeVector& types,
const std::vector<Label*>& labels) {
auto i = sig.parameter_types.types.begin();
if (sig.parameter_types.types.size() > types.size()) return false;
// TODO(danno): The test below is actually insufficient. The labels'
// parameters must be checked too. ideally, the named part of
// LabelDeclarationVector would be factored out so that the label count and
......
......@@ -25,7 +25,7 @@ static const char* const VOID_TYPE_STRING = "void";
static const char* const ARGUMENTS_TYPE_STRING = "constexpr Arguments";
static const char* const CONTEXT_TYPE_STRING = "Context";
static const char* const OBJECT_TYPE_STRING = "Object";
static const char* const STRING_TYPE_STRING = "String";
static const char* const CONST_STRING_TYPE_STRING = "constexpr String";
static const char* const CODE_TYPE_STRING = "Code";
static const char* const INTPTR_TYPE_STRING = "intptr";
static const char* const CONST_INT31_TYPE_STRING = "constexpr int31";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment