Commit efaece9c authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[torque][clenaup] Rename Constant to ExternConstant

This CL renames Constant to ExternConstant (this already happend in the
grammar). It also enforces the rule that such extern constants require
"constexpr" types.

Drive-by-change: Replaced non constexpr extern constants with
module constants.

R=tebbi@chromium.org

Bug: v8:7793
Change-Id: Icb3f75071b15b1fcabbe447941e05dd5a09d4b23
Reviewed-on: https://chromium-review.googlesource.com/1136434Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Simon Zünd <szuend@google.com>
Cr-Commit-Position: refs/heads/master@{#54453}
parent b8e3793a
......@@ -108,9 +108,10 @@ type FixedBigInt64Array extends FixedTypedArray;
const kAllFixedArrays: constexpr ExtractFixedArrayFlags generates
'ExtractFixedArrayFlag::kAllFixedArrays';
const kCOWMap: Map generates 'LoadRoot(Heap::kFixedCOWArrayMapRootIndex)';
const kEmptyFixedArray: FixedArrayBase generates
'UncheckedCast<FixedArrayBase>(LoadRoot(Heap::kEmptyFixedArrayRootIndex))';
const kFixedCOWArrayMapRootIndex: constexpr RootListIndex generates
'Heap::kFixedCOWArrayMapRootIndex';
const kEmptyFixedArrayRootIndex: constexpr RootListIndex generates
'Heap::kEmptyFixedArrayRootIndex';
const kInvalidArrayLength: constexpr MessageTemplate generates
'MessageTemplate::kInvalidArrayLength';
......@@ -136,11 +137,18 @@ const kInvalidDataViewAccessorOffset: constexpr MessageTemplate generates
const kStrictReadOnlyProperty: constexpr MessageTemplate generates
'MessageTemplate::kStrictReadOnlyProperty';
const Hole: Oddball generates 'TheHoleConstant()';
const Null: Oddball generates 'NullConstant()';
const Undefined: Oddball generates 'UndefinedConstant()';
const True: Boolean generates 'TrueConstant()';
const False: Boolean generates 'FalseConstant()';
extern macro TheHoleConstant(): Oddball;
extern macro NullConstant(): Oddball;
extern macro UndefinedConstant(): Oddball;
extern macro TrueConstant(): Boolean;
extern macro FalseConstant(): Boolean;
const Hole: Oddball = TheHoleConstant();
const Null: Oddball = NullConstant();
const Undefined: Oddball = UndefinedConstant();
const True: Boolean = TrueConstant();
const False: Boolean = FalseConstant();
const true: constexpr bool generates 'true';
const false: constexpr bool generates 'false';
......@@ -489,6 +497,7 @@ convert<intptr>(r: RawPtr): intptr {
}
extern macro UnsafeCastNumberToHeapNumber(Number): HeapNumber;
extern macro UnsafeCastObjectToFixedArrayBase(Object): FixedArrayBase;
extern macro UnsafeCastObjectToFixedArray(Object): FixedArray;
extern macro UnsafeCastObjectToFixedDoubleArray(Object): FixedDoubleArray;
extern macro UnsafeCastObjectToHeapNumber(Object): HeapNumber;
......@@ -501,6 +510,7 @@ extern macro UnsafeCastObjectToFixedTypedArrayBase(Object): FixedTypedArrayBase;
extern macro UnsafeCastObjectToNumberDictionary(Object): NumberDictionary;
extern macro UnsafeCastObjectToJSReceiver(Object): JSReceiver;
extern macro UnsafeCastObjectToJSObject(Object): JSObject;
extern macro UnsafeCastObjectToMap(Object): Map;
macro unsafe_cast<A : type>(n: Number): A;
unsafe_cast<HeapNumber>(n: Number): HeapNumber {
......@@ -543,6 +553,16 @@ unsafe_cast<JSReceiver>(o: Object): JSReceiver {
unsafe_cast<JSObject>(o: Object): JSObject {
return UnsafeCastObjectToJSObject(o);
}
unsafe_cast<Map>(o: Object): Map {
return UnsafeCastObjectToMap(o);
}
unsafe_cast<FixedArrayBase>(o: Object): FixedArrayBase {
return UnsafeCastObjectToFixedArrayBase(o);
}
const kCOWMap: Map = unsafe_cast<Map>(LoadRoot(kFixedCOWArrayMapRootIndex));
const kEmptyFixedArray: FixedArrayBase = unsafe_cast<FixedArrayBase>(
LoadRoot(kEmptyFixedArrayRootIndex));
extern macro BranchIfFastJSArray(Object, Context): never labels Taken, NotTaken;
extern macro BranchIfNotFastJSArray(Object, Context): never labels Taken,
......
......@@ -338,6 +338,10 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
return CAST(p_n);
}
TNode<FixedArrayBase> UnsafeCastObjectToFixedArrayBase(TNode<Object> p_o) {
return CAST(p_o);
}
TNode<FixedArray> UnsafeCastObjectToFixedArray(TNode<Object> p_o) {
return CAST(p_o);
}
......@@ -391,6 +395,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
return CAST(p_o);
}
TNode<Map> UnsafeCastObjectToMap(TNode<Object> p_o) { return CAST(p_o); }
Node* MatchesParameterMode(Node* value, ParameterMode mode);
#define PARAMETER_BINOP(OpName, IntPtrOpName, SmiOpName) \
......
......@@ -35,7 +35,7 @@ class Declarable {
kGenericList,
kTypeAlias,
kLabel,
kConstant,
kExternConstant,
kModuleConstant
};
Kind kind() const { return kind_; }
......@@ -49,10 +49,11 @@ class Declarable {
bool IsVariable() const { return kind() == kVariable; }
bool IsMacroList() const { return kind() == kMacroList; }
bool IsGenericList() const { return kind() == kGenericList; }
bool IsConstant() const { return kind() == kConstant; }
bool IsExternConstant() const { return kind() == kExternConstant; }
bool IsModuleConstant() const { return kind() == kModuleConstant; }
bool IsValue() const {
return IsVariable() || IsConstant() || IsParameter() || IsModuleConstant();
return IsVariable() || IsExternConstant() || IsParameter() ||
IsModuleConstant();
}
virtual const char* type_name() const { return "<<unknown>>"; }
......@@ -188,16 +189,16 @@ class Label : public Declarable {
bool used_;
};
class Constant : public Value {
class ExternConstant : public Value {
public:
DECLARE_DECLARABLE_BOILERPLATE(Constant, constant);
DECLARE_DECLARABLE_BOILERPLATE(ExternConstant, constant);
std::string value() const override { return value_; }
private:
friend class Declarations;
explicit Constant(const std::string& name, const Type* type,
const std::string& value)
: Value(Declarable::kConstant, type, name), value_(value) {}
explicit ExternConstant(const std::string& name, const Type* type,
const std::string& value)
: Value(Declarable::kExternConstant, type, name), value_(value) {}
std::string value_;
};
......
......@@ -138,7 +138,7 @@ void DeclarationVisitor::Visit(TorqueBuiltinDeclaration* decl,
CurrentCallableActivator activator(global_context_, builtin, decl);
DeclareSignature(signature);
if (signature.parameter_types.var_args) {
declarations()->DeclareConstant(
declarations()->DeclareExternConstant(
decl->signature->parameters.arguments_variable,
TypeOracle::GetArgumentsType(), "arguments");
}
......@@ -271,6 +271,18 @@ void DeclarationVisitor::Visit(VarDeclarationStatement* stmt) {
}
}
void DeclarationVisitor::Visit(ExternConstDeclaration* decl) {
const Type* type = declarations()->GetType(decl->type);
if (!type->IsConstexpr()) {
std::stringstream stream;
stream << "extern constants must have constexpr type, but found: \""
<< *type << "\"\n";
ReportError(stream.str());
}
declarations()->DeclareExternConstant(decl->name, type, decl->literal);
}
void DeclarationVisitor::Visit(LogicalOrExpression* expr) {
{
Declarations::NodeScopeActivator scope(declarations(), expr->left);
......
......@@ -107,14 +107,7 @@ class DeclarationVisitor : public FileVisitor {
}
void Visit(VarDeclarationStatement* stmt);
void Visit(ExternConstDeclaration* decl) {
// TODO(szuend): When module-wide const bindings are available, only
// constexpr types should be allowed here.
declarations()->DeclareConstant(
decl->name, declarations()->GetType(decl->type), decl->literal);
}
void Visit(ExternConstDeclaration* decl);
void Visit(LogicalOrExpression* expr);
void Visit(LogicalAndExpression* expr);
void DeclareExpressionForBranch(Expression* node);
......
......@@ -314,10 +314,11 @@ Label* Declarations::DeclarePrivateLabel(const std::string& raw_name) {
return result;
}
void Declarations::DeclareConstant(const std::string& name, const Type* type,
const std::string& value) {
void Declarations::DeclareExternConstant(const std::string& name,
const Type* type,
const std::string& value) {
CheckAlreadyDeclared(name, "constant, parameter or arguments");
Constant* result = new Constant(name, type, value);
ExternConstant* result = new ExternConstant(name, type, value);
Declare(name, std::unique_ptr<Declarable>(result));
}
......
......@@ -95,8 +95,8 @@ class Declarations {
Label* DeclarePrivateLabel(const std::string& name);
void DeclareConstant(const std::string& name, const Type* type,
const std::string& value);
void DeclareExternConstant(const std::string& name, const Type* type,
const std::string& value);
ModuleConstant* DeclareModuleConstant(const std::string& name,
const Type* type);
......
......@@ -275,8 +275,9 @@ void ImplementationVisitor::Visit(TorqueBuiltinDeclaration* decl,
size_t first = 1;
if (builtin->IsVarArgsJavaScript()) {
assert(decl->signature->parameters.has_varargs);
Constant* arguments = Constant::cast(declarations()->LookupValue(
decl->signature->parameters.arguments_variable));
ExternConstant* arguments =
ExternConstant::cast(declarations()->LookupValue(
decl->signature->parameters.arguments_variable));
std::string arguments_name = arguments->value();
GenerateIndent();
source_out()
......
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